Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

Square Switch for Solid

A switch with square corners on the track and the thumb, starting off, and named Enable feature.

UI library: Ark UI

One switch is on screen, off, with square corners on the track and the thumb. There is no visible label. Its accessible name is Enable feature.

Use the square track when the rest of the surface is square too. The usual switch is fully rounded. A saved form choice fits a Checkbox. In Solid, Ark UI still toggles it with Space and with Enter.

Preview

Preview width

Installation

MCP · Pro
Make your AI a shadcn expert
Your agent installs components, builds pages and restyles your app from one prompt, in Claude Code, Cursor or VS Code.
Part of Pro

Anatomy

Switch anatomy: root, control, thumb, label

Usage

<Switch aria-label="Enable feature" class="rounded-sm **:data-[slot=switch-thumb]:rounded" />

FAQ

How are the corners squared off?

The Switch sets rounded-sm for the track and **:data-[slot=switch-thumb]:rounded for the thumb. The thumb is the part with data-slot="switch-thumb", so the selector reaches it on every library.

How do I make every switch square?

Edit the Switch file in your ui folder: replace rounded-full on the track and the thumb there. Then you don't repeat the classes on each switch.

How do I control this switch in Solid?

Nothing in this file sets the on state, so the switch starts off and keeps its own state. To control it, keep the on or off state in your own state and pass it back. To start it on, use the default prop. The prop is defaultChecked. Pass checked; onCheckedChange receives details.checked.

What do screen readers call this switch?

It has no visible label, so the demo passes aria-label (Enable feature). Change it to the setting the switch controls, or use a visible FieldLabel instead.

How do I add a visible label to this switch?

Put the Switch in a horizontal Field next to a FieldLabel. Clicking the label toggles the switch, and screen readers read the label with it. The Field links the label to the switch for you.

Which keys toggle the switch?

Tab moves focus to the switch. Space toggles it, and so does Enter.

API Reference

Switch

Sets aria-label="Enable feature". The rest is on the Switch page.