Lesson 3: Your First AI-Built Page
| Course home | Previous: Lesson 2 | Next: Lesson 4 |
Time: about 45 minutes.
Goals
By the end of this lesson you will be able to:
- Use the plan first, then build habit on a real task.
- Get an AI agent to create a clean, semantic HTML page for Tiny Habits.
- Read basic HTML and explain what each main element is for.
- View the page in a browser through a local web server.
- Commit the result with a meaningful message.
Concepts
What HTML is
HTML describes the structure of a page: this is a heading, this is a form, this is a list. It does not decide colours or behaviour; CSS and JavaScript do that later.
An HTML element looks like this:
<label for="habit-name">New habit</label>
<label ...>is the opening tag,</label>the closing tag.for="habit-name"is an attribute: extra information about the element.New habitis the content.
Semantic HTML
“Semantic” means using the element that matches the meaning. Screen readers, search engines and browsers all use this meaning.
| Use this | For | Instead of |
|---|---|---|
<main> |
The main content of the page | <div id="main"> |
<header> |
Intro area with the title | <div class="top"> |
<h1>, <h2> |
Headings, in order | Big bold <div> |
<form> |
Anything the user submits | Loose inputs with click handlers |
<label> |
Text that names an input | Placeholder text only |
<button> |
Things you click to act | Clickable <div> or <span> |
<ul>, <li> |
Lists of things | Stacked <div>s |
<section> |
A themed part of the page with a heading | Anonymous <div> |
AI agents usually write decent semantic HTML if you ask for it, and sometimes produce “div soup” if you do not.
Why a plan first
Changing a plan costs nothing. Changing code costs a review, a test and possibly an undo. Asking for a plan first:
- Exposes misunderstandings (“I’ll use React” when you wanted plain JS).
- Shows you which files will change.
- Gives you vocabulary to learn before the code appears.
Walkthrough
Open a terminal in tiny-habits and start your agent.
Step 1: Ask for a plan
I'm building "Tiny Habits", a habit tracker web app, as a beginner learning
web development. Use only plain HTML, CSS and JavaScript: no frameworks, no
build tools, no packages.
Today I only want the HTML structure, no styling and no JavaScript yet.
The page needs:
- a title "Tiny Habits" and a one-line tagline
- a form with a labelled text input for a new habit name and an "Add" button
- a "Today" section with a message for when there are no habits yet, and an
empty list where habits will go later
- a place for error messages next to the input
Before writing any code, describe the plan: the file name, the main elements
you will use and why, and any accessibility considerations. Wait for my OK.
Step 2: Review the plan
Look for these in the reply:
- One file:
index.html. - Semantic elements:
<main>,<header>,<h1>,<form>,<label>,<input>,<button>,<section>,<ul>. lang="en"on<html>and a<meta name="viewport">tag for phones.- The label connected to the input with
forandid. - Error message area that screen readers will announce (for example
role="alert").
If something is missing, say so:
Looks good. Two changes: give the input and the list ids I can use later
from JavaScript, and make the error area announce messages to screen
readers. Then go ahead and create index.html.
Step 3: Let it build, then read every line
The agent creates index.html. Open it in VS Code. Your file should look similar to this (yours will differ in details, and that is fine):
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Tiny Habits</title>
</head>
<body>
<main>
<header>
<h1>Tiny Habits</h1>
<p>Check off one small thing a day.</p>
</header>
<form id="new-habit">
<label for="habit-name">New habit</label>
<input id="habit-name" type="text" maxlength="60" required />
<button type="submit">Add</button>
<p id="form-error" role="alert"></p>
</form>
<section aria-labelledby="today-heading">
<h2 id="today-heading">Today</h2>
<p id="empty-state">No habits yet. Add your first one above.</p>
<ul id="habit-list"></ul>
</section>
</main>
</body>
</html>
For anything you do not recognise, ask:
Explain each line of index.html to me as a beginner, grouped by section.
For each attribute (lang, charset, viewport, for, id, maxlength, required,
role, aria-labelledby), say what would go wrong without it.
Step 4: View it in the browser
In the terminal (a second terminal tab if your agent is running in the first):
python3 -m http.server 8000
Open http://localhost:8000. You should see a plain, unstyled page with the heading, the form and the empty message. It looks like 1995. That is correct: styling is Lesson 5.
Try it:
- Press Tab: focus should move to the input, then the button.
- Click the “New habit” label: the input should get focus. That proves the label is connected.
- Press Add with an empty input: the browser may show its own “fill in this field” message because of
required. In later lessons JavaScript takes over validation.
Stop the server with Ctrl+C when done.
Step 5: Commit
git add index.html
git commit -m "Add semantic HTML structure for Tiny Habits"
Step 6: Bonus, ask for a self-review
Review index.html against basic accessibility and HTML best practices for a
beginner project. List anything you would change, but do not change it.
Decide for yourself which suggestions are worth doing. You do not have to accept every suggestion an AI makes, including its own reviews.
What good output looks like
- A single
index.htmlwith no CSS or JS mixed in (not yet). - Proper
<!doctype html>,lang,charsetandviewport. - Every input has a visible
<label>linked byforandid. - Real
<button>and<form>elements, not clickable divs. - Headings in order: one
<h1>, then<h2>. - Useful
ids on the input, list, empty message and error area. - Nothing you did not ask for: no frameworks, no CDN scripts, no placeholder lorem ipsum everywhere.
Checklist
- I asked for and reviewed a plan before any code was written.
index.htmlexists and I can explain every element.- I viewed the page through
http://localhost:8000. - Keyboard Tab order and the label click both work.
- I committed with a clear message.
Mini-quiz
- Why use
<button>instead of a<div>with a click handler? - What does
<label for="habit-name">connect to? - What does the viewport meta tag do?
- Why ask for a plan before code?
- Your agent added a
<script src="https://cdn.example.com/framework.js">you did not ask for. What do you do?
Answers
1. A real button is focusable with the keyboard, activates with Enter and Space, is announced as a button by screen readers and submits forms. A div does none of that without extra work. 2. The element whose `id` is `habit-name`, the text input. Clicking the label focuses the input, and screen readers read the label when the input is focused. 3. It tells mobile browsers to use the device width instead of pretending to be a desktop screen, so the page is not zoomed out on phones. 4. A plan is cheap to change and exposes misunderstandings before any code exists. 5. Reject or revert it, and tell the agent the project uses no external scripts or frameworks. Unrequested third-party scripts add dependencies and security risk.Assignment
- Ask the agent to add a
<footer>with one line: “Your habits are stored only in this browser.” Review and commit. - Ask it to add a
<meta name="description">tag. Find out what it is used for by asking the agent, then check its answer on MDN’s HTML reference. - Compare your
index.htmlwithproject/index.html. Write down two differences and which version you prefer, and why.