If you've ever tried to explain a process in plain text and wished you could just draw a diagram right there in your document, flowchart code in markdown is the answer. Instead of switching to a separate drawing tool, you write simple text-based syntax that renders into a visual flowchart. This matters because it keeps your diagrams version-controlled, easy to edit, and right next to the content they support.

What does writing flowchart code in markdown actually mean?

Writing flowchart code in markdown means using a text-based diagramming language inside a markdown file to generate flowcharts. The most common method uses Mermaid.js, a JavaScript library that reads structured text and converts it into SVG diagrams. You write the flowchart logic using keywords like flowchart, graph, node shapes, and arrows, all inside a special code block in your markdown file.

Here's the basic structure:

A markdown file uses a fenced code block with the language identifier mermaid. Inside that block, you define a flowchart direction and then list your nodes and connections. No drawing skills needed just text.

Why would anyone write flowcharts in markdown instead of using a drawing tool?

There are several practical reasons people prefer this approach:

  • Version control Your diagram lives as text in a file, so Git can track every change.
  • No extra software You don't need Visio, Lucidchart, or any paid tool.
  • Easy updates Changing one line of text is faster than redragging boxes in a GUI.
  • Consistency Diagrams stay embedded in your documentation, so they're always accessible alongside the content they explain.

Developers, technical writers, and students all use this method when documenting workflows, algorithms, decision trees, or onboarding processes. If you're new to this, our beginner's guide to flowchart code syntax covers the foundational concepts you'll need before diving in.

How do you set up a flowchart in a markdown file?

The first step is declaring the chart type and direction. Mermaid uses a keyword like flowchart or graph, followed by a direction keyword:

  • TD or TB Top to bottom
  • LR Left to right
  • RL Right to left
  • BT Bottom to top

After that line, you define each node with an ID and a label, then connect them with arrows. The arrow style tells Mermaid what kind of link to draw.

Step-by-step example

Imagine you want to document a simple login process. Here's how the code looks inside a markdown file:

You start with the fenced code block using the mermaid identifier. Then write:

flowchart TD
A[Start] --> B{Is user registered?}
B -->|Yes| C[Enter credentials]
B -->|No| D[Sign up]
C --> E[Access granted]
D --> E

This renders as a top-down flowchart with a diamond-shaped decision node and labeled arrows. If you want to see more variations like this, check out our page on Mermaid flowchart syntax examples and usage.

What are the different node shapes you can use?

Mermaid supports several node shapes, each defined by the bracket type around the label text:

  • [Text] Rectangle (standard process step)
  • (Text) Rounded rectangle (start/end)
  • {Text} Diamond (decision point)
  • [[Text]] Subroutine shape
  • [(Text)] Cylinder (database)
  • [/Text/] Parallelogram (input/output)

Choosing the right shape makes your flowchart easier to read. Use diamonds for yes/no decisions and rectangles for actions or processes. This follows standard flowchart conventions that most readers already understand.

How do you connect nodes with arrows and labels?

Arrows define the flow between steps. The syntax uses dashes and angle brackets:

  • A --> B Solid arrow from A to B
  • A --- B Solid line (no arrowhead)
  • A -.-> B Dotted arrow
  • A ==> B Thick arrow
  • A -->|Label| B Arrow with a text label

Labels are especially helpful on decision branches so readers know what each path represents. Use short, clear labels like "Yes," "No," "Approved," or "Rejected."

What are the most common mistakes when writing flowchart code in markdown?

Even though the syntax is straightforward, there are errors that trip people up regularly:

  • Forgetting the direction keyword Without TD or LR after flowchart, the renderer won't know how to lay out the diagram.
  • Mismatched bracket types Using a curly brace to start a node but a square bracket to close it will break the rendering.
  • Using spaces in node IDs Node IDs must be single words or use underscores. Labels inside brackets can have spaces.
  • Missing the mermaid language tag The fenced code block must say ```mermaid, not just ```.
  • Special characters in labels Characters like quotes, parentheses, or brackets inside a label can confuse the parser. Wrap problematic labels in quotes.

Where can you actually use these markdown flowcharts?

Mermaid flowcharts render natively or through plugins in many popular platforms:

  • GitHub Renders Mermaid blocks automatically in markdown files, issues, and pull requests.
  • GitLab Also supports Mermaid rendering in wikis and markdown files.
  • VS Code With the Mermaid extension, you get live previews while editing.
  • Notion, Obsidian, and Typora These markdown editors support Mermaid either natively or through plugins.
  • Static site generators Tools like MkDocs, Docusaurus, and Hugo can render Mermaid with the right configuration.

Check your platform's documentation to confirm Mermaid support, or use the Mermaid Live Editor to test and preview your code before pasting it into your document.

How do you handle more complex flowcharts with subgraphs?

When your process has multiple logical sections, you can group nodes into subgraphs. This keeps large diagrams organized and readable.

The syntax uses the subgraph keyword followed by a name, then the nodes and connections that belong inside that group, closed with the end keyword.

For example, you might create one subgraph labeled "Authentication" and another labeled "Authorization," each containing their own internal flow. Arrows can connect nodes across subgraphs just like normal.

This feature is especially useful when documenting microservice architectures, multi-step pipelines, or any process with clearly defined phases.

What tips help you write cleaner flowchart code?

  • Keep node IDs short and descriptive Use IDs like A1, B2, or descriptive words like start, check, end.
  • Use consistent indentation While not strictly required, indentation makes the code easier to read and maintain.
  • Limit nodes per chart If your flowchart exceeds 15–20 nodes, consider splitting it into subgraphs or separate charts.
  • Test incrementally Add a few nodes at a time and check the render before building the full diagram.
  • Use comments Mermaid supports comments with %% to explain sections of your flowchart code.

Quick checklist before you publish your flowchart

  1. The code block opens with ```mermaid
  2. A direction keyword follows flowchart (TD, LR, etc.)
  3. Every opening bracket has a matching closing bracket
  4. Node IDs contain no spaces
  5. Decision nodes use curly braces {}
  6. Arrows include labels where paths are ambiguous
  7. You previewed the output in a Mermaid renderer before committing

Start small with a three-to-five node flowchart, get comfortable with the arrow syntax and node shapes, and build from there. Once the basics click, you'll find it much faster to document processes as code rather than dragging boxes around a canvas.