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:
- widget: the ancestor is a inheriting semantic
widget
; or - disabled label: the ancestor is used in the accessible name of a inheriting semantic
widget
that is disabled; or - disabled group: the ancestor has a semantic role of
group
and is disabled.
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
- Understanding Success Criterion 1.4.3: Contrast (Minimum)
- Understanding Success Criterion 1.4.6: Contrast (Enhanced)
- G18: Ensuring that a contrast ratio of at least 4.5:1 exists between text (and images of text) and background behind the text
- G145: Ensuring that a contrast ratio of at least 3:1 exists between text (and images of text) and background behind the text
- F83: Failure of Success Criterion 1.4.3 and 1.4.6 due to using background images that do not provide sufficient contrast with foreground text (or images of text)
- CSS Scoping Module Level 1 (Editor’s Draft)
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
- Any
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
- Any
Input Aspects
The following aspects are required in using this rule.
Test Cases
Passed
Passed Example 1
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
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
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
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
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
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
This text does not convey anything in human language.
<p style="color: #000; background: #666;">
----=====++++++++___________***********%%%%%%%%%%%±±±±@@@@@@@@
</p>
Passed Example 8
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
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
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
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
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
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
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
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
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
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
This text is not visible because of display: none
.
<p style="display: none">Some invisible text in English</p>
Inapplicable Example 2
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
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
This text is not the child of an HTML element.
<svg>
<text x="0" y="15">I love SVG!</text>
</svg>
Inapplicable Example 5
This text not part of a text node.
<p>
<img scr="/test-assets/contrast/example.png" alt="example" />
</p>
Inapplicable Example 6
This text is part of a widget because it is a child of a button
element.
<button>My button!</button>
Inapplicable Example 7
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
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
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
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
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.
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 eitherImage Button
(the state) orimage
(the keyword mapping to it), both formulations having the same meaning; similarly, “an input element with atype
attribute value ofText
” 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 andfalse
otherwise. Thus<button disabled>
,<button disabled="disabled">
and<button disabled="">
all have adisabled
attribute value oftrue
. - 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.
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:
-
The element matches the
:disabled
pseudo-class. For HTML elements this means that the element is actually disabled. -
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:
- the element is part of sequential focus navigation; or
- the element has a tabindex value that is not null.
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.
Highest Possible Contrast
The highest value of the contrast ratios between two sets of colors.
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
Text nodes with a computed font-size of:
- at least 18 points, or
- at least 14 points and a computed font weight CSS property of 700 or higher.
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
orpresentation
; or - it is an
img
element with analt
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
ofnone
; or - has an
aria-hidden
attribute set totrue
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:
- 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.
- Explicit If the element has an explicit role, then its semantic role is its explicit role.
- 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.
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:
- Accessible Rich Internet Applications (WAI-ARIA) 1.1
- WAI-ARIA Graphics Module 1.0
- Digital Publishing WAI-ARIA Module 1.0
Note: depending on the type of content being evaluated, part of the specifications might be irrelevant and should be ignored.
Rule Versions
This is the first version of this ACT rule.
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.