You are currently on Anvil1, which is now in maintenance mode. Visit Anvil2 to get the latest version of the design system.
components / Actions and Inputs
Button
Actions and Inputs
Button
Buttons are used to trigger an action for the user. This is the element that users will be interacting with the most and because there are so many uses of buttons, the Button component has a lot of variations we can use. Color, fill, size, and width can all be mixed and matched to get the exact button needed.
Hierarchy
Strict order of buttons is not necessary. Visual hierarchy between Buttons is the important goal.
Primary Actions
As a rule, only a single primary action should be present at a time to draw the user through a flow.
<Buttonprimary>Save Invoice</Button>
Destructive primary actions use a negative color. Clicking this should trigger a confirmation (usually as a Dialog) before proceeding with the action.
<Buttonnegative>Delete Invoice</Button>
Secondary Actions
When multiple actions surface information or start a workflow, the secondary variant can be used. It also pairs well with a primary action.
<Buttonprimaryoutline>Add Contractor</Button>
A negative equivalent also exists. It is used when a destructive action is less prominent, usually paired with other buttons.
<Buttonnegativeoutline>Remove Contractor</Button>
Tertiary Actions
For less pronounced, common actions throughout a page.
<Button>Copy Invoice Number</Button>
An alternative tertiary style also exists. It's used when solid gray is unable to visually work, such as on non-white backgrounds, or pairing with a secondary action.
<Buttonoutline>Copy Invoice Number</Button>
Subtle Actions
On data-heavy UIs, the subtle style can be used in large quantities without adding heavy visuals.
Text-based Subtle Actions
When the button is Text, the blue variant is preferred over gray to preserve the Button's signifier to the user.
<Buttonfill="subtle"primary>Edit</Button>
Icon-based Subtle Actions
For Icons, the gray variant is preferred if the icon is understandable to end users.
Buttons in page headers and footers prompt a user to move through a sequence of screens are right aligned to visually support navigation. The buttons are ordered from right to left by importance.
Centered buttons are used when the content is shown in a small, isolated view. These should be used sparingly and are most commonly within overlay-based components such as Modals.
There are three color variations for buttons. Blues and reds tend to be more prominent in a neutral-dominant UI, while grays allow for deemphasized actions.
There are three fills a button can have. A solid fill is useful for bold and important actions. An outline fill can be used for secondary actions and looks good next to a solid button and stand out on colored backgrounds. A subtle fill is useful for actions that don't need to call a lot of attention to.
We have two separate ways of disabling buttons. A disabled attribute will prevent clicks and change the button to a grey style. An inactive attribute will prevent clicks but keeps the button looking the same. This is useful for preventing stray clicks while an API call is running or showing an outlined-to-active state change.
We support three sizes of buttons that can be set using the size prop. Small buttons are useful for secondary or ancillary actions. Large buttons are great for important call-to-actions and helping unstick a user in a setup flow.
The default width of buttons has a consistent amount of padding between the text and the ends of the button. This can be overridden with the width property, either setting it to a specific size or making the button full width.
Specific sized buttons should only be used when buttons are next to each other or in a column and have variable text lengths. Keeping them the same width will make the buttons feel intentional. Setting a width for every button is not recommended.
Buttons can have an icon to the left or right of the action label.
<ButtonGroup><ButtoniconName="add">Add new item</Button><ButtoniconName="expand_more"iconPosition="right">Menu</Button><Buttonicon={<span>™</span>}iconPosition="right">Custom Icon</Button></ButtonGroup>
Button Icons
When pairing an Icon and an action, an Icon-only Button is used to control the interaction. To add clarity to the action, Button Icons should be paired with Tooltips.
<ButtonGroup><Tooltipel="div"text="Add New Widget"portal><ButtoniconName="add"/></Tooltip><Tooltipel="div"text="Edit Invoice"portal><ButtoniconName="edit"/></Tooltip><Tooltipel="div"text="Check Availability"direction="b"portal><ButtoniconName="event"/></Tooltip><Tooltipel="div"text="More Actions"direction="t"portal><ButtoniconName="more_vert"/></Tooltip></ButtonGroup>
<Stateinitial={5}>{([state, setState])=>(<Form><Stackspacing="1"><Tooltipel="div"text="Remove Widgets"><ButtononClick={()=>setState(state -1)}iconName="remove"/></Tooltip><Inputstyle={{width:'50px'}}value={state}/><Tooltipel="div"text="Add More Widgets"direction="t"><ButtononClick={()=>setState(state +1)}iconName="add"primary/></Tooltip></Stack><Stackspacing="1"className="m-t-3"><Tooltipel="div"text="Remove Widgets"><ButtononClick={()=>setState(state -1)}iconName="remove"small/></Tooltip><Inputsmallstyle={{width:'50px'}}value={state}/><Tooltipel="div"text="Add More Widgets"direction="t"><ButtononClick={()=>setState(state +1)}iconName="add"primarysmall/></Tooltip></Stack></Form>)}</State>
Add the loading prop to the button and it disables and gives a loading animation. Useful for preventing double submissions on forms. The button width will not change.
A user should be able to use the button name to predict what will happen when they click it.
Buttons should action-oriented, pairing a verb and a supporting noun, and be 2 to 3 words long. Common actions like “Save,” “Close,” “Cancel,” or “OK” don’t require a supporting noun.
Do
Don't
Be concise and consistent
Avoid unnecessary words and articles such as the, an, or a. Never include punctuation in button text and avoid button text that requires punctuation. Always write button text in title case. Capitalize the first word, the last word, and all major words in between. Never use emoji or exclamation points.
Do
Don't
Button name should match destination
When a button opens a modal or takeover, the destination’s title should match the button text.
Button labeled Add Transaction opens a modal titled “Add transaction”
Do
Button labeled Add Transaction opens a modal titled “Create new invoice”.
Don't
Technical Examples
Click Action
Use the onClick prop to pass a function to the button.
The standard button component uses a span element because most buttons will be passed a function. If you pass the button a href prop, it will become an a element and click through to the url.
You can pass Button through the trigger prop of the ActionMenu.
<Stateinitial={false}>{([open, setOpen])=>{consthandleClick=()=>setOpen(!open);consthandleClickOutside=()=>setOpen(false);return(<ActionMenutrigger={<ButtononClick={handleClick}smalliconName="expand_more"iconPosition="right">Use the force</Button>}sharp={false}width="auto"direction="br"open={open}onClickOutside={handleClickOutside}><ActionMenu.Item>Precognition</ActionMenu.Item><ActionMenu.Item>Psychometry</ActionMenu.Item><ActionMenu.Item>Telepathy</ActionMenu.Item><ActionMenu.Item>Shadow Vision</ActionMenu.Item><ActionMenu.Item>Levitation</ActionMenu.Item></ActionMenu>)}}</State>
Best Practices
Use the same button sizes within an action area
Prioritize the most important actions. Too many calls to action can cause confusion and make users unsure of what to do next.
Using several styles on one page may be confusing to user. Try to avoid using more than 3 styles on a screen.
Related Components
For a text button inline in a paragraph, use a Link.