Skip to content

TreeView Diagram (v11.14.0+)

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
Ctrl + Enter|

All annotations work the same way — just append them after the label:

Code:
mermaid
Ctrl + Enter|

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

Code:
mermaid
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
Ctrl + Enter|

Inline descriptions with ##

Add a visible description after ## — rendered next to the label in italic:

Code:
mermaid
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
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
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
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
Ctrl + Enter|

Combined annotations

Annotations can be combined in any order:

Code:
mermaid
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
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
Ctrl + Enter|

With custom config:

Code:
mermaid
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