HTML5 aside: Defining relations
Join the DZone community and get the full member experience.Join For Free
together with the new header and footer and article and section elements there is one more important addition to the html5 spec which is bound to improve the structure of our future html documents. the aside element caused some controversy when it was first introduced but now the spec seems to be nearing its final stage. time to find out how the aside element can help us bring more structure to our content.
why the fuzz?
when the aside element was first introduced it raised discussions left and right. while the need for capturing "sidebar"/related-like content was clear, the exact implementation clearly wasn't.
one issue raised lived purely on a semantic level. the word "aside" is easily linked to visual positioning. it's not quite as bad as "sidebar" but it still seems to suggest the content is positioned next to the main content. after fighting for years against style-based classnames front-end developers weren't too happy to see this trend resurface in an official w3c spec.
but there were more glaring issues to tackle. it turned out the original definition of the aside element didn't even qualify as a container for typical sidebar content. it was only meant to hold content directly related to a main block of content. usual sidebars often include contextual information related to the side as a whole, not necessarily to the content on the current page (just think latest news block on a calendar detail page or see the contact block to the right on this very page).
and so the first definition didn't actually cater to the needs and wants of the front-end developer community, making the new element only marginally interesting and possibly creating a lot of confusion along the way. luckily the powers that be were listening and decided to make some changes to the aside element, greatly increasing the sex-appeal of this new html5 elements once again.
the current aside spec
quote the aside element represents content that is tangentially related to the content that forms the main textual flow of a document. unquote
this latest definition opens up many more possibilities but at first glance we might be losing a little specificity compared to the original definition. upon closer inspection though, there's an elegant solution to giving extra meaning to the aside element based on it's context in the document, so no need to worry (just yet).
simple sidebar content
in most cases the aside element will behave as a simple container for sidebar content. note that this still doesn't mean the aside element should be visibly "next to" another element, it simply means the content is tangentially related to the site or page. how tangentially related is still up to you to decide though, so there's still a gray area there.
once you nest the aside element inside an article element though, it transforms a little and it will function as actual contextually related content (fe. related links or related downloads). the content captured by the aside element should be specifically related to the other content inside the article and not only to the site as a whole.
this is a pretty elegant and structurally sound solution to easily differentiate between these two levels of contextual content. an interesting take on typical html semantics that might warrant some further investigation in the future.
so everyone is happy?
well, almost everyone. looking at this very page you'll notice that the sidebar content includes actual related article content (the affiliate ads, the article info) but also typical sidebar content (the contact, archive and related section articles blocks). so if i wanted to follow the current spec, the first few sections should be contained by the article, the other sections should structurally be outside the article. sadly css isn't quite ready for that yet so i'll need to find a way around that. it's more of a design issue though and nothing a better spec could solve (unless you would link content through specific attributes, but that's taking it a little too far).
the new aside element is a gallant way to mark up related content. whether it is directly related or just marginally is dependent on its context, so use it wisely and carefully.
figuring out what content is related and how related it actually is will probably take some experimenting though. hopefully we'll stay clear from previous errors (remember when everything was a list) and i'm still in doubt whether the comments on an article belong in a section, article or aside. like most best practices though, time and testing will help in providing all the answers.
Published at DZone with permission of Niels Matthijs, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.