height

height CSS 속성은 요소의 높이를 지정합니다. 기본값은 콘텐츠 영역의 높이지만, box-sizingborder-box라면 테두리 영역의 높이를 설정합니다.

시도해보기

min-heightmax-height 속성은 height를 덮어씁니다.

구문

css
/* 키워드 */
height: auto;

/* <length> */
height: 120px;
height: 10em;

/* <percentage> */
height: 75%;

/* 전역 값 */
height: inherit;
height: initial;
height: unset;

  • <length>
    • : 높이의 절대값.
  • <percentage>
  • border-box Experimental
  • content-box Experimental
  • auto
    • : 브라우저가 요소의 높이를 계산하고 선택.
  • fill Experimental
    • : 글쓰기 방향에 따라 fill-available 인라인 크기 또는 fill-available 블록 크기를 사용.
  • max-content Experimental
    • : 본질적인 선호 높이.
  • min-content Experimental
    • : 본질적인 최소 높이.
  • available Experimental
    • : 컨테이닝 블록 높이에서 수평 여백, 테두리, 패딩을 제외한 값.
  • fit-content Experimental
    • : 다음 중 더 큰 값.
      • 본질적인 최소 높이
      • 본질적인 선호 높이와 사용 가능한 높이 중 작은 값

형식 구문

height = 
auto |
<length-percentage [0,∞]> |
min-content |
max-content |
fit-content( <length-percentage [0,∞]> )

<length-percentage> =
<length> |
<percentage>

예제

HTML

html
<div id="taller">제 키는 50픽셀입니다.</div>
<div id="shorter">제 키는 25픽셀입니다.</div>
<div id="parent">
  <div id="child">제 키는 부모의 절반입니다.</div>
</div>

CSS

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%;
}

결과

접근성 고려사항

페이지를 확대하거나 글꼴 크기를 늘렸을 때 height 속성을 지정한 요소가 잘리거나 다른 내용을 가리지 않도록 확인하세요.

명세

Specification
CSS Box Sizing Module Level 3
# preferred-size-properties
CSS Box Sizing Module Level 4
# sizing-values
초기값auto
적용대상all elements but non-replaced inline elements, table columns, and column groups
상속no
PercentagesThe 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.
계산 값a percentage or auto or the absolute length
Animation typea length, percentage or calc();

브라우저 호환성

BCD tables only load in the browser

같이 보기