CodeBlanks Logo Icon CodeBlanks

Summary - Media gallery

HTML course · Beginner · Lesson 40/68

Combine images, figcaption and video elements into a gallery page.

Media gallery

In this group you learned to add images, sound and video to the page. <img> is a void element that takes src for the address and alt for the description. <figure> and <figcaption> group an image with its caption.

width and height prevent layout shift. <audio> and <video> work with controls; <source> offers different formats. Now you will combine them on a gallery page.

Exercise Add a captioned image to the gallery

Add a <figure> element to body. Inside it, place an <img> with src, alt, width and height, and a <figcaption> with a short caption.

Show example solution
<body>
  <figure>
    <img src="https://example.com/gallery/plateau.jpg" alt="Plateau view" width="800" height="600">
    <figcaption>Morning hours on the plateau</figcaption>
  </figure>
</body>

Exercise Add a video to the gallery

The figure is already in the starting code. Add a <video> element to body (with controls). Inside it, place at least two <source> elements with type on each.

Show example solution
<body>
  <figure>
    <img src="https://example.com/gallery/plateau.jpg" alt="Plateau view" width="800" height="600">
    <figcaption>Morning hours on the plateau</figcaption>
  </figure>
  <video controls>
    <source src="https://example.com/documentary/plateau.mp4" type="video/mp4">
    <source src="https://example.com/documentary/plateau.webm" type="video/webm">
  </video>
</body>

Test yourself

  1. Match all media concepts

    img
    Image (void)
    figure
    Captioned content group
    audio
    Plays sound
    video
    Plays video
    source
    Alternative source

All lessons in Beginner