How to Use HTTPS on Localhost During Development

Check when loopback HTTP is enough, then create and verify a trusted HTTPS certificate for a localhost-only development server.

FBFenwei BianAuthorNov 24, 2026
  • https
  • localhost
  • tls
  • guide

Use http://localhost when it satisfies your local test. Browsers can treat loopback HTTP as a potentially trustworthy origin. Use a trusted local HTTPS server when you need to test an actual TLS connection, a callback that specifically requires an HTTPS URL, or behavior tied to the HTTPS origin.

Check which condition your feature requires

Open your local app as a top-level page and evaluate window.isSecureContext in the browser console. A value of true means the page passes the browser's secure-context check. It does not show that traffic used TLS. The Secure Contexts specification treats loopback IP addresses as potentially trustworthy and sets conditions for treating localhost names the same way.

Suppose a webcam feature already works at http://localhost:3000 but your test harness compares an HTTPS callback URL. Keep the webcam test on its existing origin. Configure HTTPS for the second test and register the exact callback the harness uses, including hostname and port. The browser treats http://localhost:3000 and https://localhost:3000 as separate origins.

Configure a certificate on a development machine

A public certificate authority cannot issue a normal public certificate for the bare name localhost. Let's Encrypt explains why. For a private development setup, use a local issuer you control. For example, on your own development machine, mkcert can create a local certificate authority and a leaf certificate.

  1. Run mkcert -install in the development environment that needs the trust change. Verify that the browser or client you use trusts the local issuer. Some clients use separate trust stores.
  2. Run mkcert -cert-file localhost.pem -key-file localhost-key.pem localhost 127.0.0.1 ::1 to generate files covering those exact names and addresses.
  3. Configure the development server's TLS certificate and key files. Keep the listener on loopback. Open https://localhost:3000 if that is the port the server uses.
  4. In the browser's certificate viewer, verify that the certificate is trusted and its subject alternative names include localhost. If you browse by IP, check the matching IP entry. Trust in the issuer alone cannot fix a name mismatch.

Keep the local CA private key and server key out of source control and shared images. Use distinct trust and keys for production. When a temporary development environment no longer needs the CA, use mkcert -uninstall to remove its trust from the supported local stores, and remove any trust you added separately.

Sources and further reading

About the author(s)

Software Developer & Writer • Namefi
FBAuthor

Fenwei Bian is a software developer in her thirties who spends her working hours in pull requests and her weekends with her hands in soil or sawdust. Years of open source on GitHub taught her that names are interfaces: a good one is clear, honest about what it does, and kind to whoever has to use it next.

She gardens because it rewards patience and punishes wishful thinking, and she does woodwork because a joint either fits or it doesn't. Both habits show up in how she writes about naming — measure twice, check the source, and don't sand over a rough spot and hope no one notices.

For Namefi she writes about how domain markets actually move, the practical trade-offs of tokenizing and flipping names, and picking a domain you'll still be glad you own in twenty years.

Related guides

Discuss this post

View the discussion on Namefi Discuss