Toggle

A two-state button that can be either on or off. Built on Base UI's toggle primitive.

Last updated August 7, 2026

CreditsUnchangedPublished

Copied from shadcn/ui.

Overview

import { BoldIcon } from "lucide-react"
 
import { Toggle } from "@/components/ui/toggle"
 
export function ToggleDemoExample() {
  return (
    <Toggle aria-label="Toggle bold">
      <BoldIcon />
    </Toggle>
  )
}

Installation

$ npx shadcn@latest add https://ui.persian-labs.ir/r/toggle.json

Usage

import { Toggle } from "@/components/ui/toggle"
 
export function Example() {
  return <Toggle aria-label="Toggle bold">B</Toggle>
}

Outline

import { ItalicIcon } from "lucide-react"
 
import { Toggle } from "@/components/ui/toggle"
 
export function ToggleOutlineExample() {
  return (
    <Toggle variant="outline" aria-label="Toggle italic">
      <ItalicIcon />
    </Toggle>
  )
}

RTL

import { BoldIcon } from "lucide-react"
 
import { Toggle } from "@/components/ui/toggle"
 
export function ToggleRtlExample() {
  return (
    <Toggle aria-label="ضخیم">
      <BoldIcon />
    </Toggle>
  )
}

API Reference

Toggle

PropTypeDefaultDescription
pressedbooleanundefinedWhether the toggle is pressed. Use when controlled.
defaultPressedbooleanfalseThe initial pressed state when uncontrolled.
onPressedChange(pressed, details) => voidCalled when the pressed state changes.
variant"default" | "outline""default"The visual style of the toggle.
size"default" | "sm" | "lg""default"The size of the toggle.
disabledbooleanfalsePrevents interaction with the toggle.