HOSTING

Share a D2 diagram as a link

Render a D2 diagram to SVG, paste it into one HTML file, and upload it. The recipient gets a page that opens on any device, stays sharp at any zoom and can take comments, with no D2 installed.

3 min read·

D2 is a text language for diagrams: a line such as api -> database: queries becomes two shapes and a labelled arrow. Developers keep .d2 files next to code, and assistants write them because they are plain text. The recipient usually has no d2 binary, and a PNG export blurs when they zoom into a large architecture diagram.

An HTML page with the diagram as SVG opens on any device, stays sharp at any zoom, and keeps labels as selectable text.

Render the diagram as SVG

Use whichever route you already have:

  • ✓Command line: d2 diagram.d2 diagram.svg writes the SVG. Install d2 with brew install d2 or the install script on d2lang.com.
  • ✓Add --sketch for the hand-drawn style: d2 --sketch diagram.d2 diagram.svg.
  • ✓The D2 Playground at play.d2lang.com: paste the source and export the diagram as SVG.

Put the SVG in one HTML file

Create diagram.html with:

  • ✓<!doctype html>, <meta charset="utf-8"> and <meta name="viewport" content="width=device-width, initial-scale=1"> in the head.
  • ✓A style rule so wide diagrams fit narrow screens: svg { max-width: 100%; height: auto; }.
  • ✓The SVG itself: open the .svg in a text editor, copy everything from <svg to the last </svg>, and paste it into the body. Leave out the <?xml ...?> line above it if there is one.

Why paste instead of linking the SVG

Paste the SVG into the page rather than pointing to it with <img src="diagram.svg">. An uploaded page is hosted on its own, so a second file it points to is not there.

Upload it and send the link

Drag the .html file onto the FileShare Pro dashboard and copy the link. Viewers need no account and nothing installed.

Turn on comments and viewers can leave a note on the page after typing a name. When the diagram changes, render again, replace the SVG in the page, and upload the new file over the old one; the link stays the same: updating a shared link without changing it.

Other diagram tools: Mermaid, PlantUML, Graphviz, draw.io, Excalidraw.

Frequently asked

How do I share a D2 diagram with someone who does not have D2?

Render it as SVG, paste the SVG into an HTML page, and upload the page to a host that serves HTML as a web page. The recipient opens the link in any browser.

How do I export D2 as SVG?

Run d2 diagram.d2 diagram.svg, or paste the source into the D2 Playground and export SVG.

Why use SVG instead of PNG?

SVG stays sharp at any zoom and keeps text selectable. Large architecture diagrams exported as PNG blur when someone zooms in to read a label.

Is it free?

Yes. The free plan hosts up to 50 files of up to 100 MB each, with view counts and comments included. Password-protected links are on Pro.

Got a page to share?

Drop the file, copy the link — live in seconds, free plan included.

Start sharing free