How to Write Better AI Prompts for HTML, CSS and JavaScript
Learn to write clearer AI prompts for HTML, CSS and JavaScript. Build and test a responsive pricing demo while improving your AI-assisted web development workflow.

Introduction
An AI coding assistant can generate an entire page from a short request, but the first result is not always the result you actually need. The markup may be difficult to maintain, the CSS may break on mobile, or the JavaScript may work only in the simplest case.
Often, the problem begins before the code is written: the prompt does not describe the task clearly enough.
In this tutorial, you will learn how to write more useful AI prompts for HTML, CSS, and JavaScript. Instead of asking an assistant to “make a modern website,” you will define the project, specify constraints, break the work into manageable tasks, ask for targeted changes, and verify the finished code.
We will practice these skills by creating a responsive pricing section with three plans and a working switch between monthly and annual billing. The project uses plain HTML, CSS, and JavaScript—no framework, API key, build tool, or paid AI service is required.
Important: AI helps you write and review this code. The completed pricing section does not use AI in the browser and does not process real payments. Treat all prices as demonstration content.
What You Will Learn
By the end of the tutorial, you will know how to:
- Replace vague coding requests with prompts that have a clear goal and measurable requirements.
- Give an AI assistant the right project context without overwhelming it.
- Request semantic, accessible HTML instead of unnecessary markup.
- Specify responsive CSS requirements, including breakpoints and interaction states.
- Describe JavaScript behavior precisely, including edge cases.
- Ask for one file or one change at a time when that makes the output easier to review.
- Use follow-up prompts to fix a problem without rewriting working code.
- Check AI-generated code yourself instead of trusting a confident explanation.
- Reuse a reliable prompting template in future web projects.
What We Are Building
Our demo pricing section will contain:
- A heading and an introductory paragraph.
- Three plans: Starter, Pro, and Studio.
- Accessible radio buttons for Monthly and Annually billing.
- A 20% discount when annual billing is selected.
- Visible per-month prices and an accurate annual billing total.
- A responsive card layout that works on narrow and wide screens.
- A small status message that announces the selected billing mode.
Here are the fixed sample prices that we will use throughout the tutorial:
| Plan | Monthly billing | Annual billing (per month) | Total billed annually |
|---|---|---|---|
| Starter | $15/month | $12/month | $144/year |
| Pro | $30/month | $24/month | $288/year |
| Studio | $60/month | $48/month | $576/year |
Annual prices represent a 20% discount compared with paying the monthly rate for twelve months. Keeping the figures fixed makes the requirements and tests easy to understand.
The most important part of this project is not the visual result. It is the process of getting from an imprecise request to working, testable code.
Before You Start
You need:
- An AI assistant: ChatGPT or another coding assistant.
- A code editor: VS Code or a similar editor.
- A modern browser: Chrome, Firefox, Edge, or Safari.
- A project folder:
ai-prompt-pricing-demo.
Inside the folder, create these three empty files:
ai-prompt-pricing-demo/
├── index.html
├── styles.css
└── script.js
Open the folder in your editor. Keep the AI conversation available so you can copy prompts and compare generated code with the working reference files below.
We will use an AI-assisted, developer-verified workflow:
Describe → Generate → Inspect → Test → Refine → Test again
Step 1: Understand Why Vague Prompts Produce Weak Results
Consider this request:
A weak AI prompt
Make a cool pricing section with HTML, CSS and JavaScript.
The assistant has to guess almost everything: how many plans to display, which prices to use, what “cool” means, whether the section must be responsive, how visitors interact with it, and how the files should be organized.
You may get something attractive, but you cannot reliably tell whether the assistant met your expectations—because you did not define them.
A stronger AI prompt
I am a beginner building a small pricing-section demo.
Goal:
Create a responsive pricing section with three plans:
Starter, Pro, and Studio.
Technology:
Use plain HTML5, CSS3, and vanilla JavaScript.
Use separate index.html, styles.css, and script.js files.
Do not use frameworks, libraries, or inline event handlers.
Content and pricing:
- Starter: $15 monthly or $12/month with annual billing.
- Pro: $30 monthly or $24/month with annual billing.
- Studio: $60 monthly or $48/month with annual billing.
- Show the annual totals: $144, $288, and $576.
- Explain that annual billing saves 20%.
Accessibility and behavior:
- Use semantic HTML.
- Use a labeled monthly/annual radio group.
- Make the controls usable by keyboard.
- Update visible prices and billing notes when selection changes.
- Default to monthly billing.
Design:
- Use clean, modern cards and readable contrast.
- Show three columns on wide screens and stack on phones.
- Avoid horizontal scrolling at 320px viewport width.
Workflow:
First give me a short implementation plan and explain
any assumptions. Do not generate code yet.
Why this version is better
The second prompt defines the goal, context, technologies, constraints, content, interaction, quality requirements, and output format. It also prevents the assistant from immediately generating a large block of code before you review the plan.
The key principle is simple: replace adjectives with observable requirements. “Responsive” is useful, but “no horizontal scrolling at 320px” is something you can test.
Checkpoint: The assistant should return a brief plan that mentions semantic HTML, responsive CSS, radio controls, JavaScript price updates, and a testing step. If it proposes React, Tailwind, payment integrations, or extra features, remind it that these are out of scope.
Step 2: Give the AI a Small, Stable Project Brief
Before requesting individual files, write a shared brief. You can paste it at the beginning of a conversation and refer back to it for each step.
Reusable project-context prompt
We are building a beginner-friendly pricing demo.
Project files:
- index.html: semantic page structure
- styles.css: all presentation and responsive rules
- script.js: all interactivity
Requirements:
- Three plans: Starter, Pro, Studio.
- Monthly prices: 15, 30, 60 USD.
- Annual per-month prices: 12, 24, 48 USD.
- Annual totals: 144, 288, 576 USD.
- Monthly billing selected by default.
- Annual billing saves exactly 20%.
- Native radio inputs for billing selection.
- No framework, third-party library, checkout, or API.
- No inline CSS or inline JavaScript.
- Preserve keyboard access and visible focus styling.
When I request changes, modify only what the request needs.
Explain what changed and how I can test it.
Do not claim code has been tested unless it actually has.
What context should you include?
Useful context consists of details that affect the generated solution: file names, existing HTML IDs or classes, browser requirements, design constraints, data, expected behavior, and known bugs.
Avoid sharing unrelated project information, passwords, API keys, private client data, or production credentials. If you are working in a real repository, paste only the relevant files or use a coding assistant that has been given appropriately limited access.
Checkpoint: Your assistant now has a shared definition of the project. Each following prompt can focus on one task rather than repeatedly describing the whole application.
Step 3: Write a Better Prompt for Semantic HTML
HTML prompts should describe structure and meaning, not just appearance. Ask for native elements when they already provide the behavior you need.
Prompt: Generate index.html only
Using our approved pricing-demo brief, write only index.html.
Requirements:
1. Include <!DOCTYPE html>, lang="en", UTF-8, viewport,
a descriptive title, and a meta description.
2. Use a main landmark, a heading, and three article cards.
3. Use a fieldset and legend with two labeled radio inputs.
Give both inputs name="billing" and values "monthly"
and "annual". Monthly must be checked initially.
4. Each card must include a plan name, visible price,
billing note, and a short feature list.
5. For each price element, add data-monthly and data-annual
with the per-month price as an integer.
6. Include a status paragraph with id="billing-status".
7. Link styles.css and a deferred script.js.
8. Do not use inline styles, inline JavaScript, fake buttons,
checkout links, or external dependencies.
After the file, briefly explain why fieldset, legend,
article, and label are appropriate.
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 responsive pricing demo created with HTML, CSS, and JavaScript.">
<title>AI Prompting Practice | Pricing Demo</title>
<link rel="stylesheet" href="styles.css">
<script src="script.js" defer></script>
</head>
<body>
<main class="page-container">
<header class="page-header">
<p class="eyebrow">Web Dev Guru · Prompting Practice</p>
<h1>Simple, transparent pricing</h1>
<p class="intro">
Choose a plan and compare monthly and annual billing.
All prices are examples for this learning project.
</p>
</header>
<section class="pricing" aria-labelledby="pricing-heading">
<div class="pricing-header">
<div>
<h2 id="pricing-heading">Find your plan</h2>
<p>Annual billing saves 20% compared with twelve monthly payments.</p>
</div>
<fieldset class="billing-switch">
<legend>Billing frequency</legend>
<div class="billing-options">
<label>
<input type="radio" name="billing" value="monthly" checked>
<span>Monthly</span>
</label>
<label>
<input type="radio" name="billing" value="annual">
<span>Annually</span>
</label>
</div>
</fieldset>
</div>
<p id="billing-status" class="billing-status" role="status">
Showing monthly billing.
</p>
<div class="plan-grid">
<article class="plan-card">
<h3>Starter</h3>
<p class="plan-description">For small personal projects.</p>
<p class="plan-price-row">
<span class="currency">$</span>
<span class="plan-price" data-monthly="15" data-annual="12">15</span>
<span class="per-month">/month</span>
</p>
<p class="billing-note">Billed monthly</p>
<ul>
<li>One personal project</li>
<li>Basic components</li>
<li>Community support</li>
</ul>
</article>
<article class="plan-card featured-plan">
<p class="plan-badge">Popular example</p>
<h3>Pro</h3>
<p class="plan-description">For growing websites.</p>
<p class="plan-price-row">
<span class="currency">$</span>
<span class="plan-price" data-monthly="30" data-annual="24">30</span>
<span class="per-month">/month</span>
</p>
<p class="billing-note">Billed monthly</p>
<ul>
<li>Five projects</li>
<li>Reusable components</li>
<li>Priority examples</li>
</ul>
</article>
<article class="plan-card">
<h3>Studio</h3>
<p class="plan-description">For larger demo projects.</p>
<p class="plan-price-row">
<span class="currency">$</span>
<span class="plan-price" data-monthly="60" data-annual="48">60</span>
<span class="per-month">/month</span>
</p>
<p class="billing-note">Billed monthly</p>
<ul>
<li>Unlimited demo projects</li>
<li>Advanced components</li>
<li>Team-ready examples</li>
</ul>
</article>
</div>
</section>
</main>
<footer class="page-footer">
<p>Educational demonstration — no checkout or subscriptions.</p>
</footer>
</body>
</html>
Why the HTML prompt works
<main>identifies the primary content of the page.<section>and its heading group the pricing content.- Each
<article>represents a self-contained plan card. <fieldset>and<legend>give the billing controls a meaningful group label.- Native radio inputs provide keyboard and selection behavior without custom control JavaScript.
data-monthlyanddata-annualprovide a small, explicit bridge between HTML and JavaScript.role="status"lets assistive technologies announce the billing mode when it changes.
The plan cards deliberately do not include fake “Buy now” buttons. This is an educational comparison widget, not a working purchase flow.
Checkpoint: Open index.html in a browser. Confirm that the three plans appear, both billing options can be selected, and the HTML is readable without CSS. The numbers will not change yet because JavaScript has not been added.
Step 4: Write a Better Prompt for Responsive CSS
A generic request such as “make it look professional” gives the AI too much room to guess. Instead, specify the visual system and the layouts you need.
Prompt: Generate styles.css only
Write only styles.css for the existing index.html.
Do not change the HTML or write JavaScript.
Design direction:
- Light background, dark readable text, indigo accent.
- Comfortable spacing and rounded plan cards.
- System font stack; no external fonts.
- Pro card may have a subtle emphasized border.
Responsive behavior:
- Mobile first.
- Single-column cards on narrow screens.
- Three columns when the container is at least 900px wide.
- Billing controls must wrap and remain usable on phones.
- No horizontal scrolling at a 320px viewport width.
Accessibility:
- Preserve visible native radio controls.
- Provide obvious focus-visible styling.
- Do not rely on color alone to indicate the selected option.
- Respect prefers-reduced-motion.
Use CSS custom properties for the color palette.
Keep selectors focused on the classes in index.html.
Working reference: styles.css
:root {
color-scheme: light;
--page-bg: #f4f6fc;
--card-bg: #ffffff;
--text: #172036;
--muted: #4b5870;
--border: #d6ddeb;
--accent: #4338ca;
--accent-soft: #eef2ff;
--shadow: 0 12px 34px rgba(23, 32, 54, 0.08);
}
* {
box-sizing: border-box;
}
body {
margin: 0;
min-width: 0;
background: var(--page-bg);
color: var(--text);
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
line-height: 1.6;
}
.page-container {
width: min(100% - 2rem, 1120px);
margin-inline: auto;
padding-block: 3.5rem 4rem;
}
.page-header {
max-width: 700px;
margin-bottom: 2.5rem;
}
.eyebrow {
margin: 0 0 0.5rem;
color: var(--accent);
font-weight: 700;
letter-spacing: 0.03em;
}
h1,
h2,
h3,
p {
margin-top: 0;
}
h1 {
margin-bottom: 0.75rem;
font-size: clamp(2rem, 5vw, 3.25rem);
line-height: 1.15;
}
h2 {
margin-bottom: 0.5rem;
font-size: 1.5rem;
}
h3 {
margin-bottom: 0.35rem;
font-size: 1.35rem;
}
.intro,
.pricing-header p,
.plan-description,
.billing-note,
.page-footer {
color: var(--muted);
}
.pricing-header {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: end;
gap: 1.5rem;
margin-bottom: 1rem;
}
.billing-switch {
min-width: 0;
margin: 0;
padding: 0;
border: 0;
}
.billing-switch legend {
margin-bottom: 0.4rem;
font-weight: 700;
}
.billing-options {
display: flex;
flex-wrap: wrap;
gap: 0.75rem;
}
.billing-options label {
display: inline-flex;
align-items: center;
gap: 0.4rem;
cursor: pointer;
font-weight: 600;
}
.billing-options input {
width: 1.1rem;
height: 1.1rem;
margin: 0;
accent-color: var(--accent);
}
.billing-options input:focus-visible {
outline: 3px solid var(--accent);
outline-offset: 3px;
}
.billing-status {
min-height: 1.6em;
margin-bottom: 1.25rem;
color: var(--muted);
}
.plan-grid {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 1rem;
}
.plan-card {
min-width: 0;
padding: 1.75rem;
background: var(--card-bg);
border: 2px solid var(--border);
border-radius: 1.25rem;
box-shadow: var(--shadow);
}
.featured-plan {
border-color: var(--accent);
}
.plan-badge {
display: inline-block;
margin-bottom: 0.75rem;
padding: 0.15rem 0.65rem;
border-radius: 999px;
background: var(--accent-soft);
color: #312e81;
font-size: 0.875rem;
font-weight: 700;
}
.plan-description {
min-height: 1.6em;
margin-bottom: 1.5rem;
}
.plan-price-row {
display: flex;
align-items: baseline;
gap: 0.15rem;
margin-bottom: 0.15rem;
white-space: nowrap;
}
.currency {
font-size: 1.35rem;
font-weight: 700;
}
.plan-price {
font-size: clamp(2.25rem, 5vw, 3rem);
font-weight: 800;
line-height: 1.1;
font-variant-numeric: tabular-nums;
}
.per-month {
margin-left: 0.25rem;
color: var(--muted);
}
.billing-note {
min-height: 1.6em;
margin-bottom: 1.5rem;
font-size: 0.875rem;
}
.plan-card ul {
margin: 0;
padding-left: 1.25rem;
}
.plan-card li + li {
margin-top: 0.65rem;
}
.page-footer {
padding: 0 1rem 2rem;
text-align: center;
font-size: 0.875rem;
}
@media (min-width: 900px) {
.plan-grid {
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 1.5rem;
}
}
@media (prefers-reduced-motion: no-preference) {
.plan-card {
transition: box-shadow 160ms ease;
}
}
Why the CSS prompt works
Instead of asking for an unspecified “nice design,” we gave the assistant concrete choices: palette, layout behavior, spacing, controls, breakpoints, and accessibility details.
The layout is mobile-first. One column is the default, and three columns are introduced only when the viewport reaches 900px. The minmax(0, 1fr) tracks and min-width: 0 on cards help prevent grid children from forcing a wider layout.
The radio buttons remain visible. This is especially valuable for a beginner project: using native controls avoids introducing unnecessary complexity merely to create a custom switch.
Test the CSS before adding JavaScript
Open the page and use browser responsive mode to inspect at 320px, 390px, 768px, 900px, and 1200px. Check that the cards stack on narrow screens, the text is readable, and the radio options remain visible and selectable.
Checkpoint: The layout should look deliberate at mobile and desktop widths, without horizontal scrolling. The billing controls still do not update the prices; that is our next task.
Step 5: Write a Better Prompt for JavaScript Behavior
JavaScript requests are more reliable when you describe events, inputs, outputs, and edge cases. “Make the toggle work” is too vague.
Prompt: Generate script.js only
Write only script.js for the existing pricing demo.
Do not rewrite index.html or styles.css.
DOM contract:
- Billing inputs: input[name="billing"]
- Price text: .plan-price
- Each price node has data-monthly and data-annual.
- Billing note for each card: .billing-note
- Status element: #billing-status
Behavior:
1. On initial load, read the checked billing radio.
2. Monthly: show data-monthly and "Billed monthly".
3. Annually: show data-annual as a per-month amount
and "Billed $X yearly · Save 20%".
4. Calculate X as the annual per-month amount times 12.
5. Update the status text for the selected mode.
6. Listen for change events on the radio inputs.
7. Switching back and forth must always restore the
correct values without accumulating discounts.
Implementation constraints:
- Use addEventListener, not inline handlers.
- Use textContent, not innerHTML.
- Keep the code simple enough for a beginner.
- Avoid a framework or external dependency.
- Explain each function after the code.
Working reference: script.js
const billingInputs = document.querySelectorAll('input[name="billing"]');
const planPrices = document.querySelectorAll('.plan-price');
const billingStatus = document.querySelector('#billing-status');
function updatePricing() {
const selectedBilling = document.querySelector('input[name="billing"]:checked');
if (!selectedBilling) {
return;
}
const isAnnual = selectedBilling.value === 'annual';
planPrices.forEach((priceElement) => {
const monthlyPrice = Number(priceElement.dataset.monthly);
const annualMonthlyPrice = Number(priceElement.dataset.annual);
const displayedPrice = isAnnual ? annualMonthlyPrice : monthlyPrice;
const note = priceElement.closest('.plan-card').querySelector('.billing-note');
priceElement.textContent = String(displayedPrice);
if (isAnnual) {
const annualTotal = annualMonthlyPrice * 12;
note.textContent = `Billed $${annualTotal} yearly · Save 20%`;
} else {
note.textContent = 'Billed monthly';
}
});
billingStatus.textContent = isAnnual
? 'Showing annual billing. Prices are per month and billed yearly.'
: 'Showing monthly billing.';
}
billingInputs.forEach((input) => {
input.addEventListener('change', updatePricing);
});
updatePricing();
Understand the JavaScript
querySelectorAll()finds both radio inputs and all three price elements.querySelector('input[name="billing"]:checked')reads the currently selected option.dataset.monthlyanddataset.annualread the values defined in HTML.Number()converts those strings to numbers.- The selected mode determines which original price to display, so repeated toggling does not stack discounts.
closest('.plan-card')finds the related card, allowing the correct note to be updated.textContentinserts plain text safely; it does not interpret HTML.addEventListener('change', ...)responds when the visitor changes the billing radio.- The final
updatePricing()call synchronizes the display with the initially selected option.
Scope note: The example assumes the three price elements have valid numeric data attributes and matching billing notes, as defined in our HTML. In a production application with external data, add schema validation and appropriate handling for invalid or missing values.
Test the behavior
- Reload the page. Confirm the default is Monthly and prices are $15, $30, $60.
- Select Annually. Confirm the visible per-month prices are $12, $24, $48.
- Check the notes: $144, $288, $576 billed yearly, each with “Save 20%.”
- Select Monthly again. Original values and “Billed monthly” notes should return.
- Toggle back and forth several times. Values must not keep decreasing.
- Use Tab to focus the radio group and the arrow keys to change the selected option. The page should still work without using a mouse.
Checkpoint: You now have a working HTML/CSS/JavaScript demo and a set of requirements that can be checked independently.
Step 6: Learn to Improve a Prompt Without Rebuilding Everything
The first AI response may be imperfect. The goal of a follow-up prompt is to describe one observable problem and request one targeted correction.
Weak follow-up prompt
The CSS is broken. Fix it.
This does not explain which layout fails, at what width, or what should remain unchanged.
Better CSS follow-up prompt
The pricing cards fit at desktop width, but at a 320px
viewport I see horizontal scrolling.
Please inspect only the layout-related CSS in styles.css.
Identify the rule that can cause overflow and suggest the
smallest possible change.
Do not redesign the cards, change the colors, modify the HTML,
or introduce a framework.
Return:
1. The likely cause.
2. The exact CSS declarations to replace.
3. A short manual test at 320px, 390px, and 1200px.
Better JavaScript follow-up prompt
Bug report:
Expected: Switching from annual back to monthly restores
$15, $30, and $60.
Actual: The prices decrease again after each switch.
Here is my current script.js:
[paste the relevant code here]
Find the cause and change only the price calculation.
Use the original data attributes as the source of truth.
Do not rewrite the HTML or CSS.
Show the corrected function and explain how to test it.
The text Expected / Actual / Relevant code / Scope is a particularly useful pattern for debugging prompts.
Better HTML follow-up prompt
Review the billing controls in this HTML snippet:
[paste the billing fieldset here]
Check whether the radio inputs have an accessible group name,
visible labels, and native keyboard behavior.
If there is a problem, give me the smallest HTML correction.
Do not replace the native inputs with a custom JavaScript toggle.
Checkpoint: A helpful AI response should identify the specific concern, propose a limited change, and explain how to verify that the fix works. If the assistant rewrites unrelated files, reject that extra scope and repeat your constraint.
Step 7: Ask AI to Review Its Own Output—Then Verify It Yourself
AI can spot issues, but it can also miss bugs or confidently claim that untested code works. Use it to generate a review checklist, not to provide the final verdict.
Prompt: Focused code review
Review this three-file HTML/CSS/JavaScript pricing demo.
Check:
- Semantic HTML and accessible form labeling.
- Mobile layout and possible horizontal overflow.
- Visible keyboard focus for the billing radio inputs.
- Correct monthly and annual prices.
- Correct annual totals and 20% discount.
- No inline JavaScript, unsafe HTML insertion, or dependencies.
- Repeated toggling without price drift.
- Clear and maintainable beginner-level code.
For each finding, provide:
- Severity: critical, major, minor, or none.
- File and relevant selector/function.
- Why it matters.
- The smallest practical fix.
- A manual test that could confirm the fix.
Do not invent test results. Separate code inspection from
behavior actually observed in a browser.
Your independent testing checklist
| Test | Expected result |
|---|---|
| Initial load | Monthly is selected; prices show $15 / $30 / $60 |
| Annual selection | Prices change to $12 / $24 / $48 per month |
| Annual totals | Notes show $144 / $288 / $576 per year |
| Return to monthly | Initial prices and monthly notes are restored |
| Repeat ten times | No price drift or JavaScript errors |
| Keyboard control | Focus is visible; arrows select the billing option |
| 320px viewport | No horizontal scrolling or clipped billing controls |
| 390px viewport | Cards remain readable in one column |
| 768px viewport | Layout is comfortable without overflow |
| 900px and above | Cards appear in three columns when space permits |
| JavaScript disabled | Plan information and monthly prices remain visible; switching billing modes will not update prices |
Check the discount calculation
Do not rely on the AI’s explanation of the mathematics. Verify the figures:
Starter: (15 - 12) / 15 × 100 = 20%
Pro: (30 - 24) / 30 × 100 = 20%
Studio: (60 - 48) / 60 × 100 = 20%
Annual totals:
12 × 12 = 144
24 × 12 = 288
48 × 12 = 576
Use your browser’s developer tools
Open Developer Tools → Console and check for errors while switching billing modes. Then use responsive mode to test the sizes above. In the Elements panel, inspect the radio inputs and note whether their checked states correspond to the visible prices.
For a more thorough accessibility review, use the browser’s accessibility inspection tools and test the radio group entirely with the keyboard. Automated checkers can help, but do not replace real interaction testing.
Checkpoint: The work is not complete because the AI says “done.” It is complete when the page behaves as required in your own browser.
Step 8: Create Reusable Prompt Templates for Future Projects
Once you have practiced the workflow, you can use a concise template for future HTML, CSS, and JavaScript tasks.
General-purpose AI coding prompt template
Role/context:
You are helping me build [project] for [audience/skill level].
Goal:
I need [one concrete feature or deliverable].
Existing project:
- Files: [relevant file names]
- Current behavior: [what already works]
- Relevant code: [paste only what is needed]
Technical constraints:
- Use [HTML/CSS/vanilla JavaScript/etc.].
- Keep [specific file organization].
- Do not use [unwanted libraries or approaches].
- Preserve [important existing behavior].
Requirements:
1. [observable requirement]
2. [observable requirement]
3. [observable requirement]
Accessibility/responsiveness:
- [keyboard, labels, focus, mobile requirements]
Output:
- Return [file name, exact code change, or plan].
- Explain important decisions briefly.
- Include a manual verification checklist.
- State assumptions and do not invent test results.
Short prompt for HTML
Write semantic HTML for [component].
Include [required content and structure].
Use native accessible elements and meaningful labels.
Preserve these IDs/classes: [list].
Return only [file or markup section], then explain the structure.
Do not include inline styles or inline event handlers.
Short prompt for CSS
Style the existing [component] in [file].
Use [colors, spacing, typography, layout].
Mobile behavior: [specific rules].
Desktop behavior: [specific rules].
Include visible focus styling and avoid horizontal overflow.
Do not change HTML or JavaScript.
Return the CSS and a responsive test checklist.
Short prompt for JavaScript
Implement [specific interaction] in script.js.
Inputs/selectors: [list].
Expected behavior: [exact state changes].
Edge cases: [list].
Use addEventListener and textContent when suitable.
Do not use inline JavaScript or change unrelated files.
Return the code, an explanation, and test steps.
Short prompt for debugging
Expected: [what should happen].
Actual: [what happens instead].
Reproduce: [precise sequence of actions].
Environment: [browser, screen size, relevant files].
Error message: [exact text, if any].
Relevant code: [paste minimal reproduction].
Identify the likely root cause, propose the smallest fix,
and explain how I can verify it. Do not rewrite working code.
A practical way to iterate
Use this repeatable cycle:
- Ask for a plan if the task has several independent parts.
- Request one logical part (HTML, CSS, behavior, or a specific bug fix).
- Read the response and compare it with your requirements.
- Run the code yourself and report actual results.
- Give a targeted follow-up prompt if something fails.
- Retest after each change, especially at mobile widths.
This is more reliable than repeatedly saying “make it better” with no measurable criteria.
Common Prompting Mistakes and How to Fix Them
Mistake 1: Asking for too much at once
Weak: “Build a complete SaaS site with login, pricing, payments, and dashboard.”
Better: Break the work into independent milestones and verify each before the next. Our first milestone is only a static pricing demo, not a payment system.
Mistake 2: Giving no existing code
Weak: “Fix my JavaScript.”
Better: Supply the relevant function, the HTML selectors it uses, the exact error, and steps to reproduce the problem.
Mistake 3: Using ambiguous design words
Weak: “Make it responsive and beautiful.”
Better: State the number of columns, minimum viewport to support, spacing direction, colors, and focus requirements.
Mistake 4: Forgetting edge cases
Weak: “Add annual pricing.”
Better: Define default state, exact price values, annual totals, and behavior when switching back to monthly repeatedly.
Mistake 5: Accepting explanations instead of tests
Weak: “AI says the code is error-free, so I can publish it.”
Better: Test the actual files in the browser, inspect the console, verify the calculations, and check accessibility and mobile behavior.
Mistake 6: Allowing unnecessary changes
Weak: “Fix this small bug however you want.”
Better: Name the specific file, describe what must remain untouched, and request the smallest fix plus a short test plan.
Troubleshooting the Demo
The page has no styling
Check that the file is named styles.css, that it is in the same folder as index.html, and that the HTML contains:
<link rel="stylesheet" href="styles.css">
Inspect the browser’s Network or Console panel if the file cannot be loaded.
Prices do not change
Confirm that script.js is linked with defer, that the file name matches, and that the HTML still includes the expected input name, data attributes, and selectors:
<script src="script.js" defer></script>
Check the Console for JavaScript errors. If you changed a class or an ID in HTML, update the matching selector in JavaScript as well.
The annual total is wrong
Check whether your data attributes contain the discounted per-month amount, not the full annual total. In this project, the annual total is calculated with:
const annualTotal = annualMonthlyPrice * 12;
For Starter, data-annual="12" means $12 per month when billed annually, so the annual charge is $144.
The prices keep decreasing when you toggle
Do not apply a percentage discount to the currently displayed price each time the option changes. Read the original fixed values from data-monthly and data-annual instead.
Billing controls are not usable with the keyboard
Use the native <input type="radio"> controls in the reference HTML, and do not hide them with display: none. They should receive focus and support keyboard selection.
The cards overflow on small screens
Check the viewport meta tag, container width, grid columns, min-width, and long unbroken content. Use responsive mode at 320px and share the actual offending element and computed style in your next AI debugging prompt.
Best Practices for AI-Assisted Web Development
- Describe the result, not just the technology. Say what users should be able to do.
- Make requirements testable. Provide exact values, widths, states, and expected interactions.
- Use the simplest appropriate technology. Native HTML often solves problems that do not require JavaScript.
- Ask for a plan when complexity grows. For small fixes, a direct, scoped request is enough.
- Keep file responsibilities clear. HTML provides structure, CSS controls presentation, and JavaScript adds behavior.
- Prefer focused revisions over large rewrites. Preserve parts already known to work.
- Treat generated code as untrusted until reviewed. Avoid running unexplained commands or adding unknown dependencies.
- Never paste secrets into prompts. Keep API keys, credentials, and private data out of public or unnecessary tool contexts.
- Review security, accessibility, and maintainability. “It looks good” is not the same as “It is ready for production.”
- Verify changes independently. AI can draft code and suggest tests, but you remain responsible for validating the result.
Conclusion
Writing better prompts is not about discovering a magical phrase. It is about communicating like a developer: define the problem, supply relevant context, choose the appropriate technology, set boundaries, and describe how success will be measured.
In this tutorial, you moved from a vague request to a fully specified HTML/CSS/JavaScript project. You used targeted prompts for each file, added a monthly/annual pricing interaction, practiced bug-report prompts, and built a repeatable review process.
The most useful habit: Ask AI for an implementation you can understand, inspect, and test—not merely for code that looks complete.
What to Build Next
Try applying the same prompting method to a responsive navigation menu, a filterable portfolio grid, or a form with client-side validation. Start with a short project brief and a clear acceptance checklist; then ask for HTML, CSS, and JavaScript in focused steps.
Next tutorial: How to Build a Responsive Website Using AI — Step by Step.