Most of you won’t believe what I’m about to describe, and would never use heading structure in this way. This post isn’t for you, it’s for the people who believe that it’s OK to wrap several links inside a single heading tag, or in fact use one heading to enclose one or more other elements or types of content .
If you find this difficult to comprehend, you aren’t alone, it came as an enormous surprise to me too, but I’ve recently seen four different sites using one heading to enclose at least one other element.
The problem this causes is that because heading markup is meant to enclose a single entity, a heading, and screen readers announce the beginning, the end and the level of each heading, whatever is inside the opening and closing tags gets announced as a single item.
Example 1: several links inside one heading
When several links are placed inside a heading, tabbing to any of the links causes screen reader announcement of all links, so the user has no idea which link has focus. If you have access to a screen reader check it out yourself.
Link 1 Link 2 Link 3 Link 4
For those without a screen reader, the output when the focus is on Link 1,is “Link 1 Link 2 Link 3 Link 4 heading level 4 link”. Tabbing to the second, third and subsequent links produces identical output.
I believe that the web authors who created the live example, probably wanted to mark up the links to aid navigation. What they should have done is identify the purpose of the links, for instance “Site-wide navigation” and used that as the content for the heading markup, immediately before the first of the links. (Which of course should have been in a list.)
The code that produced this is:
<h4><a href=”#”>Link 1 </a> <a href=”#”>Link 2 </a> <a href=”#”>Link 3 </a> <a href=”#”>Link 4 </a></h4>
Other problems
The above example is among the worst that I’ve come across, but other mixed content within one heading can cause almost as much confusion, Recently encountered instances include:
- Using heading markup to apply a given style to an entire paragraph, including one or more links. This has a similar effect for screen reader users as the multiple links issue, but with the added confusion that the whole paragraph sounds as though it’s a link.
- Including an image within heading markup, alongside the valid heading text, (presumably to help with positioning). Any text value given to the image ALT attribute will be announced as part of the heading, even though it may have nothing to do with it.
- Including a related link within heading markup, for instance a heading “News” and its related “RSS feed” link both inside the opening and closing heading tags. This almost sounds as though it would be a good idea, but it isn’t. The benefit of having the heading, and thus the topic of the RSS link announced when the link has focus, is cancelled by the mis-information that there’s no “News” heading only a heading for “News RSS feed”.
So please just use heading markup for heading content. Not to enclose all of the content covered by the heading, nor for styling, positioning or link context.
Ben 'Cerbera' Millard | 09/10/2008 at 2:15 | Permalink
The accessibility problems with example 1 seem like a bug with the screen reader, to me. If you have focussed a link, surely it should only read out the text for that link? Links are permitted in heading elements.
If the website Example 1 came from was trying to do a navigation list, then I agree that example should be using list markup. You could show what markup that involves to show this point more clearly.
Generally speaking, using headings for things which aren’t headings is a bad idea.
In the numbered list:
1. I agree that should be done as a paragraph. Aural output getting weirded up by incorrect markup is understandable.
2. It’s fine to have an image in a heading if that image has appropriate alt text? For most cases, the alt attribute would be the empty string. But your description makes it sound like a heading must never include an image?
3. If correct punctuation is used then the output should make sense. Generally speaking, “Foo (_Bar_)” should not sound exactly like “_Foo Bar_”.
How about Heading Links work, where the entire text of a heading is a single link? That seems like it would work wonderfully in a screen reader because the heading which has interested you can be followed immediately to the web page about it. (The same reason it works great for sighted users.)
Ben 'Cerbera' Millard | 09/10/2008 at 2:19 | Permalink
This was briefly discussed on #whatwg. Does reading the entire heading’s content when a link in a heading get focus work well most of the time? My initial reaction is that it’s a bug but maybe it provides useful context on some websites you can name?
Ben 'Cerbera' Millard | 09/10/2008 at 22:15 | Permalink
I just found a legitimate use-case for 2 links in a heading. Specifically, it’s the
<h2>that starts “Social network portability”.Jon Gibbins | 27/10/2008 at 10:21 | Permalink
Hi Bim. What screen reader and browser are you using to get these results? I understand the problem, but I cannot replicate it using JAWS 9 and IE 7. As I tab through the links in a single heading I hear “my link text 1 heading level 1 link” then “my link text 2 heading level 1 link” then “my link text 3 heading level 1 link”. dotjay Jon
AlastairC | 02/11/2008 at 23:10 | Permalink
Whilst I agree with comments about the poor markup cases highlighted, this:
“screen readers announce the beginning, the end and the level of each heading, whatever is inside the opening and closing tags gets announced as a single item.”
Sounds like a bug, similar to the bug that created the ‘more than whitespace’ checkpoint from yesteryear.
Richard Warren | 03/11/2008 at 17:21 | Permalink
Headings (h1 to h6) should only contain the relevant text of that heading. We were doing a demo last month with Supernova on an elderly laptop and went to a site that included images in the heading codes. The laptop siezed up and had to be re-booted because the images used up all the available cache when we asked for a list of page headings.
Please keep it simple and use the codes only for what they are supposed to be used for.
Richard