Class Nodes

Basic Class

          classDiagram
          class Duck {
            +String beakColor
            +swim()
            +quack()
          }
        

Complex Class

                classDiagram
                class Square~Shape~{
                  int id
                  List~int~ position
                  setPoints(List~int~ points)
                  getPoints() List~int~
                }
          
          Square : -List~string~ messages
          Square : +setMessages(List~string~ messages)
          Square : +getMessages() List~string~
          Square : +getDistanceMatrix() List~List~int~~
              

No Attributes

          classDiagram
          class Duck {
            +swim()
            +quack()
          }
        

No Methods

          classDiagram
          class Duck {
            +String beakColor
          }
        

Only Class Name

Empty line as attribute

          classDiagram
          class Duck {
            
          }
        

Visibility and Types

(Further tilde testing)

classDiagram class Duck { ~interface~~~ +String beakColor #swim() ~quack()~~~ -test()~~~~~~~ +deposit(amount) bool }

Additional Classifiers

(* Abstract | $ Static)

classDiagram class Square~Shape~{ int id* List~int~ position* setPoints(List~int~ points)* getPoints()* List~int~ } Square : -List~string~ messages* Square : +setMessages(List~string~ messages)* Square : +getMessages()$ List~string~ Square : +getDistanceMatrix() List~List~int~~ int$

Label

          classDiagram
          class Animal~test~["Animal with a label"]
        

Link

          classDiagram
          class Shape
          link Shape "https://www.github.com" "This is a tooltip for a link"
        

Click

          classDiagram
          class Shape
          click Shape href "https://www.github.com" "This is a tooltip for a link"
        

Neutral Theme

          ---
          config:
            theme: neutral
          ---
          classDiagram
          class Duck {
            +String beakColor
            +swim()
            +quack()
          }
        

Dark Theme

          ---
          config:
            theme: dark
          ---
          classDiagram
          class Duck {
            +String beakColor
            +swim()
            +quack()
          }
        

Forest Theme

          ---
          config:
            theme: forest
          ---
          classDiagram
          class Duck {
            +String beakColor
            +swim()
            +quack()
          }
        

Base Theme

          ---
          config:
            theme: base
          ---
          classDiagram
          class Duck {
            +String beakColor
            +swim()
            +quack()
          }
        

Custom Theme

          %%{
            init: {
              'theme': 'base',
              'themeVariables': {
                'primaryColor': '#BB2528',
                'primaryTextColor': '#fff',
                'primaryBorderColor': '#7C0000',
                'lineColor': '#F8B229',
                'secondaryColor': '#006100',
                'tertiaryColor': '#fff'
              }
            }
          }%%
          classDiagram
          class Duck {
            +String beakColor
            +swim()
            +quack()
          }
        

Styling within Diagram

          classDiagram
          class Duck {
            +String beakColor
            +swim()
            +quack()
          }
          style Duck fill:#f9f,stroke:#333,stroke-width:8px
        

Styling with Class

          classDiagram
          class Duck {
            +String beakColor
            +swim()
            +quack()
          }
          class Duck:::styleClass
        

Diagram Testing

Class Nodes Only

          ---
          title: Animal example
          ---
          classDiagram
              Animal : +int age
              Animal : +String gender
              Animal: +isMammal()
              Animal: +mate()
              class Duck{
                  +String beakColor
                  +swim()
                  +quack()
              }
              class Fish{
                  -int sizeInFeet
                  -canEat()
              }
              class Zebra{
                  +bool is_wild
                  +run()
              }
        

Class Nodes LR

          ---
          title: Animal example
          ---
          classDiagram
              direction LR
              Animal : +int age
              Animal : +String gender
              Animal: +isMammal()
              Animal: +mate()
              class Duck{
                  +String beakColor
                  +swim()
                  +quack()
              }
              class Fish{
                  -int sizeInFeet
                  -canEat()
              }
              class Zebra{
                  +bool is_wild
                  +run()
              }