collab/mermaid/docs/syntax/entityRelationshipDiagram.mdblame
View source
6dd74de1> **Warning**
6dd74de2>
6dd74de3> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
6dd74de4>
6dd74de5> ## Please edit the corresponding file in [/packages/mermaid/src/docs/syntax/entityRelationshipDiagram.md](../../packages/mermaid/src/docs/syntax/entityRelationshipDiagram.md).
6dd74de6
6dd74de7# Entity Relationship Diagrams
6dd74de8
6dd74de9> An entity–relationship model (or ER model) describes interrelated things of interest in a specific domain of knowledge. A basic ER model is composed of entity types (which classify the things of interest) and specifies relationships that can exist between entities (instances of those entity types) [Wikipedia](https://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model).
6dd74de10
6dd74de11Note that practitioners of ER modelling almost always refer to _entity types_ simply as _entities_. For example the `CUSTOMER` entity _type_ would be referred to simply as the `CUSTOMER` entity. This is so common it would be inadvisable to do anything else, but technically an entity is an abstract _instance_ of an entity type, and this is what an ER diagram shows - abstract instances, and the relationships between them. This is why entities are always named using singular nouns.
6dd74de12
6dd74de13Mermaid can render ER diagrams
6dd74de14
6dd74de15```mermaid-example
6dd74de16---
6dd74de17title: Order example
6dd74de18---
6dd74de19erDiagram
6dd74de20 CUSTOMER ||--o{ ORDER : places
6dd74de21 ORDER ||--|{ LINE-ITEM : contains
6dd74de22 CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
6dd74de23```
6dd74de24
6dd74de25```mermaid
6dd74de26---
6dd74de27title: Order example
6dd74de28---
6dd74de29erDiagram
6dd74de30 CUSTOMER ||--o{ ORDER : places
6dd74de31 ORDER ||--|{ LINE-ITEM : contains
6dd74de32 CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
6dd74de33```
6dd74de34
6dd74de35Entity names are often capitalised, although there is no accepted standard on this, and it is not required in Mermaid.
6dd74de36
6dd74de37Relationships between entities are represented by lines with end markers representing cardinality. Mermaid uses the most popular crow's foot notation. The crow's foot intuitively conveys the possibility of many instances of the entity that it connects to.
6dd74de38
6dd74de39ER diagrams can be used for various purposes, ranging from abstract logical models devoid of any implementation details, through to physical models of relational database tables. It can be useful to include attribute definitions on ER diagrams to aid comprehension of the purpose and meaning of entities. These do not necessarily need to be exhaustive; often a small subset of attributes is enough. Mermaid allows them to be defined in terms of their _type_ and _name_.
6dd74de40
6dd74de41```mermaid-example
6dd74de42erDiagram
6dd74de43 CUSTOMER ||--o{ ORDER : places
6dd74de44 CUSTOMER {
6dd74de45 string name
6dd74de46 string custNumber
6dd74de47 string sector
6dd74de48 }
6dd74de49 ORDER ||--|{ LINE-ITEM : contains
6dd74de50 ORDER {
6dd74de51 int orderNumber
6dd74de52 string deliveryAddress
6dd74de53 }
6dd74de54 LINE-ITEM {
6dd74de55 string productCode
6dd74de56 int quantity
6dd74de57 float pricePerUnit
6dd74de58 }
6dd74de59```
6dd74de60
6dd74de61```mermaid
6dd74de62erDiagram
6dd74de63 CUSTOMER ||--o{ ORDER : places
6dd74de64 CUSTOMER {
6dd74de65 string name
6dd74de66 string custNumber
6dd74de67 string sector
6dd74de68 }
6dd74de69 ORDER ||--|{ LINE-ITEM : contains
6dd74de70 ORDER {
6dd74de71 int orderNumber
6dd74de72 string deliveryAddress
6dd74de73 }
6dd74de74 LINE-ITEM {
6dd74de75 string productCode
6dd74de76 int quantity
6dd74de77 float pricePerUnit
6dd74de78 }
6dd74de79```
6dd74de80
6dd74de81When including attributes on ER diagrams, you must decide whether to include foreign keys as attributes. This probably depends on how closely you are trying to represent relational table structures. If your diagram is a _logical_ model which is not meant to imply a relational implementation, then it is better to leave these out because the associative relationships already convey the way that entities are associated. For example, a JSON data structure can implement a one-to-many relationship without the need for foreign key properties, using arrays. Similarly an object-oriented programming language may use pointers or references to collections. Even for models that are intended for relational implementation, you might decide that inclusion of foreign key attributes duplicates information already portrayed by the relationships, and does not add meaning to entities. Ultimately, it's your choice.
6dd74de82
6dd74de83## Syntax
6dd74de84
6dd74de85### Entities and Relationships
6dd74de86
6dd74de87Mermaid syntax for ER diagrams is compatible with PlantUML, with an extension to label the relationship. Each statement consists of the following parts:
6dd74de88
6dd74de89```
6dd74de90 <first-entity> [<relationship> <second-entity> : <relationship-label>]
6dd74de91```
6dd74de92
6dd74de93Where:
6dd74de94
6dd74de95- `first-entity` is the name of an entity. Names support any unicode characters and can include spaces if surrounded by double quotes (e.g. "name with space").
6dd74de96- `relationship` describes the way that both entities inter-relate. See below.
6dd74de97- `second-entity` is the name of the other entity.
6dd74de98- `relationship-label` describes the relationship from the perspective of the first entity.
6dd74de99
6dd74de100For example:
6dd74de101
6dd74de102```
6dd74de103 PROPERTY ||--|{ ROOM : contains
6dd74de104```
6dd74de105
6dd74de106This statement can be read as _a property contains one or more rooms, and a room is part of one and only one property_. You can see that the label here is from the first entity's perspective: a property contains a room, but a room does not contain a property. When considered from the perspective of the second entity, the equivalent label is usually very easy to infer. (Some ER diagrams label relationships from both perspectives, but this is not supported here, and is usually superfluous).
6dd74de107
6dd74de108Only the `first-entity` part of a statement is mandatory. This makes it possible to show an entity with no relationships, which can be useful during iterative construction of diagrams. If any other parts of a statement are specified, then all parts are mandatory.
6dd74de109
6dd74de110#### Unicode text
6dd74de111
6dd74de112Entity names, relationships, and attributes all support unicode text.
6dd74de113
6dd74de114```mermaid-example
6dd74de115erDiagram
6dd74de116 "This ❤ Unicode"
6dd74de117```
6dd74de118
6dd74de119```mermaid
6dd74de120erDiagram
6dd74de121 "This ❤ Unicode"
6dd74de122```
6dd74de123
6dd74de124#### Markdown formatting
6dd74de125
6dd74de126Markdown formatting and text is also supported.
6dd74de127
6dd74de128```mermaid-example
6dd74de129erDiagram
6dd74de130 "This **is** _Markdown_"
6dd74de131```
6dd74de132
6dd74de133```mermaid
6dd74de134erDiagram
6dd74de135 "This **is** _Markdown_"
6dd74de136```
6dd74de137
6dd74de138### Relationship Syntax
6dd74de139
6dd74de140The `relationship` part of each statement can be broken down into three sub-components:
6dd74de141
6dd74de142- the cardinality of the first entity with respect to the second
6dd74de143- whether the relationship confers identity on a 'child' entity
6dd74de144- the cardinality of the second entity with respect to the first
6dd74de145
6dd74de146Cardinality is a property that describes how many elements of another entity can be related to the entity in question. In the above example a `PROPERTY` can have one or more `ROOM` instances associated to it, whereas a `ROOM` can only be associated with one `PROPERTY`. In each cardinality marker there are two characters. The outermost character represents a maximum value, and the innermost character represents a minimum value. The table below summarises possible cardinalities.
6dd74de147
6dd74de148| Value (left) | Value (right) | Meaning |
6dd74de149| :----------: | :-----------: | ----------------------------- |
6dd74de150| `\|o` | `o\|` | Zero or one |
6dd74de151| `\|\|` | `\|\|` | Exactly one |
6dd74de152| `}o` | `o{` | Zero or more (no upper limit) |
6dd74de153| `}\|` | `\|{` | One or more (no upper limit) |
6dd74de154
6dd74de155**Aliases**
6dd74de156
6dd74de157| Value (left) | Value (right) | Alias for |
6dd74de158| :----------: | :-----------: | ------------ |
6dd74de159| one or zero | one or zero | Zero or one |
6dd74de160| zero or one | zero or one | Zero or one |
6dd74de161| one or more | one or more | One or more |
6dd74de162| one or many | one or many | One or more |
6dd74de163| many(1) | many(1) | One or more |
6dd74de164| 1+ | 1+ | One or more |
6dd74de165| zero or more | zero or more | Zero or more |
6dd74de166| zero or many | zero or many | Zero or more |
6dd74de167| many(0) | many(0) | Zero or more |
6dd74de168| 0+ | 0+ | Zero or more |
6dd74de169| only one | only one | Exactly one |
6dd74de170| 1 | 1 | Exactly one |
6dd74de171
6dd74de172### Identification
6dd74de173
6dd74de174Relationships may be classified as either _identifying_ or _non-identifying_ and these are rendered with either solid or dashed lines respectively. This is relevant when one of the entities in question cannot have independent existence without the other. For example a firm that insures people to drive cars might need to store data on `NAMED-DRIVER`s. In modelling this we might start out by observing that a `CAR` can be driven by many `PERSON` instances, and a `PERSON` can drive many `CAR`s - both entities can exist without the other, so this is a non-identifying relationship that we might specify in Mermaid as: `PERSON }|..|{ CAR : "driver"`. Note the two dots in the middle of the relationship that will result in a dashed line being drawn between the two entities. But when this many-to-many relationship is resolved into two one-to-many relationships, we observe that a `NAMED-DRIVER` cannot exist without both a `PERSON` and a `CAR` - the relationships become identifying and would be specified using hyphens, which translate to a solid line:
6dd74de175
6dd74de176| Value | Alias for |
6dd74de177| :---: | :---------------: |
6dd74de178| -- | _identifying_ |
6dd74de179| .. | _non-identifying_ |
6dd74de180
6dd74de181**Aliases**
6dd74de182
6dd74de183| Value | Alias for |
6dd74de184| :-----------: | :---------------: |
6dd74de185| to | _identifying_ |
6dd74de186| optionally to | _non-identifying_ |
6dd74de187
6dd74de188```mermaid-example
6dd74de189erDiagram
6dd74de190 CAR ||--o{ NAMED-DRIVER : allows
6dd74de191 PERSON }o..o{ NAMED-DRIVER : is
6dd74de192```
6dd74de193
6dd74de194```mermaid
6dd74de195erDiagram
6dd74de196 CAR ||--o{ NAMED-DRIVER : allows
6dd74de197 PERSON }o..o{ NAMED-DRIVER : is
6dd74de198```
6dd74de199
6dd74de200```mermaid-example
6dd74de201erDiagram
6dd74de202 CAR 1 to zero or more NAMED-DRIVER : allows
6dd74de203 PERSON many(0) optionally to 0+ NAMED-DRIVER : is
6dd74de204```
6dd74de205
6dd74de206```mermaid
6dd74de207erDiagram
6dd74de208 CAR 1 to zero or more NAMED-DRIVER : allows
6dd74de209 PERSON many(0) optionally to 0+ NAMED-DRIVER : is
6dd74de210```
6dd74de211
6dd74de212### Attributes
6dd74de213
6dd74de214Attributes can be defined for entities by specifying the entity name followed by a block containing multiple `type name` pairs, where a block is delimited by an opening `{` and a closing `}`. The attributes are rendered inside the entity boxes. For example:
6dd74de215
6dd74de216```mermaid-example
6dd74de217erDiagram
6dd74de218 CAR ||--o{ NAMED-DRIVER : allows
6dd74de219 CAR {
6dd74de220 string registrationNumber
6dd74de221 string make
6dd74de222 string model
6dd74de223 }
6dd74de224 PERSON ||--o{ NAMED-DRIVER : is
6dd74de225 PERSON {
6dd74de226 string firstName
6dd74de227 string lastName
6dd74de228 int age
6dd74de229 }
6dd74de230```
6dd74de231
6dd74de232```mermaid
6dd74de233erDiagram
6dd74de234 CAR ||--o{ NAMED-DRIVER : allows
6dd74de235 CAR {
6dd74de236 string registrationNumber
6dd74de237 string make
6dd74de238 string model
6dd74de239 }
6dd74de240 PERSON ||--o{ NAMED-DRIVER : is
6dd74de241 PERSON {
6dd74de242 string firstName
6dd74de243 string lastName
6dd74de244 int age
6dd74de245 }
6dd74de246```
6dd74de247
6dd74de248The `type` values must begin with an alphabetic character and may contain digits, hyphens, underscores, parentheses and square brackets. The `name` values follow a similar format to `type`, but may start with an asterisk as another option to indicate an attribute is a primary key. Other than that, there are no restrictions, and there is no implicit set of valid data types.
6dd74de249
6dd74de250### Entity Name Aliases
6dd74de251
6dd74de252An alias can be added to an entity using square brackets. If provided, the alias will be showed in the diagram instead of the entity name. Alias names follow all of the same rules as entity names.
6dd74de253
6dd74de254```mermaid-example
6dd74de255erDiagram
6dd74de256 p[Person] {
6dd74de257 string firstName
6dd74de258 string lastName
6dd74de259 }
6dd74de260 a["Customer Account"] {
6dd74de261 string email
6dd74de262 }
6dd74de263 p ||--o| a : has
6dd74de264```
6dd74de265
6dd74de266```mermaid
6dd74de267erDiagram
6dd74de268 p[Person] {
6dd74de269 string firstName
6dd74de270 string lastName
6dd74de271 }
6dd74de272 a["Customer Account"] {
6dd74de273 string email
6dd74de274 }
6dd74de275 p ||--o| a : has
6dd74de276```
6dd74de277
6dd74de278#### Attribute Keys and Comments
6dd74de279
6dd74de280Attributes may also have a `key` or comment defined. Keys can be `PK`, `FK` or `UK`, for Primary Key, Foreign Key or Unique Key (markdown formatting and unicode is not supported for keys). To specify multiple key constraints on a single attribute, separate them with a comma (e.g., `PK, FK`). A `comment` is defined by double quotes at the end of an attribute. Comments themselves cannot have double-quote characters in them.
6dd74de281
6dd74de282```mermaid-example
6dd74de283erDiagram
6dd74de284 CAR ||--o{ NAMED-DRIVER : allows
6dd74de285 CAR {
6dd74de286 string registrationNumber PK
6dd74de287 string make
6dd74de288 string model
6dd74de289 string[] parts
6dd74de290 }
6dd74de291 PERSON ||--o{ NAMED-DRIVER : is
6dd74de292 PERSON {
6dd74de293 string driversLicense PK "The license #"
6dd74de294 string(99) firstName "Only 99 characters are allowed"
6dd74de295 string lastName
6dd74de296 string phone UK
6dd74de297 int age
6dd74de298 }
6dd74de299 NAMED-DRIVER {
6dd74de300 string carRegistrationNumber PK, FK
6dd74de301 string driverLicence PK, FK
6dd74de302 }
6dd74de303 MANUFACTURER only one to zero or more CAR : makes
6dd74de304```
6dd74de305
6dd74de306```mermaid
6dd74de307erDiagram
6dd74de308 CAR ||--o{ NAMED-DRIVER : allows
6dd74de309 CAR {
6dd74de310 string registrationNumber PK
6dd74de311 string make
6dd74de312 string model
6dd74de313 string[] parts
6dd74de314 }
6dd74de315 PERSON ||--o{ NAMED-DRIVER : is
6dd74de316 PERSON {
6dd74de317 string driversLicense PK "The license #"
6dd74de318 string(99) firstName "Only 99 characters are allowed"
6dd74de319 string lastName
6dd74de320 string phone UK
6dd74de321 int age
6dd74de322 }
6dd74de323 NAMED-DRIVER {
6dd74de324 string carRegistrationNumber PK, FK
6dd74de325 string driverLicence PK, FK
6dd74de326 }
6dd74de327 MANUFACTURER only one to zero or more CAR : makes
6dd74de328```
6dd74de329
6dd74de330### Direction
6dd74de331
6dd74de332The direction statement declares the direction of the diagram.
6dd74de333
6dd74de334This declares that the diagram is oriented from top to bottom (`TB`). This can be reversed to be oriented from bottom to top (`BT`).
6dd74de335
6dd74de336```mermaid-example
6dd74de337erDiagram
6dd74de338 direction TB
6dd74de339 CUSTOMER ||--o{ ORDER : places
6dd74de340 CUSTOMER {
6dd74de341 string name
6dd74de342 string custNumber
6dd74de343 string sector
6dd74de344 }
6dd74de345 ORDER ||--|{ LINE-ITEM : contains
6dd74de346 ORDER {
6dd74de347 int orderNumber
6dd74de348 string deliveryAddress
6dd74de349 }
6dd74de350 LINE-ITEM {
6dd74de351 string productCode
6dd74de352 int quantity
6dd74de353 float pricePerUnit
6dd74de354 }
6dd74de355```
6dd74de356
6dd74de357```mermaid
6dd74de358erDiagram
6dd74de359 direction TB
6dd74de360 CUSTOMER ||--o{ ORDER : places
6dd74de361 CUSTOMER {
6dd74de362 string name
6dd74de363 string custNumber
6dd74de364 string sector
6dd74de365 }
6dd74de366 ORDER ||--|{ LINE-ITEM : contains
6dd74de367 ORDER {
6dd74de368 int orderNumber
6dd74de369 string deliveryAddress
6dd74de370 }
6dd74de371 LINE-ITEM {
6dd74de372 string productCode
6dd74de373 int quantity
6dd74de374 float pricePerUnit
6dd74de375 }
6dd74de376```
6dd74de377
6dd74de378This declares that the diagram is oriented from left to right (`LR`). This can be reversed to be oriented from right to left (`RL`).
6dd74de379
6dd74de380```mermaid-example
6dd74de381erDiagram
6dd74de382 direction LR
6dd74de383 CUSTOMER ||--o{ ORDER : places
6dd74de384 CUSTOMER {
6dd74de385 string name
6dd74de386 string custNumber
6dd74de387 string sector
6dd74de388 }
6dd74de389 ORDER ||--|{ LINE-ITEM : contains
6dd74de390 ORDER {
6dd74de391 int orderNumber
6dd74de392 string deliveryAddress
6dd74de393 }
6dd74de394 LINE-ITEM {
6dd74de395 string productCode
6dd74de396 int quantity
6dd74de397 float pricePerUnit
6dd74de398 }
6dd74de399```
6dd74de400
6dd74de401```mermaid
6dd74de402erDiagram
6dd74de403 direction LR
6dd74de404 CUSTOMER ||--o{ ORDER : places
6dd74de405 CUSTOMER {
6dd74de406 string name
6dd74de407 string custNumber
6dd74de408 string sector
6dd74de409 }
6dd74de410 ORDER ||--|{ LINE-ITEM : contains
6dd74de411 ORDER {
6dd74de412 int orderNumber
6dd74de413 string deliveryAddress
6dd74de414 }
6dd74de415 LINE-ITEM {
6dd74de416 string productCode
6dd74de417 int quantity
6dd74de418 float pricePerUnit
6dd74de419 }
6dd74de420```
6dd74de421
6dd74de422Possible diagram orientations are:
6dd74de423
6dd74de424- TB - Top to bottom
6dd74de425- BT - Bottom to top
6dd74de426- RL - Right to left
6dd74de427- LR - Left to right
6dd74de428
6dd74de429### Styling a node
6dd74de430
6dd74de431It is possible to apply specific styles such as a thicker border or a different background color to a node.
6dd74de432
6dd74de433```mermaid-example
6dd74de434erDiagram
6dd74de435 id1||--||id2 : label
6dd74de436 style id1 fill:#f9f,stroke:#333,stroke-width:4px
6dd74de437 style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
6dd74de438```
6dd74de439
6dd74de440```mermaid
6dd74de441erDiagram
6dd74de442 id1||--||id2 : label
6dd74de443 style id1 fill:#f9f,stroke:#333,stroke-width:4px
6dd74de444 style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
6dd74de445```
6dd74de446
6dd74de447It is also possible to attach styles to a list of nodes in one statement:
6dd74de448
6dd74de449```
6dd74de450 style nodeId1,nodeId2 styleList
6dd74de451```
6dd74de452
6dd74de453#### Classes
6dd74de454
6dd74de455More convenient than defining the style every time is to define a class of styles and attach this class to the nodes that
6dd74de456should have a different look.
6dd74de457
6dd74de458A class definition looks like the example below:
6dd74de459
6dd74de460```
6dd74de461 classDef className fill:#f9f,stroke:#333,stroke-width:4px
6dd74de462```
6dd74de463
6dd74de464It is also possible to define multiple classes in one statement:
6dd74de465
6dd74de466```
6dd74de467 classDef firstClassName,secondClassName font-size:12pt
6dd74de468```
6dd74de469
6dd74de470Attachment of a class to a node is done as per below:
6dd74de471
6dd74de472```
6dd74de473 class nodeId1 className
6dd74de474```
6dd74de475
6dd74de476It is also possible to attach a class to a list of nodes in one statement:
6dd74de477
6dd74de478```
6dd74de479 class nodeId1,nodeId2 className
6dd74de480```
6dd74de481
6dd74de482Multiple classes can be attached at the same time as well:
6dd74de483
6dd74de484```
6dd74de485 class nodeId1,nodeId2 className1,className2
6dd74de486```
6dd74de487
6dd74de488A shorter form of adding a class is to attach the classname to the node using the `:::`operator as per below:
6dd74de489
6dd74de490```mermaid-example
6dd74de491erDiagram
6dd74de492 direction TB
6dd74de493 CAR:::someclass {
6dd74de494 string registrationNumber
6dd74de495 string make
6dd74de496 string model
6dd74de497 }
6dd74de498 PERSON:::someclass {
6dd74de499 string firstName
6dd74de500 string lastName
6dd74de501 int age
6dd74de502 }
6dd74de503 HOUSE:::someclass
6dd74de504
6dd74de505 classDef someclass fill:#f96
6dd74de506```
6dd74de507
6dd74de508```mermaid
6dd74de509erDiagram
6dd74de510 direction TB
6dd74de511 CAR:::someclass {
6dd74de512 string registrationNumber
6dd74de513 string make
6dd74de514 string model
6dd74de515 }
6dd74de516 PERSON:::someclass {
6dd74de517 string firstName
6dd74de518 string lastName
6dd74de519 int age
6dd74de520 }
6dd74de521 HOUSE:::someclass
6dd74de522
6dd74de523 classDef someclass fill:#f96
6dd74de524```
6dd74de525
6dd74de526This form can be used when declaring relationships between entities:
6dd74de527
6dd74de528```mermaid-example
6dd74de529erDiagram
6dd74de530 CAR {
6dd74de531 string registrationNumber
6dd74de532 string make
6dd74de533 string model
6dd74de534 }
6dd74de535 PERSON {
6dd74de536 string firstName
6dd74de537 string lastName
6dd74de538 int age
6dd74de539 }
6dd74de540 PERSON:::foo ||--|| CAR : owns
6dd74de541 PERSON o{--|| HOUSE:::bar : has
6dd74de542
6dd74de543 classDef foo stroke:#f00
6dd74de544 classDef bar stroke:#0f0
6dd74de545 classDef foobar stroke:#00f
6dd74de546```
6dd74de547
6dd74de548```mermaid
6dd74de549erDiagram
6dd74de550 CAR {
6dd74de551 string registrationNumber
6dd74de552 string make
6dd74de553 string model
6dd74de554 }
6dd74de555 PERSON {
6dd74de556 string firstName
6dd74de557 string lastName
6dd74de558 int age
6dd74de559 }
6dd74de560 PERSON:::foo ||--|| CAR : owns
6dd74de561 PERSON o{--|| HOUSE:::bar : has
6dd74de562
6dd74de563 classDef foo stroke:#f00
6dd74de564 classDef bar stroke:#0f0
6dd74de565 classDef foobar stroke:#00f
6dd74de566```
6dd74de567
6dd74de568Similar to the class statement, the shorthand syntax can also apply multiple classes at once:
6dd74de569
6dd74de570```
6dd74de571 nodeId:::className1,className2
6dd74de572```
6dd74de573
6dd74de574### Default class
6dd74de575
6dd74de576If a class is named default it will be assigned to all classes without specific class definitions.
6dd74de577
6dd74de578```
6dd74de579 classDef default fill:#f9f,stroke:#333,stroke-width:4px;
6dd74de580```
6dd74de581
6dd74de582> **Note:** Custom styles from style or other class statements take priority and will overwrite the default styles. (e.g. The `default` class gives nodes a background color of pink but the `blue` class will give that node a background color of blue if applied.)
6dd74de583
6dd74de584```mermaid-example
6dd74de585erDiagram
6dd74de586 CAR {
6dd74de587 string registrationNumber
6dd74de588 string make
6dd74de589 string model
6dd74de590 }
6dd74de591 PERSON {
6dd74de592 string firstName
6dd74de593 string lastName
6dd74de594 int age
6dd74de595 }
6dd74de596 PERSON:::foo ||--|| CAR : owns
6dd74de597 PERSON o{--|| HOUSE:::bar : has
6dd74de598
6dd74de599 classDef default fill:#f9f,stroke-width:4px
6dd74de600 classDef foo stroke:#f00
6dd74de601 classDef bar stroke:#0f0
6dd74de602 classDef foobar stroke:#00f
6dd74de603```
6dd74de604
6dd74de605```mermaid
6dd74de606erDiagram
6dd74de607 CAR {
6dd74de608 string registrationNumber
6dd74de609 string make
6dd74de610 string model
6dd74de611 }
6dd74de612 PERSON {
6dd74de613 string firstName
6dd74de614 string lastName
6dd74de615 int age
6dd74de616 }
6dd74de617 PERSON:::foo ||--|| CAR : owns
6dd74de618 PERSON o{--|| HOUSE:::bar : has
6dd74de619
6dd74de620 classDef default fill:#f9f,stroke-width:4px
6dd74de621 classDef foo stroke:#f00
6dd74de622 classDef bar stroke:#0f0
6dd74de623 classDef foobar stroke:#00f
6dd74de624```
6dd74de625
6dd74de626## Configuration
6dd74de627
6dd74de628### Layout
6dd74de629
6dd74de630The layout of the diagram is handled by [`render()`](../config/setup/mermaid/interfaces/Mermaid.md#render). The default layout is dagre.
6dd74de631
6dd74de632For larger or more-complex diagrams, you can alternatively apply the ELK (Eclipse Layout Kernel) layout using your YAML frontmatter's `config`. For more information, see [Customizing ELK Layout](../intro/syntax-reference.md#customizing-elk-layout).
6dd74de633
6dd74de634```yaml
6dd74de635---
6dd74de636config:
6dd74de637 layout: elk
6dd74de638---
6dd74de639```
6dd74de640
6dd74de641Your Mermaid code should be similar to the following:
6dd74de642
6dd74de643```mermaid-example
6dd74de644---
6dd74de645title: Order example
6dd74de646config:
6dd74de647 layout: elk
6dd74de648---
6dd74de649erDiagram
6dd74de650 CUSTOMER ||--o{ ORDER : places
6dd74de651 ORDER ||--|{ LINE-ITEM : contains
6dd74de652 CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
6dd74de653```
6dd74de654
6dd74de655```mermaid
6dd74de656---
6dd74de657title: Order example
6dd74de658config:
6dd74de659 layout: elk
6dd74de660---
6dd74de661erDiagram
6dd74de662 CUSTOMER ||--o{ ORDER : places
6dd74de663 ORDER ||--|{ LINE-ITEM : contains
6dd74de664 CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
6dd74de665```
6dd74de666
6dd74de667> **Note**
6dd74de668> Note that the site needs to use mermaid version 9.4+ for this to work and have this featured enabled in the lazy-loading configuration.
6dd74de669
6dd74de670<!--- cspell:locale en,en-gb --->