# Building the Modern Web with AI: Modernizing Existing UI with Modern Web Guidance > Use Modern Web Guidance to scan an existing form, evaluate legacy patterns, and improve textarea sizing and validation feedback. - **Author**: Luca Del Puppo (@puppo92) — AI Native Engineer at Nearform - **Published**: Nov 26, 2026 - **Canonical URL**: https://blog.delpuppo.net/building-the-modern-web-with-ai/building-the-modern-web-with-ai-modernizing-existing-ui/ - **Series**: Building the Modern Web with AI (Part 2 of 2) — https://delpuppo.net/blog/series/building-the-modern-web-with-ai/ - **Series LLMs.txt**: https://delpuppo.net/blog/series/building-the-modern-web-with-ai/llms.txt - **Category**: Web Development - **Tags**: web, ai, accessibility - **Blog Index LLMs.txt**: https://delpuppo.net/blog/llms.txt ## Series Context: Building the Modern Web with AI - Part 1: [Building the Modern Web with AI: Getting Started with Modern Web Guidance](https://delpuppo.net/blog/building-the-modern-web-with-ai/building-the-modern-web-with-ai-getting-started/) - Part 2: [Building the Modern Web with AI: Modernizing Existing UI with Modern Web Guidance](https://delpuppo.net/blog/building-the-modern-web-with-ai/building-the-modern-web-with-ai-modernizing-existing-ui/) **(Current Article)** --- Open a profile form for the first time, and the empty name already has a red border. You haven't typed anything yet. Further down, the bio grows as you type, using JavaScript to measure its content and update its height. Both behaviors give us something concrete to investigate with **Modern Web Guidance**. Can we improve when the form shows errors? Can the browser handle the growing textarea while keeping it usable in older browsers? In part one, we used the skill's guides to understand implementation choices in Common Ground, our small preferences demo. This time, we'll use its modernization workflow on existing code. You'll need Git, Node.js 26 or newer, and npm. Basic HTML, CSS, and JavaScript knowledge is enough to follow the changes. ## Start with a form we can inspect The repository has two branches for this exercise, `article-2/legacy` and `article-2/modernized`. The starting branch is a deliberately prepared teaching variant of Common Ground. It adds unconditional JavaScript auto-resizing and premature `:invalid` styling. A new profile starts empty so you can observe the error timing. These choices make the exercise repeatable and keep its scope small. ```sh git clone https://github.com/Puppo/modern-web-guidance-demos.git modern-web-guidance-modernization cd modern-web-guidance-modernization git switch article-2/legacy npm ci npm start ``` Open [the local demo](http://127.0.0.1:4173/) and choose **Edit profile**. Inspect the empty name before typing, then enter several lines in **Bio** and remove some of them. The textarea expands and contracts. ![The untouched profile form, with a red error border around the empty name](/images/building-the-modern-web-with-ai/before-untouched.png) The exercise uses its own local storage key, `mwg-modernization-v1`. If you've already saved a profile here, remove that key in DevTools and reload to repeat the empty-field example. ## Ask for a modernization plan Open the checkout in Google Antigravity with Modern Web Guidance enabled. You can ask the agent to inspect the repository with this prompt: > Modernize this repository using Modern Web Guidance. Scan the frontend files for legacy patterns, verify each finding against the surrounding code, and propose a plan before editing. Target Baseline Widely available features, with progressive enhancement for newer features. Automatic textarea growth is optional in older browsers, but editing, scrolling, saving, and canceling must remain usable. For each proposed change, identify the guide and describe how to verify the behavior. This is a suggested reader prompt. The recorded work behind this article used the CLI commands below and a review of the retrieved guides. An Antigravity session may present its findings differently. The modernization workflow scans for recognizable legacy patterns, asks the agent to check their context, and then uses the matching guides to inform changes. A result includes criteria called `keepWhen` and `dropWhen`, which help distinguish an applicable finding from code that should stay. [Google's modernization workflow](https://developer.chrome.com/docs/modern-web-guidance/modernization-workflow) You can inspect the scan directly from a second terminal in the repository: ```sh npx --yes modern-web-guidance@1.0.1 legacy-scan . --json ``` The recorded run used version 1.0.1 and checked 52 rules across 38 guides. It returned two findings: - In `app.js`, the bio resizes through a JavaScript `scrollHeight` measurement. - In `styles.css`, `input:invalid` applies an error border before interaction. Check the surrounding code before accepting either proposal. Our resize handler runs on every input event and has no feature check. Our error rule has no interaction guard. Both findings apply to this exercise. The saved JSON includes the complete criteria. [Recorded scan](https://github.com/Puppo/modern-web-guidance-demos/blob/b2b1169/verification/modernization/scan-before.json) ## Let the bio grow through CSS Retrieve the guide associated with the first finding: ```sh npx --yes modern-web-guidance@1.0.1 retrieve form-fields-automatically-fit-contents ``` The starting implementation measures the textarea after each edit: ```js function resizeBio() { bioInput.style.height = 'auto'; const borderHeight = bioInput.offsetHeight - bioInput.clientHeight; bioInput.style.height = (bioInput.scrollHeight + borderHeight) + 'px'; } bioInput.addEventListener('input', resizeBio); ``` It also calls `resizeBio()` after opening the dialog so the saved bio fits. The guide points us toward `field-sizing: content`, with size constraints and an explicit fallback decision. For this demo, automatic growth is optional. A standard scrolling textarea remains usable when the property is unsupported. That lets us remove the helper, its input listener, and its call on opening. The resulting sizing rules are: ```css textarea { resize: vertical; min-block-size: 3lh; max-block-size: 7lh; overflow: auto; } @supports (field-sizing: content) { #bio { field-sizing: content; block-size: auto; } } ``` The existing form styles keep the width at `100%`. The `lh` unit bases the height limits on line height. With support, the field grows vertically until it reaches the maximum and then scrolls. With the enhancement unavailable, the HTML `rows` attribute and normal resizing behavior provide the fallback. The removal of the inline height is part of the change. Leaving an explicit height from the old helper would interfere with content-based sizing. This is why reading the guide matters beyond finding a new CSS property. [Sizing guide](https://github.com/GoogleChrome/modern-web-guidance/blob/main/skills/modern-web-guidance/guides/forms/form-fields-automatically-fit-contents.md) ![The modernized profile form with a bio expanded to fit several lines](/images/building-the-modern-web-with-ai/after-growing-bio.png) ## Show an error after interaction Now retrieve the second guide: ```sh npx --yes modern-web-guidance@1.0.1 retrieve validate-input-after-interaction ``` The starting selector matches as soon as the required name is empty: ```css #profile-form input:invalid { border-color: var(--error); } ``` The guide recommends `:user-invalid` for feedback that follows interaction or an attempted submission: ```css #profile-form input:user-invalid { border-color: var(--error); } ``` Open the modernized form and the empty name starts with a neutral border. Type spaces and move to Bio, or attempt to save the empty form, and the error appears. ![The same untouched form after modernization, with a neutral name field border](/images/building-the-modern-web-with-ai/after-untouched.png) There is another requirement in the guide. The visible state must agree with the field's accessible state and error description. Changing the CSS selector alone leaves that work unfinished. Our name field starts with `aria-invalid="false"` and `aria-describedby="name-help"`. When the error appears, the script sets `aria-invalid="true"`, adds `name-error` to the description, and supplies an explanation: > Enter a display name with at least one non-space character. After input or blur, the script reads the browser's interaction state: ```js function syncNameFeedback() { if (nameInput.matches(':user-invalid')) showNameError(true); else clearNameError(); } ``` The helpers update the text and ARIA together. A polite live region inside the dialog announces errors after field interaction. An invalid submit focuses the name with its linked explanation. Correction and cancellation clear pending feedback. The error container reserves space so the buttons stay in place as the message changes. This keeps the existing `required` and whitespace constraint, and Cancel still bypasses validation. The guide has shaped both the timing and the accessible feedback. [Validation guide](https://github.com/GoogleChrome/modern-web-guidance/blob/main/skills/modern-web-guidance/guides/forms/validate-input-after-interaction.md) ## Try the completed version Stop the server, then switch branches: ```sh git switch article-2/modernized npm ci npm start ``` **Reload every open demo tab** to load the updated code. Try these interactions: 1. Open the empty profile. Check that the name starts neutral. 2. Enter spaces and leave the name. Check the error text, then correct the value. 3. Cancel and reopen. Confirm that both the draft and error state reset. 4. Paste several lines into Bio, shorten the text, and save. Reopen to check the saved value and field size. Run the scan again: ```sh npx --yes modern-web-guidance@1.0.1 legacy-scan . --json ``` Our second run returned zero findings within the scanner's supported rules. The browser checks provide the next piece of evidence: ```sh npx playwright install chromium firefox webkit npm test -- --workers=1 ``` The modernized branch passed **20 scenarios across three browser engines**, for 60 executions. Five added scenarios cover validation timing, correction, cancellation, textarea sizing, and fallback presentation. The fallback check disables content sizing in a current browser and confirms scrolling and saving at mobile width. Actual older browsers and screen-reader speech still need their own checks. [Results and coverage](https://github.com/Puppo/modern-web-guidance-demos/blob/af6fa0d/verification/modernization/README.md) ## Take the workflow to your own code The useful output is a decision you can explain. Here, the sizing guide helped us remove a measurement handler while choosing an acceptable fallback. The validation guide led us from a selector change to consistent visual and programmatic feedback. Try the same workflow on a small frontend folder. Ask for a plan, read the relevant guide with the proposed diff, and exercise the behavior that justified the change. The repository preserves both versions so you can compare each decision. [Before and after](https://github.com/Puppo/modern-web-guidance-demos/compare/b2b1169...af6fa0d) Bye bye!