--- title: width slug: Web/CSS/width tags: - Propiedad CSS - Referencia translation_of: Web/CSS/width ---
La propiedad CSS width especifica la anchura del area de contenido de un elemento. El área de contenido está dentro del padding, borde, y margen del elemento.
Las propiedades {{cssxref("min-width")}} y {{cssxref("max-width")}} sobreescriben el valor de {{cssxref("width")}}.
{{cssinfo}}
/* Valores <length> */ width: 300px; width: 25em; /* Valores <percentage> */ width: 75%; /* Valores clave */ width: 25em border-box; width: 75% content-box; width: max-content; width: min-content; width: available; width: fit-content; width: auto; /* Valores globales */ width: inherit; width: initial; width: unset;
<length><percentage>border-box {{experimental_inline}}content-box {{experimental_inline}}autofill-available para elementos inline o block, según sea más apropiado para el modo de escritura.max-content {{experimental_inline}}min-content {{experimental_inline}}available {{experimental_inline}}fit-content {{experimental_inline}}p.goldie {
background: gold;
}
<p class="goldie">The Mozilla community produces a lot of great software.</p>
{{EmbedLiveSample('Default_width', '500px', '64px')}}
.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">Width measured in px</div> <div class="em_length">Width measured in em</div>
{{EmbedLiveSample('Pixels_and_ems', '500px', '64px')}}
.percent {
width: 20%;
background-color: silver;
border: 1px solid red;
}
<div class="percent">Width in percentage</div>
{{EmbedLiveSample('Percentage', '500px', '64px')}}
p.maxgreen {
background: lightgreen;
width: intrinsic; /* Safari/WebKit uses a non-standard name */
width: -moz-max-content; /* Firefox/Gecko */
width: -webkit-max-content; /* Chrome */
}
<p class="maxgreen">The Mozilla community produces a lot of great software.</p>
{{EmbedLiveSample('max-content', '500px', '64px')}}
p.minblue {
background: lightblue;
width: -moz-min-content; /* Firefox */
width: -webkit-min-content; /* Chrome */
}
<p class="minblue">The Mozilla community produces a lot of great software.</p>
{{EmbedLiveSample('min-content', '500px', '155px')}}
| Especificación | Estado | Comentarios |
|---|---|---|
| {{SpecName('CSS3 Box', '#the-width-and-height-properties', 'width')}} | {{Spec2('CSS3 Box')}} | Añade las palabras clave max-content, min-content, available, fit-content, border-box, content-box. |
| {{SpecName('CSS3 Transitions', '#animatable-css', 'width')}} | {{Spec2('CSS3 Transitions')}} | Incluye width como propiedad que puede ser animada. |
| {{SpecName('CSS2.1', 'visudet.html#the-width-property', 'width')}} | {{Spec2('CSS2.1')}} | Especifica a qué elementos es aplicable. |
| {{SpecName('CSS1', '#width', 'width')}} | {{Spec2('CSS1')}} | Definición inicial |
| {{SpecName('CSS3 Sizing', '#width-height-keywords', 'width')}} | {{Spec2('CSS3 Sizing')}} | Añade nuevas palabras clave de tamaño para width y height |