Skip to content

Settings Toggles with Description

Tailwind CSS settings panel with accessible switches, label descriptions, a locked required option, restore defaults and an auto-save status message.

Also known as: settings toggle switches, preference switches panel, toggle with description, notification settings

Settings Toggles with Description live demo

Open in new tab

Tailwind CSS code (HTML, JS)

A settings panel built with Tailwind CSS where every preference is an accessible switch with a bold label and a short description underneath. It fits account, notification and privacy pages in SaaS dashboards, and includes a locked "required" setting, a restore-defaults button and an auto-save status message.

How it works

The root element is .tsw-settings. Inside the card, each group is a section with a two-column grid (sm:grid-cols-[11rem_1fr]): an icon and group title on the left, a ul of rows on the right. On phones the columns stack and the icon sits next to the title.

Every row holds a label paragraph, a description paragraph and a button with role="switch". The button points to both paragraphs with aria-labelledby and aria-describedby, so screen readers announce the name, the state and the explanation together. All visuals come from the aria-checked attribute: aria-checked:bg-violet-600 colors the track, and on the thumb group-aria-checked:translate-x-5 slides it to the right while group-aria-checked:opacity-100 reveals the check icon. No extra CSS file is needed.

The script initializes each .tsw-settings on DOMContentLoaded. A click on a switch flips aria-checked, writes a message such as "Weekly digest turned off. Saved." into the data-tsw-status region and dispatches a bubbling tsw:change event with the switch id and new state. Clicking a label marked data-tsw-for toggles its switch, like a native label. The data-tsw-reset button restores every switch to the value in its data-tsw-default attribute. Disabled switches are skipped.

Customization

  • Swap violet in aria-checked:bg-violet-600, text-violet-600 and focus-visible:outline-violet-600 for emerald or sky to change the accent color.
  • h-7 w-12 on .tsw-switch and group-aria-checked:translate-x-5 on the thumb: make the switch larger or smaller; keep the translate equal to track width minus thumb width.
  • data-tsw-default on a switch: sets the value used by Restore defaults; remove it to leave that switch unchanged on reset.
  • Add the disabled attribute (and a badge like "Required") to lock a setting, as done for #tsw-s-security.
  • Listen for tsw:change on .tsw-settings, or replace the announce() call in script.js with a fetch() request, to save preferences on your server.
  • sm:grid-cols-[11rem_1fr] on each section: widen the left column or remove it for a single-column list.

Use cases

  • SaaS account pages: preferences are grouped into sections with accessible switches and short descriptions
  • Notification settings: users turn email and digest options on or off and see a saved message
  • Privacy pages: a locked required setting is shown as disabled and cannot be changed
  • Admin dashboards: a restore defaults button resets every switch at once

Accessibility

Each switch is a real button with role="switch" and aria-checked, so it is reachable with Tab and toggled with Space or Enter. Labels and descriptions are linked with aria-labelledby and aria-describedby, groups are named with aria-labelledby on each section, and decorative icons are aria-hidden. Changes are announced politely through the role="status" footer. Switches show a visible focus outline, the disabled switch uses the native disabled state, and transitions are removed with motion-reduce:transition-none.

Usage notes

The Tailwind v4 browser build is enough; no plugins are required. For several panels on one page, give every label, description and switch unique id values and update data-tsw-for to match.

Settings Toggles with Description at a glance

Framework
Tailwind CSS
Code
HTML, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Tailwind CSS
Layout
Responsive, works on mobile
Category
Toggles & Switches
License
Free for personal and commercial use

Questions about this template

Can I use the Settings Toggles with Description code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Tailwind CSS from a CDN (the links are under Requirements). Paste the HTML where the component should appear and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

The Tailwind browser build is for prototyping. In production, compile Tailwind with its CLI or your bundler.

Settings Toggles with Description – Tailwind CSS toggles & switches component screenshot
Settings Toggles with Description · Tailwind CSS Toggles & Switches

More Toggles & Switches

Day/Night Toggle – Pure CSS toggles & switches preview

Day/Night Toggle

Animated pure CSS day and night toggle switch where the sun turns into a cratered moon, clouds drift away and stars appear.

iOS Style Toggle Switch – Pure CSS toggles & switches preview

iOS Style Toggle Switch

Pure CSS iOS style toggle switches built on real checkboxes, in a grouped settings list with three sizes, five colors and a disabled state.