Introducing PrimeReact v11-alpha 🎉Discover Now
styledForm

ToggleButton

ToggleButton component is used to create a button that can be toggled on or off.

Migrating to PrimeReact: What Changed and Why
A hands-on guide to the new compound component API, headless hooks, and Tailwind-first theming in PrimeReact v11.
May 12
preview

Usage#

import { ToggleButton } from '@primereact/ui/togglebutton';
<ToggleButton.Root>
    <ToggleButton.Indicator>Toggle</ToggleButton.Indicator>
</ToggleButton.Root>

Examples#

Basic#

A button that switches between active and inactive states.

basic-demo

Render Props#

This is called the render prop pattern. It allows using a function to customize what the component displays based on its internal state.

render-props-demo

Controlled#

Use pressed and onPressedChange properties to control the state of the ToggleButton.

controlled-demo

Size#

ToggleButton provides small and large sizes as alternatives to the base by using the size property.

sizes-demo

Invalid#

Invalid state is displayed using the invalid prop to indicate a failed validation. This style is useful when integrating with form validation libraries.

invalid-demo

Disabled#

When disabled is present, the element cannot be edited and focused.

disabled-demo

API#

Sub-Components#

See Primitive API for ToggleButtonRoot, ToggleButtonIndicator, ToggleButtonGroup component documentation.

Hooks#

See Headless API for useToggleButton and useToggleButtonGroup hook documentation.

Accessibility#

See ToggleButton Primitive for WAI-ARIA compliance details and keyboard support.