Bootstrap Forced Colors CSS for Windows High Contrast Themes
Contents
Windows has supported High Contrast Themes in Windows since Windows 10. These customizable themes can be useful for users with visual impairments or for users who prefer high contrast colors. When a Contrast theme is activated is enables the forced-colors media query in browsers (at the time of writing, Edge, Chrome and Firefox).
Unfortunately, forced colors mode can cause issues with websites that are not designed to work with high contrast colors. Using Bootstrap v5 has a number of issues with missing borders and elements (This GitHub issue covers some of them) so I’ve created a stylesheet by using the forced-colors: active media query which you can simply add to your site to ‘auto-fix’ everything and adds enhancements to make Bootstrap 5 much more accessible in Firefox, Chrome, Edge on Windows.
Quick start
- Download the latest release
- Clone the repository
git clone https://github.com/coliff/bootstrap-forced-colors-css.git - Install with npm
npm install bootstrap-forced-colors-css - Install with yarn
yarn add bootstrap-forced-colors-css - Install with Composer
composer require coliff/bootstrap-forced-colors-css
Usage
Add this in the <head> which will load the CSS using a media query as follow:
<link
rel="stylesheet"
href="/css/bootstrap-forced-colors.min.css"
media="screen and (forced-colors: active)">
The CSS can be loaded via a CDN:
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap-forced-colors-css/css/bootstrap-forced-colors.min.css"
media="screen and (forced-colors: active)">
Or you can import the CSS into your own CSS file:
@import bootstrap-forced-colors.min.css
FAQS
What does this fix/improve?
- Accordion buttons have improved contrast in dark mode
- Badges within buttons have a 1px border to improve contrast
- Buttons have improved focus state contrast (2px visible outline rather than 1px)
- Disabled buttons display the correct color using the
GrayTextname - Carousel indicators have background-color issue resolved
- Close button has improved contrast by reducing the opacity
- Dropdown toggle arrows appear correctly (as triangles and not rectangles)
- List Group disabled items display the correct color using the
GrayTextname - Modal backdrop opacity changed from 0.5 to 0.8
- Navbar Menu (hamburger) toggle icons display correctly
- Navs Improves active and focus state contrast
- Pagination: Active page link has outline to indicate active page
- Pagination: Disabled page link display the correct color using the
GrayTextname - Placeholder: Fix for invisible placeholder boxes
- Popovers: Fixes invisible arrow issue
- Progress: Is no longer invisible
- Progress: Improved stacked progress bar contrast
- Spinners: Fixes animation
- Tables: Have a 1px outline to improve contrast
- Toasts: Fixes invisible close/dismiss button
- Tooltips: Fix for arrows appearing as rectangles
- Tooltips: Add 1px border to tooltips content
- Vertical Rule: Fixes invisible vertical rule
- Horizontal Rule: Improves contrast by changing opacity from 0.25 to 0.5
Demo
See this in action at: https://coliff.github.io/bootstrap-forced-colors-css/tests/
Testing
Currently, only Windows 10 & 11 with Edge, Firefox, and Chrome support forced colors mode. To test, you can enable forced colors mode in:
- Windows 10: Go to
Settings > Ease of Access > High contrastand select a theme.
Windows 11: Go to Settings > Accessibility > Contrast themes and select a theme
You can also use the Forced Colors Mode Emulation in Edge and Chrome on all platforms.
prefers-color-scheme between light and dark in the Dev Tools. Switching Bootstrap’s light/dark mode theme toggle will have no noticeable effect. The color scheme is set by the user at the OS level.Note that CanIUse lists Safari as supporting forced colors mode, however, macOS itself doesn’t have a Forced Colors / High Contrast mode which means it’s not possible to test this with Safari at all.
Interesting links about Windows High Contrast Mode
- Smashing Magazine article
- CanIUse Support (Only Windows supports forced colors mode)
- WHCM and System Colors