What's the neatest way to caption images on the web using the latest in HTML/CSS? Demo code please.
There are several semantic ways to markup an image and its caption.
An old school method is to use HTML definition lists, see Image captions the semantic way. (There are other nice tutorials demonstrating this method.)
<dl>
<dt><img src="foo.jpg" /></dt>
<dd>Foo</dd>
</dl>
There is also a figure microformat which applies on any regular markup:
<div class="figure">
<img class="image" src="foo.jpeg" alt="" /><br/>
<small class="legend">Foo</small>
</div>
And HTML5 now provides a clean straight method for images with captions through the <figure>
and <figcaption>
elements.
<figure>
<img src="foo.jpg" alt="">
<figcaption>Foo</figcaption>
</figure>
I know I've seen a number of articles with some good code over at www.alistapart.com - but here's one to start you off: http://www.alistapart.com/articles/practicalcss/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With