Cheatsheets:PlantUML: Difference between revisions
AI-assisted (RonzzWikiCowriter): new PlantUML cheatsheet (via create-page on MediaWiki MCP Server) |
Add Headings/special chars + Links to example, add Code to explanation (AI-assisted RonzzWikiCowriter) (via update-page on MediaWiki MCP Server) |
||
| (12 intermediate revisions by 2 users not shown) | |||
| Line 23: | Line 23: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|| | || | ||
<uml> | |||
@startuml | |||
Alice -> Bob: Authentication Request | |||
Bob --> Alice: Authentication Response | |||
Alice -> Bob: Another request | |||
Alice <-- Bob: Another response | |||
@enduml | |||
</uml> | |||
|} | |} | ||
| Line 94: | Line 102: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|| | || | ||
<uml> | |||
@startuml | |||
participant "Web App" as WA | |||
database "Postgres" as DB | |||
WA -> DB: SELECT * FROM orders | |||
activate DB | |||
DB --> WA: rows | |||
deactivate DB | |||
note right of DB: covered by index | |||
alt rows found | |||
WA -> WA: render table | |||
else empty | |||
WA -> WA: show placeholder | |||
end | |||
loop retry x3 | |||
WA -> WA: backoff | |||
end | |||
@enduml | |||
</uml> | |||
|} | |} | ||
| Line 126: | Line 156: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|| | || | ||
<uml> | |||
@startuml | |||
class Animal { | |||
+name: string | |||
-age: int | |||
+speak(): void | |||
} | |||
Animal <|-- Dog | |||
Dog *-- Collar | |||
@enduml | |||
</uml> | |||
|} | |} | ||
| Line 172: | Line 213: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|| | || | ||
<uml> | |||
@startuml | |||
left to right direction | |||
actor Customer | |||
rectangle "Web shop" { | |||
(Login) | |||
(Browse catalog) | |||
} | |||
Customer --> (Login) | |||
(Login) ..> (Browse catalog) : include | |||
@enduml | |||
</uml> | |||
|} | |} | ||
| Line 196: | Line 248: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|| | || | ||
<uml> | |||
@startuml | |||
start | |||
:Fetch order; | |||
if (in stock?) then (yes) | |||
:Ship order; | |||
else (no) | |||
:Notify customer; | |||
endif | |||
stop | |||
@enduml | |||
</uml> | |||
|} | |} | ||
| Line 216: | Line 279: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|| | || | ||
[ | <uml> | ||
@startuml | |||
[*] --> Idle | |||
Idle --> Running : start() | |||
Running --> Idle : stop() | |||
Running --> [*] : terminate | |||
@enduml | |||
</uml> | |||
|} | |} | ||
| Line 239: | Line 309: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|| | || | ||
[ | <uml> | ||
@startuml | |||
node "Server" { | |||
[Web] --> [App] | |||
} | |||
node "Database" { | |||
database "Postgres" as pg | |||
} | |||
[App] --> pg | |||
@enduml | |||
</uml> | |||
|} | |} | ||
| Line 245: | Line 325: | ||
== Common syntax == | == Common syntax == | ||
Comments and document-level decorations — title, header, footer, legend: | |||
<syntaxhighlight lang="text" copy> | <syntaxhighlight lang="text" copy> | ||
| Line 251: | Line 333: | ||
comment '/ | comment '/ | ||
title Order flow | title Order flow | ||
header v1.0 | ' diagram title | ||
footer %page% / %lastpage% | header v1.0 | ||
' repeated header | |||
footer page %page% of %lastpage% | |||
' %page%/%lastpage%: page numbers | |||
</syntaxhighlight> | |||
<blockquote> | |||
Start '''Comments''' <syntaxhighlight lang="text" inline>'</syntaxhighlight> at the beginning of a new line. '''Avoid trailing comments''': <syntaxhighlight lang="text" inline>title Order flow ' diagram title</syntaxhighlight> can cause a parse error as plantUML considers non-leading <code>'</code> orphaned. | |||
In a header/footer, <syntaxhighlight lang="text" inline>%page%</syntaxhighlight> / <syntaxhighlight lang="text" inline>%lastpage%</syntaxhighlight> become page numbers once the diagram spans several pages. | |||
</blockquote> | |||
{| class="wikitable" | |||
! Source (.puml) !! Rendered | |||
|- | |||
| | |||
<syntaxhighlight lang="text" copy> | |||
@startuml | |||
title Order flow | |||
header v1.0 | |||
footer confidential | |||
Alice -> Bob: Request | |||
Bob --> Alice: Response | |||
@enduml | |||
</syntaxhighlight> | |||
|| | |||
<uml> | |||
@startuml | |||
title Order flow | |||
header v1.0 | |||
footer confidential | |||
legend | Alice -> Bob: Request | ||
Bob --> Alice: Response | |||
@enduml | |||
</uml> | |||
|- | |||
| | |||
<syntaxhighlight lang="text" copy> | |||
@startuml | |||
legend right | |||
Shipped orders only | |||
endlegend | |||
Alice -> Bob: Ship order | |||
Bob --> Alice: OK | |||
@enduml | |||
</syntaxhighlight> | |||
|| | |||
<uml> | |||
@startuml | |||
legend right | |||
Shipped orders only | Shipped orders only | ||
endlegend | endlegend | ||
Alice -> Bob: Ship order | |||
Bob --> Alice: OK | |||
@enduml | |||
</uml> | |||
|} | |||
== Creole == | |||
Creole is a lightweight markup for styling text anywhere in a diagram — labels, notes, titles, class members. All diagram types support it. | |||
{| class="wikitable" | |||
! Source (.puml) !! Rendered | |||
|- | |||
| | |||
<syntaxhighlight lang="text" copy> | |||
@startuml | |||
Alice -> Bob: hello --there-- here | |||
... Some ~~long delay~~ ... | |||
Bob --> Alice: ok | |||
note left | |||
This is **bold** | |||
This is //italics// | |||
This is ""monospaced"" | |||
This is --stricken-out-- | |||
This is __underlined__ | |||
This is ~~wave-underlined~~ | |||
end note | |||
@enduml | |||
</syntaxhighlight> | |||
|| | |||
<uml> | |||
@startuml | |||
Alice -> Bob: hello --there-- here | |||
... Some ~~long delay~~ ... | |||
Bob --> Alice: ok | |||
note left | |||
This is **bold** | |||
This is //italics// | |||
This is ""monospaced"" | |||
This is --stricken-out-- | |||
This is __underlined__ | |||
This is ~~wave-underlined~~ | |||
end note | |||
@enduml | |||
</uml> | |||
|} | |||
{| class="wikitable" | |||
! Creole !! Renders as !! HTML equivalent | |||
|- | |||
| <syntaxhighlight lang="text" inline>**bold**</syntaxhighlight> || bold || <syntaxhighlight lang="text" inline><b>…</b></syntaxhighlight> | |||
|- | |||
| <syntaxhighlight lang="text" inline>//italics//</syntaxhighlight> || italic || <syntaxhighlight lang="text" inline><i>…</i></syntaxhighlight> | |||
|- | |||
| <syntaxhighlight lang="text" inline>""monospaced""</syntaxhighlight> || monospaced || <syntaxhighlight lang="text" inline><font:monospaced>…</font></syntaxhighlight> | |||
|- | |||
| <syntaxhighlight lang="text" inline>--stricken-out--</syntaxhighlight> || strikethrough || <syntaxhighlight lang="text" inline><s>…</s></syntaxhighlight> | |||
|- | |||
| <syntaxhighlight lang="text" inline>__underlined__</syntaxhighlight> || underlined || <syntaxhighlight lang="text" inline><u>…</u></syntaxhighlight> | |||
|- | |||
| <syntaxhighlight lang="text" inline>~~wave-underlined~~</syntaxhighlight> || wavy underline || <syntaxhighlight lang="text" inline><w>…</w></syntaxhighlight> | |||
|} | |||
<blockquote> | |||
'''In double-quoted strings''' — <syntaxhighlight lang="text" inline>""monospaced""</syntaxhighlight> works in quoted content — titles, notes, message labels — but not in quoted element names like <syntaxhighlight lang="text" inline>participant "Alice ..."</syntaxhighlight> or <syntaxhighlight lang="text" inline>state "Waiting ..." as W</syntaxhighlight>: the <syntaxhighlight lang="text" inline>""</syntaxhighlight> collides with the string delimiter and the diagram fails to parse. Use the HTML form there instead: | |||
{| class="wikitable" | |||
! Source (.puml) !! Rendered | |||
|- | |||
| | |||
<syntaxhighlight lang="text" copy> | |||
@startuml | |||
title "The ""answer"" is 42" | |||
participant "Alice <font:monospaced>the Great</font>" as Alice | |||
Alice -> Bob: ""mono"" label | |||
@enduml | |||
</syntaxhighlight> | |||
|| | |||
<uml> | |||
@startuml | |||
title "The ""answer"" is 42" | |||
participant "Alice <font:monospaced>the Great</font>" as Alice | |||
Alice -> Bob: ""mono"" label | |||
@enduml | |||
</uml> | |||
|} | |||
</blockquote> | |||
{| class="wikitable" | |||
! Source (.puml) !! Rendered | |||
|- | |||
| | |||
<syntaxhighlight lang="text" copy> | |||
@startuml | |||
object demo { | |||
* Bullet list | |||
* Second item | |||
** Sub item | |||
} | |||
note as n | |||
* Bullet list | |||
* Second item | |||
** Sub item | |||
---- | |||
# Numbered list | |||
# Second item | |||
## Sub item | |||
end note | |||
@enduml | |||
</syntaxhighlight> | |||
|| | |||
<uml> | |||
@startuml | |||
object demo { | |||
* Bullet list | |||
* Second item | |||
** Sub item | |||
} | |||
note as n | |||
* Bullet list | |||
* Second item | |||
** Sub item | |||
---- | |||
# Numbered list | |||
# Second item | |||
## Sub item | |||
end note | |||
@enduml | |||
</uml> | |||
|} | |||
'''Lists''' — <syntaxhighlight lang="text" inline>*</syntaxhighlight> bullet, <syntaxhighlight lang="text" inline>#</syntaxhighlight> numbered; repeat the marker to nest (<syntaxhighlight lang="text" inline>**</syntaxhighlight>, <syntaxhighlight lang="text" inline>##</syntaxhighlight>). You cannot mix bullets and numbers in one list. | |||
'''Horizontal lines''' — <syntaxhighlight lang="text" inline>----</syntaxhighlight> single, <syntaxhighlight lang="text" inline>====</syntaxhighlight> double, <syntaxhighlight lang="text" inline>____</syntaxhighlight> strong, <syntaxhighlight lang="text" inline>..My title..</syntaxhighlight> dotted with title, <syntaxhighlight lang="text" inline>==Title==</syntaxhighlight> / <syntaxhighlight lang="text" inline>--Another title--</syntaxhighlight> with a title. | |||
{| class="wikitable" | |||
! Source (.puml) !! Rendered | |||
|- | |||
| | |||
<syntaxhighlight lang="text" copy> | |||
@startuml | |||
title "The ""answer"" is <U+221E>" | |||
Alice -> Bob: <:1f600:> [[http://plantuml.com docs]] | |||
Alice -> Bob: Recolor: <#green:sunny:> | |||
note right | |||
= Heading | |||
== Sub heading | |||
<code> | |||
main() { | |||
printf("Hello world"); | |||
} | |||
</code> | |||
end note | |||
@enduml | |||
</syntaxhighlight> | |||
|| | |||
<uml> | |||
@startuml | |||
title "The ""answer"" is <U+221E>" | |||
Alice -> Bob: <:1f600:> [[http://plantuml.com docs]] | |||
Alice -> Bob: Recolor: <#green:sunny:> | |||
note right | |||
= Heading | |||
== Sub heading | |||
<code> | |||
main() { | |||
printf("Hello world"); | |||
} | |||
</code> | |||
end note | |||
@enduml | |||
</uml> | |||
|} | |||
'''Links''' — <syntaxhighlight lang="text" inline>[[http://plantuml.com]]</syntaxhighlight>, <syntaxhighlight lang="text" inline>[[http://plantuml.com This label is printed]]</syntaxhighlight>, with tooltip <syntaxhighlight lang="text" inline>[[http://plantuml.com{Optional tooltip} This label is printed]]</syntaxhighlight> — three brackets link to a field or method on class diagrams. | |||
'''Emoji & icons''' — Twemoji emoji are always available (no font dependency) and already colored: <syntaxhighlight lang="text" inline><:1f600:></syntaxhighlight>, recolored <syntaxhighlight lang="text" inline><#green:sunny:></syntaxhighlight>. OpenIconic icons: <syntaxhighlight lang="text" inline><&heart></syntaxhighlight>. List them with the special commands <syntaxhighlight lang="text" inline>emoji</syntaxhighlight> and <syntaxhighlight lang="text" inline>listopeniconic</syntaxhighlight>. | |||
'''Headings & special chars''' — inside quoted multi-line labels: <syntaxhighlight lang="text" inline>= Head</syntaxhighlight>, <syntaxhighlight lang="text" inline>== Sub</syntaxhighlight>, <syntaxhighlight lang="text" inline>=== Sub-sub</syntaxhighlight>. Any Unicode char works directly, or as <syntaxhighlight lang="text" inline><U+221E></syntaxhighlight> (hex) / <syntaxhighlight lang="text" inline>∞</syntaxhighlight> (decimal). | |||
'''Code''' — <syntaxhighlight lang="text" inline><code>…</code></syntaxhighlight> shows source code without syntax highlighting. | |||
'''Legacy HTML''' — colors, sizes, images, sub/superscripts: <syntaxhighlight lang="text" inline><color:red>…</color></syntaxhighlight>, <syntaxhighlight lang="text" inline><back:cadetblue>…</back></syntaxhighlight>, <syntaxhighlight lang="text" inline><size:18>…</size></syntaxhighlight>, <syntaxhighlight lang="text" inline><img:https://…></syntaxhighlight>, <syntaxhighlight lang="text" inline><sub></syntaxhighlight> / <syntaxhighlight lang="text" inline><sup></syntaxhighlight>. | |||
{| class="wikitable" | |||
! Source (.puml) !! Rendered | |||
|- | |||
| | |||
<syntaxhighlight lang="text" copy> | |||
@startuml | |||
Alice -> Bob: <b>Hello World</b> | |||
Alice -> Bob: ~<b>Hello World~</b> | |||
@enduml | |||
</syntaxhighlight> | |||
|| | |||
<uml> | |||
@startuml | |||
Alice -> Bob: <b>Hello World</b> | |||
Alice -> Bob: ~<b>Hello World~</b> | |||
@enduml | |||
</uml> | |||
|- | |||
| | |||
<syntaxhighlight lang="text" copy> | |||
@startuml | |||
Alice -> Bob: [[Wiki Home]] | |||
Alice -> Bob: ~[[Wiki Home]] | |||
@enduml | |||
</syntaxhighlight> | |||
|| | |||
<uml> | |||
@startuml | |||
Alice -> Bob: [[Wiki Home]] | |||
Alice -> Bob: ~[[Wiki Home]] | |||
@enduml | |||
</uml> | |||
|} | |||
'''Escaping''' — <syntaxhighlight lang="text" inline>~</syntaxhighlight> prints the next special character literally; unescaped, PlantUML interprets it as creole markup: | |||
Full reference: [https://plantuml.com/creole PlantUML Creole]. | |||
== Notes == | |||
A note is a box of text attached to an element of any diagram type — participant, class, state, use case, link. Sequence-diagram notes are covered in [[#Sequence diagrams|Sequence diagrams]]; here is the general shape: | |||
{| class="wikitable" | |||
! Source (.puml) !! Rendered | |||
|- | |||
| | |||
<syntaxhighlight lang="text" copy> | |||
@startuml | |||
class Animal | |||
note left of Animal : speaks | |||
note right of Animal : eats | |||
note top of Animal : alive | |||
note bottom of Animal : breathes | |||
@enduml | |||
</syntaxhighlight> | |||
|| | |||
<uml> | |||
@startuml | |||
class Animal | |||
note left of Animal : speaks | |||
note right of Animal : eats | |||
note top of Animal : alive | |||
note bottom of Animal : breathes | |||
@enduml | |||
</uml> | |||
|- | |||
| | |||
<syntaxhighlight lang="text" copy> | |||
@startuml | |||
participant Alice | |||
participant Bob | |||
Alice -> Bob: hi | |||
note over Alice : single line | |||
note over Alice, Bob : over a range | |||
@enduml | |||
</syntaxhighlight> | |||
|| | |||
<uml> | |||
@startuml | |||
participant Alice | |||
participant Bob | |||
Alice -> Bob: hi | |||
note over Alice : single line | |||
note over Alice, Bob : over a range | |||
@enduml | |||
</uml> | |||
|- | |||
| | |||
<syntaxhighlight lang="text" copy> | |||
@startuml | |||
start | |||
:Fetch order; | |||
note : floating single-line note | |||
:Ship order; | |||
stop | |||
@enduml | |||
</syntaxhighlight> | </syntaxhighlight> | ||
|| | |||
<uml> | |||
@startuml | |||
start | |||
:Fetch order; | |||
note : floating single-line note | |||
:Ship order; | |||
stop | |||
@enduml | |||
</uml> | |||
|} | |||
<blockquote> | <blockquote> | ||
'''Placement''' — <syntaxhighlight lang="text" inline>left of X</syntaxhighlight>, <syntaxhighlight lang="text" inline>right of X</syntaxhighlight>, <syntaxhighlight lang="text" inline>top of X</syntaxhighlight>, <syntaxhighlight lang="text" inline>bottom of X</syntaxhighlight>, '''works in the single-line format with the text after a colon''', but '''may not work with other note syntaxes in some scenarios'''. | |||
</blockquote> | </blockquote> | ||
<blockquote> | |||
In sequence diagrams <syntaxhighlight lang="text" inline>over X</syntaxhighlight> / <syntaxhighlight lang="text" inline>over X, Y</syntaxhighlight> span one or a range of participants; in activity diagrams <syntaxhighlight lang="text" inline>note</syntaxhighlight> alone (or <syntaxhighlight lang="text" inline>note right</syntaxhighlight>) floats beside the current step. | |||
</blockquote> | |||
Long text, or several lines: open a <syntaxhighlight lang="text" inline>note</syntaxhighlight> block and close with <syntaxhighlight lang="text" inline>end note</syntaxhighlight>. A note with a quoted title becomes free-floating — attach it to an element with a dotted line: | |||
{| class="wikitable" | |||
! Source (.puml) !! Rendered | |||
|- | |||
| | |||
<syntaxhighlight lang="text" copy> | |||
@startuml | |||
start | |||
:Fetch order; | |||
note right | |||
may block for seconds | |||
end note | |||
:Ship order; | |||
stop | |||
@enduml | |||
</syntaxhighlight> | |||
|| | |||
<uml> | |||
@startuml | |||
start | |||
:Fetch order; | |||
note right | |||
may block for seconds | |||
end note | |||
:Ship order; | |||
stop | |||
@enduml | |||
</uml> | |||
|- | |||
| | |||
<syntaxhighlight lang="text" copy> | |||
@startuml | |||
class Animal | |||
note "why it matters" as N1 | |||
Animal .. N1 | |||
@enduml | |||
</syntaxhighlight> | |||
|| | |||
<uml> | |||
@startuml | |||
class Animal | |||
note "why it matters" as N1 | |||
Animal .. N1 | |||
@enduml | |||
</uml> | |||
|- | |||
| | |||
<syntaxhighlight lang="text" copy> | |||
@startuml | |||
participant Alice | |||
participant Bob | |||
Alice -> Bob: hi | |||
note over Alice | |||
line one | |||
line two | |||
end note | |||
note over Alice, Bob | |||
over a range | |||
end note | |||
@enduml | |||
</syntaxhighlight> | |||
|| | |||
<uml> | |||
@startuml | |||
participant Alice | |||
participant Bob | |||
Alice -> Bob: hi | |||
note over Alice | |||
line one | |||
line two | |||
end note | |||
note over Alice, Bob | |||
over a range | |||
end note | |||
@enduml | |||
</uml> | |||
|- | |||
| | |||
<syntaxhighlight lang="text" copy> | |||
@startuml | |||
start | |||
:Fetch order; | |||
note | |||
floating multi-line note | |||
end note | |||
:Ship order; | |||
stop | |||
@enduml | |||
</syntaxhighlight> | |||
|| | |||
<uml> | |||
@startuml | |||
start | |||
:Fetch order; | |||
note | |||
floating multi-line note | |||
end note | |||
:Ship order; | |||
stop | |||
@enduml | |||
</uml> | |||
|} | |||
== Theme == | |||
Swap the whole look with one directive at the top of the diagram — themes ship with PlantUML, nothing to install: | |||
{| class="wikitable" | |||
! Source (.puml) !! Rendered | |||
|- | |||
| | |||
<syntaxhighlight lang="text" copy> | |||
@startuml | |||
!theme spacelab | |||
class Example { | |||
Theme spacelab | |||
} | |||
@enduml | |||
</syntaxhighlight> | |||
|| | |||
<uml> | |||
@startuml | |||
!theme spacelab | |||
class Example { | |||
Theme spacelab | |||
} | |||
@enduml | |||
</uml> | |||
|} | |||
* <syntaxhighlight lang="text" inline>help themes</syntaxhighlight> renders the full list of built-in themes. | |||
* Your own theme: <syntaxhighlight lang="text" inline>!theme foo from /path/to/folder</syntaxhighlight> — a file named <syntaxhighlight lang="text" inline>puml-theme-foo.puml</syntaxhighlight> (remote URLs work too). | |||
* Some themes add message helpers: <syntaxhighlight lang="text" inline>$success("…")</syntaxhighlight>, <syntaxhighlight lang="text" inline>$failure("…")</syntaxhighlight>, <syntaxhighlight lang="text" inline>$warning("…")</syntaxhighlight>. | |||
Browse the [https://the-lum.github.io/puml-themes-gallery/ gallery of official themes]. Full reference: [https://plantuml.com/theme PlantUML Themes]. | |||
== Style == | |||
CSS-like <syntaxhighlight lang="text" inline><style></syntaxhighlight> blocks replace the deprecated <syntaxhighlight lang="text" inline>skinparam</syntaxhighlight>. Selectors target everything (<syntaxhighlight lang="text" inline>element</syntaxhighlight>), one diagram type (<syntaxhighlight lang="text" inline>sequenceDiagram</syntaxhighlight>, <syntaxhighlight lang="text" inline>classDiagram</syntaxhighlight>, …) or one element (<syntaxhighlight lang="text" inline>participant</syntaxhighlight>, <syntaxhighlight lang="text" inline>arrow</syntaxhighlight>, <syntaxhighlight lang="text" inline>node</syntaxhighlight>, …): | |||
{| class="wikitable" | |||
! Source (.puml) !! Rendered | |||
|- | |||
| | |||
<syntaxhighlight lang="text" copy> | |||
@startuml | |||
<style> | |||
element { | |||
BackGroundColor: #AAA; | |||
} | |||
sequenceDiagram { | |||
participant { | |||
FontColor: green; | |||
FontSize: 26; | |||
FontStyle: italic; | |||
LineColor: #E00; | |||
} | |||
arrow { | |||
FontColor: red; | |||
LineColor: blue; | |||
} | |||
} | |||
</style> | |||
participant Alice | |||
participant Bob | |||
Alice -> Bob : hello | |||
@enduml | |||
</syntaxhighlight> | |||
|| | |||
<uml> | |||
@startuml | |||
<style> | |||
element { | |||
BackGroundColor: #AAA; | |||
} | |||
sequenceDiagram { | |||
participant { | |||
FontColor: green; | |||
FontSize: 26; | |||
FontStyle: italic; | |||
LineColor: #E00; | |||
} | |||
arrow { | |||
FontColor: red; | |||
LineColor: blue; | |||
} | |||
} | |||
</style> | |||
participant Alice | |||
participant Bob | |||
Alice -> Bob : hello | |||
@enduml | |||
</uml> | |||
|} | |||
Common properties: <syntaxhighlight lang="text" inline>FontColor</syntaxhighlight>, <syntaxhighlight lang="text" inline>FontSize</syntaxhighlight>, <syntaxhighlight lang="text" inline>FontStyle</syntaxhighlight>, <syntaxhighlight lang="text" inline>FontName</syntaxhighlight>; <syntaxhighlight lang="text" inline>BackGroundColor</syntaxhighlight>, <syntaxhighlight lang="text" inline>LineColor</syntaxhighlight>, <syntaxhighlight lang="text" inline>LineThickness</syntaxhighlight>, <syntaxhighlight lang="text" inline>RoundCorner</syntaxhighlight>, <syntaxhighlight lang="text" inline>Padding</syntaxhighlight>, <syntaxhighlight lang="text" inline>Shadowing</syntaxhighlight>. Custom classes: tag an element <syntaxhighlight lang="text" inline>as X <<primary>></syntaxhighlight>, then style <syntaxhighlight lang="text" inline>.primary { ... }</syntaxhighlight>. | |||
Full reference: [https://plantuml.com/style PlantUML Styles]. | |||
== Rendering == | == Rendering == | ||
| Line 273: | Line 910: | ||
{| class="wikitable" | {| class="wikitable" | ||
! Tool !! How | ! Tool !! How | ||
|- | |||
| This wiki || <syntaxhighlight lang="wikitext" inline><uml> ... </uml></syntaxhighlight> — see [[Help:Contributing/diagrams|rendering diagrams on this wiki]] | |||
|- | |- | ||
| CLI || <syntaxhighlight lang="bash" inline>java -jar plantuml.jar diagram.puml</syntaxhighlight> → <syntaxhighlight lang="text" inline>diagram.png</syntaxhighlight> (Java required; GraphViz only for some diagram types) | | CLI || <syntaxhighlight lang="bash" inline>java -jar plantuml.jar diagram.puml</syntaxhighlight> → <syntaxhighlight lang="text" inline>diagram.png</syntaxhighlight> (Java required; GraphViz only for some diagram types) | ||
| Line 292: | Line 931: | ||
plantuml *.puml # whole directory | plantuml *.puml # whole directory | ||
</syntaxhighlight> | </syntaxhighlight> | ||
* [https://plantuml.com/ PlantUML] — official site; every diagram type has its own page (sequence-diagram, class-diagram, use-case-diagram, …) | * [https://plantuml.com/ PlantUML] — official site; every diagram type has its own page (sequence-diagram, class-diagram, use-case-diagram, …) | ||
* [https://plantuml.com/starting Quick Start Guide] — install, first diagram | * [https://plantuml.com/starting Quick Start Guide] — install, first diagram | ||
* [https://plantuml.com/guide PlantUML Language Reference Guide] — the full syntax | * [https://plantuml.com/guide PlantUML Language Reference Guide] — the full syntax | ||
* [https://plantuml.com/creole PlantUML Creole] — styled text in any diagram | |||
* [https://plantuml.com/theme PlantUML Themes] — built-in themes, one-line look change | |||
* [https://plantuml.com/style PlantUML Styles] — CSS-like styling, the skinparam replacement | |||
* [https://kroki.io/ Kroki] — render PlantUML inside Markdown, AsciiDoc, reStructuredText, … | * [https://kroki.io/ Kroki] — render PlantUML inside Markdown, AsciiDoc, reStructuredText, … | ||
* [https://marketplace.visualstudio.com/items?itemName=jebbs.plantuml PlantUML VS Code extension] | * [https://marketplace.visualstudio.com/items?itemName=jebbs.plantuml PlantUML VS Code extension] | ||
Latest revision as of 15:32, 31 August 2026
Quick reference for smart people — part of our dev cheatsheets collection.
PlantUML is a text-based diagramming language: describe a diagram in a few lines of plain text, render it to PNG, SVG, or ASCII art. The source is just text, so diagrams live in version control and diff cleanly. One syntax covers sequence, class, use case, activity, state, component and deployment diagrams.
New to PlantUML? The Quick Start Guide may interest you.
Basic example
Wrap every diagram in @startuml ... @enduml, save as .puml and render — see Rendering:
| Source (.puml) | Rendered |
|---|---|
@startuml
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
Alice -> Bob: Another request
Alice <-- Bob: Another response
@enduml
|
|
Sequence diagrams
The workhorse. A message is sender arrow receiver: text — the text after the colon is the label.
| Arrow | Renders as |
|---|---|
-> |
solid line, no arrowhead |
--> |
dashed line, no arrowhead (typical reply) |
->> |
solid line with arrowhead |
-->> |
dashed line with arrowhead |
-x |
line ending in a cross (destroys the lifeline) |
-) |
line ending in an open arrowhead |
Solid for synchronous calls, dashed for replies and asynchronous messages.
Participants — declare to control order and role. as NAME gives an alias: the quoted text is displayed, the alias is used in messages.
@startuml
participant "Web App" as WA
actor "Customer" as C
database "Postgres" as DB
entity E
control Ctrl
boundary B
queue Q
@enduml
Role keywords: actor, participant, database, entity, control, boundary, queue.
Activations, notes and fragments:
| Source (.puml) | Rendered |
|---|---|
@startuml
participant "Web App" as WA
database "Postgres" as DB
WA -> DB: SELECT * FROM orders
activate DB
DB --> WA: rows
deactivate DB
note right of DB: covered by index
alt rows found
WA -> WA: render table
else empty
WA -> WA: show placeholder
end
loop retry x3
WA -> WA: backoff
end
@enduml
|
|
activate / deactivate — draw a lifeline bar. Shorthand:
DB ++...DB --;return valuesends a dashed reply and deactivates.Fragments —
alt/else,opt,loop,par/and,break,critical,group label— all close withend.Notes —
note left of X,note right of X,note over X,note over X, Y.Numbering —
autonumberlabels messages 1, 2, 3...
Class diagrams
| Source (.puml) | Rendered |
|---|---|
@startuml
class Animal {
+name: string
-age: int
+speak(): void
}
Animal <|-- Dog
Dog *-- Collar
@enduml
|
|
Visibility markers: + public, - private, # protected, ~ package. Kinds: abstract class, interface, enum.
Relations — labels and multiplicities go at the ends:
| Symbol | Meaning |
|---|---|
Animal <|-- Dog |
inheritance (also class Dog extends Animal)
|
..|> |
realization (implements an interface) |
*-- |
composition |
o-- |
aggregation |
-- / --> |
association |
..> |
dependency |
Dog "1" *-- "0..*" Collar : has
Use case diagrams
| Source (.puml) | Rendered |
|---|---|
@startuml
left to right direction
actor Customer
rectangle "Web shop" {
(Login)
(Browse catalog)
}
Customer --> (Login)
(Login) ..> (Browse catalog) : include
@enduml
|
|
Use cases in parentheses (Login) or usecase "Login" as L; boundaries with rectangle "name" { ... } or package. Dotted arrows express include / extend.
Activity diagrams
| Source (.puml) | Rendered |
|---|---|
@startuml
start
:Fetch order;
if (in stock?) then (yes)
:Ship order;
else (no)
:Notify customer;
endif
stop
@enduml
|
|
:action; is a step; if (cond) then (yes) ... else (no) ... endif a decision. Also while (cond) ... endwhile and fork ... end fork for concurrency.
State diagrams
| Source (.puml) | Rendered |
|---|---|
@startuml
[*] --> Idle
Idle --> Running : start()
Running --> Idle : stop()
Running --> [*] : terminate
@enduml
|
|
[*] is the initial/final state; State --> State : event labels a transition. Long names: state "Waiting for input" as Waiting.
Component & deployment
| Source (.puml) | Rendered |
|---|---|
@startuml
node "Server" {
[Web] --> [App]
}
node "Database" {
database "Postgres" as pg
}
[App] --> pg
@enduml
|
|
Square brackets for components, database "name" for datastores, node "name" { ... } / package { ... } for containers.
Common syntax
Comments and document-level decorations — title, header, footer, legend:
' single-line comment
/' multi-line
comment '/
title Order flow
' diagram title
header v1.0
' repeated header
footer page %page% of %lastpage%
' %page%/%lastpage%: page numbers
Start Comments
'at the beginning of a new line. Avoid trailing comments:title Order flow ' diagram titlecan cause a parse error as plantUML considers non-leading'orphaned.In a header/footer,
%page%/%lastpage%become page numbers once the diagram spans several pages.
| Source (.puml) | Rendered |
|---|---|
@startuml
title Order flow
header v1.0
footer confidential
Alice -> Bob: Request
Bob --> Alice: Response
@enduml
|
|
@startuml
legend right
Shipped orders only
endlegend
Alice -> Bob: Ship order
Bob --> Alice: OK
@enduml
|
|
Creole
Creole is a lightweight markup for styling text anywhere in a diagram — labels, notes, titles, class members. All diagram types support it.
| Source (.puml) | Rendered |
|---|---|
@startuml
Alice -> Bob: hello --there-- here
... Some ~~long delay~~ ...
Bob --> Alice: ok
note left
This is **bold**
This is //italics//
This is ""monospaced""
This is --stricken-out--
This is __underlined__
This is ~~wave-underlined~~
end note
@enduml
|
|
| Creole | Renders as | HTML equivalent |
|---|---|---|
**bold** |
bold | <b>…</b>
|
//italics// |
italic | <i>…</i>
|
""monospaced"" |
monospaced | <font:monospaced>…</font>
|
--stricken-out-- |
strikethrough | <s>…</s>
|
__underlined__ |
underlined | <u>…</u>
|
~~wave-underlined~~ |
wavy underline | <w>…</w>
|
In double-quoted strings —
""monospaced""works in quoted content — titles, notes, message labels — but not in quoted element names likeparticipant "Alice ..."orstate "Waiting ..." as W: the""collides with the string delimiter and the diagram fails to parse. Use the HTML form there instead:
Source (.puml) Rendered @startuml title "The ""answer"" is 42" participant "Alice <font:monospaced>the Great</font>" as Alice Alice -> Bob: ""mono"" label @enduml
| Source (.puml) | Rendered |
|---|---|
@startuml
object demo {
* Bullet list
* Second item
** Sub item
}
note as n
* Bullet list
* Second item
** Sub item
----
# Numbered list
# Second item
## Sub item
end note
@enduml
|
|
Lists — * bullet, # numbered; repeat the marker to nest (**, ##). You cannot mix bullets and numbers in one list.
Horizontal lines — ---- single, ==== double, ____ strong, ..My title.. dotted with title, ==Title== / --Another title-- with a title.
| Source (.puml) | Rendered |
|---|---|
@startuml
title "The ""answer"" is <U+221E>"
Alice -> Bob: <:1f600:> [[http://plantuml.com docs]]
Alice -> Bob: Recolor: <#green:sunny:>
note right
= Heading
== Sub heading
<code>
main() {
printf("Hello world");
}
</code>
end note
@enduml |
|
Links — [[http://plantuml.com]], [[http://plantuml.com This label is printed]], with tooltip [[http://plantuml.com{Optional tooltip} This label is printed]] — three brackets link to a field or method on class diagrams.
Emoji & icons — Twemoji emoji are always available (no font dependency) and already colored: <:1f600:>, recolored <#green:sunny:>. OpenIconic icons: <&heart>. List them with the special commands emoji and listopeniconic.
Headings & special chars — inside quoted multi-line labels: = Head, == Sub, === Sub-sub. Any Unicode char works directly, or as <U+221E> (hex) / ∞ (decimal).
Code — <code>…</code> shows source code without syntax highlighting.
Legacy HTML — colors, sizes, images, sub/superscripts: <color:red>…</color>, <back:cadetblue>…</back>, <size:18>…</size>, <img:https://…>, <sub> / <sup>.
| Source (.puml) | Rendered |
|---|---|
@startuml
Alice -> Bob: <b>Hello World</b>
Alice -> Bob: ~<b>Hello World~</b>
@enduml |
|
@startuml
Alice -> Bob: [[Wiki Home]]
Alice -> Bob: ~[[Wiki Home]]
@enduml |
|
Escaping — ~ prints the next special character literally; unescaped, PlantUML interprets it as creole markup:
Full reference: PlantUML Creole.
Notes
A note is a box of text attached to an element of any diagram type — participant, class, state, use case, link. Sequence-diagram notes are covered in Sequence diagrams; here is the general shape:
| Source (.puml) | Rendered |
|---|---|
@startuml
class Animal
note left of Animal : speaks
note right of Animal : eats
note top of Animal : alive
note bottom of Animal : breathes
@enduml |
|
@startuml
participant Alice
participant Bob
Alice -> Bob: hi
note over Alice : single line
note over Alice, Bob : over a range
@enduml |
|
@startuml
start
:Fetch order;
note : floating single-line note
:Ship order;
stop
@enduml |
|
Placement —
left of X,right of X,top of X,bottom of X, works in the single-line format with the text after a colon, but may not work with other note syntaxes in some scenarios.
In sequence diagrams
over X/over X, Yspan one or a range of participants; in activity diagramsnotealone (ornote right) floats beside the current step.
Long text, or several lines: open a note block and close with end note. A note with a quoted title becomes free-floating — attach it to an element with a dotted line:
| Source (.puml) | Rendered |
|---|---|
@startuml
start
:Fetch order;
note right
may block for seconds
end note
:Ship order;
stop
@enduml |
|
@startuml
class Animal
note "why it matters" as N1
Animal .. N1
@enduml |
|
@startuml
participant Alice
participant Bob
Alice -> Bob: hi
note over Alice
line one
line two
end note
note over Alice, Bob
over a range
end note
@enduml |
|
@startuml
start
:Fetch order;
note
floating multi-line note
end note
:Ship order;
stop
@enduml |
|
Theme
Swap the whole look with one directive at the top of the diagram — themes ship with PlantUML, nothing to install:
| Source (.puml) | Rendered |
|---|---|
@startuml
!theme spacelab
class Example {
Theme spacelab
}
@enduml |
|
help themesrenders the full list of built-in themes.- Your own theme:
!theme foo from /path/to/folder— a file namedpuml-theme-foo.puml(remote URLs work too). - Some themes add message helpers:
$success("…"),$failure("…"),$warning("…").
Browse the gallery of official themes. Full reference: PlantUML Themes.
Style
CSS-like <style> blocks replace the deprecated skinparam. Selectors target everything (element), one diagram type (sequenceDiagram, classDiagram, …) or one element (participant, arrow, node, …):
| Source (.puml) | Rendered |
|---|---|
@startuml
<style>
element {
BackGroundColor: #AAA;
}
sequenceDiagram {
participant {
FontColor: green;
FontSize: 26;
FontStyle: italic;
LineColor: #E00;
}
arrow {
FontColor: red;
LineColor: blue;
}
}
</style>
participant Alice
participant Bob
Alice -> Bob : hello
@enduml |
|
Common properties: FontColor, FontSize, FontStyle, FontName; BackGroundColor, LineColor, LineThickness, RoundCorner, Padding, Shadowing. Custom classes: tag an element as X <<primary>>, then style .primary { ... }.
Full reference: PlantUML Styles.
Rendering
| Tool | How |
|---|---|
| This wiki | <uml> ... </uml> — see rendering diagrams on this wiki
|
| CLI | java -jar plantuml.jar diagram.puml → diagram.png (Java required; GraphViz only for some diagram types)
|
| VS Code | PlantUML extension — Alt+D previews the diagram live
|
| Browser | plantuml.com online server; Kroki |
| GitLab | ```plantuml fenced blocks render natively (when enabled on the instance)
|
CLI options:
plantuml diagram.puml # PNG (default)
plantuml -tsvg diagram.puml # SVG
plantuml -tutxt diagram.puml # ASCII art
plantuml -o out/ diagram.puml # output directory
plantuml *.puml # whole directory- PlantUML — official site; every diagram type has its own page (sequence-diagram, class-diagram, use-case-diagram, …)
- Quick Start Guide — install, first diagram
- PlantUML Language Reference Guide — the full syntax
- PlantUML Creole — styled text in any diagram
- PlantUML Themes — built-in themes, one-line look change
- PlantUML Styles — CSS-like styling, the skinparam replacement
- Kroki — render PlantUML inside Markdown, AsciiDoc, reStructuredText, …
- PlantUML VS Code extension