mermaid: erDiagram styling does not seem to work
erDiagrams are supposed to supposed two styling elements: color and stroke but documentation does not provide any examples of how to use these. I’ve tried to use the following ways to apply styling in mermaide.live:
erDiagram
CUSTOMER }|..|{ DELIVERY-ADDRESS : has
classDef myclass fill:#f9f
class CUSTOMER myclass
erDiagram
CUSTOMER }|..|{ DELIVERY-ADDRESS : has
style CUSTOMER fill:#f9f
I would expect that application of fill #f9f changes filling of CUSTOMER pink, but in botj cases the selected data entity remains black with blue edges. Use of indentation in the markdown does not seem to have any effect either.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 29
- Comments: 16 (2 by maintainers)
For the Notion users out there here’s an example:
I really need per entity background fill. The docs telling me it’s possible is the ultimate fu. 😄
For anyone left wondering how to apply styles to individual attributes of the erDiagram on the live editor, here is a simple example.
Code:
Config:
this thread is about the ability to style each element separately (I guess), so that e.g. CUSTOMER entity can have a different color/fill than DELIVERY-ADDRESS
this init can change only the global style for all entities
I didn’t find any mention of
stroke
,fill
or anything similar in the parser https://github.com/mermaid-js/mermaid/tree/develop/packages/mermaid/src/diagrams/er/parser , so I doubt this is doable now, although the doc clearly says it’s possibleThank you. We use mermaid in Notion, where it supports the syntax, but not custom CSS. So to control color and fill, we’d need a support directly in mermaid markup.
Thanks, everyone for your input. The documentation for styling ER Diagrams is a bit confusing and we will work on making it clearer.
The two style attributes:
fill
andcolor
can be used on the followingCSS Class Selectors
forER Diagrams
:To apply a
fill
orstroke
to aCSS Class Selector
:To apply a
fill
orstroke
to aspecific entity
:In the example above, “CUSTOMER” refers to the
NAME
value of the entity.Currently, these three
CSS Class Selectors
require a customid
in yourhtml
:(Will look into removing this as a requirement.)
Here is a CodePen example. It’s not the prettiest ER Diagram 😅, but hopefully, it gives you a better idea of how to apply styling to ER Diagrams.
ER Diagrams Documentation
Also, a quick reminder to set your theme to base as it is the only modifiable theme (currently).
@AnilRh Thanks for the code, but it’s not specific to notion:
I use vscode to create my ER diagrams using mermaid. Can you please provide a code example of how to use the css styling rather than in the mermaid live editor?