<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: patrick clancey</title>
    <description>The latest articles on DEV Community by patrick clancey (@patrick_clancey).</description>
    <link>https://dev.to/patrick_clancey</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1694427%2F715e0ef2-0f95-4363-80c1-76b8d91fa34e.jpg</url>
      <title>DEV Community: patrick clancey</title>
      <link>https://dev.to/patrick_clancey</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/patrick_clancey"/>
    <language>en</language>
    <item>
      <title>Demystifying Modern CSS Approaches</title>
      <dc:creator>patrick clancey</dc:creator>
      <pubDate>Thu, 03 Dec 2026 12:53:56 +0000</pubDate>
      <link>https://dev.to/patrick_clancey/demystifying-modern-css-approaches-2cmk</link>
      <guid>https://dev.to/patrick_clancey/demystifying-modern-css-approaches-2cmk</guid>
      <description>&lt;p&gt;There's no shortage of opinions about how CSS should be written. Tailwind or BEM? CSS Modules or CSS-in-JS? Sass, or is native CSS good enough now? The debate can get framed as a choice where you pick one and then have to defend it.&lt;/p&gt;

&lt;p&gt;In practice, these approaches &lt;strong&gt;aren't mutually exclusive&lt;/strong&gt;. Most real projects combine several of them. A typical codebase might have a global stylesheet for resets† and design tokens, a component framework for layout, CSS Modules for the odd tricky component, and a few inline styles for values computed at runtime. A long-lived enterprise site might run Sass with BEM for its core components and gradually adopt native nesting and cascade layers as browser support allows.&lt;/p&gt;

&lt;p&gt;So the useful question isn't "which approach is best?" but "which approach suits &lt;em&gt;this part&lt;/em&gt; of &lt;em&gt;this project&lt;/em&gt;?" This guide walks through the common options, the trade-offs, and where each one fits.&lt;/p&gt;

&lt;h2&gt;
  
  
  Before getting stuck in, let's look at SSR, cached HTML and SPAs
&lt;/h2&gt;

&lt;p&gt;One factor you need to take into account before any CSS comparisons, as it can decide the matter on large sites: &lt;strong&gt;where your HTML lives, and how long it's cached.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Server-rendered sites with cached HTML
&lt;/h3&gt;

&lt;p&gt;Many large sites (CMS-driven sites, e-commerce, publishing, AEM - classic, Drupal, WordPress, the list goes on) render HTML on the server and cache it aggressively at the CDN level (Akamai, Cloudflare, Fastly). These pages may be cached indefinitely, until the content is updated.&lt;/p&gt;

&lt;p&gt;On these sites, there's a big difference in cost between two kinds of change:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Changing a CSS file&lt;/strong&gt; is cheap. You deploy one file and purge one URL, and the change is live in seconds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Changing the HTML&lt;/strong&gt; is expensive. If a shared component like the main menu appears on thousands of pages, changing one class name in its markup means invalidating or regenerating thousands of cached pages. That can mean a slow, risky cache flush, a spike in origin traffic.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So on cached server-rendered sites, approaches where &lt;strong&gt;styling decisions live in the CSS&lt;/strong&gt; and class names stay stable (BEM, Suit CSS, semantic or component names) have a real operational advantage. Approaches where &lt;strong&gt;styling decisions live in the markup&lt;/strong&gt; (utility classes, inline styles, generated class names written into SSR output) turn a visual tweak into a site-wide HTML change.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Single-page applications (SPAs).&lt;/strong&gt; In a client-rendered SPA, the markup ships inside the JavaScript bundle. The HTML document is a near-empty shell, and the bundle is versioned and replaced on every deploy. Changing a class name in a component is just part of the next build. The caching cost described above largely disappears, which is one reason utility-first and CSS-in-JS approaches thrive in SPA-heavy ecosystems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hybrid frameworks (Next, Nuxt, SvelteKit, Astro).&lt;/strong&gt; These sit in between. A statically generated or server-rendered page cached at the edge behaves like the first case; a client-side navigation behaves like the second. If your pages are cached for long periods, assume the server-rendered rules apply.&lt;/p&gt;

&lt;p&gt;Keep this in mind as you read each section. The same approach can be the right call for a SPA and the wrong one for a 50,000-page cached marketing site.&lt;/p&gt;

&lt;h2&gt;
  
  
  Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Vanilla CSS&lt;/li&gt;
&lt;li&gt;BEM and naming methodologies&lt;/li&gt;
&lt;li&gt;Preprocessors: Sass and Less&lt;/li&gt;
&lt;li&gt;CSS Modules&lt;/li&gt;
&lt;li&gt;Scoped component styles&lt;/li&gt;
&lt;li&gt;Utility-first CSS&lt;/li&gt;
&lt;li&gt;Runtime CSS-in-JS&lt;/li&gt;
&lt;li&gt;Zero-runtime CSS-in-JS&lt;/li&gt;
&lt;li&gt;Inline styles&lt;/li&gt;
&lt;li&gt;Shadow DOM and Web Components&lt;/li&gt;
&lt;li&gt;Component frameworks&lt;/li&gt;
&lt;li&gt;Wrapping up&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Vanilla CSS
&lt;/h2&gt;

&lt;p&gt;Plain stylesheets, written by hand and linked from the page. Every selector is global, and the cascade and specificity decide which rule wins.&lt;/p&gt;

&lt;p&gt;Vanilla CSS has changed a lot in recent years. Features that once required a preprocessor or a JavaScript library are now native: &lt;strong&gt;nesting&lt;/strong&gt;, &lt;strong&gt;custom properties&lt;/strong&gt; (CSS variables) for theming and design tokens, &lt;strong&gt;cascade layers&lt;/strong&gt; (&lt;code&gt;@layer&lt;/code&gt;) for controlling specificity between resets, frameworks and your own code, &lt;strong&gt;&lt;code&gt;@scope&lt;/code&gt;&lt;/strong&gt; for limiting where selectors apply, &lt;strong&gt;container queries&lt;/strong&gt; for component-level responsiveness, and &lt;strong&gt;&lt;code&gt;:has()&lt;/code&gt;&lt;/strong&gt; for parent selection. For many projects, the gap between "plain CSS" and a CSS preprocessing tool is now quite small.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* styles.css */&lt;/span&gt;
&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"styles.css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pros&lt;/th&gt;
&lt;th&gt;Cons&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt; No build step or dependencies&lt;/li&gt;
&lt;li&gt; Fastest for the browser to parse; no runtime cost &lt;/li&gt;
&lt;li&gt; Universally understood by every developer &lt;/li&gt;
&lt;li&gt; Modern features (nesting, layers, &lt;code&gt;@scope&lt;/code&gt;, variables) close most old gaps&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt; Global scope means naming collisions as the codebase grows&lt;/li&gt;
&lt;li&gt; Nothing enforces structure, so it can drift into chaos &lt;/li&gt;
&lt;li&gt; Dead CSS is hard to detect and remove safely&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;A great fit for small sites, prototypes, static pages and documentation, and as the foundation layer of any project (resets, tokens, base typography). It's also a strong choice for &lt;strong&gt;cached server-rendered sites&lt;/strong&gt;, since class names stay stable and restyling ships in the CSS file alone.&lt;/p&gt;

&lt;p&gt;One caching caveat: if you use fingerprinted filenames (&lt;code&gt;styles.a1b2c3.css&lt;/code&gt;) for cache-busting, the new filename is written into the HTML, so every CSS release forces an HTML purge anyway. On heavily cached sites, consider a stable CSS URL with a shorter TTL, or a targeted CDN purge of just the stylesheet.&lt;/p&gt;

&lt;p&gt;On its own, vanilla CSS scales poorly without conventions. That's why it's usually paired with a methodology such as BEM, which is next.&lt;/p&gt;




&lt;h2&gt;
  
  
  BEM and naming methodologies
&lt;/h2&gt;

&lt;p&gt;BEM (Block, Element, Modifier) isn't a tool; it's a naming convention layered on top of plain CSS or Sass. A &lt;strong&gt;block&lt;/strong&gt; is a standalone component (&lt;code&gt;.card&lt;/code&gt;), an &lt;strong&gt;element&lt;/strong&gt; is a part of it (&lt;code&gt;.card__title&lt;/code&gt;), and a &lt;strong&gt;modifier&lt;/strong&gt; is a variation (&lt;code&gt;.card--featured&lt;/code&gt;). Related methodologies include SMACSS, OOCSS, SUIT CSS and ITCSS (which is more about file organisation and layering).&lt;/p&gt;

&lt;p&gt;The goal is to simulate component scoping through discipline: class names are unique by convention, every selector is a single class (so specificity stays flat and predictable), and you can tell from the HTML alone which CSS applies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.page-title--alert&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"page-title page-title--alert"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pros&lt;/th&gt;
&lt;th&gt;Cons&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt; Predictable, self-documenting class names&lt;/li&gt;
&lt;li&gt; Flat, low specificity; few override battles&lt;/li&gt;
&lt;li&gt; No tooling required; works anywhere&lt;/li&gt;
&lt;li&gt; Stable class names make a clean contract between markup and CSS&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt; Verbose class names&lt;/li&gt;
&lt;li&gt; Relies entirely on team discipline&lt;/li&gt;
&lt;li&gt; Nothing enforces the rules; inconsistency creeps in&lt;/li&gt;
&lt;li&gt; Naming things is still hard&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;The best fit for &lt;strong&gt;large server-rendered sites with heavily cached HTML&lt;/strong&gt;: CMS-driven builds, AEM component libraries, e-commerce and publishing. Because class names are a stable contract, restyling a menu used on thousands of pages is a single CSS deploy rather than a site-wide cache flush. Markup and styling can also be owned by different teams (for example, CMS authors and back-end developers producing HTML, front-end developers owning CSS) with the class names as the agreed interface.&lt;/p&gt;

&lt;p&gt;BEM pairs naturally with Sass, where the &lt;code&gt;&amp;amp;__element&lt;/code&gt; and &lt;code&gt;&amp;amp;--modifier&lt;/code&gt; syntax keeps source files tidy. It's less valuable in component frameworks with built-in scoping, where the tool already solves the problem BEM exists for.&lt;/p&gt;




&lt;h2&gt;
  
  
  Preprocessors: Sass and Less
&lt;/h2&gt;

&lt;p&gt;A preprocessor is a CSS superset compiled to plain CSS at build time. Sass (usually in its SCSS syntax) is by far the most popular today; Less is still found in older codebases and Bootstrap 3-era projects.&lt;/p&gt;

&lt;p&gt;Preprocessors add variables, nesting, &lt;strong&gt;mixins&lt;/strong&gt; (reusable chunks of declarations), &lt;strong&gt;functions&lt;/strong&gt; and maths, &lt;strong&gt;loops&lt;/strong&gt; for generating utility classes, and &lt;strong&gt;partials&lt;/strong&gt; with imports for splitting styles across files. Modern Sass uses a module system (&lt;code&gt;@use&lt;/code&gt; and &lt;code&gt;@forward&lt;/code&gt;) that replaces the old global &lt;code&gt;@import&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Some of these features are now native in CSS (nesting, variables), but Sass still offers things CSS doesn't: mixins, loops, maps, and compile-time logic for generating design-system output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="nv"&gt;$title-colours&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nt"&gt;red&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nn"&gt;#c00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nt"&gt;green&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nn"&gt;#080&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nt"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nn"&gt;#00c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;@each&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="nt"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;$title-colours&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;.title-&lt;/span&gt;&lt;span class="nn"&gt;#&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"title-red"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pros&lt;/th&gt;
&lt;th&gt;Cons&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt; Mature, stable and widely known&lt;/li&gt;
&lt;li&gt; Mixins, functions and loops reduce repetition&lt;/li&gt;
&lt;li&gt; Excellent for generating design-system output&lt;/li&gt;
&lt;li&gt; Easy migration path: any CSS is valid SCSS&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt; Requires a build step&lt;/li&gt;
&lt;li&gt; Output is still global, so it needs a naming convention&lt;/li&gt;
&lt;li&gt; Some features now duplicate native CSS&lt;/li&gt;
&lt;li&gt; Deep nesting encourages over-specific selectors&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;A good fit for large traditional sites, design systems and enterprise codebases, particularly in combination with BEM. Caching behaviour is the same as vanilla CSS: the output is a stylesheet, so refactors and variable changes don't touch the cached HTML as long as the output class names stay stable.&lt;/p&gt;

&lt;p&gt;For new projects, it's worth asking whether native CSS now covers what you need. If you're only using variables and nesting, it probably does. If you're generating spacing scales, colour palettes or utility classes from maps and loops, Sass still earns its place.&lt;/p&gt;




&lt;h2&gt;
  
  
  CSS Modules
&lt;/h2&gt;

&lt;p&gt;CSS Modules are ordinary &lt;code&gt;.css&lt;/code&gt; (or &lt;code&gt;.scss&lt;/code&gt;) files that a bundler such as Vite or webpack processes so that every class name is &lt;strong&gt;locally scoped&lt;/strong&gt; by default. You import the file into a JavaScript component and get back an object mapping your class names to generated unique names. Two components can both define &lt;code&gt;.title&lt;/code&gt; without colliding.&lt;/p&gt;

&lt;p&gt;You still write standard CSS. There's no new syntax to learn beyond &lt;code&gt;composes&lt;/code&gt; for sharing styles and &lt;code&gt;:global&lt;/code&gt; for opting out of scoping.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* title.module.css */&lt;/span&gt;
&lt;span class="nc"&gt;.title&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'./title.module.css'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt; &lt;span class="n"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Hello&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Rendered HTML --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"title_x7f3a"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pros&lt;/th&gt;
&lt;th&gt;Cons&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt; True local scope without naming conventions&lt;/li&gt;
&lt;li&gt; Plain CSS syntax; works with Sass&lt;/li&gt;
&lt;li&gt; Zero runtime cost; styles extracted to static files &lt;/li&gt;
&lt;li&gt; Supported out of the box by Vite, Next and most bundlers&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt; Requires bundler support&lt;/li&gt;
&lt;li&gt; Theming and shared styles are clunkier&lt;/li&gt;
&lt;li&gt; &lt;code&gt;:global&lt;/code&gt; escapes undermine the scoping&lt;/li&gt;
&lt;li&gt; Generated class names are hard to target from outside (e.g. CMS or tests)&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;A strong fit for React and Next apps that want scoping without adopting a new paradigm. It's also a good migration path from a global Sass codebase, since the CSS barely changes.&lt;/p&gt;

&lt;p&gt;Caching: in webpack and Next.js, generated class names are derived from the file path and class name, not the CSS content, so editing styles leaves cached HTML valid. Vite’s default also hashes the file’s content, so any edit renames its classes. Set css.modules.generateScopedName to a path-based pattern if that matters to you. In every setup, renaming a class, moving a file or changing the hash configuration renames that class in every cached page. In an SPA that's irrelevant; in statically generated or SSR output behind long-lived caches, treat file moves and renames as HTML-affecting changes.&lt;/p&gt;




&lt;h2&gt;
  
  
  Scoped component styles
&lt;/h2&gt;

&lt;p&gt;Vue, Svelte and Angular all let you write CSS directly inside a component file, and the framework compiles it so the styles apply only to that component. Vue uses &lt;code&gt;&amp;lt;style scoped&amp;gt;&lt;/code&gt;, Svelte scopes styles by default, and Angular uses view encapsulation.&lt;/p&gt;

&lt;p&gt;Under the hood, the compiler adds a unique attribute or class to the component's elements (for example, &lt;code&gt;data-v-4f2a1c&lt;/code&gt; in Vue) and rewrites your selectors to match it. You write ordinary CSS, co-located with the markup that uses it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Vue single-file component --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;style&lt;/span&gt; &lt;span class="na"&gt;scoped&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Rendered output --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;data-v-4f2a1c&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;data-v-4f2a1c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pros&lt;/th&gt;
&lt;th&gt;Cons&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt; Styles live next to the markup they affect&lt;/li&gt;
&lt;li&gt; Real CSS, scoped by default&lt;/li&gt;
&lt;li&gt; No runtime cost; extracted at build time&lt;/li&gt;
&lt;li&gt; Removing a component removes its styles&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt; Tied to a specific framework&lt;/li&gt;
&lt;li&gt; Styling child components needs special selectors (&lt;code&gt;:deep()&lt;/code&gt;, &lt;code&gt;:global&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt; Attribute selectors slightly raise specificity&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;The natural default for Vue/Nuxt, Svelte/SvelteKit and Angular projects. It solves scoping and dead-code problems with very little ceremony.&lt;/p&gt;

&lt;p&gt;Caching: the scope identifiers are written into the rendered HTML, and in some frameworks they &lt;strong&gt;can change when the component file changes&lt;/strong&gt; (Vue, for example, includes the file's contents in its production hash). On a client-rendered SPA this doesn't matter. On a Nuxt or SvelteKit site serving long-cached SSR or statically generated pages, editing a shared component may mean regenerating every page that uses it. Worth checking how your framework generates its scope IDs before relying on CSS-only deploys.&lt;/p&gt;




&lt;h2&gt;
  
  
  Utility-first CSS
&lt;/h2&gt;

&lt;p&gt;Utility-first frameworks such as &lt;strong&gt;Tailwind CSS&lt;/strong&gt; and &lt;strong&gt;UnoCSS&lt;/strong&gt; provide a large set of small, single-purpose classes (&lt;code&gt;text-red-600&lt;/code&gt;, &lt;code&gt;p-4&lt;/code&gt;, &lt;code&gt;flex&lt;/code&gt;, &lt;code&gt;md:grid-cols-3&lt;/code&gt;), and you compose them directly in your markup. You rarely write custom CSS at all.&lt;/p&gt;

&lt;p&gt;At build time, the tool scans your templates and generates only the classes you actually use, so the production stylesheet is typically small. Design tokens (colours, spacing, breakpoints) are defined once in configuration, which keeps the UI consistent. Tailwind v4 moved that configuration into CSS itself using &lt;code&gt;@theme&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"text-red-600"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* Generated CSS */&lt;/span&gt;
&lt;span class="nc"&gt;.text-red-600&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;220&lt;/span&gt; &lt;span class="mi"&gt;38&lt;/span&gt; &lt;span class="mi"&gt;38&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pros&lt;/th&gt;
&lt;th&gt;Cons&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt; Very fast to build UI&lt;/li&gt;
&lt;li&gt; Consistent design tokens enforced by default&lt;/li&gt;
&lt;li&gt; Tiny production CSS; it stops growing as the app grows&lt;/li&gt;
&lt;li&gt; No naming decisions; no dead CSS&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt; Noisy, hard-to-scan markup&lt;/li&gt;
&lt;li&gt; Learning curve for the class vocabulary&lt;/li&gt;
&lt;li&gt; Overrides and variants can get awkward&lt;/li&gt;
&lt;li&gt; Ties markup to the framework; hard to migrate away&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;An excellent fit for product UIs, SPAs, startups, rapid prototyping, and teams working from an established design system. In component-based apps, the "noisy markup" complaint is softened because the classes live inside a reusable component rather than being repeated across pages.&lt;/p&gt;

&lt;p&gt;Caching: this is the &lt;strong&gt;most expensive approach for large cached server-rendered sites&lt;/strong&gt;. Styling lives in the markup, so changing how the menu looks means changing the classes in the HTML, which invalidates every cached page that contains the menu. The rebuilt CSS also needs to deploy in step with the HTML, because newly used classes won't exist in the old stylesheet. In an SPA, where the markup ships in the JS bundle, this is a non-issue.&lt;/p&gt;

&lt;p&gt;Accessibility note: because styling is applied per element, it's easy to forget focus styles, &lt;code&gt;prefers-reduced-motion&lt;/code&gt; variants and forced-colours support. Bake them into your shared components rather than relying on developers remembering the right utility each time.&lt;/p&gt;

&lt;p&gt;Reset note: Tailwind ships with &lt;strong&gt;Preflight&lt;/strong&gt;, a fairly aggressive base reset that removes heading sizes, list styles and margins from every element. That's convenient in a fully componentised app, but it catches people out with CMS or Markdown content, which then needs the typography plugin (&lt;code&gt;prose&lt;/code&gt;) to get readable defaults back. See A note on CSS resets for the alternative of resetting only what you style.&lt;/p&gt;




&lt;h2&gt;
  
  
  Runtime CSS-in-JS
&lt;/h2&gt;

&lt;p&gt;Libraries such as &lt;strong&gt;styled-components&lt;/strong&gt; and &lt;strong&gt;Emotion&lt;/strong&gt; let you write CSS inside JavaScript, usually as tagged template literals or style objects. The library generates a unique class name, injects the CSS into the page at runtime, and attaches the class to your component.&lt;/p&gt;

&lt;p&gt;Because styles are JavaScript, they have full access to props, state and theme objects. This made CSS-in-JS very popular in the React ecosystem in the late 2010s. The trade-off is that style generation happens in the browser (or on the server during SSR), which adds runtime cost and complicates server rendering. React Server Components don't support this model well, and styled-components entered maintenance mode in 2025.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;H1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="sb"&gt;`
  color: red;
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;H1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Hello&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="no"&gt;H1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Rendered HTML and injected CSS --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"sc-a1b2c3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
&lt;span class="nc"&gt;.sc-a1b2c3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pros&lt;/th&gt;
&lt;th&gt;Cons&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt; Dynamic, prop-driven styling&lt;/li&gt;
&lt;li&gt; Styles co-located with components&lt;/li&gt;
&lt;li&gt; Automatic scoping and dead-code removal&lt;/li&gt;
&lt;li&gt; Easy, powerful theming&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt; Runtime performance cost&lt;/li&gt;
&lt;li&gt; Poor fit with React Server Components&lt;/li&gt;
&lt;li&gt; Larger JavaScript bundles&lt;/li&gt;
&lt;li&gt; styled-components now in maintenance mode&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;Best suited to existing React SPAs that already use it. For new projects, zero-runtime alternatives (next section) or CSS Modules are generally a better choice.&lt;/p&gt;

&lt;p&gt;Caching: with SSR, the generated class names and critical CSS are &lt;strong&gt;inlined into each page's HTML&lt;/strong&gt;, so any style change alters the cached HTML site-wide. In a client-rendered SPA this is acceptable; for large cached server-rendered sites it's a poor fit.&lt;/p&gt;




&lt;h2&gt;
  
  
  Zero-runtime CSS-in-JS
&lt;/h2&gt;

&lt;p&gt;Tools such as &lt;strong&gt;vanilla-extract&lt;/strong&gt;, &lt;strong&gt;Linaria&lt;/strong&gt;, &lt;strong&gt;Panda CSS&lt;/strong&gt; and Meta's &lt;strong&gt;StyleX&lt;/strong&gt; keep the developer experience of writing styles in TypeScript or JavaScript, but &lt;strong&gt;extract static CSS at build time&lt;/strong&gt;. Nothing is generated in the browser.&lt;/p&gt;

&lt;p&gt;The biggest benefit is type safety: design tokens become typed objects, so a typo in a colour name is a compile error rather than a silent bug. Dynamic styling is handled through CSS custom properties rather than generating new CSS at runtime.&lt;/p&gt;

&lt;p&gt;There are two flavours worth distinguishing. &lt;strong&gt;Scoped-class&lt;/strong&gt; tools (vanilla-extract, Linaria) produce one class per style block, much like CSS Modules. &lt;strong&gt;Atomic&lt;/strong&gt; tools (StyleX, and Panda in atomic mode) produce one class per declaration, much like Tailwind.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// title.css.ts (vanilla-extract)&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@vanilla-extract/css'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;style&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'red'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt; &lt;span class="n"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Hello&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Extracted CSS and rendered HTML --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
&lt;span class="nc"&gt;.title_1x2y3z&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"title_1x2y3z"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pros&lt;/th&gt;
&lt;th&gt;Cons&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt; Type-safe design tokens&lt;/li&gt;
&lt;li&gt; No runtime cost&lt;/li&gt;
&lt;li&gt; Compatible with React Server Components&lt;/li&gt;
&lt;li&gt; Scoped by default &lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt; More build configuration&lt;/li&gt;
&lt;li&gt; Dynamic styling limited to CSS variables&lt;/li&gt;
&lt;li&gt; Smaller ecosystems and communities&lt;/li&gt;
&lt;li&gt; Debugging generated output can be harder &lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;A good fit for typed design systems, large React or Next apps, and performance-sensitive builds where you want CSS-in-JS ergonomics without the runtime.&lt;/p&gt;

&lt;p&gt;Caching depends on the flavour. &lt;strong&gt;Scoped-class&lt;/strong&gt; tools generally keep class names stable when you edit style values, so changes ship in the CSS file. &lt;strong&gt;Atomic&lt;/strong&gt; tools behave like Tailwind: changing a value changes the class names in the markup, so cached HTML must be regenerated.&lt;/p&gt;




&lt;h2&gt;
  
  
  Inline styles
&lt;/h2&gt;

&lt;p&gt;Styles applied directly to an element through the &lt;code&gt;style&lt;/code&gt; attribute in HTML, or the &lt;code&gt;style&lt;/code&gt; prop in a framework. There's no stylesheet and no selector; the declaration applies only to that element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"color: red;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pros&lt;/th&gt;
&lt;th&gt;Cons&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt; Immediate; no tooling or files&lt;/li&gt;
&lt;li&gt; Ideal for one-off values computed at runtime&lt;/li&gt;
&lt;li&gt; Guaranteed to apply to exactly that element&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt; No media queries, pseudo-classes or pseudo-elements&lt;/li&gt;
&lt;li&gt; No reuse; repeated everywhere&lt;/li&gt;
&lt;li&gt; Very high specificity; hard to override&lt;/li&gt;
&lt;li&gt; Blocked by strict Content Security Policies unless allowed &lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;Inline styles have a few legitimate uses:&lt;/p&gt;

&lt;p&gt;For anything shared, avoid them. On cached sites, every visual change is an HTML change, so a tweak to a shared component means invalidating every page that contains it.&lt;/p&gt;




&lt;h2&gt;
  
  
  Shadow DOM and Web Components
&lt;/h2&gt;

&lt;p&gt;Web Components are native browser custom elements. When a component uses a shadow root, its internal markup and styles are encapsulated: page selectors can’t reach elements inside it, and component styles can’t leak out. It’s the only approach on this list with browser-enforced selector isolation in both directions.&lt;/p&gt;

&lt;p&gt;The boundary isn't completely sealed, though. Inherited properties such as color and font-family flow in from the host element, so components pick up the page's base typography unless they reset it with &lt;code&gt;:host { all: initial; }&lt;/code&gt;. Custom properties pass through the same way, which makes them the main theming mechanism, and &lt;code&gt;::part()&lt;/code&gt; lets a component expose specific internal elements for external styling. Slotted content stays in the page's DOM, so page styles apply to it as normal. Libraries such as Lit make authoring Web Components much more ergonomic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyTitle&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;HTMLElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kc"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;attachShadow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'open'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`
      &amp;lt;style&amp;gt;
        :host { display: block; }
        h1 { color: red; }
      &amp;lt;/style&amp;gt;
      &amp;lt;h1&amp;gt;&amp;lt;slot&amp;gt;&amp;lt;/slot&amp;gt;&amp;lt;/h1&amp;gt;
    `&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;customElements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'my-title'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;MyTitle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;my-title&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/my-title&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pros&lt;/th&gt;
&lt;th&gt;Cons&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt;Selector isolation in both directions&lt;/li&gt;
&lt;li&gt; Framework-agnostic; works anywhere HTML does&lt;/li&gt;
&lt;li&gt; Native browser standard; no build step required &lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt;Theming limited to inherited properties, custom properties and &lt;code&gt;::part&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; SSR is possible (declarative shadow DOM) but tooling is less mature&lt;/li&gt;
&lt;li&gt;Global resets and element styles don’t reach inside (inherited typography does)&lt;/li&gt;
&lt;li&gt; Accessibility across shadow boundaries can be tricky (e.g. ARIA ID references)&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;A good fit for embeddable widgets, components that must work across several frameworks, and design systems shared between teams using different stacks. It's less suited as the main styling approach for a single-framework application.&lt;/p&gt;

&lt;p&gt;Caching: with declarative shadow DOM (server-rendered), styles are often inlined into each page, so changes require regenerating the cached HTML. Linking an external stylesheet from inside the shadow root avoids this.&lt;/p&gt;

&lt;p&gt;Accessibility note: ARIA attributes that reference IDs (&lt;code&gt;aria-labelledby&lt;/code&gt;, &lt;code&gt;aria-describedby&lt;/code&gt;) can't cross the shadow boundary, so labelling relationships between page content and component internals need careful design.&lt;/p&gt;




&lt;h2&gt;
  
  
  Component frameworks
&lt;/h2&gt;

&lt;p&gt;Prebuilt CSS frameworks such as &lt;strong&gt;Bootstrap&lt;/strong&gt;, &lt;strong&gt;Bulma&lt;/strong&gt; and &lt;strong&gt;Foundation&lt;/strong&gt; ship a complete stylesheet of components (buttons, cards, navbars, modals) and utility classes. You apply them by adding classes to your markup and customise them through variables or overrides.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* Provided by Bootstrap */&lt;/span&gt;
&lt;span class="nc"&gt;.text-danger&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;--bs-danger&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;important&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"bootstrap.min.css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"text-danger"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pros&lt;/th&gt;
&lt;th&gt;Cons&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt;Very quick to get started&lt;/li&gt;
&lt;li&gt;Consistent, well-documented components&lt;/li&gt;
&lt;li&gt;Reasonable accessibility baselines out of the box&lt;/li&gt;
&lt;li&gt;Large community and ecosystem &lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt;Generic look unless heavily customised&lt;/li&gt;
&lt;li&gt;Heavy if you only use a fraction of it&lt;/li&gt;
&lt;li&gt;Overrides fight the framework’s specificity&lt;/li&gt;
&lt;li&gt;Major-version upgrades can be painful&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;A good fit for admin panels, internal tools, MVPs and projects where speed matters more than a distinctive design.&lt;/p&gt;

&lt;p&gt;Caching: theme tweaks through variables or overrides only change the CSS file, which is cheap. Major-version upgrades that rename classes (for example, Bootstrap 4's &lt;code&gt;ml-*&lt;/code&gt; becoming &lt;code&gt;ms-*&lt;/code&gt; in Bootstrap 5) touch the markup and therefore every cached page. Plan upgrades accordingly.&lt;/p&gt;

&lt;p&gt;Accessibility note: framework components give you a reasonable starting point, but "accessible baselines" isn't the same as accessible. Customisations, colour overrides and how components are assembled still need testing.&lt;/p&gt;




&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;There's no single right way to write CSS, and most mature projects end up with a combination. A few principles help when choosing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Start with where your HTML lives.&lt;/strong&gt; On large server-rendered sites with cached HTML, prefer approaches where restyling changes only the CSS file and class names stay stable. In SPAs, that constraint mostly disappears, and component-scoped or utility-first approaches become more attractive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use the platform first.&lt;/strong&gt; Native CSS now covers nesting, variables, layers, scoping and container queries. Add tooling for what it genuinely adds, not out of habit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep browser defaults unless you're replacing them.&lt;/strong&gt; Reset only the elements you're actually going to style, rather than stripping everything globally and hoping every element gets restyled.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Match the approach to the layer.&lt;/strong&gt; Global CSS for a light base and tokens, a scoped or utility approach for components, inline custom properties for runtime values. Mixing approaches deliberately is fine; mixing them accidentally is how codebases get messy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bake accessibility into the shared pieces.&lt;/strong&gt; Whatever the approach, focus styles, &lt;code&gt;prefers-reduced-motion&lt;/code&gt;, forced-colours support and sufficient contrast should live in shared components and tokens, so they aren't left to each developer to remember.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The best choice is the one your team can apply consistently, that suits how your pages are rendered and cached, and that you'll still be comfortable maintaining in five years.&lt;/p&gt;




&lt;h3&gt;
  
  
  † A note on CSS resets
&lt;/h3&gt;

&lt;p&gt;Since the foundation layer often starts with a reset, I'll come clean and say I'm not a fan of aggressive CSS resets. Blanket rules like &lt;code&gt;* { margin: 0; padding: 0; }&lt;/code&gt;, or full resets that strip list bullets, heading sizes and form control styling from every element, meaning anything without specific styles renders as unformatted text, often without any space or gaps.&lt;/p&gt;

&lt;p&gt;I'd much rather have the browser's default styles than no styles at all! Browser defaults are readable, familiar and carry useful visual cues: headings look like headings, lists have bullets, links are underlined, buttons look like buttons, hover and focus outlines are visible. That matters most for content you don't fully control, such as rich text from a CMS editor, Markdown output or third-party embeds.&lt;/p&gt;

&lt;p&gt;There are accessibility considerations. Removing list styling with &lt;code&gt;list-style: none&lt;/code&gt; can cause Safari/VoiceOver to stop announcing the element as a list, and resets that include &lt;code&gt;outline: none&lt;/code&gt; remove the focus indicator keyboard users rely on.&lt;/p&gt;

&lt;p&gt;So my recommendation is to &lt;strong&gt;only reset the elements you are going to style&lt;/strong&gt;, and add the base styles you want in the same location so the reset and the default value are easy to find. &lt;/p&gt;

</description>
      <category>css</category>
      <category>frontend</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Unlocking Hidden Content: An Introduction to hidden='until-found'</title>
      <dc:creator>patrick clancey</dc:creator>
      <pubDate>Wed, 10 Sep 2025 11:00:36 +0000</pubDate>
      <link>https://dev.to/patrick_clancey/unlocking-hidden-content-an-introduction-to-hiddenuntil-found-1mpa</link>
      <guid>https://dev.to/patrick_clancey/unlocking-hidden-content-an-introduction-to-hiddenuntil-found-1mpa</guid>
      <description>&lt;p&gt;The value &lt;code&gt;'until-found'&lt;/code&gt; for the &lt;code&gt;hidden&lt;/code&gt; HTML attribute is supported by Chrome and Firefox at the time of writing. Also, support has been added to Safari TP and is expected to land this year.&lt;/p&gt;

&lt;p&gt;Before we look at the &lt;code&gt;'until-found'&lt;/code&gt; value specifically, let's quickly recap what the &lt;code&gt;hidden&lt;/code&gt; attribute does when it's added to an HTML element. This attribute tells the browser that the element's contents are not currently relevant and should not be presented to the user. Commonly, the browser will then apply the CSS style &lt;code&gt;display: none&lt;/code&gt;, totally hiding the element. In contrast, when &lt;code&gt;hidden='until-found'&lt;/code&gt; is applied, this tells the browser that the contents are relevant, but should not be visible initially.  Despite being visually hidden, its content remains discoverable by the browser (although not in the DOM and not in the accessibility tree). So, the browser's "Find in Page" and deep linking functionality will still work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;hidden&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Hello, I'm totally hidden and cannot be found.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;hidden=&lt;/span&gt;&lt;span class="s"&gt;"until-found"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Hello, I'm invisible, but can still be found!&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a user searches for and finds text within such an element, the browser automatically reveals it and scrolls it into view. This feature improves initial page load times by deferring content rendering while maintaining a seamless search experience. It's ideal for progressively disclosing content like collapsible sections that users might search for.&lt;/p&gt;

&lt;p&gt;In a nutshell, content within an element that has the hidden attribute (or CSS &lt;code&gt;display: none&lt;/code&gt;) will not be found by the browser and cannot be deep linked to. Whereas content within an element with &lt;code&gt;hidden='until-found'&lt;/code&gt; is discoverable and can be linked to.&lt;/p&gt;

&lt;h2&gt;
  
  
  Interactive Components
&lt;/h2&gt;

&lt;p&gt;Hidden content is a fundamental feature of interactive components such as accordions, carousels, and tabbed interfaces. These popular UI patterns offer several advantages including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Space Optimisation&lt;/strong&gt;: Simply stacking all content vertically can lead to extremely long, overwhelming pages that require excessive scrolling, making them hard to navigate and boring. These components allow you to condense content by showing only a portion of it at a time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Well-Structured Content&lt;/strong&gt;: Monolithic blocks of text or images can be difficult for users to scan, understand, and navigate. Key information might get lost. Grouping related information into a collapsible section helps provide a clear, logical structure for content, making it easier for users to find what they're looking for.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enhanced User Experience&lt;/strong&gt;: Long, static pages can be boring and increase cognitive load, which can lead to user fatigue or abandonment. Interactive components and progressive disclosure make the page feel more dynamic, less daunting, and quite frankly, more 'fun'.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Aesthetic Appeal&lt;/strong&gt;: These components contribute to a cleaner aesthetic. They can make a page look less cluttered and more professional.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  The Problem
&lt;/h1&gt;

&lt;p&gt;Let's take a look at what problems &lt;code&gt;hidden='until-found'&lt;/code&gt; solves. &lt;/p&gt;

&lt;p&gt;Despite the benefits of interactive components, traditional hidden content presents a significant accessibility challenge, it's simply not discoverable by browsers.&lt;/p&gt;

&lt;p&gt;This invisibility creates a disproportionate burden for several user groups. For example, visually impaired users, who often rely on screen readers and the browser's "Find in Page" functionality, are particularly affected. &lt;/p&gt;

&lt;p&gt;Similarly, users with motor control issues face additional obstacles when navigating interactive components that hide content.&lt;/p&gt;

&lt;p&gt;When content is hidden using conventional methods, search functions cannot locate relevant information severely limiting these users' ability to find what they need.&lt;/p&gt;

&lt;p&gt;These limitations create a fundamental tension: the very components designed to improve user experience for some can simultaneously erect barriers for others. This is precisely the problem that &lt;code&gt;hidden='until-found'&lt;/code&gt; was designed to solve.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation Example
&lt;/h2&gt;

&lt;p&gt;In the following tabbed component example, which is implemented using &lt;code&gt;hidden='until-found'&lt;/code&gt;, we can see how content becomes both searchable and linkable.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/clanceyp/embed/bNVZjVJ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Developer notes
&lt;/h2&gt;

&lt;p&gt;In the above example, instead of using a classname (commonly using the CSS &lt;code&gt;display: none&lt;/code&gt; property), we are using the &lt;code&gt;hidden='until-found'&lt;/code&gt; attribute. When content is 'found' by the browser, it dispatches a JavaScript event called &lt;code&gt;beforematch&lt;/code&gt;, and the content is shown. In the case of a tab component, we can't have two tabs visible at the same time, so we listen for the &lt;code&gt;beforematch&lt;/code&gt; event, and when it fires, we need to manually hide whichever tab is not required.&lt;/p&gt;

&lt;p&gt;There is one obvious difference between &lt;code&gt;hidden&lt;/code&gt; and &lt;code&gt;hidden='until-found'&lt;/code&gt; any block-level styles on the element like border or padding won't be visible when the &lt;code&gt;hidden&lt;/code&gt; attribute is used, but WILL be when &lt;code&gt;hidden='until-found'&lt;/code&gt; is applied. This is because the browser will typically only hide the element's contents and not the element itself. Not a big deal, but still something to bear in mind if you are going to be working with an existing codebase.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further Reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://caniuse.com/?search=hidden%3Duntil-found" rel="noopener noreferrer"&gt;Can I Use | hidden until-found&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.chrome.com/docs/css-ui/hidden-until-found" rel="noopener noreferrer"&gt;Making collapsed content accessible with hidden=until-found&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/hidden" rel="noopener noreferrer"&gt;HTML hidden global attribute&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://css-tricks.com/covering-hiddenuntil-found/" rel="noopener noreferrer"&gt;Covering hidden=until-found&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://drafts.csswg.org/css-pseudo-4/#selectordef-search-text" rel="noopener noreferrer"&gt;CSS Pseudo-Elements Module Level 4 ::search-text selector&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>html</category>
      <category>wcag</category>
      <category>a11y</category>
      <category>css</category>
    </item>
    <item>
      <title>WCAG: Empty Links</title>
      <dc:creator>patrick clancey</dc:creator>
      <pubDate>Thu, 17 Apr 2025 11:40:53 +0000</pubDate>
      <link>https://dev.to/patrick_clancey/wcag-empty-links-4e86</link>
      <guid>https://dev.to/patrick_clancey/wcag-empty-links-4e86</guid>
      <description>&lt;p&gt;The European Union has implemented new accessibility regulations with a compliance deadline of June 28th, 2025. Many companies are proactively taking steps to meet these standards to avoid penalties and ensure their digital platforms are accessible to all users.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.eumonitor.eu/9353000/1/j9vvik7m1c3gyxp/vkz686pm8ozr" rel="noopener noreferrer"&gt;The European Accessibility Act (EAA) - Directive 2019/882&lt;/a&gt;, which establishes a comprehensive set of accessibility rules for digital offerings within the EU market, is going to come into effect next year. The deadline for compliance with this new legislation is June 28th, 2025. WCAG 2 Level AA is widely recognised as a benchmark for achieving EAA compliance.&lt;/p&gt;

&lt;p&gt;With this in mind, I'm taking a look at some of the most common accessibility issues according to The &lt;a href="https://webaim.org/projects/million/" rel="noopener noreferrer"&gt;WebAIM 2024 report on the accessibility of the top 1,000,000 home pages&lt;/a&gt;, who they affect, and how to fix them.&lt;/p&gt;

&lt;p&gt;In this post, I'll explore empty links — their impact, who they affect, and how to fix them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why empty links matter
&lt;/h2&gt;

&lt;p&gt;Firstly, let's take a quick look at a couple of fairly typical examples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Links with graphics with no alt --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/Canine_hip_dysplasia"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"/doberman.png"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- Links icons content with no text content --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://bsky.app/"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;i&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"icon icon--bluesky"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/i&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Links containing icons, images without alt text or simply empty lead to confusion for users of assistive technologies. &lt;a href="https://webaim.org/projects/million/" rel="noopener noreferrer"&gt;WebAIM 2024 report on the accessibility of the top 1,000,000 home pages&lt;/a&gt; found that almost half of the pages tested contained empty links (or buttons). &lt;/p&gt;

&lt;p&gt;The lack of any text label on these controls means that assistive technologies can't determine where links go.&lt;/p&gt;

&lt;p&gt;To add an accessible text to the link there are a couple of options&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- use alt text --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/Canine_hip_dysplasia"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Canine hip dysplasia"&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"/doberman.png"&lt;/span&gt; &lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- use an aria label --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://bsky.app/"&lt;/span&gt; &lt;span class="na"&gt;aria-label=&lt;/span&gt;&lt;span class="s"&gt;"Bluesky"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;i&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"icon icon--bluesky"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/i&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- use a visually hidden text --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://bsky.app/"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;i&lt;/span&gt; &lt;span class="na"&gt;aria-hidden=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"icon icon--bluesky"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/i&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"visually-hidden"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Bluesky&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(for visually-hidden example see &lt;a href="https://getbootstrap.com/docs/5.0/helpers/visually-hidden/" rel="noopener noreferrer"&gt;bootstrap visually-hidden helper&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  Who is impacted by missing link text?
&lt;/h2&gt;

&lt;p&gt;Missing link text creates significant barriers for several groups of web users. &lt;/p&gt;

&lt;p&gt;For example; it affects people who are blind or have severe visual impairments who rely on screen readers. When these users encounter a link without text, their screen reader simply announces "link" without any context about where it leads.&lt;/p&gt;

&lt;p&gt;Voice control users, such as people with motor disabilities or temporary injuries, also struggle significantly. They need to be able to say the name of a link to click it, but they can't activate a link that has no name.&lt;/p&gt;

&lt;p&gt;Users with cognitive disabilities also find unnamed links particularly challenging. They need clear, consistent navigation to make sense of websites, and unlabelled links create unnecessary mental work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related WCAG guidelines
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.w3.org/WAI/WCAG22/Understanding/link-purpose-in-context" rel="noopener noreferrer"&gt;2.4.4 Link Purpose (In Context)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3.org/WAI/WCAG22/Understanding/name-role-value" rel="noopener noreferrer"&gt;4.1.2 Name, Role, Value&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Other related issue
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Alt text doesn't describe the link target
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- 
    A link with graphic where the alt describes 
    the image not the link target 
--&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/Canine_hip_dysplasia"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Doberman dog asleep in a wicker basket"&lt;/span&gt; &lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, the alt text should describe the link target not the image itself. e.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/Canine_hip_dysplasia"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Canine hip dysplasia"&lt;/span&gt; &lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Duplicate adjacent links
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- 
    A link which duplicates an adjacent link, 
    for example so users navigating with a 
    pointer can click on the image 
--&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/Canine_hip_dysplasia"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Canine hip dysplasia"&lt;/span&gt; &lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/Canine_hip_dysplasia"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
   Canine hip dysplasia
&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case the links should be combined so there is only one link. And the image should not have an alt value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/Canine_hip_dysplasia"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
   Canine hip dysplasia
&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In some rare cases, where you are providing links for pointer users and you can't combine the links, you may have to resort to removing the duplicate form the accessibility tree.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/Canine_hip_dysplasia"&lt;/span&gt; 
    &lt;span class="na"&gt;tabindex=&lt;/span&gt;&lt;span class="s"&gt;"-1"&lt;/span&gt; 
    &lt;span class="na"&gt;aria-hidden=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/Canine_hip_dysplasia"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
   Canine hip dysplasia
&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this technique pointer users can click on the image and keyboard users don't have to tab though duplicate links. &lt;/p&gt;

&lt;h3&gt;
  
  
  Links out of context
&lt;/h3&gt;

&lt;p&gt;Links that lack context e.g. "Read more".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
  Canine hip dysplasia is one of the most 
  common musculoskeletal conditions that 
  affect our canine companions
&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/Canine_hip_dysplasia"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
   Read more
  &lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To add context we can use visually hidden text or aria-label. For example;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
  Canine hip dysplasia is one of the most 
  common musculoskeletal conditions that 
  affect our canine companions
&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/Canine_hip_dysplasia"&lt;/span&gt; 
    &lt;span class="na"&gt;aria-label=&lt;/span&gt;&lt;span class="s"&gt;"Canine hip dysplasia. Read more"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Read more
  &lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Adding context is important for screen reader users as they often navigate by listing all the links on a page. If all they hear is "read more, read more, read more," they have no idea where each link leads. They lack the visual context that sighted users have.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;All links having accessible text ensures everyone, including screen reader users and those with cognitive disabilities, can understand the link's purpose and destination, leading to improved navigation and a better user experience.&lt;/p&gt;

&lt;p&gt;Providing accessible link text is generally easy and often only requires small coding change, using ARIA attributes or visually hidden text when the visual text isn't sufficient. It's a fundamental accessibility practice that significantly enhances website usability for many users with minimal effort.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tip
&lt;/h3&gt;

&lt;p&gt;To see how a link will be announced by screen readers open your browsers devtools panel, highlight the link you want to inspect, open the accessibility tab and look for the value in the "Name" section. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl9t5ar6w11trkofzgwc4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl9t5ar6w11trkofzgwc4.png" alt="Example screenshot of chrome browser devtools with accessibility tab selected and the Name section underlined" width="538" height="515"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>wcag</category>
      <category>a11y</category>
      <category>html</category>
      <category>css</category>
    </item>
    <item>
      <title>WCAG: Alternative Text for Images</title>
      <dc:creator>patrick clancey</dc:creator>
      <pubDate>Wed, 16 Oct 2024 13:04:34 +0000</pubDate>
      <link>https://dev.to/patrick_clancey/wcag-alternative-text-for-images-4dj7</link>
      <guid>https://dev.to/patrick_clancey/wcag-alternative-text-for-images-4dj7</guid>
      <description>&lt;p&gt;The European Union has implemented new accessibility regulations with a compliance deadline of June 28th, 2025. Many companies are proactively taking steps to meet these standards to avoid penalties and ensure their digital platforms are accessible to all users.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.eumonitor.eu/9353000/1/j9vvik7m1c3gyxp/vkz686pm8ozr" rel="noopener noreferrer"&gt;The European Accessibility Act (EAA) - Directive 2019/882&lt;/a&gt;, which establishes a comprehensive set of accessibility rules for digital offerings within the EU market, is going to come into effect next year. The deadline for compliance with this new legislation is June 28th, 2025. WCAG 2 Level AA is widely recognised as a benchmark for achieving EAA compliance.&lt;/p&gt;

&lt;p&gt;With this in mind, I'm taking a look at some of the most common accessibility issues according to The &lt;a href="https://webaim.org/projects/million/" rel="noopener noreferrer"&gt;WebAIM 2024 report on the accessibility of the top 1,000,000 home pages&lt;/a&gt;, who they affect, and how to fix them.&lt;/p&gt;

&lt;p&gt;In this post, I'll be looking at the image alternative (alt) text, why it's important, who it affects, and how to fix it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why alt text matters
&lt;/h2&gt;

&lt;p&gt;Alt text plays a crucial role in making the web more inclusive for all users, especially those who are visually impaired. It’s not just about filling out an attribute in your HTML code; it’s about ensuring every user can experience the full content of your site, regardless of their ability to see the images.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who is impacted by missing or poor alt text?
&lt;/h2&gt;

&lt;p&gt;The absence of alt text, or poorly written alt text, impacts several user groups, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Screen Reader Users:&lt;/strong&gt; Screen readers rely on alt text to interpret and vocalise the content of an image. Without alt text, users won’t know what the image represents, missing out on essential information.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Users with Cognitive Disabilities:&lt;/strong&gt; Descriptive alt text helps users with cognitive disabilities better understand the context of the image within the webpage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Low Bandwidth Users:&lt;/strong&gt; Alt text can be beneficial for users with slow internet connections, as it provides a text-based description of an image when it fails to load.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Search engines:&lt;/strong&gt; Search engines use the alt text to understand what an image represents. Proper alt text helps improve your website's search rankings.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By omitting alt text on images that convey meaning, you risk creating a frustrating and exclusionary experience for these users.&lt;/p&gt;

&lt;h2&gt;
  
  
  WCAG alt text guidelines
&lt;/h2&gt;

&lt;p&gt;The WCAG provides clear guidelines to ensure alt text is used effectively. Below are some key criteria that must be followed to meet accessibility standards:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.w3.org/WAI/WCAG22/Understanding/non-text-content" rel="noopener noreferrer"&gt;WCAG 1.1.1: Non-text Content (Level A)&lt;/a&gt; All non-text content, including images, must have an alt text description unless the image is purely decorative.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.w3.org/WAI/WCAG22/Understanding/link-purpose-in-context" rel="noopener noreferrer"&gt;WCAG 2.4.4: Link Purpose (In Context) (Level A)&lt;/a&gt; When an image is used as a link, the alt text should describe the link’s purpose, not just the image.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.w3.org/WAI/WCAG22/Understanding/label-in-name" rel="noopener noreferrer"&gt;WCAG 2.5.3: Label in Name (Level A)&lt;/a&gt; Any image used as a control (e.g., buttons) must have alt text that matches the label presented to users.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;WCAG offer clear standards for implementing alt text, primarily under &lt;a href="https://www.w3.org/WAI/WCAG22/Understanding/non-text-content" rel="noopener noreferrer"&gt;WCAG 1.1.1: Non-text Content&lt;/a&gt;. This criterion ensures that all non-text content, including images, has a text alternative. Here are some key principles to follow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For images that convey important information, provide descriptive &lt;code&gt;alt&lt;/code&gt; text.&lt;/li&gt;
&lt;li&gt;For decorative images that don’t add meaningful content, use empty &lt;code&gt;alt&lt;/code&gt; attributes (&lt;code&gt;&amp;lt;img alt="" ...&lt;/code&gt; or just &lt;code&gt;&amp;lt;img alt ...&lt;/code&gt;), so screen readers skip over them.&lt;/li&gt;
&lt;li&gt;Avoid redundancy: Don’t include phrases like "image of" or "photo of" in your alt text—this is implied.&lt;/li&gt;
&lt;li&gt;Avoid duplication: Don't duplicate adjacent text&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The alt attribute is non-negotiable for accessibility
&lt;/h2&gt;

&lt;p&gt;Every &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; tag must include an &lt;code&gt;alt&lt;/code&gt; attribute, without exception. While the attribute doesn't always require a value—decorative images should use an empty &lt;code&gt;alt&lt;/code&gt; —the attribute itself is mandatory. Failing to provide an &lt;code&gt;alt&lt;/code&gt; attribute results in a critical accessibility issue, as screen readers will announce a graphic and some will then read the image’s file path (&lt;code&gt;src&lt;/code&gt;) or file name, which offers no meaningful information to users.&lt;/p&gt;

&lt;h2&gt;
  
  
  Identifying Decorative Images: When to use an empty alt attribute
&lt;/h2&gt;

&lt;p&gt;Not all images on a webpage serve a functional or informative purpose. Some images are purely decorative, added for visual appeal without contributing meaningful content to the page. For these images, you should include an empty &lt;code&gt;alt&lt;/code&gt; attribute, which tells screen readers to ignore the image, allowing users to focus on the content that matters. For help see the &lt;a href="https://www.w3.org/WAI/tutorials/images/decision-tree/" rel="noopener noreferrer"&gt;WAI images decision tree&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to write effective alt text
&lt;/h2&gt;

&lt;p&gt;When writing alt text, it’s essential to consider the purpose of the image and its context within the page. Here are a few best practices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Be concise but descriptive: Summarise the content of the image in a brief, meaningful way.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- DON'T DO THIS --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"accounts.jpg"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"accounts"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- DO THIS INSTEAD --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"accounts.jpg"&lt;/span&gt; 
    &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Our company accounts team posing in front of the Berlin office"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Include relevant information: If an image conveys complex information (e.g., a chart or diagram), summarise the key insights it provides.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"sales_chart.png"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Line graph showing a 25% increase in sales over the last quarter"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Leave alt text empty for decorative images: If an image is purely decorative and does not convey important information, use an empty alt attribute.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"border.png"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Testing alt text for accessibility
&lt;/h2&gt;

&lt;p&gt;Verifying the presence and quality of alt text can be done both manually and through automated testing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Manual Testing:&lt;/strong&gt; Try navigating your website with &lt;a href="https://cleanbrowsing.org/help/docs/disable-images-in-browser/" rel="noopener noreferrer"&gt;images disabled&lt;/a&gt; or better still with a screen reader and observe how well the alt text conveys the image content.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automated Tools:&lt;/strong&gt; Tools like Axe DevTools, WAVE, or Lighthouse can automatically flag images without alt text or those with potentially problematic alt descriptions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Alt text for complex images
&lt;/h2&gt;

&lt;p&gt;Sometimes, images are more complex and can't be fully described in a short piece of text. For these cases, consider linking to a detailed description:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"graph.png"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Graph showing Q3 earnings. Full description below"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#full-description"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Read full description of the graph&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
...
&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"full-description"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
  Detailed description of the Q3 earnings here...
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: the &lt;code&gt;longdesc&lt;/code&gt; attribute is no longer recommended and shouldn't be used. &lt;/p&gt;

&lt;h2&gt;
  
  
  Video content: Accessibility considerations
&lt;/h2&gt;

&lt;p&gt;Under &lt;a href="https://www.w3.org/WAI/WCAG22/Understanding/non-text-content.html" rel="noopener noreferrer"&gt;WCAG 1.1.1: Non-text Content&lt;/a&gt;, videos are also non-text elements and must be made accessible, just like images. Videos can be informative, decorative, or both, but they must be handled properly to ensure that all users can engage with their content. Video accessibility is out of scope of this post. But for more information on this topic see &lt;a href="https://www.w3.org/WAI/media/av/" rel="noopener noreferrer"&gt;Making Audio and Video Media Accessible&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Alt text is a small but essential part of creating accessible and inclusive websites. By following WCAG guidelines and best practices, you can ensure that users relying on screen readers, users with cognitive disabilities, and those with poor connectivity can still fully engage with your content. In addition to fulfilling the legal requirements of the upcoming EAA, providing thoughtful and well-written alt text makes your website more usable and welcoming to everyone.&lt;/p&gt;

</description>
      <category>wcag</category>
      <category>a11y</category>
    </item>
    <item>
      <title>WCAG: The Unseen Impact of Missing Labels</title>
      <dc:creator>patrick clancey</dc:creator>
      <pubDate>Tue, 27 Aug 2024 06:18:03 +0000</pubDate>
      <link>https://dev.to/patrick_clancey/wcag-the-unseen-impact-of-missing-labels-ab5</link>
      <guid>https://dev.to/patrick_clancey/wcag-the-unseen-impact-of-missing-labels-ab5</guid>
      <description>&lt;p&gt;The European Union has implemented new accessibility regulations with a compliance deadline of June 28th, 2025. Many companies are proactively taking steps to meet these standards to avoid penalties and ensure their digital platforms are accessible to all users.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.eumonitor.eu/9353000/1/j9vvik7m1c3gyxp/vkz686pm8ozr" rel="noopener noreferrer"&gt;The European Accessibility Act (EAA) - Directive 2019/882&lt;/a&gt;, which establishes a comprehensive set of accessibility rules for digital offerings within the EU market, is going to come into effect next year. The deadline for compliance with this new legislation is June 28th, 2025. WCAG 2 Level AA is widely recognised as a benchmark for achieving EAA compliance.&lt;/p&gt;

&lt;p&gt;With this in mind, I'm taking a look at some of the most common accessibility issues according to The &lt;a href="https://webaim.org/projects/million/" rel="noopener noreferrer"&gt;WebAIM 2024 report on the accessibility of the top 1,000,000 home pages&lt;/a&gt;, who they affect, and how to fix them.&lt;/p&gt;

&lt;p&gt;In this post, I'll be looking at the missing label, why it's important, who it affects, and how to fix it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Missing Labels on HTML Forms: A Recipe for Confusion and Exclusion
&lt;/h2&gt;

&lt;p&gt;HTML forms without proper labels can be quite challenging for many users. It may seem like a minor mishap to omit these labels, but in reality, it becomes a major accessibility hurdle for diverse user groups. This lack of direction leads to confusion and frustration, making it difficult for users to interact effectively with the website or application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Who is Impacted by Missing Form Labels?
&lt;/h3&gt;

&lt;p&gt;Missing form labels impact a large number of users.  Here's why:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Screen reader users:&lt;/strong&gt; Screen readers rely on labels to identify form fields and provide context. Without labels, users are left guessing what information to input or even what a button does.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Users with cognitive disabilities:&lt;/strong&gt; Clear labels are crucial for users who may have difficulty understanding complex instructions or remembering information. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Users with motor disabilities:&lt;/strong&gt; Some people can take advantage of speech recognition software that translates the user's spoken words into language that the computer can understand. Having visible labels which are programatically linked with the relevant form elements is critical for the software to link the users commands with the correct input field.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Users with low vision:&lt;/strong&gt; Labels must have sufficient contrast and be easily distinguishable from the surrounding content and positioned close to their respective input fields for easy association.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Importance of Labels: More Than Just Words
&lt;/h3&gt;

&lt;p&gt;Labels serve as vital signposts in the user's journey through a form. They:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Provide context:&lt;/strong&gt; Labels tell users what information is being requested in each field.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Guide interaction:&lt;/strong&gt; They clarify the purpose of each field and how to interact with it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improve comprehension:&lt;/strong&gt; Clear labels make forms easier to understand and complete accurately.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enhance accessibility:&lt;/strong&gt;  Properly implemented labels are crucial for users who rely on assistive technologies.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  WCAG Guidelines for Form Labels
&lt;/h3&gt;

&lt;p&gt;The Web Content Accessibility Guidelines (WCAG) provide clear guidelines for labelling form elements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;WCAG 1.3.1: Info and Relationships (Level A):&lt;/strong&gt;  Information, structure, and relationships conveyed through presentation can be programmatically determined or are available in text.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WCAG 2.4.6: Headings and Labels (Level AA):&lt;/strong&gt; Headings and labels describe topic or purpose.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WCAG 3.3.2: Labels or Instructions (Level A):&lt;/strong&gt; Labels or instructions are provided when content requires user input.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Identifying and Fixing Missing Labels
&lt;/h3&gt;

&lt;p&gt;Thankfully, identifying missing labels is relatively straightforward:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Manual testing:&lt;/strong&gt; Carefully review all forms and CTAs (Call To Action) on your website and ensure each field has a visible and descriptive label.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automated testing:&lt;/strong&gt; Accessibility testing tools like WAVE, Axe, and Lighthouse can automatically detect missing labels and other accessibility issues.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once identified, fixing missing labels is usually a simple matter of adding the appropriate HTML:&lt;br&gt;
&lt;em&gt;(note: to keep the examples short, I'm not adding the &lt;code&gt;autocomplete&lt;/code&gt; attribute, but by rights, they should be included on form elements that request personal information)&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- DON'T DO THIS --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;strong&amp;gt;&lt;/span&gt;Name&lt;span class="nt"&gt;&amp;lt;/strong&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- Use a label, with a 'for' attribute --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Name&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Best Practices for Effective Form Labels
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Writing Clear and Concise Form Labels
&lt;/h4&gt;

&lt;p&gt;Use plain, simple language and avoid jargon. e.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Simple descriptive label --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Email address&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Using Descriptive Language for Form Labels
&lt;/h4&gt;

&lt;p&gt;Labels should accurately describe the information being requested. e.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Describe what data is required --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"phone"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Telephone number&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"phone"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"phone"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Properly Associating Labels with Input Fields
&lt;/h4&gt;

&lt;p&gt;Use the &lt;code&gt;&amp;lt;label&amp;gt;&lt;/code&gt; element with the &lt;code&gt;for&lt;/code&gt; attribute linked to the corresponding input's &lt;code&gt;id&lt;/code&gt; or for multi fields (like radio buttons) use &lt;code&gt;aria-labelledby&lt;/code&gt;. e.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Use a label, with a 'for' attribute --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Name&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- Use a 'aria-labelledby' attribute for 
  multi-field input group --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- Legend with ID for referencing --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;legend&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"petLegend"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Insure your pet&lt;span class="nt"&gt;&amp;lt;/legend&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"catLabel"&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"cat"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Cat&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- Cat radio button with aria-labelledby attribute --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"cat"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"pet"&lt;/span&gt; 
    &lt;span class="na"&gt;aria-labelledby=&lt;/span&gt;&lt;span class="s"&gt;"petLegend catLabel"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"dogLabel"&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"dog"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Dog&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- Dog radio button with aria-labelledby attribute --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"dog"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"pet"&lt;/span&gt; 
    &lt;span class="na"&gt;aria-labelledby=&lt;/span&gt;&lt;span class="s"&gt;"petLegend dogLabel"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Ensure all CTAs have labels
&lt;/h4&gt;

&lt;p&gt;Either add text to the CTA (visually hide it if it's not needed, e.g. if the CTA displays as an icon) or use the &lt;code&gt;aria-label&lt;/code&gt; attribute. Consider a 'close' icon on a search panel;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- DON'T DO THIS --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"close-search-icon"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- add text (can be visually hidden) --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"close-search-icon"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"visually-hidden"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Close Search
  &lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- or aria-label --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"close-search-icon"&lt;/span&gt; 
  &lt;span class="na"&gt;aria-label=&lt;/span&gt;&lt;span class="s"&gt;"Close Search"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Visually distinct and placed appropriately
&lt;/h4&gt;

&lt;p&gt;Ensure labels have sufficient contrast and are easily distinguishable from the surrounding content. Also, position labels close to their respective input fields for easy association.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion: Labels are Non-Negotiable
&lt;/h3&gt;

&lt;p&gt;Missing labels are a common accessibility issue with a significant impact on user experience. By following WCAG guidelines and implementing best practices, we can create forms that are accessible, usable, and inclusive for everyone. Remember, clear and descriptive labels are not just a nice-to-have, they are essential for creating a truly accessible web. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>WCAG: Good contrast, good vibes!</title>
      <dc:creator>patrick clancey</dc:creator>
      <pubDate>Fri, 26 Jul 2024 08:45:46 +0000</pubDate>
      <link>https://dev.to/patrick_clancey/wcag-good-contrast-good-vibes-1jco</link>
      <guid>https://dev.to/patrick_clancey/wcag-good-contrast-good-vibes-1jco</guid>
      <description>&lt;p&gt;The new accessibility recommendations from the EU are important guidelines that we should be mindful of. While the value is widely acknowledged, not everyone might have acted on it yet. Now, with a concrete deadline in place - June 28th, 2025 - it becomes an essential task to undertake. Many companies have already begun improving their websites' accessibility. Since contrast often tops the list of common accessibility failures, let's delve into this particular challenge.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.eumonitor.eu/9353000/1/j9vvik7m1c3gyxp/vkz686pm8ozr" rel="noopener noreferrer"&gt;The European Accessibility Act (EAA) - Directive 2019/882&lt;/a&gt;, which establishes a comprehensive set of accessibility rules for digital offerings within the EU market, is going to come into effect next year. The deadline for compliance with this new legislation is June 28th, 2025.&lt;br&gt;
With this in mind, I'm going to take a look at some of the most common accessibility issues according to &lt;a href="https://webaim.org/projects/million/" rel="noopener noreferrer"&gt;The 2024 report on the accessibility of the top 1,000,000 home pages&lt;/a&gt; and how to fix them.&lt;/p&gt;

&lt;p&gt;In this post, I'll be looking at contrast, why it's important, who it affects, and how to fix it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Low Contrast - Who Does It Impact?
&lt;/h2&gt;

&lt;p&gt;A better question might be, who doesn't it impact? The group that won't be affected by low contrast are those using screen readers to access the website. However, for everyone else who relies on visual cues to navigate the site, contrast plays a crucial role. Therefore, it's safe to say that nearly all visually-dependent users will be impacted by the level of contrast on a website.&lt;/p&gt;

&lt;p&gt;At some time or another, we all face issues with our sight, whether it's persistent (e.g., old age, hypermetropia), temporary (e.g., conjunctivitis, hay fever), or situational (e.g., sunny day, phone in low battery mode).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsifxomv7svsycjppks8r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsifxomv7svsycjppks8r.png" alt="Three examples of impaired vision; Permanent, low vision. Temporary, eye infection and situational, bright sunlight" width="800" height="255"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Having said that, people with colour blindness or other visual impairments are particularly affected by low contrast. It's important to follow the WCAG recommendations and ensure that our interfaces have sufficient contrast to be usable by everybody. &lt;/p&gt;
&lt;h3&gt;
  
  
  WCAG Contrast related Success Criterion
&lt;/h3&gt;

&lt;p&gt;There are four WCAG SC specifically related to contrast levels, they are;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html" rel="noopener noreferrer"&gt;WCAG SC 1.4.3:
Contrast (Minimum) (Level AA)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3.org/WAI/WCAG22/Understanding/contrast-enhanced.html" rel="noopener noreferrer"&gt;WCAG SC 1.4.6:
Contrast (Enhanced) (Level AAA)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3.org/WAI/WCAG22/Understanding/non-text-contrast.html" rel="noopener noreferrer"&gt;WCAG SC 1.4.11:
Non-text Contrast (Level AA)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3.org/WAI/WCAG22/Understanding/focus-appearance.html" rel="noopener noreferrer"&gt;WCAG SC 2.4.13:
Focus Appearance (Level AAA)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Testing for compliance
&lt;/h3&gt;

&lt;p&gt;Firstly, we need to know what issues we have and where they are, so they can be prioritised. Thankfully, contrast is one accessibility issue that can usually be picked up by accessibility tools. There is a good list on &lt;a href="https://www.w3.org/WAI/test-evaluate/tools/list/" rel="noopener noreferrer"&gt;Web Accessibility Evaluation Tools List&lt;/a&gt;. Ideally we want a tool like &lt;a href="https://pa11y.org/" rel="noopener noreferrer"&gt;pa11y&lt;/a&gt; running against a dev server to surface issues way before they go live. For manual testing, a personal favourite of mine is the &lt;a href="https://chromewebstore.google.com/detail/axe-devtools-web-accessib/lhdoppojpmngadmnindnejefpokejbdd" rel="noopener noreferrer"&gt;axe DevTools chrome extension&lt;/a&gt;. Also worth a mention is the stand-alone &lt;a href="https://www.tpgi.com/color-contrast-checker/" rel="noopener noreferrer"&gt;Colour Contrast Analyzer (CCA)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you have identified any low contrast elements, you can prioritise fixing them. Starting with elements commonly used across your site. For example, if you have a contrast issue with your global navigation that needs fixing ASAP. Same goes for any CTAs, like form buttons or link texts. And, as you are addressing contrast issues you may as well not pussy foot around with AA, go straight for AAA!&lt;/p&gt;
&lt;h3&gt;
  
  
  Addressing issues
&lt;/h3&gt;

&lt;p&gt;On the good side, technically fixing contrast issues is easy work. Usually it's just a few simple changes to your CSS. The more difficult task is getting approval to make the changes in the first place! If your colour scheme is based on approved corporate colours and/or the designs have been "signed off", it's often a slow process to get approval make global changes to the colour scheme. So with the EU Accessibility Directive coming into force next year it's well worth getting the ball rolling in order to get your necessary updates live in time!&lt;/p&gt;

&lt;p&gt;In my experience it's a good idea to offer some "ready-to-go" alternatives. As the site's product owner might not have time to fully digest the implications and impacts of contrast failures and come up with a solution, they will probably have time to look at three options and point at their favourite.  &lt;/p&gt;

&lt;p&gt;The first step is to explore some alternatives that meet the required contrast levels. Depending on what elements are failing, you'll likely find three or four viable options to consider.&lt;/p&gt;
&lt;h3&gt;
  
  
  Darken
&lt;/h3&gt;

&lt;p&gt;If you have an issue with say a blue which is too light you can usually darken it, whilst still keeping the overall colour pallet. This won't work with colours like green, orange or gold as they don't darken nicely. &lt;br&gt;
There are a number of theming tools like &lt;a href="https://fabricweb.z5.web.core.windows.net/pr-deploy-site/refs/heads/master/theming-designer/" rel="noopener noreferrer"&gt;Theming Designer&lt;/a&gt; or &lt;a href="https://paletton.com/" rel="noopener noreferrer"&gt;Paletton.com&lt;/a&gt;&lt;br&gt;
 which you can use to extend your current pallet to include some WCAG compliant colour variations.&lt;/p&gt;
&lt;h3&gt;
  
  
  Complementary
&lt;/h3&gt;

&lt;p&gt;You can expand the site's colour palette by finding some complementary colours which have higher contrast.&lt;br&gt;
Look for colour wheel generators like &lt;a href="https://www.figma.com/color-wheel/" rel="noopener noreferrer"&gt;Figma color-wheel&lt;/a&gt; or a matching colour generator like &lt;a href="https://mycolor.space/" rel="noopener noreferrer"&gt;mycolor&lt;/a&gt; to get ideas.&lt;/p&gt;
&lt;h3&gt;
  
  
  Invert
&lt;/h3&gt;

&lt;p&gt;You can try inverting the colours, or rather swapping white and black. For example if your issue is buttons that are a light colour with white text you can swap that round so the button is black with the light colour as the text. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyxxlnqm6enb223rfclyw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyxxlnqm6enb223rfclyw.png" alt="Two buttons, one with low contrast and one with compliant contrast" width="800" height="157"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Remove
&lt;/h3&gt;

&lt;p&gt;The nuclear option. Remove the colour palette from the offending elements altogether. Falling back to generic grey scale. This might sound extreme, but, you can select greys that sit nicely within any colour pallet and easily meet the contrast requirements.&lt;/p&gt;
&lt;h2&gt;
  
  
  In the meantime
&lt;/h2&gt;

&lt;p&gt;In the short term remove any CSS that is actively causing issues, for example check your CSS doesn't actively suppress the focus indicator (this was quite a common practise, so if you have inherited a code base, please check!).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* remove anything that looks similar to these */&lt;/span&gt;
&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nd"&gt;:focus&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;outline-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="cp"&gt;!important&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nd"&gt;:focus&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;outline&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt; &lt;span class="cp"&gt;!important&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Developers used to routinely remove the system outline so code similar to the above is still quite common. Read  &lt;a href="https://www.w3.org/WAI/WCAG22/Understanding/focus-appearance.html" rel="noopener noreferrer"&gt;WCAG SC 2.4.13 Focus Appearance&lt;/a&gt; to get up to speed with requirements around the focus indicator.&lt;/p&gt;

&lt;p&gt;It's worth checking when the user has requested High Contrast that your CSS is not overriding any important rules. Always a good idea to check this by enabling High Contrast on your machine to see what happens!&lt;/p&gt;

&lt;p&gt;Implementing something is better than nothing. I recommend you pick your personal favourite solution and implement it within the CSS &lt;code&gt;prefers-contrast: more&lt;/code&gt; media query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;/* can't change this until the theme update is approved */&lt;/span&gt; 
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;gold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prefers-contrast&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;more&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;/* random example; */&lt;/span&gt;
  &lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="nd"&gt;:focus-visible&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;outline&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;outline-offset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c"&gt;/* or if you are using css variables */&lt;/span&gt;
&lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--accent-color-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;gold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prefers-contrast&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;more&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
  &lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;--accent-color-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At least users who have specifically asked for high contrast will get it. And it shows you are making an effort to address the site's issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  In conclusion
&lt;/h2&gt;

&lt;p&gt;Ensuring good contrast in web design is crucial for accessibility and usability. It affects everyone who visually accesses a website, whether they have permanent, temporary, or situational vision impairments. Adhering to the WCAG success criteria related to contrast not only enhances user experience but also helps meet the upcoming European Accessibility Act requirements. While technically simple to fix, these changes often require approval due to established colour schemes and designs. Therefore, it's important to start early, prioritize common elements, and aim for AAA compliance. Remember, there are various strategies to address contrast issues, from darkening colours and finding complementary ones to inverting or even removing the colour palette. In the meantime, avoid suppressing focus indicators and consider implementing high-contrast options for users who prefer them. Ultimately, improving contrast is about making your digital content more accessible and enjoyable for all users.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;(Thank you to &lt;a href="https://unsplash.com/@jan_huber" rel="noopener noreferrer"&gt;jan huber&lt;/a&gt; for the cover image)&lt;/em&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>wcag</category>
      <category>a11y</category>
    </item>
    <item>
      <title>CSS wordwrap: Because Sometimes One Line Just Isn't Enough!</title>
      <dc:creator>patrick clancey</dc:creator>
      <pubDate>Fri, 28 Jun 2024 10:48:07 +0000</pubDate>
      <link>https://dev.to/patrick_clancey/a-deep-dive-into-css-and-text-wrapping-5862</link>
      <guid>https://dev.to/patrick_clancey/a-deep-dive-into-css-and-text-wrapping-5862</guid>
      <description>&lt;p&gt;Controlling how text wraps with CSS can be a headache. CSS offers a number of text wrapping options to keep your content readable and responsive. So your text doesn't break the page layout or look like it lost a fight with a blender.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Text wrapping is vital in web design for content readability and visual appeal across different devices and screen sizes. CSS provides properties like &lt;code&gt;overflow-wrap&lt;/code&gt;, &lt;code&gt;word-break&lt;/code&gt;, &lt;code&gt;text-wrap&lt;/code&gt; and &lt;code&gt;hyphens&lt;/code&gt; that allow developers to control text behavior at the edge of its container. This post explores the practical use of these properties to manage long strings, prevent overflow, and enhance user experience. These CSS rules are essential when dealing with unbreakable URLs, optimizing text readability and maintaining responsive designs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping vs Truncation
&lt;/h2&gt;

&lt;p&gt;For the purposes of this post I'm only going to focus on text that needs to be visible to the user, hence it needs to wrap and ignore the truncation option entirely. Although, there is some overlap in the use-cases, text truncation has a more specific use-case and is specifically for hiding content over a specific length. So I'm just going to skip over it here!&lt;/p&gt;

&lt;h2&gt;
  
  
  Text wrapping style options
&lt;/h2&gt;

&lt;p&gt;Let's jump straight in and take a look at some styles we can use to prevent strings form overflowing their container.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/clanceyp/embed/MWdVBEG?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  TLDR
&lt;/h2&gt;

&lt;p&gt;Ok, I'm going to skip the boring bits and go straight to the summary. (For reference, the rather dry detail about each style follows further down the page.)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* use for headings */&lt;/span&gt;
&lt;span class="nc"&gt;.my-h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;hyphens&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;overflow-wrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;break-word&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;text-wrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c"&gt;/* use for general static copy */&lt;/span&gt;
&lt;span class="nc"&gt;.my-text-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;hyphens&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;overflow-wrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;break-word&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c"&gt;/* 
  use specifically for breaking long strings or
  on large/dynamic content containers which 
  may contain long strings
 */&lt;/span&gt;
&lt;span class="nc"&gt;.my-url-container&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nc"&gt;.my-very-big-text-container&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nc"&gt;.my-dynamic-text-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;overflow-wrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;break-word&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As with most things CSS, there is more than one way to solve the problem. But which is the best? Let's look at three use-cases. Headings where long words might overflow on small devices, static content containers which could contain long strings like URLs, and containers that could either contain a lot of content or are repeatedly updated dynamically. Let's take these three in revers order. For contains that contain a lot of content, or are dynamically updated we can use &lt;code&gt;overflow-wrap: break-word&lt;/code&gt; this will keep the content within the containers' boundaries. For short or static content (see below for detail about hyphens and performance) we can add &lt;code&gt;hyphens: auto&lt;/code&gt; this will improve readability, but we still keep &lt;code&gt;overflow-wrap: break-word&lt;/code&gt; which will ensure that long strings still wrap if the content is in a language that the browser doesn't know how to hyphenate or the long strings aren't words. And lastly for headings (e.g. H1) we'll keep &lt;code&gt;hyphens&lt;/code&gt; and &lt;code&gt;overflow-wrap&lt;/code&gt; and we'll also add &lt;code&gt;text-wrap: balance&lt;/code&gt; this adds visual balance to the mix, so the header wraps nicely.&lt;/p&gt;

&lt;h2&gt;
  
  
  The boring bit
&lt;/h2&gt;

&lt;p&gt;Let's look at the styles in more detail&lt;/p&gt;

&lt;h3&gt;
  
  
  hyphens: auto;
&lt;/h3&gt;

&lt;p&gt;Using &lt;code&gt;hyphens: auto&lt;/code&gt; in CSS allows for automatic, language-aware hyphenation of text, which can significantly enhance the readability and aesthetic of text blocks, particularly in responsive designs and narrow layouts.&lt;/p&gt;

&lt;h4&gt;
  
  
  hyphens, on the downside
&lt;/h4&gt;

&lt;p&gt;This does more than just breaking long strings that don't fit in the container. You might still get text overflowing the container, for example a very long number won't be hyphenated so will still remain on one line. &lt;code&gt;hyphens: auto&lt;/code&gt; has a performance overhead due to the processing required to determine hyphenation points, especially in dynamic or large text content. To mitigate the impact of this, particularly for containers with extensive or frequently changing text, I recommend only using &lt;code&gt;hyphens: auto&lt;/code&gt; on specific elements that would benefit from it, don't just randomly add it here, there and everywhere!&lt;/p&gt;

&lt;h3&gt;
  
  
  overflow-wrap: break-word;
&lt;/h3&gt;

&lt;p&gt;This style ensures that long words or unbreakable strings (such as URLs) break and wrap onto the next line instead of overflowing their container.&lt;/p&gt;

&lt;h4&gt;
  
  
  overflow-wrap, on the downside
&lt;/h4&gt;

&lt;p&gt;Arbitrary word breaks at any point, which can lead to awkward or hard-to-read text breaks, disrupting the natural flow of reading. A small performance overhead (although less than that of hyphens).&lt;/p&gt;

&lt;h3&gt;
  
  
  word-wrap: break-word;
&lt;/h3&gt;

&lt;p&gt;This is an alias for &lt;code&gt;overflow-wrap: break-word&lt;/code&gt;, which is the standardized property name. Use &lt;code&gt;overflow-wrap: break-word&lt;/code&gt; instead.&lt;/p&gt;

&lt;h3&gt;
  
  
  word-wrap: break-all;
&lt;/h3&gt;

&lt;p&gt;I have nothing good to say about &lt;code&gt;word-wrap: break-all&lt;/code&gt;. I can't think of any use-case for it. Only consider using this if you have a specific issue that isn't fixed by any of the other options!&lt;/p&gt;

&lt;h4&gt;
  
  
  break-all, on the downside
&lt;/h4&gt;

&lt;p&gt;It breaks words excessively at any character, leading to awkward and very hard-to-read text at all widths.&lt;/p&gt;

&lt;h2&gt;
  
  
  Balancing text-wrapping
&lt;/h2&gt;

&lt;p&gt;The style &lt;code&gt;text-wrap: balance&lt;/code&gt; does NOT break strings. This is shorthand property which controls how text inside an element is wrapped, it's not standard (yet) but has solid support in all major browser vendors. I use this on main header elements (e.g. h1) to visually balance the content and make it more aesthetically pleasing. This is part of the &lt;a href="https://www.w3.org/TR/css-text-4/#text-wrapping" rel="noopener noreferrer"&gt;css-text-4 text-wrapping proposal&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  text-wrap balance on the downside
&lt;/h3&gt;

&lt;p&gt;I haven't seen any detailed performance metrics so I might be making too much of the potential performance impact. But nonetheless, I would only use this on specific static elements like headers. I wouldn't use this on large content blocks or anything that's repeatedly updated dynamically.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm8a52a9lk24xjpb42mmv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm8a52a9lk24xjpb42mmv.png" alt="Latin text twice, wrapping in different places to show the effect of the CSS text-wrap: balance rule" width="800" height="149"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Further reading
&lt;/h2&gt;

&lt;p&gt;Some useful resources on text wrapping in CSS&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_text/Wrapping_breaking_text" rel="noopener noreferrer"&gt;Wrapping and breaking text&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.hubspot.com/website/css-wrap-text" rel="noopener noreferrer"&gt;CSS Text Wrapping: A Beginner's Guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/text-wrap" rel="noopener noreferrer"&gt;CSS text-wrap&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-wrap" rel="noopener noreferrer"&gt;CSS overflow-wrap&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3.org/TR/css-text-4/#text-wrapping" rel="noopener noreferrer"&gt;css-text-4 text-wrapping proposal&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.erwinhofman.com/blog/use-text-wrap-balance-to-improve-inp/" rel="noopener noreferrer"&gt;Use text-wrap: balance; to improve design and INP&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>css</category>
      <category>ux</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
