[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"verticals":3,"quiz-css-scroll-margin-top-anchor-offset":44,"search-suggestions":60,"quiz-article-css-scroll-margin-top-anchor-offset":108,"path-membership-css-scroll-margin-top-anchor-offset":289},[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,"kind":47,"title":48,"description":49,"config":50,"verticalId":5,"vertical":55,"course":52,"_count":56,"access":57,"attempts":59,"questionCount":51},"01a1df1b-3774-73d0-92cf-8c4abf29b98a","css-scroll-margin-top-anchor-offset","PRACTICE_QUIZ","Test yourself — scroll-margin-top","Seven questions on scroll-margin-top and scroll-padding-top: what they do, where you put them, and which browser behaviors actually honor them.",{"questionCount":51,"timeLimitSec":52,"shuffleQuestions":18,"shuffleOptions":17,"negativeMarking":19,"passScorePct":53,"maxAttempts":52,"revealAnswers":54,"allowFlagging":18,"allowBacktracking":17},7,null,70,"AFTER_SUBMIT",{"slug":6,"name":7},{"questions":51},{"allowed":17,"reason":58},"FREE",[],[61,65,69,73,77,81,85,89,93,96,100,104],{"slug":62,"name":63,"articles":64},"webdev","Webdev",178,{"slug":66,"name":67,"articles":68},"javascript","Javascript",142,{"slug":70,"name":71,"articles":72},"frontend","Frontend",99,{"slug":74,"name":75,"articles":76},"tutorial","Tutorial",74,{"slug":78,"name":79,"articles":80},"css","Css",54,{"slug":82,"name":83,"articles":84},"performance","Performance",31,{"slug":86,"name":87,"articles":88},"typescript","Typescript",26,{"slug":90,"name":91,"articles":92},"react","React",20,{"slug":94,"name":95,"articles":92},"programming","Programming",{"slug":97,"name":98,"articles":99},"browser","Browser",18,{"slug":101,"name":102,"articles":103},"node","Node",17,{"slug":105,"name":106,"articles":107},"html","Html",12,{"id":109,"slug":46,"title":110,"subtitle":52,"excerpt":111,"coverUrl":112,"locale":13,"readingMinutes":113,"publishedAt":114,"viewCount":115,"likeCount":19,"commentCount":19,"author":116,"vertical":121,"topic":122,"tags":124,"_count":129,"playground":131,"body":133,"bodyMd":274,"seo":275,"translationGroupId":279,"series":52,"podcastUrl":52,"verticalId":5,"thread":280,"assessments":282,"translations":285,"quiz":287},"01a1df1b-36a8-772a-9e7a-3586a0ebff65","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",5,"2026-11-21T06:52:41.283Z",28,{"id":117,"name":118,"username":119,"avatarUrl":52,"headline":120},"019fe637-3c25-7088-9034-39c9f15dc3c8","Parsa Jiravand","parsa","Frontend engineer · building bestpractic",{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":78,"name":123},"CSS",[125,126,127,128],{"slug":78,"name":79,"color":52},{"slug":62,"name":63,"color":52},{"slug":70,"name":71,"color":52},{"slug":74,"name":75,"color":52},{"assessments":130},1,{"slug":46,"title":132},"scroll-margin-top — interactive playground",{"blocks":134,"version":130},[135,139,142,147,150,156,159,162,169,172,176,179,182,186,189,192,195,199,202,205,208,211,214,217,221,224,228,232,235,238,241,244,247,250,253,256,259,262,265,268],{"id":136,"html":137,"type":138},"b1","\u003Cp>You redesign a docs page. Sticky header, clean table of contents down the side, the kind of polish that makes a demo look finished. Then someone clicks &quot;Installation&quot; in the TOC, and the page jumps — except the &quot;Installation&quot; heading is now sitting \u003Cem>behind\u003C\u002Fem> the header, top third clipped off, like the scroll stopped one beat too early.\u003C\u002Fp>","paragraph",{"id":140,"html":141,"type":138},"b2","\u003Cp>It&#39;s not a bug in your heading. It&#39;s not a bug in the TOC link. The browser scrolled exactly where you told it to. You just never told it about the header.\u003C\u002Fp>",{"id":143,"html":144,"text":145,"type":146,"level":31},"b3","The obvious fix that didn&#39;t quite work","The obvious fix that didn't quite work","heading",{"id":148,"html":149,"type":138},"b4","\u003Cp>The TOC links are plain anchors: \u003Ccode>&lt;a href=&quot;#installation&quot;&gt;\u003C\u002Fcode>. The browser handles the jump on its own — no JavaScript required, which is exactly why it feels like it shouldn&#39;t need any. So the first fix is the one that feels native to the problem: intercept the click, do the math yourself.\u003C\u002Fp>",{"id":151,"code":152,"type":153,"language":154,"highlight":155},"b5","document.querySelectorAll('a[href^=\"#\"]').forEach((link) => {\n  link.addEventListener(\"click\", (e) => {\n    e.preventDefault();\n    const id = link.getAttribute(\"href\").slice(1);\n    const target = document.getElementById(id);\n    const headerHeight = document.querySelector(\"header\").offsetHeight;\n    window.scrollTo({\n      top: target.getBoundingClientRect().top + window.scrollY - headerHeight - 16,\n      behavior: \"smooth\",\n    });\n  });\n});","code","js",[],{"id":157,"html":158,"type":138},"b6","\u003Cp>It works. Click a TOC link, the heading lands below the header, clean. Ship it, close the ticket.\u003C\u002Fp>",{"id":160,"html":161,"type":138},"b7","\u003Cp>Then QA files three more:\u003C\u002Fp>",{"id":163,"type":164,"items":165,"ordered":18},"b8","list",[166,167,168],"Deep-linking straight to \u003Ccode>yoursite.com\u002Fdocs#installation\u003C\u002Fcode> — no click ever fired — still lands the heading behind the header, because the hack only runs \u003Ccode>on click\u003C\u002Fcode>.","The browser&#39;s native back\u002Fforward button restores the old scroll position, not yours — hitting Back after a TOC click snaps right back behind the header.","Mobile ships a taller header. \u003Ccode>headerHeight\u003C\u002Fcode> was read once on load; resize the window and the offset is stale until a reload.",{"id":170,"html":171,"type":138},"b9","\u003Cp>Each of those is a separate bug with a separate fix — handle \u003Ccode>DOMContentLoaded\u003C\u002Fcode> for the deep-link case, listen for \u003Ccode>popstate\u003C\u002Fcode>, re-read \u003Ccode>offsetHeight\u003C\u002Fcode> on resize. You&#39;re not patching one bug anymore. You&#39;re reimplementing the browser&#39;s own &quot;scroll to this element&quot; logic, one missed case at a time, in a \u003Ccode>&lt;script&gt;\u003C\u002Fcode> tag.\u003C\u002Fp>",{"id":173,"html":174,"text":175,"type":146,"level":31},"b10","The browser already asks &quot;how much space do you need&quot;","The browser already asks \"how much space do you need\"",{"id":177,"html":178,"type":138},"b11","\u003Cp>Fragment navigation, \u003Ccode>Element.scrollIntoView()\u003C\u002Fcode>, and the browser scrolling a focused element into view as you tab through the page all go through the same question: \u003Cem>what counts as &quot;this element is now in view&quot;?\u003C\u002Fem> Since 2021, every major browser has agreed on an answer CSS checks before any of them run — \u003Ccode>scroll-margin-top\u003C\u002Fcode> and its counterpart, \u003Ccode>scroll-padding-top\u003C\u002Fcode>.\u003C\u002Fp>",{"id":180,"html":181,"type":138},"b12","\u003Cp>Put it on the headings themselves:\u003C\u002Fp>",{"id":183,"code":184,"type":153,"language":78,"highlight":185},"b13","h2,\nh3 {\n  scroll-margin-top: 4.5rem; \u002F* roughly the header's height, plus breathing room *\u002F\n}",[],{"id":187,"html":188,"type":138},"b14","\u003Cp>That&#39;s it. No click handler, no \u003Ccode>preventDefault()\u003C\u002Fcode>, no recomputed pixel offset. Click a TOC link, hit the browser&#39;s native back button, paste a \u003Ccode>#installation\u003C\u002Fcode> link straight into the address bar — every path the browser uses to bring that heading into view now stops 4.5rem early, because the browser itself is doing the arithmetic, the same way it always has.\u003C\u002Fp>",{"id":190,"html":191,"text":191,"type":146,"level":31},"b15","Per-heading vs. whole-page: pick the one that matches the bug",{"id":193,"html":194,"type":138},"b16","\u003Cp>\u003Ccode>scroll-margin-top\u003C\u002Fcode> goes on the \u003Cstrong>target\u003C\u002Fstrong> — the thing being scrolled to. \u003Ccode>scroll-padding-top\u003C\u002Fcode> goes on the \u003Cstrong>scroll container\u003C\u002Fstrong> — usually \u003Ccode>html\u003C\u002Fcode>, or whatever element actually scrolls — and applies the same offset to every target inside it, without touching each heading individually:\u003C\u002Fp>",{"id":196,"code":197,"type":153,"language":78,"highlight":198},"b17","html {\n  scroll-padding-top: 4.5rem; \u002F* one declaration, covers every #anchor on the site *\u002F\n}",[],{"id":200,"html":201,"type":138},"b18","\u003Cp>If every page on the site sits under the same sticky header, \u003Ccode>scroll-padding-top\u003C\u002Fcode> on \u003Ccode>html\u003C\u002Fcode> is the one-line, whole-site fix — set it once, forget it. Reach for \u003Ccode>scroll-margin-top\u003C\u002Fcode> on specific elements instead when different targets need different offsets: a shorter mobile header, a taller &quot;in-page alert&quot; banner above certain sections, or a card in a horizontally-scrolling carousel that needs its own left-edge margin rather than a top one.\u003C\u002Fp>",{"id":203,"html":204,"type":138},"b19","\u003C!-- playground:start -->",{"id":206,"html":207,"text":207,"type":146,"level":31},"b20","🎮 Try it yourself",{"id":209,"html":210,"type":138},"b21","\u003Cp>\u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcss-scroll-margin-top-anchor-offset\u002Fplayground\">▶️ Open the interactive playground →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":212,"html":213,"type":138},"b22","\u003Cp>\u003Cem>Runs right in your browser — poke at it and watch the concept react live.\u003C\u002Fem>\u003C\u002Fp>",{"id":215,"html":216,"type":138},"b23","\u003C!-- playground:end -->",{"id":218,"html":219,"text":220,"type":146,"level":31},"b24","Stop hardcoding the header&#39;s height as a magic number","Stop hardcoding the header's height as a magic number",{"id":222,"html":223,"type":138},"b25","\u003Cp>\u003Ccode>4.5rem\u003C\u002Fcode> is a guess that goes stale the day someone adds a banner to the header. Read the header&#39;s real height instead, and feed it in as a custom property:\u003C\u002Fp>",{"id":225,"code":226,"type":153,"language":78,"highlight":227},"b26",":root {\n  --header-h: 64px; \u002F* kept in sync with the header's actual rendered height *\u002F\n}\n\nh2,\nh3 {\n  scroll-margin-top: calc(var(--header-h) + 16px);\n}",[],{"id":229,"code":230,"type":153,"language":154,"highlight":231},"b27","const header = document.querySelector(\"header\");\nconst setHeaderHeight = () =>\n  document.documentElement.style.setProperty(\"--header-h\", `${header.offsetHeight}px`);\n\nsetHeaderHeight();\nnew ResizeObserver(setHeaderHeight).observe(header);",[],{"id":233,"html":234,"type":138},"b28","\u003Cp>Now the only JavaScript left is measuring the header — not re-deriving the browser&#39;s entire scroll-to-element behavior. If the header grows a second row on mobile, \u003Ccode>ResizeObserver\u003C\u002Fcode> catches it and the custom property updates; \u003Ccode>scroll-margin-top\u003C\u002Fcode> reads the new value on the next scroll. The division of labor is the point: JavaScript&#39;s job shrinks to &quot;report one number,&quot; and CSS&#39;s job — &quot;stop scrolling here&quot; — stays where the browser already does it for free.\u003C\u002Fp>",{"id":236,"html":237,"text":237,"type":146,"level":31},"b29","Where this still needs a human",{"id":239,"html":240,"type":138},"b30","\u003Cp>\u003Ccode>scroll-margin-top\u003C\u002Fcode> fixes where the page \u003Cem>lands\u003C\u002Fem>. It doesn&#39;t fix a heading that&#39;s visually ambiguous about whether it&#39;s &quot;the current section&quot; once it&#39;s sitting right under the header edge — that&#39;s a design question about header contrast and spacing, not a CSS-property question. And if your TOC also needs to highlight the \u003Cem>active\u003C\u002Fem> section as the reader scrolls, that&#39;s a separate job (usually \u003Ccode>IntersectionObserver\u003C\u002Fcode>), not something \u003Ccode>scroll-margin-top\u003C\u002Fcode> does for you. It solves exactly one problem — stopping short of the header — and it&#39;s worth not asking it to solve the other two.\u003C\u002Fp>",{"id":242,"html":243,"type":138},"b31","\u003C!-- quiz:start -->",{"id":245,"html":246,"text":246,"type":146,"level":31},"b32","🧠 Test yourself",{"id":248,"html":249,"type":138},"b33","\u003Cp>Think it clicked? \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcss-scroll-margin-top-anchor-offset\u002Fquiz\">Take the 7-question quiz →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":251,"html":252,"type":138},"b34","\u003Cp>\u003Cem>Instant feedback, a hint on every question, and an explanation for each answer — right or wrong.\u003C\u002Fem>\u003C\u002Fp>",{"id":254,"html":255,"type":138},"b35","\u003C!-- quiz:end -->",{"id":257,"html":258,"type":138},"b36","\u003Cp>The bug report wasn&#39;t &quot;the table of contents is broken.&quot; It was &quot;the browser doesn&#39;t know about your header&quot; — and it turns out the browser was willing to be told, in CSS, for free, since before most of us noticed. Got a scroll offset hack sitting in a \u003Ccode>click\u003C\u002Fcode> handler somewhere? Go check what it&#39;s actually compensating for — there&#39;s a decent chance one property replaces it.\u003C\u002Fp>",{"id":260,"type":261},"b37","divider",{"id":263,"html":264,"type":138},"b38","\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":266,"html":267,"type":138},"b39","\u003Cp>\u003Cem>Thanks for reading! Let&#39;s stay connected:\u003C\u002Fem>\u003C\u002Fp>",{"id":269,"type":164,"items":270,"ordered":18},"b40",[271,272,273],"⭐ \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>","You redesign a docs page. Sticky header, clean table of contents down the side, the kind of polish that makes a demo look finished. Then someone clicks \"Installation\" in the TOC, and the page jumps — except the \"Installation\" heading is now sitting *behind* the header, top third clipped off, like the scroll stopped one beat too early.\n\nIt's not a bug in your heading. It's not a bug in the TOC link. The browser scrolled exactly where you told it to. You just never told it about the header.\n\n## The obvious fix that didn't quite work\n\nThe TOC links are plain anchors: `\u003Ca href=\"#installation\">`. The browser handles the jump on its own — no JavaScript required, which is exactly why it feels like it shouldn't need any. So the first fix is the one that feels native to the problem: intercept the click, do the math yourself.\n\n```js\ndocument.querySelectorAll('a[href^=\"#\"]').forEach((link) => {\n  link.addEventListener(\"click\", (e) => {\n    e.preventDefault();\n    const id = link.getAttribute(\"href\").slice(1);\n    const target = document.getElementById(id);\n    const headerHeight = document.querySelector(\"header\").offsetHeight;\n    window.scrollTo({\n      top: target.getBoundingClientRect().top + window.scrollY - headerHeight - 16,\n      behavior: \"smooth\",\n    });\n  });\n});\n```\n\nIt works. Click a TOC link, the heading lands below the header, clean. Ship it, close the ticket.\n\nThen QA files three more:\n\n- Deep-linking straight to `yoursite.com\u002Fdocs#installation` — no click ever fired — still lands the heading behind the header, because the hack only runs `on click`.\n- The browser's native back\u002Fforward button restores the old scroll position, not yours — hitting Back after a TOC click snaps right back behind the header.\n- Mobile ships a taller header. `headerHeight` was read once on load; resize the window and the offset is stale until a reload.\n\nEach of those is a separate bug with a separate fix — handle `DOMContentLoaded` for the deep-link case, listen for `popstate`, re-read `offsetHeight` on resize. You're not patching one bug anymore. You're reimplementing the browser's own \"scroll to this element\" logic, one missed case at a time, in a `\u003Cscript>` tag.\n\n## The browser already asks \"how much space do you need\"\n\nFragment navigation, `Element.scrollIntoView()`, and the browser scrolling a focused element into view as you tab through the page all go through the same question: *what counts as \"this element is now in view\"?* Since 2021, every major browser has agreed on an answer CSS checks before any of them run — `scroll-margin-top` and its counterpart, `scroll-padding-top`.\n\nPut it on the headings themselves:\n\n```css\nh2,\nh3 {\n  scroll-margin-top: 4.5rem; \u002F* roughly the header's height, plus breathing room *\u002F\n}\n```\n\nThat's it. No click handler, no `preventDefault()`, no recomputed pixel offset. Click a TOC link, hit the browser's native back button, paste a `#installation` link straight into the address bar — every path the browser uses to bring that heading into view now stops 4.5rem early, because the browser itself is doing the arithmetic, the same way it always has.\n\n## Per-heading vs. whole-page: pick the one that matches the bug\n\n`scroll-margin-top` goes on the **target** — the thing being scrolled to. `scroll-padding-top` goes on the **scroll container** — usually `html`, or whatever element actually scrolls — and applies the same offset to every target inside it, without touching each heading individually:\n\n```css\nhtml {\n  scroll-padding-top: 4.5rem; \u002F* one declaration, covers every #anchor on the site *\u002F\n}\n```\n\nIf every page on the site sits under the same sticky header, `scroll-padding-top` on `html` is the one-line, whole-site fix — set it once, forget it. Reach for `scroll-margin-top` on specific elements instead when different targets need different offsets: a shorter mobile header, a taller \"in-page alert\" banner above certain sections, or a card in a horizontally-scrolling carousel that needs its own left-edge margin rather than a top one.\n\n\u003C!-- playground:start -->\n\n## 🎮 Try it yourself\n\n**[▶️ Open the interactive playground →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcss-scroll-margin-top-anchor-offset\u002Fplayground)**\n\n_Runs right in your browser — poke at it and watch the concept react live._\n\n\u003C!-- playground:end -->\n\n## Stop hardcoding the header's height as a magic number\n\n`4.5rem` is a guess that goes stale the day someone adds a banner to the header. Read the header's real height instead, and feed it in as a custom property:\n\n```css\n:root {\n  --header-h: 64px; \u002F* kept in sync with the header's actual rendered height *\u002F\n}\n\nh2,\nh3 {\n  scroll-margin-top: calc(var(--header-h) + 16px);\n}\n```\n\n```js\nconst header = document.querySelector(\"header\");\nconst setHeaderHeight = () =>\n  document.documentElement.style.setProperty(\"--header-h\", `${header.offsetHeight}px`);\n\nsetHeaderHeight();\nnew ResizeObserver(setHeaderHeight).observe(header);\n```\n\nNow the only JavaScript left is measuring the header — not re-deriving the browser's entire scroll-to-element behavior. If the header grows a second row on mobile, `ResizeObserver` catches it and the custom property updates; `scroll-margin-top` reads the new value on the next scroll. The division of labor is the point: JavaScript's job shrinks to \"report one number,\" and CSS's job — \"stop scrolling here\" — stays where the browser already does it for free.\n\n## Where this still needs a human\n\n`scroll-margin-top` fixes where the page *lands*. It doesn't fix a heading that's visually ambiguous about whether it's \"the current section\" once it's sitting right under the header edge — that's a design question about header contrast and spacing, not a CSS-property question. And if your TOC also needs to highlight the *active* section as the reader scrolls, that's a separate job (usually `IntersectionObserver`), not something `scroll-margin-top` does for you. It solves exactly one problem — stopping short of the header — and it's worth not asking it to solve the other two.\n\n\u003C!-- quiz:start -->\n\n## 🧠 Test yourself\n\nThink it clicked? **[Take the 7-question quiz →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcss-scroll-margin-top-anchor-offset\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\nThe bug report wasn't \"the table of contents is broken.\" It was \"the browser doesn't know about your header\" — and it turns out the browser was willing to be told, in CSS, for free, since before most of us noticed. Got a scroll offset hack sitting in a `click` handler somewhere? Go check what it's actually compensating for — there's a decent chance one property replaces it.\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":276,"canonical":277,"description":278},"Your Sticky Header Is Hiding Anchor Links. `scroll-margin-top` Fixes I","https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcss-scroll-margin-top-anchor-offset","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 ","01a1df1b-36a8-772a-9e7a-3a0dbfcb434d",{"id":281,"locked":18},"01a1df1b-3742-7327-9820-8bc3a02db8e6",[283],{"id":45,"slug":46,"title":48,"_count":284},{"questions":51},[286],{"locale":13,"slug":46},{"id":45,"slug":46,"title":48,"_count":288,"questionCount":51},{"questions":51},[]]