html5
html5
HTML5
History of HTML
1999 HTML 4.01 XHTML 2.0 had even stricter standards than 1.0,
rejecting web pages that did not comply. It fell
2000 XHTML 1.0 out of favor gradually and was abandoned
completely in 2009.
2002
-200 HTML5 is much more tolerant and can handle
XHTML 2.0
9 markup from all the prior versions.
<!DOCTYPE html>
Just 15 characters!
The DOCTYPE tells the browser which type and version of document to expect. This
should be the last time the DOCTYPE is ever changed. From now on, all future
versions of HTML will use this same simplified declaration.
The <html> Element
This is what the <html> element looked like in XHTML:
<html lang="en">
The lang attribute in the <html> element declares which language the page content
is in. Though not strictly required, it should always be specified, as it can assist
search engines and screen readers.
Each of the world’s major languages has a two-character code, e.g. Spanish = "es", French =
"fr", German = "de", Chinese = "zh", Arabic = "ar".
The <head> Section
Here is a typical XHTML <head> section:
<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<title>My First XHTML Page</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<head>
<meta charset="utf-8">
<title>My First HTML5 Page</title>
<link rel="stylesheet" href="style.css">
</head>
Notice the simplified character set declaration, the shorter CSS stylesheet link text,
and the removal of the trailing slashes for these two lines.
Basic HTML5 Web Page
Putting the prior sections together, and now adding the <body> section and closing
tags, we have our first complete web page in HTML5:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My First HTML5 Page</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<p>HTML5 is fun!</p>
</body>
</html>
Article
Footer
Legend
Footer
Semantic Elements in HTML5
• 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>
<aside>
<figcaption>
<figure>
<footer>
<header>
<nav>
<section>
<details>
<summary>
<main>
<mark>
Semantic Elements in HTML5
HTML <section> Element
• The <section> element defines a section in a document.
• "A section is a thematic grouping of content, typically with a heading."
• A web page could normally be split into sections for introduction, content, and contact
information.
<section>
<h1>WWF</h1>
<p>The World Wide Fund for Nature (WWF) is an international organization working on
issues regarding the conservation, research and restoration of the environment, formerly
named the World Wildlife Fund. WWF was founded in 1961.</p>
</section>
<section>
<h1>WWF's Panda symbol</h1>
<p>The Panda has become the symbol of WWF. The well-known panda logo of WWF
originated from a panda named Chi Chi that was transferred from the Beijing Zoo to the
London Zoo in the same year of the establishment of WWF.</p>
</section>
Semantic Elements in HTML5
HTML <article> Element
• The <article> element specifies independent, self-contained content.
• An article should make sense on its own, and it should be possible to distribute it
independently from the rest of the web site.
• Examples of where an <article> element can be used:
• Forum post
• Blog post
• Newspaper article
<article>
<h2>Google Chrome</h2>
<p>Google Chrome is a web browser developed by Google, released in 2008. Chrome is the world's most popular web browser
today!</p>
</article>
<article>
<h2>Mozilla Firefox</h2>
<p>Mozilla Firefox is an open-source web browser developed by Mozilla. Firefox has been the second most popular web browser since
January, 2018.</p>
</article>
<article>
<h2>Microsoft Edge</h2>
<p>Microsoft Edge is a web browser developed by Microsoft, released in 2015. Microsoft Edge replaced Internet Explorer.</p>
</article>
Semantic Elements in HTML5
HTML <header> Element
• 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 HTML document. However, <header> cannot
be placed within a <footer>, <address> or another <header> element.
<article>
<header>
<h1>What Does WWF Do?</h1>
<p>WWF's mission:</p>
</header>
<p>WWF's mission is to stop the degradation of our planet's natural environment,
and build a future in which humans live in harmony with nature.</p>
</article>
Semantic Elements in HTML5
HTML <footer> Element
• The <footer> element defines a footer for a document or section.
• A <footer> element typically contains:
• authorship information
• copyright information
• contact information
• sitemap
• back to top links
• related documents
• You can have several <footer> elements in one document.
<footer>
<p>Author: Hege Refsnes</p>
<p><a href="mailto:hege@example.com">hege@example.com</a></p>
</footer>
Semantic Elements in HTML5
HTML <nav> Element
• The <nav> element defines a set of navigation links.
• Notice that NOT all links of a document should be inside a <nav> element. The <nav>
element is intended only for major block of navigation links.
• Browsers, such as screen readers for disabled users, can use this element to determine
whether to omit the initial rendering of this content.
<nav>
<a href="/html/">HTML</a> |
<a href="/css/">CSS</a> |
<a href="/js/">JavaScript</a> |
<a href="/jquery/">jQuery</a>
</nav>
Semantic Elements in HTML5
HTML <aside> Element
• The <aside> element defines some content aside from the content it is placed in (like a
sidebar).
• The <aside> content should be indirectly related to the surrounding content.
<p>My family and I visited The Epcot center this summer. The weather was nice, and Epcot
was amazing! I had a great summer together with my family!</p>
<aside>
<h4>Epcot Center</h4>
<p>Epcot is a theme park at Walt Disney World Resort featuring exciting attractions,
international pavilions, award-winning fireworks and seasonal special events.</p>
</aside>
Semantic Elements in HTML5
HTML <details> Tag
• The <details> tag specifies additional details that the user can open and close on demand.
• The <details> tag is often used to create an interactive widget that the user can open and
close. By default, the widget is closed. When open, it expands, and displays the content
within.
• Any sort of content can be put inside the <details> tag.
• The <summary> tag is used in conjuction with <details> to specify a visible heading for the
details.
<details>
<summary>Epcot Center</summary>
<p>Epcot is a theme park at Walt Disney World Resort featuring exciting attractions,
international pavilions, award-winning fireworks and seasonal special events.</p>
</details>
Semantic Elements in HTML5
HTML <summary> Tag
• The <summary> tag defines a visible heading for the <details> element. The heading can be
clicked to view/hide the details.
• The <summary> element should be the first child element of the <details> element.
<details>
<summary>Epcot Center</summary>
<p>Epcot is a theme park at Walt Disney World Resort featuring exciting attractions,
international pavilions, award-winning fireworks and seasonal special events.</p>
</details>
Semantic Elements in HTML5
HTML <main> Tag
• The <main> tag specifies the main content of a document.
• The content inside the <main> element should be unique to the document. It should not
contain any content that is repeated across documents such as sidebars, navigation links,
copyright information, site logos, and search forms.
• There must not be more than one <main> element in a document. The <main> element must
NOT be a descendant of an <article>, <aside>, <footer>, <header>, or <nav> element.
<main>
<h1>Most Popular Browsers </h1>
<p>Chrome, Firefox, and Edge are the most used browsers today. </p>
<article>
<h2>Google Chrome </h2>
<p>Google Chrome is a web browser developed by Google, released in 2008. Chrome is the world's most popular
web browser today! </p>
</article>
<article>
<h2>Microsoft Edge </h2>
<p>Microsoft Edge is a web browser developed by Microsoft, released in 2015. Microsoft Edge replaced Internet
Explorer.</p>
</article>
</main>
Semantic Elements in HTML5
HTML <mark> Tag
• The <mark> tag defines text that should be marked or highlighted.
<figure>
<img src="pic_trulli.jpg" alt="Trulli">
<figcaption>Fig1. - Trulli, Puglia, Italy.</figcaption>
</figure>
Semantic Elements in HTML5
The HTML <video> Element
• To show a video in HTML, use the <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 page might flicker while the video loads.
• The <source> element allows you to specify alternative video files which the browser may
choose from. The browser will use the first recognized format.
• The text between the <video> and </video> tags will only be displayed in browsers that do
not support the <video> element.
• To start a video automatically, use the autoplay attribute
• Add muted after autoplay to let your video start playing automatically (but muted)
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.font = "30px Arial";
ctx.strokeText("Hello World", 10, 50);
</script>
HTML5 Svg Element
• What is SVG?
SVG stands for Scalable Vector Graphics
SVG is used to define graphics for the Web
SVG is a W3C recommendation
• SVG defines vector-based graphics in XML format.
• The HTML <svg> element is a container for SVG graphics.