Text has minimum contrast

  • Rule Type:atomic
  • Rule Id: afw4f7
  • Last modified: Jan 11, 2022
  • Accessibility Requirements Mapping:
    • 1.4.3 Contrast (Minimum) (Level AA)
      • Learn More about 1.4.3 Contrast (Minimum)
      • Required for conformance to WCAG 2.0 and later on level AA and higher.
      • Outcome mapping:
        • Any failed outcomes: success criterion is not satisfied.
        • All passed outcomes: success criterion needs further testing.
        • An inapplicable outcome: success criterion needs further testing.
    • 1.4.6 Contrast (Enhanced) (Level AAA)
      • Learn More about 1.4.6 Contrast (Enhanced)
      • Required for conformance to WCAG 2.0 and later on level AAA.
      • Outcome mapping:
        • Any failed outcomes: success criterion is not satisfied.
        • All passed outcomes: success criterion needs further testing.
        • An inapplicable outcome: success criterion needs further testing.

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 4.5:1 or 3.0:1 for larger scale text, except if the test target is part of a text node that is purely decorative or does not express anything in human language.

Assumptions

  • Success criterion 1.4.3: Contrast (Minimum) has exceptions for "incidental" text, which includes inactive user interface components and decorative texts. The rule assumes that text nodes that should be ignored are disabled or hidden from assistive technologies. If this isn't the case, the text node could fail this rule while the success criterion could still be satisfied.
  • Success criterion 1.4.3: Contrast (Minimum) also has an exception for logos and brand names. Since logos and brand names are usually displayed through images to ensure correct rendering, this rule does not take logos or brand names into consideration. If a logo or brand name is included using text nodes, the text node could fail while the success criterion could still be satisfied.
  • Text that has the same foreground and background color (a contrast ratio of 1:1) is not considered to be "visual presentation of text", making it inapplicable to the success criterion. Text hidden in this way can still cause accessibility issues under other success criteria, depending on the content.
  • The definition of disabled element assumes that when the aria-disabled attribute is specified on an element, this element has also been disabled for users that do not rely on assistive technology. If this is not the case, that definition may produce incorrect results and in consequence this rule might be Inapplicable to some text nodes that still require a good contrast ratio.

Accessibility Support

  • Different browsers have different levels of support for CSS. This can cause contrast issues in one browser that do not appear in another. Because of that, this rule can produce different results depending on the browser that is used. For example, a text that is positioned using CSS transform may be on a different background in a browser that does not support CSS transform.
  • Implementation of Presentational Roles Conflict Resolution varies from one browser or assistive technology to another. Depending on this, some elements can have a semantic role of none and fail this rule with some technology but users of other technologies would not experience any accessibility issue.

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, which is why this is out of scope for this rule.

This rule is designed specifically for 1.4.3 Contrast (Minimum), which has the expected contrast ratio of 4.5:1 (or 3:1 for large text). Because text that fails a contrast ratio of 4.5:1 also fails a contrast ratio of 7:1, this rule maps to 1.4.6 Contrast (Enhanced) as well. In order to adequately test the expectation, some of the passed examples do not satisfy 1.4.6 Contrast (Enhanced).

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

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.

<p
	style="color: #CCC; height:50px; padding-top:15px; background: #000 no-repeat -20px -20px url('/test-assets/contrast/black-hole.jpeg');"
>
	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

This text does not convey anything in human language.

<p style="color: #000; background: #666;">
	----=====++++++++___________***********%%%%%%%%%%%±±±±@@@@@@@@
</p>

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>

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.5:1. Because this provides information, and 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>

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 scr="/test-assets/contrast/example.png" alt="example" />
</p>

Inapplicable Example 6

Open in a new tab

This text is part of a widget because it is a child of a button element.

<button>My button!</button>

Inapplicable Example 7

Open in a new tab

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

<div role="button">My button!</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 with type="text".

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

Inapplicable Example 9

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 10

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 11

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>

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.

Accessibility Support for Accessible Name

  • Because the accessible name and description computation is not clear about which whitespace are considered, browsers behave differently when trimming and flattening the accessible name. For example, some browsers completely trim non-breaking spaces while some keep them in the accessible name.
  • There exists a popular browser which does not perform the same trimming and flattening depending whether the accessible name comes from content, an aria-label attribute, or an alt attribute.
  • There exists a popular browser which assign no accessible name (null) when none is provided, instead of assigned an empty accessible name ("").
  • The accessible name and description computation suggest that if an aria-labelledby attribute refers to an existing but empty element, the computation should stop and return an empty name without defaulting to the next steps. Several user agents and assistive technologies chose to use the next step in the computation in this case.

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:

  • For enumerated attributes, the attribute value is either the state of the attribute, or the keyword that maps to it; even for the default states. Thus <input type="image" /> has an attribute value of either Image Button (the state) or image (the keyword mapping to it), both formulations having the same meaning; similarly, "an input element with a type attribute value of Text" can be either <input type="text" />, <input /> (missing value default), or <input type="invalid" /> (invalid value default).
  • For boolean attributes, the attribute value is true when the attribute is present and false otherwise. Thus <button disabled>, <button disabled="disabled"> and <button disabled=""> all have a disabled attribute value of true.
  • For attributes whose value is used in a case-insensitive context, the attribute value is the lowercase version of the value written in the HTML code.
  • For attributes that accept numbers, the attribute value is the result of parsing the value written in the HTML code according to the rules for parsing this kind of number.
  • For attributes that accept sets of tokens, whether space separated or comma separated, the attribute value is the set of tokens obtained after parsing the set and, depending on the case, converting its items to lowercase (if the set is used in a case-insensitive context).
  • For aria-* attributes, the attribute value is computed as indicated in the WAI-ARIA specification and the HTML Accessibility API Mappings.

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.

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".

Assumptions for Disabled Element

This definition assumes that when the aria-disabled attribute is specified on an element, this element has also been disabled for users that do not rely on assistive technology. For example, this can be done by disabling pointer events using the pointer-events property and by disabling keyboard interactions using the tabindex attribute. If this is not the case, the definition will produce incorrect results.

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.

Accessibility Support for Explicit Semantic Role

Some browsers and assistive technologies treat the tokens of the role attribute as case-sensitive. Unless lowercase letters are used for the value of the role attribute, not all user agents will be able to interpret the tokens correctly. ARIA in HTML (working draft) also specifies that authors must use lowercase letters for the role and aria-* attributes.

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:

  • The 1 second time span is an arbitrary limit which is not included in WCAG. Given that scripts can manage the focus state of elements, testing the focusability of an element consistently would be impractical without a time limit.
  • The tabindex value of an element is the value of the tabindex attribute parsed using the rules for parsing integers. For the tabindex value to be different from null, it needs to be parsed without errors.

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.

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).

Accessibility Support for Implicit Semantic Role

  • Images with an empty alt attribute should have an implicit role of presentation, according to the HTML Accessibility API Mapping (work in progress). However, there are several popular browsers that do not treat images with empty alt attribute as having a role of presentation. Instead, they add the img element to the accessibility tree with a role of either img or graphic.

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.

Marked as decorative

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

  • it has an explicit role of none or presentation; or
  • it is an img element with an alt attribute whose value is the empty string (alt=""), and with no explicit role.

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:

  • Inapplicable: No part of the test subject matches the applicability
  • Passed: A test target meets all expectations
  • Failed: A test target does not meet all expectations

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:

  • has a computed CSS property display of none; or
  • has an aria-hidden attribute set to true

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.

Accessibility Support for Definition of Semantic Role for Semantic Role

  • There exist popular web browsers and assistive technologies which do not correctly implement Presentational Roles Conflict Resolution. These technologies will not include in the accessibility tree elements that should be, according to Specifications. Thus, some elements that should have their semantic role fixed by case Conflict above are instead falling into case Explicit and are hidden for users of assistive technologies.
  • A similar conflict exists for focusable elements with a aria-hidden="true" attribute. The WAI ARIA specification does not explain how to solve it. Some browsers give precedence to the element being focusable (and expose it in the accessibility tree) while some give precedence to the aria-hidden attribute (and hide the element).

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.


Useful Links


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. This section will not be included in the rule when it is published on the W3C website.

ToolConsistencyCompleteReport
QualWebconsistentYesView Report
SortSiteconsistentYesView Report

Acknowledgments

Funding

  • WAI-Tools
Table of Contents