How to play video with HTML5

Wdd Logo.
October 16, 2013
How to play video with HTML5.

thumbnailPlacing a video in HTML5 markup is simple, no more complex for any given browser than placing an image. In this article we'll take full advantage of the built-in browser support to build the simplest possible video player.

We'll lay the application's basic framework and then use the <video> element to add a video to the web page without the need of any plugins at all.


Use Chrome, Safari or Internet Explorer 9+. For the time-being you'll have to avoid Firefox and Opera because of the cross-browser video file format issues. Although support for the video element is consistent across all modern browsers, the MP4 format trips up Firefox and Opera. You can check for compatibility here.

Before you begin you'll need to find a .mp4 that you can use, if you don't have one, you'll find lots of free mp4 files online.

Building the basic framework

The following code is the framework around which you build the player. It creates a simple layout and has a placeholder for the video itself.

You need to create a new HTML file in your working directory and name it index.html, then add this code:

<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML5 Video Player</title>
body {
font-family: sans-serif;
border: 0;
margin: 0;
padding: 0;
header {
text-align: center;
#player {
display: table;
width: 100%;
padding: 4px;
#player > div {
display: table-cell;
vertical-align: top;
<h1>HTML5 Video Player</h1>
<section id="player">
<!-- The video will appear here-->

Now, with the foundation laid, let's get to the fun part of the player by adding a video to the page.

Using the video element to add videos to web pages

The goal in designing HTML5's <video> element was to make the embedding of video within a web page as straightforward as embedding an image. Although you'll encounter additional complexities because video file formats are more feature-rich than image formats, the design goal has been attained.

Here's what an HTML5 video looks like in Chrome:


The next listing shows all of the code required to display the video. As you can see, it's not complicated.

Insert this code in place of the "<!-- The video will appear here-->" comment in the code above, make sure you replace [ YOUR VIDEO ] with the path to your .mp4, and refresh the page.

<video src="[ YOUR VIDEO ].mp4"
width="720" height="480">
Your browser does not support the video element, please #D try <a href="videos/VID_20120122_133036.mp4">downloading the video instead</a>

In this code the src attribute is the path and file name of your .mp4 file, the controls attribute indicates that you would like the video to have the standard controls (omit it if you don't want the controls) and the width and height are self-explanatory. The text inside the element is back up text to be displayed if the video tag isn't recognized by the browser.


The web is increasingly being used as a replacement for traditional broadcast media. Services like Netflix, YouTube, Spotify,, and Google Music seek to replace your DVD and CD collections with online players. With HTML5, video and audio become first-class citizens of web content. Rather than handing responsibility for playing media to a third-party application, it's played within the browser, allowing you to control and manipulate media from within your web application.

As you can see HTML5 makes it as straightforward a process to add video and audio to web pages as it is to add images.

How do you prefer to handle video? Is HTML5's <video> element robust enough? Let us know your thoughts in the comments.

Featured image/thumbnail, video image via Shutterstock.

WDD Staff

WDD staff are proud to be able to bring you this daily blog about web design and development. If there's something you think we should be talking about let us know @DesignerDepot.

Read Next

3 Essential Design Trends, December 2023

While we love the holidays, too much of a seasonal theme can get overwhelming. Thankfully, these design trends strike a…

10 Easy Ways to Make Money as a Web Designer

When you’re a web designer, the logical way to make money is designing websites; you can apply for a job at an agency,…

The 10 Most Hated Fonts of All Time

Remember when Comic Sans wasn’t the butt of the jokes? Long for the days when we actually enjoyed using the Impact…

15 Best New Fonts, November 2023

2023 is almost over, and the new fonts are still coming thick and fast. This month, we’ve found some awesome variable…

Old School Web Techniques Best Forgotten

When the web first entered the public consciousness back in the 90s, it was primarily text-based with minimal design…

20 Best New Websites, November 2023

As the nights draw in for the Northern hemisphere, what better way to brighten your day than by soaking up some design…

30 Amazing Chrome Extensions for Designers and Developers

Searching for a tool to make cross-platform design a breeze? Desperate for an extension that helps you figure out the…

Exciting New Tools for Designers, November 2023

We’ve got a mix of handy image helpers, useful design assets, and clever productivity tools, amongst other treats. Some…

The Dangers of Doomscrolling for Designers and How to Break Free

As a creative professional, navigating the digital realm is second nature to you. It’s normal to follow an endless…

From Image Adjustments to AI: Photoshop Through the Years

Remember when Merriam-Webster added Photoshop to the dictionary back in 2008? Want to learn how AI is changing design…

3 Essential Design Trends, November 2023

In the season of giving thanks, we often think of comfort and tradition. These are common themes with each of our three…

30 Obsolete Technologies that will Perplex Post-2000s Kids

Remember the screech of dial-up internet? Hold fond memories of arcade machines? In this list, we’re condensing down 30…