Mermaid Diagrams in Jekyll
This guide covers everything you need to know about using Mermaid diagrams in your Jekyll site.
✅ GitHub Pages Compatible: Works with GitHub Pages without custom plugins!
Quick Start
1. Enable Mermaid on a Page
Add mermaid: true to your page’s front matter:
---
title: "My Page with Diagrams"
mermaid: true
---
2. Add a Diagram
Option A: Native Markdown Syntax (Recommended)
Use triple backticks with mermaid as the language:
```mermaid
graph TD
A[Start] --> B{Decision}
B -->|Yes| C[Success]
B -->|No| D[Try Again]
```
Option B: HTML Div Syntax
Use the <div class="mermaid"> syntax:
<div class="mermaid">
graph TD A[Start] --> B{Decision} B -->|Yes| C[Success] B -->|No| D[Try Again]
</div>
Result:
Diagram Types
1. Flowcharts
Basic Flowchart:
Directions:
TDorTB- Top to bottomBT- Bottom to topLR- Left to rightRL- Right to left
Node Shapes:
A[Rectangle]- RectangleA(Rounded)- Rounded edgesA{Diamond}- Diamond (decision)A((Circle))- Circle
2. Sequence Diagrams
Arrow Types:
->- Solid line without arrow-->- Dotted line without arrow->>- Solid line with arrow-->>- Dotted line with arrow
3. Class Diagrams
Relationships:
<|--- Inheritance*--- Compositiono--- Aggregation-->- Association
4. State Diagrams
5. Entity Relationship Diagrams
6. Gantt Charts
7. Pie Charts
8. Git Graphs
9. Journey Diagrams
Styling and Customization
Theme Options
The Mermaid theme is configured in _includes/components/mermaid.html:
mermaid.initialize({
theme: "forest", // Options: default, forest, dark, neutral, base
themeVariables: {
primaryColor: "#007bff",
primaryTextColor: "#fff",
},
});
Custom Colors
Icons (FontAwesome)
Advanced Features
Links and Interactivity
Subgraphs
Comments
<div class="mermaid">graph TD A --> B %% This is a comment B --> C</div>
Troubleshooting
Common Issues
| Issue | Solution |
|---|---|
| Diagram not rendering | Add mermaid: true to front matter |
| Syntax error | Validate at mermaid.live |
| Diagram too small | Diagrams are responsive by default |
| Wrong colors | Check theme setting in mermaid.html |
| Console errors | Check browser DevTools for JavaScript errors |
Testing Your Diagrams
- Validate Syntax: Use Mermaid Live Editor
- Check Front Matter: Ensure
mermaid: trueis present - Browser Console: Look for JavaScript errors
- Clear Cache: Force refresh (Cmd+Shift+R / Ctrl+Shift+R)
Best Practices
1. Keep Diagrams Simple
<!-- ✅ Good - Clear and focused -->
<div class="mermaid">graph LR A[Input] --> B[Process] --> C[Output]</div>
<!-- ❌ Avoid - Too complex -->
<div class="mermaid">graph TD A --> B --> C --> D --> E --> F --> G --> H</div>
2. Use Descriptive Labels
<!-- ✅ Good -->
<div class="mermaid">
graph TD A[User Login] --> B{Credentials Valid?} B -->|Yes| C[Dashboard] B
-->|No| D[Error Message]
</div>
3. Add Comments for Complex Diagrams
<div class="mermaid">
graph TD %% Main authentication flow A[Start] --> B{Auth Type} %% OAuth path B
-->|OAuth| C[OAuth Provider] %% Basic auth path B -->|Basic| D[Verify
Credentials]
</div>
Resources
Official Documentation
- Website: mermaid.js.org
- GitHub: mermaid-js/mermaid
- Live Editor: mermaid.live
Learning Path
- Start Here: This guide covers the basics
- Practice: Use mermaid.live to test diagrams
- Reference: Keep this page bookmarked for syntax
- Master: Read Official Docs for advanced features
Implementation Details
File Structure
_includes/
└── components/
└── mermaid.html # Mermaid configuration
└── core/
└── head.html # Conditional include
_config.yml # Plugin configuration
Configuration
The implementation uses:
- Mermaid v10 - Latest stable version
- Conditional Loading - Only loads when
mermaid: true - Forest Theme - Optimized for dark mode
- FontAwesome Support - Icons in diagrams
- Responsive Design - Scales automatically
Happy Diagramming! 📊
This implementation is fully functional and GitHub Pages compatible.