Snippet API in v2.0. Switch uses one snippet — thumb. MultiSwitch has three: thumb (one render in the moving thumb), segment (one render per step background), and label (per-step label). All snippet contexts use { index, item, isSelected } (thumb on MultiSwitch omits isSelected — it's always true).

AD01 Switch — thumb snippet

Custom content inside the moving thumb

Live Demo
Day/Night:
🌙
Night Mode
Power label:
ON
Power: ON
Code
 
Notes

The thumb snippet

The thumb snippet replaces the default thumb content. For a binary Switch, the snippet runs once and you usually read the checked state from your own scope (as both examples here do).

Snippet context

If you supply items, the snippet receives { index, item } describing the active half of the tuple. For pure binary toggles you can ignore the context entirely.

AD02 MultiSwitch — segment snippet

Custom content rendered once per step background. Pair with thumb to also fill the moving thumb.

Live Demo
Status Monitor:
🟢
Online
🔴
Offline
🟡
Warning
🟢
Online
Online
Fully operational
Media Controls:
⏮️
⏮️
▶️
⏸️
⏭️
Previous
Action: Previous
Code
 
When to use segment

v2.0 split

In 1.x children ran in BOTH the moving thumb and each step background. 2.0 split that into thumb (one render) and segment (one render per step) so each snippet has one job.

1.x parity pattern

To get the v1.x behaviour where the thumb showed the active item's content, pass both thumb and segment with the same markup. Optionally hide the active segment (opacity: isSelected ? 0 : ...) to avoid double-rendering underneath the thumb.

segment context

  • index — Index of the step (was currentIndex)
  • item — The item data for this step
  • isSelectedindex === activeIndex

AD03 MultiSwitch — label snippet

Rich per-step labels with full HTML/Svelte content

Live Demo
Power Levels:
Normal
50%
Normal (50%)
Quality:
Code
 
Notes

label snippet (v2.0)

Renamed from 1.x labelTemplate. Same role: full control over each per-step label.

Snippet context

  • index — Index of this label
  • item — Item data (typed as T | undefined)
  • isSelected — Whether this label corresponds to the active step

Easier alternatives

If you only need label text, prefer labelMember or labelCallback — see Labels.

AD04 Combined example — thumb + segment + label + itemStyles

Theme selector using all four customization points at once

Live Demo
Theme:
Dark
☀️
🌙
🔄
Dark Theme
Easy on the eyes
Code
 
Combined Use

All four together

itemStyles drives per-step background colours, segment renders the static icon per step, thumb shows the theme name in the moving thumb, label renders the rich per-step caption.

Real-world fit

  • Theme selectors
  • Media players
  • Dashboard controls
  • Configuration panels

Snippets with Disabled State

Disabled Custom Switch:
🔒
Locked
 

Performance & Best Practices

⚡ Performance Tips
  • ✅ Keep snippet logic simple
  • ✅ Avoid heavy computations in snippets
  • ✅ Use $derived for computed values
  • ✅ Minimize DOM elements in snippets
  • ✅ Cache expensive operations outside the snippet
🎯 Snippet Guidelines
  • ✅ Pick the right snippet (thumb vs segment vs label)
  • ✅ Design for touch interfaces
  • ✅ Ensure content fits in available space
  • ✅ Use ?. on optional item properties
  • ✅ Test with different item shapes

Next Steps

📚
API Reference

Complete documentation of all props

Switch API
🎨
Theming

Cross-library --base-* cascade

Theming
🏠
Back to Home

Return to the showcase landing page

Home