The short answer
An acceptance criterion for a UI state says which state the screen is in (Given), what the user does or what changes (When), and what they can see, hear or do as a result (Then). Write one criterion per state, cover the states nobody designs, such as empty, loading, error, offline and expired, and give each one an ID so a test can cite it.
Most guides to Given/When/Then use business examples: a bank balance after a withdrawal, an alert when a driver accepts a ride. Those examples teach the format, but they skip the hard part of frontend work, which is everything that happens between “the user clicks” and “the result appears”. That gap is where focus gets lost, entries disappear, errors go unannounced and layouts jump. The 12 examples below fill it.
Why UI states need their own criteria
A screen has more states than it has designs. A design file usually shows the filled, successful version of a page. The page that ships also has to be empty, loading, slow, partially loaded, invalid, failed, offline, out of date, forbidden and expired. If the spec does not describe those states, the engineer decides how they behave, usually late and alone.
Criteria for states also have to say things that business criteria never mention:
- Where focus goes. A keyboard or screen-reader user who loses focus loses their place on the page.
- What is announced. A change that is only visible is invisible to some users.
- What happens to the user’s data. An error that clears a long form is a second error.
- Whether the layout moves. Content that shifts as it loads causes mis-clicks, and layout shift is a measurable Core Web Vitals metric.
We write these into the criterion itself, not into a separate accessibility or performance document, so they are tested with the behaviour they belong to. The full method is on acceptance criteria for frontends.
Start with a states table
Before writing any criteria, list the states. We do this as a table in section 4 of the feature spec template, and each row ends up with at least one criterion. Here is the table for an invented feature, a member’s saved addresses page, which most of the examples below use.
| State | When it happens | What the user sees | Criterion |
|---|---|---|---|
| Empty | Member has no saved addresses | Short message and an “Add address” action | AC-1 |
| Loading | Request in flight | Skeleton rows the size of real rows | AC-2, AC-3 |
| Partial | List loaded, map previews failed | List without previews, no error wall | AC-4 |
| Invalid | Form field fails validation | Error next to the field, focus on it | AC-5 |
| Failed | Save request fails | Message, entries kept, retry offered | AC-6 |
| Submitting | Save in progress | Button disabled, one request only | AC-7 |
| Offline | Connection lost | Notice, actions that need a network paused | AC-8 |
| Stale | Data changed elsewhere | Notice and a way to refresh | AC-9 |
| Denied | Member lacks permission | Explanation, no broken controls | AC-10 |
| Expired | Session ended mid-task | Sign-in, then return with entries | AC-11 |
| Success | Save completed | Confirmation, announced | AC-12 |
The table does most of the work. Once a state has a name and a row, it is hard to forget, and a missing criterion shows up as an empty cell.
Twelve examples, one per state
Each example is one behaviour. Where a scenario has several Then lines, they all describe the same result from different angles, such as what is shown, what is announced and what happens to the data. That keeps one failing test pointing at one problem.
1. Empty
Scenario: AC-1 Member with no saved addresses
Given a signed-in member with no saved addresses
When they open the addresses page
Then they see "No saved addresses yet" and an "Add address" button
And no empty table, column headers or pagination are shown
An empty state is a first impression. The criterion rules out the default result, which is a table with headers and nothing under them.
2. Loading
Scenario: AC-2 Addresses are loading
Given the addresses request has not returned
When the page renders
Then skeleton rows are shown in place of the address list
And the page layout does not shift when the real rows replace them
“Does not shift” is testable: the test measures layout shift between the skeleton and the loaded list.
3. Slow response
Scenario: AC-3 Addresses take too long
Given the addresses request has not returned after 10 seconds
When the member is still on the page
Then a message says the list is taking longer than usual
And a "Try again" button repeats the request
The threshold is a decision for the spec, not the engineer. Write the number you agree on. Ten seconds here is an example value, not a recommendation.
4. Partial data
Scenario: AC-4 Map previews fail to load
Given the address list loads and the map preview service fails
When the page renders
Then each address is shown with its text and actions
And the preview area shows "Map unavailable" instead of a broken image
Partial failures are common in interfaces that call several services. The criterion says which part may fail quietly and which may not.
5. Inline validation
Scenario: AC-5 Postcode in the wrong format
Given a member is adding an address
When they leave the postcode field with a value that does not match the country's format
Then "Enter a postcode like the example shown" appears below the field
And the field is marked invalid for assistive technology
And the error is not shown while they are still typing
The last line is the one most criteria miss. Errors that appear on the first keystroke punish people for not having finished.
6. Server error
Scenario: AC-6 Save fails on the server
Given the member has filled in a new address
When they press "Save" and the server returns an error
Then a message says the address was not saved
And every field keeps what the member entered
And focus moves to the message, which offers "Try again"
An error criterion answers three questions: what the user is told, what happened to their data, and what they can do next.
7. Double submit
Scenario: AC-7 Member presses Save twice
Given the member has pressed "Save" and the request is in progress
When they press "Save" again
Then no second request is sent
And the button shows that saving is in progress
This is an edge case a design file cannot show and a user will always find. The test counts requests.
8. Offline
Scenario: AC-8 Connection lost while editing
Given the member is editing an address
When the device loses its network connection
Then a notice says they are offline and changes will not be saved yet
And their entries stay in the form
And "Save" is disabled until the connection returns
Whether offline edits are queued or paused is a product decision. Write the one you chose. A test can simulate the lost connection.
9. Stale data
Scenario: AC-9 Address changed on another device
Given the member has the addresses page open
When the same address is edited from another session
Then a notice says the list has changed and offers "Refresh"
And the list does not reorder or change under the member's pointer
Interfaces that update in place need a rule for when to update and when to ask. Silent reordering causes mis-clicks.
10. Permission denied
Scenario: AC-10 Member without permission to edit
Given a member whose account role can view but not edit addresses
When they open the addresses page
Then the addresses are shown without "Edit" or "Delete" actions
And a line explains who can make changes
Hidden or disabled, with or without an explanation: choose once in the spec, not separately on every screen.
11. Session expired
Scenario: AC-11 Session expires during a long edit
Given the member's session expired while the form was open
When they press "Save"
Then they are asked to sign in again
And after signing in they return to the form with their entries restored
And the entries are not written to local storage in readable form while they sign in
The last line is a privacy rule written as a criterion. Restoring entries is good, and leaving an address in readable browser storage is not. Both belong in the same scenario because they are the same behaviour.
12. Success
Scenario: AC-12 Address saved
Given the member has filled in a valid address
When they press "Save" and the save succeeds
Then the new address appears in the list
And "Address saved" is announced to screen readers without moving focus
And focus returns to the "Add address" button
Even the happy path has frontend details. A confirmation that only appears on screen is missed by anyone who cannot see it.
What the examples have in common
The twelve examples follow five rules. We use them to review any criterion, whoever wrote it.
- One state per scenario. The Given names exactly one state. If it needs “and also”, it is two scenarios.
- Observable results only. Then lines describe what a person sees, hears or can do, or a request a test can watch. They never name a function, a component or a library, so they survive refactors.
- Data is always accounted for. Every failure scenario says what happened to the user’s entries.
- Focus and announcements are explicit. If the state changes what a keyboard or screen-reader user experiences, the criterion says how.
- Numbers are decisions. Thresholds such as timeouts are written down as agreed values. “Quickly” is not a criterion.
A useful test of a criterion: give it to two engineers separately and ask them to write the test. If the tests differ in what they check, the criterion is still ambiguous.
Weak and strong, side by side
Most weak criteria are not wrong. They are unfinished. Each one below becomes strong by naming the state, the action and one observable result.
| Weak | Strong |
|---|---|
| Show a loader while data loads | Given the list request has not returned, When the page renders, Then skeleton rows are shown and the layout does not shift when rows arrive |
| Handle errors gracefully | Given the save request fails, When the member presses Save, Then a message says nothing was saved, entries are kept and focus moves to the message |
| Works offline | Given the connection is lost while editing, When the member tries to save, Then Save is disabled and a notice explains why |
| Prevent duplicate submissions | Given a save is in progress, When Save is pressed again, Then no second request is sent |
| Accessible confirmation | Given a successful save, When the list updates, Then “Address saved” is announced without moving focus |
From criterion to test
Each criterion has an ID, and each test cites it. That link is what lets a trace report list every criterion with its test and result at release. Here is AC-7 as a Playwright test.
// addresses.spec.ts · covers AC-7 "Member presses Save twice"
test('AC-7 a second press does not send a second save', async ({ page }) => {
let saves = 0;
await page.route('**/addresses', async (route) => {
if (route.request().method() === 'POST') saves += 1;
await new Promise((r) => setTimeout(r, 500));
await route.fulfill({ status: 201, body: '{}' });
});
await page.goto('/account/addresses/new');
await page.getByLabel('Street').fill('1 Example Street');
const save = page.getByRole('button', { name: 'Save' });
await save.click();
await save.click({ force: true });
await expect(page.getByText('Address saved')).toBeVisible();
expect(saves).toBe(1);
});
The test checks what the criterion promises and nothing else. It does not care how the button prevents the second request. If the implementation changes, the test stays valid.
Some criteria cannot be fully automated. A screen-reader announcement can be checked for the right live region and text, but whether it makes sense in context needs a person. We mark those criteria for a manual pass and record the result in the same report.
Mistakes we see most often
Criteria written after the code. They describe what was built, not what was needed, and they never fail. Write criteria before design is final, while changing the answer still costs a sentence.
One scenario for every error. “Given any error, Then show a message” hides the differences that matter. A validation error, a network failure and a permission error need different copy and different recovery paths.
Implementation in the Then line. “Then the Redux store is updated” tests code, not behaviour. “Then the new address appears in the list” tests what the user gets.
States left to design. A design file is not the place where states are decided, because it only shows the states someone drew. The states table is.
No owner for the numbers. Timeouts, retry counts and session lengths are product decisions. If the spec leaves them blank, they get decided in code review.
How to start
Take one feature that is already live. Write its states table, then write one criterion per row using the examples above as patterns. Most teams find at least one state that nobody decided on, and fixing it costs far less now than after a user reports it.
The feature spec template has the states table and criteria sections in the order we fill them. The method behind them is on acceptance criteria for frontends. If you would like the criteria for your next feature written with you, that is part of what a Spec Sprint produces.