Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

A button that appears on a toolbar. It is equivalent to a regular button except that it may be rendered differently. Typically, it is expected to have an image.

More information is available in the XUL tutorial.

Relevant accessbility guidelines
  • All toolbar functionality should be duplicated elsewhere in the application
    • Where possible, provide keyboard alternatives.
    • Where possible, duplicate functionality in a menu item or context menu.
    • Where not possible, make all toolbarbuttons focusable by -moz-user-focus: normal.
Attributes
accesskey, autocheck, checkState, checked, command, crop, dir, disabled, dlgtype, group, image, label, oncommand, open, orient, tabindex, title, type, validate
Properties
accessKey, accessibleType, autoCheck, checkState, checked, command, crop, dir, disabled, dlgType, group, image, label, open, orient, tabIndex, type

Examples

Image:XUL_ref_toolbarbutton.png
<toolbar id="test-toolbar">
  <toolbarbutton accesskey="P" label="Plain"/>
  <toolbarbutton accesskey="C" label="Checkbox" type="checkbox"/>
  <toolbarbutton accesskey="b" label="Menu-button" type="menu-button">
    <menupopup>
      <menuitem label="Menu item 1"/>
      <menuitem label="Menu item 2"/>
    </menupopup>
  </toolbarbutton>
  <toolbarbutton accesskey="M" label="Menu" type="menu">
    <menupopup>
      <menuitem label="Menu item 1"/>
      <menuitem label="Menu item 2"/>
    </menupopup>
  </toolbarbutton>
</toolbar>
<toolbar id="radio-toolbar">
  <toolbarbutton accesskey="1" label="Radio 1" type="radio" group="RadioGroup"/>
  <toolbarbutton accesskey="2" label="Radio 2" type="radio" group="RadioGroup"/>
  <toolbarbutton accesskey="3" label="Radio 3" type="radio" group="RadioGroup"/>
</toolbar>

Attributes

accesskey
Type: character
This should be set to a character that is used as a shortcut key. This should be one of the characters that appears in the label attribute for the element.

 

autocheck
Type: boolean
If this attribute is true or left out, the checked state of the button will be switched each time the button is pressed. If this attribute is false, the checked state must be adjusted manually. When autocheck is true, the button type should be "checkbox" or "radio".
checkState
Type: integer, values 0, 1, or 2
This attribute may be used to create three state buttons, numbered 0, 1 and 2. When in state 0 or 1, pressing the button will switch to the opposite state. When in state 2, pressing the button will switch to state 0. This means that the button acts like a checkbox except that there is a third state which must be set manually by adjusting the check state. If you wish to have different behavior for how the states are adjusted, set the autoCheck attribute to false and adjust the state with a script. The type attribute must be set to checkbox for buttons with a check state. Constants for the possible values for this attribute are in the nsIDOMXULButtonElement interface.
checked
Type: boolean
Indicates whether the element is checked or not.
Use hasAttribute() to determine whether this attribute is set instead of getAttribute().
For buttons, the type attribute must be set to checkbox or radio for this attribute to have any effect.
command
Type: id
Set to the id of a command element that is being observed by the element.
crop
Type: one of the values below
If the label of the element is too big to fit in its given space, the text will be cropped on the side specified by the crop attribute. An ellipsis will be used in place of the cropped text. If the box direction is reversed, the cropping is reversed.
start
The text will be cropped on its left side in left-to-right text locales, and the right side in right-to-left locales.
end
The text will be cropped on its right side in left-to-right text locales, and the right side in right-to-left locales.
left
The text will be cropped on its left side.
right
The text will be cropped on its right side.
center
The text will be cropped in the middle, showing both the start and end of the text normally.
none
The text will be not be cropped using an ellipsis. However, the text will simply be cut off if it is too large. The side depends on the CSS text alignment.
Depending on the platform and theme being used, some elements will have set a maximum width so they will always appear cropped. If you wish to use the value none 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; }
dir
Type: one of the values below
The direction in which the child elements of the element are placed.
normal
For scales, the scale's values are ordered from left to right (for horizontal scales) or from top to bottom (for vertical scales)  For other elements, the elements are placed left to right or top to bottom in the order they appear in the XUL code.
reverse
For scales, the scale's values are ordered from right to left (for horizontal scales) or from bottom to top (for vertical scales). For other elements, they are placed right to left or bottom to top. This is reverse of the order in which they appear in the XUL code.
disabled
Type: boolean
Indicates whether the element is disabled or not. If this attribute is set to 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.
Visible controls have a disabled property which, except for menus and menuitems, is normally preferred to use of the attribute, as it may need to update additional state.
dlgtype
Type: one of the values below
The dialog type of the button, used only when the button is in a dialog box. You can use this feature to replace the standard dialog box buttons with custom buttons, yet the dialog event methods will still function. For example, if the dlgType is set to accept, the button will replace the dialog box's accept button, which is usually labeled OK. Using this attribute on a button that is not in a dialog box has no effect. The following values can be used as the dialog type:
accept
The OK button, which will accept the changes when pressed.
cancel
The cancel button which will cancel the operation.
help
A help button for displaying help about the dialog.
disclosure
A button to show more information. This might be a button or a disclosure triangle.
extra1
An optional additional button.
extra2
A second optional additional button.
group
Type: string group name
Buttons with type="radio" and the same value for their group attribute are put into the same group. Only one button from each group can be checked at a time. If the user selects one the buttons, the others in the group are unchecked.
image
Type: URI
The URI of the image to appear on the element. If this attribute is empty or left out, no image appears. The position of the image is determined by the dir and orient attributes.
label
Type: string
The label that will appear on the element. If this is left out, no text appears. For an editable menuitem element the value of this attribute is copied to the menulist.value property upon user selection of the menuitem.

 

oncommand
Type: script code
This event handler is called when the command is activated. This occurs when a user selects a menu item or presses a keyboard shortcut attached to the command.
open
Type: boolean
For the menu type buttons, the open attribute is set to true when the menu is open. The open attribute is not present if the menu is closed.

 

orient
Type: one of the values below
Used to specify whether the children of the element are oriented horizontally or vertically. The default value depends on the element. You can also use the -moz-box-orient style property.
horizontal
Child elements of the element are placed next to each other in a row in the order that they appear in the XUL source.
vertical
Child elements of the element are placed under each other in a column in the order that they appear in the XUL source.
tabindex
Type: integer
The tab order of the element. The tab order is the order in which the focus is moved when the user presses the "tab" key. Elements with a higher tabindex are later in the tab sequence.
title
Type: string
This functionality only applies when toolbarbutton is used in the Customize Toolbar dialog. The text that is displayed as a button's label when it's in the Customize Toolbar palette.  It overrides the value of label, which is used if title is not set.  This does not affect the button's label when it is in a toolbar, which remains determined by the label attribute.
type
Type: string
The type of button. If this attribute is not present, a normal button is created. You can set this attribute to the value menu to create a button with a menu popup. This will typically cause the button to be displayed differently.
  • menu: Set the type attribute to the value menu to create a button with a menu popup. Place a menupopup element inside the button in this case. The user may click anywhere on the button to open and close the menu.
  • menu-button: You can also use the value menu-button to create a button with a menu. Unlike the menu type, this type requires the user to press the arrow to open the menu, but a different command may be invoked when the main part of the button is pressed.
  • checkbox: Use this type to create a toggle button which will switch the checked state each time the button is pressed.
  • radio: Use this type to create a radio button. You can also create a group of toolbarbuttons using this type and the attribute group.
Examples:
type value <toolbarbutton >
  Toolbarbutton without a type attribute
menu Toolbarbutton with type attribute equals "menu"
menu-button Toolbarbutton with type attribute equals "menu-button"
checkbox Toolbarbutton with type attribute equals "checkbox"
radio Toolbarbutton with type attribute equals "radio"
validate
Type: one of the values below
This attribute indicates whether to load the image from the cache or not. This would be useful if the images are stored remotely or you plan on swapping the image frequently. The following values are accepted, or leave out the attribute entirely for default handling:
always
The image is always checked to see whether it should be reloaded.
never
The image will be loaded from the cache if possible.

Properties

accessKey
Type: character
Gets and sets the value of the accesskey attribute.
accessibleType
Type: integer
A value indicating the type of accessibility object for the element.
autoCheck
Type: boolean
Gets and sets the value of the autoCheck attribute.
checkState
Type: integer, values 0, 1, or 2
Gets and sets the value of the checkState attribute.
checked
Type: boolean
Gets and sets the value of the checked attribute.
command
Type: element id
Gets and sets the value of the command attribute.
crop
Type: string
Gets and sets the value of the crop attribute.
dir
Type: string
Gets and sets the value of the dir attribute.
disabled
Type: boolean
Gets and sets the value of the disabled attribute.
dlgType
Type: string
Gets and sets the value of the dlgType attribute.
group
Type: string group name
Gets and sets the value of the group attribute.
image
Type: image URL
Gets and sets the value of the image attribute.
label
Type: string
Gets and sets the value of the label attribute.
open
Type: boolean
Gets and sets the value of the open attribute.
orient
Type: string
Gets and sets the value of the orient attribute.
tabIndex
Type: integer
Gets and sets the value of the tabindex attribute.
type
Type: string
Gets and sets the value of the type attribute.

Methods

Inherited Methods
addEventListener(), appendChild(), blur, click, cloneNode(), compareDocumentPosition, dispatchEvent(), doCommand, focus, getAttribute(), getAttributeNode(), getAttributeNodeNS(), getAttributeNS(), getBoundingClientRect(), getClientRects(), getElementsByAttribute, getElementsByAttributeNS, getElementsByClassName(), getElementsByTagName(), getElementsByTagNameNS(), getFeature, getUserData, hasAttribute(), hasAttributeNS(), hasAttributes(), hasChildNodes(), insertBefore(), isDefaultNamespace(), isEqualNode, isSameNode, isSupported(), lookupNamespaceURI, lookupPrefix, normalize(), querySelector(), querySelectorAll(), removeAttribute(), removeAttributeNode(), removeAttributeNS(), removeChild(), removeEventListener(), replaceChild(), setAttribute(), setAttributeNode(), setAttributeNodeNS(), setAttributeNS(), setUserData

Elements
toolbar, toolbargrippy, toolbaritem, toolbarpalette, toolbarseparator, toolbarset, toolbarspacer, toolbarspring, toolbox
Interfaces
nsIAccessibleProvider, nsIDOMXULButtonElement

Document Tags and Contributors

 Last updated by: Sheppy,