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>withsrcandalt- captions with
<figure>and<figcaption> <audio>and<video>with thecontrolsattribute- 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
<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.
More in this module
Keep going in Web Developer Path
How the web works and your first HTML page
Complete the page: give it the title `My page`, put an `h1` heading inside the body, add two lines of text separated by `<br>`, and add an HTML comment.
Start โ2Elements, attributes and text formatting
Write a paragraph with the id `notes` that contains important text (`strong`), emphasised text (`em`), highlighted text (`mark`) and a subscript (`sub`).
Start โ3Links, lists and tables
Build a timetable table with a heading row of three `th` cells (Day, Subject, Time) and at least two rows of three `td` cells. Then add an ordered list of three steps and a link to `#top`.
Start โ5Semantic page layout
Build the layout: a `header` with an `h1` and a `nav` holding two links, a `main` with a `section` that contains an `article`, an `aside`, and a `footer` with some text.
Start โ6Forms and user input
Build a sign-up form with labelled text, email and password fields, two radio buttons that share the name `level`, a checkbox, a `select` with two `option`s, a `textarea` and a submit button.
Start โPractise the idea
๐ Play Geometry Explorer
Practise area, volume, circles and right-triangle relationships with short challenges.
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
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.
Pick a game
- Code BuilderThe lines of a Python program are mixed up. Tap them into the rightโฆPlay
- Bug HunterA Python program prints the wrong answer. Find the one line with theโฆPlay
- Predict the OutputRead a short Python program and choose what it prints. Then watch it runโฆPlay
- Code JungleWrite real Python to guide Miko the monkey to every banana. 24 levels:โฆPlay