Introduction
Web development is changing. For years, we've relied on Flash for video, complex JavaScript for storage, and plugins for advanced graphics. HTML5 is changing all that.
HTML5 isn't just the next version of HTML – it's a collection of new standards that bring native capabilities to browsers. Video without Flash. Graphics without Canvas. Storage without cookies. It's the biggest shift in web development since CSS.
Browser support is still spotty. Internet Explorer is behind as usual. But Firefox 3.6, Safari 5, and Chrome are implementing features rapidly. Now is the time to learn HTML5.
What is HTML5?
HTML5 is the next major revision of HTML, currently in draft status. It includes:
- New semantic elements –
<header>,<footer>,<article>,<nav> - Multimedia elements –
<video>,<audio> - Canvas API – 2D drawing and graphics
- Form improvements – New input types and validation
- Offline storage – Local Storage and Web SQL Database
- Geolocation API – Access user's location
- Web Workers – Background JavaScript threads
- WebSockets – Real-time communication
Not all of this is technically "HTML5" – some are separate specifications – but they're all part of the modern web platform.
Browser Support
Support varies widely:
Good support:
- Chrome 5+
- Safari 5+
- Firefox 3.6+
- Opera 10.6+
Poor support:
- Internet Explorer 8 and below (no support)
- IE9 will have some support (beta coming soon)
You can use HTML5 now with fallbacks for older browsers.
Check support:
if (Modernizr.canvas) {
// Use canvas
} else {
// Fallback
}
The Modernizr library detects HTML5 features.
New Semantic Elements
HTML5 adds semantic meaning to markup:
Old way (div soup):
<div id="header">
<div id="nav">
<ul>...</ul>
</div>
</div>
<div id="content">
<div class="article">
<div class="header">...</div>
<div class="content">...</div>
<div class="footer">...</div>
</div>
</div>
<div id="sidebar">...</div>
<div id="footer">...</div>
HTML5 way:
<header>
<nav>
<ul>...</ul>
</nav>
</header>
<section id="content">
<article>
<header>...</header>
<section>...</section>
<footer>...</footer>
</article>
</section>
<aside>...</aside>
<footer>...</footer>
More meaningful markup helps search engines and accessibility tools understand page structure.
New elements:
<header>– Header section<footer>– Footer section<nav>– Navigation links<article>– Self-contained content<section>– Thematic grouping<aside>– Tangentially related content<figure>– Images, diagrams, code listings<figcaption>– Caption for figure
The Video Element
This is huge. Native video without plugins:
<video width="640" height="360" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser doesn't support HTML5 video.
</video>
That's it. No Flash, no object tags, no embed tags. Just native video.
Attributes:
controls– Show playback controlsautoplay– Start playing automaticallyloop– Loop the videoposter– Image shown before playback
JavaScript control:
var video = document.getElementById('myVideo');
video.play();
video.pause();
video.currentTime = 30; // Jump to 30 seconds
The codec problem:
Different browsers support different formats:
- Safari: H.264
- Firefox: Ogg Theora
- Chrome: Both (for now)
You need to encode videos in multiple formats. It's messy, but better than Flash.
The Audio Element
Similar to video:
<audio controls>
<source src="song.mp3" type="audio/mpeg">
<source src="song.ogg" type="audio/ogg">
Your browser doesn't support HTML5 audio.
</audio>
Build custom music players with JavaScript:
var audio = document.getElementById('myAudio');
// Play/pause
audio.play();
audio.pause();
// Volume (0.0 to 1.0)
audio.volume = 0.5;
// Events
audio.addEventListener('ended', function() {
alert('Song finished!');
});
Canvas for Graphics
Canvas provides 2D drawing capabilities:
<canvas id="myCanvas" width="400" height="300"></canvas>
Draw with JavaScript:
var canvas = document.getElementById('myCanvas');
var ctx = canvas.getContext('2d');
// Draw rectangle
ctx.fillStyle = 'blue';
ctx.fillRect(50, 50, 100, 100);
// Draw circle
ctx.beginPath();
ctx.arc(200, 150, 50, 0, Math.PI * 2);
ctx.fillStyle = 'red';
ctx.fill();
// Draw text
ctx.font = '30px Arial';
ctx.fillStyle = 'black';
ctx.fillText('Hello Canvas!', 100, 250);
What you can do:
- Games
- Data visualization
- Image editing
- Animations
- Interactive graphics
Canvas opens up possibilities previously requiring Flash or plugins.
Local Storage
Store data in the browser without cookies:
// Save data
localStorage.setItem('username', 'john');
localStorage.setItem('score', '1000');
// Get data
var username = localStorage.getItem('username');
// Remove data
localStorage.removeItem('username');
// Clear all
localStorage.clear();
Advantages over cookies:
- Stores more data (5MB vs 4KB)
- Never sent to server (faster)
- Simpler API
Session Storage: Same API but data cleared when browser closes:
sessionStorage.setItem('tempData', 'value');
Store complex data:
var user = {name: 'John', age: 30};
localStorage.setItem('user', JSON.stringify(user));
var user = JSON.parse(localStorage.getItem('user'));
Form Improvements
New input types with native validation:
<!-- Email validation -->
<input type="email" name="email" required>
<!-- URL validation -->
<input type="url" name="website">
<!-- Number input -->
<input type="number" min="1" max="10" step="1">
<!-- Date picker -->
<input type="date" name="birthday">
<!-- Color picker -->
<input type="color" name="favoriteColor">
<!-- Range slider -->
<input type="range" min="0" max="100" value="50">
<!-- Search box -->
<input type="search" name="query">
Placeholder text:
<input type="text" placeholder="Enter your name">
Required fields:
<input type="text" required>
Pattern matching:
<input type="text" pattern="[0-9]{5}" title="5-digit zip code">
Browsers handle validation automatically. No JavaScript needed for basic validation.
Geolocation API
Access user's location (with permission):
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var lat = position.coords.latitude;
var lon = position.coords.longitude;
alert('Your location: ' + lat + ', ' + lon);
});
} else {
alert('Geolocation not supported');
}
Use cases:
- Show nearby restaurants
- Provide directions
- Local weather
- Location-based services
User must grant permission, so always provide fallback.
Drag and Drop
Native drag and drop without libraries:
<div id="dragItem" draggable="true">Drag me!</div>
<div id="dropZone">Drop here</div>
var dragItem = document.getElementById('dragItem');
dragItem.addEventListener('dragstart', function(e) {
e.dataTransfer.setData('text/plain', 'Dragged data');
});
var dropZone = document.getElementById('dropZone');
dropZone.addEventListener('dragover', function(e) {
e.preventDefault(); // Allow drop
});
dropZone.addEventListener('drop', function(e) {
e.preventDefault();
var data = e.dataTransfer.getData('text/plain');
alert('Dropped: ' + data);
});
Build file uploaders, sortable lists, and interactive interfaces.
Web Workers
Run JavaScript in background threads:
Main script:
var worker = new Worker('worker.js');
worker.addEventListener('message', function(e) {
alert('Worker said: ' + e.data);
});
worker.postMessage('Start working');
worker.js:
self.addEventListener('message', function(e) {
// Do heavy computation
var result = heavyCalculation();
self.postMessage(result);
});
Web Workers prevent UI freezing during intensive operations.
WebSockets
Real-time, bidirectional communication:
var socket = new WebSocket('ws://example.com/socket');
socket.onopen = function() {
socket.send('Hello Server!');
};
socket.onmessage = function(event) {
alert('Server said: ' + event.data);
};
socket.onclose = function() {
alert('Connection closed');
};
Use cases:
- Chat applications
- Real-time games
- Live updates
- Collaborative editing
Better than AJAX polling for real-time features.
Offline Applications
Make web apps work offline:
Cache manifest (cache.manifest):
CACHE MANIFEST
# v1.0
CACHE:
index.html
style.css
script.js
logo.png
NETWORK:
*
Reference in HTML:
<html manifest="cache.manifest">
The browser caches listed files. App works offline.
Update version comment (# v1.0 → # v1.1) to force cache refresh.
Practical Example: HTML5 Video Player
Let's build a custom video player:
<div id="videoPlayer">
<video id="myVideo" width="640" height="360">
<source src="video.mp4" type="video/mp4">
<source src="video.ogg" type="video/ogg">
</video>
<div id="controls">
<button id="playPause">Play</button>
<input type="range" id="seekBar" value="0">
<input type="range" id="volumeBar" min="0" max="100" value="100">
<span id="currentTime">0:00</span> / <span id="duration">0:00</span>
</div>
</div>
var video = document.getElementById('myVideo');
var playPause = document.getElementById('playPause');
var seekBar = document.getElementById('seekBar');
var volumeBar = document.getElementById('volumeBar');
// Play/Pause
playPause.addEventListener('click', function() {
if (video.paused) {
video.play();
playPause.innerHTML = 'Pause';
} else {
video.pause();
playPause.innerHTML = 'Play';
}
});
// Seek
seekBar.addEventListener('change', function() {
var time = video.duration * (seekBar.value / 100);
video.currentTime = time;
});
// Update seek bar as video plays
video.addEventListener('timeupdate', function() {
var value = (100 / video.duration) * video.currentTime;
seekBar.value = value;
});
// Volume
volumeBar.addEventListener('change', function() {
video.volume = volumeBar.value / 100;
});
A functional video player with custom controls.
Graceful Degradation
Not all browsers support HTML5. Provide fallbacks:
Video fallback to Flash:
<video width="640" height="360" controls>
<source src="movie.mp4" type="video/mp4">
<object data="player.swf">
<param name="movie" value="movie.mp4">
</object>
</video>
Canvas fallback:
<canvas id="myCanvas" width="400" height="300">
<img src="fallback.png" alt="Chart">
</canvas>
Feature detection with Modernizr:
if (Modernizr.localstorage) {
// Use Local Storage
} else {
// Use cookies
}
Always provide fallbacks for older browsers.
Internet Explorer Issues
IE8 and below don't recognize HTML5 elements. They treat <header> as unknown tags.
Fix with JavaScript:
<!--[if lt IE 9]>
<script>
document.createElement('header');
document.createElement('nav');
document.createElement('article');
document.createElement('section');
document.createElement('aside');
document.createElement('footer');
</script>
<![endif]-->
Or use html5shiv library:
<!--[if lt IE 9]>
<script src="html5shiv.js"></script>
<![endif]-->
Learning Resources
HTML5 Demos: html5demos.com – Try features in your browser
Can I Use: caniuse.com – Check browser support (launching soon)
Dive Into HTML5: diveintohtml5.org – Comprehensive guide
W3C Specs: w3.org – Official specifications
HTML5 Rocks: html5rocks.com – Tutorials and articles
Should You Use HTML5 Now?
Yes, if:
- You can require modern browsers
- You provide fallbacks
- You want to experiment with new features
- Your audience uses Chrome, Firefox, or Safari
Wait, if:
- IE6/7/8 support is critical
- You can't provide fallbacks
- Your project requires broad compatibility
HTML5 is usable now with appropriate fallbacks. Start experimenting.
The Road Ahead
HTML5 is still evolving. The spec won't be final for years. But browsers are implementing features now, and developers are using them in production.
This is the future of web development. Video without Flash. Rich graphics without plugins. Offline capabilities. Real-time communication. HTML5 brings desktop-like capabilities to the web.
Browser vendors are moving fast. IE9 will improve things. Mobile browsers (iPhone, Android) support HTML5 well. The web platform is catching up to desktop.
Getting Started
Start experimenting now:
- Try the canvas – Build a simple drawing app
- Use video/audio – Embed media without Flash
- Store data locally – Build an offline-capable app
- Use semantic elements – Improve your markup
- Test form features – Let browsers validate
Don't wait for perfect browser support. Start using HTML5 features today with appropriate fallbacks. The future of web development is here.
HTML5 isn't just a new version – it's a platform shift. Learn it now, and you'll be ahead of the curve as it becomes mainstream.