Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Styling with Themes and Classes | Customising and Integrating Mermaid.js
Mermaid.js Diagrams with JavaScript

bookStyling with Themes and Classes

When you want your diagrams to match your website's look or stand out visually, Mermaid.js offers several ways to change the appearance of your diagrams. The simplest way is to use Mermaid's built-in themes, which instantly change colors, fonts, and backgrounds. You can apply a theme by specifying it in your diagram's configuration, letting you quickly switch between styles like default, forest, dark, and neutral. This is useful for adapting diagrams to different environments, such as dark mode or brand guidelines.

index.html

index.html

copy

To go beyond built-in themes, Mermaid allows you to define and use custom classes for nodes and edges. By adding class definitions in your diagram code, you can target specific elements and apply custom styles using CSS. For example, you can assign a class to a node or an edge by using the triple-colon syntax, like A:::customNode. Then, in your CSS, you can define how .customNode should look. This approach gives you fine-grained control, letting you highlight important nodes, change edge colors, or adjust fonts for specific labels. Classes are especially helpful when you need to emphasize certain parts of a diagram or create a consistent visual language across multiple diagrams.

question mark

What is the main purpose of using classes in Mermaid diagrams?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 1

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

bookStyling with Themes and Classes

Deslize para mostrar o menu

When you want your diagrams to match your website's look or stand out visually, Mermaid.js offers several ways to change the appearance of your diagrams. The simplest way is to use Mermaid's built-in themes, which instantly change colors, fonts, and backgrounds. You can apply a theme by specifying it in your diagram's configuration, letting you quickly switch between styles like default, forest, dark, and neutral. This is useful for adapting diagrams to different environments, such as dark mode or brand guidelines.

index.html

index.html

copy

To go beyond built-in themes, Mermaid allows you to define and use custom classes for nodes and edges. By adding class definitions in your diagram code, you can target specific elements and apply custom styles using CSS. For example, you can assign a class to a node or an edge by using the triple-colon syntax, like A:::customNode. Then, in your CSS, you can define how .customNode should look. This approach gives you fine-grained control, letting you highlight important nodes, change edge colors, or adjust fonts for specific labels. Classes are especially helpful when you need to emphasize certain parts of a diagram or create a consistent visual language across multiple diagrams.

question mark

What is the main purpose of using classes in Mermaid diagrams?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 1
some-alt