Program Functions, Planning, Design

How To Get Started With Mermaid In Notion

notion and mermaid flowcharts tutorial cover

🔎 Mermaid Tutorial

Mermaid compatibility is now available in Notion code blocks. Here is how to get started using the new update. Mermaid allows Notion users to create flowcharts in the program, and flowcharts can be very useful for planning Notion workspaces, particularly, for identifying database relationships. Here’s how it works.

2022-2023 Calendars

A bundle of calendar images for Notion galleries that span from Sep 2022 to Dec 2023 + more!

Video Guide

Where To Find Mermaid In Notion

Where is mermaid?

  1. Trigger the block menu in the body of any page (“/”)

  2. Find “Code Block”

  3. Change the code language to “Mermaid”

There should be a second dropdown menu next to the language selector with three options:

  1. Code: see just the code

  2. Preview: see just the chart

  3. Split: see the code and the chart

Flowchart Orientation

There are four ways to view a flowchart with Mermaid:

  1. Left to Right: LR

  2. Right to Left : RL

  3. Top to Bottom: TB

  4. Bottom to Top: BT

 

Step 1: Connect Two Nodes

Each shape in the flowchart is called a node. The lines connecting nodes are called links. Connect the first two nodes, and let’s assume this flowchart is planning a basic project manager in Notion.

Each node has an ID and a Label

G(Goals)

This is a nice syntax to use because it allows you to quickly reference a node without spelling out the entire label further down in your code. You only have to label a node once.

flowchart LR
G(Goals) ---> P(Projects) 
 

Step 2: Adding More Nodes

There are two ways to string nodes together:

flowchart LR
G(Goals) ---> P(Projects) ---> PT(Tasks)

or

flowchart LR
G(Goals) ---> P(Projects)
P ---> PT(Tasks)
 

Step 3: Link In Multiple Directions

The goals database connects to the projects, of which connects to the tasks. Tasks also has two outcomes — complete or incomplete. This fork is created by connecting tasks to both complete and incomplete nodes like this:

PT(Tasks) ---- IC(Incompete) & C(Complete)

or like this:

PT(Tasks) ---- IC(Incompete) 
PT(Tasks) ---- C(Complete)
flowchart LR
G(Goals) ---> P(Projects)
P ---> PT(Tasks)
PT ---- IC(Incompete) & C(Complete)
C ---> R(Review)
R ---> G
 

Step 4: Adding Comments

Now let’s add some context to the connections between nodes like this:

G(Goals) ---> |Connect To| P(Projects)
flowchart LR
G(Goals) ---> |Connect To| P(Projects)
P ---> |Has| PT(Tasks)
PT ---- |Is| IC(Incomplete) & C(Complete)
C ---> |Needs| R(Review)
R ---> |Creates New| G
 

Step 5: Customizing Node Shapes

There are a handful of different node shapes you can choose from. Take a look at the link to Mermaid’s documentation below to see more. For Notion users, the database shape may be useful. Here are a few:

  • Database

    • G[(Goals)]
  • Pill Shape

    • IC([Incomplete])
  • Subroutine

    • R[[Review]]
flowchart LR
G[(Goals)] ---> |Connect To| P[(Projects)]
P ---> |Has| PT(Tasks)
PT ---- |Is| IC([Incomplete]) & C([Complete])
C ---> |Needs| R[[Review]]
R ---> |Creates New| G
 

Step 6: Customizing Link Shapes

You can customize link shapes as well. There are a lot of different options including two-way arrows, plain lines, lines that indicate a stoppage in the flow, and more. Here are a few:

  • Bold arrow

    • G ==> P
  • Two-way arrow

    • G <--> P
  • Line with circle

    • G --o P
  • Line with x

    • G --x P
  • Dotted line

    • G -.-> P
flowchart LR
G[(Goals)] <===> |Connect To| P[(Projects)]
P ---o |Has| PT(Tasks)
PT ---x |Is| IC([Incomplete])
PT ---- |Is| C([Complete])
C ---> |Needs| R[[Review]]
R -..-> |Creates New| G
 

Step 7: Code Organization

I recommend organizing your code as the flowchart grows and links begin to multiply. Using %% comments %%, you can create different sections in the flow.

For example, this is how you can separate all connections in the Goals database from the Projects database:

%% GOALS DATABASE %%
Code here

%% PROJECTS DATABASE %%
Code here
flowchart LR

%% GOALS DATABASE %%

%% Goals & Projects %%
G[(Goals)] <===> |Connect To| P[(Projects)]

%% PROJECTS DATABASE %%

%% Deadline %%
P ---o |Has| PD(Deadline)

PD ---x |Is| MT([Met])

PD ---- |Is| OV([Overdue])
OV ---> |Push| OVF{4 Days}

%% Tasks %%
P ---o |Has| PT(Tasks)
PT ---x |Is| IC([Incomplete])
PT ---- |Is| C([Complete])
C ---> |Needs| R[[Review]]

%% Review & Goals %%
R -..-> |Creates New| G
 

Step 8: Customize Node Colors

Here is the best way to add colors to your flowchart’s nodes with mermaid. Firstly, create a section for only colors. Next, add all classDef lines inside to define each color you’ll be using in the graph like this:

%% Colors %% classDef blue fill:#2374f7,stroke:#000,stroke-width:2px,color:#fff

Next, add the defined colors above next to the node you want to fill.

G[(Goals)]:::blue <===> |Connect To| P[(Projects)]:::blue
flowchart LR
%% Colors %%
classDef blue fill:#2374f7,stroke:#000,stroke-width:2px,color:#fff
classDef pink fill:#eb3dd6,stroke:#000,stroke-width:2px,color:#fff
classDef orange fill:#fc822b,stroke:#000,stroke-width:2px,color:#fff
classDef red fill:#ed2633,stroke:#000,stroke-width:2px,color:#fff
classDef green fill:#16b522,stroke:#000,stroke-width:2px,color:#fff
%% GOALS DATABASE %%
%% Goals & Projects %%
G[(Goals)]:::blue <===> |Connect To| P[(Projects)]:::blue
%% PROJECTS DATABASE %%
%% Deadline %%
P ---o |Has| PD(Deadline):::orange
PD ---x |Is| MT([Met]):::green
PD ---- |Is| OV([Overdue]):::red
OV ---> |Push| OVF{4 Days}:::pink
%% Tasks %%
P ---o |Has| PT(Tasks):::orange
PT ---x |Is| IC([Incomplete]):::red
PT ---- |Is| C([Complete]):::green
C ---> |Needs| R[[Review]]
%% Review & Goals %%
R -..-> |Creates New| G
 

Bonus: Add Notion Links TO Nodes

Yes, you can also add links to your nodes. For example, if the Goals node is representing a database called Goals, you can navigate to that page in Notion and copy/paste the page link into this piece of code:

flowchart LR  G[(Goals)] click G "insert link here"
 

Further Reading