A 2.8 kB drop-in widget that renders Mermaid markdown on any page — with scoped custom CSS, Shadow DOM isolation, and zero framework lock-in.
Built for blog posts, dashboards, docs, and any HTML page where you don't want to wire up a full framework just to show a flowchart.
~2.8 kB of widget code. Mermaid itself loads from CDN on demand, so it never bloats your initial page load.
Custom CSS targets only the diagram — your page styles can't leak in, and the diagram can't leak out. No !important wars.
One script tag, mark any element with .mermaid-embed, write Mermaid. Works with React, Vue, Astro, plain HTML — any stack.
Use as a CDN script tag for static pages, or as an npm package in your bundler.
<script src="https://unpkg.com/mermaid-embed/dist/mermaid-embed.iife.js"></script>
<div class="mermaid-embed" data-css=".node rect { fill: #eef; }">
<script type="text/mermaid">
graph TD
A --> B
</script>
</div>
# install
npm install mermaid-embed
# import — side-effects auto-init any .mermaid-embed elements
import { render, autoInit } from 'mermaid-embed';
await render('#diagram', 'graph TD; A --> B', '.node rect { fill: #fce7f3; }');
Each card embeds the same Mermaid markdown — only the data-css changes. Shadow DOM keeps every diagram's styles isolated.
Edit the Mermaid source on the left — the diagram on the right re-renders through the same widget you'd embed on your site.