Repolode
d2lang

d2lang/d2

A text-based diagram scripting language and CLI that compiles .d2 files into SVG, PNG, GIF, PDF, or PPTX diagrams.

Open-source alternative to:LucidchartVisio

Stars
25,701
Forks
767
Open issues
536
Last commit
10 days ago

What is it?

D2 is a diagram scripting language: you describe nodes, connections, containers and styles in plain text, and the D2 CLI renders the result as an SVG, PNG, GIF, PDF or PPTX file. A watch mode re-renders the output and reloads the browser preview whenever the source file changes.

The project bundles three layout engines, Dagre (the default), ELK and TALA, which can be selected with a flag, an environment variable or a setting inside the D2 source. Sketch-style rendering and LaTeX labels are also supported, and the parser reports multiple errors from a broken file. An autoformatter and syntax highlighting support editing and maintaining large diagrams.

D2 can also be used from Go programs as a library. Editor extensions for VS Code, Vim and Obsidian, along with a number of community plugins for Markdown tools, are listed in the project's related resources.

Key features

  • 01Converts plain-text .d2 scripts into SVG, PNG, GIF, PDF or PPTX output.
  • 02Provides a watch mode that live-reloads the browser preview on file changes.
  • 03Bundles Dagre, ELK and TALA layout engines, selectable per diagram.
  • 04Parser reports multiple errors and includes an autoformatter and syntax highlighting.
  • 05Can be used as a Go library to generate diagrams programmatically.

Use cases

  • Documenting software architecture diagrams stored alongside code in version control.
  • Keeping system and network diagrams up to date as text that is easy to diff and review.
  • Generating diagrams automatically from Go programs or documentation build pipelines.
  • Creating entity-relationship or flow diagrams in Markdown-based documentation sites.

Quick start

  1. 1

    Install D2 with the install script from the README

  2. 2

    Install D2 via Go

    go install github.com/d2lang/d2@latest
  3. 3

    Create an input file and render it with live reload

    echo 'x -> y -> z' > in.d2 && d2 --watch in.d2 out.svg

Things to know

  • The recommended install method is a curl script piped to sh, which some users may avoid.
  • Go install does not include the manpage.

Topics

FAQ

What is d2?
A text-based diagram scripting language and CLI that compiles .d2 files into SVG, PNG, GIF, PDF, or PPTX diagrams. D2 is a diagram scripting language: you describe nodes, connections, containers and styles in plain text, and the D2 CLI renders the result as an SVG, PNG, GIF, PDF or PPTX file. A watch mode re-renders the output and reloads the browser preview whenever the source file changes.
Is d2 free to use? What license does it have?
d2 is open source under the MPL-2.0 license. Check the license terms before using it in commercial products.
Is d2 still maintained?
Actively maintained. The last commit to d2 was on Oct 11, 2026.
What can I use d2 for?
Documenting software architecture diagrams stored alongside code in version control. Keeping system and network diagrams up to date as text that is easy to diff and review. Generating diagrams automatically from Go programs or documentation build pipelines. Creating entity-relationship or flow diagrams in Markdown-based documentation sites.
How do I install d2?
Install D2 with the install script from the README Install D2 via Go: go install github.com/d2lang/d2@latest Create an input file and render it with live reload: echo 'x -> y -> z' > in.d2 && d2 --watch in.d2 out.svg
Where can I get d2?
The source code and installation instructions are on GitHub: https://github.com/d2lang/d2

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects