<?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: RAMO</title>
    <description>The latest articles on DEV Community by RAMO (@elias_0549e0e2ef8cf6ad89a).</description>
    <link>https://dev.to/elias_0549e0e2ef8cf6ad89a</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%2F4225815%2F585211d9-cca0-479d-9f73-ab0c4bd4be82.png</url>
      <title>DEV Community: RAMO</title>
      <link>https://dev.to/elias_0549e0e2ef8cf6ad89a</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/elias_0549e0e2ef8cf6ad89a"/>
    <language>en</language>
    <item>
      <title>Form error messages that actually help: tie them to the field, say what to do, and don't rely on red</title>
      <dc:creator>RAMO</dc:creator>
      <pubDate>Tue, 17 Nov 2026 07:31:14 +0000</pubDate>
      <link>https://dev.to/elias_0549e0e2ef8cf6ad89a/form-error-messages-that-actually-help-tie-them-to-the-field-say-what-to-do-and-dont-rely-on-red-3p8</link>
      <guid>https://dev.to/elias_0549e0e2ef8cf6ad89a/form-error-messages-that-actually-help-tie-them-to-the-field-say-what-to-do-and-dont-rely-on-red-3p8</guid>
      <description>&lt;p&gt;Most form errors I see on store sites are a red border and a word in small red text that appears somewhere near the field. Sighted mouse users usually figure it out. Everyone else gets a form that just refuses to submit and doesn't say why.&lt;/p&gt;

&lt;p&gt;Good error handling isn't complicated. It's mostly HTML that's been around for years, plus a couple of decisions about timing. Here's the checklist I use when I review a form, whether it's a checkout, a contact form, or the "pick a size" step on a product page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tie the message to the field
&lt;/h2&gt;

&lt;p&gt;The error text has to be connected to its input, not just placed near it visually.&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;label&lt;/span&gt; &lt;span class="na"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"phone"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Phone number&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt;
  &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"phone"&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;"phone"&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"tel"&lt;/span&gt;
  &lt;span class="na"&gt;autocomplete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"tel"&lt;/span&gt;
  &lt;span class="na"&gt;aria-invalid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;
  &lt;span class="na"&gt;aria-describedby&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"phone-hint phone-error"&lt;/span&gt;
&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&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;"phone-hint"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;We'll only call if there's a problem with delivery.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&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;"phone-error"&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;"field-error"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Enter a phone number with at least 9 digits.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;aria-describedby&lt;/code&gt; makes the screen reader read the error when the field gets focus. You can list several ids, so the hint and the error can both be attached.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;aria-invalid="true"&lt;/code&gt; goes on only when the field actually has an error. Don't ship it as &lt;code&gt;"false"&lt;/code&gt; hard-coded in a template and forget to flip it, and don't set it to &lt;code&gt;"true"&lt;/code&gt; before the user has typed anything.&lt;/li&gt;
&lt;li&gt;Keep the error element in the DOM and empty it, or add and remove it together with the &lt;code&gt;aria-describedby&lt;/code&gt; reference. A reference to an id that doesn't exist is harmless but messy; an error that exists but isn't referenced is invisible to assistive tech.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Say what to do, not what went wrong
&lt;/h2&gt;

&lt;p&gt;"Invalid input" is the classic. Compare:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"Invalid phone" → "Enter a phone number with at least 9 digits."&lt;/li&gt;
&lt;li&gt;"Required" → "Choose a size before adding to cart."&lt;/li&gt;
&lt;li&gt;"Invalid date" → "Enter the date as DD/MM/YYYY."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The second version is a little longer and a lot more useful. If there's a format, show it in the hint &lt;em&gt;before&lt;/em&gt; the error happens, not only after.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don't rely on red
&lt;/h2&gt;

&lt;p&gt;A red border is fine as an extra signal. On its own it fails for people who don't see red well, and it fails in forced-colors / high-contrast mode, where your border color may be replaced entirely. Add an icon or the word "Error:" in the message, and make sure the text itself has enough contrast against the background. Pale red on white often doesn't.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to validate
&lt;/h2&gt;

&lt;p&gt;This is where most of the debate happens. What I've ended up with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;On submit:&lt;/strong&gt; always. This is the one moment the user clearly asked "is this okay?"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;On blur (leaving the field):&lt;/strong&gt; fine for fields with a clear format, like email or phone, but only after the user has typed something. Tabbing through an empty form shouldn't light it up in red.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;While typing:&lt;/strong&gt; only to &lt;em&gt;clear&lt;/em&gt; an error once it's fixed. Showing "too short" after the first character is just noise.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  On submit, give a summary and move focus
&lt;/h2&gt;

&lt;p&gt;If the form has more than two or three fields, a summary at the top saves people from hunting.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"error-summary"&lt;/span&gt; &lt;span class="na"&gt;tabindex&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"-1"&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"alert"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;There are 2 problems with your details&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"#phone"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Enter a phone number with at least 9 digits&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"#city"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Enter your city&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;form&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="s1"&gt;'submit'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;form&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;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&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="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;preventDefault&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;renderSummary&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// fills the list above&lt;/span&gt;
  &lt;span class="nf"&gt;markFields&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;// sets aria-invalid + message per field&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="s1"&gt;'error-summary'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;focus&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="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;Each link jumps straight to the field. For a short form, skip the summary and move focus to the first invalid field instead. Either way, don't leave focus on the submit button with nothing announced.&lt;/p&gt;

&lt;h2&gt;
  
  
  Native validation: use it, or turn it off on purpose
&lt;/h2&gt;

&lt;p&gt;The browser's built-in &lt;code&gt;required&lt;/code&gt; / &lt;code&gt;type="email"&lt;/code&gt; bubbles are better than nothing, but they look different in every browser, disappear after a few seconds, and can't be styled. If you build your own messages, add &lt;code&gt;novalidate&lt;/code&gt; to the &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt; so you don't get both at once. Keep &lt;code&gt;required&lt;/code&gt; and the input types anyway; they still help with keyboards on mobile and with autofill.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don't wipe the form
&lt;/h2&gt;

&lt;p&gt;If submit fails on the server (stock changed, session expired, payment declined), keep what the person typed. Re-rendering an empty checkout after an error is the fastest way to lose someone. Password and card fields are the reasonable exceptions.&lt;/p&gt;

&lt;h2&gt;
  
  
  The non-form forms
&lt;/h2&gt;

&lt;p&gt;Product pages have hidden forms too. The size or color picker on clothing is the common one. On things like &lt;a href="https://www.ramo.co.il/en/categories/workwear-shirts" rel="noopener noreferrer"&gt;work shirts&lt;/a&gt;, where you must pick a size before adding to cart, the same rules apply: the size group needs a label (a &lt;code&gt;&amp;lt;fieldset&amp;gt;&lt;/code&gt; with a &lt;code&gt;&amp;lt;legend&amp;gt;&lt;/code&gt; works well), and "Add to cart" without a size should produce a real message tied to that group and move focus to it, not just shake the button.&lt;/p&gt;

&lt;h2&gt;
  
  
  Five-minute test
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Submit the form empty with a screen reader on. Do you hear what's wrong and where?&lt;/li&gt;
&lt;li&gt;Fix one field. Does its error clear?&lt;/li&gt;
&lt;li&gt;Tab through without typing anything. Does anything turn red? (It shouldn't.)&lt;/li&gt;
&lt;li&gt;Turn on forced colors (Windows high contrast or the DevTools emulation). Can you still see which field is wrong?&lt;/li&gt;
&lt;li&gt;Trigger a server-side error. Is your input still there?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;None of this needs a form library, although a good one will handle most of it for you. What's the error message pattern you've seen that annoyed you most? Mine is the password field that only tells you the rules after you've broken three of them.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>html</category>
      <category>ux</category>
      <category>a11y</category>
    </item>
    <item>
      <title>Add to cart feedback: say it, don't just animate the cart icon</title>
      <dc:creator>RAMO</dc:creator>
      <pubDate>Mon, 16 Nov 2026 16:33:56 +0000</pubDate>
      <link>https://dev.to/elias_0549e0e2ef8cf6ad89a/add-to-cart-feedback-say-it-dont-just-animate-the-cart-icon-1cjk</link>
      <guid>https://dev.to/elias_0549e0e2ef8cf6ad89a/add-to-cart-feedback-say-it-dont-just-animate-the-cart-icon-1cjk</guid>
      <description>&lt;p&gt;You click "Add to cart". The little cart icon in the header bounces, the count goes from 2 to 3, and that's it. For a lot of people that's fine. For someone using a screen reader, someone zoomed in to 300%, or someone who looked down at their phone for half a second, nothing happened at all.&lt;/p&gt;

&lt;p&gt;Add-to-cart feedback is one of those things that gets designed once, usually as an animation, and never revisited. Here's what I look at when I review it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Say it, don't just show it
&lt;/h2&gt;

&lt;p&gt;The animation is visual only. The fix is a status message: a live region that already exists in the page and gets text written into it after the item is added.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"cart-status"&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"status"&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;"visually-hidden"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&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 javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;addToCart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;button&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;status&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="s1"&gt;'cart-status'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;disabled&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="k"&gt;try&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;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/api/cart'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'POST'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s1"&gt;'Content-Type'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'application/json'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;productId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;qty&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;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="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'add failed'&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;cart&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&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;status&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
      &lt;span class="sb"&gt;`Added ${button.dataset.name} to your cart. Cart now has ${cart.count} items.`&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="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
      &lt;span class="sb"&gt;`Couldn't add ${button.dataset.name} to your cart. Please try again.`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;finally&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;disabled&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="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;Two things that trip people up:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The live region has to be in the DOM &lt;strong&gt;before&lt;/strong&gt; you write to it. Injecting a new &lt;code&gt;&amp;lt;div role="status"&amp;gt;&lt;/code&gt; with text already inside is often not announced.&lt;/li&gt;
&lt;li&gt;If someone adds the same item twice, the message text is identical and some screen readers skip it. Including the cart count (or clearing the region and setting it again on the next tick) solves that.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Don't move focus unless you open something
&lt;/h2&gt;

&lt;p&gt;A common "fix" is to move focus to the cart icon after adding. Please don't. The person was on the product page, probably about to pick a second size or scroll to the specs, and now they've been thrown into the header.&lt;/p&gt;

&lt;p&gt;The rule I use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Item added, user stays on the page&lt;/strong&gt; â†’ status message, focus stays on the button.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A mini-cart drawer opens&lt;/strong&gt; â†’ it's a dialog now. Move focus into it, trap it, and return focus to the "Add to cart" button when it closes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Half-and-half setups, where a drawer slides in but focus stays behind it, are the worst of both. Keyboard users tab through the page underneath while a panel covers half the screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  The button itself
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Keep the label stable. Changing "Add to cart" to "Added âœ“" for two seconds looks nice, but if focus is on the button, some screen readers announce the change and some don't. The status message is the reliable channel; the label change is decoration.&lt;/li&gt;
&lt;li&gt;Disable it while the request is in flight, or ignore repeat clicks. Double-tap on a slow connection and you've added two boxes of screws when you wanted one.&lt;/li&gt;
&lt;li&gt;If you use &lt;code&gt;disabled&lt;/code&gt;, re-enable it in &lt;code&gt;finally&lt;/code&gt;, not only on success. I've seen buttons that stay dead forever after one network error.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Errors need the same care as success
&lt;/h2&gt;

&lt;p&gt;Out of stock between page load and click, quantity limit reached, session expired: these happen. The error should go through the same status region (or &lt;code&gt;role="alert"&lt;/code&gt; if it really needs to interrupt), and it should say what to do next. "Something went wrong" helps nobody.&lt;/p&gt;

&lt;p&gt;If the item went out of stock, say that, and if the page has an alternative (another size, a similar product), point to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Zoom and small screens
&lt;/h2&gt;

&lt;p&gt;At high zoom, the header cart icon is often off-screen. The bounce is invisible. A short inline message near the button ("Added to cart Â· View cart") covers this and also helps people who just don't look at the header. Keep it in the normal flow rather than a toast that covers the next field, and don't auto-dismiss it in two seconds.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick test checklist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Turn on a screen reader (VoiceOver or NVDA), add an item. Do you hear it?&lt;/li&gt;
&lt;li&gt;Add the same item again. Do you hear it again?&lt;/li&gt;
&lt;li&gt;Use only the keyboard. Where is focus after adding? After closing the drawer?&lt;/li&gt;
&lt;li&gt;Zoom to 300%. Can you tell the item was added without scrolling?&lt;/li&gt;
&lt;li&gt;Throttle to "Slow 3G" in DevTools and double-click the button. How many items are in the cart?&lt;/li&gt;
&lt;li&gt;Kill the network and click. Is there an error message, and does the button come back?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;None of this needs a library. It's a few lines of HTML and a habit of testing with the screen off once in a while.&lt;/p&gt;

&lt;p&gt;I've been going through this on product pages for small hardware parts, like the ones in &lt;a href="https://www.ramo.co.il/en/categories/pipe-fittings" rel="noopener noreferrer"&gt;pipe fittings&lt;/a&gt;, where people often add several items in a row and every silent add is a chance to end up with the wrong quantity.&lt;/p&gt;

&lt;p&gt;What does your store do after "Add to cart"? Drawer, toast, redirect to the cart? I'm curious which one people have found works best with assistive tech.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>a11y</category>
      <category>webdev</category>
      <category>ecommerce</category>
    </item>
    <item>
      <title>Product image galleries: thumbnails are buttons, and other things carousels forget</title>
      <dc:creator>RAMO</dc:creator>
      <pubDate>Mon, 16 Nov 2026 11:31:23 +0000</pubDate>
      <link>https://dev.to/elias_0549e0e2ef8cf6ad89a/product-image-galleries-thumbnails-are-buttons-and-other-things-carousels-forget-el0</link>
      <guid>https://dev.to/elias_0549e0e2ef8cf6ad89a/product-image-galleries-thumbnails-are-buttons-and-other-things-carousels-forget-el0</guid>
      <description>&lt;p&gt;Small parts are where product photos earn their keep. Someone looking for a replacement faucet aerator wants to see the thread, the gasket, the side profile next to a coin. So the gallery on a product page matters more than it looks, and it is usually built as a carousel copied from somewhere and never touched again.&lt;/p&gt;

&lt;p&gt;Here are the bits I check whenever I review one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thumbnails are buttons, not links and not divs
&lt;/h2&gt;

&lt;p&gt;A thumbnail that swaps the main image does not navigate anywhere. That makes it a &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt;, not an &lt;code&gt;&amp;lt;a href="#"&amp;gt;&lt;/code&gt; and definitely not a &lt;code&gt;&amp;lt;div onclick&amp;gt;&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;div&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;"gallery"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"main-photo"&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"aerator-front.jpg"&lt;/span&gt;
       &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Chrome faucet aerator, front view showing the mesh screen"&lt;/span&gt;
       &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"800"&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"800"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;ul&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;"thumbs"&lt;/span&gt; &lt;span class="na"&gt;aria-label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Product photos"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;aria-pressed&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt; &lt;span class="na"&gt;data-src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"aerator-front.jpg"&lt;/span&gt;
              &lt;span class="na"&gt;data-alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Chrome faucet aerator, front view showing the mesh screen"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"aerator-front-thumb.jpg"&lt;/span&gt; &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"80"&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"80"&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;"visually-hidden"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Photo 1 of 3: front view&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;aria-pressed&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt; &lt;span class="na"&gt;data-src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"aerator-thread.jpg"&lt;/span&gt;
              &lt;span class="na"&gt;data-alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Side view of the aerator showing the outer thread and rubber gasket"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"aerator-thread-thumb.jpg"&lt;/span&gt; &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"80"&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"80"&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;"visually-hidden"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Photo 2 of 3: thread and gasket&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You get keyboard focus, Enter and Space, and a correct role for free. &lt;code&gt;aria-pressed&lt;/code&gt; tells screen reader users which photo is showing. The thumbnail image itself gets an empty &lt;code&gt;alt&lt;/code&gt; because the button already has a name from the hidden text; otherwise you end up reading the same description twice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Swap the alt text with the image
&lt;/h2&gt;

&lt;p&gt;The most common bug I see: the main &lt;code&gt;src&lt;/code&gt; changes, the &lt;code&gt;alt&lt;/code&gt; stays on "front view" forever. If you swap one, swap both.&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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;".thumbs button"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;btn&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="n"&gt;btn&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="s2"&gt;"click"&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="o"&gt;=&amp;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;main&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="s2"&gt;"main-photo"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;btn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;alt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;btn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;alt&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;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;".thumbs button"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"aria-pressed"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="n"&gt;btn&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="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="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;Do not move focus to the main image after the click. The person chose a thumbnail; leave them on it so they can keep going through the list.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don't autoplay it
&lt;/h2&gt;

&lt;p&gt;Auto-rotating product photos are the carousel habit I would drop first. Someone is zooming into the thread pitch and the image slides away. If it really has to rotate, it needs a visible pause button and it has to stop on hover and on focus. WCAG 2.2.2 (Pause, Stop, Hide) is the rule people point to, but honestly the bigger reason is that it's annoying.&lt;/p&gt;

&lt;h2&gt;
  
  
  Swipe is extra, not the only way
&lt;/h2&gt;

&lt;p&gt;On a phone, swiping the main image is expected. Fine, add it. Just keep the thumbnails (or visible previous/next buttons) so the gallery still works with a keyboard, a switch device, or a mouse on a desktop. A gallery that only responds to touch gestures fails WCAG 2.5.1 for anyone who can't do the gesture.&lt;/p&gt;

&lt;p&gt;If you use CSS scroll snap for the swipe, you get a lot for free:&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;.slides&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;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;overflow-x&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;scroll-snap-type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="n"&gt;mandatory&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.slides&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;flex&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;0&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="kt"&gt;%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;scroll-snap-align&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;center&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;Native scrolling means momentum, no JS gesture library, and it doesn't fight the browser's back-swipe.&lt;/p&gt;

&lt;h2&gt;
  
  
  Zoom without traps
&lt;/h2&gt;

&lt;p&gt;Hover-to-zoom lenses don't exist on touch screens and are hard to use with a keyboard. Two patterns that hold up better:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A button on the main image ("View larger") that opens the full-size photo in a &lt;code&gt;&amp;lt;dialog&amp;gt;&lt;/code&gt;. Use &lt;code&gt;showModal()&lt;/code&gt;, so focus is trapped inside and Escape closes it, and return focus to the button on close.&lt;/li&gt;
&lt;li&gt;Let pinch-zoom work. Never ship &lt;code&gt;user-scalable=no&lt;/code&gt; or &lt;code&gt;maximum-scale=1&lt;/code&gt; in the viewport meta. People zoom product photos with their fingers all the time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Layout shift and loading
&lt;/h2&gt;

&lt;p&gt;Give the main image and thumbnails &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; (or an &lt;code&gt;aspect-ratio&lt;/code&gt;) so the page does not jump when they load. The first main photo is often the largest element on the page, so it should not get &lt;code&gt;loading="lazy"&lt;/code&gt;; the other gallery photos and the hidden slides can.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick review list
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Thumbnails are &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; elements with a name and &lt;code&gt;aria-pressed&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Main image &lt;code&gt;alt&lt;/code&gt; changes together with &lt;code&gt;src&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;No autoplay, or a real pause control&lt;/li&gt;
&lt;li&gt;Swipe plus a non-gesture way to change photos&lt;/li&gt;
&lt;li&gt;Zoom in a &lt;code&gt;&amp;lt;dialog&amp;gt;&lt;/code&gt;, pinch-zoom not blocked&lt;/li&gt;
&lt;li&gt;Dimensions set, first image not lazy&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of this needs a library. Most of it is choosing the right element and remembering that the image and its text belong together.&lt;/p&gt;

&lt;p&gt;If you want a feel for how much the photos matter on tiny parts, scroll through a category like &lt;a href="https://ramo.co.il/en/categories/faucet-parts-accessories" rel="noopener noreferrer"&gt;faucet parts and accessories&lt;/a&gt; and notice which listings you trust just from the side view. That's what the gallery is for.&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>webdev</category>
      <category>ecommerce</category>
      <category>frontend</category>
    </item>
    <item>
      <title>The 404 page on an online store: return a real 404, then actually help the person</title>
      <dc:creator>RAMO</dc:creator>
      <pubDate>Mon, 16 Nov 2026 07:27:37 +0000</pubDate>
      <link>https://dev.to/elias_0549e0e2ef8cf6ad89a/the-404-page-on-an-online-store-return-a-real-404-then-actually-help-the-person-5cp7</link>
      <guid>https://dev.to/elias_0549e0e2ef8cf6ad89a/the-404-page-on-an-online-store-return-a-real-404-then-actually-help-the-person-5cp7</guid>
      <description>&lt;p&gt;Products get discontinued, categories get renamed, someone pastes half a URL into WhatsApp. Every store ends up serving a lot of "not found" pages, and most of them are a cartoon, an apology, and a button back to the homepage.&lt;/p&gt;

&lt;p&gt;Two separate jobs hide in that page: tell crawlers the truth with the status code, and get the human somewhere useful. They are easy to mix up, so here they are one at a time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Job one: the status code
&lt;/h2&gt;

&lt;p&gt;A missing page should answer with &lt;code&gt;404&lt;/code&gt; (or &lt;code&gt;410&lt;/code&gt; if you know it is gone for good). The common mistake is a page that &lt;em&gt;says&lt;/em&gt; "not found" but answers &lt;code&gt;200 OK&lt;/code&gt;. Search engines call that a soft 404. At best they figure it out and drop it; at worst the empty page sits in the index competing with real pages.&lt;/p&gt;

&lt;p&gt;The other common mistake is redirecting every unknown URL to the homepage. It feels friendly, but the visitor lands somewhere unrelated with no explanation, and search engines tend to treat a mass redirect to the homepage as a soft 404 anyway.&lt;/p&gt;

&lt;p&gt;Quick check from a terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -s -o /dev/null -w &lt;span class="s2"&gt;"%{http_code}\n"&lt;/span&gt; https://example.com/products/does-not-exist
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If that prints &lt;code&gt;200&lt;/code&gt;, fix it before touching the design.&lt;/p&gt;

&lt;h3&gt;
  
  
  In the Next.js App Router
&lt;/h3&gt;

&lt;p&gt;Call &lt;code&gt;notFound()&lt;/code&gt; when the data lookup comes back empty. It renders the nearest &lt;code&gt;not-found.tsx&lt;/code&gt; and sets the 404 status.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app/products/[slug]/page.tsx&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;notFound&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"next/navigation"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;ProductPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;params&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;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&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="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="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;slug&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;params&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;product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getProduct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;slug&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="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;notFound&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;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ProductView&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;product&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two things to watch:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Call it &lt;strong&gt;before&lt;/strong&gt; anything streams. If part of the page has already been sent, the status is already out the door. Do the lookup at the top of the page (or in &lt;code&gt;generateMetadata&lt;/code&gt;, which runs first) rather than deep inside a Suspense boundary.&lt;/li&gt;
&lt;li&gt;Don't catch the error it throws. A broad &lt;code&gt;try/catch&lt;/code&gt; around the whole render will swallow it, and you are back to a &lt;code&gt;200&lt;/code&gt; with an empty page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When a product was renamed rather than removed, a permanent redirect to the new URL is the better answer than a 404. Keep a small table of old slug to new slug and check it before calling &lt;code&gt;notFound()&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Job two: help the human
&lt;/h2&gt;

&lt;p&gt;Someone who hits a 404 on a store usually knew what they wanted. The page should make it easy to keep going.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Put a search box at the top, already focused or one tap away.&lt;/strong&gt; This is the single most useful element. Pre-fill it with words from the broken URL if you can: &lt;code&gt;/products/pvc-elbow-90-deg-32&lt;/code&gt; is a pretty good search query once you swap the dashes for spaces.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app/not-found.tsx (simplified)&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"next/headers"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;NotFound&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;headers&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="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"x-pathname"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s2"&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;guess&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&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="nf"&gt;pop&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="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="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&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;g&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="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="o"&gt;??&lt;/span&gt; &lt;span class="s2"&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;We&lt;/span&gt; &lt;span class="n"&gt;couldn&lt;/span&gt;&lt;span class="s1"&gt;'t find that page&amp;lt;/h1&amp;gt;
      &amp;lt;form action="/search" role="search"&amp;gt;
        &amp;lt;label htmlFor="q"&amp;gt;Search the store&amp;lt;/label&amp;gt;
        &amp;lt;input id="q" name="q" type="search" defaultValue={guess} /&amp;gt;
        &amp;lt;button type="submit"&amp;gt;Search&amp;lt;/button&amp;gt;
      &amp;lt;/form&amp;gt;
      &amp;lt;PopularCategories /&amp;gt;
    &amp;lt;/main&amp;gt;
  );
}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(&lt;code&gt;x-pathname&lt;/code&gt; isn't a built-in header. You'd set it in middleware, or skip the pre-fill and keep the empty search box. The point is the search, not the trick.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Show a short list of top categories.&lt;/strong&gt; Six or eight links, real words, no carousel. If the store sells hardware, that's things like fittings, fasteners, sealants and hand tools, so a visitor who came for a missing PVC part can jump to something like &lt;a href="https://ramo.co.il/en/categories/pipe-fittings" rel="noopener noreferrer"&gt;pipe fittings&lt;/a&gt; and keep looking on their own.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep the normal header and footer.&lt;/strong&gt; A stripped-down error page with no navigation is a dead end. The visitor should see the same site, just with a different middle.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Say what happened in plain words.&lt;/strong&gt; "This product is no longer available" is better than "Oops!" when you actually know that. For discontinued products it's often better to keep the product page live with a clear notice and links to alternatives, and only fall back to a 404 when you have nothing to say.&lt;/p&gt;

&lt;h2&gt;
  
  
  Small details that are easy to skip
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Give the page a real &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt;, something like "Page not found – Store name", so the browser tab and history make sense.&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;noindex&lt;/code&gt; only if your setup somehow serves the page with a &lt;code&gt;200&lt;/code&gt;. A real &lt;code&gt;404&lt;/code&gt; doesn't need it.&lt;/li&gt;
&lt;li&gt;Keep it light. No huge illustration that pushes the search box below the fold on a phone.&lt;/li&gt;
&lt;li&gt;Log the 404s with the referrer. A spike from one referrer usually means a broken link in an email, an ad, or an old blog post, and that's cheaper to fix at the source.&lt;/li&gt;
&lt;li&gt;Make sure the page works when the visitor's language prefix is wrong or missing, for example &lt;code&gt;/en/...&lt;/code&gt; versus &lt;code&gt;/he/...&lt;/code&gt; on a bilingual site.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A five-minute audit
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Request a made-up URL with curl and check the status.&lt;/li&gt;
&lt;li&gt;Request a made-up product slug, not just a made-up top-level path. Dynamic routes are where soft 404s usually hide.&lt;/li&gt;
&lt;li&gt;Open the 404 on a phone. Is the search box visible without scrolling?&lt;/li&gt;
&lt;li&gt;Type something into it. Does it search the store?&lt;/li&gt;
&lt;li&gt;Check your search console's "Not found" and "Soft 404" reports once a month.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;None of this is glamorous, but the 404 page is visited a lot more often than most people think, and it's one of the cheapest pages on the site to get right. You can see how any store handles it by adding a random slug to a product URL, on &lt;a href="https://ramo.co.il/en" rel="noopener noreferrer"&gt;ramo&lt;/a&gt; or anywhere else.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>seo</category>
      <category>nextjs</category>
      <category>ecommerce</category>
    </item>
    <item>
      <title>Spec tables on product pages: keep them as real tables, and make them work on a phone</title>
      <dc:creator>RAMO</dc:creator>
      <pubDate>Sun, 15 Nov 2026 16:34:55 +0000</pubDate>
      <link>https://dev.to/elias_0549e0e2ef8cf6ad89a/spec-tables-on-product-pages-keep-them-as-real-tables-and-make-them-work-on-a-phone-2jlo</link>
      <guid>https://dev.to/elias_0549e0e2ef8cf6ad89a/spec-tables-on-product-pages-keep-them-as-real-tables-and-make-them-work-on-a-phone-2jlo</guid>
      <description>&lt;p&gt;Every hardware or electronics product page ends up with a spec table. Thread size, length, material, voltage range, what's in the box. It's the part of the page people scroll straight to when they already know what they want.&lt;/p&gt;

&lt;p&gt;It's also the part that gets built as a pile of &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;s, or a two-column grid that falls apart below 400px. A few notes on doing it in a way that holds up.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use a table. It is tabular data.
&lt;/h2&gt;

&lt;p&gt;Key/value specs are exactly what &lt;code&gt;&amp;lt;table&amp;gt;&lt;/code&gt; is for. You get row and header relationships for free, and screen readers can announce "Material, stainless steel" instead of two unrelated words.&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;table&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;"specs"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;caption&amp;gt;&lt;/span&gt;Specifications&lt;span class="nt"&gt;&amp;lt;/caption&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;tbody&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;th&lt;/span&gt; &lt;span class="na"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"row"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Material&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;Stainless steel A2&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;th&lt;/span&gt; &lt;span class="na"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"row"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Thread&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;M8&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;th&lt;/span&gt; &lt;span class="na"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"row"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Length&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;60 mm&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/tbody&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/table&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The two details people skip: &lt;code&gt;scope="row"&lt;/code&gt; on the label cell, and a &lt;code&gt;&amp;lt;caption&amp;gt;&lt;/code&gt;. The caption can be visually hidden if the section already has a heading, but having it means the table has a name when someone jumps between tables.&lt;/p&gt;

&lt;p&gt;A description list (&lt;code&gt;&amp;lt;dl&amp;gt;&lt;/code&gt;) is also a fair choice for a short, simple list of specs. Once you have more than a handful of rows, or anything that compares variants, go with the table.&lt;/p&gt;

&lt;h2&gt;
  
  
  Comparing variants is where it gets harder
&lt;/h2&gt;

&lt;p&gt;When one product comes in several sizes, the spec table often turns into a grid: sizes across the top, properties down the side.&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;table&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;"specs specs--compare"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;caption&amp;gt;&lt;/span&gt;Sizes&lt;span class="nt"&gt;&amp;lt;/caption&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;thead&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;th&lt;/span&gt; &lt;span class="na"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"col"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;6 mm&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;th&lt;/span&gt; &lt;span class="na"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"col"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;8 mm&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;th&lt;/span&gt; &lt;span class="na"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"col"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;10 mm&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/thead&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;tbody&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;th&lt;/span&gt; &lt;span class="na"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"row"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Drill bit&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;6 mm&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&lt;/span&gt;8 mm&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&lt;/span&gt;10 mm&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;th&lt;/span&gt; &lt;span class="na"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"row"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Screw size&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;4–5 mm&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&lt;/span&gt;5–6 mm&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&lt;/span&gt;6–8 mm&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/tbody&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/table&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(The values here are just example data to show the shape.)&lt;/p&gt;

&lt;p&gt;With both &lt;code&gt;scope="col"&lt;/code&gt; and &lt;code&gt;scope="row"&lt;/code&gt;, a screen reader can announce the cell with both headers. Without them, someone tabbing through hears a list of numbers with no context.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making it fit on a phone
&lt;/h2&gt;

&lt;p&gt;There are two honest options. Pick based on the table's shape.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Two-column key/value tables:&lt;/strong&gt; let them wrap. Most of the time the only CSS you need is to stop the label column from being squeezed:&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;.specs&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="kt"&gt;%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;border-collapse&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;collapse&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.specs&lt;/span&gt; &lt;span class="nt"&gt;th&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;.specs&lt;/span&gt; &lt;span class="nt"&gt;td&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="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;5rem&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;75rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;text-align&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;vertical-align&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;top&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.specs&lt;/span&gt; &lt;span class="nt"&gt;th&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="kt"&gt;%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.specs&lt;/span&gt; &lt;span class="nt"&gt;tr&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nt"&gt;tr&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;border-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1px&lt;/span&gt; &lt;span class="n"&gt;solid&lt;/span&gt; &lt;span class="mh"&gt;#e5e7eb&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;Note &lt;code&gt;text-align: start&lt;/code&gt; instead of &lt;code&gt;left&lt;/code&gt;. If the site also runs in a right-to-left language, it flips on its own.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wide comparison tables:&lt;/strong&gt; let them scroll horizontally inside a container, and don't fight it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&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;"table-scroll"&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"region"&lt;/span&gt; &lt;span class="na"&gt;aria-labelledby&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"sizes-cap"&lt;/span&gt; &lt;span class="na"&gt;tabindex&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;table&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;"specs specs--compare"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;caption&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;"sizes-cap"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Sizes&lt;span class="nt"&gt;&amp;lt;/caption&amp;gt;&lt;/span&gt;
    ...
  &lt;span class="nt"&gt;&amp;lt;/table&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.table-scroll&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;overflow-x&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="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.specs--compare&lt;/span&gt; &lt;span class="nt"&gt;th&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"row"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;sticky&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;inset-inline-start&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;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#fff&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 &lt;code&gt;tabindex="0"&lt;/code&gt; and &lt;code&gt;role="region"&lt;/code&gt; with a label let keyboard users focus the scroll area and move it with the arrow keys. The sticky first column keeps the row labels visible while the values scroll.&lt;/p&gt;

&lt;p&gt;What I'd avoid is the "turn every row into a card with &lt;code&gt;display: block&lt;/code&gt;" trick. It looks neat, but changing a table's &lt;code&gt;display&lt;/code&gt; can strip its table semantics in some browser and screen reader combinations, and then you've lost the thing that made it a table in the first place. If you go that route, test it with an actual screen reader.&lt;/p&gt;

&lt;h2&gt;
  
  
  Small things that make specs easier to read
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Units in the value, consistently.&lt;/strong&gt; "60 mm" in every row, not "60" in one row and "6 cm" in the next. If you show two unit systems, pick one as primary and keep the other in a smaller span.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Non-breaking space between number and unit.&lt;/strong&gt; &lt;code&gt;60&amp;amp;nbsp;mm&lt;/code&gt; so the unit never wraps onto its own line.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ranges with an en dash.&lt;/strong&gt; &lt;code&gt;4–5 mm&lt;/code&gt; reads better than &lt;code&gt;4-5 mm&lt;/code&gt;, and a screen reader is more likely to read it as a range.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't hide the important rows behind "Show more".&lt;/strong&gt; If people come to the page to check one dimension, that dimension should be visible without a click.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep the spec text in the HTML.&lt;/strong&gt; Specs baked into an image can't be searched, translated, zoomed cleanly, or read aloud.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A quick check
&lt;/h2&gt;

&lt;p&gt;Open a product page with lots of specs, for example a category like &lt;a href="https://ramo.co.il/en/categories/screws-and-anchors" rel="noopener noreferrer"&gt;screws and anchors&lt;/a&gt; on &lt;a href="https://ramo.co.il/en" rel="noopener noreferrer"&gt;ramo&lt;/a&gt; or any store that sells similar items, and try three things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Narrow the window to 360px. Does anything overflow the page instead of its own container?&lt;/li&gt;
&lt;li&gt;Tab through. Can you reach and scroll the wide table with the keyboard?&lt;/li&gt;
&lt;li&gt;Turn on a screen reader and move into a value cell. Do you hear the row header with it?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If all three are fine, the table is in good shape. If not, the fix is usually a few attributes and a dozen lines of CSS, not a new component.&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
      <category>a11y</category>
      <category>ecommerce</category>
    </item>
    <item>
      <title>The autocomplete attributes that let a checkout form fill itself in</title>
      <dc:creator>RAMO</dc:creator>
      <pubDate>Sun, 15 Nov 2026 11:31:03 +0000</pubDate>
      <link>https://dev.to/elias_0549e0e2ef8cf6ad89a/the-autocomplete-attributes-that-let-a-checkout-form-fill-itself-in-3pmb</link>
      <guid>https://dev.to/elias_0549e0e2ef8cf6ad89a/the-autocomplete-attributes-that-let-a-checkout-form-fill-itself-in-3pmb</guid>
      <description>&lt;p&gt;Most people don't type their address into a checkout form. Their browser or password manager does it for them, in one tap, if the form lets it.&lt;/p&gt;

&lt;p&gt;Whether that tap works comes down to a handful of HTML attributes that are easy to skip. When they're missing, autofill guesses. Sometimes it guesses right. Sometimes it puts the street name in the city field and the customer has to clean it up on a phone keyboard.&lt;/p&gt;

&lt;p&gt;Here's what I'd put on every field of a typical checkout.&lt;/p&gt;

&lt;h2&gt;
  
  
  The basic set
&lt;/h2&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;form&lt;/span&gt; &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"post"&lt;/span&gt; &lt;span class="na"&gt;action&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/checkout"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Full name&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"name"&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;"name"&lt;/span&gt; &lt;span class="na"&gt;autocomplete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Email&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"email"&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;"email"&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;autocomplete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"tel"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Phone&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"tel"&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;"tel"&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"tel"&lt;/span&gt; &lt;span class="na"&gt;autocomplete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"tel"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"street"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Street and number&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"street"&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;"street"&lt;/span&gt; &lt;span class="na"&gt;autocomplete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"shipping street-address"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"city"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;City&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"city"&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;"city"&lt;/span&gt; &lt;span class="na"&gt;autocomplete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"shipping address-level2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"zip"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Postal code&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"zip"&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;"zip"&lt;/span&gt; &lt;span class="na"&gt;autocomplete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"shipping postal-code"&lt;/span&gt; &lt;span class="na"&gt;inputmode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"numeric"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"country"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Country&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&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;"country"&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;"country"&lt;/span&gt; &lt;span class="na"&gt;autocomplete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"shipping country"&lt;/span&gt;&lt;span class="nt"&gt;&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;"IL"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Israel&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- ... --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/select&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A few things worth calling out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;address-level2&lt;/code&gt; is the city.&lt;/strong&gt; The names are not obvious. &lt;code&gt;address-level1&lt;/code&gt; is the state/region, &lt;code&gt;address-level2&lt;/code&gt; is the city or town. I've seen these swapped more than once.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The &lt;code&gt;shipping&lt;/code&gt; prefix.&lt;/strong&gt; If you also collect a billing address, prefix those fields with &lt;code&gt;billing&lt;/code&gt;. Browsers can then fill two different addresses without mixing them up.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;street-address&lt;/code&gt; vs &lt;code&gt;address-line1&lt;/code&gt;.&lt;/strong&gt; If you have one street field, use &lt;code&gt;street-address&lt;/code&gt;. If you split it into two lines, use &lt;code&gt;address-line1&lt;/code&gt; and &lt;code&gt;address-line2&lt;/code&gt;. Don't use &lt;code&gt;street-address&lt;/code&gt; on a single-line &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; and expect line 2 to appear somewhere.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;type&lt;/code&gt; and &lt;code&gt;inputmode&lt;/code&gt; are separate jobs
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;autocomplete&lt;/code&gt; tells the browser &lt;em&gt;what&lt;/em&gt; the value is. &lt;code&gt;type&lt;/code&gt; and &lt;code&gt;inputmode&lt;/code&gt; decide &lt;em&gt;which keyboard&lt;/em&gt; shows up on a phone.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;type="email"&lt;/code&gt; gives the keyboard with &lt;code&gt;@&lt;/code&gt; on it.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;type="tel"&lt;/code&gt; gives a number pad with &lt;code&gt;+&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;For a postal code, &lt;code&gt;type="number"&lt;/code&gt; is a trap: it adds spinner arrows, strips leading zeros in some cases and lets the scroll wheel change the value. Use a text input with &lt;code&gt;inputmode="numeric"&lt;/code&gt; instead.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Names are messier than forms assume
&lt;/h2&gt;

&lt;p&gt;A single "Full name" field with &lt;code&gt;autocomplete="name"&lt;/code&gt; works for almost everyone. Splitting into first and last name (&lt;code&gt;given-name&lt;/code&gt; and &lt;code&gt;family-name&lt;/code&gt;) is fine if you really need it, but plenty of people have names that don't fit that shape. If the only reason for the split is "Dear {firstName}" in emails, one field is the kinder option.&lt;/p&gt;

&lt;h2&gt;
  
  
  Payment fields, if they're yours
&lt;/h2&gt;

&lt;p&gt;If the card fields are on your page and not inside a payment provider's iframe:&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;input&lt;/span&gt; &lt;span class="na"&gt;autocomplete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"cc-name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;autocomplete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"cc-number"&lt;/span&gt; &lt;span class="na"&gt;inputmode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"numeric"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;autocomplete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"cc-exp"&lt;/span&gt; &lt;span class="na"&gt;placeholder&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"MM / YY"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;autocomplete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"cc-csc"&lt;/span&gt; &lt;span class="na"&gt;inputmode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"numeric"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you use a hosted iframe, the provider handles this, and there's nothing to add on your side.&lt;/p&gt;

&lt;h2&gt;
  
  
  Things that quietly break autofill
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;autocomplete="off"&lt;/code&gt; on the whole form.&lt;/strong&gt; Usually added years ago to stop something unrelated. Browsers often ignore it for addresses anyway, but when they do respect it, customers lose the fastest way to finish.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fields without a real &lt;code&gt;&amp;lt;label&amp;gt;&lt;/code&gt;.&lt;/strong&gt; A placeholder isn't a label. Autofill heuristics, screen readers and voice control all lean on the label.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Random &lt;code&gt;name&lt;/code&gt; attributes like &lt;code&gt;field_17&lt;/code&gt;.&lt;/strong&gt; With a proper &lt;code&gt;autocomplete&lt;/code&gt; value it mostly doesn't matter, but without one, the name is one of the few hints the browser has.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fields rendered after a delay.&lt;/strong&gt; If the address fields only appear after the user picks a delivery option, autofill may have already run on the visible ones. Test that flow specifically.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Custom dropdowns for country or city.&lt;/strong&gt; A styled &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; that pretends to be a select won't receive autofill. If you need a searchable list, keep a real input underneath it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to check yours in five minutes
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Save an address in your browser's autofill settings.&lt;/li&gt;
&lt;li&gt;Open the checkout on a phone, tap the first field and pick the saved address.&lt;/li&gt;
&lt;li&gt;Look at every field. Is the city in the city field? Did the postal code land? Did the phone number keep its country code?&lt;/li&gt;
&lt;li&gt;Repeat in one other browser, because they don't all read the attributes the same way.&lt;/li&gt;
&lt;li&gt;Tab through it with the keyboard and confirm each field announces a sensible label.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;None of this is new or clever. It's just one of those parts of a form that nobody owns, so it drifts. I went through the checkout fields at &lt;a href="https://www.ramo.co.il/en" rel="noopener noreferrer"&gt;RAMO&lt;/a&gt; with this list, and it's a good reminder that someone ordering &lt;a href="https://www.ramo.co.il/en/categories/pipe-fittings" rel="noopener noreferrer"&gt;pipe fittings&lt;/a&gt; in the middle of a plumbing job wants to type as little as possible.&lt;/p&gt;

</description>
      <category>html</category>
      <category>ux</category>
      <category>a11y</category>
      <category>ecommerce</category>
    </item>
    <item>
      <title>Breadcrumbs on a product page: the markup, the accessibility bits, and the structured data</title>
      <dc:creator>RAMO</dc:creator>
      <pubDate>Sun, 15 Nov 2026 07:30:13 +0000</pubDate>
      <link>https://dev.to/elias_0549e0e2ef8cf6ad89a/breadcrumbs-on-a-product-page-the-markup-the-accessibility-bits-and-the-structured-data-496p</link>
      <guid>https://dev.to/elias_0549e0e2ef8cf6ad89a/breadcrumbs-on-a-product-page-the-markup-the-accessibility-bits-and-the-structured-data-496p</guid>
      <description>&lt;p&gt;Breadcrumbs are one of those components nobody argues about. Everyone adds them, they look like a row of small grey links, and they get forgotten. But on a store with deep categories they do three separate jobs, and it's easy to get one of them wrong:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;They help a visitor who landed from search figure out where they are.&lt;/li&gt;
&lt;li&gt;They help screen reader users jump up a level without hunting through the menu.&lt;/li&gt;
&lt;li&gt;They give search engines a clear picture of how your pages are related.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here's a version that handles all three without much code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with plain HTML
&lt;/h2&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;nav&lt;/span&gt; &lt;span class="na"&gt;aria-label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Breadcrumb"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ol&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;"breadcrumbs"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Home&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/categories/electrical"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Electrical&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/categories/measuring-instruments"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Measuring instruments&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/products/digital-multimeter"&lt;/span&gt; &lt;span class="na"&gt;aria-current&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"page"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Digital multimeter&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ol&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A few choices in there are deliberate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;&amp;lt;nav&amp;gt;&lt;/code&gt; with an &lt;code&gt;aria-label&lt;/code&gt;.&lt;/strong&gt; A page usually has several nav regions already (header, footer). The label is what makes this one show up as "Breadcrumb navigation" in a screen reader's landmarks list instead of a third anonymous "navigation".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An ordered list.&lt;/strong&gt; The order means something, so &lt;code&gt;&amp;lt;ol&amp;gt;&lt;/code&gt; says so. Screen readers also announce "list, 4 items", which tells the user how deep they are before they start.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;aria-current="page"&lt;/code&gt; on the last item.&lt;/strong&gt; This is the part most implementations skip. It tells assistive tech which item is the current page. Whether the last item is a link or plain text is a design choice; both are fine as long as it's marked.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Keep the separators out of the content
&lt;/h2&gt;

&lt;p&gt;The most common mistake I see is putting the separator in the HTML:&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;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Home&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt; &lt;span class="ni"&gt;&amp;amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A screen reader then reads "Home, greater than, Electrical, greater than...". Draw the separators with CSS instead, so they're visual only:&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;.breadcrumbs&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;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-wrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;wrap&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="mf"&gt;0.25rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;list-style&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="nl"&gt;padding&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="nc"&gt;.breadcrumbs&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nt"&gt;li&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="s2"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin-inline-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.25rem&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="mh"&gt;#888&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;Using &lt;code&gt;margin-inline-end&lt;/code&gt; instead of &lt;code&gt;margin-right&lt;/code&gt; means the spacing still works if the page is ever shown right-to-left. On an RTL page you'll probably also want the separator to point the other way if you use an arrow-like character, which is another reason to keep it in CSS where you can change it per direction.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make it usable on a phone
&lt;/h2&gt;

&lt;p&gt;Long category names wrap badly on small screens. Two options that both work:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Let it wrap (the &lt;code&gt;flex-wrap&lt;/code&gt; above) and keep the font small but readable.&lt;/li&gt;
&lt;li&gt;Or show only the parent level on mobile ("‹ Measuring instruments") as a back link.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What I'd avoid is horizontal scrolling with the current page cut off on the right. It looks tidy, but the visitor loses the one item that tells them where they are.&lt;/p&gt;

&lt;p&gt;Also check the tap targets. Breadcrumb links tend to be small text with tiny gaps between them, which is exactly where people mis-tap. A bit of vertical padding on the links fixes most of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add BreadcrumbList structured data
&lt;/h2&gt;

&lt;p&gt;The visible breadcrumb helps people. For search engines you can describe the same trail with &lt;code&gt;BreadcrumbList&lt;/code&gt; in JSON-LD:&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;script&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"application/ld+json"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"@context"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://schema.org"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"@type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"BreadcrumbList"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"itemListElement"&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="s2"&gt;"@type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ListItem"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"position"&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="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"item"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://www.example.com/"&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="s2"&gt;"@type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ListItem"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"position"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Electrical"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"item"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://www.example.com/categories/electrical"&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="s2"&gt;"@type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ListItem"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"position"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Measuring instruments"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"item"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://www.example.com/categories/measuring-instruments"&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="s2"&gt;"@type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ListItem"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"position"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Digital multimeter"&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;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Things worth knowing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Google's documentation allows the last item to omit &lt;code&gt;item&lt;/code&gt;, since it's the current page.&lt;/li&gt;
&lt;li&gt;Use absolute URLs, and the same canonical URLs you use everywhere else. A breadcrumb pointing at a URL with tracking parameters or a different trailing slash is just noise.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The JSON-LD should match what's on screen.&lt;/strong&gt; If the visible trail says "Measuring instruments" and the structured data says something else, you've built two breadcrumbs and you'll eventually fix only one of them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The easiest way to keep them in sync is to build both from the same array.&lt;/p&gt;

&lt;h2&gt;
  
  
  One source, two outputs
&lt;/h2&gt;

&lt;p&gt;In React (or anything component-based) that looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;Breadcrumbs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;trail&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;baseUrl&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;jsonLd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"@context"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://schema.org"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"@type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"BreadcrumbList"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;itemListElement&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;trail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;crumb&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&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="p"&gt;{&lt;/span&gt;
      &lt;span class="s2"&gt;"@type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ListItem"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;i&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="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;crumb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&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="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;trail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;baseUrl&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;crumb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;href&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="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="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="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;nav&lt;/span&gt; &lt;span class="n"&gt;aria&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Breadcrumb"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ol&lt;/span&gt; &lt;span class="n"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"breadcrumbs"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;trail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;crumb&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;isLast&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="n"&gt;trail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
              &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;li&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;crumb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;crumb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;aria&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;isLast&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"page"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;undefined&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="n"&gt;crumb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;ol&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;nav&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;script&lt;/span&gt;
        &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"application/ld+json"&lt;/span&gt;
        &lt;span class="n"&gt;dangerouslySetInnerHTML&lt;/span&gt;&lt;span class="o"&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;__html&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;jsonLd&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="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure this renders on the server, not after hydration. Crawlers that don't run JavaScript, and most link preview bots, only see what's in the initial HTML.&lt;/p&gt;

&lt;h2&gt;
  
  
  Products in more than one category
&lt;/h2&gt;

&lt;p&gt;On a hardware store a product often lives in two places. A multimeter is a measuring instrument and also an electrician's tool. You don't need to show every path. Pick one primary category per product and use it consistently for the breadcrumb, the structured data and internal links. If someone arrived through the other category, the breadcrumb still showing the primary path is fine; it's better than a trail that changes depending on how you got there and confuses everyone, including crawlers.&lt;/p&gt;

&lt;h2&gt;
  
  
  A quick checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;nav aria-label="Breadcrumb"&amp;gt;&lt;/code&gt; with an &lt;code&gt;&amp;lt;ol&amp;gt;&lt;/code&gt; inside&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;aria-current="page"&lt;/code&gt; on the last item&lt;/li&gt;
&lt;li&gt;Separators drawn in CSS, not typed into the HTML&lt;/li&gt;
&lt;li&gt;Wraps cleanly on mobile, links big enough to tap&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;BreadcrumbList&lt;/code&gt; JSON-LD with absolute canonical URLs&lt;/li&gt;
&lt;li&gt;Visible trail and JSON-LD generated from the same data&lt;/li&gt;
&lt;li&gt;Rendered on the server&lt;/li&gt;
&lt;li&gt;One primary category per product&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then run the page through Google's Rich Results Test and tab through it with a screen reader once. Ten minutes, and you'll know whether all three jobs are actually being done.&lt;/p&gt;

&lt;p&gt;I've been going through this on the product pages at &lt;a href="https://www.ramo.co.il/en" rel="noopener noreferrer"&gt;RAMO&lt;/a&gt;, a hardware store where something like a &lt;a href="https://www.ramo.co.il/en/products/digital-multimeter" rel="noopener noreferrer"&gt;digital multimeter&lt;/a&gt; sits a few levels deep under &lt;a href="https://www.ramo.co.il/en/categories/electrical-measuring-instruments" rel="noopener noreferrer"&gt;electrical measuring instruments&lt;/a&gt;, so the breadcrumb is often the fastest way back to the category.&lt;/p&gt;

</description>
      <category>seo</category>
      <category>a11y</category>
      <category>html</category>
      <category>ecommerce</category>
    </item>
    <item>
      <title>Lazy loading a product grid: which images should never get loading="lazy"</title>
      <dc:creator>RAMO</dc:creator>
      <pubDate>Sat, 14 Nov 2026 17:07:14 +0000</pubDate>
      <link>https://dev.to/elias_0549e0e2ef8cf6ad89a/lazy-loading-a-product-grid-which-images-should-never-get-loadinglazy-fl1</link>
      <guid>https://dev.to/elias_0549e0e2ef8cf6ad89a/lazy-loading-a-product-grid-which-images-should-never-get-loadinglazy-fl1</guid>
      <description>&lt;p&gt;Adding &lt;code&gt;loading="lazy"&lt;/code&gt; to every &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; on a category page feels like free performance. It mostly is. The catch is the handful of images where it does the opposite of what you want, and on a store those are usually the most important ones.&lt;/p&gt;

&lt;p&gt;Here's the short version of how I decide, image by image.&lt;/p&gt;

&lt;h2&gt;
  
  
  The rule of thumb
&lt;/h2&gt;

&lt;p&gt;Lazy loading tells the browser: "don't fetch this until it's about to scroll into view." That's great for row 6 of a product grid. It's bad for anything the visitor sees the moment the page opens, because the browser now waits until layout is done to decide the image is "near the viewport" before it even starts the request.&lt;/p&gt;

&lt;p&gt;So the question for each image is simply: &lt;strong&gt;is it visible without scrolling on a typical screen?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Yes: load it normally. If it's the largest thing on screen, give it a priority hint too.&lt;/li&gt;
&lt;li&gt;No: lazy load it.&lt;/li&gt;
&lt;li&gt;Not sure: lean towards eager for the first few items, lazy for the rest.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The images people lazy load by mistake
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The hero banner.&lt;/strong&gt; If a category page opens with a big banner, that banner is very often the Largest Contentful Paint element. Lazy loading it delays your LCP for no benefit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The first row of product cards.&lt;/strong&gt; On desktop the first row is usually fully visible. On mobile, the first one or two cards are. These should load eagerly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The main product photo on a product page.&lt;/strong&gt; This one is almost always the LCP element. It should be eager and, ideally, have &lt;code&gt;fetchpriority="high"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Logos and icons in the header.&lt;/strong&gt; They're small, but they're above the fold on every single page.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it looks like in plain HTML
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Hero / main product photo: the one thing you want first --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/img/hero.webp"&lt;/span&gt; &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"..."&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"1200"&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"600"&lt;/span&gt;
     &lt;span class="na"&gt;fetchpriority&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"high"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- First visible product cards: default loading, no hint needed --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/img/p1.webp"&lt;/span&gt; &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"..."&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"300"&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"300"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/img/p2.webp"&lt;/span&gt; &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"..."&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"300"&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"300"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- Everything further down --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/img/p9.webp"&lt;/span&gt; &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"..."&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"300"&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"300"&lt;/span&gt;
     &lt;span class="na"&gt;loading&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"lazy"&lt;/span&gt; &lt;span class="na"&gt;decoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"async"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details that matter more than they look:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Always set &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt;&lt;/strong&gt; (or a CSS &lt;code&gt;aspect-ratio&lt;/code&gt;). Lazy images that arrive without reserved space push the layout around, and that shows up as layout shift.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use &lt;code&gt;fetchpriority="high"&lt;/code&gt; on one image, maybe two.&lt;/strong&gt; If everything is high priority, nothing is.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  In a grid component, decide by index
&lt;/h2&gt;

&lt;p&gt;You usually render cards in a loop, so the simplest approach is to pass the index and let the card decide:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;ProductGrid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;products&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="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;EAGER_COUNT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// roughly the first row on desktop&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ul&lt;/span&gt; &lt;span class="n"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"grid"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;products&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;li&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;img&lt;/span&gt;
            &lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="n"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imageAlt&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="n"&gt;loading&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;EAGER_COUNT&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"eager"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"lazy"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="n"&gt;decoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"async"&lt;/span&gt;
          &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;EAGER_COUNT&lt;/code&gt; is a judgment call, not a magic number. Pick it by looking at your own layout at a couple of common screen sizes. A 4-column desktop grid and a 2-column mobile grid suggest something around the first 2 to 4 items.&lt;/p&gt;

&lt;h2&gt;
  
  
  If you're on Next.js
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;next/image&lt;/code&gt; lazy loads by default, which is the right default and exactly the trap above. For the hero or the main product photo, opt out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Image&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"next/image"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Image&lt;/span&gt;
  &lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imageAlt&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;800&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;800&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;priority&lt;/span&gt;   &lt;span class="c1"&gt;// in newer versions you may see `preload` instead&lt;/span&gt;
&lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check the docs for the version you're on, since the prop name for this has changed over time. Whatever it's called, the idea is the same: one or two images on the page get it, the rest stay lazy.&lt;/p&gt;

&lt;p&gt;And give &lt;code&gt;sizes&lt;/code&gt; a real value on responsive images. Without it the browser may pick a much larger source than the card actually needs, which hurts more than the lazy/eager choice ever will.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to check you got it right
&lt;/h2&gt;

&lt;p&gt;You don't need any special tooling:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open DevTools, run a Lighthouse or Performance panel trace, and look at which element is reported as LCP. If it has &lt;code&gt;loading="lazy"&lt;/code&gt; on it, that's your fix.&lt;/li&gt;
&lt;li&gt;In the Network panel, filter by images and reload. The hero and first-row images should start early, not after a long gap.&lt;/li&gt;
&lt;li&gt;Throttle to a slow connection and scroll. Lower rows should appear as you approach them, without the page jumping.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Background images and carousels
&lt;/h2&gt;

&lt;p&gt;Two things that &lt;code&gt;loading="lazy"&lt;/code&gt; doesn't cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CSS background images&lt;/strong&gt; aren't lazy loaded by the attribute at all. If a hero is a &lt;code&gt;background-image&lt;/code&gt;, the browser only discovers it after the CSS is parsed. For the main visual, a real &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; is easier to prioritise.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Carousels&lt;/strong&gt; often render every slide up front. Make the first slide eager and the rest lazy, otherwise you're downloading images nobody has swiped to yet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The one-line summary
&lt;/h2&gt;

&lt;p&gt;Lazy load what's below the fold, prioritise the one image that's biggest above it, and reserve space for all of them.&lt;/p&gt;

&lt;p&gt;I ran into all of these while working on the category pages at &lt;a href="https://www.ramo.co.il/en" rel="noopener noreferrer"&gt;RAMO&lt;/a&gt;, a hardware store where pages like &lt;a href="https://www.ramo.co.il/he/categories/plumbing" rel="noopener noreferrer"&gt;plumbing&lt;/a&gt; are long grids of small product photos, which is exactly where getting the first row right is noticeable.&lt;/p&gt;

</description>
      <category>webperf</category>
      <category>html</category>
      <category>ecommerce</category>
      <category>nextjs</category>
    </item>
    <item>
      <title>The quantity stepper is the smallest component on a product page and the easiest one to get wrong</title>
      <dc:creator>RAMO</dc:creator>
      <pubDate>Sat, 14 Nov 2026 12:09:16 +0000</pubDate>
      <link>https://dev.to/elias_0549e0e2ef8cf6ad89a/the-quantity-stepper-is-the-smallest-component-on-a-product-page-and-the-easiest-one-to-get-wrong-8d7</link>
      <guid>https://dev.to/elias_0549e0e2ef8cf6ad89a/the-quantity-stepper-is-the-smallest-component-on-a-product-page-and-the-easiest-one-to-get-wrong-8d7</guid>
      <description>&lt;p&gt;Every store has one. A minus button, a number, a plus button. It looks like a ten-minute job, and that's exactly why it usually ships broken in some quiet way that nobody notices until a customer emails asking why they got one bag of cement instead of twelve.&lt;/p&gt;

&lt;p&gt;Here's a checklist I'd go through before calling a quantity stepper done. Nothing here is framework-specific.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Start from a real input, not a styled span
&lt;/h2&gt;

&lt;p&gt;The most common version I see in the wild is this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"qty"&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;onclick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"dec()"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;-&lt;span class="nt"&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;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"count"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;1&lt;span class="nt"&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;onclick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"inc()"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;+&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works with a mouse. It does nothing with a keyboard, a screen reader announces "minus, one, plus" with no idea what any of it means, and you can't type 12 on your phone without tapping the plus button eleven times.&lt;/p&gt;

&lt;p&gt;Start with an input and add buttons around it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"qty"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Quantity&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&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;"qty"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;aria-label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Decrease quantity"&lt;/span&gt; &lt;span class="na"&gt;aria-controls&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"qty"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;−&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&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;"qty"&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;"quantity"&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;inputmode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"numeric"&lt;/span&gt;
         &lt;span class="na"&gt;pattern&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"[0-9]*"&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;"1"&lt;/span&gt; &lt;span class="na"&gt;autocomplete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"off"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;aria-label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Increase quantity"&lt;/span&gt; &lt;span class="na"&gt;aria-controls&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"qty"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;+&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two choices in there that people argue about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;type="text"&lt;/code&gt; with &lt;code&gt;inputmode="numeric"&lt;/code&gt; instead of &lt;code&gt;type="number"&lt;/code&gt;.&lt;/strong&gt; Number inputs change value when someone scrolls the page with the cursor over them, they accept &lt;code&gt;e&lt;/code&gt; and &lt;code&gt;-&lt;/code&gt;, and their built-in spinner arrows are tiny. Text plus &lt;code&gt;inputmode&lt;/code&gt; still brings up the numeric keypad on phones without the surprises. If you prefer &lt;code&gt;type="number"&lt;/code&gt;, that's fine, just test the scroll-wheel thing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A visible label.&lt;/strong&gt; "Quantity" next to the box costs you a few pixels. Leaving it out means a screen reader user lands on an unlabeled edit field.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. The buttons need names, and &lt;code&gt;−&lt;/code&gt; isn't one
&lt;/h2&gt;

&lt;p&gt;A button whose only content is a minus sign gets read as "minus" or sometimes "hyphen", depending on the character and the screen reader. &lt;code&gt;aria-label="Decrease quantity"&lt;/code&gt; fixes that. If you have several steppers on one page (a cart, say), include the product name: "Decrease quantity, Cement 25 kg".&lt;/p&gt;

&lt;p&gt;Also use a real &lt;code&gt;&amp;lt;button type="button"&amp;gt;&lt;/code&gt;. Without &lt;code&gt;type="button"&lt;/code&gt;, a button inside a form submits it. That's how "click plus, item gets added to the cart with quantity 1" bugs happen.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Announce the change
&lt;/h2&gt;

&lt;p&gt;When someone presses plus, the value in the input changes, but focus stays on the button, so a screen reader may say nothing at all. The simplest fix is a polite live region:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&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;"visually-hidden"&lt;/span&gt; &lt;span class="na"&gt;aria-live&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"polite"&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;"qty-status"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/p&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 javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;setQty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`Quantity ${next}`&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;Keep the message short. Announcing "Quantity updated successfully to 3 units" on every click gets old fast.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Decide what happens at the edges
&lt;/h2&gt;

&lt;p&gt;Write these down before you code, because each one has a "do nothing" default that's wrong:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Minimum.&lt;/strong&gt; Usually 1. When the value is at the minimum, either disable the minus button or let it remove the line (in a cart). Pick one and be consistent. If you disable it, &lt;code&gt;aria-disabled="true"&lt;/code&gt; keeps it focusable so the keyboard user isn't suddenly thrown somewhere else on the page.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maximum.&lt;/strong&gt; If there's a stock limit, tell people when they hit it, in text, next to the field. A plus button that silently stops working feels like a bug.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pack sizes.&lt;/strong&gt; Some products only sell in multiples (a box of 100 screws, a pallet of blocks). Either step in that multiple or make the unit explicit: "Boxes" instead of "Quantity". Mixing them is how people order 100 boxes when they meant 100 screws.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Empty field.&lt;/strong&gt; Someone deletes the 1 to type 12 and then clicks away halfway. Don't snap back to 1 on every keystroke; validate on blur or on submit.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. Validate typed input without fighting the user
&lt;/h2&gt;

&lt;p&gt;Typed values are where most bugs live. A small, forgiving parser goes a long way:&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;parseQty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;min&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="n"&gt;max&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;Infinity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;step&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="o"&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="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;)&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="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;]&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="mi"&gt;10&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="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isNaN&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="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;min&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;clamped&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&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="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;min&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max&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="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;clamped&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;step&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;step&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 strips stray characters (people paste "12 pcs"), clamps to the allowed range, and rounds up to the pack size. If the number you end up with differs from what they typed, say so: "Sold in packs of 10, rounded up to 20." Quietly changing someone's order is worse than showing a message.&lt;/p&gt;

&lt;p&gt;And whatever the browser does, validate again on the server. The client-side stepper is a convenience, not a guarantee.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Touch targets and layout
&lt;/h2&gt;

&lt;p&gt;The minus and plus buttons are often 24 px squares squeezed next to the input. On a phone that's a lot of mis-taps. Give them a comfortable hit area (WCAG 2.2 sets a 24×24 CSS px minimum for target size, and bigger is kinder), and leave a little space between them and the input so a thumb doesn't land on the wrong one.&lt;/p&gt;

&lt;p&gt;If your site has an RTL version, check that the buttons don't flip in a confusing way. In Hebrew or Arabic layouts, people still expect plus to mean "more", but the visual order of minus/plus can swap with &lt;code&gt;dir="rtl"&lt;/code&gt;. Decide which order you want and set it on purpose instead of letting the flexbox decide.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Don't trigger a network request on every click
&lt;/h2&gt;

&lt;p&gt;If changing the quantity in a cart updates the server, someone clicking plus five times shouldn't fire five requests that can arrive out of order. Debounce the update, or send the final value when they stop clicking, and show the total as pending until it comes back. Out-of-order responses are a classic source of "my cart says 3 but I clicked to 5".&lt;/p&gt;

&lt;h2&gt;
  
  
  A two-minute test
&lt;/h2&gt;

&lt;p&gt;Before shipping, try this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Tab to the stepper. Can you reach the field and both buttons?&lt;/li&gt;
&lt;li&gt;Type 12 on a phone. Did you get a numeric keypad?&lt;/li&gt;
&lt;li&gt;Press plus with a screen reader running. Did it say anything useful?&lt;/li&gt;
&lt;li&gt;Paste "abc". Then paste "15 units". What happens?&lt;/li&gt;
&lt;li&gt;Go below the minimum and above the stock limit.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If all five behave, you've got a better stepper than most stores.&lt;/p&gt;

&lt;p&gt;I spent more time on this than I expected while working on &lt;a href="https://www.ramo.co.il/en" rel="noopener noreferrer"&gt;RAMO&lt;/a&gt;, a hardware store where quantities are rarely 1. Things like &lt;a href="https://www.ramo.co.il/en/categories/building-materials" rel="noopener noreferrer"&gt;building materials&lt;/a&gt; are bought by the bag or the box, and that's where every one of these edge cases shows up.&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>ecommerce</category>
      <category>html</category>
      <category>ux</category>
    </item>
    <item>
      <title>Alt text for product images: what to write when every photo looks the same</title>
      <dc:creator>RAMO</dc:creator>
      <pubDate>Sat, 14 Nov 2026 08:06:31 +0000</pubDate>
      <link>https://dev.to/elias_0549e0e2ef8cf6ad89a/alt-text-for-product-images-what-to-write-when-every-photo-looks-the-same-58a6</link>
      <guid>https://dev.to/elias_0549e0e2ef8cf6ad89a/alt-text-for-product-images-what-to-write-when-every-photo-looks-the-same-58a6</guid>
      <description>&lt;p&gt;Most alt text advice is written for blog photos. "A golden retriever catching a frisbee on a beach." Fine. But try that on a product page for a hardware store and it falls apart fast, because half the catalog is grey metal on a white background.&lt;/p&gt;

&lt;p&gt;A 1/2" brass elbow and a 3/4" brass elbow look identical in a photo. So do most drywall anchors. If the alt text just says "brass fitting", a screen reader user gets nothing the sighted user didn't already get from the title, and a sighted user at least sees the scale in the second photo.&lt;/p&gt;

&lt;p&gt;Here's how I think about it now, after rewriting a lot of these.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with what the image is for, not what's in it
&lt;/h2&gt;

&lt;p&gt;Alt text answers one question: if this image didn't load, what would the reader miss?&lt;/p&gt;

&lt;p&gt;On a product page, the images usually do one of these jobs:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Identify the product.&lt;/strong&gt; The main photo. The title right next to it already says what it is.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Show a detail you can't get from text.&lt;/strong&gt; The thread type, the connector end, the back of the packaging, how the clip locks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Show scale or use.&lt;/strong&gt; The part in someone's hand, installed under a sink, next to a ruler.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decoration.&lt;/strong&gt; A lifestyle background, a repeated brand banner.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each job gets different alt text.&lt;/p&gt;

&lt;h2&gt;
  
  
  The main photo: don't repeat the title word for word
&lt;/h2&gt;

&lt;p&gt;If the &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; says "Digital Multimeter, Auto-Range" and the alt says "Digital Multimeter, Auto-Range", a screen reader reads the same thing twice in a row. Not harmful, just noisy.&lt;/p&gt;

&lt;p&gt;Better: add what the photo shows that the title doesn't.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- meh --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"multimeter.webp"&lt;/span&gt; &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Digital multimeter"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- better --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"multimeter.webp"&lt;/span&gt;
     &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Digital multimeter, front view with rotary dial and red and black test leads"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Colour, what's included in the box, which side you're looking at. Short, factual.&lt;/p&gt;

&lt;h2&gt;
  
  
  Detail shots are where alt text actually earns its place
&lt;/h2&gt;

&lt;p&gt;This is the image people zoom into. It's also the one most often left as &lt;code&gt;alt="product image 3"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If the second photo exists to show that the fitting has a male thread on one side and a compression end on the other, say exactly that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"elbow-detail.webp"&lt;/span&gt;
     &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Close-up of the elbow: male thread on one end, compression nut on the other"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That sentence is useful to everyone, including the person on a slow connection whose images haven't loaded yet. It also tends to be the information people search for, which doesn't hurt.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scale photos: give the size in words
&lt;/h2&gt;

&lt;p&gt;"Anchor held between two fingers" is better than nothing, but the real info is the size. If the product has a length or a diameter, put it in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"anchor-hand.webp"&lt;/span&gt;
     &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Plastic wall anchor held between two fingers, about the length of a fingertip"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only state a measurement if it's actually in the product data. Guessing "approx. 3 cm" from a photo is how wrong information ends up on a page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decorative images get an empty alt, not a missing one
&lt;/h2&gt;



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

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;alt=""&lt;/code&gt; tells assistive tech to skip it. Leaving the attribute out entirely is different: some screen readers will then read the file name, and nobody wants to hear "banner underscore texture underscore final two dot webp".&lt;/p&gt;

&lt;h2&gt;
  
  
  Galleries and thumbnails
&lt;/h2&gt;

&lt;p&gt;Thumbnail strips are a common trap. Five thumbnails, each with the same alt as its large version, means the page announces everything twice.&lt;/p&gt;

&lt;p&gt;Two options that both work:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make the thumbnails buttons with a label like "Show image 2 of 5: close-up of thread", and give the image inside &lt;code&gt;alt=""&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Or keep the alt on the thumbnail and make the big preview the decorative one, if it only mirrors the selected thumb.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pick one. The bug is doing both.&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;button&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;aria-label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Show image 2 of 5: close-up of thread"&lt;/span&gt;
        &lt;span class="na"&gt;aria-pressed&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"thumb-2.webp"&lt;/span&gt; &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Generating alt text from product data
&lt;/h2&gt;

&lt;p&gt;On a big catalog nobody hand-writes 5,000 alt texts. A template from structured fields is a decent baseline:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;mainAlt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;string&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;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's not great prose, but it's honest and it scales. Then spend human time on the detail shots, because a template can't know that photo 3 exists to show the locking clip.&lt;/p&gt;

&lt;p&gt;A few things I'd avoid in generated alt text:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"Image of" / "Photo of". Screen readers already announce it's an image.&lt;/li&gt;
&lt;li&gt;Keyword lists. "Multimeter tester voltmeter electrical tool best price" helps nobody and reads like spam.&lt;/li&gt;
&lt;li&gt;Prices and stock status. They change; the alt text usually doesn't get updated with them.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A quick check you can run today
&lt;/h2&gt;

&lt;p&gt;Open a product page, turn off images (or run a screen reader for two minutes), and try to answer: what is this, what does it connect to, how big is it? If you can't, the alt text is where the fix goes.&lt;/p&gt;

&lt;p&gt;On RAMO, the hardware store I work on, the categories where this mattered most were the "everything looks alike" ones, like &lt;a href="https://www.ramo.co.il/en/categories/screws-and-anchors" rel="noopener noreferrer"&gt;screws and anchors&lt;/a&gt; and &lt;a href="https://www.ramo.co.il/en/categories/pipe-fittings" rel="noopener noreferrer"&gt;pipe fittings&lt;/a&gt;. If your catalog has a section like that, start there.&lt;/p&gt;

</description>
      <category>a11yecommercewebdevhtml</category>
    </item>
    <item>
      <title>Send purchase events from the server, not only from the thank-you page</title>
      <dc:creator>RAMO</dc:creator>
      <pubDate>Fri, 13 Nov 2026 17:08:54 +0000</pubDate>
      <link>https://dev.to/elias_0549e0e2ef8cf6ad89a/we-stopped-firing-purchase-events-from-the-thank-you-page-a-postgres-job-table-does-it-now-12c4</link>
      <guid>https://dev.to/elias_0549e0e2ef8cf6ad89a/we-stopped-firing-purchase-events-from-the-thank-you-page-a-postgres-job-table-does-it-now-12c4</guid>
      <description>&lt;p&gt;For a long time, the usual advice for store purchase events has been: the customer lands on the thank-you page, a script runs, and each ad or analytics pixel is told "this order happened, here's the value".&lt;/p&gt;

&lt;p&gt;It works most of the time. The trouble is "most of the time" is a weak guarantee for the one event an ad budget is often optimized on.&lt;/p&gt;

&lt;p&gt;Here are common ways it fails:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The customer pays, the payment provider redirects back, and the tab is closed before the redirect finishes. No thank-you page, no event.&lt;/li&gt;
&lt;li&gt;An ad blocker or a strict browser setting drops one pixel but not the others. The platforms then disagree about how many orders there were.&lt;/li&gt;
&lt;li&gt;Someone refreshes the thank-you page, or opens it again from an email link. Without careful dedup, that's a second purchase.&lt;/li&gt;
&lt;li&gt;A bank transfer or phone order is confirmed by staff hours later. There is no browser session at all.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of this is exotic. It's what happens when the source of truth (the order in the database) and the thing reporting it (a script in someone's browser) are different systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let the paid order trigger the event
&lt;/h2&gt;

&lt;p&gt;If the order row is the source of truth, the order row should trigger tracking. When an order moves to a paid state, the same transaction can insert one job per destination:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;create&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="n"&gt;conversion_jobs&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;           &lt;span class="kt"&gt;bigserial&lt;/span&gt; &lt;span class="k"&gt;primary&lt;/span&gt; &lt;span class="k"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;order_id&lt;/span&gt;     &lt;span class="kt"&gt;bigint&lt;/span&gt; &lt;span class="k"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="k"&gt;references&lt;/span&gt; &lt;span class="nf"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;destination&lt;/span&gt;  &lt;span class="kt"&gt;text&lt;/span&gt;   &lt;span class="k"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;-- e.g. an ads or analytics platform&lt;/span&gt;
  &lt;span class="n"&gt;event_name&lt;/span&gt;   &lt;span class="kt"&gt;text&lt;/span&gt;   &lt;span class="k"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="s1"&gt;'purchase'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;status&lt;/span&gt;       &lt;span class="kt"&gt;text&lt;/span&gt;   &lt;span class="k"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="s1"&gt;'pending'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;-- pending | sent | failed&lt;/span&gt;
  &lt;span class="n"&gt;attempts&lt;/span&gt;     &lt;span class="kt"&gt;int&lt;/span&gt;    &lt;span class="k"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;last_error&lt;/span&gt;   &lt;span class="kt"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;next_attempt&lt;/span&gt; &lt;span class="kt"&gt;timestamptz&lt;/span&gt; &lt;span class="k"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nb"&gt;now&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;sent_at&lt;/span&gt;      &lt;span class="kt"&gt;timestamptz&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;created_at&lt;/span&gt;   &lt;span class="kt"&gt;timestamptz&lt;/span&gt; &lt;span class="k"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nb"&gt;now&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;unique&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;destination&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;event_name&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 unique constraint does a lot of quiet work. A payment webhook retries and marks the order paid twice? The insert hits the constraint and nothing new is queued. Someone refreshes the thank-you page ten times? If that page is no longer responsible for sending purchases, it doesn't matter.&lt;/p&gt;

&lt;p&gt;A worker picks up due jobs, sends them to each platform's server-side API, and records the result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;conversion_jobs&lt;/span&gt;
&lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'pending'&lt;/span&gt; &lt;span class="k"&gt;and&lt;/span&gt; &lt;span class="n"&gt;next_attempt&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nb"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;next_attempt&lt;/span&gt;
&lt;span class="k"&gt;limit&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="k"&gt;update&lt;/span&gt; &lt;span class="n"&gt;skip&lt;/span&gt; &lt;span class="n"&gt;locked&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;for update skip locked&lt;/code&gt; means two worker runs that overlap won't grab the same job. On failure, bump the attempt count, store the error text, and push the next attempt out with a growing delay. After a set number of tries, the job goes to &lt;code&gt;failed&lt;/code&gt; and waits for a person to look at it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What can still happen in the browser
&lt;/h2&gt;

&lt;p&gt;You don't have to rip out client-side tags. The browser can still send page views, add-to-cart, begin-checkout and similar events, because those often don't have a durable database row to hang off, and they need the click identifiers and cookies the browser already has.&lt;/p&gt;

&lt;p&gt;For purchase, both sides can know about the order, so give them the same event ID, derived from the order. Several platforms will dedupe on that. For click-based ad conversions, store the click identifier with the order at checkout, so a later server-side upload has something to attach to. If that identifier is missing, the job should say so in the error field instead of failing silently.&lt;/p&gt;

&lt;h2&gt;
  
  
  The part that pays off later
&lt;/h2&gt;

&lt;p&gt;The table is boring. What makes it worth it is that it's queryable. "Did this platform get yesterday's orders?" no longer has to mean opening a vendor dashboard and squinting at a chart:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;destination&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;count&lt;/span&gt;&lt;span class="cm"&gt;(*)
from conversion_jobs
where created_at &amp;gt;= now() - interval '1 day'
group by 1, 2
order by 1, 2;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When one destination shows a pile of &lt;code&gt;failed&lt;/code&gt; rows, the stored error usually says why in plain words: an expired token, a renamed conversion action, a missing secret after a deploy. Running a query like this as part of checking a release is useful, because a release that breaks tracking often doesn't throw an error anywhere a customer would see.&lt;/p&gt;

&lt;h2&gt;
  
  
  Things that go wrong
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Values and currency.&lt;/strong&gt; Decide once what "value" means (with or without tax, with or without delivery) and compute it in one place, server-side. When each pixel computes it from the page, they disagree.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Consent.&lt;/strong&gt; Server-side does not mean "ignore consent". Store what the customer agreed to with the order, and have the worker check it before sending to a platform.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Clock drift on uploads.&lt;/strong&gt; Some platforms reject conversions with timestamps in the future or too far in the past. Send the order's paid time, not the time the worker happened to run.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test orders.&lt;/strong&gt; Mark them on the order, and skip them when jobs are inserted. Otherwise every QA run looks like a sale that bidding systems can learn from.&lt;/p&gt;

&lt;h2&gt;
  
  
  Is it worth it for a small store?
&lt;/h2&gt;

&lt;p&gt;If a store gets only a few orders a week and someone checks them by hand, maybe not yet. Once real money is spent on ads that optimize toward purchases, it usually is. Those systems learn from what you report, and an order that never got reported looks to them exactly like an order that never happened.&lt;/p&gt;

&lt;p&gt;The nice side effect is how unremarkable it becomes. Someone buys a box of &lt;a href="https://www.ramo.co.il/en/categories/screws-and-anchors" rel="noopener noreferrer"&gt;screws and anchors&lt;/a&gt; late at night, closes the tab before the redirect, and the platforms can still hear about it shortly after — once each.&lt;/p&gt;

</description>
      <category>ecommerce</category>
      <category>postgres</category>
      <category>analytics</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Pricing delivery when one cart ships from more than one place</title>
      <dc:creator>RAMO</dc:creator>
      <pubDate>Fri, 13 Nov 2026 12:08:42 +0000</pubDate>
      <link>https://dev.to/elias_0549e0e2ef8cf6ad89a/one-cart-several-warehouses-how-we-price-delivery-when-an-order-ships-from-more-than-one-place-2je1</link>
      <guid>https://dev.to/elias_0549e0e2ef8cf6ad89a/one-cart-several-warehouses-how-we-price-delivery-when-an-order-ships-from-more-than-one-place-2je1</guid>
      <description>&lt;p&gt;Most delivery-fee tutorials assume one warehouse. You set a flat fee, add a free-shipping threshold, and you are done. Many shops do not work like that. A single cart can mix things that physically leave from different places: a few bags of &lt;a href="https://www.ramo.co.il/en/categories/growing-mixes" rel="noopener noreferrer"&gt;potting soil&lt;/a&gt; from one location, a &lt;a href="https://www.ramo.co.il/en/categories/stepping-stones" rel="noopener noreferrer"&gt;stepping stone&lt;/a&gt; from another. Each place can have its own vehicles, its own rules, and its own cost to deliver.&lt;/p&gt;

&lt;p&gt;This post is about a simple model for that situation, and about one boring bug class that keeps coming back: settings that were never filled in.&lt;/p&gt;

&lt;h2&gt;
  
  
  Price delivery per shipping location, not once for the whole store
&lt;/h2&gt;

&lt;p&gt;A store-wide fee and a store-wide "free over X" rule fall apart the moment a second location starts shipping part of the cart. "Free delivery above a threshold" means little if half the items travel separately and that trip still has to be paid for.&lt;/p&gt;

&lt;p&gt;So the settings sit on the location, not on the store:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- one row per place goods ship from&lt;/span&gt;
&lt;span class="n"&gt;fulfillment_locations&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;delivery_fee&lt;/span&gt;       &lt;span class="kt"&gt;numeric&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;-- required: the fee when the free threshold is not met&lt;/span&gt;
  &lt;span class="n"&gt;free_over&lt;/span&gt;          &lt;span class="kt"&gt;numeric&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;-- null = no free tier&lt;/span&gt;
  &lt;span class="n"&gt;minimum_subtotal&lt;/span&gt;   &lt;span class="kt"&gt;numeric&lt;/span&gt;   &lt;span class="c1"&gt;-- null = no minimum to ship&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;-- which options that location actually offers&lt;/span&gt;
&lt;span class="n"&gt;location_shipping_options&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;location_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;option_code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;-- e.g. home or pickup&lt;/span&gt;
  &lt;span class="n"&gt;enabled&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some shops also store option-level prices. The important part is the same: the rule lives with the location that ships the goods, not as a single store-wide constant.&lt;/p&gt;

&lt;p&gt;At checkout, group the cart by shipping location, price each group on its own, and show the customer one line per shipment instead of a single mysterious number. That last part matters more than it sounds. When people can see that one fee belongs to one part of the order and another fee belongs to the rest, the total makes sense. When they see one large fee with no explanation, they leave.&lt;/p&gt;

&lt;h2&gt;
  
  
  NULL is not zero
&lt;/h2&gt;

&lt;p&gt;Here is the bug class. A new location gets added in the admin, someone fills in the name and the products, and the fee is left empty. Nothing crashes in the admin, so nobody notices.&lt;/p&gt;

&lt;p&gt;Then a customer puts one of those products in the cart, and checkout has to decide what a missing fee means. Depending on the code path, that can go several ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;fee ?? 0&lt;/code&gt;: delivery is free. Nice for the customer, not so nice for whoever pays the driver.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Number(fee)&lt;/code&gt;: still 0, same problem, just quieter.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;fee.toFixed(2)&lt;/code&gt;: an exception, and a report in the error tracker.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The exception is honestly the best of the three, because at least it gets noticed. The scarier paths are the first two, which can quietly give away shipping for a long time.&lt;/p&gt;

&lt;p&gt;A sturdier approach:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Fill in missing values on purpose.&lt;/strong&gt; Not with a code default, but with a real number someone decided on, written into the rows. Before a bulk update, copy the affected rows and keep the rollback SQL next to it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make "not configured" an explicit state.&lt;/strong&gt; If a location has no home-delivery option, checkout should not invent one. It should not offer that option for that group, and it should say so.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Leave the optional fields optional.&lt;/strong&gt; A minimum subtotal or a free-shipping threshold can legitimately be empty (no minimum, no free tier). The fee cannot. Spell that difference out in the code, not only in someone's head.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;LocationDelivery&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;fee&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                    &lt;span class="c1"&gt;// required, validated on load&lt;/span&gt;
  &lt;span class="n"&gt;freeOver&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&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="c1"&gt;// null = no free tier&lt;/span&gt;
  &lt;span class="n"&gt;minimumSubtotal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&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="c1"&gt;// null = no minimum&lt;/span&gt;
&lt;span class="p"&gt;}&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;loadLocationDelivery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;LocationRow&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;LocationDelivery&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;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;delivery_fee&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="c1"&gt;// fail loudly, never guess a price&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`Missing delivery fee for location ${row.id}`&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;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fee&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;delivery_fee&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;freeOver&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;free_over&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&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="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;free_over&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;minimumSubtotal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;minimum_subtotal&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&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="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;minimum_subtotal&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Catch it before a customer does
&lt;/h2&gt;

&lt;p&gt;The real fix is not only defensive code at checkout. A small query that lists any active location with products for sale but no fee, or no home-delivery option, is worth more than another layer of fallbacks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;loc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;loc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;fulfillment_locations&lt;/span&gt; &lt;span class="n"&gt;loc&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;loc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_active&lt;/span&gt;
  &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="k"&gt;EXISTS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;
    &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;location_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;loc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_active&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;loc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;delivery_fee&lt;/span&gt; &lt;span class="k"&gt;IS&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;
    &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;EXISTS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;location_shipping_options&lt;/span&gt; &lt;span class="n"&gt;opt&lt;/span&gt;
      &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;opt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;location_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;loc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;
        &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;opt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;option_code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'home'&lt;/span&gt;
        &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;opt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;enabled&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;If it returns rows, a person should hear about it. It is not clever, but it catches the problem when the location is added, not when a customer tries to pay.&lt;/p&gt;

&lt;h2&gt;
  
  
  Things that help from the start
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Put delivery rules where the goods ship from.&lt;/strong&gt; Store-level settings are fine until a second location appears, and then they are wrong in ways that are hard to see.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep every price in the database.&lt;/strong&gt; Fees, thresholds and minimums change with business decisions, and a deploy should not be required to change them. But "in the database" only helps if the database is actually filled in.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decide what NULL means per column, and write it down.&lt;/strong&gt; "No free tier" and "someone forgot" look identical in a table.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prefer a loud failure over a silent default&lt;/strong&gt; for anything that is money.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you run a store with more than one ship-from location, I am curious how you split the cart: one fee per location, or one combined fee that you settle behind the scenes?&lt;/p&gt;

</description>
      <category>ecommerce</category>
      <category>postgres</category>
      <category>nextjs</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
