Open In App
Related Articles

How to specify one or more forms the keygen element belongs to ?

Improve Article
Improve
Save Article
Save
Like Article
Like

The task is to specify one or more forms the keygen element belongs to. You can easily do this by using the form attribute which is an attribute of keygen element. form element is used to create an HTML form for user input. keygen element is used to specify a key-pair generator field in a form and used to provide a secure way to authenticate users. It is not supported in Internet Explorer. form attribute is used to specify one or more forms the <keygen> element belongs to.

Approach:

  • Create the HTML page with a form element with a specific id name.
  • Create a keygen element with the form_id.

Example:

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>
        Form Attribute
    </title>
    <style>
        body {
            text-align: center;
            background-color: lightgreen;
            font-size: 25px;
        }
          
        button {
            background-color: #4CAF50;
            /* Green */
            border: none;
            color: white;
            padding: 5px 32px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
        }
    </style>
</head>
  
<body>
    <h1 style="color:green">GeeksForGeeks</h1>
  
    <form id="form1">
        Name: <input type="text" name="usr_name">
        <button>Submit</button>
    </form>
  
    <p>
       The keygen field below is outside the form element,
       but still part of the form.
   </p>
  
    Encryption: <keygen name="security" form="form1">
  
  
</body>
</html>


Output: The keygen element is a part of the form, but it was created outside the form element.


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 16 Apr, 2021
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials