πβοΈ Theme Toggle Feature
Your portfolio now includes a light/dark theme toggle that allows users to choose their preferred viewing mode!
π― Features
β¨ Smart Theme Detection
- Auto-detects system preference on first visit
- Remembers userβs choice in localStorage
- Syncs with system theme changes (if no manual preference set)
- Smooth transitions between themes
π¨ Theme Toggle Button
Located in the navigation bar (far right):
- π Moon icon in light mode β Click to switch to dark mode
- βοΈ Sun icon in dark mode β Click to switch to light mode
- Animated hover effects with rotation
- Teal accent on hover
πΎ Persistence
- Theme choice is saved to
localStorage - Persists across page refreshes
- Persists across browser sessions
- Works on all pages
π¨ Color Schemes
Light Mode
Background: White (#ffffff)
Card Background: White (#ffffff)
Text: Dark Slate (#263238)
Primary: Teal (#55d6aa)
Secondary: Green (#57ad68)
Dark Mode
Background: Dark Navy (#1a1f2e)
Card Background: Blue-Slate (#263238)
Text: Light Gray (#f1f5f9)
Primary: Teal (#55d6aa) - stays vibrant!
Secondary: Green (#57ad68) - stays vibrant!
π How It Works
1. Initial Load
// Checks in this order:
1. localStorage for saved preference
2. System preference (prefers-color-scheme)
3. Defaults to light mode
2. Theme Toggle
// When user clicks toggle button:
1. Switches theme (light β dark)
2. Saves to localStorage
3. Updates all colors instantly
4. Shows notification
3. System Sync
// Automatically adapts to system changes:
- Only if user hasn't manually set a preference
- Listens to prefers-color-scheme changes
- Updates in real-time
π± Mobile Support
- β Theme toggle visible in mobile menu
- β Touch-friendly button size
- β Consistent behavior across devices
- β Smooth animations
π― User Experience
Smooth Transitions
All theme changes include:
- 0.3s fade transition for backgrounds
- 0.3s fade transition for text colors
- Notification feedback (π or βοΈ)
- No jarring color switches
Visual Feedback
- Hover effect: Button scales and rotates
- Icon swap: Moon β Sun based on current theme
- Color change: Teal accent on hover
- Notification: Shows which mode was activated
π¨ Dark Mode Design
Carefully Chosen Colors
- Background tones inspired by your original blog
- Teal accents remain vibrant in dark mode
- Reduced eye strain with softer contrasts
- Maintains brand identity across themes
What Changes in Dark Mode
- β Background colors (dark navy)
- β Text colors (light gray)
- β Card backgrounds (blue-slate)
- β Navigation background (translucent dark)
- β Footer background (very dark)
- β Teal/green accents (stay the same!)
π§ Customization
Change Dark Mode Colors
Edit assets/css/modern.css:
[data-theme="dark"] {
--bg-primary: #1a1f2e; /* Main background */
--bg-card: #263238; /* Cards */
--text-primary: #f1f5f9; /* Main text */
/* etc. */
}
Disable Auto System Detection
Remove this code from assets/js/modern.js:
// Listen for system theme changes
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
// ... code to remove ...
});
Change Transition Speed
Edit assets/css/modern.css:
body {
transition: background-color 0.3s ease, color 0.3s ease;
/* Change 0.3s to your preferred speed */
}
π§ͺ Testing
Test Scenarios
- First visit - Should detect system preference
- Toggle button - Should switch themes smoothly
- Page refresh - Should remember choice
- Different pages - Theme should persist
- System change - Should sync (if no manual preference)
- Mobile - Button should be accessible
Browser Testing
- β Chrome/Edge
- β Firefox
- β Safari
- β Mobile browsers
π Analytics
Theme changes are tracked (if Google Analytics is enabled):
Event Category: 'Theme'
Event Action: 'Toggle'
Event Label: 'dark' or 'light'
π― Best Practices
When to Use Each Theme
Light Mode:
- π± Bright environments
- βοΈ Daytime browsing
- π Reading text-heavy content
- π¨οΈ Before printing
Dark Mode:
- π Night-time browsing
- π» Reduced eye strain
- π OLED battery saving
- π¬ Watching media
π Performance
- β Zero impact on page load speed
- β Instant theme switching
- β Lightweight - only CSS variables change
- β No Flash - theme applied before render
π Privacy
- β Theme preference stored locally only
- β No server communication
- β No tracking (except optional analytics)
- β User has full control
π Code Structure
Files Modified
assets/css/modern.css- Dark mode stylesassets/js/modern.js- Theme toggle logic_includes/navigation.html- Toggle button
Key Functions
initThemeToggle()- Initialize theme on loadtoggleTheme()- Switch between themes- Event listeners for button and system changes
π Try It Out!
- Visit: http://localhost:4000
- Look for the theme toggle button in the navigation
- Click to switch between light and dark modes
- Refresh the page - your choice is saved!
- Try it on mobile too!
Your portfolio now offers a beautiful dark mode with your signature teal color scheme! πβ¨