Graph TD online

graph TD is the first line of a Mermaid flowchart that runs from top to bottom. TD means top-down: it sets the overall layout direction, including for diagrams with branches or loops.

In the free Mermaid online editor you paste that line, add the steps underneath, and the preview draws the flowchart in the browser without uploading it for rendering. No account is needed to export or share. Optional AI features send relevant content to the selected provider.

People search for graph TD when they already have a snippet, often from a README or a ticket, and want to see it. The sample below is the same shape as the one on the homepage: a start node, a decision, and a loop back when the answer is no.

Editable example

The source below is in the page HTML. Edit the copy in the text box if you want to change a label, then open it in the live editor for the preview. The link itself always opens this graph TD example.

graph TD
    A[Start] --> B{Ready?}
    B -->|Yes| C[Write graph TD]
    B -->|No| D[Review the syntax]
    D --> B
    C --> E[Export PNG, SVG or PDF]

The link opens the example printed above. If you change the text box, the button sends your edited copy to the editor instead.

Edit this graph TD example in the free Mermaid live editor

Syntax cheat sheet

These are the tokens that show up in almost every graph TD diagram. The direction token is the part that changes the layout.

Mermaid flowchart syntax
SyntaxMeaning
graph TDStart a top-down flowchart. graph is the older keyword, and it still renders.
flowchart TDStart a top-down flowchart with the keyword used in the current Mermaid documentation.
TD / TB / BT / LR / RLDirection after the keyword: top-down, top-to-bottom, bottom-to-top, left-to-right, or right-to-left.
A[Text]A rectangular step.
B{Text}A decision diamond.
C(Text)A rounded node.
A --> BAn arrow from A to B.
A -->|Yes| BAn arrow with a label on it.
A["Text (note)"]Put quotes around a label that contains parentheses or other punctuation.

How graph TD differs from flowchart TD

graph TD and flowchart TD both declare a top-down Mermaid flowchart and draw the same layout. flowchart is the keyword in the current Mermaid documentation. graph is an older alias that still works, so a diagram that already says graph TD does not need to be rewritten.

Use LR instead of TD when the process should read from left to right, for example graph LR. BT draws from the bottom, and RL draws from the right. The nodes and arrows stay the same; only the direction token changes.

graph TD compared with flowchart TD
Comparisongraph TDflowchart TD
Keywordgraph, an older alias that still rendersflowchart, the keyword in the current docs
DirectionTD, top to bottomTD, top to bottom
LayoutTop-down flowchartThe same top-down flowchart
When to use itKeep it on diagrams you already havePrefer it when you write a new diagram

How to draw a graph TD diagram online

Write a top-down Mermaid flowchart with graph TD, preview it in the browser, and export PNG, SVG or PDF.

  1. Start with graph TD. Put graph TD on the first line. That tells Mermaid to draw a flowchart from top to bottom.
  2. Add nodes and arrows. Write one step per line. Use A[Text] for a rectangle, B{Text} for a decision, and --> for an arrow. Add a label with -->|Yes|.
  3. Preview, then export or share. Open the example in the live editor, fix any syntax error the preview reports, then export PNG, SVG or PDF or copy a share link. Ordinary rendering happens in your browser.

FAQ

What does graph TD mean in Mermaid?

graph starts a flowchart, and TD sets the overall direction to top-down. A loop can still point back to an earlier node. graph LR uses left-to-right layout instead.

Is graph TD the same as flowchart TD?

They declare the same top-down flowchart and draw the same layout. flowchart is the keyword in the current Mermaid documentation. graph is an older alias that still works, so existing graph TD code can stay as it is.

How do I turn a graph TD diagram sideways?

Replace TD with LR for left to right, RL for right to left, or BT for bottom to top. You can also use TB, which means the same top-to-bottom direction as TD.

Can I export a graph TD diagram as PNG?

Yes. Open the diagram in the editor and choose Export Drawing, then PNG, SVG or PDF. PNG can be 1x to 4x, with an optional transparent background. The file is created in your browser.

The same editor renders every diagram on this site. These pages cover the neighbouring searches.