Byte by Byte › Book 6: Python, Data and How Computers Work › Chapter 10: Building Web Pages with HTML
Chapter 10: Building Web Pages with HTML
You will learn: what HTML is and how a browser displays it, the parts of an HTML element (tags, content and attributes), the basic structure of every web page, how to add headings, paragraphs, lists, links, images and tables, how to write good alt text, how to add colour and alignment the modern way, and how to create, save and view a web page with Notepad and Microsoft Edge.
🌟 The Adventure
News of the Festival reached the surface faster than Memoon expected. Two days later, a small brown sparrow landed on the jetty, a notebook under one wing and a press badge on her chest. It was Pip, the reporter from The Memunic Times, whom Memoon had met at the Festival of Makers.
"A city of fish under the sea!" chirped Pip. "A giant ancient computer! A light show on a wall! My readers will love it. But I can't dive, and my editor wants it on the Light Bridges by Friday, as a proper page that every village can open."
Behind her came Old Bramble, the badger who ran the newspaper's reading room, walking carefully with his white cane. "And make sure I can read it too," he said with a smile. "My screen reader can read words aloud to me. But when a page is full of pictures with no descriptions, all it says is image, image, image."
Memoon had used thousands of web pages. She had learned in Book 3 how they travelled across the Light Bridges from a server to a browser. But she had never asked herself what a web page actually was inside.
She opened one in Edge, right-clicked, and chose View page source. The screen filled with words in angle brackets.
💡 Learn With Memoon
What is HTML? Every web page is a text file written in HTML, which stands for HyperText Markup Language. HTML was invented by the British scientist Tim Berners-Lee at CERN in Switzerland, as part of his invention of the World Wide Web around 1990.
- HyperText means text containing hyperlinks, which take you to other pages when you click them.
- Markup means extra labels added to text to say what each part is: this is a heading, this is a paragraph, this is a picture.
HTML is not a programming language. It has no variables, no loops and no decisions. It is a markup language: it describes the structure of content. The browser (such as Microsoft Edge) reads the HTML and decides how to display it. Displaying the page is called rendering.
Tags and elements. HTML labels are called tags. A tag is a word inside angle brackets. Most tags come in pairs:
<h1>Welcome to Pearlhaven</h1>
| Part | Example | Meaning |
|---|---|---|
| Opening tag | <h1> | Start of a level-1 heading |
| Content | Welcome to Pearlhaven | What the reader sees |
| Closing tag | </h1> | End of the heading; note the forward slash |
| Element | The whole thing | Opening tag + content + closing tag |
A few elements have no content and no closing tag. They are called empty elements: for example <br> (a line break) and <img> (an image).
Attributes. An attribute gives extra information about an element. It goes inside the opening tag, as a name, an equals sign and a value in quotes:
<a href="https://www.memunictimes.example">Read The Memunic Times</a>
Here href is the attribute name and the web address is its value.
The structure of every web page. Every HTML page follows the same skeleton:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Visit Pearlhaven</title>
</head>
<body>
<h1>Welcome to Pearlhaven</h1>
<p>A city of coral under the Data Sea.</p>
</body>
</html>
| Line | What it does |
|---|---|
<!DOCTYPE html> | Tells the browser this is a modern HTML page |
<html lang="en"> | Starts the page and says it is in English |
<head> | Information about the page, not shown in the page itself |
<meta charset="UTF-8"> | The page uses UTF-8 Unicode text (Chapter 4), so every script and emoji works |
<title> | The text shown on the browser tab and in search results |
<body> | Everything the reader actually sees goes in here |
Elements go inside other elements, like boxes inside boxes. This is called nesting. The rule is: close elements in the reverse order you opened them. <p><strong>Hi</strong></p> is correct; <p><strong>Hi</p></strong> is wrong. Indenting nested elements, as above, makes this easy to check.
Text elements.
| Element | Meaning | Example |
|---|
<h1> to Headings: h1 is the main title, h2 for sections, <h2>Things to do</h2>
<h6> | h3 for sub-sections, down to h6 |
<p> | A paragraph | <p>The coral towers glow at night.</p> |
<br> | A line break inside a paragraph | Line one<br>Line two |
<hr> | A horizontal line between sections | <hr> |
<strong> | Important text, shown in bold | <strong>Do not touch the eels.</strong> |
<em> | Emphasised text, shown in italics | It is <em>very</em> deep. |
<!-- --> | A comment: notes the browser ignores | <!-- Section 2 starts here --> |
Use only one <h1> per page, and use headings in order. Screen readers let blind users jump from heading to heading, so headings must show the real structure of the page, not just make text big. You may also see <b> and <i> for bold and italics. They still work, but <strong> and <em> are preferred because they say why the text is different, not just how it looks.
The browser ignores extra spaces and line breaks in your HTML. However many blank lines you type, a new paragraph only starts at a <p> .
Lists.
<h2>What to bring</h2>
<ul>
<li>A breathing bubble</li>
<li>A waterproof notebook</li>
<li>Good manners for octopuses</li>
</ul>
<h2>How to get there</h2>
<ol>
<li>Go to the jetty at Riverbend.</li>
<li>Ask Nimo for a bubble.</li>
<li>Swim down until you see the lights.</li>
</ol>
<ul> is an unordered list, shown with bullets. <ol> is an ordered list, shown with numbers. Each item is an <li> (list item). An ordered list can use letters or Roman numerals with the type attribute: <ol type="A"> or <ol type="i"> , and can begin at another number with start , for example <ol start="5"> .
Links. The <a> element (anchor) makes a hyperlink. Its href attribute is the address to go to:
<a href="https://www.python.org">Download Python</a> <a href="festival.html">See photos of the Festival</a>
The first is an absolute link: a full web address. The second is a relative link to another file in the same folder as this page. Adding target="_blank" opens a link in a new tab. Always make link text say where the link goes: "Download Python" is helpful, "click here" is not.
Images. The <img> element shows a picture:
<img src="glow-wall.jpg" alt="A giant glowing rangoli flower in magenta, gold and cyan on a dark wall above a coral city" width="400">
| Attribute | Meaning |
|---|---|
src | Source: the image file, or its web address |
alt | Alternative text: a description read aloud by screen readers, and shown if the image cannot load |
width (and Size in pixels. Give just one and the browser keeps the right shape height )
If you put the image in the same folder as your HTML file, src is just its file name. File names on the web should have no spaces and should match exactly, including capitals: Glow-Wall.JPG and glow-wall.jpg may not be the same file on a web server.
Writing good alt text. Describe what the picture shows and why it matters, in one sentence. Do not start with "image of" (the screen reader already says it is an image). A purely decorative image, such as a border, should have empty alt text: alt="" , so the screen reader skips it. Good alt text is part of accessibility: making technology usable by everyone, including people with disabilities. In many countries, including India, public websites are expected to meet accessibility guidelines.
Tables. A table is built row by row:
<table>
<tr>
<th>Event</th>
<th>Time</th>
</tr>
<tr>
<td>Glow Wall show</td>
<td>8 pm</td>
</tr>
<tr>
<td>Tide gate tour</td>
<td>10 am</td>
</tr>
</table>
<tr> is a table row. <th> is a header cell, shown in bold. <td> is an ordinary data cell. Tables are for data in rows and columns, such as timetables or results, not for arranging the layout of a page.
Colour and alignment: the old way and the modern way. Some older computer books teach tags such as <font color="red"> , <center> and attributes such as bgcolor and align . These are obsolete: they were removed from HTML years ago, and although many browsers still show them, you should not use them. Modern pages control appearance with CSS (Cascading Style Sheets). You will learn CSS properly in Book 7. For now, you can add small pieces of CSS to any element with the style attribute:
| What you want | Obsolete way (do not use) | Modern way |
|---|---|---|
| Red text | <font color="red"> | <p style="color: red;"> |
| Page background colour | <body bgcolor="lightblue"> | <body style="background-color: lightblue;"> |
| Centred heading | <center><h1> | <h1 style="text-align: center;"> |
| Font | <font face="Arial"> | <p style="font-family: Arial;"> |
| Text size | <font size="5"> | <p style="font-size: 24px;"> |
Colours can be names like teal or coral , or the hex codes you learned in Chapter 4, such as #FF8000 . Several properties can go in one style attribute, separated by semicolons: style="color: white; background-color: #003366;" . Choose colours with strong contrast so the text is easy to read.
Making and viewing your page.
- Make a folder called My Website in Documents.
- Open Notepad. Type your HTML.
- Click File → Save as. Go to your My Website folder. Change Save as type to All files. Type the name
index.html(the usual name for a site's home page). Check that Encoding is UTF-8. Click Save. - In File Explorer, double-click
index.html. It opens in Microsoft Edge. - Keep both windows open. After each change in Notepad, press Ctrl + S to save, then click on Edge and press F5 to refresh.
If you see your tags printed on the page, or the file opens in Notepad again, the file has probably been saved as index.html.txt . Turn on View → Show → File name extensions in File Explorer (from Book 3) to check.
Websites and the web. A website is a collection of linked web pages, usually with images, stored together. Your pages are on your own computer, so only you can see them. To put a site on the internet, the files must be copied to a web server, as you learned in Book 3. Never put personal information such as your full name, school, address, phone number or photos of yourself on a public web page.
💡 Memoon’s tip: Browsers are forgiving: they try to show a page even with mistakes in it, so a missing closing tag might not look wrong today. Check your code by eye, or paste it into the free checker at validator.w3.org.

✍️ Try It Yourself
Activity 1: Look inside a real page. Open any web page in Microsoft Edge, for example python.org. Press Ctrl + U to view its source. Use Ctrl + F to search for <h1 , <p , <a href and <img . Do the images have alt text? (Real pages also contain lots of CSS and JavaScript; ignore those for now.)
Activity 2: Your first page. Make the My Website folder and create index.html with the skeleton from this chapter. Change the title and heading to All About Me (use your first name only), and add two paragraphs: one about your hobbies and one about your favourite subject. View it in Edge.
Activity 3: Add structure. Add to your page:
- An
<h2>heading My Favourite Things followed by an unordered list of at least four items. - An
<h2>heading My Morning Routine followed by an ordered list of steps. - A horizontal line between the sections.
- One sentence with an important word in
<strong>and another with an emphasised word in<em>.
Activity 4: Links and images. Save a picture you have drawn in Paint (or one you have permission to use) into your My Website folder as picture.png . Add it to your page with a width of 300 and good alt text. Then add a link to a website you like, which opens in a new tab.
Activity 5: A second page. Create hobbies.html in the same folder with its own heading and a table of your weekly activities (Day, Activity, Time). Link the two pages together with relative links: index.html should link to hobbies.html , and hobbies.html should have a link back home. You have built a two-page website!
Activity 6: Style it. Using only the style attribute, give your page a background colour, centre the main heading, and change the colour of the <h2> headings using a hex code. Check that the text is still easy to read.
Unplugged: Mark it up. Take a printed page from a magazine or textbook. With a pencil, mark where the <h1> , <h2> , <p> , <ul> and <img> elements would be if it were a web page. Write alt text for every picture.
🎉 Memoon Solves It
Memoon built the page in Notepad, inside the Deep Engine, on a slate that Octavia connected to the Light Bridge cable. She gave it one <h1> : Visit Pearlhaven. Below it came <h2> sections for the city, the Deep Engine and the Festival of Tides, an ordered list explaining how to visit, a table of festival events, and a link to Pip's full article.
For the photo of the Glow Wall, she thought carefully about Old Bramble. Then she wrote:
alt="A giant glowing rangoli flower in magenta, gold and cyan on a dark wall
above a coral city" .
She used a deep sea-blue background with white text, centred the heading with a style attribute, and checked every closing tag twice. Then Octavia sent the files to the server at Snowpeak.
The next morning Pip landed on the jetty in a flurry of feathers. "Every village has seen it! The Riverbend frogs want to visit! Moonbrook is organising swimming lessons!" Behind her, Old Bramble was beaming. "My screen reader read me every heading," he said, "and then it read me a giant glowing rangoli flower in magenta, gold and cyan. I could almost see it."
But that afternoon, visitors started arriving in Pearlhaven, and with them came a new problem. Octavia had to record every visitor's name, home village and visiting day, and her records were scrolls. Lots of scrolls. Within a day, Beautine, who had come to help, was buried in them.
❓ Check Your Knowledge
- What does HTML stand for? Is it a programming language? Explain.
- Label the parts of this element:
<p>The tide is high.</p> - What is an attribute? Give an example.
- What is the difference between the
<head>and the<body>of a page? - Why should a page use UTF-8?
- Write the HTML for an ordered list of three steps for making tea.
- What is the difference between an absolute link and a relative link?
- Write an
<img>element for a file calledfish.png, 250 pixels wide, with good alt text. - Why is alt text important? What should a decorative image's alt text be?
- What do
<tr>,<th>and<td>stand for? - A textbook tells you to write
<font color="blue">. What would you write instead in modern HTML? - Find the three mistakes:
<h1>My Page<h1> <p>I like <strong>swimming</p></strong> <img src="me.jpg">
- Challenge: Write a complete HTML page for a school club of your choice with a title, a main heading, a paragraph, a list of activities, a table of meeting times, an image with alt text and a link to another page.
📚 Word Bank
- HTML: HyperText Markup Language, used to write web pages.
- Markup language: a language that labels the parts of a document; it does not give instructions like a programming language.
- Hyperlink: clickable text or an image that takes you to another page.
- Browser: a program that requests web pages and displays them, such as Microsoft Edge.
- Render: to display a web page from its HTML.
- Tag: an HTML label in angle brackets, such as
<p>. - Element: an opening tag, its content and its closing tag.
- Empty element: an element with no content and no closing tag, such as
<br>. - Attribute: extra information inside an opening tag, such as
hreforalt. - Nesting: placing elements inside other elements.
- Unordered list: a bulleted list made with
<ul>. - Ordered list: a numbered list made with
<ol>. - Absolute link: a link using a full web address.
- Relative link: a link to a file in relation to the current page, such as another file in the same folder.
- Alt text: a text description of an image for people who cannot see it.
- Accessibility: designing technology so that everyone, including people with disabilities, can use it.
- CSS: Cascading Style Sheets, the language that controls how web pages look.
- Obsolete: removed from use; old HTML tags such as
<font>are obsolete. - Website: a collection of linked web pages.
- Web server: a computer that stores websites and sends pages to browsers.
Keep learning with Byte by Byte
Explore Book 6: Python, Data and How Computers Work. Find the ebook, purchase details and teaching slides on MemuniCity.
Comments
Post a Comment