Flowcharts: classDef styling
简介 / Introduction
Once a flowchart has more than a couple of branches, the “happy path” and the “failure path” start to look identical, and readers have to read every label to tell them apart. Coloring the nodes is the fastest fix. Mermaid offers a declarative classDef syntax; PlantUML combines a <style> block with skinparam. The result is the same picture, but the syntax is not. This article renders the same “validate parameters” flow in both engines.
PlantUML 版
1 | @startuml |
Key syntax notes:
<style>block — a declarative style sheet.activityis the selector;element,node,classand others work too.BackgroundColor/BorderColor/FontColor/ArrowColor— the property names the style sheet accepts, with hex color values.;<<#DDF3E0>>— append<<#RRGGBB>>at the end of an action statement to color that one node (it must come after the;; putting it before triggers a “syntax is deprecated” warning).- To color a whole element class at once,
skinparam activityBackgroundColor #F5F5F5also works, but it applies to every activity in the diagram.
PlantUML has no “define a named style, then attach it” mechanism like classDef. Styling goes either through the global <style> block or through global skinparam values; per-node overrides are done with the <<#COLOR>> suffix.
Mermaid 版
1 | flowchart TD |
Key syntax notes:
classDef <name> <properties>— defines a named style; properties are space-separated and values are comma-separated.fill/stroke— background color and border color.color— text color;stroke-width— border thickness.class <node list> <style name>— attaches a style to nodes.class C,R okgives both C and R theokstyle.style C fill:#DDF3E0colors a single node directly, butclassDefis less repetitive when the same style is reused.
对比 / Side-by-side
| Meaning | PlantUML | Mermaid |
|---|---|---|
| Declare a style sheet | <style> activity { BackgroundColor #DDF3E0 } </style> |
classDef ok fill:#DDF3E0 |
| Apply a style to elements | none; use the <<#DDF3E0>> suffix per node |
class C,R ok |
| Element type selector | activity / element / node / class |
none; a classDef applies to any node |
| Global uniform palette | skinparam activityBackgroundColor #F5F5F5 |
classDef plus a batched class |
| Color property names | BackgroundColor / BorderColor / FontColor |
fill / stroke / color |
| Stroke thickness | extra properties inside the <style> block |
stroke-width:1px inline in classDef |
小结 / Wrap-up
Mermaid’s classDef is a “name it once, reference it everywhere” declarative model, which suits defining several semantic palettes and reusing them across a diagram. PlantUML goes with “global style sheet plus per-node overrides”: the <style> block sets the baseline and the <<#RRGGBB>> suffix highlights individual nodes. Both produce identical SVG output in the end, so the choice comes down to which mental model you prefer — Mermaid feels like CSS, PlantUML feels like a config file.
- Title: Flowcharts: classDef styling
- Author: puml.online
- Created at : 2026-11-10 01:00:00
- Updated at : 2026-11-26 01:07:01
- Link: https://puml.online/blog/flowchart-styled-classes-en/
- License: This work is licensed under CC BY-NC-SA 4.0.