Skip to main content
Mermaid provides a powerful theming system that allows you to customize the appearance of diagrams. You can use built-in themes, customize theme variables, or apply custom CSS for complete control.

Available themes

Mermaid includes five built-in themes:
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

Set a theme for all diagrams when initializing Mermaid:

Theme variables

Theme variables allow you to customize colors and styling. This only works with the base theme.

Core theme variables

Color calculation

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
Mermaid only recognizes hex color codes (e.g., #ff0000). Color names (e.g., red) will not work.

Complete example with theme variables

Diagram-specific theme variables

Different diagram types have specific theme variables:

Custom CSS

For advanced customization, you can inject custom CSS:
Custom CSS has the highest specificity and will override theme variables. Use with caution as it may break when Mermaid updates its internal structure.

Dynamic theming

Change themes based on user preferences or system settings:

Theme examples

Theme reference tables

Core variables

Note variables

Best practices

  1. Use the base theme for customization - It’s the only theme designed to be modified
  2. Test color contrast - Ensure text is readable against backgrounds
  3. Use hex colors only - Color names are not supported
  4. Set darkMode appropriately - Helps Mermaid calculate better derived colors
  5. Consider accessibility - Follow WCAG guidelines for color contrast
  6. Document your theme - Keep a reference of your custom color scheme
  7. Test across diagram types - Theme variables affect different diagrams differently

Troubleshooting

  • Ensure you’re using the base theme when setting themeVariables
  • Check that colors are in hex format (#rrggbb)
  • Verify there are no typos in variable names
  • Clear any cached configurations with reset()
  • Set darkMode: true for dark backgrounds
  • Explicitly set text colors instead of relying on calculation
  • Test with a contrast checker tool
  • Use the neutral theme for black and white output
  • 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