HTML <legend> tagS2C Home   « HTML <legend> tag

Definition

The <legend> tag is used for defining a title or explanation for parent of the <legend> tag which can be a <details>, <fieldset> or <figure> element.

Example


<form action="../../htmladvanced/simpleform.html" method="get">
  <fieldset>
    <legend>Pie Survey</legend>
  <p>Name:<input type="text" name="name"></p>
  <p>Which pie do you prefer?:</p>
  <p><input type="radio" name="pie" checked="checked" value="chicken"> Chicken</p>
  <p><input type="radio" name="pie" value="fish"> Fish</p>
  <p><input type="radio" name="pie" value="shepherds"> Shepherds</p>
    <p>Select a pie shape:</p>
    <p><select name="shape">
      <optgroup label="Normal">
        <option value="round">round</option>
        <option value="square">square</option>
      </optgroup>
      <optgroup label="Custom">
        <option value="hexagon">hexagon</option>
        <option value="star">star</option>
        <option value="triangle">triangle</option>
      </optgroup>
    </select></p>
  <p>Submit your information:</p>
  <p><input type="submit" value="Submit"></p>
  </fieldset>
</form>
Pie Survey

Name:

Which pie do you prefer?:

Chicken

Fish

Shepherds

Select a pie shape:

Submit your information:

Attributes

The following attributes can be used with the <legend> tag.


<legend> Specific Attributes
Attribute Value Description Example
There are no required or optional attributes specific to the <legend> tag.
<legend> Global Attributes
Attribute Description Example
Common
classSpecifies a classname for the element allowing you to apply the style of the predefined class to the content.

<legend class="name">Legend text</legend>
idSpecifies a unique id for the element allowing you to apply the style of the predefined id to the content.

<legend id="name">Legend text</legend>
styleSpecifies an inline style for the element allowing you to apply the style to the contentt.

<legend style="color:red;">Legend text</legend>
titleSpecifies an inline style for the element allowing you to apply the style to the content.

<legend title="Content info">Legend text</legend>
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<legend accesskey="a">Legend text</legend>
tabindexSpecifies a tab order for the element.

<legend tabindex="1">Legend text</legend>
Language
dirSpecifies the directional flow of the content.

<!-- The text will flow from left to right -->
<legend dir="ltr">Legend text</legend>
<!-- The text will flow from right to left -->
<legend dir="rtl">Legend text</legend>
langSpecifies a language code for the content of the element.

<legend lang="en">Legend text</legend>
spellcheckSpecifies an inline style for the element allowing you to apply the style to the contentt.

<!-- Valid values true and false. -->
<!-- Default inherited / browser specific. -->
<legend spellcheck="true">Legend text</legend> 
translateSpecifies an inline style for the element allowing you to apply the style to the content.

<!-- Valid values yes and no. -->
<!-- Default yes. -->
<legend translate="no">Legend text</legend> 
Miscellaneous
contenteditableSpecifies whether the content of the element is editable.

<!-- Valid values true and false. -->
<!-- Default inherited. -->
<legend contenteditable="true">Legend text</legend> 
draggableSpecifies whether the element is draggable.

<!-- Valid values true and false. -->
<!-- Default browser specific. -->
<legend draggable="true">Legend text</legend>
hiddenSpecifies whether the element is not yet, or no longer, relevant.

<!-- Valid values an empty string or hidden -->
<legend hidden>Legend text</legend> 
<legend hidden="hidden">Legend text</legend> 
<legend> Event Attributes
Attribute Description Example
Document Element
oncopyThe script to be run when the user copies the content of an element.

 <!-- Executes go() function -->
<legend oncopy="go()">Legend text</legend> 
oncutThe script to be run when the user cuts the content of an element.

 <!-- Executes go() function -->
<legend oncut="go()">Legend text</legend>
onpasteThe script to be run when the user pastes some content into an element.

 <!-- Executes go() function -->
<legend onpaste="go()">Legend text</legend>
Drag and Drop
ondragThe script to be run when an element is dragged.

 <!-- Executes go() function -->
<legend ondrag="go()">Legend text</legend>
ondragendThe script to be run when an element has stopped being dragged.

 <!-- Executes go() function -->
<legend ondragend="go()">Legend text</legend>
ondragenterThe script to be run when an element has been dragged to a valid drop target.

 <!-- Executes go() function -->
<legend ondragenter="go()">Legend text</legend>
ondragleaveThe script to be run when an element leaves a valid drop target.

 <!-- Executes go() function -->
<legend ondragleave="go()">Legend text</legend>
ondragoverThe script to be run when an element is being dragged over a valid drop target.

 <!-- Executes go() function -->
<legend ondragover="go()">Legend text</legend>
ondragstartThe script to be run at the start of a drag operation.

 <!-- Executes go() function -->
<legend ondragstart="go()">Legend text</legend>
ondropThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<legend ondrop="go()">Legend text</legend>
Form
onblurThe script to be run when the element loses focus.

 <!-- Executes go() function -->
<legend onblur="go()">Legend text</legend>
onchangeThe script to be run when object changed and attempt to leave field.

 <!-- Executes go() function -->
<legend onchange="go()">Legend text</legend>
oncontextmenuThe script to be run when a context menu is triggered.

 <!-- Executes go() function -->
<legend oncontextmenu="go()">Legend text</legend>
onfocusThe script to be run when the element gets focus.

 <!-- Executes go() function -->
<legend onfocus="go()">Legend text</legend>
oninputThe script to be run when an element gets user input.

 <!-- Executes go() function -->
<legend oninput="go()">Legend text</legend>
oninvalidThe script to be run when an element is invalid.

 <!-- Executes go() function -->
<legend oninvalid="go()">Legend text</legend>
onresetThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<legend onreset="go()">Legend text</legend>
onselectThe script to be run when some or all of the contents of an object are selected.

 <!-- Executes go() function -->
<legend onselect="go()">Legend text</legend>
onsubmitThe script to be run when a form is submitted.

 <!-- Executes go() function -->
<legend onsubmit="go()">Legend text</legend>
Keyboard
onkeydownThe script to be run when an element is in focus and keyboard key is pressed down.

 <!-- Executes go() function -->
<legend onkeydown="go()">Legend text</legend>
onkeypressThe script to be run when an element is in focus and keyboard key is pressed down and released.

 <!-- Executes go() function -->
<legend onkeypress="go()">Legend text</legend>
onkeyupThe script to be run when an element is in focus and keyboard key is released.

 <!-- Executes go() function -->
<legend onkeyup="go()">Legend text</legend>
Media
onabortThe script code to be run on abort.

 <!-- Executes go() function -->
<legend onabort="go()">Legend text</legend>
oncanplayThe script to be run when a file has buffered enough so it is ready to start playing.

 <!-- Executes go() function -->
<legend oncanplay="go()">Legend text</legend>
oncanplaythroughThe script to be run when a file can be played all the way to the end without further need of buffering.

 <!-- Executes go() function -->
<legend oncanplaythrough="go()">Legend text</legend>
oncuechangeThe script to be run when the cue changes when using the track element.

 <!-- Executes go() function -->
<legend oncuechange="go()">Legend text</legend>
ondurationchangeThe script to be run when the length of the media is changed.

 <!-- Executes go() function -->
<legend ondurationchange="go()">Legend text</legend>
onemptiedThe script to be run when a media resource element suddenly becomes empty, usually due to an error.

 <!-- Executes go() function -->
<legend onemptied="go()">Legend text</legend>
onendedThe script to be run when the media has reach the end.

 <!-- Executes go() function -->
<legend onended="go()">Legend text</legend>
onloadeddataThe script to be run when media data is loaded and playback can start.

 <!-- Executes go() function -->
<legend onloadeddata="go()">Legend text</legend>
onloadedmetadataThe script to be run when metadata has been loaded.

 <!-- Executes go() function -->
<legend onloadedmetadata="go()">Legend text</legend>
onloadstartThe script to be run whenthe media resource has started loading.

 <!-- Executes go() function -->
<legend onloadstart="go()">Legend text</legend>
onpauseThe script to be run when the media resource has been paused.

 <!-- Executes go() function -->
<legend onpause="go()">Legend text</legend>
onplayThe script to be run when the media resource starts playback.

 <!-- Executes go() function -->
<legend onplay="go()">Legend text</legend>
onplayingThe script to be run when when playback has already begun.

 <!-- Executes go() function -->
<legend onplaying="go()">Legend text</legend>
onprogressThe script to be run when the browser is fetching the media data.

 <!-- Executes go() function -->
<legend onprogress="go()">Legend text</legend>
onratechangeThe script to be run when the playback rate changes.

 <!-- Executes go() function -->
<legend onratechange="go()">Legend text</legend>
onseekedThe script to be run when the seeking attribute is set to false indicating that seeking has finished.

 <!-- Executes go() function -->
<legend onseeked="go()">Legend text</legend>
onseekingThe script to be run when the seeking attribute is set to true indicating that seeking is currently active.

 <!-- Executes go() function -->
<legend onseeking="go()">Legend text</legend>
onstalledThe script to be run when the browser is unable to continue fetching media data.

 <!-- Executes go() function -->
<legend onstalled="go()">Legend text</legend>
onsuspendThe script to be run when media data has stopped before being completely loaded.

 <!-- Executes go() function -->
<legend onsuspend="go()">Legend text</legend>
ontimeupdateThe script to be run when the media resources current playback position has changed.

 <!-- Executes go() function -->
<legend ontimeupdate="go()">Legend text</legend>
onvolumechangeThe script to be run when the volume has changed or been muted.

 <!-- Executes go() function -->
<legend onvolumechange="go()">Legend text</legend>
onwaitingThe script to be run when the media resource has paused but is expected to resume.

 <!-- Executes go() function -->
<legend onwaiting="go()">Legend text</legend>
Mouse
onclickThe script to be run when when a mouse is clicked on an element.

 <!-- Executes go() function -->
<legend onclick="go()">Legend text</legend>
ondblclickThe script to be run when a mouse is double clicked on an element.

 <!-- Executes go() function -->
<legend ondblclick="go()">Legend text</legend>
onmousedownThe script to be run when he mouse button is pressed down while the cursor is over an element.

 <!-- Executes go() function -->
<legend onmousedown="go()">Legend text</legend>
onmousemoveThe script to be run when the mouse button is moved.

 <!-- Executes go() function -->
<legend onmousemove="go()">Legend text</legend>
onmouseoutThe script to be run when the mouse cursor moves off an element.

 <!-- Executes go() function -->
<legend onmouseout="go()">Legend text</legend>
onmouseoverThe script to be run when the mouse cursor moves over an element.

 <!-- Executes go() function -->
<legend onmouseover="go()">Legend text</legend>
onmouseupThe script to be run when the mouse button is released while the cursor is over the element.

 <!-- Executes go() function -->
<legend onmouseup="go()">Legend text</legend>
onwheelThe script to be run when the mouse wheel rolls up or down over an element.

 <!-- Executes go() function -->
<legend onwheel="go()">Legend text</legend>
Scroll
onscrollThe script code to be run when the scrollbar of an element is being scrolled.

 <!-- Executes go() function -->
<legend onscroll="go()">Legend text</legend> 
Window - NONE

Relevant HTML Tutorials

HTML Advanced - Advanced Forms