Understanding WCAG SC 3.3.1 Error Identification
Version and Level: 2.0/2.1/2.2 (Level A)

WCAG SC 3.3.1 requires that when an input error is automatically detected, the item in error is identified, and the error is described to the user in text. This helps ensure that users can understand and correct errors effectively.

Benefits:

  1. Enhanced User Experience: Clear error messages help users quickly identify and correct mistakes, improving their overall experience.
  2. Accessibility: Ensures that users with disabilities, particularly those using assistive technologies, can understand and resolve input errors effectively.
  3. Reduced Frustration: Specific error messages prevent user frustration by providing clear guidance on how to fix the issues.

Main Objective:

To ensure users can effectively identify and correct mistakes, provide clear error messages or alternatives when an input error is detected. Using color or icons to indicate errors is acceptable, but text error messages are compulsory.

Users may inadvertently input incorrect data, such as an invalid email address or text in a numeric field, when completing tasks like submitting a form on a website.

The method of conveying error messages should accommodate user preferences and ensure accessibility for all users, including those with visual impairments or using assistive technologies like screen readers.

Authors can use client-side scripting or server-side code to detect errors either before form submission or immediately after a user leaves an input field.

The placement of error messages can vary, including inline near the input field, in a dialog, as an alert message, at the beginning of the form, or after the form. This success criterion does not prescribe a specific display method but requires that errors are communicated to users in text or a text alternative.

Error message placement should ensure accessibility for visually impaired users, achieved by incorporating ARIA attributes such as role="alert", role="alertdialog", aria-live, aria-atomic, and aria-describedby, depending on the method used to display the messages.

For instance, when employing role="alertdialog" for an error message, focus should immediately shift to the first interactive element in the dialog, and it should remain trapped inside until the user exits the dialog. Upon dismissal of the dialog, focus must return to the last focused element within the document.

Best Practices:

  • Text-Based Errors: Ensure all error messages are provided in text. If errors are indicated only by color or icons, ensure text accompanies.

  • Use of ARIA Attributes: Use the necessary Aria Attributes depending on the method the error message is displayed. Use ,role="alert", aria-live="assertive",and aria-atomic to ensure that messages are immediately perceived and understood by visually impaired users. If the method the message is displayed is via a dialog, use role="alertdialog" and aria-modal="true" to emphasize the urgency of the dialog message and ensure proper interaction.

  • Optimal Placement and Relationship of Error Messages in Forms: Error messages positioned at the top, before, or at the bottom of the form should directly relate to corresponding input fields. Consider using anchor tags to wrap each error message (e.g., <a href="#email-address">Email address is required</a>) that direct to the invalid input field. Use aria-describedby to establish an association between the error message and the field.

  • Focus Redirection: After invalid form submission, ensure focus shifts either to the first invalid field or the error messages block. Ensure screen reader users are alerted to errors.

Examples & Explanation:

Example: A webpage contains a visual link which can be activated and interacted by users.

What Should Be Avoided

A login form is available for accessing a web application. If a user submits the form with any empty or incorrect input values, the corresponding field will be highlighted with a red border.

HTML/CSS

              <!DOCTYPE html>
              <html lang="en">
              <head>
                <meta charset="UTF-8">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <title>Incorrect form validation Implementation</title>
                <style>
                  .invalid {
                    border: 1px solid red;
                  }
                </style>
              </head>
              <body>
                <form name="signup" id="signup">
                  <div>
                    <label for="username">Username (required)</label><br>
                    <input type="text" name="username" id="username">
                  </div>
                  <div>
                    <label for="password">Password (required)</label><br>
                    <input type="password" name="password" id="password">
                  </div>
                  <div>
                    <label for="confirmPassword">Confirm Password (required)</label><br>
                    <input type="password" name="confirmPassword" id="confirmPassword">
                  </div>
                  <div>
                    <input type="submit" name="button" id="button" value="Submit">
                  </div>
                </form>
              
                <script>
                  document.addEventListener('DOMContentLoaded', function() {
                    var form = document.getElementById('signup');
                    form.addEventListener('submit', function(event) {
                      event.preventDefault(); // Prevent form submission
              
                      // Remove existing error styles
                      var invalidFields = document.querySelectorAll('.invalid');
                      invalidFields.forEach(function(field) {
                        field.classList.remove('invalid');
                      });
              
                      // Check each input field for validity
                      var username = document.getElementById('username').value.trim();
                      var password = document.getElementById('password').value.trim();
                      var confirmPassword = document.getElementById('confirmPassword').value.trim();
                      var isValid = true;
              
                      if (username === '') {
                        document.getElementById('username').classList.add('invalid');
                        isValid = false;
                      }
                      if (password === '') {
                        document.getElementById('password').classList.add('invalid');
                        isValid = false;
                      }
                      if (confirmPassword === '') {
                        document.getElementById('confirmPassword').classList.add('invalid');
                        isValid = false;
                      }
                      if (password !== confirmPassword) {
                        document.getElementById('password').classList.add('invalid');
                        document.getElementById('confirmPassword').classList.add('invalid');
                        isValid = false;
                      }
              
                      // Optionally, you can add more validation logic here
              
                      // If there are errors, prevent form submission
                      if (!isValid) {
                        return false;
                      }
              
                      // If no errors, you can optionally submit the form
                      // form.submit(); // Uncomment this line to submit the form
                    });
                  });
                </script>
              </body>
              </html>
                

Explanation:This approach lacks a direct and accessible method for users to identify and correct errors. Relying only on color to indicate errors means users who cannot perceive visual cues will struggle to understand the form's feedback. This approach does not meet success criteria 3.3.1 for error identification as it does not provide alternative methods for conveying errors to all users, including those relying on assistive technologies.

What Should Be Done

A login form is available for accessing a web application. If a user submits the form with any empty or incorrect input values, a text message will appear at the top of the form. This message will include ARIA attributes to ensure users relying on assistive technology can also perceive the error messages.

HTML/CSS

              <!DOCTYPE html>
              <html lang="en">
              <head>
                <meta charset="UTF-8">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <title>Document</title>
              </head>
              <body>
              
                <form name="signup" id="signup">
                  <div id="errors" role="alert" aria-atomic="true"></div>
                  <div>
                    <label for="username">Username (required)</label><br>
                    <input type="text" name="username" id="username" aria-describedby="username-error">
                  </div>
                  <div>
                    <label for="password">Password (required)</label><br>
                    <input type="password" name="password" id="password" aria-describedby="password-error">
                  </div>
                  <div>
                    <label for="confirmPassword">Confirm Password (required)</label><br>
                    <input type="password" name="confirmPassword" id="confirmPassword" aria-describedby="confirmPassword-error">
                  </div>
                  <div>
                    <input type="submit" name="button" id="button" value="Submit">
                  </div>
                </form>
              
                <script>
                  document.addEventListener('DOMContentLoaded', function() {
                    var form = document.getElementById('signup');
                    form.addEventListener('submit', function(event) {
                      event.preventDefault(); // Prevent form submission
              
                      var errorsElement = document.getElementById('errors');
                      errorsElement.innerHTML = ''; // Clear previous error messages
              
                      // Check each input field for validity
                      var username = document.getElementById('username').value.trim();
                      var password = document.getElementById('password').value.trim();
                      var confirmPassword = document.getElementById('confirmPassword').value.trim();
              
                      var firstInvalidField = null; // Track the first invalid field
                     
                      if (username === '') {
                        errorsElement.innerHTML += '<p id="username-error">Please enter a username.</p>';
                        if (!firstInvalidField) {
                          firstInvalidField = document.getElementById('username');
                        }
                      }
                      if (password === '') {
                        errorsElement.innerHTML += '<p id="password-error">Please enter a password.</p>';
                        if (!firstInvalidField) {
                          firstInvalidField = document.getElementById('password');
                        }
                      }
                      if (confirmPassword === '') {
                        errorsElement.innerHTML += '<p id="confirmPassword-error">Please confirm your password.</p>';
                        if (!firstInvalidField) {
                          firstInvalidField = document.getElementById('confirmPassword');
                        }
                      }
                      if (password !== confirmPassword) {
                        errorsElement.innerHTML += '<p id="confirmPassword-error">Passwords do not match.</p>';
                        if (!firstInvalidField) {
                          firstInvalidField = document.getElementById('password');
                        }
                      }
              
                      // Optionally, you can add more validation logic here
              
                      // If there are errors, prevent form submission and focus on the first invalid field
                      if (errorsElement.innerHTML !== '' && firstInvalidField) {
                        firstInvalidField.focus();
                        return false;
                      }
              
                      // If no errors, you can optionally submit the form
                      // form.submit(); // Uncomment this line to submit the form
                    });
                  });
                </script>
              
              </body>
              </html>
                

Explanation:By providing text-based error messages, users can clearly understand what specific issues are invalid without needing to infer them themselves. These error messages are dynamically injected into an empty HTML paragraph, predefined in the source code. Each error message includes aria attributes (aria-describedby) to establish association between the error message and the corresponding input field when the user focuses on an invalid input. Additionally, JavaScript code ensures that the focus shifts to the utmost invalid input field, enhancing usability. The paragraphs containing error messages also have role="alert" and aria-atomic="true" attributes. These attributes ensure that the error messages are announced as soon as the page is redirected or updated, making them immediately perceivable by users relying on assistive technologies. It's important to note that while colors are not utilized in this example, their use is not discouraged as long as a textual message accompanies them, ensuring accessibility for all users.

Next Up

Expand your understanding with SC 3.3.2 - Labels or Instructions. Learn to make labels and instructions clear for all users.

Go to SC 3.3.2