brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: HTML video needs muted and playsinline to autoplay nicely on phones

Html
~/tips/tip-html-video-playsinline-muted

width="640" height="360" poster="demo.jpg">

Make a short silent clip start by itself without taking over the screen.

A short looping clip is a lovely replacement for a heavy GIF, until it refuses to start on a phone. The usual reason is a missing attribute or two.

This is the set I use:

<video autoplay muted loop playsinline
       width="640" height="360" poster="demo.jpg">
  <source src="demo.mp4" type="video/mp4">
</video>

muted is what gets autoplay accepted, since browsers block video that starts with sound. playsinline asks the browser to play inside the page, so a phone does not need to jump into full screen. loop makes it behave like a GIF, and poster shows a still while the file loads. Width and height keep the layout from jumping.

Autoplay can still be refused, for example when a visitor has a data or battery saving mode on, so make the poster image meaningful by itself. Something that moves for more than a few seconds should also be stoppable: add controls if the clip is long or distracting. And if the video has speech that people need, autoplaying it muted is the wrong design. Give them a play button and captions.

Further reading: MDN: the video element

More Html tips import { format } from "dates"; The HTML optgroup element puts headings inside a long dropdown srclang="en" label="English" default> An HTML noindex meta tag keeps one page out of search results title="Example blog" href="/feed.xml"> All Html tips (14) All topics

Link