Skip to content

Responsive layout standard

This page sets the rules for layouts that work at every screen width, from a phone to a desktop. It is written for engineers who write or review markup, CSS and UI tests. Direction and accessibility rules are in Accessibility and RTL; the area code A11Y covers both pages.

Breakpoints

The UIKit is mobile-first and uses these breakpoints:

Name Minimum width Typical use
sm 640px Large phones in landscape
md 768px Tablets; the phone layout ends below this width
lg 1024px Desktop navigation replaces the menu button
xl 1280px Wide desktop

Write styles for the phone first and add min-width queries for larger screens.

Rules

CS-A11Y-012: Use only the UIKit breakpoints

Severity: minor · Applies to: blazor, template · Enforced by: manual (target: ENF-048) · Status: active

Why

When every page picks its own width, components switch layout at different points and the page looks broken between them. The UIKit components already switch at the breakpoints above, so other values disagree with them.

Do

  • Use 640px, 768px, 1024px and 1280px in media queries, or the Tailwind prefixes sm:, md:, lg: and xl:.
  • Prefer min-width queries.

Don't

  • Introduce other values such as 900px, 641px or 767.98px.

Example

.order-summary {
    display: block;
}

@media (min-width: 768px) {
    .order-summary {
        display: grid;
        grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    }
}

How to check

  • Search the change for @media queries and compare the values with the table.
  • A stylelint rule will report other values (ENF-048).

CS-A11Y-013: Render a control and its explanation in every responsive branch

Severity: major · Applies to: blazor, template · Enforced by: manual · Status: active

Why

Many screens render twice: a table for the desktop and a card list for the phone. A pager, a filter or a "why is this disabled" message that lives in only one branch disappears on the other screen size. A phone list that shows the first page of a server-paged result and simply ends hides the rest of the data.

Do

  • Hold shared text, such as a disabled reason, in one property and render it in both branches.
  • When a list moves from client paging to server paging, check every rendering of that list for a pager and a total.
  • Check the documentation before reporting a missing phone feature: some phone views are reduced on purpose.

Don't

  • Put a pager, a filter or an explanation inside a desktop-only or phone-only container when the consequence exists on both.

How to check

A Playwright test runs the screen at 375px and at 1440px width and asserts the pager, the total and the explanation in both.

CS-A11Y-014: Scope responsive end-to-end locators to visible elements

Severity: minor · Applies to: blazor, template · Enforced by: manual · Status: active

Why

When a control is rendered once per branch with the same data-testid, .First resolves to whichever twin comes first in the DOM. On a desktop run that can be the hidden phone control, and the test waits out its timeout. A test that checks IsVisibleAsync before clicking exits early and passes without doing anything.

Do

  • Scope locators for responsive controls with :visible, for example Locator("[data-testid='orders-next']:visible").
  • Fail the test when the expected control is not visible.

Don't

  • Use .First on a locator that can match a hidden twin.
  • Guard a click with a visibility check that returns silently.

How to check

Review end-to-end locators for controls that exist in both branches.

CS-A11Y-015: Keep a visible close action in phone modals

Severity: minor · Applies to: blazor, template · Enforced by: manual · Status: active

Why

At phone width a modal is a full-screen view, and a footer that holds no primary action may be hidden to save space. A read-only dialog then has no visible way to close unless the header carries one.

Do

  • Give every modal a close button in its header that is visible at every width.
  • In phone tests, close a read-only modal from the header.

Don't

  • Make the footer button the only way to close a modal.

How to check

A Playwright test at 375px width opens each read-only modal and closes it.

CS-A11Y-016: Use only CSS classes that are defined

Severity: minor · Applies to: blazor, template · Enforced by: manual · Status: active

Why

A class that no stylesheet defines fails silently: the element renders with browser defaults, and no build step, console message or test reports it. A class meant for one context (for example a white-on-dark phone chip) used in another renders invisible text.

Do

  • Check each application class in a new page against the stylesheets, for example with a script that extracts the class names and searches the theme file for each.
  • Decide whether a missing class matters by measuring the element with getComputedStyle, not by its name.
  • Use the class that the theme defines for the role, for example the theme's secondary button class beside a primary one.

Don't

  • Invent a class name that sounds right without checking the theme.
  • Use a class outside the context it was written for.

How to check

Run the class check over new Razor pages before review. Tailwind utility classes are checked by the Tailwind build's content scan.

CS-A11Y-017: Keep one theme file and no duplicated selectors

Severity: minor · Applies to: blazor, template · Enforced by: manual · Status: active

Why

When a rule block is pasted twice, the later copy wins. If the two copies differ, the earlier one is dead code that looks alive, and it starts to matter again when someone edits the later one. Styles spread over several global files make this hard to see.

Do

  • Take design tokens from the UIKit.
  • Keep application-wide classes in one theme file per application.
  • Keep component styles in the component's scoped .razor.css file.
  • When a selector must appear twice on purpose (an override inside a media query), add a comment that says so.

Don't

  • Copy a block of rules to edit it in a second place.
  • Add a second global stylesheet for a feature.

How to check

Search the theme file for selectors that appear more than once outside media queries, and confirm each one is intentional.

CS-A11Y-018: Link the scoped CSS bundle in App.razor

Severity: major · Applies to: blazor, template · Enforced by: manual · Status: active

Why

Scoped .razor.css styles of the application and of every referenced Razor class library, including the UIKit, are served in the <AssemblyName>.styles.css bundle. Without that link the kit's scoped rules are missing, and components fall back to unstyled layouts with no error.

Do

  • Link <AssemblyName>.styles.css in the <head> of App.razor.

Don't

  • Remove the link because the application itself has no scoped CSS.

Example

<link rel="stylesheet" href="@Assets["Orders.Shell.styles.css"]" />

How to check

App.razor of every host links its styles.css bundle.

CS-A11Y-019: Keep a component's own display when a breakpoint helper shows it

Severity: minor · Applies to: blazor, template · Enforced by: manual · Status: active

Why

A "show only on phone" helper such as .phone-only { display: block !important; } also overrides a component that needs flex or grid. The markup is correct, so bUnit cannot see the problem; only a real browser at the real width shows a strip of chips laid out as wrapped blocks.

Do

  • Use the Tailwind responsive display utilities (hidden md:flex), which set the display the component needs.
  • When a custom helper class is used, add the component's display beside it inside the same media query.

Don't

  • Add a show-or-hide helper that forces display: block on every element it is applied to.

How to check

A Playwright test at the target width reads getComputedStyle(element).display for the component.

CS-A11Y-021: Keep flex layouts inside the viewport at phone width

Severity: major · Applies to: blazor, template · Enforced by: manual · Status: active

Why

A flex row that does not wrap, or a fixed-size flex item with long content, pushes controls past the edge of a column that clips its overflow, and the controls still count as visible in tests. A pixel flex-basis written for a row becomes a height when a breakpoint turns the row into a column.

Do

  • Give flex rows that render at phone width flex-wrap: wrap.
  • Cap fixed-size flex items with max-width and let their text wrap with overflow-wrap: anywhere.
  • When a media query switches a container to flex-direction: column, reset the items' flex-basis to auto in the same query.

Don't

  • Rely on overflow-x: hidden on the main column to hide overflow.

How to check

A phone-width browser test asserts that each key control's bounding box lies within the viewport and that inputs keep a normal height.

CS-A11Y-022: Take every colour from a theme token

Severity: minor · Applies to: blazor, template · Enforced by: manual · Status: active

Why

A literal colour does not change with the theme. When the text colour follows a token and the background is literal, or the other way round, one theme shows white on white or dark on dark.

Do

  • Use the theme's CSS custom properties for every colour, background and border colour.
  • Add a token to the theme file when no existing token fits, and define it for every theme.

Don't

  • Write hex, rgb() or named colours in component or page CSS.

How to check

Search the change for literal colour values outside the theme file, and check the page in both themes.

CS-A11Y-023: Space sibling controls with CSS, not markup whitespace

Severity: nit · Applies to: blazor, template · Enforced by: manual · Status: active

Why

Razor emits no whitespace after a block such as @if { }, so spacing that depends on whitespace between inline siblings disappears on the rows where the block renders.

Do

  • Put sibling controls in a flex container with gap, or give them a margin from the theme's spacing tokens.

Don't

  • Rely on line breaks or spaces in the markup to separate controls.

How to check

A layout test measures the gap between sibling controls with every conditional control shown.