Keep a diagram's style in its code with %% flowgraph-theme
One comment line keeps a Mermaid diagram's Flowgraph theme in the file, so it looks the same in your repository, in VS Code, from the CLI and through the render API.
A diagram you styled in Flowgraph Studio and committed to a repository used to lose its look on the way: the code went into the file, and the theme stayed behind on the website. Now the style travels inside the code, as one comment line. Every place Flowgraph draws the file reads it: the VS Code extension, the CLI, the render API, and the website when you import the file again. Other Mermaid tools skip it, as they skip any %% comment.
Plan: Free, Pro and Pro Max.
What the line looks like
flowchart LR
web[Web app] --> api[Orders API]
api --> db[(Orders DB)]
%% flowgraph-theme: {"v":1,"presetId":"midnight","colors":{"accentColor":"#2DD4BF"}}
%% flowgraph-layout: {"v":1,"nodes":{"web":{"x":40,"y":60}}}
presetIdis the preset the style starts from: Midnight, Glass, Blueprint CAD and the rest (the list is below).- Everything else is only what you changed from that preset, so a plain preset stays short:
{"v":1,"presetId":"glass"}. vis the line's own version. Leave it as1.- It sits just above the
%% flowgraph-layout:line, which keeps the positions you arranged by hand. Both are optional, and each works without the other.
Get the line into a file
You rarely need to write it by hand:
- From the website: open the diagram, choose Export → Mermaid code, and keep Style, positions and story on Keep them. The
.mmdor.mdfile you download carries the line. - From VS Code: with the Flowgraph Studio extension, Pull and Save into Workspace write the saved diagram's style into the file. If your repository's
flowgraph.ymlalready gives files that style, no line is added, so the files stay plain. - By hand: add the line at the end of the diagram, as in the examples below.
Where it's read
| Where | What happens |
|---|---|
| VS Code preview and VS Code's Markdown preview | The diagram is drawn, and its background painted, in the line's style, ahead of the repository's flowgraph.yml and the flowgraph.theme setting. Exports from the preview use it too. |
| Render API and the CLI | /v1/render, flowgraph render and flowgraph sync draw the diagram in the line's style. |
| Importing into Flowgraph Studio | Opening the file, pasting the code, a repository import and Open on flowgraph.studio all give the new diagram the line's style. The line then leaves the code: on the website the style is kept beside the code, where the Style panel edits it. |
| Typing or pasting into the code panel | The same: once the line is complete, it becomes the diagram's style and leaves the code. |
| The API and AI assistants | Code sent to POST or PUT /v1/diagrams, or through the MCP server, saves the line as the diagram's style. |
Which style wins
When a file has a theme line, that's its style. A style from anywhere else is only the default for files without one:
- The diagram's own
%% flowgraph-theme:line. - The
theme:file named in the repository'sflowgraph.yml(see Keep README diagrams up to date in CI). - In VS Code, the
flowgraph.themesetting. - Glass.
The render API's theme field and the CLI's --theme flag follow the same rule: they style code that doesn't bring its own.
So a repository can give all its diagrams one look through flowgraph.yml, and a single diagram that needs its own (a slide, a dark poster) carries a line.
Write one by hand
Start with a preset and add what you want to change:
| Key | Values |
|---|---|
presetId |
midnight, monochrome, glass, cyberpunk-neon, warm-editorial, blueprint-cad, forest-canopy, ember-workshop, print-ready, slide-deck, sage-notebook |
colors |
Any of nodeFillTop, nodeFillBottom, nodeBorder, nodeText, edgeColor, canvasBg, accentColor, clusterBg, clusterBorder, shadowColor, as #RRGGBB, rgb() or hsl() |
fontFamily |
Inter, Plus Jakarta Sans, Space Grotesk, IBM Plex Sans, Source Sans 3, Nunito, Roboto Slab, Merriweather, Lora, JetBrains Mono, Fira Code, Caveat |
curveStyle |
basis, bumpX, monotoneX, stepAfter, linear |
lookMode |
classic, handDrawn |
direction |
default, TB, LR, BT, RL |
layoutEngine |
elk, elk.stress, elk.mrtree, elk.radial, elk.rectpacking, dagre |
backgroundPattern |
dots, grid, crosshair, blueprint, none |
edgeLabelBackground |
none, canvas, custom (with edgeLabelBackgroundColor as a colour) |
cornerRadius |
0 to 24 |
borderWidth |
0 to 4 |
edgeThickness |
1 to 4 |
nodeSpacing |
20 to 140 |
rankSpacing |
30 to 160 |
shadowBlur |
0 to 36 |
shadowOffsetY |
0 to 24 |
shadowOpacity |
0 to 1 |
flowSpeed |
0.6 to 4 |
useGradients, useShadows, animatedFlow |
true or false |
Anything Flowgraph doesn't recognise is ignored, and so is a value that isn't one of those listed. A number out of range is brought to the nearest end of its range, so "cornerRadius":40 gives 24. A line that isn't valid JSON is ignored as a whole, and the diagram is drawn as if it had none.
The easiest way to get exact values is to style the diagram on the website and export it, or to download the style with Export → Theme JSON: the line takes the same keys.
Examples
Each of these is drawn on this page in its own style, by the same renderer the editor uses.
A service map in Midnight with a teal accent:
flowchart LR
web[Web app] --> api[Orders API]
api --> queue[(Order events)]
queue --> worker[Fulfilment worker]
worker --> db[(Orders DB)]
%% flowgraph-theme: {"v":1,"presetId":"midnight","colors":{"accentColor":"#2DD4BF"}}A release process in Blueprint CAD, drawn with straight lines:
flowchart TB
build[Build] --> test{Tests pass?}
test -->|yes| stage[Deploy to staging]
test -->|no| fix[Fix and push]
fix --> build
stage --> prod[Release]
%% flowgraph-theme: {"v":1,"presetId":"blueprint-cad","curveStyle":"linear"}A sign-in sequence in Forest Canopy with a serif font:
sequenceDiagram
participant U as User
participant A as App
participant S as Sign-in service
U->>A: Open the app
A->>S: Ask for a session
S-->>A: Session token
A-->>U: Signed in
%% flowgraph-theme: {"v":1,"presetId":"forest-canopy","fontFamily":"Lora"}Leave it out
Choose Export → Mermaid code → Plain Mermaid for code with none of Flowgraph's own lines: no style, no saved positions, no story. Use it when the code goes somewhere that should draw it its own way.
More guides
- Edit Mermaid diagrams visually in VS CodeDrag, connect and restyle a Mermaid diagram on Flowgraph's canvas inside VS Code, and every change is written back into the .mmd file or Markdown block as ordinary code.
- Preview Flowgraph diagrams in VS Code, with icons, layout and your themeInstall the Flowgraph Studio extension to preview Mermaid files and Markdown blocks in VS Code as Flowgraph draws them, see mistakes in plain words, and export SVG or PNG.
- Connect Claude, Cursor or VS Code to Flowgraph Studio by signing inAdd Flowgraph Studio's MCP server to Claude, Claude Code, Cursor or VS Code with its address alone, approve the connection once, and revoke it whenever you like. No API key to copy.