[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"verticals":3,"article-css-focus-within-group-focus":44,"search-suggestions":230,"path-membership-css-focus-within-group-focus":271,"related-css-focus-within-group-focus":272,"code:jsx:true:ri72pg":402,"code:jsx:true:1qn3i1a":403,"code:css:true:12xtg9c":404,"comments-01a22fd5-4b5e-7649-83f0-a37d6da8cd14":405},[4,20,32],{"id":5,"slug":6,"name":7,"tagline":8,"description":9,"accentFrom":10,"accentTo":11,"icon":12,"defaultLocale":13,"locales":14,"features":16,"position":19},"019fe637-3d33-714b-b57f-23e163ffca0c","dev","Web Development","Read it. Run it. Prove it.","A post a day on modern web development — most with an editable playground and a quiz that explains every answer. Free, no account needed.","violet-500","cyan-400","◇","en",[13,15],"fa",{"courses":17,"paths":17,"articles":17,"exams":18,"flashcards":18,"packages":17,"community":17,"certificates":17,"teams":17,"commerce":17},true,false,0,{"id":21,"slug":22,"name":23,"tagline":24,"description":25,"accentFrom":26,"accentTo":10,"icon":27,"defaultLocale":13,"locales":28,"features":30,"position":31},"019fe637-3dc2-754c-8657-0f175bfee7c6","lang","Languages","Learn a language the way you learn a codebase.","Grammar explained the way good documentation explains an API — one idea at a time, each with a quiz.","amber-400","⌘",[13,15,29],"es",{"courses":18,"paths":18,"articles":17,"exams":18,"flashcards":17,"packages":18,"community":17,"certificates":17,"teams":18,"commerce":18},2,{"id":33,"slug":34,"name":35,"tagline":36,"description":37,"accentFrom":38,"accentTo":39,"icon":40,"defaultLocale":13,"locales":41,"features":42,"position":43},"7b3c16f2-931d-410e-802e-e1fa4edab7de","soft","Soft Skills","The half of the job nobody wrote documentation for.","Weekly, on the parts of working life that decide more than your code does — first weeks, meetings, interviews, promotions, and the people around you. Written from what actually happens, and recorded as a podcast you can listen to on the walk.","emerald-400","teal-300","◉",[13],{"courses":18,"paths":18,"articles":17,"exams":18,"flashcards":18,"packages":18,"community":17,"certificates":18,"teams":18,"commerce":18},3,{"id":45,"slug":46,"title":47,"subtitle":48,"excerpt":49,"coverUrl":50,"locale":13,"readingMinutes":51,"publishedAt":52,"viewCount":53,"likeCount":19,"commentCount":19,"author":54,"vertical":59,"topic":60,"tags":63,"_count":75,"playground":77,"body":79,"bodyMd":213,"seo":214,"translationGroupId":217,"series":48,"podcastUrl":48,"verticalId":5,"thread":218,"assessments":220,"translations":226,"quiz":228},"01a22fd5-4b5e-7649-83f0-a37d6da8cd14","css-focus-within-group-focus","I Stopped Checking relatedTarget. :focus-within Does It in CSS.",null,"A search box's own clear button kept un-focusing the whole wrapper, so I started checking event.relatedTarget on every blur to tell 'focus left the widget' from 'focus moved inside it.' :focus-within in CSS made the check unnecessary.","\u002Fmedia\u002Fcovers\u002Fcss-focus-within-group-focus.png",5,"2026-12-04T21:44:50.650Z",72,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},"019fe637-3c25-7088-9034-39c9f15dc3c8","Parsa Jiravand","parsa","Frontend engineer · building bestpractic",{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},"css","CSS",[64,66,69,72],{"slug":61,"name":65,"color":48},"Css",{"slug":67,"name":68,"color":48},"frontend","Frontend",{"slug":70,"name":71,"color":48},"webdev","Webdev",{"slug":73,"name":74,"color":48},"tutorial","Tutorial",{"assessments":76},1,{"slug":46,"title":78},":focus-within — interactive playground",{"blocks":80,"version":76},[81,85,88,92,95,101,104,107,111,114,118,121,124,128,131,134,137,144,147,150,153,159,162,165,168,171,174,177,180,183,186,189,192,195,198,201,204,207],{"id":82,"html":83,"type":84},"b1","\u003Cp>I built a search box with a clear button inside it — the little × that shows up once you&#39;ve typed something. Standard stuff. The input had a nice blue ring when focused, so I matched it on the wrapper too: \u003Ccode>border-color: var(--focus-color)\u003C\u002Fcode> the moment the input gets focus, so the whole pill looks selected, not just the text caret.\u003C\u002Fp>","paragraph",{"id":86,"html":87,"type":84},"b2","\u003Cp>It worked, until a teammate typed a query and clicked the ×. For one frame, the wrapper&#39;s border flashed back to gray — like the whole box had lost focus — before the input (correctly) still showing the cleared, empty state kept its own focus ring. It looked like a rendering glitch. It wasn&#39;t. It was \u003Ccode>onBlur\u003C\u002Fcode> doing exactly what \u003Ccode>onBlur\u003C\u002Fcode> does.\u003C\u002Fp>",{"id":89,"html":90,"text":90,"type":91,"level":31},"b3","The fix everyone reaches for first","heading",{"id":93,"html":94,"type":84},"b4","\u003Cp>The wrapper&#39;s &quot;focused&quot; look was driven by state, toggled from the input&#39;s own focus and blur events:\u003C\u002Fp>",{"id":96,"code":97,"type":98,"language":99,"highlight":100},"b5","function SearchBox() {\n  const [focused, setFocused] = useState(false);\n\n  return (\n    \u003Cdiv className={focused ? \"search focused\" : \"search\"}>\n      \u003Cinput\n        onFocus={() => setFocused(true)}\n        onBlur={() => setFocused(false)}\n      \u002F>\n      \u003Cbutton onClick={clear}>×\u003C\u002Fbutton>\n    \u003C\u002Fdiv>\n  );\n}","code","jsx",[],{"id":102,"html":103,"type":84},"b6","\u003Cp>Click the ×, and here&#39;s the order of events: the button steals focus away from the input, so the input&#39;s \u003Ccode>blur\u003C\u002Fcode> fires, \u003Ccode>setFocused(false)\u003C\u002Fcode> runs, and the wrapper&#39;s &quot;focused&quot; class disappears — a full render cycle before anyone notices the focus is still \u003Cem>inside the same component\u003C\u002Fem>, just on a different element.\u003C\u002Fp>",{"id":105,"html":106,"type":84},"b7","\u003Cp>The standard patch, and the one you&#39;ll find in a dozen Stack Overflow answers for exactly this: check where focus is going before you believe it left.\u003C\u002Fp>",{"id":108,"code":109,"type":98,"language":99,"highlight":110},"b8","onBlur={(e) => {\n  if (!e.currentTarget.contains(e.relatedTarget)) {\n    setFocused(false);\n  }\n}}",[],{"id":112,"html":113,"type":84},"b9","\u003Cp>\u003Ccode>relatedTarget\u003C\u002Fcode> is the element about to receive focus — MDN documents it on the \u003Ccode>FocusEvent\u003C\u002Fcode> interface for exactly this reason. \u003Ccode>currentTarget.contains(relatedTarget)\u003C\u002Fcode> asks &quot;is the new focus target a descendant of the wrapper I&#39;m attached to?&quot; If yes, don&#39;t un-focus. It works. It also has to be written again for every dropdown, every combobox, every form row with more than one focusable child — and it quietly breaks the moment the new target sits behind a portal or an iframe, where \u003Ccode>contains()\u003C\u002Fcode> can&#39;t see it at all.\u003C\u002Fp>",{"id":115,"html":116,"text":117,"type":91,"level":31},"b10","The actual problem: blur is per-element, CSS doesn&#39;t know your widget is one thing","The actual problem: blur is per-element, CSS doesn't know your widget is one thing",{"id":119,"html":120,"type":84},"b11","\u003Cp>\u003Ccode>focus\u003C\u002Fcode> and \u003Ccode>blur\u003C\u002Fcode> are defined per element. The browser has no built-in notion that the input and its clear button are &quot;one search box&quot; — that grouping exists only in your head and your JSX. So every time focus moves \u003Cem>within\u003C\u002Fem> a thing you consider one unit, the browser reports it as a departure from one element and an arrival at another, and you&#39;re stuck inferring &quot;same widget&quot; from DOM containment by hand.\u003C\u002Fp>",{"id":122,"html":123,"type":84},"b12","\u003Cp>CSS already has the word for that grouping. It&#39;s a pseudo-class, not a state you manage:\u003C\u002Fp>",{"id":125,"code":126,"type":98,"language":61,"highlight":127},"b13",".search:focus-within {\n  border-color: var(--focus-color);\n}",[],{"id":129,"html":130,"type":84},"b14","\u003Cp>\u003Ccode>:focus-within\u003C\u002Fcode> matches an element if \u003Cem>that element or any descendant\u003C\u002Fem> currently has focus. Click into the input — matches. Tab to the clear button — still matches, because the button is a descendant of \u003Ccode>.search\u003C\u002Fcode>. Click the × to actually blur out of the whole component — only then does it stop matching. No \u003Ccode>useState\u003C\u002Fcode>, no \u003Ccode>onFocus\u003C\u002Fcode>\u002F\u003Ccode>onBlur\u003C\u002Fcode> pair, no \u003Ccode>relatedTarget\u003C\u002Fcode> containment check, and no render at all: the browser repaints the border because the CSS rule re-evaluates, not because your component re-rendered.\u003C\u002Fp>",{"id":132,"html":133,"text":133,"type":91,"level":31},"b15","Quick gut check before you keep scrolling",{"id":135,"html":136,"type":84},"b16","\u003Cp>\u003Ccode>:focus\u003C\u002Fcode>, \u003Ccode>:focus-visible\u003C\u002Fcode>, and \u003Ccode>:focus-within\u003C\u002Fcode> read like three names for the same idea. They&#39;re not:\u003C\u002Fp>",{"id":138,"type":139,"items":140,"ordered":18},"b17","list",[141,142,143],"\u003Cstrong>\u003Ccode>:focus\u003C\u002Fcode>\u003C\u002Fstrong> — matches the element that literally has focus right now. Just that one element.","\u003Cstrong>\u003Ccode>:focus-visible\u003C\u002Fcode>\u003C\u002Fstrong> — matches only when the browser thinks the focus indicator should show (keyboard navigation, mostly — a mouse click on a \u003Ccode>&lt;button&gt;\u003C\u002Fcode> usually doesn&#39;t trigger it). I wrote about this one back when \u003Ccode>outline: none\u003C\u002Fcode> was the fight.","\u003Cstrong>\u003Ccode>:focus-within\u003C\u002Fcode>\u003C\u002Fstrong> — matches an \u003Cem>ancestor\u003C\u002Fem> of whatever has focus, all the way up. The one this post is about.",{"id":145,"html":146,"type":84},"b18","\u003Cp>They compose. \u003Ccode>.search:focus-within:not(:focus)\u003C\u002Fcode> matches the wrapper exactly when focus is inside it but not \u003Cem>on\u003C\u002Fem> it — useful if the wrapper itself is also focusable and you want different styling for &quot;I&#39;m focused&quot; versus &quot;something inside me is.&quot;\u003C\u002Fp>",{"id":148,"html":149,"text":149,"type":91,"level":31},"b19","Where this earns its keep beyond one search box",{"id":151,"html":152,"type":84},"b20","\u003Cp>The same pattern shows up anywhere a widget is more than one focusable element and you want it to read as one thing:\u003C\u002Fp>",{"id":154,"type":139,"items":155,"ordered":18},"b21",[156,157,158],"\u003Cstrong>Form rows\u003C\u002Fstrong> — highlight the whole label-plus-input row when the input inside it is focused, without a listener on every row.","\u003Cstrong>Toolbars with grouped fields\u003C\u002Fstrong> — a date range picker with two inputs should look &quot;active&quot; if focus is on either one.","\u003Cstrong>Custom dropdowns and comboboxes\u003C\u002Fstrong> — keep a wrapper visually &quot;open&quot; while focus bounces between the trigger and the menu, instead of tracking that by hand.",{"id":160,"html":161,"type":84},"b22","\u003Cp>One honest limit: \u003Ccode>:focus-within\u003C\u002Fcode> is CSS-only. It changes what gets \u003Cem>styled\u003C\u002Fem>, not what your JavaScript \u003Cem>knows\u003C\u002Fem>. If a component genuinely needs a boolean in JS — to fire an analytics event, say, or gate some other logic — you still need \u003Ccode>focus\u003C\u002Fcode>\u002F\u003Ccode>blur\u003C\u002Fcode> listeners (with the \u003Ccode>relatedTarget\u003C\u002Fcode> check, if you only want to know when focus leaves the whole group). What you get to delete is every line of state and every re-render that existed \u003Cem>only\u003C\u002Fem> to drive a style.\u003C\u002Fp>",{"id":163,"html":164,"type":84},"b23","\u003Cp>Support isn&#39;t the concern here — \u003Ccode>:focus-within\u003C\u002Fcode> has shipped in every engine for years (Chrome 60+, Firefox 52+, Safari 10.1+), no polyfill, no flag. The concern was ever having written the JS in the first place.\u003C\u002Fp>",{"id":166,"html":167,"type":84},"b24","\u003C!-- playground:start -->",{"id":169,"html":170,"text":170,"type":91,"level":31},"b25","🎮 Try it yourself",{"id":172,"html":173,"type":84},"b26","\u003Cp>\u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcss-focus-within-group-focus\u002Fplayground\">▶️ Open the interactive playground →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":175,"html":176,"type":84},"b27","\u003Cp>\u003Cem>Runs right in your browser — poke at it and watch the concept react live.\u003C\u002Fem>\u003C\u002Fp>",{"id":178,"html":179,"type":84},"b28","\u003C!-- playground:end -->",{"id":181,"html":182,"type":84},"b29","\u003C!-- quiz:start -->",{"id":184,"html":185,"text":185,"type":91,"level":31},"b30","🧠 Test yourself",{"id":187,"html":188,"type":84},"b31","\u003Cp>Think it clicked? \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcss-focus-within-group-focus\u002Fquiz\">Take the 7-question quiz →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":190,"html":191,"type":84},"b32","\u003Cp>\u003Cem>Instant feedback, a hint on every question, and an explanation for each answer — right or wrong.\u003C\u002Fem>\u003C\u002Fp>",{"id":193,"html":194,"type":84},"b33","\u003C!-- quiz:end -->",{"id":196,"html":197,"type":84},"b34","\u003Cp>Go find the component in your codebase with an \u003Ccode>onFocus\u003C\u002Fcode>\u002F\u003Ccode>onBlur\u003C\u002Fcode> pair whose only job is toggling a CSS class on a parent. I&#39;d bet money you have at least one. Rip it out and see if the browser was already willing to do it for free — then tell me what broke, because I&#39;d genuinely like to hear about the one case where it didn&#39;t just work.\u003C\u002Fp>",{"id":199,"type":200},"b35","divider",{"id":202,"html":203,"type":84},"b36","\u003Cp>🚀 \u003Cstrong>Want more like this?\u003C\u002Fstrong> Every guide, playground, and quiz lives on \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002F\">bestpractic.org\u003C\u002Fa>\u003C\u002Fstrong> — open it and \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002F\">sign up free\u003C\u002Fa>\u003C\u002Fstrong> so the next one finds you.\u003C\u002Fp>",{"id":205,"html":206,"type":84},"b37","\u003Cp>\u003Cem>Thanks for reading! Let&#39;s stay connected:\u003C\u002Fem>\u003C\u002Fp>",{"id":208,"type":139,"items":209,"ordered":18},"b38",[210,211,212],"⭐ \u003Cstrong>GitHub\u003C\u002Fstrong> — follow me and star the projects: \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fparsajiravand\">github.com\u002Fparsajiravand\u003C\u002Fa>","💬 \u003Cstrong>Discord\u003C\u002Fstrong> — join the frontend best-practices community: \u003Ca href=\"https:\u002F\u002Fdiscord.gg\u002Fd9KRhuAwQ\">discord.gg\u002Fd9KRhuAwQ\u003C\u002Fa>","📸 \u003Cstrong>Instagram\u003C\u002Fstrong> — frontend best practices, daily: \u003Ca href=\"https:\u002F\u002Fwww.instagram.com\u002Fbestpractice___\u002F\">@bestpractice___\u003C\u002Fa>","I built a search box with a clear button inside it — the little × that shows up once you've typed something. Standard stuff. The input had a nice blue ring when focused, so I matched it on the wrapper too: `border-color: var(--focus-color)` the moment the input gets focus, so the whole pill looks selected, not just the text caret.\n\nIt worked, until a teammate typed a query and clicked the ×. For one frame, the wrapper's border flashed back to gray — like the whole box had lost focus — before the input (correctly) still showing the cleared, empty state kept its own focus ring. It looked like a rendering glitch. It wasn't. It was `onBlur` doing exactly what `onBlur` does.\n\n## The fix everyone reaches for first\n\nThe wrapper's \"focused\" look was driven by state, toggled from the input's own focus and blur events:\n\n```jsx\nfunction SearchBox() {\n  const [focused, setFocused] = useState(false);\n\n  return (\n    \u003Cdiv className={focused ? \"search focused\" : \"search\"}>\n      \u003Cinput\n        onFocus={() => setFocused(true)}\n        onBlur={() => setFocused(false)}\n      \u002F>\n      \u003Cbutton onClick={clear}>×\u003C\u002Fbutton>\n    \u003C\u002Fdiv>\n  );\n}\n```\n\nClick the ×, and here's the order of events: the button steals focus away from the input, so the input's `blur` fires, `setFocused(false)` runs, and the wrapper's \"focused\" class disappears — a full render cycle before anyone notices the focus is still *inside the same component*, just on a different element.\n\nThe standard patch, and the one you'll find in a dozen Stack Overflow answers for exactly this: check where focus is going before you believe it left.\n\n```jsx\nonBlur={(e) => {\n  if (!e.currentTarget.contains(e.relatedTarget)) {\n    setFocused(false);\n  }\n}}\n```\n\n`relatedTarget` is the element about to receive focus — MDN documents it on the `FocusEvent` interface for exactly this reason. `currentTarget.contains(relatedTarget)` asks \"is the new focus target a descendant of the wrapper I'm attached to?\" If yes, don't un-focus. It works. It also has to be written again for every dropdown, every combobox, every form row with more than one focusable child — and it quietly breaks the moment the new target sits behind a portal or an iframe, where `contains()` can't see it at all.\n\n## The actual problem: blur is per-element, CSS doesn't know your widget is one thing\n\n`focus` and `blur` are defined per element. The browser has no built-in notion that the input and its clear button are \"one search box\" — that grouping exists only in your head and your JSX. So every time focus moves *within* a thing you consider one unit, the browser reports it as a departure from one element and an arrival at another, and you're stuck inferring \"same widget\" from DOM containment by hand.\n\nCSS already has the word for that grouping. It's a pseudo-class, not a state you manage:\n\n```css\n.search:focus-within {\n  border-color: var(--focus-color);\n}\n```\n\n`:focus-within` matches an element if *that element or any descendant* currently has focus. Click into the input — matches. Tab to the clear button — still matches, because the button is a descendant of `.search`. Click the × to actually blur out of the whole component — only then does it stop matching. No `useState`, no `onFocus`\u002F`onBlur` pair, no `relatedTarget` containment check, and no render at all: the browser repaints the border because the CSS rule re-evaluates, not because your component re-rendered.\n\n## Quick gut check before you keep scrolling\n\n`:focus`, `:focus-visible`, and `:focus-within` read like three names for the same idea. They're not:\n\n- **`:focus`** — matches the element that literally has focus right now. Just that one element.\n- **`:focus-visible`** — matches only when the browser thinks the focus indicator should show (keyboard navigation, mostly — a mouse click on a `\u003Cbutton>` usually doesn't trigger it). I wrote about this one back when `outline: none` was the fight.\n- **`:focus-within`** — matches an *ancestor* of whatever has focus, all the way up. The one this post is about.\n\nThey compose. `.search:focus-within:not(:focus)` matches the wrapper exactly when focus is inside it but not *on* it — useful if the wrapper itself is also focusable and you want different styling for \"I'm focused\" versus \"something inside me is.\"\n\n## Where this earns its keep beyond one search box\n\nThe same pattern shows up anywhere a widget is more than one focusable element and you want it to read as one thing:\n\n- **Form rows** — highlight the whole label-plus-input row when the input inside it is focused, without a listener on every row.\n- **Toolbars with grouped fields** — a date range picker with two inputs should look \"active\" if focus is on either one.\n- **Custom dropdowns and comboboxes** — keep a wrapper visually \"open\" while focus bounces between the trigger and the menu, instead of tracking that by hand.\n\nOne honest limit: `:focus-within` is CSS-only. It changes what gets *styled*, not what your JavaScript *knows*. If a component genuinely needs a boolean in JS — to fire an analytics event, say, or gate some other logic — you still need `focus`\u002F`blur` listeners (with the `relatedTarget` check, if you only want to know when focus leaves the whole group). What you get to delete is every line of state and every re-render that existed *only* to drive a style.\n\nSupport isn't the concern here — `:focus-within` has shipped in every engine for years (Chrome 60+, Firefox 52+, Safari 10.1+), no polyfill, no flag. The concern was ever having written the JS in the first place.\n\n\u003C!-- playground:start -->\n\n## 🎮 Try it yourself\n\n**[▶️ Open the interactive playground →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcss-focus-within-group-focus\u002Fplayground)**\n\n_Runs right in your browser — poke at it and watch the concept react live._\n\n\u003C!-- playground:end -->\n\n\u003C!-- quiz:start -->\n\n## 🧠 Test yourself\n\nThink it clicked? **[Take the 7-question quiz →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcss-focus-within-group-focus\u002Fquiz)**\n\n_Instant feedback, a hint on every question, and an explanation for each answer — right or wrong._\n\n\u003C!-- quiz:end -->\n\nGo find the component in your codebase with an `onFocus`\u002F`onBlur` pair whose only job is toggling a CSS class on a parent. I'd bet money you have at least one. Rip it out and see if the browser was already willing to do it for free — then tell me what broke, because I'd genuinely like to hear about the one case where it didn't just work.\n\n---\n\n🚀 **Want more like this?** Every guide, playground, and quiz lives on **[bestpractic.org](https:\u002F\u002Fbestpractic.org\u002F)** — open it and **[sign up free](https:\u002F\u002Fbestpractic.org\u002F)** so the next one finds you.\n\n*Thanks for reading! Let's stay connected:*\n\n- ⭐ **GitHub** — follow me and star the projects: [github.com\u002Fparsajiravand](https:\u002F\u002Fgithub.com\u002Fparsajiravand)\n- 💬 **Discord** — join the frontend best-practices community: [discord.gg\u002Fd9KRhuAwQ](https:\u002F\u002Fdiscord.gg\u002Fd9KRhuAwQ)\n- 📸 **Instagram** — frontend best practices, daily: [@bestpractice___](https:\u002F\u002Fwww.instagram.com\u002Fbestpractice___\u002F)",{"title":47,"canonical":215,"description":216},"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcss-focus-within-group-focus","A search box's own clear button kept un-focusing the whole wrapper, so I started checking event.relatedTarget on every blur to tell 'focus left the widget' from 'focus moved inside","01a22fd5-4b5e-7649-83f0-a5cf309d07d4",{"id":219,"locked":18},"01a22fd5-4b8c-7745-b402-87bcd47b1cc4",[221],{"id":222,"slug":46,"title":223,"_count":224},"01a22fd5-4bb6-752f-90f2-c91aeb200710",":focus-within — test yourself",{"questions":225},7,[227],{"locale":13,"slug":46},{"id":222,"slug":46,"title":223,"_count":229,"questionCount":225},{"questions":225},[231,233,237,239,241,243,247,251,255,259,263,267],{"slug":70,"name":71,"articles":232},203,{"slug":234,"name":235,"articles":236},"javascript","Javascript",159,{"slug":67,"name":68,"articles":238},106,{"slug":73,"name":74,"articles":240},93,{"slug":61,"name":65,"articles":242},60,{"slug":244,"name":245,"articles":246},"typescript","Typescript",38,{"slug":248,"name":249,"articles":250},"performance","Performance",34,{"slug":252,"name":253,"articles":254},"programming","Programming",27,{"slug":256,"name":257,"articles":258},"react","React",23,{"slug":260,"name":261,"articles":262},"node","Node",19,{"slug":264,"name":265,"articles":266},"browser","Browser",18,{"slug":268,"name":269,"articles":270},"nextjs","Nextjs",14,[],{"items":273,"meta":400},[274,286,310,328,346,364,382],{"id":45,"slug":46,"title":47,"subtitle":48,"excerpt":49,"coverUrl":50,"locale":13,"readingMinutes":51,"publishedAt":52,"viewCount":275,"likeCount":19,"commentCount":19,"author":276,"vertical":277,"topic":278,"tags":279,"_count":284,"playground":285,"hasQuiz":17,"hasPlayground":17},74,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[280,281,282,283],{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":70,"name":71,"color":48},{"slug":73,"name":74,"color":48},{"assessments":76},{"slug":46},{"id":287,"slug":288,"title":289,"subtitle":48,"excerpt":290,"coverUrl":291,"locale":13,"readingMinutes":292,"publishedAt":293,"viewCount":294,"likeCount":19,"commentCount":19,"author":295,"vertical":296,"topic":297,"tags":300,"_count":308,"playground":309,"hasQuiz":17,"hasPlayground":17},"01a21cc5-8784-732c-a79f-34ec3066e4d0","checkbox-switch-native-toggle","Your Toggle Switch Is Five Elements. `checkbox switch` Is One.","Every settings page has a toggle switch, and almost every one of them is a checkbox wearing a costume: a label, a span, a ::before, a transition, and — if someone remembered — a role=\"switch\". Safari shipped an attribute that does the whole job: checkbox switch.","\u002Fmedia\u002Fcovers\u002Fcheckbox-switch-native-toggle.png",6,"2026-12-03T16:10:59.158Z",146,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":298,"name":299},"html","HTML",[301,303,304,307],{"slug":298,"name":302,"color":48},"Html",{"slug":61,"name":65,"color":48},{"slug":305,"name":306,"color":48},"accessibility","Accessibility",{"slug":70,"name":71,"color":48},{"assessments":76},{"slug":288},{"id":311,"slug":312,"title":313,"subtitle":48,"excerpt":314,"coverUrl":315,"locale":13,"readingMinutes":51,"publishedAt":316,"viewCount":317,"likeCount":19,"commentCount":19,"author":318,"vertical":319,"topic":320,"tags":321,"_count":326,"playground":327,"hasQuiz":17,"hasPlayground":17},"01a21cc5-6e70-753b-8ca9-4a22a6062694","css-line-clamp-text-truncation","`line-clamp` Is Standardized Now. No Browser Ships It By Default.","Every card-grid truncation trick runs through the same four lines of `-webkit-line-clamp` CSS that nobody fully understands. The standardized `line-clamp` property exists in the spec — but Safari's implementation hasn't left Safari Technology Preview, Chrome has it prototyped behind an experimental flag, and Firefox keeps it behind a flag of its own.","\u002Fmedia\u002Fcovers\u002Fcss-line-clamp-text-truncation.png","2026-12-02T12:04:15.163Z",175,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[322,323,324,325],{"slug":61,"name":65,"color":48},{"slug":70,"name":71,"color":48},{"slug":67,"name":68,"color":48},{"slug":73,"name":74,"color":48},{"assessments":76},{"slug":312},{"id":329,"slug":330,"title":331,"subtitle":48,"excerpt":332,"coverUrl":333,"locale":13,"readingMinutes":51,"publishedAt":334,"viewCount":335,"likeCount":19,"commentCount":19,"author":336,"vertical":337,"topic":338,"tags":339,"_count":344,"playground":345,"hasQuiz":17,"hasPlayground":17},"01a21cc5-8175-722c-b0a2-f4c1db300af5","css-mask-image-scroll-fade-edges","CSS mask-image Explained: Fade Edges Without Gradient Divs","Horizontally scrolling chip lists and tab bars usually hint 'there's more to scroll' with an absolutely positioned gradient div glued to each edge. It works on a solid background and falls apart on anything else. mask-image fades the actual content, not a fake overlay.","\u002Fmedia\u002Fcovers\u002Fcss-mask-image-scroll-fade-edges.png","2026-12-02T01:45:45.100Z",186,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[340,341,342,343],{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":70,"name":71,"color":48},{"slug":73,"name":74,"color":48},{"assessments":76},{"slug":330},{"id":347,"slug":348,"title":349,"subtitle":48,"excerpt":350,"coverUrl":351,"locale":13,"readingMinutes":292,"publishedAt":352,"viewCount":353,"likeCount":19,"commentCount":19,"author":354,"vertical":355,"topic":356,"tags":357,"_count":362,"playground":363,"hasQuiz":17,"hasPlayground":17},"01a1fce0-c3d4-737b-8a48-5669d1350ff2","css-transition-behavior-allow-discrete","CSS Transitions Skip display: none. transition-behavior Fixes That.","You can finally animate a dialog in from display: none without JavaScript — transition-behavior and @starting-style turn the jump-cut into a real transition.","\u002Fmedia\u002Fcovers\u002Fcss-transition-behavior-allow-discrete.png","2026-11-27T11:46:28.711Z",258,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[358,359,360,361],{"slug":61,"name":65,"color":48},{"slug":70,"name":71,"color":48},{"slug":67,"name":68,"color":48},{"slug":73,"name":74,"color":48},{"assessments":76},{"slug":348},{"id":365,"slug":366,"title":367,"subtitle":48,"excerpt":368,"coverUrl":369,"locale":13,"readingMinutes":292,"publishedAt":370,"viewCount":371,"likeCount":19,"commentCount":19,"author":372,"vertical":373,"topic":374,"tags":375,"_count":380,"playground":381,"hasQuiz":17,"hasPlayground":17},"01a1df1b-24b4-759b-be78-50479b1bfe26","scrollbar-color-native-scrollbar-styling","I Deleted My Scrollbar Hacks. `scrollbar-color` Replaced Them.","A dashboard's scrollbar matched Figma in Chrome and looked broken in Firefox. scrollbar-color and scrollbar-width fix that with two lines of standard CSS — no vendor prefixes, no UA sniffing.","\u002Fmedia\u002Fcovers\u002Fscrollbar-color-native-scrollbar-styling.png","2026-11-27T11:42:54.989Z",225,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[376,377,378,379],{"slug":61,"name":65,"color":48},{"slug":70,"name":71,"color":48},{"slug":67,"name":68,"color":48},{"slug":73,"name":74,"color":48},{"assessments":76},{"slug":366},{"id":383,"slug":384,"title":385,"subtitle":48,"excerpt":386,"coverUrl":387,"locale":13,"readingMinutes":51,"publishedAt":388,"viewCount":389,"likeCount":19,"commentCount":19,"author":390,"vertical":391,"topic":392,"tags":393,"_count":398,"playground":399,"hasQuiz":17,"hasPlayground":17},"01a1df1b-36a8-772a-9e7a-3586a0ebff65","css-scroll-margin-top-anchor-offset","Your Sticky Header Is Hiding Anchor Links. `scroll-margin-top` Fixes It.","Clicking a table-of-contents link lands the heading right behind your sticky nav, half-hidden. The fix isn't a JavaScript scroll offset — it's one CSS property the browser already checks before it scrolls.","\u002Fmedia\u002Fcovers\u002Fcss-scroll-margin-top-anchor-offset.png","2026-11-21T06:52:41.283Z",466,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[394,395,396,397],{"slug":61,"name":65,"color":48},{"slug":70,"name":71,"color":48},{"slug":67,"name":68,"color":48},{"slug":73,"name":74,"color":48},{"assessments":76},{"slug":384},{"page":76,"perPage":225,"total":242,"totalPages":401},9,"\u003Cdiv class=\"shj shj-lang-jsx shj-multiline\" data-lang=\"jsx\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003Cdiv>6\u003C\u002Fdiv>\u003Cdiv>7\u003C\u002Fdiv>\u003Cdiv>8\u003C\u002Fdiv>\u003Cdiv>9\u003C\u002Fdiv>\u003Cdiv>10\u003C\u002Fdiv>\u003Cdiv>11\u003C\u002Fdiv>\u003Cdiv>12\u003C\u002Fdiv>\u003Cdiv>13\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-class\">SearchBox\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>focused\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> setFocused\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-func\">useState\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bool\">false\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n\n  \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\n    \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-var\">div\u003C\u002Fspan> \u003Cspan class=\"shj-class\">className\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">={\u003C\u002Fspan>focused \u003Cspan class=\"shj-oper\">?\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"search focused\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"search\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>\n      \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-var\">input\u003C\u002Fspan>\n        \u003Cspan class=\"shj-class\">onFocus\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">={\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-func\">setFocused\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bool\">true\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan>\n        \u003Cspan class=\"shj-class\">onBlur\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">={\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-func\">setFocused\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bool\">false\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan>\n      \u003Cspan class=\"shj-oper\">\u002F&gt;\u003C\u002Fspan>\n      \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-var\">button\u003C\u002Fspan> \u003Cspan class=\"shj-class\">onClick\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">={\u003C\u002Fspan>clear\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>×\u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u002F\u003C\u002Fspan>\u003Cspan class=\"shj-var\">button\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>\n    \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u002F\u003C\u002Fspan>\u003Cspan class=\"shj-var\">div\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>\n  \u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-jsx shj-multiline\" data-lang=\"jsx\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">onBlur\u003Cspan class=\"shj-oper\">=\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>e\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-kwd\">if\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">!\u003C\u002Fspan>e\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>currentTarget\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">contains\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>e\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>relatedTarget\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n    \u003Cspan class=\"shj-func\">setFocused\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bool\">false\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n  \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-css shj-multiline\" data-lang=\"css\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-var\">.search\u003C\u002Fspan>\u003Cspan class=\"shj-var\">:focus-within\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-var\">border-color\u003C\u002Fspan>: \u003Cspan class=\"shj-func\">var\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>--\u003Cspan class=\"shj-num\">focus-color\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>",{"locked":18,"total":19,"comments":406},[]]