Back to course

Lesson 15: Embedding Audio and Video

The HTML Masterclass: From Zero to Web Developer

15. Embedding Audio and Video

HTML5 introduced standard elements for embedding media without relying on third-party plugins (like Flash).

15.1 The Video Element (<video>)

The <video> element embeds a video file. It typically uses the controls attribute to display standard playback buttons.

html

Why multiple <source> tags?

Browsers support different video formats (MP4, WebM, OGG). Providing multiple sources ensures compatibility. The browser will try them in order until it finds one it can play.

15.2 The Audio Element (<audio>)

The <audio> element works similarly but doesn't need width/height specifications.

html

15.3 Important Attributes

AttributeDescription
controlsDisplays the player controls (play/pause, volume, etc.).
autoplayAutomatically starts playing the media (often blocked by browsers).
loopCauses the media to restart automatically when finished.
mutedSilences the audio output by default.