Table of contents
- 1. Examples
- 2. Attributes
- 3. Properties
- 4. Methods
- 5. Style classes
- 6. Related
- 7. Notes
This element is used to provide a label for a control element. If the user clicks the label, it will move the focus to the associated control, specified with the control attribute.
More information is available in the XUL tutorial.
Examples

<label value="Email address" control="email"/> <textbox id="email"/>
Attributes
Inherited from XUL element
align
, allowevents
, allownegativeassertions
, class
, coalesceduplicatearcs
, collapsed
, container
, containment
, context
,
, datasources
, dir
, empty
, equalsize
, flags
, flex
, height
,
, id
, insertafter
, insertbefore
, left
, maxheight
, maxwidth
,
, minheight
, minwidth
, mousethrough
, noinitialfocus
, observes
, ordinal
, orient
, pack
, persist
, popup
, position
, preference-editable
, querytype
, ref
, removeelement
, sortDirection
, sortResource
, sortResource2
, statustext
, style
, template
, tooltip
, tooltiptext
, top
, uri
, wait-cursor
, width
crop
crop attribute. An ellipsis will be used in place of the cropped text. If the box direction is reversed, the cropping is reversed.startendleftrightcenternonenone and the displayed text is larger than this maximum width, you may be able to use the max-width CSS property (or the maxwidth attribute) to override this size. For example, for a menuitem in a menu you can add the following CSS rule when you want to use the value none:
menupopup > menuitem, menupopup > menu { max-width: none; }
disabled
true the element is disabled. Disabled elements are usually drawn with grayed-out text. If the element is disabled, it does not respond to user actions, it cannot be focused, and the command event will not fire.
disabled
property which, except for menus and menuitems, is normally preferred to use of the attribute, as it may need to update additional state.
value
Properties
Inherited Properties
align
,
attributes, allowEvents
,
baseURI, boxObject
, builder
,
childElementCount,
childNodes,
children, className
,
clientHeight,
clientLeft,
clientTop,
clientWidth, collapsed
, contextMenu
, controllers
, database
, datasources
, dir
,
firstChild,
firstElementChild, flex
, height
, hidden
, id
,
lastChild,
lastElementChild, left
,
localName, maxHeight
, maxWidth
, menu
, minHeight
, minWidth
,
namespaceURI,
nextElementSibling,
nextSibling,
nodeName,
nodeType,
nodeValue, observes
, ordinal
, orient
,
ownerDocument, pack
,
parentNode, persist
,
prefix,
previousElementSibling,
previousSibling, ref
, resource
,
scrollHeight,
scrollLeft,
scrollTop,
scrollWidth, statusText
, style
,
tagName,
textContent, tooltip
, tooltipText
, top
, width
accessibleType
Methods
Style classes
The following classes may be used to style the element. These classes should be used instead of changing the style of the element directly since they will fit more naturally with the user's selected theme.
-
header - A class used for headings. Typically, this will cause the text to appear bold.
-
indent - This class causes the text to be indented on its left side.
-
monospace - This class causes the text to be displayed in a monospace font.
-
plain - This class causes the element to be displayed with no border or margin.
-
small-margin - This class causes the text to be displayed with a smaller margin.
-
text-link - Labels with this class may be focused and the click handler run or the address in the href attribute opened on a mouse click or Enter key press. Labels will appear like a link (blue and underlined).
Related
- Elements
description
- Attributes
label
- Interfaces
nsIAccessibleProvider,nsIDOMXULLabelElement
Notes
Labels are not focusable
Starting in Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)
, labels are properly not focusable. They used to incorrectly inherit from nsIDOMXULControlElement
.
The caption is in the "value" attribute
Remember that the label element has a "value" attribute, unlike value in HTML whereas buttons, checkboxes use label="foo" as the attribute
<label label="A Caption"/> <-- wrong --> <label value="A Caption"/> <label value="Click the button"/> <button label="A Button"/> <checkbox label="A Decision" value="1"/>
Wrapping
By default, label text does not wrap. To enable wrapping, use a text node instead of the value attribute.
<label control="email">Email address</label> <textbox id="email"/>
If the text node contains no tags, it can easily be accessed and manipulated from JavaScript using node.textContent
.
Mozilla Developer Network