Skip to content

Error field is not identified using color differences only #1914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d5fd2ef
Create error-field-is-not-identified-using-color-only
giacomo-petri Sep 5, 2022
4e177ad
Update error-field-is-not-identified-using-color-only
giacomo-petri Sep 5, 2022
34e0526
Update error-field-is-not-identified-using-color-only
giacomo-petri Sep 8, 2022
d877bd9
Rename error-field-is-not-identified-using-color-only to error-field-…
giacomo-petri Sep 8, 2022
42cd956
Update error-field-is-not-identified-using-color-only-i3z4v8.md
giacomo-petri Sep 8, 2022
fd8d6ec
Update error-field-is-not-identified-using-color-only-i3z4v8.md
giacomo-petri Sep 8, 2022
27f4474
Update error-field-is-not-identified-using-color-only-i3z4v8.md
giacomo-petri Sep 8, 2022
ed6ad31
Update error-field-is-not-identified-using-color-only-i3z4v8.md
giacomo-petri Sep 8, 2022
84e5bc2
Update error-field-is-not-identified-using-color-only-i3z4v8.md
giacomo-petri Sep 8, 2022
7e646ad
Update error-field-is-not-identified-using-color-only-i3z4v8.md
giacomo-petri Sep 8, 2022
4c0fcf2
Update error-field-is-not-identified-using-color-only-i3z4v8.md
giacomo-petri Sep 8, 2022
1125715
Update error-field-is-not-identified-using-color-only-i3z4v8.md
giacomo-petri Sep 8, 2022
eb7163b
Update error-field-is-not-identified-using-color-only-i3z4v8.md
giacomo-petri Sep 8, 2022
eae9d70
Update error-field-is-not-identified-using-color-only-i3z4v8.md
giacomo-petri Sep 8, 2022
3a8e604
Update error-field-is-not-identified-using-color-only-i3z4v8.md
giacomo-petri Sep 8, 2022
bac7869
Update error-field-is-not-identified-using-color-only-i3z4v8.md
giacomo-petri Sep 8, 2022
72d095c
Update error-field-is-not-identified-using-color-only-i3z4v8.md
giacomo-petri Sep 14, 2022
fef2a75
Apply suggestions from code review
giacomo-petri Oct 7, 2022
ae35c3e
Update error-field-is-not-identified-using-color-only-i3z4v8.md
giacomo-petri Oct 7, 2022
9940265
Update error-field-is-not-identified-using-color-only-i3z4v8.md
giacomo-petri Oct 7, 2022
a5198c9
Update _rules/error-field-is-not-identified-using-color-only-i3z4v8.md
giacomo-petri Oct 7, 2022
1998047
Update error-field-is-not-identified-using-color-only-i3z4v8.md
giacomo-petri May 9, 2023
68d9853
Merge branch 'act-rules:develop' into giacomo-petri-error-field-not-i…
giacomo-petri May 9, 2023
1ef6b3d
Update error-field-is-not-identified-using-color-only-i3z4v8.md
giacomo-petri May 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 175 additions & 0 deletions _rules/error-field-is-not-identified-using-color-only-i3z4v8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
---
id: i3z4v8
name: Error field is not identified using color differences only
rule_type: atomic
description: |
This rule checks that error fields can be identified not only by color differences but through another visual means.
accessibility_requirements:
wcag21:1.4.1: # Use of Color (A)
forConformance: true
failed: not satisfied
passed: further testing needed
inapplicable: further testing needed
input_aspects:
- DOM Tree
- CSS Styling
acknowledgments:
authors:
- Giacomo Petri
---

## Description

This rule checks that errors are not identified only through color differences.

## Applicability

This rule applies to each [HTML element][] that is [visible][] and has one of the following [semantic roles][]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This rule applies to each [HTML element][] that is [visible][] and has one of the following [semantic roles][]:
This rule applies to any [HTML element][] that is [visible][] and has one of the following [semantic roles][]:

- checkbox,
- combobox,
- listbox,
- menuitemcheckbox,
- menuitemradio,
- radio,
- searchbox,
- slider,
- spinbutton,
- switch or
- textbox.

## Expectation

Each test target either has no [visible][] [form field error indicators][], or at least one of the [visible][] [form field error indicators][] identifies the presence of errors not only through color differences.
Copy link
Collaborator

@Jym77 Jym77 May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing a potential pitfall here (also when looking at examples):
This somewhat implicitly consider that we have something to compare the error indicator to, in order to decide whether it is color differences or more (i.e. "differences" with what?)

This could either be another field, not in error, in the same form, or the same field when not errored.
The second solution somewhat requires a statefull rule and the tester to act (and put the field in error). This hopefully will be doable soonish (once we've solved #1953 / #2045), but that may still take time.
The first point could be doable by targeting pairs of field, passing if they are both errored or none errored, and comparing if only one is errored 🤔

Put otherwise: if there is only one form field in the page, and it is in error, how do we check the rule?

Copy link
Collaborator Author

@giacomo-petri giacomo-petri May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could either be another field, not in error, in the same form

Comparing a pair of inputs, where one fails and the other does not, is not an optimal approach. Additionally, inputs may have different styles, such as checkboxes or text fields. Therefore, it is advisable to only compare inputs of the same type and with the same CSS.

Put otherwise: if there is only one form field in the page, and it is in error, how do we check the rule?

Limiting the rule to a specific pair of inputs (assuming the previous concern is addressed) would, in my opinion, be too restrictive.

I think we should go with the second option. @Jym77, should we put this rule on hold till #1953 / #2045 are solved?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a list worth bringing to attention that this is another rule proposal that would benefit from being statefull, so that we are sure the solution can handle it.


## Assumptions

When content is communicated using colors that vary not just in hue but also have a substantial difference in brightness, this constitutes an extra visual differentiation provided that the difference in the colors' relative luminance creates a contrast ratio of 3:1 or more.
Comment on lines +42 to +46
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we somehow need to put in the Expectation the fact that "contrast of 3:1 or more" is not a color difference.
We probably need to keep an assumption that this is indeed enough, but we also want to say in the "normative" part that the rule accepts this.


Nonetheless, if content depends on the user's capacity to precisely perceive or distinguish a certain color, an extra visual cue will be necessary, regardless of the contrast ratio between those colors.

## Accessibility Support

There are no major accessibility support issues known for this rule.

## Background

- [Understanding Success Criterion 1.4.1: Use of Color](https://www.w3.org/WAI/WCAG21/Understanding/use-of-color.html)
- [F81 - Failure of Success Criterion 1.4.1 due to identifying required or error fields using color differences only](https://www.w3.org/WAI/WCAG21/Techniques/failures/F81.html)

It is possible for an error field to be distinguishable from adjacent fields but still not have a meaningful error message. In that case, it would pass Success Criterion 1.4.1: Use of Color but still fail [Success Criterion 3.3.1: Error Identification](https://www.w3.org/WAI/WCAG21/Understanding/error-identification.html) and, if applicable, [Success Criterion 3.3.3: Error Suggestion](https://www.w3.org/WAI/WCAG21/Understanding/error-suggestion.html).

Although a contrast ratio of 3:1 or more resulting from a difference in color may suffice, employing supplementary visual indicators is considered a best practice.

## Test Cases

### Passed

#### Passed Example 1

The "first name" `input` value is empty. Its [form field error indicator][] (the `p` element) conveys the presence of an error through its text.

```html
<label for="first_name">First Name</label>
<input type="text" id="first_name" autocomplete="given-name" required style="border:1px solid #dd0000" aria-invalid="true" aria-errormessage="first_name_error_msg">
<p id="first_name_error_msg" class="error_msg" style="color:#dd0000">This field is empty. Enter your first name.</p>
<label for="last_name" style="color:#333333">Last Name</label>
<input type="text" id="last_name" autocomplete="family-name" required style="border:1px solid #b0b0b0" value="Doe">
```

#### Passed Example 2

The "phone number" `input` value doesn't match the `type` value. Its [form field error indicator][] (the first couple of `label` and `input` elements) conveys the presence of an error through its CSS properties:
- `font-weight: bold`; and
- `border-width: 3px`.

```html
<label for="phone_number" style="color:#dd0000; font-weight:bold">Phone number</label>
<input type="tel" id="phone_number" autocomplete="tel" required style="border:3px solid #dd0000" aria-invalid="true" value="John Doe">
<label for="email" style="color:#333333">Email</label>
<input type="email" id="email" autocomplete="email" required style="border:1px solid #b0b0b0" value="john.doe@example.com">
```

#### Passed Example 3

The email `input` value is missing the "@" symbol. Its [form field error indicator][] (the first couple of `label` and `input` elements) conveyed the presence of an error through its lightness (difference in relative luminance between the colors leads to a contrast ratio greater than 3:1).

```html
<label for="email" style="color:#dd0000">Email</label>
<input type="email" id="email" autocomplete="email" required style="border:1px solid #dd0000" aria-invalid="true" value="john.doeexample.com">
<label for="address" style="color:#000">Address</label>
<input type="text" id="address" autocomplete="address-line1" required style="border:1px solid #000" value="5th Example Street">
```

#### Passed Example 4

This `input` element does not have a [form field error indicator][].

```html
<label for="first_name" style="color:#000;">First Name</label>
<input type="text" id="first_name" autocomplete="given-name" required style="border:1px solid #000" value="John">
<label for="last_name" style="color:#000">Last Name</label>
<input type="text" id="last_name" autocomplete="family-name" required style="border:1px solid #000" value="Doe">
```

### Failed

#### Failed Example 1

The "first name" `input` value is empty. Its [form field error indicator][] (the red border color of the first `input` element) conveys the presence of an error through color (hue) differences only.

```html
<label for="first_name" style="color:#333333">First Name</label>
<input type="text" id="first_name" autocomplete="given-name" required style="border:1px solid #dd0000" aria-invalid="true">
<label for="last_name" style="color:#333333">Last Name</label>
<input type="text" id="last_name" autocomplete="family-name" required style="border:1px solid #b0b0b0" value="Doe">
```

#### Failed Example 2

The "phone number" `input` value doesn't match the `type` value. Its [form field error indicator][] (the red color of the first `label` element) conveys the presence of an error through color (hue) differences only.

```html
<label for="phone_number" style="color:#dd0000">Phone number</label>
<input type="tel" id="phone_number" autocomplete="tel" required style="border:1px solid #b0b0b0" aria-invalid="true" value="John Doe">
<label for="email" style="color:#333333">Email</label>
<input type="email" id="email" autocomplete="email" required style="border:1px solid #b0b0b0" value="john.doe@example.com">
```

#### Failed Example 3

The email `input` value is missing the "@" symbol. Its [form field error indicator][] (for the first couple of `label` and `input` elements, respectively the red text color and the red border color) conveys the presence of an error through color (hue) differences only.

```html
<label for="email" style="color:#dd0000">Email</label>
<input type="email" id="email" autocomplete="email" required style="border:1px solid #dd0000" aria-invalid="true" value="john.doeexample.com">
<label for="address" style="color:#333333">Address</label>
<input type="text" id="address" autocomplete="address-line1" required style="border:1px solid #b0b0b0" value="5th Example Street">
```

### Inapplicable

#### Inapplicable Example 1

There are no elements with any of the required [semantic roles][semantic role].

```html
<p>This is a paragraph.</p>
```

#### Inapplicable Example 2

These `input` elements are not [visible][].

```html
<div style="display:none">
<label for="phone_number" style="color:#dd0000">Phone number</label>
<input type="tel" id="phone_number" autocomplete="tel" required style="border:1px solid #b0b0b0" aria-invalid="true" value="John Doe">
<label for="email" style="color:#333333">Email</label>
<input type="email" id="email" autocomplete="email" required style="border:1px solid #b0b0b0" value="john.doe@example.com">
</div>
```

[form field error indicator]: #form-field-error-indicator 'Definition of Form Field Error Indicator'
[html element]: #namespaced-element 'Definition of HTML Element'
[semantic role]: #semantic-role 'Definition of semantic role'
[visible]: #visible 'Definition of Visible'