twbs / bootstrap

The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.
https://getbootstrap.com
MIT License
170.47k stars 78.83k forks source link

Windows High Contrast Mode / forced color adaptations #35941

Open patrickhlauke opened 2 years ago

patrickhlauke commented 2 years ago

Proposal

Adding a few surgical, very specific general styles to Bootstrap using the (forced-colors) media query, to make sure that some of our components that aren't properly discernible in Windows High Contrast Mode stand a slightly better chance at having at least minimal styles applied even in WHCM.

Motivation and context

Splitting the idea out of https://github.com/twbs/bootstrap/pull/29490

A lot of the standard Bootstrap styles rely on background colours, borders and shadows (e.g. to make buttons/pills/etc look "button-like"). These styles usually get completely overridden by Windows High Contrast Mode (WHCM), which explicitly ignores things like background and forces specific user-defined colours for things.

Until recently, there was no clean standardised way of approaching this issue (even with proprietary things like -ms-high-contrast - see https://www.tpgi.com/windows-high-contrast-mode-the-limited-utility-of-ms-high-contrast/)

However, the relatively new (forced-colors) media query offers a relatively stable way of approaching this issue now, adding very targeted adaptations/tweaks for cases where WHCM is enabled.

I have recently been playing with it on a project (not directly using Bootstrap, but the concept is obviously the same) to force an outline (rather than a border, so it doesn't affect element dimensions), a la

@media (forced-colors) {
  button {
    outline: 1px solid LinkText !important;
  }
}

Trying to do further/more intense styling is probably counterproductive (i.e. not doing a whole exercise like dark mode or anything), but just some basics like this would immediately make BS more WHCM-friendly for very little extra effort.

davidscotson commented 2 years ago

Hi @patrickhlauke, are you aware of a shared gist or other source that gathers together the forced-color adaptions that aren't yet accepted into upstream Bootstrap? I'm looking at adding them to a Bootstrap 4(.6) project and if one doesn't exist I might create it as it seems generally useful and shareable, rather than project specific.

patrickhlauke commented 2 years ago

i don't think there's a single collated list at the moment. would suggest, if you can find the time, going through the docs pages and trying to identify all the different places where currently forced colors/WHCM is not ideal (in terms of borders, outlines, etc not showing up)

davidscotson commented 2 years ago

I've started a gist here, I'll try to remember to update it as I test and find issues:

https://gist.github.com/davidscotson/446f5a637715af9d1db832f60640e705

patrickhlauke commented 2 years ago

Taking https://getbootstrap.com/docs/5.2/examples/cheatsheet/ for a quick spin in high contrast (Windows 10 WHCM, Chrome):

Forms

Overview

Floating labels

Validation

Components

image

Alerts

Badge

Carousel

Dropdowns

Modal

Navs

Navbar

Pagination

Popovers

Progress

Spinners

Toasts

Tooltips

Other

A few other examples not covered in the cheatsheet:

robfentress commented 1 year ago

Another thing I didn't see in previous comments is the fact that you can't see the checked state of the checkboxes when viewed in certain themes, such as High Contrast White in Windows 10 and Desert High Contrast in Windows 11. You can find an explanation of the issues I found with this control and my proposed solutions in this CodePen: Fixing Accessibility of Bootstrap's Checkbox Styling

Here is a gist of the same, basically: Contrast tweaks for checkbox in Bootstrap

This is easy to miss, because it doesn't show up when checking with darker themes, which is all most people test with.

I'm not sure, but I think I remember there being similar issues with the radio buttons.

coliff commented 3 months ago

I spent a lot of time going through the components and have created a forced-colors: active stylesheet which fixes just about all issues I could find in both dark and light high contrast themes. Tested with Edge on Windows 11.

Some fixes made are a bit opinionated, e.g. increasing border width from 1px to 2px on form inputs to counter the fact that there is no box-shadow. It'd be great to see some/most of these fixes be made to Bootstrap in the future. For now though, users can use this stylesheet to improve things for Windows users with High Contrast themes.

<link
  rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/bootstrap-forced-colors-css@1/css/bootstrap-forced-colors.min.css" 
  media="screen and (forced-colors: active)">
Testing with Forced Colors Mode Emulation in Chrome / Edge ![edge-test-forced-colors-active](https://github.com/twbs/bootstrap/assets/1212885/dc681871-7605-42d8-82d0-b6361e7f3faa) ![edge-test-forced-colors-active-light-mode](https://github.com/twbs/bootstrap/assets/1212885/df7766a8-d825-4845-8a2e-1f733dbd38e8)