Button examples

Show params

Params

params:
- name: element
  type: string
  required: false
  description: Whether to use an `input`, `button` or `a` element to create the button. In most cases you will not need to set this as it will be configured automatically if you use `href` or `html`.
- name: text
  type: string
  required: true
  description: If `html` is set, this is not required. Text for the button or link. If `html` is provided, the `text` argument will be ignored and `element` will be automatically set to `button` unless `href` is also set, or it has already been defined. This argument has no effect if `element` is set to `input`.
- name: html
  type: string
  required: true
  description: If `text` is set, this is not required. HTML for the button or link. If `html` is provided, the `text` argument will be ignored and `element` will be automatically set to `button` unless `href` is also set, or it has already been defined. This argument has no effect if `element` is set to `input`.
- name: name
  type: string
  required: false
  description: Name for the `input` or `button`. This has no effect on `a` elements.
- name: type
  type: string
  required: false
  description: Type of `input` or `button` – `button`, `submit` or `reset`. Defaults to `button`. This has no effect on `a` elements.
- name: value
  type: string
  required: false
  description: Value for the `button` tag. This has no effect on `a` or `input` elements.
- name: disabled
  type: boolean
  required: false
  description: Whether the button should be disabled. For button and input elements, `disabled` and `aria-disabled` attributes will be set automatically.
- name: href
  type: string
  required: false
  description: The URL that the button should link to. If this is set, `element` will be automatically set to `a` if it has not already been defined.
- name: target
  type: string
  required: false
  description: The target where the button should link to.
- name: classes
  type: string
  required: false
  description: Classes to add to the button component.
- name: attributes
  type: object
  required: false
  description: HTML attributes (for example data attributes) to add to the button component.
- name: preventDoubleClick
  type: boolean
  required: false
  description: Prevent accidental double clicks on submit buttons from submitting forms multiple times

default

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "text": "Default"
})  }}

Markup



<!-- button --><button class="c-button" >
  Default
</button><!-- /button -->

default with active state

Simulate triggering the :active CSS pseudo-class

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "name": "active",
  "text": "Active",
  "classes": "ds-active"
})  }}

Markup



<!-- button --><button name="active" class="c-button ds-active" >
  Active
</button><!-- /button -->

default with hover state

Simulate triggering the :hover CSS pseudo-class

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "name": "hover",
  "text": "Hovered",
  "classes": "ds-hover"
})  }}

Markup



<!-- button --><button name="hover" class="c-button ds-hover" >
  Hovered
</button><!-- /button -->

default with focus state

Simulate triggering the :focus CSS pseudo-class

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "name": "focus",
  "text": "Focussed",
  "classes": "ds-focus"
})  }}

Markup



<!-- button --><button name="focus" class="c-button ds-focus" >
  Focussed
</button><!-- /button -->

default disabled

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "text": "Disabled",
  "disabled": true
})  }}

Markup



<!-- button --><button disabled="disabled" aria-disabled="true" class="c-button c-button--disabled" >
  Disabled
</button><!-- /button -->

primary

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "text": "Primary",
  "classes": "c-button--primary"
})  }}

Markup



<!-- button --><button class="c-button c-button--primary" >
  Primary
</button><!-- /button -->

primary with active state

Simulate triggering the :active CSS pseudo-class

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "name": "active",
  "text": "Active",
  "classes": "c-button--primary ds-active"
})  }}

Markup



<!-- button --><button name="active" class="c-button c-button--primary ds-active" >
  Active
</button><!-- /button -->

primary with hover state

Simulate triggering the :hover CSS pseudo-class

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "name": "hover",
  "text": "Hover",
  "classes": "c-button--primary ds-hover"
})  }}

Markup



<!-- button --><button name="hover" class="c-button c-button--primary ds-hover" >
  Hover
</button><!-- /button -->

primary with focus state

Simulate triggering the :focus CSS pseudo-class

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "name": "focus",
  "text": "Focus",
  "classes": "c-button--primary ds-focus"
})  }}

Markup



<!-- button --><button name="focus" class="c-button c-button--primary ds-focus" >
  Focus
</button><!-- /button -->

primary disabled

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "text": "Disabled",
  "disabled": true,
  "classes": "c-button--primary"
})  }}

Markup



<!-- button --><button disabled="disabled" aria-disabled="true" class="c-button c-button--primary c-button--disabled" >
  Disabled
</button><!-- /button -->

alert

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "text": "Alert",
  "classes": "c-button--alert"
})  }}

Markup



<!-- button --><button class="c-button c-button--alert" >
  Alert
</button><!-- /button -->

alert with active state

Simulate triggering the :active CSS pseudo-class

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "name": "active",
  "text": "Active",
  "classes": "c-button--alert ds-active"
})  }}

Markup



<!-- button --><button name="active" class="c-button c-button--alert ds-active" >
  Active
</button><!-- /button -->

alert with hover state

Simulate triggering the :hover CSS pseudo-class

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "name": "hover",
  "text": "Hover",
  "classes": "c-button--alert ds-hover"
})  }}

Markup



<!-- button --><button name="hover" class="c-button c-button--alert ds-hover" >
  Hover
</button><!-- /button -->

alert with focus state

Simulate triggering the :focus CSS pseudo-class

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "name": "focus",
  "text": "Focus",
  "classes": "c-button--alert ds-focus"
})  }}

Markup



<!-- button --><button name="focus" class="c-button c-button--alert ds-focus" >
  Focus
</button><!-- /button -->

alert disabled

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "text": "Disabled",
  "disabled": true,
  "classes": "c-button--alert"
})  }}

Markup



<!-- button --><button disabled="disabled" aria-disabled="true" class="c-button c-button--alert c-button--disabled" >
  Disabled
</button><!-- /button -->

transparent

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "text": "Transparent",
  "classes": "c-button--transparent"
})  }}

Markup



<!-- button --><button class="c-button c-button--transparent" >
  Transparent
</button><!-- /button -->

transparent with active state

Simulate triggering the :active CSS pseudo-class

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "name": "active",
  "text": "Active",
  "classes": "c-button--transparent ds-active"
})  }}

Markup



<!-- button --><button name="active" class="c-button c-button--transparent ds-active" >
  Active
</button><!-- /button -->

transparent with hover state

Simulate triggering the :hover CSS pseudo-class

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "name": "hover",
  "text": "Hover",
  "classes": "c-button--transparent ds-hover"
})  }}

Markup



<!-- button --><button name="hover" class="c-button c-button--transparent ds-hover" >
  Hover
</button><!-- /button -->

transparent with focus state

Simulate triggering the :focus CSS pseudo-class

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "name": "focus",
  "text": "Focus",
  "classes": "c-button--transparent ds-focus"
})  }}

Markup



<!-- button --><button name="focus" class="c-button c-button--transparent ds-focus" >
  Focus
</button><!-- /button -->

transparent disabled

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "text": "Disabled",
  "disabled": true,
  "classes": "c-button--transparent"
})  }}

Markup



<!-- button --><button disabled="disabled" aria-disabled="true" class="c-button c-button--transparent c-button--disabled" >
  Disabled
</button><!-- /button -->

small

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "text": "Small",
  "classes": "c-button--sm"
})  }}

Markup



<!-- button --><button class="c-button c-button--sm" >
  Small
</button><!-- /button -->

link

Link button
Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "text": "Link button",
  "href": "/"
})  }}

Markup



<!-- button --><a href="/" role="button" draggable="false" class="c-button" >
  Link button
</a><!-- /button -->

link with target blank

Link button with target
Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "text": "Link button with target",
  "href": "http://www.google.com",
  "target": "_blank"
})  }}

Markup



<!-- button --><a href="http://www.google.com" role="button" draggable="false" target="_blank" class="c-button" >
  Link button with target
</a><!-- /button -->

link disabled

Disabled link button
Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "text": "Disabled link button",
  "href": "/",
  "disabled": true
})  }}

Markup



<!-- button --><a href="/" role="button" draggable="false" tabindex="-1" aria-disabled="true" class="c-button c-button--disabled" >
  Disabled link button
</a><!-- /button -->

button with right icon

Button with icon
Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "html": "Button with icon<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 140 140\"  class=\"self-center ml-2\" aria-hidden=\"true\" focusable=\"false\" width=\"1em\" height=\"1em\"><path d=\"M113.72 61.66A5 5 0 00110 60H30a5 5 0 00-5 5.53l7.5 70a5 5 0 005 4.47h65a5 5 0 005-4.47l7.5-70a5 5 0 00-1.28-3.87zM125 27.92h-25a2.5 2.5 0 01-2.5-2.5V17.5A17.52 17.52 0 0080 0H60a17.58 17.58 0 00-17.5 17.23l-.12 8.22a2.51 2.51 0 01-2.5 2.47H15a10 10 0 000 20h110a10 10 0 000-20zM57.5 17.46A2.51 2.51 0 0160 15h20a2.5 2.5 0 012.5 2.5v7.92a2.5 2.5 0 01-2.5 2.5H59.88a2.51 2.51 0 01-2.5-2.54z\" fill=\"currentColor\"/></svg>",
  "href": "/"
})  }}

Markup



<!-- button --><a href="/" role="button" draggable="false" class="c-button" >
  Button with icon<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 140 140"  class="self-center ml-2" aria-hidden="true" focusable="false" width="1em" height="1em"><path d="M113.72 61.66A5 5 0 00110 60H30a5 5 0 00-5 5.53l7.5 70a5 5 0 005 4.47h65a5 5 0 005-4.47l7.5-70a5 5 0 00-1.28-3.87zM125 27.92h-25a2.5 2.5 0 01-2.5-2.5V17.5A17.52 17.52 0 0080 0H60a17.58 17.58 0 00-17.5 17.23l-.12 8.22a2.51 2.51 0 01-2.5 2.47H15a10 10 0 000 20h110a10 10 0 000-20zM57.5 17.46A2.51 2.51 0 0160 15h20a2.5 2.5 0 012.5 2.5v7.92a2.5 2.5 0 01-2.5 2.5H59.88a2.51 2.51 0 01-2.5-2.54z" fill="currentColor"/></svg>
</a><!-- /button -->

button with left icon

Button with icon
Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "html": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 140 140\"  class=\"self-center mr-2\" aria-hidden=\"true\" focusable=\"false\" width=\"1em\" height=\"1em\"><path d=\"M113.72 61.66A5 5 0 00110 60H30a5 5 0 00-5 5.53l7.5 70a5 5 0 005 4.47h65a5 5 0 005-4.47l7.5-70a5 5 0 00-1.28-3.87zM125 27.92h-25a2.5 2.5 0 01-2.5-2.5V17.5A17.52 17.52 0 0080 0H60a17.58 17.58 0 00-17.5 17.23l-.12 8.22a2.51 2.51 0 01-2.5 2.47H15a10 10 0 000 20h110a10 10 0 000-20zM57.5 17.46A2.51 2.51 0 0160 15h20a2.5 2.5 0 012.5 2.5v7.92a2.5 2.5 0 01-2.5 2.5H59.88a2.51 2.51 0 01-2.5-2.54z\" fill=\"currentColor\"/></svg>Button with icon",
  "href": "/"
})  }}

Markup



<!-- button --><a href="/" role="button" draggable="false" class="c-button" >
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 140 140"  class="self-center mr-2" aria-hidden="true" focusable="false" width="1em" height="1em"><path d="M113.72 61.66A5 5 0 00110 60H30a5 5 0 00-5 5.53l7.5 70a5 5 0 005 4.47h65a5 5 0 005-4.47l7.5-70a5 5 0 00-1.28-3.87zM125 27.92h-25a2.5 2.5 0 01-2.5-2.5V17.5A17.52 17.52 0 0080 0H60a17.58 17.58 0 00-17.5 17.23l-.12 8.22a2.51 2.51 0 01-2.5 2.47H15a10 10 0 000 20h110a10 10 0 000-20zM57.5 17.46A2.51 2.51 0 0160 15h20a2.5 2.5 0 012.5 2.5v7.92a2.5 2.5 0 01-2.5 2.5H59.88a2.51 2.51 0 01-2.5-2.54z" fill="currentColor"/></svg>Button with icon
</a><!-- /button -->

backbutton

Transparent with left icon

Volver
Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "html": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 140 140\" class=\"self-center mr-2\" aria-hidden=\"true\" focusable=\"false\" width=\"1em\" height=\"1em\"><path d=\"M37.93 27.93l-35 35a10 10 0 000 14.14l35 35a10 10 0 1014.14-14.14L38.41 84.27A2.5 2.5 0 0140.18 80H130a10 10 0 000-20H40.18a2.5 2.5 0 01-1.77-4.27l13.66-13.66a10 10 0 00-14.14-14.14z\" fill=\"currentColor\"></path></svg>Volver",
  "classes": "c-button--transparent",
  "href": "/"
})  }}

Markup



<!-- button --><a href="/" role="button" draggable="false" class="c-button c-button--transparent" >
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 140 140" class="self-center mr-2" aria-hidden="true" focusable="false" width="1em" height="1em"><path d="M37.93 27.93l-35 35a10 10 0 000 14.14l35 35a10 10 0 1014.14-14.14L38.41 84.27A2.5 2.5 0 0140.18 80H130a10 10 0 000-20H40.18a2.5 2.5 0 01-1.77-4.27l13.66-13.66a10 10 0 00-14.14-14.14z" fill="currentColor"></path></svg>Volver
</a><!-- /button -->

button with only icon

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "html": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 140 140\"  class=\"self-center my-1\" aria-hidden=\"true\" focusable=\"false\" width=\"1em\" height=\"1em\" role=\"img\" aria-label=\"Borrar\"><path d=\"M113.72 61.66A5 5 0 00110 60H30a5 5 0 00-5 5.53l7.5 70a5 5 0 005 4.47h65a5 5 0 005-4.47l7.5-70a5 5 0 00-1.28-3.87zM125 27.92h-25a2.5 2.5 0 01-2.5-2.5V17.5A17.52 17.52 0 0080 0H60a17.58 17.58 0 00-17.5 17.23l-.12 8.22a2.51 2.51 0 01-2.5 2.47H15a10 10 0 000 20h110a10 10 0 000-20zM57.5 17.46A2.51 2.51 0 0160 15h20a2.5 2.5 0 012.5 2.5v7.92a2.5 2.5 0 01-2.5 2.5H59.88a2.51 2.51 0 01-2.5-2.54z\" fill=\"currentColor\"/></svg>",
  "href": "/",
  "classes": "c-button--primary align-bottom"
})  }}

Markup



<!-- button --><a href="/" role="button" draggable="false" class="c-button c-button--primary align-bottom" >
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 140 140"  class="self-center my-1" aria-hidden="true" focusable="false" width="1em" height="1em" role="img" aria-label="Borrar"><path d="M113.72 61.66A5 5 0 00110 60H30a5 5 0 00-5 5.53l7.5 70a5 5 0 005 4.47h65a5 5 0 005-4.47l7.5-70a5 5 0 00-1.28-3.87zM125 27.92h-25a2.5 2.5 0 01-2.5-2.5V17.5A17.52 17.52 0 0080 0H60a17.58 17.58 0 00-17.5 17.23l-.12 8.22a2.51 2.51 0 01-2.5 2.47H15a10 10 0 000 20h110a10 10 0 000-20zM57.5 17.46A2.51 2.51 0 0160 15h20a2.5 2.5 0 012.5 2.5v7.92a2.5 2.5 0 01-2.5 2.5H59.88a2.51 2.51 0 01-2.5-2.54z" fill="currentColor"/></svg>
</a><!-- /button -->

button small with only icon

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "html": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 140 140\"  class=\"self-center my-1\" aria-hidden=\"true\" focusable=\"false\" width=\"1em\" height=\"1em\" role=\"img\" aria-label=\"Borrar\"><path d=\"M113.72 61.66A5 5 0 00110 60H30a5 5 0 00-5 5.53l7.5 70a5 5 0 005 4.47h65a5 5 0 005-4.47l7.5-70a5 5 0 00-1.28-3.87zM125 27.92h-25a2.5 2.5 0 01-2.5-2.5V17.5A17.52 17.52 0 0080 0H60a17.58 17.58 0 00-17.5 17.23l-.12 8.22a2.51 2.51 0 01-2.5 2.47H15a10 10 0 000 20h110a10 10 0 000-20zM57.5 17.46A2.51 2.51 0 0160 15h20a2.5 2.5 0 012.5 2.5v7.92a2.5 2.5 0 01-2.5 2.5H59.88a2.51 2.51 0 01-2.5-2.54z\" fill=\"currentColor\"/></svg>",
  "href": "/",
  "classes": "c-button--primary c-button--sm align-bottom"
})  }}

Markup



<!-- button --><a href="/" role="button" draggable="false" class="c-button c-button--primary c-button--sm align-bottom" >
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 140 140"  class="self-center my-1" aria-hidden="true" focusable="false" width="1em" height="1em" role="img" aria-label="Borrar"><path d="M113.72 61.66A5 5 0 00110 60H30a5 5 0 00-5 5.53l7.5 70a5 5 0 005 4.47h65a5 5 0 005-4.47l7.5-70a5 5 0 00-1.28-3.87zM125 27.92h-25a2.5 2.5 0 01-2.5-2.5V17.5A17.52 17.52 0 0080 0H60a17.58 17.58 0 00-17.5 17.23l-.12 8.22a2.51 2.51 0 01-2.5 2.47H15a10 10 0 000 20h110a10 10 0 000-20zM57.5 17.46A2.51 2.51 0 0160 15h20a2.5 2.5 0 012.5 2.5v7.92a2.5 2.5 0 01-2.5 2.5H59.88a2.51 2.51 0 01-2.5-2.54z" fill="currentColor"/></svg>
</a><!-- /button -->

input

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "element": "input",
  "name": "send-form",
  "text": "Submit"
})  }}

Markup



<!-- button --><input value="Submit" type="submit" name="send-form" class="c-button" ><!-- /button -->

input disabled

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "element": "input",
  "text": "Submit",
  "disabled": true
})  }}

Markup



<!-- button --><input value="Submit" type="submit" disabled="disabled" aria-disabled="true" class="c-button c-button--disabled" ><!-- /button -->

prevent double click

Show code

Macro

{% from "components/button/_macro.button.njk" import componentButton %}
{{ componentButton({
  "text": "Submit",
  "preventDoubleClick": true
})  }}

Markup



<!-- button --><button data-prevent-double-click="true" class="c-button" >
  Submit
</button><!-- /button -->