<fieldset>
    <legend>Condiments</legend>
    <p class="field__hint" id="condiments-hint">Please choose a flavour of ice cream.</p>

    <div class="field">
        <input type="checkbox" id="condiments-ketchup" name="condiments" value="ketchup" aria-describedby="condiments-hint" />
        <label for="condiments-ketchup">Ketchup</label>
    </div>

    <div class="field">
        <input type="checkbox" id="condiments-mustard" name="condiments" value="mustard" aria-describedby="condiments-hint" />
        <label for="condiments-mustard">Mustard</label>
    </div>

    <div class="field">
        <input type="checkbox" id="condiments-relish" name="condiments" value="relish" aria-describedby="condiments-hint" />
        <label for="condiments-relish">Relish</label>
    </div>
</fieldset>
{% set ariaDescribedby = '' %}
{% if hint %}
    {% set ariaDescribedby = name + '-hint' %}
{% elif error %}
    {% set ariaDescribedby = name + '-error' %}
{% elif hint and error %}
    {% set ariaDescribedby = name + '-hint' + " " + name + '-error' %}
{% endif %}

<fieldset{% if error %} class="field--error"{% endif %}>
    <legend>{{ legend }}</legend>
    {%- if hint %}
    {% render '@hint', { name: name, content: hint } %}
    {%- endif %}
    {%- for value, label in options -%}
    {%- render '@checkbox', {name: name, id: name + '-' + value, value: value, label: label, ariaDescribedby: ariaDescribedby, hint: false, error: false, invalid: error}, true -%}
    {%- endfor -%}
    {%- if error %}
    {% render '@error', { name: name, content: error } %}
    {%- endif -%}
</fieldset>
{
  "name": "condiments",
  "legend": "Condiments",
  "hint": "Please choose a flavour of ice cream.",
  "error": false,
  "options": {
    "ketchup": "Ketchup",
    "mustard": "Mustard",
    "relish": "Relish"
  }
}

Checkboxes

A group of checkboxes is wrapped in a fieldset with a legend which names the input group. This technique is derived from WebAIM’s article, Accessible Form Controls.

A hint for the group can be added immediately after the <legend> in a paragraph with a class of field__hint.

A validation error message for the group can be added immediately after the last checkbox in a paragraph with a class of field__error.

Hints and validation error messages must be associated with the checkbox using unique IDs which can be referenced from the checkboxes’ aria-describedby attributes. For more information, see WebAIM’s form validation error documentation.

Checkboxes with an associated error should also be given an aria-invalid attribute of true.