Skip to main content
Mermaid provides multiple ways to configure diagrams, from site-wide settings to diagram-specific customization. Understanding the configuration hierarchy helps you control how your diagrams render.

Configuration hierarchy

When Mermaid renders a diagram, configuration is applied in the following order:
  1. Default configuration - Built-in defaults for all options
  2. Site configuration - Set via mermaid.initialize() and applied to all diagrams
  3. Frontmatter - Diagram-level configuration in YAML format (v10.5.0+)
  4. Directives - Deprecated diagram-level configuration
The final render configuration is the result of merging these sources, with later sources overriding earlier ones.

Site configuration with initialize

The initialize() method sets site-wide configuration that applies to all diagrams. This should be called once when your application loads.
The initialize() call is applied only once. Subsequent calls will not override the initial configuration.

Frontmatter configuration

Frontmatter allows diagram authors to override configuration for individual diagrams. The frontmatter is a YAML block at the top of the diagram. The config key can contain any configuration option except secure options (like securityLevel).

Available frontmatter options

  • title - Set an accessible title for the diagram
  • config - Override any non-secure configuration options
  • theme - Change the theme (default, base, dark, forest, neutral)
  • themeVariables - Customize theme colors and styles

Common configuration options

Top-level options

These options apply to all diagram types:

Diagram-specific options

Each diagram type has its own configuration namespace:

Resetting configuration

The reset() method resets the current configuration back to the site configuration:

Security considerations

Certain configuration options cannot be overridden by diagram authors for security reasons. These secure options include:
  • securityLevel
  • secure (the list of secure keys itself)
  • Any keys listed in siteConfig.secure
Attempts to modify secure keys via frontmatter or directives will be ignored and logged as warnings.

Configuration flow

Best practices

  • Use initialize for site-wide settings - Set common options once instead of repeating them
  • Use frontmatter for diagram-specific changes - Override only what’s needed per diagram
  • Avoid directive syntax - Directives are deprecated; use frontmatter instead
  • Store config in variables - Avoid calling getConfig() repeatedly
  • Validate your configuration - Invalid options will be silently ignored

Next steps

Directives

Learn about the deprecated directive syntax

Accessibility

Configure accessibility features