Buttons
Work in progress
This page is a work in progress.
Please file an issue or submit a pull request if information or coding is missing, incorrect or out of sync with the main repository (wet-boew/wet-boew).
Purpose
Use buttons to create a call to action that entices the user to submit content from a form. Also, use buttons also take users to a webpage that provides additional information.
Design and coding
Basic use
Default
Use the button classes on <a>
, <button>
, or <input>
elements to create visual consistency. The browser shows certain elements as a button. However, there is often a lack of visual consistency for each button type. Each browser can have a different button default appearance.
Correct use
Compliance point(s):
- Use the
<button>
element whenever possible to ensure matching cross-browser rendering- There is a bug in Firefox <30 that makes it impossible to set the
line-height
in<input>
-based buttons - These buttons therefore have uneven heights in Firefox
- There is a bug in Firefox <30 that makes it impossible to set the
Incorrect use
Compliance point(s):
- Do not use this component in a way that conflicts with the preceding compliance point(s)
Code
// Default button:
<button type="submit">Button</button>
<input type="button" value="Input" />
<input type="submit" value="Submit" />
<a class="btn btn-default" href="#"</a>
// Styled button:
<button class="btn btn-default" type="submit">Button</button>
<input class="btn btn-default" type="button" value="Input" />
<input class="btn btn-default" type="submit" value="Submit" />
<a class="btn btn-default" href="#" role="button">Link</a>
Enhanced use
Colours
Use to add colours to buttons. Colours signify such things as a link to warning information (caution button) to a link to the next learning module (success button).
Appearance
Correct use
Compliance point(s):
- Use buttons as follows:
- Default: Standard button
- Primary: Provides extra visual weight and identifies the primary action in a set of buttons
- Success: Indicates a successful or positive action that advances the user to a next phase or module
- Info: Contextual button for informational alert messages
- Warning: Indicates to take caution with this action
- Danger: Indicates a dangerous or potentially negative action
- Link: De-emphasize a button by making it look like a link, while maintaining button behavior
Incorrect use
Compliance point(s):
- Do not use this component in a way that conflicts with the preceding compliance point(s)
Code
// Default:
<button type="button" class="btn btn-default">Default</button>
// Primary:
<button type="button" class="btn btn-primary">Primary</button>
// Success:
<button type="button" class="btn btn-success">Success</button>
// Info:
<button type="button" class="btn btn-info">Info</button>
// Warning:
<button type="button" class="btn btn-warning">Warning</button>
// Danger:
<button type="button" class="btn btn-danger">Danger</button>
// Link:
<button type="button" class="btn btn-link">Link</button>
Sizing
Use to increase or decrease the size of a button.
Appearance
Correct use
Compliance point(s):
- Default sizing: Use for a typical button
- Extra small and small buttons: Use when several buttons are contained within a toolbar and space is at a premium. The button size reduces to maximize the amount of buttons that appear in a single row
- Large button: Use when the button needs additional prominence on the page. Since the default buttons already create prominence and a call to action, there is limited value/need to increase their size
Incorrect use
Compliance point(s):
- Do not use this component in a way that conflicts with the preceding compliance point(s)
Code
// Large button:
<button type="button" class="btn btn-default btn-lg">Large button</button>
// Default button:
<button type="button" class="btn btn-default">Default button</button>
// Small button:
<button type="button" class="btn btn-default btn-sm">Small button</button>
// Extra small button:
<button type="button" class="btn btn-default btn-xs">Extra small button</button>
Full width
Use to create block level buttons (those that span the full width of a parent).
Appearance
Correct use
Compliance point(s):
- Use
.btn-block
when the button is within a small container- This button spans the full width of the parent container, and is fully justified within the available space
- Test the button in all resolutions
- In a responsive design, full width buttons may not look good in all resolutions
Incorrect use
Compliance point(s):
- Do not use this component in a way that conflicts with the preceding compliance point(s)
Code
// Block level button:
<button type="button" class="btn btn-default btn-block">Block level button</button>
Active state
Use .active
with <button>
and <a>
elements if you need to have a button look active at all times (usually for display or instructional purposes on fake buttons or links). When a user presses a button it appears in the active state (with an inset shadow, and darker background and border). For <button>
and <a>
elements, this is auto-styled in CSS via :active
.
Appearance
Correct use
Compliance point(s):
- Add
.active
to<a>
or<button>
elements to indicate that a link or button is in an active state - Use when the link or button target matches the current page address
Incorrect use
Compliance point(s):
- Do not use this component in a way that conflicts with the preceding compliance point(s)
Code
// Active button:
<button type="button" class="btn btn-default active">Button</button>
// Active link:
<a href="#" class="btn btn-default active" role="button">Link</a>
Disabled state
Use to disable buttons and links (not clickable), and give them a faded appearance.
Appearance
Correct use
Compliance point(s):
- Use
disabled="disabled"
to disable a button - Add the
.disabled
class to an<a>
element to indicate that a link is disabled - Remove the
href
attribute to fully disable links, as the class only changes the appearance of the<a>
tag, not the functionality
Incorrect use
Compliance point(s):
- Do not use this component in a way that conflicts with the preceding compliance point(s)
Code
// Disabled button:
<button type="button" class="btn btn-default btn-lg" disabled="disabled">Button</button>
// Disabled link:
<a href="#" class="btn btn-default btn-lg disabled" role="button">Link</a>
Groups
Use to group a series of buttons together on a single line with the button group.
Correct use
Compliance point(s):
- Use to make a single toolbar of buttons
- Wrap a series of buttons with
.btn
within a.btn-group
- Add
.btn-group-*
to the.btn-group
rather than applying button sizing classes to every button in a group - Wrap a series of buttons with
.btn
within.btn-group btn-group-justified
− to use justified button groups with<a>
elements - Wrap each button within a button group to use justified button groups with
<button>
elements. Most browsers don't properly apply our CSS for justification to<button>
elements. Since we support button dropdowns, we can workaround that
Incorrect use
Compliance point(s):
- Do not use this component in a way that conflicts with the preceding compliance point(s)
Code
// Default:
<div class="btn-group">
<button class="btn btn-default" type="button">...</button>...
</div>
// Large button group:
<div class="btn-group btn-group-lg">...
</div>
//Small button group:
<div class="btn-group btn-group-sm">...
</div>
// Extra small button group:
<div class="btn-group btn-group-xs">...
</div>
// Justified links:
<div class="btn-group btn-group-justified">
<a class="btn btn-default" role="button">...</a>...
</div>
// Justified button group:
<div class="btn-group btn-group-justified">
<div class="btn-group">
<button type="button" class="btn btn-default">...</button>
</div>...
</div>
Toolbars
Use to display multiple groups of buttons together on a single line.
Appearance
Correct use
Compliance point(s):
- Use to make a toolbar that contains multiple groups of buttons
Incorrect use
Compliance point(s):
- Do not use this component in a way that conflicts with the preceding compliance point(s)
Code
// Multiple button groups:
<ul class="btn-toolbar list-inline" role="toolbar">
<li class="btn-group">
<button type="button" class="btn btn-default">1</button>
...
</li>
<li class="btn-group">
<button type="button" class="btn btn-default">4</button>
...
</li>
<li class="btn-group">
<button type="button" class="btn btn-default">6</button>
</li>
</ul>
Button types
Use the correct button text for the correct user interaction.
Don't focus on the button colours/styling
The below buttons are pre-styled for guidance and demonstration purposes.
As long as all button compliance points are adhered to, the button can have different colours, sizes, groupings and so forth than what is shown.
Button type | Example | Compliance point(s) |
---|---|---|
Primary action button | For example: |
|
Sign in |
|
|
Register |
|
|
Sign out |
|
|
Previous / Next |
|
|
Submit |
|
|
Calculate |
|
|
Cancel |
|
|
Save |
|
|
Add |
|
|
Edit |
|
|
Delete |
|
|
View |
|
|
Retrieve |
|
|
Search |
|
|
Reset |
|
|
Start again |
|
|
|
||
Clear |
|
|
Exit Quit |
Do not use
|
|
I agree | Do not use
|
|
Add-on features
Additional add-on features and behaviours are available.
Some of the code and documentation for this page is sourced from Bootstrap (external link)
- Date modified: