HTML 5
HTML 5
HTML 5
Introduction
HTML5 is the latest standard for HTML, providing new elements and APIs for building
modern, interactive web applications. It offers improved support for multimedia,
better semantic elements, and enhanced form controls.
A basic HTML5 document includes the <!DOCTYPE html> declaration and a few
fundamental elements.
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML5 Basics</title>
</head>
<body>
<h1>Hello, HTML5!</h1>
</body>
</html>
Explanation:
1. Semantic Elements
HTML5 introduces semantic elements to improve the structure and readability of web
pages.
Examples:
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Semantic Elements</title>
</head>
<body>
<header>
<h1>Welcome to My Website</h1>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</header>
<main>
<section id="home">
<h2>Home</h2>
</section>
<section id="about">
<h2>About</h2>
</section>
<section id="contact">
<h2>Contact</h2>
</section>
</main>
<footer>
</footer>
</body>
</html>
2. Form Enhancements
Examples:
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML5 Forms</title>
</head>
<body>
<h1>HTML5 Forms</h1>
<label for="email">Email:</label>
<br>
<label for="date">Date:</label>
<br>
<label for="number">Number:</label>
<br>
<label for="range">Range:</label>
<input type="range" id="range" name="range" min="0" max="100">
<br>
<label for="color">Color:</label>
<br>
</form>
</body>
</html>
3. Multimedia Elements
Examples:
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML5 Multimedia</title>
</head>
<body>
<h1>HTML5 Multimedia</h1>
<h2>Audio</h2>
<audio controls>
</audio>
<h2>Video</h2>
</video>
</body>
</html>
4. Canvas Element
Examples:
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML5 Canvas</title>
</head>
<body>
<h1>HTML5 Canvas</h1>
</canvas>
<script>
// Draw a rectangle
ctx.fillStyle = '#FF0000';
// Draw a circle
ctx.beginPath();
ctx.stroke();
</script>
</body>
</html>
5. Geolocation
Examples:
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML5 Geolocation</title>
</head>
<body>
<h1>HTML5 Geolocation</h1>
<p id="result"></p>
<script>
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
function showPosition(position) {
</script>
</body>
</html>
6. Local Storage
Examples:
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<p id="storedData"></p>
<script>
function saveData() {
function loadData() {
</script>
</body>
</html>