What are directives?
Directives give diagram authors the capability to alter the appearance of a diagram before rendering by changing the applied configuration. They are applied on top of the site configuration and allow you to override settings for individual diagrams.Directive syntax
A directive always starts and ends with%% signs with directive text in between:
init as the root key. All general configurations are defined at the top level, and diagram-specific configurations are nested under the diagram type.
Multi-line format
Single-line format
The JSON object must use valid key-value pairs and be enclosed in quotation marks, or it will be ignored.
Types of directive options
Mermaid supports two types of configuration options in directives:General/top-level configurations
These apply to all diagrams:theme- Visual theme selectionfontFamily- Font family for all textlogLevel- Logging verbositysecurityLevel- Security restrictionsstartOnLoad- Auto-render behaviorhtmlLabels- HTML support in labels
Diagram-specific configurations
These apply only to specific diagram types:flowchart- Flowchart options likecurve,diagramPaddingsequence- Sequence diagram options likemirrorActors,wrapgantt- Gantt chart options likebarHeight,fontSize- And more for each diagram type
Directive examples
Changing theme
Set the theme toforest:
Available themes: default, base, dark, forest, neutral
Changing font family
Set a custom font family:Changing log level
Set the log level for debugging: Log level values:1- debug2- info3- warn4- error5- fatal only (default)
Flowchart configuration
Configure flowchart-specific options: Common flowchart options:curve- Edge curve style (linear, basis, cardinal)diagramPadding- Padding around the diagramuseMaxWidth- Fit to container width
Sequence diagram configuration
Enable text wrapping for long messages: Common sequence diagram options:width- Actor box widthheight- Actor box heightmessageAlign- Message text alignment (left, center, right)mirrorActors- Show actors on both sidesuseMaxWidth- Fit to container widthrightAngles- Use right-angle arrowsshowSequenceNumbers- Display sequence numberswrap- Wrap long message text
Combining directives
Multipleinit or initialize directives are merged together. Later values override earlier ones:
This produces the merged configuration:
Both
init and initialize are accepted as directive keywords and will be grouped together.Migration to frontmatter
The frontmatter syntax is the recommended replacement for directives:- Directive (deprecated)
- Frontmatter (recommended)
Limitations
- Security restrictions - Secure configuration keys cannot be overridden via directives
- No schema validation - Invalid options are silently ignored
- JSON syntax only - Must use valid JSON with quoted keys and values
- Deprecated - Directives will be removed in a future major version
Next steps
Setup and configuration
Learn about frontmatter and modern configuration
Accessibility
Add accessibility features to diagrams