HTML5

HTML5 Comprehensive Guide: The Modern Web Standard

HTML5 is the latest evolution of the standard that defines the structure and presentation of content on the World Wide Web. It was designed to support the modern web—reducing the need for external plugins like Flash, improving error handling, and providing better support for mobile devices (Mozilla, 2024a).


Part 1: Getting Started with HTML5

The HTML5 DOCTYPE
In previous versions of HTML, the DOCTYPE declaration was long and complex. In HTML5, it is incredibly simple. It tells the browser that this is an HTML5 document (Mozilla, 2024a).

<!DOCTYPE html>

Minimum HTML5 Document
Here is the absolute minimum structure required for a valid HTML5 page:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Title of the document</title>
</head>
<body>
  Content of the document......
</body>
</html>

Part 2: What's New in HTML5?

HTML5 introduced several powerful new features and elements to handle today's internet usage (W3C, 2014):

  • Semantic Elements: Better structure for web pages (e.g., <header>, <footer>, <article>, <nav>).
  • Multimedia: Native support for video and audio playback without plugins (<video>, <audio>).
  • Graphics: The <canvas> element and SVG for drawing on the fly.
  • Form Controls: New input types like date, time, email, url, and search.
  • Web Storage: Store data locally within the user's browser much better than cookies (localStorage and sessionStorage) (Mozilla, 2024b).

New Semantic/Structural Elements
These tags define different parts of a web page (Mozilla, 2024a):

  • <article>: Defines an independent, self-contained article.
  • <aside>: Defines content aside from the main content (like a sidebar).
  • <header>: Defines a header for a document or section.
  • <footer>: Defines a footer for a document or section.
  • <nav>: Defines a set of navigation links.
  • <section>: Defines a section in a document.
  • <figure> and <figcaption>: Specifies self-contained content (like an image) and its caption.

Deprecated Elements (Removed in HTML5)
Because HTML5 relies on CSS for styling, many old presentational tags were removed, including: <acronym>, <applet>, <center>, <font>, <frame>, <frameset>, <strike>, and <tt> (W3C, 2014).


Part 3: HTML5 Multimedia (Video & Audio)

Before HTML5, you needed plugins like Flash to play audio and video. Now, you can embed them directly into your HTML (Mozilla, 2024c).

The <video> Element

<video width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>

The <audio> Element

<audio controls>
  <source src="song.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

Note: The controls attribute adds play, pause, and volume controls to the media player (Mozilla, 2024c).


Part 4: The HTML5 Canvas

The <canvas> element is used to draw graphics on the fly, via scripting (usually JavaScript). It is only a container for graphics; you must use a script to actually draw the graphics (Mozilla, 2024d).

Creating a Canvas

<canvas id="myCanvas" width="200" height="100" style="border:1px solid #000000;"></canvas>

Drawing a Rectangle
All drawing on the canvas must be done inside JavaScript. The canvas is a two-dimensional grid, with the upper-left corner at coordinate (0,0) (Mozilla, 2024d).

<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(0, 0, 150, 75);
</script>

Drawing Lines (Paths)
Use moveTo() for the start point, lineTo() for the end point, and stroke() to draw the line.

ctx.moveTo(0, 0);
ctx.lineTo(200, 100);
ctx.stroke();

Drawing a Circle
Use the arc() method (Mozilla, 2024d).

ctx.beginPath();
ctx.arc(95, 50, 40, 0, 2 * Math.PI);
ctx.stroke();

Drawing Text
Use fillText() for solid text or strokeText() for outlined text.

ctx.font = "30px Arial";
ctx.fillText("Hello World", 10, 50);

Gradients
You can fill shapes with linear or radial gradients (Mozilla, 2024d).

var grd = ctx.createLinearGradient(0, 0, 200, 0);
grd.addColorStop(0, "red");
grd.addColorStop(1, "white");
ctx.fillStyle = grd;
ctx.fillRect(10, 10, 150, 80);

Part 5: HTML5 Web Storage

Web storage is a significant improvement over cookies. It allows web applications to store data locally within the user's browser, with a much larger storage limit and without sending the data to the server with every HTTP request (Mozilla, 2024b).

  • localStorage: Stores data with no expiration date. The data will not be deleted when the browser is closed.
  • sessionStorage: Stores data for one session. The data is deleted when the browser tab is closed.
// Store data
localStorage.setItem("username", "Yasser");

// Retrieve data
var user = localStorage.getItem("username");

// Remove data
localStorage.removeItem("username");

Conclusion: HTML5 transformed the web from a simple document delivery system into a powerful application platform. By mastering semantic tags, Canvas, native multimedia, and Web Storage, you can build modern, responsive, and highly interactive web applications (W3C, 2014).


References

Mozilla. (2024a). HTML: HyperText Markup Language. MDN Web Docs. https://developer.mozilla.org/en-US/docs/Web/HTML

Mozilla. (2024b). Web Storage API. MDN Web Docs. https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API

Mozilla. (2024c). Video and audio content. MDN Web Docs. https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Video_and_audio_content

Mozilla. (2024d). Canvas API. MDN Web Docs. https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API

W3C. (2014). HTML5: A vocabulary and associated APIs for HTML and XHTML. W3C Recommendation. https://www.w3.org/TR/html5/

1 comment: