Autoplay videos are excellent for grabbing attention, but getting them to play reliably across all browsers requires the right attributes and optimization strategy.
What we'll cover:
You can find the complete working code in our Next.js Video Autoplay repository. All examples below are drawn directly from this project.
Modern browsers enforce strict autoplay policies. The rule to remember is videos must be muted to autoplay.
| Condition | Chrome | Safari | iOS Safari |
|---|---|---|---|
| Unmuted video | Blocked | Blocked | Blocked |
| Muted video | Works | Works | Works |
| Muted + playsInline | Works | Works | Works |
Three attributes make autoplay work everywhere:
autoPlay : tells the browser to start playing immediatelymuted : satisfies the "no surprise audio" policyplaysInline : prevents iOS from playing videos in fullscreenThat's all. Now that you understand how it works, let’s build it!
Here's a simple component that works across all modern browsers:
// components/AutoplayVideo.tsx
'use client';
interface AutoplayVideoProps {
src: string;
poster?: string;
className?: string;
}
export function AutoplayVideo({
src,
poster,
className = '',
}: AutoplayVideoProps) {
return (
<video
src={src}
autoPlay
muted
playsInline
loop
poster={poster}
className={className}
/>
);
}
This works with any video URL. But a 60MB hero video will still kill your page load.
You could manually encode videos with ffmpeg. Resize them. Strip audio. Convert formats. Then re-encode every time you change dimensions or quality settings.