height

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

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

구문

/* 키워드 */
height: auto;

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

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

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

<length>
높이의 절대값.
<percentage>
컨테이닝 블록 높이의 백분율.
border-box  This is an experimental API that should not be used in production code.
앞선 <length> 또는 <percentage>가 요소의 보더 박스에 적용.
content-box  This is an experimental API that should not be used in production code.
앞선 <length> 또는 <percentage>가 요소의 콘텐츠 박스에 적용.
auto
브라우저가 요소의 너비를 계산하고 선택.
fill This is an experimental API that should not be used in production code.
글쓰기 방향에 따라 fill-available 인라인 크기 또는 fill-available 블록 크기를 사용.
max-content  This is an experimental API that should not be used in production code.
본질적인 선호 높이.
min-content  This is an experimental API that should not be used in production code.
본질적인 최소 높이.
available  This is an experimental API that should not be used in production code.
컨테이닝 블록 너비에서 수평 여백, 테두리, 패딩을 제외한 값.
fit-content  This is an experimental API that should not be used in production code.
다음 중 더 큰 값.
  • 본질적인 최소 너비
  • 본질적인 선호 너비와 사용 가능한 너비 중 작은 값

형식 구문

auto | (en-US) <length> | (en-US) <percentage> | (en-US) min-content | (en-US) max-content | (en-US) fit-content | (en-US) fit-content(<length-percentage>)

where
<length-percentage> = <length> | (en-US) <percentage>

예제

HTML

<div id="taller">제 키는 50픽셀입니다.</div>
<div id="shorter">제 키는 25픽셀입니다.</div>
<div id="parent">
  <div id="child">
    제 키는 부모의 절반입니다.
  </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%;
}

결과

접근성 고려사항

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

명세

Specification Status Comment
CSS Basic Box Model
The definition of 'height' in that specification.
Candidate Recommendation Added the max-content, min-content, available, fit-content, border-box, content-box keywords.
CSS Transitions
The definition of 'height' in that specification.
Working Draft Lists height as animatable.
CSS Level 2 (Revision 1)
The definition of 'height' in that specification.
Recommendation Adds support for the <length> values and precises on which element it applies to.
CSS Level 1
The definition of 'height' in that specification.
Recommendation Initial definition.
CSS Box Sizing Module Level 3
The definition of 'width' in that specification.
Working Draft Adds new sizing keywords for width and height.

초기값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.
Computed valuea percentage or auto or the absolute length
Animation typea length, percentage or calc();

브라우저 호환성

BCD tables only load in the browser

같이 보기