|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Themes using CSS Variables in Vue Appearance component | Syncfusion |
| 4 | +description: Learn here all about Themes using CSS Variables in Syncfusion Vue Appearance component of Syncfusion Essential JS 2 and more. |
| 5 | +control: Themes using CSS Variables |
| 6 | +platform: ej2-vue |
| 7 | +documentation: ug |
| 8 | +domainurl: ##DomainURL## |
| 9 | +--- |
| 10 | + |
| 11 | +# About CSS variables in themes |
| 12 | + |
| 13 | +[CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties), also known as custom properties, are entities defined by CSS authors that contain specific values that can be reused throughout a CSS file. They are identified by their name, which must begin with two hyphens (--) followed by an identifier. These variables can be assigned any valid CSS value, such as colors, lengths, or fonts. To retrieve the value of a CSS variable, the var() function is used. |
| 14 | + |
| 15 | +Syncfusion currently offers two modern and highly customizable themes using CSS variables. These themes are designed to provide a consistent and visually appealing look and feel across all Syncfusion components. The themes available are: |
| 16 | + |
| 17 | +* Material 3 Theme |
| 18 | +* Fluent 2 Theme |
| 19 | + |
| 20 | +## CSS themes - Syncfusion Vue components |
| 21 | + |
| 22 | +[Material 3](https://m3.material.io/) and [Fluent 2](https://fluent2.microsoft.design/get-started/whatisnew) themes have been introduced across all EJ2 Controls, featuring both `light` and `dark` variants. This themes utilizes `CSS variables` to allow easy customization of control colors in CSS format. With this implementation, users can seamlessly switch between light and dark color schemes, providing a flexible solution to meet their preferences and application needs. |
| 23 | + |
| 24 | +> Kindly note that in the Material 3 theme, CSS variables with rgb() values are used for color variables. The use of hex values in this context may lead to improper functionality. For example, in previous versions of the Material theme or other themes, the primary color variable was defined as follows: $primary: #6200ee;. However, in the Material 3 theme, the primary color variable is defined as follows: --color-sf-primary: 98, 0, 238;. |
| 25 | +
|
| 26 | +### Utilization of CSS variables in modern themes |
| 27 | + |
| 28 | +Modern themes like Material 3 and Fluent 2 incorporate support for CSS variables, where `Material 3` utilizes `rgb()` values for customizing colors and `Fluent 2` uses `hex` values for color customization. For more information you can refer this [documentation](./theme#syncfusion-material-3-theme) for color variables of our themes. The examples below shows CSS variables with their values used for the respective themes. |
| 29 | + |
| 30 | +{% tabs %} |
| 31 | +{% highlight ts tabtitle="material3.css" %} |
| 32 | +{% include code-snippet/common/css-value-cs1/material3.css %} |
| 33 | +{% endhighlight %} |
| 34 | +{% highlight ts tabtitle="fluent2.css" %} |
| 35 | +{% include code-snippet/common/css-value-cs1/fluent2.css %} |
| 36 | +{% endhighlight %} |
| 37 | +{% endtabs %} |
| 38 | + |
| 39 | +### How to get these themes? |
| 40 | + |
| 41 | +To access themes provided by Syncfusion, you have two primary options, |
| 42 | + |
| 43 | +* Package |
| 44 | +* CDN links |
| 45 | + |
| 46 | +| | Light | Dark | |
| 47 | +|-----------|---------|--------| |
| 48 | +|Package | [Material 3 Light](https://www.npmjs.com/package/@syncfusion/ej2-material3-theme) | [Material 3 Dark](https://www.npmjs.com/package/@syncfusion/ej2-material3-dark-theme) | |
| 49 | +| | [Fluent 2 Light](https://www.npmjs.com/package/@syncfusion/ej2-fluent2-theme) | [Fluent 2 Dark](https://www.npmjs.com/package/@syncfusion/ej2-fluent2-dark-theme) | |
| 50 | +| CDN | [Material 3 Light](https://cdn.syncfusion.com/ej2/24.2.8/material3.css) | [Material 3 Dark](https://cdn.syncfusion.com/ej2/24.2.8/material3-dark.css) | |
| 51 | +| | [Fluent 2 light](https://cdn.syncfusion.com/ej2/26.1.35/fluent2.css) | [Fluent 2 Dark](https://cdn.syncfusion.com/ej2/26.1.35/fluent2-dark.css) | |
| 52 | + |
| 53 | +### Color Customization in themes |
| 54 | + |
| 55 | +CSS variables allows you to dynamically change color values in real-time using JavaScript. This flexibility enables you to create interactive experiences where colors can adjust based on user interactions or other dynamic factors. |
| 56 | + |
| 57 | +#### Customization using CSS |
| 58 | + |
| 59 | +Here you can find the example for `Material 3` customization using CSS class. |
| 60 | + |
| 61 | +{% tabs %} |
| 62 | +{% highlight html tabtitle="app.vue" %} |
| 63 | +{% include code-snippet/common/material3-cs2/app.vue %} |
| 64 | +{% endhighlight %} |
| 65 | +{% endtabs %} |
| 66 | + |
| 67 | +{% previewsample "page.domainurl/code-snippet/common/material3-cs2" %} |
| 68 | + |
| 69 | +**Default primary value** |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +**Customized primary value** |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +Example for `Fluent 2` customization using CSS class. |
| 78 | + |
| 79 | +{% tabs %} |
| 80 | +{% highlight html tabtitle="app.vue" %} |
| 81 | +{% include code-snippet/common/fluent2-cs2/app.vue %} |
| 82 | +{% endhighlight %} |
| 83 | +{% endtabs %} |
| 84 | + |
| 85 | +{% previewsample "page.domainurl/code-snippet/common/fluent2-cs2" %} |
| 86 | + |
| 87 | +**Default primary value** |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | +**Customized primary value** |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | +With this CSS variable support, you can effortlessly customize the color variable values for Syncfusion Vue Components. |
| 96 | + |
| 97 | +### Switching Light and Dark mode with CSS variables |
| 98 | + |
| 99 | +Switching between modes has become easier with the updated modern themes, which offer Light and Dark variants. In both the `Material 3` and `Fluent 2` light themes, there are distinct class variables for light and dark modes in a `single file`, providing flexibility for seamless switching between the two modes within your application. |
| 100 | + |
| 101 | +{% tabs %} |
| 102 | +{% highlight html tabtitle="app.vue" %} |
| 103 | +{% include code-snippet/common/material3-cs1/app.vue %} |
| 104 | +{% endhighlight %} |
| 105 | +{% endtabs %} |
| 106 | + |
| 107 | +{% previewsample "page.domainurl/code-snippet/common/material3-cs1" %} |
| 108 | + |
| 109 | +### Mode switching in Fluent 2 theme |
| 110 | + |
| 111 | +Similar to `Material 3`, we offer both Light and Dark variants with `Fluent 2`. In the Fluent 2 theme, there are distinct class variables for light and dark modes, as shown in the preview below. |
| 112 | + |
| 113 | +{% tabs %} |
| 114 | +{% highlight html tabtitle="app.vue" %} |
| 115 | +{% include code-snippet/common/fluent2-cs1/app.vue %} |
| 116 | +{% endhighlight %} |
| 117 | +{% endtabs %} |
| 118 | + |
| 119 | +{% previewsample "page.domainurl/code-snippet/common/fluent2-cs1" %} |
| 120 | + |
| 121 | +### How to switch dark mode? |
| 122 | + |
| 123 | +To activate dark mode, just append the `e-dark-mode` class to the body section of your application for both `Material 3` and `Fluent 2` theme. Once applied, the theme seamlessly switches to dark mode. Please refer to the example image below for visual guidance. |
| 124 | + |
| 125 | +`Material 3` dark mode |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | +`Fluent 2` dark mode |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | +### ThemeStudio Application |
| 134 | + |
| 135 | +The ThemeStudio application now includes seamless integration with the Material 3 and Fluent 2 themes, offering a comprehensive solution for customization requirements. This enhancement enables users to effortlessly customize and personalize their themes. |
| 136 | + |
| 137 | +Access the Syncfusion ThemeStudio application, featuring our themes, via the following link: [Link to Syncfusion ThemeStudio](https://ej2.syncfusion.com/themestudio/?theme=material3) |
0 commit comments