Skip to content

Web front end (framework-independent)

Scope: any web front end, whatever the framework or build tool, with a focus on accessibility, performance, security, resilience and testing. Framework-specific rules are in React, and the general guidelines still apply, including the test strategy in Testing and delivery. Games that run in the browser are in Web games. Cross-platform accessibility principles and the laws behind them, including the WCAG 2.2 Level AA baseline (A11Y-1), are in Accessibility.

Entries are sorted by score from 1 to 10 (criteria): 9โ€“10 start here or strongly recommended, 6โ€“8 recommended, 1โ€“5 further reading or conditional.

Adopted references

  • 10 Web Content Accessibility Guidelines (WCAG) 2.2 (W3C Recommendation): the baseline for accessibility. Testable success criteria at levels A, AA and AAA.
  • 9 ARIA Authoring Practices Guide (W3C WAI): patterns for custom widgets such as tabs, menus, comboboxes and dialogs, with the roles, states and keyboard support each one needs.
  • 9 Cross Site Scripting Prevention Cheat Sheet (OWASP): the baseline for XSS defences, including output encoding, HTML sanitization, safe sinks and the escape hatches in frameworks.
  • 8 The most effective ways to improve Core Web Vitals (web.dev): the highest-impact fixes for loading, responsiveness and layout stability, in priority order.
  • 8 HTTP Headers Cheat Sheet (OWASP): which security headers to send, with recommended values.
  • 8 Content Security Policy Cheat Sheet (OWASP): how to build, deploy and test a CSP.
  • 8 Best Practices (Playwright): how to write resilient end-to-end tests: test user-visible behaviour, isolate tests, use locators and web-first assertions, debug failures on CI with traces, and test across browsers.
  • 7 Accessibility (MDN): guides and references for accessible HTML, CSS, JavaScript and ARIA.
  • 7 Baseline (web.dev): which web platform features work across the core browsers, as Newly or Widely available.
  • 7 Web Vitals (web.dev): the Core Web Vitals (LCP, INP and CLS), their "good" thresholds and how to measure them.
  • 7 Component Testing (Vitest): testing the components of any framework in a real browser with Browser Mode, including what makes a good component test, user interactions, accessibility and mocking.

Key rules

Accessibility

Performance

Security

Compatibility and resilience

Testing

How to enforce

Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.

  • 7 axe-core rules: automated checks tagged by WCAG version and level, including aria-allowed-role, aria-required-children and nested-interactive for misused ARIA. Run them in end-to-end tests with @axe-core/playwright. Partly checks A11Y-1, WEB-2 and WEB-3.
  • 6 Lighthouse CI: fails CI when lab metrics, resource sizes such as total script bytes, or individual audits such as unsized-images miss your assertions. Lab tests can't measure INP. Partly checks WEB-4, WEB-5 and WEB-6.
  • 6 Size Limit: fails CI when the size or estimated download and run time of your JavaScript, dependencies included, exceeds a budget. Partly checks WEB-5.
  • 6 eslint-plugin-no-unsanitized (Mozilla): flags assignments to innerHTML and calls such as insertAdjacentHTML or document.write that don't go through an escaping function. Partly checks WEB-8.
  • 6 HTTP Observatory CLI (MDN): scans a deployed site and grades its CSP, HSTS, X-Content-Type-Options, framing protection, Referrer-Policy, cookies and Subresource Integrity. Run it against a staging deployment in CI. Checks WEB-9, and partly WEB-10 and WEB-11.
  • 6 @eslint/css use-baseline: flags CSS properties, values, at-rules and selectors outside your Baseline target, unless they're guarded with @supports. Partly checks WEB-12.
  • 6 Playwright failOnFlakyTests: fails the run when a test passes only on retry, so retries can't hide new flakiness. Set it on CI, or pass --fail-on-flaky-tests. Partly checks WEB-18.
  • 6 Mock Service Worker onUnhandledFrame (onUnhandledRequest before MSW 3): set to 'error', it turns every request that no handler covers into an error, so tests can't reach the real network by accident. Partly checks WEB-20.
  • 6 Vitest sequence.shuffle: runs test files and tests in random order, which exposes tests that depend on others having run first. Partly checks WEB-16.
  • 5 eslint-plugin-compat: flags JavaScript web APIs that the browsers in your Browserslist config don't support. Partly checks WEB-12.
  • 5 eslint-plugin-playwright no-wait-for-timeout: the recommended config flags page.waitForTimeout(), and prefer-web-first-assertions flags assertions that don't retry. Turn on no-raw-locators to flag CSS and XPath locators. Partly checks WEB-14 and WEB-15.
  • 5 eslint-plugin-testing-library no-container: flags container.querySelector and other container methods, and no-node-access flags DOM traversal and direct node access instead of queries and user events. Partly checks WEB-14.

Tutorials and further reading

  • 7 Learn Performance (web.dev): a course on web performance concepts and techniques, from resource loading to images, fonts and JavaScript.
  • 7 Learn Accessibility (web.dev): an evergreen course and reference on accessible design and development.
  • 7 Accessibility on the web (MDN Learn): a module on accessible HTML, CSS, JavaScript, WAI-ARIA and testing with assistive technology.
  • 6 Learn Images (web.dev): an in-depth course on image formats, compression and responsive images.
  • 6 Learn Testing (web.dev): a course on testing web apps, from types of tests and where they run to component testing in practice, static analysis and assertions.
  • 6 The Testing Trophy and Testing Classifications (Kent C. Dodds, 2021): the testing trophy, a guide to the return on investment of static analysis, unit, integration and end-to-end tests for JavaScript applications, and how its author classifies them.