Settings Component — Astro
Comprehensive settings panel for theme switching, font size, font pair, and accessibility options
Settings Component
A comprehensive settings panel for theme switching, font size, font pair (sans + mono), and accessibility options.
Add this component
The command below includes <strong>Settings</strong>—run it in your project directory to install this component (and the CSS if needed). No prompts.
Choose your package manager — click a tab to select, then copy the command.
Features
- Theme Switcher - Integrated ThemeSwitcher component with theme icons (persists in localStorage as
theme) - Font Size Slider - Adjustable from 75% to 150% with filled track indicator (uses CSS gradient with
--slider-progressvariable). Persists in localStorage asfontSizeScale - Font (font pair) - Same UI as Theme: trigger button, dropdown menu with options, and preview panel (sample text in the selected sans + mono). Six pairs: Geist, Inter + JetBrains Mono, IBM Plex Sans + Mono, Source Sans 3 + Source Code Pro, DM Sans + DM Mono, Outfit + JetBrains Mono. Sets
--font-familyand--font-family-monoonhtml. Persists in localStorage asfontPair(geist,inter-jetbrains,ibm-plex,source,dm,outfit-jetbrains) - Sound - “Play sound on click” checkbox. When enabled, a short click sound (Web Audio API) plays on links, buttons, and other interactive elements. Off by default for accessibility. Persists in localStorage as
soundEffects - Reduce Motion Toggle - Applies
.reduced-motionclass to document root. Persists in localStorage asreducedMotion - High Contrast Toggle - Applies
.high-contrastclass to document root. Persists in localStorage ashighContrast - Scrollbar Style - Radio button group with three options: Thin (default, 0.5rem/8px), Thick (1.5rem/24px), and Hidden. Applies classes to
htmlelement (.scrollbar-thickor.scrollbar-hidden). Persists in localStorage asscrollbarStyle(values:thin,thick,hidden) - Opening and Closing Animations - Smooth slide-in from right with overlay fade. Respects both system
prefers-reduced-motionand the Settings “Reduce motion” toggle (no delay when either is active). Same behavior in Astro, Svelte, and React. - Focus Trapping - Tab cycles within panel when open
- Focus Management - Returns focus to trigger element on close
- Slide-in panel with overlay
- All settings persist in localStorage - All preferences are automatically saved and restored on page load
- Full keyboard navigation (Escape to close)
- Accessible ARIA attributes
- Slider track visibility optimized for all themes
- Mobile Responsive - Full width on mobile devices, optimized layout
Settings Persistence
All settings options automatically persist to localStorage and are restored when the page loads:
theme- Selected theme name (e.g.,github-dark-classic,github-light)fontSizeScale- Font size multiplier (e.g.,1.0for 100%,1.25for 125%)fontPair- Font pair id (geist,inter-jetbrains,ibm-plex,source,dm,outfit-jetbrains); applies both--font-familyand--font-family-monoon loadsoundEffects-trueorfalse; whentrue, click sound plays on interactive elements (default: off)reducedMotion- Boolean string (trueorfalse)highContrast- Boolean string (trueorfalse)scrollbarStyle- Scrollbar style preference (thin,thick, orhidden)
Live example
Open Settings via the gear icon in the navbar or the button below (same as navbar).
Usage
Include Settings once in your layout (e.g. with Navbar). Scripts run after DOM ready so the panel and theme switcher work when imported.
Usage
Full example for each framework (Astro, Vanilla, Svelte, Vue, React). Switch framework via View as or by clicking a Usage tab—both stay in sync.
Props
open(boolean, optional) - Whether settings panel is open by default (default: false)
Opening Settings
The Settings component registers window.openSettings() and window.closeSettings(). The Navbar gear button calls openSettings().
// Open the settings panel (e.g. from a button or navbar)
window.openSettings();
// Close the settings panel
window.closeSettings();