HTML Cheatsheet
Media
Use this HTML reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.
<video> Element
<!-- Basic video with fallback message --> <video src="/videos/demo.mp4" controls> Your browser does not support HTML video. </video> <!-- Multiple sources for cross-browser support --> <video controls width="800" height="450" poster="/videos/thumb.jpg"> <source src="/videos/demo.av1.mp4" type="video/mp4; codecs=av01"> <source src="/videos/demo.webm" type="video/webm"> <source src="/videos/demo.mp4" type="video/mp4"> <!-- Subtitles / captions --> <track kind="captions" src="/videos/demo-en.vtt" srclang="en" label="English" default> <track kind="captions" src="/videos/demo-es.vtt" srclang="es" label="Spanish"> Your browser does not support HTML video. </video>
<video> Attributes
| Attribute | Description |
|---|---|
src | Video URL (or use <source> children) |
controls | Show native browser controls |
autoplay | Start playing on load (requires muted in most browsers) |
muted | Muted by default |
loop | Loop playback |
preload | none / metadata / auto |
poster | Image shown before video loads |
width / height | Dimensions in pixels |
playsinline | Play inline on iOS instead of fullscreen |
crossorigin | anonymous / use-credentials |
<!-- Autoplaying background video (requires muted) --> <video autoplay muted loop playsinline poster="/bg-thumb.jpg"> <source src="/bg.webm" type="video/webm"> <source src="/bg.mp4" type="video/mp4"> </video>
<audio> Element
<!-- Basic audio --> <audio src="/audio/song.mp3" controls> Your browser does not support HTML audio. </audio> <!-- Multiple sources --> <audio controls preload="metadata"> <source src="/audio/song.ogg" type="audio/ogg"> <source src="/audio/song.mp3" type="audio/mpeg"> <source src="/audio/song.wav" type="audio/wav"> Your browser does not support HTML audio. </audio>
<audio> Attributes
| Attribute | Description |
|---|---|
src | Audio URL |
controls | Show native controls |
autoplay | Autoplay (may be blocked by browser) |
muted | Muted by default |
loop | Loop playback |
preload | none / metadata / auto |
crossorigin | anonymous / use-credentials |
<source> Element
Provides alternative media resources for <video>, <audio>, and <picture>. Browser picks the first supported format.
<video controls> <!-- Most modern codec first (best quality/size) --> <source src="video.av1.mp4" type="video/mp4; codecs=av01.0.05M.08"> <source src="video.webm" type="video/webm; codecs=vp9,opus"> <source src="video.mp4" type="video/mp4"> </video>
<source> Attributes for Media
| Attribute | Description |
|---|---|
src | Media URL |
type | MIME type with optional codecs parameter |
media | Media condition (for <picture>) |
srcset | Image candidates (for <picture>) |
sizes | Size hints (for <picture>) |
width / height | Dimensions hint (for <picture>) |
Common MIME types
| Format | MIME type |
|---|---|
| MP4 (H.264) | video/mp4 |
| MP4 (AV1) | video/mp4; codecs=av01 |
| WebM (VP9) | video/webm; codecs=vp9 |
| WebM (AV1) | video/webm; codecs=av01 |
| Ogg Theora | video/ogg |
| MP3 | audio/mpeg |
| Ogg Vorbis | audio/ogg |
| WAV | audio/wav |
| AAC | audio/aac |
| FLAC | audio/flac |
| WebM audio | audio/webm |
<track> Element
Text tracks for <video> and <audio> — captions, subtitles, chapters, metadata.
<video controls src="/movie.mp4"> <!-- Captions: for deaf/HoH — includes speaker IDs and sound descriptions --> <track kind="captions" src="/captions-en.vtt" srclang="en" label="English" default> <!-- Subtitles: only dialogue translation --> <track kind="subtitles" src="/subs-es.vtt" srclang="es" label="Spanish"> <track kind="subtitles" src="/subs-fr.vtt" srclang="fr" label="French"> <!-- Chapters: navigation cue points --> <track kind="chapters" src="/chapters.vtt" srclang="en" label="Chapters"> <!-- Metadata: for JavaScript consumption --> <track kind="metadata" src="/meta.vtt"> <!-- Descriptions: extended descriptions for blind users --> <track kind="descriptions" src="/descriptions-en.vtt" srclang="en"> </video>
WebVTT file format
<!-- WEBVTT 00:00:00.000 --> 00:00:03.000 Welcome to the tutorial. 00:00:03.500 --> 00:00:07.000 Today we will cover HTML5 media elements. 00:00:07.500 --> 00:00:10.000 Let's get started! -->
<track> Attributes
| Attribute | Values | Description |
|---|---|---|
kind | subtitles, captions, chapters, metadata, descriptions | Track type |
src | URL | VTT file URL |
srclang | BCP-47 | Language of the track |
label | string | Human-readable name shown in UI |
default | boolean | This track is active by default |
<embed> Element
Embeds external content via a plugin (PDF, Flash — largely obsolete except PDF).
<!-- PDF viewer --> <embed type="application/pdf" src="/docs/report.pdf" width="800" height="600" title="Annual Report PDF" >
<object> Element
Alternative to <embed> — more flexible fallback mechanism.
<object data="/docs/report.pdf" type="application/pdf" width="800" height="600" > <p> Your browser can't display this PDF. <a href="/docs/report.pdf">Download it instead</a>. </p> </object>
<iframe> Element
Embeds another HTML document (or any URL) inline.
<!-- YouTube embed --> <iframe width="560" height="315" src="https://www.youtube.com/embed/VIDEO_ID" title="Video title" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen loading="lazy" referrerpolicy="strict-origin-when-cross-origin" ></iframe> <!-- Google Maps --> <iframe src="https://maps.google.com/maps?q=New+York&output=embed" width="600" height="400" style="border:0" loading="lazy" title="Map of New York" allowfullscreen ></iframe> <!-- Sandboxed iframe --> <iframe src="https://example.com" sandbox="allow-scripts allow-same-origin" title="Sandboxed content" ></iframe>
<iframe> Attributes
| Attribute | Description |
|---|---|
src | URL to embed |
srcdoc | Inline HTML to render (overrides src) |
name | Named browsing context (for target) |
width / height | Dimensions |
title | Accessible label (required) |
loading | eager / lazy |
sandbox | Security restrictions (see below) |
allow | Feature policy (camera, microphone, etc.) |
allowfullscreen | Allow fullscreen API |
referrerpolicy | Controls Referer header |
sandbox token values
| Value | Allows |
|---|---|
allow-forms | Form submission |
allow-scripts | Script execution |
allow-same-origin | Same-origin requests |
allow-popups | Popups / window.open() |
allow-top-navigation | Navigate the top-level frame |
allow-downloads | Downloads |
allow-modals | Dialogs (alert(), confirm()) |
allow-pointer-lock | Pointer Lock API |
allow-presentation | Presentation API |
allow-storage-access-by-user-activation | Storage Access API |
Empty
sandbox=""applies all restrictions. Add only what you need.
JavaScript Media API
<video id="player" src="/video.mp4" controls></video> <script> const video = document.getElementById('player'); // Playback control video.play(); video.pause(); video.load(); // reload source // Properties video.currentTime = 30; // seek to 30s video.playbackRate = 1.5; // 1.5x speed video.volume = 0.5; // 0 to 1 video.muted = true; video.loop = true; // State console.log(video.paused); // true/false console.log(video.duration); // total seconds console.log(video.ended); // true/false console.log(video.readyState); // 0-4 // Events video.addEventListener('play', () => console.log('playing')); video.addEventListener('pause', () => console.log('paused')); video.addEventListener('ended', () => console.log('ended')); video.addEventListener('timeupdate', () => console.log(video.currentTime)); video.addEventListener('loadedmetadata', () => console.log(video.duration)); video.addEventListener('error', (e) => console.error(e)); </script>
Responsive Video (CSS)
<!-- Aspect-ratio box (16:9) --> <div style="position: relative; padding-top: 56.25%;"> <iframe style="position: absolute; inset: 0; width: 100%; height: 100%;" src="https://www.youtube.com/embed/VIDEO_ID" title="Video" allowfullscreen ></iframe> </div> <!-- Modern CSS: aspect-ratio property --> <video controls style="width: 100%; aspect-ratio: 16/9;"> <source src="/video.mp4" type="video/mp4"> </video>
Codec and Format Support (2025)
| Format | Chrome | Firefox | Safari | Use case |
|---|---|---|---|---|
| H.264 MP4 | Yes | Yes | Yes | Universal compatibility |
| AV1 MP4 | Yes | Yes | Yes (M1+) | Best compression |
| VP9 WebM | Yes | Yes | Yes | Open, good compression |
| HEVC MP4 | Partial | No | Yes | Apple ecosystem |
| MP3 | Yes | Yes | Yes | Audio |
| AAC | Yes | Yes | Yes | Audio |
| Ogg Vorbis | Yes | Yes | No | Open audio |
| FLAC | Yes | Yes | Yes | Lossless audio |
| Opus | Yes | Yes | Yes | Best for streaming |