Skip to the content.

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:

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>

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:

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:

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:

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

Checklist

Mini-quiz

  1. Why use <button> instead of a <div> with a click handler?
  2. What does <label for="habit-name"> connect to?
  3. What does the viewport meta tag do?
  4. Why ask for a plan before code?
  5. 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

  1. Ask the agent to add a <footer> with one line: “Your habits are stored only in this browser.” Review and commit.
  2. 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.
  3. Compare your index.html with project/index.html. Write down two differences and which version you prefer, and why.

Next: Lesson 4: Prompting like a pro