Mermaid Line Breaks, Quotes, and Special Characters in Labels
Long labels, quotes, and symbols such as parentheses or semicolons are the most common reasons a Mermaid diagram looks wrong or will not render. This guide covers every technique, with a quick reference at the end.
Line breaks with <br>
The simplest way to break a label across lines is the HTML tag <br>. It works in flowchart node labels and edge labels.
Line breaks in node and edge labels
Each <br> starts a new line.
flowchart LR
A[Order service<br>v2.3] -->|publishes<br>OrderCreated| B[Billing service<br>v1.8]In sequence diagrams, <br/> works in messages and notes:
Line breaks in sequence messages and notes
Useful for showing a request line and its payload on separate lines.
sequenceDiagram
Client->>API: POST /orders<br/>{ "sku": "A-42" }
Note over Client,API: Idempotency key<br/>sent in the header
API-->>Client: 201 CreatedMarkdown strings: real newlines and formatting
Flowcharts also support Markdown strings. Wrap the label in double quotes and backticks: "`...`". Inside, a real newline becomes a line break, and you can use **bold** and *italic*.
Markdown strings with bold text and newlines
Mermaid also wraps long Markdown strings automatically.
flowchart TD
A["`**Payment service**
Handles charges and refunds`"] --> B["`*Async*
Ledger writer`"]Characters that need quotes
Brackets, braces, and parentheses define node shapes, so a label containing them must be wrapped in double quotes:
flowchart LR
A[Retry (3x)] %% breaks
B["Retry (3x)"] %% works
Quoting is also the safest option for labels with /, &, |, =, or leading symbols. When in doubt, quote the label.
Quotes, semicolons, and other symbols: entity codes
You cannot put a double quote inside a double-quoted label directly. Mermaid supports entity codes instead. They start with # and end with ;:
Escaping quotes and symbols
#quot; is a double quote, #35; is a hash sign, and numeric codes such as #9829; insert any Unicode character by its decimal number.
flowchart LR
A["He said #quot;ship it#quot;"] --> B["Issue #35;42"]
B --> C["Made with #9829;"]In sequence diagrams, a semicolon ends the statement, so write #59; for a literal semicolon in a message.
Emoji and non-English text
Emoji and Unicode text such as Chinese, Japanese, or accented characters work in labels. Quoting the label avoids surprises with punctuation:
Unicode labels and emoji
Unicode text renders as long as the viewer has a font that includes those characters.
flowchart LR
A["🚀 Deploy"] --> B["✅ 检查通过"]
B --> C["Café menu"]Node IDs are not labels
A node ID must be a single word made of letters, numbers, and underscores. The label is what readers see. Keep IDs short and put the readable text in the label:
flowchart LR
user_svc["User Service (Go)"] --> auth_db[("Auth DB")]
Avoid IDs that collide with keywords, such as end, graph, subgraph, or style.
Quick reference
| You want | Write |
|---|---|
| Line break (flowchart) | A[First<br>Second] |
| Line break (sequence) | A->>B: First<br/>Second |
| Bold or italic text | A["`**bold** *italic*`"] |
| Parentheses or brackets in a label | A["Retry (3x)"] |
| Double quote | #quot; |
| Hash sign | #35; |
| Semicolon (sequence) | #59; |
| Any Unicode character | #<decimal code>;, for example #9829; |
| Comment | %% your comment on its own line |
Try it in Mermaid Preview: Try these snippets in the live editor. If a label still breaks, the error message points to the line that needs quotes.
Open the editor →