101 commands · 7 cheat sheets · HTML

Media and Embedding master quick reference

Browse 101 commands from 7 focused cheat sheets on page 1 of 1. Each example opens its matching detailed section.

Media and Embedding · 15 commands

Fullscreen and Picture-in-Picture API Cheat Sheet

Open full cheat sheet
UseSyntaxExamples
Enter fullscreenawait panel.requestFullscreen()View examples
Prefer hidden browser UIawait panel.requestFullscreen({ navigationUI: 'hide' })View examples
Exit fullscreenawait document.exitFullscreen()View examples
Read active elementconst active = document.fullscreenElementView examples
Check availabilityif (document.fullscreenEnabled) enableButton()View examples
Observe state changedocument.addEventListener('fullscreenchange', syncFullscreenUI)View examples
Observe request errorspanel.addEventListener('fullscreenerror', reportFailure)View examples
Style the fullscreen element.viewer:fullscreen { inline-size: 100%; block-size: 100%; }View examples
Style fullscreen backdrop.viewer::backdrop { background: #000; }View examples
Delegate both features<iframe src="/player" allow="fullscreen; picture-in-picture"> </iframe>View examples
Enter video PiPconst pipWindow = await video.requestPictureInPicture()View examples
Exit video PiPawait document.exitPictureInPicture()View examples
Read active PiP videoconst active = document.pictureInPictureElementView examples
Observe PiP entryvideo.addEventListener('enterpictureinpicture', syncPipUI)View examples
Discourage video PiP<video controls disablepictureinpicture></video>View examples

Media and Embedding · 17 commands

HTML Audio and Video Cheat Sheet

Open full cheat sheet
UseSyntaxExamples
Embed controlled video<video controls width="960" height="540" src="demo.mp4"> </video>View examples
Embed controlled audio<audio controls src="episode.mp3"></audio>View examples
Show a poster image<video controls poster="poster.jpg" src="demo.mp4"> </video>View examples
Offer alternate formats<source src="demo.webm" type="video/webm">View examples
Provide legacy fallback content<video controls> <a href="demo.mp4">Download the video</a> </video>View examples
Add captions<track kind="captions" src="captions-en.vtt" srclang="en" label="English" default>View examples
Add translated subtitles<track kind="subtitles" src="subtitles-pt.vtt" srclang="pt-BR" label="Português">View examples
Link a transcript<a href="transcript.html">Read the transcript</a>View examples
Hint metadata loading<video controls preload="metadata" src="demo.mp4"> </video>View examples
Defer media loading<audio controls preload="none" src="episode.mp3"> </audio>View examples
Request inline playback<video controls playsinline src="demo.mp4"></video>View examples
Request muted autoplay<video autoplay muted playsinline src="ambient.mp4"> </video>View examples
Size video responsivelyvideo { max-inline-size: 100%; block-size: auto; }View examples
Reserve media spacevideo { aspect-ratio: 16 / 9; inline-size: 100%; }View examples
Pause with JavaScriptdocument.querySelector('video').pause();View examples
Request playbackawait video.play();View examples
Seek to a timevideo.currentTime = 30;View examples

Media and Embedding · 11 commands

HTML Canvas and Inline SVG Cheat Sheet

Open full cheat sheet
UseSyntaxExamples
Declare a canvas<canvas id="chart" width="640" height="360"> Chart data is listed below. </canvas>View examples
Get a 2D contextconst context = canvas.getContext('2d')View examples
Clear the bitmapcontext.clearRect(0, 0, canvas.width, canvas.height)View examples
Draw a filled rectanglecontext.fillRect(20, 20, 120, 60)View examples
Scale for device pixelscanvas.width = Math.round(cssWidth * devicePixelRatio)View examples
Declare responsive SVG<svg viewBox="0 0 100 100" role="img" aria-labelledby="title"> <title id="title">Chart</title> </svg>View examples
Draw a circle<circle cx="50" cy="50" r="40" fill="steelblue" />View examples
Draw an SVG path<path d="M10 90 L50 10 L90 90 Z" />View examples
Hide decorative SVG<svg aria-hidden="true" focusable="false">...</svg>View examples
Caption a graphic<figure> <svg role="img">...</svg> <figcaption>Quarterly revenue.</figcaption> </figure>View examples
Inherit text color<path fill="currentColor" d="..." />View examples

Media and Embedding · 15 commands

HTML iframes Cheat Sheet

Open full cheat sheet
UseSyntaxExamples
Embed a page<iframe src="/preview" title="Document preview"> </iframe>View examples
Reserve space<iframe src="/chart" title="Sales chart" width="800" height="450"> </iframe>View examples
Fit the containeriframe { inline-size: 100%; block-size: auto; aspect-ratio: 16 / 9; }View examples
Defer off-screen loading<iframe loading="lazy" src="/map" title="Office map"> </iframe>View examples
Limit referrer data<iframe referrerpolicy="strict-origin" src="https://example.com" title="Example"> </iframe>View examples
Apply all sandbox restrictions<iframe sandbox src="/untrusted" title="Untrusted preview"> </iframe>View examples
Allow scripts only<iframe sandbox="allow-scripts" src="https://widgets.example" title="Widget"> </iframe>View examples
Allow form submission<iframe sandbox="allow-forms" src="/survey" title="Survey"> </iframe>View examples
Allow fullscreen<iframe allow="fullscreen" src="/player" title="Video player"> </iframe>View examples
Deny camera and microphone<iframe allow="camera 'none'; microphone 'none'" src="/widget" title="Widget"> </iframe>View examples
Embed inline HTML<iframe srcdoc="<p>Preview</p>" title="Inline preview"> </iframe>View examples
Name a navigation target<iframe name="report" title="Generated report"></iframe>View examples
Open a link in a frame<a href="/report" target="report">Load report</a>View examples
Send a cross-window messageframe.contentWindow.postMessage({ type: 'ready' }, 'https://widget.example')View examples
Validate a received messageif (event.origin !== 'https://widget.example') returnView examples

Media and Embedding · 15 commands

HTML Responsive Images Cheat Sheet

Open full cheat sheet
UseSyntaxExamples
Embed an image<img src="team.jpg" alt="The product team in the studio">View examples
Hide a decorative image<img src="divider.svg" alt="">View examples
Reserve image space<img src="portrait.jpg" alt="Ada Lovelace" width="800" height="1000">View examples
Lazy-load an image<img src="gallery-4.jpg" alt="Mountain lake at sunrise" loading="lazy" width="1200" height="800">View examples
Request async decoding<img src="chart.png" alt="Quarterly revenue increased each month" decoding="async" width="960" height="540">View examples
Prioritize a key image<img src="hero.jpg" alt="Developer workspace" fetchpriority="high" width="1600" height="900">View examples
Offer density variants<img src="logo.png" srcset="logo.png 1x, logo@2x.png 2x" alt="Northwind" width="240" height="80">View examples
Offer width variants<img src="trail-800.jpg" srcset="trail-480.jpg 480w, trail-800.jpg 800w, trail-1280.jpg 1280w" alt="Forest trail">View examples
Describe the image slot<img src="trail-800.jpg" srcset="trail-480.jpg 480w, trail-800.jpg 800w, trail-1280.jpg 1280w" sizes="(max-width: 600px) 100vw, 50vw" alt="Forest trail">View examples
Offer a modern format<picture> <source srcset="portrait.avif" type="image/avif"> <img src="portrait.jpg" alt="Ada at her desk"> </picture>View examples
Offer several formats<picture> <source srcset="hero.avif" type="image/avif"> <source srcset="hero.webp" type="image/webp"> <img src="hero.jpg" alt="City skyline"> </picture>View examples
Change the crop<picture> <source media="(max-width: 600px)" srcset="speaker-close.jpg"> <img src="speaker-wide.jpg" alt="Speaker presenting on stage"> </picture>View examples
Combine media and widths<picture> <source media="(min-width: 900px)" srcset="banner-1200.jpg 1200w, banner-1800.jpg 1800w" sizes="80vw"> <img src="banner-720.jpg" alt="Conference attendees"> </picture>View examples
Caption an image<figure> <img src="diagram.svg" alt="Request flow from browser to server"> <figcaption>Figure 1: Request lifecycle</figcaption> </figure>View examples
Label an image link<a href="/reports/"> <img src="report-cover.jpg" alt="Open the annual report"> </a>View examples

Media and Embedding · 14 commands

Media Capture and Screen Sharing Cheat Sheet

Open full cheat sheet
UseSyntaxExamples
Request camera and microphoneconst stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true })View examples
Prefer a video sizevideo: { width: { ideal: 1280 }, height: { ideal: 720 } }View examples
Require a facing modeawait track.applyConstraints({ facingMode: { exact: 'environment' } })View examples
Inspect active settingsconst settings = track.getSettings()View examples
Detect constraint namesconst supported = navigator.mediaDevices.getSupportedConstraints()View examples
List media devicesconst devices = await navigator.mediaDevices.enumerateDevices()View examples
Watch device changesnavigator.mediaDevices.addEventListener('devicechange', refreshDevices)View examples
Prompt for a display surfaceconst display = await navigator.mediaDevices.getDisplayMedia({ video: true, audio: true })View examples
Delegate display capture<iframe src="https://tools.example" allow="display-capture"> </iframe>View examples
Mute outgoing mediatrack.enabled = falseView examples
Release a sourcestream.getTracks().forEach(track => track.stop())View examples
Handle external terminationtrack.addEventListener('ended', handleShareEnded, { once: true })View examples
Record supported mediaconst recorder = new MediaRecorder(stream, { mimeType })View examples
Preview captured mediavideo.srcObject = stream; await video.play()View examples

Media and Embedding · 14 commands

Web Audio API Cheat Sheet

Open full cheat sheet
UseSyntaxExamples
Create an audio contextconst context = new AudioContext({ latencyHint: 'interactive' })View examples
Resume after user activationawait context.resume()View examples
Release the contextawait context.close()View examples
Connect a media elementconst source = context.createMediaElementSource(audioElement)View examples
Play an AudioBufferconst source = new AudioBufferSourceNode(context, { buffer }); source.start()View examples
Decode fetched audioconst buffer = await context.decodeAudioData(await response.arrayBuffer())View examples
Control levelconst gain = new GainNode(context, { gain: 0.5 })View examples
Connect graph nodessource.connect(gain).connect(context.destination)View examples
Remove graph routingsource.disconnect()View examples
Schedule a gain rampgain.gain.linearRampToValueAtTime(1, context.currentTime + 0.2)View examples
Replace future automationgain.gain.cancelAndHoldAtTime(context.currentTime)View examples
Read waveform samplesanalyser.getFloatTimeDomainData(samples)View examples
Load an audio worklet moduleawait context.audioWorklet.addModule('/audio/meter-processor.js')View examples
Message a processornode.port.postMessage({ type: 'reset' })View examples
CMDMEMO TERMINALREAD ONLY