 Search
components/badge: Badge components/button: Button components/checkbox: Checkbox components/dialog: Dialog components/input: Input components/popover: Popover components/pre: Pre components/radio: Radio components/separator: Separator components/switch: Switch components/table: Table components/textarea: Textarea components/tooltip: Tooltip components/typography: Typography plugins/plugin-nf: Nerd Font Plugin plugins/theme-catppuccin: Catppuccin Theme plugins/theme-gruvbox: Gruvbox Theme plugins/theme-nord: Nord Theme start/changelog: Changelog start/ascii-boxes: ASCII Boxes start/intro: Introduction start/intro: ## Features start/plugins: Plugins start/plugins: ## Official Plugins start/plugins: ### Themes start/plugins: ## Community Plugins contributing/contributing: Contributing contributing/contributing: ## Local Development contributing/contributing: ## Issues contributing/contributing: ## Pull Requests contributing/style-guide: Style Guide contributing/style-guide: ## CSS Units contributing/style-guide: ## Selectors contributing/style-guide: ## Documentation plugins/plugin-dev: Developing Plugins plugins/plugin-dev: ### Style Layers start/tuis-vs-guis: TUIs vs GUIs start/tuis-vs-guis: ## Monospace Fonts start/tuis-vs-guis: ## Character Cells installation/nextjs: Next.js installation/vite: Vite start/theming: Theming start/theming: ## CSS Variables start/theming: ### Font Styles start/theming: ### Colors start/theming: ### Light & Dark start/theming: ## Theme Plugins start/installation: Installation start/installation: ## Installation start/installation: ## Using CSS start/installation: ## Using ESM start/installation: ## Using a CDN start/installation: ## Full Library Import start/installation: ### CSS start/installation: ### ESM start/installation: ### CDN installation/astro: Astro installation/astro: ## Scoping installation/astro: ### Frontmatter Imports installation/astro: ### <style> tag installation/astro: ### Full Library Import

Switch

Displays a switch

<label>
  <input type="checkbox" is-="switch" />
  Switch
</label>

Import

@import "@webtui/css/components/switch.css";

Usage

<label>
    <input type="checkbox" is-="switch" />
    Switch
</label>

Examples

Checked/Unchecked

Use the checked attribute to set the initial value of the switch checkbox

<label>
  <input type="checkbox" is-="switch" />
  Unchecked
</label>
<label>
  <input type="checkbox" is-="switch" checked />
  Checked
</label>

Disabled

Use the disabled attribute to disable the switch

<label>
  <input type="checkbox" is-="switch" disabled />
  Disabled
</label>
<label>
  <input type="checkbox" is-="switch" checked disabled />
  Checked Disabled
</label>

Size

Use the size- attribute to set the size of the switch

<label>
  <input type="checkbox" is-="switch" size-="small" />
  Small
</label>
<label>
  <input type="checkbox" is-="switch" />
  Default
</label>

Bar Size

Set the bar- attribute to thin or line to set the size of the switch bar

<label>
  <input type="checkbox" is-="switch" />
  Default
</label>
<label>
  <input type="checkbox" is-="switch" bar-="thin" />
  Thin Bar
</label>
<label>
  <input type="checkbox" is-="switch" bar-="line" />
  Line Bar
</label>

Reference

Properties

  • --switch-thumb-color: The color of the switch thumb
  • --switch-track-color: The color of the switch track
#my-switch-input {
  --switch-thumb-color: var(--foreground0);
  --switch-track-color: var(--background1);
}

Extending

To extend the Checkbox stylesheet, define a CSS rule on the components layer

@layer components {
  input[type="checkbox"][is-="switch"] {
    /* ... */
  }
}

Scope

  • All native <input type="checkbox"> elements with is-="switch"
input[type="checkbox"][is-="switch"] {
  /* ... */
}