Mermaid Diagram Editor - Create Flowcharts & Diagrams Online
Create flowcharts, sequence diagrams, ER diagrams, and 20+ diagram types with Mermaid.js live preview. Export as SVG/PNG — 100% client-side, no data sent to server.
Frequently Asked Questions
What is a Mermaid Diagram Editor?
A Mermaid Diagram Editor is an online tool that lets you create diagrams using Mermaid.js, a text-based diagramming language. Instead of dragging and dropping shapes, you write simple, Markdown-like syntax (e.g., graph TD; A-->B) and the editor renders it as a visual diagram in real time. Mermaid supports over 20 diagram types including flowcharts, sequence diagrams, class diagrams, ER diagrams, Gantt charts, mindmaps, and more.
How do I use this Mermaid Diagram Editor?
Select a diagram template from the Templates dropdown (e.g., Flowchart or Sequence Diagram) or start writing Mermaid code from scratch. As you type, the preview panel updates in real time. If there is a syntax error, a red 'Invalid' badge appears. Choose a Mermaid theme (Default, Dark, Forest, Neutral) to change the visual style. When satisfied, click Download SVG or Download PNG to export your diagram.
Is my diagram data safe? Does anything get sent to a server?
All diagram rendering is performed 100% client-side in your browser using the mermaid.js JavaScript library. No diagram code, no rendered images, and no user data are ever transmitted to any server. Your diagrams exist only in your browser's memory and localStorage. This makes the tool safe for proprietary architecture diagrams, internal database schemas, and confidential documentation.
What diagram types does Mermaid support?
Mermaid.js supports over 20 diagram types: Flowchart (process flows), Sequence Diagram (actor interactions), Class Diagram (OOP structure), State Diagram (state machines), ER Diagram (database schemas), Gantt Chart (project timelines), Pie Chart (proportional data), Mindmap (idea hierarchies), Git Graph (branching visualization), Timeline (chronological events), and many more including C4, Sankey, XY Chart, Kanban, and Architecture diagrams.
How do I export my diagram as an image?
Click Download SVG for a scalable vector graphic that stays crisp at any size — ideal for documentation. Click Download PNG for a raster image, with options to choose the scale (1x, 2x for retina, 3x for print) and transparent or white background. You can also click Copy SVG to copy the SVG markup to your clipboard for pasting into design tools like Figma.
What are Mermaid themes?
Mermaid.js includes four built-in themes: Default (blue/purple tones), Dark (dark backgrounds for presentations), Forest (green tones, organic feel), and Neutral (grayscale, professional). The theme affects node colors, line styles, and backgrounds within the diagram. The app's UI theme (dark/light mode) is independent of the Mermaid diagram theme.
Does the editor auto-save my work?
Yes. Your diagram code is automatically saved to your browser's localStorage as you type. When you revisit the page, your last diagram will be restored automatically. Note that localStorage is browser-specific — switching browsers or clearing browser data will remove the saved diagram. For long-term storage, export your diagram or copy the shareable URL.
Code Examples
// Mermaid Diagram Rendering and Export in JavaScript (Browser)
/**
* Initialize mermaid.js with configuration
*/
async function initMermaid(theme = 'default') {
const mermaid = await import('https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs');
mermaid.default.initialize({
startOnLoad: false,
theme: theme, // 'default', 'dark', 'forest', 'neutral'
securityLevel: 'strict',
});
return mermaid.default;
}
/**
* Render Mermaid code to SVG string
*/
async function renderMermaid(mermaidInstance, code, elementId = 'mermaid-output') {
try {
const { svg } = await mermaidInstance.render(elementId, code);
return { svg, error: null };
} catch (error) {
return { svg: null, error: error.message };
}
}
/**
* Export SVG string as downloadable .svg file
*/
function downloadSvg(svgContent, filename = 'diagram.svg') {
const blob = new Blob([svgContent], { type: 'image/svg+xml;charset=utf-8' });
const url = URL.createObjectURL(blob);
const anchor = document.createElement('a');
anchor.href = url;
anchor.download = filename;
anchor.click();
URL.revokeObjectURL(url);
}
/**
* Convert SVG to PNG and download
*/
async function downloadPng(svgContent, scale = 2, filename = 'diagram.png') {
return new Promise((resolve, reject) => {
const svgBlob = new Blob([svgContent], { type: 'image/svg+xml;charset=utf-8' });
const url = URL.createObjectURL(svgBlob);
const img = new Image();
img.onload = () => {
const canvas = document.createElement('canvas');
canvas.width = img.naturalWidth * scale;
canvas.height = img.naturalHeight * scale;
const ctx = canvas.getContext('2d');
ctx.fillStyle = '#ffffff';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.scale(scale, scale);
ctx.drawImage(img, 0, 0);
canvas.toBlob((blob) => {
const pngUrl = URL.createObjectURL(blob);
const anchor = document.createElement('a');
anchor.href = pngUrl;
anchor.download = filename;
anchor.click();
URL.revokeObjectURL(pngUrl);
URL.revokeObjectURL(url);
resolve();
}, 'image/png');
};
img.onerror = reject;
img.src = url;
});
}
/**
* Encode diagram state for URL sharing
*/
function encodeDiagramState(code, theme) {
const state = JSON.stringify({ code, theme });
return btoa(unescape(encodeURIComponent(state)));
}
function decodeDiagramState(encoded) {
try {
const json = decodeURIComponent(escape(atob(encoded)));
return JSON.parse(json);
} catch {
return null;
}
}
// Example usage
(async () => {
const mermaid = await initMermaid('default');
const code = `
graph TD
A[Start] --> B{Is it working?}
B -->|Yes| C[Great!]
B -->|No| D[Debug]
D --> B
`;
const { svg, error } = await renderMermaid(mermaid, code);
if (error) {
console.error('Render error:', error);
return;
}
console.log('SVG rendered successfully');
// Download as SVG
downloadSvg(svg, 'flowchart.svg');
// Download as PNG at 2x resolution
await downloadPng(svg, 2, 'flowchart.png');
// Create shareable URL
const encoded = encodeDiagramState(code, 'default');
console.log(`Share URL: https://ohmyutils.com/en/mermaid-diagram-editor?state=${encoded}`);
})();