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

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

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.

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 cause by specifying the text color but not the background or vise versa, must be tested separately from 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.

<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

The first p element is has a contrast ratio of 21:1 (default black on white). The second p element contains Helvetica text which is decorative, because it does not convey information or provides functionality; its purpose is to show the aesthetic of the Helvetica font.

Note: Because this is non-text content, success criterion 1.4.11 Non-text Contrast requires font example to have a color contrast of 3:1.

<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;" aria-hidden="true">
	The quick brown fox jumps over the lazy dog.
</p>

Passed Example 8

Open in a new tab

This text does not convey anything in human language.

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

Passed Example 9

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 10

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>

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

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

Examples for Accessible Name

Note: The examples presented here are non-normative and not testable. They serve to illustrate some common pitfalls about the definition and to help implementers of ACT rules understand it.

The input elements have an accessible name of, respectively, "Billing Name" and "Billing Address". These accessible names are given by the aria-labelledby attributes and associated elements.

<div id="myBillingId">Billing</div>

<div>
	<div id="myNameId">Name</div>
	<input type="text" aria-labelledby="myBillingId myNameId" />
</div>
<div>
	<div id="myAddressId">Address</div>
	<input type="text" aria-labelledby="myBillingId myAddressId" />
</div>

This button element has an accessible name of "Share ACT rules" given by its aria-label attribute.

<button aria-label="Share ACT rules">Share</button>

This img element has an accessible name of "ACT rules" given by its alt attribute.

<img src="#" alt="ACT rules" />

The button element has an accessible name of "Share ACT rules" given by the enclosing label element (implicit label)

<label>Share ACT rules<button>Share</button></label>

The button element has an accessible name of "Share ACT rules" given by the associated label element (explicit label)

<label for="act-rules">Share ACT rules</label><button id="act-rules"></button>

This a element has an accessible name of "ACT rules" given from its content. Note that not all semantic roles allow name from content.

<a href="https://act-rules.github.io/">ACT rules</a>

This span element has an empty accessible name ("") because span does not allow name from content.

<span>ACT rules</span>

This span element has an empty accessible name ("") because span is not a labelable element.

<label>ACT rules<span></span></label>

Note: When the same element can have an accessible name from several sources, the order of precedence is: aria-labelledby, aria-label, own attributes, label element, name from content. The examples here are listed in the same order.

Note: For more examples of accessible name computation, including many tricky cases, check the Accessible Name Testable Statements.

Disabled Element

An element is considered disabled when it has been rendered inoperable using one of the following properties:

  1. The disabled attribute. The presence of this attribute, regardless of its value, on a

    will disable the element itself if it is not a fieldset or, if it is, will disable any descendants of the element, excluding those that are descendants of the first legend child of the element.

    Note: When the disabled attribute is specified on a fieldset element, shadow-including descendants are not disabled by default. Such behavior may however be explicitly implemented by form-associated custom elements.

  2. The aria-disabled attribute. The presence of this attribute with a value that is an ASCII case-insensitive match for true on an element will communicate its state, and the state of its shadow-including descendants, as "disabled" to assistive technology.

    Note: When the aria-disabled attribute is specified on an element, it is assumed that the 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.

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.

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.

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 its hidden state is false, 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.

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.

Examples for Visible

Note: The examples presented here are non-normative and not testable. They serve to illustrate some common pitfalls about the definition and to help the implementers of ACT rules understand it.

This span element is visible (by default, elements are visible).

<span>Now you can see me!</span>

This span element is not visible because of the CSS visibility property.

<span style="visibility: hidden">I'm the invisible man</span>

This span element is not visible because of the CSS display property.

<span style="display: none">I'm the invisible man</span>

This span element is not visible because it is positioned off-screen

<span style="position: absolute; top: -9999px; left: -9999px;">Incredible how you can</span>

This span element is not visible because it contains only whitespace and line breaks.

<span>
	<br />
	&nbsp;
</span>

This span element is not visible because it has the exact same color as its background.

<span style="color: #00F; background: #00F;">See right through me</span>

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.

ToolConsitencyCompleteReport
QualWebconsistentYesView Report
SortSitepartially-consistentYesView Report

Acknowledgments

Table of Contents