Skip to main content

Don’t meddle with user input

Posted in Accessibility and Design

A big part of my role involves coaching designers and developers to produce more accessible work; not once have I spoken to someone who’s actively trying to make the people’s experiences worse. Every idea comes from a good place, and one I encounter frequently is limiting the characters a user can type in a form field.

Every time this comes up I refer to one of my favourite GitHub Issues, where the following suggestion is made for the GOV.UK Date Input component:

Date fields currently allow users to enter as many characters as they want but day and month input values should be at most 2 characters long, and year input fields at most 4 characters long. This could be made clearer and more user friendly with the maxlength attribute.

Hanna Laakso responds:

If you use maxlength attribute on a form field to limit user input, users might not receive appropriate feedback of the limit. For instance, the user might not notice that not all the information they entered appeared in the form field … It is generally better to let users enter their information in a way that suits them and allow them to submit the form.

Hanna then goes on to suggest using hint text to help the user to enter the date in the right format, and validation to tell the user how to fix the problem in any particular form field. This should also help satisfy 3.3.2 Labels or Instructions and 3.3.3 Error Suggestion, respectively, from the Web Content Accessibility Guidelines (WCAG).

Sometimes the things we think might help a user achieve a task actually get in the way. Worse, things like maxlength affect user input, so we can’t be absolutely sure that the information we have received is what was intended.

Accessibility in your inbox

I send an accessibility-centric newsletter on the last day of every month, containing:

  • A roundup of the articles I’ve posted
  • A hot pick from my archives
  • Some interesting posts from around the web

I don’t collect any data on when, where or if people open the emails I send them. Your email will only be used to send you newsletters and will never be passed on. You can unsubscribe at any time.

More posts

Here are a couple more posts for you to enjoy. If that’s not enough, have a look at the full list.

  1. Images as the first thing in a button or link

    If the text of an interactive element like a button or link is preceded with an accessible image, we’ve probably got an accessibility problem.

  2. Alt text for CSS generated content

    There’s an interesting feature in Safari 17.4 that allows content added with CSS to have ‘alt’ text. I’m not sure how I feel about this.