HTML <legend> Tag

Topic: HTML5 Tags Reference« Prev|Next »

Description

The <legend> tag is used to assign a caption to a set of form controls defined by the <fieldset> element.

The following table summarizes the usages context and the version history of this tag.

Parent: <fieldset>
Placement: Inline
Content: Inline and text
Start/End Tag: Start tag: required, End tag: required
Version: HTML 2, 3.2, 4, 4.01, 5

Syntax

The basic syntax of the <legend> tag is given with:

HTML / XHTML: <legend> ... </legend>

The example below shows the <legend> tag in action.

  • <form action="http://www.example.com/" method="post">
  •     <fieldset>
  •         <legend>Gender</legend>
  •         <input type="radio" name="gender" value="male" id="male">
  •         <label for="male">Male</label>
  •         <input type="radio" name="gender" value="female" id="female">
  •         <label for="female">Female</label>
  •     </fieldset>
  • </form>

Tag-Specific Attributes

The following table shows the attributes that are specific to the <legend> tag.

Attribute Value Description
align top
bottom
left
right
Obsolete Specifies the alignment or position of the caption text with respect to the fieldset.

Global Attributes

Like all other HTML tags, the <legend> tag supports the global attributes in HTML5.


Event Attributes

The <legend> tag also supports the event attributes in HTML5.


Browser Compatibility

The <legend> tag is supported in all major modern browsers.

Browsers Icon

Basic Support—

  • Firefox 1+
  • Google Chrome 1+
  • Internet Explorer 4+
  • Apple Safari 1+
  • Opera 4+

Further Reading

See tutorial on: HTML Forms.

Other form-related tags: <form>, <fieldset>, <label>, <input>, <textarea>, <select>, <optgroup>, <option>, <button>.

 
Close

Your Feedback:

 

We would love to hear from you! Please say something.