Content updated
By the end, you can…
- Embed a media file with browser controls.
- Explain the purpose of captions, transcripts, and iframe titles.
One idea at a time
HTML has audio and video elements for playable media. They point to files just as an image does. A controls attribute asks the browser to provide its own play, pause, and other available controls. The controls may look different across browsers, so teach their purpose rather than expecting one exact appearance.
A source element supplies a file and can identify its media type, a format label such as audio/mpeg for MP3 audio. Multiple sources can offer different formats. The browser needs a file it can actually decode: changing the filename extension does not convert a recording. Begin with one short file that you own or have permission to use.
Media should not be the only way to get essential information. A transcript supplies the spoken content as readable text. Captions synchronize speech and relevant sounds with a video. A track element can connect a WebVTT caption file to video; a caption file is a separate text resource with timed text entries, not a paragraph beside the player. Creating one is an optional later task; the required exercise here uses audio and a plain transcript.
Read the tags as containers and file references: <audio> plays sound and <video> plays moving pictures, each with a closing tag. Put source and track inside the player; both are void elements with no closing tag. source uses src for the file path and type for its media format. track uses kind="captions", src for the caption file, srclang for its language, and label for the name shown in the controls. default requests that track initially, subject to the user's preferences.
controls is a boolean attribute: remove it to turn the feature off; controls="false" still enables it. Its presence requests the browser's playback controls. An audio element may use src directly, as in the interactive tone example, instead of a child source. The a, h2, and p elements below are the familiar link, heading, and paragraph: they provide a download link and readable transcript.
Match each media tag to its job
Let the visitor choose when media plays, and provide the information as text too.
Choose a player
<audio>Sound player- Use controls for browser playback controls. Give it a src directly or put source inside it. Close with </audio>.
<video>Video player- Use controls and close with </video>. A transcript or captions make its information available without relying only on sound.
Provide the files
<source>Media file- src gives the path and type identifies its format. A void element inside the player: no closing tag.
<track>Timed captions- Connects a separate caption file using src. kind identifies captions, srclang the language, and label the choice name. A void element.
Keep alternatives available
<a> / <p>Download link and transcript- Keep useful alternatives outside the player; fallback inside it does not cover every file error.
<iframe>Another document embedded here- Used by some external players. Give it a descriptive title and a closing tag. This lesson does not load an external player.
Walk through an example
<audio controls>
<source src="welcome.mp3" type="audio/mpeg">
<a href="welcome.mp3">Download the welcome recording</a>
</audio>
<h2>Transcript</h2>
<p>Welcome to my garden notebook.</p>
<video controls width="320">
<source src="planting.mp4" type="video/mp4">
<track kind="captions" src="planting-en.vtt" srclang="en" label="English" default>
<a href="planting.mp4">Download the planting video</a>
</video>The audio example has browser controls and a transcript outside the player. The video has a source and a captions track. These filenames are examples you must supply for a local project. The interactive example instead includes an actual short generated tone so you can test a working player immediately; it contains no speech.
See it happen: try a small change
The supplied audio is a quiet, short generated tone with no speech. Press Play if you want to hear it, then compare the version without controls.
Code to notice
<audio controls src="tone.wav">
</audio>
<p>Audio description: a short, steady tone with no speech.</p>Live result
What changed: The browser provides playback controls. The actual preview embeds a generated WAV tone rather than requesting tone.wav.
Make playback a deliberate choice
Avoid starting audio automatically. A user should choose when sound begins, and browsers may block autoplay anyway. A video poster can supply a picture before playback. Width and height describe dimensions, while later styling can make media fit narrow screens. Test that a phone-sized view can still reach the controls.
An iframe embeds another document, such as an approved video player. Give it a descriptive title explaining the embedded content. External providers can add tracking, require network access, or refuse embedding. Do not assume that every ordinary webpage URL can be embedded. This lesson uses a local media demonstration rather than an external provider.
The text inside audio or video is fallback for browsers that do not support the element; it is not a guaranteed error message for every missing file. Keep useful alternatives outside the player too. Captions and a transcript should accurately represent the recording, not merely repeat its filename.
Try it in your browser
If you have an audio file, place it beside your HTML page and use its real filename and format in source. Put the matching transcript outside audio. Save, refresh, and test playback. If you have no file, use the supplied tone example instead; no recording or caption file is required to continue the course.
A common wrong turn
A player can appear even when the media file is missing. Seeing controls does not prove playback works. Check the path, file format, and actual playback, then check captions or the transcript separately.
Change one thing
Play and pause the supplied tone. Compare the version with controls to the version without them. Notice that an audio element with no controls does not give the visitor a visible way to start playback.
Your turn: add a recording and its transcript
Add a short audio recording you own to a local HTML page, with controls and a transcript. If you do not have a recording, use the lesson's player to practice playback and explain the markup before collecting a file.
Try this in your own HTML file, then open the page in a browser. There is no separate checked practice for this task yet.
- If you have a recording, put it beside the page and match its filename and media type. Otherwise use the supplied tone player for the following observations.
- For your own recording, add controls and a matching transcript outside the player. For the supplied tone, identify the controls and its no-speech text description.
- Test play and pause with the keyboard and pointer. Explain how the transcript or tone description communicates the content without sound.
Go to the source
Examples are authored for Tuklas and checked with code and reference documentation. This is not a claim of independent human review. Suggest a correction.