How to Add Multiline Labels in Graphviz

All Graphviz tools and guides

In a quoted DOT label, use \n for a centered line break or \l to end a left-aligned line. For mixed formatting, use an HTML-like label with <BR/>.

Use a quoted multiline label

digraph Status {
  node [shape=box];
  api [label="API gateway\nPublic endpoint"];
  worker [label="Worker\lQueue: emails\lRetries: 3\l"];
  api -> worker;
}

Run this example

The API label is centered on two lines. Each worker line ends with \l, including the last one, so the three lines are left-aligned.

Use a quoted multiline label: rendered example

Mix bold text with line breaks

digraph Status {
  node [shape=box];
  api [label=<<B>API gateway</B><BR/>Public endpoint>];
  worker [label=<Worker<BR/>Queue: emails &amp; alerts>];
  api -> worker;
}

Run this example

The gateway heading is bold. The worker label uses an escaped ampersand because HTML-like labels follow different escaping rules from quoted DOT strings.

What to watch for

Paste these examples directly into the DOT editor. If your application generates DOT inside a JavaScript or Python string, that host language may need an additional backslash to preserve the DOT escape. Inspect the generated DOT before debugging the renderer.

HTML-like labels support a defined subset of tags, not arbitrary webpage HTML. Keep the outer angle-bracket delimiter around the whole label and escape literal ampersands as &amp;. A backslash-n inside an HTML-like label is not the same mechanism as <BR/>.

Related guides

Reference: Official documentation.