Skip to Main Content

Buttons

Buttons are a key element that lets users take action on the page they’re viewing.

Use when:

  • User needs to launch an application, trigger sign-up flow, or submit a form.
  • User needs to get to other pages on the website (for example, support articles, blogs).
  • You want to let the user jump to a section of the page (anchor link) or return to the top of the page.

Interactive component

Library integration

Use the codes below to add this component to your project. Download the latest version of the library to easily implement our full range of components.

Angular

Step 1. Install

Execute the following command to install this component.

npm i [NPM-PLACE-HOLDER]/ds-button

Step 2. Import

Import the following into your app.module.ts file.

import { DsButtonModule } from 'ds-button';

Code snippets

Primary button
<cpc-ds-button 
    ariaLabel="Some aria label" 
    (click)="beep()" 
    class='primary-button' 
    body='Primary buttons'>
</cpc-ds-button>
Secondary button
<cpc-ds-button 
 class='secondary-button' 
 body='Secondary button'>
</cpc-ds-button>
Microaction button
<div>
    <a 
    role="button" 
    aria-label="Microaction button focus (copy)" 
    class="micro-buttons copy" 
    href="http://msn.com" 
    target="_blank">LINK MSN</a>
</div>
Properties
Name Type Default Description
class string primary-button

There are 3 classes available:

  • primary-button
  • secondary-button
  • micro-buttons

Micro-button example:


a[role='button'].YOUR_CLASS:before {
  content: url('assets/img/icons/YOUR_ICON.svg');
  position: relative;
  padding-right: 10px;
  display: inline-block;
  top: 3px;
}

Specify your class and icon when using micro-buttons.

body string Text for button

Text can be used. The language service will be used to pass the EN or FR text

type
  • button
  • link
  • submit
  • reset
button  
ariaLabel string  

Set if required for accessibility.

(click) Method  

(click)="beep()"

HTML

Step 1: Import CSS

Import the following in your theme or page.

<link type="text/css" href="[CSS-PLACE-HOLDER]" rel="stylesheet">

Step 2: Import JS

<script src="[JS-PLACE-HOLDER]"></script>

Code snippets

Primary button
<button class="primary-button by-keyboard">Primary Button</button>
Secondary button
<button class="secondary-button by-keyboard">Secondary Button</button>
Submit button
<input 
  type="submit"
  value="Submit Button"
  class="button primary-button by-keyboard">
Microaction button
<a 
  role="button" 
  class="micro-buttons copy by-keyboard"
  href=http://google.com
  target="_blank"
  aria-label="Microaction button focus (opens in a new window)">
  Microaction button focus
</a>
Group button
<div class="btn-group">
  <button 
   type="button" 
   class="button primary-button by-keyboard">
    Group 1
  </button>
  <button 
   type="button" 
   class="button primary-button by-keyboard">
    Group 2
  </button>
  <button 
   type="button" 
   class="button primary-button by-keyboard">
    Group 3
   </button>
</div>

General guidelines

Types of buttons

We have two types of buttons, Primary and Secondary:
Primary button:
Primary buttons

Primary “filled” buttons draw the user’s attention to your main call to action. Their bold colour stands out on a page, giving them a sense of priority among other elements on a busy screen.

Secondary button:
Secondary buttons

Secondary buttons are used to suggest an alternative action. Their background is unfilled and marked by a thin, coloured border.

Secondary buttons generally appear alongside a primary one but can sometimes appear alone.

  • Don’t use Secondary buttons too casually! Often seen as a safe way to enhance user experience, they can just as easily divert users from a desired action.
Text links
Links

Links are interactive text components that can sit within body copy or be used on their own as a navigational element. The clickable text appears blue to let the user know that it’s actionable. Links shouldn’t appear next to primary or secondary buttons or be substitutes for secondary buttons.

Links can also expand or reveal more sections of information. Some examples are “View more,” “Show all,” etc.

Microaction buttons
Microinteraction buttons

Microaction buttons communicate what they do to a user directly. Use icons or icons with copy to ensure a user knows what a microaction button is for.

Microaction buttons are for Canada Post products and tools, and not for marketing purposes on the website. Microactions serve different functions. They let users:

  • Turn functions off and on
  • Make a comment
  • Change their settings
  • View a notification message
  • Interact with a data field
  • Share or like content on social media

Positioning

Users read content in two distinct patterns: F and Z. When a page is content-heavy, a user reads in the F pattern, scanning downward along the left and across the top. When content is sparse or presented in columns, users read in a Z pattern along the top of the page, diagonally through the center and along the bottom. Place buttons where a user can see them based on the reading pattern of the page.

Buttons are left-justified with the left edge of the column.

  • Generally, a page should have 1 well-placed primary button to help users avoid confusion.

Interactions

States

A button is a UI element that lets users take a predetermined action. It consists of a single element, which is usually a rectangular area with a text label. A button can be a standalone element or part of a group.

Buttons can have the following states:

  1. Default: In this state, the button is clickable and would trigger the intended action.
  2. Hover: Using this state lets the user know that a button can be clicked.
  3. Focus: A focus state highlights interactive components and is crucial for users that navigate websites without a mouse.

General guidelines

Research shows that our choice of words affects user behaviour. The right copy can help convince a user to submit a form or click to learn more about our products.

  Guidelines Examples
Recommended length Up to 3 words or 22 characters Call us
Line wrap Avoid Track another item
Phrasing Start with a verb Get directions
Case Sentence case without period Copy link

Dos and don’ts

Length

Be specific and persuasive about what the button does, while keeping it short and concise. Aim for a maximum of 3 words or 22 characters. Note that French translations are often 1.5 times longer than the English content.

  • Add address
  • Add

Phrasing

Start with a descriptive verb that clearly states the outcome.
  • Return to profile
  • Profile

Subsequent headings

Button copy should complement the heading of the linked page or modal window that appears once a user selects the button.

  • Button content: Add description
  • Subsequent heading: Add description
  • Button content: Add description
  • Subsequent heading: Tracking number

Branded names

Be cautious about using branded names in button copy. Users don’t necessarily know them, and may feel discouraged from taking action. An exception is if the button appears on deeper pages of the website and you’re confident that users are familiar with the term.
  • Start shipping
  • Use Snap Ship

Accessibility considerations

Accessible error messages

It’s important to keep buttons enabled, even if required information is missing from forms. This way, when a user selects a button to move forward, it will trigger an error message that will help them identify what they’ve missed and what they need to do to move forward. Use accessible error messages that link users to the corresponding entries. If multiple errors apply, add an overview accessibility error message that links users to the applicable errors.

Overview accessible error message

 

Accessible error message

Microaction buttons

Apply text next to microactions that communicates what will happen when a user selects them. In cases where the microactions need to remain simply as icons, ensure that alt text describes their functions.

Microactions with visible text

  • Add, calendar, copy, delete, feedback, save, search
 

Microactions with alt text

  • Close

Customized alt text

The function of a microaction that is positioned next an item may not be clear for users who rely on assistive technology. Apply customized alt text when microactions correspond to specific items. This is especially helpful in charts that can be difficult to visualize.

Customized alt text for microaction

  • Delete item 8524303909315109 from recently tracked items

Code Samples

Basic

Note that this component may require additional styling.

Angular 2

Angular Material buttons are native <button> or <a> elements enhanced with Material Design styling and ink ripples.

Note that this component may require additional styling.

Mendix

Buttons are an out-of-the-box functionality.

To use them, simply select the appropriate button widget from the toolbox on the right.

There are two style options for these buttons, Primary or Secondary. Select the one you want from the Button style dropdown in the widget window.

Primary is the primary blue standard button and Default is the secondary style button.

The Mendix toolkit can be found here.

Guidelines

Keyboard interaction

When a button has focus, Spacebar or Enter must activate the button.

Things to remember when Enter activates a button:

  • Focus must be set depending on the type of action the button performs.
  • If activating the button doesn’t dismiss the current context, focus will typically remain on the button after activation. For example, an ‘Apply’ button.
  • If the button action indicates a context change, such as adding another search criteria, focus will move to the starting point for that action.

Adding extra context

Sometimes button text doesn't give enough context. For example, a table might have a column of multiple "Select" buttons to select the respective row. In these cases, an alternate non-visible context can be provided to the button text.

Add alternate non-visible context to button text in one of the following ways:

  • Set the button element aria-describedby text to the ID of the element containing the description. This should only be done if a description of the button's function is present.
  • Append contextual text to the button text using a screen reader-only CSS class.
  • Append an aria-label containing the contextual information to the button.

Microaction button text

When a microaction button is presented without a label, you must have off-screen text for non-sighted users to help them understand what the button does.

Testing

When testing a button, the tester must ensure:

  • The button is fully keyboard operable
  • Indications for the focused and the hovered states are clear and prominent
  • The button is properly used for a button’s intended purpose.
  • The button has the role of "button" (role=”button”)
  • The screen reader announces the button label and any extra context (if applied).

Related content