Checkboxes

The checkbox component allows users to pick the option or options they want from a list, by checking one or more boxes.

Sample HTML

<form>
    <fieldset>
        <legend>What topics are you interested in?</legend>
        <p class="ds_hint-text">Select as many as you like</p>

        <div class="ds_field-group">
            <div class="ds_checkbox">
                <input class="ds_checkbox__input" id="education" type="checkbox" />
                <label class="ds_checkbox__label" for="education">Education</label>
            </div>

            <div class="ds_checkbox">
                <input class="ds_checkbox__input" id="housing" type="checkbox" />
                <label class="ds_checkbox__label" for="housing">Housing</label>
            </div>

            <div class="ds_checkbox">
                <input class="ds_checkbox__input" id="transport" type="checkbox" />
                <label class="ds_checkbox__label" for="transport">Transport</label>
            </div>
        </div>
    </fieldset>
</form>

About this component

Checkboxes allow users to pick any number of items from a list. Unlike radio buttons which allow users to pick one option.

Why we use this component

We use this component when we want users to be able to:

  • pick one or more items from a list
  • toggle between selecting and deselecting an option

If users should only pick one option from a list, you should use the radio buttons component.

Other versions of this component

Checkboxes with hint text

Hint text can be added to checkboxes, just as it can to any other form component.

You can use hint text for more details about a checkbox. You should avoid adding hint text to the checkbox’s label element.

Sample HTML

<form>
    <fieldset>
        <legend>What are you interested in?</legend>

        <div class="ds_field-group">
            <div class="ds_checkbox">
                <input class="ds_checkbox__input" id="benefits" type="checkbox" />
                <label class="ds_checkbox__label" for="benefits">Benefits and grants</label>
                <p class="ds_hint-text">Information on benefits, funds and grants, including Child Benefit and tax credits.</p>
            </div>

            <div class="ds_checkbox">
                <input class="ds_checkbox__input" id="environment" type="checkbox" />
                <label class="ds_checkbox__label" for="environment">Environment, farming and marine</label>
                <p class="ds_hint-text">Guidance on recycling, flooding, farming, fishing and conservation, including advice for businesses.</p>
            </div>

            <div class="ds_checkbox">
                <input class="ds_checkbox__input" id="living-in-scotland" type="checkbox" />
                <label class="ds_checkbox__label" for="living-in-scotland">Living in and visiting Scotland</label>
                <p class="ds_hint-text">Voting, charities, tourism and life in Scotland.</p>
            </div>
        </div>
    </fieldset>
</form>

Small checkboxes

Although small checkboxes appear smaller, their clickable area is the same as normal checkboxes. This makes them easier for users to pick.

Sample HTML

<form>
    <fieldset>
        <legend>What topics are you interested in?</legend>
        <p class="ds_hint-text">Select as many as you like</p>

        <div class="ds_field-group">
            <div class="ds_checkbox  ds_checkbox--small">
                <input class="ds_checkbox__input" id="education" type="checkbox" />
                <label class="ds_checkbox__label" for="education">Education</label>
            </div>

            <div class="ds_checkbox  ds_checkbox--small">
                <input class="ds_checkbox__input" id="housing" type="checkbox" />
                <label class="ds_checkbox__label" for="housing">Housing</label>
            </div>

            <div class="ds_checkbox  ds_checkbox--small">
                <input class="ds_checkbox__input" id="transport" type="checkbox" />
                <label class="ds_checkbox__label" for="transport">Transport</label>
            </div>
        </div>
    </fieldset>
</form>

Error messages

The error state for checkboxes marks the entire fieldset.

Sample HTML

<form>
    <div class="ds_question  ds_question--error" id="error-id">
        <fieldset>
            <legend>What topics are you interested in?</legend>
            <p class="ds_hint-text">Select an option</p>
            <p class="ds_question__error-message">This field is required</p>

            <div class="ds_field-group">
                <div class="ds_checkbox">
                    <input class="ds_checkbox__input" id="education" type="checkbox" />
                    <label class="ds_checkbox__label" for="education">Education</label>
                </div>

                <div class="ds_checkbox">
                    <input class="ds_checkbox__input" id="housing" type="checkbox" />
                    <label class="ds_checkbox__label" for="housing">Housing</label>
                </div>

                <div class="ds_checkbox">
                    <input class="ds_checkbox__input" id="transport" type="checkbox" />
                    <label class="ds_checkbox__label" for="transport">Transport</label>
                </div>
            </div>
        </fieldset>
    </div>
</form>

Website analytics

Checkbox items can be tracked through the original page path and a data attribute identifying the checkbox and its value, if set.

The data attribute is added automatically by the Design System’s ‘tracking’ script.

Accessibility

We use a custom style for checkboxes so that they’re larger and easier to use than the standard checkboxes defined by a browser. We also use a custom style to make their focussed and selected states clearer.

Checkboxes should only be stacked vertically. This makes tabbing through the checkboxes easier to follow. It also ensures better visibility of the options for screen magnifier users.

Feedback, help or support

If you need any help or want to give any feedback you can e-mail us at: designsystem@gov.scot

Back to top