Markeee Markeee - 8 months ago 41
HTML Question

Can we use <figcaption> on images without using <figure>

I am converting my website to use HTML5 semantic elements. I have lots of portfolio pages, containing lots of images. Each image has a caption, like this:

<img ... >
<p class="caption">... </p>

Can I replace the
tag and class with
without having to wrap the image and the caption in a

Wrapping all the images and captions in a
element will be a pain for me to do, and adds extra (unnecassary) code.

seems like semantically better than using a
tag with a class.

The images are not directly referenced by the main text on the page, so using
isn't strictly necassary or needed (and as I've said I'm loath to spend the time doing this and feel it adds to code bloat).

This is obviously a very different question to: "Can a element contain only a without an image?"

Answer Source

You can, but it wouldn't be valid HTML. The specs say the parent must be a <figure>:

Permitted parent elements: A <figure> element; the <figcaption> element must be its first or last child.