Unsaved
Ready
Loading Monaco Editor...
Preview
Styling
All diagram types

Mermaid Block Diagram Syntax & Layout Examples

Block diagrams place labeled boxes on a grid and connect them. You control the columns, then fill the cells left to right.

Examples

Copy an example, or open it in the live editor with this diagram already loaded.

Three tiers

columns 3 places the next three blocks on one row. The arrows repeat the reading order.

block-beta
    columns 3
    web["Web app"] api["API"] db[("Database")]
    web --> api
    api --> db

A block that spans columns

The :2 suffix spans two columns. space would leave a single cell empty if you needed a gap instead.

block-beta
    columns 2
    edge["Edge cache"]:2
    app["Application"] db[("Postgres")]
    edge --> app
    app --> db

Shapes for different roles

Brackets pick the shape. A cylinder marks storage, and a diamond marks a decision you still want in the grid.

block-beta
    columns 1
    req["Request"]
    choice{"Cache hit?"}
    store[("Cache")]
    req --> choice
    choice --> store

What is a Block Diagram?

A Mermaid block diagram is a grid of blocks. block-beta starts the diagram, columns N sets the width, and the following lines fill cells from left to right. A block is an id plus a label, such as api["API"]. Shapes follow the same brackets as flowcharts: [ ] rectangle, ( ) rounded, [( )] cylinder, { } diamond. space leaves a cell empty, and id:2 makes a block span two columns. Arrows use the flowchart form A --> B. Use a block diagram for a structured layout. Use a flowchart when the story is a process rather than a grid.

When to use it

Use a block diagram for a fixed layout: a request path across three tiers, or a page of labeled parts. Use a flowchart for decisions. Use a C4 diagram when the boxes need the C4 types and descriptions.

Edit this block diagram in the live editor, read the Mermaid cheat sheet, or compare it with Flowchart, C4 Diagram and Architecture Diagram.

Common Use Cases

  • •System architecture - Show high-level component relationships
  • •Network topology - Visualize servers, databases, and connections
  • •Hardware design - Layout electronic components and data paths
  • •Process overview - Show major system components and their interactions
  • •Infrastructure diagrams - Document cloud architecture and services

Syntax Quick Reference

ElementSyntaxDescription
Columnscolumns NSet grid column count
Blockid["Label"]Define a named block
SpacespaceEmpty grid cell
Span columnsid:NBlock spans N columns
ConnectionA --> BConnect blocks with arrow
Block arrowid<["text"]>(direction)Arrow-shaped block

Syntax tips

  • •Start with block-beta and set columns before the blocks. Cells fill left to right, then wrap.
  • •A block needs an id and a label: web["Web app"]. The id is what arrows refer to.
  • •id:2 spans two columns. space consumes one empty cell.
  • •Connect blocks with flowchart arrows: web --> api. Put the arrows after the blocks are declared.
  • •Use a cylinder, [("Database")], for storage so it is visually distinct from a service.

Common mistakes

Setting columns 3 and then wondering why the fourth block wraps.

The column count is the wrap width. Change columns, or span a block with :2, until the grid matches the picture you want.

Drawing an arrow to a label instead of an id.

Arrows use the id, the token before the brackets. web["Web app"] is linked as web, not as Web app.

Using a block diagram for a long decision process.

The grid fights a branching process. Move that diagram to a flowchart.

Export Options

Block diagrams are architecture sketches. SVG is the better docs export. Free PNG exports include a watermark.

Got Mermaid code from ChatGPT? Paste it here to render and export instantly.

Get the Free Mermaid Syntax Cheat Sheet

Free Mermaid Syntax Cheat Sheet

All 21 diagram types in one PDF reference.

Frequently Asked Questions

Ready to create your own block diagram?

Open the editor with this example pre-loaded and start customizing.

Block Diagram templates

Related Diagram Types

All diagram types