D2

A modern diagram scripting language that turns text to diagrams.

[Docs](https://d2lang.com) | [Cheat sheet](./docs/assets/cheat_sheet.pdf) | [Comparisons](https://text-to-diagram.com) | [Playground](https://play.d2lang.com) [![ci](https://github.com/d2lang/d2/actions/workflows/ci.yml/badge.svg)](https://github.com/d2lang/d2/actions/workflows/ci.yml) [![weekly race tests](https://github.com/d2lang/d2/actions/workflows/weekly-race.yml/badge.svg)](https://github.com/d2lang/d2/actions/workflows/weekly-race.yml) [![release](https://img.shields.io/github/v/release/d2lang/d2)](https://github.com/d2lang/d2/releases) [![changelog](https://img.shields.io/badge/changelog-read-blue)](https://d2lang.com/releases/intro/) [![npm version](https://img.shields.io/npm/v/@d2lang/d2)](https://www.npmjs.com/package/@d2lang/d2) [![discord](https://img.shields.io/discord/1039184639652265985?label=discord)](https://discord.gg/NF6X8K4eDq) [![license](https://img.shields.io/github/license/d2lang/d2?color=9cf)](./LICENSE.txt) D2 Playground button

D2 feature showcase: Normal, Sketch, Animated, Terminal, Dark Mode, and ASCII

[Open in Playground](https://play.d2lang.com/?script=bVHBTsMwDL33K_wDmyaOPSDBhACJQ2GTOKKsMZ23NOkSh6mq-u84accQ4hLZzy_287MmjzWTsyV4avZcxIA-lLA2hJYDDGGvOiyhE9TZseiM4k_n28RwUUM15zAUAPpvMwDUjfx-kBceFeNZ9QLWqt4L-oaaAqxT8jOn7g1ZjX4UmupIxjiPcFc9S36KGFOzL1EG9_EqLhfSj7Pzxyz_fQqEwb3BZRsNU2eEyn5i6l0JlQvceNy8vmT1AHO7cDILVjuDGSRdQoykYaidDewVWRY_PLXK94sj9mOmHdzu43-q2IPU2At1nF2Bxe3FiJvVqg2_4Ly4d5FxciFheccUzDteK2mV2rUtcTFO50vo5VDL6QJP2221Kb4B) · [Browse more examples](https://d2lang.com/examples/overview/) ## 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.

NVIDIA Google Amazon GitLab Samsung Stripe Alibaba Group LangChain UK Ministry of Justice

## Quickstart On macOS or Linux, run the install script. ```sh curl -fsSL https://d2lang.com/install.sh | sh -s -- ``` On x64 Windows, download the MSI installer from the [latest release](https://github.com/d2lang/d2/releases/latest). The [installation guide](./docs/INSTALL.md) 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`. ```sh d2 hello.d2 ``` With [uv](https://docs.astral.sh/uv/), run the native CLI directly with `uvx d2lang hello.d2`. Run `d2 validate hello.d2` to check a diagram for errors and warnings. Add `--max-warnings 0` to fail a CI check on warnings, or `--json` to read the diagnostics programmatically. 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`. To check source without rendering, call `d2compiler.Validate(path, reader, opts)` in Go or `await d2.validate(source)` in JavaScript. Both return a report with source ranges and rule codes. [Go examples](./docs/examples/lib) · [D2.js usage guide](./d2js/js/README.md#usage) ## Comparison For a comparison against other popular text-to-diagram tools, see [https://text-to-diagram.com](https://text-to-diagram.com). ## Contributing Contributions are welcome! See [./docs/CONTRIBUTING.md](./docs/CONTRIBUTING.md). Parser and editor authors can use the [structural grammar](./docs/grammar/structure.ebnf), [lexical grammar](./docs/grammar/lexical.ebnf), and [conformance cases](./docs/grammar/testdata/). D2 is an independent open-source project fiscally sponsored by Hack Club. [Sponsor D2](https://d2lang.com/sponsor/) ## License Open sourced under the Mozilla Public License 2.0. See [./LICENSE.txt](./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 - **Agent skill** — Install with `npx skills add d2lang/d2` (for Claude Code, Codex, Cursor, Copilot, Gemini CLI, and other Agent Skills clients). [Skill source](./skills/d2/SKILL.md) - **VS Code** — Install [d2lang, the official D2 extension](https://marketplace.visualstudio.com/items?itemName=d2lang.d2lang). [Source code](https://github.com/d2lang/d2-vscode) - **Vim extension**: [https://github.com/d2lang/d2-vim](https://github.com/d2lang/d2-vim) - **Obsidian plugin**: [https://github.com/d2lang/d2-obsidian](https://github.com/d2lang/d2-obsidian) ### Community integrations **Libraries and publishing** - [Astro D2](https://astro-d2.vercel.app/getting-started/) — Render D2 code blocks in Astro or remark. - [MkDocs D2](https://landmaj.github.io/mkdocs-d2-plugin/guide/usage/) — Embed D2 diagrams in MkDocs pages. - [d2-python](https://github.com/h0rv/d2-python#coming-from-py-d2) — Build D2 source from typed Python. Includes a migration guide for py-d2. - [VitePress D2](https://github.com/BadgerHobbs/vitepress-plugin-d2#readme) — Render D2 code blocks in VitePress. - [mdBook D2](https://github.com/danieleades/mdbook-d2#readme) — Render D2 code blocks in mdBook. **Editors and notes** - [Zed](https://zed.dev/extensions/d2) — Add D2 language support in Zed. - [JetBrains IDEs](https://plugins.jetbrains.com/plugin/29542-d2-diagram) — Edit, format, and preview D2 diagrams. - [Emacs Org Babel](https://github.com/xcapaldi/ob-d2#readme) — Evaluate D2 source blocks in Org documents. - [Logseq D2](https://github.com/b-yp/logseq-d2#readme) — Render D2 diagrams offline in Logseq using WebAssembly. **Tools with D2 support** - [dependency-cruiser](https://github.com/sverweij/dependency-cruiser/blob/main/doc/cli.md#d2) — Export JavaScript and TypeScript dependency graphs to D2. - [LikeC4](https://likec4.dev/tooling/cli/#generate-mermaid-dot-d2-plantuml) — Export architecture views to D2. - [Markdown Preview Enhanced](https://github.com/shd101wyy/markdown-preview-enhanced/blob/master/docs/diagrams.md#d2) — Preview D2 code blocks in Markdown using the local D2 CLI. - [Kroki](https://docs.kroki.io/kroki/setup/configuration/#_d2) — Render D2 through an HTTP API. It also powers D2 previews in [GitLab instances with Kroki enabled](https://docs.gitlab.com/administration/integration/kroki/). - [KubeDiagrams](https://github.com/philippemerle/KubeDiagrams#d2-diagram-generation) — Generate D2 diagrams from Kubernetes manifests and Helm charts. - [Mark for Confluence](https://github.com/kovetskiy/mark#readme) — Publish Markdown with rendered D2 diagrams to Confluence. - [Asciidoctor Diagram](https://docs.asciidoctor.org/diagram-extension/latest/diagram_types/d2/) — Render D2 blocks in AsciiDoc using the D2 CLI. ### Misc - **Comparison site**: [https://github.com/d2lang/text-to-diagram-site](https://github.com/d2lang/text-to-diagram-site) - **Playground**: [https://github.com/d2lang/d2-playground](https://github.com/d2lang/d2-playground) - **Language docs**: [https://github.com/d2lang/d2-docs](https://github.com/d2lang/d2-docs) - **Hosted icons**: [https://icons.d2lang.com](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](./ci/release/changelogs/next.md). - I have a question or need help. - The best way to get help is to ask on [D2 Discord](https://discord.gg/NF6X8K4eDq) - I have a feature request, proposal, or bug report. - Please open up a Github Issue. - I have a private inquiry. - Please reach out at .