When you scan a "join Wi-Fi" QR code, your phone isn't talking to the router. The QR code just holds a short line of text in a format phones agree on:

WIFI:T:WPA;S:MyHomeNetwork;P:correct horse battery;; 
  • T is the security type: WPA (also used for WPA2/WPA3 personal), WEP, or nopass for open networks.
  • S is the network name (SSID), exactly as broadcast, capitals included.
  • P is the password.
  • H:true can be added for hidden networks.
  • The line ends with ;;.

Escaping

If your SSID or password contains \, ;, ,, : or ", those characters must be escaped with a backslash, or the phone splits the string in the wrong place:

WIFI:T:WPA;S:Cafe\;Guest;P:pa\:ss;; 

This is the most common reason a printed Wi-Fi code "doesn't work".

Generating one in JavaScript

const esc = s => s.replace(/([\\;,:"])/g, '\\$1'); const wifi = (ssid, pass, type = 'WPA') => `WIFI:T:${type};S:${esc(ssid)};P:${esc(pass)};;`; // Feed the string to any QR library, e.g. qrcode: QRCode.toDataURL(wifi('Home', 'secret')) 

Before you print

  • Anyone who can photograph the code can read the password, so use it on a guest network.
  • If you change the password, the old code stops working. The code is static; nothing to "renew".
  • Print at a decent size with a white border (the quiet zone) and test with two different phones.

Disclosure: I run GoToolsOnline, which has a free QR code generator that builds this Wi-Fi string (and vCards, links, email, SMS) for you.