Summary -

In this topic, we described about the <keygen> tag along with detailed example.

The <keygen> element is new in HTML5. Generating a key pair. The <keygen> tag is used for generating a key pair used for forms.

<keygen> tag can be used mostly along with Web-based certificate management systems. When the form is submitted, the private key stored locally and public key sent to server. The tag can be specified like <keygen name=""> with a name in between the quotes of the name attribute.

<keygen> has no data, so end tag not required. <keygen> is not a nested tag.

Syntax -

<keygen>.... HTML text here </keygen>

Optional Attributes -

AttributeDescriptionValues
autofocusSpecifies the keygen element should get autofocus on page loadNone.
challengeSpecifies the <keygen> element value should be challenged.Text.
disabledSpecifies that the form control should be diasabledNone.
formSpecifies the <keygen> belonging form idForm_id
keytypeSpecifies the key security algorithmRsa (default)Dsaec
nameSpecifies form control name.Text

Example -

<!DOCTYPE html>
<html>
	<head>
		<title>Form example</title>
	</head>
	<body>
		<form action="search-results.htm">
			<label>Search: </label>
			<input type="text" name="search" >
			<label>Encryption: </label> <keygen name="security">
			<input type="submit" value="Submit">
		</form>
	</body>
</html>

Output -