By the end of this lesson you will be able to
- Explain that HTML describes the structure and meaning of a page, not how it looks.
- Identify the opening tag, content, closing tag and attributes of an element.
- Write the skeleton of a valid HTML page with a title, headings and paragraphs.
- Add a link, an image with alternative text and a list to a page.
- Use the live editor to change HTML and describe the effect of each change.
Every web page you have ever read, from a school notice to an online shop, is a text file written in HTML. Your browser reads that file and turns it into the page you see. Learning HTML shows you what a page is really made of, and it is the first step to making your own page, however small. You need no special software: a text editor, or the live editor in this lesson, is enough.
What HTML is
HTML stands for HyperText Markup Language. A markup language is plain text with labels added to say what each piece of text is: this is a heading, this is a paragraph, this is a link. HTML does not decide colours or fonts. It describes the structure and meaning of the page. Appearance is the job of CSS, which you meet in the next module.
Think of a school exercise book. A title at the top, a numbered list of questions and a note in the margin all have different roles, even before anyone chooses a pen colour. HTML marks those roles. When your Browser downloads a file such as index.html from a Web server, it reads the labels and draws the page.
- Step 1: Server holds index.html
- Step 2: Browser downloads it
- Step 3: Browser reads the tags
- Step 4: Page is drawn
Read this figure as text
A flow showing an HTML file on a server being downloaded, read by the browser and shown as a page.
Four numbered boxes joined by arrows. Step 1: a server holds the file index.html. Step 2: your browser asks for it and downloads it. Step 3: the browser reads the labels (tags) in the text. Step 4: the browser draws headings, paragraphs, links and images on screen.
Elements, tags and attributes
The building block of HTML is the element. Most elements have an opening tag, some content and a closing tag. A tag is a word inside angle brackets: <p> opens a paragraph and </p> closes it. The slash in the closing tag is what makes it a closing tag. Together, the opening tag, content and closing tag make one element.
Some tags carry extra information called attributes. An attribute sits inside the opening tag as a name, an equals sign and a value in quotation marks. In the link below, href is the attribute name and the web address is its value. The text between the tags, "Visit the example site", is what the reader sees and clicks.
<a Opening tagStarts the link elementhrefAttribute nameSays what extra information follows="https://example.org"Attribute valueWhere the link goes>Visit the example siteContentThe words the reader sees</a>Closing tagEnds the elementRead this figure as text
A link element split into its opening tag, attribute name, attribute value, content and closing tag.
The text <a href="https://example.org">Visit the example site</a> is split into five labelled parts. The opening tag starts with <a. The attribute name is href. The attribute value is "https://example.org", which is where the link goes. The content is Visit the example site, which the reader sees. The closing tag is </a>.
The skeleton of every page
Every HTML page has the same outer shape. The first line, <!doctype html>, tells the browser to treat the file as modern HTML. The <html> element wraps everything and lang="en" states the language, which helps screen readers pronounce the words correctly. Inside, <head> holds information about the page that is not drawn in the main area, and <body> holds everything the reader sees.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Amina's Garden Club</title>
</head>
<body>
<h1>Welcome to the garden club</h1>
<p>We meet every Saturday morning to grow vegetables together.</p>
</body>
</html>Line by line: <meta charset="utf-8"> says which character set the file uses, so letters with accents and symbols display correctly. The viewport line makes pages behave sensibly on phones (you will use it again in the responsive design lesson). The <title> text appears on the browser tab and in search results. The indentation is only for people; the browser ignores it.
- html
- headInformation about the page
- meta charset
- meta viewport
- titleShown on the tab
- bodyWhat the reader sees
- h1Main heading
- pParagraph
Read this figure as text
A tree with html at the top, head and body below it, and the elements that sit inside each.
The top element is html. It has two children: head and body. Inside head are meta charset, meta viewport and title. Inside body are an h1 heading and a p paragraph. This nesting, with elements inside other elements, is how every HTML page is organised.
Headings, paragraphs, links, images and lists
Headings run from <h1> (the most important) down to <h6>. Use one <h1> per page for the main title, then <h2> for sections and <h3> for parts of sections. Choose headings by their level in the outline, not by how large they look; size is changed later with CSS. Paragraphs use <p>. Browsers ignore extra spaces and blank lines in your file, so two paragraphs need two <p> elements.
A link uses the <a> (anchor) element with an href attribute. An address starting with https:// goes to another site. A name such as about.html goes to another file in the same folder. An image uses <img>, which is a void element: it has no content and no closing tag. Its src attribute says which file to show, and its alt attribute holds a short text description for people who cannot see the picture.
<h1>Garden club</h1>
<h2>This month</h2>
<p>Read the <a href="https://example.org/seeds">seed guide</a> before Saturday.</p>
<img src="tomatoes.jpg" alt="Ripe red tomatoes growing on a vine" width="300">
<h2>What to bring</h2>
<ul>
<li>Gloves</li>
<li>A water bottle</li>
</ul>
<h2>Our routine</h2>
<ol>
<li>Dig the beds</li>
<li>Plant the seedlings</li>
<li>Water them</li>
</ol><ul> makes an unordered (bulleted) list and <ol> makes an ordered (numbered) list. Each item is an <li> inside the list. Notice the nesting: <li> elements live inside <ul>, so they are closed before the </ul>. If tomatoes.jpg is not in the same folder as your page, the image will show as a broken picture, because src is a file path just like the ones you learned in the files module.
| Element | Meaning | Example |
|---|---|---|
<h1> to <h6> | Headings, from most to least important | <h2>Contact</h2> |
<p> | A paragraph of text | <p>Hello.</p> |
<a href="..."> | A link to another page or file | <a href="about.html">About</a> |
<img src="..." alt="..."> | An image (no closing tag) | <img src="cat.jpg" alt="A grey cat"> |
<ul> / <ol> and <li> | A bulleted or numbered list and its items | <ul><li>Tea</li></ul> |
<strong> and <em> | Strong importance and emphasis | <strong>Closed</strong> |
Try it in the live editor
The best way to learn HTML is to change it and watch what happens. The editor below runs entirely in your browser. It shows a safe preview and cannot change any file on your computer. Nothing you type is sent anywhere.
Change the headings, add a link and a list, then look at the preview. Try deleting a closing tag to see what the browser does.
Loading lab…
Guided changes in the editor
Step 1: Change a heading
Edit the text inside an
<h1>element to say your own name or a club name.You should see: The big heading in the preview changes as you type.
Step 2: Add a paragraph
Below the heading, type
<p>then a sentence then</p>.You should see: A new paragraph appears under the heading.
Step 3: Add a link
Inside the paragraph, add
<a href="https://example.org">my link</a>.You should see: The words "my link" appear in link colour.
Step 4: Break it on purpose
Delete one closing
</p>tag and look at the preview, then put it back.You should see: The layout may change in an odd way. Putting the tag back repairs it.
Common mistakes
✖ Instead of: Saving the page as
index.html.txtbecause Notepad added.txt.✔ Do this: Choose All files as the type when saving, and check that the name ends only in
.html. Turn on file extensions in File Explorer if you cannot see them.✖ Instead of: Using many blank lines or spaces in the file to space out the page.
✔ Do this: Browsers collapse extra whitespace. Use separate elements such as
<p>, and use CSS for spacing.✖ Instead of: Leaving out
alton images, or writing "image" as the alt text.✔ Do this: Describe what the picture shows in a short phrase, such as "Ripe red tomatoes growing on a vine".
✖ Instead of: Using curly quotation marks around attribute values after pasting from a word processor.
✔ Do this: Use plain straight quotes (
"). Type the page in a plain text editor, not in a word processor.
If something goes wrong
- My page opens as plain code text instead of a styled page.
- The file probably ends in
.txt. Rename it so it ends in.html, then open it again in the browser. - My image shows as a broken picture icon.
- Check that the file named in
srcexists, that it is in the right folder next to your page and that the spelling and capital letters match exactly. - My link does nothing or goes to the wrong place.
- Check that the
hrefvalue is inside quotation marks and spelled correctly. A link to another site needs the fullhttps://address. - I changed the file but the browser shows the old page.
- Save the file again, then refresh the browser page with F5 (or Ctrl and R).
Key terms
- HTML tag
- A word inside angle brackets that marks the start or end of an HTML element.
- HTML attribute
- Extra information placed inside an opening tag as a name and a value.
- Hyperlink
- Text or an image on a web page that takes you to another page or file when you select it.
Practise it for real
Reading is not the same as being able to do it. Complete these on your own computer, then tick only what you have actually done. These ticks are your own honest record: nothing checks them for you.
Build a one-page profile
In the live editor, write a page about a fictional club or hobby. Include a title, an <h1>, two <h2> sections, at least two paragraphs, one link to https://example.org, and one bulleted list with three items. Read the preview after each change.
Save and open a real page
Open Text Editor (Ubuntu) or Notepad (Windows). Type the minimal page from this lesson, change the title and the heading to your own words and save it as index.html in a new folder called mysite. Open it by double-clicking. Windows hint: in the Save dialog set "Save as type" to All files so Notepad does not add .txt.
Challenge: fix the broken page
Paste this broken snippet into the editor and repair it without being told what is wrong: <h1>Market day<h1> <p>Open on <strong>Sundays</p></strong> <img src="stall.jpg"> <ul><li>Fruit<li>Bread</ul>. Then explain each fix in one sentence.
Knowledge check
6 questions. You need 80% to pass. Mistakes here are part of learning, and you can retry as often as you like.
Summary
- HTML marks up the structure and meaning of a page; CSS handles looks.
- An element is an opening tag, content and a closing tag, with attributes inside the opening tag.
- Every page has doctype, html, head (title) and body.
- Use headings by level, paragraphs for text, `<a href>` for links and `<img>` with alt for pictures.
- Lists use `<ul>` or `<ol>` with `<li>` items inside.
Checklist: can you do these?
Marking a lesson as read does not prove you can do it. Skills count as demonstrated when you pass the quiz (not yet) and complete the practical tasks (not yet).
Related lessons
References and further reading
Official sources for details that can change between versions.
- HTML: HyperText Markup Language (MDN Web Docs)
- Getting started with HTML (MDN Web Docs)
- HTML element reference (MDN Web Docs)