DEV Community

Rahul T
Rahul T

Posted on

4 2

How to draw flowChart(diagrams) in markdown using Mermaid!!

Table of contents

Prerequisites

  1. VS Code
  2. Install the following extensions in VS Code
    1. Markdown Preview Enhanced
    2. Markdown Preview Meramid Support
    3. Meramid Markdown Syntax Highlighting (optional)

Getting Started

Create a file with markdown extension (abc.md)
Then copy this code and paste it there

graph TD;
    A-->B;
    A-->C;
    B-->D;
    C-->D;   
Enter fullscreen mode Exit fullscreen mode

Open the file in VS Code and right click and select Markdown Preview Enhanced. Then you can see this diagram there

Render Mermaid diagram in Webpage

For this you have to use two script tags, they are :

<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
Enter fullscreen mode Exit fullscreen mode
<script>mermaid.initialize({theme: 'dark', startOnLoad:true});</script>
Enter fullscreen mode Exit fullscreen mode

For light theme you can replace that theme to light

Then you can write the mermaid diagram code inside div with class mermaid

Example:

<html>
  <body>
    <script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
    <script>mermaid.initialize({ theme: 'dark', startOnLoad:true});</script>

    Here is one mermaid diagram:
    <div class="mermaid">
     pie title Some Title
         "FRIENDS" : 5
         "FAMILY" : 2
    </div>
  </body>
</html>
Enter fullscreen mode Exit fullscreen mode

You can see more examples of diagrams here

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay