Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
D

d2

> 编程语言
Open source

D2 is a modern diagram scripting language that turns text to diagrams.

24.8K stars0 likes2 views
WebsiteGitHub

About

D2 is a modern diagram scripting language that turns text to diagrams.

Table of Contents

  • What does D2 look like?
  • Quickstart
  • Install
  • D2 as a library
  • Themes
  • Fonts
  • Export file types
  • Language tooling
  • Plugins
  • Comparison
  • Contributing
  • License
  • Related
    • Official plugins
    • Community plugins
    • Misc
  • FAQ
  • Notable open-source projects documenting with D2

What does D2 look like?

…

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.

bash
# 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:

bash
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:

bash
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:

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

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

  • VSCode extension: https://github.com/d2lang/d2-vscode
  • Vim extension: https://github.com/d2lang/d2-vim
  • Obsidian plugin: https://github.com/d2lang/d2-obsidian

Community plugins

  • Tree-sitter grammar: https://github.com/ravsii/tree-sitter-d2
  • Emacs major mode: https://github.com/andorsk/d2-mode
  • Goldmark extension: https://github.com/FurqanSoftware/goldmark-d2
  • Telegram bot: https://github.com/meinside/telegram-d2-bot
  • Postgres importer: https://github.com/zekenie/d2-erd-from-postgres
  • Structurizr to D2 exporter: https://github.com/goto1134/structurizr-d2-exporter
  • MdBook preprocessor: https://github.com/danieleades/mdbook-d2
  • ROS2 D2 Exporter: https://github.com/Greenroom-Robotics/ros-d2
  • D2 org-mode support: https://github.com/xcapaldi/ob-d2
  • Python D2 diagram builder: https://github.com/MrBlenny/py-d2
  • Clojure D2 transpiler: https://github.com/judepayne/dictim
  • JavaScript D2 diagram builder: https://github.com/Kreshnik/d2lang-js
  • C# & dotnet SDK: https://github.com/Stephanvs/d2lang-cs
  • Maven plugin: https://github.com/andrinmeier/unofficial-d2lang-maven-plugin
  • Confluence plugin: https://github.com/andrinmeier/unofficial-d2lang-confluence-plugin
  • CIL (C#, Visual Basic, F#, C++ CLR) to D2: https://github.com/HugoVG/AppDiagram
  • D2 Snippets (for text editors): https://github.com/Paracelsus-Rose/D2-Language-Code-Snippets
  • Mongo to D2: https://github.com/novuhq/mongo-to-D2
  • Pandoc filter (TypeScript): https://github.com/ram02z/d2-filter
  • Pandoc filter (Python): https://github.com/fliiiix/pandoc-d2-filter
  • Logseq-D2: https://github.com/b-yp/logseq-d2
  • ent2d2: https://github.com/tmc/ent2d2
  • MkDocs Plugin: https://github.com/landmaj/mkdocs-d2-plugin
  • Remark Plugin: https://github.com/mech-a/remark-d2
  • VitePress Plugin: https://github.com/BadgerHobbs/vitepress-plugin-d2
  • Zed extension: https://github.com/gabeidx/zed-d2
  • Hexo blog extension: https://github.com/leverimmy/hexo-d2
  • Rehype Plugin: https://github.com/stereobooster/beoe/tree/main/packages/rehype-d2
  • AsyncAPI to D2: https://github.com/holydocs/messageflow
  • Database Schemas to D2: https://github.com/holydocs/dberd

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?
    • See ./ci/release/changelogs/next.md.
  • 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 [email protected].

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.

  • ElasticSearch
  • Sourcegraph
  • Temporal
  • Tauri
    • Rust GUI framework (78.5k stars)
  • Intellij
  • Coder
  • UC Berkeley
  • Coronacheck
    • Official app of the Netherlands for coronavirus entry passes.
  • [Block Protocol](https://github.com/blockprotocol/blockpro

Issues· 530 open

View all issuesOpen on GitHub
  • #1085

    fix corner of person shape path

    buggood first issuerenderUpdated Sep 30, 2026
  • #2891

    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

    Updated Sep 29, 2026
  • #2937

    PNG export stops when an SVG icon uses a valid SVG feature that the built-in renderer does not accept

    Updated Sep 29, 2026
  • #1435

    Typst support

    good first issueUpdated Sep 21, 2026
  • #2933

    d2.js v0.1.34 not published on npm

    Updated Sep 21, 2026
  • #2931

    Watch viewer does not scale properly

    Updated Sep 18, 2026
  • #2927

    Static methods in class diagrams

    Updated Sep 13, 2026
  • #2846

    Proposal: Add --if-changed flag to speed up compilation of large files and folders in CI

    Updated Sep 12, 2026
  • #2682

    When reserved keywords are uppercase and quoted to be used as nodes, they are lowercased in the output

    Updated Sep 8, 2026
  • #2768

    TALA License

    Updated Sep 5, 2026

> Tags

Godeveloper-toolsdiagrammingdiagramsgo

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 30, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言