Suppose I have a list of article previews on my homepage with the following design:
where there's an image to the left with all of the content to the right (region, date, title, abstract, and a Read More button that isn't in the image). How would you go about writing this semantically and accessible to screen readers?
Typically I would do something like this:
<article>
<img class="image" src="path/to/image" alt="appropriate alt text">
<div class="content">
<div class=""info>
<span class="region">Europe</span>
<time class="date" pubdate>Date</time>
</div>
<h2 class="title">Article Title</h2>
<p class="abstract">Abstract of article...</p>
Read More
</div>
</article>
But, I feel like this could be more semantic and accessible for screen readers. One thought I had was doing something like this:
<article>
<img class="image" src="path/to/image" alt="appropriate alt text">
<div class="content">
<h2 class="title">Article Title</h2>
<div class=""info>
<span class="region">Europe</span>
<time class="date" pubdate>Date</time>
</div>
<p class="abstract">Abstract of article...</p>
Read More
</div>
</article>
and since I have .content as a flex container, I can change the visual order of the children like so:
.content {
display: flex;
}
.info {
order: -1;
}
This way a screen reader will read the title of the article before reading the region and date. Does this make sense? I'm trying to become more familiar with semantic and accessibility best practices.
Similarly, would it make sense to change the DOM order of the image and the rest of the content. Like so:
<article>
<div class="content">
<h2 class="title">Article Title</h2>
<div class=""info>
<span class="region">Europe</span>
<time class="date" pubdate>Date</time>
</div>
<p class="abstract">Abstract of article...</p>
Read More
</div>
<img class="image" src="path/to/image" alt="appropriate alt text">
</article>
And then change the visual order:
article {
display: flex;
}
.image {
order: -1;
}
Or would this cause too much confusion? My thought process is that I would like to deliver the most important information of the article to the screen reader first. Are there any reasons to not use this approach? Maybe users are accustomed to image first, content second?
Semantically speaking, is this how you would organize this code? Any improvements that could be made? Maybe wrapping the image in a figure tag?
Any help would be appreciated!
What's the best way to make an heading appear after a related content?
You can use the aria-labelledby attribute to indicate the label of the region
<article aria-labelledby="title1">
<img class="image" src="path/to/image" alt="appropriate alt text">
<div class="content">
<div class="info">
<span class="region">Europe</span>
<time class="date" pubdate>Date</time>
</div>
<h2 class="title" id="title1">Article Title</h2>
<p class="abstract">Abstract of article...</p>
Read More
</div>
</article>
Note that, as the article tag is not announced by NVDA, you may replace the article tag with div[role=region]
I would definitely go with your latest suggestion (the image is last in the DOM and you change the order with FlexBox). This approach is exactly what I do in those situations.
And I don't think you should wrap the image in a figure tag. It would be more confusing.
If you haven't come across it already it might be worth visiting the "Designing for Screen Reader Compatibility" page of the WebAIM website. From that page...
Audio interfaces present content linearly to users, one item at a time. This contrasts with the way in which most people use visual interfaces. Sighted users can scan an entire screen almost instantaneously, comprehending the overall layout, the artistic style, and other macro-level aspects of the content. Screen reader users cannot comprehend these macro-level aspects as quickly.
At the very least the WebAIM "Introduction to Web Accessibility" article should be an obligatory read for every self-respecting web-content creator.
Related
On my web page, I have a long article.
Now an example of how html might look like this (just picture it being a lot longer):
<h1>Page title</h1>
<article>
<h2>Some title></h2>
<p>Content for that title</p>
<h2>Some other title </h2>
<p> some content for that other title </p>
</article>
This pattern continues.
According to WGAC, all headings should be in sequentially descending order, this is an issue here since my article might have more than 5 (h1 - h5) headers. So what can I do as best practice here?
Should each header be included in an <article> or <section> tag or can they be h2 as shown above?
Example
<main>
<h1>Different Front End Technologies</h1>
<p>Introduction...</p>
<section aria-labelledby="h2-html">
<h2 id="h2-html">HTML</h2>
<p>html...</p>
<h3>Sectioning Elements</h3>
<p>fjdfk</p>
<h4>The Header element</h4>
<h4>The Main element</h4>
<h3>Inline Elements</h3>
<p>fdsfa</p>
<h4>The time element</h4>
<h4>The address element</h4>
</section>
<section aria-labelledby="h2-css">
<h2 id="h2-css">CSS</h2>
<p>fdsafdas</p>
<h3>The Cascade</h3>
<h3>CSS Vars</h3>
<h4>The :root selector</h4>
<h4>Using a var in a property</h4>
<h5>Using calc() with a var</h5>
<h6>Example using calc()</h6>
<h6>Gotchyas using var in older browsers</h6>
<h5>var as inline style</h5>
</section>
<section aria-labelledby="h2-JS">
<h2 id="h2-JS">JavaScript</h2>
</section>
</main>
Note how everything under a <h2> is related to that <h2>. Everything under a <h3> is related to that <h3> which is related to the <h2>. This continues down.
When there are subjects not related to each other again you can move back up to the suitable heading level.
"Skipping heading levels" is when you jump from a <h2> to a <h4> - that is the bit that can be confusing for people using a screen reader as they are likely to navigate by headings using shortcuts in their screen reader.
Bonus for screen readers
If you have a really complex document and you are sure you are not over-nesting items, then there are actually 7 heading levels as far as screen readers are concerned.
You can read more about level 7 headings here
I'm trying to write a semantic HTML and also trying to use class names based on BEM methodology.
Before I start the project with completely wrong structure, I just wanted to double check with you if this is right, what I'm doing:
<main>
<article class="card card--light">
<section class="card__wrapper">
<div class="card__image">
an image
</div>
<div class="card__name">
a name
</div>
<div class="card__button">
<button>Click Me</button>
</div>
</section>
</article>
</main>
Is it ok that all sections go inside an article?
Am I doing maybe too many divs?
It's often a good choice to use an <article> tag for card.
There is one error, the HTML5 tag <article> is already creating a section of the page. So there is no meaning of having a <section> as only child. This <section> means "I'm a section of the article", but that's not really the case here. So you should use a simple <div> instead of a <section>.
Globally, be careful with too much HTML5 semantic elements. Using an extra <div> has no bad consequences, this is not true for "sectioning content" tags (<article>, <section>, <nav> and <aside>). For example screen reader will notifiy the visitor for each new section.
I'm reading through the docs of Foundation's Card component and I see that they are using <h4> tags in the cards. For my purpose, I don't need to have my text as a heading and I don't have <h3> on my page so I don't want to be skipping heading levels.
So I'm wondering if it would be good practice from an accessibility point of view to have my text in a <p> tag instead of what they have as <h4> tags in the docs?
Example from Foundation:
<div class="card" style="width: 300px;">
<div class="card-divider">
<h4>I'm featured</h4>
</div>
<img src="assets/img/generic/rectangle-1.jpg">
<div class="card-section">
<p>This card makes use of the card-divider element.</p>
</div>
</div>
What I want to do:
<div class="card" style="width: 300px;">
<div class="card-divider">
<p>I'm featured</p>
</div>
<img src="assets/img/generic/rectangle-1.jpg">
<div class="card-section">
<p>This card makes use of the card-divider element.</p>
</div>
</div>
It's not an automatic accessibility problem if you skip heading levels. There are valid cases where it makes sense but it should only happen rarely.
If you remove the heading from the cards, that will make it harder for screen reader users to find the cards. Screen reading software has shortcut keys to make finding different types of elements on the page easier. In this case, I can navigate to all the headings by using the H key (or on iOS, with VoiceOver, I can set my rotor to "headings" and swipe down to move to the next heading).
I would recommend keeping the headings, even if they skip levels. It's a worse problem not having headings than it is to skip levels.
However, if you have control over generating a <p> instead of an <h4>, do you not have control of changing the <h4> to an <h3>?
I need to make a website accessible for assistive technology. One issue I have is with a block level anchor tag. The code is similar to this:
<a href="/page">
<div class="text">
<h2>Mammals</h2>
<p>We have a large selection of dogs, cats, and hamsters.</p>
<p class="link-description">Explore Mammals</p>
</div>
<div class="image">
<img src="/cat.jpg" alt="Black cat in a tree" />
</div>
</a>
My goal is to have the entire block (The image, heading, paragraph text, and both div's) clickable but for screen readers to read the link as "Explore Mammals" instead of "Mammals We have a large selection of dogs, cats, and hamsters. Explore Mammals Black cat in a tree." In addition, this is a responsive site so the div's are side by side on desktop but stacked on mobile and the two div's animate in when the page is scrolled.
Does anyone have ideas on how to overcome the accessibility issue described?
That is not an accessibility issue, that is a usability issue. Screen readers just happen to be the audience most affected by it.
In this case you can use aria-label on the <a> to override the content within. Depending on your screen reader it may read the image separately but still use the aria-label text.
<a href="/page" aria-label="Explore Mammals">
<div class="text">
<h2>Mammals</h2>
<p>We have a large selection of dogs, cats, and hamsters.</p>
<p class="link-description">Explore Mammals</p>
</div>
<div class="image">
<img src="/cat.jpg" alt="Black cat in a tree" />
</div>
</a>
I have a div containing an event I want it to look like this
[-----] TITLE
[-IMG-] Author
[-----] Date
The way I have it set up now is like this
<div class="book">
<img class="thumb">
<h2>TITLE</h3>
<span>Author</span>
<br />
<span>Date</span>
</div>
I don't think that I should be using <span> for the author and Description since I want them on multiple lines (also doing display:block makes it act weird with the floated element to the left) but I don't know if a <p> tag is suitable since it's only 1 line of text.
What tag should I be using for this?
Thanks!!
Author is a subheader, i would use <h3> as for date the ideal would be to use HTML 5 time tag but this brings some complications in older browsers and IE so i would recommend using <p> if you want the line break.
<div class="book">
<img class="thumb" alt="">
<h2>TITLE</h2>
<h3>Author</h3>
<p>Date</p>
</div>
This elements will give you the line brakes you want and are semantically correct.
P.D: As #Will Martin mentioned it is recommended that you use the alt attribute with the image tag.
Starting with amosriveras answer from 2011, I'd do things different:
HTML 4.01:
<div class="book">
<h2>TITLE</h2>
<img class="thumb" alt="">
<div>Author</div>
<div>Date</div>
</div>
the h2 has to be the first element, otherwise the img would not be part of this heading scope
"Author" is no heading content; also this would mean that the "Date" belongs to the Author heading scope (it should belong to the "TITLE" instead). So use a div instead of a h3 (no, not p, because it is not a paragraph)
"Date" is not a paragraph, so use a div instead of p
HTML5:
<article class="book">
<img class="thumb" alt="">
<h1>TITLE</h1>
<div>Author</div>
<div><time>Date</time></div>
</article>
using article instead of div
now the "TITLE" heading can be placed anywhere in this article; also it can become a h1
using time for "Date"
Using a dl would be possible, too:
<article class="book">
<img class="thumb" alt="">
<h1>TITLE</h1>
<dl>
<dt>Author</dt>
<dd>AUTHOR NAME</dd>
<dt>Date</dt>
<dd><time>DATE</time></dd>
</dl>
</article>
the img could be placed in a dd, for example with a dt "Photo" or something like that (depends on the context). I'd only do that if the image is really relevant to the book/event.
While not strictly paragraphs, I think that the <p> tag is most appropriate here.
You are separating out different, but related, types of information. Just because it isn't in sentence form, doesn't mean it doesn't make some sense to use <p>, with classes for the type of information in them.
Whichever you end up deciding, remember that the design is separate from the elements. That is, the fact that they are on different lines shouldn't be your primary decision point.
After reading #Mazlix's comment on #Amosrivera's answer, I'd like to suggest a definition list.
<dl>
<dt><img class="thumb" alt="book cover" /> TITLE</dt>
<dd class="author">AUTHOR</dd>
<dd class="date>DATE</dd>
</dl>
The styling might get tetchy if you try to a single DL with multiple DT/DD pairs within it, but you could just as easily use a whole bunch of definition lists.
EDIT:
#David Thomas beat me to the punch there. Ah well, c'est la vie.