Trusted certificates for localhost with mkcert

HTTPS on your dev server without the browser warning, in three commands.

SNP 143 #46B Filed ssl webdev cmd

shell
mkcert -install
mkcert localhost 127.0.0.1 ::1 myapp.test

The first command creates a local certificate authority and adds it to your system and browser trust stores. The second writes localhost+3.pem and localhost+3-key.pem, signed by that authority, so browsers on this machine trust them.

Point your server at them, for example in a Vite config:

javascript
server: {
  https: {
    cert: './localhost+3.pem',
    key: './localhost+3-key.pem',
  },
}

Install it with brew install mkcert, choco install mkcert or your distro's package. Don't commit the key files, and never use this authority for anything but your own machine. Some things (the clipboard API, service workers, geolocation) only work on HTTPS, which is usually why you end up here.