D2 Diagram Editor
Edit D2 architecture diagrams, preview them live and export SVG.
D2 source
503 / 50,000 characters · 28 lines
Preview
Used: Dagre layout · – theme · –
Loading the D2 engine… the first render can take a few seconds.
Compiles in your browser. Imports, icons, links and scripts are never loaded.
Related Tools
How to use
- 1.Type or paste D2 source, or choose an example; loading an example over your edits asks first.
- 2.Pick a diagram theme and a sketch style, or keep From source to use the settings in vars.d2-config.
- 3.Use Fit, the zoom buttons or 100% to inspect the preview, and scroll it with the mouse or the arrow keys.
- 4.When D2 reports an error, fix the highlighted line; the previous diagram stays visible as a stale preview.
- 5.Copy SVG puts the markup on the clipboard and Download SVG saves an .svg file.
D2 Diagram Editor
D2 is a text language for diagrams: shapes, nested containers, connections between them, SQL tables, sequence diagrams and grids. This editor compiles your source with D2.js, the WebAssembly build of the D2 compiler, about 400 ms after you stop typing, and lays it out with the Dagre engine. Only the newest request is rendered, so a slow layout never replaces a newer one. The SVG keeps D2's embedded fonts and opens offline. Sources are limited to 50,000 characters and a layout stops after 5 seconds.
Layout, theme and sketch
The editor always lays diagrams out with Dagre. If vars.d2-config asks for ELK or another engine, the preview says so and still uses Dagre; your source is never changed. A theme or sketch style chosen here overrides the one in the source, while From source keeps it. The line under the preview shows the layout, theme and sketch style actually used. Layers, scenarios and steps are not rendered: only the main board is shown and exported.
Security
D2 imports, icons and images would read other files or load content from other sites, so the editor never does either. Imports are reported as errors with their line, and icons are left out of the preview and the SVG with a warning. Before preview, copy and download the SVG is cleaned: scripts, event handlers, external links and references, and Markdown or HTML blocks are removed, while the embedded fonts stay. The preview is an image, so nothing in it can run or navigate.
Privacy
Compiling and rendering happen in your browser. Your source and the generated SVG are never uploaded, stored or logged; reloading the page clears them. Only the theme and sketch choices are remembered on this device.
Frequently asked questions
- Is my D2 source uploaded?
- No. The D2 compiler runs as WebAssembly in your browser. The source and the SVG are never uploaded, stored or logged; only the theme and sketch choices are remembered on this device.
- Why are imports not supported?
- The editor works on one source and never reads other files, so @file and ...@file imports are reported with their line. Paste the imported content into the source instead.
- What happens to icons and links?
- Icons and images point to other sites, so the editor never loads them and leaves them out of the preview and the SVG, with a warning that names their lines. Links are kept as plain shapes without the link.
- Which layout engine is used?
- Dagre. If the source asks for another layout engine in vars.d2-config, the editor still uses Dagre, says so, and leaves the source unchanged.
