Available themes
Mermaid includes five built-in themes:- default
- dark
- forest
- neutral
- base
The default theme with a clean, professional appearance.Best for: General purpose diagrams, documentation, presentations.
The
base theme is the only theme that can be customized using theme variables. All other themes have fixed color schemes.Setting themes
- Site-wide (initialize)
- Per-diagram (frontmatter)
- Per-diagram (directive)
Set a theme for all diagrams when initializing Mermaid:
Theme variables
Theme variables allow you to customize colors and styling. This only works with thebase theme.
Core theme variables
Color calculation
Understanding derived colors
Understanding derived colors
Mermaid automatically calculates many colors from your primary color choices to ensure visual consistency:
- Border colors are derived from their corresponding fill colors
- Text colors are adjusted based on background for readability
- Secondary and tertiary colors can be calculated from the primary color
- darkMode: true changes how colors are derived for better contrast
Complete example with theme variables
Diagram-specific theme variables
Different diagram types have specific theme variables:- Flowchart
- Sequence diagram
- Class diagram
- State diagram
- ER diagram
- Gantt chart
- Pie chart
Custom CSS
For advanced customization, you can inject custom CSS:Dynamic theming
Change themes based on user preferences or system settings:Theme examples
- Corporate brand
- High contrast
- Pastel
- Dark blue
Theme reference tables
Core variables
Note variables
Best practices
- Use the base theme for customization - It’s the only theme designed to be modified
- Test color contrast - Ensure text is readable against backgrounds
- Use hex colors only - Color names are not supported
- Set darkMode appropriately - Helps Mermaid calculate better derived colors
- Consider accessibility - Follow WCAG guidelines for color contrast
- Document your theme - Keep a reference of your custom color scheme
- Test across diagram types - Theme variables affect different diagrams differently
Troubleshooting
Theme changes not applying
Theme changes not applying
- Ensure you’re using the
basetheme when settingthemeVariables - Check that colors are in hex format (
#rrggbb) - Verify there are no typos in variable names
- Clear any cached configurations with
reset()
Poor color contrast
Poor color contrast
- Set
darkMode: truefor dark backgrounds - Explicitly set text colors instead of relying on calculation
- Test with a contrast checker tool
- Use the
neutraltheme for black and white output
Inconsistent appearance across diagrams
Inconsistent appearance across diagrams
- Some diagram types use different theme variables
- Not all variables apply to all diagram types
- Consider using custom CSS for fine-grained control
- Check diagram-specific theme variable tables
Next steps
Configuration
Explore all configuration options
Syntax overview
Learn Mermaid syntax basics
Diagram types
Explore different diagram types
Examples
See themed diagram examples