# Mermaid Layout Editor > A browser editor that renders Mermaid flowcharts and lets you hand-tune their layout: move nodes, resize nodes and subgraphs, move edge labels, and pin edges to specific attachment points with custom orthogonal routes. Every manual change is stored as a plain Mermaid comment line (`%% @...`) inside the diagram source, so the code stays valid Mermaid and any other renderer simply ignores the layout hints. This page describes the layout-hint syntax so that an LLM can read, preserve and write it. ## Scope - Layout hints apply to **flowcharts only** (`flowchart` / `graph`). Other diagram types render normally but ignore hints. - Layout engine: ELK (default) or dagre, chosen in the UI. Hints are applied on top of whatever the engine produced, so coordinates depend on the engine and on the diagram content. - Rendering uses Mermaid 12. ## Hint lines Each hint is one line of its own, anywhere in the diagram (the editor appends new ones at the end, indented like the diagram body): ``` %% @pos , %% @size , %% @grow ,,, %% @label , %% @edge [from:] [to:] [via:] ``` Rules that apply to every hint: - The line must start with `%%` (leading whitespace allowed), followed by `@kind`, the id, and the values. Nothing else may be on the line. - Numbers are plain decimals, optionally negative (`12`, `-4.5`). No units, no exponent notation. - Pairs are comma-separated with no space required (`120,80` or `120, 80`). - One line per id and kind. If an id appears twice for the same kind, the last line wins; keep exactly one. - Ids are the Mermaid ids (`A` in `A[Label]`), not the labels. Ids may not contain whitespace. - All units are SVG pixels of the rendered diagram. ### @pos — pin a node ``` %% @pos pack 240,310 ``` Places the **centre** of node `pack` at (x, y). This is the node's `translate(x, y)` in the coordinate space of its parent SVG group, which for most diagrams is the whole diagram's coordinate space (origin at top-left of the layout, y growing downward). A pinned node is no longer moved by the layout engine. Subgraphs containing pinned nodes re-fit around their children, keeping their original padding. ### @size — resize a node ``` %% @size pack 180,60 ``` Sets the node's shape to `width,height`, centred on its position. The label text is not scaled. Minimum 10 px per side. The editor always writes a `@pos` line alongside a `@size` line for the same node. ### @grow — enlarge a subgraph box ``` %% @grow ship 0,20,40,0 ``` Adds extra space to subgraph `ship` beyond the box that fits its children: `left,top,right,bottom` in pixels. The subgraph's title stays centred at its top. Use the subgraph's id (`subgraph ship [Shipping]` → `ship`). ### @label — move an edge label ``` %% @label check-->pack 0,-18 ``` Offsets the edge's label by `dx,dy` from where it would otherwise be drawn (the midpoint of the routed edge, or Mermaid's original label position). ### @edge — anchor and route an edge ``` %% @edge check-->reorder from:right to:top %% @edge wait-->pack from:left to:bottom via:y420,x60 ``` Any combination of the three parts, separated by spaces, in any order; at least one is required. - `from:` — where the edge leaves the source node. - `to:` — where the edge enters the target node. - `via:` — comma-separated orthogonal waypoints, see below. An omitted `from`/`to` is chosen automatically (the facing sides of the two boxes). When an edge has an `@edge` hint, or when either of its endpoints is pinned/resized, it is redrawn as an orthogonal polyline with rounded corners instead of Mermaid's original curve. Self-loops (`A --> A`) ignore `@edge`. ## Edge keys Edges are identified by their endpoint ids, not by arrow style or label: ``` --> ``` - The key always uses `-->`, whatever the arrow in the source (`---`, `-.->`, `==>`, `--o`, `-- text -->`, `-->|text|` all become `A-->B`). - Direction follows the source code: `A --> B` is `A-->B`; `B --> A` is `B-->A`. - Chained edges are split: `A --> B --> C` gives `A-->B` and `B-->C`. `A & B --> C` gives `A-->C` and `B-->C`. - When the same pair has several edges, the first (in source order) is `A-->B`, the second `A-->B#1`, the third `A-->B#2`, and so on. - An endpoint may be a subgraph id when an edge connects to a subgraph. ## Anchors Anchors are points on the node's bounding box. For non-rectangular shapes (diamonds, circles, stadiums…) the point is pulled in along the line to the centre until it lies on the shape's outline. Named anchors, clockwise from the top-left corner: ``` top-left top-25 top top-75 top-right left-25 right-25 left right left-75 right-75 bottom-left bottom-25 bottom bottom-75 bottom-right ``` - `top`, `right`, `bottom`, `left` are the side midpoints. - `-` is a point that far along the side: along `top`/`bottom` from left to right, along `left`/`right` from top to bottom. Any percentage strictly between 0 and 100 is allowed, including decimals: `top-33.33`, `left-10`, `bottom-62.5`. Use this to spread several edges along one side. - Corners leave/enter in whichever of their two directions faces the other node. - An unrecognised anchor name is ignored (treated as omitted). ## Waypoints (`via:`) `via:` lists the coordinates of the edge's interior segments, in order from source to target, as axis-tagged numbers in diagram SVG coordinates: - `y` — a horizontal run at that y. - `x` — a vertical run at that x. Each token sets one coordinate of the next corner, so tokens should alternate between `x` and `y`. The router adds short stubs (16 px) out of the source anchor and into the target anchor when needed to make the turns orthogonal. Example: leave `wait` from its left side, run down to y=420, across to x=60, then into `pack`'s bottom: ``` %% @edge wait-->pack from:left to:bottom via:y420,x60 ``` When the anchors alone give a good route, omit `via`. ## Complete example ```mermaid flowchart TD start([Order received]) --> check{In stock?} check -->|Yes| pack[Pack items] check -->|No| reorder[Reorder from supplier] reorder --> wait[Wait for delivery] wait --> pack subgraph ship [Shipping] pack --> label[Print label] label --> courier[Hand to courier] end courier --> done([Done]) %% @pos reorder 360,250 %% @size pack 180,56 %% @pos pack 120,250 %% @grow ship 0,0,40,0 %% @edge check-->reorder from:right to:top %% @edge wait-->pack from:left to:right %% @label check-->pack -12,0 ``` ## Guidance for LLMs - **Preserve hints.** When editing a diagram that contains `%% @` lines, keep them unchanged unless asked to change the layout. When renaming a node id, rename it in its `@pos`/`@size`/`@grow` lines and in every edge key that uses it. When deleting a node or edge, delete its hint lines. When adding or removing an edge between a pair that already has edges, the `#n` suffixes of later edges in that pair shift. - **Prefer relative hints when writing from scratch.** `@edge` anchors, `@label` offsets and `@grow` paddings do not need absolute coordinates and are safe to write without seeing the rendered diagram. `@pos` and `via:` use absolute coordinates that depend on the layout engine's output; only write them if you know the current coordinates (for example from existing `@pos` lines in the same diagram) and move them relative to those. - **Don't invent other hint kinds.** Only `@pos`, `@size`, `@grow`, `@label` and `@edge` are recognised; any other `%%` line is an ordinary Mermaid comment. - **Hints are optional.** A diagram with no hint lines is just a normal Mermaid flowchart laid out by the engine. Removing all `%% @` lines restores the automatic layout. ## Files and embedding - The editor opens `.mmd` files, Markdown files (it takes the first ```` ```mermaid ```` fenced block), and SVGs it exported. - "SVG with embedded code" stores the full source (with hints) in the SVG as `…`. To recover the diagram from such an SVG, read the text of that element. - "HTML editor" exports a standalone copy of the editor with the diagram embedded as JSON in ``.