<?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: richi.codes</title>
    <description>The latest articles on DEV Community by richi.codes (@richicodes).</description>
    <link>https://dev.to/richicodes</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%2F10997%2Fdibuix_rixi.jpg</url>
      <title>DEV Community: richi.codes</title>
      <link>https://dev.to/richicodes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/richicodes"/>
    <language>en</language>
    <item>
      <title>CSS typed arithmetic: turn any length into a number</title>
      <dc:creator>richi.codes</dc:creator>
      <pubDate>Thu, 19 Nov 2026 08:30:40 +0000</pubDate>
      <link>https://dev.to/richicodes/css-typed-arithmetic-turn-any-length-into-a-number-4f03</link>
      <guid>https://dev.to/richicodes/css-typed-arithmetic-turn-any-length-into-a-number-4f03</guid>
      <description>&lt;p&gt;&lt;strong&gt;This note has an interactive demo.&lt;/strong&gt; &lt;a href="https://richi.codes/article/2026-11-19-css-typed-arithmetic-turn-any-length-into-a-number" rel="noopener noreferrer"&gt;Try it in the original&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;calc(100cqw / 1px)&lt;/code&gt; used to be an invalid declaration. Now it's a number: if the container is 521 pixels wide, you get &lt;code&gt;521&lt;/code&gt;, with no unit attached. With Firefox 158 joining Chrome and Safari, this is called CSS typed arithmetic, and it became Baseline newly available in October 2026.&lt;/p&gt;

&lt;p&gt;That sounds like a footnote in the &lt;code&gt;calc()&lt;/code&gt; spec. In practice it's the bridge CSS was missing between &lt;em&gt;types&lt;/em&gt;. A length can now become a number, and a number can become an angle, a colour hue, a column count or a counter that CSS prints on screen. Everything in the demo above is computed this way: the big pixel readout, the value in &lt;code&gt;rem&lt;/code&gt;, how many 92px columns fit, the needle angle and the colours. The only JavaScript changes the width of the box, like resizing a window would.&lt;/p&gt;

&lt;h2&gt;
  
  
  What changed in calc()
&lt;/h2&gt;

&lt;p&gt;The rules for &lt;code&gt;calc()&lt;/code&gt; used to be strict. You could multiply a length by a number (&lt;code&gt;200px * 4&lt;/code&gt;) or divide it by a number (&lt;code&gt;1000px / 2&lt;/code&gt;), but the right-hand side of a division had to be unitless. So there was no way to ask "how many times does &lt;code&gt;1px&lt;/code&gt; fit into this width?".&lt;/p&gt;

&lt;p&gt;The current CSS Values and Units Level 4 spec relaxes that. Division and multiplication can take typed values on both sides, units of the same type cancel out, and what matters is the type the whole expression resolves to. As MDN puts it, you can divide a value with one unit by a value with a different unit of the same data type, and the result is a unitless &lt;code&gt;&amp;lt;number&amp;gt;&lt;/code&gt;. Chrome's release note for version 140 gives two examples: &lt;code&gt;calc(10em / 1px)&lt;/code&gt; and &lt;code&gt;calc(20% / 0.5em * 1px)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Once you have a number, you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;use it directly in properties that take numbers (&lt;code&gt;opacity&lt;/code&gt;, &lt;code&gt;line-height&lt;/code&gt;, &lt;code&gt;scale&lt;/code&gt;), or&lt;/li&gt;
&lt;li&gt;multiply it by a unit to land in a &lt;em&gt;different&lt;/em&gt; type: &lt;code&gt;* 1deg&lt;/code&gt; gives an angle, &lt;code&gt;* 1ms&lt;/code&gt; a time, &lt;code&gt;* 1rem&lt;/code&gt; a length again.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This last step is the new part: a measured length can turn into an angle or a time, which is exactly the use Chrome's note highlights.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pattern from the demo
&lt;/h2&gt;

&lt;p&gt;Here's the core of the demo's CSS, trimmed:&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="k"&gt;@property&lt;/span&gt; &lt;span class="nv"&gt;--px&lt;/span&gt;   &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;syntax&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;number&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="nl"&gt;inherits&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;initial-value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;@property&lt;/span&gt; &lt;span class="nv"&gt;--pxi&lt;/span&gt;  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;syntax&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;integer&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;inherits&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;initial-value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;@property&lt;/span&gt; &lt;span class="nv"&gt;--cols&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;syntax&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;integer&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;inherits&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;initial-value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.stage&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;container-type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;inline-size&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.scene&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;--px&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;   &lt;span class="nf"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100cqw&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                 &lt;span class="cm"&gt;/* length -&amp;gt; number */&lt;/span&gt;
  &lt;span class="nv"&gt;--pxi&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="nf"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100cqw&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                 &lt;span class="cm"&gt;/* same, rounded to an integer */&lt;/span&gt;
  &lt;span class="nv"&gt;--cols&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;down&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100cqw&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;92px&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="cm"&gt;/* how many 92px columns fit */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.grid&lt;/span&gt;   &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;repeat&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;--cols&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1fr&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="nc"&gt;.needle&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;180deg&lt;/span&gt; &lt;span class="o"&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;--px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.5deg&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="cm"&gt;/* number -&amp;gt; angle */&lt;/span&gt;
&lt;span class="nc"&gt;.tile&lt;/span&gt;   &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;oklch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.72&lt;/span&gt; &lt;span class="mf"&gt;0.17&lt;/span&gt; &lt;span class="nf"&gt;calc&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;--px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.4deg&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="p"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/* CSS prints the width by itself */&lt;/span&gt;
&lt;span class="nc"&gt;.readout&lt;/span&gt;     &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;counter-reset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;px&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;--pxi&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="nc"&gt;.big&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nt"&gt;before&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;px&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;A few details make this work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Registering the properties with &lt;code&gt;@property&lt;/code&gt;.&lt;/strong&gt; An unregistered custom property is just a token list: &lt;code&gt;var(--px)&lt;/code&gt; pastes the text &lt;code&gt;calc(100cqw / 1px)&lt;/code&gt; wherever it's used, and &lt;code&gt;100cqw&lt;/code&gt; is then resolved there. Registering &lt;code&gt;--px&lt;/code&gt; as a &lt;code&gt;&amp;lt;number&amp;gt;&lt;/code&gt; makes the browser compute it once on &lt;code&gt;.scene&lt;/code&gt; and pass the resulting number down to the children.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The &lt;code&gt;&amp;lt;integer&amp;gt;&lt;/code&gt; version rounds for you.&lt;/strong&gt; The spec says that when a math function resolving to a &lt;code&gt;&amp;lt;number&amp;gt;&lt;/code&gt; is used where only an &lt;code&gt;&amp;lt;integer&amp;gt;&lt;/code&gt; is accepted, the value is rounded to the nearest integer. That's why &lt;code&gt;--pxi&lt;/code&gt; holds &lt;code&gt;521&lt;/code&gt; when the container is 520.875px wide, and why it can feed &lt;code&gt;counter-reset&lt;/code&gt;, which only takes integers. &lt;code&gt;counter()&lt;/code&gt; then prints it as text. In the demo, the &lt;code&gt;rem&lt;/code&gt; readout uses the same trick: &lt;code&gt;round(down, 100cqw / 1rem * 10)&lt;/code&gt; gives tenths, and &lt;code&gt;mod()&lt;/code&gt; splits them into the whole and decimal parts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;round(down, 100cqw / 92px)&lt;/code&gt; is a column count.&lt;/strong&gt; &lt;code&gt;repeat()&lt;/code&gt; needs an integer, and now you can derive one from the space available: with 521px you get 5 columns, with 259px you get 2. &lt;code&gt;auto-fill&lt;/code&gt; can lay out a similar grid, but it doesn't hand you the number, and here every other property can read &lt;code&gt;--cols&lt;/code&gt; too.&lt;/p&gt;

&lt;p&gt;If you read my note on &lt;a href="https://richi.codes/article/2026-10-20-css-progress-one-number-drives-the-whole-layout" rel="noopener noreferrer"&gt;&lt;code&gt;progress()&lt;/code&gt;&lt;/a&gt;, this will feel familiar. &lt;code&gt;progress()&lt;/code&gt; gives you a 0-to-1 ratio between two values; typed arithmetic is the general tool underneath, and it doesn't clamp or force a range on you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Browser support and gotchas
&lt;/h2&gt;

&lt;p&gt;According to MDN's compatibility data, dividing typed values to get a unitless number works in Chrome 140, Safari 26 and Firefox 158. web.dev's October 2026 roundup lists it as Baseline newly available with that Firefox release.&lt;/p&gt;

&lt;p&gt;Things worth knowing before you use it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unitless divided by a unit is still invalid.&lt;/strong&gt; &lt;code&gt;calc(1000 / 2px)&lt;/code&gt; doesn't parse. The unit has to be on top, or on both sides.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The final type has to be something a property accepts.&lt;/strong&gt; &lt;code&gt;width: calc(200px * 4px)&lt;/code&gt; is invalid, because a squared length is meaningless. Intermediate steps can be squared, though: in my tests, Chromium 151 and WebKit 26.5 accept &lt;code&gt;width: calc(10px * 10px / 1px)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The divisor's unit sets the scale.&lt;/strong&gt; &lt;code&gt;100vw / 1px&lt;/code&gt; and &lt;code&gt;100vw / 1em&lt;/code&gt; are both valid but give very different numbers, and &lt;code&gt;em&lt;/code&gt; depends on the font size where it's resolved.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Feature detection is one line.&lt;/strong&gt; &lt;code&gt;CSS.supports('opacity', 'calc(1px / 1px)')&lt;/code&gt; returns &lt;code&gt;true&lt;/code&gt; only where the division gives a number. In CSS, wrap the typed rules in &lt;code&gt;@supports (opacity: calc(1px / 1px))&lt;/code&gt;. Don't rely on the cascade to fall back: once a value goes through &lt;code&gt;var()&lt;/code&gt;, an unsupported expression doesn't drop the declaration at parse time, it becomes invalid later and you end up with the initial or inherited value. The demo uses the JavaScript check and, without support, writes the same numbers into the custom properties itself. I tested that fallback in Firefox 153, which doesn't have the feature.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to keep an eye on
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Older browsers still in use.&lt;/strong&gt; Baseline newly available means the latest versions of the major browsers; Firefox only got there in October 2026. Keep an &lt;code&gt;@supports&lt;/code&gt; fallback for now.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Patterns built on top.&lt;/strong&gt; Combined with &lt;code&gt;sibling-index()&lt;/code&gt;, container units and &lt;code&gt;round()&lt;/code&gt;, this makes CSS a small calculator for layouts. I expect more fluid-typography and "fit as many as you can" recipes that used to need a &lt;code&gt;ResizeObserver&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Readability.&lt;/strong&gt; A chain of &lt;code&gt;calc()&lt;/code&gt;, &lt;code&gt;round()&lt;/code&gt; and &lt;code&gt;mod()&lt;/code&gt; gets cryptic fast. Naming each step with a registered custom property, as the demo does, keeps it maintainable.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://web.dev/blog/web-platform-10-2026" rel="noopener noreferrer"&gt;New to the web platform in October 2026 — web.dev&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Values_and_units/Using_typed_arithmetic" rel="noopener noreferrer"&gt;Using CSS typed arithmetic — MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/calc" rel="noopener noreferrer"&gt;calc() — MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.chrome.com/release-notes/140" rel="noopener noreferrer"&gt;Chrome 140 release notes — Chrome for Developers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3.org/TR/css-values-4/#calc-type-checking" rel="noopener noreferrer"&gt;CSS Values and Units Module Level 4: type checking — W3C&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://richi.codes/article/2026-11-19-css-typed-arithmetic-turn-any-length-into-a-number?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=crosspost" rel="noopener noreferrer"&gt;richi.codes&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>calc</category>
      <category>responsive</category>
      <category>baseline</category>
    </item>
    <item>
      <title>moveBefore(): move DOM nodes without resetting them</title>
      <dc:creator>richi.codes</dc:creator>
      <pubDate>Wed, 18 Nov 2026 08:30:40 +0000</pubDate>
      <link>https://dev.to/richicodes/movebefore-move-dom-nodes-without-resetting-them-462j</link>
      <guid>https://dev.to/richicodes/movebefore-move-dom-nodes-without-resetting-them-462j</guid>
      <description>&lt;p&gt;&lt;strong&gt;This note has an interactive demo.&lt;/strong&gt; &lt;a href="https://richi.codes/article/2026-11-18-movebefore-move-dom-nodes-without-resetting-them" rel="noopener noreferrer"&gt;Try it in the original&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Moving an element around the DOM has always been a small lie: the browser actually removes it and inserts it again, and everything that lives inside it starts over. &lt;code&gt;Element.moveBefore()&lt;/code&gt; is the first real "move" in the DOM, and it already works in Chrome and Firefox.&lt;/p&gt;

&lt;p&gt;Try the demo above before reading on. The card has three things that hate being moved: an &lt;code&gt;&amp;lt;iframe&amp;gt;&lt;/code&gt; with its own clock, a CSS animation filling a bar, and a text field. Turn on auto-move, type in the field, and switch between &lt;code&gt;moveBefore()&lt;/code&gt; and &lt;code&gt;insertBefore()&lt;/code&gt;. With the first one, the clock keeps counting, the bar keeps filling and your cursor stays where it was. With the second, the iframe reloads, the animation jumps back to zero and focus is gone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a move used to reset everything
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;appendChild()&lt;/code&gt;, &lt;code&gt;insertBefore()&lt;/code&gt;, &lt;code&gt;prepend()&lt;/code&gt; and friends don't have a "move" mode. If the node is already in the document, the browser first takes it out and then puts it back in the new place. For a plain &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; with text you never notice. For anything with state, that removal is destructive. According to MDN, &lt;code&gt;moveBefore()&lt;/code&gt; keeps, among others:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;animation and transition state,&lt;/li&gt;
&lt;li&gt;the loading state of an &lt;code&gt;&amp;lt;iframe&amp;gt;&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;interactivity states such as &lt;code&gt;:focus&lt;/code&gt; and &lt;code&gt;:active&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;the fullscreen element,&lt;/li&gt;
&lt;li&gt;open popovers,&lt;/li&gt;
&lt;li&gt;modal &lt;code&gt;&amp;lt;dialog&amp;gt;&lt;/code&gt; elements (they don't get closed).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Chrome's announcement puts the problem plainly: framework authors spend a lot of effort on workarounds (DOM-morphing libraries, bug reports they can't fix), and users still see application state reset when they don't expect it.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;Same arguments as &lt;code&gt;insertBefore()&lt;/code&gt;: the node to move and the node to place it before, or &lt;code&gt;null&lt;/code&gt; to put it at the end. This is the line the demo runs on every move:&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="c1"&gt;// target is the other dock; null means "at the end"&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;mode&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="s1"&gt;'move'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;supported&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;moveBefore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;widget&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insertBefore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;widget&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&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;It returns &lt;code&gt;undefined&lt;/code&gt; and exists on &lt;code&gt;Element&lt;/code&gt;, &lt;code&gt;Document&lt;/code&gt; and &lt;code&gt;DocumentFragment&lt;/code&gt;. There are a few rules worth knowing, because unlike &lt;code&gt;insertBefore()&lt;/code&gt; it throws in situations you might not expect:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Both the node and the new parent have to be in the same document, and both connected or both disconnected. Moving a freshly created element (not yet in the page) into the page with &lt;code&gt;moveBefore()&lt;/code&gt; throws a &lt;code&gt;HierarchyRequestError&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The second argument is required. &lt;code&gt;parent.moveBefore(node)&lt;/code&gt; throws a &lt;code&gt;TypeError&lt;/code&gt;; pass &lt;code&gt;null&lt;/code&gt; explicitly.&lt;/li&gt;
&lt;li&gt;If the reference node isn't a child of the parent, you get a &lt;code&gt;NotFoundError&lt;/code&gt;, just like &lt;code&gt;insertBefore()&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because of that, and because Safari doesn't have it yet, I'd wrap it in a tiny helper that falls back to the old behaviour:&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;moveNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ref&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'moveBefore'&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;moveBefore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// Not movable (e.g. a node that isn't in the page yet): fall through.&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insertBefore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ref&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;I ran it in Chromium, Firefox and WebKit with Playwright: in the first two a focused input stays focused after the move; in WebKit it falls back to &lt;code&gt;insertBefore()&lt;/code&gt; and loses focus, as expected. A node that isn't in the page yet goes through the &lt;code&gt;catch&lt;/code&gt; and gets inserted normally.&lt;/p&gt;

&lt;h2&gt;
  
  
  Custom elements: connectedMoveCallback()
&lt;/h2&gt;

&lt;p&gt;Here's a catch for web components. A plain move with &lt;code&gt;insertBefore()&lt;/code&gt; fires &lt;code&gt;disconnectedCallback()&lt;/code&gt; and then &lt;code&gt;connectedCallback()&lt;/code&gt;, and since those are where most components set up and tear down, a move can wipe their state. MDN's custom elements guide says &lt;code&gt;moveBefore()&lt;/code&gt; alone doesn't fix that: you also have to define &lt;code&gt;connectedMoveCallback()&lt;/code&gt;. When it exists and you move the element with &lt;code&gt;moveBefore()&lt;/code&gt;, it runs instead of the other two.&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;MovableWidget&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;connectedCallback&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="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'connected'&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="nf"&gt;disconnectedCallback&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="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'disconnected'&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="nf"&gt;connectedMoveCallback&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="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'moved'&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="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;'movable-widget'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;MovableWidget&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;In my test, moving the element with &lt;code&gt;moveBefore()&lt;/code&gt; logged only &lt;code&gt;moved&lt;/code&gt;; moving it back with &lt;code&gt;insertBefore()&lt;/code&gt; logged &lt;code&gt;disconnected&lt;/code&gt; and &lt;code&gt;connected&lt;/code&gt;. An empty &lt;code&gt;connectedMoveCallback()&lt;/code&gt; is enough if all you want is to skip the teardown.&lt;/p&gt;

&lt;h2&gt;
  
  
  Browser support and gotchas
&lt;/h2&gt;

&lt;p&gt;According to MDN's compatibility data, &lt;code&gt;moveBefore()&lt;/code&gt; shipped in Chrome 133 (February 2025) and Firefox 144 (October 2025). Safari doesn't support it: WebKit's tracking bug is still open, with some dependencies pending. That means it isn't Baseline, so feature detection is mandatory:&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;supported&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'moveBefore'&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nc"&gt;Element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other things to keep in mind:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MutationObserver still sees a removal and an addition.&lt;/strong&gt; MDN says so and my test agreed: one move produced one record with a removed node and another with an added node. If your code reacts to "node removed" by cleaning things up, check whether it came back.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It's "most" state, not all of it.&lt;/strong&gt; The Chrome post is careful to say it preserves most state. Test the specific thing you care about.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The fallback is visible.&lt;/strong&gt; In Safari, users get the old reset behaviour. That's fine for progressive enhancement, but don't build a feature that only makes sense if the iframe never reloads.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to keep an eye on
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Safari.&lt;/strong&gt; WebKit bug 281223 is the one to watch; when it closes, &lt;code&gt;moveBefore()&lt;/code&gt; is a candidate for Baseline.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frameworks and libraries.&lt;/strong&gt; Anything that reorders keyed lists or morphs HTML could switch to &lt;code&gt;moveBefore()&lt;/code&gt; where available and stop reloading embeds and losing focus for free.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Your own components.&lt;/strong&gt; If you write custom elements, adding &lt;code&gt;connectedMoveCallback()&lt;/code&gt; now costs nothing and makes them behave in Chrome and Firefox today.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/moveBefore" rel="noopener noreferrer"&gt;Element: moveBefore() method - MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements" rel="noopener noreferrer"&gt;Using custom elements: lifecycle callbacks and state-preserving moves - MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.chrome.com/blog/movebefore-api" rel="noopener noreferrer"&gt;Preserve state during DOM mutations with moveBefore() - Chrome for Developers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dom.spec.whatwg.org/#dom-parentnode-movebefore" rel="noopener noreferrer"&gt;DOM Standard: moveBefore()&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bugs.webkit.org/show_bug.cgi?id=281223" rel="noopener noreferrer"&gt;WebKit bug 281223: Element.moveBefore() API&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://richi.codes/article/2026-11-18-movebefore-move-dom-nodes-without-resetting-them?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=crosspost" rel="noopener noreferrer"&gt;richi.codes&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>dom</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>webcomponents</category>
    </item>
    <item>
      <title>CSS Grid Lanes: native masonry, now in Safari</title>
      <dc:creator>richi.codes</dc:creator>
      <pubDate>Tue, 17 Nov 2026 08:30:40 +0000</pubDate>
      <link>https://dev.to/richicodes/css-grid-lanes-native-masonry-now-in-safari-b5j</link>
      <guid>https://dev.to/richicodes/css-grid-lanes-native-masonry-now-in-safari-b5j</guid>
      <description>&lt;p&gt;&lt;strong&gt;This note has an interactive demo.&lt;/strong&gt; &lt;a href="https://richi.codes/article/2026-11-17-css-grid-lanes-native-masonry-now-in-safari" rel="noopener noreferrer"&gt;Try it in the original&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Masonry layouts, the Pinterest-style wall of cards with different heights, finally have a native CSS value: &lt;code&gt;display: grid-lanes&lt;/code&gt;. Safari ships it, and Safari 27.2 (WebKit's release post is from October 26) just renamed the one property that controls how it behaves. Chrome and Firefox aren't there yet, so this is a good moment to learn how it works and how to use it today without breaking anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it is and why it matters
&lt;/h2&gt;

&lt;p&gt;For years, a masonry wall meant a JavaScript library measuring every card and positioning it absolutely. CSS Grid alone can't do it: rows force every card in a row to share the same height, so short cards leave holes under them. Multi-column layout packs things tightly, but it fills the first column top to bottom before moving to the next, so items 1, 2 and 3 end up stacked on the left instead of reading across.&lt;/p&gt;

&lt;p&gt;Grid Lanes, defined in CSS Grid Layout Level 3, sits in between. One axis is a real grid (your columns), and the other axis is a stacking axis with no rows. MDN sums it up well: "each row of items loads into the column with the most room, causing a tightly packed layout without strict row tracks."&lt;/p&gt;

&lt;p&gt;The demo above lets you switch between &lt;code&gt;grid&lt;/code&gt; and &lt;code&gt;grid-lanes&lt;/code&gt; with the same cards. Watch the board height drop and the gaps disappear.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;This is the whole thing, and it's the same CSS the demo uses:&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;.board&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid-lanes&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;auto-fill&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;minmax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;120px&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1fr&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="nl"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10px&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;You define columns exactly as you would in a normal grid. The browser then places each card, in order, into "whichever grid track is currently the least filled", in the spec's words. Everything you know from Grid still works on the grid axis: &lt;code&gt;grid-column-end: span 2&lt;/code&gt; makes a card cover two columns, and cards with a definite position (&lt;code&gt;grid-column: 2 / 4&lt;/code&gt;) are placed before the rest. If you define &lt;code&gt;grid-template-rows&lt;/code&gt; instead of columns, the layout turns sideways and items flow into rows. There's also &lt;code&gt;inline-grid-lanes&lt;/code&gt; for the inline-level version.&lt;/p&gt;

&lt;h2&gt;
  
  
  fit-tolerance: tightness against order
&lt;/h2&gt;

&lt;p&gt;Here's the subtle part. If the browser always picked the strictly shortest column, a 2 px difference would send card 5 to the far left while card 4 sits on the right, and the reading order would zigzag for no visible benefit. So the spec treats columns whose heights are within a threshold of the shortest one as tied. Among tied columns, the browser takes the first one at or after an "auto-placement cursor", which points just past the previous card. In plain terms: when it doesn't matter much, keep going left to right.&lt;/p&gt;

&lt;p&gt;That threshold is &lt;code&gt;fit-tolerance&lt;/code&gt;:&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;.board&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;fit-tolerance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;normal&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="cm"&gt;/* 1em in grid lanes layout */&lt;/span&gt;
  &lt;span class="nl"&gt;fit-tolerance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;4em&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="cm"&gt;/* tolerate bigger differences, keep more order */&lt;/span&gt;
  &lt;span class="nl"&gt;fit-tolerance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;infinite&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="cm"&gt;/* strictly in order, ignore column heights */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The initial value, &lt;code&gt;normal&lt;/code&gt;, resolves to &lt;code&gt;1em&lt;/code&gt; in grid lanes layout. &lt;code&gt;infinite&lt;/code&gt;, according to the spec, makes items "distribute themselves strictly in order, without considering the length of the tracks at all", which can leave very uneven columns. Move the &lt;code&gt;fit-tolerance&lt;/code&gt; slider in the demo and turn on "Tab order": the line connecting the cards in DOM order gets straighter as the tolerance grows, and the "cards out of turn" counter drops to zero.&lt;/p&gt;

&lt;p&gt;The property used to be called &lt;code&gt;flow-tolerance&lt;/code&gt;. The spec renamed it, and Safari 27.2 adopted &lt;code&gt;fit-tolerance&lt;/code&gt;, keeping &lt;code&gt;flow-tolerance&lt;/code&gt; as a deprecated alias. The 27.2 notes also explain why this matters beyond looks: a higher value keeps consecutive items in neighbouring columns, so keyboard focus moves more predictably.&lt;/p&gt;

&lt;h2&gt;
  
  
  Browser support and gotchas
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Safari&lt;/strong&gt; supports &lt;code&gt;display: grid-lanes&lt;/code&gt; since 26.4, according to MDN's compatibility data, and &lt;code&gt;fit-tolerance&lt;/code&gt; under its new name since 27.2.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Firefox&lt;/strong&gt; has it only in preview builds. &lt;strong&gt;Chrome and Edge&lt;/strong&gt; have no stable support: WebKit's January article said a variant had been behind a flag since version 140 and was being updated to the final syntax. MDN marks the feature as experimental and not Baseline.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The fallback is one extra line.&lt;/strong&gt; Browsers ignore values they don't understand, so declare a normal grid first:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.board&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid-lanes&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;auto-fill&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;minmax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;120px&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1fr&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="nl"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10px&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;Without support you get a regular grid with holes, which is perfectly usable. WebKit also suggests &lt;code&gt;@supports not (display: grid-lanes)&lt;/code&gt; rules to crop images or truncate text so the grid fallback looks tidy, or loading a JavaScript masonry library only when &lt;code&gt;CSS.supports('display', 'grid-lanes')&lt;/code&gt; is false. The demo does a version of the latter: in browsers without support, it runs the spec's placement algorithm in JavaScript. I checked it against WebKit's native rendering (Playwright's WebKit build) at seven tolerances and three column widths, and every card landed in the same spot.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Order and accessibility.&lt;/strong&gt; The spec itself warns that this layout "can switch between endward in the inline or block axis in a seemingly arbitrary manner". Tab order follows the DOM, not the visual position. If the order of your cards carries meaning (a timeline, ranked results), raise &lt;code&gt;fit-tolerance&lt;/code&gt; or pick another layout. The spec points to &lt;code&gt;reading-flow&lt;/code&gt; for content without an inherent order, but that property is currently only in Chromium-based browsers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The spec is still moving.&lt;/strong&gt; The latest published Working Draft is from January 2026, and the Editor's Draft changed again in October. The spec even notes that the property that controls orientation is still to be decided.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to keep an eye on
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;When Chrome and Edge ship the final &lt;code&gt;grid-lanes&lt;/code&gt; syntax, not the flagged prototype. That's the moment this stops being a progressive enhancement and becomes a default.&lt;/li&gt;
&lt;li&gt;Firefox moving it out of preview builds.&lt;/li&gt;
&lt;li&gt;Whether the orientation control and the other open issues in CSS Grid Level 3 change any syntax before then. For now, &lt;code&gt;display: grid-lanes&lt;/code&gt; plus a &lt;code&gt;display: grid&lt;/code&gt; fallback is the safe way to use it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://drafts.csswg.org/css-grid-3/" rel="noopener noreferrer"&gt;CSS Grid Layout Module Level 3 (Editor's Draft)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Grid_layout/Grid_lanes" rel="noopener noreferrer"&gt;Grid lanes layout - MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://webkit.org/blog/18515/webkit-features-for-safari-27-2/" rel="noopener noreferrer"&gt;WebKit Features for Safari 27.2 - WebKit blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://webkit.org/blog/17758/when-will-css-grid-lanes-arrive-how-long-until-we-can-use-it/" rel="noopener noreferrer"&gt;When will CSS Grid Lanes arrive? How long until we can use it? - WebKit blog&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://richi.codes/article/2026-11-17-css-grid-lanes-native-masonry-now-in-safari?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=crosspost" rel="noopener noreferrer"&gt;richi.codes&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>layout</category>
      <category>masonry</category>
      <category>safari</category>
    </item>
    <item>
      <title>Safari may darken your site unless you say so</title>
      <dc:creator>richi.codes</dc:creator>
      <pubDate>Mon, 16 Nov 2026 08:30:41 +0000</pubDate>
      <link>https://dev.to/richicodes/safari-may-darken-your-site-unless-you-say-so-966</link>
      <guid>https://dev.to/richicodes/safari-may-darken-your-site-unless-you-say-so-966</guid>
      <description>&lt;p&gt;&lt;strong&gt;This note has an interactive demo.&lt;/strong&gt; &lt;a href="https://richi.codes/article/2026-11-16-safari-may-darken-your-site-unless-you-say-so" rel="noopener noreferrer"&gt;Try it in the original&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If your site is light and never says a word about dark mode, Safari is about to make that decision for you. On 3 November the WebKit team introduced Adaptive Dark Mode in Safari 27.3 beta: when a user with a dark system turns it on, light pages get repainted in dark colors. The one line that decides whether your page is touched is &lt;code&gt;color-scheme&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The demo above simulates it. Set the system to dark, leave "Nothing" selected and watch the warm, light page turn dark. The photo stays as it was, the black-and-white logo flips, and the &lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt; chart stays bright white in the middle of it all. Then switch to &lt;code&gt;light dark&lt;/code&gt; and the page uses the dark palette its author designed, not one generated for it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Safari actually does
&lt;/h2&gt;

&lt;p&gt;The WebKit post is unusually detailed about the mechanics, so this is worth reading carefully rather than guessing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Who gets transformed.&lt;/strong&gt; Pages that declare dark support with &lt;code&gt;color-scheme: light dark&lt;/code&gt; are left unchanged. For everything else, Safari quickly estimates whether the page is mostly light or mostly dark; pages that are already dark with light text are left alone.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How.&lt;/strong&gt; The core is a color matrix that inverts luminosity while preserving hue, so light backgrounds become dark and dark text becomes light. Text aims for the WCAG 4.5:1 contrast ratio, light CSS gradients are transformed too, and buttons, text over images and hover menus are adjusted so they stay usable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Images.&lt;/strong&gt; Most are left alone. SVG colors are transformed when needed, and for bitmaps Safari looks at the pixel histogram and inverts "simple black-and-white logos".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Things that may break.&lt;/strong&gt; Masks and &lt;code&gt;mix-blend-mode&lt;/code&gt; may be turned off on transformed elements, and &lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt; content is not changed. That is the white chart in the demo: anything you draw in light colors stays light.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The user decides.&lt;/strong&gt; With the system set to dark, Safari offers a preview on a bright site and the user taps "Try".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It isn't the first browser to do this. MDN's &lt;code&gt;color-scheme&lt;/code&gt; page already points to Chrome's Auto Dark Theme on Android as one of the overrides that &lt;code&gt;only&lt;/code&gt; turns off. And the CSS Color Adjustment spec describes exactly this case: when the user prefers a color scheme the author hasn't supported, the user agent overrides it and auto-adjusts the other colors.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix is one declaration
&lt;/h2&gt;

&lt;p&gt;If you already have a dark theme, say so, and say it early. WebKit recommends putting it in the HTML &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; or on &lt;code&gt;:root&lt;/code&gt; rather than adding it later with JavaScript, and MDN suggests putting the meta tag before any CSS to avoid a flash on load:&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;meta&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"color-scheme"&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"light dark"&lt;/span&gt;&lt;span class="nt"&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 css"&gt;&lt;code&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nt"&gt;root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;color-scheme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;light&lt;/span&gt; &lt;span class="n"&gt;dark&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;light-dark&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;#FAF7F2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;#16130F&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="nf"&gt;light-dark&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;#1C1917&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;#F5F0E8&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;That is the palette the demo uses in &lt;code&gt;light dark&lt;/code&gt; mode. &lt;code&gt;light-dark()&lt;/code&gt; returns the first color when the used scheme is light and the second when it is dark, and it only works when &lt;code&gt;color-scheme&lt;/code&gt; allows both. &lt;code&gt;color-scheme&lt;/code&gt; has been Baseline Widely available since January 2022 and &lt;code&gt;light-dark()&lt;/code&gt; has been Baseline since May 2024, so you don't need a fallback for current browsers. The demo still has one: it checks &lt;code&gt;CSS.supports('color', 'light-dark(#000, #fff)')&lt;/code&gt; and switches palettes with an attribute when the check fails.&lt;/p&gt;

&lt;p&gt;If your page needs to stay light (a print-like document, a brand that has never had a dark version), the opt-out is the &lt;code&gt;only&lt;/code&gt; keyword:&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;meta&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"color-scheme"&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"light only"&lt;/span&gt;&lt;span class="nt"&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 css"&gt;&lt;code&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nt"&gt;root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;color-scheme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;light&lt;/span&gt; &lt;span class="n"&gt;only&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;The spec grammar is &lt;code&gt;normal | [ light | dark | &amp;lt;custom-ident&amp;gt; ]+ &amp;amp;&amp;amp; only?&lt;/code&gt;, so &lt;code&gt;light only&lt;/code&gt; and &lt;code&gt;only light&lt;/code&gt; mean the same thing. You can also scope it to a single element (an embedded map, a diagram) instead of the whole page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotchas
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;only&lt;/code&gt; didn't work in Safari 27.3 beta 1.&lt;/strong&gt; WebKit says so in the post and adds that it may change during the beta. Declaring a real dark mode is the path that works today.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Your JavaScript can't see the transformation.&lt;/strong&gt; For privacy, Safari doesn't let pages detect when Adaptive Dark Mode is applied. Reading CSS colors gives the original authored values and images drawn to a canvas render in their original form. The demo's middle readout shows this: the user sees a dark background while your script reads the light one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Partial dark support counts.&lt;/strong&gt; If only some components have dark styles, WebKit suggests putting &lt;code&gt;color-scheme: light dark&lt;/code&gt; on those specific elements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Canvas is on you.&lt;/strong&gt; Neither Safari nor &lt;code&gt;light-dark()&lt;/code&gt; will recolor what you draw. If you declare dark support, redraw charts with colors read from your theme. The demo deliberately doesn't, so you can see the gap in both modes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The simulation is a simulation.&lt;/strong&gt; The demo inverts lightness in OKLCH and keeps hue, which follows WebKit's description, but it's not Safari's algorithm. To see the real thing you need the Safari 27.3 beta.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to keep an eye on
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Whether the &lt;code&gt;only&lt;/code&gt; keyword starts working during the 27.3 betas, and whether the behavior reaches the stable release unchanged.&lt;/li&gt;
&lt;li&gt;How Safari handles &lt;code&gt;prefers-color-scheme&lt;/code&gt; on transformed pages. The post doesn't say, so I wouldn't assume anything.&lt;/li&gt;
&lt;li&gt;Sites that set &lt;code&gt;color-scheme&lt;/code&gt; from JavaScript after load. WebKit explicitly advises against it; if a theme toggle does that today, it's worth adding a static declaration in the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; as well.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://webkit.org/blog/18541/introducing-adaptive-dark-mode/" rel="noopener noreferrer"&gt;Introducing Adaptive Dark Mode – WebKit blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/color-scheme" rel="noopener noreferrer"&gt;color-scheme – MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/light-dark" rel="noopener noreferrer"&gt;light-dark() – MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://drafts.csswg.org/css-color-adjust-1/" rel="noopener noreferrer"&gt;CSS Color Adjustment Module Level 1 – W3C Editor's Draft&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://richi.codes/article/2026-11-16-safari-may-darken-your-site-unless-you-say-so?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=crosspost" rel="noopener noreferrer"&gt;richi.codes&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>darkmode</category>
      <category>safari</category>
      <category>colorscheme</category>
    </item>
    <item>
      <title>data-nosnippet: decide what AI Overviews can quote</title>
      <dc:creator>richi.codes</dc:creator>
      <pubDate>Sun, 15 Nov 2026 08:30:43 +0000</pubDate>
      <link>https://dev.to/richicodes/data-nosnippet-decide-what-ai-overviews-can-quote-1del</link>
      <guid>https://dev.to/richicodes/data-nosnippet-decide-what-ai-overviews-can-quote-1del</guid>
      <description>&lt;p&gt;&lt;strong&gt;This note has an interactive demo.&lt;/strong&gt; &lt;a href="https://richi.codes/article/2026-11-15-data-nosnippet-decide-what-ai-overviews-can-quote" rel="noopener noreferrer"&gt;Try it in the original&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There's no special markup that gets you into Google's AI Overviews, but there is markup that keeps parts of your page out of them. The same snippet controls that have shaped the grey text under a search result for years (&lt;code&gt;nosnippet&lt;/code&gt;, &lt;code&gt;max-snippet&lt;/code&gt; and the &lt;code&gt;data-nosnippet&lt;/code&gt; attribute) now also decide how much of your page Google may use as direct input for AI Overviews and AI Mode. It's one of the few levers that is documented, works per page or per paragraph, and doesn't require blocking a crawler.&lt;/p&gt;

&lt;p&gt;The demo above is a small page with a robots meta tag you can change. Tap a block to give it &lt;code&gt;data-nosnippet&lt;/code&gt;, move the &lt;code&gt;max-snippet&lt;/code&gt; slider, and watch the counter, the search result and the "AI input" box shrink. The fine-print block is a &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;, and that's on purpose: try excluding it and see what happens.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Google actually says
&lt;/h2&gt;

&lt;p&gt;Google's page on AI features is refreshingly blunt: "There are no additional requirements to appear in AI Overviews or AI Mode, nor other special optimizations necessary." It also says there's "no special schema.org structured data that you need to add". What it lists instead are SEO basics: allow crawling, keep important content in text, link it internally, and make sure your structured data matches the visible text.&lt;/p&gt;

&lt;p&gt;The interesting part is the other direction. To limit what's shown from your pages, that same page points you to &lt;code&gt;nosnippet&lt;/code&gt;, &lt;code&gt;data-nosnippet&lt;/code&gt;, &lt;code&gt;max-snippet&lt;/code&gt; and &lt;code&gt;noindex&lt;/code&gt;. And the robots meta tag documentation spells out the AI part:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;nosnippet&lt;/code&gt; applies to "all forms of search results", with AI Overviews and AI Mode named in the list, and it "will also prevent the content from being used as a direct input for AI Overviews and AI Mode".&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;max-snippet:[number]&lt;/code&gt; caps the text snippet at that many characters, and it "will also limit how much of the content may be used as a direct input for AI Overviews and AI Mode". &lt;code&gt;0&lt;/code&gt; means no snippet (the same as &lt;code&gt;nosnippet&lt;/code&gt;) and &lt;code&gt;-1&lt;/code&gt; lets Google choose.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So it's not an AI-only switch. It's your snippet, and AI features now read from the same budget.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;Page-wide rules go in a meta tag (or in an &lt;code&gt;X-Robots-Tag&lt;/code&gt; HTTP header). Partial rules go on the elements themselves:&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;meta&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"robots"&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"max-snippet:120"&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;Basil needs light. &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;data-nosnippet&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Call 555 0142.&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;section&lt;/span&gt; &lt;span class="na"&gt;data-nosnippet&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;The members-only trick: pinch the tips every week.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/section&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;data-nosnippet&lt;/code&gt; is a boolean attribute: any value is ignored, so &lt;code&gt;data-nosnippet="false"&lt;/code&gt; still excludes the text. And it only counts on &lt;code&gt;span&lt;/code&gt;, &lt;code&gt;div&lt;/code&gt; and &lt;code&gt;section&lt;/code&gt;. Google's own example marks a custom element as "NOT VALID: not a span, div, or section", which is why the &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; in the demo turns yellow and doesn't change the count until you convert it to a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The demo models that with a tree walker that collects every text node and skips the ones inside an excluded block:&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="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;SKIP&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'span[data-nosnippet], div[data-nosnippet], section[data-nosnippet]'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;quotableText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;walker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createTreeWalker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;NodeFilter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;SHOW_TEXT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;walker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;nextNode&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;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;walker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;nextNode&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="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;closest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;SKIP&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// inside an excluded block&lt;/span&gt;
    &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s1"&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;return&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;+/&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then &lt;code&gt;nosnippet&lt;/code&gt; or &lt;code&gt;max-snippet:0&lt;/code&gt; leave nothing, and &lt;code&gt;max-snippet:N&lt;/code&gt; keeps the first N characters. I ran this function in Chromium against a page with a &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt;, a &lt;code&gt;&amp;lt;section&amp;gt;&lt;/code&gt;, a &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; and a &lt;code&gt;&amp;lt;div data-nosnippet="false"&amp;gt;&lt;/code&gt;, all excluded: it returned only the plain text plus the &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;, which is exactly the rule from the docs. I also ran the demo in Chromium, Firefox and WebKit, with no console errors.&lt;/p&gt;

&lt;p&gt;Be clear about what this is: a model of the rules, not of Google. Google picks which sentences to show and how many; the demo only shows the upper limit of what you allow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotchas
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;It's not only AI.&lt;/strong&gt; &lt;code&gt;nosnippet&lt;/code&gt; also removes the snippet from regular results, Images and Discover. If you just want shorter AI input, &lt;code&gt;max-snippet&lt;/code&gt; or a targeted &lt;code&gt;data-nosnippet&lt;/code&gt; is the gentler tool.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The HTML has to be valid.&lt;/strong&gt; Google asks for valid HTML with every tag properly closed so the section can be read reliably.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't toggle it with JavaScript.&lt;/strong&gt; Extraction may happen before and after rendering, so Google says not to add or remove &lt;code&gt;data-nosnippet&lt;/code&gt; on existing nodes with JavaScript. Put it in the HTML your server sends. The demo toggles it with JavaScript only because it's a simulation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Structured data inside an excluded block still counts.&lt;/strong&gt; The docs say structured data declared within a &lt;code&gt;data-nosnippet&lt;/code&gt; element remains usable for search results.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Blocking the crawler hides the rules.&lt;/strong&gt; These settings are only read if crawlers are allowed to fetch the page. Disallow it in robots.txt and Google never sees your &lt;code&gt;nosnippet&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Conflicts resolve to the stricter rule.&lt;/strong&gt; With &lt;code&gt;max-snippet:50&lt;/code&gt; and &lt;code&gt;nosnippet&lt;/code&gt; on the same page, &lt;code&gt;nosnippet&lt;/code&gt; wins.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Google-Extended is a different control.&lt;/strong&gt; It covers Gemini training and grounding in Gemini Apps and Vertex AI, and Google says it doesn't affect inclusion in Google Search. It isn't the switch for AI Overviews.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Separate permission overrides the cap.&lt;/strong&gt; The docs note that the &lt;code&gt;max-snippet&lt;/code&gt; limit doesn't apply where a publisher has separately granted permission to use the content.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to keep an eye on
&lt;/h2&gt;

&lt;p&gt;These are Google rules. Other engines and assistants have their own controls, or none, so check each one's documentation before assuming the same markup works there. And watch the robots meta tag page: the AI Overviews and AI Mode wording is what makes &lt;code&gt;max-snippet&lt;/code&gt; matter here, and if Google changes how AI features use content, that's where it will show up first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/search/docs/appearance/ai-features" rel="noopener noreferrer"&gt;AI features and your website (Google Search Central)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag" rel="noopener noreferrer"&gt;Robots meta tag, data-nosnippet and X-Robots-Tag specifications (Google Search Central)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/crawling/docs/crawlers-fetchers/google-common-crawlers" rel="noopener noreferrer"&gt;Google's common crawlers: Google-Extended (Google Crawling Infrastructure)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://richi.codes/article/2026-11-15-data-nosnippet-decide-what-ai-overviews-can-quote?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=crosspost" rel="noopener noreferrer"&gt;richi.codes&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>seo</category>
      <category>html</category>
      <category>aioverviews</category>
    </item>
    <item>
      <title>CSS text-box: text finally centered in its box</title>
      <dc:creator>richi.codes</dc:creator>
      <pubDate>Sat, 14 Nov 2026 08:30:41 +0000</pubDate>
      <link>https://dev.to/richicodes/css-text-box-text-finally-centered-in-its-box-1j6</link>
      <guid>https://dev.to/richicodes/css-text-box-text-finally-centered-in-its-box-1j6</guid>
      <description>&lt;p&gt;&lt;strong&gt;This note has an interactive demo.&lt;/strong&gt; &lt;a href="https://richi.codes/article/2026-11-14-css-text-box-text-finally-centered-in-its-box" rel="noopener noreferrer"&gt;Try it in the original&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You give a button &lt;code&gt;padding: 12px&lt;/code&gt; and the label still looks a little off: more air above the letters than below, or the other way round. It isn't you. It's the font. And there's now a one-line fix that works in Chrome, Safari and Firefox: &lt;code&gt;text-box&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Flip the switch in the demo above and watch the dashed box around "Hxg" collapse onto the cap line and the baseline. The button, the pill and the number below use the same padding top and bottom in both states. Only the trimmed version actually looks centered.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why text is never centered on its own
&lt;/h2&gt;

&lt;p&gt;Every font carries some vertical space beyond the letters themselves: room for accents above the capitals and for descenders like the tail of the "g". On top of that, &lt;code&gt;line-height&lt;/code&gt; adds leading, and CSS splits that extra space in two, half above and half below the text. That's what the Chrome team calls &lt;em&gt;half-leading&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;All of that space counts toward the element's height. So when you put &lt;code&gt;padding: 12px&lt;/code&gt; on a button, the real distance from the top edge to the top of the capitals is 12px plus whatever the font and the line height add. The usual workaround was to hand-tune &lt;code&gt;padding-block&lt;/code&gt; until it looked right, and the Chrome article points out the problem with that: it might look right on one screen or OS and wrong on another, because each font brings a different amount of space.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;text-box&lt;/code&gt; is a shorthand for two properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;text-box-trim&lt;/code&gt; says &lt;strong&gt;which&lt;/strong&gt; edges to trim: &lt;code&gt;none&lt;/code&gt; (the default), &lt;code&gt;trim-start&lt;/code&gt;, &lt;code&gt;trim-end&lt;/code&gt; or &lt;code&gt;trim-both&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;text-box-edge&lt;/code&gt; says &lt;strong&gt;where&lt;/strong&gt; to trim to. The first value is the over edge (&lt;code&gt;text&lt;/code&gt;, &lt;code&gt;cap&lt;/code&gt; or &lt;code&gt;ex&lt;/code&gt;), the second is the under edge (&lt;code&gt;text&lt;/code&gt; or &lt;code&gt;alphabetic&lt;/code&gt;). Its initial value is &lt;code&gt;auto&lt;/code&gt;, which is the same as &lt;code&gt;text&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The combination you'll use most is trimming to the top of the capitals and to the baseline:&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;.btn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;12px&lt;/span&gt; &lt;span class="mi"&gt;18px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;text-box&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;trim-both&lt;/span&gt; &lt;span class="n"&gt;cap&lt;/span&gt; &lt;span class="n"&gt;alphabetic&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;That's exactly what the demo's button does. I measured it in Chromium and WebKit with a 17px bold system font and &lt;code&gt;line-height: 1.4&lt;/code&gt;: the button goes from 52px tall to 40px, and the 12px of padding is now the real gap between the edge and the letters.&lt;/p&gt;

&lt;p&gt;The longhand version is equivalent:&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;.pill&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;text-box-trim&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;trim-both&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;text-box-edge&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cap&lt;/span&gt; &lt;span class="n"&gt;alphabetic&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;One thing I checked because it's easy to get wrong: &lt;code&gt;text-box-edge&lt;/code&gt; on its own does nothing. MDN says it has no effect if &lt;code&gt;text-box-trim&lt;/code&gt; isn't set or is &lt;code&gt;none&lt;/code&gt;, and in my test a button with only &lt;code&gt;text-box-edge: cap alphabetic&lt;/code&gt; stayed at 52px.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;ex&lt;/code&gt; value trims to the x-height instead of the capitals. Try it in the demo: the box shrinks to the height of the "x", which is handy for lowercase-only labels or for aligning text with a small icon.&lt;/p&gt;

&lt;h2&gt;
  
  
  Support and gotchas
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Support&lt;/strong&gt;: Chrome and Edge 133, Safari 18.2 and Firefox 154, released on August 18, 2026. MDN marks it as Baseline 2026, newly available.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Older browsers just ignore it.&lt;/strong&gt; Nothing breaks; you get today's spacing. Detect it with &lt;code&gt;CSS.supports('text-box', 'trim-both cap alphabetic')&lt;/code&gt; or &lt;code&gt;@supports&lt;/code&gt;. The Firefox build I used for testing predates 154, so the demo showed its warning there and faked the trim with negative margins computed from canvas text metrics. That's fine for a demo, not something I'd ship.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It depends on the font.&lt;/strong&gt; The same values trim different amounts with different fonts. Switch between sans, serif and mono in the demo and watch the box height change.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Descenders stick out.&lt;/strong&gt; With &lt;code&gt;alphabetic&lt;/code&gt; the box ends at the baseline, so the tail of the "g" overflows below it. That's intentional, but it means anything painted only inside the box, like a background clipped to the text, gets cut off. It happened to me in the first version of the demo with a gradient set via &lt;code&gt;background-clip: text&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-line text&lt;/strong&gt; is trimmed above the first line and below the last one, not between lines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Where it applies&lt;/strong&gt;: block containers and inline boxes. It isn't inherited, so set it on the element whose box you want to tighten.&lt;/li&gt;
&lt;li&gt;It used to be called &lt;code&gt;leading-trim&lt;/code&gt;, in case you find old articles.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to keep an eye on
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The extra edge values.&lt;/strong&gt; The grammar also includes &lt;code&gt;ideographic&lt;/code&gt; and &lt;code&gt;ideographic-ink&lt;/code&gt;. MDN doesn't describe them yet, so check support before relying on them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Your own components.&lt;/strong&gt; It's worth reviewing buttons, badges and tags where block padding was hand-tuned to compensate for the font: some of those magic numbers can now go.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The real-world baseline.&lt;/strong&gt; Firefox 154 is recent. Until older versions fade out, think of it as progressive enhancement.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/text-box" rel="noopener noreferrer"&gt;text-box - CSS | MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/text-box-trim" rel="noopener noreferrer"&gt;text-box-trim - CSS | MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/text-box-edge" rel="noopener noreferrer"&gt;text-box-edge - CSS | MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.chrome.com/blog/css-text-box-trim" rel="noopener noreferrer"&gt;CSS text-box-trim | Chrome for Developers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/154" rel="noopener noreferrer"&gt;Firefox 154 release notes for developers | MDN&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://richi.codes/article/2026-11-14-css-text-box-text-finally-centered-in-its-box?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=crosspost" rel="noopener noreferrer"&gt;richi.codes&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>typography</category>
      <category>ui</category>
      <category>baseline</category>
    </item>
    <item>
      <title>Customizable &lt;select&gt;: now in Chrome and Safari</title>
      <dc:creator>richi.codes</dc:creator>
      <pubDate>Fri, 13 Nov 2026 08:30:42 +0000</pubDate>
      <link>https://dev.to/richicodes/customizable-now-in-chrome-and-safari-3ck1</link>
      <guid>https://dev.to/richicodes/customizable-now-in-chrome-and-safari-3ck1</guid>
      <description>&lt;p&gt;&lt;strong&gt;This note has an interactive demo.&lt;/strong&gt; &lt;a href="https://richi.codes/article/2026-11-13-customizable-select-now-in-chrome-and-safari" rel="noopener noreferrer"&gt;Try it in the original&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;select&amp;gt;&lt;/code&gt; you can finally style is no longer a Chrome-only experiment. Safari 27, released on September 14, 2026, added "the customizable &lt;code&gt;&amp;lt;select&amp;gt;&lt;/code&gt; element, allowing custom styling with &lt;code&gt;appearance: base-select&lt;/code&gt; and custom content with the &lt;code&gt;&amp;lt;selectedcontent&amp;gt;&lt;/code&gt; HTML element". Chrome has shipped it since version 135. So two of the three big engines now give you a real &lt;code&gt;&amp;lt;select&amp;gt;&lt;/code&gt;, with real keyboard support and real form behavior, that you can design like any other component.&lt;/p&gt;

&lt;p&gt;Open the demo above and pick a theme. The colored circles, the two-line options, the checkmark, the rotating arrow and the picker that fades in are all one native &lt;code&gt;&amp;lt;select&amp;gt;&lt;/code&gt;. Then tick "Remove base-select": the same HTML falls back to the classic control, and the whole page still works.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this matters
&lt;/h2&gt;

&lt;p&gt;For twenty years the answer to "can I style this dropdown?" was "rebuild it in JavaScript". That meant a &lt;code&gt;div&lt;/code&gt; pretending to be a listbox, your own keyboard handling, your own ARIA, and a form field that no longer submitted by itself. The customizable select keeps the native element and only opens up its insides. As Chrome's announcement puts it, it's "accessible, standardized and CSS styleable".&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;You opt in with one CSS property, on the select and on its picker:&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;select&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="nf"&gt;picker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;select&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;appearance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;base-select&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;MDN notes you can opt in the select alone, but you "can't opt-in the picker without opting in the &lt;code&gt;&amp;lt;select&amp;gt;&lt;/code&gt; element".&lt;/p&gt;

&lt;p&gt;Then the HTML can carry more than text. A &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; as the first child becomes the closed control, and &lt;code&gt;&amp;lt;selectedcontent&amp;gt;&lt;/code&gt; inside it shows a copy of the chosen option:&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;select&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"theme"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&amp;lt;selectedcontent&amp;gt;&amp;lt;/selectedcontent&amp;gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"ember"&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="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"swatch"&lt;/span&gt; &lt;span class="na"&gt;aria-hidden&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/span&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="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"txt"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;span&amp;gt;&lt;/span&gt;Ember&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;small&amp;gt;&lt;/span&gt;richi.codes orange&lt;span class="nt"&gt;&amp;lt;/small&amp;gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- more options --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/select&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each option in the demo is exactly that: a decorative circle plus a name and a short description.&lt;/p&gt;

&lt;p&gt;The parts you style are new pseudo-elements and pseudo-classes:&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;/* the arrow, and how it turns while open */&lt;/span&gt;
&lt;span class="nt"&gt;select&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nt"&gt;picker-icon&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;rotate&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;3s&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;select&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nt"&gt;open&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nt"&gt;picker-icon&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;180deg&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/* the selected option and its checkmark */&lt;/span&gt;
&lt;span class="nt"&gt;option&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nt"&gt;checked&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;color-mix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;oklab&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;--sa&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="kt"&gt;%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;transparent&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="nt"&gt;option&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nt"&gt;checkmark&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;margin-left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"✓"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/* the clone in the closed button: hide the description */&lt;/span&gt;
&lt;span class="nt"&gt;selectedcontent&lt;/span&gt; &lt;span class="nt"&gt;small&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;none&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;The picker is a popover in the top layer, so it animates like one. This is the entry animation from the demo, with &lt;code&gt;@starting-style&lt;/code&gt; for the first frame:&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="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nf"&gt;picker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;select&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;translateY&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;-8px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;96&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;opacity&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;25s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;transform&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;35s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
              &lt;span class="n"&gt;overlay&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;35s&lt;/span&gt; &lt;span class="n"&gt;allow-discrete&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;display&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;35s&lt;/span&gt; &lt;span class="n"&gt;allow-discrete&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;select&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nt"&gt;open&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nf"&gt;picker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;select&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;@starting-style&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;select&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nl"&gt;open&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nf"&gt;picker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;select&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;translateY&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;-8px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;96&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's also implicitly anchored to the button, so you can nudge it with &lt;code&gt;anchor()&lt;/code&gt; if you need to.&lt;/p&gt;

&lt;h2&gt;
  
  
  Browser support and gotchas
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Chrome 135+ and Safari 27, not Firefox yet.&lt;/strong&gt; MDN's compatibility data lists &lt;code&gt;appearance: base-select&lt;/code&gt; in Firefox 149 only behind two preferences, and &lt;code&gt;&amp;lt;selectedcontent&amp;gt;&lt;/code&gt; and &lt;code&gt;::picker(select)&lt;/code&gt; aren't there. MDN marks it as limited availability, not Baseline.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The fallback is the classic select.&lt;/strong&gt; Without support, the browser ignores the button and keeps the options as plain text. Wrap your styles in &lt;code&gt;@supports (appearance: base-select)&lt;/code&gt; so the classic control isn't half-styled. The demo does that and also rewrites the option text as "Ember · richi.codes orange" in the fallback, so the name and description don't run together.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WebKit's golden rule.&lt;/strong&gt; The WebKit team's advice is to "always provide text content or accessible text attributes for your &lt;code&gt;option&lt;/code&gt; elements". Icons go with &lt;code&gt;aria-hidden="true"&lt;/code&gt; or &lt;code&gt;alt=""&lt;/code&gt;, and the meaning lives in text. MDN adds that &lt;code&gt;::checkmark&lt;/code&gt; and &lt;code&gt;::picker-icon&lt;/code&gt; aren't in the accessibility tree, so whatever you put in their &lt;code&gt;content&lt;/code&gt; isn't announced.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The value can change if you skip &lt;code&gt;value&lt;/code&gt;.&lt;/strong&gt; Without a &lt;code&gt;value&lt;/code&gt; attribute, the select's value is the option's trimmed &lt;code&gt;textContent&lt;/code&gt;. Add a description inside the option and your submitted value changes too. I checked it in Chromium and WebKit with a bare &lt;code&gt;&amp;lt;option&amp;gt;&lt;/code&gt;: the value followed the text. Chrome's post says it plainly: options that use the &lt;code&gt;value&lt;/code&gt; attribute are unaffected.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;&amp;lt;selectedcontent&amp;gt;&lt;/code&gt; goes stale.&lt;/strong&gt; It copies the option when the selection changes, and only then. In Chromium and WebKit I changed an option's text after loading: the button kept the old text until I selected again. The demo hits this itself. It translates the options into English after the page has parsed, so it re-selects the current option to refresh the copy. Frameworks that re-render options need to do the same.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The clone doesn't bring the option's styles.&lt;/strong&gt; In the demo, each option's colors live in custom properties on the &lt;code&gt;&amp;lt;option&amp;gt;&lt;/code&gt;. The copy inside &lt;code&gt;&amp;lt;selectedcontent&amp;gt;&lt;/code&gt; lives elsewhere in the tree and doesn't inherit them, so its circle takes the active theme's colors from the root instead.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Native behaviors you give up.&lt;/strong&gt; Chrome lists them: the select doesn't render outside the browser pane, it doesn't trigger the mobile operating system's own components, and it stops taking the width of the longest option.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to keep an eye on
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Firefox: the work is behind preferences. When it ships, this becomes Baseline and you can drop most plan B code.&lt;/li&gt;
&lt;li&gt;Framework support. MDN warns that some frameworks block these features and others hit hydration errors with server-side rendering.&lt;/li&gt;
&lt;li&gt;More "base" form controls. Chrome's post says there are more "base" elements yet to be completed. This is just the first one.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Forms/Customizable_select" rel="noopener noreferrer"&gt;Customizable select elements | MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/selectedcontent" rel="noopener noreferrer"&gt;&lt;code&gt;&amp;lt;selectedcontent&amp;gt;&lt;/code&gt; | MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.chrome.com/blog/a-customizable-select" rel="noopener noreferrer"&gt;The &lt;code&gt;&amp;lt;select&amp;gt;&lt;/code&gt; element can now be customized with CSS | Chrome for Developers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.apple.com/documentation/safari-release-notes/safari-27-release-notes" rel="noopener noreferrer"&gt;Safari 27 Release Notes | Apple Developer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://webkit.org/blog/18117/the-golden-rule-of-customizable-select/" rel="noopener noreferrer"&gt;The golden rule of Customizable Select | WebKit&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://richi.codes/article/2026-11-13-customizable-select-now-in-chrome-and-safari?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=crosspost" rel="noopener noreferrer"&gt;richi.codes&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
      <category>select</category>
      <category>forms</category>
    </item>
    <item>
      <title>CSS corner-shape: squircles, scoops and notches</title>
      <dc:creator>richi.codes</dc:creator>
      <pubDate>Thu, 12 Nov 2026 08:30:42 +0000</pubDate>
      <link>https://dev.to/richicodes/css-corner-shape-squircles-scoops-and-notches-1fmd</link>
      <guid>https://dev.to/richicodes/css-corner-shape-squircles-scoops-and-notches-1fmd</guid>
      <description>&lt;p&gt;&lt;strong&gt;This note has an interactive demo.&lt;/strong&gt; &lt;a href="https://richi.codes/article/2026-11-12-css-corner-shape-squircles-scoops-and-notches" rel="noopener noreferrer"&gt;Try it in the original&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since it arrived, &lt;code&gt;border-radius&lt;/code&gt; has given us exactly one kind of corner: a quarter of an ellipse. &lt;code&gt;corner-shape&lt;/code&gt; changes that. You keep &lt;code&gt;border-radius&lt;/code&gt; for the &lt;em&gt;size&lt;/em&gt; of the corner and add one property for its &lt;em&gt;shape&lt;/em&gt;: squircle, bevel, scoop, notch, or anything in between. Borders, outlines and shadows follow the new outline, and the browser can animate from one shape to another.&lt;/p&gt;

&lt;p&gt;Play with the demo above first. Press the chips, drag the K slider, then hit "Morph between shapes". Watch the teal border and the glow: they're not a separate layer, they bend with the box.&lt;/p&gt;

&lt;h2&gt;
  
  
  Size from border-radius, shape from corner-shape
&lt;/h2&gt;

&lt;p&gt;The property doesn't replace &lt;code&gt;border-radius&lt;/code&gt;, it builds on it. MDN puts it plainly: "If a &lt;code&gt;border-radius&lt;/code&gt; is not applied to a container, or the &lt;code&gt;border-radius&lt;/code&gt; resolves to &lt;code&gt;0&lt;/code&gt;, &lt;code&gt;corner-shape&lt;/code&gt; will have no effect."&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;.card&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;56px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="cm"&gt;/* how big the corner is */&lt;/span&gt;
  &lt;span class="nl"&gt;corner-shape&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;scoop&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="cm"&gt;/* what the corner looks like */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's the whole of the demo's main shape. The keywords are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;square&lt;/code&gt; = &lt;code&gt;superellipse(infinity)&lt;/code&gt;: a normal square corner.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;squircle&lt;/code&gt; = &lt;code&gt;superellipse(2)&lt;/code&gt;: between round and square, the app-icon look.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;round&lt;/code&gt; = &lt;code&gt;superellipse(1)&lt;/code&gt;: today's &lt;code&gt;border-radius&lt;/code&gt;, and the initial value.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;bevel&lt;/code&gt; = &lt;code&gt;superellipse(0)&lt;/code&gt;: a straight diagonal cut.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;scoop&lt;/code&gt; = &lt;code&gt;superellipse(-1)&lt;/code&gt;: a concave quarter circle bitten out.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;notch&lt;/code&gt; = &lt;code&gt;superellipse(-infinity)&lt;/code&gt;: a concave 90° step.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because the initial value is &lt;code&gt;round&lt;/code&gt;, adding &lt;code&gt;corner-shape&lt;/code&gt; to an existing design changes nothing until you pick another shape.&lt;/p&gt;

&lt;h2&gt;
  
  
  What superellipse(K) really means
&lt;/h2&gt;

&lt;p&gt;Every keyword is a point on one continuous scale. The spec defines &lt;code&gt;superellipse(K)&lt;/code&gt; as a quarter of a superellipse "using an exponent of 2^K". A superellipse is the curve &lt;code&gt;|x|^n + |y|^n = 1&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With K = 1, n = 2 and you get a circle: &lt;code&gt;round&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;With K = 2, n = 4: the flatter-sided &lt;code&gt;squircle&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;With K = 0, n = 1: a straight line, &lt;code&gt;bevel&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Negative K mirrors the curve inwards, so &lt;code&gt;superellipse(-1)&lt;/code&gt; is a concave circle, &lt;code&gt;scoop&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's what the small corner plot in the demo draws. It's the same formula I use in the fallback (more on that below): each corner is sampled from the parametric superellipse &lt;code&gt;x = cos(t)^(2/n)&lt;/code&gt;, &lt;code&gt;y = sin(t)^(2/n)&lt;/code&gt; and mirrored inwards when K is negative.&lt;/p&gt;

&lt;p&gt;You can also mix shapes per corner, with the same clockwise order as &lt;code&gt;border-radius&lt;/code&gt; (top-left, top-right, bottom-right, bottom-left):&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;.launch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;14px&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="cm"&gt;/* only top-left and bottom-right */&lt;/span&gt;
  &lt;span class="nl"&gt;corner-shape&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;notch&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.tag&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;32px&lt;/span&gt; &lt;span class="mi"&gt;32px&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;corner-shape&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;bevel&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="cm"&gt;/* the right side becomes an arrow */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Those are two of the four small pieces at the bottom of the demo. There are longhands too: &lt;code&gt;corner-top-left-shape&lt;/code&gt;, logical ones like &lt;code&gt;corner-start-start-shape&lt;/code&gt;, and per-side shorthands like &lt;code&gt;corner-top-shape&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Borders, shadows and animation come with it
&lt;/h2&gt;

&lt;p&gt;This is what makes it more than a &lt;code&gt;clip-path&lt;/code&gt; trick. According to MDN, background, border, outline, &lt;code&gt;box-shadow&lt;/code&gt;, &lt;code&gt;overflow&lt;/code&gt; and &lt;code&gt;backdrop-filter&lt;/code&gt; all follow the corner shape. A clip-path just cuts pixels away, so a border gets sliced and a shadow disappears.&lt;/p&gt;

&lt;p&gt;There's one nuance in the spec: the inner edge of the border follows the outer curve at a nearly constant distance, but &lt;code&gt;box-shadow&lt;/code&gt; doesn't trace the path exactly. It "scales the corner-shape path in an axis-aligned manner". With big spreads you may see a small difference.&lt;/p&gt;

&lt;p&gt;It also animates:&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;.card&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;corner-shape&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;9s&lt;/span&gt; &lt;span class="nf"&gt;cubic-bezier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&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;The browser interpolates the K parameter, not the keyword. The spec doesn't move K linearly, though. Going from &lt;code&gt;bevel&lt;/code&gt; (0) to &lt;code&gt;round&lt;/code&gt; (1) to &lt;code&gt;square&lt;/code&gt; (infinity) linearly would start fast and crawl at the end, so the spec maps K onto a 0–1 scale first. I checked it in Chromium: 400 ms into a one-second linear transition from &lt;code&gt;round&lt;/code&gt; to &lt;code&gt;notch&lt;/code&gt;, &lt;code&gt;getComputedStyle&lt;/code&gt; reports &lt;code&gt;superellipse(-0.327908)&lt;/code&gt;, a real in-between shape rather than a jump.&lt;/p&gt;

&lt;h2&gt;
  
  
  Browser support and gotchas
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Only Chromium so far.&lt;/strong&gt; The Chrome 139 release notes list "Corner shaping (&lt;code&gt;corner-shape&lt;/code&gt;, &lt;code&gt;superellipse&lt;/code&gt;, &lt;code&gt;squircle&lt;/code&gt;)", and webstatus.dev shows it in Chrome and Edge since August 2025. Firefox and Safari don't have it yet, so it's far from Baseline.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The fallback is free if round is acceptable.&lt;/strong&gt; In a browser without support, &lt;code&gt;corner-shape&lt;/code&gt; is ignored and &lt;code&gt;border-radius&lt;/code&gt; still draws round corners. For a squircle button that's a perfectly fine degradation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Concave shapes need a plan B.&lt;/strong&gt; If your design depends on a scoop or notch (a ticket, a sci-fi frame), round corners aren't the same thing. Detect support with &lt;code&gt;@supports (corner-shape: squircle)&lt;/code&gt; or &lt;code&gt;CSS.supports('corner-shape', 'squircle')&lt;/code&gt;. The demo then computes the same superellipse as a &lt;code&gt;clip-path: polygon()&lt;/code&gt; and shows a notice. It's honest about the trade-off: in Firefox and Safari the shape is right, but the border and shadow no longer follow it, so the demo swaps the shadow for a &lt;code&gt;drop-shadow()&lt;/code&gt; filter on a wrapper.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Opposite corners can collide.&lt;/strong&gt; With large radii and concave shapes, MDN notes that "the browser constrains the values to prevent the overlap", so the result may be smaller than what you asked for.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Content isn't reshaped.&lt;/strong&gt; Text and hover areas still belong to the rectangular box. Leave padding near notched or scooped corners.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to keep an eye on
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Whether Firefox and Safari pick up &lt;code&gt;corner-shape&lt;/code&gt;. Until they do, use it as an enhancement on top of &lt;code&gt;border-radius&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The rest of CSS Borders Level 4, where this lives. It's an Editor's Draft that also covers &lt;code&gt;border-shape&lt;/code&gt; and partial borders, so details may still change.&lt;/li&gt;
&lt;li&gt;Design tools exporting squircles. Since &lt;code&gt;superellipse()&lt;/code&gt; takes any number, a design system can now name its exact corner curve in CSS instead of shipping an SVG mask.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/corner-shape" rel="noopener noreferrer"&gt;corner-shape - CSS | MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://drafts.csswg.org/css-borders-4/" rel="noopener noreferrer"&gt;CSS Borders and Box Decorations Module Level 4 (Editor's Draft)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.chrome.com/release-notes/139" rel="noopener noreferrer"&gt;Chrome 139 release notes | Chrome for Developers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://webstatus.dev/features/corner-shape" rel="noopener noreferrer"&gt;corner-shape | Web Platform Status&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://richi.codes/article/2026-11-12-css-corner-shape-squircles-scoops-and-notches?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=crosspost" rel="noopener noreferrer"&gt;richi.codes&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>cornershape</category>
      <category>borderradius</category>
      <category>ui</category>
    </item>
    <item>
      <title>Scoped custom element registries end tag clashes</title>
      <dc:creator>richi.codes</dc:creator>
      <pubDate>Wed, 11 Nov 2026 08:30:42 +0000</pubDate>
      <link>https://dev.to/richicodes/scoped-custom-element-registries-end-tag-clashes-bm0</link>
      <guid>https://dev.to/richicodes/scoped-custom-element-registries-end-tag-clashes-bm0</guid>
      <description>&lt;p&gt;&lt;strong&gt;This note has an interactive demo.&lt;/strong&gt; &lt;a href="https://richi.codes/article/2026-11-11-scoped-custom-element-registries-end-tag-clashes" rel="noopener noreferrer"&gt;Try it in the original&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Two libraries can now define the same custom element name on one page without breaking each other. Scoped custom element registries became Baseline on 27 October 2026, when Firefox 159 shipped them. Chrome and Edge 146 and Safari 26 already had them.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem: one name, one page
&lt;/h2&gt;

&lt;p&gt;Every custom element you've ever registered went into the same place: &lt;code&gt;window.customElements&lt;/code&gt;, the global registry. Names in it have to be unique across the whole page. MDN describes the result: if two libraries both try to define &lt;code&gt;&amp;lt;my-button&amp;gt;&lt;/code&gt;, one of them fails.&lt;/p&gt;

&lt;p&gt;You can see it in the demo above. Switch it to "Global registry": Ember UI calls &lt;code&gt;customElements.define('ui-button', …)&lt;/code&gt; first and wins. When Tide UI tries the same thing, the browser throws a &lt;code&gt;NotSupportedError&lt;/code&gt;, and the log shows the real message from your browser. Tide UI's button then renders with Ember UI's class, because there's only one &lt;code&gt;ui-button&lt;/code&gt; on the page. That's an orange pill where a teal one should be.&lt;/p&gt;

&lt;p&gt;So far the fix has been social, not technical: prefix every tag (&lt;code&gt;&amp;lt;ember-button&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;tide-button&amp;gt;&lt;/code&gt;) and hope nobody else picks the same prefix. That gets harder when the same page loads two versions of one design system, which can happen with micro-frontends.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: a registry per shadow root
&lt;/h2&gt;

&lt;p&gt;Now you can create as many registries as you want with &lt;code&gt;new CustomElementRegistry()&lt;/code&gt; and attach each one to a shadow root. MDN explains that definitions in a scoped registry aren't added to the global one. They only apply to the nodes linked to that registry. This is the core of the demo's "Scoped registries" mode:&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;registryA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CustomElementRegistry&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;registryA&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;'ui-button'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;EmberButton&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;registryB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CustomElementRegistry&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;registryB&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;'ui-button'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;TideButton&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;shadowA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;emberHost&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="n"&gt;customElementRegistry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;registryA&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;shadowA&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="s1"&gt;'&amp;lt;ui-button&amp;gt;&amp;lt;/ui-button&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// EmberButton&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;shadowB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tideHost&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="n"&gt;customElementRegistry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;registryB&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;shadowB&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="s1"&gt;'&amp;lt;ui-button&amp;gt;&amp;lt;/ui-button&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// TideButton&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;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ui-button'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// undefined: the global registry stays clean&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same tag now has two classes, two looks and two behaviours, and the global registry doesn't know about either. The demo's log checks this live: &lt;code&gt;shadowA.customElementRegistry === registryA&lt;/code&gt; returns &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Attaching the registry later
&lt;/h2&gt;

&lt;p&gt;You don't always have the registry ready when the shadow root is created. You can pass &lt;code&gt;customElementRegistry: null&lt;/code&gt;, add your markup, and connect the registry later with &lt;code&gt;initialize()&lt;/code&gt;. That's the "Lazy island" panel in the demo:&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;island&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;islandHost&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="n"&gt;customElementRegistry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&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;island&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="s1"&gt;'&amp;lt;ui-button&amp;gt;&amp;lt;/ui-button&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// still :not(:defined)&lt;/span&gt;

&lt;span class="n"&gt;registryB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;island&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// now it's a TideButton&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Until you call &lt;code&gt;initialize()&lt;/code&gt;, the island's &lt;code&gt;&amp;lt;ui-button&amp;gt;&lt;/code&gt; elements exist in the DOM but nobody upgrades them, so CSS can target them with &lt;code&gt;:not(:defined)&lt;/code&gt;. In the demo, that's the dashed box. Press the button and they upgrade on the spot.&lt;/p&gt;

&lt;p&gt;The same idea works without JavaScript creating the shadow root. With declarative shadow DOM, the &lt;code&gt;shadowrootcustomelementregistry&lt;/code&gt; attribute on the &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt; tells the parser to leave the registry empty. Chrome's article points out that this attribute alone does nothing more: you still have to define the elements and call &lt;code&gt;initialize()&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;my-host&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;template&lt;/span&gt; &lt;span class="na"&gt;shadowrootmode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"open"&lt;/span&gt; &lt;span class="na"&gt;shadowrootcustomelementregistry&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ui-button&amp;gt;&amp;lt;/ui-button&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;/my-host&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There's also a version for single elements: &lt;code&gt;document.createElement('ui-button', { customElementRegistry: registryA })&lt;/code&gt;. According to Chrome, an element created this way keeps using that registry wherever you insert it later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotchas
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No fallback to the global registry.&lt;/strong&gt; I tested this in Chromium 151. In a shadow root with a scoped registry, a tag that only exists globally stays undefined. Each library has to define every element it uses inside its own registry.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Feature-detect by constructing, not by checking for the class.&lt;/strong&gt; In the Firefox and WebKit builds I tested with, &lt;code&gt;CustomElementRegistry&lt;/code&gt; exists (it's the type of &lt;code&gt;window.customElements&lt;/code&gt;), but &lt;code&gt;new CustomElementRegistry()&lt;/code&gt; throws &lt;code&gt;TypeError: Illegal constructor&lt;/code&gt;. The WebKit build even has &lt;code&gt;initialize&lt;/code&gt; on the prototype. The demo uses this check:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;supportsScoped&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CustomElementRegistry&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;supportsScoped&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&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;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use a fresh class for each definition.&lt;/strong&gt; Firefox and WebKit refuse to register the same constructor under two names in the global registry. The demo creates a new class each time it calls &lt;code&gt;define()&lt;/code&gt;, so its fallback doesn't break.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;There's no clean fallback.&lt;/strong&gt; If a browser doesn't support scoped registries, you're back to renaming tags. That's what the demo does in that case, with a visible warning.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Browser support
&lt;/h2&gt;

&lt;p&gt;According to &lt;a href="https://webstatus.dev/features/scoped-custom-element-registries" rel="noopener noreferrer"&gt;webstatus.dev&lt;/a&gt;, it works in Chrome and Edge 146, Firefox 159 and Safari 26, and it's been Baseline Newly available since 27 October 2026. Firefox 159's release notes also list the &lt;code&gt;customElementRegistry&lt;/code&gt; property on &lt;code&gt;Document&lt;/code&gt;, &lt;code&gt;Element&lt;/code&gt; and &lt;code&gt;ShadowRoot&lt;/code&gt;. Because it's so new, anyone who hasn't updated Firefox in the last two weeks will hit the fallback.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to keep an eye on
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Libraries adopting it.&lt;/strong&gt; The feature only pays off once component libraries let you pass a registry in, or create their own scoped registries, instead of calling &lt;code&gt;customElements.define()&lt;/code&gt; when they're imported.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Firefox stragglers.&lt;/strong&gt; Firefox 159 is days old. Check your analytics before you remove a prefix-based fallback.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Server-rendered components.&lt;/strong&gt; The declarative &lt;code&gt;shadowrootcustomelementregistry&lt;/code&gt; path is the one to watch if you render shadow DOM on the server.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements" rel="noopener noreferrer"&gt;Using custom elements: Scoped custom element registries (MDN)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/CustomElementRegistry" rel="noopener noreferrer"&gt;CustomElementRegistry() constructor (MDN)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.chrome.com/blog/scoped-registries" rel="noopener noreferrer"&gt;Scoped custom element registries (Chrome for Developers)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/159" rel="noopener noreferrer"&gt;Firefox 159 release notes for developers (MDN)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://webkit.org/blog/17333/webkit-features-in-safari-26-0/" rel="noopener noreferrer"&gt;WebKit features in Safari 26.0 (WebKit blog)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://richi.codes/article/2026-11-11-scoped-custom-element-registries-end-tag-clashes?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=crosspost" rel="noopener noreferrer"&gt;richi.codes&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webcomponents</category>
      <category>html</category>
      <category>javascript</category>
      <category>baseline</category>
    </item>
    <item>
      <title>Your app isn't frozen, it's buffering</title>
      <dc:creator>richi.codes</dc:creator>
      <pubDate>Tue, 10 Nov 2026 08:30:42 +0000</pubDate>
      <link>https://dev.to/richicodes/your-app-isnt-frozen-its-buffering-2f1d</link>
      <guid>https://dev.to/richicodes/your-app-isnt-frozen-its-buffering-2f1d</guid>
      <description>&lt;p&gt;&lt;strong&gt;This note has an interactive demo.&lt;/strong&gt; &lt;a href="https://richi.codes/article/2026-11-10-your-app-isnt-frozen-its-buffering" rel="noopener noreferrer"&gt;Try it in the original&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The window looked frozen, but the program was working the whole time. It just had no way of saying so.&lt;/p&gt;

&lt;p&gt;The job was to take a command-line calculation engine that worked fine in the hands of the person who wrote it, and turn it into an application other people could install and use on macOS, Windows and Linux. I put a graphical interface on top of the original engine, running it as a child process. That's where the interesting problems showed up.&lt;/p&gt;

&lt;p&gt;The demo above recreates the first one. Press &lt;strong&gt;Run calculation&lt;/strong&gt; with both switches off: that's how the original program behaved. Then turn the switches on one by one.&lt;/p&gt;

&lt;h2&gt;
  
  
  "It's hung"
&lt;/h2&gt;

&lt;p&gt;Launch a long calculation and the window seemed to freeze. There were two separate causes, and they looked identical from the outside.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The engine was waiting for a keyboard answer.&lt;/strong&gt; In a terminal that was normal: it asked a question, you typed &lt;code&gt;y&lt;/code&gt;, and it carried on. Launched from the interface, nobody could answer, so it waited forever. &lt;code&gt;input()&lt;/code&gt; reads a line from standard input and only gives up when it hits end of file, at which point it raises &lt;code&gt;EOFError&lt;/code&gt;. A pipe that nobody writes to and nobody closes never gets there.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The output was held until the end.&lt;/strong&gt; This one is sneakier. Python's docs are blunt about it: when interactive, &lt;code&gt;stdout&lt;/code&gt; is line-buffered; otherwise it is block-buffered like a regular file. In a terminal, each &lt;code&gt;print()&lt;/code&gt; shows up straight away. When the parent process reads &lt;code&gt;stdout&lt;/code&gt; through a pipe, it's no longer interactive, so the lines pile up in memory and only reach the interface when the buffer fills or the process ends. The engine was printing progress the whole time. The window just didn't receive it.&lt;/p&gt;

&lt;p&gt;That's what the middle column of the demo shows: with buffering on, the child writes every step, the bytes collect in the buffer, and the window gets everything at once at the end.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I changed
&lt;/h2&gt;

&lt;p&gt;Three things, all small:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Options as arguments instead of questions.&lt;/strong&gt; The interface passes everything the engine used to ask for on the command line, so it never reaches the &lt;code&gt;input()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;PYTHONUNBUFFERED=1&lt;/code&gt; in the child's environment.&lt;/strong&gt; Setting it to any non-empty string is equivalent to running Python with &lt;code&gt;-u&lt;/code&gt;, which forces &lt;code&gt;stdout&lt;/code&gt; and &lt;code&gt;stderr&lt;/code&gt; to be unbuffered.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Step-by-step progress with an estimated time.&lt;/strong&gt; Once lines arrive as they're written, the interface can show a real progress bar.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is the minimal version of both sides. The engine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;argparse&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;

&lt;span class="n"&gt;parser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;argparse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ArgumentParser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"--steps"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"--defaults"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"store_true"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse_args&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;monotonic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# the real work goes here&lt;/span&gt;
    &lt;span class="n"&gt;elapsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;monotonic&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="n"&gt;start&lt;/span&gt;
    &lt;span class="n"&gt;eta&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;elapsed&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"step {i}/{args.steps} · ETA {eta:.1f} s"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the side that launches it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;

&lt;span class="n"&gt;env&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"PYTHONUNBUFFERED"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;proc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Popen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;executable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"engine.py"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"--defaults"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"--steps"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"4"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;stdin&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;DEVNULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;# nobody will type: input() raises EOFError instead of waiting&lt;/span&gt;
    &lt;span class="n"&gt;stdout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;PIPE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;t0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;monotonic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;proc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;        &lt;span class="c1"&gt;# each line arrives as soon as the child prints it&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{time.monotonic() - t0:.2f}s  {line.rstrip()}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;proc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;wait&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;I ran it both ways. With &lt;code&gt;PYTHONUNBUFFERED=1&lt;/code&gt;, the four lines arrived at 0.23, 0.43, 0.63 and 0.83 seconds. Without it, all four arrived together at 0.82 seconds. Same work, same total time; only the experience changes.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;stdin=subprocess.DEVNULL&lt;/code&gt; is a cheap safety net on top of the arguments: if some forgotten &lt;code&gt;input()&lt;/code&gt; is still lurking, it hits end of file and fails right away with &lt;code&gt;EOFError&lt;/code&gt; instead of hanging silently. A loud failure beats an eternal wait.&lt;/p&gt;

&lt;p&gt;The calculation didn't get any faster. It just stopped being scary.&lt;/p&gt;

&lt;h2&gt;
  
  
  A result shifted by one whole period
&lt;/h2&gt;

&lt;p&gt;The second problem was worse, because it didn't look like a problem. With some data files, a date came out exactly one period early. The program didn't crash; it gave a number that looked fine.&lt;/p&gt;

&lt;p&gt;The cause was that it took an auxiliary point in the data file as its reference instead of the last real observation. I excluded those points and checked that this case was corrected without changing the results of the other reference files.&lt;/p&gt;

&lt;p&gt;This is the kind of bug that worries me most, because it doesn't warn you. That's why it pays to keep test cases with known results and rerun them after every change.&lt;/p&gt;

&lt;h2&gt;
  
  
  "The application is damaged"
&lt;/h2&gt;

&lt;p&gt;On macOS, the freshly downloaded app showed that message. I solved it by signing it ad hoc during the automated build. I also left automated builds for the three systems and clear messages when the wrong file is loaded, instead of an incomprehensible error.&lt;/p&gt;

&lt;h2&gt;
  
  
  If you have the same problem
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Does it ask anything on the keyboard?&lt;/strong&gt; Search for &lt;code&gt;input(&lt;/code&gt; in the engine. Turn every question into an argument, and launch the child with &lt;code&gt;stdin=subprocess.DEVNULL&lt;/code&gt; so any leftover fails fast.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Does progress only show up at the end?&lt;/strong&gt; Set &lt;code&gt;PYTHONUNBUFFERED=1&lt;/code&gt; in the child's &lt;code&gt;env&lt;/code&gt;, run it with &lt;code&gt;python -u&lt;/code&gt;, or pass &lt;code&gt;flush=True&lt;/code&gt; to the &lt;code&gt;print()&lt;/code&gt; calls you care about.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Does &lt;code&gt;stderr&lt;/code&gt; behave differently from &lt;code&gt;stdout&lt;/code&gt;?&lt;/strong&gt; Since Python 3.9, non-interactive &lt;code&gt;stderr&lt;/code&gt; is line-buffered, so warnings may show up while normal output doesn't. That mismatch is a strong clue.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep reading the pipe.&lt;/strong&gt; The &lt;code&gt;subprocess&lt;/code&gt; docs warn that &lt;code&gt;wait()&lt;/code&gt; can deadlock with &lt;code&gt;stdout=PIPE&lt;/code&gt; if the child fills the OS pipe buffer. Read it as it comes, and in a GUI do it off the interface thread so the window doesn't freeze for real.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep reference cases with known results.&lt;/strong&gt; The bugs that don't crash are the ones that get through.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to keep an eye on
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Engines that aren't Python.&lt;/strong&gt; &lt;code&gt;PYTHONUNBUFFERED&lt;/code&gt; is a Python setting. If the engine is written in something else, check how that language buffers output to a pipe before assuming the same fix works.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Partial lines.&lt;/strong&gt; A prompt like &lt;code&gt;input("Continue? ")&lt;/code&gt; doesn't end in a newline, so a parent reading line by line won't see it even with &lt;code&gt;-u&lt;/code&gt;. I checked: the question never shows up while the child waits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Very chatty children.&lt;/strong&gt; For a handful of progress lines, turning buffering off costs nothing noticeable. If the engine dumps huge logs, I'd rather leave buffering on and use &lt;code&gt;flush=True&lt;/code&gt; only on the progress lines.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you have a program that only its author knows how to use, &lt;a href="https://richi.codes/#write" rel="noopener noreferrer"&gt;write to me&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Written with AI help from real work of mine.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3/library/sys.html#sys.stdout" rel="noopener noreferrer"&gt;sys.stdout, sys.stderr: buffering (Python docs)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUNBUFFERED" rel="noopener noreferrer"&gt;-u and PYTHONUNBUFFERED (Python docs)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3/library/subprocess.html#subprocess.Popen" rel="noopener noreferrer"&gt;subprocess.Popen: DEVNULL, env and pipe deadlocks (Python docs)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3/library/functions.html#input" rel="noopener noreferrer"&gt;input() and print(flush=True) (Python docs)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://richi.codes/article/2026-11-10-your-app-isnt-frozen-its-buffering?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=crosspost" rel="noopener noreferrer"&gt;richi.codes&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>casestudy</category>
      <category>python</category>
      <category>debugging</category>
      <category>desktop</category>
    </item>
    <item>
      <title>CSS text-wrap: balanced headlines, no lonely words</title>
      <dc:creator>richi.codes</dc:creator>
      <pubDate>Mon, 09 Nov 2026 08:30:42 +0000</pubDate>
      <link>https://dev.to/richicodes/css-text-wrap-balanced-headlines-no-lonely-words-24pd</link>
      <guid>https://dev.to/richicodes/css-text-wrap-balanced-headlines-no-lonely-words-24pd</guid>
      <description>&lt;p&gt;&lt;strong&gt;This note has an interactive demo.&lt;/strong&gt; &lt;a href="https://richi.codes/article/2026-11-09-css-text-wrap-balanced-headlines-no-lonely-words" rel="noopener noreferrer"&gt;Try it in the original&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This Friday, 13 November 2026, &lt;code&gt;text-wrap: balance&lt;/code&gt; becomes Baseline Widely available. Web.dev defines that status as 30 months after a feature works in every major engine, and &lt;a href="https://webstatus.dev/features/text-wrap-balance" rel="noopener noreferrer"&gt;webstatus.dev&lt;/a&gt; dates that moment to 13 May 2024, when Safari 17.5 shipped it. It's a good excuse to look at the two &lt;code&gt;text-wrap&lt;/code&gt; values that fix the typography problems we've all shipped: headlines with one long line and one tiny one, and paragraphs that end with a single word hanging on its own.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem: the browser only looks one line ahead
&lt;/h2&gt;

&lt;p&gt;By default, the browser wraps text greedily. It fills a line until the next word doesn't fit, breaks, and moves on, without looking at what that does to the following lines. That's fast, and for most text it's fine. But on a three-line headline, like the one in the demo, it often leaves "alone" by itself on the last line, and in a paragraph it creates a short last line that looks like a mistake.&lt;/p&gt;

&lt;p&gt;Designers used to fix this by hand with &lt;code&gt;&amp;lt;br&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;amp;nbsp;&lt;/code&gt; between the last two words or a JavaScript library that measured the text. All of those break as soon as the width changes, the font loads late or someone edits the copy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two values, two jobs
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;text-wrap&lt;/code&gt; is a shorthand for &lt;code&gt;text-wrap-mode&lt;/code&gt; (&lt;code&gt;wrap&lt;/code&gt; or &lt;code&gt;nowrap&lt;/code&gt;) and &lt;code&gt;text-wrap-style&lt;/code&gt;. The interesting values are on the style side:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;balance&lt;/code&gt;&lt;/strong&gt; spreads the text so that every line has roughly the same number of characters. It's meant for short blocks: headlines, captions, pull quotes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;pretty&lt;/code&gt;&lt;/strong&gt; keeps normal wrapping but lets the browser use a slower algorithm that favours better layout over speed. In practice, it's what avoids the lonely last word in a paragraph.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is all the CSS the demo above uses on its "After" panel:&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;h1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;blockquote&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="nb"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;p&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;pretty&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;Play with the width slider (or press "Sweep") and watch the bars: each one is a real line, measured with a &lt;code&gt;Range&lt;/code&gt; per word and &lt;code&gt;getClientRects()&lt;/code&gt;. On the left, with plain &lt;code&gt;wrap&lt;/code&gt;, at many widths the headline ends with a last line that is barely a fifth of the column, marked in orange as a "lonely word". On the right, &lt;code&gt;balance&lt;/code&gt; evens the lines out, and the shortest line is usually two or three times longer. You can switch each element between &lt;code&gt;wrap&lt;/code&gt;, &lt;code&gt;balance&lt;/code&gt; and &lt;code&gt;pretty&lt;/code&gt; to see what each value does on its own.&lt;/p&gt;

&lt;h2&gt;
  
  
  What balance doesn't do
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;balance&lt;/code&gt; changes where lines break, not how wide the box is. The Chrome docs point out that a balanced heading can leave empty space on the right, which looks odd inside a card with a border or a background. If that bothers you, set a &lt;code&gt;max-inline-size&lt;/code&gt; on the heading.&lt;/p&gt;

&lt;p&gt;It also has a line limit, because balancing is expensive. According to MDN, it only kicks in for blocks of six lines or fewer in Chromium and ten or fewer in Firefox. Beyond that, the text wraps as usual. That's why &lt;code&gt;balance&lt;/code&gt; makes no sense on body copy: Chrome's own guide recommends using it selectively on headings and not on &lt;code&gt;*&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What pretty does depends on the browser
&lt;/h2&gt;

&lt;p&gt;The spec leaves the exact improvements to each browser, and the two engines that ship it really do different things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Chrome&lt;/strong&gt; added &lt;code&gt;pretty&lt;/code&gt; in version 117. Its blog says it's focused on orphans: it avoids a single word on the last line, and adjusts earlier lines to make room.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Safari&lt;/strong&gt; added it in version 26. The WebKit team says their implementation improves every line of the paragraph, not just the end: it evens out the ragged edge, avoids short lines and reduces hyphenation. The same post says Chromium only adjusts the last four lines.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On performance, MDN warns that &lt;code&gt;pretty&lt;/code&gt; has a cost and recommends it for text where layout matters more than speed. The WebKit post is more relaxed: the number of elements doesn't matter, and you'd need paragraphs of hundreds or thousands of lines to notice anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Browser support and fallback
&lt;/h2&gt;

&lt;p&gt;According to MDN's compatibility data, &lt;code&gt;balance&lt;/code&gt; works in Chrome and Edge 114, Firefox 121 and Safari 17.5. &lt;code&gt;pretty&lt;/code&gt; works in Chrome and Edge 117 and Safari 26, but &lt;strong&gt;not in Firefox yet&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The nice part is that you don't need a fallback. If a browser doesn't know the value, it ignores the declaration and the text keeps wrapping as always. Nothing breaks: it just looks slightly worse. If you want to know which case you're in, as the demo does to show its warning, it's one line:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hasPretty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;CSS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;supports&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;text-wrap&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pretty&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Firefox, the demo detects that &lt;code&gt;pretty&lt;/code&gt; isn't supported, says so, and its paragraph behaves like &lt;code&gt;wrap&lt;/code&gt;, which is exactly what your users will see.&lt;/p&gt;

&lt;p&gt;One small gotcha: if you use the longhand, the property is &lt;code&gt;text-wrap-style: balance&lt;/code&gt;, not &lt;code&gt;text-wrap-mode&lt;/code&gt;, which only accepts &lt;code&gt;wrap&lt;/code&gt; and &lt;code&gt;nowrap&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to keep an eye on
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;pretty&lt;/code&gt; in Firefox&lt;/strong&gt;: until it arrives, a third of the picture is missing, although the fallback costs nothing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chromium and the rest of the paragraph&lt;/strong&gt;: if Chromium extends &lt;code&gt;pretty&lt;/code&gt; beyond the last lines, as WebKit did, the result will look more alike across browsers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;avoid-short-last-line&lt;/code&gt;&lt;/strong&gt;: it already appears in the &lt;code&gt;text-wrap-style&lt;/code&gt; grammar on MDN, but MDN's compatibility data doesn't list it for any browser, so I'm not using it yet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/text-wrap" rel="noopener noreferrer"&gt;text-wrap - CSS | MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.chrome.com/docs/css-ui/css-text-wrap-balance" rel="noopener noreferrer"&gt;CSS text-wrap: balance | Chrome for Developers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://webkit.org/blog/16547/better-typography-with-text-wrap-pretty/" rel="noopener noreferrer"&gt;Better typography with text-wrap pretty | WebKit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.chrome.com/blog/css-text-wrap-pretty" rel="noopener noreferrer"&gt;CSS text-wrap: pretty | Chrome for Developers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://web.dev/baseline" rel="noopener noreferrer"&gt;Baseline | web.dev&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://richi.codes/article/2026-11-09-css-text-wrap-balanced-headlines-no-lonely-words?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=crosspost" rel="noopener noreferrer"&gt;richi.codes&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>typography</category>
      <category>textwrap</category>
      <category>ux</category>
    </item>
    <item>
      <title>ariaNotify(): talk to screen readers without hacks</title>
      <dc:creator>richi.codes</dc:creator>
      <pubDate>Sun, 08 Nov 2026 08:30:42 +0000</pubDate>
      <link>https://dev.to/richicodes/arianotify-talk-to-screen-readers-without-hacks-2b5k</link>
      <guid>https://dev.to/richicodes/arianotify-talk-to-screen-readers-without-hacks-2b5k</guid>
      <description>&lt;p&gt;&lt;strong&gt;This note has an interactive demo.&lt;/strong&gt; &lt;a href="https://richi.codes/article/2026-11-08-arianotify-talk-to-screen-readers-without-hacks" rel="noopener noreferrer"&gt;Try it in the original&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Telling a screen reader "Draft saved" used to mean hiding an empty &lt;code&gt;&amp;lt;div aria-live&amp;gt;&lt;/code&gt; somewhere in the page and writing text into it. Since September 2026 there's a proper method for that in every major browser: &lt;code&gt;element.ariaNotify("Draft saved")&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it is and why it matters
&lt;/h2&gt;

&lt;p&gt;Plenty of things happen in a modern interface that a sighted user notices at a glance: a badge on the cart goes from 2 to 3, a small "Saved" shows up in a corner, an icon turns red when the connection drops. Someone using a screen reader gets none of that unless the page says it out loud.&lt;/p&gt;

&lt;p&gt;The usual tool was ARIA live regions. They work, but they come with strings attached. MDN sums it up well: live regions can only announce something after the DOM changes, and what they read is the updated content of that node. So we all ended up with the same workaround: a visually hidden node with &lt;code&gt;aria-live&lt;/code&gt;, whose text we empty and refill just so it gets read. MDN calls that pattern "inefficient and error-prone", and anyone who has had to debug why a message is read twice, or not at all, knows what they mean.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ariaNotify()&lt;/code&gt; takes that workaround away. You call a method, pass it the text, and the browser hands it to the assistive technology. No helper nodes, and the message doesn't have to match anything on screen.&lt;/p&gt;

&lt;p&gt;It became Baseline (newly available) in September 2026: Chrome and Edge 141, Firefox 150 and Safari 27.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;The WAI-ARIA spec defines it as a mixin that both &lt;code&gt;Element&lt;/code&gt; and &lt;code&gt;Document&lt;/code&gt; include:&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="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ariaNotify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;announcement&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ariaNotify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;announcement&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;priority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;high&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ariaNotify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;announcement&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It returns &lt;code&gt;undefined&lt;/code&gt;. The only option is &lt;code&gt;priority&lt;/code&gt;, with two values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;"normal"&lt;/code&gt; (the default): it is spoken after whatever the screen reader is currently saying. It is roughly the equivalent of &lt;code&gt;aria-live="polite"&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;"high"&lt;/code&gt;: it interrupts and is spoken right away. It is roughly &lt;code&gt;aria-live="assertive"&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It doesn't need user activation, so you can call it from a timer or when a network response arrives. That is exactly why you should use it sparingly.&lt;/p&gt;

&lt;p&gt;In the demo above each button in the "app" calls &lt;code&gt;ariaNotify()&lt;/code&gt; on itself. This is the helper it uses, plan B included:&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;priority&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;normal&lt;/span&gt;&lt;span class="dl"&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;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ariaNotify&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ariaNotify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;priority&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Plan B: a visually hidden aria-live region, emptied and refilled&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;region&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;priority&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;high&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;assertive&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;polite&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;region&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;region&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;50&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="nx"&gt;saveButton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentTarget&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Draft saved at 10:42.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;offlineButton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentTarget&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Connection lost. Your changes will sync when you are back.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;high&lt;/span&gt;&lt;span class="dl"&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;The right-hand panel of the demo is a &lt;em&gt;virtual&lt;/em&gt; screen reader: it can't hear what your real one says, but it draws the model MDN describes. Press "Upload 3 files" and you'll see the three messages queue up; press "Lose the connection" while it's talking and the high priority one cuts it off and goes first. Tick "Read aloud" and the browser's speech synthesis reads them so you can hear them too. If you have VoiceOver, NVDA or TalkBack running, the real announcement reaches them as well.&lt;/p&gt;

&lt;h3&gt;
  
  
  Which element to call it on
&lt;/h3&gt;

&lt;p&gt;It isn't just a matter of taste. According to the spec, if the element is excluded from the accessibility tree the call is ignored. MDN warns that, depending on the browser, that includes containers with little semantic value such as &lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt;. The safest bet is to call it on the element the user just interacted with, like the button in the demo, or on &lt;code&gt;document&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Language comes from the element
&lt;/h3&gt;

&lt;p&gt;There's no &lt;code&gt;lang&lt;/code&gt; parameter. The spec says the announcement inherits the language and direction of the element it is called on, so the screen reader picks the voice from the nearest &lt;code&gt;lang&lt;/code&gt; attribute. If the message is in a different language from the page, call it from an element that declares it. In the demo, the last button has &lt;code&gt;lang&lt;/code&gt; set to the opposite language of the page:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;note&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;note&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lang&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;es&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;note&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;note&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ariaNotify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tu pedido está listo.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Support and gotchas
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Feature detection&lt;/strong&gt;: &lt;code&gt;"ariaNotify" in Element.prototype&lt;/code&gt;. Older Safari versions don't have it (in my tests WebKit 26.5 returns &lt;code&gt;false&lt;/code&gt;), so keep the live region as a fallback for now. The demo shows a notice and switches to it automatically.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't count on a queue&lt;/strong&gt;: MDN is explicit that some screen readers read several announcements in a row, but it's not guaranteed and often only the latest one is spoken. If you have two things to say, say them in a single call.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Live regions still win&lt;/strong&gt;: per MDN, &lt;code&gt;aria-live&lt;/code&gt; announcements take priority over &lt;code&gt;ariaNotify()&lt;/code&gt; ones. If you mix both, the live region goes first.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;macOS and ChromeOS&lt;/strong&gt;: MDN's compatibility data notes that with VoiceOver an announcement may be dropped if another accessibility event fires at the same moment, and that on ChromeOS the method exists in Chrome but announcements are never spoken.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Iframes&lt;/strong&gt;: usage is controlled by the &lt;code&gt;aria-notify&lt;/code&gt; permissions policy. Its default allowlist is &lt;code&gt;*&lt;/code&gt;, so it works inside iframes unless someone blocks it, and when it is blocked the announcements fail silently.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't spam&lt;/strong&gt;: not needing user activation is convenient, but every announcement interrupts someone who is listening. One message per relevant event, short and useful.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to keep an eye on
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;How each screen reader handles the queue and &lt;code&gt;high&lt;/code&gt; priority. This is where behaviour will vary most for a while, so it's worth testing with NVDA, JAWS and VoiceOver rather than trusting the simulation.&lt;/li&gt;
&lt;li&gt;When the share of browsers without support is small enough to drop the live region fallback in your project.&lt;/li&gt;
&lt;li&gt;The spec only defines &lt;code&gt;normal&lt;/code&gt; and &lt;code&gt;high&lt;/code&gt; for now. If more options are added, they will show up in the &lt;code&gt;AriaNotificationOptions&lt;/code&gt; dictionary.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/ariaNotify" rel="noopener noreferrer"&gt;Element: ariaNotify() method, MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/ariaNotify" rel="noopener noreferrer"&gt;Document: ariaNotify() method, MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://w3c.github.io/aria/#ARIANotifyMixin" rel="noopener noreferrer"&gt;Interface Mixin ARIANotifyMixin, WAI-ARIA (W3C Editor's Draft)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.chrome.com/blog/chrome-141-beta" rel="noopener noreferrer"&gt;Chrome 141 beta, Chrome for Developers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://webstatus.dev/features/arianotify" rel="noopener noreferrer"&gt;ariaNotify(), Web Platform Status&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://richi.codes/article/2026-11-08-arianotify-talk-to-screen-readers-without-hacks?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=crosspost" rel="noopener noreferrer"&gt;richi.codes&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>javascript</category>
      <category>aria</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
