Skip to content
AI for Web Dev AI WorkflowCoding AssistantsPrompt Engineering

How to Use AI for Web Development: A Beginner’s Step-by-Step Guide

Learn how to use AI for web development by building a responsive FAQ with HTML, CSS, JavaScript and optional PHP. Includes prompts, code, tests and review tips.

Introduction

AI assistants can help web developers plan projects, write code, explain unfamiliar concepts, identify bugs, and review their work. This makes them useful learning partners—but not replacements for understanding how a website works.

In this tutorial, you will use an AI assistant to build a small web project one step at a time. You will create the page structure with HTML, style it with CSS, add live search with JavaScript, and then use PHP to generate the FAQ content on the server.

The important skill is not asking AI to “build everything.” It is learning how to give clear instructions, inspect the result, test it yourself, and improve it.

Important: The FAQ page we build is not an AI chatbot. AI helps us develop the website; visitors use a normal, predictable search feature. You do not need an AI API key or a paid AI service to run the finished project.

What You Will Learn

By the end of this tutorial, you will be able to:

  • Turn a simple website idea into a clear AI prompt.
  • Ask AI for HTML, CSS, JavaScript, and PHP in manageable steps.
  • Recognize the purpose of each language in the project.
  • Review AI-generated code instead of copying it blindly.
  • Test responsive layouts, keyboard interaction, and JavaScript behavior.
  • Use PHP safely to render text from a server-side array.
  • Ask AI for debugging help while independently verifying its suggestions.

What We Are Building

Our Web Development FAQ will include:

  1. A heading and short introduction.
  2. Five questions about common web technologies.
  3. Native expandable answers using the HTML <details> element.
  4. A search field that filters questions immediately as you type.
  5. A message when no questions match.
  6. Responsive styling for phones and desktop screens.
  7. An optional PHP version that generates the same questions from an array.

We’ll first build a fully working HTML + CSS + JavaScript version. After that, we’ll create an optional PHP-powered version that generates the same FAQ content on the server.

Before You Start

You need:

  • An AI assistant: ChatGPT or another general-purpose coding assistant.
  • A code editor: Visual Studio Code or a similar editor.
  • A modern web browser: Chrome, Firefox, Edge, or Safari.
  • PHP (optional for the final step): PHP 8 or newer installed locally, or a local development environment that runs PHP.

Create a new folder named ai-web-development-faq. Inside it, create these three empty files:

ai-web-development-faq/
├── index.html
├── styles.css
└── script.js

Keep the AI conversation open alongside your editor. We will write a focused prompt for each stage, then compare the result with a working reference implementation.


Step 1: Use AI to Plan the Project

Before writing code, explain what you want to build, which technologies to use, and what the finished result should do.

Your first AI prompt

I am a beginner learning web development.

Help me plan a small, responsive FAQ page about HTML, CSS,
JavaScript, PHP, and responsive design.

Requirements:
- Use semantic HTML.
- Use an external CSS file.
- Keep all JavaScript in a separate script.js file.
- Display five expandable questions and answers.
- Add a search input that filters questions as I type.
- Show a no-results message when nothing matches.
- Make it usable by keyboard and on mobile screens.
- Do not use libraries, frameworks, or an AI API.

First, explain the file structure and implementation steps.
Do not write the complete code yet.

Why this prompt works

It provides the AI with a role, a clear task, a technology stack, specific functionality, accessibility expectations, and an explicit limit: plan first, code later.

Review the AI’s response. Does it propose separate files? Does it use native HTML features where possible? Does it avoid unnecessary frameworks and dependencies?

Checkpoint: You should have a short plan describing HTML for structure, CSS for presentation, JavaScript for searching, and PHP as an optional later enhancement.


Step 2: Ask AI to Generate the HTML Structure

HTML describes the page’s content and meaning. It is the foundation for everything that follows.

Prompt for the HTML

Now write only the complete index.html file for our FAQ project.

Use semantic HTML5, a descriptive page title, a responsive
viewport meta tag, and a visible label for the search field.

Add five native <details> elements with <summary> questions.
Put them inside a container with id="faq-list".

Use these exact IDs for JavaScript:
- faq-search
- faq-list
- result-count
- no-results

Link styles.css and script.js as external files.
Use the defer attribute for script.js.
Do not add inline CSS or inline JavaScript event handlers.
Explain the important elements after the code.

Working reference: index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="A beginner-friendly FAQ about web development.">
    <title>Web Development FAQ | Web Dev Guru</title>
    <link rel="stylesheet" href="styles.css">
    <script src="script.js" defer></script>
</head>
<body>
    <main class="container">
        <header class="page-header">
            <p class="eyebrow">Web Dev Guru · Beginner Project</p>
            <h1>Web Development FAQ</h1>
            <p class="intro">
                Explore common questions about building websites.
            </p>
        </header>

        <section class="faq-panel" aria-labelledby="faq-heading">
            <h2 id="faq-heading">Questions and answers</h2>

            <label for="faq-search">Search questions</label>
            <input
                type="search"
                id="faq-search"
                placeholder="Try searching for CSS"
                autocomplete="off"
            >

            <p id="result-count" role="status">Showing 5 of 5 questions</p>

            <div id="faq-list" class="faq-list">
                <details class="faq-item">
                    <summary>What does HTML do?</summary>
                    <p>HTML gives a web page its structure and meaning.</p>
                </details>

                <details class="faq-item">
                    <summary>What is CSS used for?</summary>
                    <p>CSS controls layout, colors, spacing, and visual styling.</p>
                </details>

                <details class="faq-item">
                    <summary>What does JavaScript add to a website?</summary>
                    <p>JavaScript adds behavior such as interactive search and updates.</p>
                </details>

                <details class="faq-item">
                    <summary>What is PHP?</summary>
                    <p>PHP runs on the server and can generate HTML dynamically.</p>
                </details>

                <details class="faq-item">
                    <summary>What is responsive design?</summary>
                    <p>Responsive design adapts a layout to different screen sizes.</p>
                </details>
            </div>

            <p id="no-results" class="empty-state" hidden>
                No matching questions found. Try another keyword.
            </p>
        </section>
    </main>

    <footer class="site-footer">
        <p>Built as a learning project with AI assistance.</p>
    </footer>
</body>
</html>

Understand what AI generated

  • <main> identifies the primary content of the page.
  • <label for="faq-search"> gives the search field an accessible name.
  • <details> and <summary> create expandable answers without custom toggle JavaScript.
  • role="status" allows assistive technologies to announce updates to the result count.
  • The hidden attribute keeps the no-results message invisible until it is needed.
  • defer loads our JavaScript without blocking HTML parsing and runs it after the document is parsed.

Checkpoint: Open index.html in your browser. You should see the heading, the search input, and five expandable questions. The page will look plain until we add CSS, and search will not work until Step 4.


Step 3: Use AI to Write the CSS

Now give the AI your HTML (or tell it to use the file you just produced). Describe the visual result rather than simply asking for “nice CSS.”

Prompt for the CSS

Write a complete styles.css file for the FAQ HTML we created.

Design direction:
- Clean, modern, beginner-friendly layout.
- Light background and white FAQ cards.
- Readable system fonts and comfortable spacing.
- Maximum content width around 760px.
- Responsive layout down to 320px wide.
- Clear keyboard focus indicators.
- No CSS framework, animation, or external font dependency.

Preserve the native <details> interaction.
Ensure elements with the hidden attribute stay hidden.
Return only the CSS, then explain the key decisions.

Working reference: styles.css

:root {
    color-scheme: light;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #1d293d;
    background: #f4f7fb;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    line-height: 1.6;
}

.container {
    width: min(100% - 2rem, 760px);
    margin-inline: auto;
}

.page-header {
    padding-block: 3.5rem 2rem;
}

.eyebrow {
    margin: 0 0 0.75rem;
    color: #3859aa;
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

h1 {
    margin: 0;
    font-size: clamp(2rem, 5vw, 3rem);
    line-height: 1.15;
}

.intro {
    max-width: 52ch;
    color: #526077;
}

.faq-panel {
    padding-bottom: 2rem;
}

.faq-panel h2 {
    margin-bottom: 1rem;
    font-size: 1.375rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 650;
}

#faq-search {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 1px solid #9aa8bd;
    border-radius: 0.75rem;
    background: #fff;
    color: inherit;
    font: inherit;
}

#faq-search:focus-visible,
.faq-item summary:focus-visible {
    outline: 3px solid #315ec7;
    outline-offset: 3px;
}

#result-count {
    margin-block: 0.875rem 1.25rem;
    color: #526077;
    font-size: 0.9375rem;
}

.faq-list {
    display: grid;
    gap: 0.75rem;
}

.faq-item {
    border: 1px solid #d5dfec;
    border-radius: 0.875rem;
    background: #fff;
}

.faq-item summary {
    padding: 1rem 1.25rem;
    cursor: pointer;
    font-weight: 700;
}

.faq-item p {
    margin: 0;
    padding: 1rem 1.25rem;
    border-top: 1px solid #e5ebf3;
}

.empty-state {
    padding: 1rem;
    border: 1px dashed #9aa8bd;
    border-radius: 0.75rem;
    background: #fff;
}

[hidden] {
    display: none !important;
}

.site-footer {
    padding: 1.5rem 1rem 2rem;
    color: #526077;
    text-align: center;
    font-size: 0.875rem;
}

@media (max-width: 480px) {
    .page-header {
        padding-top: 2.5rem;
    }

    .faq-item summary,
    .faq-item p {
        padding: 0.875rem 1rem;
    }
}

Understand what AI generated

The .container rule keeps the content readable on large monitors while allowing it to shrink on smaller screens. The clamp() function scales the main heading without requiring several media queries.

The :focus-visible rules make keyboard focus easier to see, and [hidden] prevents the CSS layout rules from accidentally displaying elements that JavaScript has hidden.

Test the layout

Resize the browser or open DevTools and enable a mobile viewport. Check widths around 320px, 390px, 768px, and desktop. Make sure you can read the content without horizontal scrolling.

Checkpoint: The page should now have a centered layout, a clearly styled search field, and separate FAQ cards. The native expand/collapse behavior should still work.


Step 4: Use AI to Add JavaScript Search

JavaScript will make the search field interactive. We will filter the FAQ cards by looking for the typed phrase in each card’s question or answer.

Prompt for the JavaScript

Write script.js for our existing FAQ page.

Use vanilla JavaScript only, in this separate file.

Requirements:
- Read the search value as the user types.
- Search both question and answer text, case-insensitively.
- Show matching .faq-item elements and hide the others.
- Update #result-count with "Showing X of 5 questions".
- Reveal #no-results only when there are zero matches.
- Treat an empty search field as "show all questions".
- Do not use innerHTML, eval, libraries, or inline event handlers.
- Keep the code readable for a beginner.

Explain each part after the code.

Working reference: script.js

const searchInput = document.querySelector("#faq-search");
const faqItems = [...document.querySelectorAll(".faq-item")];
const resultCount = document.querySelector("#result-count");
const noResults = document.querySelector("#no-results");

function filterFaqs() {
    const searchTerm = searchInput.value.trim().toLowerCase();
    let matches = 0;

    faqItems.forEach((item) => {
        const text = item.textContent.toLowerCase();
        const isMatch = text.includes(searchTerm);

        item.hidden = !isMatch;

        if (isMatch) {
            matches += 1;
        }
    });

    resultCount.textContent = `Showing ${matches} of ${faqItems.length} questions`;
    noResults.hidden = matches !== 0;
}

searchInput.addEventListener("input", filterFaqs);
filterFaqs();

Understand what AI generated

  1. querySelector() finds the search input and output elements.
  2. querySelectorAll() finds all FAQ cards; [... ] turns that collection into an array.
  3. trim().toLowerCase() removes extra spaces and makes matching case-insensitive.
  4. textContent reads text safely without interpreting it as HTML.
  5. includes() checks whether a card contains the search term.
  6. The hidden property controls whether each card is displayed.
  7. addEventListener("input", ...) reruns the search whenever the input changes.
  8. The final filterFaqs() call sets the correct initial count.

Test the behavior

Try these checks in your browser:

ActionExpected result
Leave the search emptyAll 5 questions appear.
Type CSSThe CSS question appears.
Type serverThe PHP question appears because its answer mentions the server.
Type css in lowercaseThe same result appears as for CSS.
Type xyz123No cards appear; the no-results message is visible.
Clear the fieldAll questions reappear.
Press Tab and Enter on a questionThe answer opens or closes without a mouse.

Checkpoint: Your HTML, CSS, and JavaScript project is now functional. Do not move to PHP until these tests pass.


Step 5: Ask AI to Help Add PHP

PHP runs on the server, not in the browser. Instead of writing every FAQ item directly into the HTML, we can store the questions in a PHP array and generate the same markup with a loop.

This is a small but meaningful introduction to server-side development. It also shows why AI-generated PHP must be reviewed carefully: server-side code can process data and perform privileged actions.

Prompt for the PHP conversion

I have a working FAQ project with index.html, styles.css,
and script.js.

Help me convert index.html to index.php.

Requirements:
- Keep the same HTML structure, IDs, and classes.
- Store the five questions and answers in a PHP array.
- Render each FAQ item using foreach.
- Escape each question and answer with htmlspecialchars,
  including ENT_QUOTES and UTF-8 encoding.
- Keep CSS and JavaScript in their existing separate files.
- Do not add a database, user input handling, or an AI API.
- Give me a complete index.php file and local testing steps.
- Explain why output escaping matters.

Update the project folder

Rename index.html to index.php. Your folder should now look like this:

ai-web-development-faq/
├── index.php
├── styles.css
└── script.js

Leave styles.css and script.js unchanged. Replace the old HTML contents with the following PHP-powered version.

Working reference: index.php

<?php
$faqs = [
    [
        'question' => 'What does HTML do?',
        'answer' => 'HTML gives a web page its structure and meaning.',
    ],
    [
        'question' => 'What is CSS used for?',
        'answer' => 'CSS controls layout, colors, spacing, and visual styling.',
    ],
    [
        'question' => 'What does JavaScript add to a website?',
        'answer' => 'JavaScript adds behavior such as interactive search and updates.',
    ],
    [
        'question' => 'What is PHP?',
        'answer' => 'PHP runs on the server and can generate HTML dynamically.',
    ],
    [
        'question' => 'What is responsive design?',
        'answer' => 'Responsive design adapts a layout to different screen sizes.',
    ],
];
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="A beginner-friendly FAQ about web development.">
    <title>Web Development FAQ | Web Dev Guru</title>
    <link rel="stylesheet" href="styles.css">
    <script src="script.js" defer></script>
</head>
<body>
    <main class="container">
        <header class="page-header">
            <p class="eyebrow">Web Dev Guru · Beginner Project</p>
            <h1>Web Development FAQ</h1>
            <p class="intro">
                Explore common questions about building websites.
            </p>
        </header>

        <section class="faq-panel" aria-labelledby="faq-heading">
            <h2 id="faq-heading">Questions and answers</h2>

            <label for="faq-search">Search questions</label>
            <input
                type="search"
                id="faq-search"
                placeholder="Try searching for CSS"
                autocomplete="off"
            >

            <p id="result-count" role="status">
                Showing <?= count($faqs) ?> of <?= count($faqs) ?> questions
            </p>

            <div id="faq-list" class="faq-list">
                <?php foreach ($faqs as $faq): ?>
                    <details class="faq-item">
                        <summary><?= htmlspecialchars($faq['question'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') ?></summary>
                        <p><?= htmlspecialchars($faq['answer'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') ?></p>
                    </details>
                <?php endforeach; ?>
            </div>

            <p id="no-results" class="empty-state" hidden>
                No matching questions found. Try another keyword.
            </p>
        </section>
    </main>

    <footer class="site-footer">
        <p>Built as a learning project with AI assistance.</p>
    </footer>
</body>
</html>

Understand what AI generated

  • $faqs is an array of question-and-answer pairs.
  • foreach ($faqs as $faq) outputs one FAQ card per pair.
  • <?= ... ?> is PHP’s short echo syntax, used to output values inside HTML.
  • count($faqs) keeps the initial result count accurate if you add or remove items.
  • htmlspecialchars() converts characters such as <, >, and & into safe HTML text. This is essential when rendering values that could eventually come from users or other untrusted sources.

The current array is hard-coded, but escaping output is still a good habit. Never assume AI-generated code is secure because it looks simple.

Run PHP locally

Open a terminal inside the project folder and run:

php -v

If PHP is installed, you will see a version number. Then start PHP’s built-in development server:

php -S localhost:8000

Open this URL in your browser:

http://localhost:8000/index.php

The page should look and behave exactly as before. PHP generates the FAQ markup on the server; JavaScript still filters the rendered cards in the browser.

Important: Opening index.php with a file:// URL will not execute PHP. PHP’s built-in server is for local development and testing, not production hosting.

Checkpoint: Five questions appear at the local URL, expandable answers still work, and search produces the same results as in Step 4.


Step 6: Use AI to Debug Problems—Without Trusting Every Suggestion

AI is useful when you can provide the actual error message, the relevant code, and the behavior you expected.

For example, if search stops working after editing the markup, open your browser’s Developer Tools and check the Console tab. Copy the real error message instead of guessing at the cause.

A useful debugging prompt

Act as a careful JavaScript debugging assistant.

Expected behavior:
Typing a word should filter the FAQ cards immediately.

Actual behavior:
[Describe what happens here.]

Console error:
[Paste the exact error message here.]

Relevant HTML and JavaScript:
[Paste only the relevant code here.]

Please:
1. Explain the likely cause in beginner-friendly language.
2. Suggest the smallest reasonable fix.
3. Show only the code that needs to change.
4. Give me steps to verify the fix.
5. Do not rewrite unrelated files.

What if AI proposes the wrong solution?

Ask it to explain why the change is necessary. Compare the proposal with the browser’s behavior and the relevant language documentation. An AI assistant can invent API names, miss context, or suggest a large rewrite for a tiny issue.

A good debugging workflow is:

  1. Reproduce the problem.
  2. Read the browser console or PHP error output.
  3. Isolate the smallest relevant section of code.
  4. Ask AI for a minimal, explained change.
  5. Apply the change and rerun the tests.
  6. Revert it if the behavior gets worse.

Step 7: Ask AI for a Code Review

A project that “works on my computer” still needs review. Ask AI to look for accessibility, security, maintainability, and logic issues—but verify its recommendations yourself.

Code review prompt

Review my small FAQ project as a web development mentor.

I will provide index.php, styles.css, and script.js.

Check for:
- Correct HTML semantics and accessibility.
- Keyboard interaction and visible focus states.
- Responsive behavior on narrow screens.
- JavaScript bugs and missing edge cases.
- Safe PHP output handling.
- Unnecessary code or dependencies.

For each finding, explain:
1. The issue and its impact.
2. The exact file and code involved.
3. A minimal proposed fix.
4. How I can test that the fix works.

Do not claim that you ran tests or inspected the live page
unless you actually had access to do so.

Your independent verification checklist

  • [ ] All project files are in the correct folder.
  • [ ] The HTML page has one meaningful <h1>.
  • [ ] Each search input has a visible label.
  • [ ] FAQ items open using keyboard controls.
  • [ ] Search works with uppercase, lowercase, and empty input.
  • [ ] An unmatched search displays the no-results message.
  • [ ] No JavaScript errors appear in the browser console.
  • [ ] The design fits 320px, 390px, 768px, and desktop widths.
  • [ ] The PHP page runs through an HTTP server, not file://.
  • [ ] PHP output is escaped before appearing in HTML.

You can also run a quick PHP syntax check:

php -l index.php

This checks PHP syntax; it does not prove that the application is secure or bug-free. For additional HTML validation, use the Nu HTML Checker and review its findings.


Step 8: Learn to Write Better Prompts

You can reuse the same prompt structure for almost any web development task.

A reusable AI coding prompt template

Role:
You are a web development mentor and careful code reviewer.

Project:
[Describe what you are building.]

Technology:
[HTML, CSS, JavaScript, PHP, or another stack.]

Current state:
[Describe the files and functionality that already exist.]

Task:
[Describe one specific change you want.]

Requirements:
[List expected behavior, responsive and accessibility needs.]

Constraints:
[No inline JS, no extra dependencies, preserve existing code, etc.]

Output:
[Ask for the exact file or minimal changed code and an explanation.]

Verification:
[Ask for realistic tests and known limitations.]

Weak prompt versus stronger prompt

Weak:

Make me a good website with AI.

Stronger:

Create a responsive, accessible FAQ component using semantic HTML, external CSS, and vanilla JavaScript. Include five expandable questions, live text filtering, a no-results message, and keyboard-visible focus styles. Keep the JavaScript in script.js and explain how to test each feature.

Specific prompts reduce ambiguity. They do not guarantee correct code, which is why review and testing remain part of the process.


Common Problems and Solutions

The page has no styling

Check that styles.css exists beside index.html or index.php, and that the HTML contains:

<link rel="stylesheet" href="styles.css">

Refresh the browser and check DevTools → Network for a missing CSS file.

Search does not respond

Make sure the JavaScript filename and link match:

<script src="script.js" defer></script>

Also verify that the HTML IDs match the selectors in script.js exactly. Check the browser console for errors.

Every question disappears

Clear the search field. Search is designed to hide cards that do not include the entered phrase. If they remain hidden, inspect the hidden property and the filterFaqs() function.

PHP code appears as text or the browser downloads the file

You are probably opening PHP as a static file or serving it through a server that does not execute PHP. Use a PHP-enabled local server and visit http://localhost:8000/index.php.

The terminal says php is not recognized

Install PHP or use a local development environment that includes it. Verify the installation and its PATH configuration before retrying php -v.


Best Practices When Using AI for Web Development

Start with small tasks. Ask AI to plan first, then work through one file or feature at a time. Smaller changes are easier to understand and test.

Never paste secrets into prompts. Keep passwords, API keys, private customer data, and credentials out of AI conversations and example code.

Inspect every generated dependency. AI may suggest unnecessary packages or nonexistent functions. Check official documentation and package sources before installing or using them.

Test behavior, not just appearance. A polished screenshot cannot prove that keyboard navigation, JavaScript, PHP, or error handling works correctly.

Keep human control over important decisions. Security, privacy, accessibility, data handling, and deployments require independent review. For a real production project, add appropriate automated tests and a proper deployment process.

Use version control. Commit working milestones in Git so you can compare AI-suggested changes and roll back mistakes.

Conclusion

You have used an AI assistant the way a developer should: as a collaborator in a controlled development process.

Starting from a simple idea, you planned a project, built semantic HTML, added responsive CSS, implemented a JavaScript search, and optionally generated the same content with PHP. You also learned how to test the result, investigate errors, and ask for focused code reviews.

The most useful skill is not getting AI to produce more code. It is knowing what to ask, how to understand the answer, and how to verify that the final website actually works.

What to Build Next

Try extending this project yourself. Add a category filter for HTML, CSS, JavaScript, and PHP, or add a new FAQ item to the PHP array and confirm that the result counter updates correctly.

For the next lesson, explore How to Write Better AI Prompts for HTML, CSS and JavaScript and practice turning vague design requests into precise technical instructions.