Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semantic HTML of an articles list

In a typical index of articles (like a blog without excerpt) like this image:

example

those items should be a list (<ul><li>) or just divs?

And also, they should be figure/figcaption? Because would make some sense, but also... picture is part of an artcile not the main content, so maybe title/description is not the caption of the image, but the caption of the article.

what do you think?

EDIT: a live example - https://news.google.com/?hl=en

like image 259
felixjet Avatar asked Oct 10 '13 22:10

felixjet


People also ask

Is Article a semantic tag in HTML?

Semantic HTML elements are those that clearly describe their meaning in a human- and machine-readable way. Elements such as <header> , <footer> and <article> are all considered semantic because they accurately describe the purpose of the element and the type of content that is inside them.

What is semantic HTML explain with example?

Semantic HTML or semantic markup is HTML that introduces meaning to the web page rather than just presentation. For example, a <p> tag indicates that the enclosed text is a paragraph. This is both semantic and presentational because people know what paragraphs are, and browsers know how to display them.

What are semantics tags in HTML?

The HTML semantics refers to the tags that provide meaning to an HTML page rather than just presentation. It makes HTML more comprehensible by better defining the different sections and layout of web pages.


2 Answers

I’d use an article for each snippet (i.e. a news teaser).

Each article contains an h1 element for the heading, an img element for the image, and p element(s) for the text.

As you probably want to link to a full version, you could enclose all elements in one a element (which is allowed in HTML5), or the heading etc. only.

So it could look like:

<article>   <h1><a href="" title=""><!-- news title --></a></h1>   <img src="" alt="" />   <p><!-- news description --></p> </article> 

Only use figure if this image itself should have a separate caption. The news description (here contained in p) usually isn’t the caption for that image.

You may change the order of the article children. Thanks to the way sectioning elements work, the heading doesn’t have to be the first element.

You may use an ul, but it’s not necessary. ol, however, should only be used if the order is really meaningful for understanding the content (i.e. a different order would change the meaning of the document). Typical example: if the items are ranked by relevance (e.g. most relevant teaser at the top), you should use ol.


Regarding your question if the teaser should be an article:

Don’t confuse article (HTML5 element) with the term "article" (English language). article has a separate definition that doesn’t necessarily have something to do with the understanding of the term "article".

The teaser should also be an article – the teaser article and the fulltext article are different articles, although they refer to the same entity.

like image 162
unor Avatar answered Sep 19 '22 09:09

unor


The answers here leave a lot to be desired. The HTML spec has an example of blog post markup with comments inside.

https://www.w3.org/TR/2013/CR-html5-20130806/sections.html#the-article-element

While the accepted answer has copy/pasted the description of how the <article> element is used it does not answer the question asked at all.

Here is the answer from W3.ORG

If you can use a native HTML element [HTML51] or attribute with the semantics and behavior you require already built in, instead of re-purposing an element and adding an ARIA role, state or property to make it accessible, then do so.

Here is the logic I am proceeding with after researching: I have a list of reviews. Each review is ordered by helpful votes. Therefore the first level will be an ordered list since reviews will be ordered by their helpful votes. Otherwise an unordered list would suffice such as the nested comments:

<ol>     <li class="review" role="article"> <!-- reviews ordered by votes-->         <header>             <h2>Review title</h2>         </header>         <p>Review body</p>         <section class="comments">             <ul>                 <li class="comment" role="article"> <!-- comments with votes-->                  </li>             </ul>         </section>     </li> </ol> 

An insightful answer by @Terrill Thompson explains that screen readers are helped by semantic list markup. So yes, a list of <article>'s does make sense. As things become complex he mentions how confusing it can be. This is where ARIA, role and tabindex attributes should absolutely be added and tested.

That answer has a comment directing users to a conversation at W3.ORG. By definition it appears that <article> would not be part of a list where it should be "stand alone content". However the question here, myself and probably you reading this require a deeper answer where article applies to a true list of articles.

Such as:

  • List of blog articles with excerpts
  • Search results
  • Reviews
  • Comments
like image 33
Ben Racicot Avatar answered Sep 20 '22 09:09

Ben Racicot