HTML5 <legend> Tag

The HTML <legend> tag is used to represent a caption for the content of its parent <fieldset>.

The only content permitted inside this element is Phrasing content. Both the starting and ending tag are mandatory for this element. The parent of the <legend> tag can only be a <fieldset> whose first child is this <legend> element.

The following style is applied to this element by default:

legend {
  display: block;
  padding-start: 2px;
  padding-end: 2px;
  border: none; 
}

Here is an example of using this tag:

<fieldset>
  <legend>Family</legend>
  <input type="checkbox" id="checkbox">
  <label for="checkbox">Yes, I am married.</label>
</fieldset>

Attributes

This element only accepts global attributes.

Examples

See the Pen HTML legend Tag by Tutorialio (@tutorialio) on CodePen.

Further Reading

  1. Read more about the HTML <legend> element on MDN.
  2. You can also read the HTML <legend> tag reference on W3C.

Reader Comments

1. You can register or login to post a comment. Asking readers to register improves the quality of discussion.

2. As a registered user, you will also get to access features like choosing between a light and dark theme or anything else that we might implement in future.

Follow Us For Updates

FacebookTwitterGoogle+
Go To Top