Skip to content

TreeView Diagram (v11.14.0+) โ€‹

WARNING

TreeView diagrams are in beta. Diagrams start with the treeView-beta keyword, and the syntax may still change in a backwards-incompatible way before it is declared stable.

Introduction โ€‹

A TreeView diagram is used to represent hierarchical data in the form of a directory-like structure, with file/folder icons, connector lines, and optional annotations.

Syntax โ€‹

The structure of the tree depends only on indentation. Labels can be bare (unquoted) or quoted (for names containing spaces).

  • Directories are indicated by a trailing / on the label โ€” they render in bold text.
  • Icons are hidden by default โ€” enable the built-in file/folder icons with the showIcons config option, or set one per node with icon().
  • Quoted labels ("my file") support spaces in names.
treeView-beta
    my-project/
        src/
            index.js
        package.json
        README.md

Quoted labels (backward compatible):

treeView-beta
    "my project"
        "folder with spaces"
            "file.js"

Box-Drawing Input โ€‹

As an alternative to indentation, you can use box-drawing characters to define the tree structure. The parser auto-detects the format โ€” no extra keyword or config is needed. This is how most file tree diagrams are drawn already, so you can turn those into Mermaid diagrams with very little effort.

Both standard (โ”œโ”€โ”€, โ””โ”€โ”€, โ”‚) and heavy (โ”ฃโ”โ”, โ”—โ”โ”, โ”ƒ) Unicode variants are supported.

Code:
mermaid
treeView-beta
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ index.ts
โ”‚   โ””โ”€โ”€ utils.ts
โ”œโ”€โ”€ package.json
โ””โ”€โ”€ README.md
Ctrl + Enter|

All annotations work the same way โ€” just append them after the label:

Code:
mermaid
treeView-beta
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ App.tsx :::highlight icon(logos:react) ## main component
โ”‚   โ””โ”€โ”€ index.ts ## entry point
โ”œโ”€โ”€ .env ## environment variables
โ”œโ”€โ”€ Dockerfile
โ””โ”€โ”€ package.json
Ctrl + Enter|

Depth is inferred from the column position of the branch character, so deeper nesting works naturally:

Code:
mermaid
treeView-beta
โ”œโ”€โ”€ packages/
โ”‚   โ”œโ”€โ”€ mermaid/
โ”‚   โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ parser.ts
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ renderer.ts
โ”‚   โ”‚   โ””โ”€โ”€ package.json
โ”‚   โ””โ”€โ”€ parser/
โ”‚       โ””โ”€โ”€ src/
โ””โ”€โ”€ README.md
Ctrl + Enter|

Note: If a parse error occurs, line numbers in the error message refer to your original input. Tab characters are automatically expanded to spaces.

Annotations โ€‹

Highlighting with :::class โ€‹

Annotate a node with :::className to apply a CSS class. A built-in highlight class is provided:

Code:
mermaid
treeView-beta
    src/
        App.tsx :::highlight
        index.js
    package.json
Ctrl + Enter|

Inline descriptions with ## โ€‹

Add a visible description after ## โ€” rendered next to the label in italic:

Code:
mermaid
treeView-beta
    src/
        index.js ## app entry point
        config.ts ## runtime configuration
    package.json ## project manifest
Ctrl + Enter|

Icons โ€‹

Icons are hidden by default. Set the showIcons config option to true to show the built-in icons โ€” file for files and folder for directories:

Code:
mermaid
---
config:
  treeView:
    showIcons: true
---
treeView-beta
    src/
        index.js
    package.json
Ctrl + Enter|

File-type icons via config maps โ€‹

Mermaid ships no filename/extension mapping โ€” file-type icons are fully user-configured through the filenameIcons and extensionIcons config options, using icons from a registered icon pack such as material-icon-theme. Values are resolved like icon() references โ€” pack:name is used as-is, unprefixed names resolve via defaultIconPack, and none hides the icon for matching files. Directories and unmapped files keep the built-in folder/file icons:

Code:
mermaid
---
config:
  treeView:
    showIcons: true
    defaultIconPack: material-icon-theme
    filenameIcons:
      Dockerfile: docker
    extensionIcons:
      .ts: typescript
      .tsx: react-ts
      .txt: none
---
treeView-beta
    src/
        App.tsx
        utils.ts
    Dockerfile
    notes.txt
    README.md
Ctrl + Enter|

Icon overrides with icon() โ€‹

Set a node's icon explicitly with icon(name), where name is any icon from a registered icon pack, referenced as pack:name. Explicit icons always render, even when showIcons is off:

Code:
mermaid
treeView-beta
    src/
        App.tsx icon(logos:react)
        index.js
    package.json
Ctrl + Enter|

When defaultIconPack is set, unprefixed names resolve in that pack โ€” icon(rust) becomes shorthand for icon(material-icon-theme:rust). The built-in file and folder icons can always be referenced without a prefix, e.g. icon(folder).

INFO

Icon packs are not bundled with Mermaid โ€” they must be registered with registerIconPacks by the site embedding the diagram. See registering icon packs. An unregistered icon renders as a question mark.

Hiding icons โ€‹

When showIcons is enabled, use icon() or icon(none) to hide the icon of a single node:

Code:
mermaid
---
config:
  treeView:
    showIcons: true
---
treeView-beta
    src/
        index.js icon(none)
    package.json
Ctrl + Enter|

Combined annotations โ€‹

Annotations can be combined in any order:

Code:
mermaid
treeView-beta
    my-project/
        src/
            App.tsx :::highlight icon(logos:react) ## main component
            index.js ## entry point
        .env ## environment variables
        Dockerfile
        package.json
Ctrl + Enter|

Comments โ€‹

Use %% for invisible comments (standard Mermaid convention):

treeView-beta
    %% Generated files โ€” do not edit
    src/
        generated/
        index.js

Examples โ€‹

Basic with quoted labels:

Code:
mermaid
treeView-beta
    "packages"
        "mermaid"
            "src"
        "parser"
Ctrl + Enter|

Unicode and emoji in labels:

Labels are rendered exactly as written โ€” unicode characters and consecutive spaces are preserved. Since the built-in icons are hidden by default, emoji make handy inline icons:

Code:
mermaid
treeView-beta
    ๐Ÿš€ rocket-app/
        ๐Ÿ“ฆ packages/
            ๐ŸŽจ ui/
            ๐Ÿ› ๏ธ utils/
        ๐Ÿงช tests/
        ๐Ÿ“ README.md
        โš™๏ธ config.yaml
Ctrl + Enter|

With custom config:

Code:
mermaid
---
config:
    treeView:
        rowIndent: 80
        lineThickness: 3
    themeVariables:
        treeView:
            labelFontSize: '20px'
            labelColor: '#FF0000'
            lineColor: '#00FF00'
---
treeView-beta
    "packages"
        "mermaid"
            "src"
        "parser"
Ctrl + Enter|

Config Variables โ€‹

PropertyDescriptionDefault Value
rowIndentIndentation for each row10
paddingXHorizontal padding of row5
paddingYVertical padding of row5
lineThicknessThickness of the line1
showIconsWhether to show the default file/folder icons (explicit icon() always renders)false
defaultIconPackRegistered iconify pack used to resolve unprefixed icon references''
filenameIconsFilename โ†’ icon map for file-type icons{}
extensionIconsExtension โ†’ icon map for file-type icons{}

Theme Variables โ€‹

PropertyDescriptionDefault Value
labelFontSizeFont size of the label'16px'
labelColorColor of the label'black'
lineColorColor of the line'black'
iconColorColor of icons (applies to icons that use currentColor)'#546e7a'
descriptionColorColor of ## description text'#6a9955'
highlightBgHighlight background fillrgba(255,193,7,0.15)
highlightStrokeHighlight border stroke#ffc107
Opens in mermaid.ai