Class :9 : Web Site Design :HTML 5

5.1 Introduction to HTML 5

HTML 5 stands for HyperText Markup Language version 5. It is the modern version of HTML used to create and structure web pages and web applications. HTML5 provides many new elements, attributes, APIs, and multimedia features that make websites more interactive, responsive, and user-friendly.

Main features of HTML 5

  1. It provides new semantic elements such as <header>, <nav>, <section>, <article>, <aside>, and <footer>.
  2. It supports audio and video without requiring additional plugins.
  3. It provides the <canvas> element for drawing graphics using JavaScript.
  4. It supports SVG (Scalable Vector Graphics).
  5. It provides built-in drag-and-drop functionality.
  6. It introduces new input types and attributes for HTML forms.
  7. It supports better form validation.
  8. It provides APIs for developing modern web applications.

5.2 New Features in HTML 5

HTML5 introduced many new features that make web development easier, faster, and more interactive. It provides new elements for creating structured web pages, multimedia content, graphics, forms, and interactive applications.

Major New Features of HTML 5

  1. Semantic Elements : HTML5 provides meaningful elements,Common semantic elements include:
  • <header> – Defines the introductory or header area of a webpage or section. It may contain a logo, title, heading, or navigation links.
  • <nav> – Defines a section containing the main navigation links of a website.
  • <section> – Represents a thematic or logical section of related content.
  • <article> – Represents independent, self-contained content such as a blog post, news article, or forum post.
  • <aside> – Contains additional or related content, such as a sidebar, advertisements, or related links.
  • <footer> – Defines the bottom section of a webpage or section. It may contain copyright information, contact details, or useful links.

Question: Write an HTML5 program using semantic elements to create a basic webpage layout. The webpage should include:

  • A <header> displaying “My Website”
  • A <nav> section containing Home, About, and Contact links
  • A <section> containing an <article> with the heading “HTML5” and a short description
  • An <aside> displaying “Related Links”
  • A <footer> displaying “© 2026 My Website”
HTML5 Semantic Elements

HTML5 Semantic Elements

Output:

Advantages of Semantic Elements

  1. Easy to Understand: Make the structure and content of a webpage easier to understand.
  2. Better SEO: Help search engines understand webpage content and improve Search Engine Optimization (SEO).
  3. Improved Accessibility: Help screen readers and other assistive technologies understand the webpage structure.
  4. Easy Maintenance: Make HTML code more organized, readable, and easier to maintain.
  5. Clear Structure: Clearly identify different parts of a webpage, such as the header, navigation, main content, sidebar, and footer.

5.2  HTML 5 Audio and Video

HTML5 provides built-in <audio> and <video> elements for adding sound and video content directly to a webpage without requiring external plugins such as Flash.The <audio> element is used to embed and play audio files such as music, voice recordings, and sound effects on a webpage. Syntax is below:

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

Important attributes:

  • controls – Displays play, pause, volume, and other audio controls.
  • autoplay – Starts playing the audio automatically.
  • loop – Repeats the audio continuously.
  • muted – Starts the audio in muted mode.
  • preload – Specifies how the browser should load the audio file.

HTML5 Video

The <video> element is used to embed video files directly into a webpage. syntax is given below.

<video width="600" controls> 
<source src="video.mp4" type="video/mp4"> Your browser does not support the video element.
</video>

Important attributes:

  • controls – Displays video controls such as play, pause, volume, and fullscreen.
  • width / height – Specifies the dimensions of the video.
  • autoplay – Automatically starts the video.
  • loop – Replays the video continuously.
  • muted – Starts the video without sound.
  • poster – Specifies an image displayed before the video starts.
  • preload – Specifies how the browser should load the video.

Multiple Media Formats

The <source> element allows multiple audio or video formats to be provided. The browser selects a format it supports.

<video controls width="600"> 
<source src="video.mp4" type="video/mp4">
<source src="video.webm" type="video/webm"> Your browser does not support HTML5 video.
</video>

Advantages of HTML 5 Audio and Video

  1. HTML5 provides built-in <audio> and <video> elements, so users do not need to install additional plugins.
  2. Audio and video files can be easily added to a webpage using simple HTML tags.
  3. HTML5 provides controls such as play, pause, volume, and progress bar.
  4. HTML5 supports several common audio and video formats, allowing multimedia content to be used on different devices and browsers.
  5. HTML5 multimedia elements are supported by modern browsers such as Chrome, Firefox, Edge, and Safari.
  6. It supports features such as autoplay, looping, and muted playback.
  7. Works across modern web browsers.
  8. Supports features such as autoplay, looping, and muted playback.
  9. Improves multimedia integration and user experience.

1. Write HTML code to add an audio file.

HTML5 Audio Example

Output:

Click Run Code to see the output.

2. Write HTML 5  code to add a video file

HTML5 Video Example

Output:

Click Run Code to see the output.

3. Write HTML 5  code for an audio file with autoplay, loop, and muted features.

HTML5 Audio Features

Output:

Click Run Code to see the output.

4. Write HTML 5 code for a video with controls, autoplay, loop, and muted features.

Video Features

Output:

Click Run Code to see the output.

5.3 HTML 5 Canvas

 

HTML5 Canvas is an HTML5 element used to draw graphics, shapes, lines, text, images, animations, and charts on a webpage using JavaScript.

The <canvas> element creates a rectangular drawing area on a webpage. JavaScript is used to draw inside this area. the syntax is given below:

<canvas id="myCanvas" width="500" height="300"> </canvas>
  • canvas> – Defines the drawing area.
  • id – Gives a unique name to the canvas.
  • width – Specifies the width of the canvas.
  • height – Specifies the height of the canvas.

Example: Draw a Rectangle by using HTML 5

HTML5 Canvas Example

Output:

Click Run Code to see the output.

Explanation

  1. The <canvas> tag creates a drawing area.
  2. getElementById() accesses the canvas.
  3. getContext("2d") creates a 2D drawing context.
  4. fillStyle specifies the color.
  5. fillRect() draws a filled rectangle.

Example: Draw a Circle by using  html 5 circle

HTML5 Canvas Circle

Output:

Click Run Code to see the output.

A circle can be drawn in HTML5 Canvas using the JavaScript arc() method. The arc() method creates a curved path based on a center point, radius, starting angle, and ending angle.

5.4 HTML5 SVG

SVG (Scalable Vector Graphics) is an XML-based markup language used to create two-dimensional graphics on webpages. HTML5 supports SVG directly, so we can create lines, circles, rectangles, polygons, text, and other graphics without using external plugins.The main advantage of SVG is that its graphics can be scaled to any size without losing quality. Syntax is given below.

<svg width="500" height="300">
<!-- SVG elements are written here -->
</svg>

Common SVG Attributes

  • width – Defines the width of the SVG area.
  • height – Defines the height of the SVG area.
  • fill – Specifies the filling color.
  • stroke – Specifies the outline color.
  • stroke-width – Specifies the thickness of the outline.

Example 1: Draw a Rectangle

SVG Rectangle Example

Output:

Click Run Code to see the output.

Explanation

  • rect creates a rectangle.
  • x and y specify the starting position.
  • width specifies the width.
  • height specifies the height.
  • fill specifies the inside color.
  • stroke specifies the border color.
  • stroke-width specifies the border thickness.

Example 2: Draw a Circle by using SVG

SVG Circle Example

Output:

Click Run Code to see the output.

5.2.2 HTML 5 Drag and Drop

HTML 5 Drag and Drop allows users to drag an element from one location and drop it into another location. It is commonly used for moving images, text, files, and other HTML elements.

Important Attributes and Events

Attribute/EventPurpose
draggable="true"Makes an element draggable
ondragstartRuns when dragging starts
ondragoverRuns when an element is dragged over a drop area
ondropRuns when the element is dropped
dataTransfer.setData()Stores the dragged element’s data
dataTransfer.getData()Retrieves the dragged data
preventDefault()Allows the drop operation

Working: First, the “Drag Me” box is made draggable using draggable="true". When dragging starts, its ID is stored. The ondragover event allows dropping, and ondrop moves the dragged element into the drop area.

Example: Simple Drag and Drop

HTML5 Drag and Drop

Output:

Click Run Code to see the output.

HTML 5 Forms

HTML5 Forms are used to collect information from users, such as name, email, password, date, phone number, and other data. HTML5 introduced several new input types and validation features that make forms easier to create and use.

Important HTML5 Input Types

Input TypePurpose
textEnter text
emailEnter an email address
passwordEnter a password
numberEnter numbers
dateSelect a date
timeSelect a time
telEnter a telephone number
urlEnter a website URL
searchEnter search text
colorSelect a color
rangeSelect a value from a range
monthSelect a month
weekSelect a week
datetime-localSelect local date and time

Basic HTML 5 Form Example

HTML5 Form

Output:

Click Run Code to see the output.

HTML5 Form Validation

HTML5 provides built-in validation without JavaScript.

HTML5 Form Validation

Output:

Click Run Code to see the output.
 

How it works: The browser automatically validates the form before submission. For example, entering an age below 10, above 60, or a username shorter than 5 characters will display a validation message.

Compiled By: Er. Basant kumar yadav

error: Content is protected !!
Scroll to Top