The top property controls vertical offset for positioned elements — essential for layouts using absolute, relative, fixed, and sticky positioning.
01
Vertical
Move down.
02
position
Required pair.
03
px / %
Length units.
04
absolute
Inside parent.
05
fixed
Viewport lock.
06
sticky
Scroll stick.
Fundamentals
Introduction
The top property in CSS is used to specify the vertical position of a positioned element. This property works in conjunction with position values such as absolute, relative, fixed, or sticky.
By setting the top property, you can control the distance between the top edge of the element and the top edge of its containing element.
Definition and Usage
Use top when you need precise vertical placement — for example, placing a badge inside a card, pinning a navbar with position: fixed; top: 0;, or nudging an element with position: relative.
💡
Beginner Tip
top does nothing on position: static elements. Always set a non-static position value first.
Foundation
📝 Syntax
The syntax for the top property is straightforward and can be applied to any positioned element.
syntax.css
element{position:position-value;top:value;}
Here, position-value can be absolute, relative, fixed, or sticky, and value can be a length (e.g., px, em), a percentage (%), or other valid CSS units.
Basic Example
top.css
.box{position:absolute;top:50px;}
Syntax Rules
Requires position other than static.
Positive values move the element down from the top edge of its containing block.
Negative values move the element upward.
Percentages are relative to the height of the containing block.
The property is not inherited.
Related Properties
position — enables offset properties like top
left, right, bottom — other inset offset properties
inset — shorthand for top, right, bottom, and left
z-index — controls stacking order of positioned elements
Defaults
🎯 Default Value
The default value of the top property is auto, which means the browser will calculate the top position of the element.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Default value
auto
Offset 50px down
position: absolute; top: 50px;
Pin to viewport top
position: fixed; top: 0;
Sticky header threshold
position: sticky; top: 0;
Works on static?
No
Inherited
No
Reference
💎 Property Values
The top property accepts length, percentage, and keyword values.
Value
Example
Description
length
top: 50px;
Specifies the top position in length units such as px, em, rem, etc.
percentage
top: 25%;
Specifies the top position as a percentage of the containing element’s height.
auto
top: auto;
Default value. The browser calculates the top position.
initial
top: initial;
Sets the property to its default value.
inherit
top: inherit;
Inherits the value from the parent element.
autopx%em
Context
When to Use top
top is essential whenever you need vertical control in positioned layouts:
Overlays and badges — Place elements inside cards with position: absolute; top: ...
Fixed headers — Keep navigation at the viewport top with top: 0
Sticky sections — Define when sticky elements stick using a top threshold
Micro-adjustments — Nudge icons or labels with position: relative; top: -2px;
Preview
👀 Live Preview
Three absolutely positioned boxes at different top values inside the same container:
Choose absolute, relative, fixed, or sticky on the element.
position
2
Define top offset
Set a length, percentage, or leave as auto.
Offset
3
Browser positions element
The top edge moves relative to the containing block or viewport.
Layout
=
✅
Precise vertical placement
Elements land exactly where your layout needs them.
Compatibility
Browser Compatibility
The top property is supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. It is also supported in older browsers, making it a reliable property to use for positioning elements.
✓ Universal · All browsers
Core layout property
top has been part of CSS positioning since the earliest layout models and works everywhere.
99%Browser support
Google Chrome1+ · Desktop & Mobile
Full support
Mozilla Firefox1+ · Desktop & Mobile
Full support
Apple Safari1+ · macOS & iOS
Full support
Microsoft Edge12+ · All versions
Full support
Opera4+ · All versions
Full support
Testing tip
Test sticky and fixed top values on mobile Safari and Chrome — viewport UI can affect visible placement.
top property99% supported
Bottom line:top is one of the most dependable CSS properties for vertical positioning.
Wrap Up
Conclusion
The top property is a fundamental tool for web developers to control the vertical positioning of elements.
Whether you are creating a complex layout or simply adjusting the position of a single element, understanding and using the top property effectively can enhance the design and functionality of your website. Experiment with different values and see how this property can be used to create precise and dynamic layouts.