Rules
Page Structure
- Page Regions in HTML5 Using
WAI-ARIA
<header role="banner">
…
<nav role="navigation">
<ul role="menubar" aria-label="functions" id="appmenu">
<li role="menuitem" aria-haspopup="true">
File
<ul role="menu">
<li role="menuitem">menu 1</li>
<li role="menuitem">menu 2</li>
<li role="menuitem">menu 3</li>
</ul>
</li>
<li role="menuitem">Help</li>
</ul>
</nav>
<form role="search">…</form>
</header>
<main role="main">
<aside role="complementary">…</aside>
…
</main>
<footer role="contentinfo">
…
</footer>
- Using
aria-labelledby
<nav aria-labelledby="regionheading">
<h3 id="regionheading">On this Page</h3>
…ht
</nav>
- Using
aria-label
<nav aria-label="Main Navigation">
…
</nav>
- Provide a ‘Skip to main content’ link.
<a href="#content" class="skipcontent">Skip to content</a>
.skipcontent {
position: absolute;
top: -1000px;
left: -1000px;
height: 1px;
width: 1px;
text-align: left;
overflow: hidden;
background-color: red;
&:active,
&:focus,
&:hover {
left: 0;
top: 0;
width: auto;
height: auto;
overflow: visible;
z-index: 1001;
color: white;
}
}
Menus
- Indicate the current item
// 1.Using invisible text
<li>
<span class="current">
<span class="visuallyhidden">Current Page: </span>
Space Bears
</span>
</li>
// 2.Using WAI-ARIA
// Use the aria-current="page" attribute to indicate the current page in the menu.
<li>
<a href="#main" aria-current="page">
Space Bears
</a>
</li>
Indicate submenus
aria-haspopup="true"
declares that a menu item has a submenu.aria-expanded="false"
declares that the submenu is hidden.
<nav aria-label="Main Navigation">
<ul>
<li><a href="…">Home</a></li>
<li><a href="…">Shop</a></li>
<li class="has-submenu">
<a href="…" aria-haspopup="true" aria-expanded="false">
Space Bears
</a>
<ul>
<li><a href="…">Space Bear 6</a></li>
<li><a href="…">Space Bear 6 Plus</a></li>
</ul>
</li>
<li><a href="…">Mars Cars</a></li>
<li><a href="…">Contact</a></li>
</ul>
</nav>
Additional markup
menubar
: Represents a (usually horizontal) menu bar.menu
: Represents a set of links or commands in a menu bar, it is used for the fly-out menus.menuitem
: Represents an individual menu item.separator
: Represents a separator between two groups of menu items in a menu.
- Each
A
element must contain text or animg
with analt
attribute.
// example 1
<a href="about.html">About Me</a>
// example 2
<a href="/"><img src="logo.png" alt="** logo"></a>
Images
// Informative Images
<li>
<img src="phone.png" alt="Telephone:"> 0123 456 7890
</li>
// Decorative Images example 1
<img src="topinfo_bg.png" alt="">
// Decorative Images example 2
<img src="topinfo_bg.png" role="presentation">
// Functional Images
<input type="image" src="searchbutton.png" alt="Search">
// ALT text should not be an image file name. *
Forms
label
elements should not be blank.
// If you want to hide label, you can follow these examples blow.
// Hiding label text
<label class="visuallyhidden">Search:
<input type="text" name="search">
</label>
<button type="submit">Search</button>
// Using aria-label
<input type="text" name="search" aria-label="Search">
<button type="submit">Search</button>
// Using aria-labelledby
<input type="text" name="search" aria-labelledby="searchbutton">
<button id="searchbutton" type="submit">Search</button>
// Using the title attribute
<input title="Search" type="text" name="search">
<button type="submit">Search</button>
- Make sure
placeholder
attributes are not being used in place oflabel
tags
<label>First name:
<input type="text" name="firstname" placeholder="example: John">
</label>
- Group related form elements with
fieldset
and describe the group withlegend
, Important forinput type="radio"
andinput type="checkbox"
<fieldset>
<legend>I want to receive</legend>
<label>
<input type="checkbox" name="newsletter">
The weekly newsletter
</label>
[…]
</fieldset>
Misc
- Language Attribute
<html lang="en">
Add a
title
attribute to eachframe
andiframe
element.No duplicate IDs, Notice for reusable components &
svg
elements,please rechecks their props.Headings should not be empty.
Add
role=alert
for feedbacks
Tools
Articles
Examples
Tests
Test color contrast
Test for different types of color blindness.
Test using a screen reader
Test using keyboard only