--- title: width slug: Web/CSS/width tags: - CSS - CSS Property - Reference translation_of: Web/CSS/width ---
CSS width 속성은 요소의 너비를 설정합니다. 기본값은 콘텐츠 영역의 너비이지만, {{cssxref("box-sizing")}}이 border-box라면 테두리 영역의 너비를 설정합니다.
{{cssxref("min-width")}}와 {{cssxref("max-width")}} 속성은 width를 덮어씁니다.
/* <length> */ width: 300px; width: 25em; /* <percentage> */ width: 75%; /* 키워드 */ width: 25em border-box; width: 75% content-box; width: max-content; width: min-content; width: available; width: fit-content(20em); width: auto; /* 전역 값 */ width: inherit; width: initial; width: unset;
width 속성은 다음과 같이 지정합니다.
min-content, max-content, fit-content, auto 키워드 중 하나.<length> 또는 <percentage> 값.automax-contentmin-contentfit-content({{cssxref("<length-percentage>")}}min(max-content, max(min-content, <length-percentage>))의 결과.p.goldie {
background: gold;
}
<p class="goldie">모질라 커뮤니티는 많은 수의 대단한 소프트웨어를 제작합니다.</p>
{{EmbedLiveSample('기본_너비', '500px', '64px')}}
px과 em.px_length {
width: 200px;
background-color: red;
color: white;
border: 1px solid black;
}
.em_length {
width: 20em;
background-color: white;
color: red;
border: 1px solid black;
}
<div class="px_length">픽셀 너비</div> <div class="em_length">em 너비</div>
{{EmbedLiveSample('px과_em', '500px', '64px')}}
.percent {
width: 20%;
background-color: silver;
border: 1px solid red;
}
<div class="percent">백분율 너비</div>
{{EmbedLiveSample('백분율', '500px', '64px')}}
max-contentp.maxgreen {
background: lightgreen;
width: intrinsic; /* Safari/WebKit uses a non-standard name */
width: -moz-max-content; /* Firefox/Gecko */
width: -webkit-max-content; /* Chrome */
width: max-content;
}
<p class="maxgreen">Mozilla 커뮤니티는 많은 수의 대단한 소프트웨어를 제작합니다.</p>
{{EmbedLiveSample('max-content_2', '500px', '64px')}}
min-contentp.minblue {
background: lightblue;
width: -moz-min-content; /* Firefox */
width: -webkit-min-content; /* Chrome */
width: min-content;
}
<p class="minblue">Mozilla 커뮤니티는 많은 수의 대단한 소프트웨어를 제작합니다.</p>
{{EmbedLiveSample('min-content_2', '500px', '155px')}}
페이지를 확대하거나 글꼴 크기를 늘렸을 때 width 속성을 지정한 요소가 잘리거나 다른 내용을 가리지 않도록 확인하세요.
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('CSS4 Sizing', '#width-height-keywords', 'width')}} | {{Spec2('CSS4 Sizing')}} | |
| {{SpecName('CSS3 Sizing', '#width-height-keywords', 'width')}} | {{Spec2('CSS3 Sizing')}} | Added the max-content, min-content, fit-content keywords. |
| {{SpecName('CSS2.1', 'visudet.html#the-width-property', 'width')}} | {{Spec2('CSS2.1')}} | Precises on which element it applies to. |
| {{SpecName('CSS1', '#width', 'width')}} | {{Spec2('CSS1')}} | Initial definition. |
{{Compat("css.properties.width")}}