sticky-and-fixed-elements
Sticky and Fixed Elements
position: fixed vs position: sticky
| Property | Behaviour | Use for |
|---|---|---|
position: fixed |
Removed from document flow. Always stays at the same viewport position regardless of scroll or parent. | Global navigation header, bottom toolbar, floating action button |
position: sticky |
Stays in document flow until it hits its scroll threshold, then locks in place. Returns to flow when parent scrolls past. | Table column headers, section headings in a long list, in-page toolbars within a scroll container |
Prefer sticky over fixed when the element belongs to a specific section or scroll context. Fixed elements sit above everything and affect the entire viewport — use them only for truly global UI.
Top — Navigation Header
The global navigation header is the most common fixed element. It should:
- Remain visible at all times so the user can always navigate away
- Be as thin as possible to maximise content area — 48–64px is a common range
- Have a background and shadow so content scrolling beneath it does not bleed through
- On scroll, a subtle shadow (
--shadow-sm) signals that content is behind it
.site-header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: var(--header-height);
background: var(--color-surface);
box-shadow: var(--shadow-sm);
z-index: var(--z-header);
}
Compensate for the fixed header with matching top padding on the page body:
body { padding-top: var(--header-height); }
Bottom — Toolbar on Mobile
On mobile, the bottom of the screen is the most reachable area with one thumb. A persistent bottom toolbar is the natural home for:
- Primary navigation (bottom tab bar — iOS and Android convention)
- Contextual actions for the current view (edit, share, delete)
- A floating action button (FAB) for the single most important action
Bottom toolbars should:
- Respect the safe area inset on devices with a home indicator:
padding-bottom: env(safe-area-inset-bottom) - Be visually separated from content (background fill, top border, or shadow)
- Contain 3–5 items maximum — more than 5 should move to a menu or a different pattern
- Use icons with labels for navigation tabs, or icons alone for contextual toolbars (with tooltips)
On desktop, bottom toolbars are uncommon. Status bars, editor toolbars, and command palettes are the desktop equivalent — these are typically position: fixed at the bottom or position: sticky within their scroll container.
Sticky Table Headers
For data tables inside a scroll container, sticky column headers prevent the user from losing track of what each column means.
thead th {
position: sticky;
top: 0;
background: var(--color-surface);
z-index: 1;
}
If the table also has a sticky first column (for row identifiers), the top-left cell needs both top: 0 and left: 0, and a higher z-index to sit above both the header row and the sticky column.
Stacking and Z-index
Sticky and fixed elements create stacking context. Define z-index as named tokens, not arbitrary numbers:
--z-base: 0;
--z-dropdown: 100;
--z-sticky: 200;
--z-header: 300;
--z-modal: 400;
--z-toast: 500;
Every fixed or sticky element must declare its z-index explicitly using a token. Avoid ad-hoc values like z-index: 9999 — they signal an unmanaged stacking context and will eventually conflict.
How Many Fixed Layers Is Too Many
Each fixed layer removes space from the content area and adds visual complexity. A page should rarely need more than:
- 1 fixed header (top)
- 1 fixed toolbar or bottom nav (bottom, mobile)
- 1 floating action button or contextual overlay
A fixed header + fixed bottom toolbar + floating button + sticky sidebar + sticky table header all simultaneously is too many layers. Consolidate where possible.
Review Checklist
- Is
stickyused for section-scoped elements andfixedonly for truly global UI? - Does the fixed header compensate for its height with body padding?
- Does the bottom toolbar respect
env(safe-area-inset-bottom)on mobile? - Are all z-index values defined as named tokens, not arbitrary numbers?
- Is the total number of simultaneous fixed layers minimal — header + one bottom element maximum in most cases?
- Does content scrolling behind a fixed element not visually bleed through (background + shadow on the fixed element)?
More from dembrandt/dembrandt-skills
nielsen-usability-heuristics
UI design and review should apply Nielsen's 10 Usability Heuristics — the foundational principles for evaluating and improving usability. Use when auditing an interface, designing interaction flows, writing error messages, or reviewing any UI for usability issues.
45form-design
Forms have three layers of guidance: helper text below the input explains what to enter, placeholder shows the expected format, and validation confirms correctness. Real-time validation for complex inputs. Submit enables only when the form is valid. Use when designing or reviewing any form, input field, or data entry UI.
44color-mode-and-theme
Choose light, dark, or combined color mode deliberately based on brand tone and user context. Offer a theme selector only when user control genuinely matters — enterprise tools, data-heavy UIs, or extended-use applications. Use when defining the base color palette, designing a design system, or deciding whether to build dark mode support.
43generate-ui-from-brand
Pipeline skill — turns a URL or DESIGN.md into a concrete UI structure with decisions already made. Extracts live design tokens, normalizes them into a semantic system, applies UX principles, and outputs an actionable UI spec. Use when building UI for an existing brand from scratch, auditing a design system, or refactoring visual inconsistency.
42scroll-areas
Scroll areas inside a layout should be avoided wherever possible. When unavoidable, allow only one scroll axis at a time and always keep the user in control. Use when designing layouts, data tables, panels, or any component that might introduce an inner scroll container.
42micro-interactions
Micro-interactions are small, purposeful animations and responses that reward the user and make the interface feel alive — an animated icon, a satisfying toggle, a subtle reveal. Borrowed from the natural world, they add delight without distraction. Use when designing interactive components, success states, toggles, loaders, or any moment worth celebrating.
42