HTML is the language we use to write web pages.
It is concerned only with content and structure,
not with appearance.
The World Wide Web Consortium (W3C) current version is HTML5.
HTML is the markup that turns text documents into web pages.
Primarily, it indicates document structure.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Welcome!</title>
</head>
<body>
<h1>Welcome to my web page!</h1>
<p>
This is a paragraph. Good, isn't it?
</p>
</body>
</html>
HTML uses tags for markup.
Tags generally come in pairs, e.g.:
start tag | end tag |
---|---|
<head> |
</head> |
<p> |
</p> |
But not always! E.g. <meta … />
The DOCTYPE tells the browser which version of HTML you are using.
For HTML5, the DOCTYPE is much simplified:
<!DOCTYPE html>
After the DOCTYPE, everything is enclosed between <html>
and </html>
tags.
The document is divided into <head>
…</head>
and
<body>
…</body>
The head gives information about the document.
The title and favicon appear in a browser tab.
The body contains the real content of the document.
It appears in the browser window below the menu bar.
h1
<h1>Welcome to my web page!</h1>
h2, h3, h4, h5, h6
h1
), sections (h2
), subsections
(h3
).p
tags to delimit paragraphs:
<p>
This is a paragraph. Good, isn't it?
</p>
<p>
This is another paragraph. It's not as good as the first
one, in my opinion.
</p>
Simply leaving blank lines does not work:
<p>
This is a paragraph. Good, isn't it?
This sentence will be in the same paragraph, not a new
one.
</p>
<p>
elements.
For lists where the ordering of the items is unimportant
(usually shown with bullet points)
<ul>
<li>Sex</li>
<li>Drugs</li>
<li>Rock'n'Roll</li>
</ul>
For lists where the ordering of the items is relevant
(usually shown with numbers)
<ol>
<li>I came</li>
<li>I saw</li>
<li>I conquered</li>
</ol>
To tabulate data, use an HTML table:
Service | Price (euros) |
---|---|
Dry cut | 12 |
Beard trim | 10 |
<table>
<tr>
<th>Service</th>
<th>Price (euros)</th>
</tr>
<tr>
<td>Dry cut</td>
<td>12</td>
</tr>
<tr>
<td>Beard trim</td>
<td>10</td>
</tr>
</table>
A web page comprises a DOCTYPE followed by
elements, text and comments.
<p>This is an example of an element.</p>
<!-- This is an example of a comment. -->
An HTML element =
start tag + content + end tag
<p>This is an example of an element.</p>
… except for void elements,
which have start tag but no content and no end tag, e.g.
<meta … />
start tag + content + end tag
An element's content can be text but it can also be one or more other elements nested inside it, or even a mix of both.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Welcome!</title>
</head>
<body>
<h1>Welcome to my web page!</h1>
<p>
This is a paragraph. Good, isn't it?
</p>
<p>
This is another paragraph. It's not as good as
the first one, in <em>my</em> opinion.
</p>
</body>
</html>