Components Checkboxes Checkboxes enable users to select one or more options from a visible list of options, and to toggle a single option on or off.
Examples Interact with each example to see how it works.
Code Mustache / Handlebars // Developer note: ensure your ".mustache" files are imported as plain text. In Webpack you might use https://github.com/webpack-contrib/raw-loader
import Mustache from "mustache";
import FieldsetBlock from "@govtnz/ds/build/mustache/FieldsetBlock.mustache";
import H1 from "@govtnz/ds/build/mustache/H1.mustache";
import P from "@govtnz/ds/build/mustache/P.mustache";
import CheckboxBlock from "@govtnz/ds/build/mustache/CheckboxBlock.mustache";
// The variables FieldsetBlock, H1, P, CheckboxBlock are all strings that are mustache templates.
export default `${Mustache.render(FieldsetBlock, {
legend: `${Mustache.render(H1, {
"styleSize=large": true,
styleSize: true,
id: `providerChoiceTitle1`,
marginBottom8: ``,
children: `Who are your providers?`
})}`,
hint: `${Mustache.render(P, { children: `Select all that apply.` })}`,
hintId: `hintId1`,
children: `${Mustache.render(CheckboxBlock, {
label: `Aardvark Access`,
id: `anyCheckboxId1`,
value: `provider1`,
name: `providerChoice1`
})}${Mustache.render(CheckboxBlock, {
label: `Bumblebee Business`,
id: `anyCheckboxId2`,
value: `provider2`,
name: `providerChoice1`
})}${Mustache.render(CheckboxBlock, {
label: `Caterpillar Company`,
id: `anyCheckboxId3`,
value: `provider3`,
name: `providerChoice1`
})}`
})}`;
React (JavaScript) import React from "react";
import FieldsetBlock from "@govtnz/ds/build/react-js/FieldsetBlock";
import "@govtnz/ds/build/css/FieldsetBlock.css"; // or @govtnz/ds/build/scss/FieldsetBlock.scss
import H1 from "@govtnz/ds/build/react-js/H1";
import "@govtnz/ds/build/css/H1.css"; // or @govtnz/ds/build/scss/H1.scss
import P from "@govtnz/ds/build/react-js/P";
import "@govtnz/ds/build/css/P.css"; // or @govtnz/ds/build/scss/P.scss
import CheckboxBlock from "@govtnz/ds/build/react-js/CheckboxBlock";
import "@govtnz/ds/build/css/CheckboxBlock.css"; // or @govtnz/ds/build/scss/CheckboxBlock.scss
export default () => (
<FieldsetBlock
legend={
<H1 styleSize="large" id="providerChoiceTitle1" marginBottom8>
Who are your providers?
</H1>
}
hint={<P>Select all that apply.</P>}
hintId="hintId1"
>
<CheckboxBlock
label="Aardvark Access"
id="anyCheckboxId1"
value="provider1"
name="providerChoice1"
/>
<CheckboxBlock
label="Bumblebee Business"
id="anyCheckboxId2"
value="provider2"
name="providerChoice1"
/>
<CheckboxBlock
label="Caterpillar Company"
id="anyCheckboxId3"
value="provider3"
name="providerChoice1"
/>
</FieldsetBlock>
);
React (TypeScript) import React from "react";
import FieldsetBlock from "@govtnz/ds/build/react-ts/FieldsetBlock";
import "@govtnz/ds/build/css/FieldsetBlock.css"; // or @govtnz/ds/build/scss/FieldsetBlock.scss
import H1 from "@govtnz/ds/build/react-ts/H1";
import "@govtnz/ds/build/css/H1.css"; // or @govtnz/ds/build/scss/H1.scss
import P from "@govtnz/ds/build/react-ts/P";
import "@govtnz/ds/build/css/P.css"; // or @govtnz/ds/build/scss/P.scss
import CheckboxBlock from "@govtnz/ds/build/react-ts/CheckboxBlock";
import "@govtnz/ds/build/css/CheckboxBlock.css"; // or @govtnz/ds/build/scss/CheckboxBlock.scss
export default () => (
<FieldsetBlock
legend={
<H1 styleSize="large" id="providerChoiceTitle1" marginBottom8>
Who are your providers?
</H1>
}
hint={<P>Select all that apply.</P>}
hintId="hintId1"
>
<CheckboxBlock
label="Aardvark Access"
id="anyCheckboxId1"
value="provider1"
name="providerChoice1"
/>
<CheckboxBlock
label="Bumblebee Business"
id="anyCheckboxId2"
value="provider2"
name="providerChoice1"
/>
<CheckboxBlock
label="Caterpillar Company"
id="anyCheckboxId3"
value="provider3"
name="providerChoice1"
/>
</FieldsetBlock>
);
React with Styled Components (JavaScript) import React from "react";
import FieldsetBlock from "@govtnz/ds/build/react-js-styled-components/FieldsetBlock";
import H1 from "@govtnz/ds/build/react-js-styled-components/H1";
import P from "@govtnz/ds/build/react-js-styled-components/P";
import CheckboxBlock from "@govtnz/ds/build/react-js-styled-components/CheckboxBlock";
export default () => (
<FieldsetBlock
legend={
<H1 styleSize="large" id="providerChoiceTitle1" marginBottom8>
Who are your providers?
</H1>
}
hint={<P>Select all that apply.</P>}
hintId="hintId1"
>
<CheckboxBlock
label="Aardvark Access"
id="anyCheckboxId1"
value="provider1"
name="providerChoice1"
/>
<CheckboxBlock
label="Bumblebee Business"
id="anyCheckboxId2"
value="provider2"
name="providerChoice1"
/>
<CheckboxBlock
label="Caterpillar Company"
id="anyCheckboxId3"
value="provider3"
name="providerChoice1"
/>
</FieldsetBlock>
);
React with Styled Components (TypeScript) import React from "react";
import FieldsetBlock from "@govtnz/ds/build/react-ts-styled-components/FieldsetBlock";
import H1 from "@govtnz/ds/build/react-ts-styled-components/H1";
import P from "@govtnz/ds/build/react-ts-styled-components/P";
import CheckboxBlock from "@govtnz/ds/build/react-ts-styled-components/CheckboxBlock";
export default () => (
<FieldsetBlock
legend={
<H1 styleSize="large" id="providerChoiceTitle1" marginBottom8>
Who are your providers?
</H1>
}
hint={<P>Select all that apply.</P>}
hintId="hintId1"
>
<CheckboxBlock
label="Aardvark Access"
id="anyCheckboxId1"
value="provider1"
name="providerChoice1"
/>
<CheckboxBlock
label="Bumblebee Business"
id="anyCheckboxId2"
value="provider2"
name="providerChoice1"
/>
<CheckboxBlock
label="Caterpillar Company"
id="anyCheckboxId3"
value="provider3"
name="providerChoice1"
/>
</FieldsetBlock>
);
Vue (JavaScript) <template>
<fieldset-block
legend="Who are your providers?"
hint="Select all that apply."
hintId="hintId1"
>
<checkbox-block
label="Aardvark Access"
id="anyCheckboxId1"
value="provider1"
name="providerChoice1"
/>
<checkbox-block
label="Bumblebee Business"
id="anyCheckboxId2"
value="provider2"
name="providerChoice1"
/>
<checkbox-block
label="Caterpillar Company"
id="anyCheckboxId3"
value="provider3"
name="providerChoice1"
/>
</fieldset-block>
</template>
<script>
import Vue from "vue";
import FieldsetBlock from "@govtnz/ds/build/vue-js/FieldsetBlock.vue";
import H1 from "@govtnz/ds/build/vue-js/H1.vue";
import P from "@govtnz/ds/build/vue-js/P.vue";
import CheckboxBlock from "@govtnz/ds/build/vue-js/CheckboxBlock.vue";
export default {
components: {
"fieldset-block": FieldsetBlock,
"c-h1": H1,
"c-p": P,
"checkbox-block": CheckboxBlock
}
};
</script>
Vue (TypeScript) <template>
<fieldset-block
legend="Who are your providers?"
hint="Select all that apply."
hintId="hintId1"
>
<checkbox-block
label="Aardvark Access"
id="anyCheckboxId1"
value="provider1"
name="providerChoice1"
/>
<checkbox-block
label="Bumblebee Business"
id="anyCheckboxId2"
value="provider2"
name="providerChoice1"
/>
<checkbox-block
label="Caterpillar Company"
id="anyCheckboxId3"
value="provider3"
name="providerChoice1"
/>
</fieldset-block>
</template>
<script lang="ts">
import Vue from "vue";
import FieldsetBlock from "@govtnz/ds/build/vue-ts/FieldsetBlock.vue";
import H1 from "@govtnz/ds/build/vue-ts/H1.vue";
import P from "@govtnz/ds/build/vue-ts/P.vue";
import CheckboxBlock from "@govtnz/ds/build/vue-ts/CheckboxBlock.vue";
export default {
components: {
"fieldset-block": FieldsetBlock,
"c-h1": H1,
"c-p": P,
"checkbox-block": CheckboxBlock
}
};
</script>
HTML <!--
Remember to add these styles:
in CSS: FieldsetBlock.css, H1.css, P.css, CheckboxBlock.css
OR in Sass (SCSS): FieldsetBlock.scss, H1.scss, P.scss, CheckboxBlock.scss
-->
<div class="g-fieldsetBlock-form-group">
<fieldset class="g-fieldsetBlock-fieldset" aria-describedby="hintId1">
<legend class="g-fieldsetBlock-fieldset__legend">
<h1
class="g-heading g-heading-l g-heading-mb-8"
id="providerChoiceTitle1"
>
Who are your providers?
</h1>
</legend>
<div class="g-fieldsetBlock-hint" id="hintId1">
<p class="g-body">Select all that apply.</p>
</div>
<div>
<div class="g-checkboxes__item">
<input
class="g-checkboxes__input"
id="anyCheckboxId1"
type="checkbox"
name="providerChoice1"
value="provider1"
/>
<label class="g-checkboxes__label" for="anyCheckboxId1">
Aardvark Access
</label>
</div>
<div class="g-checkboxes__item">
<input
class="g-checkboxes__input"
id="anyCheckboxId2"
type="checkbox"
name="providerChoice1"
value="provider2"
/>
<label class="g-checkboxes__label" for="anyCheckboxId2">
Bumblebee Business
</label>
</div>
<div class="g-checkboxes__item">
<input
class="g-checkboxes__input"
id="anyCheckboxId3"
type="checkbox"
name="providerChoice1"
value="provider3"
/>
<label class="g-checkboxes__label" for="anyCheckboxId3">
Caterpillar Company
</label>
</div>
</div>
</fieldset>
</div>
twig-embed {% embed "FieldsetBlock.html.twig" with {'hintId':'hintId1'} only %}{% block legend %}{% embed "H1.html.twig" with {'styleSize':'large', 'id':'providerChoiceTitle1', 'marginBottom8':'true', 'children':'Who are your providers?'} only %}{% endembed %}{% endblock %}{% block hint %}{% embed "P.html.twig" with {'children':'Select all that apply.'} only %}{% endembed %}{% endblock %}{% block children %}{% embed "CheckboxBlock.html.twig" with {'label':'Aardvark Access', 'id':'anyCheckboxId1', 'value':'provider1', 'name':'providerChoice1'} only %}{% endembed %}
{% embed "CheckboxBlock.html.twig" with {'label':'Bumblebee Business', 'id':'anyCheckboxId2', 'value':'provider2', 'name':'providerChoice1'} only %}{% endembed %}
{% embed "CheckboxBlock.html.twig" with {'label':'Caterpillar Company', 'id':'anyCheckboxId3', 'value':'provider3', 'name':'providerChoice1'} only %}{% endembed %}{% endblock %}{% endembed %}
Error
Code Mustache / Handlebars // Developer note: ensure your ".mustache" files are imported as plain text. In Webpack you might use https://github.com/webpack-contrib/raw-loader
import Mustache from "mustache";
import FieldsetBlock from "@govtnz/ds/build/mustache/FieldsetBlock.mustache";
import H1 from "@govtnz/ds/build/mustache/H1.mustache";
import P from "@govtnz/ds/build/mustache/P.mustache";
import CheckboxBlock from "@govtnz/ds/build/mustache/CheckboxBlock.mustache";
// The variables FieldsetBlock, H1, P, CheckboxBlock are all strings that are mustache templates.
export default `${Mustache.render(FieldsetBlock, {
legend: `${Mustache.render(H1, {
"styleSize=large": true,
styleSize: true,
id: `providerChoiceTitle2`,
marginBottom8: ``,
children: `Who are your providers?`
})}`,
hint: `${Mustache.render(P, { children: `Select all that apply.` })}`,
hintId: `hintId21`,
errorId: true,
error: `You must choose at least one provider.`,
children: `${Mustache.render(CheckboxBlock, {
label: `Aardvark Access`,
id: `anyCheckboxId21`,
value: `provider1`,
name: `providerChoice2`
})}${Mustache.render(CheckboxBlock, {
label: `Bumblebee Business`,
id: `kboxId22`,
value: `provider2`,
name: `providerChoice2`
})}${Mustache.render(CheckboxBlock, {
label: `Caterpillar Company`,
id: `anyCheckboxId23`,
value: `provider3`,
name: `providerChoice2`,
labelId: `labelId23`
})}`
})}`;
React (JavaScript) import React from "react";
import FieldsetBlock from "@govtnz/ds/build/react-js/FieldsetBlock";
import "@govtnz/ds/build/css/FieldsetBlock.css"; // or @govtnz/ds/build/scss/FieldsetBlock.scss
import H1 from "@govtnz/ds/build/react-js/H1";
import "@govtnz/ds/build/css/H1.css"; // or @govtnz/ds/build/scss/H1.scss
import P from "@govtnz/ds/build/react-js/P";
import "@govtnz/ds/build/css/P.css"; // or @govtnz/ds/build/scss/P.scss
import CheckboxBlock from "@govtnz/ds/build/react-js/CheckboxBlock";
import "@govtnz/ds/build/css/CheckboxBlock.css"; // or @govtnz/ds/build/scss/CheckboxBlock.scss
export default () => (
<FieldsetBlock
legend={
<H1 styleSize="large" id="providerChoiceTitle2" marginBottom8>
Who are your providers?
</H1>
}
hint={<P>Select all that apply.</P>}
hintId="hintId21"
errorId="errorId21"
error="You must choose at least one provider."
>
<CheckboxBlock
label="Aardvark Access"
id="anyCheckboxId21"
value="provider1"
name="providerChoice2"
/>
<CheckboxBlock
label="Bumblebee Business"
id="kboxId22"
value="provider2"
name="providerChoice2"
/>
<CheckboxBlock
label="Caterpillar Company"
id="anyCheckboxId23"
value="provider3"
name="providerChoice2"
labelId="labelId23"
/>
</FieldsetBlock>
);
React (TypeScript) import React from "react";
import FieldsetBlock from "@govtnz/ds/build/react-ts/FieldsetBlock";
import "@govtnz/ds/build/css/FieldsetBlock.css"; // or @govtnz/ds/build/scss/FieldsetBlock.scss
import H1 from "@govtnz/ds/build/react-ts/H1";
import "@govtnz/ds/build/css/H1.css"; // or @govtnz/ds/build/scss/H1.scss
import P from "@govtnz/ds/build/react-ts/P";
import "@govtnz/ds/build/css/P.css"; // or @govtnz/ds/build/scss/P.scss
import CheckboxBlock from "@govtnz/ds/build/react-ts/CheckboxBlock";
import "@govtnz/ds/build/css/CheckboxBlock.css"; // or @govtnz/ds/build/scss/CheckboxBlock.scss
export default () => (
<FieldsetBlock
legend={
<H1 styleSize="large" id="providerChoiceTitle2" marginBottom8>
Who are your providers?
</H1>
}
hint={<P>Select all that apply.</P>}
hintId="hintId21"
errorId="errorId21"
error="You must choose at least one provider."
>
<CheckboxBlock
label="Aardvark Access"
id="anyCheckboxId21"
value="provider1"
name="providerChoice2"
/>
<CheckboxBlock
label="Bumblebee Business"
id="kboxId22"
value="provider2"
name="providerChoice2"
/>
<CheckboxBlock
label="Caterpillar Company"
id="anyCheckboxId23"
value="provider3"
name="providerChoice2"
labelId="labelId23"
/>
</FieldsetBlock>
);
React with Styled Components (JavaScript) import React from "react";
import FieldsetBlock from "@govtnz/ds/build/react-js-styled-components/FieldsetBlock";
import H1 from "@govtnz/ds/build/react-js-styled-components/H1";
import P from "@govtnz/ds/build/react-js-styled-components/P";
import CheckboxBlock from "@govtnz/ds/build/react-js-styled-components/CheckboxBlock";
export default () => (
<FieldsetBlock
legend={
<H1 styleSize="large" id="providerChoiceTitle2" marginBottom8>
Who are your providers?
</H1>
}
hint={<P>Select all that apply.</P>}
hintId="hintId21"
errorId="errorId21"
error="You must choose at least one provider."
>
<CheckboxBlock
label="Aardvark Access"
id="anyCheckboxId21"
value="provider1"
name="providerChoice2"
/>
<CheckboxBlock
label="Bumblebee Business"
id="kboxId22"
value="provider2"
name="providerChoice2"
/>
<CheckboxBlock
label="Caterpillar Company"
id="anyCheckboxId23"
value="provider3"
name="providerChoice2"
labelId="labelId23"
/>
</FieldsetBlock>
);
React with Styled Components (TypeScript) import React from "react";
import FieldsetBlock from "@govtnz/ds/build/react-ts-styled-components/FieldsetBlock";
import H1 from "@govtnz/ds/build/react-ts-styled-components/H1";
import P from "@govtnz/ds/build/react-ts-styled-components/P";
import CheckboxBlock from "@govtnz/ds/build/react-ts-styled-components/CheckboxBlock";
export default () => (
<FieldsetBlock
legend={
<H1 styleSize="large" id="providerChoiceTitle2" marginBottom8>
Who are your providers?
</H1>
}
hint={<P>Select all that apply.</P>}
hintId="hintId21"
errorId="errorId21"
error="You must choose at least one provider."
>
<CheckboxBlock
label="Aardvark Access"
id="anyCheckboxId21"
value="provider1"
name="providerChoice2"
/>
<CheckboxBlock
label="Bumblebee Business"
id="kboxId22"
value="provider2"
name="providerChoice2"
/>
<CheckboxBlock
label="Caterpillar Company"
id="anyCheckboxId23"
value="provider3"
name="providerChoice2"
labelId="labelId23"
/>
</FieldsetBlock>
);
Vue (JavaScript) <template>
<fieldset-block
legend="Who are your providers?"
hint="Select all that apply."
hintId="hintId21"
errorId="errorId21"
error="You must choose at least one provider."
>
<checkbox-block
label="Aardvark Access"
id="anyCheckboxId21"
value="provider1"
name="providerChoice2"
/>
<checkbox-block
label="Bumblebee Business"
id="kboxId22"
value="provider2"
name="providerChoice2"
/>
<checkbox-block
label="Caterpillar Company"
id="anyCheckboxId23"
value="provider3"
name="providerChoice2"
labelId="labelId23"
/>
</fieldset-block>
</template>
<script>
import Vue from "vue";
import FieldsetBlock from "@govtnz/ds/build/vue-js/FieldsetBlock.vue";
import H1 from "@govtnz/ds/build/vue-js/H1.vue";
import P from "@govtnz/ds/build/vue-js/P.vue";
import CheckboxBlock from "@govtnz/ds/build/vue-js/CheckboxBlock.vue";
export default {
components: {
"fieldset-block": FieldsetBlock,
"c-h1": H1,
"c-p": P,
"checkbox-block": CheckboxBlock
}
};
</script>
Vue (TypeScript) <template>
<fieldset-block
legend="Who are your providers?"
hint="Select all that apply."
hintId="hintId21"
errorId="errorId21"
error="You must choose at least one provider."
>
<checkbox-block
label="Aardvark Access"
id="anyCheckboxId21"
value="provider1"
name="providerChoice2"
/>
<checkbox-block
label="Bumblebee Business"
id="kboxId22"
value="provider2"
name="providerChoice2"
/>
<checkbox-block
label="Caterpillar Company"
id="anyCheckboxId23"
value="provider3"
name="providerChoice2"
labelId="labelId23"
/>
</fieldset-block>
</template>
<script lang="ts">
import Vue from "vue";
import FieldsetBlock from "@govtnz/ds/build/vue-ts/FieldsetBlock.vue";
import H1 from "@govtnz/ds/build/vue-ts/H1.vue";
import P from "@govtnz/ds/build/vue-ts/P.vue";
import CheckboxBlock from "@govtnz/ds/build/vue-ts/CheckboxBlock.vue";
export default {
components: {
"fieldset-block": FieldsetBlock,
"c-h1": H1,
"c-p": P,
"checkbox-block": CheckboxBlock
}
};
</script>
HTML <!--
Remember to add these styles:
in CSS: FieldsetBlock.css, H1.css, P.css, CheckboxBlock.css
OR in Sass (SCSS): FieldsetBlock.scss, H1.scss, P.scss, CheckboxBlock.scss
-->
<div class="g-fieldsetBlock-form-group">
<fieldset
class="g-fieldsetBlock-fieldset"
aria-describedby="hintId21 errorId21"
>
<legend class="g-fieldsetBlock-fieldset__legend">
<h1
class="g-heading g-heading-l g-heading-mb-8"
id="providerChoiceTitle2"
>
Who are your providers?
</h1>
</legend>
<div class="g-fieldsetBlock-hint" id="hintId21">
<p class="g-body">Select all that apply.</p>
</div>
<div class="g-fieldsetBlock-error-message" id="errorId21">
<span class="g-fieldsetBlock-visually-hidden"> Error: </span> You must
choose at least one provider.
</div>
<div>
<div class="g-checkboxes__item">
<input
class="g-checkboxes__input"
id="anyCheckboxId21"
type="checkbox"
name="providerChoice2"
value="provider1"
/>
<label class="g-checkboxes__label" for="anyCheckboxId21">
Aardvark Access
</label>
</div>
<div class="g-checkboxes__item">
<input
class="g-checkboxes__input"
id="kboxId22"
type="checkbox"
name="providerChoice2"
value="provider2"
/>
<label class="g-checkboxes__label" for="kboxId22">
Bumblebee Business
</label>
</div>
<div class="g-checkboxes__item">
<input
class="g-checkboxes__input"
id="anyCheckboxId23"
type="checkbox"
name="providerChoice2"
value="provider3"
/>
<label class="g-checkboxes__label" for="anyCheckboxId23">
Caterpillar Company
</label>
</div>
</div>
</fieldset>
</div>
twig-embed {% embed "FieldsetBlock.html.twig" with {'hintId':'hintId21', 'errorId':'errorId21', 'error':'You must choose at least one provider.'} only %}{% block legend %}{% embed "H1.html.twig" with {'styleSize':'large', 'id':'providerChoiceTitle2', 'marginBottom8':'true', 'children':'Who are your providers?'} only %}{% endembed %}{% endblock %}{% block hint %}{% embed "P.html.twig" with {'children':'Select all that apply.'} only %}{% endembed %}{% endblock %}{% block children %}{% embed "CheckboxBlock.html.twig" with {'label':'Aardvark Access', 'id':'anyCheckboxId21', 'value':'provider1', 'name':'providerChoice2'} only %}{% endembed %}
{% embed "CheckboxBlock.html.twig" with {'label':'Bumblebee Business', 'id':'kboxId22', 'value':'provider2', 'name':'providerChoice2'} only %}{% endembed %}
{% embed "CheckboxBlock.html.twig" with {'label':'Caterpillar Company', 'id':'anyCheckboxId23', 'value':'provider3', 'name':'providerChoice2', 'labelId':'labelId23'} only %}{% endembed %}{% endblock %}{% endembed %}
Checkboxes with hints
Code Mustache / Handlebars // Developer note: ensure your ".mustache" files are imported as plain text. In Webpack you might use https://github.com/webpack-contrib/raw-loader
import Mustache from "mustache";
import FieldsetBlock from "@govtnz/ds/build/mustache/FieldsetBlock.mustache";
import H1 from "@govtnz/ds/build/mustache/H1.mustache";
import P from "@govtnz/ds/build/mustache/P.mustache";
import CheckboxBlock from "@govtnz/ds/build/mustache/CheckboxBlock.mustache";
// The variables FieldsetBlock, H1, P, CheckboxBlock are all strings that are mustache templates.
export default `${Mustache.render(FieldsetBlock, {
legend: `${Mustache.render(H1, {
"styleSize=large": true,
styleSize: true,
id: `providerChoiceTitle3`,
marginBottom8: ``,
children: `Who are your providers?`
})}`,
hint: `${Mustache.render(P, { children: `Select all that apply.` })}`,
hintId: `hintId3`,
children: `${Mustache.render(CheckboxBlock, {
label: `Aardvark Access`,
id: `anyCheckboxId31`,
value: `provider1`,
name: `providerChoice3`,
labelId: `labelId31`,
hintId: `hintId31`,
hint: `Aardvark Access provides internet`
})}${Mustache.render(CheckboxBlock, {
label: `Bumblebee Business`,
id: `anyCheckboxId32`,
value: `provider2`,
name: `providerChoice3`,
labelId: `labelId32`,
hintId: `hintId32`,
hint: `Bumblebee Business provides electricity`
})}${Mustache.render(CheckboxBlock, {
label: `Caterpillar Company`,
id: `anyCheckboxId33`,
value: `provider3`,
name: `providerChoice3`,
labelId: `labelId33`,
hintId: `hintId33`,
hint: `Caterpillar Company provides telephone`
})}`
})}`;
React (JavaScript) import React from "react";
import FieldsetBlock from "@govtnz/ds/build/react-js/FieldsetBlock";
import "@govtnz/ds/build/css/FieldsetBlock.css"; // or @govtnz/ds/build/scss/FieldsetBlock.scss
import H1 from "@govtnz/ds/build/react-js/H1";
import "@govtnz/ds/build/css/H1.css"; // or @govtnz/ds/build/scss/H1.scss
import P from "@govtnz/ds/build/react-js/P";
import "@govtnz/ds/build/css/P.css"; // or @govtnz/ds/build/scss/P.scss
import CheckboxBlock from "@govtnz/ds/build/react-js/CheckboxBlock";
import "@govtnz/ds/build/css/CheckboxBlock.css"; // or @govtnz/ds/build/scss/CheckboxBlock.scss
export default () => (
<FieldsetBlock
legend={
<H1 styleSize="large" id="providerChoiceTitle3" marginBottom8>
Who are your providers?
</H1>
}
hint={<P>Select all that apply.</P>}
hintId="hintId3"
>
<CheckboxBlock
label="Aardvark Access"
id="anyCheckboxId31"
value="provider1"
name="providerChoice3"
labelId="labelId31"
hintId="hintId31"
hint="Aardvark Access provides internet"
/>
<CheckboxBlock
label="Bumblebee Business"
id="anyCheckboxId32"
value="provider2"
name="providerChoice3"
labelId="labelId32"
hintId="hintId32"
hint="Bumblebee Business provides electricity"
/>
<CheckboxBlock
label="Caterpillar Company"
id="anyCheckboxId33"
value="provider3"
name="providerChoice3"
labelId="labelId33"
hintId="hintId33"
hint="Caterpillar Company provides telephone"
/>
</FieldsetBlock>
);
React (TypeScript) import React from "react";
import FieldsetBlock from "@govtnz/ds/build/react-ts/FieldsetBlock";
import "@govtnz/ds/build/css/FieldsetBlock.css"; // or @govtnz/ds/build/scss/FieldsetBlock.scss
import H1 from "@govtnz/ds/build/react-ts/H1";
import "@govtnz/ds/build/css/H1.css"; // or @govtnz/ds/build/scss/H1.scss
import P from "@govtnz/ds/build/react-ts/P";
import "@govtnz/ds/build/css/P.css"; // or @govtnz/ds/build/scss/P.scss
import CheckboxBlock from "@govtnz/ds/build/react-ts/CheckboxBlock";
import "@govtnz/ds/build/css/CheckboxBlock.css"; // or @govtnz/ds/build/scss/CheckboxBlock.scss
export default () => (
<FieldsetBlock
legend={
<H1 styleSize="large" id="providerChoiceTitle3" marginBottom8>
Who are your providers?
</H1>
}
hint={<P>Select all that apply.</P>}
hintId="hintId3"
>
<CheckboxBlock
label="Aardvark Access"
id="anyCheckboxId31"
value="provider1"
name="providerChoice3"
labelId="labelId31"
hintId="hintId31"
hint="Aardvark Access provides internet"
/>
<CheckboxBlock
label="Bumblebee Business"
id="anyCheckboxId32"
value="provider2"
name="providerChoice3"
labelId="labelId32"
hintId="hintId32"
hint="Bumblebee Business provides electricity"
/>
<CheckboxBlock
label="Caterpillar Company"
id="anyCheckboxId33"
value="provider3"
name="providerChoice3"
labelId="labelId33"
hintId="hintId33"
hint="Caterpillar Company provides telephone"
/>
</FieldsetBlock>
);
React with Styled Components (JavaScript) import React from "react";
import FieldsetBlock from "@govtnz/ds/build/react-js-styled-components/FieldsetBlock";
import H1 from "@govtnz/ds/build/react-js-styled-components/H1";
import P from "@govtnz/ds/build/react-js-styled-components/P";
import CheckboxBlock from "@govtnz/ds/build/react-js-styled-components/CheckboxBlock";
export default () => (
<FieldsetBlock
legend={
<H1 styleSize="large" id="providerChoiceTitle3" marginBottom8>
Who are your providers?
</H1>
}
hint={<P>Select all that apply.</P>}
hintId="hintId3"
>
<CheckboxBlock
label="Aardvark Access"
id="anyCheckboxId31"
value="provider1"
name="providerChoice3"
labelId="labelId31"
hintId="hintId31"
hint="Aardvark Access provides internet"
/>
<CheckboxBlock
label="Bumblebee Business"
id="anyCheckboxId32"
value="provider2"
name="providerChoice3"
labelId="labelId32"
hintId="hintId32"
hint="Bumblebee Business provides electricity"
/>
<CheckboxBlock
label="Caterpillar Company"
id="anyCheckboxId33"
value="provider3"
name="providerChoice3"
labelId="labelId33"
hintId="hintId33"
hint="Caterpillar Company provides telephone"
/>
</FieldsetBlock>
);
React with Styled Components (TypeScript) import React from "react";
import FieldsetBlock from "@govtnz/ds/build/react-ts-styled-components/FieldsetBlock";
import H1 from "@govtnz/ds/build/react-ts-styled-components/H1";
import P from "@govtnz/ds/build/react-ts-styled-components/P";
import CheckboxBlock from "@govtnz/ds/build/react-ts-styled-components/CheckboxBlock";
export default () => (
<FieldsetBlock
legend={
<H1 styleSize="large" id="providerChoiceTitle3" marginBottom8>
Who are your providers?
</H1>
}
hint={<P>Select all that apply.</P>}
hintId="hintId3"
>
<CheckboxBlock
label="Aardvark Access"
id="anyCheckboxId31"
value="provider1"
name="providerChoice3"
labelId="labelId31"
hintId="hintId31"
hint="Aardvark Access provides internet"
/>
<CheckboxBlock
label="Bumblebee Business"
id="anyCheckboxId32"
value="provider2"
name="providerChoice3"
labelId="labelId32"
hintId="hintId32"
hint="Bumblebee Business provides electricity"
/>
<CheckboxBlock
label="Caterpillar Company"
id="anyCheckboxId33"
value="provider3"
name="providerChoice3"
labelId="labelId33"
hintId="hintId33"
hint="Caterpillar Company provides telephone"
/>
</FieldsetBlock>
);
Vue (JavaScript) <template>
<fieldset-block
legend="Who are your providers?"
hint="Select all that apply."
hintId="hintId3"
>
<checkbox-block
label="Aardvark Access"
id="anyCheckboxId31"
value="provider1"
name="providerChoice3"
labelId="labelId31"
hintId="hintId31"
hint="Aardvark Access provides internet"
/>
<checkbox-block
label="Bumblebee Business"
id="anyCheckboxId32"
value="provider2"
name="providerChoice3"
labelId="labelId32"
hintId="hintId32"
hint="Bumblebee Business provides electricity"
/>
<checkbox-block
label="Caterpillar Company"
id="anyCheckboxId33"
value="provider3"
name="providerChoice3"
labelId="labelId33"
hintId="hintId33"
hint="Caterpillar Company provides telephone"
/>
</fieldset-block>
</template>
<script>
import Vue from "vue";
import FieldsetBlock from "@govtnz/ds/build/vue-js/FieldsetBlock.vue";
import H1 from "@govtnz/ds/build/vue-js/H1.vue";
import P from "@govtnz/ds/build/vue-js/P.vue";
import CheckboxBlock from "@govtnz/ds/build/vue-js/CheckboxBlock.vue";
export default {
components: {
"fieldset-block": FieldsetBlock,
"c-h1": H1,
"c-p": P,
"checkbox-block": CheckboxBlock
}
};
</script>
Vue (TypeScript) <template>
<fieldset-block
legend="Who are your providers?"
hint="Select all that apply."
hintId="hintId3"
>
<checkbox-block
label="Aardvark Access"
id="anyCheckboxId31"
value="provider1"
name="providerChoice3"
labelId="labelId31"
hintId="hintId31"
hint="Aardvark Access provides internet"
/>
<checkbox-block
label="Bumblebee Business"
id="anyCheckboxId32"
value="provider2"
name="providerChoice3"
labelId="labelId32"
hintId="hintId32"
hint="Bumblebee Business provides electricity"
/>
<checkbox-block
label="Caterpillar Company"
id="anyCheckboxId33"
value="provider3"
name="providerChoice3"
labelId="labelId33"
hintId="hintId33"
hint="Caterpillar Company provides telephone"
/>
</fieldset-block>
</template>
<script lang="ts">
import Vue from "vue";
import FieldsetBlock from "@govtnz/ds/build/vue-ts/FieldsetBlock.vue";
import H1 from "@govtnz/ds/build/vue-ts/H1.vue";
import P from "@govtnz/ds/build/vue-ts/P.vue";
import CheckboxBlock from "@govtnz/ds/build/vue-ts/CheckboxBlock.vue";
export default {
components: {
"fieldset-block": FieldsetBlock,
"c-h1": H1,
"c-p": P,
"checkbox-block": CheckboxBlock
}
};
</script>
HTML <!--
Remember to add these styles:
in CSS: FieldsetBlock.css, H1.css, P.css, CheckboxBlock.css
OR in Sass (SCSS): FieldsetBlock.scss, H1.scss, P.scss, CheckboxBlock.scss
-->
<div class="g-fieldsetBlock-form-group">
<fieldset class="g-fieldsetBlock-fieldset" aria-describedby="hintId3">
<legend class="g-fieldsetBlock-fieldset__legend">
<h1
class="g-heading g-heading-l g-heading-mb-8"
id="providerChoiceTitle3"
>
Who are your providers?
</h1>
</legend>
<div class="g-fieldsetBlock-hint" id="hintId3">
<p class="g-body">Select all that apply.</p>
</div>
<div>
<div class="g-checkboxes__item">
<input
class="g-checkboxes__input"
id="anyCheckboxId31"
type="checkbox"
aria-describedby="hintId31"
name="providerChoice3"
value="provider1"
/>
<label class="g-checkboxes__label" for="anyCheckboxId31">
Aardvark Access
</label>
<div class="g-checkboxes__hint" id="hintId31">
Aardvark Access provides internet
</div>
</div>
<div class="g-checkboxes__item">
<input
class="g-checkboxes__input"
id="anyCheckboxId32"
type="checkbox"
aria-describedby="hintId32"
name="providerChoice3"
value="provider2"
/>
<label class="g-checkboxes__label" for="anyCheckboxId32">
Bumblebee Business
</label>
<div class="g-checkboxes__hint" id="hintId32">
Bumblebee Business provides electricity
</div>
</div>
<div class="g-checkboxes__item">
<input
class="g-checkboxes__input"
id="anyCheckboxId33"
type="checkbox"
aria-describedby="hintId33"
name="providerChoice3"
value="provider3"
/>
<label class="g-checkboxes__label" for="anyCheckboxId33">
Caterpillar Company
</label>
<div class="g-checkboxes__hint" id="hintId33">
Caterpillar Company provides telephone
</div>
</div>
</div>
</fieldset>
</div>
twig-embed {% embed "FieldsetBlock.html.twig" with {'hintId':'hintId3'} only %}{% block legend %}{% embed "H1.html.twig" with {'styleSize':'large', 'id':'providerChoiceTitle3', 'marginBottom8':'true', 'children':'Who are your providers?'} only %}{% endembed %}{% endblock %}{% block hint %}{% embed "P.html.twig" with {'children':'Select all that apply.'} only %}{% endembed %}{% endblock %}{% block children %}{% embed "CheckboxBlock.html.twig" with {'label':'Aardvark Access', 'id':'anyCheckboxId31', 'value':'provider1', 'name':'providerChoice3', 'labelId':'labelId31', 'hintId':'hintId31', 'hint':'Aardvark Access provides internet'} only %}{% endembed %}
{% embed "CheckboxBlock.html.twig" with {'label':'Bumblebee Business', 'id':'anyCheckboxId32', 'value':'provider2', 'name':'providerChoice3', 'labelId':'labelId32', 'hintId':'hintId32', 'hint':'Bumblebee Business provides electricity'} only %}{% endembed %}
{% embed "CheckboxBlock.html.twig" with {'label':'Caterpillar Company', 'id':'anyCheckboxId33', 'value':'provider3', 'name':'providerChoice3', 'labelId':'labelId33', 'hintId':'hintId33', 'hint':'Caterpillar Company provides telephone'} only %}{% endembed %}{% endblock %}{% endembed %}
When to use it Use the checkboxes component when you need to help users:
select one or more options from a list toggle a single option on or off. When not to use it Do not use the checkboxes component if users can only choose one option from a selection. In this case, use radio buttons instead.
How it works Checkboxes are grouped together in a <fieldset>
with a <legend>
that describes them, as shown in the examples on this page. This is usually a question, like ‘Who are your providers?’.
If you are asking just one question per page, you can set the contents of the <legend>
as the page heading. This is good practice because users of screen readers will only hear the contents once.
Always position each checkbox to the left of its label. This makes it easier to find, especially for users of screen magnifiers.
Unlike with radio buttons, users can select multiple checkboxes from a list. Do not assume that users will know how many checkboxes they can select based on only the visual difference between radio buttons and checkboxes.
If needed, add a hint to explain this, like ‘Select all that apply’.
Do not pre-select checkboxes as users are likely to:
not realise they’ve missed a question submit the wrong answer. Order checkbox labels alphabetically by default.
In some cases, pre-selected ordering can be helpful, such as listing options from the most to the least common. An example is ordering answers to the question ‘What is your nationality?’ based on population size.
Another example of pre-selected ordering is listing options chronologically. For example, you could order possible time periods for contact from earliest to latest, so users can select the periods that suit them best.
However, using pre-selected ordering could reinforce bias in your service, so use it with caution. If in doubt, order alphabetically.
Credit Guidance, original HTML and CSS derived from GOV.UK Design System .
Get in touch If you’ve got a question, idea, or suggestion, email the Design System (DS) team at info@digital.govt.nz , use our NZGDS Slack app , or discuss Checkboxes on 'GitHub issues'.