Mermaid in Markdown: Write and Preview Diagrams Online

To use Mermaid in markdown, put the diagram inside a fenced code block that starts with ```mermaid. Markdown Preview draws it live next to the rest of your document, using the same code block GitHub reads, so you can write the text and the diagrams in one place. It is free, needs no sign-up, and your document stays in your browser.

How to add a Mermaid diagram to markdown

  1. Open Markdown Preview and start a new line with three backticks followed by mermaid.
  2. On the next lines, write the diagram, for example flowchart LR and then A --> B.
  3. Close the block with three backticks on a line of their own.
  4. The diagram draws in the preview as you type. Keep writing your document around it.

This is a complete diagram:

```mermaid
flowchart LR
  Idea --> Draft --> Review --> Publish
```

The rest of the syntax for headings, tables and code is in the markdown cheatsheet.

Mermaid diagram types you can use

The first line of the block names the type. Each of these was drawn in the editor before it went on this list.

DiagramFirst lineGood for
Flowchartflowchartsteps, decisions and processes
Sequence diagramsequenceDiagrammessages between people or systems
Class diagramclassDiagramclasses and how they relate
State diagramstateDiagram-v2states and the moves between them
Entity relationshiperDiagramdatabase tables and their links
Gantt chartganttproject plans and timelines
Pie chartpieshares of a whole
Mindmapmindmapideas branching from one topic
Timelinetimelineevents in order
Git graphgitGraphbranches, commits and merges
User journeyjourneyhow a user feels at each step
Quadrant chartquadrantChartitems placed on two axes
XY chartxychart-betabar and line charts

Export diagrams with your document

Diagrams travel with the document they sit in. Save it as a PDF and every diagram goes in as a sharp vector graphic; the markdown to PDF guide shows the steps. Export as HTML and you get one file with the diagrams inside it as SVG, which opens in any browser. Writing a README? Check how the diagrams and the rest of the file come out in the README preview before you push.

When a diagram has a mistake

A diagram that cannot be drawn does not disappear or leave a blank space. In its place you see Mermaid's own reason, with the line where it went wrong, above your diagram code, so you can fix it while the rest of the document keeps rendering.

Try it with a sample document

A short write-up with a flowchart, a sequence diagram and a Gantt chart between ordinary paragraphs. Open it in the editor and change any line to see the diagram redraw.

# Login flow

How a user signs in, written as markdown with Mermaid diagrams.

## Steps

```mermaid
flowchart LR
  A[Open app] --> B{Signed in?}
  B -- Yes --> C[Dashboard]
  B -- No --> D[Login form] --> C
```

## Who talks to whom

```mermaid
sequenceDiagram
  Browser->>Server: POST /login
  Server-->>Browser: Session cookie
```

## Plan

```mermaid
gantt
  title Release plan
  dateFormat YYYY-MM-DD
  section Build
  Login form :a1, 2026-12-01, 5d
  Testing    :after a1, 3d
```

Questions about Mermaid in markdown

Does markdown support Mermaid diagrams?

Plain markdown does not, but many tools that render markdown do, including GitHub, GitLab and Markdown Preview. They all look for a fenced code block labelled mermaid and draw the text inside it as a diagram, so the same block works in each of them.

How do I preview a Mermaid diagram online for free?

Open Markdown Preview, paste your diagram inside a block that starts with ```mermaid and ends with ```, and it draws next to your text straight away. It is free, needs no sign-up, and the diagram is drawn by your own browser, so nothing is uploaded.

Why is my Mermaid diagram not rendering?

Markdown Preview shows the reason and the line it failed on in place of the diagram. The usual causes are a fence not labelled exactly mermaid, an arrow with nothing after it, or a label with brackets or other symbols that needs double quotes around it, like A["Step (1)"].

Can I export Mermaid diagrams to PDF?

Yes. Choose Export > Print / Save as PDF. Diagrams are drawn before printing, so they go into the PDF as sharp vector graphics with the rest of your document. Diagrams print in the theme they were drawn in, so switch to the light theme first if you want light diagrams.

Can I export a Mermaid diagram as PNG or SVG?

Not as a separate image file. Diagrams go into the PDF as vector graphics and into the exported HTML file as SVG, together with the rest of the document. For a single image file of one diagram, a diagram-only tool such as the Mermaid Live Editor is the better fit.

Will my diagram look the same on GitHub?

The diagram code is the same, because GitHub reads the same mermaid code block. Colours and fonts can differ a little between the two, since each site styles diagrams its own way, but the shapes, labels and arrows match.

Do diagrams follow dark mode?

Yes. Diagrams redraw in a dark style when you switch the editor to the dark theme, and in a neutral light style in the light theme.

Draw your first diagram

Write the text and the diagrams in one document, with math, tables and highlighted code alongside. No account, and your documents stay in your browser.