時序圖
時序圖展示誰對誰說了什麼,按順序從上往下排列。它以 sequence 及其標題開頭。
sequence Paying at the till
actor Customer
participant Till
participant bank: Bank of Example
database Ledger
Customer -> Till: Scan the items
Till -> bank: Ask to pay 12.50
bank -> Ledger: Hold the amount
Ledger --> bank: Held
if Card accepted
bank --> Till: Approved
Till --> Customer: Receipt
else Card declined
bank --> Till: Declined
Till --> Customer: Try another card
note over Till, bank: Card details never stay on the till

設定
| 設定 | 別名 | 值 |
|---|---|---|
numbers |
numbered, numbering, autonumber |
on 為訊息編號;預設關閉。單獨一行的 autonumber 效果相同。 |
activations |
activation, bars |
off 表示不畫啟用條;預設開啟 |
mirror |
footer, heads below |
off 表示不在底部重複畫出參與者的頭部;預設開啟 |
參與者
參與者以列表示,按首次命名的順序排列 —— 無論是在訊息中命名,還是在頂部宣告:
| 行 | 繪製為 |
|---|---|
participant Till |
方框 |
actor Customer(也可寫作 person) |
人形 |
database Ledger |
圓柱體 |
宣告時可以為長名稱指定一個用於書寫訊息的短名稱,兩種順序均可:participant bank: Bank of Example,或 participant Bank of Example as bank。名稱後方括號中的顏色會為參與者的頭部著色:actor Customer [orange]。
訊息
From -> To: what is said 是一條訊息,訊息按書寫順序從上往下排列。
| 箭頭 | 含義 |
|---|---|
->, ->> |
呼叫:帶實心箭頭的實線 |
-->, -->>, ..> |
回覆:帶開放箭頭的虛線 |
<-, <-- |
同上,但指回第一個名稱 |
得到回覆的呼叫會在接收方畫一個啟用條,從呼叫一直延續到回覆返回;從未得到回覆的呼叫則不畫。發給自己的訊息 —— Ann -> Ann: Think —— 是位於其自身列上的一個迴環。文字後方括號中的顏色或角色會為訊息著色:Till --> Customer: Declined [bad]。
塊
縮排在塊關鍵字下方的行會被畫在一個框中,框以該關鍵字命名,關鍵字之後的文字作為其條件:
| 單詞 | 別名 | 用途 |
|---|---|---|
loop |
重複進行的事情 | |
if |
alt |
選擇;在其各行之後、以相同縮排寫的 else 會增加另一種情況 |
opt |
optional |
可能發生的事情 |
par |
parallel |
同時發生的事情;and 會增加另一條分支 |
critical |
必須完整發生的事情 | |
break |
代替其餘部分發生的事情 | |
region |
其他任何需要加框的片段 |
sequence A month of banking
numbers: on
actor Ann
participant Bank of Example as Bank
Ann -> Bank: Log in
Bank --> Ann: Welcome
== Every month ==
loop Until the account is closed
Bank -> Ann: Statement
Ann --> Bank: Read
par
Ann -> Bank: Pay the rent
and
Ann -> Bank: Save a little
note right of Ann: Busy month
Ann -> Ann: Plan next month

沒有緊跟在其 if 或 par 之後的 else 或 and 會被指出。下方有縮排行的訊息會收到警告 —— 只有塊才能包含行 —— 這些行會被當作訊息讀取。
註解和分隔線
| 行 | 繪製為 |
|---|---|
note over A: text |
位於 A 上方的註解 |
note over A, C: text |
從 A 橫跨到 C 的註解 |
note left of A: text |
位於 A 左側的註解 |
note right of A: text |
位於 A 右側的註解 |
== Later that day == |
橫貫所有列的分隔線 |