Color modes#
Bootstrap 5.3 has introduced color modes. This chapter is a guide for how to implement color modes in Plone 6.
Added in version Plone: 6.0.6
Preferred color modes#
You will need to add some JavaScript functionality to set the Bootstrap theme to the user's preferred color scheme.
Add the JavaScript file to the browser/static
folder of your Plone 6 project.
Register it in the browser/profiles/default/registry
of your Plone 6 project.
See Registering JavaScript and CSS for more information.
(() => {
'use strict'
// Set Bootstrap Theme to the preferred color scheme
const setPreferredTheme = () => {
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.documentElement.setAttribute('data-bs-theme', 'dark')
} else {
document.documentElement.setAttribute('data-bs-theme', 'light')
}
}
window.addEventListener('DOMContentLoaded', () => {
setPreferredTheme()
})
})()
Customize single elements#
Elements can be assigned a static theme using the data-bs-theme
attribute.
When set to a value, the element will be rendered in the given theme, overriding the global theme.
See the following example.
<form data-bs-theme='light'>
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>