How to use the legend element in HTML
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.
Syntax
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
alignattribute is obsolete in HTML5 but can be used with style sheets.
The <legend> element supports global events and attributes.
Examples
The following examples demonstrate how to use the <legend> element in HTML:
Explanation
- 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.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved