- height
- Try it
- Syntax
- Values
- Accessibility concerns
- Formal definition
- Formal syntax
- Examples
- Setting height using pixels and percentages
- HTML
- CSS
- Result
- Specifications
- Browser compatibility
- See also
- Found a content problem with this page?
- MDN
- Support
- Our communities
- Developers
- CSS height Property
- Browser Support
- CSS Syntax
- Property Values
- More Examples
- Example
- Border Height in CSS
- How to Set Border Height in CSS?
- Step 1: Create a “div” Container
- Step 2: Insert a Heading
- Step 3: Make a List
- Можно ли задать высоту для бордера?
- Войдите, чтобы написать ответ
- Почему из-за фонового изображения фризит страницу?
height
The height CSS property specifies the height of an element. By default, the property defines the height of the content area. If box-sizing is set to border-box , however, it instead determines the height of the border area.
Try it
The min-height and max-height properties override height .
Syntax
/* values */ height: 120px; height: 10em; height: 100vh; /* value */ height: 75%; /* Keyword values */ height: max-content; height: min-content; height: fit-content(20em); height: auto; /* Global values */ height: inherit; height: initial; height: revert; height: revert-layer; height: unset;
Values
Defines the height as a distance value.
Defines the height as a percentage of the containing block’s height.
The browser will calculate and select a height for the specified element.
The intrinsic preferred height.
The intrinsic minimum height.
Box will use the available space, but never more than max-content
Uses the fit-content formula with the available space replaced by the specified argument, i.e. min(max-content, max(min-content, ))
Enables selecting a middle value within a range of values between a defined minimum and maximum
Accessibility concerns
Ensure that elements set with a height aren’t truncated and/or don’t obscure other content when the page is zoomed to increase text size.
Formal definition
Initial value | auto |
---|---|
Applies to | all elements but non-replaced inline elements, table columns, and column groups |
Inherited | no |
Percentages | The percentage is calculated with respect to the height of the generated box’s containing block. If the height of the containing block is not specified explicitly (i.e., it depends on content height), and this element is not absolutely positioned, the value computes to auto . A percentage height on the root element is relative to the initial containing block. |
Computed value | a percentage or auto or the absolute length |
Animation type | a length, percentage or calc(); |
Formal syntax
height =
auto |
|
min-content |
max-content |
fit-content( )
=
|
Examples
Setting height using pixels and percentages
HTML
div id="taller">I'm 50 pixels tall.div> div id="shorter">I'm 25 pixels tall.div> div id="parent"> div id="child">I'm half the height of my parent.div> div>
CSS
div width: 250px; margin-bottom: 5px; border: 2px solid blue; > #taller height: 50px; > #shorter height: 25px; > #parent height: 100px; > #child height: 50%; width: 75%; >
Result
Specifications
Browser compatibility
BCD tables only load in the browser
See also
Found a content problem with this page?
This page was last modified on Jul 18, 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.
CSS height Property
The height of an element does not include padding, borders, or margins!
If height: auto; the element will automatically adjust its height to allow its content to be displayed correctly.
If height is set to a numeric value (like pixels, (r)em, percentages) then if the content does not fit within the specified height, it will overflow. How the container will handle the overflowing content is defined by the overflow property.
Note: The min-height and max-height properties override the height property.
Default value: | auto |
---|---|
Inherited: | no |
Animatable: | yes. Read about animatable Try it |
Version: | CSS1 |
JavaScript syntax: | object.style.height=»500px» 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 | The browser calculates the height. This is default | Demo ❯ |
length | Defines the height in px, cm, etc. Read about length units | Demo ❯ |
% | Defines the height in percent of the containing block | Demo ❯ |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
More Examples
Example
Set the height of an element to 50% of the height of the parent element:
Border Height in CSS
In web development, the “border” property plays a significant role. They may be utilized to distinguish or highlight stuff on a website, which makes it simple and easy for visitors to perceive and act on the site. Furthermore, the user can also determine the border height. Border height in CSS actually depends on the length of the border lines.
Sometimes, the user thinks the border will always be applied horizontally according to the element’s boundary. However, this concept is wrong. You can set the border height according to their preferences.
This post will explain how to set border height in CSS.
How to Set Border Height in CSS?
To set the border height in CSS, the “line-height” property is used. This property is commonly used for setting the distance between text lines.
For this purpose, try out the mentioned instructions.
Step 1: Create a “div” Container
Initially, make a “div” container with the help of the “ ” element. Also, assign it a “class” attribute inside the opening tag of the “” element and specify a name for the class according to your choice.
Step 2: Insert a Heading
Next, insert a heading by using any heading tag “ ” to “ ”. In this example, we have utilized the “ ” tag.
Step 3: Make a List
Then, utilize the “ ” tag to make the ordered list and add the data inside the list with the help of the “ ” tag:
Можно ли задать высоту для бордера?
можно ли как-то задать размеры для свойств border, например, чтобы bordser-left был 10px или таких свойств нет и нужно будет придумывать другие пути как это сделать?
Подойдите к вопросу иначе. Рамка всегда есть, но ее не видно.
При наведении, рамка меняет цвет и ее видно.
Добавив transition: border-color 0.3s; сделаем смену цвета плавной.
tosster22, вам нужно сразу добавить прозрачный бордер, а при наведении менять цвет, что бы не прыгал блок. Еще вариант использовать box-shadow
https://codepen.io/michelre/pen/EoPMGv
проблема в том, что нужно height для бордера. Суть такая, есть ссылка и у нее есть padding 20px. Нужно padding оставить такой же, а при наведении добавить рамку которая в 10px
tosster22, что значит высота? У бордера есть «толщина» или имеется в виду размер этого бордера? Так он описывает элемент.
tosster22, тогда бордер здесь не поможет, можно, например сделать псевдоэлемент с нужной вам высотой, позиционировать его относительно элемента и показывать при наведении на элемент