Mermaid Diagram Editor · Tutorial
How to draw a flowchart from text with Mermaid
7 min readbeginnerUpdated
You need a flowchart of a sign-up process for documentation, and you want to be able to change it later without redrawing. You will write it in Mermaid, add a decision and a loop, and export it.
What you need
Steps
Choose a direction
The first line sets the diagram type and direction.
flowchart TDdraws top-down; useLRfor left to right.Add steps and arrows
Each node has an ID and a label. Square brackets make a box, curly braces a decision diamond, and
([ ])a rounded end point. Arrows are-->.flowchart TD A[Customer submits form] --> B{Valid?} B -- No --> C[Show errors] C --> A B -- Yes --> D[Save to database]Label the decision
Text between the dashes, as in
B -- Yes --> D, labels the arrow. Every branch of a decision should have one.Fix an error
Delete the closing
]on one line. The preview fades and the message names the line and what Mermaid expected. Put it back and the diagram returns.Export
Use Download PNG for slides, Download SVG for documents, or Copy as Markdown to paste into a GitHub README, where it renders automatically.
Try it yourself
Opens the Mermaid Diagram Editor with this tutorial's sample loaded.
Common mistakes
- Using reserved words as IDs
- An ID called
endbreaks the flowchart. UsefinishorEndinstead. - Brackets or quotes inside labels
- Wrap labels with special characters in double quotes, such as
A["Total (incl. tax)"].
Next steps
Go back to the Mermaid Diagram Editor, or keep going with one of these:
FAQ
Can I change the colours?
Yes, with classDef and class lines, or a %%{init: {"theme": "forest"}}%% line at the top.