- CSS bottom Property
- Definition and Usage
- Browser Support
- CSS Syntax
- Property Values
- Align div to the bottom of the page in 3 steps
- Step 1 : Setting the parent position to relative.
- Step 2 : Setting the div position to absolute.
- Step 3 : Setting the bottom property to 0;
- Optional : bottom right
- Example
- Omar Ghader
- bottom
- Try it
- Syntax
- Values
- Formal definition
- Formal syntax
- Examples
- Absolute and fixed positioning
- HTML
- CSS
- Result
- Specifications
- Browser compatibility
- See also
- Found a content problem with this page?
- MDN
- Support
- Our communities
- Developers
CSS bottom Property
Set the bottom edge of the element to 10px above the bottom edge of its nearest parent element with some positioning:
Definition and Usage
The bottom property affects the vertical position of a positioned element. This property has no effect on non-positioned elements.
- If position: absolute; or position: fixed; — the bottom property sets the bottom edge of an element to a unit above/below the bottom edge of its nearest positioned ancestor.
- If position: relative; — the bottom property makes the element’s bottom edge to move above/below its normal position.
- If position: sticky; — the bottom property behaves like its position is relative when the element is inside the viewport, and like its position is fixed when it is outside.
- If position: static; — the bottom property has no effect.
Default value: | auto |
---|---|
Inherited: | no |
Animatable: | yes. Read about animatable Try it |
Version: | CSS2 |
JavaScript syntax: | object.style.bottom=»10px» Try it |
Browser Support
The numbers in the table specify the first browser version that fully supports the property.
CSS Syntax
Property Values
Value | Description | Demo |
---|---|---|
auto | Lets the browser calculate the bottom edge position. This is default | Demo ❯ |
length | Sets the bottom edge position in px, cm, etc. Negative values are allowed. Read about length units | Demo ❯ |
% | Sets the bottom edge position in % of containing element. Negative values are allowed | Demo ❯ |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
Align div to the bottom of the page in 3 steps
Aligning an element at the bottom of the page is a very common issue in web development and css. You will find the best practices for aligning the div at the bottom of the page.
Step 1 : Setting the parent position to relative.
If you want to align a div at the bottom of a parent div, the parent should have a position : relative .
style> .parent < position: relative; /* Set parent position to relative */ > style> div class="parent"> div class="bottom">div> div>
Step 2 : Setting the div position to absolute.
The div that we want to align at the bottom should have a position : absolute .
style> .parent < position: relative; > .bottom < position: absolute; /* Set div position to relative */ > style> div class="parent"> div class="bottom">div> div>
Step 3 : Setting the bottom property to 0;
The div that we want to align at the bottom should have a bottom : 0; .
style> .parent < position: relative; > .bottom < position: absolute; bottom: 0; /* set the bottom to 0*/ > style> div class="parent"> div class="bottom">div> div>
Optional : bottom right
If you want to position the div to bottom right, you should add right : 0; .
style> .parent < position: relative; > .bottom < position: absolute; bottom: 0; right: 0; /* set the right to 0 */ > style> div class="parent"> div class="bottom">div> div>
Example
Omar Ghader
Fullstack web engineer and devops. Mobile web specialist
bottom
The bottom CSS property participates in setting the vertical position of a positioned element. It has no effect on non-positioned elements.
Try it
The effect of bottom depends on how the element is positioned (i.e., the value of the position property):
- When position is set to absolute or fixed , the bottom property specifies the distance between the element’s outer margin of bottom edge and the inner border of the bottom edge of its containing block.
- When position is set to relative , the bottom property specifies the distance the element’s bottom edge is moved above its normal position.
- When position is set to sticky , the bottom property is used to compute the sticky-constraint rectangle.
- When position is set to static , the bottom property has no effect.
When both top and bottom are specified, position is set to absolute or fixed , and height is unspecified (either auto or 100% ) both the top and bottom distances are respected. In all other situations, if height is constrained in any way or position is set to relative , the top property takes precedence and the bottom property is ignored.
Syntax
/* values */ bottom: 3px; bottom: 2.4em; /* s of the height of the containing block */ bottom: 10%; /* Keyword value */ bottom: auto; /* Global values */ bottom: inherit; bottom: initial; bottom: revert; bottom: revert-layer; bottom: unset;
Values
A negative, null, or positive that represents:
- for absolutely positioned elements, the distance to the bottom edge of the containing block.
- for relatively positioned elements, the distance that the element is moved above its normal position.
- for absolutely positioned elements, the position of the element is based on the top property, while height: auto is treated as a height based on the content; or if top is also auto , the element is positioned where it should vertically be positioned if it were a static element.
- for relatively positioned elements, the distance of the element from its normal position is based on the top property; or if top is also auto , the element is not moved vertically at all.
Specifies that the value is the same as the computed value from its parent element (which might not be its containing block). This computed value is then handled as if it were a , , or the auto keyword.
Formal definition
Initial value | auto |
---|---|
Applies to | positioned elements |
Inherited | no |
Percentages | refer to the height of the containing block |
Computed value | if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, auto |
Animation type | a length, percentage or calc(); |
Formal syntax
Examples
Absolute and fixed positioning
This example demonstrates the difference in behavior of the bottom property, when position is absolute versus fixed .
HTML
p> Thisbr />isbr />somebr />tall,br />tall,br />tall,br />tall,br />tallbr />content. p> div class="fixed">p>Fixedp>div> div class="absolute">p>Absolutep>div>
CSS
p font-size: 30px; line-height: 2em; > div width: 48%; text-align: center; background: rgba(55, 55, 55, 0.2); border: 1px solid blue; > .absolute position: absolute; bottom: 0; left: 0; > .fixed position: fixed; bottom: 0; right: 0; >
Result
Specifications
Browser compatibility
BCD tables only load in the browser
See also
- inset , the shorthand for all related properties: top , bottom , left , and right
- The mapped logical properties: inset-block-start , inset-block-end , inset-inline-start , and inset-inline-end and the shorthands inset-block and inset-inline
- position
Found a content problem with this page?
This page was last modified on Feb 21, 2023 by MDN contributors.
Your blueprint for a better internet.
MDN
Support
Our communities
Developers
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.