HTML Audio & Video
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 automaticallymuted- Mutes the audio (required for autoplay in most browsers)loop- Loops the video continuouslyposter- Image shown before video playswidth/height- Sets dimensions
HTML
CSS
JS
Quick Quiz
Which attribute is required for autoplay to work in most browsers?
Enjoying these tutorials?