Open In App

How to set a keygen element that automatically get focused when page loads in HTML5 ?

Last Updated : 06 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The <keygen> tag in HTML is used to specify a key-pair generator field in a form. The purpose of this element is to provide a secure way to authenticate users. When a form is submitted then two keys are generated, private key and public key. The private key is stored locally, and the public key is sent to the server. The public key is used to generate a client certificate to authenticate the user for the future.

Syntax

<keygen name = "anyname">

If we want a keygen element should automatically get focus when the page loads then we can use the autofocus attribute of <keygen> tag. The autofocus attribute is a boolean attribute and when this attribute is present, it specifies the <keygen> an element that should automatically get focused when the page loads.

Syntax:

<keygen autofocus>

Example: In this example, we will use <keygen> tag

HTML




<!DOCTYPE html>
<html>
<body>
    <form action="mypage.php" method="get">
        Username: <input type="text" name="user_name">
        Encryption:
        <keygen name="security" autofocus>
        <input type="submit">
    </form>
</body>
</html>


Output:


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads