All diagram types Open editor

merIDK / Diagram types / Railroad (syntax) diagram

Mermaid railroad (syntax) diagram: example and syntax

Railroad diagrams draw a grammar as tracks you can follow, the way JSON and SQL are documented. Mermaid builds them from EBNF, ABNF or PEG grammars.

Open this example in the editor

Example code

railroad-ebnf-beta
title "Number"

number = [ "-" ] , digit , { digit } ;
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;

Result

railroad-ebnf-beta
title "Number"

number = [ "-" ] , digit , { digit } ;
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;

Syntax quick reference

How to use it

  1. Open the example in the editor, or paste your own Mermaid code.
  2. Edit the code on the left. The preview updates as you type, and errors point to the line.
  3. Export SVG or PNG, copy a Markdown block for GitHub or Notion, or copy a share link.

More diagram types