Dark Mode 2.2.0
After a long time, Element Plus supports dark mode!
We extracted and unified all necessary variables to make it possible to implement based on CSS Vars.
How to enable it?
First you can create a switch to toggle dark class of html.
If you only need dark mode, just add
darkclass for html.
<html class="dark">
<head></head>
<body></body>
</html>If you want to toggle it, i recommend useDark | VueUse.
Then, you can quickly enable it with just one line of code to import CSS in your entry.
// if you just want to import css
import 'element-plus/theme-chalk/dark/css-vars.css'If you want an example, you can refer to element-plus-vite-starter.
Shadow DOM
The Shadow DOM stylesheet includes dark mode. Toggle the dark class on the host element, the element that owns the shadow root.
For dark mode overrides, add a stylesheet after it inside the shadow root and use :host(.dark).
With the regular stylesheet in the shadow root, components can inherit dark variables from page ancestors. Use the Shadow DOM stylesheet and the host's dark class to apply component-specific dark styles inside the shadow root.
Custom variables
By CSS
Just override it by CSS Vars.
For example, new file styles/dark/css-vars.css:
html.dark {
/* custom dark bg color */
--el-bg-color: #626aef;
}Import it after styles of Element Plus:
import 'element-plus/theme-chalk/dark/css-vars.css'
import './styles/dark/css-vars.css'By SCSS
If you use scss, you can also import scss file to compile.
You can refer Theming to get more info.
/*just override what you need*/
@forward 'element-plus/theme-chalk/src/dark/var.scss' with (
$bg-color: (
'page': #0a0a0a,
'': #626aef,
'overlay': #1d1e1f,
)
);import './styles/element/index.scss'
// or just want to import scss?
// import 'element-plus/theme-chalk/src/dark/css-vars.scss'