Adjusting Mermaid mindmap colors

Hi all!

First off, big kudos to the Obsidian dev team for updating the Mermaid plugin, which now includes support for mind maps! I’ve really enjoyed using it to quickly brainstorm and visualize ideas.

I noticed that at least on my machine, the default mindmap node colors colors can sometimes make the black text hard to read. (This might be light-theme specific.) Here’s what it looks like for me:

image

Here is a CSS snippet I use to adjust the colors so that they’re more readable for me in the light theme:

/* Make mindmap colors readable */
.theme-light .mermaid {
    --color-red: #ff7777;
    --color-orange: #ffbb99;
    --color-yellow: #ffeeaa;
    --color-green: #bbffbb;
    --color-cyan: #bbffee;
    --color-blue: #aaccff;
    --color-purple: #ddbbff;
    --color-pink: #ffcccc; 
}

This is what the same diagram looks like with the snippet enabled:

image

Hope this is helpful to someone else.

Craig

2 Likes

Hi Craig,

I came across the same issue as you’ve solved here.
However the instructions listed isn’t getting me to the result.

What I tried was to add the following at the top of the markdown page in source mode:

---
/* Make mindmap colors readable */
.theme-light .mermaid {
    --color-red: #ff7777;
    --color-orange: #ffbb99;
    --color-yellow: #ffeeaa;
    --color-green: #bbffbb;
    --color-cyan: #bbffee;
    --color-blue: #aaccff;
    --color-purple: #ddbbff;
    --color-pink: #ffcccc; 
}

However, my end result is still the same (I don’t want yellow there, as with white it text doesn’t contrast well enough).

Here’s the mindmap code:


mindmap
    Root
        A[A]
        :::urgent large
        B(B)
        Cdd

Any help to get this sorted appreciated!

Hi @mzee ,

Thanks for your note. I think you have two issues to solve:

Using CSS Snippets

First, CSS snippets don’t go in the note, they are individual files in a special folder in your vault. I recommend you read the Obsidian docs on CSS files, but here’s a summary:

  1. Put the CSS code into a text file in the special directory .obsidian/snippets under your vault folder, for example /home/mzee/Vault/.obsidian/snippets/mermaid.css.
  2. Under Obsidian settings → Appearance → CSS Snippets, make sure the file you just added is selected. For example:

image

Once you’ve done that, you should see the effects of the CSS being applied.

Light Mode vs. Dark Mode

Second, the CSS snippet I pasted above is for light mode. I expect the colors will not work well in dark mode. I don’t use dark mode much myself, but you can perhaps try these instead as a starting place:

/* Make mindmap colors readable (Light mode) */
.theme-light .mermaid {
    --color-red: #ff7777;
    --color-orange: #ffbb99;
    --color-yellow: #ffeeaa;
    --color-green: #bbffbb;
    --color-cyan: #bbffee;
    --color-blue: #aaccff;
    --color-purple: #ddbbff;
    --color-pink: #ffcccc;
}

/* Make mindmap colors readable (Dark mode) */
.theme-dark .mermaid {
    --color-red: #933;
    --color-orange: #963;
    --color-yellow: #993;
    --color-green: #393;
    --color-cyan: #399;
    --color-blue: #339;
    --color-purple: #639;
    --color-pink: #966;
}

/* Override root text color in mermaid 
 * so that it's the same color as regular node text */
.mermaid .section-root text {
    fill: inherit !important;
}

This is what they look like in my vault in dark mode:

image

I hope this helps. Please let us know how you make out.

Good luck!

Craig

3 Likes

thanks for taking time to write this out, it solved for me!

1 Like

Thanks so much for the CSS snippets below. I really appreciate it.

1 Like

Hey @Craig , I’m unable to replicate what you did, here’s screenshots of what I have set up– a mermaid.css file with your classes, enabled in my vault, but the mermaid output on mindmap is still the default coloring. do I have to override each node in the map with `–color-<color_name>` ?

Hi @mkmatheson,

Your setup looks fine. Unfortunately the way Mermaid mind map colors work in Obsidian have changed since that post in 2023, so the old CSS doesn’t work anymore. It took me a little while to figure out how to set the colors again. New CSS at the bottom of this post.

By default, the Mermaid mind map colors look kind of garish to me:

I prefer a pale, warm palette for the mind map, with light backgrounds and black text. Here’s what my adjusted palette looks like in light mode:

It looks like you’re using dark mode. I don’t use dark mode in Obsidian, so I had to guess at what might look OK in a dark theme. You’ll probably want to adjust the colors to your taste, but beware: there is some transformation being applied to the colors that I don’t understand, so making them “lighter” seems to make them “darker” instead. (Actual CSS devs can tell you what’s really going on, I’m sure. :slight_smile: )

Here’s the dark theme palette I came up with:

In the new CSS paradigm, the root and each branch (called “section” in the CSS) must have their colors explicitly set and overriden using !important. I’m not a CSS expert, so this is very much a brute-force approach, but it does work.

I styled branches (sections) 0-6, since I rarely have more branches than that, but you can of course style more if you like, following the pattern in the CSS.

Below is the CSS I use to style my Mermaid diagrams. I hope it’s helpful for you.

Craig


.obsidian/snippets/mermaid.css

/* Resize Mermaid diagrams to fit on the page by default */
.mermaid svg {
    max-width: 100%;
    height: auto;
}

/* Override resizing if desired */
.no-resize-mermaid .mermaid svg {
    max-width: inherit;
    height: inherit;
}

/******************/
/* MINDMAP COLORS */
/******************/

/* Mindmap section colors */
.theme-light {
    --mermaid-mindmap-text-color: #000000;
    --mermaid-mindmap-root-color: #DDDDDD;
    --mermaid-mindmap-section-0-color: #C8DFF0;
    --mermaid-mindmap-section-1-color: #F9C6B8;
    --mermaid-mindmap-section-2-color: #BFE8E0;
    --mermaid-mindmap-section-3-color: #FAEBA2;
    --mermaid-mindmap-section-4-color: #DAB9C3;
    --mermaid-mindmap-section-5-color: #DFF6F5;
    --mermaid-mindmap-section-6-color: #FAD9C3;
}

.theme-dark {
    --mermaid-mindmap-text-color: #000000;
    --mermaid-mindmap-root-color: #8F8F8F;
    --mermaid-mindmap-section-0-color: #7A91A2;
    --mermaid-mindmap-section-1-color: #AB786A;
    --mermaid-mindmap-section-2-color: #719A92;
    --mermaid-mindmap-section-3-color: #AC9D54;
    --mermaid-mindmap-section-4-color: #8C6B75;
    --mermaid-mindmap-section-5-color: #91A8A7;
    --mermaid-mindmap-section-6-color: #AC8B75;
}

/* All nodes */
.mermaid .mindmap-nodes text {
    fill: var(--mermaid-mindmap-text-color) !important;
}

/* Root node */
.mermaid .mindmap-nodes .section-root .node-bkg {
    fill: var(--mermaid-mindmap-root-color) !important;
    stroke: var(--mermaid-mindmap-root-color) !important;
}
.mermaid .mindmap-nodes .section-root .node-line--1 {
    stroke: var(--mermaid-mindmap-root-color) !important;
}
.mermaid .mindmap-nodes .section-root .text-inner-tspan {
    font-weight: bold;
}

/* Section 0 */
.mermaid .mindmap-nodes .section-0 .node-bkg {
    fill: var(--mermaid-mindmap-section-0-color) !important;
}
.mermaid .mindmap-nodes .section-0 .node-line-0 {
    stroke: var(--mermaid-mindmap-section-0-color) !important;
}
.mermaid .mindmap-edges .section-edge-0 {
    stroke: var(--mermaid-mindmap-section-0-color) !important;
}

/* Section 1 */
.mermaid .mindmap-nodes .section-1 .node-bkg {
    fill: var(--mermaid-mindmap-section-1-color) !important;
}
.mermaid .mindmap-nodes .section-1 .node-line-1 {
    stroke: var(--mermaid-mindmap-section-1-color) !important;
}
.mermaid .mindmap-edges .section-edge-1 {
    stroke: var(--mermaid-mindmap-section-1-color) !important;
}

/* Section 2 */
.mermaid .mindmap-nodes .section-2 .node-bkg {
    fill: var(--mermaid-mindmap-section-2-color) !important;
}
.mermaid .mindmap-nodes .section-2 .node-line-2 {
    stroke: var(--mermaid-mindmap-section-2-color) !important;
}
.mermaid .mindmap-edges .section-edge-2 {
    stroke: var(--mermaid-mindmap-section-2-color) !important;
}

/* Section 3 */
.mermaid .mindmap-nodes .section-3 .node-bkg {
    fill: var(--mermaid-mindmap-section-3-color) !important;
}
.mermaid .mindmap-nodes .section-3 .node-line-3 {
    stroke: var(--mermaid-mindmap-section-3-color) !important;
}
.mermaid .mindmap-edges .section-edge-3 {
    stroke: var(--mermaid-mindmap-section-3-color) !important;
}

/* Section 4 */
.mermaid .mindmap-nodes .section-4 .node-bkg {
    fill: var(--mermaid-mindmap-section-4-color) !important;
}
.mermaid .mindmap-nodes .section-4 .node-line-4 {
    stroke: var(--mermaid-mindmap-section-4-color) !important;
}
.mermaid .mindmap-edges .section-edge-4 {
    stroke: var(--mermaid-mindmap-section-4-color) !important;
}

/* Section 5 */
.mermaid .mindmap-nodes .section-5 .node-bkg {
    fill: var(--mermaid-mindmap-section-5-color) !important;
}
.mermaid .mindmap-nodes .section-5 .node-line-5 {
    stroke: var(--mermaid-mindmap-section-5-color) !important;
}
.mermaid .mindmap-edges .section-edge-5 {
    stroke: var(--mermaid-mindmap-section-5-color) !important;
}

/* Section 6 */
.mermaid .mindmap-nodes .section-6 .node-bkg {
    fill: var(--mermaid-mindmap-section-6-color) !important;
}
.mermaid .mindmap-nodes .section-6 .node-line-6 {
    stroke: var(--mermaid-mindmap-section-6-color) !important;
}
.mermaid .mindmap-edges .section-edge-6 {
    stroke: var(--mermaid-mindmap-section-6-color) !important;
}
1 Like

Thanks @Craig ! Really appreciate you looking into this after so much time. To be honest I completely forgot Obsidian is an Electron app and realize I could have inspected the css classes on the mindmap to see where it gets its default styling.

1 Like