Forms & Inputs

HTML <legend> Tag

The <legend> tag defines a caption for the <fieldset> element.

Definition and Usage

The <legend> tag defines a caption for the <fieldset> element.

Standard Syntax:<legend>...</legend>

Interactive ExampleRunnable

HTML <legend> Example

html
Try it Yourself
Live code demonstration for the <legend> tag. Click "Try it Yourself" to edit and experiment in real time.
<div style="font-family: system-ui, sans-serif; padding: 16px; background: #ffffff; border-radius: 8px; border: 1px solid #e2e8f0; color: #0f172a;">
<form action="/action_page.php">
  <fieldset>
    
    <legend>Personalia:</legend>
    <label for="fname">First 
    name:</label>
    <input type="text" id="fname" name="fname"><br><br>
    
    <label for="lname">Last name:</label>
    <input 
    type="text" id="lname" name="lname"><br><br>
    <label 
    for="email">Email:</label>
    <input type="email" 
    id="email" name="email"><br><br>
    <label 
    for="birthday">Birthday:</label>
    <input type="date" 
    id="birthday" name="birthday"><br><br>
    <input 
    type="submit" value="Submit">
  </fieldset>
</form>
</div>

Attributes for <legend>

0 Supported Attributes

The <legend> tag does not have tag-specific attributes. It supports all standard Global Attributes.

Global Attributes

The <legend> tag also supports the standard global attributes in HTML, including class, id, style, title, hidden, and data-*.

HTML Global Attributes Reference →
Event Attributes

The <legend> tag supports event attributes in HTML, such as onclick, onmouseover, onfocus, and more.

HTML Event Attributes Reference →

Browser Compatibility

ChromeEdgeFirefoxSafariOpera

More Tags in Forms & Inputs

View All 123Tags →