An "About me" page
Make a page about_me.html with the tab title "About me", a main heading with your name, two subheadings ("Hobbies" and "Favourite subjects") and one paragraph below each of them.
HTML (HyperText Markup Language) describes the structure of a web page: what is a heading, what is a paragraph, where an image is and where a link is. In this lesson you prepare your tool, write your first page and open it in the browser – without installing a server.
| Tool | What it is for | Note |
|---|---|---|
| Visual Studio Code | a code editor: colours the code, completes tags, reports errors | free; the Live Server extension refreshes the page automatically when you save the file |
| a browser (Chrome, Firefox, Edge) | shows the page and has developer tools (F12) | you already have one |
| an online editor | working without installation | CodePen, JSFiddle |
Make a folder my_site, open it in VS Code (File → Open Folder) and make a file index.html in it. The name index.html is a convention: it is the folder's home page, which the server shows when no file name is given.
HTML is written with tags in angle brackets. Most of them come in pairs – an opening and a closing tag, with the content between them. Together they make an element:
<p>This is a paragraph.</p>
└┬┘└───────┬───────┘└┬─┘
opening content closing tag (with /)
Attributes give an element extra data and are written in the opening tag as name="value":
<a href="https://developer.mozilla.org">MDN</a>
<img src="logo.png" alt="School logo">
Some elements have no content and therefore no closing tag: <img>, <br>, <hr>, <input>, <meta>.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My first page</title>
</head>
<body>
<h1>Hello, world!</h1>
<p>This is my first web page. I made it in HTML.</p>
<!-- comment: the browser does not show this -->
</body>
</html>
Result:
| Part | Meaning |
|---|---|
<!DOCTYPE html> | tells the browser that this is modern HTML (HTML5) |
<html lang="en"> | the whole document; lang helps search engines and screen readers |
<head> | data about the page – not visible on the page |
<meta charset="utf-8"> | the character encoding – without it letters such as é, ü, č, š are shown incorrectly |
<meta name="viewport" ...> | the page is shown properly on a phone |
<title> | the title on the browser tab and in search results |
<body> | everything that is visible on the page |
<!-- ... --> | a comment for the programmer |
In VS Code it is enough to type ! in an empty file and press Tab – the editor writes the skeleton itself.
<h1>Page title (h1)</h1>
<h2>Chapter (h2)</h2>
<h3>Section (h3)</h3>
<p>A paragraph is a block of text. The browser joins several spaces
and line breaks into a single space.</p>
<p>A new line inside a paragraph:<br>is made with the br tag.</p>
<hr>
<p>Above is a horizontal line (hr).</p>
Result:
There are six levels of headings, from h1 to h6. A page should have one h1 (the main title), and the others follow in order like chapters in a book – they are not chosen by font size; CSS is used for that.
Elements are placed inside one another and closed in reverse order:
| Correct | Wrong |
|---|---|
<p>This is <strong>important</strong>.</p> | <p>This is <strong>important.</p></strong> |
Indent the content of an element by 2 spaces – it makes no difference to the browser, but it is much easier for you to see what is inside what. In VS Code Shift+Alt+F tidies the code for you.
Each task has an example, a hint and a solution. The solutions have been checked in the browser.
Make a page about_me.html with the tab title "About me", a main heading with your name, two subheadings ("Hobbies" and "Favourite subjects") and one paragraph below each of them.
There are four mistakes in the code below. Find them and fix them.
<html>
<head>
<title>Café</title>
</head>
<body>
<h1>Our school café<h1>
<p>It is next to the <strong>gym.</p></strong>
</body>
<meta charset="utf-8"> – letters such as é, ü, č, š turn into strange characters.<h1>...<h1> opens a new heading instead of closing the old one.1. Which part of an HTML document is visible on the page?
2. What is <meta charset="utf-8"> for?
3. How many h1 headings should a page have?
4. How are nested tags closed correctly?