This is the third and final part of the series of posts which cover audio and video support in HTML 5 (across various browsers).
You can read the first part and the second part too. In this part we will cover the HTML 5 markup for the <video> element. Going by basics all you need is:
- <video src="microreviews.webm"></video>
However, it is better to fix a height and width for the video
- <video src="microreviews.webm" width="320" height="240"></video>
If you don't want to create your own controls and wants the defaults to be used
- <video src="microreviews.webm" width="320" height="240" controls></video>
The preload attribute tells the browser that you would like it to start downloading (but not playing) the video file as soon as the page loads.
- <video src="microreviews.webm" width="320" height="240" preload></video>
- <video src="microreviews.webm" width="320" height="240" preload="none"></video>
The autoplay attribute tells the browser that you would like it to start downloading the video file as soon as the page
loads, and you would like it to start playing the video automatically as soon as possible.
- <video src="microreviews.webm" width="320" height="240" autoplay></video>
However, as we have leant in the previous posts, all browsers don’t support all types of videos. So we need three video
files:
- <video width="320" height="240" controls>
- <source src="microreviews.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
- <source src="microreviews.webm" type='video/webm; codecs="vp8, vorbis"'>
- <source src="microreviews.ogv" type='video/ogg; codecs="theora, vorbis"'>
- </video>
As we can see that the video element doesn’t link to any video. Instead, it just specifies the height and the width of the
video and that default controls are needed. Each
sourceelement links to a single video file (with thesrcattribute),and it also gives information about the video format (in the
typeattribute).The type attribute is a combination of three pieces of information: the container format, the video codec, and the audio codec.
However, setting the
typeattribute in your HTML markup is not sufficient. You also need to ensure that your web server includes the proper MIME type in theContent-TypeHTTP header.
- AddType video/ogg .ogv
- AddType video/mp4 .mp4
- AddType video/webm .webm
If you’re using the Apache web server or some derivative of Apache, you can use an AddType directive in your site-wide
httpd.confor in an.htaccessfile in the directory where you store your video files. (If you use some other web server, consult your server’s documentation on how to set theContent-TypeHTTP header for specific file types.)
If you want to get your videos to play everywhere without any problem, just use a copy of the codes from here.
Get in touch with the writer at mitra[dot]arkid[at]gmail[dot]com
Related posts:

