Chapter 010mAI Lab

HTML Introduction — AI Lab

Learn what HTML is, how HTML Elements work, and how to create your first HTML document with simple examples and practice exercises.

AI Lab15 min3 prompts

AI Lab — Learn AI-Assisted HTML

Learn how to use AI effectively to generate, explain, and debug HTML code. Master prompt engineering for web development.

AI Lab — Learn AI-Assisted HTML

Welcome to the AI Lab for HTML Introduction! In this lab, you'll learn how to use AI effectively to write, understand, and debug HTML code.

What You'll Learn

  • How to write effective prompts for AI to generate HTML
  • How to ask AI to explain HTML code you don't understand
  • How to use AI to debug HTML errors
  • How to verify AI-generated code for correctness

Why AI + HTML?

AI can help you learn HTML faster by generating examples, explaining concepts, and catching mistakes. But AI is a tool, not a replacement for understanding. This lab teaches you how to use AI as a learning accelerator while building your own skills.

Prompt Lessons

01

Generate a Basic HTML Page

easygenerate

Ask AI to generate a complete HTML5 document with a title, heading, and paragraph.

You will learn
Learn how to write a clear prompt that specifies structure, content, and HTML5 standards.
Prompt
Try with AI
Create a valid HTML5 document with the following requirements:

1. Page title: "My First Web Page"
2. A main heading (h1) that says "Welcome to HTML"
3. A paragraph (p) that briefly introduces what HTML is
4. Use proper HTML5 document structure with <!DOCTYPE html>, <html>, <head>, and <body>
5. Set the language attribute to "en"

Return the complete HTML document.

This prompt works well because it:

  1. Specifies the document type (HTML5) — so AI knows the standard
  2. Lists exact content requirements — title, heading, paragraph
  3. Requests proper structure — DOCTYPE, html, head, body
  4. Is specific — AI doesn't have to guess what you want

The numbered list makes each requirement clear and unambiguous. AI can verify each item is present in its output.

Expected Output

A complete, valid HTML5 document with proper structure.

Example Output

<!DOCTYPE html>
<html lang="en">
<head>
  <title>My First Web Page</title>
</head>
<body>
  <h1>Welcome to HTML</h1>
  <p>HTML (HyperText Markup Language) is the standard language for creating web pages.</p>
</body>
</html>

Why it works

The prompt is structured, specific, and lists requirements as a checklist.

Common Mistakes

  • Not specifying HTML5 — AI may use HTML4
  • Vague instructions like "make a page"
  • Missing the DOCTYPE requirement

Verification Checklist

  • Has <!DOCTYPE html>
  • Has <html>, <head>, <body> tags
  • Title is in <head>
  • Content is in <body>
  • Valid HTML5 syntax

Follow-up Prompts

  1. Add a navigation menu
  2. Include CSS styling
  3. Add an image
02

Explain HTML Elements with AI

easyexplain

Paste a piece of HTML code and ask AI to explain what each element does.

You will learn
Learn how to ask AI to explain code clearly with examples.
Prompt
Try with AI
Explain this HTML code to me. Break down each element and describe what it does:

```html
<div class="container">
  <header>
    <h1>My Blog</h1>
    <nav>
      <a href="/">Home</a>
      <a href="/about">About</a>
    </nav>
  </header>
  <main>
    <article>
      <h2>Post Title</h2>
      <p>Post content goes here.</p>
    </article>
  </main>
</div>
```

For each element, explain:
1. What the tag does
2. Why it's used in this context
3. Any important attributes

This prompt works because it asks AI to break down each element, explain its purpose, and list attributes.

Expected Output

A clear, element-by-element breakdown of the HTML code with explanations.

Example Output

AI would explain: <div> is a container, <header> is the page header, <nav> contains navigation links, <main> holds primary content, <article> represents a self-contained post.

Why it works

The prompt includes the actual code to explain and asks for a structured breakdown.

Common Mistakes

  • Asking "what is HTML?" without providing code
  • Not specifying what aspects to explain

Verification Checklist

  • AI explains each element
  • Explanations are clear
  • Attributes are mentioned
  • Context is explained

Follow-up Prompts

  1. How do I make this responsive?
  2. What CSS would style this?
03

Debug HTML Errors with AI

mediumdebug

Provide AI with broken HTML code and an error description, then ask it to find and fix the problem.

You will learn
Learn how to provide AI with enough context to debug HTML effectively.
Prompt
Try with AI
I have an HTML page that's not displaying correctly. The image is broken and the link doesn't work.

Here's my code:
```html
<!DOCTYPE html>
<html>
<head>
  <title>My Page</title>
</head>
<body>
  <h1>My Photo</h1>
  <img src="photo.jpg">
  <a href="www.google.com">Search</a>
</body>
</html>
```

Problems I'm seeing:
1. The image shows a broken icon
2. Clicking the link goes to a wrong URL

Find the errors and provide the corrected code.

This debug prompt works well because it provides: the actual code, a description of what's wrong, and specific symptoms. AI can match symptoms to common causes.

Expected Output

AI identifies: missing alt attribute on img, and missing https:// in the href. Provides corrected code.

Example Output

<img src="photo.jpg" alt="My Photo">
<a href="https://www.google.com">Search</a>

Why it works

Providing both the code AND the observed symptoms gives AI maximum context to diagnose the issue.

Common Mistakes

  • Saying "my code is broken" without showing the code
  • Not describing what "broken" means
  • Not providing error messages

Verification Checklist

  • AI identifies both errors
  • Corrected code is provided
  • Explanations for each fix
  • Code is valid HTML5

Follow-up Prompts

  1. How do I add more images?
  2. How do I create a navigation bar?