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><a href="first-category.html">First category</a></li>
<li><a href="second-category.html">Second category</a></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
articleelement, asYou 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
articleelement. Besides, if you intend to quote a few sentences of the articles (instead of providing summaries), you could even useblockquoteelements, 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
articleelements inside alielement, just feed it to the validator. As you can see, it is permitted to do so. Moreover, as the Working Draft says:3) I wouldn’t use
navelements for those categories, as those links are not part of the main navigation of the page:4) Do not use the
detailsand/orsummaryelements, 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:
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: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 anul). I’ll leave my ‘update’ as is; after all, it might be useful to someone.