Skip to content

Switches

Binary toggle controls with on/off states.


Setup

Switch styles are included in Manifest CSS or a standalone stylesheet, both referencing theme variables.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/mnfst@latest/lib/manifest.min.css" />

Default


<input type="checkbox" role="switch" />

Utilities

Switches accept Manifest utility classes, which can be stacked in any combination.

Colors


<!-- Brand variant -->
<input type="checkbox" role="switch" class="brand" checked />

<!-- Accent variant -->
<input type="checkbox" role="switch" class="accent" checked />

<!-- Positive variant -->
<input type="checkbox" role="switch" class="positive" />

<!-- Negative variant -->
<input type="checkbox" role="switch" class="negative" checked />

Size


<!-- Small variant -->
<input type="checkbox" role="switch" class="sm" checked />

<!-- Large variant -->
<input type="checkbox" role="switch" class="lg" checked />

Appearance


<!-- Border variant -->
<input type="checkbox" role="switch" class="outlined" checked />

<!-- Combined with colors -->
<input type="checkbox" role="switch" class="outlined brand" />
<input type="checkbox" role="switch" class="outlined accent" />
<input type="checkbox" role="switch" class="outlined positive" />
<input type="checkbox" role="switch" class="outlined negative" />

Form Layouts

Labels

Placing the switch and text inside a <label> automatically arranges them in a row.


<label>
    <input type="checkbox" role="switch" checked />
    Enable notifications
</label>

Groups

Placing labelled switches inside a <fieldset> automatically arranges them in a column with a gap.


<fieldset>
    <label>
        <input type="checkbox" role="switch" checked />
        Option A
    </label>
    <label>
        <input type="checkbox" role="switch" />
        Option B
    </label>
</fieldset>

Styles

Theme

Default switches use the following theme variables:

Variable Purpose
--color-field-surface Switch background
--color-field-surface-hover Switch background on hover
--color-field-inverse Marker color
--spacing-field-height Switch size and corner rounding
--transition Transition for interactive states

Customization

Modify base switch styles with custom CSS for the input[role=switch] selector. Overriding the field theme variables keeps both color modes working.


input[role=switch] {
    --color-field-surface: color-mix(in oklch, var(--color-brand-surface) 20%, transparent);
    --color-field-inverse: var(--color-brand-content);

    /* Checked */
    &:checked {
        --color-field-surface: var(--color-brand-surface);
        --color-field-surface-hover: var(--color-brand-surface-hover);
        --color-field-inverse: var(--color-brand-inverse);
    }
}