Mermaid Block Diagrams
Block diagrams show system components as blocks with connections. Perfect for visualizing system architecture, data flow, and component relationships.
Use Case
Use block diagrams when you need to:
- Show system architecture
- Visualize component relationships
- Document data flow
- Design system components
- Communicate system structure
Code (Basic)
1```mermaid
2block-beta
3 columns 2
4
5 block:Left
6 A[Component A]
7 B["Component B"]
8 end
9
10 block:Right
11 C[Component C]
12 D[Component D]
13 end
14
15 A --> B
16 B --> C
17 C --> D
18```
Result:
Explanation
block-beta- Start block diagram (beta syntax)columns N- Optional, defines column layoutblock:ID/end- Define a vertical block region with an identifier- Inside a block you place regular nodes like
A[Label] -->- Connection between nodes (same as in flowcharts)
Examples
Example 1: System Layout with Columns and Space
1```mermaid
2block-beta
3 columns 1
4
5 db(("DB"))
6 blockArrowId6<[" "]>(down)
7
8 block:ID
9 A
10 B["A wide one in the middle"]
11 C
12 end
13
14 space
15
16 D
17
18 ID --> D
19 C --> D
20
21 style B fill:#969,stroke:#333,stroke-width:4px
22```
Result:
Example 2: Simple System Architecture
1```mermaid
2block-beta
3 columns 2
4
5 block:ClientSide
6 Client[Web Client]
7 end
8
9 block:ServerSide
10 API[API Gateway]
11 Auth[Auth Service]
12 DB[(Database)]
13 end
14
15 Client --> API
16 API --> Auth
17 API --> DB
18```
Result:
Block Elements & Styling
[Label]- Rectangle(Label)- Rounded rectangle([Label])- Stadium shape[[Label]]- Double rectangle[(Label)]- Cylinder (database)block:ID- Logical group of vertically stacked nodesspace- Adds horizontal space between blocksstyle ID ...- Apply CSS-like style to a node or block
Notes
- Use
block-betafor modern block diagrams - Combine
columns,block:ID,space, and arrows to control layout - Connections use
-->for directed edges - Layout is still mostly automatic; you influence it via columns and blocks
Gotchas/Warnings
- ⚠️ Indentation: Block contents must be consistently indented under
block:ID - ⚠️ IDs:
block:IDdefines an identifier you can later connect from/to - ⚠️ HTML: If you use
inside labels, be sure your renderer passes it through correctly - ⚠️ Beta:
block-betais still evolving; check Mermaid docs if syntax changes
Related Snippets
- Architecture Diagrams (C4 Model)
Create system architecture diagrams using C4 model with Mermaid - Chart.js Bar Chart
Create bar charts for data visualization - Graphviz DOT Diagrams
Create complex graph layouts with Graphviz DOT language - KaTeX Math Examples and Tips
Comprehensive guide to KaTeX math notation with examples and tips - Mermaid Arbitrary Graphs
Create arbitrary graphs and networks with Mermaid - Mermaid Charts (Pie, Bar, Line)
Create pie charts, bar charts, and line charts with Mermaid - Mermaid Class Diagrams (UML)
Create UML class diagrams with Mermaid - Mermaid Entity Relationship Diagrams
Create Entity Relationship Diagrams (ERD) with Mermaid - Mermaid Flowchart
Create flowcharts and decision trees with Mermaid - Mermaid Gantt Chart
Create Gantt charts for project timelines and scheduling - Mermaid Git Diagrams
Create Git branch and commit diagrams with Mermaid - Mermaid Kanban Boards
Create Kanban boards for project management with Mermaid - Mermaid Mindmaps
Create mindmaps for brainstorming and organizing ideas with Mermaid - Mermaid Packet Diagrams
Create packet diagrams for network protocols with Mermaid - Mermaid Quadrant Charts
Create quadrant charts for prioritization with Mermaid - Mermaid Radar Charts
Create radar charts for multi-dimensional comparisons with Mermaid - Mermaid Requirement Diagrams
Create requirement diagrams for system requirements with Mermaid - Mermaid Sankey Diagrams
Create Sankey diagrams for flow visualization with Mermaid - Mermaid Sequence Diagram
Create sequence diagrams for interactions and API flows - Mermaid State Diagrams
Create state diagrams and state machines with Mermaid - Mermaid Timeline Diagrams
Create timeline diagrams for chronological events with Mermaid - Mermaid Treemap Diagrams
Create treemap diagrams for hierarchical data visualization with Mermaid - Mermaid User Journey Diagrams
Create user journey maps with Mermaid - Mermaid ZenUML Diagrams
Create ZenUML sequence diagrams with Mermaid - P5.js Interactive Visualizations
Create interactive visualizations and animations with P5.js