HTML 5 and CSS3
HTML 5 and CSS3
HTML 5 and CSS3
Content
• What is HTML5
• Components of HTML 5
• Detecting HTML 5 capabilities
• HTML5 Form tags
• Media tags
• Web worker
• Canvas
• Geolocation
• Web Storage
• Introduction to CSS3
• Introduction to Media element
• CSS3 validations
• Many more….
What is HTML 5
• HTML5 will be the new standard for HTML.
• The previous version of HTML, HTML 4.01, came in 1999. The web
has changed a lot since then.
• Audio & Video: You can embed audio or video on your web pages without
resorting to third-party plugins.
• Geolocation: Now visitors can choose to share their physical location with
your web application.
HTML 5 Syntax
• The DOCTYPE:
• DOCTYPEs in older versions of HTML were longer because the
HTML language was SGML based and therefore required a reference
to a DTD.
• Character Encoding:
• HTML 5 authors can use simple syntax to specify Character Encoding
as follows:
• <meta charset="UTF-8"> All the above syntax is case-insensitive.
HTML 5 Syntax
The input element's type attribute now has the following new values:
Type Description
color Color selector, which could be represented by a wheel or swatch picker
date Selector for calendar date
datetime-
local Date and time display, with no setting or indication for time zones
datetime Full date and time display, including a time zone.
email Input type should be an email.
month Selector for a month within a given year
number A field containing a numeric value only
range Numeric selector within a range of values, typically visualized as a slider
Term to supply to a search engine. For example, the search bar atop a
search browser.
tel Input type should be telephone number.
time Time indicator and selector, with no time zone information
url Input type should be URL type.
week Selector for a week within a given year
HTML 5 Removed Elements
Removed Elements
The following HTML 4.01 elements are removed
from HTML5:
<acronym>
<applet>
<basefont>
<big>
<center>
<dir>
<font>
<frame>
<frameset>
<noframes>
<strike>
<tt>
Tags - <header>:
"a group of introductory or navigational aids. A header element
typically contains the section’s heading (an h1–h6 element or
an hgroup element), but can also contain other content, such
as a table of contents, a search form, or any relevant logos."
<header>
<h1>Main Header</h1>
<p class="tagline">Tagline</p>
</header>
Tags - <nav>:
"Not all groups of links on a page need to be in a nav element
only sections that consist of major navigation blocks are
appropriate for the nav element."
<nav role="navigation">
<ul>
<li>
<a href="#" title="link">link</a>
</li>
</ul>
</nav>
Tags - <article>:
"a composition that forms an independent part of a document,
page, application, or site. This could be a forum post, a
magazine or newspaper article, a Web log entry ..."
<article>
<h2>Item</h2>
<p>Some content here.</p>
</article>
Tags - <section>:
"section is a blob of content that you could store as an
individual record in a database."
<section id="foo">
<h2>Foo</h2>
<p>
Content here
</p>
</section>
Tags - <article> vs.
<section>:
"Authors are encouraged to use the article
element instead of the section element when it
would make sense to syndicate the contents of
the element."
HTML5 element <canvas> gives you an easy and powerful way to draw
graphics using JavaScript.
It can be used to draw graphs, make photo compositions or do simple (and not
so simple) animations.
<!DOCTYPE HTML>
<html> OK
<head>
<style>
#mycanvas{
border:1px solid red;
}
</style>
</head>
<body>
<canvas id="mycanvas" width="100" height="100"></canvas>
</body>
</html>
Video
• HTML5 <video>
• HTML5 has DOM methods, properties, and events for the
<video> and <audio> elements.
<!DOCTYPE html>
<html>
<body>
<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>
Geolocation
HTML5 Geolocation API lets you share your location with your favorite web
sites.
A Javascript can capture your latitude and longitude and can be sent to
backend web server and do fancy location-aware things like finding local
businesses or showing your location on a map.
Today most of the browsers and mobile devices support Geolocation API. The
geolocation APIs work with a new property of the global navigator object ie.
Geolocation object which can be created as follows:
<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;
}
</script>
Web Workers
You can continue to do whatever you want: clicking, selecting things, etc.,
while the web worker runs in the background.
Web Workers
function startWorker()
{
if(typeof(Worker)!=="undefined")
{
if(typeof(w)=="undefined")
{
w=new Worker("demo_workers.js");
}
w.onmessage = function (event) {
document.getElementById("result1").innerHTML=event.data;
};
}else {
document.getElementById("result").innerHTML="Sorry, your browser does
not support Web Workers...";
}
}
function stopWorker()
{
w.terminate();
}
Web Storage
With HTML5, web pages can store data locally within the user's browser.
Earlier, this was done with cookies. However, Web Storage is more secure and
faster.
The data is not included with every server request, but used ONLY when asked
for. It is also possible to store large amounts of data, without affecting the
website's performance.
The data is stored in key/value pairs, and a web page can only access data
stored by itself.
Web Storage
Before using web storage, check browser support for localStorage and
sessionStorage:
if(typeof(Storage)!=="undefined")
{
// Yes! localStorage and sessionStorage support!
// Some code.....
}
else
{
// Sorry! No web storage support..
}
Web Storage
Before using web storage, check browser support for localStorage and
sessionStorage:
if(typeof(Storage)!=="undefined")
{
// Yes! localStorage and sessionStorage support!
// Some code.....
}
else
{
// Sorry! No web storage support..
}
CSS3
CSS3 is split up into "modules". The old specification has
been split into smaller pieces, and new ones are also
added.
• Some of the most important CSS3 modules are:
• Selectors
• Box Model
• Backgrounds and Borders
• Text Effects
• 2D/3D Transformations
• Animations
• Multiple Column Layout
• User Interface
CSS Effects
• Rounded corners
• Gradients
• Box and text shadows
• Fonts
• Transparencies
• Multiple background images and border images
• Multiple columns and grid layout
• Box sizing
• Stroke and outlines
• Animation, movement and rotation
• Improved selectors
CSS Effect Example
.amazing {
border: 1px solid blue;
color: red;
background-color: gold;
-webkit-border-radius: 40px;
-moz-border-radius: 40px;
border-bottom-left-radius: x y; border-bottom-right-radius: 0;
Create Rounded Corners
border-radius: [x] {1,4} [ / [y] {1,4} ]?
border-radius -moz-border-radius
border-top-left-radius -moz-border-radius-topleft
border-top-right-radius -moz-border-radius-topright
border-bottom-right-radius -moz-border-radius-bottomright
border-bottom-left-radius -moz-border-radius-bottomleft
Drop Shadow
text-shadow: x y b color
• x = horizontal offset
x < 0: left of the text
x > 0: right of the text
• y = vertical offset
y < 0: above the text
y > 0: below the text
• b = blur radius
Drop Shadow
box-shadow: x y b color
Examples:
• rgba(r, g, b, opacity)
• background:-moz-linear-gradient(top,rgba(255,255,255,1),
rgba(185,185,185,1));
Multiple background images
background:
<image> <position> <size> <repeat> <attachment> <box>,
<image> <position> <size> <repeat> <attachment> <box>,
<image> <position> <size> <repeat> <attachment> <box>,
<image> <position> <size> <repeat> <attachment> <box> <color>;
OR
background-image: <image>, <image>, <image>, <image>;
background-repeat: <repeat>, <repeat>, <repeat>,<repeat>;
background-position: <position>, <position>, <position>,<position>;
/* plus any background attachment and/or box properties as needed */
#example {
width: 500px;
height: 250px;
background-image: url(decoration.png), url(ribbon.png),
url(old_paper.jpg);
background-repeat: no-repeat;
background-position: left top, right bottom, left top;
}
Multi-Column Layout
#multi-column {
/* For Mozilla: */
-moz-column-width: 13em;
-moz-column-gap: 1em;
/* For WebKit: */
-webkit-column-width: 13em;
-webkit-column-gap: 1em;
}
Multi-Column Layout
#multi-column {
-moz-column-count: 3;
-moz-column-gap: 1em;
-moz-column-rule: 1px solid black;
-webkit-column-count: 3;
-webkit-column-gap: 1em;
-webkit-column-rule: 1px solid black;
}
Demos : CSS3