HTML & CSS Interview Question #45

How do the audio and video elements work in HTML?

Forms, Validation, Metadata, Media, Responsive Images & Accessibility Mid-Level Intermediate

Quick Interview Answer

The audio and video elements provide native browser playback for supported media formats. The controls attribute asks the browser to display its standard playback controls, while source elements can provide alternative media files.

Detailed Explanation

The audio and video elements provide native browser playback for supported media formats. The controls attribute asks the browser to display its standard playback controls, while source elements can provide alternative media files.

Captions and other accessibility requirements should be considered for video and audio content. Autoplay is restricted by browsers in many circumstances and should not be assumed to work.

Code Example

<video controls width="640">
    <source src="/media/tutorial.mp4"
            type="video/mp4">
    <track kind="captions"
           src="/media/tutorial-en.vtt"
           srclang="en"
           label="English">
    Your browser does not support video.
</video>