Having a markup like this:
<aside>
<div class="widget">
<h2>Latest news</h2>
<ul>...</ul>
<a>more news</a>
</div>
<div class="widget">
<h2>Choose site theme</h2>
<input type="select" />
</div>
<div class="widget">
<h2>Newsletter subscription</h2>
<form>...</form>
</div>
<div class="widget">
<h2>Related articles</h2>
<ul>...</ul>
</div>
</aside>
Which tag is more appropriate here: <div>
or <section>
?
Is section supposed to be used only inside <article>
tag and never inside <aside>
?
Yes, you may use
section
there.When you use headings, you have "implicit" sections anyway. By using
section
, you can make them explicit, which is encouraged (see last quote).These snippets are semantically equivalent (they have the same outline):
Note: if you don’t provide a heading for the
aside
, the document outline will be different whensection
is used. Which is not a bad thing; I guess that outline is what you typically want anyway. You can play around with gsnedders’ online outliner.Of course you can also have other sectioning elements instead of
section
inside of theaside
(e.g.nav
for the navigation of thataside
, orarticle
for a list of related posts, etc.).Side note: In your case, you might consider using several
aside
elements instead. This can’t be answered in general, it depends on the content, but a rule of thumb could be: Use oneaside
with severalsections
/headings inside, if all these sections are related somehow (i.e. if you could find a heading that describes all these sections). Use severalaside
, if not.So your example could look like:
(And use a container
div
for these, if you need one.)The HTML 5 spec does not prohibit you from using the
section
element inside of anaside
element. Theaside
element is allowed to have flow content inside, and that includes thesection
element.However, even though the
div
element is now, in HTML5, supposed to be the sectioning element of "last resort", usingsection
in this context goes against the intent of the element. From the spec we see:Now, little "sections" of an aside are definitely not something that belong in the outline of the entire document, so the short answer to your question is to use
div
. Alternatively, because your aside looks like it has four "items" inside, you might consider aul
with fourli
s and then style with the ruleaside ul li
.