Making a search result list (like in Google) is not very hard, if you just need something that works. Now, however, I want to do it with perfection, using the benefits of HTML5 semantics. The goal is to define the defacto way of marking up a search result list that potentially could be used by any future search engine.
For each hit, I want to
order them by increasing number
display a clickable title
show a short summary
display additional data like categories, publishing date and file size
My first idea is something like this:
<ol>
<li>
<article>
<header>
<h1>
<a href="url-to-the-page.html">
The Title of the Page
</a>
</h1>
</header>
<p>A short summary of the page</p>
<footer>
<dl>
<dt>Categories</dt>
<dd>
<nav>
<ul>
<li>First category</li>
<li>Second category</li>
</ul>
</nav>
</dd>
<dt>File size</dt>
<dd>2 kB</dd>
<dt>Published</dt>
<dd>
<time datetime="2010-07-15T13:15:05-02:00" pubdate>Today</time>
</dd>
</dl>
</footer>
</article>
</li>
<li>
...
</li>
...
</ol>
I am not really happy about the <article/> within the <li/>. First, the search result hit is not an article by itself, but just a very short summary of one. Second, I am not even sure you are allowed to put an article within a list.
Maybe the <details/> and <summary/> tags are more suitable than <article/>, but I don't know if I can add a <footer/> inside that?
All suggestions and opinions are welcome! I really want every single detail to be perfect.
1) I think you should stick with the article element, as
[t]he article element represents a
self-contained composition in a
document, page, application, or site
and that is intended to be
independently distributable or
reusable [source]
You merely have a list of separate documents, so I think this is fully appropriate. The same is true for the front page of a blog, containing several posts with titles and outlines, each in a separate article element. Besides, if you intend to quote a few sentences of the articles (instead of providing summaries), you could even use blockquote elements, like in the example of a forum post showing the original posts a user is replying to.
2) If you're wondering if it's allowed to include article elements inside a li element, just feed it to the validator. As you can see, it is permitted to do so. Moreover, as the Working Draft says:
Contexts in which this element may be
used:
Where flow content is expected.
3) I wouldn't use nav elements for those categories, as those links are not part of the main navigation of the page:
only sections that consist of major navigation blocks are appropriate for the nav element. In particular, it is common for footers to have a short list of links to various pages of a site, such as the terms of service, the home page, and a copyright page. The footer element alone is sufficient for such cases, without a nav element. [source]
4) Do not use the details and/or summary elements, as those are used as part of interactive elements and are not intended for plain documents.
UPDATE: Regarding if it's a good idea to use an (un)ordered list to present search results:
The ul element represents a list of
items, where the order of the items is
not important — that is, where
changing the order would not
materially change the meaning of the
document. [source]
As a list of search results actually is a list, I think this is the appropriate element to use; however, as it seems to me that the order is important (I expect the best matching result to be on top of the list), I think that you should use an ordered list (ol) instead:
The ol element represents a list of
items, where the items have been
intentionally ordered, such that
changing the order would change the
meaning of the document. [source]
Using CSS you can simply hide the numbers.
EDIT: Whoops, I just realized you already use an ol (due to my fatique, I thought you used an ul). I'll leave my ‘update’ as is; after all, it might be useful to someone.
I'd markup it up this way (without using any RDFa/microdata vocabularies or microformats; so only using what the plain HTML5 spec gives):
<ol start="1">
<li id="1">
<article>
<h1>The Title of the Page</h1>
<p>A short summary of the page</p>
<footer>
<dl>
<dt>Categories</dt>
<dd>First category</dd>
<dd>Second category</dd>
<dt>File size</dt>
<dd>2 <abbr title="kilobyte">kB</code></dd>
<dt>Published</dt>
<dd><time datetime="2010-07-15T13:15:05-02:00">Today</time></dd>
</dl>
</footer>
</article>
</li>
<li id="2">
<article>
…
</article>
</li>
</ol>
start attribute for ol
If the search engine uses pagination, you should give the start attribute to the ol, so that each li reflects the correct ranking position.
id for each li
Each li should get id atribute, so that you can link to it. The value should be the rank/position.
One could think that the id should be given to the article instead, but I think this would be wrong: the rank/order could change by time. You are not referring to a specific result but to a result position.
Remove the header
It is not needed if it contains only the heading (h1).
Add rel="external" to the link
The link to each search result is an external link (leading to a different website), so it should get the rel value external.
Remove nav
The category links are not navigation in scope of the article. So remove the nav.
Each category in a dd
You used:
<dt>Categories</dt>
<dd>
<ul>
<li>First category</li>
<li>Second category</li>
</ul>
</dd>
Instead, you should list each category in its own dd and remove the ul:
<dt>Categories</dt>
<dd>First category</dd>
<dd>Second category</dd>
abbr for file size
The unit in "2 kB" should be marked-up with abbr:
2 <abbr title="kilobyte">kB</code>
Remove pubdate attribute
It's not in the spec anymore.
Other things that could be done
give hreflang attribute to the link if the linked result has a different language than the search engine
give lang attribute to the link description and the summary if it is in a different language than the search engine
summary: use blockquote (with cite attribute) instead of p, if the search engine does not create a summary itself but uses the meta-description or a snippet from the page.
title/link description: use q (with cite attribute) if the link description is exactly the title from the linked webpage
Aiming for a 'perfect' HTML5 template is futile because the spec itself is far from perfect, with most of the prescribed use-cases for the new 'semantic' elements obscure at best. As long as your document is structured in a logical fashion, you won't have any problems with search engines (most of the new tags don't have the slightest impact). Indeed, following the HTML5 spec to the letter - for example, using <h1> tags within each new sectioning element - may make your site less accessible (to screen readers, for example). Don't strive for 'perfect' or close-to, because it doesn't exist - HTML5 is not thought-out well enough for that. Just concentrate on keeping your markup logical and uncluttered.
I found a good resource for HTML5 is HTML5Doctor. Check the article archive for practical implementations of the new tags. Not a complete reference mind you, but nice enough to ease into it :)
As shown by the Footer element page, sections can contain footers :)
Related
I have a global navigation for my site which is in the header of all pages. I have marked it up using the <nav> tag.
I also have a navigation present on many individual pages that only apply to that page. So if its a long article, the page navigation lets you paginate sections. This too has been marked up using the <nav> tag.
All pages also have a footer which is almost identical to one at the bottom of StackOverflow's page. There are headings to group navigation links together, some copyright information, and anything else that's interesting.
I don't think its appropriate to also markup the footer's navigation within a <nav> tag because its not intended to be the main navigation for the page or any page. SO have used a table with <th> tags to wrap the headings (and the links are rows underneath) e.g:
<tr>
<th> TECHNOLOGY </th>
</tr>
<tr>
<td>
<ol>
<li>Stack Overflow</li>
<li>Server Fault</li>
<li>Super User</li>
</ol>
</td>
</tr>
With HTML5, I understand that description lists <dl> can be used for name-value pairs. So would the following be allowed/appropriate:
<dl>
<dt> TECHNOLOGY </dt>
<dd> Stack Overflow </dd>
<dd> Server Fault </dd>
<dd> Super User </dd>
</dl>
I can't think of a better way of doing it personally (without using nav + lists), but I also don't want to markup stuff incorrectly (i.e. causing poor semantic value).
If a HTML5 expert could shed some light that would be great.
UPDATE: I've had to make a judgement call and decided that a definition list is still the most semantically appropriate thing to use. Its just my personal judgement because just using a list is meaningless.
According to the official HTML 5 Spec on the <nav> element (emphasis by me):
Not all groups of links on a page need to be in a nav element — the
element is primarily intended for sections that consist of major
navigation blocks. In particular, it is common for footers to have a
short list of links to various pages of a site, such as the terms of
service, the home page, and a copyright page. The footer element alone
is sufficient for such cases; while a nav element can be used in such
cases, it is usually unnecessary.
I think using a <dl> in your case would not be semantically correct, since that element is reserved for association lists, pairing a name/term and a value.
You said it yourself that the footer menu you have is almost identical to Stack Overflow, so if you inspect the code of their menu it is constructed with an ordered list (<ol>).
Personally, I like to use unordered lists for navigation in most cases, and to get a header in your nav, I would suggest a construct like this:
<ul id="footer-menu">
<li>
<strong>TECHNOLOGY</strong>
<ul>
<li>Stack Overflow</li>
<li>Server Fault</li>
</ul>
</li>
</ul>
In this way, each list-item of the "footer-menu" list can be a menu with a heading. Semantically, it is a list of link lists. I made a super-basic fiddle for you to illustrate how it would work: http://jsfiddle.net/psnb6tb9/
I think you have to decide if you want to use heading elements (and sectioning content elements), or not. Both ways are possible. It mostly depends on whether you want the footer content to become part of the document outline.
If yes, your footer would contain a section (possibly multiple, depending on your footer content), with several section as children, e.g.:
<footer>
<section>
<!-- you may use a heading element here, e.g.,
<h1>Sister sites</h1>
-->
<section>
<h1>Technology</h1>
<ul>
<li>Stack Overflow</li>
<li>Server Fault</li>
</ul>
</section>
<section>
<h1>Life / Arts</h1>
<ul>
<li>Photography</li>
<li>Science Fiction & Fantasy</li>
</ul>
</section>
</section>
</footer>
This might especially make sense if the list of sister sites is complex/long, and relevant for your users.
If not, your footer would not contain any heading or sectioning content elements. The dl element seems to be appropriate in this case, e.g.:
<footer>
<dl>
<dt>Technology</dt>
<dd>Stack Overflow</dd>
<dd>Server Fault</dd>
<dt>Life / Arts</dt>
<dd>Photography</dd>
<dd>Science Fiction & Fantasy</dd>
</dl>
</footer>
This might especially make sense if the list of sister sites is not really relevant or important for most of your users (I’d guess Stack Exchange’s footer falls into this category).
However, this is not really suitable if your footer would contain additional "sections" (in which case you probably should use sectioning content elements, i.e., section).
A middle ground would be to use a section/heading only for the whole list of sister sites, not for its sub-sections, e.g.:
<footer>
<section>
<h1>Sister sites</h1>
<dl>
<dt>Technology</dt>
<dd>Stack Overflow</dd>
<dd>Server Fault</dd>
<dt>Life / Arts</dt>
<dd>Photography</dd>
<dd>Science Fiction & Fantasy</dd>
</dl>
</section>
</footer>
This might especially make sense if the sister site list is relevant, but the categorization of these sister sites is not that important.
I'm trying to find the best way to code a search result page in HTML5.
Here's how I've done it.
<section>
<header>
<h2>Results for <kbd>this terms</kbd></h2>
</header>
<!-- list of results -->
<ol>
<!-- First result -->
<li>
<article>
<header>
<h3>
<cite>
This is a result
</cite>
</h3>
</header>
<blockquote cite="http://addressofthepage.ch/">
<p>So, setting about it as methodically as men might smoke out a wasps' nest, the Martians spread this strange stifling vapour over the Londonward country. The horns of the crescent slowly moved apart, until at last they formed a line from Hanwell to Coombe and Malden. All night through their destructive tubes advanced.</p>
<footer>
<p>Published <time datetime="2010-07-15T13:15:05-02:00">MMMM DDth, YYYY</time> at the <abbr title="Uniform Resource Locator">URL</abbr> http://addressofthepage.ch/</p>
</footer>
</blockquote>
</article>
</li>
<!-- Second result ... and so on -->
<li>...</li>
</ol>
</section>
The main questions are
<header> mentions the search terms. What is the best tag to use? <kbd>?
Is the <cite> tag related to the <blockquote> if it is positioned in the <header>?
Is not better to put the <cite> in blockquote > footer like <p>[...] at the URL <cite>http://addressofthepage.ch/</cite></p>
All this is also available on a Gist
is meant as a way to show keys. That's why many sites style that tag as a keyboard key. You're not showing keys, you're showing a search term. A <span> should be fine. Maybe add a class like <span class="search-term">.
Semantically speaking, no, it wouldn't be related as it's not a child.
The "correct" HTML for using cite and blockquote would be:
A quote here...
— Foo Bar
gist here of the HTML: https://gist.github.com/OscarGodson/5a3e87ce895b3af952de (stackoverflow appears to have issues rendering HTML when in code tags?!)
Notice the cite and footer tags. As per spec:
The blockquote element represents content that is quoted from another
source, optionally with a citation which must be within a footer or
cite element, and optionally with in-line changes such as annotations
and abbreviations. Content inside a blockquote other than citations
and in-line changes must be quoted from another source, whose address,
if it has one, may be cited in the cite attribute.
Source: http://www.w3.org/html/wg/drafts/html/master/grouping-content.html#the-blockquote-element
The main thing to remember, and coming from someone who's been doing this for a long, long time, semantics matter, but don't overthink it. Sure, the blockquote has some strict rules about how to properly use it, but browsers will handle whatever you give it fine. Do what makes sense for your app and that should be semantic enough 90% of the time as long as everything isn't a span and div. If you over analyze this stuff you'll spend more time deciding which tag to use instead of just getting stuff done ;)
In a typical index of articles (like a blog without excerpt) like this image:
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
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><!-- news title --></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.
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
This is an opinion question so it comes down to preference.
Based on your image, I would use a <ul> <li> though I could get the same result using divs.
If each item represents an article, then each should be represented using <article> elements.
If you feel that it's an ordered or unordered list of articles, then you could use <ol> or <ul> elements respectively.
I would recommend keeping the markup as simple as possible and as complex as necessary, so something along the lines of:
<div>
<article>
<img>
<div>…</div>
</article>
<article>
<img>
<div>…</div>
</article>
…
</div>
As other people said, I think that each article should be marked with an article tag.
I also suggest to surround the whole list with an aside tag. So If you have one main article in the page (surrounded with main), it will not be affected by the other articles.
Here is a nice article about aside.
Let's say you had something like a TV show listing, where you had a show title, and a show description. You want the listing to be accessible for people with disabilities as well.
Would it make more sense to use a definition list:
<dl>
<dt>...title...</dt><dd>...description...</dd>
...
</dl>
Or an unordered list with headings?
<ul>
<li><h3>...title...</h3><p>...description...</p></li>
...
</ul>
Which makes more semantic sense and will respond better to screen readers? (knowing that they can both be styled the same way)
If you are using HTML 4.01, you shouldn't use dl as it's defined as "definition list" (and your example does not consist of terms and their definitions). If you are using HTML5, the use of dl is fine, because the definition of dl changed.
Using headings inside of li might be a bit problematic regarding the document outline. The scope of a heading would include the start of the next li: <li><!--scope start--><h3>title</h3><p>description</p></li><li><!--scope end--><h3>…. By using section (resp. article), this could be avoided.
So, for HTML5, I think the following ways are possible:
dl
<dl>
<dt>Title1</dt>
<dd>Description1</dd>
<dt>Title2</dt>
<dd>Description2</dd>
</dl>
That would be my favorite, if you only want to provide title and description for each show (if not, see the last example).
ul + section
<ul>
<li>
<section>
<h1>Title1</h1>
<p>Description1</p>
</section>
</li>
<li>
<section>
<h1>Title2</h1>
<p>Description2</p>
</section>
</li>
</ul>
I don't like that very much. The list isn't adding much here, so why not omit it? (see next example)
headings only
<section>
<h1>Title1</h1>
<p>Description1</p>
</section>
<section>
<h1>Title2</h1>
<p>Description2</p>
</section>
Instead of section the article element might be possible, too.
You could also omit section (or article) and use headings only (in the case of section it wouldn't change the meaning); in that case you'd need to apply the correct heading level.
headings + dl
If you want to provide additional metadata (maybe in the future), I'd go with the following markup:
<section>
<h1>Title1</h1>
<dl>
<dt>Description</dt>
<dd>…</dd>
<dt>Rating</dt>
<dd>…</dd>
<dt>Time</dt>
<dd>…</dd>
<dt>Length</dt>
<dd>…</dd>
</dl>
</section>
I prefer the former. First, it seems to make more sense to me just based on the content.
But that's me. I think the markup should reflect the document structure, and since (as you say) the CSS can style it either way, why not make the markup reflect the content? A list containing items that contain a header for a title, followed by a description seems a bit of overkill to me.
But, hey. You know what they say about opinions.
In this case using a Definition list makes much more sense. Aside from this though, is it really necessary to use a list at all? It may make more sense just to use your Heading tags appropriately on the page wit a tag (x= 2-6) and have everything apply under the header of that. TV Shows in specific it may not make sense to use a "List" to display them with definitions or anything else. Again, they can be styled however, so i'm only worried about sematics with this.
Hope this helps
Zach
using HTML5, would it be semantically correct to place an <article> element within a <li> element. A situation where this would prove useful is a list of recent or popular articles on a blog. Consider the following:
<section id="popular">
<div class="blurb">
<h2>Popular Articles</h2>
<p>The most popular posts from my blog.</p>
</div>
<ul>
<li>
<article>
<h3>Article</h3>
<p>An excerpt from the article.</p>
</article>
</li>
<li>
<article>
<h3>Article</h3>
<p>An excerpt from the article.</p>
</article>
</li>
<li>
<article>
<h3>Article</h3>
<p>An excerpt from the article.</p>
</article>
</li>
</ul>
</section>
Which would appear as follows:
Popular Articles
The most popular posts from my blog.
Article
An excerpt from the article.
Article
An excerpt from the article.
Article
An excerpt from the article.
To me, this seems an excellent way of marking up the information. My only question is if it is correct to nest the <article> element inside the <li> element in this way.
There is nothing semantically incorrect about it, but it is not really necessary. The <ul> and <li> elements aren't really adding anything here, unless you are taking advantage of their default styling. Simply putting the <article> tags directly within the <section id="popular"> should be sufficient, and it reduces the complexity of your page as well as its size.
To determine whether something is semantically correct and useful in HTML, ask yourself a few questions. Are you using each element for its intended purpose? For instance, it's not semantically correct if you use an <a> element for a button, as <a> is for hyperlinks, <button> is for buttons. Do you need each element you are using in order to convey all of the semantic information about your content (sections, headings, links, etc)? Is there anything meaningful that you intend to convey that isn't expressed by use of appropriate elements? Having lots of extra meaningless elements usually isn't harmful, but it adds clutter, and it may mean that there are semantic distinctions you are conveying visually but not encoding in a way that a screen reader or automated bot or browser that presented the information in a different format could make sense of.
If it displays correctly in all implementations, I don't have any idea why it would be incorrect... HTML5 is meant to be flexible. Also, the documentation states:
Contexts in which this element can be
used:
Where flow content is expected.
Which looks to be the context of most elements available.