Skip to main content AWT

Toggle

An on/off switch for a single setting.

Live example

These are real Toggle blocks rendering on this page right now. Tab to them and try them in both color schemes.

Dark mode you don’t have to build

Every block supports dark mode. Use the light/dark toggle in the header and the live example above switches with it.

Parameters

Everything the Toggle block accepts. Setting is the label you see in the block’s settings panel. Parameter is what the same value is called in code. Accepts is what you can put in it.

Toggle block parameters
SettingParameterTypeDefaultAcceptsWhat it does
Typed on the blocklabelstring“Toggle label”Any textThe visible label. Screen readers announce it too, so make it say what the control does.
NamenamestringemptyAny textThe field name submitted with the form.
Sizesizestring“md”sm, mdThe control height.
On by defaulttoggledbooleanfalsetrue or falseStarts the switch on.
Disableddisabledbooleanfalsetrue or falseRenders the disabled state. Disabled controls are skipped by keyboard focus, so prefer hiding over disabling when you can.
Read-onlyreadonlybooleanfalsetrue or falseMakes the field read-only: visible and focusable, but not editable.
Off state labellabelAstring“Off”Any textThe state text shown while off.
On state labellabelBstring“On”Any textThe state text shown while on.
Visually hide labelhideLabelbooleanfalsetrue or falseVisually hides the label while keeping it for screen readers. Use only when the context makes the purpose obvious.

Accessibility parameters, on this and every AWT block

Every AWT block has an Accessibility panel in its settings. Each control in it becomes a real HTML attribute on the block’s outer element:

Accessibility parameters shared by every AWT block
SettingParameterWhat it does
Accessible name (aria-label)ariaLabelBecomes aria-label on the block’s outer element. Replaces the accessible name screen readers announce. Set it only when the visible label is not enough.
Described by (aria-describedby)ariaDescribedbyBecomes aria-describedby. Point it at the ID of another element on the page whose text adds a longer description.
Labelled by (aria-labelledby)ariaLabelledbyBecomes aria-labelledby. Point it at the ID of another element whose text should become this block’s accessible name.
RoleawtRoleBecomes the role attribute. Overrides the element’s ARIA role. The list offers only roles that suit the element.
Language (lang)awtLangBecomes the lang attribute. Set it when this block’s content is in a different language from the page, as a BCP-47 code like “fr”.