Glassmorphism✨ Premium

Neu Toggle

Two switches carved into the material: a 64 × 34 px inset track and a large 80 × 40 px model with an icon, whose raised knob slides 40 px with a 3.7 px bounce on each side and turns violet or orange. Real role="switch" buttons, keyboard-operable.

CSSToggleInteractive

Updated

This effect is part of Effect.Labs — 840 vanilla effects, some free, some premium. Glassmorphism has 47 effects, including 6 free. Explore the category →

3 usage examples

House lighting circuits — wall-mounted home automation panel — Neu Toggle example 1

① House lighting circuits — wall-mounted home automation panel

WhenHallway wall screen: kitchen, garage and terrace each have a switch, and a large model controls the outdoor lights at dusk.
WhyThe knob sliding in its track mimics a real switch; the bounce confirms the action when the lamp is often in another room. The large bulb model that turns orange stands apart from the simple circuits.
SettingsOriginal sizes, shadows and curve. Three .neu-toggle and one .neu-toggle-big with a bulb icon; labels in #374151 (8.1:1). A “1 circuit on of 3” counter in role="status" updates on click. The screen has the material's tint, black frame on a painted wall.
Eco mode and schedule of a pellet stove — the stove's app — Neu Toggle example 2

② Eco mode and schedule of a pellet stove — the stove's app

WhenIn the evening, from the sofa, the user switches the stove to eco mode on their phone; tomorrow's schedule stays on.
WhyThe large flame model turning orange speaks of heating without a caption; a soft material for a household object, and the simple violet switch for a secondary setting.
Settings.neu-toggle-big with a flame instead of the moon; the status line goes from “Normal power · 7 kW” to “Eco · 4 kW, lower flame” (text in #92400e, 5.6:1). Schedule as an active .neu-toggle. Phone in front of the lit stove.
Reverb and chorus — digital guitar effects pedalboard — Neu Toggle example 3

③ Reverb and chorus — digital guitar effects pedalboard

WhenThe guitarist switches effects on the screen of a digital pedalboard: reverb already running, chorus to add, delay and boost as simple switches.
WhyThe relief echoes the footswitches of physical pedals; the knob's position reads from a distance on stage, without depending on color under the lights.
SettingsTwo .neu-toggle-big with wave icons (reverb on, chorus off) and two .neu-toggle. Label widened to 72 px to align the columns; decorative raised knobs in the same material.

How it works

Each switch is a <button type="button" role="switch" aria-checked> inside a <label class="neu-toggle-wrap"> with its text: clicking the text also flips the switch, and a screen reader announces “Wi-Fi, switch, on”. The .neu-toggle track (64 × 34 px, border-radius: 17px) is carved by two inset shadows #b8bec7 4px 4px 8px inset and #fff -4px -4px 8px inset; the .neu-toggle-knob (26 px, round) is raised by two 3 px / 6 px drop shadows. When on (.active class), it moves from left: 4px to left: 34px and fills with the #8b5cf6 → #a78bfa gradient. The large .neu-toggle-big (80 × 40 px, 32 px knob with an SVG icon) goes from 4 to 44 px and turns orange #f59e0b → #f97316, icon in white.

The bounce comes from the cubic-bezier(.68, -.55, .27, 1.55) curve over 0.3 s: its two values outside 0–1 make the knob back up before leaving, then overshoot its target. Measured in Chromium on the large model: the knob drops to 0.3 px (3.7 px backwards), rises to 47.7 px (3.7 px past 44) and settles at 44 px — the same round trip when switching off. The JavaScript fits in six lines: one listener per switch flips .active and aria-checked. It covers every .neu-toggle and .neu-toggle-big on the page, with no id: as many switches as you like.

The code holds the effect and nothing else: no site rule or variable (no --primary), no script from another effect, nothing that could collide with your stylesheet. Each switch is a real <button type="button" role="switch"> wrapped by its <label>: Tab reaches it, Space and Enter flip it, so does a click on the label, and the script is a single loop that updates aria-checked. As for the whole family, the surface is declared by .neu-toggle-scene (background: #e0e5ec, padding: 28px, border-radius: 24px): the relief does not depend on your page background.

Accessibility

  • Keyboard and screen readers: measured in Chromium and Firefox, Tab reaches both switches, Space and Enter flip them, aria-checked follows (“true” / “false”). The accessible name comes from the wrapping label (“Wi-Fi”, “Mode sombre”). Focus is shown by outline: 2px solid #8b5cf6 3 px off the edge (3.3:1 on the material, above the required 3:1).
  • Contrast: the #6b7280 labels on #e0e5ec measure 3.8:1 for 13.6 px at weight 600, below the 4.5:1 threshold — switch them to #374151 (8.1:1), as in the scenes. The track only exists through its inset shadows (#b8bec7, 1.5:1): when off, the switch is a very pale shape. When on, the violet knob (gradient #8b5cf6 → #a78bfa) contrasts from 3.3:1 to 2.2:1 depending on the point of the gradient; the large model's orange #f59e0b only at 1.7:1 on the material — the state stays readable through the knob's position, not its color.
  • Position rather than color: the state reads first by which side the knob is on (left off, right on), which does not depend on color vision. For an important setting, add a status text (“2 circuits on”).
  • prefers-reduced-motion not in the code: the bounce (3.7 px back-up and overshoot) plays even when the system asks for less motion. It is short and user-triggered; to remove it: @media (prefers-reduced-motion: reduce) { .neu-toggle-knob, .neu-toggle-big-knob { transition: none } }.

Browser compatibility

CSS: inset and drop box-shadow, transition with a cubic-bezier outside 0–1, linear-gradient, flexbox with gap. JavaScript: querySelectorAll, classList.toggle, setAttribute, no dependency. Measured in Chromium, Firefox and WebKit (Playwright): toggles with the mouse, the keyboard and by clicking the label, identical bounce. Flex gap needs Chrome 84, Firefox 63, Safari 14.1.

Chrome 84+✓ Full
Firefox 63+✓ Full
Safari 14.1+✓ Full
Edge 84+✓ Full
Mobile iOS 14.5+✓ Full (tapping the label toggles too)
Android Chrome✓ Full

Without JavaScript, the switches show their initial state and do not flip: keep the real state server-side, or pair them with a checkbox if the action is critical. Before flex gap, the label touches the switch.

The code

HTML structure to paste into your page (the CSS + JS come with Premium):

index.html — structure
<div class="neu-toggle-scene">
  <label class="neu-toggle-wrap">
    <span class="neu-toggle-label">Wi-Fi</span>
    <button type="button" class="neu-toggle active" role="switch" aria-checked="true">
      <span class="neu-toggle-knob"></span>
    </button>
  </label>
  <label class="neu-toggle-wrap">
    <span class="neu-toggle-label">Dark mode</span>
    <button type="button" class="neu-toggle-big" role="switch" aria-checked="false">
      <span class="neu-toggle-big-knob"><svg viewBox="0 0 24 24" aria-hidden="true">…</svg></span>
    </button>
  </label>
</div>
Unlock the full code — $9.90/mo incl. tax

The full HTML + CSS + JS of Neu Toggle, ready to paste — plus all 840 effects. Or $299 once, lifetime access.

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Bounce (CSS — transition: .3s cubic-bezier(.68, -.55, .27, 1.55)) 0.3 s, 3.7 px back-up and overshoot cubic-bezier(.34, 1.56, .64, 1) keeps the overshoot on arrival without the back-up on departure. ease removes the bounce. Beyond 0.4 s, the switch feels sluggish.
On color (CSS — .neu-toggle.active .neu-toggle-knob, .neu-toggle-big.active .neu-toggle-big-knob) violet #8b5cf6 → #a78bfa; orange #f59e0b → #f97316 Change the gradient and the colored shadow rgba(…, .4) 0 2px 8px together. “Running” green: #16a34a → #22c55e.
Large model icon (HTML — <svg> in .neu-toggle-big-knob) moon (Dark mode) Any 24 × 24 stroke SVG, shown at 16 px: gray stroke when off, white when on. Keep aria-hidden="true": the name comes from the label.
Initial state (HTML — active class + aria-checked) Wi-Fi on, Dark mode off Set both together: class="neu-toggle active" aria-checked="true". To react to a change, listen to click on the button and read aria-checked.
Material tint (CSS — #e0e5ec, shadows #b8bec7 / #fff) light bluish gray Track, off knob and the .neu-toggle-scene surface must share one tint; change all three with a shadow pair from the same family.

FAQ

A <button role="switch"> announces itself as a switch (“on / off”) and flips with Space as well as Enter. In a form sent to the server, a visually hidden <input type="checkbox" role="switch"> under the track would submit the value on its own; here, read aria-checked in JavaScript.
Add your own listener after the effect's script: btn.addEventListener('click', () => console.log(btn.getAttribute('aria-checked'))). Listeners run in the order they were added: yours reads the state already flipped.
Neu Button triggers an action and sinks in; Neu Toggle remembers a two-position state, visible by which side the knob is on, with a bounce on change. To “turn on the terrace”, the toggle; to “start a coffee”, the button.