This reverts commitec5fa1d4c0. Revert "Bug 1606785 - Format Firefox CSS files with Prettier r=desktop-theme-reviewers,perftest-reviewers,places-reviewers,translations-reviewers,omc-reviewers,backup-reviewers,browser-installer-reviewers,sparky,dao,pdahiya,nrishel,kpatenio" This reverts commitbaa5d72bbd. Revert "Bug 1606785 - Format browser/themes and toolkit/themes CSS files with Prettier r=desktop-theme-reviewers,pip-reviewers,tabbrowser-reviewers,places-reviewers,dao,mconley" This reverts commit9604b0a8ae. Revert "Bug 1606785 - Format browser/themes/preferences CSS files with Prettier r=settings-reviewers,desktop-theme-reviewers,dao,mconley" This reverts commit686c1cf85f. Revert "Bug 1606785 - Format urlbar CSS files with Prettier r=urlbar-reviewers,desktop-theme-reviewers,dao" This reverts commita7a4f31251. Revert "Bug 1606785 - Format webcompat CSS files with Prettier r=webcompat-reviewers,denschub" This reverts commit41bc4d5237. Revert "Bug 1606785 - Format search CSS files with Prettier r=search-reviewers,jteow" This reverts commit7bb7f82374. Revert "Bug 1606785 - Format dom CSS files with Prettier r=emilio" This reverts commitc22e910235. Revert "Bug 1606785 - Format android CSS files with Prettier r=geckoview-reviewers,hiro" This reverts commitc08e43fc3d. Revert "Bug 1606785 - Format layout CSS files with Prettier r=layout-reviewers,dholbert" This reverts commit4f2a32d1a4. Revert "Bug 1606785 - Format devtools CSS files with Prettier r=devtools-reviewers,nchevobbe,frontend-codestyle-reviewers" This reverts commitc05f675ddf. Revert "Bug 1606785 - Format recomp CSS files with Prettier r=reusable-components-reviewers,desktop-theme-reviewers,dao,mkennedy" This reverts commitb10c7de8d0. Revert "Bug 1606785 - Format sidebar CSS files with Prettier r=sidebar-reviewers,desktop-theme-reviewers,dao,nsharpley" This reverts commitd32c555e37. Revert "Bug 1606785 - Format shopping CSS files with Prettier r=shopping-reviewers,desktop-theme-reviewers,dao,rking" This reverts commit965887a708. Revert "Bug 1606785 - Format profiles CSS files with Prettier r=profiles-reviewers,desktop-theme-reviewers,dao,mossop" This reverts commit8338860f74. Revert "Bug 1606785 - Format genai and ml CSS files with Prettier r=firefox-ai-ml-reviewers,Mardak" This reverts commitd66681f553. Revert "Bug 1606785 - Format firefoxview CSS files with Prettier r=fxview-reviewers,desktop-theme-reviewers,dao,jsudiaman" This reverts commit530b815cad. Revert "Bug 1606785 - Format aboutlogins, megalist, and form autofill CSS files with Prettier r=credential-management-reviewers,mtigley,desktop-theme-reviewers,dao" This reverts commit813c864381.
MozButton
moz-button is a reusable, accessible, and customizable button component designed to indicate an available action for the user.
It is a wrapper of the <button> element with built-in support for label and title, as well as icons.
It supports various types (default, primary, destructive, icon, icon ghost, ghost) and sizes (default, small).
<div style={{ display: 'flex', justifyContent: 'center', gap: '1rem', flexWrap: 'wrap' }}>
<moz-button label="Default">"Default"</moz-button>
<moz-button type="primary" label="Primary"></moz-button>
<moz-button type="destructive" label="Destructive"></moz-button>
<moz-button iconsrc="chrome://global/skin/icons/more.svg"
tooltiptext="Icon">
</moz-button>
<moz-button iconsrc="chrome://global/skin/icons/more.svg"
tooltiptext="Icon Ghost" type="ghost">
</moz-button>
<moz-button type="ghost" label="Ghost"></moz-button>
</div>
More information about this component including design, writing, and localization guidelines, as well as design assets, can be found on our Acorn site.
Usage guidelines
When to use
- Confirm an action or make a change.
When not to use
- Don't use buttons in place of links.
- Don't use buttons to navigate in-page or to new pages.
Avoid these common mistakes
- Do not change button types (e.g.,
primarytodestructive) based on hover or interaction. - Do not change button text or labels based on user interaction (e.g. don't change the button text on hover).
- Do not create "Schrödinger’s Buttons," i.e. buttons that only become visible when hovered or focused via keyboard.
Code
The source for moz-button can be found under toolkit/content/widgets/moz-button/
How to use moz-button
Importing the element
Like other custom elements, you should usually be able to rely on moz-button getting lazy loaded at the time of first use.
See this documentation for more information on using design system custom elements.
Setting the type
Default
If you won't explicitly set the type of moz-button, it will be set to default. In this case you will get a regular button, also known as a "Secondary" button.
A regular button may appear beside a primary button, or alone. Use it for secondary actions (e.g., Cancel) or for multiple actions of equal importance.
<moz-button label="Button"></moz-button>
<moz-button label="Button"></moz-button>
Primary
Primary buttons represent the most important action on a page and stand out with distinct styling. To avoid visual clutter, only one primary button should be used per page.
<moz-button type="primary" label="Primary"></moz-button>
<moz-button type="primary" label="Primary"></moz-button>
Destructive
Destructive (Danger) buttons typically appear in dialogs to indicate that the user is about to make a destructive and irreversible action such as deleting or removing a file.
<moz-button type="destructive" label="Destructive"></moz-button>
<moz-button type="destructive" label="Destructive"></moz-button>
Icon
Icon buttons are used for actions that can be easily represented with a symbol instead of text. They are ideal for saving space, simplifying the interface, or providing quick access to common functions like search, settings, or closing a window. However, they should include accessible tooltips to ensure clarity and usability.
There are two ways of providing an icon/image to moz-button:
- You can either specify
type="icon"and provide a background-image for the::part:
<moz-button type="icon" title="I am an icon button" aria-label="I am an icon button"></moz-button>
moz-button::part(button) {
background-image: url("chrome://global/skin/icons/more.svg");
}
- Or you can provide an icon URI via
.iconSrcproperty /iconsrcattribute, in which case settingtype="icon"is redundant:
<moz-button iconsrc="chrome://global/skin/icons/more.svg"
title="I am an icon button"
aria-label="I am an icon button">
</moz-button>
<moz-button iconsrc="chrome://global/skin/icons/more.svg"
title="I am an icon button"
aria-label="I am an icon button">
</moz-button>
You can also use iconsrc together with label to get a button with both icon and text.
<moz-button iconsrc="chrome://global/skin/icons/edit-copy.svg" label="Button"></moz-button>
<moz-button iconsrc="chrome://global/skin/icons/edit-copy.svg" label="Button"></moz-button>
To adjust the icon's position, use the .iconPosition property / iconposition attribute. It accepts two values: start (the default) or end.
<moz-button iconposition="end" iconsrc="chrome://global/skin/icons/edit-copy.svg" label="Button"></moz-button>
<moz-button iconposition="end" iconsrc="chrome://global/skin/icons/edit-copy.svg" label="Button"></moz-button>
To add a badge to the icon button, set .attention boolean property to true or add attention attribute to the markup.
<moz-button iconsrc="chrome://global/skin/icons/more.svg"
title="I am an icon button"
aria-label="I am an icon button"
attention>
</moz-button>
<moz-button iconsrc="chrome://global/skin/icons/more.svg"
title="I am an icon button"
aria-label="I am an icon button"
attention>
</moz-button>
Ghost
Ghost buttons are used for secondary or less prominent actions. They are ideal for optional actions, alternative choices, or when a clean, subtle look is desired.
<moz-button type="ghost" label="I am a ghost button"></moz-button>
<moz-button type="ghost" label="👻 I am a ghost button"></moz-button>
Setting the size
There are 2 options for the moz-button size: default and small. Small buttons are only used for smaller UI surfaces. (e.g., Infobar).
<moz-button label="Default"></moz-button>
<moz-button label="Small" size="small"></moz-button>
<div style={{ display: 'flex', alignItems: 'center', gap: '1rem' }}>
<moz-button label="Default"></moz-button>
<moz-button label="Small" size="small"></moz-button>
</div>
Setting the disabled state
In order to disable the moz-button, add disabled="" or disabled to the markup with no value.
<moz-button label="Button" disabled></moz-button>
<moz-button label="Button" disabled></moz-button>
Setting the accesskey
accesskey defines an keyboard shortcut for the button.
<moz-button label="Button" accesskey="t"></moz-button>
<moz-button label="Button" accesskey="t"></moz-button>
Customizing moz-button
You can add the inner padding on the moz-button to give the button a larger target, and make it clickable when the window and cursor are up against the edge of the screen.
Use the following variables to achieve this:
--button-outer-padding-inline - Used to set the outer inline padding of toolbar style buttons.
--button-outer-padding-block - Used to set the outer block padding of toolbar style buttons.
--button-outer-padding-inline-start - Used to set the outer inline-start padding of toolbar style buttons.
--button-outer-padding-inline-end - Used to set the outer inline-end padding of toolbar style buttons.
--button-outer-padding-block-start - Used to set the outer block-start padding of toolbar style buttons.
--button-outer-padding-block-end - Used to set the outer block-end padding of toolbar style buttons.
Fluent usage
The label, tooltiptext, title, aria-label and accesskey attributes of moz-button will generally be provided via Fluent attributes.
The relevant data-l10n-attrs are set automatically, so to get things working you just need to supply a data-l10n-id as you would with any other element.
For example, the following Fluent messages:
moz-button-ftl-id = This is the visible text content!
moz-button-labelled =
.label = Button
moz-button-titled = Button
.tooltiptext = Button with title
moz-button-titled-2 =
.label = Button
.title = Another button with title
moz-button-aria-labelled =
.aria-label = Button with aria-label
moz-button-with-accesskey = Button
.accesskey = t
would be used to set text and attributes on the different moz-button elements as follows:
<moz-button data-l10n-id="moz-button-ftl-id"></moz-button>
<moz-button data-l10n-id="moz-button-labelled"></moz-button>
<moz-button data-l10n-id="moz-button-titled"></moz-button>
<moz-button data-l10n-id="moz-button-titled-2"></moz-button>
<moz-button data-l10n-id="moz-button-aria-labelled"></moz-button>
<moz-button data-l10n-id="moz-button-with-accesskey"></moz-button>