• Post category:HTML

What is the Use of Legend Tag in HTML | Explained

 Legend Tag in HTML

In this article, we will see about what is the use of legend tag in HTML. We use the <fieldset> tag to group a set of fields and the <legend> tag to give it a title.

Example :

<!DOCTYPE html>
         width: 50%;
         label {
            display: inline-block;
            float: left;
            clear: left;
            width: 90px;
            text-align: left;
         input[type="text"] {
            margin:5px 0px;
      <h2>HTML Legend Tag</h2>
            <!-- Legend tag using -->
            <legend>LOG IN FORM</legend>
            <input type="text">
            <input type="text">
            <input type="text">


legend tag in html


  • In the above code, we have created the sample form using HTML <form> tag and inside it, we have the <fieldset> tag.
  • Then we created some details like name, email, password, etc using <label> and <input> tags.
  • In CSS, we have styled the label and input tag
  • If we create the title or caption of the field set, we need to use HTML <legend> tag as in the above example code.
  • See the above output, our Filedset caption/title is displayed successfully.

If we used the legend tag, it will make the professional look to your forms. This is introduced in HTML 5. This tag is used to add headlines or separate parts of our HTML form. Instead of Creating headings using <h1> tag, we can create that using <legend> tag easily. Because it gives very unique to our fieldset.

Leave a Reply