I would like to create a standard way to provide an image with an alt tag for accessibility and SEO, a descriptive caption, and a separate element for a photographer credit. It appears that only one <figcaption>
is allowed per <figure>
and it must be the first or last element, so that rules out doing this:
<figure>
<img src="https://placedog.net/500/280" alt="a handsome pooch stares at the camera">
<figcaption class="caption">George, the doggo</figcaption>
<figcaption class="photo-credit">Photo: Jane Doe</figcaption>
</figure>
Which of these is best, and why?
1
<figure>
<img src="https://placedog.net/500/280" alt="a handsome pooch stares at the camera">
<div class="photo-credit">Photo: Jane Doe</div>
<figcaption class="caption">George, the doggo</figcaption>
</figure>
2
<figure>
<img src="https://placedog.net/500/280" alt="a handsome pooch stares at the camera">
<figcaption>
<span class="caption">George, the doggo</span>
<span class="photo-credit">Photo: Jane Doe</span>
</figcaption>
</figure>
3
Something else…
3
Answers
I think this is a very personal choice and all your proposals are correct. However, I guess the
figure
component should only accept two children:img
andfigcaption
. I also thinkfigcaption
must only do one thing: show the figure caption. If I need a space to credits, so, I need to implement it.Below my implementation:
I would go with a variation of option 2, where you add punctuation to the contents of the inline elements to make them read better as sentences.
The MDN Web Docs spec describes the
<figure>
element as follows (emphasis mine):Placing the photo credit outside of the
<figure>
(as another answer suggests) would make it no longer “self-contained”, as the credit is an integral part of the photograph. The<figcaption>
element is the most appropriate place for the credit, as long as you word it in such a way that readers won’t confuse it with part of the caption.Using an
<i>
element for the credit can further separate it (both visually and semantically) from the caption, as:I’d probably go with
<cite />
since MDN describes it as follows: