Developer and Text Tools

How to Write Graphviz DOT Graphs and Fix Their Syntax Errors

Learn the DOT language from nodes and edges to clusters and layouts, read DOT syntax errors, and preview and export graphs right in your browser.

Saizul Amin
Saizul Amin7 Nov 2026 · 4 min read
How to Write Graphviz DOT Graphs and Fix Their Syntax Errors

Graphviz has been drawing graphs from plain text since the early 1990s, and its DOT language is still everywhere: build tools export dependency graphs in it, databases describe query plans with it, and countless README files contain a small digraph block. Writing DOT is quick once you know a handful of rules, and this guide covers them along with the errors that trip people up.

The smallest useful graph

A DOT file starts with digraph for a directed graph or graph for an undirected one, followed by an optional name and a pair of braces. Inside, each statement ends with an optional semicolon.

digraph deploy { build -> test -> release; }

That single line creates three nodes and two edges, because DOT lets you chain edges. In an undirected graph you write -- instead of ->. Mixing the two is one of the most common errors.

Attributes and defaults

Attributes go in square brackets after a node or edge: release [shape=box, color=green] or test -> release [label="pass"]. Instead of repeating them, set defaults for everything that follows with node [shape=box, style="rounded,filled"] or edge [color="#475569"]. Graph-wide settings such as rankdir=LR, which turns a top-to-bottom flow sideways, are written as plain assignments.

Labels can contain \n for a line break. Quoted strings may contain spaces and punctuation, while plain identifiers must be letters, digits and underscores.

Grouping with clusters

A subgraph whose name starts with cluster is drawn inside its own box. Give it a label and a style and the nodes inside are kept together:

subgraph cluster_ci { label="CI"; checkout -> install -> lint; }

Another useful group is { rank=same; a; b; }, which forces nodes onto one row in a layered layout.

Choosing a layout engine

Graphviz offers several engines. dot draws layered, hierarchical graphs and suits anything with a direction of flow: pipelines, call graphs, org charts and state machines. neato and fdp use spring models for undirected networks, and circo arranges nodes around circles, which works well for rings and small cycles. You can name the engine with a layout attribute in the file or choose it in your tool.

Editing with a live preview

The free Graphviz DOT Graph Editor redraws the graph as you type. Its built-in renderer is written in TypeScript and works offline. It reads the full DOT grammar, including strict graphs, ports, HTML labels, edges to whole subgraphs and every comment style, and draws a layered layout that follows the same ideas as dot, plus spring and circular layouts. Snippet buttons insert a node, an edge, a cluster, a same-rank group or a set of default styles, and a statistics bar counts nodes, edges and clusters, the connected parts of the graph and whether a directed graph has a cycle.

When you need the exact Graphviz output, press the button to load Graphviz compiled to WebAssembly. It is about 1.2 MB, comes from a pinned version on jsDelivr, and once loaded the preview uses the real engine with its own warnings. Your DOT text is never sent anywhere either way.

Reading syntax errors

A good error message says where and what. The editor reports each problem with its line and column, then skips the broken statement and keeps drawing the rest, so one typo does not blank the whole picture. Click an error to jump to that line.

Load the broken sample to see the typical cases. A line like b -> c [label="ok"; forgets the closing bracket, so the parser runs into the next line and reports that it expected an attribute name or ] but found --, and that the bracket opened on line 3 is still open. A line like e -> ; has an edge with no target, reported as a missing node name. Fix both and the graph renders cleanly.

Other frequent mistakes are using -> in an undirected graph, forgetting quotes around a label with spaces, and leaving a subgraph without its closing brace. Each produces a message that names the problem in plain words.

Exporting the result

Download SVG for documentation and websites, since it stays sharp at any zoom level, or PNG at double resolution for slides and chat. You can also download the DOT source, copy the SVG markup, or print the graph together with its source. The Format DOT button rewrites a messy file with one statement per line and consistent quoting.

Diagrams that live with your code

The real strength of DOT is that a diagram is just text. It can sit in a repository next to the code it describes, be reviewed in a pull request and be regenerated by a script. Keep graphs small and focused, use clusters for structure, and let the layout engine do the positioning.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages