Radio buttons

Form fields that allow users to pick a single item

Sample HTML

<form>
    <fieldset>
        <legend>Was this page useful?</legend>
        <p class="ds_hint-text">Select an option</p>

        <div class="ds_field-group">
            <div class="ds_radio">
                <input class="ds_radio__input" id="useful-yes" name="feedback-type" type="radio" value="yes" />
                <label class="ds_radio__label" for="useful-yes">Yes</label>
            </div>

            <div class="ds_radio">
                <input class="ds_radio__input" id="useful-no" name="feedback-type" type="radio" value="no" />
                <label class="ds_radio__label" for="useful-no">No</label>
            </div>

            <div class="ds_radio">
                <input class="ds_radio__input" id="useful-maybe" name="feedback-type" type="radio" value="maybe" />
                <label class="ds_radio__label" for="useful-maybe">Maybe</label>
            </div>
        </div>
    </fieldset>
</form>

About this component

Radio buttons are a form component that allows users to select a single item from a list of options.

Why we use this component

We use this component when we want users to be able to only pick one option from a list.

If there are lots of options, you should think about whether a select component would work better.

If users need to be able to pick more than one option from a list, use the checkboxes component instead.

Other versions of this component

Radio buttons with hint text

Hint text can be added to radio buttons. You can use hint text for more details about a radio button. You should avoid adding hint text to the radio button’s label element.

Sample HTML

<form>
    <fieldset>
        <legend>How will the payments be paid in?</legend>

        <div class="ds_field-group">
            <div class="ds_radio">
                <input class="ds_radio__input" id="payment-advance" name="payment-type" type="radio" value="advance" />
                <label class="ds_radio__label" for="payment-advance">Advance</label>
                <p class="ds_hint-text">This means you're paid for the period coming up, i.e. the month ahead</p>
            </div>

            <div class="ds_radio">
                <input class="ds_radio__input" id="payment-arrears" name="payment-type" type="radio" value="arrears" />
                <label class="ds_radio__label" for="payment-arrears">Arrears</label>
                <p class="ds_hint-text">This means you're paid for the time that's just passed, i.e. for the last month</p>
            </div>
        </div>
    </fieldset>
</form>

Small radio buttons

Although small radio buttons appear smaller, their clickable area remains the same as normal radio buttons. This makes them easier for users to select.

Sample HTML

<form>
    <fieldset>
        <legend>Is a letting agency managing the property?</legend>

        <div class="ds_field-group">
            <div class="ds_radio  ds_radio--small">
                <input class="ds_radio__input" id="letting-agent-yes" name="letting-agent" type="radio" value="yes" />
                <label class="ds_radio__label" for="letting-agent-yes">Yes</label>
            </div>

            <div class="ds_radio  ds_radio--small">
                <input class="ds_radio__input" id="letting-agent-no" name="letting-agent" type="radio" value="no" />
                <label class="ds_radio__label" for="letting-agent-no">No</label>
            </div>
        </div>
    </fieldset>
</form>

Error messages

The error state for radio buttons marks the entire fieldset.

Sample HTML

<form>
    <div class="ds_question  ds_question--error" id="error-id-one">
        <fieldset aria-invalid="true">
            <legend>Did this resolve your issue?</legend>
            <p class="ds_hint-text">Hint text</p>
            <p class="ds_question__error-message">This field is required</p>

            <div class="ds_field-group">
                <div class="ds_radio">
                    <input class="ds_radio__input" id="resolve-yes" name="resolve" type="radio" value="yes" />
                    <label class="ds_radio__label" for="resolve-yes">Yes</label>
                </div>

                <div class="ds_radio">
                    <input class="ds_radio__input" id="resolve-no" name="resolve" type="radio" value="no" />
                    <label class="ds_radio__label" for="resolve-no">No</label>
                </div>
            </div>
        </fieldset>
    </div>
</form>

Inline radio buttons

In some cases you can display radio buttons beside one another.

Only use inline radio buttons when:

  • the question only has two options
  • the text for both options is short

If you are using an inline display for a yes/no choice, make ‘Yes’ the first option.

Sample HTML

<form>
    <fieldset>
        <legend>Is a letting agency managing the property?</legend>

        <div class="ds_field-group  ds_field-group--inline">
            <div class="ds_radio">
                <input class="ds_radio__input" id="letting-agent-yes" name="letting-agent" type="radio" value="yes" />
                <label class="ds_radio__label" for="letting-agent-yes">Yes</label>
            </div>

            <div class="ds_radio">
                <input class="ds_radio__input" id="letting-agent-no" name="letting-agent" type="radio" value="no" />
                <label class="ds_radio__label" for="letting-agent-no">No</label>
            </div>
        </div>
    </fieldset>
</form>

Revealing additional questions

If there are additional questions that apply to a particular radio option, they can be made to display only when that option is chosen.

This will:

  • make the related questions easier to answer by grouping them together
  • make the form simpler for users who do not need to complete the related questions

Sample HTML

<form>
    <div class="ds_question">
        <fieldset id="landlord-improvements-query">
            <legend>Has the landlord improved the property since you moved in?</legend>

            <div class="ds_field-group">
                <div class="ds_radio">
                    <input checked="" id="landlord-improvements-yes" value="yes" name="landlord-improvements-query" class="ds_radio__input" type="radio" />
                    <label for="landlord-improvements-yes" class="ds_radio__label">Yes</label>

                    <div class="ds_reveal-content">
                        <div class="ds_question">
                            <label class="ds_label" for="landlord-improvements-details">What work has your landlord done to improve the property?</label>
                            <textarea id="landlord-improvements-details" class="ds_input" rows="4" data-validation="requiredField" aria-required="true"></textarea>
                        </div>
                    </div>
                </div>
                <div class="ds_radio">
                    <input id="landlord-improvements-no" value="no" name="landlord-improvements-query" class="ds_radio__input" type="radio" />
                    <label for="landlord-improvements-no" class="ds_radio__label">No</label>
                </div>
            </div>
        </fieldset>
    </div>
</form>

Website analytics

Radio buttons can be tracked through the original page path and a data attribute showing the question type and value selected.

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

Accessibility

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

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