Skip to content

Instantly share code, notes, and snippets.

@willmendesneto
Last active May 17, 2022 13:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willmendesneto/4302de65ed6fa0e3661d3c0c08cf2a28 to your computer and use it in GitHub Desktop.
Save willmendesneto/4302de65ed6fa0e3661d3c0c08cf2a28 to your computer and use it in GitHub Desktop.
Using CSS for highlight errors in HTML - A11Y Linting HTML with CSS
/* Highliting accessibility errors in HTML */
/* highlight HTML element with invalid value for lang attribute */
html:not([lang]),
html[lang=""] {
border: 2px dotted red !important;
}
/* highlight images missing alt text */
img:not([alt]) {
filter: blur(5px) !important;
}
/* highlight on all elements that are inside of lists but not a list item <li> and displays them with a red outline.*/
:is(ul, ol) > *:not(li) {
outline: 2px dotted red !important;
}
/* highlight on links without valid href attribute */
a:not([href]),
a[href="#"],
a[href=""],
a[href*="javascript:void(0)"] {
outline: 2px dotted red !important;
}
/* highlights label with invalid for attribute */
label:not([for]),
label[for="#"],
label[for=""] {
border: 2px dotted red !important;
}
/* Avoids div buttons from hell. More details in https://www.htmhell.dev/2-div-with-button-role/ */
div[role="button"] {
color: red;
text-decoration: blink !important;
}
/* highlight on empty anchors/buttons */
button:empty,
a:empty {
border: 2px dotted red !important;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment