World-class creation of valid, beautiful, and accessible Mermaid diagrams...
Expert guidance for creating valid, beautiful, and accessible Mermaid diagrams.
Choose the diagram type that best matches the information structure:
Critical syntax rules:
graph or flowchart (never flow)TD (top-down), LR (left-right), BT, RLnodeId["Label"] for special chars)"text with \"quotes\""%% prefixNode shapes:
A[Rectangle]
B(Rounded rectangle)
C([Stadium/Pill shape])
D[[Subroutine]]
E[(Database)]
F((Circle))
G>Flag/Asymmetric]
H{Decision diamond}
I{{Hexagon}}
J[/Parallelogram/]
K[\Reverse parallelogram\]
L[/Trapezoid\]
M[\Reverse trapezoid/]
Connection types:
--> solid arrow--- solid line (no arrow)-.-> dotted arrow-.- dotted line==> thick arrow=== thick line--text--> labeled arrow---|text|--- labeled lineLayout optimization:
Label clarity:
Hierarchy and grouping:
flowchart TD
subgraph Frontend
A[Web App]
B[Mobile App]
end
subgraph Backend
C[API Server]
D[Database]
end
A --> C
B --> C
C --> D
Class-based styling:
flowchart TD
A[Normal Node]
B[Important Node]
C[Critical Node]
classDef important fill:#ff9,stroke:#333,stroke-width:2px
classDef critical fill:#f99,stroke:#333,stroke-width:4px
class B important
class C critical
Individual node styling:
flowchart TD
A[Start]
B[Process]
C[End]
style A fill:#9f9,stroke:#333,stroke-width:2px
style C fill:#f99,stroke:#333,stroke-width:2px
Recommended color schemes:
fill:#f5f5f5,stroke:#333fill:#d4edda,stroke:#28a745fill:#fff3cd,stroke:#ffc107fill:#f8d7da,stroke:#dc3545fill:#d1ecf1,stroke:#17a2b8Structure:
flowchart TD
Start([Start]) --> Input[/Input Data/]
Input --> Process{Valid?}
Process -->|Yes| Action[Process Data]
Process -->|No| Error[Show Error]
Action --> Output[/Output Result/]
Error --> Input
Output --> End([End])
Best practices:
Structure:
sequenceDiagram
participant User
participant Frontend
participant API
participant Database
User->>Frontend: Click Submit
activate Frontend
Frontend->>API: POST /api/data
activate API
API->>Database: INSERT query
activate Database
Database-->>API: Success
deactivate Database
API-->>Frontend: 200 OK
deactivate API
Frontend-->>User: Show confirmation
deactivate Frontend
Best practices:
-->> for returns/responsesNote for important contextloop, alt, opt, par for control flowStructure:
classDiagram
class Animal {
+String name
+int age
+makeSound() void
}
class Dog {
+String breed
+bark() void
}
class Cat {
+bool indoor
+meow() void
}
Animal <|-- Dog
Animal <|-- Cat
Relationships:
<|-- inheritance*-- compositiono-- aggregation--> association-- link..> dependency..|> realizationStructure:
stateDiagram-v2
[*] --> Draft
Draft --> Review: Submit
Review --> Approved: Approve
Review --> Rejected: Reject
Rejected --> Draft: Revise
Approved --> Published: Publish
Published --> Archived: Archive
Archived --> [*]
Best practices:
[*] initial state[*] final state (if applicable)Structure:
erDiagram
Customer ||--o{ Order : places
Customer {
string name
string email
int customer_id PK
}
Order ||--|{ OrderLine : contains
Order {
int order_id PK
date order_date
int customer_id FK
}
Product ||--o{ OrderLine : includes
OrderLine {
int order_id FK
int product_id FK
int quantity
}
Product {
int product_id PK
string name
decimal price
}
Cardinality symbols:
||--|| one-to-one||--o{ one-to-many}o--o{ many-to-many||--|| exactly one|o--o| zero or oneStructure:
gantt
title Project Timeline
dateFormat YYYY-MM-DD
section Planning
Requirements :done, req, 2024-01-01, 2024-01-15
Design :active, design, 2024-01-16, 2024-02-01
section Development
Frontend :dev1, 2024-02-02, 30d
Backend :dev2, 2024-02-02, 30d
Integration :after dev1 dev2, 10d
section Testing
QA Testing :test, after dev1 dev2, 15d
UAT :after test, 10d
Best practices:
after keywordSyntax errors:
flow TD → ✅ flowchart TD#quot; or single quotesDesign issues:
Accessibility issues:
Add links and tooltips:
flowchart TD
A[Homepage]
B[Product Page]
C[Checkout]
click A "https://example.com" "Go to homepage"
click B "https://example.com/products" "View products"
Combine multiple styling approaches:
flowchart LR
A[Start] --> B{Decision}
B -->|Path 1| C[Option A]
B -->|Path 2| D[Option B]
C --> E[End]
D --> E
classDef decision fill:#ffe6cc,stroke:#d79b00,stroke-width:2px
classDef terminal fill:#d5e8d4,stroke:#82b366,stroke-width:2px
class B decision
class A,E terminal
flowchart TB
subgraph cloud[Cloud Infrastructure]
direction LR
A[Load Balancer]
B[App Server 1]
C[App Server 2]
end
D[User] --> A
A --> B
A --> C
style cloud fill:#e1f5ff,stroke:#01579b
When creating a diagram:
For complex diagrams with many nodes or advanced patterns, see:
Before finalizing a diagram: