HTML <keygen> Tag

Beginner
5 min read
Updated: Oct 2026
3 examples
Obsolete

Definition and Usage

The <keygen> element was a form control that generated a public/private key pair in the browser. On submit, the public key was sent to the server; the private key stayed on the device (often for certificate enrollment).

Study it for legacy pages only. There is no modern HTML replacement element — certificate workflows use platform tools or the Web Cryptography API, not <keygen>.

Obsolete.

Non-conforming in the HTML Living Standard. Removed from browsers (e.g. Chrome ~57). Do not use it in new forms.

Use instead.

For enrollment: generate keys with the Web Cryptography API, then export/install materials for the user. For enterprise device management: use native on-device management — not an HTML tag. Ordinary forms still use <form> and <input>.

HTML Syntax

syntax.html
<keygen name=" pubkey">

Historically a void element (no end tag, no children), used inside a <form>. Modern browsers ignore it as a key-pair control.

Attributes

Historical attributes on <keygen> (all obsolete with the element):

AttributeDescriptionTry it
nameForm field name for the submitted public keyTry it
challengeChallenge string submitted with the public keyTry it
keytypeKey algorithm type (historically rsa)Try it
disabledDisabled the control so it could not be usedLegacy only
autofocusFocused the control when the page loadedLegacy only
formAssociated the control with a form by idLegacy only

Global Attributes

The <keygen> tag also supports the Global Attributes in HTML.

Live Preview

<keygen> does not generate keys here. This preview shows what a modern page should do instead: a normal form without keygen, plus a clear obsolete notice.

Simulated legacy markup note — no key pair is created in the browser.

Modern form (no keygen)
Legacy would have been: <keygen name="pubkey"> — ignored today.

Demo only — form does not upload or generate keys.

HTML Examples

Legacy snippets are for study. Prefer forms without <keygen> for real pages.

Example 1 — Basic keygen in a Form

Historical minimum: a named keygen control inside a form. Modern browsers do not generate keys.

HTML
<!-- Obsolete — do not use -->
<form action="/enroll" method="post">
  <label for="user">Username:</label>
  <input type="text" id="user" name="user">
  <keygen name="pubkey">
  <button type="submit">Enroll</button>
</form>
Try It Yourself

How It Works

  1. Place <keygen> in a form so it participates in submit (historically).
  2. Set name for the public-key field in the form data.
  3. Old browsers generated a key pair and submitted the public key.
  4. Today: the control does nothing useful — remove it and redesign enrollment.

Example 2 — challenge and keytype

Extra legacy attributes that traveled with the public key.

HTML
<!-- Obsolete — learning only -->
<form action="/enroll" method="post">
  <keygen
    name="pubkey"
    challenge="abc123"
    keytype="rsa"
  >
  <button type="submit">Submit</button>
</form>
Try It Yourself

How It Works

  1. challenge was a string the server could verify with the submitted key material.
  2. keytype selected the algorithm (commonly rsa).
  3. name still labeled the field in the form payload.
  4. All three are obsolete with the element — do not ship this markup.

Example 3 — Form Without keygen

HTML side of a safer pattern: a normal form. Key generation belongs outside obsolete tags (e.g. Web Crypto or OS tools).

HTML
<form action="/enroll" method="post" enctype="multipart/form-data">
  <label for="user">Username:</label>
  <input type="text" id="user" name="user" required>

  <label for="cert">Certificate file:</label>
  <input type="file" id="cert" name="cert" accept=".pem,.crt,.cer">

  <button type="submit">Continue</button>
</form>
Try It Yourself

How It Works

  1. Drop <keygen> entirely from the form.
  2. Collect normal fields with labeled <input> controls.
  3. Optionally accept a file if your flow imports a certificate the user already has.
  4. Generate keys elsewhere (Web Crypto / OS / MDM) — not with an HTML tag.

Edge Cases & Pitfalls

Most problems with <keygen> today are assuming it still enrolls certificates.

obsolete

Never ship in new HTML

Validators flag it. Replace enrollment with Web Crypto or platform certificate tools.

security

Inconsistent and removed

Browser support was uneven; Chrome emptied then removed the control. Do not rebuild on it.

html

No HTML successor tag

Unlike isindex → form+input, keygen has no drop-in HTML element. Use APIs/tools instead.

forms

Leaving keygen in a form is useless

It will not submit a public key in modern browsers. Audit old enrollment pages and remove the tag.

attrs

challenge / keytype died with the element

Those attributes are not general HTML form attributes — they only made sense on keygen.

Browser Support

The <keygen> element is obsolete. It is non-conforming for authors in the HTML Living Standard. Chrome removed it around version 57; other modern engines do not provide a useful keygen UI.

✓ Obsolete · Not supported

<keygen>

No useful key-pair form control in modern Chrome, Firefox, Safari, Edge, or Opera.

0% Modern keygen support
Google Chrome Removed (~57+)
Not supported
Mozilla Firefox No useful UI
Not supported
Apple Safari No useful UI
Not supported
Microsoft Edge No useful UI
Not supported
Opera Removed with Chromium
Not supported
Internet Explorer Never / EOL
Not supported
<keygen> Not supported

Bottom line: Learn <keygen> for history and audits only. Build enrollment with Web Crypto or platform certificate tooling — not HTML keygen.

Key Takeaways

  • Role: <keygen> once generated key pairs inside HTML forms.
  • Attrs: legacy name, challenge, keytype (plus form control attrs).
  • Status: obsolete — do not use in new documents.
  • Replace with: Web Crypto / OS certificate tools — not another HTML tag.

One line: <keygen> is web history — learn it to remove it, not to build new enrollment.

Default CSS Settings

Modern browsers do not expose a meaningful keygen control. There is no reliable user-agent stylesheet to depend on:

default.css
/* Conceptual only — do not rely on keygen styling */
keygen {
  display: none;
}

Style ordinary <form> / <input> controls instead.

Frequently Asked Questions

keygen was a form control that generated a public/private key pair in the browser. On submit, the public key (and challenge) were sent to the server while the private key stayed local — mainly for certificate enrollment.
No. It is obsolete and non-conforming for authors. The WHATWG HTML Standard tells authors not to use it.
For certificate enrollment, use the Web Cryptography API to generate a key pair, then export materials for the user to install. For enterprise device management, use native on-device management — not an HTML tag.
challenge was a string submitted with the public key. keytype selected the key algorithm (historically rsa). Both are obsolete with the element.
No. Chrome removed it (around Chrome 57). Current Firefox, Safari, and Edge do not provide a useful keygen control. Do not depend on it.
No. Learn it only to recognize legacy markup. Never add it to new forms.

Next: label

Associate captions with form controls using the label element.

label tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful