Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


How to use the legend element in HTML

Ayesha Naeem

The <legend> element represents a title or a caption for contents of the <fieldset> element. The content of <legend> is displayed at the top of the frame that contains it.


Attributes and events

The <legend> element accepts align as a single specific attribute.

align accepts one of the following inputs:

  • top: legend is aligned to the top of its container.
  • bottom: legend is aligned to the bottom of its container.
  • left: legend is aligned to the left of its container.
  • right: legend is aligned to the right of its container.

The align attribute is obsolete in HTML5 but can be used with style sheets.

The <legend> element supports global events and attributes.


The following examples demonstrate how to use the <legend> element in HTML:


  • The document creates an HTML form through the <form> element.
  • The <form> element contains a <fieldset> element that represents a single category of information. The category of information in the above example is Contact Information.
  • The <fieldset> element contains multiple types of inputs in the Contact Information category.
  • The <legend> tag indicates the category of information.




Ayesha Naeem
Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring