Building a UI
Components, layout, styling and accessibility, the parts of a frontend you need to specify.
8 min read · Last reviewed November 20, 2026
Building a UI
A UI is a tree of components that turn data into pixels and user actions into events. Agents are good at writing components. They're bad at guessing your design intent, so that's the part you supply.
You'll be able to#
- Describe a UI precisely enough that an builds what you pictured
- Choose a framework, styling approach and component library
- Catch accessibility and responsiveness problems in review
The mental model#
UI = f(state). You describe what the screen should look like for a given state, and the framework updates the DOM when that state changes. Components are functions with props (inputs) and sometimes their own state.
Key concepts#
- Component: A reusable piece of UI (
<Button>,<UserCard>). Composition means building big components from small ones. - Props vs state: Props are passed in from the parent. State is owned locally and changes over time.
- Layout: Flexbox (one dimension) and CSS Grid (two dimensions). Responsive design means layouts adapt to the screen size, using breakpoints and mobile-first CSS.
- Styling approaches: Utility classes (Tailwind), CSS Modules, CSS-in-JS. Design tokens are named values for colours, spacing and type.
- Component libraries: shadcn/ui (copy-in, built on Radix), MUI, Mantine, Chakra. Headless libraries (Radix, React Aria) give you behaviour and accessibility with no styling.
- Forms: Controlled inputs, client-side validation for user experience, server-side validation for correctness (always both).
- Accessibility (a11y): Semantic HTML (
<button>, not a clickable<div>), labels, keyboard navigation, focus states, colour contrast (WCAG AA), alt text. - UI states: Every data-driven view has loading, empty, error and success states. Agents tend to build only the success state.
Decisions you make (not the agent)#
Your call, not the agent's
| Decision | Sensible default | Choose otherwise when… |
|---|---|---|
| Framework | React via Next.js | Simpler sites: Astro. Preference: Svelte/Vue |
| Styling | Tailwind CSS | Existing design system or team preference |
| Components | shadcn/ui | You need a full prebuilt suite (MUI) |
| Design reference | Give a screenshot, Figma link, or named product | Never leave this to "modern and clean" |
| Breakpoints | Mobile-first; test at 375px, 768px, 1280px | — |
What good output looks like#
- Small components with clear props, matching the existing folder conventions
- Semantic HTML, keyboard support and visible focus states
- Loading, empty and error states all handled
- No hardcoded colours or spacing outside the design tokens and theme
Red flags#
<div onClick>instead of<button>- Images without
alt; inputs without labels - One 600-line component
- A new UI library installed when the project already has one
- Common agent mistakes: only the success state is built; a placeholder is used in place of a label (it disappears once the user types); colours and spacing are hardcoded instead of coming from the tokens; a styled
<div>replaces a real button, which loses the keyboard behaviour a<button>gets for free
Worked example#
Task: Add a signup form (name, email, password) to a Next.js app.
You prompt: "Add a signup form." It looks right on your laptop. The agent used placeholders instead of labels, a styled <div onClick> for the submit button, hardcoded hex colours, and built only the success path.
What a good result contains: real <label> elements tied to their inputs, a <button type="submit">, validation messages next to the fields, loading and error states for the request, and colours from the project's tokens.
The wrong turn: the "button" can't be reached with the Tab key and doesn't respond to Enter or Space, because a <div> doesn't get the keyboard behaviour a button has by default. The placeholder text vanishes as soon as someone types, so they can't see what a field was for. Nothing happens visibly while the request is in flight, and a failed request shows nothing at all.
How review catches it: put the mouse away and use only the keyboard: Tab through the form and press Enter. Resize to a phone width. Turn on network throttling or go offline and submit. Then re-prompt with the rules stated: semantic form elements, labels, all four states, and tokens only.
Sample prompts#
Weak vs strong#
Make a nice dashboard page.
Why it fails: No layout, data source, states or accessibility requirements, and "nice" has no criteria, so the agent invents a generic dashboard and only the success state.
Build a /dashboard page in our Next.js + Tailwind + shadcn/ui app. Layout: left sidebar nav (collapsible on mobile into a sheet), top bar with search and user menu, main area with 4 stat cards in a responsive grid (1 col mobile, 2 tablet, 4 desktop) and a recent-orders table below. Reference: similar density to Linear's UI. See attached screenshot for tone. Data: use the existing getDashboardStats() and getRecentOrders() in lib/data.ts. States: skeleton loaders, empty state for no orders, error state with retry. A11y: keyboard-navigable nav, proper table semantics, AA contrast. Use existing components in components/ui before creating new ones.
Why it works: It gives the layout, a visual reference, a data source, all four UI states, accessibility requirements and a reuse constraint.
What changed
- Layout is described, including how it changes by screen size
- Reference gives the tone and density to match
- Data points at the existing functions instead of inventing new ones
- States lists loading, empty and error, not just success
- A11y names keyboard and contrast requirements
- Reuse says to use existing components first
Audit components/ for accessibility issues: semantic elements, labels, focus management, keyboard traps, contrast, alt text. Output a table of issues by file, severity, and fix, then fix the high-severity ones.
Why it works: A table by file and severity turns a vague "make it accessible" into work you can review and finish.
Review a UI before you accept it#
Review the signup form against this checklist and report each failure with file and line: native elements for interactive controls (button, a, input), a label for every input, keyboard order and visible focus, loading, empty and error states, colours and spacing from tokens, and layout at 375, 768 and 1280 px. Don't fix anything yet.
Why it works: A fixed checklist stops "looks fine to me" and gives you a list you can verify one item at a time.
Reuse before building#
Before you write any new component, list the components in components/ui and the design tokens that already exist, say which you will reuse for this screen, and justify any new component you think is necessary. Wait for my OK.
Why it works: It prevents the most common UI drift: a second button, a second modal, a one-off colour.
Explain what the UI does not handle#
For each component you built, list the states it handles (loading, empty, error, success, disabled) and the ones it doesn't. For every interactive element, say which native element it uses, and explain any that is not a native button, link or input.
Why it works: It makes the agent account for the missing states and the non-native controls, which are exactly where agent-built UIs fall short. Check the answer against the code.
Check your understanding#
Check your understanding
Checklist#
- Works at mobile, tablet and desktop widths
- Every interactive element is reachable by keyboard
- Loading, empty and error states exist
- Lighthouse accessibility score ≥ 90
- Every input has a real
<label>, and buttons are real<button>s - Colours and spacing come from the design tokens
Go deeper#
- react.dev
- MDN: Learn web development
- WCAG quick reference
- MDN: HTML, a good basis for accessibility: native elements, labels and keyboard behaviour
- State and data fetching: where the data your components show should live
- Reviewing and verifying AI output: checking what the agent built