Skip to content

ELK Layout

The default Mermaid flowchart layout is dagre. For more control over spacing and routing, switch to the Eclipse Layout Kernel (ELK).

Terminal window
npm install @mermaid-js/layout-elk

Mermaid imports ELK dynamically the first time it needs it, so the package only has to be installed in your project — you do not need to import it yourself.

Pass layout: 'elk' through mermaidConfig:

mermaid({
mermaidConfig: { layout: 'elk' },
});

Setting layout: 'elk' globally applies to flowchart diagrams. Other diagram types (sequence, gantt, pie, etc.) are unaffected. To enable ELK for a single flowchart without changing global config, use a Mermaid frontmatter directive:

```mermaid
---
config:
layout: elk
---
flowchart LR
A --> B --> C
```

See a live comparison on the ELK Layout page.

Learn more about Mermaid layouts or the Eclipse Layout Kernel.