D2 is a modern diagram scripting language that turns text to diagrams. https://d2lang.com
  • Go 97%
  • Shell 1.2%
  • Python 0.7%
  • JavaScript 0.7%
  • HTML 0.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Alexander Wang 62fded6ae4
Merge pull request #2901 from d2lang/security/local-resource-policy
security: require explicit local file access
2026-09-11 15:43:30 -07:00
.github Build npm release packages without rewriting tagged sources 2026-09-07 15:20:21 -07:00
ci security: restrict remote asset network access 2026-09-11 07:48:15 -07:00
cmd/d2plugin-dagre go: use github.com/d2lang/d2 module path 2026-08-06 21:22:48 -07:00
d2ast go: use github.com/d2lang/d2 module path 2026-08-06 21:22:48 -07:00
d2chaos deprecate legacy and test-only APIs 2026-08-09 18:14:52 -07:00
d2cli security: enforce local policy in watch mode 2026-09-11 15:33:04 -07:00
d2compiler security: require explicit local file access 2026-09-11 15:33:04 -07:00
d2exporter deprecate legacy and test-only APIs 2026-08-09 18:14:52 -07:00
d2format perf: eliminate repeated work in compilation 2026-09-05 09:37:32 -07:00
d2graph perf: eliminate repeated work in compilation 2026-09-05 09:37:32 -07:00
d2ir security: require explicit local file access 2026-09-11 15:33:04 -07:00
d2js Build npm releases from exact D2 tags and stamp WASM versions 2026-09-07 14:55:59 -07:00
d2layouts Merge pull request #2893 from d2lang/codex/grid-integral-measurements 2026-09-10 09:13:43 -07:00
d2lib security: require explicit local file access 2026-09-11 15:33:04 -07:00
d2lsp d2js: use UTF-16 columns for completions 2026-08-09 18:03:15 -07:00
d2oracle cleanup: remove unused font work and renderer scaffolding 2026-09-04 21:18:33 -07:00
d2parser parser: bound nesting and honor cancellation 2026-09-11 07:27:41 -07:00
d2plugin plugins: preserve staged selection semantics 2026-09-11 07:56:15 -07:00
d2renderers Merge pull request #2899 from d2lang/security/asset-network-policy 2026-09-11 15:29:42 -07:00
d2target Avoid repeated JSON decoding and corpus copying during rendering 2026-09-07 10:28:09 -07:00
d2themes perf(svg): reduce SVG payloads with verified rendering parity 2026-09-05 09:43:58 -07:00
docs open source TALA 2026-09-07 13:42:34 -07:00
e2etests tala: preserve enclosed routes when compound containers move 2026-09-08 09:30:59 -07:00
e2etests-cli d2cli: make multiboard publication transactional 2026-09-11 08:26:16 -07:00
internal cleanup: remove unused font work and renderer scaffolding 2026-09-04 21:18:33 -07:00
lib tests: preserve trusted remote bundler fixtures 2026-09-11 15:34:08 -07:00
testdata d2compiler: prevent recursive class glob cycles 2026-08-28 07:05:14 -07:00
.gitattributes e2e: add ten real-world diagram fixtures 2026-09-04 22:44:43 -07:00
.gitignore add claude- prefix to gitignore for notes 2025-06-23 09:15:23 -06:00
.gitmodules update transferred dependency links 2026-08-02 17:07:43 -07:00
.pre-commit-hooks.yaml feat: add d2 pre-commit hook 2025-06-03 12:39:09 -03:00
.prettierignore d2latex: replace MathJax JavaScript with mathjax-go 2026-08-09 03:12:07 -07:00
CODE_OF_CONDUCT.md docs: adopt Contributor Covenant code of conduct 2026-09-07 07:15:46 -07:00
go.mod deps: use Dagro v0.2.1 ranking optimizations 2026-09-07 11:37:56 -07:00
go.sum deps: use Dagro v0.2.1 ranking optimizations 2026-09-07 11:37:56 -07:00
install.sh open source TALA 2026-09-07 13:42:34 -07:00
LICENSE.txt release: ship Dagro license notices 2026-08-08 10:50:58 -07:00
main.go go: use github.com/d2lang/d2 module path 2026-08-06 21:22:48 -07:00
make.sh release: remove obsolete browser continuity tooling 2026-09-03 07:34:04 -07:00
Makefile ci: restore coverage and simplify release orchestration 2026-09-07 06:36:54 -07:00
README.md open source TALA 2026-09-07 13:42:34 -07:00
THIRD_PARTY_NOTICES.txt raster: add pure-Go export rendering 2026-09-01 17:38:55 -07:00

Table of Contents

What does D2 look like?

vars: {
  d2-config: {
    layout-engine: elk
    # Terminal theme code
    theme-id: 300
  }
}
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

D2 render example

Open in playground

For more examples, see ./docs/examples.

Quickstart

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.svg

A browser window will open with out.svg and live-reload on changes to in.d2.

Install

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@latest

You 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 -- --uninstall

For 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.

D2 as a library

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.

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 supports SVG, PNG, GIF, PDF, and PPTX exports.

Language tooling

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.

Plugins

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:

  • 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, opt-in): Native layout and edge-routing engine designed specifically for software architecture diagrams. Select it with --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.

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.

License

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!

Official plugins

Community plugins

Misc

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.

Notable open-source projects documenting with D2

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.