# Switch
A versatile Switch, managing state, context, and styling.
```jsx featured
Show All
```
```css preview
.switch-root[data-variant="outlined"] {
display: flex;
flex-direction: row;
gap: calc(12px * var(--lcs-spacing, 1));
cursor: pointer;
.switch-container {
overflow: hidden;
border-radius: 32px;
width: calc(44px * var(--lcs-spacing, 1));
min-width: calc(44px * var(--lcs-spacing, 1));
&[data-focused="true"] {
outline: 1px solid rgba(var(--switch-color), 0.8);
outline-offset: 0.5px;
}
&[data-variant="outlined"] {
background-color: rgba(var(--panel-color), 0.4);
border: 2px solid rgb(var(--panel-color));
transition: background-color 100ms;
}
}
}
.switch-indicator[data-variant="outlined"] {
position: relative;
display: flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
width: calc(20px * var(--lcs-spacing, 1));
height: calc(20px * var(--lcs-spacing, 1));
min-width: calc(12px * var(--lcs-spacing, 1));
min-height: calc(12px * var(--lcs-spacing, 1));
border: 1px solid transparent;
border-radius: 100%;
transition:
background-color 100ms,
border-color 100ms,
margin 100ms;
&[data-checked="true"] {
margin-left: 50%;
}
/* Indicator background */
&::before {
content: "";
position: absolute;
top: 50%;
left: 50%;
transform: translate(-100%, -50%);
width: 200%;
height: 200%;
pointer-events: none;
opacity: 0;
transition:
opacity 100ms,
background-color 100ms;
}
&[data-checked="true"]::before {
opacity: 1;
}
/* Indicator face (renders above ::before track fill) */
&::after {
content: "";
position: absolute;
inset: -1px;
border-radius: inherit;
background-color: inherit;
pointer-events: none;
transition: background-color 100ms;
}
&[data-variant="outlined"] {
outline: none;
background-color: rgb(222, 222, 222);
&::before {
background-color: rgba(var(--switch-color), 0.2);
}
&[data-checked="true"] {
background-color: rgb(222, 222, 222);
}
&:not([data-disabled="true"], [data-readonly="true"]) {
&[data-hovered="true"],
&[data-focused="true"] {
&::before {
background-color: rgba(var(--switch-color), 0.7);
}
}
}
}
}
```
[View Source](https://github.com/LocusInc/locus-ui/tree/main/packages/locus-ui/src/components/switch)
## Anatomy
```jsx code no-header
```
## Examples
### Variants
Switch components come with three built in variants, `solid`, `outlined`, and `muted`.
```jsx
{["outlined", "solid", "muted"].map((variant) => (
{variant.charAt(0).toUpperCase() + variant.slice(1)} Switch
))}
```
### Label Positions
The label element `