
d2
io.github.d2lang/d2
Look up D2 syntax, check diagrams, and render them locally.
Documentation
A modern diagram scripting language that turns text to diagrams.
Docs | Cheat sheet | Comparisons | Playground
https://user-images.githubusercontent.com/3120367/206125010-bd1fea8e-248a-43e7-8f85-0bbfca0c6e2a.mp4
Source code
vars: {
d2-config: {
layout-engine: elk
theme-id: Terminal
}
}
network: {
cell tower: {
satellites: {
shape: stored_data
style.multiple: true
}
transmitter
satellites -> transmitter: send
satellites -> transmitter: send
satellites -> transmitter: send
}
online portal: {
ui: {shape: hexagon}
}
data processor: {
storage: {
shape: cylinder
style.multiple: true
}
}
cell tower.transmitter -> data processor.storage: phone logs
}
user: {
shape: person
width: 130
}
user -> network.cell tower: make call
user -> network.online portal.ui: access {
style.stroke-dash: 3
}
api server -> network.online portal.ui: display
api server -> logs: persist
logs: {shape: page; style.multiple: true}
network.data processor -> api server
Open in Playground · Browse more examples
Trusted by
Organizations around the world use D2 to power blog posts and docs both internally and externally. D2 is also integrated into many popular tools and services.
Quickstart
On macOS or Linux, run the install script.
curl -fsSL https://d2lang.com/install.sh | sh -s --
On x64 Windows, download the MSI installer from the latest release. The installation guide covers other platforms, package managers, and uninstalling.
Save x -> y -> z in a file named hello.d2, then run the following command to create hello.svg.
d2 hello.d2
With uv, run the native CLI directly with uvx d2lang hello.d2.
For a live preview in your browser, run d2 --watch hello.d2 and edit the file.
D2 as a library
You can render diagrams from Go with d2lib or from JavaScript and TypeScript with
@d2lang/d2.
Go examples · D2.js usage guide
Themes
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.
Fonts
D2 ships with "Source Sans Pro" as the font in renders. If you wish to use a different one, please see ./d2renderers/d2fonts.
Export file types
D2 renders SVG, PNG, GIF, PDF, PowerPoint (.pptx), and text diagrams (.txt) without a browser.
For example, d2 hello.d2 hello.txt draws the diagram with Unicode characters.
Use --ascii-mode=standard for plain ASCII. Export guide
For animated SVG and GIF, set animate-interval and animate-duration in
vars.d2-config. With TALA, newly appended SQL rows can drop into place
while existing rows and connections stay anchored. Appending a sequence message can
extend the activation bar and draw the arrow from sender to recipient.
Animated TALA example · D2 source
Layout engines
D2 bundles three layout engines. Select one with --layout=dagre, --layout=elk, or
--layout=tala. You can also set D2_LAYOUT or vars.d2-config.layout-engine in D2 source.
Run d2 layout to list the engines or d2 layout <name> for their configuration options.
- Dagro (default, bundled): A native Go port of the Dagre directed graph layout engine that produces layered/hierarchical layouts. Based on Graphviz's DOT algorithm.
- elk-go (bundled): A native Go port of the ELK directed graph layout engine, particularly suited for node-link diagrams with an inherent direction and ports.
- TALA (bundled): Native layout and edge-routing engine designed specifically for software architecture diagrams.
D2 also handles specialized layouts such as sequence diagrams and grids. Go applications can use the layout packages directly or provide layout and routing functions through d2lib.
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.
Comparison
For a comparison against other popular text-to-diagram tools, see https://text-to-diagram.com.
Contributing
Contributions are welcome! See ./docs/CONTRIBUTING.md. Parser and editor authors can use the structural grammar, lexical grammar, and conformance cases.
D2 is an independent open-source project fiscally sponsored by Hack Club. Sponsor D2
License
Open sourced under the Mozilla Public License 2.0. See ./LICENSE.txt.
Related
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!
Official plugins
- VS Code — Install d2lang, the official D2 extension. Source code
- Vim extension: https://github.com/d2lang/d2-vim
- Obsidian plugin: https://github.com/d2lang/d2-obsidian
Community integrations
Libraries and publishing
- Astro D2 — Render D2 code blocks in Astro or remark.
- MkDocs D2 — Embed D2 diagrams in MkDocs pages.
- d2-python — Build D2 source from typed Python. Includes a migration guide for py-d2.
- VitePress D2 — Render D2 code blocks in VitePress.
- mdBook D2 — Render D2 code blocks in mdBook.
Editors and notes
- Zed — Add D2 language support in Zed.
- JetBrains IDEs — Edit, format, and preview D2 diagrams.
- Emacs Org Babel — Evaluate D2 source blocks in Org documents.
- Logseq D2 — Render D2 diagrams offline in Logseq using WebAssembly.
Tools with D2 support
- dependency-cruiser — Export JavaScript and TypeScript dependency graphs to D2.
- LikeC4 — Export architecture views to D2.
- Markdown Preview Enhanced — Preview D2 code blocks in Markdown using the local D2 CLI.
- Kroki — Render D2 through an HTTP API. It also powers D2 previews in GitLab instances with Kroki enabled.
- KubeDiagrams — Generate D2 diagrams from Kubernetes manifests and Helm charts.
- Mark for Confluence — Publish Markdown with rendered D2 diagrams to Confluence.
- Asciidoctor Diagram — Render D2 blocks in AsciiDoc using the D2 CLI.
Misc
- Comparison site: https://github.com/d2lang/text-to-diagram-site
- Playground: https://github.com/d2lang/d2-playground
- Language docs: https://github.com/d2lang/d2-docs
- Hosted icons: https://icons.d2lang.com
FAQ
- Does D2 collect telemetry?
- No, D2 does not use an internet connection after installation, except to check for version updates from Github periodically.
- Does D2 need a browser to run?
- No, D2 can run entirely server-side.
- What's coming in the next release?
- I have a question or need help.
- The best way to get help is to ask on D2 Discord
- I have a feature request, proposal, or bug report.
- Please open up a Github Issue.
- I have a private inquiry.
- Please reach out at alex@d2lang.com.
d2langpip install d2lang