HTML HTML Basics Images, Text and Links Images and File Paths Challenge

Nick Evershed
Nick Evershed
5,536 Points

Caption tag?

What is a caption tag, and how would I add one?

<!DOCTYPE html> <html> <head> <title>The Moon</title> </head> <body> <img src="img/moon.jpg" alt="Moon"> </img> </body> </html>

index.html
<!DOCTYPE html> 
<html>
  <head>
    <title>The Moon</title>
  </head>
  <body>
    <img src="img/moon.jpg" alt="Moon"> </img>
  </body>
</html>
adam n
adam n
57,282 Points

The video before the challenge goes over how to add a caption. Let me know if this helps here

2 Answers

Jonathan Gardner
Jonathan Gardner
8,383 Points

You need to nest the img inside of <figure> tags and add the <figcaption> Tag to specify the caption text. Also img is a self closing tag so you don’t need a </img> closing tag after it.

<figure> <img src=“img/moon.jpg” alt=“Moon”> <figcaption>This is your caption</figcaption> </figure>

leosa
leosa
Pro Student 4,622 Points

I agree with Jonathan. At the beginning, I thought you had meant the <caption> tag not the <figcaption>, but this makes since. By the way, the <figcaption> tag defines a caption for a <figure> element. The <figcaption> element can be placed as the first or last child of the <figure> element.

If that definition doesn't make any sense, here is an example:

 <figure>
  <img src="pic_trulli.jpg" alt="Trulli" style="width:100%">
  <figcaption>Fig.1 - Trulli, Puglia, Italy.</figcaption>
</figure> 
leosa
PRO
leosa
Pro Student 4,622 Points

The <caption> tag defines a table caption. The <caption> tag must be inserted immediately after the <table> tag. By the way, you can specify only one caption per table.

Here is an example of using the <caption> tag:

 <table>
  <caption>Monthly savings</caption>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
</table> 
adam n
adam n
57,282 Points

He's dealing with images here so he wont necessarily be using the caption element. Look at the course + stage he's on for context to his problem.