Web Analytics

HTML Audio & Video

Beginner ~10 min read

HTML5 Media Elements

Before HTML5, playing audio or video required plugins like Flash. HTML5 introduced native <audio> and <video> elements.

The Audio Element

The <audio> element embeds sound content in documents.

HTML
CSS
JS
Tip: Common audio formats are MP3, WAV, and OGG. MP3 has the best browser support.

The Video Element

The <video> element embeds video content. Use multiple <source> elements for different formats.

HTML
CSS
JS

Video Attributes

  • controls - Shows play/pause, volume, etc.
  • autoplay - Starts playing automatically
  • muted - Mutes the audio (required for autoplay in most browsers)
  • loop - Loops the video continuously
  • poster - Image shown before video plays
  • width/height - Sets dimensions
HTML
CSS
JS

Quick Quiz

Which attribute is required for autoplay to work in most browsers?

A
controls
B
muted
C
loop
D
poster