Mermaid Chart Tutorial: Creating Diagrams with Code
Mermaid Chart is a powerful web-based diagram editor built by the team behind Mermaid.js, allowing you to create and edit diagrams directly in your browser. It enhances the core Mermaid functionality with features like AI diagramming, collaboration capabilities, and cloud storage for your diagrams.
What is Mermaid?
Mermaid is a JavaScript-based diagramming tool that allows you to create diagrams using text and code rather than dragging and dropping elements. This approach offers several advantages:
Version control friendly: Diagrams can be stored as text in repositories
Quick creation: No need to manually position elements
Easy updates: Modify the code to update the diagram rather than redrawing
Markdown integration: Works seamlessly in documentation
Text between pipes |text| labels the connections[4][7]
Sequence Diagrams
code
sequenceDiagram
participant User
participant System
User->>System: Request data
System-->>User: Return data
User->>System: Submit form
System-->>User: Confirm submission
Sequence diagrams show the order of interactions between actors in a process[7]
Entity-Relationship Diagrams
code
erDiagram
CUSTOMER ||--o{ ORDER : places
ORDER ||--|{ LINE_ITEM : contains
CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
ER diagrams show relationships between entities in a system[7]
Advanced Features and Customization
Node Styling
You can customize node shapes using different bracket styles:
[Text] - Rectangle
(Text) - Rounded rectangle
{Text} - Diamond
([Text]) - Stadium shape[4]
Link Styling
Links between nodes can also be customized:
--> - Arrow
--- - Line without arrow
-.-> - Dotted line with arrow
--o - Line with circle
--x - Line with cross[4]
Subgraphs and Grouping
Group related nodes together using subgraphs:
code
flowchart TD
subgraph Backend
B1[Server] --> B2[Database]
end
subgraph Frontend
F1[UI] --> F2[API Client]
end
F2 --> B1
This creates visual sections in your diagram to better organize information[4][6]
Saving and Sharing Your Diagrams
Mermaid Chart provides several options for preserving your work:
Timeline History: Your edits are autosaved and appear in the Timeline tab (last 30 edits viewable)
Manual Saving: Click the Save icon in the History section
Export Options:
Export as PNG
Export as SVG
Export as Markdown[1]
Loading from Gists
You can load diagrams from GitHub Gists:
Create a Gist with a code.mmd file and optionally a config.json file
Copy the Gist URL
Paste it into the respective field in the Actions section
Click "Load Gist"[1]
Integration with Other Tools
Mermaid Chart can be integrated with various tools:
GitHub: Native support in markdown files
Notion: Supports Mermaid diagrams
VS Code: Extensions available for live preview
Confluence: Plugins available[2][3]
Best Practices
For effective diagrams:
Keep it simple: Focus on clarity over complexity
Use meaningful labels: Ensure all elements are clearly labeled
Maintain consistent styling: Use a consistent approach to shapes, colors, and fonts
Validate your syntax: Check for errors before sharing
Reuse code snippets: Save common patterns for future use[5][7]
Troubleshooting
If your diagram doesn't render correctly:
Check for syntax errors in your code
Verify that all brackets and parentheses are properly closed
Make sure node IDs are unique
Use the preview panel to identify issues as you type[1][8]
By mastering Mermaid Chart, you'll be able to quickly create professional diagrams for documentation, presentations, or collaboration, all without leaving your keyboard or dealing with complex design tools.