HTML basics: tags and elements
Make the title
Make Pizza night the big title. On line 1, change both p to h1, then press Run.
The words in angle brackets are tags. They tell the browser what each piece is.
Learn
Opening and closing tags
Every web page you have ever scrolled past is, underneath, a text file written in HTML. HTML does not make things pretty and it does not make things move. Its one job is to say what each piece of content is: this is a heading, this is a paragraph, this is a list.
Look at your first line. Most tags come in pairs, an opening tag and a closing tag with a slash: <h1> opens the heading and </h1> closes it.
The opening tag, the content and the closing tag together make an element.
Learn
Headings, paragraphs and lists
Some useful elements:
<h1>to<h6>: headings, from biggest to smallest<p>: a paragraph<ul>with<li>inside: a bulleted list, one<li>per item<strong>: words that matter
Browsers show <strong> in bold, and screen readers can say it with stress. <b> also makes text bold, but it says nothing about meaning, so use <strong> when the words are important.
Elements can live inside other elements. That is called nesting, and it is how a page gets its structure: each <li> here sits inside the <ul>.
<h1>Pizza night</h1> <p>Bring <strong>one</strong> topping each.</p> <ul> <li>Cheese</li> <li>Mushrooms</li> <li>Peppers</li> </ul> <h2>When</h2> <p>Saturday at 7.</p>
Learn
Closing tags in order
The rule: close things in the reverse order you opened them, like stacking boxes. <p><strong>Hi</strong></p> is fine. <p><strong>Hi</p></strong> is a mess, and browsers will quietly guess what you meant (often wrongly).
Indenting nested elements is optional for the browser but very much not optional for your sanity. Future you, debugging at 1am, will thank you.
Try it in the editor: change the text, break a closing tag on purpose and see what happens. That is how this sticks.
Look it upWeb cheatsheet
Practice
Add a heading and a paragraph
Add an <h1> heading with the exact text My Playlist, and below it a <p> paragraph with any text you like.
<!-- Write your h1 and p below --> Songs I can't stop playing
Practice
Make a list of three songs
The list below has only one song. Make it a <ul> with exactly three <li> items (any song names you like).
<h2>Top songs</h2> <ul> <li>Song one</li> </ul>
Break/fixFix the bug
The paragraph comes out huge
The recipe's first line should be the only big heading, with a normal paragraph under it. Instead the paragraph comes out huge and bold. Find out why and fix it.
<h1>Pancakes<h1> <p>Serves 4. Takes 20 minutes.</p> <ul> <li>2 eggs</li> <li>100 g flour</li> </ul>
Your turn
Write a game night page
Write a page for a game night from nothing. It needs:
- one
h1that saysGame night - a paragraph that has the word
Fridayinside astrong - an
h2that saysGames, followed by a list of three games - an
h2that saysSnacks, followed by a list of two snacks
On your own. Hints open after your first check.
Passed
You can now
<p>Pizza night</p> <ul> <li>Saturday at 7</li> <li>Bring a friend</li> </ul>