← All guides

A Mermaid syntax style guide

Last updated: 2026-05-01

Mermaid does not enforce a style. Your team should. Diagrams written by ten people without a shared style end up looking like ten different diagrams stitched together — which is fine for one repo, painful for thirty.

This is the style guide we use, formed from a few years of Mermaid in production documentation. Borrow it, fork it, or replace it with your own. The point is having one.

1. Node IDs

2. Labels

3. Direction

4. Comments

Mermaid comments use %%:

flowchart TD
  %% Public flow — visitors hit this without auth
  Home --> Pricing
  Pricing --> Signup
  %% Private flow — requires session cookie
  Signup --> Dashboard

5. Indentation

6. Line lengths

Long edge definitions hurt readability. Two patterns help:

Pattern A — split into smaller diagrams when one diagram crosses 30 lines.

Pattern B — break long edges with intermediate nodes:

%% Hard to read
A -- "validates and forwards to" --> B

%% Easier
A --> Validator
Validator --> B

The intermediate node names what is happening, which is often the point of the diagram in the first place.

7. Sequence diagrams

8. Class and ER diagrams

9. State diagrams

10. Theming

Putting it together

A diagram that follows the rules above:

%%{init: {'theme': 'default'}}%%
flowchart TD
  %% Public path — no auth required
  Home --> Pricing
  Pricing --> Signup

  %% Authenticated path
  Signup --> Verify
  Verify --> Dashboard

Compare with the same diagram written without the rules:

flowchart
  HOME --> Pricing_Page
  Pricing_Page --> SIGNUP_FORM
  SIGNUP_FORM --> verify_email_send
  verify_email_send --> DASHBOARD_v2

Both render. The first one survives a pull request review six months later.


Open the live preview · Diagram types · More guides