Skip to content
Español

Navigate

Type to search. Press Escape to close.

    Components · css New in 1.1

    Segmented control

    A row of pills where exactly one is chosen: day, week, month; monthly or yearly billing; list or board. Under the pills is a plain radio group, so the browser provides everything a segmented control has to do — one tab stop for the group, arrow keys to move the choice, a value that a form sends, and a name for every option — and the stylesheet only draws it.

    CSS: css/components/segmented.css (in ivolt.css). JS: none. New in 1.1.

    Period, billing and viewfixtures/segmented/basic.htmlOpen alone — Period, billing and view
    <div class="iv-stack iv-u-gap-5">
      <fieldset class="iv-segmented">
        <legend class="iv-u-sr-only">Period</legend>
        <label class="iv-segmented__item"><input type="radio" name="seg-period" value="day"><span>Day</span></label>
        <label class="iv-segmented__item"><input type="radio" name="seg-period" value="week" checked><span>Week</span></label>
        <label class="iv-segmented__item"><input type="radio" name="seg-period" value="month"><span>Month</span></label>
        <label class="iv-segmented__item"><input type="radio" name="seg-period" value="year"><span>Year</span></label>
      </fieldset>
    
      <fieldset class="iv-segmented iv-segmented--brand">
        <legend class="iv-u-sr-only">Billing</legend>
        <label class="iv-segmented__item"><input type="radio" name="seg-billing" value="monthly"><span>Monthly</span></label>
        <label class="iv-segmented__item"><input type="radio" name="seg-billing" value="yearly" checked><span>Yearly <span class="iv-badge iv-badge--success">−20 %</span></span></label>
      </fieldset>
    
      <fieldset class="iv-segmented iv-segmented--block iv-segmented--sm" style="max-width: 24rem">
        <legend class="iv-u-sr-only">View</legend>
        <label class="iv-segmented__item"><input type="radio" name="seg-view" value="list" checked><span>List</span></label>
        <label class="iv-segmented__item"><input type="radio" name="seg-view" value="board"><span>Board</span></label>
        <label class="iv-segmented__item"><input type="radio" name="seg-view" value="calendar" disabled><span>Calendar</span></label>
      </fieldset>
    
      <p class="iv-u-m-0 iv-u-text-sm iv-u-text-muted">Native radio groups: Tab reaches the group once, the arrow keys move the choice. Nothing on this page reacts to it.</p>
    </div>

    When to use it

    Use a segmented control for two to five short, mutually exclusive options that change what the reader is looking at, and that are worth showing all at once. More options, or long labels, belong in a select or a plain radio list. If each option shows a different panel of content, the pattern is tabs, which manage the panels for you; a segmented control only holds a value, and what changes on the page is yours to wire up.

    Anatomy

    <fieldset class="iv-segmented">
      <legend class="iv-u-sr-only">Period</legend>
      <label class="iv-segmented__item">
        <input type="radio" name="period" value="week" checked><span>Week</span>
      </label>
      …
    </fieldset>

    The <fieldset> groups the radios and its <legend> names the group (visually hidden here, because the context usually makes it obvious). Each option is a <label class="iv-segmented__item"> holding the input and, right after it, the visible face — a <span> that can carry a badge, as the “−20 %” on the yearly option shows.

    Variants

    • iv-segmented--brand fills the chosen segment with the primary and its ink, which suits a pricing toggle. A badge inside the filled segment takes the segment's text colour.
    • iv-segmented--block stretches the control to the width of its container and shares the room equally.
    • iv-segmented--sm is the compact size for toolbars and card headers.
    • A disabled radio dims its option and takes it out of the arrow-key cycle, which the browser handles.

    Accessibility

    The radios stay in the accessibility tree and the tab order; they are made transparent and laid over their face, not hidden with display: none. A screen reader announces “Period, grouping; Week, radio button, checked, 2 of 4”. The focus ring is drawn on the face when the input has :focus-visible. Changing the choice with the arrow keys selects it immediately — that is how native radio groups work — so the page must not do anything expensive or irreversible on change. In forced colours the chosen segment uses the system highlight.

    Customising

    .toolbar .iv-segmented {
      --iv-segmented-radius: var(--iv-radius-md);
      --iv-segmented-pad: 0.125rem;
    }

    Locals: --iv-segmented-radius (full pill by default) and --iv-segmented-pad (the gap between the track and the segments). Colours come from the theme: the track is the surface, the chosen segment the raised surface with a soft shadow, or the primary with --brand.

    Common mistakes

    • Building it from buttons with aria-pressed: you then owe the arrow keys, the single tab stop and the form value by hand.
    • Forgetting the name attribute: without it the radios are not one group and several can be checked.
    • Labels that wrap onto two lines. Shorten them or use a select.
    • Expecting it to switch panels by itself. Use tabs for that.

    Class index

    Every class of the family. The full list per stylesheet lives in the reference.

    ClassWhat it does
    iv-segmentedThe track, on a <fieldset>.
    iv-segmented__itemOne option: a label holding the radio and its face.
    iv-segmented--brandThe chosen segment is filled with the primary.
    iv-segmented--blockFull width, options share the room.
    iv-segmented--smCompact size.