In Lesson 1 you built the frame of a page. Now let's fill the <body> with real content: headings, text, lists, pictures, links, tables and input boxes.
flag
What you'll learn
How to write headings and paragraphs.
How to make lists, show images and create links.
How to build a simple table and a box people can type in.
waving_handLet's fill the page
Content tags tell the browser what each piece of your page is: a heading, a paragraph, a list, a picture, a link.
The browser then shows each piece in a fitting way. Headings are big and bold, list items get bullets, and links are blue and clickable.
newspaper
Think of a newspaper. It has the paper's name in huge letters at the top, section names, headlines, stories, photos, short lists, small tables like the weather, and a coupon you can fill in.
A web page is built from the same kinds of pieces, and HTML has a tag for each one.
<body>
<h1>Front Page Bytes</h1>
<h2>Tech News</h2>
<h3>New Phones Arrive This Week</h3>
<img>PhotoNothing to wrap, so no closing tag.
<p></p>
<a>Read the full story →</a>
<ul>
<li>• New phones</li>
<li>• Laptop deals</li>
<li>• Game reviews</li>
</ul>
<table>
City
Weather
Cebu
Sunny
Manila
Rainy
</table>
<input>you@example.comNothing to wrap, so no closing tag.
</body>
Now let's see the tags ↓
<body>
<h1>Front Page Bytes</h1>
<h2>Tech News</h2>
<h3>New Phones Arrive This Week</h3>
<img>PhotoNothing to wrap, so no closing tag.
<p></p>
<a>Read the full story →</a>
<ul>
<li>• New phones</li>
<li>• Laptop deals</li>
<li>• Game reviews</li>
</ul>
<table>
City
Weather
Cebu
Sunny
Manila
Rainy
</table>
<input>you@example.comNothing to wrap, so no closing tag.
</body>
Each green pair wraps around what it holds: the opening tag comes before the content and the closing tag comes right after it.
Pairs can sit inside other pairs. Each <li> item is inside the <ul> list, and everything is inside <body>.
The yellow tags, <img> and <input>, have nothing to wrap, so they have no closing tag.
searchA closer look
Six sizes of headings
HTML has six heading levels, from <h1> to <h6>. <h1> is the most important and the biggest, so use it once per page for the main title.
Use <h2> for sections and <h3> for parts inside a section, like chapters and sub-chapters in a book.
Choose a heading by how important it is, not by how big it looks. You'll learn to change sizes with CSS later.
Tags with no closing tag
Most tags wrap around content, so they need a closing tag. A few tags have nothing to wrap, so they have no closing tag.
These are called empty tags. You may also see them called self-closing or void tags. All three names mean the same thing.
An empty tag keeps all its information inside the opening tag, like src (which picture to show) and alt (a short description) on <img>. These extra details are called attributes, and Lesson 4 covers them.
These are the empty tags you'll meet most often:
<img> shows a picture.
<input> makes a box people can type in.
<br> starts a new line inside the same block of text, like the lines of an address.
<hr> draws a line across the page to split two parts, like two news stories.
<meta> and <link> sit inside <head>. <meta> gives extra information about the page, and <link> connects a file to the page, like a CSS file. You'll use <link> again in the CSS lessons and exercises.
On other websites you may see a slash at the end, like <br /> or <img src="logo.png" alt="Logo" />. In HTML, both ways work the same. These lessons write empty tags without the slash.
The one thing to leave out is a closing tag, like </img> or </br>. The browser skips the first one and reads the second one as another <br>. Common mistakes, further down, shows what happens.
New line or same line
Some elements always start on a new line and take up the full width, like headings, paragraphs, lists and tables.
Others sit inside a line of text, like links. That's why a link can appear in the middle of a sentence.
A page inside your page: <iframe>
<iframe> shows another web page inside your page, like a small window. Its src says which page to show.
Many websites don't allow being shown this way, and the mini browsers in these lessons block it for safety, so this one has no live example.
constructionLet's build it
Let's write a news story for Front Page Bytes. Each step shows the whole page, with the frame from Lesson 1 around it. The new content goes inside <body>, and new lines are highlighted.
Steps 1 to 5 build one story. Steps 6 and 7 are two small extras.
<h1> is the name of the site, <h2> is the section, and <h3> is the story's headline. Each level is a little smaller than the one before.
2Step 2: Add a paragraph
Your code
<!DOCTYPE html><html lang="en"> <head> <title>Front Page Bytes</title> </head> <body> <h1>Front Page Bytes</h1> <h2>Tech News</h2> <h3>New Phones Arrive This Week</h3> <p>Three new phones go on sale on Friday. Each one has a bigger battery and a sharper camera.</p> </body></html>
What you see
description(no title)
<p> holds a block of text. The browser adds a little space above and below each paragraph, so they don't run together.
3Step 3: Add a list
Your code
<!DOCTYPE html><html lang="en"> <head> <title>Front Page Bytes</title> </head> <body> <h1>Front Page Bytes</h1> <h2>Tech News</h2> <h3>New Phones Arrive This Week</h3> <p>Three new phones go on sale on Friday. Each one has a bigger battery and a sharper camera.</p> <ul> <li>Bigger batteries</li> <li>Sharper cameras</li> <li>Faster charging</li> </ul> </body></html>
What you see
description(no title)
<ul> starts a bulleted list, and each item goes inside its own <li>.
Change <ul> to <ol> (and </ul> to </ol>) and the bullets become numbers: 1, 2, 3.
4Step 4: Add an image
Your code
<!DOCTYPE html><html lang="en"> <head> <title>Front Page Bytes</title> </head> <body> <h1>Front Page Bytes</h1> <h2>Tech News</h2> <h3>New Phones Arrive This Week</h3> <img src="/storage/assets/WebcoreIcon.png" alt="WebCore logo" width="120"> <p>Three new phones go on sale on Friday. Each one has a bigger battery and a sharper camera.</p> <ul> <li>Bigger batteries</li> <li>Sharper cameras</li> <li>Faster charging</li> </ul> </body></html>
What you see
description(no title)
<img> shows a picture. src says where the picture file is, alt describes it in words, and width sets its width in pixels.
There's no closing tag, because the image doesn't wrap around any text.
5Step 5: Add a link
Your code
<!DOCTYPE html><html lang="en"> <head> <title>Front Page Bytes</title> </head> <body> <h1>Front Page Bytes</h1> <h2>Tech News</h2> <h3>New Phones Arrive This Week</h3> <img src="/storage/assets/WebcoreIcon.png" alt="WebCore logo" width="120"> <p>Three new phones go on sale on Friday. Each one has a bigger battery and a sharper camera.</p> <ul> <li>Bigger batteries</li> <li>Sharper cameras</li> <li>Faster charging</li> </ul> <a href="/news/phones">Read the full story</a> </body></html>
What you see
description(no title)
<a> makes a link. href is where it goes, and the text between the tags is what people click.
Links in these mini browsers don't open, so you stay on the lesson.
A table is built row by row. <table> wraps everything, each <tr> is one row, <th> is a header cell (shown in bold), and <td> is a normal cell.
Tables have no lines around the cells yet. You'll add those with CSS.
7Step 7: Extra: a box to type in
Your code
<!DOCTYPE html><html lang="en"> <head> <title>Front Page Bytes</title> </head> <body> <h2>Get the Newsletter</h2> <p>Type your email address:</p> <input type="email" placeholder="you@example.com"> </body></html>
What you see
description(no title)
<input> makes a box visitors can type in. Try typing in the mini browser!
type="email" says what kind of input it is, and placeholder is the grey hint text that disappears when you type. Like <img>, it has no closing tag.
There's no picture file called banner.jpg here, so the browser shows a broken-image icon and the alt text instead. Screen readers also read the alt text aloud.
tips_and_updatesTip: Check the file name and folder in src. Keep a clear alt text, because it shows whenever the picture can't load.
The address was meant to be on two lines, but there's an extra blank line between them. The browser reads </br> as a second <br>, so it starts two new lines instead of one.
tips_and_updatesTip: Write <br> on its own. Empty tags like <br>, <img> and <input> have nothing inside, so they have no closing tag.
quizTest your knowledge
Edit the code on the left. The mini browser updates as you type, and each goal gets a check mark when it's done.
auto_awesomeNo clicking needed. Each goal gets a check mark by itself once your code does it.