{"id":20189,"date":"2025-10-10T13:35:13","date_gmt":"2025-10-10T08:05:13","guid":{"rendered":"https:\/\/vinish.dev\/?p=20189"},"modified":"2025-10-12T21:04:27","modified_gmt":"2025-10-12T15:34:27","slug":"sticky-header-changes-on-scroll","status":"publish","type":"post","link":"https:\/\/vinish.dev\/sticky-header-changes-on-scroll","title":{"rendered":"How to Create a Sticky Header That Changes on Scroll"},"content":{"rendered":"\n<p>A sticky header can make your site feel faster and easier to navigate, since your logo and menu stay within reach as you scroll. I will show you how to create a sticky header that changes on scroll, first with a quick example, then with a complete, <a href=\"https:\/\/vinish.dev\/css-grid-responsive-layouts-tutorial\">responsive<\/a> version. I will explain every step in plain language, so even if you are new to CSS and JavaScript, you can follow along and test it on your own.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What a \u201csticky header\u201d is, and why it should change on scroll<\/h2>\n\n\n\n<p>A sticky header is a top bar that sticks to the top of the page as you scroll down. In CSS, this is usually done with <code>position: sticky<\/code> plus <code>top: 0<\/code>. Unlike <code>position: fixed<\/code>, a sticky element stays in the normal page flow until you scroll past it, then it sticks. I like to change the header\u2019s background, height, and shadow once the user scrolls a little, which improves readability over the content and makes the header feel subtle at the top, then more solid as you move down.<\/p>\n\n\n\n<p>Key CSS for the sticky behavior looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.header {\n  position: sticky;\n  top: 0;               \/* stick to top when reached *\/\n  z-index: 1000;        \/* keep it above page content *\/\n}\n<\/pre>\n\n\n\n<p>To \u201cchange on scroll,\u201d I add or remove a class on the header when the page scroll position is greater than a small threshold. For example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">header.classList.toggle('scrolled', window.scrollY &gt; 10);\n<\/pre>\n\n\n\n<p>This flips the <code>.scrolled<\/code> class on the header element. Then I can define different styles for <code>.header.scrolled<\/code> in CSS.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example 1: Sticky header that changes on scroll<\/h2>\n\n\n\n<p>This first example uses mostly a single div for the header, minimal CSS, and a tiny script that adds a shadow, a darker background, and slightly reduces padding once you scroll. Copy, paste, and run it in your browser.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;!doctype html&gt;<br>&lt;html lang=\"en\"&gt;<br>&lt;head&gt;<br>  &lt;meta charset=\"utf-8\" \/&gt;<br>  &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" \/&gt;<br>  &lt;title&gt;Quick Sticky Header That Changes on Scroll&lt;\/title&gt;<br>  &lt;style&gt;<br>    :root {<br>      --text: #111827;<br>      --text-inverse: #ffffff;<br>      --bg: rgba(255, 255, 255, 0.7);<br>      --bg-scrolled: #111827;<br>    }<br><br>    * { box-sizing: border-box; }<br>    body {<br>      margin: 0;<br>      font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;<br>      line-height: 1.6;<br>      color: var(--text);<br>    }<br><br>    \/* Sticky header *\/<br>    .header {<br>      position: sticky;<br>      top: 0;<br>      z-index: 1000;<br>      background: var(--bg);<br>      color: var(--text);<br>      backdrop-filter: saturate(180%) blur(8px);<br>      padding: 16px 20px;<br>      transition:<br>        background-color 200ms ease,<br>        color 200ms ease,<br>        box-shadow 200ms ease,<br>        padding 200ms ease;<br>    }<br><br>    \/* Style once scrolled *\/<br>    .header.scrolled {<br>      background: var(--bg-scrolled);<br>      color: var(--text-inverse);<br>      box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);<br>      padding: 10px 20px;<br>    }<br><br>    .title { font-weight: 700; font-size: 18px; }<br><br>    \/* Page content *\/<br>    .content { padding: 24px 20px; max-width: 800px; margin: 0 auto; }<br>    .block {<br>      height: 85vh;<br>      margin-bottom: 24px;<br>      padding: 20px;<br>      border-radius: 12px;<br>      background: linear-gradient(180deg, #fdf2f8, #eff6ff);<br>    }<br><br>    @media (max-width: 480px) {<br>      .title { font-size: 16px; }<br>    }<br>  &lt;\/style&gt;<br>&lt;\/head&gt;<br>&lt;body&gt;<br>  &lt;div class=\"header\" id=\"header\"&gt;<br>    &lt;div class=\"title\"&gt;My Sticky Header&lt;\/div&gt;<br>  &lt;\/div&gt;<br><br>  &lt;main class=\"content\"&gt;<br>    &lt;div class=\"block\"&gt;Scroll to see the header change, background darkens and padding shrinks.&lt;\/div&gt;<br>    &lt;div class=\"block\"&gt;Keep scrolling for more space to test the behavior.&lt;\/div&gt;<br>    &lt;div class=\"block\"&gt;End of demo.&lt;\/div&gt;<br>  &lt;\/main&gt;<br><br>  &lt;script&gt;<br>    (function () {<br>      const header = document.getElementById('header');<br>      const onScroll = () =&gt; header.classList.toggle('scrolled', window.scrollY &gt; 10);<br>      onScroll(); \/\/ initialize on load<br>      window.addEventListener('scroll', onScroll, { passive: true });<br>    })();<br>  &lt;\/script&gt;<br>&lt;\/body&gt;<br>&lt;\/html&gt;<\/pre>\n\n\n\n<p>A couple of important lines:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>CSS <code>position: sticky; top: 0;<\/code> makes the header stick.<\/li>\n\n\n\n<li>JavaScript <code>header.classList.toggle('scrolled', window.scrollY &gt; 10);<\/code> adds the <code>scrolled<\/code> class once you scroll farther than 10 pixels.<\/li>\n\n\n\n<li>The <code>.header.scrolled<\/code> rule sets a darker background and a shadow for contrast.<\/li>\n<\/ul>\n\n\n\n<p>If your content ever overlaps the header, increase <code>z-index<\/code> on <code>.header<\/code> or check that no parent has <code>overflow: hidden<\/code> that can trap the sticky element.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example 2: Complete responsive sticky header that changes on scroll<\/h2>\n\n\n\n<p>This full example adds a logo, a navigation menu, a call to action button, and a mobile menu that slides down. The header changes background, height, logo size, and <a href=\"https:\/\/vinish.dev\/shadows-depth-css-layers\">shadow<\/a> when you scroll. It uses <code>IntersectionObserver<\/code> for a smooth, efficient scroll detection, with a tiny fallback to <code>scroll<\/code> if needed.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;!doctype html&gt;<br>&lt;html lang=\"en\"&gt;<br>&lt;head&gt;<br>  &lt;meta charset=\"utf-8\" \/&gt;<br>  &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" \/&gt;<br>  &lt;title&gt;Complete Sticky Header That Changes on Scroll&lt;\/title&gt;<br>  &lt;style&gt;<br>    :root {<br>      --brand: #2563eb;<br>      --text: #111827;<br>      --text-dim: #374151;<br>      --bg-scrolled: #ffffff;<br>      --header-height: 72px;<br>      --header-height-scrolled: 56px;<br>    }<br><br>    * { box-sizing: border-box; }<br>    body {<br>      margin: 0;<br>      font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;<br>      color: var(--text);<br>      line-height: 1.6;<br>    }<br><br>    \/* Sticky site header *\/<br>    .header {<br>      position: sticky;<br>      top: 0;<br>      z-index: 1000;<br>      background: rgba(255, 255, 255, 0.6);<br>      backdrop-filter: saturate(180%) blur(8px);<br>      transition: background-color 200ms ease, box-shadow 200ms ease;<br>    }<br><br>    .header-inner {<br>      max-width: 1100px;<br>      margin: 0 auto;<br>      height: var(--header-height);<br>      display: flex;<br>      align-items: center;<br>      justify-content: space-between;<br>      gap: 16px;<br>      padding: 0 16px;<br>      transition: height 200ms ease;<br>    }<br><br>    .header.is-scrolled {<br>      background: var(--bg-scrolled);<br>      box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);<br>    }<br><br>    .header.is-scrolled .header-inner {<br>      height: var(--header-height-scrolled);<br>    }<br><br>    \/* Brand *\/<br>    .brand {<br>      display: inline-flex;<br>      align-items: center;<br>      gap: 10px;<br>      text-decoration: none;<br>      color: var(--text);<br>      font-weight: 800;<br>      letter-spacing: 0.2px;<br>    }<br><br>    .logo {<br>      width: 36px;<br>      height: 36px;<br>      border-radius: 8px;<br>      background: linear-gradient(135deg, var(--brand), #7c3aed);<br>      display: grid;<br>      place-items: center;<br>      color: #fff;<br>      font-size: 18px;<br>      transition: transform 200ms ease;<br>      user-select: none;<br>    }<br><br>    .header.is-scrolled .logo {<br>      transform: scale(0.9);<br>    }<br><br>    \/* Navigation *\/<br>    .nav {<br>      display: flex;<br>      align-items: center;<br>      gap: 12px;<br>    }<br><br>    .nav a {<br>      text-decoration: none;<br>      color: var(--text-dim);<br>      padding: 8px 10px;<br>      border-radius: 8px;<br>      transition: background-color 150ms ease, color 150ms ease;<br>    }<br><br>    .nav a:hover {<br>      background: rgba(37, 99, 235, 0.08);<br>      color: var(--text);<br>    }<br><br>    .cta {<br>      background: var(--brand);<br>      color: #fff;<br>      border: none;<br>      padding: 10px 14px;<br>      border-radius: 10px;<br>      cursor: pointer;<br>      font-weight: 600;<br>    }<br><br>    \/* Mobile menu button *\/<br>    .menu-btn {<br>      display: none;<br>      background: transparent;<br>      border: 0;<br>      padding: 8px 10px;<br>      border-radius: 8px;<br>      font-size: 16px;<br>    }<br><br>    \/* Content *\/<br>    main { max-width: 1100px; margin: 0 auto; padding: 16px; }<br>    .hero {<br>      height: 60vh;<br>      margin: 16px;<br>      border-radius: 16px;<br>      display: grid;<br>      place-items: center;<br>      text-align: center;<br>      background: linear-gradient(135deg, #e0f2fe, #f5f3ff);<br>    }<br><br>    .section {<br>      max-width: 900px;<br>      margin: 0 auto;<br>      padding: 24px 16px;<br>    }<br>    .section + .section { border-top: 1px solid #e5e7eb; }<br><br>    .footer {<br>      border-top: 1px solid #e5e7eb;<br>      color: #6b7280;<br>      text-align: center;<br>      padding: 24px 16px;<br>    }<br><br>    \/* Mobile layout *\/<br>    @media (max-width: 768px) {<br>      .menu-btn { display: inline-flex; align-items: center; gap: 8px; }<br>      .nav {<br>        position: fixed;<br>        inset: var(--header-height) 0 auto 0; \/* top, right, bottom, left *\/<br>        background: rgba(255, 255, 255, 0.98);<br>        transform: translateY(-110%);<br>        opacity: 0;<br>        pointer-events: none;<br>        transition: transform 220ms ease, opacity 220ms ease;<br>        padding: 16px;<br>        box-shadow: 0 14px 30px rgba(0, 0, 0, 0.08);<br>        flex-direction: column;<br>        gap: 8px;<br>      }<br>      .header.is-scrolled .nav {<br>        inset: var(--header-height-scrolled) 0 auto 0;<br>      }<br>      .nav.open {<br>        transform: translateY(0);<br>        opacity: 1;<br>        pointer-events: auto;<br>      }<br>      .nav a { font-size: 18px; }<br>      .cta { width: 100%; text-align: center; }<br>    }<br><br>    \/* Nice anchor jumps under a sticky header *\/<br>    :where(h2, h3, section, [id]) { scroll-margin-top: var(--header-height-scrolled); }<br>  &lt;\/style&gt;<br>&lt;\/head&gt;<br>&lt;body&gt;<br>  &lt;header class=\"header\" id=\"site-header\"&gt;<br>    &lt;div class=\"header-inner\"&gt;<br>      &lt;a class=\"brand\" href=\"#\"&gt;<br>        &lt;div class=\"logo\" aria-hidden=\"true\"&gt;S&lt;\/div&gt;<br>        &lt;span&gt;StickySite&lt;\/span&gt;<br>      &lt;\/a&gt;<br><br>      &lt;button class=\"menu-btn\" id=\"menu-btn\" aria-expanded=\"false\" aria-controls=\"site-nav\"&gt;<br>        Menu<br>      &lt;\/button&gt;<br><br>      &lt;nav class=\"nav\" id=\"site-nav\"&gt;<br>        &lt;a href=\"#features\"&gt;Features&lt;\/a&gt;<br>        &lt;a href=\"#pricing\"&gt;Pricing&lt;\/a&gt;<br>        &lt;a href=\"#docs\"&gt;Docs&lt;\/a&gt;<br>        &lt;button class=\"cta\"&gt;Get Started&lt;\/button&gt;<br>      &lt;\/nav&gt;<br>    &lt;\/div&gt;<br>  &lt;\/header&gt;<br><br>  &lt;main&gt;<br>    &lt;div class=\"hero\"&gt;<br>      &lt;div&gt;<br>        &lt;h1&gt;Sticky Header That Changes on Scroll&lt;\/h1&gt;<br>        &lt;p&gt;Scroll down to watch the header background, height, and shadow adapt.&lt;\/p&gt;<br>      &lt;\/div&gt;<br>    &lt;\/div&gt;<br><br>    &lt;section class=\"section\" id=\"features\"&gt;<br>      &lt;h2&gt;Features&lt;\/h2&gt;<br>      &lt;p&gt;Readable at any scroll position, smooth transitions, mobile menu, and clean CSS variables for sizes and colors.&lt;\/p&gt;<br>      &lt;p&gt;Keep scrolling to trigger the header change.&lt;\/p&gt;<br>    &lt;\/section&gt;<br><br>    &lt;section class=\"section\" id=\"pricing\"&gt;<br>      &lt;h2&gt;Pricing&lt;\/h2&gt;<br>      &lt;p&gt;Use this space to test anchor links under a sticky header, the page offsets correctly using scroll-margin-top.&lt;\/p&gt;<br>    &lt;\/section&gt;<br><br>    &lt;section class=\"section\" id=\"docs\"&gt;<br>      &lt;h2&gt;Docs&lt;\/h2&gt;<br>      &lt;p&gt;Replace this content with your documentation, or keep it as a scroll testing area.&lt;\/p&gt;<br>    &lt;\/section&gt;<br>  &lt;\/main&gt;<br><br>  &lt;footer class=\"footer\"&gt;Footer area&lt;\/footer&gt;<br><br>  &lt;script&gt;<br>    (function () {<br>      const header = document.getElementById('site-header');<br>      const menuBtn = document.getElementById('menu-btn');<br>      const nav = document.getElementById('site-nav');<br><br>      \/\/ Mobile menu toggle<br>      menuBtn.addEventListener('click', () =&gt; {<br>        const open = nav.classList.toggle('open');<br>        menuBtn.setAttribute('aria-expanded', String(open));<br>      });<br><br>      \/\/ Helper to toggle scrolled class<br>      const update = (scrolled) =&gt; header.classList.toggle('is-scrolled', scrolled);<br><br>      \/\/ Prefer IntersectionObserver for performance<br>      if ('IntersectionObserver' in window) {<br>        const sentinel = document.createElement('div');<br>        sentinel.style.position = 'absolute';<br>        sentinel.style.top = '0';<br>        sentinel.style.height = '1px';<br>        sentinel.style.width = '1px';<br>        document.body.prepend(sentinel);<br><br>        const obs = new IntersectionObserver((entries) =&gt; {<br>          \/\/ When sentinel leaves the viewport, user has scrolled<br>          update(!entries[0].isIntersecting);<br>        });<br>        obs.observe(sentinel);<br><br>        \/\/ Set initial state<br>        requestAnimationFrame(() =&gt; update(window.scrollY &gt; 10));<br>      } else {<br>        \/\/ Fallback<br>        const onScroll = () =&gt; update(window.scrollY &gt; 10);<br>        onScroll();<br>        window.addEventListener('scroll', onScroll, { passive: true });<br>      }<br>    })();<br>  &lt;\/script&gt;<br>&lt;\/body&gt;<br>&lt;\/html&gt;<\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img decoding=\"async\" width=\"1024\" height=\"457\" src=\"https:\/\/vinish.dev\/wp-content\/uploads\/2025\/10\/sticky-header-2-1024x457.png\" alt=\"Responsive sticky header over a hero section, transparent background before scrolling.\" class=\"wp-image-20194\" srcset=\"https:\/\/vinish.dev\/wp-content\/uploads\/2025\/10\/sticky-header-2-1024x457.png 1024w, https:\/\/vinish.dev\/wp-content\/uploads\/2025\/10\/sticky-header-2-300x134.png 300w, https:\/\/vinish.dev\/wp-content\/uploads\/2025\/10\/sticky-header-2-768x342.png 768w, https:\/\/vinish.dev\/wp-content\/uploads\/2025\/10\/sticky-header-2.png 1200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>A few details I want you to notice:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The header sticks with <code>position: sticky; top: 0;<\/code> so content naturally flows below it.<\/li>\n\n\n\n<li>I change the header\u2019s height by targeting <code>.header.is-scrolled .header-inner<\/code>. That keeps the transition smooth.<\/li>\n\n\n\n<li>The mobile menu is <code>position: fixed<\/code> inside the header, it slides in under the header using <code>inset<\/code> and a transform, then it adjusts its top offset when the header is scrolled.<\/li>\n<\/ul>\n\n\n\n<p>To highlight the core scroll logic, here is the <code>IntersectionObserver<\/code> line that flips state based on a tiny sentinel at the top of the page:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">new IntersectionObserver(entries =&gt; update(!entries[0].isIntersecting));\n<\/pre>\n\n\n\n<p>This is both smooth and battery friendly, since the browser can batch these observations.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common pitfalls and quick fixes<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Header covering anchor links: add <code>scroll-margin-top<\/code> to sections, for example <code>scroll-margin-top: 56px;<\/code> so in page links land cleanly below the header.<\/li>\n\n\n\n<li>Header not staying on top: ensure a high <code>z-index<\/code> on the header, and avoid <code>overflow: hidden<\/code> on a parent wrapper.<\/li>\n\n\n\n<li>Low contrast after scroll: add a solid background and <code>box-shadow<\/code> to <code>.is-scrolled<\/code> so text remains legible over complex content.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Closing thoughts<\/h2>\n\n\n\n<p>You now have two working patterns for a sticky header that changes on scroll. The quick version is perfect for prototypes or simple sites, the complete version gives you a solid base for production with responsive behavior and smooth performance. As you refine your design, play with the transition timing, the shadow intensity, and the color contrast so the header feels helpful, not distracting.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A sticky header can make your site feel faster and easier to navigate, since your logo and menu stay within reach as you scroll. I will show you how to create a sticky header that changes on scroll, first with a quick example, then with a complete, responsive version. I will explain every step in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":20194,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1821],"tags":[1822],"class_list":["post-20189","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-css","tag-ai-assisted"],"blocksy_meta":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Create a Sticky Header That Changes on Scroll &#8226; Vinish.Dev<\/title>\n<meta name=\"description\" content=\"Learn how to create a sticky header that changes on scroll using simple HTML, CSS, and a tiny bit of JavaScript, includes a quick demo.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vinish.dev\/sticky-header-changes-on-scroll\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create a Sticky Header That Changes on Scroll &#8226; Vinish.Dev\" \/>\n<meta property=\"og:description\" content=\"Learn how to create a sticky header that changes on scroll using simple HTML, CSS, and a tiny bit of JavaScript, includes a quick demo.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vinish.dev\/sticky-header-changes-on-scroll\" \/>\n<meta property=\"og:site_name\" content=\"Vinish.Dev\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/foxinfotech2014\" \/>\n<meta property=\"article:published_time\" content=\"2025-10-10T08:05:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-10-12T15:34:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/vinish.dev\/wp-content\/uploads\/2025\/10\/sticky-header-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"535\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Vinish Kapoor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/x.com\/vinish_kapoor\" \/>\n<meta name=\"twitter:site\" content=\"@foxinfotech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vinish Kapoor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/vinish.dev\\\/sticky-header-changes-on-scroll#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vinish.dev\\\/sticky-header-changes-on-scroll\"},\"author\":{\"name\":\"Vinish Kapoor\",\"@id\":\"https:\\\/\\\/vinish.dev\\\/#\\\/schema\\\/person\\\/a7790479716d2a54131ca873f8483d3f\"},\"headline\":\"How to Create a Sticky Header That Changes on Scroll\",\"datePublished\":\"2025-10-10T08:05:13+00:00\",\"dateModified\":\"2025-10-12T15:34:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/vinish.dev\\\/sticky-header-changes-on-scroll\"},\"wordCount\":611,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/vinish.dev\\\/#\\\/schema\\\/person\\\/df5e5ca816f6f4302efc03cf58dc97b4\"},\"image\":{\"@id\":\"https:\\\/\\\/vinish.dev\\\/sticky-header-changes-on-scroll#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/vinish.dev\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/sticky-header-2.png\",\"keywords\":[\"AI-Assisted\"],\"articleSection\":[\"CSS\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/vinish.dev\\\/sticky-header-changes-on-scroll#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/vinish.dev\\\/sticky-header-changes-on-scroll\",\"url\":\"https:\\\/\\\/vinish.dev\\\/sticky-header-changes-on-scroll\",\"name\":\"How to Create a Sticky Header That Changes on Scroll &#8226; Vinish.Dev\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vinish.dev\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/vinish.dev\\\/sticky-header-changes-on-scroll#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/vinish.dev\\\/sticky-header-changes-on-scroll#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/vinish.dev\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/sticky-header-2.png\",\"datePublished\":\"2025-10-10T08:05:13+00:00\",\"dateModified\":\"2025-10-12T15:34:27+00:00\",\"description\":\"Learn how to create a sticky header that changes on scroll using simple HTML, CSS, and a tiny bit of JavaScript, includes a quick demo.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/vinish.dev\\\/sticky-header-changes-on-scroll#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/vinish.dev\\\/sticky-header-changes-on-scroll\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/vinish.dev\\\/sticky-header-changes-on-scroll#primaryimage\",\"url\":\"https:\\\/\\\/vinish.dev\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/sticky-header-2.png\",\"contentUrl\":\"https:\\\/\\\/vinish.dev\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/sticky-header-2.png\",\"width\":1200,\"height\":535,\"caption\":\"Responsive sticky header over a hero section, transparent background before scrolling.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/vinish.dev\\\/sticky-header-changes-on-scroll#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/vinish.dev\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"CSS\",\"item\":\"https:\\\/\\\/vinish.dev\\\/category\\\/css\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Create a Sticky Header That Changes on Scroll\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/vinish.dev\\\/#website\",\"url\":\"https:\\\/\\\/vinish.dev\\\/\",\"name\":\"Vinish.Dev\",\"description\":\"Vinish Kapoor&#039;s Blog: Best Oracle Blog for Developers\",\"publisher\":{\"@id\":\"https:\\\/\\\/vinish.dev\\\/#\\\/schema\\\/person\\\/df5e5ca816f6f4302efc03cf58dc97b4\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/vinish.dev\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/vinish.dev\\\/#\\\/schema\\\/person\\\/df5e5ca816f6f4302efc03cf58dc97b4\",\"name\":\"Vinish Kapoor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/vinish.dev\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/vinishprofile.png\",\"url\":\"https:\\\/\\\/vinish.dev\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/vinishprofile.png\",\"contentUrl\":\"https:\\\/\\\/vinish.dev\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/vinishprofile.png\",\"width\":192,\"height\":192,\"caption\":\"Vinish Kapoor\"},\"logo\":{\"@id\":\"https:\\\/\\\/vinish.dev\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/vinishprofile.png\"},\"description\":\"Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 25+ years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.\",\"sameAs\":[\"https:\\\/\\\/vinish.dev\\\/\",\"https:\\\/\\\/www.facebook.com\\\/foxinfotech2014\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/vinish-kapoor\\\/\",\"https:\\\/\\\/x.com\\\/foxinfotech\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/vinish.dev\\\/#\\\/schema\\\/person\\\/a7790479716d2a54131ca873f8483d3f\",\"name\":\"Vinish Kapoor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a67232caa79b11f24f16c371866a96cfb575e011ebda6fa6e3d088a837a31bde?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a67232caa79b11f24f16c371866a96cfb575e011ebda6fa6e3d088a837a31bde?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a67232caa79b11f24f16c371866a96cfb575e011ebda6fa6e3d088a837a31bde?s=96&d=identicon&r=g\",\"caption\":\"Vinish Kapoor\"},\"description\":\"Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 25+ years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.\",\"sameAs\":[\"https:\\\/\\\/vinish.dev\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/vinish-kapoor\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/x.com\\\/vinish_kapoor\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Create a Sticky Header That Changes on Scroll &#8226; Vinish.Dev","description":"Learn how to create a sticky header that changes on scroll using simple HTML, CSS, and a tiny bit of JavaScript, includes a quick demo.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/vinish.dev\/sticky-header-changes-on-scroll","og_locale":"en_US","og_type":"article","og_title":"How to Create a Sticky Header That Changes on Scroll &#8226; Vinish.Dev","og_description":"Learn how to create a sticky header that changes on scroll using simple HTML, CSS, and a tiny bit of JavaScript, includes a quick demo.","og_url":"https:\/\/vinish.dev\/sticky-header-changes-on-scroll","og_site_name":"Vinish.Dev","article_publisher":"https:\/\/www.facebook.com\/foxinfotech2014","article_published_time":"2025-10-10T08:05:13+00:00","article_modified_time":"2025-10-12T15:34:27+00:00","og_image":[{"width":1200,"height":535,"url":"https:\/\/vinish.dev\/wp-content\/uploads\/2025\/10\/sticky-header-2.png","type":"image\/png"}],"author":"Vinish Kapoor","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/x.com\/vinish_kapoor","twitter_site":"@foxinfotech","twitter_misc":{"Written by":"Vinish Kapoor","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vinish.dev\/sticky-header-changes-on-scroll#article","isPartOf":{"@id":"https:\/\/vinish.dev\/sticky-header-changes-on-scroll"},"author":{"name":"Vinish Kapoor","@id":"https:\/\/vinish.dev\/#\/schema\/person\/a7790479716d2a54131ca873f8483d3f"},"headline":"How to Create a Sticky Header That Changes on Scroll","datePublished":"2025-10-10T08:05:13+00:00","dateModified":"2025-10-12T15:34:27+00:00","mainEntityOfPage":{"@id":"https:\/\/vinish.dev\/sticky-header-changes-on-scroll"},"wordCount":611,"commentCount":0,"publisher":{"@id":"https:\/\/vinish.dev\/#\/schema\/person\/df5e5ca816f6f4302efc03cf58dc97b4"},"image":{"@id":"https:\/\/vinish.dev\/sticky-header-changes-on-scroll#primaryimage"},"thumbnailUrl":"https:\/\/vinish.dev\/wp-content\/uploads\/2025\/10\/sticky-header-2.png","keywords":["AI-Assisted"],"articleSection":["CSS"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/vinish.dev\/sticky-header-changes-on-scroll#respond"]}]},{"@type":"WebPage","@id":"https:\/\/vinish.dev\/sticky-header-changes-on-scroll","url":"https:\/\/vinish.dev\/sticky-header-changes-on-scroll","name":"How to Create a Sticky Header That Changes on Scroll &#8226; Vinish.Dev","isPartOf":{"@id":"https:\/\/vinish.dev\/#website"},"primaryImageOfPage":{"@id":"https:\/\/vinish.dev\/sticky-header-changes-on-scroll#primaryimage"},"image":{"@id":"https:\/\/vinish.dev\/sticky-header-changes-on-scroll#primaryimage"},"thumbnailUrl":"https:\/\/vinish.dev\/wp-content\/uploads\/2025\/10\/sticky-header-2.png","datePublished":"2025-10-10T08:05:13+00:00","dateModified":"2025-10-12T15:34:27+00:00","description":"Learn how to create a sticky header that changes on scroll using simple HTML, CSS, and a tiny bit of JavaScript, includes a quick demo.","breadcrumb":{"@id":"https:\/\/vinish.dev\/sticky-header-changes-on-scroll#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vinish.dev\/sticky-header-changes-on-scroll"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vinish.dev\/sticky-header-changes-on-scroll#primaryimage","url":"https:\/\/vinish.dev\/wp-content\/uploads\/2025\/10\/sticky-header-2.png","contentUrl":"https:\/\/vinish.dev\/wp-content\/uploads\/2025\/10\/sticky-header-2.png","width":1200,"height":535,"caption":"Responsive sticky header over a hero section, transparent background before scrolling."},{"@type":"BreadcrumbList","@id":"https:\/\/vinish.dev\/sticky-header-changes-on-scroll#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vinish.dev\/"},{"@type":"ListItem","position":2,"name":"CSS","item":"https:\/\/vinish.dev\/category\/css"},{"@type":"ListItem","position":3,"name":"How to Create a Sticky Header That Changes on Scroll"}]},{"@type":"WebSite","@id":"https:\/\/vinish.dev\/#website","url":"https:\/\/vinish.dev\/","name":"Vinish.Dev","description":"Vinish Kapoor&#039;s Blog: Best Oracle Blog for Developers","publisher":{"@id":"https:\/\/vinish.dev\/#\/schema\/person\/df5e5ca816f6f4302efc03cf58dc97b4"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vinish.dev\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/vinish.dev\/#\/schema\/person\/df5e5ca816f6f4302efc03cf58dc97b4","name":"Vinish Kapoor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vinish.dev\/wp-content\/uploads\/2023\/12\/vinishprofile.png","url":"https:\/\/vinish.dev\/wp-content\/uploads\/2023\/12\/vinishprofile.png","contentUrl":"https:\/\/vinish.dev\/wp-content\/uploads\/2023\/12\/vinishprofile.png","width":192,"height":192,"caption":"Vinish Kapoor"},"logo":{"@id":"https:\/\/vinish.dev\/wp-content\/uploads\/2023\/12\/vinishprofile.png"},"description":"Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 25+ years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.","sameAs":["https:\/\/vinish.dev\/","https:\/\/www.facebook.com\/foxinfotech2014","https:\/\/www.linkedin.com\/in\/vinish-kapoor\/","https:\/\/x.com\/foxinfotech"]},{"@type":"Person","@id":"https:\/\/vinish.dev\/#\/schema\/person\/a7790479716d2a54131ca873f8483d3f","name":"Vinish Kapoor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a67232caa79b11f24f16c371866a96cfb575e011ebda6fa6e3d088a837a31bde?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a67232caa79b11f24f16c371866a96cfb575e011ebda6fa6e3d088a837a31bde?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a67232caa79b11f24f16c371866a96cfb575e011ebda6fa6e3d088a837a31bde?s=96&d=identicon&r=g","caption":"Vinish Kapoor"},"description":"Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 25+ years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.","sameAs":["https:\/\/vinish.dev\/","https:\/\/www.linkedin.com\/in\/vinish-kapoor\/","https:\/\/x.com\/https:\/\/x.com\/vinish_kapoor"]}]}},"_links":{"self":[{"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/posts\/20189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/comments?post=20189"}],"version-history":[{"count":8,"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/posts\/20189\/revisions"}],"predecessor-version":[{"id":20245,"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/posts\/20189\/revisions\/20245"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/media\/20194"}],"wp:attachment":[{"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/media?parent=20189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/categories?post=20189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/tags?post=20189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}