HTML5
HTML5
HTML5 | Introduction
Features:
• It has introduced new multimedia features which supports both audio and
video controls by using <audio> and <video> tags.
• There are new graphics elements including vector graphics and tags.
• Enrich semantic content by including <header> <footer>, <article>,
<section> and <figure> are added.
• Drag and Drop- The user can grab an object and drag it further dropping it
to a new location.
• Geo-location services- It helps to locate the geographical location of a
client.
• Web storage facility which provides web application methods to store data
on the web browser.
• Uses SQL database to store data offline.
• Allows drawing various shapes like triangle, rectangle, circle, etc.
• Capable of handling incorrect syntax.
• Easy DOCTYPE declaration i.e., <!doctype html>
• Easy character encoding i.e., <meta charset=”UTF-8″>
• <aside>: The <aside> tag is used to describe the main object of the web
page in a shorter way like a highlighter. It basically identifies the content
that is related to the primary content of the web page but does not constitute
the main intent of the primary page. The <aside> tag contains mainly
author information, links, related content and so on.
• <mark>: The <mark> tag in HTML is used to define the marked text. It is
used to highlight the part of the text in the paragraph.
• <wbr>: The <wbr> tag in HTML stands for word break opportunity and is
used to define the position within the text which is treated as a line break
by the browser. It is mostly used when the used word is too long and there
are chances that the browser may break lines at the wrong place for fitting
the text.
Advantages:
• All browsers supported.
• More device friendly.
• Easy to use and implement.
• HTML 5 in integration with CSS, JavaScript, etc. can help build beautiful
websites.
Disadvantages:
• Long codes have to be written which is time consuming.
• Only modern browsers support it.
Supported Browsers: It is supported by all modern browsers.
Below examples illustrate the HTML 5 content.
<!DOCTYPE html>
<html>
<head>
<title>HTML 5</title>
<style>
h1 {
font-size:50px;
}
</style>
</head>
<body>
<h1>Welcome to HTML5</h1>
</body>
</html>
HTML | pattern Attribute
This attribute is used to specify the regular expression on which the input
element value is checked. This attribute works with the following input types:
text, password, date, search, email, etc. Use the Global title attribute to
describe the pattern for helping the user.
Syntax:
<input pattern = "regular_exp">
Syntax:
<element placeholder="">
Supported Tags
This attribute is used with two elements which are listed below:
Element Description
<input> Used with the readonly attribute for read-only input fields.
<textarea> Utilized with the readonly attribute for read-only text areas.
Supported Tags
Element Purpose
Input autofocus Automatically focuses the input field when the page
Attribute loads.
Textarea autofocus Automatically focuses the text area when the page
Attribute loads.
<!DOCTYPE html>
<html>
<head>
<title>HTML autofocus Attribute </title>
</head>
<body>
<h2>HTML autofocus Attribute</h2>
<form>
<label
>First Name:
<input
type="text"
autofocus
placeholder="Enter Name"
/>
</label>
</form>
</body>
</html>
Syntax:
<input type="number">
Example:
<!DOCTYPE html>
<html>
<head>
<title>
HTML input type number
</title>
</head>
<body style="text-align:center;">
<h1 style="color:green;">
GeeksForGeeks
</h1>
Syntax:
<input type="password">
Note: The “value” attribute in radio buttons assigns a distinct identifier for
each option. While not visible to users, this value is sent to the server upon
submission, helping identify the selected radio button.
HTML <input type=”radio”> Syntax:
<input type="radio">
Syntax:
<input type="range">
Supported Browsers:
• Google Chrome 4.0 and above
• Firefox 23.0 and above
• Edge 12.0 and above
• Opera 11.0 and above
• Internet Explorer 10 and above
• Apple Safari 3.1 and above
Example:
<!DOCTYPE html>
<html>
<head>
<title>
HTML Input Type range
</title>
</head>
<style>
#Geek_p {
font-size: 30px;
color: green;
}
</style>
<body style="text-align:center;">
<h1 style="color:green;">
GeeksForGeeks
</h1>
</html>
Syntax:
<input type="time">
Example:
<!DOCTYPE html>
<html>
<head>
<title>
HTML input type time
</title>
</head>
<body style="text-align:center;">
<h1 style="color:green;">
GeeksForGeeks
</h1>
<form action="#">
Input Time: <input type="time" name="time">
</html>
HTML | <input type=”week”>
The HTML <input type=”week”> is used to define a week and a year
control field.
Syntax:
<input type="week">
Example:
<!DOCTYPE html>
<html>
<head>
<title>
HTML Input Type week
</title>
</head>
<style>
#Geek_p {
font-size: 30px;
color: green;
}
</style>
<body style="text-align:center;">
<h1 style="color:green;">
GeeksForGeeks
</h1>
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>HTML Input type = "Date" </title>
</head>
<body>
<h2>HTML <input type="date"></h2>
</body>
</html>
Syntax:
<input type="email">
<!DOCTYPE html>
<html>
<head>
<title>
HTML input type email
</title>
</head>
<body style="text-align:center;">
<form>
Email:
<input
type="email"
value="[email protected]">
</form>
</body>
</html>
To embed a video inside a web page, we need to set the src attribute inside the
<video> element that specifies the path or URL for video. A web page serves
content to a wide variety of users with various types of browsers. Each browser
supports different video formats (MP4, WebM, and Ogg) as mentioned earlier.
Therefore, we can supply all the formats that HTML supports by including
multiple <source> tag within <video> element. We let the browser decide
which format is more suitable for video playback.
We can also enable the built-in controls for controlling audio and video
playback to the users (if needed) with the help of controls attribute. It provides
an interface that enables users to manage video playback functions such as
volume adjustment, video navigation (forward and backwards) and play or
pause operations.
Setting the Dimension of Video Display Area
To set the dimension of video display area, also known as the viewport, we can
use the height and width attributes of the <video> element. These attributes
define the height and width of the video viewport in pixels.
Note that the video will adjust its aspect ratio (e.g. 4:3 and 16:9) to align with
the specified height and width. Therefore, it is advisable to match the
dimensions of viewport for a better user experience.
We can pass a URL of an image that works as a thumbnail for the video within
the poster attribute of <video> element. It will display the specified image until
the video starts playing.
The <audio> element is used to enable the support of audio file within a web
page. We can include multiple sources of audio, however, the browser will
choose the most appropriate file automatically. Most of the attributes
of <video> element is also compatible with the <audio> element. The most
frequently used attributes of HTML audio element are controls, autoplay, loop,
muted and src.
How to embed an audio in HTML?
Like video, audio player is also embedded inside a web page either by setting
the src attribute or by including <source> tag within the audio element. The src
attribute and source tag specifies the path or URL for audio. The
current HTML5 draft specification does not specify which audio formats
browsers should support in the audio tag. But most commonly used audio
formats are ogg, mp3 and wav. Therefore, it is also possible to supply all these
formats by using multiple <source> tag within <audio> element. We let the
browser decide which format is more suitable for audio playback.
It is necessary to use the controls attribute so that users can manage audio
playback functions such as volume adjustment, forward or backwards
navigation and play or pause operations.
The autoplay is a Boolean attribute that is used to play the audio automatically
once the page is loaded. If loop attribute is present on the <audio> element, the
audio sound will automatically rewind to the beginning once the end of audio is
reached.
Following is the list of important attributes which can be used with the <embed>
tag.
width
1
Width of the object in pixels.
height
2
Height of the object in pixels.
title
3
It is used to label the content. The title should describe the content.
src
4
URL of the object to be embedded.
type
5
It indicates the type of input like mp4 and mp3.
To embed an external video file inside the web page, we can pass the path of video
file into the src attribute of <embed> element. The supported video formats are
MP4, WebM, and Ogg. We don’t need to use the controls attribute as <embed> tag
provides the controls automatically depending on the type of media. The controls
attribute allows users to manage the video playback functions.
To add a soundtrack into the webpage, we can pass the path of audio file into
the src attribute by mentioning the type of audio. The supported audio formats
are ogg, mp3 and wav.
data
1
The location or path of the resource is passed into data attribute.
type
2
It indicates the type of resource.
height
3
It signifies the height of the resource display area.
width
4
It signifies the width of the resource display area.
form
5 Its value is the id of a form. The form attribute shows which object is associated with
the form.
name
6
It specify a unique name for the object.
usemap
7
Specifies a URL of a client-side image map to be used with the object.
HTML Layout
HTML layouts are the backbone of web pages, providing a structured and
organized presentation of content. They play a crucial role in enhancing the
user experience by making the website easy to navigate.
Layout Components
Layouts Descriptions
<head>
<title>Page Layout</title>
<style>
.head1 {
font-size: 40px;
color: #009900;
font-weight: bold;
}
.head2 {
font-size: 17px;
margin-left: 10px;
margin-bottom: 15px;
}
body {
margin: 0 auto;
background-position: center;
background-size: contain;
}
.menu {
position: sticky;
top: 0;
background-color: #009900;
padding: 10px 0px 10px 0px;
color: white;
margin: 0 auto;
overflow: hidden;
}
.menu a {
float: left;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 20px;
}
.menu-log {
right: auto;
float: right;
}
footer {
width: 100%;
bottom: 0px;
background-color: #000;
color: #fff;
position: absolute;
padding-top: 20px;
padding-bottom: 50px;
text-align: center;
font-size: 30px;
font-weight: bold;
}
.body_sec {
margin-left: 20px;
}
</style>
</head>
<body>
</html>
HTML Iframes
Syntax:
<iframe src="URL" title="description"></iframe>
• The src attribute specifies the URL of the document you want to embed.
• Iframes can include videos, maps, or entire web pages from other sources.
Attributes Value:
It contains a single value URL that specifies the URL of the document that is
embedded in the iframe. There are two types of URL links which are listed
below:
URL Descriptions
Supported Attributes:
Attributes Description