Lecture HTML4 New Tag
Lecture HTML4 New Tag
<article>
<h1>Google Chrome</h1>
<p>Google Chrome is a free, open-source web browser developed by Google, released in
2008.</p>
</article>
</body>
</html>
HTML <aside> Tag
• The <aside> tag defines some content aside from the content it is
placed in.
• The aside content should be related to the surrounding content.
<!DOCTYPE html>
<html>
<body>
<aside>
<h4>Epcot Center</h4>
<p>The Epcot Center is a theme park in Disney World, Florida.</p>
</aside>
</body>
</html>
HTML <audio> Tag
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</body>
</html>
HTML <canvas> Tag
• The <canvas> tag is used to draw graphics, on the fly, via scripting
(usually JavaScript).
• The <canvas> tag is only a container for graphics, you must use a
script to actually draw the graphics.
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas">Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "red";
ctx.fillRect(0, 0, 80, 100);
</script>
</body>
</html>
HTML <details> Tag
• The <details> tag specifies additional details that the user can view
or hide on demand.
• The <details> tag can be used to create an interactive widget that
the user can open and close. Any sort of content can be put inside
the <details> tag.
• The content of a <details> element should not be visible unless the
open attribute is set.
• The details tag is currently only supported in Opera, Chrome, and in Safari 6.
<!DOCTYPE html>
<html>
<body>
<details>
<summary>Copyright 1999-2014.</summary>
<p> - by Refsnes Data. All Rights Reserved.</p>
<p>All content and graphics on this web site are the property of the company Refsnes Data.</p>
</details>
<p><b>Note:</b> The details tag is currently only supported in Opera, Chrome, and in Safari 6.</p>
</body>
</html>
HTML <datalist> Tag
• The data list tag specifies a list of pre-defined options for an input
element.
• The data list tag is used to provide an "autocomplete" feature on
input elements. Users will see a drop-down list of pre-defined
options as they input data.
• Use the input element's list attribute to bind it together with a
data list element.
<!DOCTYPE html>
<html>
<body>
<p><strong>Note:</strong> The datalist tag is not supported in Internet Explorer 9 and earlier versions, or in Safari.</p>
</body>
</html>
HTML <embed> Tag
<embed src="helloworld.swf">
</body>
</html>
HTML <figure> Tag
<p>The Pulpit Rock is a massive cliff 604 metres (1982 feet) above Lysefjorden, opposite the Kjerag plateau, in
Forsand, Ryfylke, Norway. The top of the cliff is approximately 25 by 25 metres (82 by 82 feet) square and
almost flat, and is a famous tourist attraction in Norway.</p>
<figure>
<img src="img_pulpit.jpg" alt="The Pulpit Rock" width="304"
height="228">
</figure>
</body>
</html>
HTML <header> Tag
• The <header> element represents a container for introductory
content or a set of navigational links.
• A <header> element typically contains:
• one or more heading elements (<h1> - <h6>)
• logo or icon
• authorship information
• You can have several <header> elements in one document.
• Note: A <header> tag cannot be placed within a <footer>,
<address> or another <header> element.
<!DOCTYPE html>
<html>
<body>
<article>
<header>
<h1>Most important heading here</h1>
<h3>Less important heading here</h3>
<p>Some additional information here.</p>
</header>
<p>Lorem Ipsum dolor set amet....</p>
</article>
</body>
</html>
HTML <footer> Tag
<footer>
<p>Posted by: Hege Refsnes</p>
<p>Contact information: <a
href="mailto:[email protected]">[email protected]</a>.<
/p>
</footer>
</body>
</html>
<hgroup> tag– heading group
</body>
</html>
HTML <dialog> Tag
<body>
<p><b>Note:</b> The dialog tag is currently only supported in Chrome version 37+, Safari 6+ and Opera
24+.</p>
<table>
<tr>
<th>January <dialog open>This is an open dialog window</dialog></th>
<th>February</th>
<th>March</th>
</tr>
<tr>
<td>31</td>
<td>28</td>
<td>31</td>
</tr>
</table>
</body>
</html>
HTML <mark> Tag
<p>Display a gauge:</p>
<meter value="2" min="0" max="10">2 out of 10</meter><br>
<meter value="0.6">60%</meter>
</body>
</html>
HTML <nav> Tag
<nav>
<a href="/html/">HTML</a> |
<a href="/css/">CSS</a> |
<a href="/js/">JavaScript</a> |
<a href="/jquery/">jQuery</a>
</nav>
</body>
</html>
HTML <progress> Tag
Downloading progress:
<progress value="22" max="100">
</progress>
</body>
</html>
New Form Elements
Tag Description
The <datalist> tag is used to provide an "autocomplete" feature for <input> elements. Users will
The <datalist> element's id attribute must be equal to the <input> element's list attribute (this
Tag Description
<audio> Defines sound or music content
<embed> Defines containers for external applications (like plug-ins)
<source> Defines sources for <video> and <audio>
<track> Defines tracks for <video> and <audio>
<video> Defines video or movie content
The HTML <video> Element
• The controls attribute adds video controls, like play, pause, and
volume.
• It is a good idea to always include width and height attributes.
• If height and width are not set, the browser does not know the
size of the video. The effect will be that the page will change (or
flicker) while the video loads.
• Text between the <video> and </video> tags will only display in
browsers that do not support the <video> element.
• Multiple <source> elements can link to different video files. The
browser will use the first recognized format.
<!DOCTYPE html>
<html>
<body>
</body>
</html>
.
HTML Iframes
An HTML iframe is used to display a web page within a web page. The
6. SVG integrates with other W3C standards such as the DOM and XSL
SVG
An SVG image begins with an <svg> element
The width and height attributes of the <svg> element define the width and height of the SVG image
The cx and cy attributes define the x and y coordinates of the center of the circle. If cx and cy are not set, the circle's
center is set to (0, 0)
The stroke and stroke-width attributes control how the outline of a shape appears. We set the outline of the circle to a
4px green "border"
The fill attribute refers to the color inside the circle. We set the fill color to yellow
</body>
</html>
SVG Shapes : SVG has some predefined shape elements that can be used by developers:
Rectangle <rect>
Circle <circle>
Ellipse <ellipse>
Line <line>
Polyline <polyline>
Polygon <polygon>
Path <path>
Text <text>
Stroking <path> - by using stroke attribute in it
Blur effect
Linear
Radial
SVG Stroke Properties
SVG offers a wide range of stroke properties. In this chapter we will look at the following:
stroke
stroke-width
stroke-linecap : butt, round, square
stroke-dasharray : <path stroke-dasharray="5,5" d="M5 20 l215 0" />
All the stroke properties can be applied to any kind of lines, text and outlines of elements like a circle.
SVG Blur Effects
<defs> and <filter>
All internet SVG filters are defined within a <defs> element. The <defs> element is
short for definitions and contains definition of special elements (such as filters).The
<filter> element is used to define an SVG filter. The <filter> element has a required
id attribute which identifies the filter. The graphic then points to the filter to use.
SVG <feGaussianBlur>
<svg height="110" width="110">
<defs>
<filter id="f1" x="0" y="0">
<feGaussianBlur in="SourceGraphic" stdDeviation="15" />
</filter>
</defs>
<rect width="90" height="90" stroke="green" stroke-width="3"
fill="yellow" filter="url(#f1)" />
</svg>
SVG Gradient
A gradient is a smooth transition from one color to another. In addition, several color transitions
can be applied to the same element.
There are two main types of gradients in SVG:
Linear
Radial
SVG LINEAR
The <linearGradient> element is used to define a linear gradient.
The <linearGradient> element must be nested within a <defs> tag. The <defs> tag is short
for definitions and contains definition of special elements (such as gradients). Linear
gradients can be defined as horizontal, vertical or angular gradients:
Horizontal gradients are created when y1 and y2 are equal and x1 and x2 differ
Vertical gradients are created when x1 and x2 are equal and y1 and y2 differ
Angular gradients are created when x1 and x2 differ and y1 and y2 differ
<svg height="150" width="400">
<defs>
<linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:rgb(255,255,0);stop-opacity:1" />
<stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
</linearGradient>
</defs>
<ellipse cx="200" cy="70" rx="85" ry="55" fill="url(#grad1)" />
<text fill="#ffffff" font-size="45" font-family="Verdana" x="150" y="86">SVG</text>
Sorry, your browser does not support inline SVG.
</svg>
SVG Radial Gradient -
<radialGradient>
The <radialGradient> element is used to define a radial gradient.
The <radialGradient> element must be nested within a <defs> tag. The <defs> tag is
short for definitions and contains definition of special elements (such as gradients).
<svg height="150" width="500">
<defs>
<radialGradient id="grad1" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">
<stop offset="0%" style="stop-color:rgb(255,255,255);
stop-opacity:0" />
<stop offset="100%" style="stop-color:rgb(0,0,255);stop-opacity:1" />
</radialGradient>
</defs>
<ellipse cx="200" cy="70" rx="85" ry="55" fill="url(#grad1)" />
</svg>
SVG EXAMPLES:
DRAG/DROP
Drag and Drop (DnD) is powerful User Interface concept which makes it easy to copy, reorder
and deletion of items with the help of mouse clicks. This allows the user to click and hold the
mouse button down over an element, drag it to another location, and release the mouse button
to drop the element there.
Sr.No. Events & Description
dragstart
1 Fires when the user starts dragging of the object.
dragenter
Fired when the mouse is first moved over the target element while a drag is occurring. A
listener for this event should indicate whether a drop is allowed over this location. If there
2 are no listeners, or the listeners perform no operations, then a drop is not allowed by default.
dragover
This event is fired as the mouse is moved over an element when a drag is occurring. Much of
3 the time, the operation that occurs during a listener will be the same as the dragenter event.
dragleave
This event is fired when the mouse leaves an element while a drag is occurring. Listeners
4 should remove any highlighting or insertion markers used for drop feedback.
drag
5 Fires every time the mouse is moved while the object is being dragged.
drop
The drop event is fired on the element where the drop was occurred at the end of the drag
6 operation. A listener would be responsible for retrieving the data being dragged and inserting
it at the drop location.
dragend
7 Fires when the user releases the mouse button while dragging an object.
<!DOCTYPE HTML> <body>
<html>
<head>
<style>
#div1, #div2 {
<h2>Drag and Drop</h2>
float: left; <p>Drag the image back and forth between the two div
width: 100px;
height: 35px;
elements.</p>
margin: 10px;
padding: 10px;
border: 1px solid black;
<div id="div1" ondrop="drop(event)"
} ondragover="allowDrop(event)">
</style>
<script>
<img src="img_w3slogo.gif" draggable="true"
function allowDrop(ev) { ondragstart="drag(event)" id="drag1" width="88" height="31">
ev.preventDefault();
}
</div>
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
<div id="div2" ondrop="drop(event)"
} ondragover="allowDrop(event)"></div>
function drop(ev) {
ev.preventDefault(); </body>
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
</html>
}
</script>
</head>
OUTPUT:
For Practice:
GEOLOCATION
The HTML Geolocation API is used to locate a user's position.
Using HTML Geolocation
The getCurrentPosition() method is used to return the user's position.
<!DOCTYPE html>
<html> OUTPUT:
<body>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
AUDIO
The HTML <audio> element is used to play an audio file on a web page.
The <source> element allows you to specify alternative audio files which the browser may choose from. The browser will
use the first recognized format.
The text between the <audio> and </audio> tags will only be displayed in browsers that do not support the <audio>
element.
<!DOCTYPE html>
<html>
<body>
</body>
</html>
INPUT TYPES
<input type="button">
• <input type="radio">
<input type="checkbox"> • <input type="range">
<input type="color"> • <input type="reset">
<input type="date"> • <input type="search">
• <input type="submit">
<input type="datetime-local">
• <input type="tel">
<input type="email"> • <input type="text">
<input type="file"> • <input type="time">
<input type="hidden"> • <input type="url">
• <input type="week">
<input type="image">
<input type="month">
<input type="number">
<input type="password">
Input Restrictions
Attribute Description
checked Specifies that an input field should be pre-selected when the page loads (for
type="checkbox" or type="radio")
disabled Specifies that an input field should be disabled
max Specifies the maximum value for an input field
maxlength Specifies the maximum number of character for an input field
min Specifies the minimum value for an input field
pattern Specifies a regular expression to check the input value against
readonly Specifies that an input field is read only (cannot be changed)
required Specifies that an input field is required (must be filled out)
size Specifies the width (in characters) of an input field
step Specifies the legal number intervals for an input field
value Specifies the default value for an input field
FORM ATTRIBUTES
Attribute Description
accept-charset Specifies the character encodings used for form submission
enctype Specifies how the form-data should be encoded when submitting it to the server (only for method="post")
rel Specifies the relationship between a linked resource and the current document
target Specifies where to display the response that is received after submitting the form
The Target Attribute
The target attribute specifies where to display the response that is received after submitting the
form.
Value Description
_blank The response is displayed in a new window or tab
_self The response is displayed in the current window
_parent The response is displayed in the parent frame
_top The response is displayed in the full body of the window
framename The response is displayed in a named iframe
<!DOCTYPE html>
<html>
<body>
<p>When submitting this form, the result will be opened in a new browser
tab:</p>
</body>
</html>
The Method Attribute
The method attribute specifies the HTTP method to be used when submitting the form data.
The form-data can be sent as URL variables (with method="get") or as HTTP post transaction
(with method="post").
POST:
•Appends the form data inside the body of the HTTP request (the submitted form data is not
shown in the URL)
•POST has no size limitations, and can be used to send large amounts of data.
•Form submissions with POST cannot be bookmarked
SEMANTIC
A semantic element clearly describes its meaning to both the browser and the developer.
Examples of non-semantic elements: <div> and <span> - Tells nothing about its content.
Examples of semantic elements: <form>, <table>, and <article> - Clearly defines its content.
<article> <main>
<aside> <mark>
<details> <nav>
<figcaption> <section>
<figure> <summary>
<footer> <time>
<header>
WEBSTORAGE
HTML web storage provides two objects for storing data on the client:
<script>
if (localStorage.clickcount) {
localStorage.clickcount = Number(localStorage.clickcount) + 1;
} else {
localStorage.clickcount = 1;
}
document.getElementById("result").innerHTML = "You have clicked the button " +
localStorage.clickcount + " time(s).";
The sessionStorage Object
The sessionStorage object is equal to the localStorage object, except that it stores the data for only
one session. The data is deleted when the user closes the specific browser tab.
if (sessionStorage.clickcount) {
sessionStorage.clickcount = Number(sessionStorage.clickcount) + 1;
} else {
sessionStorage.clickcount = 1;
}
document.getElementById("result").innerHTML = "You have clicked the button " +
sessionStorage.clickcount + " time(s) in this session.";
APP CACHE
The current version of HTML5 introduces application cache, which means that a web application
is cached, and accessible without an internet connection. Now we can make an offline web
application that will run without an internet connection by just creating a manifest file in our
application.
Syntax:
<html manifest="demo.appcache">
Uses of the application cache are:
Offline browsing: The users can use the application whenever they want to access the site when
they’re offline
Speed: When the data is already stored then it is easy to access data with the greater speed,
cached resources load faster than uncached resources.
Reduced server load: The browser will only download updated resources from the server.
HTML Cache Manifest Example
<!DOCTYPE HTML>
<html manifest="demo.appcache">
<body>
The content of the document......
</body>
</html>
The extension is .appcache
The Manifest File
The manifest file is a simple text file, which tells the browser what to cache (and what to never
cache).The manifest file has three sections:
CACHE MANIFEST - Files listed under this header will be cached after they are downloaded for
the first time
NETWORK - Files listed under this header require a connection to the server, and will never be
cached
FALLBACK - Files listed under this header specifies fallback pages if a page is inaccessible
WEB WORKERS
When executing scripts in an HTML page, the page becomes unresponsive until the script is
finished.
A web worker is a JavaScript that runs in the background, independently of other scripts,
without affecting the performance of the page. You can continue to do whatever you want:
clicking, selecting things, etc., while the web worker runs in the background.
Following are some key features of the Web Workers: