Meaning of the text
Coded with HTML
How it looks
Coded with CSS
(up/down arrow to unfold)
Example of HTML document
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> Titre du document </title>
</head>
<body>
Contenu du document
</body>
</html>
Starts with the specification of the language
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> Titre du document </title>
</head>
<body>
Contenu du document
</body>
</html>
A single tree with root html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> Titre du document </title>
</head>
<body>
Contenu du document
</body>
</html>
Meta-data in the first child head
of html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> Titre du document </title>
</head>
<body>
Contenu du document
</body>
</html>
Specify the character encoding
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> Titre du document </title>
</head>
<body>
Contenu du document
</body>
</html>
Specify the window title
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> Titre du document </title>
</head>
<body>
Contenu du document
</body>
</html>
The second child of html
contains the actual document
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> Titre du document </title>
</head>
<body>
Contenu du document
</body>
</html>
<main>
<header>
, <footer>
<section>
<h1>
, ..., <h6>
<article>
<aside>
<nav>
<address>
<p>
<pre>
<iframe>
<div>
<ol>
<ul>
<li>
<dl>
<dt>
, <dd>
<table>
<tr>
, <th>
, <td>
<form>
<input>
, <textarea>
, <select>
<img>
<object>
, <audio>
, <video>
<a>
<em>
, <strong>
<cite>
<quote>
<abbr>
<time>
<code>
, <var>
<sup>
, <sub>
<span>
No need to close always-empty tags
<meta charset="UTF-8">
<img src="image.png">
<link rel="stylesheet" href="style.css">
But not true for other XML languages, such as SVG
It is possible to inspect the HTML code of an element
With Firefox: Right-Click ⟶ Inspect Element
(up/down arrow to unfold)
CSS Zen Garden for an example of what can be done with CSS.
Try another CSS, and another one, and again another one...
h3 { /* h3 is the selector */
font-family: sans-serif;
font-style: italic !important; /* rule tagged as important */
}
A declaration is made of
Beware Do NOT forget the semicolon...
Note: indentation is meaningless
The main classes of selectors are as follows
*
h1
or p
.classname
#identifier
Can be combined/adapted/modified in various manners
The official, complete list can be found on the W3C webpage
Whenever for a given elements two rules are
contradictory,
a cascading decision algorithm is
followed.
By increasing priority
!important
!important
If still tie, more specific selectors win, then order of apparition
myfile.html
<!DOCTYPE html>
<html lang="en">
<head>
…
<link rel="stylesheet"
href="myfile.css">
…
</head>
…
</html>
myfile.css
* {
color: blue;
text-align: left;
}
h2 {
font-weigth: bold;
}
…
1fr
into 2fr
and 3fr
...
Wide range of user needs
So make use of the semantics elements to give meaning
Stay agnostic on the presentation
Best practice thought and designed by... the W3C of course
Wide scale of browser types
Need to adapt to different viewports
(up/down arrow to unfold)
<!DOCTYPE html>
<html lang="en">
<head>
…
<meta name="viewport"
content="width=device-width, initial-scale=1">
…
</head>
…
</html>
More
information for
example here
Some types of media
all
print
screen
speech
With constraints
screen and (min-width: 480px)
screen and (orientation: landscape)
myfile.html
<!DOCTYPE html>
<html lang="en">
<head>
…
<link rel="stylesheet"
src="myfile.css"
media="print">
…
</head>
…
</html>
myfile.css
h1 {
color: blue;
/* style for all media */
}
@media print {
/* style only media print */
}
@media only screen
and (min-device-width: 375px)
and (max-device-width: 812px)
and (orientation: portrait) {
/* CSS, smartphone portrait */
}
@media only screen
and (min-device-width: 375px)
and (max-device-width: 812px)
and (orientation: landscape) {
/* CSS, smartphone landscape */
}
@media only screen
and (min-device-width: 813px) {
/* CSS Rules for "large" screens */
}
Beware: make sure to capture all cases,
or to give a default behavior.