Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

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

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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 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.


<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> element. The autofocus attribute is a boolean attribute and when this attribute present, it specifies the <keygen> an element that should automatically get focused when the page loads.


<keygen autofocus>


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


My Personal Notes arrow_drop_up
Last Updated : 08 Apr, 2021
Like Article
Save Article
Similar Reads
Related Tutorials