Skip to content
IndexRequest a UIAboutContact

Toggle Button Toolbar

A formatting toolbar with Bold, Italic and Underline toggles and an alignment group, navigated with arrow keys.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Clean UI design of a text formatting toolbar: a rounded white bar with three toggle buttons B I U where Bold is pressed with a dark filled background, a thin divider, then three alignment buttons with the middle one selected, below the bar a sample paragraph shown bold and centred, thin border, light theme, flat modern style. Variants: all toggles off, and keyboard focus ring on the Italic button. Negative: heavy shadows, gradients, text errors, clutter. Reduced motion: static design.

About this pattern

Definition

A toolbar groups related controls into one tab stop. Toggle buttons (Bold, Italic, Underline) keep their own on or off state with aria-pressed; the alignment buttons are a radio-like group where exactly one is selected. Arrow keys move between buttons.

Purpose & UX principles

  • Use the toolbar role with a label, and a roving tabindex so Tab enters once and leaves once.
  • Toggles show a clear pressed style that does not rely on colour alone, such as a filled background.
  • Apply the change to the selection immediately and show it in the sample.

Interaction states

  • Three toggles, three alignment buttons, Left and Right or Home and End on the keyboard.

Motion specification

  • Changes apply instantly; no animation.
  • Reduced motion: nothing to change.

Responsive behaviour

  • Keep buttons at least 32px wide and tall; 44px on touch.
  • Provide visible tooltips or labels for icon-only buttons.

Code

HTML
<div class="bx"><div class="tl" id="tl" role="toolbar" aria-label="Text formatting"><button type="button" class="t" data-f="b" aria-pressed="false" aria-label="Bold"><b>B</b></button><button type="button" class="t" data-f="i" aria-pressed="false" aria-label="Italic"><i>I</i></button><button type="button" class="t" data-f="u" aria-pressed="false" aria-label="Underline"><u>U</u></button><span class="dv"></span><button type="button" class="t" data-a="left" aria-pressed="true" aria-label="Align left">&#8676;</button><button type="button" class="t" data-a="center" aria-pressed="false" aria-label="Align centre">&#8801;</button><button type="button" class="t" data-a="right" aria-pressed="false" aria-label="Align right">&#8677;</button></div><p class="sm" id="sm">Formatting is applied to this sample text.</p></div>

Related patterns

Split Button with Menu

↗
Split Button with MenuButtons & Actions

Segmented Control

↗
Segmented ControlInputs & Forms

Icon Button

↗
Icon ButtonButtons & Actions