Our product tour videos looked perfect in Chrome and showed a black rectangle with a crossed-out play button on some iPads. We had encoded one AV1 file to save bandwidth and served it alone. The fix took five minutes. Understanding which Apple devices would play what, and how to detect it without guessing from the user agent, took longer, and that is what this guide covers.

By the end you will know which codec families Safari handles, why the answer depends on the device and not only the browser version, how to ask the browser properly, and how to order <source> elements so every visitor gets something that plays.

The short version

Codec / container

Safari situation

Safe to rely on?

H.264 (AVC) in MP4

Supported everywhere Safari runs

Yes, the universal fallback

AAC audio in MP4

Supported everywhere

Yes

HEVC (H.265) in MP4

Supported on Apple devices with hardware decode, which covers all recent ones

Yes for Apple devices, but other browsers vary

VP8 / VP9 in WebM

Supported in current Safari on macOS and iOS, with older versions and devices missing

Only with detection

Opus audio

Supported in current Safari, older versions limited

Only with detection

AV1

Only on devices with a hardware AV1 decoder (A17 Pro, M3 and later chips)

Only with detection

The important column is the last one. Apple rarely ships software decoders for new codecs. Safari plays a format when the chip can decode it efficiently, so two iPhones on the same iOS release can give different answers for AV1.

Why device matters more than version

Chrome bundles its own software decoders for VP9 and AV1, so a recent Chrome plays them on almost any machine, at the cost of CPU and battery on older hardware. Safari leans on the platform's media frameworks and the video decode block in Apple silicon. That gives excellent battery life, but it means:

  • AV1 arrived in Safari 17 only for devices whose chip decodes it in hardware.

  • HEVC has worked for years because Apple devices have had HEVC hardware since around 2017.

  • Feature tables that list "Safari 17: AV1 yes" are true for some devices and misleading for the rest.

This is why user-agent sniffing fails. The browser version tells you nothing about the chip.

Asking the browser: canPlayType

The oldest API is HTMLMediaElement.canPlayType(). It takes a MIME type with an optional codecs parameter and returns one of three strings:

  • "": cannot play it.

  • "maybe": might play it; usually the answer when you omit codecs.

  • "probably": the engine believes it can decode this exact codec string.

const v = document.createElement('video');

console.log(v.canPlayType('video/mp4'));                               // "maybe"
console.log(v.canPlayType('video/mp4; codecs="avc1.640028"'));         // H.264 High 4.0
console.log(v.canPlayType('video/mp4; codecs="hvc1.1.6.L120.B0"'));    // HEVC Main
console.log(v.canPlayType('video/mp4; codecs="av01.0.08M.08"'));       // AV1 Main 4.0 8-bit
console.log(v.canPlayType('video/webm; codecs="vp9, opus"'));

Always pass the full codec string. Without it, most engines answer "maybe" for anything they recognise as a container, which tells you nothing. Also note that canPlayType is a yes or no answer about decoding at all. It does not tell you whether a 4K 60 fps stream will play smoothly on a five-year-old phone.

Asking properly: MediaCapabilities.decodingInfo

navigator.mediaCapabilities.decodingInfo() answers a better question: can this device decode a stream with this codec, resolution, frame rate and bitrate, and will it be smooth and power efficient? Safari, Chrome and Firefox all support it.

async function canDecode(contentType, width, height, bitrate, framerate) {
  if (!('mediaCapabilities' in navigator)) return { supported: false };
  return navigator.mediaCapabilities.decodingInfo({
    type: 'file',            // 'media-source' if you use MSE, 'webrtc' for calls
    video: { contentType, width, height, bitrate, framerate },
  });
}

const av1 = await canDecode('video/mp4; codecs="av01.0.08M.08"', 1920, 1080, 4_000_000, 30);
// { supported: true, smooth: true, powerEfficient: true } on an M3 MacBook
// { supported: false, ... } on an M1 MacBook in Safari

We use it in two ways:

  1. Choosing a rendition for our adaptive streams. A device reporting powerEfficient: false for AV1 gets HEVC or H.264 instead, even if supported is true, because software decode drains batteries on laptops and phones.

  2. Analytics. We log the result once per session (without identifiers) so we know what share of visitors could use each codec before we spend money encoding it.

Set type to match how you play the video. file means a plain src URL. media-source means Media Source Extensions, which is what HLS.js, dash.js and Shaka Player use. The answers can differ between the two.

Codec strings you will actually use

Codec strings encode profile and level. Getting them wrong produces false negatives.

Format

Example codec string

Notes

H.264 High, level 4.0

avc1.640028

Covers 1080p30

H.264 Main, level 3.1

avc1.4d401f

Safer for very old devices

HEVC Main, level 4.0

hvc1.1.6.L120.B0

Use the hvc1 tag for Apple; hev1 is often rejected

AV1 Main, level 4.0, 8-bit

av01.0.08M.08

Level 4.0 = 1080p60

VP9 profile 0

vp09.00.40.08

Short form vp9 also accepted by many engines

AAC-LC

mp4a.40.2

Audio pairing for MP4

Opus

opus

Audio pairing for WebM or MP4

Your encoder can print the real string. With FFmpeg's tools, ffprobe -show_streams shows the profile and level, and packagers such as Shaka Packager write the exact codec string into the manifest.

Ordering sources so nobody gets a black box

The <video> element tries <source> children in order and plays the first one the browser says it can handle. It does not pick the best one. So the order is your preference list, best format first, universal fallback last:

<video controls playsinline preload="metadata" poster="/media/tour-poster.jpg" width="1280" height="720">
  <source src="/media/tour.av1.mp4"  type='video/mp4; codecs="av01.0.08M.08, mp4a.40.2"'>
  <source src="/media/tour.hevc.mp4" type='video/mp4; codecs="hvc1.1.6.L120.B0, mp4a.40.2"'>
  <source src="/media/tour.vp9.webm" type='video/webm; codecs="vp09.00.40.08, opus"'>
  <source src="/media/tour.h264.mp4" type='video/mp4; codecs="avc1.640028, mp4a.40.2"'>
  <p>Your browser cannot play this video. <a href="/media/tour.h264.mp4">Download it</a>.</p>
</video>

Rules we follow:

  • Always include the type attribute with codecs. Without it the browser may download the start of each file to sniff it, and it may pick a file it then fails to decode.

  • Always end with H.264 + AAC in MP4. It is the one format every engine plays.

  • Keep the audio codec in the string. A browser that plays VP9 but not Opus inside MP4 will otherwise pick a file it cannot fully play.

Our original bug was a single AV1 source with no fallback. On an iPad without an AV1 decoder, the element had nothing it could play.

Streaming: HLS versus MSE

For long videos you will use adaptive streaming. Safari plays HLS natively through the src attribute, and HLS manifests can list renditions with CODECS attributes so the player picks per device. Chrome and Firefox need a JavaScript player using MSE for HLS or DASH. iOS supports Managed Media Source (ManagedMediaSource), Apple's power-aware variant of MSE, which current versions of popular players use when present.

The practical rule: put the codec strings in your manifest, offer an H.264 rendition at every resolution you care about, and let the player use MediaCapabilities to choose.

Encoding budget: which formats to bother with

Every extra codec costs encode time and storage. Our decision rule:

  1. H.264 + AAC: always. It is the fallback.

  2. HEVC: worth it if a large share of traffic is Apple devices and the videos are long. It gives similar quality at noticeably lower bitrates than H.264.

  3. AV1: worth it for high-traffic videos where bandwidth cost dominates, now that recent Apple chips and most Android and desktop browsers decode it. Check your own analytics first.

  4. VP9 WebM: we dropped it once AV1 and HEVC covered the devices that benefited.

Common mistakes

Mistake

Why it hurts

Do this instead

Single AV1 or WebM source

Older Apple devices show a broken player

Always end with H.264 MP4

type="video/mp4" without codecs

Browser picks an MP4 it cannot decode

Include the full codec string

HEVC tagged hev1

Safari and QuickTime reject the file

Remux with the hvc1 tag

UA sniffing for codec support

Same Safari version, different chips

Use decodingInfo()

Ignoring powerEfficient

Software decode drains batteries

Prefer the efficient codec

Testing only on the newest Mac

Hides devices without AV1 hardware

Test on an older iPhone too

Key takeaways

  • Safari's codec support follows the hardware: check per device, not per browser version.

  • canPlayType needs full codec strings and only answers "can it decode at all".

  • MediaCapabilities.decodingInfo answers "smooth and power efficient at this resolution".

  • <source> order is a preference list: best first, H.264 + AAC MP4 last.

  • Put codec strings in your HLS or DASH manifests and let the player choose.

References