Table of contents
A sticky menu stays within reach as visitors scroll through a page. You can use the same approach for a table of contents or another Joomla module. This guide covers Cassiopeia's header setting, custom CSS for individual modules and the common reasons sticky positioning does not work.
How sticky positioning works
The CSS property position: sticky is enough to keep a block visible as the page scrolls. The element initially moves with the page. Once it reaches the specified offset, it stays near the edge of its scrolling area, within the limits of its containing block.
With position: fixed, the element is removed from the normal document flow. You need to account for its position and the space it would otherwise occupy. For a module in a sidebar, sticky positioning is usually a useful starting point.
Joomla does not have a universal sticky switch for every module and template. Check your template's settings first. If there is no suitable option, assign a CSS class to the module and add your own styles. The examples below use Cassiopeia and refer to the Joomla 5 and 6 interface. Third-party templates may use different settings and HTML wrappers.
Make the Cassiopeia header sticky
Cassiopeia has a built-in Sticky Header option. It applies to the entire header element, including any content it contains.
- Open System and choose Site Template Styles in the Templates panel.
- Select the Cassiopeia style assigned to the pages you want to change. If you have several styles, check their menu assignments.
- Open the Advanced tab.
- Enable Sticky Header and save the settings.
- Open a long page on your site and scroll down.
Keep the header reasonably short. A logo, extra rows and an expanded menu can take up a large part of the screen. Keeping only the navigation sticky while allowing the rest of the header to scroll requires a separate solution based on your template's markup.
Make an individual module sticky
A custom CSS class lets you control a particular module independently of other blocks. In this example, a short sidebar menu stays visible on wider screens and scrolls normally on narrow screens.
Assign a CSS class
Open Content → Site Modules and select the module. Make sure it is published, assigned to the required pages and displayed in an existing template position. Cassiopeia uses sidebar-right for the right sidebar.
On the Advanced tab, add the following value to Module Class:
sticky-module
Enter the name without a dot. If the field already contains classes, keep them and add the new one after a space.
Save the module. The template needs to output this class on the module's HTML wrapper. If you use a custom layout or module style without a wrapper, inspect the resulting markup in your browser's developer tools.
Add custom styles
Cassiopeia loads custom rules from user.css. Open System → Site Templates, open the Cassiopeia files and select user.css in the css directory under /media/templates/site/cassiopeia. If the file does not exist, create a CSS file named user.css in that directory.
For standard Cassiopeia, the path is media/templates/site/cassiopeia/css/user.css. Keep any existing content and append these rules:
@media (min-width: 992px) {
.sticky-module {
position: sticky;
top: 1rem;
}
}
The position: sticky declaration sets the positioning method. The top value sets the offset from the top edge of the scrolling area. The min-width: 992px condition enables the rule only on wider screens. This is the breakpoint chosen for this example, rather than a requirement of sticky positioning.
Save the file and reload the page. If the appearance has not changed, check that user.css is loading and refresh any cached page content or styles.
Sticky positioning does not require z-index. Use it when you need to change the stacking order of overlapping blocks. Choose a value that fits your template's layers so the module does not cover the header, dropdown menus or dialogs.
Leave space below a sticky header
If the header is already sticky, a module with top: 0 may slide underneath it. Increase the offset in the rule you added earlier:
@media (min-width: 992px) {
.sticky-module {
position: sticky;
top: 96px;
}
}
The value 96px is an example. Measure the header on your site and add a small gap. Check several viewport widths, as menu items wrapping onto another line can make the header taller.
For a table of contents, also check the destinations of anchor links. Each section heading should remain visible below the header after navigation. If the template does not handle this, use scroll-margin-top to add a scroll offset to the target elements.
When to use a Bootstrap class
If your template loads the relevant Bootstrap 5 styles, you can use the built-in sticky-top class instead of writing a custom positioning rule. It keeps the element at the top edge. Responsive variants are also available, such as sticky-lg-top, which starts at 992 px in the standard Bootstrap configuration.
Enter the class in Module Class, without a dot. Using Joomla does not guarantee that a third-party template loads these CSS rules. Check that they are present on the page.
When you need an offset below a header, a custom class with your own top value is easier to control. Avoid combining several positioning methods on the same block without a reason.
Why a module does not stick
Inspect the element's markup and computed styles to find the cause. Arbitrary changes to height or z-index will not resolve every limitation.
- The rule is not applied. Check that the class appears on the correct wrapper, the stylesheet is loaded and another rule has not overridden
positionortop. - There is no offset. To make an element stick near the top, set
topto a value other thanauto. Theposition: stickydeclaration alone is not enough for this behaviour. - There is no room to move. If the wrapper ends immediately after the module, the module has nowhere to travel. Check the height of the sidebar and any intermediate containers. Avoid assigning an arbitrary large height just to create the effect.
- An ancestor defines another scrolling area. An ancestor with
overflow: auto,scrollor evenhiddencan change the area used for sticky positioning. Check bothoverflow-xandoverflow-y. Do not replace these values withunsetthroughout the page, as that can break clipping and other components. - The element is stretched. In a grid or flex container, the module may stretch to fill the available height. Check the alignment of the element you want to make sticky. Any alignment change should leave the sidebar tall enough for the module to move.
- The module is too tall. If it does not fit in the viewport after allowing for the top offset, some links may be difficult to reach during scrolling. Reduce the content or disable sticky positioning at those viewport sizes.
Also check the page on a phone, at increased zoom levels and with keyboard navigation. A sticky block should help visitors navigate without covering content or focused controls.
Make the last sidebar module sticky
If the modules in a Joomla position vary between pages, a CSS selector can target the last block. For Cassiopeia's standard right sidebar with the card module style, use this example:
@media (min-width: 992px) {
.container-sidebar-right > .sidebar-right:last-child {
position: sticky;
top: 1rem;
}
}
The selector is limited to the right sidebar. The > combinator selects a direct child, and :last-child requires that element to be the last among its sibling elements. If the template adds another wrapper or appends a different block to the sidebar, you will need to adjust the selector.
This approach applies styles directly to a matching element. It does not add a CSS class automatically. To target one particular module, assigning a custom class in its settings is usually simpler and more reliable.
Check the result
Scroll from the top of the page to the footer and back. Make sure the module starts sticking at the intended offset, stays within the sidebar and does not cover the header. Check a short page, a mobile viewport, link destinations and access to every menu item.
For a Joomla site using Cassiopeia, start with the built-in option when you want a sticky header. For an individual module, use a custom class and a few CSS declarations. If it does not stick, inspect the containers, offset and module height before adjusting the styles.





