HTML: your first web page

Lesson 1 of 17 · HTML, CSS and JavaScript

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.

Before you start: required prior knowledge – what the web is, frontend and backend.
How to learn: do the tasks at the end on your own in your editor first; open the hint and the solution only after that. Every example has the code and a live result below it; type the code into your own file and change it.

What you need

ToolWhat it is forNote
Visual Studio Codea code editor: colours the code, completes tags, reports errorsfree; 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 editorworking without installationCodePen, 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.

Tags, elements and attributes

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>.

The skeleton of every HTML page

<!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:

PartMeaning
<!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.

Headings and paragraphs

<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.

Nesting and indentation

Elements are placed inside one another and closed in reverse order:

CorrectWrong
<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.

Tip: right-click any element on a page → Inspect (or F12) shows its HTML and CSS. You can change the values live – the change lasts until you refresh the page.

Practice tasks

Each task has an example, a hint and a solution. The solutions have been checked in the browser.

TASK 01Difficulty: easy

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.

TASK 02Difficulty: medium

Find the mistakes

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>
Common mistakes and tips
  • A forgotten <meta charset="utf-8"> – letters such as é, ü, č, š turn into strange characters.
  • A closing tag without the slash: <h1>...<h1> opens a new heading instead of closing the old one.
  • Headings are chosen by meaning (h1 → h2 → h3), not by font size.
  • The file must be saved (Ctrl+S) before you refresh the browser – otherwise you see the old version.

Check your knowledge

Open the quiz

Your first web page

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?