Added a theme toggle button that allows users to switch between dark and light themes with smooth transitions and persistent preferences.
- Added a theme toggle button positioned at the top-right of the page
- Button includes sun and moon SVG icons for visual indication
- Includes accessibility attributes (
aria-label,title) for screen readers
- Added light theme CSS variables under
[data-theme="light"]selector - Added
--code-bgvariable for code block backgrounds - Added
.theme-togglebutton styles including:- Fixed positioning in top-right corner
- Hover, focus, and active states
- Icon toggle visibility based on current theme
- Added smooth transition animations for theme switching on key elements
- Added
themeToggleDOM element reference - Added
initTheme()function to load saved theme preference from localStorage - Added
toggleTheme()function to switch between themes - Added
setTheme(theme)function to apply theme and persist to localStorage - Theme toggle event listener added to
setupEventListeners()
- Positioned in top-right corner (fixed position)
- Circular button with sun/moon icons
- Smooth scale animation on hover/click
- Keyboard accessible (focusable, works with Enter/Space)
| Variable | Dark Theme | Light Theme |
|---|---|---|
--background |
#0f172a |
#f8fafc |
--surface |
#1e293b |
#ffffff |
--surface-hover |
#334155 |
#f1f5f9 |
--text-primary |
#f1f5f9 |
#1e293b |
--text-secondary |
#94a3b8 |
#64748b |
--border-color |
#334155 |
#e2e8f0 |
--assistant-message |
#374151 |
#f1f5f9 |
- Theme preference is saved to
localStorage - Preference persists across page reloads and browser sessions
- Defaults to dark theme if no preference is saved
- 0.3s ease transitions on background, border, color, and box-shadow
- Applied to all major UI elements for seamless theme switching
- Button has
aria-label="Toggle theme"for screen readers - Button has
titleattribute for tooltip on hover - Supports keyboard navigation (Tab to focus, Enter/Space to activate)
- Color contrast maintained in both themes for readability