
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
svelte-toggle
Advanced tools
Accessible toggle switch component
This Svelte component implements accessibility practices for toggle buttons recommended by the Inclusive Components guide.
Try it in the Svelte REPL.
# yarn
yarn add -D svelte-toggle
# npm
npm i -D svelte-toggle
# pnpm
pnpm i -D svelte-toggle
The component is toggled by default.
<script>
import Toggle from "svelte-toggle";
let isToggled = true;
</script>
<Toggle on:toggle={(e) => (isToggled = e.detail)} />
Toggled? {isToggled}
The toggled prop supports two way binding.
<script>
import Toggle from "svelte-toggle";
let toggled = false;
</script>
<Toggle bind:toggled />
<button on:click={() => (toggled = !toggled)}>
{toggled ? "Turn off" : "Turn on"}
</button>
Customize the toggle switch descriptors using the "on" and "off" props.
<Toggle on="On" off="Off" />
Alternatively, you can override the default slot:
<Toggle let:toggled>
<strong>{toggled ? "Yes" : "No"}</strong>
</Toggle>
Set small to true to use the small size variant.
<Toggle small />
Customize the switch colors:
switchColor (default: #fff)toggledColor (default: #0f62fe)untoggledColor (default: #8d8d8d)<Toggle switchColor="#eee" toggledColor="#24a148" untoggledColor="#fa4d56" />
Customize the label text through the label prop.
<Toggle label="Custom label" />
Set hideLabel to true to visually hide the label.
Note: You should still provide a label value for accessibility.
<Toggle hideLabel label="Custom label" />
Set disabled to true to use the disabled state.
<Toggle disabled />
ToggleCore is an unstyled component that provides the accessibility attributes for the label and button elements.
Use this component if you want to style the component yourself.
<script>
import { ToggleCore } from "svelte-toggle";
let on = false;
</script>
<ToggleCore toggled={on} let:label let:button>
<!-- svelte-ignore a11y-label-has-associated-control -->
<label {...label}>Label</label>
<button {...button} on:click={() => (on = !on)}>
{on ? "On" : "Off"}
</button>
</ToggleCore>
API for the default Toggle component.
| Prop name | Type | Default value |
|---|---|---|
| id | string | "toggle" + Math.random().toString(36)" |
| label | string | "Label" |
| hideLabel | boolean | false |
| small | boolean | false |
| toggled | boolean | true |
| disabled | boolean | false |
| on | string | undefined |
| off | string | undefined |
| switchColor | string | "#fff" |
| toggledColor | string | "#0f62fe" |
| untoggledColor | string | "#8d8d8d" |
toggled changes<script>
import Toggle from "svelte-toggle";
let events = [];
</script>
<Toggle on:toggle={(e) => (events = [...events, e.detail])} />
on:toggle: {events.join(", ")}
FAQs
Accessible toggle switch component
The npm package svelte-toggle receives a total of 1,332 weekly downloads. As such, svelte-toggle popularity was classified as popular.
We found that svelte-toggle demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.