Buttons are clickable elements that trigger an action. They can communicate calls to action, are visually prominent, and allow users to interact with the pages in various ways.
The vf-button
component can be used with forms on a page and as a prominent 'call to action' link that goes to another page.
A button can be used to submit data or take action and as a link to navigate to another page.
Use the primary button for the principal call to action on a page or form. Avoid having multiple primary buttons on the same page or form.
Use secondary buttons for secondary calls to action. Pages with too many prominent calls to action make it hard for users to know what to do next. Before adding lots of secondary buttons, try to simplify the page or break the content down across multiple pages.
Tertiary buttons can be used for less prominent actions. Consider using a link instead of a button to send users to another page, if this action is not very important.
As the vf-button
is relatively large, depending on the context, you may wish to use the vf-button--small
variant instead.
As a general rule, the vf-button
should be left aligned on the page and when used inside a larger component.
When used in conjunction with a single form input, as in the vf-search component, the vf-button
needs to be inline with the input and to the right of it.
When a vf-button
is used in a banner (e.g. to accept cookies) it needs to follow the content and be right aligned.
If using the vf-button
as a link do not use it to link to content on the same page. Use the vf-link-list
component instead.
Write button text in sentence case, describing the action it performs. For example:
Try to keep the text on the button short and clear.
The guidelines on buttons in the GOV.UK Design System and the Carbon Design System include additional advice on when and how to use buttons.
As of vf-button v2.0.0-alpha.2 vf-button has experimental Angular support.
yarn add @visual-framework/vf-button
import { VfButton } from "@visual-framework/vf-button/vf-button.angular.component.ts";
@NgModule({
declarations: [VfButton, YourOtherComponents],
...
})
<button class="vf-button" primary="true" small="true">Hello world</button>
@import '~@visual-framework/vf-button/vf-button.scss';
(you should also make use of vf-sass-starter)Depending on the success of this method, we plan to add standardized guidance to the component library and component generator.
Usage:
<button class="vf-button" primary="true" small="true">Hello</button>
Depending on your environment you'll want to use render
or include
. As a rule of thumb: server-side use include
, precompiled browser use render
. If you're using vf-eleventy you should use include
.
include
You'll need to pass a context object from your code or Yaml file (example), as well as the path to the Nunjucks template. Nunjucks' include
is an abstraction of render
and provides some additional portability.
{% set context fromYourYamlFile %}
- or -
{% set context = {
"component-type": "element",
"text": "Primary button",
"theme": "primary"
}
%}
{% include "../path_to/vf-button/vf-button.njk" %}
render
This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include
is not be available.
{% render '@vf-button', {
"component-type": "element",
"text": "Primary button",
"theme": "primary"
} %}
import { VfButton } from "@visual-framework/vf-button/vf-button.react.js";
// or
import { VfButton } from "@visual-framework/vf-button/vf-button.jsx";
<VfButton parameter="value" />
For individual parameter names and options, see the Nunjucks syntax example. Also follow the React setup guide. Note: React support is in its early pre-alpha stage and not all component are yet supported.
<button class="vf-button vf-button--primary">Primary button</button>
Depending on your environment you'll want to use render
or include
. As a rule of thumb: server-side use include
, precompiled browser use render
. If you're using vf-eleventy you should use include
.
include
You'll need to pass a context object from your code or Yaml file (example), as well as the path to the Nunjucks template. Nunjucks' include
is an abstraction of render
and provides some additional portability.
{% set context fromYourYamlFile %}
- or -
{% set context = {
"component-type": "element",
"text": "Secondary button",
"theme": "secondary"
}
%}
{% include "../path_to/vf-button/vf-button.njk" %}
render
This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include
is not be available.
{% render '@vf-button', {
"component-type": "element",
"text": "Secondary button",
"theme": "secondary"
} %}
import { VfButton } from "@visual-framework/vf-button/vf-button.react.js";
// or
import { VfButton } from "@visual-framework/vf-button/vf-button.jsx";
<VfButton parameter="value" />
For individual parameter names and options, see the Nunjucks syntax example. Also follow the React setup guide. Note: React support is in its early pre-alpha stage and not all component are yet supported.
<button class="vf-button vf-button--secondary">Secondary button</button>
Depending on your environment you'll want to use render
or include
. As a rule of thumb: server-side use include
, precompiled browser use render
. If you're using vf-eleventy you should use include
.
include
You'll need to pass a context object from your code or Yaml file (example), as well as the path to the Nunjucks template. Nunjucks' include
is an abstraction of render
and provides some additional portability.
{% set context fromYourYamlFile %}
- or -
{% set context = {
"component-type": "element",
"text": "Tertiary button",
"theme": "tertiary"
}
%}
{% include "../path_to/vf-button/vf-button.njk" %}
render
This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include
is not be available.
{% render '@vf-button', {
"component-type": "element",
"text": "Tertiary button",
"theme": "tertiary"
} %}
import { VfButton } from "@visual-framework/vf-button/vf-button.react.js";
// or
import { VfButton } from "@visual-framework/vf-button/vf-button.jsx";
<VfButton parameter="value" />
For individual parameter names and options, see the Nunjucks syntax example. Also follow the React setup guide. Note: React support is in its early pre-alpha stage and not all component are yet supported.
<button class="vf-button vf-button--tertiary">Tertiary button</button>
Depending on your environment you'll want to use render
or include
. As a rule of thumb: server-side use include
, precompiled browser use render
. If you're using vf-eleventy you should use include
.
include
You'll need to pass a context object from your code or Yaml file (example), as well as the path to the Nunjucks template. Nunjucks' include
is an abstraction of render
and provides some additional portability.
{% set context fromYourYamlFile %}
- or -
{% set context = {
"component-type": "element",
"text": "Small button",
"theme": "primary",
"size": "sm"
}
%}
{% include "../path_to/vf-button/vf-button.njk" %}
render
This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include
is not be available.
{% render '@vf-button', {
"component-type": "element",
"text": "Small button",
"theme": "primary",
"size": "sm"
} %}
import { VfButton } from "@visual-framework/vf-button/vf-button.react.js";
// or
import { VfButton } from "@visual-framework/vf-button/vf-button.jsx";
<VfButton parameter="value" />
For individual parameter names and options, see the Nunjucks syntax example. Also follow the React setup guide. Note: React support is in its early pre-alpha stage and not all component are yet supported.
<button class="vf-button vf-button--primary vf-button--sm ">Small button</button>
Depending on your environment you'll want to use render
or include
. As a rule of thumb: server-side use include
, precompiled browser use render
. If you're using vf-eleventy you should use include
.
include
You'll need to pass a context object from your code or Yaml file (example), as well as the path to the Nunjucks template. Nunjucks' include
is an abstraction of render
and provides some additional portability.
{% set context fromYourYamlFile %}
- or -
{% set context = {
"component-type": "element",
"text": "a link variant",
"theme": "link"
}
%}
{% include "../path_to/vf-button/vf-button.njk" %}
render
This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include
is not be available.
{% render '@vf-button', {
"component-type": "element",
"text": "a link variant",
"theme": "link"
} %}
import { VfButton } from "@visual-framework/vf-button/vf-button.react.js";
// or
import { VfButton } from "@visual-framework/vf-button/vf-button.jsx";
<VfButton parameter="value" />
For individual parameter names and options, see the Nunjucks syntax example. Also follow the React setup guide. Note: React support is in its early pre-alpha stage and not all component are yet supported.
<button class="vf-button vf-button--link">a link variant</button>
This component is distributed with npm. After installing npm, you can install the vf-button
with this command.
$ yarn add --dev @visual-framework/vf-button
The source files included are written in Sass(scss
). You can point your Sass include-path
at your node_modules
directory and import it like this.
@import "@visual-framework/vf-button/index.scss";
Make sure you import Sass requirements along with the modules. You can use a project boilerplate or the vf-sass-starter
@visual-framework@vf-sass-config@2.6.1
.set-type
mixin.link
theme button variant. This variant is similar to link style.set-
style functions to cleaner versionv2.0.0
of the vf-design-tokens
package or newerwebkit-appearance: none;
as needed for Safari browsers as autoprefixer is not doing this:hover
text color rule so that it doesn't to white on hover
File system location: components/vf-button
Find an issue on this page? Propose a change or discuss it.