Book a free demo

Web Developer Path ยท lesson 4 of 18

Images, audio, video and embeds

Add pictures, captions, sound and video to a page, and learn why alt text matters.

What you will learn

  • <img> with src and alt
  • captions with <figure> and <figcaption>
  • <audio> and <video> with the controls attribute
  • embedding another page with <iframe>

Understand the idea

The <img> tag shows a picture. It is a void element, so it has no closing tag. src is the address of the image file and alt is a short description used by screen readers, shown when the picture cannot load, and read by search engines. Good alt text describes what the picture shows, for example alt="A red kite flying over a field". A purely decorative picture can use an empty alt="". width and height reserve space so the page does not jump while the picture loads.

<figure> wraps a picture, diagram or code sample together with <figcaption>, its caption. They show the reader that the caption belongs to the picture, which helps both people and search engines.

<audio> and <video> play sound and movies without any extra software. Add the controls attribute to show the play button and volume. Inside the tag you can list one or more <source> files in different formats, and any text you write between the tags is shown to a browser that cannot play them. Never start sound playing automatically; it surprises and annoys visitors.

<iframe> embeds another page inside yours, such as a map or a video from another site. Always give it a title that describes it. Only embed sites you trust, because the embedded page runs inside yours. In the lesson preview, files from the internet are blocked for safety, so pictures appear as their alt text; the markup is what we are checking.

Example

A picture with a caption, plus audio and video
<figure>
  <img src="kite.jpg" alt="A red kite flying over a field" width="300">
  <figcaption>A kite on a windy day</figcaption>
</figure>

<audio controls>
  <source src="birdsong.mp3" type="audio/mpeg">
  Your browser cannot play audio.
</audio>

<video controls width="320">
  <source src="clip.mp4" type="video/mp4">
</video>

The alt text describes the picture. controls has no value; its presence is what shows the player buttons.

Your turn: code to type and practise

Write a figure that contains an image (with src and alt) and a caption, then an audio player with controls and a video player with controls.

Stretch challenge

Add a <source> to the audio and a fallback sentence for browsers that cannot play it.

โ† Links, lists and tablesSemantic page layout โ†’

HTML

More in this module

Keep going in Web Developer Path

Practise the idea

๐Ÿ“ Play Geometry Explorer

Practise area, volume, circles and right-triangle relationships with short challenges.

Play now

FAQ

Images, audio, video and embeds: common questions

Why does an image need alt text?

Alt text lets screen readers describe the picture to blind users, appears if the picture fails to load, and helps search engines understand the image.

What does the controls attribute do?

It shows the browser's play, pause and volume buttons on an audio or video element. Without it nothing visible appears.

Is it safe to use an iframe?

Only embed sites you trust and always give the iframe a title. The embedded page runs inside your page.

I am stuck. What can I do?

Press Hint for a nudge, read the message next to each goal, and compare your code with the lesson text. If you still need it, Show answer reveals a model solution. Try to type it yourself rather than copy it.

Does my work get saved?

Your ticks and XP are saved in this browser, and in your account if you log in. The code you type is not stored on a server.

Start a conversation

Enjoying coding? Meet a teacher.

Tell us the learner's age, country and what they would like to build, and we will suggest a class. A parent or guardian can make the enquiry.

  • Tell us the learnerโ€™s age or grade and goals
  • Weโ€™ll suggest a suitable class or learning path
  • Weโ€™ll confirm format, timing and fees with a parent or guardian

For a childโ€™s class, please have a parent or guardian send the enquiry. Avoid sharing passwords or sensitive personal details.

Weโ€™ll use your details only to respond to this request.

Play it, don't just read it

Write some code right now

Free games that need no sign-up. Pick one and play for five minutes.

All free games โ†’
Chat on WhatsApp
Esc

Try