Theme Toggle
The theme toggle button is located in the header toolbar, next to the GitHub icon.Locate the theme toggle
Look for the sun/moon icon in the top-right corner of the CodeInk interface.
Click to switch themes
Click the theme toggle button to switch between light and dark modes.The theme changes instantly without page reload.
Available Themes
Light Theme
A clean, bright theme optimized for well-lit environments. Features high contrast for readability.
Dark Theme
A comfortable dark theme that reduces eye strain in low-light conditions. The default theme.
Theme Implementation
The theme system is controlled by adata-theme attribute on the document root:
src/components/ThemeToggle.astro
Theme Storage
Your theme preference is stored in localStorage under the keycodeink-theme:
If localStorage is unavailable (e.g., in private browsing mode), the theme resets to dark mode on page reload.
Theme Events
CodeInk dispatches a custom event when the theme changes:Components That React to Theme Changes
Several components automatically update when the theme changes:- CodeMirror Editor - Switches between light and dark editor themes
- Mermaid Diagrams - Re-renders with theme-appropriate colors
- Syntax Highlighting - Switches between One Dark Pro (dark) and GitHub Light (light)
src/scripts/editor.ts
Default Theme
CodeInk defaults to dark mode on first visit. The initial theme is determined by:- localStorage - If a theme preference exists, use it
- System preference - Detect OS theme preference (if available)
- Default - Fall back to dark mode
The dark theme is optimized for extended coding sessions and reduces eye strain in low-light environments.
Theme-Aware Syntax Highlighting
Syntax highlighting themes automatically match your selected CodeInk theme:| CodeInk Theme | Editor Theme | Syntax Theme |
|---|---|---|
| Dark | One Dark Pro | One Dark Pro |
| Light | Light (CodeMirror default) | GitHub Light |
Accessibility
The theme toggle button includes proper ARIA labels:- Dark mode active: “Switch to light theme”
- Light mode active: “Switch to dark theme”
Best Practices
Match your environment
Use light theme in bright rooms and dark theme in dim lighting.
Try both themes
Experiment with both themes to find which you prefer for different tasks.
Reduce eye strain
Dark theme can reduce eye fatigue during long editing sessions.
Preview diagrams
Check Mermaid diagrams in both themes to ensure proper contrast.
Related Features
- Editor - CodeMirror editor with theme support
- Syntax Highlighting - Theme-aware code highlighting
- Mermaid Diagrams - Theme-aware diagram rendering