Skip to content

Button

The button system provides a flexible and consistent way to create interactive elements across your application. It offers three main button types (Primary, Secondary, and Tertiary) with three emphasis levels (High, Medium, and Low) for each type. This system allows for a wide range of visual hierarchies and use cases.

All buttons can be styled using the documented variables, with any provided values over-riding the provided defaults.

Button Implementation

Buttons use the btn class, along with your chosen skin, e.g. skin-primary-emphasised

Don’t forget to also include the interactive class so that the button receives the skins hover, active, focus and disabled

Icon Support

Buttons can include icons on the left or right side of the text, or as standalone icon buttons. Use the icon-container class to wrap your SVG icons.

Disabled State

Add the disabled attribute to a button to indicate that it’s not interactive.

Bordered Buttons

We may want to have our borders have a low, or no border by default, but also have consistent widths on our buttons with emphasised borders. For this reason, the bordered class can be used to specify the button should have an emphasised border. The height is adjusted, ensuring that both bordered and non bordered buttons are a consistent width.

Button Bars

Placing buttons together as a bar can be made easy using the btn-bar class applied to a parent div. Vertical button bars can also be created, using the btn-bar-vertical class.

CSS Variables

General Button Variables

VariableDefault ValueDescription
--btn-radiusvar(--radius-site)Border radius of the button
--btn-animation-speedvar(--animation-speed-quick)Speed of button animations
--btn-hover-scale1.005Scale factor on hover
--btn-active-scale0.995Scale factor when active
--btn-gap0.5remGap between button elements
--btn-icon-scale-hover1.15Icon scale factor on hover
--btn-icon-scale-active1.3Icon scale factor when active
--btn-icon-stroke-width3Stroke width of icon SVGs
--btn-padding-x1remHorizontal padding
--btn-padding-y0.5remVertical padding
--btn-border-width0pxDefault border width
--btn-bordered-border-width3pxBorder width for bordered buttons
--btn-line-heightvar(--line-height-body)Line height of button text
--btn-heightcalc(var(--line-height) + 2 * var(--btn-padding-y))Total button height
--btn-text-sizevar(--text-body)Font size of button text
--btn-icon-sizecalc(var(--btn-height) - (2 * var(--btn-padding-y)))Size of button icons

Accessibility

The button system is designed with accessibility in mind:

  • Use of semantic <button> elements for all buttons.
  • Provides descriptive text for screen readers.
  • Supports keyboard navigation and focus states.

For further guidance on documentation, refer to the WAI-ARIA Button Pattern.

Keyboard Interaction

  • Buttons are focusable and can be activated using the Space or Enter keys.
  • Tab key navigates between buttons.
  • Disabled buttons do not receive focus or be clickable.

Best Practices

  • Use button types consistently across your application.
  • Choose the appropriate emphasis level based on the action’s importance.
  • Use clear, action-oriented text for button labels.
  • Avoid using too many high emphasis buttons on a single page.
  • Consider the visual hierarchy when placing buttons near each other.

Implementation Notes

When implementing buttons in your project:

  • Ensure that button text is clear and descriptive.
  • Use icons judiciously to enhance understanding, not replace text.
  • Make sure that aria labels on icon only buttons clearly explain the function of the button, and don’t just state what the icon is.
  • Test buttons across different screen sizes to ensure proper scaling and touch targets.
  • Implement proper focus management, especially when buttons trigger modals or other interactive elements.
  • Ensure that aria labels for icon only buttons are correct