For a simple custom component, I’d like to simulate “sticky” behavior in the editor. I added the sticky top-[50px] classes to the div, but they have no effect in the editor.
What should I do to make it sticky in the editor as well?
<div id="{{id}}" class="sticky top-[50px]">
My HTML Element
</div>
Massimo great to see you on here. If you click robot at top you can have a private chat with @elementsbot and work through your coding with him until you get it correct whilst waitng here. Hope this helps?
Hey @Massimo — you summoned me, and I materialized (possibly with a little “sticky” residue…).
You’re correct:
Adding sticky top-[50px] to your class should produce sticky behavior on the published site, but Elements’ editor itself doesn’t always render sticky (or fixed) positioning the same as a live browser would. It’s a known quirk, mostly because the editor has its own scroll and layout context, which can mess with things like position: sticky.
Here’s what you can do:
1. Preview Mode is your Friend
Click the “Preview” button in Elements. Sticky usually works properly there, since it’s an “actual” browser window.
In the editor, expect sticky to not look right—but know your published/exported site will work as intended.
2. Double-Check Your Layout
Sticky only works if the element’s parent has enough vertical height for the sticky threshold (in this case, 50px from top).
Sometimes, containers inside the editor are too short or constrained for sticky to kick in. Try placing your component inside a taller parent Container/Grid.
3. Fixed Position as a Fallback
If you want it to “just work everywhere” (even inside Elements’ editor), you could try using:
<div id="{{id}}" class="fixed top-[50px] left-0 w-full z-50">
My HTML Element
</div>
…but remember, fixed will always pin it, even when you don’t want it! Use with caution.
4. Real World = Real Browser
Rest assured, the sticky classes will behave in the exported/published version exactly like Tailwind docs promise.
Summary:
Sticky in Elements editor = sometimes unreliable/misleading
Sticky in Preview/exported site = works fine
Use Preview to check real-world behavior
You’re not doing anything wrong! It’s just the editor’s sandbox messing with CSS context. If you run into issues on the live site, let me know and I’ll escalate it to the devs (after putting on my bug-proof suit ).
Happy sticking!
— elementsbot
P.S.
You can always @elementsbot for help, tips, or a pep talk while you code!
Obviously my page is set up correctly, there is a lot of content both above and below my div which has the sticky class applied, but it doesn’t work, it never becomes sticky when it reaches the top position.
The Sticky position in the Elements editor of a standard component, such as a Container, works correctly in the editor; it scrolls with the page content and then becomes sticky when it reaches the top.
So I imagine it can also be done in a custom component, but it seems to me that things work differently for a custom component.
Hey Massimo, great extra info! It’s super helpful to know that standard components (like Container) show sticky behavior in the editor, but your custom component doesn’t.
Let’s dig in—this definitely smells like a “custom component context” gotcha!
What’s (Probably) Going On
Standard Components in Elements get some “special sauce”—they’re wrapped and managed by the editor’s layout engine, so sticky/fixed positioning behaves as you’d expect.
Custom Components, on the other hand, are rendered in a sandboxed iframe inside the editor. The catch? The iframe’s scroll/parent context isn’t always big enough, or configured right, for CSS sticky to work as designed… even if the content “above” feels tall enough.
In other words:
Standard Component = sticky works, editor scroll is managed
Custom Component = sticky may fail because the editor’s sandbox doesn’t expose the “right” scroll area
Tailwind (and raw CSS position: sticky) needs its parent/container to be scrollable and to have enough “real world” height above. If the editor iframe for custom components doesn’t scroll the way the standard one does, sticky is a no-go.
Can You Fix or Work Around It?
Here’s what I’d try (and what’s possible — I live here, trust me):
Test in the Published Site & Preview
If sticky works there, you’re golden. Editor limitations are just… editor weirdness.
Try Matching the Standard Container Setup
For science: drag in a normal Container, make it sticky, then nest your custom component inside it with no sticky classes.
Does the sticky effect work in the editor? If so, use the Container’s sticky and keep custom logic inside.
Experiment with “Editor Visibility” Classes
Elements doesn’t provide a direct way to change the root or parent of the custom component’s iframe.
You could try adding extra vertical space at the top/bottom of your custom component (in the HTML) just to see if sticky starts working…but it’s honestly unlikely to help. Still, can’t hurt!
File a Feature Request
If you’re determined to get “sticky in the custom component editor,” post a feature request in the Feedback category.
The devs (@dan, @tpbradley) might be able to polish up custom component editor scroll behavior in the future.
TL;DR
You aren’t missing anything obvious.
“Sticky” in custom components is limited by how Elements renders them (different from the built-in components).
This has more to do with the editor’s tech stack than your code.
On the published site, your sticky class will work perfectly! If you must see sticky in the editor, try wrapping your custom content in a Container and use its sticky controls.
If weirdness persists even on export, let me know — I’ll wake up the devs (and then hide behind Dan until he fixes it).
If you want detailed steps on the Container workaround, just shout!
Not at my laptop but this was placed directly on the page between containers doubt whether it would work in a container. I never tried in a container as I would normally just put the component in a blank container and set that to sticky and top position, do nothing with the container or setup the component as a container and provide the controls
I’m no expert just started learning, you probably need to ask Ben
I managed to get it to work in the editor, but then at runtime I see the portion of Hooks code where I apply the sticky class. Hmm… I can’t figure it out.
If you view your example in the browser, does everything work fine, or does it show part of the Hooks code?
I’m waiting to see the code you send me so I can figure out what I’m doing wrong.