<div> - groups content <section> - groups related content <article> - groups independent, self-contained content
It's used to wrap introductory information or navigation links for its parent tag and works well around content that's repeated at the top on multiple pages.
header shares the embedded landmark feature you saw with
main, allowing assistive technologies to quickly navigate to that content.
header is meant for use in the
body tag of your HTML document. This is different than the
head element, which contains the page's title, meta information, etc.
Similar to header and nav, the footer element has a built-in landmark feature that allows assistive devices to quickly navigate to it. It's primarily used to contain copyright information or links to related documents that usually sit at the bottom of a page.
<body> <header> <h1>Training</h1> <nav> <ul> <li><a href="#stealth">Stealth & Agility</a></li> <li><a href="#combat">Combat</a></li> <li><a href="#weapons">Weapons</a></li> </ul> </nav> </header> <main> <section id="stealth"> <h2>Stealth & Agility Training</h2> <article><h3>Climb foliage quickly using a minimum spanning tree approach</h3></article> <article><h3>No training is NP-complete without parkour</h3></article> </section> <section id="combat"> <h2>Combat Training</h2> <article><h3>Dispatch multiple enemies with multithreaded tactics</h3></article> <article><h3>Goodbye world: 5 proven ways to knock out an opponent</h3></article> </section> <section id="weapons"> <h2>Weapons Training</h2> <article><h3>Swords: the best tool to literally divide and conquer</h3></article> <article><h3>Breadth-first or depth-first in multi-weapon training?</h3></article> </section> </main> <footer>© 2018 Camper Cat</footer> </body>
<form> <fieldset> <legend>Choose one of these three items:</legend> <input id="one" type="radio" name="items" value="one"> <label for="one">Choice One</label><br> <input id="two" type="radio" name="items" value="two"> <label for="two">Choice Two</label><br> <input id="three" type="radio" name="items" value="three"> <label for="three">Choice Three</label> </fieldset> </form>
<p>Master Camper Cat officiated the cage match between Goro and Scorpion <time datetime="2013-02-13">last Wednesday</time>, which ended in a draw.</p>
The WCAG-recommended contrast ratio of 4.5:1 applies for color use as well as gray-scale combinations.
Give Links Meaning by Using Descriptive Link Text¶
Screen reader users have different options for what type of content their device reads. This includes skipping to (or over) landmark elements, jumping to the main content, or getting a page summary from the headings. Another option is to only hear the links available on a page.
Screen readers do this by reading the link text, or what's between the anchor (
a) tags. Having a list of "click here" or "read more" links isn't helpful. Instead, you should use brief but descriptive text within the
a tags to provide more meaning for these users.
Make Links Navigable with HTML Access Keys¶
HTML offers the
accesskey attribute to specify a shortcut key to activate or bring focus to an element. This can make navigation more efficient for keyboard-only users.
HTML5 allows this attribute to be used on any element, but it's particularly useful when it's used with interactive ones. This includes links, buttons, and form controls.
Here's an example:
<button accesskey="b">Important Button</button>
Use tabindex to Add Keyboard Focus to an Element¶
tabindex attribute has three distinct functions relating to an element's keyboard focus. When it's on a tag, it indicates that element can be focused on. The value (an integer that's positive, negative, or zero) determines the behavior.
Certain elements, such as links and form controls, automatically receive keyboard focus when a user tabs through a page. It's in the same order as the elements come in the HTML source markup. This same functionality can be given to other elements, such as
p, by placing a
tabindex="0" attribute on them. Here's an example:
<div tabindex="0">I need keyboard focus!</div>
Note: A negative
tabindex value (typically -1) indicates that an element is focusable, but is not reachable by the keyboard. This method is generally used to bring focus to content programmatically (like when a
div used for a pop-up window is activated), and is beyond the scope of these challenges.
<div tabindex="1">I get keyboard focus, and I get it first!</div> <div tabindex="2">I get keyboard focus, and I get it second!</div>