
High Contrast Mode in Web-Accessibility
High contrast mode is a feature that allows users to increase the contrast of elements on their screen, making it easier to read text and distinguish between different elements. This can be particularly helpful for users with visual impairments such as color blindness or low vision. High contrast mode can be found in most operating systems and web browsers as a built-in feature.
When high contrast mode is turned on, the operating system or browser will adjust the colors of elements on the screen, such as text, backgrounds, and images, to make them more distinct from one another. This can make it easier for users with visual impairments to read text, navigate websites, and use apps and software.
In web browsers, the High Contrast mode can be enabled through the browser’s accessibility settings or by using keyboard shortcuts. Some browsers also have extensions that allow users to enable high contrast mode on specific websites.
It’s worth mentioning that High contrast mode is not a one-size-fits-all solution, users might prefer different color schemes, and it’s important to test our website with different color schemes, and also to provide a way for users to switch back to their preferred color scheme.
How a web developer will make sure that they have covered this during code development?
- Use appropriate color contrast ratios: Web developers should ensure that the colors used for text and background elements meet the recommended color contrast ratio guidelines, which are defined by the Web Content Accessibility Guidelines (WCAG). This will make it easier for users with visual impairments to read text and distinguish between different elements on the page.
- Test with different color schemes: Developers should test their website with different color schemes and different devices, this will ensure that the website looks and behaves correctly with high-contrast mode enabled, and that the website is accessible for users with visual impairments.
- Provide a high-contrast mode toggle: Developers should provide a way for users to switch back to the default or their preferred color scheme, this can be done by adding a toggle button or link that the user can click to enable and disable the high-contrast mode.
- Use appropriate semantic HTML: Developers should use appropriate semantic HTML elements such as headings, buttons, and links to make it easier for assistive technologies to understand the structure of the page, this will help users with visual impairments to navigate the page more easily.
- Use ARIA attributes: Developers should use ARIA attributes to provide additional information about the elements on the page, this will help users with visual impairments to understand the purpose of the elements on the page and interact with them more easily.
- Test with real users: Developers should test the website with real users with visual impairments to get feedback and make sure that the website is accessible and user-friendly.
It’s worth noting that accessibility is an ongoing process, and testing and updating the website for accessibility should be an integral part of the development process.
Example:
HTML:
<button id="toggle-high-contrast">Toggle High Contrast</button>
CSS:
/* Default styles */
body {
color: #000;
background-color: #fff;
}
/* High-contrast styles */
.high-contrast {
color: #fff;
background-color: #000;
}
JavaScript:
// Get the toggle button
var toggleButton = document.getElementById("toggle-high-contrast");
// Add a click event listener to the toggle button
toggleButton.addEventListener("click", function() {
// Get the body element
var body = document.getElementsByTagName("body")[0];
// Toggle the "high-contrast" class on the body element
body.classList.toggle("high-contrast");
});
In this example, the HTML defines a button with an id of “toggle-high-contrast”, which can be used to toggle the high-contrast mode. The CSS defines the default styles for the body element, as well as the high-contrast styles. The JavaScript is used to toggle the “high-contrast” class on the body element when the toggle button is clicked.
This is just one way to implement a high-contrast mode toggle, and it can be adapted to suit different needs. It’s worth mentioning that this is a simple example, in a real-world scenario, you should also take into consideration, the user’s preferences, and provide a way for the user to save their preferences.
It’s important to note that this example is provided for demonstration purposes only, and that there are many other ways to implement a high-contrast mode toggle, and this code should be tested and modified to suit our particular needs.
What is forced-color-adjust?
The forced-color-adjust
CSS property is used to control the color adjustment of an element, including its children. It allows authors to override the user's preferences and force a specific color adjustment on the page.
This property can take one of two values: auto
or none
.
- When set to
auto
, the browser will use the user's color preferences, as set in the operating system or browser settings. - When set to
none
, the browser will ignore the user's preferences and use the colors specified in the CSS.
For example:
body {
forced-color-adjust: none;
}
This will force the browser to use the colors specified in the CSS, even if the user has set a different color scheme in their operating system or browser settings. It’s worth noting that forced-color-adjust
is a relatively new property and support may vary among browsers. Also, it's considered to be an accessibility feature, so it's not recommended to use this property without good reason, as it might be confusing to users, especially those with visual impairments.
What is it used for?
The forced-color-adjust
CSS property is mainly used for accessibility purposes. It allows developers to provide a specific color scheme for users with visual impairments, even if the user has set different color preferences on their operating system or browser.
For example, a developer could use this property to force a high-contrast color scheme on their website for users who have difficulty distinguishing between different colors. This would make it easier for those users to read text and navigate the site.
Additionally, the property can also be used to override the browser’s default color settings and ensure that a website’s design is consistent across different platforms and devices.
It’s worth noting, however, that using the forced-color-adjust
property should be done with caution and consideration, as it can override the user's preferences and cause confusion or frustration. It's always recommended to provide an option for users to switch back to the default or their preferred color scheme.
How can we test it in chrome?
There are a few ways to test the forced-color-adjust
property in Chrome:
- Use the Developer Tools: Open the Developer Tools by right-clicking on the page and selecting “Inspect” or by pressing “Ctrl + Shift + I” on Windows or “Cmd + Shift + I” on Mac. Once the Developer Tools are open, you can toggle the
forced-color-adjust
property in the "Elements" tab by selecting the element you want to test and modifying the CSS in the "Styles" section. - Use a Chrome Extension: There are several Chrome extensions available that allow you to test different color schemes, including high-contrast modes. One such extension is “Accessibility Developer Tools” which allows you to simulate various visual impairments and test our website’s accessibility.
- Test on a different device: The forced-color-adjust property can also be tested on different devices, such as smartphones, tablets, and laptops. This allows you to test how the website looks and behaves with different color schemes and settings.
It’s also good practice to test our website with different screen readers, keyboard navigation and different devices to ensure accessibility compliance.
It’s worth mentioning that it’s important to test our website with real users with visual impairments to get feedback and make sure that our design is accessible and user-friendly.