Skip to main content Skip to list of components
Service phase: Beta

This is a new service – give us your feedback to help improve it.

Components

Checkboxes

Checkboxes allow users to post multiple options for the same field.

Contents

  1. Component status
  2. Small
  3. Preselected
  4. Hint
  5. Error
  6. Inline
  7. Single
Open this example in new tab

HTML

<div class="tna-fieldset tna-fieldset--small-hint">
  <fieldset class="tna-fieldset__inner">
    <legend class="tna-fieldset__legend">
      <h4 class="tna-fieldset__heading tna-heading-m">
        Categories
      </h4>
    </legend>
    <div class="tna-fieldset__body">
      <div class="tna-checkboxes" id="categories">
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-alpha" value="alpha" name="categories">
          <label for="categories-alpha" class="tna-checkboxes__item-label">
            Alpha
          </label>
        </div>
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-beta" value="beta" name="categories">
          <label for="categories-beta" class="tna-checkboxes__item-label">
            Beta
          </label>
        </div>
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-gamma" value="gamma" name="categories">
          <label for="categories-gamma" class="tna-checkboxes__item-label">
            Gamma
          </label>
        </div>
      </div>
    </div>
  </fieldset>
</div>

Nunjucks

Nunjucks options
Primary options
Name Type Description
label string

The label for the checkboxes field. Required if there are multiple checkboxes. Optional for only one checkbox.

headingLevel number

The heading level which represents an element from <h1> through to <h6>. Leave blank or set to 0 to use a plain <label> element with no heading.

headingSize string

The physical size of the checkboxes title (xl, l, m, s or xs).

Default value: m

id string

Required.

A unique ID for the checkboxes component.

name string

Required.

The name of the form field.

hint string

An optional hint to display above the form field.

error object

If set, the details of any errors.

See macro options for error.

items array

Required.

A list of checkbox items.

See macro options for items.

small boolean

If true, show smaller checkboxes.

inline boolean

If true, show the checkboxes inline rather than vertical.

formItemClasses string

Classes to add to the checkboxes form group.

formItemAttributes object

HTML attributes (for example data attributes) to add to the checkboxes form group.

fieldsetClasses string

Classes to add to the <fieldset> element when there is more than one item.

fieldsetAttributes object

HTML attributes (for example data attributes) to add to the <fieldset> element when there is more than one item.

classes string

Classes to add to the checkbox elements.

attributes object

HTML attributes (for example data attributes) to add to the checkbox elements.

Options for error
Name Type Description
text string

Required.

The error text to display.

Options for items
Name Type Description
text string

Required.

The label of the checkbox item.

value string

Required.

The form field value.

name string

The name of the form field item. If set, this will override the main name property.

checked boolean

If true, the checkbox will be checked.

{% from "nationalarchives/components/checkboxes/macro.njk" import tnaCheckboxes %}

{{ tnaCheckboxes({
  label: "Categories",
  headingLevel: 4,
  headingSize: "m",
  id: "categories",
  name: "categories",
  items: [
    {
      text: "Alpha",
      value: "alpha"
    },
    {
      text: "Beta",
      value: "beta"
    },
    {
      text: "Gamma",
      value: "gamma"
    }
  ]
}) }}

Jinja

Important information

This is an experimental feature that outputs a Jinja template based on the Nunjucks example. Check the converted code for accuracy.
{% from "components/checkboxes/macro.html" import tnaCheckboxes %}

{{ tnaCheckboxes({
  "label": "Categories",
  "headingLevel": 4,
  "headingSize": "m",
  "id": "categories",
  "name": "categories",
  "items": [
    {
      "text": "Alpha",
      "value": "alpha"
    },
    {
      "text": "Beta",
      "value": "beta"
    },
    {
      "text": "Gamma",
      "value": "gamma"
    }
  ]
}) }}
Phase
To be reviewed
Tested without CSS
Yes
Passed DAC audit
Not yet audied
Documentation complete
No
Open this example in new tab

HTML

<div class="tna-fieldset tna-fieldset--small-hint">
  <fieldset class="tna-fieldset__inner">
    <legend class="tna-fieldset__legend">
      <h4 class="tna-fieldset__heading tna-heading-m">
        Categories
      </h4>
    </legend>
    <div class="tna-fieldset__body">
      <div class="tna-checkboxes tna-checkboxes--small" id="categories">
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-ADM" value="ADM" name="categories">
          <label for="categories-ADM" class="tna-checkboxes__item-label">
            Admiralty, Navy, Royal Marines, and Coastguard
          </label>
        </div>
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-AIR" value="AIR" name="categories">
          <label for="categories-AIR" class="tna-checkboxes__item-label">
            Air Ministry and Royal Air Force records
          </label>
        </div>
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-BT" value="BT" name="categories">
          <label for="categories-BT" class="tna-checkboxes__item-label">
            Board of Trade and successors
          </label>
        </div>
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-C" value="C" name="categories">
          <label for="categories-C" class="tna-checkboxes__item-label">
            Chancery, the Wardrobe, Royal Household, Exchequer and various commissions
          </label>
        </div>
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-CO" value="CO" name="categories">
          <label for="categories-CO" class="tna-checkboxes__item-label">
            Colonial Office, Commonwealth and Foreign and Commonwealth Offices
          </label>
        </div>
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-E" value="E" name="categories">
          <label for="categories-E" class="tna-checkboxes__item-label">
            Exchequer, Office of First Fruits and Tenths, and the Court of Augmentations
          </label>
        </div>
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-FO" value="FO" name="categories">
          <label for="categories-FO" class="tna-checkboxes__item-label">
            Foreign Office
          </label>
        </div>
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-HO" value="HO" name="categories">
          <label for="categories-HO" class="tna-checkboxes__item-label">
            Home Office
          </label>
        </div>
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-PROB" value="PROB" name="categories">
          <label for="categories-PROB" class="tna-checkboxes__item-label">
            Prerogative Court of Canterbury
          </label>
        </div>
      </div>
    </div>
  </fieldset>
</div>

Nunjucks

Nunjucks options
Primary options
Name Type Description
label string

The label for the checkboxes field. Required if there are multiple checkboxes. Optional for only one checkbox.

headingLevel number

The heading level which represents an element from <h1> through to <h6>. Leave blank or set to 0 to use a plain <label> element with no heading.

headingSize string

The physical size of the checkboxes title (xl, l, m, s or xs).

Default value: m

id string

Required.

A unique ID for the checkboxes component.

name string

Required.

The name of the form field.

hint string

An optional hint to display above the form field.

error object

If set, the details of any errors.

See macro options for error.

items array

Required.

A list of checkbox items.

See macro options for items.

small boolean

If true, show smaller checkboxes.

inline boolean

If true, show the checkboxes inline rather than vertical.

formItemClasses string

Classes to add to the checkboxes form group.

formItemAttributes object

HTML attributes (for example data attributes) to add to the checkboxes form group.

fieldsetClasses string

Classes to add to the <fieldset> element when there is more than one item.

fieldsetAttributes object

HTML attributes (for example data attributes) to add to the <fieldset> element when there is more than one item.

classes string

Classes to add to the checkbox elements.

attributes object

HTML attributes (for example data attributes) to add to the checkbox elements.

Options for error
Name Type Description
text string

Required.

The error text to display.

Options for items
Name Type Description
text string

Required.

The label of the checkbox item.

value string

Required.

The form field value.

name string

The name of the form field item. If set, this will override the main name property.

checked boolean

If true, the checkbox will be checked.

{% from "nationalarchives/components/checkboxes/macro.njk" import tnaCheckboxes %}

{{ tnaCheckboxes({
  label: "Categories",
  headingLevel: 4,
  headingSize: "m",
  id: "categories",
  name: "categories",
  items: [
    {
      text: "Admiralty, Navy, Royal Marines, and Coastguard",
      value: "ADM"
    },
    {
      text: "Air Ministry and Royal Air Force records",
      value: "AIR"
    },
    {
      text: "Board of Trade and successors",
      value: "BT"
    },
    {
      text: "Chancery, the Wardrobe, Royal Household, Exchequer and various commissions",
      value: "C"
    },
    {
      text: "Colonial Office, Commonwealth and Foreign and Commonwealth Offices",
      value: "CO"
    },
    {
      text: "Exchequer, Office of First Fruits and Tenths, and the Court of Augmentations",
      value: "E"
    },
    {
      text: "Foreign Office",
      value: "FO"
    },
    {
      text: "Home Office",
      value: "HO"
    },
    {
      text: "Prerogative Court of Canterbury",
      value: "PROB"
    }
  ],
  small: true
}) }}

Jinja

Important information

This is an experimental feature that outputs a Jinja template based on the Nunjucks example. Check the converted code for accuracy.
{% from "components/checkboxes/macro.html" import tnaCheckboxes %}

{{ tnaCheckboxes({
  "label": "Categories",
  "headingLevel": 4,
  "headingSize": "m",
  "id": "categories",
  "name": "categories",
  "items": [
    {
      "text": "Admiralty, Navy, Royal Marines, and Coastguard",
      "value": "ADM"
    },
    {
      "text": "Air Ministry and Royal Air Force records",
      "value": "AIR"
    },
    {
      "text": "Board of Trade and successors",
      "value": "BT"
    },
    {
      "text": "Chancery, the Wardrobe, Royal Household, Exchequer and various commissions",
      "value": "C"
    },
    {
      "text": "Colonial Office, Commonwealth and Foreign and Commonwealth Offices",
      "value": "CO"
    },
    {
      "text": "Exchequer, Office of First Fruits and Tenths, and the Court of Augmentations",
      "value": "E"
    },
    {
      "text": "Foreign Office",
      "value": "FO"
    },
    {
      "text": "Home Office",
      "value": "HO"
    },
    {
      "text": "Prerogative Court of Canterbury",
      "value": "PROB"
    }
  ],
  "small": true
}) }}
Open this example in new tab

HTML

<div class="tna-fieldset tna-fieldset--small-hint">
  <fieldset class="tna-fieldset__inner">
    <legend class="tna-fieldset__legend">
      <h4 class="tna-fieldset__heading tna-heading-m">
        Categories
      </h4>
    </legend>
    <div class="tna-fieldset__body">
      <div class="tna-checkboxes" id="categories">
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-alpha" value="alpha" name="categories">
          <label for="categories-alpha" class="tna-checkboxes__item-label">
            Alpha
          </label>
        </div>
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-beta" value="beta" name="categories" checked>
          <label for="categories-beta" class="tna-checkboxes__item-label">
            Beta
          </label>
        </div>
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-gamma" value="gamma" name="categories">
          <label for="categories-gamma" class="tna-checkboxes__item-label">
            Gamma
          </label>
        </div>
      </div>
    </div>
  </fieldset>
</div>

Nunjucks

Nunjucks options
Primary options
Name Type Description
label string

The label for the checkboxes field. Required if there are multiple checkboxes. Optional for only one checkbox.

headingLevel number

The heading level which represents an element from <h1> through to <h6>. Leave blank or set to 0 to use a plain <label> element with no heading.

headingSize string

The physical size of the checkboxes title (xl, l, m, s or xs).

Default value: m

id string

Required.

A unique ID for the checkboxes component.

name string

Required.

The name of the form field.

hint string

An optional hint to display above the form field.

error object

If set, the details of any errors.

See macro options for error.

items array

Required.

A list of checkbox items.

See macro options for items.

small boolean

If true, show smaller checkboxes.

inline boolean

If true, show the checkboxes inline rather than vertical.

formItemClasses string

Classes to add to the checkboxes form group.

formItemAttributes object

HTML attributes (for example data attributes) to add to the checkboxes form group.

fieldsetClasses string

Classes to add to the <fieldset> element when there is more than one item.

fieldsetAttributes object

HTML attributes (for example data attributes) to add to the <fieldset> element when there is more than one item.

classes string

Classes to add to the checkbox elements.

attributes object

HTML attributes (for example data attributes) to add to the checkbox elements.

Options for error
Name Type Description
text string

Required.

The error text to display.

Options for items
Name Type Description
text string

Required.

The label of the checkbox item.

value string

Required.

The form field value.

name string

The name of the form field item. If set, this will override the main name property.

checked boolean

If true, the checkbox will be checked.

{% from "nationalarchives/components/checkboxes/macro.njk" import tnaCheckboxes %}

{{ tnaCheckboxes({
  label: "Categories",
  headingLevel: 4,
  headingSize: "m",
  id: "categories",
  name: "categories",
  items: [
    {
      text: "Alpha",
      value: "alpha"
    },
    {
      text: "Beta",
      value: "beta",
      checked: true
    },
    {
      text: "Gamma",
      value: "gamma"
    }
  ]
}) }}

Jinja

Important information

This is an experimental feature that outputs a Jinja template based on the Nunjucks example. Check the converted code for accuracy.
{% from "components/checkboxes/macro.html" import tnaCheckboxes %}

{{ tnaCheckboxes({
  "label": "Categories",
  "headingLevel": 4,
  "headingSize": "m",
  "id": "categories",
  "name": "categories",
  "items": [
    {
      "text": "Alpha",
      "value": "alpha"
    },
    {
      "text": "Beta",
      "value": "beta",
      "checked": true
    },
    {
      "text": "Gamma",
      "value": "gamma"
    }
  ]
}) }}
Open this example in new tab

HTML

<div class="tna-fieldset tna-fieldset--small-hint">
  <fieldset class="tna-fieldset__inner" aria-describedby="categories-hint">
    <legend class="tna-fieldset__legend">
      <h4 class="tna-fieldset__heading tna-heading-m">
        Categories
      </h4>
    </legend>
    <p id="categories-hint" class="tna-fieldset__hint">
      Select all that apply.
    </p>
    <div class="tna-fieldset__body">
      <div class="tna-checkboxes" id="categories">
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-alpha" value="alpha" name="categories">
          <label for="categories-alpha" class="tna-checkboxes__item-label">
            Alpha
          </label>
        </div>
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-beta" value="beta" name="categories">
          <label for="categories-beta" class="tna-checkboxes__item-label">
            Beta
          </label>
        </div>
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-gamma" value="gamma" name="categories">
          <label for="categories-gamma" class="tna-checkboxes__item-label">
            Gamma
          </label>
        </div>
      </div>
    </div>
  </fieldset>
</div>

Nunjucks

Nunjucks options
Primary options
Name Type Description
label string

The label for the checkboxes field. Required if there are multiple checkboxes. Optional for only one checkbox.

headingLevel number

The heading level which represents an element from <h1> through to <h6>. Leave blank or set to 0 to use a plain <label> element with no heading.

headingSize string

The physical size of the checkboxes title (xl, l, m, s or xs).

Default value: m

id string

Required.

A unique ID for the checkboxes component.

name string

Required.

The name of the form field.

hint string

An optional hint to display above the form field.

error object

If set, the details of any errors.

See macro options for error.

items array

Required.

A list of checkbox items.

See macro options for items.

small boolean

If true, show smaller checkboxes.

inline boolean

If true, show the checkboxes inline rather than vertical.

formItemClasses string

Classes to add to the checkboxes form group.

formItemAttributes object

HTML attributes (for example data attributes) to add to the checkboxes form group.

fieldsetClasses string

Classes to add to the <fieldset> element when there is more than one item.

fieldsetAttributes object

HTML attributes (for example data attributes) to add to the <fieldset> element when there is more than one item.

classes string

Classes to add to the checkbox elements.

attributes object

HTML attributes (for example data attributes) to add to the checkbox elements.

Options for error
Name Type Description
text string

Required.

The error text to display.

Options for items
Name Type Description
text string

Required.

The label of the checkbox item.

value string

Required.

The form field value.

name string

The name of the form field item. If set, this will override the main name property.

checked boolean

If true, the checkbox will be checked.

{% from "nationalarchives/components/checkboxes/macro.njk" import tnaCheckboxes %}

{{ tnaCheckboxes({
  label: "Categories",
  headingLevel: 4,
  headingSize: "m",
  id: "categories",
  name: "categories",
  hint: "Select all that apply.",
  items: [
    {
      text: "Alpha",
      value: "alpha"
    },
    {
      text: "Beta",
      value: "beta"
    },
    {
      text: "Gamma",
      value: "gamma"
    }
  ]
}) }}

Jinja

Important information

This is an experimental feature that outputs a Jinja template based on the Nunjucks example. Check the converted code for accuracy.
{% from "components/checkboxes/macro.html" import tnaCheckboxes %}

{{ tnaCheckboxes({
  "label": "Categories",
  "headingLevel": 4,
  "headingSize": "m",
  "id": "categories",
  "name": "categories",
  "hint": "Select all that apply.",
  "items": [
    {
      "text": "Alpha",
      "value": "alpha"
    },
    {
      "text": "Beta",
      "value": "beta"
    },
    {
      "text": "Gamma",
      "value": "gamma"
    }
  ]
}) }}
Open this example in new tab

HTML

<div class="tna-fieldset tna-fieldset--small-hint tna-fieldset--error">
  <fieldset class="tna-fieldset__inner" aria-describedby="categories-error">
    <legend class="tna-fieldset__legend">
      <h4 class="tna-fieldset__heading tna-heading-m">
        Categories
      </h4>
    </legend>
    <p id="categories-error" class="tna-fieldset__error">
      <span class="tna-!--visually-hidden">Error:</span> You must select a category
    </p>
    <div class="tna-fieldset__body">
      <div class="tna-checkboxes" id="categories">
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-alpha" value="alpha" name="categories">
          <label for="categories-alpha" class="tna-checkboxes__item-label">
            Alpha
          </label>
        </div>
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-beta" value="beta" name="categories">
          <label for="categories-beta" class="tna-checkboxes__item-label">
            Beta
          </label>
        </div>
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-gamma" value="gamma" name="categories">
          <label for="categories-gamma" class="tna-checkboxes__item-label">
            Gamma
          </label>
        </div>
      </div>
    </div>
  </fieldset>
</div>

Nunjucks

Nunjucks options
Primary options
Name Type Description
label string

The label for the checkboxes field. Required if there are multiple checkboxes. Optional for only one checkbox.

headingLevel number

The heading level which represents an element from <h1> through to <h6>. Leave blank or set to 0 to use a plain <label> element with no heading.

headingSize string

The physical size of the checkboxes title (xl, l, m, s or xs).

Default value: m

id string

Required.

A unique ID for the checkboxes component.

name string

Required.

The name of the form field.

hint string

An optional hint to display above the form field.

error object

If set, the details of any errors.

See macro options for error.

items array

Required.

A list of checkbox items.

See macro options for items.

small boolean

If true, show smaller checkboxes.

inline boolean

If true, show the checkboxes inline rather than vertical.

formItemClasses string

Classes to add to the checkboxes form group.

formItemAttributes object

HTML attributes (for example data attributes) to add to the checkboxes form group.

fieldsetClasses string

Classes to add to the <fieldset> element when there is more than one item.

fieldsetAttributes object

HTML attributes (for example data attributes) to add to the <fieldset> element when there is more than one item.

classes string

Classes to add to the checkbox elements.

attributes object

HTML attributes (for example data attributes) to add to the checkbox elements.

Options for error
Name Type Description
text string

Required.

The error text to display.

Options for items
Name Type Description
text string

Required.

The label of the checkbox item.

value string

Required.

The form field value.

name string

The name of the form field item. If set, this will override the main name property.

checked boolean

If true, the checkbox will be checked.

{% from "nationalarchives/components/checkboxes/macro.njk" import tnaCheckboxes %}

{{ tnaCheckboxes({
  label: "Categories",
  headingLevel: 4,
  headingSize: "m",
  id: "categories",
  name: "categories",
  error: {
    text: "You must select a category"
  },
  items: [
    {
      text: "Alpha",
      value: "alpha"
    },
    {
      text: "Beta",
      value: "beta"
    },
    {
      text: "Gamma",
      value: "gamma"
    }
  ]
}) }}

Jinja

Important information

This is an experimental feature that outputs a Jinja template based on the Nunjucks example. Check the converted code for accuracy.
{% from "components/checkboxes/macro.html" import tnaCheckboxes %}

{{ tnaCheckboxes({
  "label": "Categories",
  "headingLevel": 4,
  "headingSize": "m",
  "id": "categories",
  "name": "categories",
  "error": {
    "text": "You must select a category"
  },
  "items": [
    {
      "text": "Alpha",
      "value": "alpha"
    },
    {
      "text": "Beta",
      "value": "beta"
    },
    {
      "text": "Gamma",
      "value": "gamma"
    }
  ]
}) }}
Open this example in new tab

HTML

<div class="tna-fieldset tna-fieldset--small-hint">
  <fieldset class="tna-fieldset__inner">
    <legend class="tna-fieldset__legend">
      <h4 class="tna-fieldset__heading tna-heading-m">
        Categories
      </h4>
    </legend>
    <div class="tna-fieldset__body">
      <div class="tna-checkboxes tna-checkboxes--small tna-checkboxes--inline" id="categories">
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-alpha" value="alpha" name="categories">
          <label for="categories-alpha" class="tna-checkboxes__item-label">
            Alpha
          </label>
        </div>
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-beta" value="beta" name="categories">
          <label for="categories-beta" class="tna-checkboxes__item-label">
            Beta
          </label>
        </div>
        <div class="tna-checkboxes__item">
          <input type="checkbox" id="categories-gamma" value="gamma" name="categories">
          <label for="categories-gamma" class="tna-checkboxes__item-label">
            Gamma
          </label>
        </div>
      </div>
    </div>
  </fieldset>
</div>

Nunjucks

Nunjucks options
Primary options
Name Type Description
label string

The label for the checkboxes field. Required if there are multiple checkboxes. Optional for only one checkbox.

headingLevel number

The heading level which represents an element from <h1> through to <h6>. Leave blank or set to 0 to use a plain <label> element with no heading.

headingSize string

The physical size of the checkboxes title (xl, l, m, s or xs).

Default value: m

id string

Required.

A unique ID for the checkboxes component.

name string

Required.

The name of the form field.

hint string

An optional hint to display above the form field.

error object

If set, the details of any errors.

See macro options for error.

items array

Required.

A list of checkbox items.

See macro options for items.

small boolean

If true, show smaller checkboxes.

inline boolean

If true, show the checkboxes inline rather than vertical.

formItemClasses string

Classes to add to the checkboxes form group.

formItemAttributes object

HTML attributes (for example data attributes) to add to the checkboxes form group.

fieldsetClasses string

Classes to add to the <fieldset> element when there is more than one item.

fieldsetAttributes object

HTML attributes (for example data attributes) to add to the <fieldset> element when there is more than one item.

classes string

Classes to add to the checkbox elements.

attributes object

HTML attributes (for example data attributes) to add to the checkbox elements.

Options for error
Name Type Description
text string

Required.

The error text to display.

Options for items
Name Type Description
text string

Required.

The label of the checkbox item.

value string

Required.

The form field value.

name string

The name of the form field item. If set, this will override the main name property.

checked boolean

If true, the checkbox will be checked.

{% from "nationalarchives/components/checkboxes/macro.njk" import tnaCheckboxes %}

{{ tnaCheckboxes({
  label: "Categories",
  headingLevel: 4,
  headingSize: "m",
  id: "categories",
  name: "categories",
  items: [
    {
      text: "Alpha",
      value: "alpha"
    },
    {
      text: "Beta",
      value: "beta"
    },
    {
      text: "Gamma",
      value: "gamma"
    }
  ],
  inline: true
}) }}

Jinja

Important information

This is an experimental feature that outputs a Jinja template based on the Nunjucks example. Check the converted code for accuracy.
{% from "components/checkboxes/macro.html" import tnaCheckboxes %}

{{ tnaCheckboxes({
  "label": "Categories",
  "headingLevel": 4,
  "headingSize": "m",
  "id": "categories",
  "name": "categories",
  "items": [
    {
      "text": "Alpha",
      "value": "alpha"
    },
    {
      "text": "Beta",
      "value": "beta"
    },
    {
      "text": "Gamma",
      "value": "gamma"
    }
  ],
  "inline": true
}) }}

When there is only a single checkbox, it isn't rendered within a <fieldset>.

Open this example in new tab

HTML

<div class="tna-form-item">
  <div class="tna-form-item__header">
    <h4 class="tna-form-item__label tna-heading-m">
      <label for="terms">
        Terms and conditions
      </label>
    </h4>
  </div>
  <div class="tna-form-item__body">
    <div class="tna-checkboxes">
      <div class="tna-checkboxes__item">
        <input type="checkbox" id="terms" value="agree" name="terms">
        <label for="terms" class="tna-checkboxes__item-label">
          I agree to the terms and conditions
        </label>
      </div>
    </div>
  </div>
</div>

Nunjucks

Nunjucks options
Primary options
Name Type Description
label string

The label for the checkboxes field. Required if there are multiple checkboxes. Optional for only one checkbox.

headingLevel number

The heading level which represents an element from <h1> through to <h6>. Leave blank or set to 0 to use a plain <label> element with no heading.

headingSize string

The physical size of the checkboxes title (xl, l, m, s or xs).

Default value: m

id string

Required.

A unique ID for the checkboxes component.

name string

Required.

The name of the form field.

hint string

An optional hint to display above the form field.

error object

If set, the details of any errors.

See macro options for error.

items array

Required.

A list of checkbox items.

See macro options for items.

small boolean

If true, show smaller checkboxes.

inline boolean

If true, show the checkboxes inline rather than vertical.

formItemClasses string

Classes to add to the checkboxes form group.

formItemAttributes object

HTML attributes (for example data attributes) to add to the checkboxes form group.

fieldsetClasses string

Classes to add to the <fieldset> element when there is more than one item.

fieldsetAttributes object

HTML attributes (for example data attributes) to add to the <fieldset> element when there is more than one item.

classes string

Classes to add to the checkbox elements.

attributes object

HTML attributes (for example data attributes) to add to the checkbox elements.

Options for error
Name Type Description
text string

Required.

The error text to display.

Options for items
Name Type Description
text string

Required.

The label of the checkbox item.

value string

Required.

The form field value.

name string

The name of the form field item. If set, this will override the main name property.

checked boolean

If true, the checkbox will be checked.

{% from "nationalarchives/components/checkboxes/macro.njk" import tnaCheckboxes %}

{{ tnaCheckboxes({
  label: "Terms and conditions",
  headingLevel: 4,
  headingSize: "m",
  id: "terms",
  name: "terms",
  items: [
    {
      text: "I agree to the terms and conditions",
      value: "agree"
    }
  ]
}) }}

Jinja

Important information

This is an experimental feature that outputs a Jinja template based on the Nunjucks example. Check the converted code for accuracy.
{% from "components/checkboxes/macro.html" import tnaCheckboxes %}

{{ tnaCheckboxes({
  "label": "Terms and conditions",
  "headingLevel": 4,
  "headingSize": "m",
  "id": "terms",
  "name": "terms",
  "items": [
    {
      "text": "I agree to the terms and conditions",
      "value": "agree"
    }
  ]
}) }}

Back to top