Skip to content

Proposed Text has minimum contrast

Description

This rule checks that the highest possible contrast of every text character with its background meets the minimal contrast requirement.

Applicability

This rule applies to any visible character in a text node that is a child in the flat tree of an HTML element, except if the text node has an ancestor in the flat tree for which at least one of the following is true:

Expectation

For each test target, the highest possible contrast between the foreground colors and background colors is at least 3.0:1 for large scale text and 4.5:1 for other texts, except if the test target is part of a text node that is purely decorative or does not express anything in human language.

Assumptions

Accessibility Support

Background

Passing this rule does not mean that the text has sufficient color contrast. If all background pixels have a low contrast with all foreground pixels, the success criterion is guaranteed to not be satisfied. When some pixels have sufficient contrast, and others do not, legibility should be considered. There is no clear method for determining legibility when some but not all pixels have sufficient contrast, which is why passing this rule does not necessarily mean the corresponding success criterion is met.

When the text color or background color is not specified in the web page, colors from other origins will be used. Testers must ensure colors are not affected by styles from a user origin, such as a custom style sheet. Contrast issues caused by specifying the text color but not the background or vice versa, must be tested separately from this rule.

Bibliography

Accessibility Requirements Mapping

Secondary Requirements

This rule is related to the following accessibility requirements, but was not designed to test this requirements directly. These secondary requirements can either be stricter than the rule requires, or may be satisfied in ways not tested by the rule:

Input Aspects

The following aspects are required in using this rule.

Test Cases

Passed

Passed Example 1

Open in a new tab

This dark gray text has a contrast ratio of 12.6:1 on the white background.

<p style="color: #333; background: #FFF;">
	Some text in a human language
</p>

Passed Example 2

Open in a new tab

This dark gray text has a contrast ratio between 12.6:1 and 5:1 on the white to blue gradient background.

<p style="color: #333; background: linear-gradient(to right, #FFF, #00F); width: 500px;">
	Some text in a human language
</p>

Passed Example 3

Open in a new tab

This light gray text has a contrast ratio between 13:1 and 5:1 on the background image.

<style>
	p {
		color: #ccc;
		height: 50px;
		padding-top: 15px;
		background: #000 no-repeat -20px -20px url('/test-assets/contrast/black-hole.jpeg');
		text-shadow: 0px 0px 2px black;
	}
</style>
<p>Black hole sun</p>

Passed Example 4

Open in a new tab

This black text has a contrast ratio between 6.1:1 and 9:1 on gray background with white text shadow on it.

<p style="color: #000; background: #737373; text-shadow: white 0 0 3px">
	Some text in a human language
</p>

Passed Example 5

Open in a new tab

This 18pt large black text has a contrast ratio of 3.6:1 on the gray background.

<p style="color: #000; font-size:18pt; background: #666;">
	Some text in a human language
</p>

Passed Example 6

Open in a new tab

This 14pt bold black text has a contrast ratio of 3.6:1 on the gray background.

<p style="color: #000; font-size:14pt; font-weight:700; background: #666;">
	Some text in English
</p>

Passed Example 7

Open in a new tab

The content of this button (“X”) does not convey anything in human language; therefore, it passes the rule regardless of its contrast ratio. However, Success Criterion 1.4.11 Non-Text Content should be examined for this non-text element.

<button style="color: #666; background-color: #000" aria-label="Close">X</button>

Passed Example 8

Open in a new tab

This text has the default browser text color on the default browser background color. By default this is black text on a white background, which has a contrast ratio of 21:1.

<p>Some text in a human language</p>

Passed Example 9

Open in a new tab

This dark gray text has a contrast ratio of 12.6:1 on the white background in a shadow DOM tree.

<p style="color: #CCC; background: #fff;" id="p"></p>
<script>
	const shadowRoot = document.getElementById('p').attachShadow({ mode: 'open' })
	shadowRoot.innerHTML = '<span style="color: #333;">Some text in English</span>'
</script>

Passed Example 10

Open in a new tab

This text has the default user agent link text and background color, of #0000EE and white. This results in a contrast ratio of 9.39:1.

<a href="https://w3c.org/">W3C</a>

Passed Example 11

Open in a new tab

This text is using the default user agent text color and background color. By default, this is black text on a white background with a contrast ratio of 21:1

<div role="button">My button!</div>

Failed

Failed Example 1

Open in a new tab

This light gray text has a contrast ratio of 2.3:1 on the white background.

<p style="color: #AAA; background: white;">
	Some text in English
</p>

Failed Example 2

Open in a new tab

This light gray text has a contrast ratio between 1.2:1 and 2.3:1 on the white to blue gradient background.

<p style="color: #AAA; background: linear-gradient(to right, #FFF, #00F); width: 300px">
	Some text in English
</p>

Failed Example 3

Open in a new tab

This light gray text has a contrast ratio between 2.7:1 and 3:1 on the background image.

<p
	style="color: #555; height:50px; padding-top:20px; background: black no-repeat -20px -20px url('/test-assets/contrast/black-hole.jpeg');"
>
	Black hole sun
</p>

Failed Example 4

Open in a new tab

This black text with 30% alpha channel has a contrast ratio of 2.1:1 on the white background.

<p style="color: rgba(0,0,0,.3); background: #FFF">
	Some text in English
</p>

Failed Example 5

Open in a new tab

This black text with 30% opacity has a contrast ratio of 2.1:1 on the white background.

<div style="background: #FFF">
	<p style="color: #000; opacity: .3">
		Some text in English
	</p>
</div>

Failed Example 6

Open in a new tab

This light gray text has a contrast ratio of 2.3:1 on the white background in a shadow DOM tree.

<p style="color: #aaa; background: #fff;" id="p"></p>
<script>
	const shadowRoot = document.getElementById('p').attachShadow({ mode: 'open' })
	shadowRoot.textContent = 'Some text in English'
</script>

Failed Example 7

Open in a new tab

This semi-transparent gray text has a contrast ratio between 2.3:1 and 4.2:1 on the black and white background. The light gray text is compared to the white section of the background and the dark gray text is compared to the black section of the background.

<style>
	#backgroundSplit {
		color: rgba(90, 90, 90, 0.8);
		background-position: top 0 left 0;
		background-image: linear-gradient(90deg, transparent, transparent 3.3em, black 3.3em, black 6em);
		padding: 0 1em;
	}
</style>
<span id="backgroundSplit">
	Hello world
</span>

Failed Example 8

Open in a new tab

The first p element has a contrast ratio of 12.6:1. The second p element, which contains an example of the Helvetica font, has a contrast ratio of 3.85:1. Because this provides information, and is not only for aesthetic purposes, this is not considered purely decorative.

<p style="color: #333; background: #FFF;">
	Helvetica is a widely used sans-serif typeface developed in 1957 by Max Miedinger and Eduard Hoffmann.
</p>
<p style="font-family: helvetica; background: #EEE; color: #777;">
	The quick brown fox jumps over the lazy dog.
</p>

Failed Example 9

Open in a new tab

This text in a button element has a contrast ratio of 3.85:1.

<button style="color: #777; background: #EEE;">My button!</button>

Failed Example 10

Open in a new tab

This text in a semantic button has a contrast ratio of 3.85:1.

<div role="button" style="color: #777; background: #EEE;">My button!</div>

Inapplicable

Inapplicable Example 1

Open in a new tab

This text is not visible because of display: none.

<p style="display: none">Some invisible text in English</p>

Inapplicable Example 2

Open in a new tab

This text is not visible because it is positioned off screen.

<p style="position:absolute; top: -999em">Some invisible text in English</p>

Inapplicable Example 3

Open in a new tab

This text is not visible because the foreground color is the same as the background color.

<p style="color: white; background: white;" aria-hidden="true">Hidden text - U U D D L R L R B A S</p>

Inapplicable Example 4

Open in a new tab

This text is not the child of an HTML element.

<svg>
	<text x="0" y="15">I love SVG!</text>
</svg>

Inapplicable Example 5

Open in a new tab

This text not part of a text node.

<p>
	<img src="/test-assets/contrast/example.png" alt="example" />
</p>

Inapplicable Example 6

Open in a new tab

This text is part of a label of a disabled widget, because it is in a label element that is the label for an input element with type="text".

<label style="color:#888; background: white;">
	My name
	<input type="text" disabled />
</label>

Inapplicable Example 7

Open in a new tab

This text is part of a label of a disabled widget, because it is in an element that is referenced by aria-labelledby from an element with role="textbox".

<label id="my_pets_name" style="color:#888; background: white;">
	My pet's name
</label>
<div
	role="textbox"
	aria-labelledby="my_pets_name"
	aria-disabled="true"
	style="height:20px; width:100px; border:1px solid black;"
>
	test
</div>

Inapplicable Example 8

Open in a new tab

This text is part of a label of a disabled widget, because it is in a label element that is the label for an input element in a fieldset element with the disabled attribute.

<fieldset disabled style="color:#888; background: white;">
	<label>
		My name
		<input />
	</label>
</fieldset>

Inapplicable Example 9

Open in a new tab

This text is part of a label of a disabled widget, because it is in a label element that is the label for an input element in an element with role="group" with the aria-disabled="true" attribute.

<div role="group" aria-disabled="true" style="color:#888; background: white;">
	<label>
		My name
		<input />
	</label>
</div>

Inapplicable Example 10

Open in a new tab

This text is part of a disabled widget because it is a child of a button element with the disabled attribute.

<button style="color: #777; background: #EEE;" disabled>My button!</button>

Inapplicable Example 11

Open in a new tab

This text is part of a disabled widget because it is a child of an element with the role attribute set to button and with an aria-disabled attribute set to true.

<div role="button" style="color: #777; background: #EEE;" aria-disabled="true">My button!</div>

Glossary

Accessible Name

The accessible name is the programmatically determined name of a user interface element that is included in the accessibility tree.

The accessible name is calculated using the accessible name and description computation.

For native markup languages, such as HTML and SVG, additional information on how to calculate the accessible name can be found in HTML Accessibility API Mappings 1.0, Accessible Name and Description Computation (working draft) and SVG Accessibility API Mappings, Name and Description (working draft).

For more details, see examples of accessible name.

Note: As per the accessible name and description computation, each element always has an accessible name. When no accessible name is provided, the element will nonetheless be assigned an empty ("") one.

Note: As per the accessible name and description computation, accessible names are flat string trimmed of leading and trailing whitespace. Notably, it is not possible for a non-empty accessible name to be composed only of whitespace since these must be trimmed.

Attribute value

The attribute value of a content attribute set on an HTML element is the value that the attribute gets after being parsed and computed according to specifications. It may differ from the value that is actually written in the HTML code due to trimming whitespace or non-digits characters, default values, or case-insensitivity.

Some notable case of attribute value, among others:

This list is not exhaustive, and only serves as an illustration for some of the most common cases.

The attribute value of an IDL attribute is the value returned on getting it. Note that when an IDL attribute reflects a content attribute, they have the same attribute value.

Background Colors Of Text

The colors of all pixels, excluding the foreground colors pixels, in the bounding box around a visible character in a text node.

Bounding Box around Text

The smallest rectangle that encloses all the visible pixels of a character (including anti-aliased pixels), plus one pixel on every edge (top, right, bottom, left), aligned on the horizontal and vertical axis.

Disabled Element

An element is disabled when it has been rendered inoperable in one or more of the following ways:

  1. The element matches the :disabled pseudo-class. For HTML elements this means that the element is actually disabled.

  2. The element has a shadow-including ancestor whose aria-disabled attribute value is “true”.

Explicit Semantic Role

The explicit semantic role of an element is determined by its role attribute (if any).

The role attribute takes a list of tokens. The explicit semantic role is the first valid role in this list. The valid roles are all non-abstract roles from WAI-ARIA Specifications. If the element has no role attribute, or if it has one with no valid role, then this element has no explicit semantic role.

Other roles may be added as they become available. Not all roles will be supported in all assistive technologies. Testers are encouraged to adjust which roles are allowed according to the accessibility support base line. For the purposes of executing test cases in all rules, it should be assumed that all roles are supported by assistive technologies so that none of the roles fail due to lack of accessibility support.

Focusable

An element is focusable if one or both of the following are true:

Exception: Elements that lose focus during a period of up to 1 second after gaining focus, without the user interacting with the page the element is on, are not considered focusable.

Notes:

Foreground Colors Of Text

The colors of all the pixels of a visible character in a text node that change color when the CSS color property is changed. This includes anti-aliased pixels.

Note: Anti-aliasing is a technique in which the foreground color and background color are blended to create smooth edges.

Highest Possible Contrast

The highest value of the contrast ratios between two sets of colors (A and B). That is, the highest contrast ratio between either the darkest color in A and the brightest color in B, or the brightest color in A and the darkest color in B.

Implicit Semantic Role

The implicit semantic role of an element is a pre-defined value given by the host language which depends on the element and its ancestors.

Implicit roles for HTML and SVG, are documented in the HTML accessibility API mappings (working draft) and the SVG accessibility API mappings (working draft).

Included in the accessibility tree

Elements included in the accessibility tree of platform specific accessibility APIs are exposed to assistive technologies. This allows users of assistive technology to access the elements in a way that meets the requirements of the individual user.

The general rules for when elements are included in the accessibility tree are defined in the core accessibility API mappings. For native markup languages, such as HTML and SVG, additional rules for when elements are included in the accessibility tree can be found in the HTML accessibility API mappings (working draft) and the SVG accessibility API mappings (working draft).

For more details, see examples of included in the accessibility tree.

Programmatically hidden elements are removed from the accessibility tree. However, some browsers will leave focusable elements with an aria-hidden attribute set to true in the accessibility tree. Because they are hidden, these elements are considered not included in the accessibility tree. This may cause confusion for users of assistive technologies because they may still be able to interact with these focusable elements using sequential keyboard navigation, even though the element should not be included in the accessibility tree.

Inheriting Semantic Role

An element with an inheriting semantic role of X is any element with a non-abstract semantic role that inherits from X, or is the same as X.

Example: An “inheriting semantic link” is any element that either has the semantic role of link or a semantic role that inherits from the link role, such as doc-biblioref.

Large Scale Text

A text node is large scale text if at least one of the following is true:

Marked as decorative

An element is marked as decorative if one or more of the following conditions is true:

Elements are marked as decorative as a way to convey the intention of the author that they are pure decoration. It is different from the element actually being pure decoration as authors may make mistakes. It is different from the element being effectively ignored by assistive technologies as rules such as presentational roles conflict resolution may overwrite this intention.

Elements can also be ignored by assistive technologies if they are programmatically hidden. This is different from marking the element as decorative and does not convey the same intention. Notably, being programmatically hidden may change as users interact with the page (showing and hiding elements) while being marked as decorative should stay the same through all states of the page.

Namespaced Element

An element with a specific namespaceURI value from HTML namespaces. For example an “SVG element” is any element with the “SVG namespace”, which is http://www.w3.org/2000/svg.

Namespaced elements are not limited to elements described in a specification. They also include custom elements. Elements such as a and title have a different namespace depending on where they are used. For example a title in an HTML page usually has the HTML namespace. When used in an svg element, a title element has the SVG namespace instead.

Outcome

An outcome is a conclusion that comes from evaluating an ACT Rule on a test subject or one of its constituent test target. An outcome can be one of the three following types:

Note: A rule has one passed or failed outcome for every test target. When there are no test targets the rule has one inapplicable outcome. This means that each test subject will have one or more outcomes.

Note: Implementations using the EARL10-Schema can express the outcome with the outcome property. In addition to passed, failed and inapplicable, EARL 1.0 also defined an incomplete outcome. While this cannot be the outcome of an ACT Rule when applied in its entirety, it often happens that rules are only partially evaluated. For example, when applicability was automated, but the expectations have to be evaluated manually. Such “interim” results can be expressed with the incomplete outcome.

Programmatically Hidden

An HTML element is programmatically hidden if either it has a computed CSS property visibility whose value is not visible; or at least one of the following is true for any of its inclusive ancestors in the flat tree:

Note: Contrary to the other conditions, the visibility CSS property may be reverted by descendants.

Note: The HTML standard suggests setting the CSS display property to none for elements with the hidden attribute. While not required by HTML, all modern browsers follow this suggestion. Because of this the hidden attribute is not used in this definition. In browsers that use this suggestion, overriding the CSS display property can reveal elements with the hidden attribute.

Semantic Role

The semantic role of an element is determined by the first of these cases that applies:

  1. Conflict If the element is marked as decorative, but the element is included in the accessibility tree; or would be included in the accessibility tree when it is not programmatically hidden, then its semantic role is its implicit role.
  2. Explicit If the element has an explicit role, then its semantic role is its explicit role.
  3. Implicit The semantic role of the element is its implicit role.

This definition can be used in expressions such as “semantic button” meaning any element with a semantic role of button.

Visible

Content perceivable through sight.

Content is considered visible if making it fully transparent would result in a difference in the pixels rendered for any part of the document that is currently within the viewport or can be brought into the viewport via scrolling.

Content is defined in WCAG.

For more details, see examples of visible.

WAI-ARIA specifications

The WAI ARIA Specifications group both the WAI ARIA W3C Recommendation and ARIA modules, namely:

Note: depending on the type of content being evaluated, part of the specifications might be irrelevant and should be ignored.

Rule Versions

  1. Proposed version, 30 August 2023 (compare)
  2. Latest version, 30 August 2023

Implementations

This section is not part of the official rule. It is populated dynamically and not accounted for in the change history or the last modified date.

Implementation Type Consistency Report
Axe DevTools Pro 4.37.1 Semi-automated tool Consistent Axe DevTools Pro Report
Axe-core 4.8.3 Automated tool Consistent Axe-core Report
Equal Access Accessibility Checker 3.1.42-rc.0 Automated tool Consistent Equal Access Accessibility Checker Report
QualWeb 3.0.0 Automated tool Consistent QualWeb Report
SortSite 6.45 Automated tool Consistent SortSite Report
Total Validator (+Browser) 17.4.0 Automated tool Consistent Total Validator (+Browser) Report
Back to Top