HTML <keygen> Element
The <keygen> element was historically used within an HTML form to generate a cryptographic public and private key pair in the browser. The private key was stored locally while the public key could be submitted to a server as part of the form data.
<keygen> element must not be used in new HTML. Modern browsers have removed support for it, and applications requiring cryptographic operations should use current web security technologies designed for their specific requirements.
Historical Syntax
Older HTML documents may contain markup similar to the following:
<form action="register.php" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username">
<keygen name="public-key">
<button type="submit">Register</button>
</form>
In a supporting browser, the <keygen> element provided a control for generating a key pair. The private key remained on the user's device while information representing the public key was submitted with the form. This code is shown for historical reference only and should not be used in modern HTML.
Attributes
The <keygen> element historically supported several element-specific attributes associated with key generation and form submission. These attributes are obsolete along with the element and are included here to help identify and understand older HTML source code.
| Attribute | Description |
|---|---|
autofocus |
Indicated that the key generation control should receive focus automatically when the page loaded. |
challenge |
Specified a challenge string that could be included with the generated key information. |
disabled |
Prevented the key generation control from being used or submitted. |
form |
Associated the key generation control with a particular form. |
keytype |
Specified the type of cryptographic key that should be generated. |
name |
Specified the name used when the generated public-key information was submitted with the form. |
Historical Use
The <keygen> element was designed to make client-side key generation available directly through an HTML form. When the form was displayed, a supporting browser could present a control that allowed the user to select a key size or other available key-generation option.
When the form was submitted, the browser generated a public and private key pair. The private key was retained by the browser or its associated key store, while the public-key information was encoded and sent to the server.
This mechanism was primarily associated with certificate enrollment and authentication systems rather than ordinary forms. Its behavior depended heavily on browser-specific cryptographic implementations.
Why It Became Obsolete
The <keygen> element depended on browser-managed cryptographic behavior that was difficult to implement consistently and did not fit well with the direction of modern web security. Browser support varied, and the element offered limited control over how keys and certificates were generated and managed.
Browser vendors eventually removed support for <keygen>, and the element was removed from the HTML standard. Modern web applications use purpose-specific security mechanisms and cryptographic APIs instead of an HTML element that automatically generates and submits keys.
Modern Alternative
There is no direct modern HTML element that replaces <keygen>. The appropriate replacement depends on why the original page generated a key pair.
Modern applications may use the Web Cryptography API when they need browser-based cryptographic operations. Authentication systems may instead use technologies such as WebAuthn and passkeys when the goal is secure user authentication.
These technologies work very differently from <keygen> and generally require JavaScript and server-side processing. An old <keygen> element therefore cannot simply be replaced with another HTML tag.
Legacy Browser Support
The <keygen> element was supported by some earlier browsers, but support has been removed from modern browser engines. Current webpages should not expect the element to display a working key-generation control or perform its historical cryptographic behavior.
Unlike obsolete elements that browsers continue to render for compatibility with old webpages, <keygen> no longer provides a usable legacy mechanism for generating cryptographic keys. Existing applications that depend on it must be redesigned using current security technologies.
For detailed legacy browser compatibility information, see Can I Use: HTML <keygen> Element .
Related Elements
The <keygen> element was historically used as a form control. Modern forms use the <form>, <input>, <label>, and <button> elements for collecting and submitting ordinary user input, but none of these directly replaces its cryptographic functionality.
Specifications
The <keygen> element is an obsolete, non-conforming feature in modern HTML and must not be used in new documents. Applications that previously depended on it should use current security and cryptographic technologies appropriate to their requirements.
