N
NJHTools

UML Class Diagram Online

Describe classes, their members and relationships in Mermaid text and get a UML class diagram with live preview and SVG or PNG export. Free, no signup, and it runs in your browser.

Zoom
100%
Export
Mermaid code25 lines

Tab inserts spaces. Press Esc, then Tab, to move focus out. Autosaved in this browser.

PreviewLoading Mermaid…

Rendering…

Example class diagram code

This is the Mermaid source loaded in the editor above. Copy it into a Markdown file inside a ```mermaid block and GitHub, GitLab, Notion or Obsidian will render it.

classDiagram
    direction LR
    class Animal {
        <<abstract>>
        +String name
        +int age
        +makeSound()* void
        +isAdult() bool
    }
    class Dog {
        +String breed
        +fetch() void
    }
    class Cat {
        -int lives
        +purr() void
    }
    class Owner {
        +String name
        +adopt(Animal a) void
    }

    Animal <|-- Dog
    Animal <|-- Cat
    Owner "1" --> "0..*" Animal : owns

Class diagram syntax cheat sheet

SyntaxWhat it does
classDiagramStart a UML class diagram.
class Name { +field; +method() }Declare a class with members. Visibility: + public, - private, # protected, ~ package.
method()* / field$Trailing * marks abstract, $ marks static.
<<interface>>Annotation inside a class: interface, abstract, enumeration, service.
A <|-- BInheritance (B extends A). *-- composition, o-- aggregation, --> association, ..> dependency, ..|> realization.
A "1" --> "*" B : labelRelationship with cardinality on each end and a label.
direction LRLay the diagram out left to right.

How to make a Mermaid class diagram

  1. 1Start the code with classDiagram.
  2. 2Define classes with members inside braces.
  3. 3Mark visibility with +, -, # or ~.
  4. 4Add relationships such as Animal <|-- Dog.
  5. 5Export as SVG or PNG, or copy a share link.

Classes and members

Write class Order { +String id +List~Item~ items +total() Decimal } with one member per line inside the braces. Members with parentheses are methods, and the type after the parentheses is the return type.

Prefix members with + for public, - for private, # for protected and ~ for package or internal. Generics use tildes, as in List~Item~, because angle brackets are reserved.

Relationship arrows

<|-- is inheritance, *-- composition, o-- aggregation, --> association, ..> dependency and ..|> realization (implementing an interface). Add a label after a colon: Customer --> Order : places.

Put multiplicity in quotes on either side: Customer "1" --> "*" Order.

Annotations

Mark special classes with <<interface>>, <<abstract>>, <<enumeration>> or <<service>>, either inside the class body or as <<interface>> Shape on its own line.

Keep diagrams focused: show the classes relevant to one feature rather than the whole codebase.

Frequently Asked Questions

How do I show inheritance in a Mermaid class diagram?↓

Use <|-- with the parent on the arrowhead side: Animal <|-- Dog means Dog extends Animal.

How do I write generic types?↓

Use tildes instead of angle brackets, for example List~String~ or Map~K,V~.

What is the difference between composition and aggregation?↓

Composition (*--) means the part cannot exist without the whole; aggregation (o--) means the part can exist independently.

Will this diagram render on GitHub, GitLab or Notion?↓

Yes, all three render Mermaid. On GitHub and GitLab, put the code in a fenced code block that starts with ```mermaid. In Notion, add a code block and set its language to Mermaid. Hosted platforms may run an older Mermaid version, so very new syntax can fail there.

How do I export the diagram as PNG or SVG?↓

Use the export buttons above the preview. SVG stays sharp at any size and suits docs and slides; PNG is a raster image that works anywhere images are accepted. Both are created in your browser.

How does sharing work, and is my diagram private?↓

The share link stores your diagram code in the URL hash, the part after #, which browsers do not send to servers. Nothing is uploaded, and your work is autosaved in your own browser. Anyone with the link can see the diagram, so share it only with people you trust.

Last updated: