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 : uses
Diagram depends on Exporter. The fields describe data and the methods describe operations. The model is a design summary, not a guarantee that the current code implements every displayed member.

How to use this tool

  1. Start with the example in the editor and identify the elements that answer your question.
  2. Replace the sample labels and values, previewing after each structural change.
  3. Review the diagram at its intended reading size, then keep the source and export the format your document accepts.

Syntax and interpretation

ConceptHow to apply it
MembersWrite fields and operations inside a class block. Visibility prefixes distinguish public and private members.
RelationshipsInheritance and composition carry stronger meaning than a general association. Choose the symbol that matches the design.
MultiplicityEndpoint 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.