Description

HTML element <keygen> is used to generate an encryption key for passing encrypted form data to a server.

When an HTML form is submitted, it makes the browser generate a public and private key pair, where the public key is sent to the server along with the form data, and the private key is stored in the browser's local key storage.

The below table summarizes its usage.

Usage Details
Placement It is displayed as an Inline element.
Contents None. It is an empty element.
Tags Only an opening tag is required.
Versions HTML5

Syntax

Here is the basic syntax of the <keygen> element.

<keygen>

Examples

In the below example, the <keygen> element is used to define the text that the user is supposed to enter using a keyboard.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>HTML Element - keygen</title>
</head>
<body>
    <form action="https://example.com/post" method="post">
        <label>Username: <input type="text" name="username"></label>
        <label>Encryption: <keygen name="key"></label>
        <input type="submit" value="Submit">
    </form>
</body>
</html>

Attributes

The following table shows the list of supported and unsupported attributes for the <keygen> element.

Attribute Type Details
Element-Specific Attributes The tags <keygen> has some element-specific attributes listed in the below table.
Global Attributes Like all other HTML tags, the tag <keygen> supports the HTML Global Attributes.
Event Attributes The tags <keygen> also supports the HTML Event Attributes.

Here is a list of attributes that are specific to the <keygen> element.

Attribute Value Description
autofocus autofocus This is a boolean attribute.
Specifies that a keygen element should automatically get focused when the page loads.
challenge challenge Specifies a challenge string that is submitted along with the public key. The default value is an empty string, if not specified.
disabled disabled This is a boolean attribute.
It indicates that the keygen form control is disabled for interaction.
form form-id Specifies the <form> element that the <keygen> element is associated with (its form owner).
keytype rsa
dsa
ec
Specifies the type of key generated. The default value is rsa.
name name Defines a name for the keygen element, which is submitted with the form data.

Browser Compatibility

The tags <keygen> is supported in all modern browsers.

  • Google Chrome 1+
  • Internet Explorer or Edge x
  • Firefox 1+
  • Apple Safari 1.2+
  • Opera 3+

Related Links