Mermaid Diagrams: Compare Approaches, Fix Render Mistakes
Why do your mermaid diagrams break the moment you switch markdown browser apps?
You've just spent forty minutes crafting a beautiful sequence diagram in mermaid syntax. It renders perfectly in your current markdown browser app. Then you paste the same markdown file into a different browser-based editor—and all you see is a wall of code where your diagram should be. Sound familiar?
I've been testing markdown browser apps for API documentation workflows for the past three years, and this is the single most common complaint I hear from technical writers. The problem isn't mermaid itself. The problem is that not every markdown browser app handles mermaid diagrams the same way—and most guides gloss over the differences. So let's weigh two approaches side by side: using a markdown browser app with native mermaid support versus one that requires manual configuration. Along the way, I'll expose the mistakes that break your diagrams and show you exactly how to fix each one.
What is mermaid diagram support in a markdown browser app?
Mermaid is a JavaScript-based diagramming tool that lets you write flowcharts, sequence diagrams, Gantt charts, and more using plain text syntax. In a markdown browser app, mermaid support means the editor can take a fenced code block tagged with the word mermaid and render it as a visual diagram in real time.
Here's the thing, though: markdown itself doesn't natively understand mermaid. The markdown specification only defines fenced code blocks as code blocks. It's up to the markdown browser app to intercept those blocks and hand them off to mermaid.js for rendering. This is where the two approaches diverge.
Approach A: Native mermaid rendering
Some markdown browser apps—like HackMD, CodiMD, and StackEdit—ship with mermaid.js bundled. You write the syntax, and the diagram appears instantly in the preview pane. Zero configuration required.
Approach B: Manual mermaid integration
Approach B: Manual mermaid integration
Other browser-based markdown editors treat mermaid as an optional plugin or extension. You have to enable it through a settings menu, install a browser extension, or inject a custom script into the editor's configuration file. Some apps require you to paste a snippet of JavaScript into your document's front matter or header block before mermaid syntax will render at all. This approach gives you more control over which version of mermaid.js loads and how it behaves, but it also introduces more failure points—especially if you're collaborating with teammates who haven't configured their environment the same way you have.
Side-by-side comparison: Which approach wins?
Let's break down how these two approaches actually perform across the criteria that matter most to technical writers and documentation teams.
Setup time and friction
Native rendering wins hands down. You open the editor, start typing mermaid syntax inside a fenced code block, and the diagram appears. There's no documentation to read, no settings panel to hunt through, and no JavaScript to debug. Manual integration, by contrast, can take anywhere from five minutes to an hour depending on the editor's documentation quality and your comfort level with front-end configuration. If you're onboarding a new hire who just needs to update a few sequence diagrams in an existing doc set, that friction adds up fast.
Portability across apps
This is where things get interesting. A markdown file with mermaid diagrams created in a native-rendering app will look broken the moment you open it in an app that doesn't bundle mermaid.js. The fenced code block is still there in plain text—your content isn't lost—but the visual diagram won't render. Manual integration apps often produce markdown files that are more portable because the configuration lives in the document itself or in a shared config file. However, this only helps if the destination app reads and respects that configuration, which many don't.
Version control and consistency
Native-rendering apps typically bundle a specific version of mermaid.js and update it on their own schedule. This means your diagrams might render slightly differently after an app update if mermaid's syntax rules changed between versions. Manual integration lets you pin a specific mermaid version, which is critical for documentation teams that need reproducible builds. If your CI pipeline generates documentation from markdown sources, pinning the version ensures that a diagram that rendered correctly in your last deploy won't suddenly break because mermaid.js shipped a breaking change.
Collaboration and onboarding
When multiple writers are editing the same markdown files, native rendering removes a whole category of "works on my machine" problems. Everyone sees the same diagrams because everyone is using the same bundled mermaid version. Manual integration creates a hidden dependency: if one writer hasn't installed the plugin or configured the script, they'll see raw code instead of diagrams and might accidentally "fix" what they think is broken formatting by removing the mermaid fence or altering the syntax.
Common mermaid render mistakes (and how to fix them)
Regardless of which approach your markdown browser app uses, you'll eventually hit rendering errors. Mermaid is forgiving in some ways and surprisingly strict in others. Here are the mistakes I see most often, along with concrete fixes for each.
Mistake 1: Wrong fence language tag
The most common reason a mermaid diagram won't render is a typo in the fence's language tag. The opening fence must read exactly mermaid—not "Mermaid", not "mermaid.js", not "diagram". Markdown browser apps that support native rendering look for that specific tag to decide whether to hand the code block to mermaid.js or display it as plain text.
Fix: Double-check that your opening fence uses lowercase letters and no extra characters. The correct format is three backticks followed immediately by the word mermaid, with no space between them.
Mistake 2: Special characters breaking syntax
Mermaid syntax uses certain characters as structural markers. Parentheses define node shapes in flowcharts, square brackets define labels, and pipes separate text in sequence diagrams. If your node text contains any of these characters, mermaid's parser may choke and refuse to render the entire diagram.
Fix: Wrap text containing special characters in double quotes. For example, instead of writing A[Function (input)], write A["Function (input)"]. The quotes tell mermaid to treat everything inside as a literal string rather than parsing it as syntax.
Mistake 3: Indentation and whitespace issues
Mermaid is sensitive to leading whitespace in certain diagram types. In sequence diagrams, for instance, the participant declarations and message arrows must start at the beginning of the line. If your markdown editor auto-indents code inside fenced blocks, or if you've pasted content from another source that introduced leading spaces, the diagram may fail to render or render incorrectly.
Fix: Strip leading whitespace from every line inside the mermaid block. Most markdown browser apps have a command or keyboard shortcut for reformatting code blocks. Alternatively, paste your mermaid syntax into a plain text editor first, remove any stray indentation, then paste it back into your markdown file.
Mistake 4: Mixing diagram types in one block
Each mermaid code block should define exactly one diagram. I've seen writers try to combine a flowchart and a sequence diagram in the same fenced block, separated by blank lines or comments. Mermaid doesn't support this. The parser reads the first line to determine the diagram type, then tries to interpret everything else through that lens, which produces broken or empty output.
Fix: Split multi-diagram content into separate fenced code blocks. Each block should start with its own diagram type declaration—graph TD for a flowchart, sequenceDiagram for a sequence diagram, and so on.
Mistake 5: Outdated syntax from older mermaid versions
Mermaid's syntax has evolved significantly across versions. Some older tutorials and documentation examples use syntax that has been deprecated or changed. For example, the way arrows and links are styled has shifted between major versions, and some diagram types have been renamed. If you copied syntax from an old Stack Overflow answer, it might not work in the version of mermaid.js your editor bundles.
Fix: Check which version of mermaid.js your markdown browser app is using, then cross-reference the official mermaid documentation for that version. If you're using manual integration, consider upgrading to the latest stable release—but test your existing diagrams first, as newer versions may introduce breaking changes.
Mistake 6: HTML and markdown inside diagram labels
Some markdown browser apps pass mermaid labels through an HTML sanitizer before rendering. If you've included markdown formatting (like bold asterisks) or HTML tags inside node labels, the sanitizer may strip them or display them as literal text. This is especially common in apps that prioritize security by filtering all user input.
Fix: Use mermaid's built-in formatting syntax instead of markdown or HTML. Mermaid supports a limited set of formatting options within labels, such as <br/> for line breaks. Check the mermaid documentation for your version to see which formatting options are supported inside labels.
Choosing the right approach for your workflow
The best approach depends on how you work and who you work with. Here's a quick framework for deciding.
Choose native rendering if: you're a solo writer or small team that primarily works within a single markdown browser app; you value speed and simplicity over fine-grained control; your documentation doesn't go through a CI pipeline that requires pinned dependency versions; and you're okay with the app's update cycle determining which mermaid features are available.
Choose manual integration if: you're part of a larger documentation team with a CI/CD pipeline; you need reproducible builds where the same markdown always produces the same output; you work across multiple markdown browser apps and need your diagrams to render consistently in each one; or you need to use a specific mermaid version because your diagrams rely on syntax that changed in newer releases.
Quick checklist for mermaid diagrams in any markdown browser app
- Verify the fence tag is lowercase mermaid with no extra characters
- Confirm your markdown browser app actually supports mermaid rendering, either natively or through configuration
- Check that each code block contains only one diagram type
- Strip stray indentation from every line inside the block
- Wrap node text containing special characters in double quotes
- Use mermaid's built-in formatting syntax instead of markdown or HTML inside labels
- Test diagrams in the destination app before sharing, not just in your editing app
- If using manual integration, document the setup steps for collaborators
The Bottom Line
Mermaid diagrams don't have to be a source of frustration. The rendering problems you encounter almost always fall into one of two categories: a mismatch between how your markdown browser app handles mermaid, or a syntax mistake that mermaid's parser can't forgive. Once you understand which approach your editor uses—native rendering or manual integration—you can anticipate where things might break and take steps to prevent them.
If you frequently switch between markdown browser apps, lean toward editors with native mermaid support. The slight loss of version control is worth the gain in portability and reduced setup friction. If you're building documentation that needs to render identically every time, invest in manual integration with a pinned mermaid version and document the setup for your team.
Either way, the mistakes outlined above will catch up to you eventually. Bookmark this page, run through the checklist when a diagram won't render, and you'll spend less time debugging syntax and more time actually writing documentation. Your sequence diagrams, flowcharts, and Gantt charts should work for you—not against you.