VionetoVioneto
Back to the magazine

VIONETO MAGAZINE Hosting & embedding

Serve different video files on mobile and desktop with HTML

Show a close-up video on narrow screens and an overview on desktop. Use the HTML source media attribute and verify the selected file with currentSrc.

A desktop screen shows the wide shot while a phone next to it shows the tighter video cut.
Two edits let the phone show a useful close-up and the desktop show the full control panel.Image: Vioneto · original illustration

A repair tutorial shows three similar buttons on the front of a machine. In the wide shot, their labels are hard to read on a phone. A tighter cut can show the setting control clearly, while the desktop cut gives viewers the whole panel for context. If you control the HTML video element, the browser can pick the appropriate edit when it selects a source.

List the narrow-screen source first

Put the specific source before the general one. The browser considers the source elements in order. In this example the media attribute checks the viewport width, and the final source has no media condition. The 600-pixel decision point illustrates the technique. Choose a breakpoint that makes sense for the layout of your own tutorial.

<video controls preload="metadata"> <source media="(max-width: 600px)" src="detail.mp4" type="video/mp4"> <source src="overview.mp4" type="video/mp4"> </video>

Give the player room to preserve the proportions of either file. If someone resizes or rotates the device after the video loads, this rule alone does not switch the file already in use. Start from a fresh page load when checking each viewport.

Check which file the browser selected

In a local Chrome test with two H.264 files, a 390-CSS-pixel viewport selected a 216 × 384 portrait clip. A 1,280-CSS-pixel viewport selected a 384 × 216 landscape clip. Each load requested only its selected local file. On your page, video.currentSrc gives the file URL, while video.videoWidth and video.videoHeight show its intrinsic dimensions. Reload with the network panel open to spot unexpected duplicate requests.

Check that both edits cover the full task

  • Try the player controls on narrow screens and check that screen rotation leaves the instructions usable.
  • Make sure both cuts show the complete repair step. If their edits have different timing, provide separately timed captions.
  • For a hosted player inside an iframe, use the provider’s supported settings for any source selection. For a player you control, verify the browsers used by your audience and keep a usable fallback for each edit.

Make an embedded player responsive without cropping it

Choose an inline player, popup or video page

Topics

Sources and further reading

  1. https://html.spec.whatwg.org/multipage/embedded-content.html#the-source-element
  2. https://html.spec.whatwg.org/multipage/media.html#concept-media-load-resource