City of Ghent Style Guide

Radios

When to use this component

Use the radios component when users should only be able to select one option and no more.

When not to use this component

Do not use the radios component when you need to help users:

  • Select one or more options.
  • Toggle a single option on or off.

In these cases, use the checkboxes component (for a single option or a short list of options) or the checkboxes with filter component (for a long list of options) instead.

When users should be able to select one option and no more from a long list of options:

  • Try to reduce and simplify the list of options to present fewer options to the user.
  • When there are no better alternatives, use the select component.

How it works

  • Radios are grouped in a fieldset.
  • The fieldset uses a legend to present a description for the radios. This is typically a question.
  • Users should be able to select only one option and no more. Once they selected an option, they can only select another one, and the one that was selected should become deselected. Furthermore, users cannot go back to having no option selected, except when refreshing their browser window.
  • Do not select radios by default as users might not notice this, resulting in not realising they missed a question and/or sending a wrong answer.
  • The options should have short but clearly different labels. There’s no need to name the action “Select this radio to…” because it is already a radio. Avoid repeating words at the start of the labels for the options so that the options are easiliy scannable.

Usage, behavior, layout and validation

The radios component is a form element that should always be used in a form. For a description of the usage, the behavior, the layout and validation of form elements, see the form component examples and documentation.

<fieldset class="form-item {{ modifier }}">
  <legend>
    <span class="legend-title">{{ label }}</span>
    {% if label_optional %}
      <span class="label-optional">({{ label_optional }})</span>
    {% endif %}
  </legend>
  <div class="form-item">
    {% if field_description %}
      {% include '@field-message' with {
        "field_message": field_description,
        "id": id ~ '-description',
        "modifier": null
      } %}
    {% endif %}
    <div class="form-columns">
      <div class="form-item-column">
        {% for option in options %}
          {% include '@input' with {
            "id": "input-" ~ id ~ "-" ~ modifier ~ "-" ~ option.id,
            "type": "radio",
            "name": option.name,
            "label": option.label,
            "modifier": modifier,
            "attributes": option.attributes
          } %}
        {% endfor %}
      </div>
      <div class="form-item-column">
        {% if modifier == 'error' %}
          {% include '@field-message' with {
            "id": id ~ '-validation',
            "modifier": "error"
          } %}
        {% endif %}

        {% if modifier == 'success' %}
          {% include '@field-message' with {
            "id": id ~ '-validation',
            "modifier": "success"
          } %}
        {% endif %}
      </div>
    </div>
  </div>
</fieldset>
<fieldset class="form-item ">
    <legend>
        <span class="legend-title">radio buttons</span>
    </legend>
    <div class="form-item">
        <div class="form-columns">
            <div class="form-item-column">
                <div class="radio">

                    <input type="radio" id="input-input-radio--radio-1" name="radiogroup" class="radio" />
                    <label for="input-input-radio--radio-1">Radio option 1</label>
                </div>
                <div class="radio">

                    <input type="radio" id="input-input-radio--radio-2" name="radiogroup" class="radio" />
                    <label for="input-input-radio--radio-2">Radio option 2</label>
                </div>
            </div>
            <div class="form-item-column">

            </div>
        </div>
    </div>
</fieldset>
{
  "id": "input-radio",
  "label": "radio buttons",
  "options": [
    {
      "label": "Radio option 1",
      "name": "radiogroup",
      "id": "radio-1"
    },
    {
      "label": "Radio option 2",
      "name": "radiogroup",
      "id": "radio-2"
    }
  ]
}