img
Shows an image with meaningful alt text or empty alt when decorative.
Learn HTML Media with practical examples for rich HTML features, native browser behavior, accessibility, performance, SEO and live practice.
HTML advanced
Media is the broad group of images, video, audio, captions, sources, posters, icons and embedded visual material inside a page.
Good media HTML is not only about showing something. It is about choosing the right format, loading it at the right time, describing it clearly and keeping the page fast.
A professional page treats media as content, not decoration by default. If media communicates meaning, that meaning must stay available when the file cannot be seen, heard or loaded.
Shows an image with meaningful alt text or empty alt when decorative.
Embeds video with controls, source files, poster images and captions.
Embeds audio with controls, sources and transcripts when needed.
Adds captions, subtitles or descriptions to timed media.
Syntax and behavior
The browser can choose sources and show native controls, but you still decide meaning, loading behavior and fallback text.
<figure> <video controls poster="/assets/video/lesson-poster.webp"> <source src="/assets/video/lesson.webm" type="video/webm"> <source src="/assets/video/lesson.mp4" type="video/mp4"> <track src="/assets/video/captions.vtt" kind="captions" srclang="en" label="English"> Your browser does not support embedded video. </video> <figcaption>Short lesson preview with captions.</figcaption> </figure>
<video src="huge-file.mp4" autoplay></video> <img src="photo.jpg"> <audio src="voice.mp3"></audio>
HTML quick reference
Use these patterns when you need the syntax quickly. Each example has its own anchor, so search engines and readers can land directly on the exact pattern instead of only at the top of the lesson.
A clean version of the markup from this lesson. Use it when you need the correct HTML shape quickly.
<figure> <video controls poster="/assets/video/lesson-poster.webp"> <source src="/assets/video/lesson.webm" type="video/webm"> <source src="/assets/video/lesson.mp4" type="video/mp4"> <track src="/assets/video/captions.vtt" kind="captions" srclang="en" label="English"> Your browser does not support embedded video. </video> <figcaption>Short lesson preview with captions.</figcaption> </figure>
Meaningful markup that stays understandable before CSS and JavaScript are added.
The starting point from the practice lab. Change the HTML first, then use CSS only for presentation.
<main class="demo-card"> <figure> <div class="poster" role="img" aria-label="Abstract lesson preview"></div> <figcaption>Use captions and text alternatives for important media.</figcaption> </figure> <p>Media should support the lesson instead of slowing it down.</p> </main> <style> body { margin: 0; min-height: 100vh; display: grid; place-items: center; font-family: Inter, system-ui, sans-serif; background: #07111f; color: white; } .demo-card { width: min(820px, calc(100% - 32px)); padding: 34px; border-radius: 24px; background: #101a2d; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3); } h1 { margin: 0 0 16px; font-size: clamp(34px, 7vw, 58px); line-height: 1; } h2 { margin: 22px 0 10px; } p, li { color: #cfd8e6; line-height: 1.7; } button { border: 0; border-radius: 999px; padding: 12px 16px; background: #8cffc1; color: #07111f; font-weight: 900; } a { color: #8cffc1; font-weight: 900; } .poster { aspect-ratio: 16 / 9; border-radius: 20px; background: linear-gradient(135deg, #8cffc1, #4f8cff 48%, #ff6b7a); } figcaption { color: #cfd8e6; margin-top: 12px; } </style>
A complete practice snippet that shows how the HTML behaves in context.
A weak pattern from the lesson. Use it as a warning sign when reviewing real pages.
<video src="huge-file.mp4" autoplay></video> <img src="photo.jpg"> <audio src="voice.mp3"></audio>
A recognizable mistake you can search for and refactor.
Rules that matter
These elements can create rich interfaces, but they still need clear purpose, safe fallbacks and production discipline.
Images need alt text when meaningful. Video and audio often need captions or transcripts.
Autoplay can be intrusive and is often blocked unless muted.
WebP, AVIF, WebM and optimized MP4 can reduce transfer size.
Width, height and aspect-ratio prevent layout jumps.
Off-screen media should not always load immediately.
Fallback text should explain what the user is missing.
Production thinking
This matters because media can make a page premium, but it can also make a page slow, inaccessible and hard to understand.
Media is accessible when the same information is available visually, audibly or textually. Captions, transcripts and alt text are not extras.
Media should be processed before deployment: correct size, compression, poster image, cache headers and privacy-aware third-party embeds.
Search engines understand media better when filenames, surrounding text, captions, alt text and structured context describe the asset clearly.
Live code lab
Edit the HTML or CSS, then use Run to refresh the preview. The preview is isolated, so links and forms stay inside this practice area.
Mini assignment
Practice assignment
Try it yourself
Self-check
Do not only read this page. Answer these questions out loud or write the answers in your own notes. If one answer feels vague, revisit the examples before moving on.