Keyboard Accessibility Tips Using HTML and CSS

Making your web site accessible for keyboard-only customers is a vital a part of the larger accessibility image. Listed below are some keyboard accessibility suggestions you may rapidly implement utilizing fundamental HTML and CSS.

A11y From the Starting

The following pointers are a part of Web Accessibility: the Complete Learning Guide, the place we’ve collected a spread of tutorials, articles, programs, and ebooks, that can assist you perceive net accessibility from the start.

What’s Keyboard Accessibility?

A keyboard may be the first means for some customers to navigate web sites. These days, when most net interfaces are designed with mouse cursors and contact interplay in thoughts, keyboard navigation is uncared for. Keyboard accessibility is the observe of creating positive that customers can navigate effectively and unhindered utilizing simply their keyboard.

Who May Want Keyboard Accessibility?

These are the principle goal teams of keyboard accessibility:

  • Customers with motor disabilities who’ve issue utilizing a mouse, utilizing a contact machine, or clicking on small issues.
  • Blind or visually impaired customers steadily desire to navigate web sites with particular Braille keyboards.
  • Amputees or these with congenital amputation (beginning with out a limb or limbs, particularly arms on this case) usually use particular {hardware} mimicking keyboard performance.
  • Anybody who merely doesn’t have entry to a functioning mouse or touchpad.

1. Check Your Website for Keyboard Accessibility

Crucial purpose of keyboard accessibility is to make each interactive factor, akin to hyperlinks and type controls, accessible with the Tab key. That is how keyboard-only customers navigate by an internet web page. Testing your web site for keyboard accessibility is definitely fairly simple: simply press the Tab key and navigate from the highest of the web page to the underside, highlighting energetic parts as you go.

Navigating quick links in the Tuts footer with the Tab keyNavigating quick links in the Tuts footer with the Tab keyNavigating quick links in the Tuts footer with the Tab key
Navigating fast hyperlinks within the Tuts+ footer with the Tab key

Observe how simple or troublesome it’s to get to the principle content material, click on a menu merchandise, fill in a type, function a slider, or observe your present place on the web page. You can even check the reverse route utilizing the Shift + Tab keyboard shortcut.

2. Create Noticeable :focus Kinds

CSS has a :focus pseudo-class that’s triggered when a person clicks or faucets on an merchandise, or selects it with the Tab key. The :focus state solely applies to focusable elements, particularly <a>, <button>, <enter>, <textarea>, <choose>, and <space>.

Each browser comes with its personal default :focus kinds–often a dotted black define across the factor, or a blurred glow, nevertheless many designers discover it to not their style and can utterly take away it. That is really the primary mistake that ruins keyboard accessibility on net pages. If you happen to don’t just like the default kinds, use one thing that matches your web site’s design. 

focus styles in Google Chrome browserfocus styles in Google Chrome browserfocus styles in Google Chrome browser
Default :focus kinds in Google Chrome browser

Select a mode that’s simply noticeable however doesn’t rely solely on colours. Right here’s a doable instance that may work effectively for keyboard-only customers:

:focus {
    define: 3px stable purple;   

3. Use Non-Shade Designators for Hyperlinks

Hyperlinks shouldn’t be distinguished solely by colour. This precept is often talked about in relation to visible accessibility, as folks with low imaginative and prescient discover the variations between sure colours troublesome to discern. Nonetheless, clearly seen hyperlinks are additionally vital for keyboard accessibility. Keyboard-only customers ought to have the ability to spot hyperlinks as rapidly as doable. This helps them scan the web page and work out methods to navigate to the half they’re involved in.

Equally to :focus kinds, hyperlinks additionally include default browser styling— blue underlines usually. Nonetheless, designers steadily take away the underline and solely use colours to point the presence of a hyperlink. If you happen to take away the default underline at all times use another non-color designator that matches your web site design, akin to borders, icons, or outlines.

Clear links on govuk 1 hyperlink 2 focused 3 visitedClear links on govuk 1 hyperlink 2 focused 3 visitedClear links on govuk 1 hyperlink 2 focused 3 visited
Clear hyperlinks on (1) hyperlink (2) centered (3) visited

You should use the title attribute to explain a hyperlink’s content material, nevertheless it solely turns into seen when somebody hovers the hyperlink. Keyboard-only customers don’t have entry to hover occasions, so by no means place essential data within the title attribute. It additionally doesn’t depend as a non-color designator. For instance, by no means do that:

<a href="#" title="Vital data">
    Click on right here

As a substitute, do that:

<a href="#" title="Repetition of Vital Info or addition of some secondary particulars">
    Vital data

WCAG 2.0 additionally warns concerning the accessibility problems of the title attribute. Both use it with care or don’t use it in any respect.

4. Use Native Management Components

Varieties are interactive parts, in order that they should be accessible by way of the keyboard. Keyboard-only customers ought to have the ability to fill in varieties, press buttons, use vary sliders, choose choices, and function controls with ease. In case you have any varieties in your web site it’s best to check them one after the other, utilizing the Tab key. Consider signup varieties, publication varieties, login varieties, remark varieties, buying carts, and so forth.

The easiest way to create accessible varieties is through the use of native management parts wherever it’s doable. Native management parts include built-in keyboard accessibility, that means they’re focusable and reply to keypress occasions by default. They’re as follows:

  • <button>
  • <enter>
  • <textarea>
  • <choose>
  • <possibility>

For instance, you may create a keyboard accessible vary slider with the next HTML:

<enter sort="vary" min="0" max="10">

Keyboard customers can first focus it with the Tab key, then transfer the slider up and down with House

If you must use a non-focusable HTML tag for an interactive factor for some purpose, you can also make it focusable with the tabindex="0" attribute. As an example, right here’s a <div> become a focusable button:

<div position="button" tabindex="0">
    Click on me

The position="button" attribute within the above snippet is an ARIA landmark position. Though keyboard-only customers don’t want it, it’s indispensable for display reader customers and visible accessibility.

Even when the non-native button has been made focusable, it’s nonetheless inferior to its native counterpart when it comes to keyboard accessibility. You’ll perceive this instantly once you attempt to add an occasion handler to the button. Right here’s what a click on occasion listener seems like with the native <button> factor:

<button onclick="alert('Hello, I'm a local button!')">
    Click on me

And, right here’s the equal utilizing the div button:

<div position="button" tabindex="0" onclick="alert('Hello, I'm a non-native button!')">
    Click on me

If you happen to click on the buttons utilizing your mouse or touchpad you may see each alert messages. Nonetheless, if you happen to navigate to every button utilizing the Tab key and hit Enter to course of them, you’ll solely see the primary message, belonging to the native button. To make the non-native button course of the keyboard enter, you additionally have to outline a keypress occasion handler individually:

<div position="button" tabindex="0" onclick="alert('Hello, I'm a non-native button!')" 
onkeydown="alert('Hello, I'm a non-native button!')">
    Click on me

Now, when keyboard customers hit Enter, additionally they see the message belonging to the non-native button. As you may see, it’s a lot simpler and faster to make use of the native model. So, except you’ve got purpose for not utilizing them, at all times use native management parts.

5. Add a “Skip to Fundamental Content material” Hyperlink

Including a Skip to primary content material or Skip navigation hyperlink to your net pages significantly helps keyboard-only customers. Normally, these customers received’t wish to soar by all of the navigation hyperlinks earlier than they start to learn the content material. That is very true after they take a look at multiple web page in your web site. Simply think about, and not using a skip navigation hyperlink, they should undergo the identical navigation hyperlinks on the homepage each time. It doesn’t seem to be a very entertaining exercise.

To create a functioning skip navigation hyperlink, you must bind it to the principle content material utilizing the id and href HTML attributes within the following means:

<a class="skip-main" href="#primary">Skip to primary content material</a>
<primary id="primary" tabindex="-1">Fundamental content material</primary>

You additionally want so as to add the tabindex="-1" attribute to the container of the principle content material. This is identical tabindex we’ve got used above to make the non-native button focusable. The tabindex attribute is used to change the default navigation order. With a worth of 0, it makes non-focusable parts focusable. With a worth of -1, it additionally makes parts focusable however they grow to be non-reachable with default keyboard navigation. Sure browsers, akin to Chrome and IE, require the presence of tabindex="-1" on the goal of the skip navigation hyperlink, so by no means omit it.

Reveal the Skip Hyperlink Solely to Keyboard Customers

You should use CSS to make the skip navigation hyperlink seen just for keyboard customers. In its default state, disguise the hyperlink from common customers by positioning it out of the viewport. Then, reveal it for keyboard customers by creating separate kinds for the main target state that’s triggered when the person hits the Tab key. 

You’ll be able to see this impact in motion on websites like, and (as common)

Reveal the Skip Link Only to Keyboard UsersReveal the Skip Link Only to Keyboard UsersReveal the Skip Link Only to Keyboard Users
Have you ever ever seen this hyperlink earlier than?

The next CSS is a simplified model of the skip navigation code of NC State College’s IT Accessibility Handbook:

a.skip-main {
    left: -999px;
    place: absolute;
    high: auto;
    width: 1px;
    peak: 1px;
    overflow: hidden;
    z-index: -999;
a.skip-main:focus {
    left: auto;
    high: auto;
    width: 30%;
    peak: auto;
    overflow: auto;
    margin: 0 35%;
    padding: 5px;
    font-size: 20px;
    define: 3px stable purple;
    text-align: middle;
    z-index: 999;

When the person hits the Tab key, the .skip-main factor is given its focus state and the skip navigation hyperlink seems on the display. 

You’ll be able to rapidly check the way it works if you happen to click on on the very high of the demo under and hit the Tab key. You could discover it simpler to open the demo below in full page view as a substitute.

Subsequent Steps

On this article, I shared some fundamental keyboard accessibility suggestions which you’ll implement utilizing HMTL and CSS. There are different, extra superior issues you might do for keyboard accessibility as effectively. As an example, you might:

Along with the following pointers, avoid using CAPTCHAs the place doable, as they’ve serious accessibility problems, each for display reader and keyboard-only customers. If you happen to nonetheless want to make use of them, present greater than two methods to unravel them, in any other case customers with accessibility wants will wrestle to course of your varieties. Tell us if in case you have any keyboard accessibility suggestions of your personal!

Trending Merchandise
[product_category category=”trending” per_page=”8″ columns=”2″ orderby=”date” order=”desc”].

We will be happy to hear your thoughts

Leave a reply

Compare items
  • Total (0)