merIDK / Diagram types / ELK layout
Mermaid ELK layout: example and syntax
For large graphs, the ELK layout engine usually gives cleaner results than the default Dagre engine: fewer edge crossings and straighter lines. Switch it on per diagram in the frontmatter, or for every diagram with the Layout menu.
Open this example in the editor
Example code
---
config:
layout: elk
elk:
mergeEdges: true
nodePlacementStrategy: BRANDES_KOEPF
---
flowchart TD
web[Web app] --> gw[API gateway]
mobile[Mobile app] --> gw
gw --> auth[Auth service]
gw --> orders[Order service]
gw --> search[Search service]
orders --> pay[Payment service]
orders --> stock[Inventory service]
orders --> q[[Event bus]]
q --> mail[Email worker]
q --> stats[Analytics worker]
auth --> udb[(Users DB)]
orders --> odb[(Orders DB)]
search --> idx[(Search index)]
stats --> wh[(Warehouse)]
Result
---
config:
layout: elk
elk:
mergeEdges: true
nodePlacementStrategy: BRANDES_KOEPF
---
flowchart TD
web[Web app] --> gw[API gateway]
mobile[Mobile app] --> gw
gw --> auth[Auth service]
gw --> orders[Order service]
gw --> search[Search service]
orders --> pay[Payment service]
orders --> stock[Inventory service]
orders --> q[[Event bus]]
q --> mail[Email worker]
q --> stats[Analytics worker]
auth --> udb[(Users DB)]
orders --> odb[(Orders DB)]
search --> idx[(Search index)]
stats --> wh[(Warehouse)]Syntax quick reference
- Turn it on with frontmatter:
config: layout: elk. elk.mergeEdges: truebundles parallel edges.elk.nodePlacementStrategyacceptsBRANDES_KOEPF,NETWORK_SIMPLEX,LINEAR_SEGMENTSorSIMPLE.- Icons are not supported with ELK in Mermaid 11; use Dagre for icon diagrams.
How to use it
- Open the example in the editor, or paste your own Mermaid code.
- Edit the code on the left. The preview updates as you type, and errors point to the line.
- Export SVG or PNG, copy a Markdown block for GitHub or Notion, or copy a share link.