Create an RSA or elliptic-curve key pair with the Web Crypto API and export both keys as PEM. Generation happens locally — the private key never leaves your browser.
Yes — generateKey runs in your browser via Web Crypto and nothing is transmitted.
EC keys are smaller and faster at similar security; RSA is more widely compatible. P-256 or RSA-2048 are sensible defaults.
The public key as SPKI (BEGIN PUBLIC KEY) and the private key as PKCS#8 (BEGIN PRIVATE KEY).