HTML video embed code
Putting a video on a page is more than a single line of HTML. This guide walks through the three embed patterns you actually need — a standard player, an autoplaying background loop and a lazy-loaded clip — with copy-paste code for each. Or drop a file into TinyVid and it writes all three for you.
The HTML video element
The native video element is all you need to embed video in HTML — no library, no iframe, no third-party player. At its simplest it wraps one or more source lines, each pointing at a file and naming its type, and the browser plays the first one it can support.
Give the video an explicit width and height, or a CSS aspect ratio, so the browser reserves the right space and the page does not jump while it loads. Add a poster image for the frame shown before playback, and the controls attribute for a standard player. Everything else — autoplay, looping, lazy-loading — is a variation on those few attributes.
Three ways to embed a video
Almost every video embed on the web is one of these three patterns, and TinyVid ships all three as presets. Each one comes filled in with the right codecs, a fallback source and your video's real dimensions — then you flip autoplay, looping, controls or a poster until the code fits your page.
Standard player
A player with visible controls, a poster and progressive download. This is the default for any video a visitor chooses to watch — a tutorial, a product demo, a talk. List the small modern file first and the H.264 MP4 last so every browser picks a source it can play, and set preload to metadata so the clip only loads when someone presses play.
<video poster="poster.jpg" width="1280" height="720" controls preload="metadata" style="max-width:100%;height:auto">
<source src="video.webm" type="video/webm">
<source src="video.mp4" type="video/mp4">
</video>Background loop
A silent, looping clip that autoplays behind a hero or section. Because browsers only allow autoplay when the video is muted, this pattern combines the muted, autoplay, loop and playsinline attributes and uses object-fit to cover the area. Keep it short and heavily compressed — it downloads for every visitor, so a Hero background preset with no audio is the right source.
<video poster="poster.jpg" autoplay loop muted playsinline style="width:100%;height:100%;object-fit:cover">
<source src="video.webm" type="video/webm">
<source src="video.mp4" type="video/mp4">
</video>Lazy-load
A clip that only downloads when it scrolls into view, keeping it off the critical path. Its address is held in a data attribute and swapped in by a small IntersectionObserver script once the element nears the viewport. This is the friendliest pattern for pages with several videos, where loading them all up front would wreck performance.
<video class="lazy-video" poster="poster.jpg" width="1280" height="720" data-src="video.mp4" loop muted playsinline preload="none" style="max-width:100%;height:auto"></video>
<!-- IntersectionObserver swaps data-src → src on view -->Generate your embed code
Drop a video below. TinyVid converts it to web-ready formats, then hands you the generator: pick a preset, flip the options you need, and copy code that already carries your video's real width and height — so the page reserves the right space and nothing jumps as it loads. Free up to 200 MB, no account.
Drop your video here
Attributes and best practices
A handful of attributes do most of the work. The poster gives the player a first frame; preload set to metadata — or none for lazy clips — stops the browser pulling video before it is needed; a width and height, or an aspect ratio, prevent layout shift. For autoplay to work the video must be muted, and playsinline stops iOS forcing it fullscreen.
Offer more than one source. A WebM or AV1 file first and an H.264 MP4 last lets modern browsers take the small file while older ones fall back gracefully — the browser picks the first type it can decode. Naming the codecs in each source's type helps it choose without downloading anything.
Do not forget accessibility. Add a track element with captions for spoken content, and never rely on autoplay alone to carry meaning. A muted background loop should be decorative only — anything a visitor needs to hear belongs in a standard player they can control.
Video tag attributes at a glance
Every attribute you are likely to need on a video element, and when it earns its place.
| Attribute | What it does |
|---|---|
| controls | Shows the browser's play, pause, volume and timeline UI. Include it on any video a visitor is meant to operate; leave it off only for decorative background loops. |
| poster | Image shown before playback begins. Without one the player sits blank or blindly grabs the first frame, so a poster is what keeps the slot from looking broken while the video loads. |
| preload | How much the browser fetches up front: metadata reads dimensions and duration only, none defers everything until play, auto lets the browser pull the file. Use metadata for most players and none below the fold. |
| autoplay | Starts playback without a click. Browsers only honour it on muted video, so it goes hand in hand with muted — and it belongs on decorative clips, not on content someone should choose to watch. |
| muted | Drops the audio at playback. Required for autoplay to work at all. For a clip that should never have sound, remove the audio track from the file itself rather than relying on the attribute. |
| loop | Restarts the clip when it ends. Natural for short background loops, irritating on anything with narration. |
| playsinline | Keeps the video in the page on iOS instead of throwing it into the native fullscreen player. Essential for background loops on iPhone. |
| width / height | Reserve the player's space before the file arrives so the page does not jump as it loads — the difference between a clean layout and a Cumulative Layout Shift penalty. An aspect-ratio in CSS does the same job responsively. |
| <source> | Lets you offer several files: the browser picks the first type it can decode. List the small modern file (WebM or AV1) first and an H.264 MP4 last as the universal fallback. |
| <track> | Attaches captions or subtitles as a WebVTT file. Add it to anything with speech — it is the accessibility baseline, and it makes the content searchable. |
An embed is only as fast as the file behind it. Shrink yours first with the compress video for web guide.