adn-ui
Components

Toggle

A high-quality, styled React toggle button component built with @base-ui/react.

The Toggle component provides a two-state button for toggling states such as bookmarks, pins, or favorites.

Usage

import { Toggle } from "@/components/ui/toggle";

export function ExampleToggle() {
  return (
    <Toggle.Root aria-label="Toggle pin" variant="outline">
      Pin to Top
    </Toggle.Root>
  );
}

Preview

Custom Styling

Apply custom active state colors, hover effects, or rounded shapes via className:

<Toggle.Root className="data-[pressed]:bg-indigo-600 data-[pressed]:text-white hover:bg-indigo-500/10 rounded-full px-4">
  Favorite
</Toggle.Root>

Styling & Class Names

Target internal toggle CSS slots for custom overrides:

Class NameElement / SlotDescription
.toggleRoot buttonTwo-state toggle button element (data-[pressed]).
toggle--defaultDefault variantTransparent background style.
toggle--outlineOutline variantBordered container style.

Anatomy

import { Toggle } from "@base-ui/react/toggle";

<Toggle />;

API Reference

Toggle.Root Props

PropTypeDefaultDescription
pressedbooleanundefinedControlled pressed state of the toggle button.
defaultPressedbooleanfalseInitial uncontrolled pressed state.
onPressedChange(pressed: boolean) => voidundefinedEvent handler called when pressed state changes.
disabledbooleanfalseDisables user interaction.
variant'default' | 'outline''default'Visual style of the toggle button.
size'sm' | 'md' | 'lg''md'Size variant of the toggle button.

On this page