W3docs

HTML <keygen> Tag

The HTML <keygen> tag is obsolete and removed from browsers. Learn what it did, its old attributes, and the modern Web Crypto API replacement.

The <keygen> tag was an HTML form-associated element used to generate a public/private key pair for client-certificate enrollment. It has since been deprecated and removed from the HTML standard and from all modern browsers, so it no longer works anywhere. This page documents what it did and what to use instead.

Danger

<keygen> is obsolete. It was removed from the HTML specification and dropped by every major browser (around 2017–2020). It does nothing in current browsers and must not be used in new pages. For generating cryptographic keys in the browser, use the Web Cryptography API (crypto.subtle.generateKey()) instead — see the What to use instead section below.

What it did

When a form containing a <keygen> element was submitted, the browser:

  1. Generated a fresh public/private key pair on the user's device.
  2. Stored the private key in the local keystore (the browser or OS keychain); it never left the device.
  3. Sent the public key to the server, packaged as a SignedPublicKeyAndChallenge (SPKAC) string, alongside the rest of the form data.

The server could then use that public key to issue a client certificate, binding it to the key the user kept locally. The whole mechanism existed to support client-certificate enrollment — a way for a website to provision a TLS client certificate into the user's browser.

This was about provisioning keys/certificates for authentication, not about signing documents.

Example of the (obsolete) HTML <keygen> tag

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <!-- This element no longer works in any modern browser. -->
    <form action="/form/submit" method="post">
      <keygen name="rsaPublicKey" keytype="rsa">
      User's name:
      <input type="text" name="usr_name" />
      <input type="submit" />
    </form>
  </body>
</html>

The <keygen> tag was placed inside a <form> container and did not require a closing tag.

Browser Support

  • Chrome, Edge, Firefox, Safari, Opera: Removed. All major browsers dropped support for <keygen>; it is ignored if it appears in markup today.
  • Mobile Browsers: Not supported.

What to use instead

<keygen> was deprecated because its job moved into JavaScript. The direct technical replacement for generating a key pair in the browser is the Web Cryptography API, specifically crypto.subtle.generateKey(). It gives scripts fine-grained control over the algorithm, key usages, and whether the key is extractable — none of which <keygen> offered.

// Generate an RSA key pair with the Web Crypto API.
const keyPair = await crypto.subtle.generateKey(
  {
    name: "RSASSA-PKCS1-v1_5",
    modulusLength: 2048,
    publicExponent: new Uint8Array([0x01, 0x00, 0x01]), // 65537
    hash: "SHA-256",
  },
  true,                 // keys can be exported
  ["sign", "verify"]    // allowed operations
);

// Export the public key to send it to the server.
const publicKey = await crypto.subtle.exportKey("spki", keyPair.publicKey);

For user authentication more broadly, modern applications use the Web Authentication API (WebAuthn) — the standard behind passkeys and hardware security keys — rather than client-certificate enrollment via <keygen>.

Note: protocols such as OAuth and OpenID Connect solve a different problem (delegated authorization and sign-in). They are not a replacement for the cryptographic key generation that <keygen> performed.

Attributes (obsolete)

These attributes were defined for <keygen> while it was part of the spec. They are listed for reference only — the element and all of its attributes are obsolete.

AttributeValueDescription
autofocusautofocusSpecified that the element automatically receives focus when the page loaded.
challengestringA challenge string packaged with the public key (in the SPKAC) when the form was submitted. Defaulted to an empty string if omitted.
disableddisabledDisabled the <keygen> element.
formform_idAssociated the element with a specific form by its id, letting it sit outside that form in the markup.
keytypersa, dsa, ecThe key algorithm. rsa was the only consistently supported value (and the default); dsa and ec were never reliably implemented.
namestringThe name submitted with the generated public key.

The <keygen> tag also supported the Global Attributes and the Event Attributes.

<keygen> is one of several elements that have been removed from HTML. See the full list of deprecated HTML tags and the <form> element it was designed to work with.

Practice

Practice
Which statement about the HTML keygen element is correct?
Which statement about the HTML keygen element is correct?
Was this page helpful?