Introduction
TL;DR
Mermaid is a JavaScript-based diagramming tool that renders diagrams from Markdown-inspired text syntax in the browser. You declare diagrams in Markdown code blocks using the mermaid language identifier, and GitHub (since 2022), GitLab (13.0+), Notion, and Obsidian automatically render them. Mermaid supports 10+ diagram types including flowcharts, sequence diagrams, Gantt charts, ER diagrams, and class diagrams, enabling version-controlled, text-based documentation without GUI tools.
Mermaid eliminates context switching between documentation and diagram editors. Unlike Visio or Lucidchart, your diagrams live in the same repository as your code, are reviewable via Git diff, and can be collaboratively edited like any Markdown file.
Why it matters: Technical teams can maintain diagrams as living documentation without proprietary tools, reducing friction in architecture discussions, project planning, and system design reviews.
What is Mermaid?
Mermaid is a text-based diagramming and charting library that takes Markdown-inspired syntax and creates diagrams dynamically in the browser using JavaScript. Maintained by Knut Sveidqvist and developed collaboratively with the CommonMark community, Mermaid has become the de facto standard for diagram-as-code in modern technical documentation.
Core Advantages
Text-Based Definition: Diagrams are defined in plain text, not GUI coordinates. You describe relationships and flows; Mermaid handles layout.
Version Control: Diagram source code can be stored in Git, enabling:
- Change tracking via commit history
- Merge conflict detection
- Pull request reviews with diff-based feedback
- Branch-based diagram prototyping
Platform Support: GitHub, GitLab, Notion, Obsidian, and dozens of documentation platforms natively render Mermaid blocks.
No License Dependencies: Unlike Microsoft Visio or Lucidchart, Mermaid is open-source and requires no subscriptions.
Why it matters: Developers spend less time formatting and more time capturing logic. System architects can iterate on designs in issue comments and merge requests, shortening feedback loops by hours or days.
Getting Started: Basic Syntax
How to Declare Mermaid in Markdown
In any Markdown file, wrap your diagram code in a code block with the mermaid language identifier:
| |
When rendered on GitHub or GitLab, this block becomes an iframe that loads Mermaid.js and converts your text into a SVG diagram.
Supported Platforms & Versions
| Platform | Support | Notes |
|---|---|---|
| GitHub | ✅ Yes | Enabled 2022; works on Issues, PRs, Wikis, .md files |
| GitLab | ✅ Yes | GitLab 13.0+; Mermaid 8.4.8 bundled |
| Notion | ✅ Yes | Native support in code blocks |
| Obsidian | ✅ Yes | Requires optional plugin; local rendering |
| Local Markdown Viewers | ⚠️ Conditional | Requires mermaid.js CDN script |
| Static Site Generators | ⚠️ Varies | Jekyll, Hugo, 11ty need plugins (e.g., mermaid-filter) |
For local HTML rendering, include the Mermaid CDN in your document head:
| |
Why it matters: While GitHub and GitLab render Mermaid automatically, teams using static sites or local-first tools need to ensure the Mermaid library is available.
Diagram Types & Syntax
1. Flowcharts (Flowchart)
Flowcharts depict process steps using geometric shapes (nodes) and directional arrows (edges). They are ideal for decision trees, troubleshooting workflows, and business processes.
Basic Syntax
| |
Node Shapes
| Shape | Syntax | Example |
|---|---|---|
| Rectangle | id[text] | A[Process] |
| Rounded Box | id(text) | B(Rounded) |
| Diamond | id{text} | C{Decision} |
| Circle | id((text)) | D((Loop)) |
| Cylinder (Database) | id[(text)] | E[(Database)] |
| Subroutine | id[[text]] | F[[Function]] |
| Asymmetric | id>text] | G>Flag] |
| Trapezoid | id[/text/] | H[/Input/] |
Direction Modifiers
| Direction | Syntax | Orientation |
|---|---|---|
| Top-Down | TD or TB | Vertical flow downward |
| Bottom-Top | BT | Vertical flow upward |
| Left-Right | LR | Horizontal flow right |
| Right-Left | RL | Horizontal flow left |
Link Styles
| Type | Syntax | Appearance |
|---|---|---|
| Arrow | A --> B | Solid arrow |
| Dotted | A -.-> B | Dashed line with arrow |
| Thick | A ==> B | Bold solid arrow |
| Text on Link | `A –> | label| B` |
| Long Link | A ---> B | Extra-long edge (add more dashes) |
Complete Flowchart Example
| |
Why it matters: Flowcharts are universally understood by both technical and non-technical stakeholders, making them essential for communicating algorithms, API workflows, and troubleshooting procedures.
2. Sequence Diagrams
Sequence diagrams model interactions between multiple actors (participants) over time, showing the order and dependencies of messages. They are critical for API design, microservices communication, and protocol specification.[7]
Basic Syntax[2]
| |
Participant Types[2]
| Type | Syntax | Symbol |
|---|---|---|
| Actor | actor A | Person icon (left edge) |
| Participant | participant B | Box (vertical lifeline) |
| Entity | entity E | Database icon |
| Custom | participant B as Label | Aliased name |
Message Types[2]
| Interaction | Syntax | Arrow Style |
|---|---|---|
| Synchronous (blocking) | A->>B: message | Solid arrow |
| Asynchronous (non-blocking) | A--->B: message | Open arrow |
| Return / Response | B-->>A: message | Dotted solid arrow |
| Asynchronous Return | B--->>A: message | Dotted open arrow |
Control Flow[2]
| Structure | Syntax |
|---|---|
| Note | note over A: text or note right of A: text |
| Loop | loop Label … end |
| Alt (If/Else) | alt Condition … else … end |
| Opt (If) | opt Condition … end |
| Parallel | par Name … and … end |
| Break | break Label … end |
| Activate | activate A / deactivate A |
| Autonumber | autonumber (at top) |
Advanced Sequence Diagram
| |
Why it matters: Sequence diagrams force engineers to think through timing, error handling, and dependencies before implementation—reducing bugs and architectural rework.
3. Gantt Charts
Gantt charts visualize project timelines, task dependencies, and work allocation over time. They are essential for project managers, product teams, and cross-functional roadmapping.[8]
Basic Syntax[8]
| |
Task States[8]
| State | Syntax | Appearance |
|---|---|---|
| Default | None | Regular bar |
| Completed | done | Striped bar |
| Active | active | Highlighted bar |
| Critical | crit | Red/bold bar |
Task Syntax[8]
| |
- state (optional):
done,active,crit, ormilestone - id: Unique identifier for dependencies
- start: Date (
YYYY-MM-DD) orafter [previous_id] - duration:
1w,3d,2h,30m(week, day, hour, minute)
Date Format Options[8]
| Format | Example | Use Case |
|---|---|---|
YYYY-MM-DD | 2025-01-15 | ISO standard |
YYYY/MM/DD | 2025/01/15 | Alternative |
| Relative | after task_id, 1w | Dependency-driven |
Advanced Gantt with Milestones
| |
Why it matters: Gantt charts enable stakeholders to see task sequencing, critical paths, and realistic delivery dates—essential for managing expectations and allocating resources.
4. Entity-Relationship Diagrams (ER Diagrams)
ER diagrams model database schemas, showing entities (tables), attributes, and relationships using crow’s foot notation.[10]
Basic Syntax[10]
| |
Crow’s Foot Cardinality[10]
| Notation | Cardinality | Meaning |
|---|---|---|
|o | 0..1 | Zero or one |
|{ | 1..* | One or many |
o{ | 0..* | Zero or many |
|| | 1..1 | Exactly one |
Relationship Syntax[10]
| |
Example: CUSTOMER \|\|--o{ ORDER : places
- CUSTOMER: 1 or 1 (one customer)
- ORDER: 0 or many (multiple orders)
- Label: “places” (from customer perspective)
Advanced ER with Attributes
| |
Why it matters: ER diagrams align database architects, backend engineers, and data analysts on schema structure before implementation—preventing costly redesigns.
5. Class Diagrams
Class diagrams model object-oriented structure, showing classes, attributes, methods, and inheritance relationships.[11]
Basic Syntax
| |
Relationship Types[11]
| Relationship | Syntax | Symbol | Meaning |
|---|---|---|---|
| Inheritance | A <|-- B | <| | B extends A |
| Composition | A --* B | --* | A owns B (strong) |
| Aggregation | A --o B | --o | A uses B (weak) |
| Association | A --> B | --> | A knows B |
| Dependency | A ..> B | ..> | A depends on B |
| Realization | A ..|> B | ..|> | A implements B (interface) |
Member Visibility[11]
| Modifier | Symbol | Visibility |
|---|---|---|
| Public | + | Accessible everywhere |
| Protected | # | Accessible in subclasses |
| Private | - | Accessible only in class |
| Package | ~ | Accessible in package |
Complete Class Diagram Example
| |
Why it matters: Class diagrams facilitate code reviews and onboarding by making the codebase’s structure explicit before diving into implementation details.
Advanced Features & Customization
Styling & Classes
Apply consistent styling to nodes without repeating CSS:[10]
| |
Available CSS Properties:
fill: Background color (hex)stroke: Border color (hex)stroke-width: Border thickness (px)color: Text color (hex)font-style:italicornormalfont-weight:boldornormal
Markdown Formatting in Nodes
Mermaid 10.0+ supports Markdown formatting within node text:[12]
| |
Supported Formatting:
**text**: Bold*text*: Italic<br/>: Line break- Basic Markdown lists
Why it matters: Rich text formatting makes diagrams more readable and reduces the need for accompanying documentation.
Configuration via YAML Frontmatter
For static site generators that parse YAML, configure Mermaid globally:[10]
| |
This applies to all diagrams in that document without repetition.
Practical Implementation Tips
1. Using Mermaid Live Editor
For complex diagrams, use Mermaid Live to draft, visualize, and debug in real-time before copying into your repository.[9]
Workflow:
- Visit https://mermaid.live
- Write diagram code in the left panel
- See live preview on the right
- Export as SVG or PNG
- Copy code into your .md file
2. Incremental Diagram Building
Start with core elements and iteratively add details:[13]
| |
This iterative approach makes reviewing and debugging easier.
3. Git-Based Diagram Management
Store diagrams in version control to track evolution:
| |
This is impossible with image-based tools and enables collaborative design iteration.
4. Rendering Diagrams to Static Files (Node.js)
For PDF exports or static hosting, use the Mermaid CLI:[5]
| |
Use Case: Generate diagram snapshots in CI/CD pipelines for technical specifications or PDFs.
5. Integration with GitHub Workflows
Embed diagrams directly in issue templates and pull request descriptions:[1]
| |
This enables visual communication without leaving GitHub.
Why it matters: Visual context in issues and PRs reduces misunderstandings and accelerates decision-making.
Common Pitfalls & Troubleshooting
| Issue | Cause | Solution |
|---|---|---|
| Diagram not rendering on GitHub | Mermaid not supported in your fork/repo setting | Update GitHub (auto-enabled 2022+) or enable in Settings |
| “mermaid” block renders as code | Platform doesn’t support Mermaid | Use Mermaid Live → PNG/SVG export |
| Text overflows node boxes | Long labels without breaks | Use <br/> or quoted markdown strings |
| Circular dependencies fail | Graph has unresolvable cycles | Refactor diagram to be acyclic or use loop construct |
| Styling not applied | CSS property typo | Check exact property names: stroke-width (not stroke_width) |
Summary
- Mermaid is text-based diagram-as-code that integrates natively with GitHub, GitLab, and modern documentation platforms.
- 10+ diagram types cover flowcharts, sequences, Gantt charts, ER models, and class diagrams.
- Version control integration enables diff-based diagram reviews and branch-based iteration.
- No external tools needed—write and review diagrams in pull requests, issues, and wikis.
- Start with Mermaid Live for complex diagrams to validate syntax before committing.
- Styling and Markdown formatting improve readability without sacrificing maintainability.
Recommended Hashtags
#Mermaid #Markdown #DiagramAsCode #GitHub #GitLab #TechnicalDocumentation #Flowchart #SequenceDiagram #DevOps #SoftwareArchitecture
References
- (Include diagrams in your Markdown files with Mermaid, 2024-07-22)[https://github.blog/developer-skills/github/include-diagrams-markdown-files-mermaid/]
- (Add Flow Chart in Markdown Using Mermaid, 2022-09-20)[https://help.jotterpad.app/en/article/add-flow-chart-in-markdown-using-mermaid-te0vrj/]
- (Sequence diagram, 2021-01-22)[https://mkdocs-magicspace.alnoda.org/tutorials/markdown/diagrams/]
- (Use Mermaid syntax to create diagrams, 2020-04-14)[https://www.drawio.com/blog/mermaid-diagrams]
- (Flowcharts - Basic Syntax, 2025)[https://emersonbottero.github.io/mermaid-docs/syntax/flowchart.html]
- (Add Sequence Diagram in Markdown Using Mermaid, 2022-09-20)[https://help.jotterpad.app/en/article/add-sequence-diagram-in-markdown-using-mermaid-1ngera4/]
- (How to install Mermaid to render flowcharts in markdown, 2025-02-09)[https://stackoverflow.com/questions/50762662/how-to-install-mermaid-to-render-flowcharts-in-markdown]
- (How to Create Stunning Mermaid Diagrams, 2025-08-04)[https://clickup.com/blog/mermaid-diagram-examples/]
- (Sequence Diagrams in Markdown with Mermaid.js, 2023-04-09)[https://newdevsguide.com/2023/04/10/mermaid-sequence-diagrams/]
- (Flowchart Basic Syntax, 2025-05-21)[https://docs.mermaidchart.com/mermaid-oss/syntax/flowchart.html]
- (Entity Relationship Diagram, 2025-04-10)[https://docs.mermaidchart.com/mermaid-oss/syntax/entityRelationshipDiagram.html]
- (Gantt Diagrams, 2025-04-10)[https://docs.mermaidchart.com/mermaid-oss/syntax/gantt.html]
- (Support gitlab markdown in mermaid markdown, 2018-01-17)[https://gitlab.com/gitlab-org/gitlab/-/issues/20727]
- (Mermaid Gantt Chart Timeline Visualization, 2024-09-18)[https://www.youtube.com/watch?v=nXQk6nAiYCk]
- (GitLab Flavored Markdown: Mermaid, 2020-06-04)[https://everyonecancontribute.cafe/post/2020-06-05-mermaid/]
- (Markdown Mermaid Type Overview, 2021-11-11)[https://minhan2.tistory.com/entry/Markdown-mermaid-%ED%83%80%EC%9E%85-%EC%A2%85%EB%A5%98]
- (Why mermaid graph not appear in GitLab, 2019-11-29)[https://stackoverflow.com/questions/59117144/why-mermaid-graph-not-appear-in-gitlab]
- (Gantt Diagrams, 2023-12-31)[https://docs.mermaidviewer.com/diagrams/gantt.html]
- (다이어그램? ERD? Mermaid 하나면 끝!, 2021)[https://www.jeong-min.com/47-mermaid/]