Skip to content

Theme Configuration

Dynamic and integrated theme configuration was introduced in Mermaid version 8.7.0.

Themes can now be customized at the site-wide level, or on individual Mermaid diagrams. For site-wide theme customization, the initialize call is used. For diagram specific customization, frontmatter config is used.

Available Themes

  1. redux-color - The default theme for the diagram types listed under Per-diagram defaults. It pairs the redux geometry and typography with a categorical colour palette, so entities, actors, branches, classes, subgraph containers and chart series each get their own colour.

  2. redux-dark-color - The dark counterpart of redux-color.

  3. redux - The same geometry and typography as redux-color, but monochrome. Use this when you want the colour to carry meaning you assign yourself rather than being cycled per item.

  4. redux-dark - The dark counterpart of redux.

  5. default - The long-standing Mermaid look, and still the default for every diagram type not listed under Per-diagram defaults.

  6. neutral - This theme is great for black-and-white documents that will be printed.

  7. dark - This theme goes well with dark-colored elements or dark-mode. To use the dark theme (which changes the theme of the schema itself) with dark-mode (which sets the background), set darkMode to true in your config.

  8. forest - This theme contains shades of green.

  9. neo - A flatter, softer look, intended to be paired with look: neo.

  10. neo-dark - The dark counterpart of neo.

  11. base - This is the only theme that can be modified. Use this theme as the base for customizations.

Per-diagram defaults

Not every diagram type defaults to the same theme and look. Since v12.0.0 these do, to the redux-color theme and the neo look. The name on the left is the config key — what you write to scope a setting to that diagram, which is not always the keyword the diagram starts with:

Config keyDiagram
agentflowagentflow-beta
flowchartflowchart
swimlaneswimlane-beta
classclassDiagram
ererDiagram
requirementrequirementDiagram
sequencesequenceDiagram
statestateDiagram
usecaseusecase-beta
vennvenn-beta

Every other diagram type defaults to the default theme and the classic look.

layout works the same way. Only swimlane overrides it, to swimlane; everything else uses the global default, dagre.

These are only defaults, and the most specific thing you say wins. Highest priority first:

  1. The diagram's own frontmatter or %%{init}%% directive.
  2. What you passed to mermaid.initialize().
  3. The diagram type's default, above.
  4. The global default (theme: default, look: classic, layout: dagre).

A layout that is not registered in the running build falls back to dagre, with a warning in the console. elk ships as a separate package you register yourself, and cose-bilkent is only bundled into builds that include the large features, so naming either as a default does not require every build to carry it.

Within each of the first two you can also scope a value to one diagram type, and the scoped value wins over the global one you set alongside it. theme, look and layout can all be set this way:

javascript
mermaid.initialize({
  look: 'classic', // everything is classic...
  flowchart: { look: 'handDrawn' }, // ...except flowcharts
  er: { theme: 'neutral' },
});

The same works in frontmatter, for one diagram:

yaml
---
config:
  flowchart:
    look: handDrawn
---

Going back to the previous appearance

The nine types above changed appearance when these became their defaults. To draw one the way Mermaid drew it before, name the previous theme and look in its front matter:

yaml
---
config:
  theme: default
  look: classic
---

For every diagram on a page, pass the same two keys to mermaid.initialize():

javascript
mermaid.initialize({ theme: 'default', look: 'classic' });

Site-wide Theme

To customize themes site-wide, call the initialize method on the mermaid.

Example of initialize call setting theme to base:

javascript
mermaid.initialize({
  securityLevel: 'loose',
  theme: 'base',
});

Diagram-specific Themes

To customize the theme of an individual diagram, use frontmatter config.

Example of frontmatter config setting the theme to forest:

Code:
mermaid
Ctrl + Enter|

Reminder: the only theme that can be customized is the base theme. The following section covers how to use themeVariables for customizations.

Customizing Themes with themeVariables

To make a custom theme, modify themeVariables via frontmatter config.

You will need to use the base theme as it is the only modifiable theme.

ParameterDescriptionTypeProperties
themeVariablesModifiable with frontmatter configObjectprimaryColor, primaryTextColor, lineColor (see full list)

Example of modifying themeVariables using frontmatter config:

Code:
mermaid
Ctrl + Enter|

Color and Color Calculation

To ensure diagram readability, the default value of certain variables is calculated or derived from other variables. For example, primaryBorderColor is derived from the primaryColor variable. So if the primaryColor variable is customized, Mermaid will adjust primaryBorderColor automatically. Adjustments can mean a color inversion, a hue change, a darkening/lightening by 10%, etc.

The theming engine will only recognize hex colors and not color names. So, the value #ff0000 will work, but red will not.

Theme Variables

VariableDefault valueDescription
darkModefalseAffects how derived colors are calculated. Set value to true for dark mode.
background#f4f4f4Used to calculate color for items that should either be background colored or contrasting to the background
fontFamilytrebuchet ms, verdana, arialFont family for diagram text
fontSize16pxFont size in pixels
primaryColor#fff4ddColor to be used as background in nodes, other colors will be derived from this
primaryTextColorcalculated from darkMode #ddd/#333Color to be used as text color in nodes using primaryColor
secondaryColorcalculated from primaryColor
primaryBorderColorcalculated from primaryColorColor to be used as border in nodes using primaryColor
secondaryBorderColorcalculated from secondaryColorColor to be used as border in nodes using secondaryColor
secondaryTextColorcalculated from secondaryColorColor to be used as text color in nodes using secondaryColor
tertiaryColorcalculated from primaryColor
tertiaryBorderColorcalculated from tertiaryColorColor to be used as border in nodes using tertiaryColor
tertiaryTextColorcalculated from tertiaryColorColor to be used as text color in nodes using tertiaryColor
noteBkgColor#fff5adColor used as background in notes
noteTextColor#333Text color in note rectangles
noteBorderColorcalculated from noteBkgColorBorder color in note rectangles
lineColorcalculated from background
textColorcalculated from primaryTextColorText in diagram over the background for instance text on labels and on signals in sequence diagram or the title in Gantt diagram
mainBkgcalculated from primaryColorBackground in flowchart objects like rects/circles, class diagram classes, sequence diagram etc
errorBkgColortertiaryColorColor for syntax error message
errorTextColortertiaryTextColorColor for syntax error message

Flowchart Variables

VariableDefault valueDescription
nodeBorderprimaryBorderColorNode Border Color
clusterBkgtertiaryColorBackground in subgraphs
clusterBordertertiaryBorderColorCluster Border Color
defaultLinkColorlineColorLink Color
titleColortertiaryTextColorTitle Color
edgeLabelBackgroundcalculated from secondaryColor
nodeTextColorprimaryTextColorColor for text inside Nodes

Sequence Diagram Variables

VariableDefault valueDescription
actorBkgmainBkgActor Background Color
actorBorderprimaryBorderColorActor Border Color
actorTextColorprimaryTextColorActor Text Color
actorLineColoractorBorderActor Line Color
signalColortextColorSignal Color
signalTextColortextColorSignal Text Color
labelBoxBkgColoractorBkgLabel Box Background Color
labelBoxBorderColoractorBorderLabel Box Border Color
labelTextColoractorTextColorLabel Text Color
loopTextColoractorTextColorLoop Text Color
activationBorderColorcalculated from secondaryColorActivation Border Color
activationBkgColorsecondaryColorActivation Background Color
sequenceNumberColorcalculated from lineColorSequence Number Color

Pie Diagram Variables

VariableDefault valueDescription
pie1primaryColorFill for 1st section in pie diagram
pie2secondaryColorFill for 2nd section in pie diagram
pie3calculated from tertiaryFill for 3rd section in pie diagram
pie4calculated from primaryColorFill for 4th section in pie diagram
pie5calculated from secondaryColorFill for 5th section in pie diagram
pie6calculated from tertiaryColorFill for 6th section in pie diagram
pie7calculated from primaryColorFill for 7th section in pie diagram
pie8calculated from primaryColorFill for 8th section in pie diagram
pie9calculated from primaryColorFill for 9th section in pie diagram
pie10calculated from primaryColorFill for 10th section in pie diagram
pie11calculated from primaryColorFill for 11th section in pie diagram
pie12calculated from primaryColorFill for 12th section in pie diagram
pieTitleTextSize25pxTitle text size
pieTitleTextColortaskTextDarkColorTitle text color
pieSectionTextSize17pxText size of individual section labels
pieSectionTextColortextColorText color of individual section labels
pieLegendTextSize17pxText size of labels in diagram legend
pieLegendTextColortaskTextDarkColorText color of labels in diagram legend
pieStrokeColorblackBorder color of individual pie sections
pieStrokeWidth2pxBorder width of individual pie sections
pieOuterStrokeWidth2pxBorder width of pie diagram's outer circle
pieOuterStrokeColorblackBorder color of pie diagram's outer circle
pieOpacity0.7Opacity of individual pie sections

State Colors

VariableDefault valueDescription
labelColorprimaryTextColor
altBackgroundtertiaryColorUsed for background in deep composite states

Class Colors

VariableDefault valueDescription
classTexttextColorColor of Text in class diagrams

User Journey Colors

VariableDefault valueDescription
fillType0primaryColorFill for 1st section in journey diagram
fillType1secondaryColorFill for 2nd section in journey diagram
fillType2calculated from primaryColorFill for 3rd section in journey diagram
fillType3calculated from secondaryColorFill for 4th section in journey diagram
fillType4calculated from primaryColorFill for 5th section in journey diagram
fillType5calculated from secondaryColorFill for 6th section in journey diagram
fillType6calculated from primaryColorFill for 7th section in journey diagram
fillType7calculated from secondaryColorFill for 8th section in journey diagram
Opens in mermaid.ai