DEV Community

riona he
riona he

Posted on AI-assisted

Five Things Your AI Builder Wrote JavaScript For (That HTML Already Does)

Disclosure: I work on VibUI, a paid library of website prompts. It's linked once, at the end.

You open the file for the FAQ section and find a hundred and forty lines of JavaScript. State variables, event listeners, an animation timer. The thing it does is open and close a box.

HTML has had an element for that for years. AI tools write the script version a lot, because the examples they learned from did. Here are five spots where you can delete code and keep the behaviour.

1. Accordions

<details>
  <summary>Is there a free plan?</summary>
  <p>Yes, with limits. See the pricing section.</p>
</details>
Enter fullscreen mode Exit fullscreen mode

Keyboard support and screen reader semantics come free. Style the marker in CSS if you want.

2. Modals

<dialog id="signup">
  <form method="dialog">
    <h2>Join the waitlist</h2>
    <button>Close</button>
  </form>
</dialog>
<button onclick="document.getElementById('signup').showModal()">Join</button>
Enter fullscreen mode Exit fullscreen mode

One line of script opens it, and the browser handles the backdrop, the Escape key and keeping focus inside.

3. Form validation

<input type="email" name="email" required autocomplete="email">
<input type="text" name="code" pattern="[A-Z]{4}[0-9]{2}" minlength="6" required>
Enter fullscreen mode Exit fullscreen mode

Browsers check these on submit. You'll still validate on the server, but you don't need a validation library for "this field is empty".

4. Lazy loading and smooth scrolling

<img src="shot.webp" alt="Dashboard screenshot" width="800" height="500" loading="lazy">
Enter fullscreen mode Exit fullscreen mode
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
Enter fullscreen mode Exit fullscreen mode

5. Sticky headers and snap carousels

header { position: sticky; top: 0; }
.row { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; }
.row > * { scroll-snap-align: start; }
Enter fullscreen mode Exit fullscreen mode

No scroll listeners, no carousel library.

Quick reference

The script does Native option Watch out for
Open and close a panel <details> Styling the marker
Modal window <dialog> + showModal() Check support for your audience
Check an email field type="email", required Still validate on the server
Defer offscreen images loading="lazy" Keep width and height set
Smooth scroll scroll-behavior Respect reduced motion
Snap a row of cards scroll-snap-type Add visible controls if content is hidden
Popup menus The popover attribute Newer, so test in the browsers you support

Always check browser support for anything newer before you rely on it.

Put it in the prompt

Prefer native HTML and CSS over JavaScript. Use <details> for accordions, <dialog> for modals,
built-in input validation, loading="lazy", CSS scroll-snap and position: sticky.
No script unless a feature can't be done without it, and explain why if you add any.
Enter fullscreen mode Exit fullscreen mode

Any of these tools will follow it: v0, Lovable, Bolt, Cursor, Windsurf, Claude, ChatGPT, Gemini, Replit, GitHub Copilot, Framer AI, Google Stitch, Readdy, Aura.build, OpenAI Codex. The result is less code to read, and less to break.

A small plug

Sections built mostly in plain HTML and CSS are easier to review. If you want starting points like that: VibUI is the library I work on: 2,852 website prompt templates (775 pages, 1,100 sections, 817 components, 160 animated backgrounds), about 1,000 of them with source code. It's one-time pricing with no auto-renewal: $48 quarterly, $99 yearly, $179 lifetime (listed down from $384). Yearly and lifetime also include 2,407 AI video prompts. There are 60 free samples, and a free account can copy 2 prompts. Open a free sample with source code and count how much of it is script.

Top comments (0)