Enquiry form #
Description: An accessible Contact Us or Enquiry form enables users to reach out for support, questions, or feedback without barriers.
Key Accessibility Practices for Contact Us / Enquiry Forms #
- Clear Labels and Instructions:
- Use clear, descriptive labels for each input field (e.g., “Full Name,” “Email Address,” “Message”).
- For fields with specific requirements (like “Enter a valid email address” or character limits for comments), provide helper text linked to the field using
aria-describedby.
- Required Fields and Validation:
- Indicate required fields clearly, using
aria-required="true"or visually with an asterisk (*) and an explanation. - Provide accessible error messages in real-time for invalid input or missing required fields. Use
aria-live="assertive"on error messages to ensure screen reader users receive immediate feedback.
- Indicate required fields clearly, using
- Keyboard Navigation and Focus Management:
- Ensure the form is fully keyboard-accessible, with a logical tab order and visible focus indicators for each field. Users should be able to navigate through the form without needing a mouse.
- Avoid unexpected focus shifts that could disorient users. Keep the focus within the form to guide users through each field and error if needed.
- Descriptive Button Labels:
- Use descriptive text for buttons, such as “Send Message” or “Submit Enquiry,” instead of generic “Submit” labels. This helps all users, including those with cognitive disabilities, understand the button’s purpose.
- Confirmation and Success Feedback:
- Upon successful submission, display a confirmation message in a polite live region (
aria-live="polite") to inform screen reader users that their message was received. - Consider redirecting users to a “Thank you” page or clearing the form fields to confirm the submission.
- Upon successful submission, display a confirmation message in a polite live region (
Here’s an example of an accessible Contact Us or Enquiry form that follows these accessibility best practices.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Accessible Contact Us Form</title>
<style>
.error-message {color: red;font-size: 0.9em;}
.hidden {display: none; }
.focusable:focus { outline: 3px solid #FFBF00;}
</style>
<script>
function validateContactForm(event) {
event.preventDefault();
let valid = true;
const nameField = document.getElementById('name');
const emailField = document.getElementById('email');
const messageField = document.getElementById('message');
const nameError = document.getElementById('name-error');
const emailError = document.getElementById('email-error');
const messageError = document.getElementById('message-error');
const successMessage = document.getElementById('success-message');
// Reset error and success messages
nameError.classList.add('hidden');
emailError.classList.add('hidden');
messageError.classList.add('hidden');
successMessage.classList.add('hidden');
// Validate name
if (nameField.value.trim() === "") {
nameError.classList.remove('hidden');
nameError.setAttribute('aria-live', 'assertive');
valid = false;
}
// Validate email
const emailPattern = /^[^@\s]+@[^@\s]+\.[^@\s]+$/;
if (!emailPattern.test(emailField.value.trim())) {
emailError.classList.remove('hidden');
emailError.setAttribute('aria-live', 'assertive');
valid = false;
}
// Validate message
if (messageField.value.trim() === "" || messageField.value.length < 10) {
messageError.classList.remove('hidden');
messageError.setAttribute('aria-live', 'assertive');
valid = false;
}
// Show success message if valid
if (valid) {
successMessage.classList.remove('hidden');
successMessage.setAttribute('aria-live', 'polite');
nameField.value = "";
emailField.value = "";
messageField.value = "";
}
}
</script>
</head>
<body>
<h1>Contact Us</h1>
<form onsubmit="validateContactForm(event)">
<!-- Name Field -->
<label for="name">Full Name:</label>
<input type="text" id="name" name="name" class="focusable" aria-describedby="name-error" aria-required="true" required>
<div id="name-error" class="error-message hidden">Enter your name.</div>
<!-- Email Field -->
<label for="email">Email Address:</label>
<input type="email" id="email" name="email" class="focusable" aria-describedby="email-error" aria-required="true" required>
<div id="email-error" class="error-message hidden">Enter a valid email address.</div>
<!-- Message Field -->
<label for="message">Message:</label>
<textarea id="message" name="message" class="focusable" aria-describedby="message-error" aria-required="true" required></textarea>
<div id="message-error" class="error-message hidden">Enter a message (at least 10 characters).</div>
<button type="submit" class="focusable">Send Message</button>
</form>
<!-- Success Message -->
<div id="success-message" role="status" aria-live="polite" class="hidden">
Thank you! Message has been sent.
</div>
</body>
</html>
Explanation #
- Clear Labels and Required Fields:
- Each field has a
<label>to describe its purpose, making the form accessible for screen reader users. Required fields are marked witharia-required="true"and a red error message appears when required fields are empty or incorrectly filled out.
- Each field has a
- Accessible Error Handling:
- Real-time validation provides immediate feedback if required fields are empty or contain invalid input. The error messages are associated with the input fields via
aria-describedby, allowing screen readers to read error messages along with the input field. Usingaria-live="assertive"on errors ensures they are announced immediately.
- Real-time validation provides immediate feedback if required fields are empty or contain invalid input. The error messages are associated with the input fields via
- Keyboard Navigation and Focus:
- All form fields and buttons are accessible by keyboard, with focus indicators provided by the
.focusableclass, making it easy for keyboard-only users to navigate and interact with the form. - Focus remains within the form, avoiding unexpected shifts that could disorient users, especially those using screen readers.
- All form fields and buttons are accessible by keyboard, with focus indicators provided by the
- Descriptive Button Labels:
- The button is labeled “Send Message” instead of a generic “Submit,” making the action clear to all users, including those with cognitive disabilities.
- Polite Success Feedback:
- Upon successful submission, a polite live region (
aria-live="polite") announces the success message “Thank you! Your message has been sent,” so screen reader users know the form was successfully submitted. - After submission, the form fields are cleared to confirm the submission and indicate the form is ready for a new entry.
- Upon successful submission, a polite live region (
Key Takeaways
- Use Clear Labels and Required Indicators: Each field should have a
<label>for clarity, and required fields should be marked witharia-required="true"or visually indicated with an asterisk and explanation. - Provide Immediate, Accessible Error Feedback: Use
aria-live="assertive"on error messages and associate them with fields usingaria-describedbyto help users understand issues in real-time and correct errors before submission. - Ensure Full Keyboard Accessibility: All form elements should be keyboard-accessible, with logical tab order and clear focus indicators. Avoid focus shifts to keep users oriented within the form.
- Use Descriptive Button Labels: Labels like “Send Message” or “Submit Enquiry” clarify the action’s purpose, improving usability for all users, including those with cognitive disabilities.
- Provide Polite Confirmation Feedback: After successful submission, use a polite live region (
aria-live="polite") for the confirmation message, and consider clearing the fields or redirecting to a “Thank you” page.