Adding video and audio the HTML5 way
I'll be honest. I've always found adding media such as video and audio into a web page is an utter pain in HTML 4.01. It's not difficult, just messy. HTML5 makes things far easier. The syntax is much like adding an image:
<video src="myVideo.ogg"></video>
A breath of fresh air for most web designers! Rather than the abundance of code currently needed to include video in a page, HTML5 allows a single <video></video>
tag (or <audio></audio>
for audio) to do all the heavy lifting. It's also possible to insert text between the opening and closing tag to inform users when they aren't using an HTML5 compatible browser and there are additional attributes you'd ordinarily want to add, such as the height
and width
. Let's add these in:
<video src="video/myVideo.mp4" width="640" height="480">What, do you mean you don't understand HTML5?</video>
Now, if we add the preceding code snippet into our page and look at it in Safari...