We’re moving to a new home! Our website is currently in test mode while we update and transfer our content. Some pages and resources may be temporarily unavailable. We’ll be back with all resources shortly. Thank you for your patience.

HTML & CSS | 01.1 Your First HTML Page

Lesson objective

Create, save and open a simple HTML page. Explain tags, elements and attributes, and distinguish the document head from its visible body.

Learn

01.1 | YOUR FIRST PAGE AND THE HTML DOCUMENT STRUCTURE

01 | WHAT ARE YOU BUILDING?

Every web page needs content and structure. HTML HyperText Markup Language describes that structure. It tells a browser which text is a heading, which text is a paragraph, and where other content belongs.

Think of a page as a well-organized document. HTML labels the parts. CSS will control their appearance, and JavaScript can add behaviour. In this first lesson, focus on giving a short page a sensible structure.

HTML is a markup language, rather than a programming language for calculations and decision-making. A browser reads the markup and renders the page you see.

02 | YOUR FIRST ELEMENT

<p>I am learning HTML.</p>

The browser displays “I am learning HTML.” as a paragraph. The markup itself is not shown as ordinary page text.

A tag is part of an element not another word for the whole element
PartExamplePurpose
Opening tag<p>Starts the paragraph
ContentI am learning HTML.The text inside it
Closing tag</p>Ends the paragraph
Element<p>I am learning HTML.</p>The complete paragraph structure

Most elements have an opening and a closing tag. The slash in the closing tag matters. Some elements, such as <meta>, are void elements and do not have closing tags.

You can put elements inside other elements. Close nested elements in the reverse order to opening them:

<p>I am building <strong>my first page</strong>.</p>

03 | THE COMPLETE DOCUMENT

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My first website</title>
</head>
<body>
  <h1>Welcome to my website</h1>
  <p>I am learning to build web pages.</p>
</body>
</html>

The indentation makes the structure easier for people to read. It is not what makes the heading larger the <h1> element has meaning and browsers provide default styles.

Follow the nesting: the document has an outer <html> element, containing <head> followed by <body>. The heading and paragraph belong inside the body.

04 | WHAT EACH PART DOES

Read this alongside the complete example
MarkupMeaning
<!DOCTYPE html>A declaration at the start that requests modern standards-mode rendering. It is not a normal content element.
<html lang="en">The root element. lang identifies the main language as English.
<head>Document metadata and links to resources not the visible page heading.
<meta charset="UTF-8">Declares the character encoding, so characters are interpreted appropriately.
<meta name="viewport" …>Sets the initial mobile viewport to the device width. It helps responsive pages but does not replace responsive CSS.
<title>The document title, usually shown in the browser tab.
<body>Contains the page content displayed in the browser.
<h1>A top-level heading in the visible page.
<p>A paragraph.

Head is not heading: <head> contains document information, while <h1> is a heading in the body. Changing the title changes the tab label; changing the h1 changes the visible heading.

The title is not unimportant simply because it is outside the body. It helps users identify tabs and bookmarks.

05 | ATTRIBUTES ADD INFORMATION

<html lang="en">

An attribute gives extra information about an element. It usually appears in the opening tag as a name and value. In this example, lang is the attribute name and en is its value.

Use straight quotation marks around attribute values. Follow the examples exactly at first; formatting your code consistently makes mistakes easier to spot.

A common beginner mistake is to think the language attribute translates the text. It does not: it identifies the language of the content for browsers and assistive technologies.

06 | CREATE AND OPEN THE FILE

  1. Create a folder called first-website.
  2. Open a plain-text code editor. Create a new file and paste the complete document above.
  3. Save it inside your folder as index.html. Check that it is not called index.html.txt.
  4. Open the file in a web browser for example, by using the browser’s Open File option.
  5. Change the h1 text in your editor, save the file, and refresh the browser.

You do not need hosting, a database or a server to view this simple local HTML file. Opening it on your computer does not publish it online.

Use plain text, not a word processor document. Rich-text formatting and “smart quotes” can introduce characters you did not intend. If the browser shows your code as text, check the file extension and that the file was saved as plain text.

07 | TRY IT: EDIT AND PREVIEW

Change the tab title, heading and paragraph below, then select Run preview. This preview supports basic HTML only; scripts, external resources and navigation are blocked.

Rendered body content

Document title:

Edits stay while this page is open. Copy your finished code into your own index.html file to keep it.

MATCH THE STRUCTURE

Choose the role of each part.

08 | FIX COMMON MISTAKES

Debug by checking one small thing at a time
ProblemWhat to check
The browser shows the old headingSave the edited file, then refresh; check you opened the same file.
The file opens as plain textCheck .html rather than .txt and use a plain-text editor.
The tab title changed but the heading did notYou edited <title>; edit <h1> to change the visible heading.
Text is unexpectedly bold or nestedCheck closing tags and nesting order.
The layout is simple and unstyledThat is expected. CSS comes later; browser defaults still show structure.

Browsers often try to recover from malformed HTML. A page looking acceptable does not prove the markup is correct. Develop good habits: use a complete document, tidy indentation and correctly nested elements.

Further reading: MDN: creating HTML content.

Terminology

Terminology

HTML

HyperText Markup Language: markup that describes web content and structure.

Tag

Markup such as <p> or </p> marking an element’s boundary.

Element

A part of the document, often consisting of an opening tag, content and closing tag.

Attribute

Extra information on an element, usually written in its opening tag.

Nesting

Putting an element inside another, with properly ordered closing tags.

Doctype

The <!DOCTYPE html> declaration used for modern standards-mode rendering.

Head

The document metadata container, distinct from its visible headings.

Body

The element containing the displayed page content.

Title

The document title, usually shown in the browser tab.

Void element

An element such as meta that has no content or closing tag.

Rendering

The browser interpreting document structure to display a page.

File extension

The end of a filename indicating its type, such as .html.

Questions

Questions

TICK-BOX KNOWLEDGE CHECK

Select all correct answers. One point per exact set.

1. What is HTML mainly used for?
2. Which belong in head in our example?
3. Which belong in body?
4. Which statements are correct?
5. Which filename is appropriate for a simple HTML homepage?
6. Which is correctly nested?
7. Which steps let you see an edit in your local page?
8. Which are true?

EXPLAIN AND DEBUG

Answer in your book or discuss with a partner before revealing the samples.

1. Explain the difference between title and h1.

2. Identify the tag, content and complete element in <p>Hello</p>.

3. Correct this nesting: <p>I enjoy <strong>robotics</p></strong>.

4. Explain why a changed page might still show old text.

5. Why include lang="en"?

BUILD | A PAGE ABOUT YOUR NEXT IDEA

Create an index.html page introducing a project you would like to build. Use a complete document and make the tab title different from the visible heading.

The checklist is for self-review. There is no automatic score for this practical task.

Flashcards

Flashcards

Click to flip a card. Tick the ideas you need to learn.

0 cards selected for revision.

    Selections are kept while this page is open.

    Workbook

    Workbook

    COMING SOON

    The workbook for 01.1 Your First HTML Page is coming soon. For now, complete the practical build task and keep your index.html file.