Sphinx RTD-Theme Dark Modeο
A comprehensive dark mode implementation for the Sphinx Read the Docs theme that provides an elegant dark interface while maintaining excellent readability and accessibility. Theme used for this web site.
Featuresο
π Dark Mode Stylingο
Complete Dark Theme: Professional dark color scheme for all elements
High Contrast: Optimized text contrast for excellent readability
Eye-Friendly: Reduces eye strain during extended reading sessions
Consistent Design: Maintains RTD themeβs clean, professional appearance
π¨ Enhanced Visual Elementsο
Smooth Transitions: Animated hover effects and state changes
Custom Scrollbars: Dark-themed scrollbars that match the overall design
Improved Navigation: Enhanced sidebar and navigation styling
Code Block Optimization: Dark syntax highlighting for better code readability
π§ Responsive Designο
Mobile Friendly: Optimized for all screen sizes
Print Compatibility: Maintains readability when printed
Accessibility: WCAG compliant color contrasts
Cross-Browser: Works across all modern browsers
Installationο
Requirementsο
Sphinx documentation generator
Read the Docs theme (
sphinx_rtd_theme)Basic CSS customization support
Setupο
Copy the CSS fileβs
custom.cssandcode-block.cssto your Sphinx project:Click on this link custom.css to download the custom.css file. Click on this link code-block.css to download the custom.css file.
Copy the file
custom.cssandcode-block.cssto thesource/_static/cssdirectory.Tip
Right click on the link, copy link address. Use a shell terminal and navigate to
source/_static/cssdirectory. Then usewgetto download. This will download the custom.css and code-block.css files, without needing to copy from your Download directory.Update your
conf.pyto include the CSS:# Ensure static path is configured html_static_path = ['_static'] # Add your custom CSS html_css_files = [ 'css/custom.css', 'css/code-block.css', # ... your other CSS files ]
Build your documentation:
make clean && make html
Clear browser cache (important for seeing changes):
Hard refresh:
Ctrl+F5(Windows/Linux) orCmd+Shift+R(Mac)Clear cache: Use browser developer tools to clear site data
Incognito/Private mode: Test in a fresh browser session
CSS File Structureο
The dark mode CSS is organized into logical sections:
custom.css
βββ Color Variables # Global color definitions
βββ Body & Background # Main page styling
βββ Navigation & Sidebar # Left sidebar styling
βββ Content Area # Main content styling
βββ Code Blocks # Syntax highlighting
βββ Tables & Lists # Data presentation
βββ Search & Forms # Interactive elements
βββ Responsive Design # Mobile adaptations
βββ Print Styles # Print-friendly overrides
Color Schemeο
Primary Colorsο
Element |
Light Mode |
Dark Mode |
Usage |
|---|---|---|---|
Background |
|
|
Main page background |
Text |
|
|
Primary text content |
Sidebar |
|
|
Navigation background |
Code Blocks |
|
|
Code background |
Links |
|
|
Hyperlinks |
Borders |
|
|
Dividers and borders |
Accent Colorsο
Success:
#27ae60β#2ecc71(Green)Warning:
#f39c12β#f1c40f(Orange/Yellow)Error:
#e74c3cβ#e67e22(Red/Orange)Info:
#3498dbβ#74b9ff(Blue)
Customizationο
Adjusting Colorsο
To modify the color scheme, edit the CSS variables at the top of the custom.css file:
:root {
--bg-color: #1e1e1e; /* Main background */
--text-color: #e0e0e0; /* Primary text */
--sidebar-bg: #2d2d2d; /* Sidebar background */
--accent-color: #4da6e0; /* Links and accents */
--border-color: #404040; /* Borders and dividers */
}
To modify the code block css see Code Block CSS - Syntax Highlighting Reference
Troubleshootingο
Common Issuesο
Q: Dark mode not applying
A: Ensure custom.css is in the correct path and listed in html_css_files
Q: CSS changes not visible
A: Hard refresh your browser (Ctrl+F5 or Cmd+Shift+R) or clear browser cache. This is the most common issue when developing CSS.
Q: Navigation hover effects not working A: Try a hard refresh first. If still not working, check browser developer tools to see if CSS is loading properly.
Q: Some elements still show light colors A: Check for theme-specific CSS that may override the dark styles
Q: Text is hard to read A: Adjust contrast ratios in the color variables section
Q: Mobile layout issues A: Verify responsive breakpoints are working correctly
This dark mode CSS was developed to provide a professional, accessible, and visually appealing dark theme for Sphinx documentation while maintaining the excellent usability of the Read the Docs theme.