Putting HTML elements to use
It's time to practice using some of the elements we have just looked at. Let's revisit the example from Chapter 1. If we compare the following markup to the original markup in Chapter 1 (remember, you can download all the examples from http://rwd.education) you can see where the new elements we've looked at have been employed:
<article>
<header class="Header">
<a href="/" class="LogoWrapper"
><img src="img/SOC-Logo.png" alt="Scone O'Clock logo"
/></a>
<h1 class="Strap">Scones: the most resplendent of snacks</h1>
</header>
<section class="IntroWrapper">
<p class="IntroText">
Occasionally maligned and misunderstood; the scone is a quintessentially British classic.
</p>
<figure class="MoneyShot">
<img class="MoneyShotImg" src="img/scones.jpg" alt="Incredible scones" />
<figcaption class="ImageCaption">
Incredible scones, picture from Wikipedia
</figcaption>
</figure>
</section>
<p>Recipe and serving suggestions follow.</p>
<section class="Ingredients">
<h3 class="SubHeader">Ingredients</h3>
</section>
<section class="HowToMake">
<h3 class="SubHeader">Method</h3>
</section>
<footer>
Made for the book,
<a href="http://rwd.education"
>'Responsive web design with HTML5 and CSS'</a
>
by
<address><a href="http://benfrain">Ben Frain</a></address>
</footer>
</article>
I've removed a good portion of the inner content so we can concentrate on the structure. Hopefully you will agree that it's easy to discern different sections of markup from one another. However, at this point I'd also like to offer some pragmatic advice; it isn't the end of the world if you don't always pick the correct element for every single given situation.
For example, whether or not I used a <section>
or <div>
in the earlier example is of little real consequence. If we use an <em>
when we should actually be using an <i>
, I certainly don't feel it's a crime against humanity; the folks at the W3C won't hunt you down and tar and feather you for making the wrong choice. Just apply a little common sense. That said, if you can use elements like the <header>
and <footer>
when relevant, there are inherent accessibility benefits in doing so. IÂ certainly think you're better than using nothing but div
elements in your markup!