HTML XHTML The Complete Reference
home » reference » appendix a » html element reference

<legend> (Field Legend)


This HTML 4 element is used to assign a caption to a set of form fields as defined by the <fieldset> element.

Standard Syntax


<legend
accesskey="character"
align="bottom | left | right | top" (transitional only)
class="class name(s)"
dir="ltr | rtl"
id="unique alphanumeric identifier"
lang="language code"
style="style information"
title="advisory text"
</legend>

Attributes Defined by Internet Explorer


align="center" (4)
contenteditable=" false | true | inherit" (5.5)
disabled="false | true" (5.5)
hidefocus="true | false" (5.5)
language="javascript | jscript | vbs | vbscript" (4)
tabindex="number" (5.5)
unselectable="on | off" (5.5)

Standard Event Attributes


onclick, ondblclick, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup

Events Defined by Internet Explorer


onactivate, onafterupdate, onbeforeactivate, onbeforecopy, onbeforecut, onbeforedeactivate, onbeforeeditfocus, onbeforepaste, onblur, oncontextmenu, oncontrolselect, oncopy, oncut, ondeactivate, onerrorupdate, onfocus, onfocusin, onfocusout, onhelp, onlosecapture, onmouseenter, onmouseleave, onmouseup, onmousewheel, onmove, onmoveend, onmovestart, onpaste, onpropertychange, onreadystatechange, onresize, onresizeend, onresizestart, ontimeerror

Element Specific Attributes


accesskey
This attribute specifies a keyboard navigation accelerator for the element. Pressing ALT or a similar key in association with the specified key selects the form section or the legend itself.

align
This attribute indicates where the legend value should be positioned within the border created by a <fieldset> element. The default position for the legend is the upper-left corner. It also is possible to position the legend to the right by setting the attribute to right. The specification defines bottom and top as well. Microsoft defines the use of center and also defines another attribute, valign, to set the vertical alignment separately. Future support for valign is unclear; page designers are encouraged to use only the align attribute and to eventually rely on style sheets for legend positioning.

Example


<form>
<fieldset>
<legend align="top">
User Information</legend>
First Name: <input type="text" id="firstname"
   size="20"><br>
Last Name: <input type="text" id="lastname"
  size="20"><br>
</fieldset>
</form>

Compatibility


HTML 4, 4.01, XHTML 1.0, 1.1, Basic
Internet Explorer 4, 5, 5.5, 6
Netscape 6, 7
Opera 4-7

Notes


A <legend> tag should occur only within a <fieldset> tag. There should be only one legend per fieldset element.

The <legend> tag improves accessibility when the fieldset is not rendered visually.

Some versions of Microsoft documentation show a valign attribute for <legend> positioning. However, the valign attribute does not appear to work consistently and has since been dropped from the official documentation.

(X)HTML Elements
CSS Properties
Previous: layer Next: li
< Home | About | Chapters | Examples | Errata | Reference | Site Map >