如何创建可访问的web窗体

null

+$Forms are an essential component of the web because they connect users to your business and help them accomplish what they came to your site or app for. That being said, you want to make sure that all of your users are able to use your forms without having to suffer a horrible experience. The goal is to make these key user interactions as frictionless as possible.

+$Although it's true that building forms can be a difficult task at times, making them moderately accessible isn't as complicated as you might think. There are often excuses thrown around like 'we don't have time to worry about accessibility' or 'we'll make it accessible later'. These excuses are often (if not always) invalid and you can help your team change this mindset.

+$Here are some questions you should consider when building forms:

  • +$What difficulties might someone with visual impairments have using my form?
  • +$Does the user have a clear indication of what data is expected for input?
  • +$Is the form easy to use – will the users be able to understand it quickly?
  • +$Am I able to use the keyboard in order to complete the form?

+$How to make a basic subscription form

+$I've given you some starter code to help you get ahead. We'll+$begin With This+$and Eventually+$get To This

+$I've provided you with some basic styling and elements that would make up a simple subscription form but there's a lot we can do here to make this form more usable. With anything you create, using good semantic HTML will get you a long way.

+$Let's start by connecting the+$elements to their respective+$s. We do this by giving the+$an id and using that as the for attribute for the+$. We can use "name" and "email" for these and we've already done two things:

  1. +$We've programmatically associated the label to the input. The benefit of this is that it will read the label to a screen reader user if that input is focused.
  2. +$The user can now click on the label and the respective input will be focused, so users now have a larger target size.

+$Now that our inputs and labels are all wired up, we can define the HTML input types. These are really useful and a super easy way to give an excellent user experience. Adding the类型+$attribute will help the user auto-fill your form and will also provide a more suitable keyboard for mobile users. For our use case we can do+$type="text"+$for the name input and+$type="email"+$for the email input.

+$We also want our users to have a good idea of what type of data (and its formatting) we expect from them. Here it is pretty obvious but that isn't always the case. It's generally good practice to provide a label that's always viewable and a placeholder that communicates the expected input. This means not using the占位符+$attribute as a visual label for inputs where the label is not viewable once a user begins typing. This has been a popular practice for a lot of developers and really needs to be put to bed once and for all. We can give a placeholder of "ex. Jane Doe" for the name and "ex. jane.doe@example.com" for the email.

+$Now we can get to work on the focus+$styling. The default styling of focus states are different between the browsers and we can improve whatever the default styling might be in order to make it more user friendly. In our case here, we want the inputs to have a thick, coloured outline that matches up with the button.

+$Add focus styles to input selector

+$Lastly, we need to add some focus styles around the button element. This is often overlooked but can really help keyboard-only users know where they are. We need to add this+$&::moz-focus-innner+$bit to get rid of some default styling in Firefox (you might want to save that snippet for future use).

+$Just like that, we have a basic subscription form you can be proud of and improve on. Because we've used good semantics, the form is accessible via keyboard only (try using the tab and spacebar/enter keys). The colours used for the button are a colour ratio of 11.51, meeting the AAA standards for WCAG (Web Content Accessibility Guidelines). We've provided labels for both visual users and screen-reader users, as well as styled focus states for our keyboard-using friends. Finally, notice that the font is set to+$18px+$in the body. This makes our form much more readable (you should try to stay above 14px).

+$Designing and building with accessibility in mind takes practice but you'll be a better developer for it and help make the web a better place.

generate, the award winning conference for web designers, returns to NYC on April 24-25! Click the image to book a ticket 

+$generate, the award winning conference for web designers, returns to NYC on April 24-25! Click the image to book a ticket

+$This article was originally published in issue 316 of,这是全球最畅销的网页设计师和开发者杂志。+$Buy Issue 316 Here要么订阅这里

相关文章:



翻译字数超限