
D2
Open-source declarative diagram language that turns text into clean, themeable diagrams.
- Verified facts
- 5 of 5
- Alternatives ranked
- 5
- Approved reviews
- 0
- Visits sent from here
- 0
About D2
D2 (short for Declarative Diagramming) is a text-to-diagram language created by Terrastruct and now run as an independent open-source project. You describe shapes and connections in a compact syntax and the D2 command-line tool renders SVG, PNG or PDF, with a watch mode that live-reloads as you edit. Compared with Mermaid it offers more control: multiple layout engines, themes, custom fonts, icons, nested containers, SQL table and class shapes, sequence diagrams, imports for splitting diagrams across files, and even sketch-style rendering. It works completely offline on macOS, Linux and Windows, and there is an online playground plus plugins for popular editors and documentation tools. D2 is licensed under MPL-2.0. It is not yet rendered natively by GitHub the way Mermaid is, so you usually commit the generated images or use a plugin, and its ecosystem is younger.
Best for: Developers who want diagrams as code with more layout and styling control than Mermaid.
Pros and cons
What works
- Clean default output with themes and custom fonts
- Multiple layout engines to choose from
- Offline CLI with live-reload watch mode
- Modular diagrams through imports
Why people leave
- Not rendered natively on GitHub
- Smaller ecosystem than Mermaid or PlantUML
- Still needs a CLI or plugin to render
Top D2 alternatives
See all 5- 1
Mermaid66.5Renders natively on GitHub and GitLab, with a larger ecosystem of integrations.
- 2
PlantUML62.6Broader UML coverage for formal software documentation.
- 3GrGraphviz59.6
The long-standing layout engine for very large or generated graphs.
- 4
Eraser57.2A hosted diagrams-as-code editor with AI and team features.
- 5
Structurizr55.3Model-based approach for keeping many architecture diagrams consistent.
Why people left D2
In reviewers' own words, from reviews of the apps they moved to. These are their opinions, not ours.
No switching stories yet. If you moved away from D2, review the app you switched to and tell us why.
Reviews
No approved reviews yet. How we verify reviewers
Write a review of D2
D2: common questions
Is D2 free?
Yes. D2 is free, open-source software.
Is D2 open source?
Yes. The source code is on GitHub at terrastruct/d2.
What platforms does D2 run on?
D2 is available for Windows, macOS, Linux and Web.
What are the best alternatives to D2?
The highest-ranked D2 alternatives right now are Mermaid, PlantUML and Graphviz. See the full ranked list for pricing, platforms and verified facts.