Sticky

Make elements remain at the top of the viewport, like a sticky navigation.

Table of contents

Usage

To create an element that remains at the top of the viewport when scrolling down the site, add the data-uk-sticky attribute to that element.

Note Example elements on this page are only sticky until you scroll down to the next heading and disappear afterwards. This was done so as not to clutter your screen with all variations of sticky containers.

Position

By default, the element sticks to the top of the viewport. You can set the position: bottom option to stick it to the bottom of the viewport.

Start

To apply an offset to when the element should start being sticky, add the start option. The value can be in vh, % and px. It supports basic mathematics operands + and -. The default value of 0 means that the element’s top border and viewport’s top border intersect. A CSS Selector will set start to the selected element’s bottom border and the element’s top border.

End

To apply an offset to when the element should stop being sticky, add the stop option. The value can be in vh, % and px. It supports basic mathematics operands + and -. A value of 0 means that the element’s top border and viewport’s top border intersect, which would cause the element not to be sticky at all if start is also set to 0. A CSS Selector will set the end to the selected element’s bottom border and the element’s bottom border. false will make the element stick until the end of the page. true selects the parent element.

Offset

To set an offset to the viewport’s edge when the element is sticky, add the offset option. The value can be in vh, % and px. It supports basic mathematics operands + and -.

Animation

Add an animation from the Animation component in order to have the sticky element reappear smoothly if a start offset is set.

Show On Up

You can make the sticky element show only when scrolling up to save space. Together with an animation, this makes for a very smooth experience.

Responsive

It’s possible to disable the sticky behavior for different device widths by applying the media option to the attribute and adding the appropriate viewport width. Add a number in pixel, for example media: 640, or a breakpoint, for example media: @m. The element will be sticky from the specified viewport width and upwards, but not below.

Oversized Content

Sticky content that is larger than the viewport will scroll down and stick to the bottom of the viewport. Changing the scroll direction will immediately scroll the sticky content up and change the sticky behavior to stick to the top of the viewport. Scrolling down will change the behavior again.

Overflow Flip

The overflow-flip option disables the sticky behavior for oversized content. Instead, it only flips the sticky position if the element is larger than the viewport. Changing the scroll direction will not affect the sticky position. Together with the start and end options, two nice sticky effects can be achieved. Cover an element by following content or reveal it by previous content.

Component options

Any of these options can be applied to the component attribute. Separate multiple options with a semicolon. Learn more

OptionValueDefaultDescription
positiontop, bottomtopThe position the element should be stuck to.
startLength, CSS Selector0Start offset. The value can be in vh, % and px. It supports basic mathematics operands + and -. The default value of 0 means that the element’s top border and viewport’s top border intersect. A CSS Selector will set start to the selected element’s bottom border and the element’s top border.
end Length, CSS Selector, BooleanfalseEnd offset. The value can be in vh, % and px. It supports basic mathematics operands + and -. A value of 0 means that the element’s top border and viewport’s top border intersect, which would cause the element not to be sticky at all if start is also set to 0. A CSS Selector will set the end to the selected element’s bottom and the element’s bottom border. false will make the element stick until the end of the page. true selects the parent element.
offset Length0The offset the Sticky should be fixed to. The value can be in vh, % and px. It supports basic mathematics operands + and -.
overflow-flip BooleanfalseFlip the Sticky’s position option if the element overflows the viewport and disable overflow scrolling.
animation StringfalseThe animation to use when the element becomes sticky.
cls-activeStringuk-activeThe active class.
cls-inactiveStringThe inactive class.
show-on-upBooleanfalseOnly show sticky element when scrolling up.
media Number, StringfalseCondition for the active status - a width as integer (e.g. 640) or a breakpoint (e.g. @s, @m, @l, @xl) or any valid media query (e.g. (min-width: 900px)).
target-offset false, LengthfalseInitially make sure that the Sticky element is not over a referenced element via the page’s location hash. The offset defines by how far the element will be above the referenced element. false will disable this behavior.

JavaScript

Learn more about JavaScript components.

Initialization

Events

The following events will be triggered on elements with this component attached:

NameDescription
activeFires after the element becomes sticky.
inactiveFires after the element is no longer sticky.
Customize

Customize your Franken UI experience.