Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
High Contrast JS test
function isHighContrast() {
var e, c;
//Create a test div
e = document.createElement("div");
//Set its color style to something unusual = "rgb(31,41,59)";
//Attach to body so we can inspect it
//Use standard means if available, otherwise use the IE methods
c = document.defaultView ? document.defaultView.getComputedStyle(e, null).color : e.currentStyle.color;
//Delete the test DIV
//get rid of extra spaces in result
c = c.replace(/ /g, "");
//Check if we got back what we set
//If not we are in high contrast mode
if (c != "rgb(31,41,59)") {
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.