Web Programming Course
SUT • Fall 2018
Image © Wikipedia
New Doctype
<!DOCTYPE html>
Simpler Character Encoding
<!DOCTYPE html>
<!-- HTML 4.01 -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!-- some authors might miss the quotes: -->
<meta http-equiv=content-type content=text/html; charset=UTF-8>
<!-- HTML 5 -->
<meta charset="UTF-8">
New Input Types
<!DOCTYPE html>
<input type="time">
<input type="date">
<input type="datetime-local">
<input type="month">
<input type="week">
<input type="color">
<input type="number">
<input type="email">
<input type="url">
<input type="search">
<input type="tel">
<input type="range" min="1" max="10" step="2">
Online Demo
More on MDN
New Form Elements
<!DOCTYPE html>
<form oninput="result.value=parseInt(a.value)+parseInt(b.value)">
<input type="range" name="b" value="50"> +
<input type="number" name="a" value="10"> =
<output name="result">60</output>
</form>
<output>
More on MDN
New Form Elements
<!DOCTYPE html>
<label for="myBrowser">Choose a browser from this list:</label>
<input list="browsers" id="myBrowser" name="myBrowser">
<datalist id="browsers">
<option value="Chrome">
<option value="Firefox">
<option value="Internet Explorer">
<option value="Opera">
<option value="Safari">
<option value="Microsoft Edge">
</datalist>
<datalist>
More on MDN
<body>
<div id="header"> ... </div>
<div id="nav"> ... </div>
<div class="article">
My Awesome Article...
<span class="author"> by John Doe </span>
<a href="#2018-04-13"> April 13, 2018 </a>
</p>
</div>
<div id="aside"> ... </div>
<div id="footer"> ... </div>
</body>
Semantic Elements Overview
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Sample HTML5 document</title>
</head>
<body>
<header> ... </header>
<nav> ... </nav>
<article>
<section> ... </section>
</article>
<aside> ... </aside>
<footer> ... </footer>
</body>
</html>
Semantic Elements Overview
<!DOCTYPE html>
<header>
...
</header>
<nav>
...
</nav>
<article>
<section>
...
</section>
</article>
<aside>
...
</aside>
<footer>
...
</footer>
Online Demo
Other New Elements
<!DOCTYPE html>
<progress value="70" max="100">70 %</progress>
<meter min="200" max="500"
value="350">350 degrees</meter>
<audio controls>
<source src="horse.ogg" type="audio/ogg">
Your browser does not support the audio element.
</audio>
<video width="300" controls>
<source src="mov_bbb.mp4" type="video/mp4">
<source src="mov_bbb.ogg" type="video/ogg">
Your browser does not support HTML5 video.
</video>
New Attributes
<!DOCTYPE html>
<p contenteditable>This is a paragraph</p>
<img src="loading.gif" data-src="..." alt="">
<p>
<span> To be </span>
<span hidden> or not to be </span>
</p>
contenteditable
data-*
hidden,
...
This is a paragraph but it is an editable one!
To be or not to be
Form Validation
<!DOCTYPE html>
<form action="user_favorites" method="post">
<div>
<label for="choose">Would you prefer an apple or an orange?</label>
<input id="choose" name="i_like" required pattern="apple|orange">
</div>
<div>
<label for="number">How many would you like?</label>
<input type="number" id="number" name="amount"
value="1" min="1" max="10">
</div>
<div>
<button type="submit">Submit</button> or
<button type="reset">Reset</button>
</div>
</form>
Online Demo
More on MDN
To ensure that users fill out forms in the correct format
Form NO Validation
<!DOCTYPE html>
<form action="user_favorites" method="post" novalidate>
<div>
<label for="choose">
Would you prefer an apple or an orange?
</label>
<input id="choose" name="i_like"
required pattern="apple|orange">
</div> ...
<div>
<button type="submit">Submit</button>
</div>
</form>
Online Demo
More on MDN
To prevent the native form validation
Form Input Placeholders
<!DOCTYPE html>
<form action="login" method="post">
<h1>Login Form</h1>
<input type="email" name="email"
placeholder="john@doe.com">
<input type="password" name="password"
placeholder="password">
<input type="submit" value="Login">
</form>
Online Demo
More on MDN
To show an example input
Note: placeholder might lead to bad UX
More on MDN & HTML5Doctor
HTML 4.01
HTML 5
Elements having a meaning, a role.
The semantic tree-like structure of a web page
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
More on MDN
Markup
Output
Outline
HTML5 proposed a new algorithm to overcome the 6-level limit
<h1>My fantastic site</h1>
<section>
<h1>About me</h1>
<p> I am a man who lives a
fascinating life...</p>
<section>
<h1>What I do for a living</h1>
<p>I sell enterprise-managed
ant farms.</p>
</section>
</section>
<section>
<h1>Contact</h1>
<p>Shout my name
and I will come to you.</p>
</section>
More on HTML5Doctor
Markup
Outline
The Idea is a bit older back to 1991:
I would in fact prefer, instead of <H1>, <H2> etc for headings to have a nestable <SECTION>..</SECTION> element, and a generic <H>..</H> which at any level within the sections would produce the required level of heading.
<body>
, <blockquote>
, <figure>
, <details>
, <fieldset>
, <td>
An isolated part of a document having their own separate outlines
Define a new section in the outline
Try Online
There are currently no known native implementations of the outline algorithm in graphical browsers or assistive technology user agents, although the algorithm is implemented in other software such as conformance checkers and browser extensions. Therefore the outline algorithm cannot be relied upon to convey document structure to users. Authors should use heading rank (h1-h6) to convey document structure.
More on MDN, Medium, Chrome Devtools