Skip navigation
Future CSS Tip! 🔮 You can combine scroll-driven animation and anchor positioning to create a CSS…
0:00 / 0:34

Future CSS Tip! 🔮 You can combine scroll-driven animation and anchor positioning to create a CSS…

jhey ʕ•ᴥ•ʔ

@jh3yy148K followers

Visit on X
891 likesDownloadOriginal post

129,299 views

Future CSS Tip! 🔮 You can combine scroll-driven animation and anchor positioning to create a CSS only nav indicator 🤯 .el { animation: move; animation-timeline: --blog; } keyframes move {to { left: anchor(--blog left); }} Adapts to long text! 😎 CodePen.IO link below! 👇

9 Comments

Comments from the original post on X (Twitter)

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    Here's that @CodePen link! 🚀 You'll need to be in Chrome Canary to see this one in action as it requires Chromium 116+ 👀 But, it's pretty exciting to think what's possible with these APIs 🔥

    13 likes

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    And here's a shot of it updating to really long text in real-time 😎 CSS anchor-positioning will grab the left and right of whatever element is asked for and it will return a live value 🔥 [contenteditable] to the rescue! 😅

    6 likes

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    The gist of this demo is that 1. Anchor an indicator to the "Home" link 2. As we scroll animate a custom property change 3. That updates the CSS anchor position with the indicator moving to the relevant anchor 🤓 There's a little more to it than that. But, it's Friday! 😅

    6 likes

  • rich spirit's profile picture

    @zeusnotthegod

    @CodePen you..are goated

    2 likes

  • Khaled's profile picture

    @khaledbenyahya_

    @CodePen Pretty neat! That would solve a problem I'm currently facing, gonna try to implement this with Tailwind

    2 likes

  • Antonio Craveiro Jr's profile picture

    @craveiro_jr

    @CodePen @SaveToNotion

    1 like

  • Rob Winter ❄️ 🇺🇦's profile picture

    @AllStarBob

    @CodePen I can see this being very popular. Single page sites with clear sections will have usable navigation. 🤌🏻

    1 like

  • Jordan Fortin's profile picture

    @JordanFortin87

    @CodePen You can do that with basic HTML & CSS, just saying why do all the extra work

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    @CodePen This is just HTML & CSS 🤔 Show me how you create the nav indicator without using the new APIs

    2 likes