Class Diagram Online Editor

Draw UML class diagrams with Mermaid online: attributes, methods, visibility, inheritance, composition and interfaces, with live preview and free image export.

Try it

Edit the code; the preview updates as you type.

Open in editor

Rendering diagram…

What is a class diagram?

A UML class diagram shows the classes in a system, the data and methods each one has, and how they relate through inheritance, composition, aggregation and association.

In Mermaid every class diagram starts with classDiagram. Members are listed inside braces with a visibility prefix, and relationships are short arrows between class names.

When to use it

  • Designing an object model before you write the code
  • Documenting interfaces and their implementations
  • Explaining a design pattern such as strategy or observer
  • Onboarding developers to an unfamiliar codebase
  • UML coursework and exam preparation

Mermaid class diagram syntax

Every diagram of this type starts with classDiagram.

SyntaxMeaning
class Name { }Declares a class; members go inside the braces, one per line.
+ - # ~Visibility: public, private, protected and package or internal.
+method(arg) ReturnTypeA method; the return type follows the closing parenthesis.
A <|-- BInheritance: B extends A.
A <|.. BRealization: B implements interface A.
A *-- BComposition: B cannot exist without A.
A o-- BAggregation: A holds B, but B can exist on its own.
A --> B / A ..> BAssociation and dependency.
A "1" --> "*" BCardinality labels on either end of a relationship.
List~T~Generic types use tildes instead of angle brackets.
<<interface>>An annotation such as interface, abstract or enumeration.

More examples

Inheritance with an abstract base class

Rendering diagram…
Mermaid code
classDiagram
  class Shape {
    <<abstract>>
    +area()* double
    +count$ int
  }
  Shape <|-- Circle
  Shape <|-- Rectangle
  class Circle {
    +double radius
  }
  class Rectangle {
    +double width
    +double height
  }
Add $ after a member for static and * for abstract.

Common mistakes and how to fix them

Generics are written with angle brackets, such as List<String>.
Use tildes: List~String~.
A class name contains spaces or a dot.
Use a single identifier, or give it a label: class Order["Customer order"].
The arrow points the wrong way for inheritance.
The triangle sits next to the parent: Parent <|-- Child.

Export your class diagram

Download a PNG, SVG or PDF straight from the playground above. For more options, such as a 1x to 4x scale, a transparent background or copying the image, choose Open in editor and use the Export menu there. Export is free, needs no account and adds no watermark.

Frequently asked questions

How do I show inheritance in a Mermaid class diagram?

Write Parent <|-- Child. The hollow triangle is drawn next to the parent class. Use <|.. when a class implements an interface.

What is the difference between composition and aggregation?

Composition (*--) means the part cannot exist without the whole, like an order and its line items. Aggregation (o--) means the part can exist on its own, like a team and its players.

Can I mark a class as an interface or abstract class?

Yes. Put an annotation such as <<interface>> or <<abstract>> on the first line inside the class block.

Can I export the class diagram for a report?

Yes. Export a high-resolution PNG for documents and slides, an SVG for lossless scaling, or a PDF for printing. All exports are free.