D2 is a modern diagram scripting language that turns text to diagrams.
D2 is a modern diagram scripting language that turns text to diagrams.
…Open in playground
For more examples, see ./docs/examples.
The most convenient way to use D2 is to just run it as a CLI executable to
produce SVGs from .d2 files.
# First, install D2
curl -fsSL https://d2lang.com/install.sh | sh -s --
echo 'x -> y -> z' > in.d2
d2 --watch in.d2 out.svgA browser window will open with out.svg and live-reload on changes to in.d2.
The easiest way to install is with our install script:
curl -fsSL https://d2lang.com/install.sh | sh -s --You can run the install script with --dry-run to see the commands that will be used
to install without executing them.
Or if you have Go installed you can install from source though you won't get the manpage:
go install github.com/d2lang/d2@latestYou can also install a release from source which will include manpages. See ./docs/INSTALL.md#source-release.
To uninstall with the install script:
curl -fsSL https://d2lang.com/install.sh | sh -s -- --uninstallFor detailed installation docs, see ./docs/INSTALL.md. We demonstrate alternative methods and examples for each OS.
As well, the functioning of the install script is described in detail to alleviate any concern of its use. We recommend using your OS's package manager directly instead for improved security but the install script is by no means insecure.
In addition to being a runnable CLI tool, D2 can also be used to produce diagrams from Go programs.
For examples, see ./docs/examples/lib.
D2 includes a variety of official themes to style your diagrams beautifully right out of the box. See ./d2themes to browse the available themes and make or contribute your own creation.
D2 ships with "Source Sans Pro" as the font in renders. If you wish to use a different one, please see ./d2renderers/d2fonts.
D2 supports SVG, PNG, GIF, PDF, and PPTX exports.
D2 is designed with language tooling in mind. D2's parser can parse multiple errors from a broken program, has an autoformatter, syntax highlighting, and we have plans for LSP's and more. Good language tooling is necessary for creating and maintaining large diagrams.
The extensions for VSCode and Vim can be found in the Related section.
D2 is designed to be extensible and composable. The plugin system allows you to change out layout engines and customize the rendering pipeline. Plugins can either be bundled with the build or separately installed as a standalone binary.
Layout engines:
--layout=tala,
D2_LAYOUT=tala, or a layout-engine: tala setting under vars.d2-config in D2 source.D2 intends to integrate with a variety of layout engines, e.g. dot, as well as
single-purpose layout types like sequence diagrams. You can choose whichever layout engine
you like and works best for the diagram you're making.
Sketch-mode rendering uses rough-go, a native Go compatibility port of the Rough.js 4.6.6 rendering surface used by D2.
LaTeX labels use mathjax-go, a native Go port of the MathJax 3.2.2 TeX-to-SVG pipeline.
For a comparison against other popular text-to-diagram tools, see https://text-to-diagram.com.
Contributions are welcome! See ./docs/CONTRIBUTING.md.
Open sourced under the Mozilla Public License 2.0. See ./LICENSE.txt.
We are constantly working on new plugins, integrations, extensions. Contributions are welcome in any official or community plugins. If you have somewhere in your workflow that you want to use D2, feel free to open a discussion. We have limited bandwidth and usually choose the most high-demand ones to work on. If you make something cool with D2 yourself, let us know and we'll be happy to include it here!
Do you have or see an open-source project with .d2 files? Please submit a PR adding to
this selected list of featured projects using D2.
fix corner of person shape path
TALA in v0.9.0 fails with "route-search work limit exceeded" on a 120-node / 100-edge diagram that the 0.4.3 plugin laid out fine
PNG export stops when an SVG icon uses a valid SVG feature that the built-in renderer does not accept
Typst support
d2.js v0.1.34 not published on npm
Watch viewer does not scale properly
Static methods in class diagrams
Proposal: Add --if-changed flag to speed up compilation of large files and folders in CI
When reserved keywords are uppercase and quoted to be used as nodes, they are lowercased in the output
TALA License