Diagrams / Mermaid Class Diagram: Syntax & Examples
Mermaid Class Diagram: Syntax & Examples
Learn Mermaid class diagram syntax with attributes, methods and associations. Compare relationship types and edit a working example in your browser.
When to use Class Diagram
A Mermaid class diagram describes types, members, and associations in a software model. Use it to explain a design decision or the relationships in a small domain. Select the classes relevant to that question instead of exporting every implementation detail into one unreadable image.
Read the Class Diagram example
Diagram source
classDiagram
class Diagram {
+String code
+String type
+render()
}
class Exporter {
+toPNG()
+toSVG()
+toPDF()
}
Diagram --> Exporter : usesHow to use this tool
- Start with the example in the editor and identify the elements that answer your question.
- Replace the sample labels and values, previewing after each structural change.
- Review the diagram at its intended reading size, then keep the source and export the format your document accepts.
Syntax and interpretation
| Concept | How to apply it |
|---|---|
| Members | Write fields and operations inside a class block. Visibility prefixes distinguish public and private members. |
| Relationships | Inheritance and composition carry stronger meaning than a general association. Choose the symbol that matches the design. |
| Multiplicity | Endpoint multiplicities explain how many instances participate. Check both ends rather than assuming a single arrow captures the full rule. |
Common questions
Is a class diagram the same as an ER diagram?
No. A class model can include behavior and inheritance; an ER model focuses on entities, attributes, and data relationships. Choose the view that matches the discussion.