Your First HTML Page
Write a complete HTML page by hand, learn what tags, elements and attributes are, and open your file in a browser to see the result.
Welcome back!
Step 1 of 12Learn
Tags, elements and attributes
HTML works by wrapping content in tags. A tag is a word in angle brackets. Most come in pairs: an opening tag like <p> and a closing tag like </p>, which has a slash. Together with the content between them they form an element:
<p>I build websites now.</p>The browser doesn't show the tags themselves. It reads them as instructions: "this text is a paragraph." Change p to h1 and the same text becomes a big main heading.
Some elements need extra information. That goes inside the opening tag as an attribute, written name="value":
<a href="https://example.com">Visit my favorite site</a>Here a (anchor) makes a link, and the href attribute says where it goes. The text between the tags is what people click.
A few elements have no content and no closing tag, like <img> for images or <br> for a line break. These are called void elements.
Elements can also go inside other elements. That's called nesting, and the rule is simple: close them in the reverse order you opened them, like stacking and unstacking boxes.
Step 2 of 12Practice · Diagram
Anatomy of an element
Tap the attribute.
Tap the shape that answers the question, then press Check.
- <p class="intro">Hello</p>
- Opening tag: <p ...>
Starts the element.
- Attribute: class="intro"
Extra information, written inside the opening tag as name="value".
- Content: Hello
What appears on the page.
- Closing tag: </p>
Same name with a slash.
Step 3 of 12Practice · Spot the mistake
This snippet has nesting and closing mistakes. Tap the lines that are wrong.
Step 4 of 12Learn
The skeleton every page needs
A full HTML document has a standard skeleton. Type this into a new file and save it as index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My First Website</title>
</head>
<body>
<h1>Hello, world!</h1>
<p>This is my very first web page.</p>
</body>
</html>Line by line:
<!DOCTYPE html>tells the browser this is modern HTML.<html lang="en">wraps everything. Thelangattribute helps screen readers pronounce words correctly and helps search engines.<head>holds information about the page that isn't shown in the main window.<meta charset="utf-8">makes accents and symbols display correctly, and<title>sets the text on the browser tab and in search results.<body>holds everything visitors actually see.
The indentation is not required, but it makes nesting easy to see. Professional developers indent consistently, usually with two spaces, because a tidy file is far easier to fix.
Step 5 of 12Practice · Sort into groups
Does each item belong in the head or the body?
Tap an item, then tap its group (or drag it there).
Step 6 of 12Diagram
The skeleton as a tree
Tap a shape with to see more.
- <html lang="en">
- <head>
Information about the page; not shown in the page itself.
- <body>
Everything visible on the page.
- <meta charset>
- <title>
The text on the browser tab.
- <h1>
- <p>
Step 7 of 12Tap to reveal
Your setup in four steps
1. Pick an editor
A code editor like Visual Studio Code (free) colors your code, auto-closes tags and catches typos. Plain Notepad works too. Avoid word processors such as Word or Google Docs, because they add hidden formatting and curly quotes that break HTML.
2. Make a project folder
Create a folder named something like
my-website. Everything for your site goes in here. Use lowercase names without spaces, such asmy-website, because spaces in file names cause broken links online.3. Save as index.html
The home page of a site is almost always called
index.html. Servers send it automatically when someone visits the folder. Make sure the file really ends in.htmland not.html.txt; turn on file extensions in your file explorer to check.4. Open it in a browser
Double-click the file, or drag it onto a browser window. After every change, save the file and press refresh in the browser to see the update.
Step 8 of 12Practice · Fill in the blanks
Fill in the blanks
The text shown on a browser tab comes from the element inside the head. The home page file of a website is usually named .
Step 9 of 12Note
Step 10 of 12Diagram
The edit loop you will repeat all day
Tap a shape with to see more.
- Edit the file
- Save
Skip this and nothing changes.
- Refresh the browser
- Check the result
Wrong? Fix one thing and go around again.
Step 11 of 12Practice · Code challenge
Web pages are often built by code. Write a function wrap(tag, text) that returns an HTML element as a string. For example, wrap("h1", "Hello") should return "<h1>Hello</h1>".
wrap("h1", "Hello")wrap("p", "I like pizza")wrap("strong", "wow")
Step 12 of 12Practice · Choose one
Jordan saves a file as index.html, opens it, and the browser shows the raw code with all the tags visible. What is the most likely problem?
Lesson complete!