--- title: max-width slug: Web/CSS/max-width tags: - CSS - CSS Property - Reference translation_of: Web/CSS/max-width ---
max-width CSS 속성은 요소의 최대 너비를 설정합니다. max-width는 {{cssxref("width")}} 속성의 사용값이 자신의 값보다 커지는걸 방지합니다.
max-width가 {{cssxref("width")}}를 재설정하고, {{cssxref("min-height")}}가 max-width를 재설정합니다.
/* <length> 값 */ max-width: 3.5em; /* <percentage> 값 */ max-width: 75%; /* 키워드 값 */ max-width: none; max-width: max-content; max-width: min-content; max-width: fit-content; max-width: fill-available; /* 전역 값 */ max-width: inherit; max-width: initial; max-width: unset;
nonemax-content {{experimental_inline()}}min-content {{experimental_inline()}}fill-available {{experimental_inline()}}available로 구현함을 참고하세요.)fit-content {{experimental_inline()}}max-content와 동일.다음 예제에서, 자식(child) 요소의 너비는 150픽셀과 부모(parent) 요소의 너비 중 더 작은 값이 됩니다.
<div id="parent">
<div id="child">
Fusce pulvinar vestibulum eros, sed luctus ex lobortis quis.
</div>
</div>
#parent {
background: lightblue;
width: 300px;
}
#child {
background: gold;
width: 100%;
max-width: 150px;
}
{{EmbedLiveSample("basic-max-width-demo", 350, 100)}}
fit-content 값을 사용하여 해당 요소의 내용이 필요로 하는 너비만 차지하도록 설정할 수 있습니다.
#parent {
background: lightblue;
width: 300px;
}
#child {
background: gold;
width: 100%;
max-width: -moz-fit-content;
max-width: -webkit-fit-content;
}
{{EmbedLiveSample("fit-content-demo", 400, 100)}}
페이지의 확대 또는 글씨 크기를 키운 후에도 max-width를 설정한 요소의 내용이 잘리거나, 다른 요소를 가리지 않도록 주의하세요.
| Specification | Status | Comment |
|---|---|---|
| {{ SpecName('CSS3 Sizing', '#width-height-keywords', 'max-width') }} | {{ Spec2('CSS3 Sizing') }} | Adds the max-content, min-content, fit-content, and fill-available keywords. (Both CSS3 Box and CSS3 Writing Modes drafts used to define these keywords, but are superseded by this spec.) |
| {{ SpecName('CSS3 Transitions', '#animatable-css', 'max-width') }} | {{ Spec2('CSS3 Transitions') }} | Defines max-width as animatable. |
| {{ SpecName('CSS2.1', 'visudet.html#min-max-widths', 'max-width') }} | {{ Spec2('CSS2.1') }} | Initial definition. |
{{cssinfo}}
{{Compat("css.properties.max-width")}}