Skip to content
Related Articles

Related Articles

Improve Article

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

  • Last Updated : 08 Apr, 2021

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


Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :