All diagram types Open editor

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

How to use it

  1. Open the example in the editor, or paste your own Mermaid code.
  2. Edit the code on the left. The preview updates as you type, and errors point to the line.
  3. Export SVG or PNG, copy a Markdown block for GitHub or Notion, or copy a share link.

More diagram types