ToggleButton is used to select a boolean value using a button.

import ToggleButton from 'primevue/togglebutton';

Two-way binding to a boolean property is defined using the standard v-model directive.


<ToggleButton v-model="checked" onLabel="On" offLabel="Off" />

Icons and Labels can be customized using onLabel, offLabel, onIcon and offIcon properties.


<ToggleButton v-model="checked" onLabel="Locked" offLabel="Unlocked" onIcon="pi pi-lock" 
    offIcon="pi pi-lock-open" class="w-9rem" aria-label="Do you confirm" />

Invalid state is displayed using the invalid prop to indicate a failed validation. You can use this style when integrating with form validation libraries.


<ToggleButton v-model="checked" onIcon="pi pi-check" offIcon="pi pi-times" invalid class="w-full sm:w-10rem" aria-label="Confirmation" />

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


<ToggleButton v-model="checked" disabled onIcon="pi pi-check" offIcon="pi pi-times"
    class="w-full sm:w-10rem" aria-label="Confirmation" />

Screen Reader

ToggleButton component uses a hidden native checkbox element as the switch element internally that is only visible to screen readers. Value to describe the component can be defined with aria-labelledby or aria-label props, it is highly suggested to use either of these props as the component changes the label displayed which will result in screen readers to read different labels when the component receives focus. To prevent this, always provide an aria label that does not change related to state.

<span id="rememberme">Remember Me</span>
<ToggleButton aria-labelledby="rememberme" />

<ToggleButton aria-label="Remember Me" />

Keyboard Support

Keyboard interaction is derived from the native browser handling of checkboxs in a group.

tabMoves focus to the button.
spaceToggles the checked state.