repo_id
stringlengths
22
103
file_path
stringlengths
41
147
content
stringlengths
181
193k
__index_level_0__
int64
0
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/skewx/index.md
--- title: skewX() slug: Web/CSS/transform-function/skewX page-type: css-function browser-compat: css.types.transform-function.skewX --- {{CSSRef}} The **`skewX()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) defines a transformation that skews an element in the horizontal direction on the 2D plane. Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-skewX.html")}} This transformation is a shear mapping ([transvection](https://en.wikipedia.org/wiki/Shear_mapping)) that distorts each point within an element by a certain angle in the horizontal direction. The abscissa (horizontal, x-coordinate) of each point is modified by a value proportionate to the specified angle and the distance to the origin; thus, the farther from the origin a point is, the greater will be the value added it. > **Note:** `skewX(a)` is equivalent to > `skew(a)`. ## Syntax ```css skewX(a) ``` ### Values - `a` - : Is an {{cssxref("&lt;angle&gt;")}} representing the angle to use to distort the element along the abscissa (horizontal, x-coordinate). <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd ><mtd ><mo>tan</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd ><mtd ><mo>tan</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd ><mtd ><mo>tan</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd ><mtd ><mo>tan</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> <tr> <td><code>[1 0 tan(a) 1 0 0]</code></td> </tr> </tbody> </table> ## Examples ### HTML ```html <div>Normal</div> <div class="skewed">Skewed</div> ``` ### CSS ```css div { width: 80px; height: 80px; background-color: skyblue; } .skewed { transform: skewX(10deg); /* Equal to skew(10deg) */ background-color: pink; } ``` ### Result {{EmbedLiveSample("Examples", 200, 200)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("transform")}} - {{cssxref("&lt;transform-function&gt;")}} - Individual transform properties: - {{cssxref("translate")}} - {{cssxref("scale")}} - {{cssxref("rotate")}} - Note: there is no `skew` property
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/translatez/index.md
--- title: translateZ() slug: Web/CSS/transform-function/translateZ page-type: css-function browser-compat: css.types.transform-function.translateZ --- {{CSSRef}} The **`translateZ()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) repositions an element along the z-axis in 3D space, i.e., closer to or farther away from the viewer. Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-translateZ.html")}} This transformation is defined by a {{cssxref("&lt;length&gt;")}} which specifies how far inward or outward the element or elements move. In the above interactive examples, [`perspective: 550px;`](/en-US/docs/Web/CSS/perspective) (to create a 3D space) and [`transform-style: preserve-3d;`](/en-US/docs/Web/CSS/transform-style) (so the children, the 6 sides of the cube, are also positioned in the 3D space), have been set on the cube. > **Note:** `translateZ(tz)` is equivalent to > `translate3d(0, 0, tz)`. ## Syntax ```css translateZ(tz) ``` ### Values - `tz` - : A {{cssxref("&lt;length&gt;")}} representing the z-component of the translating vector [0, 0, tz]. In [Cartesian coordinate system](/en-US/docs/Web/CSS/transform-function#cartesian_coordinates) it represents shift along z-axis. A positive value moves the element towards the viewer, and a negative value farther away. <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td colspan="2"> This transformation applies to the 3D space and can't be represented on the plane. </td> <td> A translation is not a linear transformation in ℝ^3 and can't be represented using a Cartesian-coordinate matrix. </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn> </mtd><mtd><mi>t</mi> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> </tbody> </table> ## Examples In this example, two boxes are created. One is positioned normally on the page, without being translated at all. The second is altered by applying perspective to create a 3D space, then moved towards the user. ### HTML ```html <div>Static</div> <div class="moved">Moved</div> ``` ### CSS ```css div { position: relative; width: 60px; height: 60px; left: 100px; background-color: skyblue; } .moved { transform: perspective(500px) translateZ(200px); background-color: pink; } ``` What really matters here is the class "moved"; let's take a look at what it does. First, the [`perspective()`](/en-US/docs/Web/CSS/transform-function/perspective) function positions the viewer relative to the plane that lies where z=0 (in essence, the surface of the screen). A value of `500px` means the user is 500 pixels "in front of" the imagery located at z=0. Then, the `translateZ()` function moves the element 200 pixels "outward" from the screen, toward the user. This has the effect of making the element appear larger when viewed on a 2D display, or closer when viewed using a VR headset or other 3D display device. Note if the `perspective()` value is less than the `translateZ()` value, such as `transform: perspective(200px) translateZ(300px);` the transformed element will not be visible as it is further than the user's viewport. The smaller the difference between the perspective and translateZ values, the closer the user is to the element and the larger the translated element will seem. > **Note:** As the composition of transforms isn't commutative, the order you write the different functions is significant. In particular, in general, you want `perspective()` to be placed before `translateZ()`. ### Result {{EmbedLiveSample("Examples", 250, 250)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("transform")}} - {{cssxref("&lt;transform-function&gt;")}} - {{cssxref("translate")}}
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/scaley/index.md
--- title: scaleY() slug: Web/CSS/transform-function/scaleY page-type: css-function browser-compat: css.types.transform-function.scaleY --- {{CSSRef}} The **`scaleY()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) defines a transformation that resizes an element along the y-axis (vertically). Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-scaleY.html")}} It modifies the ordinate (vertical, y-coordinate) of each element point by a constant factor, except when the scale factor is 1, in which case the function is the identity transform. The scaling is not isotropic, and the angles of the element are not conserved. `scaleY(-1)` defines an [axial symmetry](https://en.wikipedia.org/wiki/Axial_symmetry), with a horizontal axis passing through the origin (as specified by the {{cssxref("transform-origin")}} property). > **Note:** `scaleY(sy)` is equivalent to > `scale(1, sy)` or > `scale3d(1, sy, 1)`. > > `transform: rotateX(180deg);` === `transform: scaleY(-1);` ## Syntax ```css scaleY(s) ``` ### Values - `s` - : Is a {{cssxref("&lt;number&gt;")}} representing the scaling factor to apply on the ordinate (vertical, y-coordinate) of each point of the element. <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mi>s</mi></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mi>s</mi> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mi>s</mi> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mi>s</mi> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> <tr> <td><code>[1 0 0 s 0 0]</code></td> </tr> </tbody> </table> ## Examples ### HTML ```html <div>Normal</div> <div class="scaled">Scaled</div> ``` ### CSS ```css div { width: 80px; height: 80px; background-color: skyblue; } .scaled { transform: scaleY(0.6); background-color: pink; } ``` ### Result {{EmbedLiveSample("Examples", 200, 200)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`scaleX()`](/en-US/docs/Web/CSS/transform-function/scaleX) - [`scaleZ()`](/en-US/docs/Web/CSS/transform-function/scaleZ) - {{cssxref("transform")}} - {{cssxref("&lt;transform-function&gt;")}} - {{cssxref("transform-origin")}} - Individual transform properties: - {{cssxref("translate")}} - {{cssxref("scale")}} - {{cssxref("rotate")}} - Note: there is no `skew` property
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/scale3d/index.md
--- title: scale3d() slug: Web/CSS/transform-function/scale3d page-type: css-function browser-compat: css.types.transform-function.scale3d --- {{CSSRef}} The **`scale3d()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) defines a transformation that resizes an element in 3D space. Because the amount of scaling is defined by a vector [sx, sy, sz], it can resize different dimensions at different scales. Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-scale3d.html")}} This scaling transformation is characterized by a three-dimensional vector. Its coordinates define how much scaling is done in each direction. If all three coordinates are equal, the scaling is uniform (_isotropic_) and the aspect ratio of the element is preserved (this is a [homothetic transformation](https://en.wikipedia.org/wiki/Homothetic_transformation)). When a coordinate value is outside the \[-1, 1] range, the element grows along that dimension; when inside, it shrinks. If it is negative, the result a [point reflection](https://en.wikipedia.org/wiki/Point_reflection) in that dimension. A value of 1 has no effect. ## Syntax The `scale3d()` function is specified with three values, which represent the amount of scaling to be applied in each direction. ```css scale3d(sx, sy, sz) ``` ### Values - `sx` - : Is a {{cssxref("&lt;number&gt;")}} representing the abscissa (horizontal, x-component) of the scaling vector. - `sy` - : Is a {{cssxref("&lt;number&gt;")}} representing the ordinate (vertical, y-component) of the scaling vector. - `sz` - : Is a {{cssxref("&lt;number&gt;")}} representing the z-component of the scaling vector. <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td colspan="2"> This transformation applies to the 3D space and can't be represented on the plane. </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mi>sx</mi> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mi>sy</mi> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mi>sz</mi></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mi>sx</mi> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mi>sy</mi> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mi>sz</mi> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> </tbody> </table> ## Examples ### Without changing the origin #### HTML ```html <div>Normal</div> <div class="scaled">Scaled</div> ``` #### CSS ```css div { width: 80px; height: 80px; background-color: skyblue; } .scaled { transform: perspective(500px) scale3d(2, 0.7, 0.2) translateZ(100px); background-color: pink; } ``` #### Result {{EmbedLiveSample("Without_changing_the_origin","200","200")}} ### Translating the origin of the transformation #### HTML ```html <div>Normal</div> <div class="scaled">Scaled</div> ``` #### CSS ```css div { width: 80px; height: 80px; background-color: skyblue; } .scaled { transform: perspective(500px) scale3d(2, 0.7, 0.2) translateZ(100px); transform-origin: left; background-color: pink; } ``` #### Result {{EmbedLiveSample("Translating_the_origin_of_the_transformation","200","200")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("transform")}} - {{cssxref("&lt;transform-function&gt;")}} - [`scaleZ()`](/en-US/docs/Web/CSS/transform-function/scaleZ) - [`translate3d()`](/en-US/docs/Web/CSS/transform-function/translate3d) - [`rotate3d()`](/en-US/docs/Web/CSS/transform-function/rotate3d) - Individual transform properties: - {{cssxref("translate")}} - {{cssxref("scale")}} - {{cssxref("rotate")}}
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/translatex/index.md
--- title: translateX() slug: Web/CSS/transform-function/translateX page-type: css-function browser-compat: css.types.transform-function.translateX --- {{CSSRef}} The **`translateX()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) repositions an element horizontally on the 2D plane. Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-translateX.html")}} > **Note:** `translateX(tx)` is equivalent to > `translate(tx, 0)` or > `translate3d(tx, 0, 0)`. ## Syntax ```css /* <length-percentage> values */ transform: translateX(200px); transform: translateX(50%); ``` ### Values - `<length-percentage>` - : Is a {{cssxref("&lt;length&gt;")}} or {{cssxref("&lt;percentage&gt;")}} representing the abscissa (horizontal, x-component) of the translating vector [tx, 0]. In [Cartesian coordinate system](/en-US/docs/Web/CSS/transform-function#cartesian_coordinates) it represents shift along x-axis. A percentage value refers to the width of the reference box defined by the {{cssxref("transform-box")}} property. <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td rowspan="2"> <p> A translation is not a linear transformation in ℝ^2 and can't be represented using a Cartesian-coordinate matrix. </p> </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mi>t</mi> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mi>t</mi> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mi>t</mi> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> <tr> <td><code>[1 0 0 1 t 0]</code></td> </tr> </tbody> </table> ### Formal syntax ```css translateX({{cssxref("&lt;length-percentage&gt;")}}) ``` ## Examples ### HTML ```html <div>Static</div> <div class="moved">Moved</div> <div>Static</div> ``` ### CSS ```css div { width: 60px; height: 60px; background-color: skyblue; } .moved { transform: translateX(10px); /* Equal to translate(10px) */ background-color: pink; } ``` ### Result {{EmbedLiveSample("Examples", 250, 250)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`translate()`](/en-US/docs/Web/CSS/transform-function/translate) - [`translateY()`](/en-US/docs/Web/CSS/transform-function/translateY) - {{cssxref("transform")}} - {{cssxref("&lt;transform-function&gt;")}} - {{cssxref("translate")}}
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/scalez/index.md
--- title: scaleZ() slug: Web/CSS/transform-function/scaleZ page-type: css-function browser-compat: css.types.transform-function.scaleZ --- {{CSSRef}} The **`scaleZ()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) defines a transformation that resizes an element along the z-axis. Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-scaleZ.html")}} This scaling transformation modifies the z-coordinate of each element point by a constant factor, except when the scale factor is 1, in which case the function is the identity transform. The scaling is not isotropic, and the angles of the element are not conserved. `scaleZ(-1)` defines an [axial symmetry](https://en.wikipedia.org/wiki/Axial_symmetry), with the z-axis passing through the origin (as specified by the {{cssxref("transform-origin")}} property). In the above interactive examples, [`perspective: 550px;`](/en-US/docs/Web/CSS/perspective) (to create a 3D space) and [`transform-style: preserve-3d;`](/en-US/docs/Web/CSS/transform-style) (so the children, the 6 sides of the cube, are also positioned in the 3D space), have been set on the cube. > **Note:** `scaleZ(sz)` is equivalent to > `scale3d(1, 1, sz)`. ## Syntax ```css scaleZ(s) ``` ### Values - `s` - : Is a {{cssxref("&lt;number&gt;")}} representing the scaling factor to apply on the z-coordinate of each point of the element. <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td colspan="2"> This transformation applies to the 3D space and can't be represented on the plane. </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mi>s</mi></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mi>s</mi> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> </tbody> </table> ## Examples ### HTML ```html <div>Normal</div> <div class="perspective">Translated</div> <div class="scaled-translated">Scaled</div> ``` ### CSS ```css div { width: 80px; height: 80px; background-color: skyblue; } .perspective { /* Includes a perspective to create a 3D space */ transform: perspective(400px) translateZ(-100px); background-color: limegreen; } .scaled-translated { /* Includes a perspective to create a 3D space */ transform: perspective(400px) scaleZ(2) translateZ(-100px); background-color: pink; } ``` ### Result {{EmbedLiveSample("Examples", 200, 300)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`scaleX()`](/en-US/docs/Web/CSS/transform-function/scaleX) - [`scaleY()`](/en-US/docs/Web/CSS/transform-function/scaleY) - {{cssxref("transform")}} - {{cssxref("&lt;transform-function&gt;")}} - {{cssxref("transform-origin")}} - Individual transform properties: - {{cssxref("translate")}} - {{cssxref("scale")}} - {{cssxref("rotate")}} - Note: there is no `skew` property
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/translatey/index.md
--- title: translateY() slug: Web/CSS/transform-function/translateY page-type: css-function browser-compat: css.types.transform-function.translateY --- {{CSSRef}} The **`translateY()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) repositions an element vertically on the 2D plane. Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-translateY.html")}} > **Note:** `translateY(ty)` is equivalent to > `translate(0, ty)` or > `translate3d(0, ty, 0)`. ## Syntax ```css /* <length-percentage> values */ transform: translateY(200px); transform: translateY(50%); ``` ### Values - `<length-percentage>` - : The value is a {{cssxref("&lt;length&gt;")}} or {{cssxref("&lt;percentage&gt;")}} representing the ordinate (vertical, y-coordinate) of the translating vector [0, ty]. In [Cartesian coordinate system](/en-US/docs/Web/CSS/transform-function#cartesian_coordinates) it represents shift along y-axis. A percentage value refers to the height of the reference box defined by the {{cssxref("transform-box")}} property. <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td rowspan="2"> <p> A translation is not a linear transformation in ℝ^2 and can't be represented using a Cartesian-coordinate matrix. </p> </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn></mtd> <mtd><mn>0</mn></mtd> <mtd><mn>0</mn></mtd> </mtr ><mtr ><mtd><mn>0</mn></mtd> <mtd><mn>1</mn></mtd> <mtd><mi>t</mi></mtd> </mtr ><mtr ><mtd><mn>0</mn></mtd> <mtd><mn>0</mn></mtd> <mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn></mtd> <mtd><mn>0</mn></mtd> <mtd><mn>0</mn></mtd> </mtr ><mtr ><mtd><mn>0</mn></mtd> <mtd><mn>1</mn></mtd> <mtd><mi>t</mi></mtd> </mtr ><mtr ><mtd><mn>0</mn></mtd> <mtd><mn>0</mn></mtd> <mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn></mtd> <mtd><mn>0</mn></mtd> <mtd><mn>0</mn></mtd> <mtd><mn>0</mn></mtd> </mtr ><mtr ><mtd><mn>0</mn></mtd> <mtd><mn>1</mn></mtd> <mtd><mn>0</mn></mtd> <mtd><mi>t</mi></mtd> </mtr ><mtr ><mtd><mn>0</mn></mtd> <mtd><mn>0</mn></mtd> <mtd><mn>1</mn></mtd> <mtd><mn>0</mn></mtd> </mtr ><mtr ><mtd><mn>0</mn></mtd> <mtd><mn>0</mn></mtd> <mtd><mn>0</mn></mtd> <mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> <tr> <td><code>[1 0 0 1 0 t]</code></td> </tr> </tbody> </table> ### Formal syntax ```css translateY({{cssxref("&lt;length-percentage&gt;")}}) ``` ## Examples ### HTML ```html <div>Static</div> <div class="moved">Moved</div> <div>Static</div> ``` ### CSS ```css div { width: 60px; height: 60px; background-color: skyblue; } .moved { transform: translateY(10px); background-color: pink; } ``` ### Result {{EmbedLiveSample("Examples", 250, 250)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("transform")}} - {{cssxref("&lt;transform-function&gt;")}} - {{cssxref("translate")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/visual_formatting_model/index.md
--- title: Visual formatting model slug: Web/CSS/Visual_formatting_model page-type: guide --- {{CSSRef}} In CSS, the **visual formatting model** describes how user agents take the document tree, and process and display it for visual media. This includes {{glossary("continuous media")}} such as a computer screen and [paged media](/en-US/docs/Web/CSS/CSS_paged_media) such as a book or document printed by browser print functions. Most of the information applies equally to continuous and paged media. In the visual formatting model, each element in the document tree generates zero or more boxes according to the box model. The layout of these boxes is governed by: - Box dimensions and type. - Positioning scheme (normal flow, float, and absolute positioning). - Relationships between elements in the document tree. - External information (e.g., viewport size, intrinsic dimensions of images, etc.). Much of the information about the visual formatting model is defined in CSS2, however, various level 3 specifications have added to this information. When reading specifications you will often find references to the model as defined in CSS2, so an understanding of the model and the terms used to describe it in CSS2 is valuable when reading other layout specifications. In this document we define the model and introduce some of the related terms and concepts, linking to more specific pages on MDN for further details. ## The role of the viewport In continuous media, the {{glossary("viewport")}} is the viewing area of the browser window. User agents can change the layout of the page when the viewport size changes — for example, if you resize your window, or change the orientation of a mobile device. If the viewport is smaller than the size of the document then the user agent needs to offer a way to scroll to the parts of the document that are not displayed. We most often see this as scrolling in the **block dimension** — vertically in a horizontal, top-to-bottom language. However, you might design something that requires scrolling in the **inline dimension** too. ## Box generation **Box generation** is the part of the CSS visual formatting model that creates boxes from the document's elements. Generated boxes are of different types, which affect their visual formatting. The type of the box generated depends on the value of the CSS {{cssxref("display")}} property. Initially defined in CSS2, the `display` property is extended in the [CSS Display Module Level 3](https://www.w3.org/TR/css-display-3/). In addition, some of the terminologies around the display have been updated and clarified in the years since CSS2. CSS takes your source document and renders it onto a canvas. To do this, it generates an intermediary structure, the **box tree**, which represents the formatting structure of the rendered document. Each box in the box tree represents its corresponding element (or pseudo-element) in space and/or time on the canvas, while each text run in the box tree likewise represents the contents of its corresponding text nodes. Then, for each element, CSS generates zero or more boxes as specified by that element's `display` property value. > **Note:** Boxes are often referred to by their display type — e.g. a box generated by an element with `display: block` is called a "block box" or just a "block". Note however that block boxes, block-level boxes and box containers are all subtly different; see the [Block boxes](#block_boxes) section below for more details. ### The principal box When an element generates one or more boxes, one of them is the **principal box**, which contains its descendant boxes and generated content in the box tree, and is also the box involved in any positioning scheme. Some elements may generate additional boxes in addition to the principal box, for example `display: list-item` generates more than one box (e.g. a **principal block box** and a **child marker box**). And some values (such as `none` or `contents`) cause the element and/or its descendants to not generate any boxes at all. ### Anonymous boxes An **anonymous box** is created when there is not an HTML element to use for the box. This situation happens when, for example, you declare `display: flex` on a parent element, and directly inside there is a run of text not contained in another element. In order to fix the box tree, an anonymous box is created around that run of text. It will then behave as a flex item, however, it cannot be targeted and styled like a regular box because there is no element to target. {{EmbedGHLiveSample("css-examples/visual-formatting/anonymous-flex.html", '100%', 720)}} The same thing happens when you have text runs interspersed with block elements. In the next example I have a string inside a `<div>`; in the middle of my string is a `<p>` element containing part of the text. {{EmbedGHLiveSample("css-examples/visual-formatting/anonymous-block.html", '100%', 720)}} The string is split into three boxes in the box tree. The part of the string before the paragraph element is wrapped in an anonymous box, then we have the `<p>`, which generates a box, and then another anonymous box. Something to consider about these anonymous boxes is that they inherit styles from their direct parent, but you cannot change how they look by targeting the anonymous box. In my examples, I am using a direct child selector to target the children of the container. This does not change the anonymous boxes, as they are not "elements" as such. **Inline anonymous boxes** are created when a string is split by an inline element, for example, a sentence that includes a section wrapped with `<em></em>`. This splits the sentence into three inline boxes — an anonymous inline box before the emphasized section, the section wrapped in the `<em>` element, then a final anonymous inline box. As with the anonymous block boxes, these anonymous inline boxes cannot be styled independently in the way the `<em>` can; they just inherit the styles of their container. Other formatting contexts also create anonymous boxes. [Grid layout](/en-US/docs/Web/CSS/CSS_grid_layout) behaves in the same way as the [flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout) example above, turning strings of text into a grid item with an anonymous box. [Multiple-column](/en-US/docs/Web/CSS/CSS_multicol_layout) layout creates anonymous column boxes around the columns; these also cannot be styled or otherwise targeted. [Table layout](/en-US/docs/Web/CSS/CSS_table) will add anonymous boxes to create a proper table structure — for example adding an anonymous table row — if there was no box with `display: table-row`. ### Line boxes **Line boxes** are the boxes that wrap each line of text. You can see the difference between line boxes and their containing block if you float an item and then follow it by a block that has a background color. In the following example, the line boxes following the floated `<div>` are shortened to wrap around the float. The background of the box runs behind the float, as the floated item has been taken out of flow. {{EmbedGHLiveSample("css-examples/visual-formatting/line-boxes.html", '100%', 720)}} ## Positioning schemes and in-flow and out-of-flow elements In CSS, a box may be laid out according to three positioning schemes — **normal flow**, **floats**, or **absolute positioning**. ### Normal flow In CSS, the normal flow includes block-level formatting of block boxes, inline-level formatting of inline boxes, and also includes relative and sticky positioning of block-level and inline-level boxes. Read more about [flow layout](/en-US/docs/Web/CSS/CSS_flow_layout) in CSS. ### Floats In the float model, a box is first laid out according to the normal flow, then taken out of the flow and positioned, typically to the left or right. Content may flow along the side of a float. Find out more about [floats](/en-US/docs/Learn/CSS/CSS_layout/Floats). ### Absolute positioning In the absolute positioning model (which also includes fixed positioning), a box is removed from the normal flow entirely and assigned a position with respect to a containing block (which is the viewport in the case of fixed positioning). An element is called **out of flow** if it is floated, absolutely positioned, or is the root element. An element is called **in-flow** if it is not out of the flow. Read about [CSS positioned layout](/en-US/docs/Web/CSS/CSS_positioned_layout). ## Formatting contexts and the display property Boxes can be described as having an **outer display type**, which is `block` or `inline`. This outer display type refers to how the box behaves alongside other elements on the page. Boxes also have an inner display type, dictating how their children behave. For normal block and inline layout, or normal flow, this display type is `flow`. This means that the child elements will also be either `block` or `inline`. However, the inner display type might be something like `grid` or `flex`, in which case the direct children will display as a grid, or flex items. In such a case the element is described as creating a grid or flex [formatting context](/en-US/docs/Web/CSS/CSS_flow_layout/Introduction_to_formatting_contexts). In many ways, this is similar to a block formatting context, however, the children behave as flex or grid items rather than items in normal flow. The interactions between block-level and inline-level boxes are described in the MDN documentation for {{cssxref("display")}}. In addition, the references for specific values of display explain how these formatting contexts work in terms of box layout. - [CSS grid layout](/en-US/docs/Web/CSS/CSS_grid_layout) - [CSS flexible box layout](/en-US/docs/Web/CSS/CSS_flexible_box_layout) - [CSS table](/en-US/docs/Web/CSS/CSS_table) module - [CSS lists and counters](/en-US/docs/Web/CSS/CSS_lists) module ### Independent formatting contexts Elements either participate in the formatting context of their containing block or establish an independent formatting context. A grid container, for example, establishes a new **Grid Formatting Context** for its children. **Independent formatting contexts** contain floats, and margins do not collapse across formatting context boundaries. Therefore, creating a new block formatting context can ensure that floats and margins remain inside a box. To do this, add `display: flow-root` to the box on which you wish to create a new [block formatting context](/en-US/docs/Web/CSS/CSS_display/Block_formatting_context). The following example shows the effect of `display: flow-root`. The box with the black background appears to wrap round the floated item and text. If you remove `display: flow-root` from the editable CSS the floated item will poke out of the bottom of the box as it is no longer contained. {{EmbedGHLiveSample("css-examples/display/multi-keyword/block-flow-root.html", '100%', 720)}} ### Block boxes In specifications, block boxes, block-level boxes, and block containers are all referred to as **block boxes** in certain places. These things are somewhat different and the term block box should only be used if there is no ambiguity. #### Block containers A **block container** either contains only inline-level boxes participating in an inline formatting context, or only block-level boxes participating in a block formatting context. For this reason, we see the behavior explained above, where anonymous boxes are introduced to ensure all of the items can participate in a block or inline formatting context. An element is a block container only if it contains block-level or inline-level boxes. #### Inline-level and block-level boxes These are the boxes contained inside the block container that are participating in inline or block layout, respectively. #### Block boxes A block box is a block-level box that is also a block container. As described in CSS `display`, it is possible for a box to be a block-level box, but not also a block container (it might be a flex or grid container for example). ## See also - CSS key concepts: - [CSS syntax](/en-US/docs/Web/CSS/Syntax) - [Comments](/en-US/docs/Web/CSS/Comments) - [Specificity](/en-US/docs/Web/CSS/Specificity) - [Inheritance](/en-US/docs/Web/CSS/Inheritance) - [Box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model) - [Layout modes](/en-US/docs/Web/CSS/Layout_mode) - **Visual formatting models** - [Margin collapsing](/en-US/docs/Web/CSS/CSS_box_model/Mastering_margin_collapsing) - Values - [Initial values](/en-US/docs/Web/CSS/initial_value) - [Computed values](/en-US/docs/Web/CSS/computed_value) - [Used values](/en-US/docs/Web/CSS/used_value) - [Actual values](/en-US/docs/Web/CSS/actual_value) - [Value definition syntax](/en-US/docs/Web/CSS/Value_definition_syntax) - [Shorthand properties](/en-US/docs/Web/CSS/Shorthand_properties) - [Replaced elements](/en-US/docs/Web/CSS/Replaced_element)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/backface-visibility/index.md
--- title: backface-visibility slug: Web/CSS/backface-visibility page-type: css-property browser-compat: css.properties.backface-visibility --- {{CSSRef}} The **`backface-visibility`** [CSS](/en-US/docs/Web/CSS) property sets whether the back face of an element is visible when turned towards the user. {{EmbedInteractiveExample("pages/css/backface-visibility.html")}} An element's back face is a mirror image of its front face. Though invisible in 2D, the back face can become visible when a transformation causes the element to be rotated in 3D space. (This property has no effect on 2D transforms, which have no perspective.) ## Syntax ```css /* Keyword values */ backface-visibility: visible; backface-visibility: hidden; /* Global values */ backface-visibility: inherit; backface-visibility: initial; backface-visibility: revert; backface-visibility: revert-layer; backface-visibility: unset; ``` The `backface-visibility` property is specified as one of the keywords listed below. ### Values - `visible` - : The back face is visible when turned towards the user. - `hidden` - : The back face is hidden, effectively making the element invisible when turned away from the user. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Cube with transparent and opaque faces This example shows a cube with transparent faces, and one with opaque faces. #### HTML ```html <table> <tr> <th><code>backface-visibility: visible;</code></th> <th><code>backface-visibility: hidden;</code></th> </tr> <tr> <td> <div class="container"> <div class="cube showbf"> <div class="face front">1</div> <div class="face back">2</div> <div class="face right">3</div> <div class="face left">4</div> <div class="face top">5</div> <div class="face bottom">6</div> </div> </div> <p> Since all faces are partially transparent, the back faces (2, 4, 5) are visible through the front faces (1, 3, 6). </p> </td> <td> <div class="container"> <div class="cube hidebf"> <div class="face front">1</div> <div class="face back">2</div> <div class="face right">3</div> <div class="face left">4</div> <div class="face top">5</div> <div class="face bottom">6</div> </div> </div> <p>The three back faces (2, 4, 5) are hidden.</p> </td> </tr> </table> ``` #### CSS ```css /* Classes that will show or hide the three back faces of the "cube" */ .showbf div { backface-visibility: visible; } .hidebf div { backface-visibility: hidden; } /* Define the container div, the cube div, and a generic face */ .container { width: 150px; height: 150px; margin: 75px 0 0 75px; border: none; } .cube { width: 100%; height: 100%; perspective: 550px; perspective-origin: 150% 150%; transform-style: preserve-3d; } .face { display: block; position: absolute; width: 100px; height: 100px; border: none; line-height: 100px; font-family: sans-serif; font-size: 60px; color: white; text-align: center; } /* Define each face based on direction */ .front { background: rgb(0 0 0 / 30%); transform: translateZ(50px); } .back { background: rgb(0 255 0 / 100%); color: black; transform: rotateY(180deg) translateZ(50px); } .right { background: rgb(196 0 0 / 70%); transform: rotateY(90deg) translateZ(50px); } .left { background: rgb(0 0 196 / 70%); transform: rotateY(-90deg) translateZ(50px); } .top { background: rgb(196 196 0 / 70%); transform: rotateX(90deg) translateZ(50px); } .bottom { background: rgb(196 0 196 / 70%); transform: rotateX(-90deg) translateZ(50px); } /* Make the table a little nicer */ th, p, td { background-color: #eeeeee; margin: 0px; padding: 6px; font-family: sans-serif; text-align: left; } ``` #### Result {{EmbedLiveSample('Cube_with_transparent_and_opaque_faces', '100%', 360)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Using CSS transforms](/en-US/docs/Web/CSS/CSS_transforms/Using_CSS_transforms)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/text-decoration-thickness/index.md
--- title: text-decoration-thickness slug: Web/CSS/text-decoration-thickness page-type: css-property browser-compat: css.properties.text-decoration-thickness --- {{CSSRef}} The **`text-decoration-thickness`** [CSS](/en-US/docs/Web/CSS) property sets the stroke thickness of the decoration line that is used on text in an element, such as a line-through, underline, or overline. {{EmbedInteractiveExample("pages/css/text-decoration-thickness.html")}} ## Syntax ```css /* Single keyword */ text-decoration-thickness: auto; text-decoration-thickness: from-font; /* length */ text-decoration-thickness: 0.1em; text-decoration-thickness: 3px; /* percentage */ text-decoration-thickness: 10%; /* Global values */ text-decoration-thickness: inherit; text-decoration-thickness: initial; text-decoration-thickness: revert; text-decoration-thickness: revert-layer; text-decoration-thickness: unset; ``` ### Values - `auto` - : The browser chooses an appropriate width for the text decoration line. - `from-font` - : If the font file includes information about a preferred thickness, use that value. If the font file doesn't include this information, behave as if `auto` was set, with the browser choosing an appropriate thickness. - `<length>` - : Specifies the thickness of the text decoration line as a {{cssxref('length')}}, overriding the font file suggestion or the browser default. - `<percentage>` - : Specifies the thickness of the text decoration line as a {{cssxref('percentage')}} of **1em** in the current font. A percentage inherits as a relative value, and so therefore scales with changes in the font. The browser must use a minimum of 1 device pixel. For a given application of this property, the thickness is constant across the whole box it is applied to, even if there are child elements with a different font size. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Varying thickness #### HTML ```html <p class="thin">Here's some text with a 1px red underline.</p> <p class="thick">This one has a 5px red underline.</p> <p class="shorthand">This uses the equivalent shorthand.</p> ``` #### CSS ```css .thin { text-decoration-line: underline; text-decoration-style: solid; text-decoration-color: red; text-decoration-thickness: 1px; } .thick { text-decoration-line: underline; text-decoration-style: solid; text-decoration-color: red; text-decoration-thickness: 5px; } .shorthand { text-decoration: underline solid red 5px; } ``` #### Results {{EmbedLiveSample('Varying_thickness')}} ## Specifications {{Specifications}} > **Note:** The property used to be called `text-decoration-width`, but was updated in 2019 to `text-decoration-thickness`. ## Browser compatibility {{Compat}} ## See also - {{cssxref("text-decoration")}} - {{cssxref("text-underline-offset")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/break-inside/index.md
--- title: break-inside slug: Web/CSS/break-inside page-type: css-property browser-compat: css.properties.break-inside --- {{CSSRef}} The **`break-inside`** [CSS](/en-US/docs/Web/CSS) property sets how page, column, or region breaks should behave inside a generated box. If there is no generated box, the property is ignored. {{EmbedInteractiveExample("pages/css/break-inside.html")}} ## Syntax ```css /* Keyword values */ break-inside: auto; break-inside: avoid; break-inside: avoid-page; break-inside: avoid-column; break-inside: avoid-region; /* Global values */ break-inside: inherit; break-inside: initial; break-inside: revert; break-inside: revert-layer; break-inside: unset; ``` Each possible break point (in other words, each element boundary) is affected by three properties: the {{cssxref("break-after")}} value of the previous element, the {{cssxref("break-before")}} value of the next element, and the `break-inside` value of the containing element. To determine if a break must be done, the following rules are applied: 1. If any of the three concerned values is a _forced break value_ (`always`, `left`, `right`, `page`, `column`, or `region`), it has precedence. If more than one of them are such a break, the value of the element that appears the latest in the flow is used. Thus, the `break-before` value has precedence over the `break-after` value, which in turn has precedence over the `break-inside` value. 2. If any of the three concerned values is an _avoid break value_ (`avoid`, `avoid-page`, `avoid-region`, or `avoid-column`), no such break will be applied at that point. Once forced breaks have been applied, soft breaks may be added if needed, but not on element boundaries that resolve in a corresponding `avoid` value. ### Values - `auto` - : Allows, but does not force, any break (page, column, or region) to be inserted within the principal box. - `avoid` - : Avoids any break (page, column, or region) from being inserted within the principal box. - `avoid-page` - : Avoids any page break within the principal box. - `avoid-column` - : Avoids any column break within the principal box. - `avoid-region` {{experimental_inline}} - : Avoids any region break within the principal box. ## Page break aliases For compatibility reasons, the legacy {{cssxref("page-break-inside")}} property should be treated by browsers as an alias of `break-inside`. This ensures that sites using `page-break-inside` continue to work as designed. A subset of values should be aliased as follows: | page-break-inside | break-inside | | ----------------- | ------------ | | `auto` | `auto` | | `avoid` | `avoid` | ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Avoiding breaking inside a figure In the following example we have a container that contains an `<h1>` spanning all columns (achieved using `column-span: all`) and a series of paragraphs laid out in multiple columns using `column-width: 200px`. We also have a `<figure>` containing an image and a caption. By default, it is possible for you to get a break between the image and its caption, which is not what we want. To avoid this, we have set `break-inside: avoid` on the `<figure>`, which causes them to always stay together. #### HTML ```html <article> <h1>Main heading</h1> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vitae fringilla mauris. Quisque commodo eget nisi sed pretium. Mauris luctus nec lacus in ultricies. Mauris vitae hendrerit arcu, ac scelerisque lacus. Aliquam lobortis in lacus sit amet posuere. Fusce iaculis urna id neque dapibus, eu lacinia lectus dictum. </p> <figure> <img src="https://mdn.dev/archives/media/attachments/2020/07/29/17350/3b4892b7e820122ac6dd7678891d4507/firefox.png" /> <figcaption>The Firefox logo — fox wrapped around the world</figcaption> </figure> <p> Praesent condimentum dui dui, sit amet rutrum diam tincidunt eu. Cras suscipit porta leo sit amet rutrum. Sed vehicula ornare tincidunt. Curabitur a ipsum ac diam mattis volutpat ac ut elit. Nullam luctus justo non vestibulum gravida. Morbi metus libero, pharetra non porttitor a, molestie nec nisi. </p> <p> In finibus viverra enim vel suscipit. Quisque consequat velit eu orci malesuada, ut interdum tortor molestie. Proin sed pellentesque augue. Nam risus justo, faucibus non porta a, congue vel massa. Cras luctus lacus nisl, sed tincidunt velit pharetra ac. Duis suscipit faucibus dui sed ultricies. </p> </article> ``` #### CSS ```css html { font-family: helvetica, arial, sans-serif; } body { width: 80%; margin: 0 auto; } h1 { font-size: 3rem; letter-spacing: 2px; column-span: all; } h1 + p { margin-top: 0; } p { line-height: 1.5; break-after: column; } figure { break-inside: avoid; } img { max-width: 70%; display: block; margin: 0 auto; } figcaption { font-style: italic; font-size: 0.8rem; width: 70%; } article { column-width: 200px; gap: 20px; } ``` ### Result {{EmbedLiveSample('Avoiding_breaking_inside_a_figure', '100%', 600)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Multiple-column Layout](/en-US/docs/Learn/CSS/CSS_layout/Multiple-column_Layout) - [Breaking Boxes With CSS Fragmentation](https://www.smashingmagazine.com/2019/02/css-fragmentation/)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_right/index.md
--- title: ":right" slug: Web/CSS/:right page-type: css-pseudo-class browser-compat: css.selectors.right --- {{CSSRef}} The **`:right`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes), used with the {{cssxref("@page")}} [at-rule](/en-US/docs/Web/CSS/At-rule), represents all right-hand pages of a printed document. ```css /* Selects any right-hand pages when printing */ @page :right { margin: 2in 3in; } ``` Whether a given page is "left" or "right" is determined by the major writing direction of the document. For example, if the first page has a major writing direction of left-to-right then it will be a `:right` page; if it has a major writing direction of right-to-left then it will be a {{Cssxref(":left")}} page. > **Note:** This pseudo-class can be used to change only the {{ Cssxref("margin") }}, {{ Cssxref("padding") }}, {{ Cssxref("border") }}, and {{ Cssxref("background") }} properties of the _page box_. All other properties will be ignored, and only the page box, not the document content on the page, will be affected. ## Syntax ```css :right { /* ... */ } ``` ## Examples ### Setting margins for right-hand pages ```css @page :right { margin: 2in 3in; } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{ Cssxref("@page") }} - Other page-related pseudo-classes: {{ Cssxref(":first") }}, {{ Cssxref(":left") }}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/grid-row/index.md
--- title: grid-row slug: Web/CSS/grid-row page-type: css-shorthand-property browser-compat: css.properties.grid-row --- {{CSSRef}} The **`grid-row`** CSS [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) specifies a grid item's size and location within a {{glossary("grid row")}} by contributing a line, a span, or nothing (automatic) to its grid placement, thereby specifying the inline-start and inline-end edge of its {{glossary("grid areas", "grid area")}}. {{EmbedInteractiveExample("pages/css/grid-row.html")}} ## Constituent properties This property is a shorthand for the following CSS properties: - [`grid-row-end`](/en-US/docs/Web/CSS/grid-row-end) - [`grid-row-start`](/en-US/docs/Web/CSS/grid-row-start) ## Syntax ```css /* Keyword values */ grid-row: auto; grid-row: auto / auto; /* <custom-ident> values */ grid-row: somegridarea; grid-row: somegridarea / someothergridarea; /* <integer> + <custom-ident> values */ grid-row: somegridarea 4; grid-row: 4 somegridarea / 6; /* span + <integer> + <custom-ident> values */ grid-row: span 3; grid-row: span somegridarea; grid-row: 5 somegridarea span; grid-row: span 3 / 6; grid-row: span somegridarea / span someothergridarea; grid-row: 5 somegridarea span / 2 span; /* Global values */ grid-row: inherit; grid-row: initial; grid-row: revert; grid-row: revert-layer; grid-row: unset; ``` This property is specified as one or two `<grid-line>` values. If two `<grid-line>` values are given, they are separated by `/`. The `grid-row-start` longhand is set to the value before the slash, and the `grid-row-end` longhand is set to the value after the slash. Each `<grid-line>` value can be specified as: - either the `auto` keyword - or a `<custom-ident>` value - or an `<integer>` value - or both `<custom-ident>` and `<integer>`, separated by a space - or the keyword `span` together with either a `<custom-ident>` or an `<integer>` or both. ### Values - `auto` - : Is a keyword indicating that the property contributes nothing to the grid item's placement, indicating auto-placement, an automatic span, or a default span of `1`. - `<custom-ident>` - : If there is a named line with the name `<custom-ident>-start`/`<custom-ident>-end`, it contributes the first such line to the grid item's placement. > **Note:** Named grid areas automatically generate implicit named lines of this form, so specifying `grid-row: foo;` will choose the start/end edge of that named grid area (unless another line named `foo-start`/`foo-end` was explicitly specified before it). Otherwise, this is treated as if the integer `1` had been specified along with the `<custom-ident>`. - `<integer> && <custom-ident>?` - : Contributes the nth grid line to the grid item's placement. If a negative integer is given, it instead counts in reverse, starting from the end edge of the explicit grid. If a name is given as a `<custom-ident>`, only lines with that name are counted. If not enough lines with that name exist, all implicit grid lines are assumed to have that name for the purpose of finding this position. An {{cssxref("integer")}} value of `0` is invalid. - `span && [ <integer> || <custom-ident> ]` - : Contributes a grid span to the grid item's placement such that the corresponding edge of the grid item's grid area is n lines from the opposite edge. If a name is given as a `<custom-ident>`, only lines with that name are counted. If not enough lines with that name exist, all implicit grid lines on the side of the explicit grid corresponding to the search direction are assumed to have that name for the purpose of counting this span. If the `<integer>` is omitted, it defaults to `1`. Negative integers or 0 are invalid. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting grid row size and location #### HTML ```html <div id="grid"> <div id="item1"></div> <div id="item2"></div> <div id="item3"></div> </div> ``` #### CSS ```css #grid { display: grid; height: 200px; grid-template-columns: 200px; grid-template-rows: repeat(6, 1fr); } #item1 { background-color: lime; } #item2 { background-color: yellow; grid-row: 2 / 4; } #item3 { background-color: blue; grid-row: span 2 / 7; } ``` #### Result {{EmbedLiveSample("Setting_grid_row_size_and_location", "200px", "200px")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Related CSS properties: {{cssxref("grid-row-start")}}, {{cssxref("grid-row-end")}}, {{cssxref("grid-column")}}, {{cssxref("grid-column-start")}}, {{cssxref("grid-column-end")}} - Grid Layout Guide: _[Line-based placement with CSS Grid](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_layout_using_line-based_placement)_ - Video tutorial: _[Line-based placement](https://gridbyexample.com/video/series-line-based-placement/)_
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/grid-column-end/index.md
--- title: grid-column-end slug: Web/CSS/grid-column-end page-type: css-property browser-compat: css.properties.grid-column-end --- {{CSSRef}} The **`grid-column-end`** CSS property specifies a grid item's end position within the grid column by contributing a line, a span, or nothing (automatic) to its grid placement, thereby specifying the block-end edge of its {{glossary("grid areas", "grid area")}}. {{EmbedInteractiveExample("pages/css/grid-column-end.html")}} ## Syntax ```css /* Keyword value */ grid-column-end: auto; /* <custom-ident> values */ grid-column-end: somegridarea; /* <integer> + <custom-ident> values */ grid-column-end: 2; grid-column-end: somegridarea 4; /* span + <integer> + <custom-ident> values */ grid-column-end: span 3; grid-column-end: span somegridarea; grid-column-end: 5 somegridarea span; /* Global values */ grid-column-end: inherit; grid-column-end: initial; grid-column-end: revert; grid-column-end: revert-layer; grid-column-end: unset; ``` ### Values - `auto` - : Is a keyword indicating that the property contributes nothing to the grid item's placement, indicating auto-placement, an automatic span, or a default span of `1`. - `<custom-ident>` - : If there is a named line with the name '\<custom-ident>-end', it contributes the first such line to the grid item's placement. > **Note:** Named grid areas automatically generate implicit named lines of this form, so specifying `grid-column-end: foo;` will choose the end edge of that named grid area (unless another line named `foo-end` was explicitly specified before it). Otherwise, this is treated as if the integer `1` had been specified along with the `<custom-ident>`. - `<integer> && <custom-ident>?` - : Contributes the nth grid line to the grid item's placement. If a negative integer is given, it instead counts in reverse, starting from the end edge of the explicit grid. If a name is given as a \<custom-ident>, only lines with that name are counted. If not enough lines with that name exist, all implicit grid lines are assumed to have that name for the purpose of finding this position. An {{cssxref("integer")}} value of `0` is invalid. - `span && [ <integer> || <custom-ident> ]` - : Contributes a grid span to the grid item's placement such that the column end edge of the grid item's grid area is n lines from the start edge. If a name is given as a \<custom-ident>, only lines with that name are counted. If not enough lines with that name exist, all implicit grid lines on the side of the explicit grid corresponding to the search direction are assumed to have that name for the purpose of counting this span. If the \<integer> is omitted, it defaults to `1`. Negative integers or 0 are invalid. The `<custom-ident>` cannot take the `span` value. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting column end for a grid item #### HTML ```html <div class="wrapper"> <div class="box1">One</div> <div class="box2">Two</div> <div class="box3">Three</div> <div class="box4">Four</div> <div class="box5">Five</div> </div> ``` #### CSS ```css .wrapper { display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 100px; } .box1 { grid-column-start: 1; grid-column-end: 4; grid-row-start: 1; grid-row-end: 3; } .box2 { grid-column-start: 1; grid-row-start: 3; grid-row-end: 5; } ``` ```css hidden * { box-sizing: border-box; } .wrapper { border: 2px solid #f76707; border-radius: 5px; background-color: #fff4e6; } .wrapper > div { border: 2px solid #ffa94d; border-radius: 5px; background-color: #ffd8a8; padding: 1em; color: #d9480f; } .nested { border: 2px solid #ffec99; border-radius: 5px; background-color: #fff9db; padding: 1em; } ``` #### Result {{ EmbedLiveSample('Setting_column_end_for_a_grid_item', '230', '420') }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Related CSS properties: {{cssxref("grid-column-start")}}, {{cssxref("grid-column")}}, {{cssxref("grid-row-start")}}, {{cssxref("grid-row-end")}}, {{cssxref("grid-row")}} - Grid Layout Guide: _[Line-based placement with CSS Grid](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_layout_using_line-based_placement)_ - Video tutorial: _[Line-based placement](https://gridbyexample.com/video/series-line-based-placement/)_
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_media_queries/index.md
--- title: CSS media queries slug: Web/CSS/CSS_media_queries page-type: css-module spec-urls: - https://drafts.csswg.org/mediaqueries-3/ - https://drafts.csswg.org/mediaqueries/ - https://drafts.csswg.org/mediaqueries-5/ --- {{CSSRef}} The **CSS media queries** module enables testing and querying of viewport values and browser or device features, to conditionally apply CSS styles based on the current user environment. Media queries are used in the CSS `@media` rule and other contexts and languages such as HTML and JavaScript. Media queries are a key component of [responsive design](/en-US/docs/Learn/CSS/CSS_layout/Responsive_Design). They enable conditional setting of CSS styles depending on the presence or value of device characteristics. It's common to use a media query based on {{Glossary("viewport")}} size to set appropriate layouts on devices with different screen sizes — for example three columns on a wide screen or a single column on a narrow screen. Other common examples include increasing the font size and hiding navigation menus when printing a page, adjusting the padding between paragraphs when a page is viewed in portrait or landscape mode, or increasing the size of buttons to provide a larger hit area on touchscreens. In [CSS](/en-US/docs/Web/CSS), use the {{cssxref("@media")}} [at-rule](/en-US/docs/Web/CSS/At-rule) to conditionally apply part of a style sheet based on the result of a media query. To conditionally apply an entire style sheet, use {{cssxref("@import")}}. When designing reusable HTML components, you may also use [container queries](/en-US/docs/Web/CSS/CSS_containment/Container_queries), which allow you to apply styles based on the size of a containing element rather than the viewport or other device characteristics. ## Reference ### At-rules - {{cssxref("@import")}} - {{cssxref("@media")}} ### Descriptors - {{cssxref("@media/any-hover", "any-hover")}} - {{cssxref("@media/any-pointer", "any-pointer")}} - {{cssxref("@media/aspect-ratio", "aspect-ratio")}} - {{cssxref("@media/color", "color")}} - {{cssxref("@media/color-gamut", "color-gamut")}} - {{cssxref("@media/color-index", "color-index")}} - {{cssxref("@media/device-aspect-ratio", "device-aspect-ratio")}} - {{cssxref("@media/device-height", "device-height")}} - {{cssxref("@media/device-width", "device-width")}} - {{cssxref("@media/display-mode", "display-mode")}} - {{cssxref("@media/dynamic-range", "dynamic-range")}} - {{cssxref("@media/forced-colors", "forced-colors")}} - {{cssxref("@media/grid", "grid")}} - {{cssxref("@media/height", "height")}} - {{cssxref("@media/hover", "hover")}} - {{cssxref("@media/inverted-colors", "inverted-colors")}} - {{cssxref("@media/monochrome", "monochrome")}} - {{cssxref("@media/orientation", "orientation")}} - {{cssxref("@media/overflow-block", "overflow-block")}} - {{cssxref("@media/overflow-inline", "overflow-inline")}} - {{cssxref("@media/pointer", "pointer")}} - {{cssxref("@media/prefers-color-scheme", "prefers-color-scheme")}} - {{cssxref("@media/prefers-contrast", "prefers-contrast")}} - {{cssxref("@media/prefers-reduced-data", "prefers-reduced-data")}} - {{cssxref("@media/prefers-reduced-motion", "prefers-reduced-motion")}} - {{cssxref("@media/prefers-reduced-transparency", "prefers-reduced-transparency")}} - {{cssxref("@media/resolution", "resolution")}} - {{cssxref("@media/scan", "scan")}} - {{cssxref("@media/scripting", "scripting")}} - {{cssxref("@media/update", "update")}} - {{cssxref("@media/video-dynamic-range", "video-dynamic-range")}} - {{cssxref("@media/width", "width")}} > **Note:** CSS media queries level 5 introduces five `@media` descriptors that have not been implemented: {{cssxref("@media/environment-blending", "environment-blending")}}, {{cssxref("@media/horizontal-viewport-segments", "horizontal-viewport-segments")}}, {{cssxref("@media/nav-controls", "nav-controls")}}, {{cssxref("@media/vertical-viewport-segments", "vertical-viewport-segments")}}, and {{cssxref("@media/video-color-gamut", "video-color-gamut")}} > **Note:** CSS media queries level 4 deprecated three `@media` descriptors: {{cssxref("@media/device-aspect-ratio", "device-aspect-ratio")}}, {{cssxref("@media/device-height", "device-height")}}, and {{cssxref("@media/device-width", "device-width")}}. ### Data types and operators - [`<media-types>`](/en-US/docs/Web/CSS/@media#media_types) - [`<media-features>`](/en-US/docs/Web/CSS/@media#media_features) - [`<resolution>`](/en-US/docs/Web/CSS/resolution) - [Logical operators](/en-US/docs/Web/CSS/@media#logical_operators) ### Glossary terms - [media](/en-US/docs/Glossary/Media/CSS) - [media query](/en-US/docs/Glossary/Media_query) ## Guides - [Using media queries](/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries) - : Introduces media queries, their syntax, and the operators and media features used to construct media query expressions. - [Beginner's guide to media queries](/en-US/docs/Learn/CSS/CSS_layout/Media_queries) - : Introduction to media queries and approaches for using them to create responsive designs. - [Testing media queries](/en-US/docs/Web/CSS/CSS_media_queries/Testing_media_queries) - : Describes how to use media queries in your JavaScript code to determine the state of a device, and to set up listeners that notify your code when the results of media queries change (such as when the user rotates the screen or resizes the browser). - [Using media queries for accessibility](/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries_for_accessibility) - : Learn how media queries can help users understand your website better. - [Printing](/en-US/docs/Web/CSS/CSS_media_queries/Printing) - : Tips and techniques for helping improve web content printer output. - [Learn: responsive images](/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images) - : Learn how to use media queries with `sizes` to implement responsive image solutions on websites. ## Related concepts - [CSS containment](/en-US/docs/Web/CSS/CSS_containment) module - {{cssxref("@container")}} at-rule - [Using container queries](/en-US/docs/Web/CSS/CSS_containment/Container_queries) - [Using size and style container queries](/en-US/docs/Web/CSS/CSS_containment/Container_size_and_style_queries) - [CSS conditional rules](/en-US/docs/Web/CSS/CSS_conditional_rules) module - {{cssxref("@supports")}} at-rule - [Using feature queries](/en-US/docs/Web/CSS/CSS_conditional_rules/Using_feature_queries) - [CSS paged media](/en-US/docs/Web/CSS/CSS_paged_media) module - {{cssxref("@page")}} at-rule - [CSS object model](/en-US/docs/Web/API/CSS_Object_Model) module - {{DOMxRef("MediaQueryList")}} interface - {{DOMxRef("MediaQueryList.matches", "matches")}} property - {{DOMxRef("MediaQueryList.media", "media")}} property - {{DOMxRef("MediaQueryList.change_event", "change")}} event - {{DOMxRef("MediaList")}} interface - {{DOMxRef("MediaList.mediaText", "mediaText")}} property - {{DOMxRef("MediaQueryListEvent")}} object - HTML - `sizes` attribute for [`<img>`](/en-US/docs/Web/HTML/Element/img#sizes), [`<link>`](/en-US/docs/Web/HTML/Element/link#sizes), and [`<source>`](/en-US/docs/Web/HTML/Element/source#sizes) for {{HTMLElement("picture")}} - `media` attribute for [`<link>`](/en-US/docs/Web/HTML/Element/link#media), [`<source>`](/en-US/docs/Web/HTML/Element/source#media), and [`<style>`](/en-US/docs/Web/HTML/Element/style#media) [HTML](/en-US/docs/Web/HTML) - [Viewport `<meta>` tag](/en-US/docs/Web/HTML/Viewport_meta_tag) - SVG [`media`](/en-US/docs/Web/SVG/Attribute/media) attribute ## Specifications {{Specifications}} ## See also - [Container queries](/en-US/docs/Web/CSS/CSS_containment/Container_queries) - [Using the `srcset` and `sizes` attributes](/en-US/docs/Web/HTML/Element/img#using_the_srcset_and_sizes_attributes) - [CSS paged media](/en-US/docs/Web/CSS/CSS_paged_media) - Use {{cssxref("@supports")}} to apply styles that depend on browser support for various CSS technologies.
0
data/mdn-content/files/en-us/web/css/css_media_queries
data/mdn-content/files/en-us/web/css/css_media_queries/using_media_queries/index.md
--- title: Using media queries slug: Web/CSS/CSS_media_queries/Using_media_queries page-type: guide --- {{CSSRef}} **Media queries** allow you to apply CSS styles depending on a device's media type (such as print vs. screen) or other features or characteristics such as screen resolution or orientation, aspect ratio, browser {{glossary("viewport")}} width or height, user preferences such as preferring reduced motion, data usage, or transparency. Media queries are used for the following: - To conditionally apply styles with the [CSS](/en-US/docs/Web/CSS) {{cssxref("@media")}} and {{cssxref("@import")}} [at-rules](/en-US/docs/Web/CSS/At-rule). - To target specific media for the {{HTMLElement("style")}}, {{HTMLElement("link")}}, {{HTMLElement("source")}}, and other [HTML](/en-US/docs/Web/HTML) elements with the `media=` or `sizes="` attributes. - To [test and monitor media states](/en-US/docs/Web/CSS/CSS_media_queries/Testing_media_queries) using the {{domxref("Window.matchMedia()")}} and {{domxref("EventTarget.addEventListener()")}} methods. > **Note:** The examples on this page use CSS's `@media` for illustrative purposes, but the basic syntax remains the same for all types of media queries. ## Syntax A media query is composed of an optional _media type_ and any number of _media feature_ expressions, which may optionally be combined in various ways using _logical operators_. Media queries are case-insensitive. - [Media types](/en-US/docs/Web/CSS/@media#media_types) define the broad category of device for which the media query applies: `all`, `print`, `screen`. The type is optional (assumed to be `all`) except when using the `not` or `only` logical operators. - [Media features](/en-US/docs/Web/CSS/@media#media_features) describe a specific characteristic of the {{glossary("user agent")}}, output device, or environment: - {{cssxref("@media/any-hover", "any-hover")}} - {{cssxref("@media/any-pointer", "any-pointer")}} - {{cssxref("@media/aspect-ratio", "aspect-ratio")}} - {{cssxref("@media/color", "color")}} - {{cssxref("@media/color-gamut", "color-gamut")}} - {{cssxref("@media/color-index", "color-index")}} - {{cssxref("@media/device-aspect-ratio", "device-aspect-ratio")}} {{deprecated_inline}} - {{cssxref("@media/device-height", "device-height")}} {{deprecated_inline}} - {{cssxref("@media/device-width", "device-width")}} {{deprecated_inline}} - {{cssxref("@media/display-mode", "display-mode")}} - {{cssxref("@media/dynamic-range", "dynamic-range")}} - {{cssxref("@media/forced-colors", "forced-colors")}} - {{cssxref("@media/grid", "grid")}} - {{cssxref("@media/height", "height")}} - {{cssxref("@media/hover", "hover")}} - {{cssxref("@media/inverted-colors", "inverted-colors")}} - {{cssxref("@media/monochrome", "monochrome")}} - {{cssxref("@media/orientation", "orientation")}} - {{cssxref("@media/overflow-block", "overflow-block")}} - {{cssxref("@media/overflow-inline", "overflow-inline")}} - {{cssxref("@media/pointer", "pointer")}} - {{cssxref("@media/prefers-color-scheme", "prefers-color-scheme")}} - {{cssxref("@media/prefers-contrast", "prefers-contrast")}} - {{cssxref("@media/prefers-reduced-motion", "prefers-reduced-motion")}} - {{cssxref("@media/prefers-reduced-transparency", "prefers-reduced-transparency")}} {{experimental_inline}} - {{cssxref("@media/resolution", "resolution")}} - {{cssxref("@media/scripting", "scripting")}} - {{cssxref("@media/update", "update")}} - {{cssxref("@media/video-dynamic-range", "video-dynamic-range")}} - {{cssxref("@media/width", "width")}}. For example, the {{cssxref("@media/hover", "hover")}} feature allows a query to check whether the device supports hovering over elements. Media feature expressions test for their presence or value, and are entirely optional. Each media feature expression must be surrounded by parentheses. - [Logical operators](/en-US/docs/Web/CSS/@media#logical_operators) can be used to compose a complex media query: `not`, `and`, and `only`. You can also combine multiple media queries into a single rule by separating them with commas. A media query computes to `true` when the media type (if specified) matches the device on which a document is being displayed _and_ all media feature expressions compute as true. Queries involving unknown media types are always false. > **Note:** A style sheet with a media query attached to its {{HTMLElement("link")}} tag [will still download](https://scottjehl.github.io/CSS-Download-Tests/) even if the query returns `false`, the download will happen but the priority of downloading will be much lower. > Nevertheless, its contents will not apply unless and until the result of the query changes to `true`. > You can read why this happens in Tomayac's blog [Why Browser Download Stylesheet with Non-Matching Media Queries](https://medium.com/@tomayac/why-browsers-download-stylesheets-with-non-matching-media-queries-eb61b91b85a2). ## Targeting media types Media types describe the general category of a given device. Although websites are commonly designed with screens in mind, you may want to create styles that target special devices such as printers or audio-based screen readers. For example, this CSS targets printers: ```css @media print { /* … */ } ``` You can also target multiple devices. For instance, this `@media` rule uses two media queries to target both screen and print devices: ```css @media screen, print { /* … */ } ``` See [media types](/en-US/docs/Web/CSS/@media#media_types) for the list of available media types. Because media types describe devices in very broad terms, most of the originally-defined media types were deprecated, with just `screen`, `print`, and `all` remaining. To target more specific attributes, use _media features_ instead. ## Targeting media features Media features describe the specific characteristics of a given {{glossary("user agent")}}, output device, or environment. For instance, you can apply specific styles to widescreen monitors, computers that use mice, or devices that are being used in low-light conditions. This example applies styles when the user's _primary_ input mechanism (such as a mouse) can hover over elements: ```css @media (hover: hover) { /* … */ } ``` Media features are either range or discrete. _Discrete features_ take their value from an {{glossary("enumerated")}} set of possible keyword values. For example, the discrete `orientation` feature accepts either `landscape` or `portrait`. ```css @media print and (orientation: portrait) { /* … */ } ``` Many _range features_ can be prefixed with "min-" or "max-" to express "minimum condition" or "maximum condition" constraints. For example, this CSS will apply styles only if your browser's {{glossary("viewport")}} width is equal to or narrower than 1250px: ```css @media (max-width: 1250px) { /* … */ } ``` This can also be written as: ```css @media (width <= 1250px) { /* … */ } ``` With media query range features, you can either use the inclusive `min-` and `max-` prefixes or the more concise range syntax operators `<=` and `=>`. The following media queries are equivalent: ```css @media (min-width: 30em) and (max-width: 50em) { /* … */ } @media (30em <= width <= 50em) { /* … */ } ``` The range comparisons above are inclusive. To not include the comparison value, use `<` and `>`. ```css @media (30em < width < 50em) { /* … */ } ``` If you create a media feature query without specifying a value, the nested styles will be used as long as the feature's value is not 0 or `none`. For example, this CSS will apply to any device with a color screen: ```css @media (color) { /* … */ } ``` If a feature doesn't apply to the device on which the browser is running, expressions involving that media feature are always false. For more [Media feature](/en-US/docs/Web/CSS/@media#media_features) examples, please see the reference page for each specific feature. ## Creating complex media queries Sometimes you may want to create a media query that depends on multiple conditions. This is where the _logical operators_ come in: `not`, `and`, and `only`. Furthermore, you can combine multiple media queries into a _comma-separated list_; this allows you to apply the same styles in different situations. In the previous example, we saw the `and` operator used to group a media _type_ with a media _feature_. The `and` operator can also combine multiple media features into a single media query. The `not` operator, meanwhile, negates a media query, basically reversing its normal meaning. The `only` operator prevents older browsers from applying the styles. > **Note:** In most cases, the `all` media type is used by default when no other type is specified. > However, if you use the `not` or `only` operators, you must explicitly specify a media type. ### Combining multiple types or features The `and` keyword combines a media feature with a media type _or_ other media features. This example combines two media features to restrict styles to landscape-oriented devices with a width of at least 30 ems: ```css @media (min-width: 30em) and (orientation: landscape) { /* … */ } ``` To limit the styles to devices with a screen, you can chain the media features to the `screen` media type: ```css @media screen and (min-width: 30em) and (orientation: landscape) { /* … */ } ``` ### Testing for multiple queries You can use a comma-separated list of media queries to apply styles when the user's device matches any one of various media types, features, or states. The following rule contains two media queries. The block's styles will apply if either the user's device has a height of 680px or more _or_ is if the browser viewport is in portrait mode (the viewport height is greater than the viewport width): ```css @media (min-height: 680px), screen and (orientation: portrait) { /* … */ } ``` In this example, if the user is printing to a PDF and the page height is 800px, the media query returns true because the first query component — which tests whether the viewport has a height of `680px` or more — is true. Likewise, if a user is on a smartphone in portrait mode with a viewport height of 480px, the media query returns true because the second query component is true. In a comma-separated list of media queries, the individual media queries end at the comma or, in the case of the last media query in the list, at the opening bracket (`{`). ### Inverting a query's meaning The `not` keyword inverts the meaning of a single media query. For example, the CSS styles in this media query will apply to everything _except_ printed media: ```css @media not print { /* … */ } ``` The `not` negates only the media query it is applied to. The `not`, without parenthesis, negates all the features within the media query in which it is contained. This means, in a comma-separated list of media queries, each `not` applies to the single query it is contained within, applying to _all_ the features within that single query. In this example, the `not` applies to the first media query, which concludes at the first comma: ```css @media not screen and (color), print and (color) { /* … */ } ``` The above query is evaluated like this: ```css @media (not (screen and (color))), print and (color) { /* … */ } ``` Both examples are valid. Media conditions can be grouped by wrapping them in parentheses (`()`). These groups can then be nested within a condition the same as a single media query. The `not` is evaluated last in a media query, meaning it applies to the entire media query, not to a single feature within a query, as if an open parenthesis was added immediately after the `not` and closed at the end of the media query. The following query: ```css @media not all and (monochrome) { /* … */ } ``` is evaluated like this: ```css @media not (all and (monochrome)) { /* … */ } ``` It is not evaluated like this: ```css example-bad @media (not all) and (monochrome) { /* … */ } ``` To negate a single feature within a media query, use parenthesis. Encompassing a `not` and a media feature in parentheses limits the components of the query that get negated. In this example, we negate the `hover` media feature but not the `all` media type: ```css @media all and (not(hover)) { /* … */ } ``` The `not(hover)` matches if the device has no hover capability. In this case, because of the parentheses, the `not` applies to `hover` but not to `all`. ### Improving compatibility with older browsers The `only` keyword prevents older browsers that do not support media queries with media features from applying the given styles. _It has no effect on modern browsers._ ```css @media only screen and (color) { /* … */ } ``` ### Testing for multiple features with `or` You can use `or` to test for a match among more than one feature, resolving to `true` if any of the features are true. For example, the following query tests for devices that have a monochrome display or hover capability: ```css @media (not (color)) or (hover) { /* … */ } ``` ## See also - [@media](/en-US/docs/Web/CSS/@media) - [Container queries](/en-US/docs/Web/CSS/CSS_containment/Container_queries) - [Testing media queries programmatically](/en-US/docs/Web/CSS/CSS_media_queries/Testing_media_queries) - [CSS Animations Between Media Queries](https://davidwalsh.name/animate-media-queries) - [Extended Mozilla media features](/en-US/docs/Web/CSS/Mozilla_Extensions#media_features) - [Extended WebKit media features](/en-US/docs/Web/CSS/WebKit_Extensions#media_features)
0
data/mdn-content/files/en-us/web/css/css_media_queries
data/mdn-content/files/en-us/web/css/css_media_queries/using_media_queries_for_accessibility/index.md
--- title: Using media queries for accessibility slug: Web/CSS/CSS_media_queries/Using_media_queries_for_accessibility page-type: guide --- {{CSSRef}} [**CSS media queries**](/en-US/docs/Web/CSS/CSS_media_queries) can be used to help users with disabilities better experience your website. ## Reduced Motion Blinking and flashing animation can be problematic for people with cognitive concerns such as Attention Deficit Hyperactivity Disorder (ADHD). Additionally, certain kinds of motion can be a trigger for Vestibular disorders, epilepsy, and migraine and Scotopic sensitivity. The [`prefers-reduced-motion`](/en-US/docs/Web/CSS/@media/prefers-reduced-motion) media query enables providing an experience with fewer animations and transitions to users who have set their operating system's accessibility preferences to reduce motion. Reducing animations or switching animation off completely based on the user's preference can also benefit users with low battery or low-end devices. ### Syntax - `no-preference` - : Indicates that the user has made no preference known to the system. - `reduce` - : Indicates that user has notified the system that they prefer an interface that minimizes the amount of movement or animation, preferably to the point where all non-essential movement is removed. ### Example This example has an annoying animation unless you turn on Reduce Motion in [your accessibility preferences](/en-US/docs/Web/Accessibility/Accessibility:_What_users_can_to_to_browse_safely). #### HTML ```html <div class="animation">animated box</div> ``` #### CSS ```css .animation { animation: vibrate 0.3s linear infinite both; } @media (prefers-reduced-motion: reduce) { .animation { animation: none; } } ``` The value of `prefers-reduced-motion` is `reduce`, not "none". This preference does not mean all animations must be removed, which could be achieved with `* {animation: none !important;}`. Rather, users expect motion animation, including those triggered by user interaction, to be disabled unless the animation is essential to the functionality or the information being conveyed (see [WCAG: Animation from Interactions](https://www.w3.org/WAI/WCAG21/Understanding/animation-from-interactions.html)). ## See also - [`prefers-contrast`](/en-US/docs/Web/CSS/@media/prefers-contrast): to adjust page styles based on user's contrast preference - [`prefers-reduced-transparency`](/en-US/docs/Web/CSS/@media/prefers-reduced-transparency) - [`prefers-color-scheme`](/en-US/docs/Web/CSS/@media/prefers-color-scheme) - [`inverted-colors`](/en-US/docs/Web/CSS/@media/inverted-colors) - [Designing With Reduced Motion For Motion Sensitivities](https://www.smashingmagazine.com/2020/09/design-reduced-motion-sensitivities/)
0
data/mdn-content/files/en-us/web/css/css_media_queries
data/mdn-content/files/en-us/web/css/css_media_queries/printing/index.md
--- title: Printing slug: Web/CSS/CSS_media_queries/Printing page-type: guide --- {{CSSRef}} There may be times in which your website or application would like to improve the user's experience when printing content. There are several possible scenarios: - You wish to adjust layout to take advantage of the size and shape of the paper. - You wish to use different styles to enhance the appearance of your content on paper. - You wish to use higher resolution images for a better result. - You want to adjust the user experience of printing, such as presenting a specially-formatted version of your content before printing begins. There may be other cases in which you want to manage the printing process, but these are some of the most common scenarios. This article provides tips and techniques for helping your web content print better. ## Using a print style sheet Add the following to your {{HTMLElement("head")}} tag. ```html <link href="/path/to/print.css" media="print" rel="stylesheet" /> ``` ## Using media queries and @page to control printed content You can use the CSS {{cssxref("@media")}} at-rule to set different styles for your webpage when it is printed on paper or as a PDF versus when it is displayed on the screen. The `print` [media type](/en-US/docs/Web/CSS/@media#media_type) sets the styles for printed media; these styles will only be used for printed content. Add this at the end of your stylesheet. Note that [specificity](/en-US/docs/Web/CSS/Specificity) and precedence rules still apply: ```css @media print { /* All your print styles go here */ #header, #footer, #nav { display: none !important; } } ``` You can also use the {{cssxref("@page")}} at-rule to modify different aspects of printed pages including the page's dimensions, orientation, and margins. The `@page` at-rule can be used to target all pages in a print-out or just a specific subset of pages ## Detecting print requests Browsers send {{domxref("Window/beforeprint_event", "beforeprint")}} and {{domxref("Window/afterprint_event", "afterprint")}} events to determine when printing may have occurred. You can use this to adjust the user interface presented during printing (for example displaying or hiding user interface elements during the print process). ## Examples Here are some common examples. ### Automatically close the window when finished The following example will close the window after the user has printed its contents: ```js window.addEventListener("afterprint", () => self.close); ``` ### Print an external page without opening it If you want to be able to print an external page without opening it, you can utilize a hidden {{HTMLElement("iframe")}} (see: [HTMLIFrameElement](/en-US/docs/Web/API/HTMLIFrameElement)), automatically removing it after the user prints its contents. The following is a possible example which will print a file named `externalPage.html`: #### HTML ```html <button id="print_external">Print external page!</button> ``` #### JavaScript ```js function setPrint() { const closePrint = () => { document.body.removeChild(this); }; this.contentWindow.onbeforeunload = closePrint; this.contentWindow.onafterprint = closePrint; this.contentWindow.print(); } document.getElementById("print_external").addEventListener("click", () => { const hideFrame = document.createElement("iframe"); hideFrame.onload = setPrint; hideFrame.style.display = "none"; // hide iframe hideFrame.src = "external-page.html"; document.body.appendChild(hideFrame); }); ``` ## See also - [`window.print`](/en-US/docs/Web/API/Window/print) - {{ domxref("window.beforeprint_event", "beforeprint") }} event - {{ domxref("window.afterprint_event", "afterprint") }} event - [Media queries](/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries) - {{cssxref("@media")}} - [CSS paged media](/en-US/docs/Web/CSS/CSS_paged_media) module
0
data/mdn-content/files/en-us/web/css/css_media_queries
data/mdn-content/files/en-us/web/css/css_media_queries/testing_media_queries/index.md
--- title: Testing media queries programmatically slug: Web/CSS/CSS_media_queries/Testing_media_queries page-type: guide browser-compat: api.MediaQueryList --- {{CSSRef}} The {{Glossary("DOM")}} provides features that can test the results of a {{Glossary("media query")}} programmatically, via the {{domxref("MediaQueryList")}} interface and its methods and properties. Once you've created a `MediaQueryList` object, you can check the result of the [query](/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries) or receive notifications when the result changes. ## Creating a media query list Before you can evaluate the results of a media query, you need to create the {{domxref("MediaQueryList")}} object representing the query. To do this, use the {{domxref("window.matchMedia")}} method. For example, to set up a query list that determines if the device is in landscape or portrait [orientation](/en-US/docs/Web/CSS/@media/orientation): ```js const mediaQueryList = window.matchMedia("(orientation: portrait)"); ``` ## Checking the result of a query Once you've created your media query list, you can check the result of the query by looking at the value of its [`matches`](/en-US/docs/Web/API/MediaQueryList/matches) property: ```js if (mediaQueryList.matches) { /* The viewport is currently in portrait orientation */ } else { /* The viewport is not currently in portrait orientation, therefore landscape */ } ``` ## Receiving query notifications If you need to be aware of changes to the evaluated result of the query on an ongoing basis, it's more efficient to register a [listener](/en-US/docs/Web/API/EventTarget/addEventListener) than to poll the query's result. To do this, call the {{domxref("EventTarget.addEventListener", "addEventListener()")}} method on the {{domxref("MediaQueryList")}} object, with a callback function to invoke when the media query status changes (e.g., the media query test goes from `true` to `false`): ```js // Create the query list. const mediaQueryList = window.matchMedia("(orientation: portrait)"); // Define a callback function for the event listener. function handleOrientationChange(mql) { // … } // Run the orientation change handler once. handleOrientationChange(mediaQueryList); // Add the callback function as a listener to the query list. mediaQueryList.addEventListener("change", handleOrientationChange); ``` This code creates the orientation-testing media query list and adds an event listener to it. After defining the listener, we also call the listener directly. This makes our listener perform adjustments based on the current device orientation; otherwise, our code might assume the device is in portrait mode at startup, even if it's actually in landscape mode. The `handleOrientationChange()` function would look at the result of the query and handle whatever we need to do on an orientation change: ```js function handleOrientationChange(evt) { if (evt.matches) { /* The viewport is currently in portrait orientation */ } else { /* The viewport is currently in landscape orientation */ } } ``` Above, we define the parameter as `evt` — an event object of type {{domxref("MediaQueryListEvent")}} that also includes the {{domxref("MediaQueryListEvent.media","media")}} and {{domxref("MediaQueryListEvent.matches","matches")}} properties, so you can query these features of the `MediaQueryList` by directly accessing it, or accessing the event object. ## Ending query notifications To stop receiving notifications about changes to the value of your media query, call {{domxref("EventTarget.removeEventListener", "removeEventListener()")}} on the `MediaQueryList`, passing it the name of the previously-defined callback function: ```js mediaQueryList.removeEventListener("change", handleOrientationChange); ``` ## Browser compatibility {{Compat}} ## See also - [Media queries](/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries) - [CSS media queries](/en-US/docs/Web/CSS/CSS_media_queries) module - [CSS object model](/en-US/docs/Web/API/CSS_Object_Model) module - {{domxref("window.matchMedia()")}} - {{domxref("MediaQueryList")}} - {{domxref("MediaQueryListEvent")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/columns/index.md
--- title: columns slug: Web/CSS/columns page-type: css-shorthand-property browser-compat: css.properties.columns --- {{CSSRef}} The **`columns`** [CSS](/en-US/docs/Web/CSS) shorthand property sets the number of columns to use when drawing an element's contents, as well as those columns' widths. {{EmbedInteractiveExample("pages/css/columns.html")}} ## Constituent properties This property is a shorthand for the following CSS properties: - [`column-count`](/en-US/docs/Web/CSS/column-count) - [`column-width`](/en-US/docs/Web/CSS/column-width) ## Syntax ```css /* Column width */ columns: 18em; /* Column count */ columns: auto; columns: 2; /* Both column width and count */ columns: 2 auto; columns: auto 12em; columns: auto auto; /* Global values */ columns: inherit; columns: initial; columns: revert; columns: revert-layer; columns: unset; ``` The `columns` property may be specified as one or two of the values listed below, in any order. ### Values - `<'column-width'>` - : The ideal column width, defined as a {{cssxref("&lt;length&gt;")}} or the keyword `auto`. The actual width may be wider or narrower to fit the available space. See {{cssxref("column-width")}}. - `<'column-count'>` - : The ideal number of columns into which the element's content should be flowed, defined as an {{cssxref("&lt;integer&gt;")}} or the keyword `auto`. If neither this value nor the column's width are `auto`, it merely indicates the maximum allowable number of columns. See {{cssxref("column-count")}}. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting three equal columns #### HTML ```html <p class="content-box"> This is a bunch of text split into three columns using the CSS `columns` property. The text is equally distributed over the columns. </p> ``` #### CSS ```css .content-box { columns: 3 auto; } ``` #### Result {{EmbedLiveSample('Setting_three_equal_columns', 'auto', 120)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("widows")}} - {{cssxref("orphans")}} - [Paged media](/en-US/docs/Web/CSS/CSS_paged_media) - [Multiple-column Layout](/en-US/docs/Learn/CSS/CSS_layout/Multiple-column_Layout)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/minmax/index.md
--- title: minmax() slug: Web/CSS/minmax page-type: css-function browser-compat: css.properties.grid-template-columns.minmax --- {{CSSRef}} The **`minmax()`** [CSS function](/en-US/docs/Web/CSS/CSS_Functions) defines a size range greater than or equal to _min_ and less than or equal to _max_. It is used with [CSS Grids](/en-US/docs/Web/CSS/CSS_grid_layout). {{EmbedInteractiveExample("pages/css/function-minmax.html")}} ## Syntax ```css /* <inflexible-breadth>, <track-breadth> values */ minmax(200px, 1fr) minmax(400px, 50%) minmax(30%, 300px) minmax(100px, max-content) minmax(min-content, 400px) minmax(max-content, auto) minmax(auto, 300px) minmax(min-content, auto) /* <fixed-breadth>, <track-breadth> values */ minmax(200px, 1fr) minmax(30%, 300px) minmax(400px, 50%) minmax(50%, min-content) minmax(300px, max-content) minmax(200px, auto) /* <inflexible-breadth>, <fixed-breadth> values */ minmax(400px, 50%) minmax(30%, 300px) minmax(min-content, 200px) minmax(max-content, 200px) minmax(auto, 300px) ``` A function taking two parameters, _min_ and _max_. Each parameter can be a `<length>`, a `<percentage>`, a `<flex>` value, or one of the keyword values `max-content`, `min-content`, or `auto`. If _max_ < _min_, then _max_ is ignored and `minmax(min,max)` is treated as _min_. As a maximum, a {{cssxref("flex_value","&lt;flex&gt;")}} value sets the flex factor of a grid track; it is invalid as a minimum. ### Values - {{cssxref("&lt;length&gt;")}} - : A non-negative length. - {{cssxref("&lt;percentage&gt;")}} - : A non-negative percentage relative to the inline size of the grid container in column grid tracks, and the block size of the grid container in row grid tracks. If the size of the grid container depends on the size of its tracks, then the `<percentage>` must be treated as `auto`. The {{glossary("user agent")}} may adjust the intrinsic size contributions of the track to the size of the grid container and increase the final size of the track by the minimum amount that would result in honoring the percentage. - {{cssxref("&lt;flex&gt;")}} - : A non-negative dimension with the unit `fr` specifying the track's flex factor. Each `<flex>`-sized track takes a share of the remaining space in proportion to its flex factor. - `max-content` - : Represents the largest max-content contribution of the grid items occupying the grid track. - `min-content` - : Represents the largest min-content contribution of the grid items occupying the grid track. - `auto` - : As `min`, it represents the largest minimum size (as specified by {{cssxref("min-width")}}/{{cssxref("min-height")}}) of the grid items occupying the grid track. As `max`, it is identical to `max-content`. However, unlike `max-content`, it allows expansion of the track by the {{cssxref("align-content")}} and {{cssxref("justify-content")}} property values like `normal` and `stretch`. ### Formal syntax {{csssyntax}} ### CSS properties `minmax()` function can be used within: - {{CSSxRef("grid-template-columns")}} - {{CSSxRef("grid-template-rows")}} - {{CSSxRef("grid-auto-columns")}} - {{CSSxRef("grid-auto-rows")}} ## Examples ### CSS ```css #container { display: grid; grid-template-columns: minmax(min-content, 300px) minmax(200px, 1fr) 150px; grid-gap: 5px; box-sizing: border-box; height: 200px; width: 100%; background-color: #8cffa0; padding: 10px; } #container > div { background-color: #8ca0ff; padding: 5px; } ``` ### HTML ```html <div id="container"> <div>Item as wide as the content, but at most 300 pixels.</div> <div>Item with flexible width but a minimum of 200 pixels.</div> <div>Inflexible item of 150 pixels width.</div> </div> ``` ### Result {{EmbedLiveSample("Examples", "100%", 200)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Grid Layout Guide: _[Basic concepts of grid layout - track sizing with minmax()](/en-US/docs/Web/CSS/CSS_grid_layout/Basic_concepts_of_grid_layout#track_sizing_and_minmax)_ - [CSS grids, logical values and writing modes](/en-US/docs/Web/CSS/CSS_grid_layout/Grids_logical_values_and_writing_modes) - Video tutorial: _[Introducing minmax()](https://gridbyexample.com/video/series-minmax/)_
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-top-style/index.md
--- title: border-top-style slug: Web/CSS/border-top-style page-type: css-property browser-compat: css.properties.border-top-style --- {{CSSRef}} The **`border-top-style`** [CSS](/en-US/docs/Web/CSS) property sets the line style of an element's top {{CSSxRef("border")}}. {{EmbedInteractiveExample("pages/css/border-top-style.html")}} > **Note:** The specification doesn't define how borders of different styles connect in the corners. ## Syntax ```css /* Keyword values */ border-top-style: none; border-top-style: hidden; border-top-style: dotted; border-top-style: dashed; border-top-style: solid; border-top-style: double; border-top-style: groove; border-top-style: ridge; border-top-style: inset; border-top-style: outset; /* Global values */ border-top-style: inherit; border-top-style: initial; border-top-style: revert; border-top-style: revert-layer; border-top-style: unset; ``` The `border-top-style` property is specified as a single {{cssxref("line-style")}} keyword value. ## Formal definition {{CSSInfo}} ## Formal syntax {{CSSSyntax}} ## Examples ### Setting border-top-style #### HTML ```html <table> <tr> <td class="b1">none</td> <td class="b2">hidden</td> <td class="b3">dotted</td> <td class="b4">dashed</td> </tr> <tr> <td class="b5">solid</td> <td class="b6">double</td> <td class="b7">groove</td> <td class="b8">ridge</td> </tr> <tr> <td class="b9">inset</td> <td class="b10">outset</td> </tr> </table> ``` #### CSS ```css /* Define look of the table */ table { border-width: 2px; background-color: #52e385; } tr, td { padding: 3px; } /* border-top-style example classes */ .b1 { border-top-style: none; } .b2 { border-top-style: hidden; } .b3 { border-top-style: dotted; } .b4 { border-top-style: dashed; } .b5 { border-top-style: solid; } .b6 { border-top-style: double; } .b7 { border-top-style: groove; } .b8 { border-top-style: ridge; } .b9 { border-top-style: inset; } .b10 { border-top-style: outset; } ``` #### Result {{EmbedLiveSample('Examples', 300, 200)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - The other style-related border properties: {{CSSxRef("border-left-style")}}, {{CSSxRef("border-right-style")}}, {{CSSxRef("border-bottom-style")}}, and {{CSSxRef("border-style")}}. - The other top-border-related properties: {{CSSxRef("border-top")}}, {{CSSxRef("border-top-color")}}, and {{CSSxRef("border-top-width")}}.
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/max-block-size/index.md
--- title: max-block-size slug: Web/CSS/max-block-size page-type: css-property browser-compat: css.properties.max-block-size --- {{CSSRef}} The **`max-block-size`** [CSS](/en-US/docs/Web/CSS) property specifies the maximum size of an element in the direction opposite that of the writing direction as specified by {{cssxref("writing-mode")}}. That is, if the writing direction is horizontal, then `max-block-size` is equivalent to {{cssxref("max-height")}}; if the writing direction is vertical, `max-block-size` is the same as {{cssxref("max-width")}}. The other dimension's maximum length is specified using the {{cssxref("max-inline-size")}} property. This is useful because the `max-width` is always used for horizontal sizes and `max-height` is always used for vertical sizes, and if you need to set lengths based on the size of your text content, you need to be able to do so with the writing direction in mind. Any time you would normally use `max-height` or `max-width`, you should instead use `max-block-size` to set the maximum "height" of the content (even though this may not be a vertical value) and `max-inline-size` to set the maximum "width" of the content (although this may instead be vertical rather than horizontal). See [`writing-mode` examples](/en-US/docs/Web/CSS/writing-mode#examples), which show the different writing modes in action. {{EmbedInteractiveExample("pages/css/max-block-size.html")}} ## Syntax ```css /* <length> values */ max-block-size: 300px; max-block-size: 25em; /* <percentage> values */ max-block-size: 75%; /* Keyword values */ max-block-size: none; max-block-size: max-content; max-block-size: min-content; max-block-size: fit-content; max-block-size: fit-content(20em); /* Global values */ max-block-size: inherit; max-block-size: initial; max-block-size: revert; max-block-size: revert-layer; max-block-size: unset; ``` ### Values The `max-block-size` property's value can be any value that's legal for the {{cssxref("max-width")}} and {{cssxref("max-height")}} properties: - {{cssxref("&lt;length&gt;")}} - : Defines the `max-block-size` as an absolute value. - {{cssxref("&lt;percentage&gt;")}} - : Defines the `max-block-size` as a percentage of the containing block's size in block axis. - `none` - : No limit on the size of the box. - `max-content` - : The intrinsic preferred `max-block-size`. - `min-content` - : The intrinsic minimum `max-block-size`. - `fit-content` - : Use the available space, but not more than [max-content](/en-US/docs/Web/CSS/max-content), i.e `min(max-content, max(min-content, stretch))`. - `fit-content({{cssxref("&lt;length-percentage&gt;")}})` {{Experimental_Inline}} - : Uses the `fit-content` formula with the available space replaced by the specified argument, i.e. `min(max-content, max(min-content, argument))`. ### How writing-mode affects directionality The values of `writing-mode` affect the mapping of `max-block-size` to `max-width` or `max-height` as follows: | Values of `writing-mode` | `max-block-size` is equivalent to | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | | `horizontal-tb`, `lr` {{deprecated_inline}}, `lr-tb` {{deprecated_inline}}, `rl` {{deprecated_inline}}, `rb` {{deprecated_inline}}, `rb-rl` {{deprecated_inline}} | {{cssxref("max-height")}} | | `vertical-rl`, `vertical-lr`, `sideways-rl` {{experimental_inline}}, `sideways-lr` {{experimental_inline}}, `tb` {{deprecated_inline}}, `tb-rl` {{deprecated_inline}} | {{cssxref("max-width")}} | > **Note:** The `writing-mode` values `sideways-lr` and `sideways-rl` were removed from the CSS Writing Modes Level 3 specification late in its design process. They may be restored in Level 4. > **Note:** The writing modes `lr`, `lr-tb`, `rl`, `rb`, and `rb-tl` are no longer allowed in {{Glossary("HTML")}} contexts; they may only be used in {{Glossary("SVG")}} 1.x contexts. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting max-block-size with horizontal and vertical text In this example, the same text (the opening sentences from [Herman Melville's](https://en.wikipedia.org/wiki/Herman_Melville) novel _[Moby-Dick](https://en.wikipedia.org/wiki/Moby-Dick)_) is presented in both the `horizontal-tb` and `vertical-rl` writing modes. Everything else about the two boxes is identical, including the values used for {{cssxref("max-block-size")}}. #### HTML The HTML establishes the two {{HTMLElement("div")}} blocks that will be presented with their {{cssxref("writing-mode")}} set using the classes `horizontal` or `vertical`. Both boxes share the `standard-box` class, which establishes coloring, padding, and their respective values of `max-block-size`. ```html <p>Writing mode <code>horizontal-tb</code> (the default):</p> <div class="standard-box horizontal"> Call me Ishmael. Some years ago—never mind how long precisely—having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation. </div> <p>Writing mode <code>vertical-rl</code>:</p> <div class="standard-box vertical"> Call me Ishmael. Some years ago—never mind how long precisely—having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation. </div> ``` #### CSS The CSS defines three classes. The first, `standard-box`, is applied to both boxes, as seen above. It provides standard styling including the minimum and maximum block sizes, font size, and so forth. After that come the classes `horizontal` and `vertical`, which add the {{cssxref("writing-mode")}} property to the box, with the value set to `horizontal-tb` or `vertical-rl` depending on which class is used. ```css .standard-box { padding: 4px; background-color: #abcdef; color: #000; font: 16px "Open Sans", "Helvetica", "Arial", sans-serif; max-block-size: 160px; min-block-size: 100px; } .horizontal { writing-mode: horizontal-tb; } .vertical { writing-mode: vertical-rl; } ``` #### Result {{EmbedLiveSample("Setting_max-block-size_with_horizontal_and_vertical_text", 600, 850)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - The mapped physical properties: {{cssxref("max-width")}} and {{cssxref("max-height")}} - Setting the other direction's maximum size: {{cssxref("max-inline-size")}} - {{cssxref("writing-mode")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/transform-box/index.md
--- title: transform-box slug: Web/CSS/transform-box page-type: css-property browser-compat: css.properties.transform-box --- {{CSSRef}} The **`transform-box`** CSS property defines the layout box to which the {{cssxref("transform")}}, individual transform properties {{cssxref("translate")}},{{cssxref("scale")}}, and {{cssxref("rotate")}}, and {{cssxref("transform-origin")}} properties relate. ## Syntax ```css /* Keyword values */ transform-box: content-box; transform-box: border-box; transform-box: fill-box; transform-box: stroke-box; transform-box: view-box; /* Global values */ transform-box: inherit; transform-box: initial; transform-box: revert; transform-box: revert-layer; transform-box: unset; ``` The `transform-box` property is specified as one of the keyword values listed below. ### Values - `content-box` - : The content box is used as the reference box. The reference box of a {{htmlElement("table")}} is the border box of its [table wrapper box](/en-US/docs/Glossary/Table_Wrapper_Box), not its table box. - `border-box` - : The border box is used as the reference box. The reference box of a {{htmlElement("table")}} is the border box of its [table wrapper box](/en-US/docs/Glossary/Table_Wrapper_Box), not its table box. - `fill-box` - : The object bounding box is used as the reference box. For elements with associated CSS layout box, acts as `content-box`. - `stroke-box` - : The stroke bounding box is used as the reference box. For elements with associated CSS layout box, acts as `border-box`. - `view-box` - : The nearest {{Glossary("SVG")}} viewport is used as the reference box. If a {{SVGAttr("viewBox")}} attribute is specified for the SVG viewport creating element, the reference box is positioned at the origin of the coordinate system established by the `viewBox` attribute, and the dimension of the reference box is set to the width and height values of the `viewBox` attribute. For elements with associated CSS layout box, acts as `border-box`. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### SVG transform-origin scoping In this example we have an SVG: ```html <svg id="svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50"> <g> <circle id="center" fill="red" r="1" transform="translate(25 25)" /> <circle id="boxcenter" fill="blue" r=".5" transform="translate(15 15)" /> <rect id="box" x="10" y="10" width="10" height="10" rx="1" ry="1" stroke="black" fill="none" /> </g> </svg> ``` In the CSS we have an animation that uses a transform to rotate the rectangle infinitely. `transform-box: fill-box` is used to make the `transform-origin` the center of the bounding box, so the rectangle spins in place. Without it, the transform origin is the center of the SVG canvas, and so you get a very different effect. ```css svg { width: 80vh; border: 1px solid #d9d9d9; position: absolute; margin: auto; top: 0; right: 0; bottom: 0; left: 0; } #box { transform-origin: 50% 50%; /* anything other than `0 0` to see the effect */ transform-box: fill-box; animation: rotateBox 3s linear infinite; } @keyframes rotateBox { to { transform: rotate(360deg); } } ``` Full credit for this example goes to [Pogany](https://codepen.io/giaco); see [this codepen](https://codepen.io/giaco/pen/OwowJQ) for a live version. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Using CSS transforms](/en-US/docs/Web/CSS/CSS_transforms/Using_CSS_transforms) - {{cssxref("transform")}}, {{cssxref("transform-origin")}} - Individual transform properties: - {{cssxref("translate")}} - {{cssxref("scale")}} - {{cssxref("rotate")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/-webkit-mask-repeat-x/index.md
--- title: "-webkit-mask-repeat-x" slug: Web/CSS/-webkit-mask-repeat-x page-type: css-property status: - non-standard browser-compat: css.properties.-webkit-mask-repeat-x --- {{CSSRef}}{{Non-standard_header}} The `-webkit-mask-repeat-x` property specifies whether and how a mask image is repeated (tiled) horizontally. ## Syntax ```css /* Keyword values */ -webkit-mask-repeat-x: repeat; -webkit-mask-repeat-x: no-repeat; -webkit-mask-repeat-x: space; -webkit-mask-repeat-x: round; /* Multiple values */ -webkit-mask-repeat-x: repeat, no-repeat, space; /* Global values */ -webkit-mask-repeat-x: inherit; -webkit-mask-repeat-x: initial; -webkit-mask-repeat-x: revert; -webkit-mask-repeat-x: revert-layer; -webkit-mask-repeat-x: unset; ``` ### Values - repeat - : The mask image is repeated both horizontally and vertically. - no-repeat - : The mask image is not repeated; only one copy of the mask image is drawn. The remainder of the masked element's content is not displayed. - repeat - : The mask image is repeated both horizontally and vertically. - space - : The image is repeated as much as possible without clipping. The first and last images are pinned to either side of the element, and whitespace is distributed evenly between the images. The {{cssxref("mask-position")}} property is ignored unless only one image can be displayed without clipping. The only case where clipping happens using space is when there isn't enough room to display one image. - round - : As the allowed space increases in size, the repeated images will stretch (leaving no gaps) until there is room for another one to be added. When the next image is added, all of the current ones compress to allow room. Example: An image with an original width of 260px, repeated three times, might stretch until each repetition is 300px wide, and then another image will be added. They will then compress to 225px. ## Formal definition {{CSSInfo}} ## Formal syntax ```plain -webkit-mask-repeat-x = repeat | no-repeat | space | round ``` ## Examples ### Using a repeating or non-repeating mask image ```css .exampleone { -webkit-mask-image: url("mask.png"); -webkit-mask-repeat-x: repeat; } .exampletwo { -webkit-mask-image: url("mask.png"); -webkit-mask-repeat-x: no-repeat; } ``` ### Using multiple mask images You can specify a different `<repeat-style>` for each mask image, separated by commas: ```css .examplethree { -webkit-mask-image: url("mask1.png"), url("mask2.png"); -webkit-mask-repeat-x: repeat, space; } ``` Each image is matched with the corresponding repeat style, from first specified to last. ## Specifications Not part of any standard. ## Browser compatibility {{Compat}} ## See also {{cssxref("mask-repeat", "-webkit-mask-repeat")}}, {{cssxref("-webkit-mask-repeat-y")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/grid/index.md
--- title: grid slug: Web/CSS/grid page-type: css-shorthand-property browser-compat: css.properties.grid --- {{CSSRef}} The **`grid`** CSS property is a [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) that sets all of the explicit and implicit grid properties in a single declaration. Using `grid` you specify one axis using {{cssxref("grid-template-rows")}} or {{cssxref("grid-template-columns")}}, you then specify how content should auto-repeat in the other axis using the implicit grid properties: {{cssxref("grid-auto-rows")}}, {{cssxref("grid-auto-columns")}}, and {{cssxref("grid-auto-flow")}}. {{EmbedInteractiveExample("pages/css/grid.html")}} > **Note:** The sub-properties you don't specify are set to their initial value, as normal for shorthands. Also, the gutter properties are NOT reset by this shorthand. ## Constituent properties This property is a shorthand for the following CSS properties: - [`grid-auto-columns`](/en-US/docs/Web/CSS/grid-auto-columns) - [`grid-auto-flow`](/en-US/docs/Web/CSS/grid-auto-flow) - [`grid-auto-rows`](/en-US/docs/Web/CSS/grid-auto-rows) - [`grid-template-areas`](/en-US/docs/Web/CSS/grid-template-areas) - [`grid-template-columns`](/en-US/docs/Web/CSS/grid-template-columns) - [`grid-template-rows`](/en-US/docs/Web/CSS/grid-template-rows) ## Syntax ```css /* <'grid-template'> values */ grid: none; grid: "a" 100px "b" 1fr; grid: [linename1] "a" 100px [linename2]; grid: "a" 200px "b" min-content; grid: "a" minmax(100px, max-content) "b" 20%; grid: 100px / 200px; grid: minmax(400px, min-content) / repeat(auto-fill, 50px); /* <'grid-template-rows'> / [ auto-flow && dense? ] <'grid-auto-columns'>? values */ grid: 200px / auto-flow; grid: 30% / auto-flow dense; grid: repeat(3, [line1 line2 line3] 200px) / auto-flow 300px; grid: [line1] minmax(20em, max-content) / auto-flow dense 40%; /* [ auto-flow && dense? ] <'grid-auto-rows'>? / <'grid-template-columns'> values */ grid: auto-flow / 200px; grid: auto-flow dense / 30%; grid: auto-flow 300px / repeat(3, [line1 line2 line3] 200px); grid: auto-flow dense 40% / [line1] minmax(20em, max-content); /* Global values */ grid: inherit; grid: initial; grid: revert; grid: revert-layer; grid: unset; ``` ### Values - `<'grid-template'>` - : Defines the {{cssxref("grid-template")}} including {{cssxref("grid-template-columns")}}, {{cssxref("grid-template-rows")}} and {{cssxref("grid-template-areas")}}. - `<'grid-template-rows'> / [ auto-flow && dense? ] <'grid-auto-columns'>?` - : Sets up an auto-flow by setting the row tracks explicitly via the {{cssxref("grid-template-rows")}} property (and the {{cssxref("grid-template-columns")}} property to `none`) and specifying how to auto-repeat the column tracks via {{cssxref("grid-auto-columns")}} (and setting {{cssxref("grid-auto-rows")}} to `auto`). {{cssxref("grid-auto-flow")}} is also set to `column` accordingly, with `dense` if it's specified. All other `grid` sub-properties are reset to their initial values. - `[ auto-flow && dense? ] <'grid-auto-rows'>? / <'grid-template-columns'>` - : Sets up an auto-flow by setting the column tracks explicitly via the {{cssxref("grid-template-columns")}} property (and the {{cssxref("grid-template-rows")}} property to `none`) and specifying how to auto-repeat the row tracks via {{cssxref("grid-auto-rows")}} (and setting {{cssxref("grid-auto-columns")}} to `auto`). {{cssxref("grid-auto-flow")}} is also set to `row` accordingly, with `dense` if it's specified. All other `grid` sub-properties are reset to their initial values. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Creating a grid layout #### HTML ```html <div id="container"> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> </div> ``` #### CSS ```css #container { display: grid; grid: repeat(2, 60px) / auto-flow 80px; } #container > div { background-color: #8ca0ff; width: 50px; height: 50px; } ``` #### Result {{EmbedLiveSample("Creating_a_grid_layout", "100%", 150)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Related CSS properties: {{cssxref("grid-template")}}, {{cssxref("grid-template-rows")}}, {{cssxref("grid-template-columns")}}, {{cssxref("grid-template-areas")}}, {{cssxref("grid-auto-columns")}}, {{cssxref("grid-auto-rows")}}, {{cssxref("grid-auto-flow")}} - Grid Layout Guide: _[Line-based placement with CSS Grid](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_layout_using_line-based_placement)_ - Grid Layout Guide: _[Grid template areas - Grid definition shorthands](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_template_areas#grid_definition_shorthands)_
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-inline-color/index.md
--- title: border-inline-color slug: Web/CSS/border-inline-color page-type: css-property browser-compat: css.properties.border-inline-color --- {{CSSRef}} The **`border-inline-color`** [CSS](/en-US/docs/Web/CSS) property defines the color of the logical inline borders of an element, which maps to a physical border color depending on the element's writing mode, directionality, and text orientation. It corresponds to the {{cssxref("border-top-color")}} and {{cssxref("border-bottom-color")}}, or {{cssxref("border-right-color")}} and {{cssxref("border-left-color")}} property depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. {{EmbedInteractiveExample("pages/css/border-inline-color.html")}} The border color in the other dimension can be set with {{cssxref("border-block-color")}} which sets {{cssxref("border-block-start-color")}}, and {{cssxref("border-block-end-color")}}. ## Syntax ```css border-inline-color: yellow; border-inline-color: #f5f6f7; /* Global values */ border-inline-color: inherit; border-inline-color: initial; border-inline-color: revert; border-inline-color: revert-layer; border-inline-color: unset; ``` ### Values - {{CSSXref("&lt;color&gt;")}} - : The color of the border. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Border color with vertical text #### HTML ```html <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ```css div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; border: 10px solid blue; border-inline-color: red; } ``` #### Results {{EmbedLiveSample("Border_color_with_vertical_text", 140, 140)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS Logical Properties and Values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values) - This property maps to the physical border properties: {{cssxref("border-top-color")}}, {{cssxref("border-right-color")}}, {{cssxref("border-bottom-color")}}, or {{cssxref("border-left-color")}}. - {{cssxref("writing-mode")}}, {{cssxref("direction")}}, {{cssxref("text-orientation")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_optional/index.md
--- title: ":optional" slug: Web/CSS/:optional page-type: css-pseudo-class browser-compat: css.selectors.optional --- {{CSSRef}} The **`:optional`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents any {{HTMLElement("input")}}, {{HTMLElement("select")}}, or {{HTMLElement("textarea")}} element that does not have the [`required`](/en-US/docs/Web/HTML/Element/input#required) attribute set on it. {{EmbedInteractiveExample("pages/tabbed/pseudo-class-optional.html", "tabbed-standard")}} This pseudo-class is useful for styling fields that are not required to submit a form. > **Note:** The {{cssxref(":required")}} pseudo-class selects _required_ form fields. ## Syntax ```css :optional { /* ... */ } ``` ## Examples ### The optional field has a purple border #### HTML ```html <form> <div class="field"> <label for="url_input">Enter a URL:</label> <input type="url" id="url_input" /> </div> <div class="field"> <label for="email_input">Enter an email address:</label> <input type="email" id="email_input" required /> </div> </form> ``` #### CSS ```css label { display: block; margin: 1px; padding: 1px; } .field { margin: 1px; padding: 1px; } input:optional { border-color: rebeccapurple; border-width: 3px; } ``` #### Result {{EmbedLiveSample('Examples', 600, 120)}} ## Accessibility concerns If a [form](/en-US/docs/Web/HTML/Element/form) contains optional {{htmlelement("input")}}s, required inputs should be indicated using the [`required`](/en-US/docs/Web/HTML/Element/input#required) attribute. This will ensure that people navigating with the aid of assistive technology such as a screen reader will be able to understand which inputs need valid content to ensure a successful form submission. Required inputs should also be indicated visually, using a treatment that does not rely solely on color to convey meaning. Typically, descriptive text and/or an icon are used. - [MDN Understanding WCAG, Guideline 3.3 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Understandable#guideline_3.3_%e2%80%94_input_assistance_help_users_avoid_and_correct_mistakes) - [Understanding Success Criterion 3.3.2 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/minimize-error-cues.html) ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Other validation-related pseudo-classes: {{ cssxref(":required") }}, {{ cssxref(":invalid") }}, {{ cssxref(":valid") }} - [Form data validation](/en-US/docs/Learn/Forms/Form_validation)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-bottom-color/index.md
--- title: border-bottom-color slug: Web/CSS/border-bottom-color page-type: css-property browser-compat: css.properties.border-bottom-color --- {{CSSRef}} The **`border-bottom-color`** CSS property sets the color of an element's bottom [border](/en-US/docs/Web/CSS/border). It can also be set with the shorthand CSS properties {{cssxref("border-color")}} or {{cssxref("border-bottom")}}. {{EmbedInteractiveExample("pages/css/border-bottom-color.html")}} ## Syntax ```css /* <color> values */ border-bottom-color: red; border-bottom-color: #ffbb00; border-bottom-color: rgb(255 0 0); border-bottom-color: hsl(100deg 50% 25% / 75%); border-bottom-color: currentcolor; border-bottom-color: transparent; /* Global values */ border-bottom-color: inherit; border-bottom-color: initial; border-bottom-color: revert; border-bottom-color: revert-layer; border-bottom-color: unset; ``` The `border-bottom-color` property is specified as a single value. ### Values - {{cssxref("&lt;color&gt;")}} - : The color of the bottom border. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### A simple div with a border #### HTML ```html <div class="mybox"> <p> This is a box with a border around it. Note which side of the box is <span class="redtext">red</span>. </p> </div> ``` #### CSS ```css .mybox { border: solid 0.3em gold; border-bottom-color: red; width: auto; } .redtext { color: red; } ``` #### Result {{EmbedLiveSample('A_simple_div_with_a_border')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - The border-related CSS shorthand properties: {{Cssxref("border")}}, {{Cssxref("border-bottom")}}, and {{Cssxref("border-color")}}. - The color-related CSS properties for the other borders: {{Cssxref("border-right-color")}}, {{Cssxref("border-top-color")}}, and {{Cssxref("border-left-color")}}. - The other border-related CSS properties applying to the same border: {{cssxref("border-bottom-style")}} and {{cssxref("border-bottom-width")}}. - The default [`currentcolor`](/en-US/docs/Web/CSS/color_value#currentcolor_keyword) color value.
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/padding-inline/index.md
--- title: padding-inline slug: Web/CSS/padding-inline page-type: css-shorthand-property browser-compat: css.properties.padding-inline --- {{CSSRef}} The **`padding-inline`** [CSS](/en-US/docs/Web/CSS) [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) defines the logical inline start and end padding of an element, which maps to physical padding properties depending on the element's writing mode, directionality, and text orientation. {{EmbedInteractiveExample("pages/css/padding-inline.html")}} ## Constituent properties This property is a shorthand for the following CSS properties: - [`padding-inline-end`](/en-US/docs/Web/CSS/padding-inline-end) - [`padding-inline-start`](/en-US/docs/Web/CSS/padding-inline-start) ## Syntax ```css /* <length> values */ padding-inline: 10px 20px; /* An absolute length */ padding-inline: 1em 2em; /* relative to the text size */ padding-inline: 10px; /* sets both start and end values */ /* <percentage> values */ padding-inline: 5% 2%; /* relative to the nearest block container's width */ /* Global values */ padding-inline: inherit; padding-inline: initial; padding-inline: revert; padding-inline: revert-layer; padding-inline: unset; ``` The `padding-inline` property may be specified with one or two values. If one value is given, it is used as the value for both {{cssxref("padding-inline-start")}} and {{cssxref("padding-inline-end")}}. If two values are given, the first is used for {{cssxref("padding-inline-start")}} and the second for {{cssxref("padding-inline-end")}}. ### Values - {{cssxref("&lt;length&gt;")}} - : The size of the padding as a fixed value. Must be nonnegative. - {{cssxref("&lt;percentage&gt;")}} - : The size of the padding as a percentage, relative to the inline size (_width_ in a horizontal language, defined by {{cssxref("writing-mode")}}) of the [containing block](/en-US/docs/Web/CSS/Containing_block). Must be nonnegative. ## Description Values for this property correspond to the {{cssxref("padding-top")}} and {{cssxref("padding-bottom")}}, or {{cssxref("padding-right")}}, and {{cssxref("padding-left")}} property depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting inline padding for vertical text #### HTML ```html <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ```css div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-rl; padding-inline: 20px 40px; background-color: #c8c800; } ``` #### Result {{EmbedLiveSample("Setting_inline_padding_for_vertical_text", 140, 140)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS Logical Properties and Values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values) - The mapped physical properties: {{cssxref("padding-top")}}, {{cssxref("padding-right")}}, {{cssxref("padding-bottom")}}, and {{cssxref("padding-left")}} - {{cssxref("writing-mode")}}, {{cssxref("direction")}}, {{cssxref("text-orientation")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/generic-family/index.md
--- title: <generic-family> slug: Web/CSS/generic-family page-type: css-type spec-urls: https://drafts.csswg.org/css-fonts/#generic-font-families --- {{CSSRef}} The **`<generic-family>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) represents the keyword values for generic font families used in the {{cssxref("font")}} shorthand and {{cssxref("font-family")}} longhand properties. The `<generic-family>` represents one or more locally-installed fonts belonging to that category of fonts. ## Syntax ```css <generic-family> = serif | sans-serif | monospace | cursive | fantasy | system-ui | ui-serif | ui-sans-serif | ui-monospace | ui-rounded | emoji | math | fangsong ``` ## Values The `<generic-family>` {{glossary("enumerated")}} type is specified using one of the values listed below: - `serif` - : A serif is a small line or stroke attached to the end of a larger stroke in a letter. In serif fonts, glyphs have finishing strokes, flared or tapering ends. Examples include Lucida Bright, Lucida Fax, Palatino, Palatino Linotype, Palladio, and URW Palladio. - `sans-serif` - : A font without serifs; glyphs have plain stroke endings, without ornamentation. Example sans-serif fonts include Open Sans, Fira Sans, Lucida Sans, Lucida Sans Unicode, Trebuchet MS, Liberation Sans, and Nimbus Sans L. - `monospace` - : All glyphs have the same fixed width. Example monospace fonts include Fira Mono, DejaVu Sans Mono, Menlo, Consolas, Liberation Mono, Monaco, and Lucida Console. - `cursive` - : Glyphs in cursive fonts generally have either joining strokes or other cursive characteristics beyond those of italic typefaces. The glyphs are partially or completely connected, and the result looks more like handwritten pen or brush writing than printed letter work. Example cursive fonts include Brush Script MT, Brush Script Std, Lucida Calligraphy, Lucida Handwriting, and Apple Chancery. - `fantasy` - : Fantasy fonts are primarily decorative fonts that contain playful representations of characters. Example fantasy fonts include Papyrus, Herculanum, Party LET, Curlz MT, and Harrington. - `system-ui` - : Glyphs are taken from the default user interface font on a given platform. Because typographic traditions vary widely across the world, this generic family is provided for typefaces that don't map cleanly into the others. - `ui-serif` - : The default user interface serif font. See the definition of `serif` above. - `ui-sans-serif` - : The default user interface sans-serif font. See the definition of `sans-serif` above. - `ui-monospace` - : The default user interface monospace font. See the definition of `monospace` above. - `ui-rounded` - : The default user interface font that has rounded features. - `math` - : Fonts for displaying mathematical expressions, for example superscript and subscript, brackets that cross several lines, nesting expressions, and double-struck glyphs with distinct meanings. - `emoji` - : Fonts that are specifically designed to render emoji. - `fangsong` - : A particular style of Chinese characters that are between serif-style Song and cursive-style Kai forms. This style is often used for government documents. ## Examples This example demos several of the `<generic-family>` enumerated values for the {{cssxref("font-family")}} property. ### HTML ```html <ul> <li class="serif">serif</li> <li class="sans-serif">sans-serif</li> <li class="monospace">monospace</li> <li class="cursive">cursive</li> <li class="fantasy">fantasy</li> <li class="system-ui">system-ui</li> </ul> ``` ### CSS ```css ul { font-size: 1.5rem; line-height: 2; } .serif { font-family: serif; } .sans-serif { font-family: sans-serif; } .monospace { font-family: monospace; } .cursive { font-family: cursive; } .fantasy { font-family: fantasy; } .system-ui { font-family: system-ui; } ``` ### Result {{EmbedLiveSample("Examples", "500", "355")}} ## Specifications {{Specifications}} ## See also - Properties that use this data type: {{cssxref("font-family")}} and {{cssxref("font")}} - [CSS fonts module](/en-US/docs/Web/CSS/CSS_fonts)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/transition-duration/index.md
--- title: transition-duration slug: Web/CSS/transition-duration page-type: css-property browser-compat: css.properties.transition-duration --- {{CSSRef}} The **`transition-duration`** [CSS](/en-US/docs/Web/CSS) property sets the length of time a transition animation should take to complete. By default, the value is `0s`, meaning that no animation will occur. {{EmbedInteractiveExample("pages/css/transition-duration.html")}} You may specify multiple durations; each duration will be applied to the corresponding property as specified by the {{ cssxref("transition-property") }} property, which acts as a master list. If the number of specified durations is less than in the master list, the user agent repeats the list of durations. If the number of specified durations is more than in the master list, the list is truncated to the right size. In both the cases, the CSS declaration stays valid. ## Syntax ```css /* <time> values */ transition-duration: 6s; transition-duration: 120ms; transition-duration: 1s, 15s; transition-duration: 10s, 30s, 230ms; /* Global values */ transition-duration: inherit; transition-duration: initial; transition-duration: revert; transition-duration: revert-layer; transition-duration: unset; ``` ### Values - `<time>` - : Is a {{cssxref("&lt;time&gt;")}} denoting the amount of time the transition from the old value of a property to the new value should take. A time of `0s` indicates that no transition will happen, that is the switch between the two states will be instantaneous. A negative value for the time renders the declaration invalid. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Example showing different durations #### HTML ```html <div class="box duration-1">0.5 seconds</div> <div class="box duration-2">2 seconds</div> <div class="box duration-3">4 seconds</div> <button id="change">Change</button> ``` #### CSS ```css .box { margin: 20px; padding: 10px; display: inline-block; width: 100px; height: 100px; background-color: red; font-size: 18px; transition-property: background-color, font-size, transform, color; transition-timing-function: ease-in-out; } .transformed-state { transform: rotate(270deg); background-color: blue; color: yellow; font-size: 12px; transition-property: background-color, font-size, transform, color; transition-timing-function: ease-in-out; } .duration-1 { transition-duration: 0.5s; } .duration-2 { transition-duration: 2s; } .duration-3 { transition-duration: 4s; } ``` #### JavaScript ```js function change() { const elements = document.querySelectorAll("div.box"); for (const element of elements) { element.classList.toggle("transformed-state"); } } const changeButton = document.querySelector("#change"); changeButton.addEventListener("click", change); ``` #### Result {{EmbedLiveSample("Example_showing_different_durations",275,200)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Using CSS transitions](/en-US/docs/Web/CSS/CSS_transitions/Using_CSS_transitions) - {{cssxref('transition')}} - {{cssxref('transition-property')}} - {{cssxref('transition-timing-function')}} - {{cssxref('transition-delay')}} - {{domxref("TransitionEvent")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/background-image/index.md
--- title: background-image slug: Web/CSS/background-image page-type: css-property browser-compat: css.properties.background-image --- {{CSSRef}} The **`background-image`** [CSS](/en-US/docs/Web/CSS) property sets one or more background images on an element. {{EmbedInteractiveExample("pages/css/background-image.html")}} The background images are drawn on stacking context layers on top of each other. The first layer specified is drawn as if it is closest to the user. The [borders](/en-US/docs/Web/CSS/border) of the element are then drawn on top of them, and the {{cssxref("background-color")}} is drawn beneath them. How the images are drawn relative to the box and its borders is defined by the {{cssxref("background-clip")}} and {{cssxref("background-origin")}} CSS properties. If a specified image cannot be drawn (for example, when the file denoted by the specified URI cannot be loaded), browsers handle it as they would a `none` value. > **Note:** Even if the images are opaque and the color won't be displayed in normal circumstances, web developers should always specify a {{cssxref("background-color")}}. If the images cannot be loaded—for instance, when the network is down—the background color will be used as a fallback. ## Syntax ```css background-image: linear-gradient( to bottom, rgb(255 255 0 / 50%), rgb(0 0 255 / 50%) ), url("catfront.png"); /* Global values */ background-image: inherit; background-image: initial; background-image: revert; background-image: revert-layer; background-image: unset; ``` Each background image is specified either as the keyword `none` or as an {{cssxref("&lt;image&gt;")}} value. To specify multiple background images, supply multiple values, separated by a comma. ### Values - `none` - : Is a keyword denoting the absence of images. - `<image>` - : Is an {{cssxref("&lt;image&gt;")}} denoting the image to display. There can be several of them, separated by commas, as [multiple backgrounds](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders/Using_multiple_backgrounds) are supported. ## Accessibility concerns Browsers do not provide any special information on background images to assistive technology. This is important primarily for screen readers, as a screen reader will not announce its presence and therefore convey nothing to its users. If the image contains information critical to understanding the page's overall purpose, it is better to describe it semantically in the document. - [MDN Understanding WCAG, Guideline 1.1 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.1_—_providing_text_alternatives_for_non-text_content) - [Understanding Success Criterion 1.1.1 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/2016/NOTE-UNDERSTANDING-WCAG20-20161007/text-equiv-all.html) ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Layering background images Note that the star image is partially transparent and is layered over the cat image. #### HTML ```html <div> <p class="catsandstars">This paragraph is full of cats<br />and stars.</p> <p>This paragraph is not.</p> <p class="catsandstars">Here are more cats for you.<br />Look at them!</p> <p>And no more.</p> </div> ``` #### CSS ```css p { font-size: 1.5em; color: #fe7f88; background-image: none; background-color: transparent; } div { background-image: url("mdn_logo_only_color.png"); } .catsandstars { background-image: url("startransparent.gif"), url("catfront.png"); background-color: transparent; } ``` #### Result {{EmbedLiveSample('Layering_background_images')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Implementing image sprites in CSS](/en-US/docs/Web/CSS/CSS_images/Implementing_image_sprites_in_CSS) - {{HTMLElement("img")}} - Image-related data types: {{cssxref("&lt;image&gt;")}}, {{cssxref("&lt;gradient&gt;")}} - Image-related functions: - {{cssxref("cross-fade", "cross-fade()")}} - {{cssxref("element", "element()")}} - {{cssxref("image/image", "image()")}} - {{cssxref("image/image-set", "image-set()")}} - {{cssxref("gradient/linear-gradient", "linear-gradient()")}} - {{cssxref("gradient/radial-gradient", "radial-gradient()")}} - {{cssxref("gradient/conic-gradient", "conic-gradient()")}} - {{cssxref("gradient/repeating-linear-gradient", "repeating-linear-gradient()")}} - {{cssxref("gradient/repeating-radial-gradient", "repeating-radial-gradient()")}} - {{cssxref("gradient/repeating-conic-gradient", "repeating-conic-gradient()")}} - {{cssxref("image/paint", "paint()")}} - {{cssxref("url", "url()")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/@counter-style/index.md
--- title: "@counter-style" slug: Web/CSS/@counter-style page-type: css-at-rule browser-compat: css.at-rules.counter-style --- {{CSSRef}} The **`@counter-style`** [CSS](/en-US/docs/Web/CSS) [at-rule](/en-US/docs/Web/CSS/At-rule) lets you extend predefined list styles and define your own counter styles that are not part of the predefined set of styles. The `@counter-style` rule contains [descriptors](#descriptors) defining how the counter value is converted into a string representation. ```css @counter-style thumbs { system: cyclic; symbols: "\1F44D"; suffix: " "; } ul { list-style: thumbs; } ``` While CSS provides many useful predefined counter styles, the `@counter-style` at-rule offers an open-ended method for creating counters. This at-rule caters to the needs of worldwide typography by allowing authors to define their own counter styles when the predefined styles don't fit their requirements. ## Syntax The `@counter-style` at-rule is identified by a [counter style name](#counter_style_name), and the style of the named counter can be fine-tuned using a `<declaration-list>` consisting of one or more [descriptors](#descriptors) and their values. ### Counter style name - `<counter-style-name>` - : Provides a name for your counter style. It is specified as a case-sensitive {{cssxref("custom-ident")}} without quotes. The value should not be equal to `none`. Like all custom identifiers, the value of your counter style can't be a [CSS-wide keyword](/en-US/docs/Web/CSS/CSS_Types#css-wide_keywords). Avoid other enumerated CSS property values, including values of [list](/en-US/docs/Web/CSS/CSS_lists#properties) and [counter style](/en-US/docs/Web/CSS/CSS_counter_styles#properties) properties. The name of your counter can't be the case-insensitive {{cssxref("list-style-type")}} property values of `decimal`, `disc`, `square`, `circle`, `disclosure-open`, and `disclosure-closed`. > **Note:** The non-overridable counter style names `decimal`, `disc`, `square`, `circle`, `disclosure-open`, and `disclosure-closed` cannot be used as the name of a custom counter. However, they are valid in other contexts where the `<counter-style-name>` data type is expected, such as in `system: extend <counter-style-name>`. ### Descriptors - {{cssxref("@counter-style/system", "system")}} - : Specifies the algorithm to be used for converting the integer value of a counter to a string representation. If the value is `cyclic`, `numeric`, `alphabetic`, `symbolic`, or `fixed`, the `symbols` descriptor must also be specified. If the value is `additive` , the `additive-symbols` descriptor must also be specified. - {{cssxref("@counter-style/symbols", "symbols")}} - : Specifies the symbols that are to be used for the marker representations. Symbols can contain strings, images, or custom identifiers. This descriptor is required if the `system` descriptor is set to `cyclic`, `numeric`, `alphabetic`, `symbolic`, or `fixed`. - {{cssxref("@counter-style/additive-symbols", "additive-symbols")}} - : Defines the _additive tuples_ for additive systems. While the symbols specified in the `symbols` descriptor are used for constructing marker representation by most algorithms, additive counter systems, such as Roman numerals, consist of a series of weighted symbols. The descriptors is a list of counter symbol along with their non-negative integer weights, listed by weight in descending order. This descriptor is required if the `system` descriptor is set to `additive`. - {{cssxref("@counter-style/negative", "negative")}} - : Specifies to symbols to be appended or prepended to the counter representation if the value is negative. - {{cssxref("@counter-style/prefix", "prefix")}} - : Specifies a symbol that should be prepended to the marker representation. Prefixes are added to the representation in the final stage, before any characters added to negative counter values by the `negative` descriptor. - {{cssxref("@counter-style/suffix", "suffix")}} - : Specifies, similar to the prefix descriptor, a symbol that is appended to the marker representation. Suffixes come after the marker representation, including after any characters added to negative counter values by the `negative` descriptor. - {{cssxref("@counter-style/range", "range")}} - : Defines the range of values over which the counter style is applicable. If a counter style is used to represent a counter value outside of the ranges defined by this descriptor, the counter style will drop back to its `fallback` style. - {{cssxref("@counter-style/pad", "pad")}} - : Is used when you need the marker representations to be of a minimum length. For example if you want the counters to start at 01 and go through 02, 03, 04, etc., then the `pad` descriptor is to be used. For representations larger than the specified `pad` value, the marker is constructed as normal. - {{cssxref("@counter-style/speak-as", "speak-as")}} - : Describes how speech synthesizers, such as screen readers, should announce the counter style. For example, the value of the list item marker can be read out as numbers or alphabets for ordered lists or as audio cues for unordered lists, based on the value of this descriptor. - {{cssxref("@counter-style/fallback", "fallback")}} - : Specifies the counter name of the system to fall back to if either the specified system is unable to construct the representation of a counter value or if the counter value is outside the specified `range`. If the fallback counter also fails to represent the value, then that counter's fallback is used, if one is specified. If there are either no fallback counters described or if the chain of fallback systems are unable to represent a counter value, then it will ultimately fall back to the `decimal` style. ## Formal syntax {{csssyntax}} ## Examples ### Specifying symbols with counter-style ```css @counter-style circled-alpha { system: fixed; symbols: Ⓐ Ⓑ Ⓒ Ⓓ Ⓔ Ⓕ Ⓖ Ⓗ Ⓘ Ⓙ Ⓚ Ⓛ Ⓜ Ⓝ Ⓞ Ⓟ Ⓠ Ⓡ Ⓢ Ⓣ Ⓤ Ⓥ Ⓦ Ⓧ Ⓨ Ⓩ; suffix: " "; } ``` The above counter style rule can be applied to lists like this: ```css .items { list-style: circled-alpha; } ``` The above code produces the following result: ```html hidden <ol class="items"> <li>one</li> <li>two</li> <li>three</li> <li>four</li> <li>five</li> </ol> <p>...</p> <ol class="items" start="25"> <li>twenty-five</li> <li>twenty-six</li> <li>twenty-seven</li> <li>twenty-eight</li> </ol> ``` {{EmbedLiveSample('Specifying symbols with counter-style', '', '300')}} See more examples on the [demo page](https://mdn.github.io/css-examples/counter-style-demo/). ### Ready-made counter styles Find a collection of over 100 `counter-style` code snippets in the [Ready-made Counter Styles](https://www.w3.org/TR/predefined-counter-styles/) document. This document provides counter styles that meet the needs of languages and cultures around the world. The [Counter styles converter](https://r12a.github.io/app-counters/) pulls from this list to test and create copy and paste code for counter styles. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{Cssxref("list-style")}}, {{Cssxref("list-style-image")}}, {{Cssxref("list-style-position")}}, {{Cssxref("list-style-type")}} - {{cssxref("symbols", "symbols()")}}, the functional notation creating anonymous counter styles. - CSS {{Cssxref("counter", "counter()")}} and {{Cssxref("counters", "counters()")}} functions - [Counter style demo](https://mdn.github.io/css-examples/counter-style-demo/) ([code](https://github.com/mdn/css-examples/tree/main/counter-style-demo))
0
data/mdn-content/files/en-us/web/css/@counter-style
data/mdn-content/files/en-us/web/css/@counter-style/additive-symbols/index.md
--- title: additive-symbols slug: Web/CSS/@counter-style/additive-symbols page-type: css-at-rule-descriptor browser-compat: css.at-rules.counter-style.additive-symbols --- {{CSSRef}} The **`additive-symbols`** descriptor of the {{cssxref('@counter-style')}} at-rule is used to specify counter symbols when the `@counter-style` {{cssxref('@counter-style/system', 'system')}} descriptor value is set as `additive`. The additive system is used to construct [sign-value numbering](https://en.wikipedia.org/wiki/Sign-value_notation) systems such as Roman numerals. ## Syntax ```css /* Single tuple */ additive-symbols: 3 "*"; /* Comma-separated list of tuples */ additive-symbols: 3 "0", 2 "\2E\20", 1 url(symbol.png); /* Binary counter */ additive-symbols: 2 "1", 1 "0"; /* Etruscan (a civilization in ancient Italy) counter */ additive-symbols: 100 "𐌟", 50 "𐌣", 10 "𐌢", 5 "𐌡", 1 "𐌠"; ``` ### Values The descriptor accepts a comma-separated list of _additive tuples_ with each tuple consisting of the following two values separated by a space: - {{cssxref("integer")}} - : A non-negative integer values specifying the integer weight of the associated symbol value of the tuple. - [`<symbol>`](/en-US/docs/Web/CSS/@counter-style/symbols#symbol) - : Specifies the counter symbol to be used for the weight value defined by the associated `<integer>` weight value of the tuple. > **Note:** The additive tuples must be specified in order of descending weight; otherwise, the descriptor declaration isn't valid and is ignored. ## Description The `additive-symbols` descriptor defines a comma-separated list of _additive tuples_. Each _additive tuple_ contains a space-separated non-negative integer and counter symbol. To be valid, the list must be in the descending order of integer. The integer and symbol are concatenated together to form the counter symbol. When the `system` descriptor value is `cyclic`, `numeric`, `alphabetic`, `symbolic`, or `fixed`, use the {{cssxref('symbols')}} descriptor instead of `additive-symbols`. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Specifying additive symbols #### HTML In this example, {{cssxref("@counter-style/system","system: additive")}} along with the `additive-symbols` descriptor values specify how numbers should be represented as Roman numerals. The value of each {{HTMLElement("li")}} element in the list is converted to a Roman numeral according to the rules defined in {{cssxref("@counter-style")}}. ```html <ul> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> <li>Five</li> <li value="109">109</li> <li>110</li> </ul> ``` #### CSS ```css @counter-style uppercase-roman { system: additive; additive-symbols: 1000 M, 900 CM, 500 D, 400 CD, 100 C, 90 XC, 50 L, 40 XL, 10 X, 9 IX, 5 V, 4 IV, 1 I; } ul { list-style: uppercase-roman; padding-left: 5em; } ``` #### Result {{ EmbedLiveSample('Specifying_additive_symbols') }} For the list item with the value of `109`, the numeral `C` represents `100`, and `IX` represents `9`. This generates `CIX` counter for the list item `109`. The next list item automatically gets a value of `110`. The roman numeral `CX` is derived from `C` for `100` and `X` for `10`. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("@counter-style")}} descriptors: {{cssxref("@counter-style/system","system")}}, {{cssxref("@counter-style/symbols", "symbols")}}, {{cssxref("@counter-style/negative", "negative")}}, {{cssxref("@counter-style/prefix", "prefix")}}, {{cssxref("@counter-style/suffix", "suffix")}}, {{cssxref("@counter-style/range", "range")}}, {{cssxref("@counter-style/pad", "pad")}}, {{cssxref("@counter-style/speak-as", "speak-as")}}, {{cssxref("@counter-style/fallback", "fallback")}} - List style properties: {{Cssxref("list-style")}}, {{Cssxref("list-style-image")}}, {{Cssxref("list-style-position")}} - {{cssxref("symbols", "symbols()")}} function to create anonymous counter styles - [CSS counter styles](/en-US/docs/Web/CSS/CSS_counter_styles) module
0
data/mdn-content/files/en-us/web/css/@counter-style
data/mdn-content/files/en-us/web/css/@counter-style/negative/index.md
--- title: negative slug: Web/CSS/@counter-style/negative page-type: css-at-rule-descriptor browser-compat: css.at-rules.counter-style.negative --- {{CSSRef}} The **`negative`** descriptor of the {{cssxref("@counter-style")}} at-rule lets you define how negative counter values are represented when defining custom counter styles. The value of the `negative` descriptor defines the symbols to be added before and after the counter representation when the counter's value is negative. ## Syntax ```css /* One <symbol> value */ negative: "--"; /* Adds '--' before if counter value is negative */ /* Two <symbol> values */ negative: "(" ")"; /* Adds '(- before and ')' after if counter value is negative */ ``` ### Values The `negative` descriptor accepts up to two [`<symbol>`](/en-US/docs/Web/CSS/@counter-style/symbols#values) values. - `<symbol>` - : If only one value is specified, it is added before the counter representation when the counter is negative. If two values are specified, the first one is added before and the second one is added after the counter representation when the counter is negative. ## Description If the counter value is negative, the specified `<symbol>` for the `negative` descriptor is added before the counter representation, replacing the default `-` for negative values. The second `<symbol>`, if specified, is added after the counter representation. The `negative` descriptor is relevant in two cases: if counter styles have the `system` value of `symbolic`, `alphabetic`, `numeric`, and `additive` and the count is negative; and if `system` value is `extends` and the extended counter style itself uses a negative sign. For systems that don't support negative counter values, specifying the `negative` descriptor has no effect and is ignored. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Rendering negative counters This example [extends](/en-US/docs/Web/CSS/@counter-style/system#extends) the [`decimal`](/en-US/docs/Web/CSS/list-style-type#decimal) list style. The `negative` descriptor is used to add `(-` and `)` before and after negative counter values. #### HTML ```html <ol start="-3"> <li>Negative three</li> <li>Negative two</li> <li>Negative one</li> <li>Zero</li> <li>One</li> </ol> ``` #### CSS ```css @counter-style neg { system: extends decimal; negative: "(-" ")"; suffix: ": "; } ol { list-style: neg; } ``` #### Result {{ EmbedLiveSample('Rendering negative counters') }} The prefix and suffix listed as the value of the `negative` descriptor are only added to the marker when the counter value is less than zero. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("@counter-style")}} descriptors: {{cssxref("@counter-style/system","system")}}, {{cssxref("@counter-style/symbols", "symbols")}}, {{cssxref("@counter-style/additive-symbols", "additive-symbols")}}, {{cssxref("@counter-style/prefix", "prefix")}}, {{cssxref("@counter-style/suffix", "suffix")}}, {{cssxref("@counter-style/range", "range")}}, {{cssxref("@counter-style/pad", "pad")}}, {{cssxref("@counter-style/speak-as", "speak-as")}}, {{cssxref("@counter-style/fallback", "fallback")}} - List style properties: {{Cssxref("list-style")}}, {{Cssxref("list-style-image")}}, {{Cssxref("list-style-position")}} - {{cssxref("symbols", "symbols()")}} function to create anonymous counter styles - [CSS counter styles](/en-US/docs/Web/CSS/CSS_counter_styles) module - [CSS lists and counters](/en-US/docs/Web/CSS/CSS_lists) module
0
data/mdn-content/files/en-us/web/css/@counter-style
data/mdn-content/files/en-us/web/css/@counter-style/symbols/index.md
--- title: symbols slug: Web/CSS/@counter-style/symbols page-type: css-at-rule-descriptor browser-compat: css.at-rules.counter-style.symbols --- {{CSSRef}} The **`symbols`** [CSS](/en-US/docs/Web/CSS) descriptor of the {{cssxref("@counter-style")}} at-rule is used to specify the symbols for creating counter representations in the specified counter system. Specifying this descriptor is mandatory when the value of the {{cssxref('@counter-style/system', 'system')}} descriptor is `cyclic`, `numeric`, `alphabetic`, `symbolic`, or `fixed`. ## Syntax ```css symbols: A B C D E; symbols: "\24B6" "\24B7" "\24B8" D E; symbols: "0" "1" "2" "4" "5" "6" "7" "8" "9"; symbols: url("one.svg") url("two.svg") url("three.svg"); symbols: indic-numbers; ``` ### Values The `symbols` descriptor is specified as a list of one or more space-separated `<symbol>` values. - `<symbol>` - : Specifies the symbol to use within the counter system. Each symbol in the list can be either a {{cssxref("&lt;string&gt;")}}, an {{cssxref("&lt;image&gt;")}}, or a {{cssxref("&lt;custom-ident&gt;")}}. The `<image>` value can, in turn, be specified as a {{cssxref("&lt;url&gt;")}} or {{cssxref("&lt;gradient&gt;")}}. > **Note:** When using an {{glossary("identifier")}} for a symbol, note that {{glossary("ASCII")}} non-letters such as `*`, `"`, and `\` are not considered identifiers. They must be either quoted as a string or escaped. ## Description A symbol can be a string, image, or identifier. It is used within the {{cssxref("@counter-style")}} [at-rule](/en-US/docs/Web/CSS/At-rule). When the value of the {{cssxref('@counter-style/system', 'system')}} descriptor is `cyclic`, `numeric`, `alphabetic`, `symbolic`, or `fixed`, the `symbols` descriptor must be specified. For the `additive` system, use the {{cssxref('@counter-style/additive-symbols', 'additive-symbols')}} descriptor instead to specify the symbols. While a space between quoted symbols is not required, it makes CSS more readable. To use a quote as a symbol, either escape the quote character or enclose the character within different quotes, such as `"'"`. When defining symbols with identifiers instead of strings, be sure to use identifier syntax rules. For example, as noted above, ASCII non-letters such as `*` are not identifiers and must be either quoted or escaped. Hex escape characters are followed by a space. This space may look like the space separating two identifiers, but it enables digits to follow hex-escaped characters. This means that two spaces must be included after a hex-escaped identifier to separate it from the next identifier. For example, it is better to use the string `"\2A 1"` instead of `\2A 1` with two spaces, as your code tools might remove double spaces. It is generally safer to quote identifiers that need to be escaped or use strings. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting counter symbols In this example, the list of values for the `symbols` descriptor include letters (`A`, `D`, `E`), a number within quotes (`"1"`), and a hex-escape identifier within quotes (`"\24B7"`) for the character `Ⓑ`. #### HTML ```html <ul class="list"> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> <li>Five</li> </ul> ``` #### CSS ```css @counter-style symbols-example { system: fixed; symbols: A "1" "\24B7" D E; } .list { list-style: symbols-example; } ``` #### Result {{EmbedLiveSample('Setting_counter_symbols')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("@counter-style")}} descriptors: {{cssxref("@counter-style/system","system")}}, {{cssxref("@counter-style/additive-symbols", "additive-symbols")}}, {{cssxref("@counter-style/negative", "negative")}}, {{cssxref("@counter-style/prefix", "prefix")}}, {{cssxref("@counter-style/suffix", "suffix")}}, {{cssxref("@counter-style/range", "range")}}, {{cssxref("@counter-style/pad", "pad")}}, {{cssxref("@counter-style/speak-as", "speak-as")}}, {{cssxref("@counter-style/fallback", "fallback")}} - List style properties: {{cssxref("list-style")}}, {{cssxref("list-style-image")}}, {{cssxref("list-style-position")}} - {{cssxref("symbols", "symbols()")}} function - {{cssxref("url", "url()")}} function - [CSS counter styles](/en-US/docs/Web/CSS/CSS_counter_styles) module
0
data/mdn-content/files/en-us/web/css/@counter-style
data/mdn-content/files/en-us/web/css/@counter-style/speak-as/index.md
--- title: speak-as slug: Web/CSS/@counter-style/speak-as page-type: css-at-rule-descriptor browser-compat: css.at-rules.counter-style.speak-as --- {{CSSRef}} The **`speak-as`** descriptor specifies how a counter symbol constructed with a given {{cssxref('@counter-style')}} will be represented in the spoken form. For example, an author can specify a counter symbol to be either spoken as its numerical value or just represented with an audio cue. ## Syntax ```css /* Keyword values */ speak-as: auto; speak-as: bullets; speak-as: numbers; speak-as: words; speak-as: spell-out; /* @counter-style name value */ speak-as: <counter-style-name>; ``` ### Values - `auto` - : If the value of `speak-as` is specified as `auto`, then the effective value of `speak-as` will be determined based on the value of the {{cssxref("@counter-style/system", "system")}} descriptor: - If the value of `system` is `alphabetic`, the effective value of `speak-as` will be `spell-out`. - If `system` is `cyclic`, the effective value of `speak-as` will be `bullets`. - If `system` is `extends`, the value of `speak-as` will be the same as if `speak-as: auto` is specified on the extended style. - For all other cases, specifying `auto` has the same effect as specifying `speak-as: numbers`. - `bullets` - : A phrase or an audio cue defined by the {{Glossary("user agent")}} for representing an unordered list item will be read out. - `numbers` - : The numerical value of the counter will be read out in the document language. - `words` - : The user agent will generate a counter value as normal and read it out as a word in the document language. - `spell-out` - : The user agent will generate a counter representation as normal and would read it out letter by letter. If the user agent doesn't know how to read out a particular counter symbol, the user agent might read it out as if the value of `speak-as` was `numbers`. - `<counter-style-name>` - : The name of another counter style, specified as a {{cssxref("&lt;custom-ident&gt;")}}. If included, the counter will be spoken out in the form specified in that counter style, kind of like specifying the {{cssxref("@counter-style/fallback", "fallback")}} descriptor. If the specified style does not exist, `speak-as` defaults to `auto`. ## Accessibility concerns Assistive technology support is very limited for the `speak-as` property. Do not rely on it to convey information critical to understanding the page's purpose. [Let's Talk About Speech CSS | CSS Tricks](https://css-tricks.com/lets-talk-speech-css/) (2017) ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting the spoken form for a counter In this example, the counter system is fixed with unintelligible symbols used for the visual markers. However, the `speak-as` descriptor is used to set the list item markers as numbers in the accessibility tree. When supported, numbers rather than visual markers will be read out by screen readers. To experience the result of the `speak-as` descriptor, use assistive technology such as VoiceOver or another screen reader or view the [accessibility panel](https://firefox-source-docs.mozilla.org/devtools-user/index.html#accessibility-inspector) in the developer tools of a browser that supports `speak-as`. #### HTML ```html <ul class="list"> <li>I had one apple</li> <li>I ate two bananas</li> <li>I devoured three oranges</li> <li>I am not hungry for dinner</li> <li>But I'll have five scopps of ice cream for desert</li> </ul> ``` #### CSS ```css @counter-style speak-as-example { system: fixed; symbols:     ; suffix: " "; speak-as: numbers; } .list { list-style: speak-as-example; } ``` #### Result {{ EmbedLiveSample('Setting_the_spoken_form_for_a_counter') }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Other {{cssxref("@counter-style")}} descriptors: {{cssxref("@counter-style/system","system")}}, {{cssxref("@counter-style/symbols", "symbols")}}, {{cssxref("@counter-style/additive-symbols", "additive-symbols")}}, {{cssxref("@counter-style/negative", "negative")}}, {{cssxref("@counter-style/prefix", "prefix")}}, {{cssxref("@counter-style/suffix", "suffix")}}, {{cssxref("@counter-style/range", "range")}}, {{cssxref("@counter-style/pad", "pad")}}, and {{cssxref("@counter-style/fallback", "fallback")}} - {{Cssxref("list-style")}}, {{Cssxref("list-style-image")}}, {{Cssxref("list-style-position")}} - {{cssxref("symbols", "symbols()")}}: the functional notation for creating anonymous counter styles. - [CSS counter styles](/en-US/docs/Web/CSS/CSS_counter_styles) module - [CSS lists and counters](/en-US/docs/Web/CSS/CSS_lists) module
0
data/mdn-content/files/en-us/web/css/@counter-style
data/mdn-content/files/en-us/web/css/@counter-style/prefix/index.md
--- title: prefix slug: Web/CSS/@counter-style/prefix page-type: css-at-rule-descriptor browser-compat: css.at-rules.counter-style.prefix --- {{CSSRef}} The {{cssxref('@counter-style')}} rule's **`prefix`** descriptor specifies content that will be added to the beginning of the counter's marker representation. When the counter value is negative, the `prefix` comes before the negative sign and any other `<symbol>`s added by the {{cssxref("@counter-style/negative", "negative")}} descriptor. ## Syntax ```css /* <symbol> value: string, image, or identifier */ prefix: "»"; prefix: "Page "; prefix: url(bullet.png); ``` ### Values The **`prefix`** descriptor takes as its value a single `<symbol>`: - `<symbol>` - : Specifies a `<symbol>` — a {{cssxref("&lt;string&gt;")}}, {{cssxref("&lt;image&gt;")}}, or {{cssxref("&lt;custom-ident&gt;")}} — that is prepended to the marker representation. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Adding a prefix to a counter In this example, each counter number is prefixed by "Book " (with a space) and followed by a colon (`:`). The colon is added with the {{cssxref("@counter-style/suffix", "suffix")}} descriptor. #### HTML ```html <ol class="books"> <li>Flamer, by Mike Curato</li> <li>Gender Queer: A Memoir, by Maia Kobabe</li> <li>Tricks, by Ellen Hopkins</li> <li>The Handmaid’s Tale: The Graphic Novel, by Margaret Atwood</li> <li>Crank, by Ellen Hopkins</li> </ol> ``` #### CSS ```css @counter-style books { system: numeric; symbols: "0" "1" "2" "3" "4" "5" "6" "7" "8" "9"; prefix: "Book "; suffix: ": "; } .books { list-style: books; padding-left: 15ch; } ``` #### Result {{ EmbedLiveSample('Adding_a_prefix_to_a_counter') }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Other {{cssxref("@counter-style")}} descriptors: {{cssxref("@counter-style/system","system")}}, {{cssxref("@counter-style/symbols", "symbols")}}, {{cssxref("@counter-style/additive-symbols", "additive-symbols")}}, {{cssxref("@counter-style/negative", "negative")}}, {{cssxref("@counter-style/suffix", "suffix")}}, {{cssxref("@counter-style/range", "range")}}, {{cssxref("@counter-style/pad", "pad")}}, {{cssxref("@counter-style/speak-as", "speak-as")}}, and {{cssxref("@counter-style/fallback", "fallback")}} - {{Cssxref("list-style")}}, {{Cssxref("list-style-image")}}, {{Cssxref("list-style-position")}} - {{cssxref("symbols", "symbols()")}}: the functional notation for creating anonymous counter styles - [CSS counter styles](/en-US/docs/Web/CSS/CSS_counter_styles) module - [CSS lists and counters](/en-US/docs/Web/CSS/CSS_lists) module
0
data/mdn-content/files/en-us/web/css/@counter-style
data/mdn-content/files/en-us/web/css/@counter-style/pad/index.md
--- title: pad slug: Web/CSS/@counter-style/pad page-type: css-at-rule-descriptor browser-compat: css.at-rules.counter-style.pad --- {{CSSRef}} The **`pad`** descriptor of the {{cssxref("@counter-style")}} at-rule is used to set a minimum length for marker representations. ## Syntax ```css pad: 3 "0"; pad: "+" 5; ``` ### Values The descriptor accepts the following two values, which are separated by a space and can be specified in any order: - {{cssxref("integer")}} - : Specifies the minimum length that all marker representations must reach. The value must be non-negative. In the case of the `pad` descriptor, this value is also known as the _pad length_. - [`<symbol>`](/en-US/docs/Web/CSS/@counter-style/symbols#symbol) - : Specifies the symbol to be used for padding if the minimum length defined by the `<integer>` is not reached. In the case of the `pad` descriptor, this value is also known as the _padding symbol_. ## Description Use the `pad` descriptor when you need the marker representations to be of a minimum length. If a marker representation is shorter than the specified pad length, then the marker representation will be padded with the specified padding symbol. Marker representations longer than the pad length are displayed without any additional padding. The `pad` descriptor takes an `<integer>` for the minimum marker length and a `<symbol>` for the padding. A common use case of the `pad` descriptor is when you need a list to start numbering from `01` and go through `02`, `03`, `04`, and so on, instead of just `1`, `2`, `3`, and `4`. By specifying the `pad` descriptor as `pad: 2 "0"` in this case, the browser ensures to make the counter at least two characters long and adds a padding with `0` to reach the minimum two-character length where needed. Counters that are already two or more characters long in this example will be displayed normally, without padding. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Padding a counter This example extends the `decimal` {{cssxref("@counter-style/system","system")}} to create a counter that is at least three characters long, padding shorter counters with `0` to reach that minimum length. A {{cssxref("@counter-style/suffix", "suffix")}} descriptor has been added to make the output more legible. #### HTML ```html <ul> <li>One</li> <li>Two</li> <li>Three</li> <li value="40">Forty</li> <li>Forty-one</li> <li value="200">Two hundred</li> <li value="3000">Three thousand</li> <li>and so on</li> </ul> ``` #### CSS ```css @counter-style pad-example { system: extends decimal; suffix: ": "; pad: 3 "0"; } ul { list-style: pad-example; } ``` #### Result {{ EmbedLiveSample('Padding a counter', '100', '200') }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("@counter-style")}} descriptors: {{cssxref("@counter-style/system","system")}}, {{cssxref("@counter-style/symbols", "symbols")}}, {{cssxref("@counter-style/additive-symbols", "additive-symbols")}}, {{cssxref("@counter-style/negative", "negative")}}, {{cssxref("@counter-style/prefix", "prefix")}}, {{cssxref("@counter-style/suffix", "suffix")}}, {{cssxref("@counter-style/range", "range")}}, {{cssxref("@counter-style/speak-as", "speak-as")}}, {{cssxref("@counter-style/fallback", "fallback")}} - List style properties: {{Cssxref("list-style")}}, {{Cssxref("list-style-image")}}, {{Cssxref("list-style-position")}} - {{cssxref("symbols", "symbols()")}} function to create anonymous counter styles - [CSS counter styles](/en-US/docs/Web/CSS/CSS_counter_styles) module - [CSS lists and counters](/en-US/docs/Web/CSS/CSS_lists) module
0
data/mdn-content/files/en-us/web/css/@counter-style
data/mdn-content/files/en-us/web/css/@counter-style/fallback/index.md
--- title: fallback slug: Web/CSS/@counter-style/fallback page-type: css-at-rule-descriptor browser-compat: css.at-rules.counter-style.fallback --- {{CSSRef}} The **`fallback`** descriptor of the {{cssxref("@counter-style")}} at-rule can be used to specify a counter style to fall back to if the counter style being defined cannot create a marker representation for a particular counter value. ## Syntax ```css /* Keyword values */ fallback: lower-alpha; fallback: custom-gangnam-style; ``` ## Value The descriptor takes a single `<counter-style-name>` as its value: - [`<counter-style-name>`](/en-US/docs/Web/CSS/@counter-style#counter-style-name) - : Provides the name of the counter style to be used as the fallback, which is either the case-sensitive `<custom-ident>` of a custom CSS counter style (without quotes) or a case-insensitive {{cssxref("list-style-type")}} property value such as `decimal`, `disc`, and so on. If omitted, the counter fallback defaults to `decimal`. ## Description The counter style provided as the value of the `fallback` descriptor is used when a {{cssxref('@counter-style/range', 'range')}} descriptor is specified for a counter style; the `fallback` style is used to represent all the values that fall outside the range. The `fallback` style is also used when the `fixed` {{cssxref('@counter-style/system', 'system')}} is used and there are not enough symbols to cover all the list items; the `fallback` style is used to represent all the values beyond the scope of the fixed system. In both these cases, and any other time the defined counter cannot create a specific counter value, the `fallback` style is used. If the specified fallback style is also unable to construct a representation, then the `fallback` value of that fallback counter is used. If that fallback style's fallback is also unable to construct a representation, then that fallback's fallback is used. This falling back continues until a fallback is found that can construct the counter-representation. If no fallback `fallback` value is able to construct a representation―if a fallback style doesn't have a `fallback` value set, or if a `fallback` value is not specified or invalid―the `fallback` defaults to `decimal`. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Specifying a fallback counter style #### HTML ```html <ul class="list"> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> <li>Five</li> </ul> ``` #### CSS ```css @counter-style fallback-example { system: fixed; symbols: "\24B6" "\24B7" "\24B8"; fallback: upper-alpha; } .list { list-style: fallback-example; } ``` #### Result {{ EmbedLiveSample('Specifying_a_fallback_counter_style') }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Other {{cssxref("@counter-style")}} descriptors: {{cssxref("@counter-style/system","system")}}, {{cssxref("@counter-style/symbols", "symbols")}}, {{cssxref("@counter-style/additive-symbols", "additive-symbols")}}, {{cssxref("@counter-style/negative", "negative")}}, {{cssxref("@counter-style/prefix", "prefix")}}, {{cssxref("@counter-style/suffix", "suffix")}}, {{cssxref("@counter-style/range", "range")}}, {{cssxref("@counter-style/pad", "pad")}}, and {{cssxref("@counter-style/speak-as", "speak-as")}} - {{Cssxref("list-style")}}, {{Cssxref("list-style-image")}}, {{Cssxref("list-style-position")}} - {{cssxref("symbols", "symbols()")}}: the functional notation for creating anonymous counter styles
0
data/mdn-content/files/en-us/web/css/@counter-style
data/mdn-content/files/en-us/web/css/@counter-style/range/index.md
--- title: range slug: Web/CSS/@counter-style/range page-type: css-at-rule-descriptor browser-compat: css.at-rules.counter-style.range --- {{CSSRef}} The **`range`** descriptor lets the author specify one or more ranges of counter values for which the style is applied when defining custom counter styles with the {{cssxref("@counter-style")}} at-rule. When the `range` descriptor is included, the defined counter will only be used for values in the set ranges. If the counter value is outside the specified range, the fallback style will be used to construct the representation of that marker. ## Syntax ```css /* Keyword value */ range: auto; /* Range values */ range: 2 5; range: infinite 10; range: 6 infinite; range: infinite infinite; /* Multiple range values */ range: 2 5, 8 10; range: infinite 6, 10 infinite; ``` ### Values The value is a comma-separated list of ranges each including a lower and upper limit or the keyword `auto`. - `auto` - : The entire set of numbers representable by the counter {{cssxref("@counter-style/system","system")}}. Those range values depends on the counter system: - For `cyclic`, `numeric`, and `fixed` systems, the range is negative `infinity` to positive `infinity`. - For `alphabetic` and `symbolic` systems, the range is `1` to positive `infinity`. - For `additive` systems, the range is `0` to `positive` infinity. - When using `extend` to extend a system, the range is whatever `auto` would produce for the system being extended, including extensions of complex predefined styles, such as some Japanese, Korean, Chinese, and Ethiopian counter styles. - `[ [ <integer> | infinite ]{2} ]#` - : Each range within the comma separated list of ranges includes two values, each being either an {{cssxref("integer")}} or the keyword `infinite`. If `infinite` is used as the first value in a range, it represents negative infinity; if it is used as the second value, it represents positive infinity. The first value of each range is the lower bound for the range and the second value is the upper bound, inclusive. If the lower bound of any range in the list is higher than the upper bound, the entire `range` descriptor is invalid and will be ignored. ## Description The value of the `range` descriptor can be either `auto` or a comma separated list of lower and upper bound ranges specified using negative or positive integers or the keyword `infinite`. ### Understanding `auto` When the value is set to `auto`, the range is the default range for the counter system. If the `system` is `cyclic`, `numeric`, or `fixed`, the range will be from negative infinity to positive infinity. If the `system` is `alphabetic` or `symbolic`, the range will be from `1` to positive `infinity`. For `system: additive`, `auto` results in the range `0` to positive `infinity`. When extending a counter, if `range` is set to `auto`, the range value will be the range of the `system` of the counter that is being extended, not the `range` value, if any, of that counter. For example, if counter "B" has the `system: extends A` set, with counter being an `alphabetic` counter, setting `range: auto` on "B" sets the range of "B" from `1` to `infinity`. This is the range of the `alphabetic` system, not necessarily the range set in the "A" counter style definiton. With `range: auto` set on "B", the `range` is set to the default range of the `alphabetic` system, not the `range` value set in counter A's descriptor list. ### `infinite` explained When range is specified as integers (versus `auto`), the value `infinite` can be used to denote infinity. If _infinite_ is specified as the first value in a range, then it is interpreted as negative infinity. If used as the upper bound, the second value in the range pair, it is taken as positive infinity. ### List of ranges The value of `range` is either `auto`, discussed above, or a comma separated list of one or more ranges. The range of the counter style is the union of all the ranges defined in the list. Each range in the list of ranges takes two values. Those values are either an {{cssxref("integer")}} or the keyword `infinite`. The first value is the _lower bound_, inclusive. The second value is the _upper bound_, inclusive. For two integer values, the lower value must come first. If the lower bound of any range in the list is higher than the upper bound, the entire `range` descriptor is invalid and will be ignored. The `infinite` keyword will not invalidated the range as it's position determines it's value; either negative or positive infinity based on whether it's the lower bound or upper bound, respectively. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting counter style over a range #### HTML ```html <ul class="list"> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> <li>Five</li> <li>Six</li> <li>Seven</li> <li>Eight</li> <li>Nine</li> <li>Ten</li> </ul> ``` #### CSS ```css @counter-style range-multi-example { system: cyclic; symbols: "\25A0" "\25A1"; range: 2 4, 7 9; } .list { list-style: range-multi-example; } ``` #### Result {{EmbedLiveSample('Setting counter style over a range')}} The first range is the list of ranges includes 2, 3, and 4. The second includes 7, 8, and 9. The range is the union of these two ranges, or 2, 3, 4, 7, 8, and 9. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Other {{cssxref("@counter-style")}} descriptors: {{cssxref("@counter-style/system","system")}}, {{cssxref("@counter-style/symbols", "symbols")}}, {{cssxref("@counter-style/additive-symbols", "additive-symbols")}}, {{cssxref("@counter-style/negative", "negative")}}, {{cssxref("@counter-style/prefix", "prefix")}}, {{cssxref("@counter-style/suffix", "suffix")}}, {{cssxref("@counter-style/pad", "pad")}}, {{cssxref("@counter-style/speak-as", "speak-as")}}, and {{cssxref("@counter-style/fallback", "fallback")}} - {{Cssxref("list-style")}}, {{Cssxref("list-style-image")}}, {{Cssxref("list-style-position")}} - {{cssxref("symbols", "symbols()")}}: the functional notation for creating anonymous counter styles. - [CSS counter styles](/en-US/docs/Web/CSS/CSS_counter_styles) module - [CSS lists and counters](/en-US/docs/Web/CSS/CSS_lists) module
0
data/mdn-content/files/en-us/web/css/@counter-style
data/mdn-content/files/en-us/web/css/@counter-style/system/index.md
--- title: system slug: Web/CSS/@counter-style/system page-type: css-at-rule-descriptor browser-compat: css.at-rules.counter-style.system --- {{CSSRef}} The **`system`** descriptor specifies the algorithm to be used for converting the integer value of a counter to a string representation. It is used in a {{cssxref("@counter-style")}} to define the behavior of the defined style. If the algorithm specified in the `system` descriptor is unable to construct the representation for a particular counter value, then that value's representation will be constructed using the fallback system provided. ## Syntax ```css /* Keyword values */ system: cyclic; system: numeric; system: alphabetic; system: symbolic; system: additive; system: fixed; /* Other values */ system: fixed 3; system: extends decimal; system: extends circled-letters; ``` ## Values This may take one of three forms: - One of the keyword values `cyclic`, `numeric`, `alphabetic`, `symbolic`, `additive`, or `fixed`. - The keyword value `fixed` along with an integer. - The keyword value `extends` along with a [`<counter-style-name>`](/en-US/docs/Web/CSS/@counter-style#counter-style-name) value. The values include: - `cyclic` - : Cycles through the list of symbols provided in the [`symbols`](/en-US/docs/Web/CSS/@counter-style/symbols) descriptor. Once the end of the list is reached, the cycle will loop back to the beginning and start over. This value is useful both for basic bullet styles with just one symbol and for styles with multiple symbols. At least one symbol must be specified in the `symbols` descriptor, otherwise the counter style is not valid. - `numeric` - : Interprets the counter symbols as digits in a [place-value numbering system](https://en.wikipedia.org/wiki/Positional_notation). The numeric system is similar to the `alphabetic` system, described above. The main difference is that in the `alphabetic` system, the first counter symbol given in the `symbols` descriptor is interpreted as `1`, the next as `2`, and so on. However, in the numeric system, the first counter symbol is interpreted as 0, the next as `1`, then `2`, and so on. At least two counter symbols must be specified in the `symbols` descriptor or the counter style is not valid. - `alphabetic` - : Interprets the specified symbols as digits, to an alphabetic numbering system. If the characters `"a"` to `"z"` are specified as symbols in a counter style, with the `alphabetic` system, then the first 26 counter representations will be `"a"`, `"b"` up to `"z"`. Until this point, the behavior is the same as that of the `symbolic` system, described above. However, after `"z"`, it will continue as `"aa"`, `"ab"`, `"ac"`… The `symbols` descriptor must contain at least two symbols or the counter style is not valid. The first counter symbol provided in the `symbols` descriptor is interpreted as `1`, the next as `2`, and so on. This system is also defined strictly over positive counter values. - `symbolic` - : Cycles through the symbols provided in the `symbols` descriptor list repeatedly, doubling, tripling, and so on, the symbols on each successive pass through the list. For example, if two symbols "◽" and "◾" are specified in the `symbols` descriptor, on each successive pass, they will become "◽◽" and "◾◾", then "◽◽◽" and "◾◾◾", and so on in subsequent passes. At least one symbol must be specified in the `symbols` descriptor, otherwise the counter style is not valid. This counter system works for positive counter values only. - `additive` - : Used to represent "sign-value" numbering systems, such as Roman numerals, which rather than reuse digits in different positions to obtain different values, define additional digits for larger values. The value of a number in such a system can be found out by adding the digits in the number. An additional descriptor called `additive-symbols` must be specified with at least one _additive tuple_, or else the counter style rule will not be valid. An additive tuple is similar to a composite counter symbol, which is made up of two parts: a normal counter symbol and a non-negative integer weight. The additive tuples must be specified in the descending order of their weights or the system is invalid. - `fixed` or `fixed <integer>` - : Defines a finite set of symbols, iterating once through the list of symbols provided in the `symbols` descriptor. Once the specified symbols have been iterated through, the fallback counter style is used. This keyword value is useful in cases where the counter style values are finite. At least one symbol must be specified in the `symbols` descriptor, otherwise the counter style is not valid. The `fixed` keyword can be followed by an optional {{cssxref("&lt;integer&gt;")}} value. If specified, the `<integer>` value indicates the item in the list that will get the first symbol from the list of symbols. If omitted, the default value of `integer` is `1`, which gives the first item in the list the first symbol. - `extends` - : Extends the algorithm of another browser- or author-defined counter style by allowing the alteration of some aspects of the extended counter style. Any unspecified descriptors and their values are inherited from the extended counter style specified. If the counter style name specified with `extends` is not yet defined, the `decimal` counter style will be extended by default. It must not contain a `symbols` or `additive-symbols` descriptor, otherwise the counter style rule will be invalid. If one or more counter styles definitions form a cycle with their `extends` values, the browser will treat all the participating counter styles as extending from the `decimal` style. > **Note:** The [`symbols`](/en-US/docs/Web/CSS/@counter-style/symbols) descriptor is required when the value is `cyclic`, `numeric`, `alphabetic`, `symbolic`, or `fixed`. The [`additive-symbols`](/en-US/docs/Web/CSS/@counter-style/additive-symbols) descriptor is required if the `additive` value is set. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Cyclic counter The `cyclic` value iterates through the list of symbols, repeating the list as necessary: #### CSS ```html hidden <ul> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> <li>Five</li> <li>Six</li> </ul> ``` ```css @counter-style fisheye { system: cyclic; symbols: ◉ ➀; suffix: ": "; } ul { list-style: fisheye; } ``` #### Result {{ EmbedLiveSample('Cyclic_counter') }} ### Fixed counter The `fixed` value iterates through the list of symbols only once, starting the single cycle at the list item number indicated by the `integer` value: #### CSS ```html hidden <ul> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> <li>Five</li> <li>Six</li> </ul> ``` ```css @counter-style circled-digits { system: fixed 3; symbols: ➀ ➁ ➂; suffix: ": "; } ul { list-style: circled-digits; } ``` #### Result {{ EmbedLiveSample('Fixed_counter') }} ### Symbolic counter The `symbolic` value loops through the list defined in the `symbols` descriptor, doubling and tripling the number of symbols for the second and third cycles through the list, respectively: #### CSS ```html hidden <ul> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> <li>Five</li> <li>Six</li> <li>Seven</li> <li>Eight</li> </ul> ``` ```css @counter-style abc { system: symbolic; symbols: a b c; suffix: ". "; } ul { list-style: abc; } ``` #### Result {{ EmbedLiveSample('Symbolic_counter') }} ### Alphabetic counter #### CSS ```html hidden <ul> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> <li>Five</li> <li>Six</li> <li>Seven</li> <li>Eight</li> </ul> ``` ```css @counter-style abc { system: alphabetic; symbols: a b c; suffix: ". "; } ul { list-style: abc; } ``` #### Result {{ EmbedLiveSample('Alphabetic_counter') }} ### Numeric counter The first symbol provided in the `symbols` descriptor is interpreted as `0` here. #### CSS ```html hidden <ul> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> <li>Five</li> <li>Six</li> <li>Seven</li> <li>Eight</li> </ul> ``` ```css @counter-style abc { system: numeric; symbols: a b c; suffix: ". "; } ul { list-style: abc; } ``` #### Result {{ EmbedLiveSample('Numeric_counter') }} ### Numeric counter with numeric symbols As shown in the following example, if digits from `0` to `9` are specified as symbols, this counter style will render symbols same as the decimal counter style. #### CSS ```html hidden <ul class="list"> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> <li>Five</li> <li>Six</li> <li>Seven</li> <li>Eight</li> <li>Nine</li> <li>Ten</li> </ul> ``` ```css @counter-style numbers { system: numeric; symbols: "0" "1" "2" "3" "4" "5" "6" "7" "8" "9"; suffix: "."; } ul { list-style: numbers; } ``` #### Result {{ EmbedLiveSample('Numeric_counter_with_numeric_symbols') }} ### Additive counter This example renders a list using Roman numerals. Notice that a `range` is specified. This is because the representation will produce correct Roman numerals only until the counter value of `3999`. Once outside of the range, the rest of the counter representations will be based on the `decimal` style, which is the fall back. If you need to represent counter values as Roman numerals, you could use either one of the predefined counter styles, `upper-roman` or `lower-roman`, rather than recreating the rule yourself. #### HTML We use the [`start`](/en-US/docs/Web/HTML/Element/ol#start) attribute on the {{HTMLElement("ol")}} element to demonstrate that counting doesn't need to start at `1`. Additionally, we use the [`value`](/en-US/docs/Web/HTML/Element/li#value) attribute on the fifth {{HTMLElement("li")}} element to demonstrate that the counters you define using `@counter-style` behave just like native counters. ```html <ol start="48"> <li>48</li> <li>49</li> <li>50</li> <li>51</li> <li value="109">109</li> <li>110</li> <ol></ol> </ol> ``` #### CSS ```css @counter-style uppercase-roman { system: additive; range: 1 3999; additive-symbols: 1000 M, 900 CM, 500 D, 400 CD, 100 C, 90 XC, 50 L, 40 XL, 10 X, 9 IX, 5 V, 4 IV, 1 I; } ol { list-style: uppercase-roman; padding-left: 5em; } ``` #### Result {{ EmbedLiveSample('Additive_counter', '') }} ### Extending a counter This example uses the algorithm, symbols, and other properties of [`lower-alpha`](/en-US/docs/Web/CSS/list-style-type#lower-alpha), one of the several native {{CSSXref("list-style-type")}} counter values, but extends it by removing the period (`'.'`) after the counter representation and enclosing the characters in parentheses, as in `(a)` and `(b)`. #### HTML ```html <ul class="list"> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> <li>Five</li> </ul> ``` #### CSS ```css @counter-style alpha-modified { system: extends lower-alpha; prefix: "("; suffix: ") "; } ul { list-style: alpha-modified; } ``` #### Result {{ EmbedLiveSample('Extending_a_counter') }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Other {{cssxref("@counter-style")}} descriptors, including {{cssxref("@counter-style/symbols", "symbols")}}, {{cssxref("@counter-style/additive-symbols", "additive-symbols")}}, {{cssxref("@counter-style/negative", "negative")}}, {{cssxref("@counter-style/prefix", "prefix")}}, {{cssxref("@counter-style/suffix", "suffix")}}, {{cssxref("@counter-style/range", "range")}}, {{cssxref("@counter-style/pad", "pad")}}, {{cssxref("@counter-style/speak-as", "speak-as")}}, and {{cssxref("@counter-style/fallback", "fallback")}} - {{cssxref("list-style")}}, {{cssxref("list-style-image")}}, {{cssxref("list-style-position")}} - {{cssxref("symbols", "symbols()")}}, the functional notation creating anonymous counter styles.
0
data/mdn-content/files/en-us/web/css/@counter-style
data/mdn-content/files/en-us/web/css/@counter-style/suffix/index.md
--- title: suffix slug: Web/CSS/@counter-style/suffix page-type: css-at-rule-descriptor browser-compat: css.at-rules.counter-style.suffix --- {{CSSRef}} The **`suffix`** descriptor of the {{cssxref("@counter-style")}} rule specifies content that will be added to the end of the marker representation. ## Syntax ```css /* <symbol> value: string, image, or identifier */ suffix: ""; suffix: ") "; suffix: url(bullet.png); ``` ### Values The **`suffix`** descriptor takes as its value a single `<symbol>`: - `<symbol>` - : Specifies a `<symbol>` that is appended to the marker representation. It may be a {{cssxref("&lt;string&gt;")}}, {{cssxref("&lt;image&gt;")}}, or {{cssxref("&lt;custom-ident&gt;")}}. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting a suffix for a counter #### HTML ```html <ul class="choices"> <li>One</li> <li>Two</li> <li>Three</li> <li>None of the above</li> </ul> ``` #### CSS ```css @counter-style options { system: fixed; symbols: A B C D; suffix: ") "; } .choices { list-style: options; } ``` #### Result {{ EmbedLiveSample('Setting_a_suffix_for_a_counter')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Other {{cssxref("@counter-style")}} descriptors: {{cssxref("@counter-style/system","system")}}, {{cssxref("@counter-style/symbols", "symbols")}}, {{cssxref("@counter-style/additive-symbols", "additive-symbols")}}, {{cssxref("@counter-style/negative", "negative")}}, {{cssxref("@counter-style/prefix", "prefix")}}, {{cssxref("@counter-style/range", "range")}}, {{cssxref("@counter-style/pad", "pad")}}, {{cssxref("@counter-style/speak-as", "speak-as")}}, and {{cssxref("@counter-style/fallback", "fallback")}} - {{Cssxref("list-style")}}, {{Cssxref("list-style-image")}}, {{Cssxref("list-style-position")}} - {{cssxref("symbols", "symbols()")}}: the functional notation for creating anonymous counter styles - [CSS counter styles](/en-US/docs/Web/CSS/CSS_counter_styles) module - [CSS lists and counters](/en-US/docs/Web/CSS/CSS_lists) module
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/scroll-timeline-axis/index.md
--- title: scroll-timeline-axis slug: Web/CSS/scroll-timeline-axis page-type: css-property status: - experimental browser-compat: css.properties.scroll-timeline-axis --- {{CSSRef}}{{SeeCompatTable}} The **`scroll-timeline-axis`** [CSS](/en-US/docs/Web/CSS) property is used to specify the scrollbar direction that will be used to provide the timeline for a _named scroll progress timeline_ animation, which is progressed through by scrolling a scrollable element (_scroller_) between top and bottom (or left and right). `scroll-timeline` is set on the scroller that will provide the timeline. See [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations) for more details. > **Note:** If the scroller element does not overflow its container in the axis dimension or if the overflow is hidden or clipped, no scroll progress timeline will be created. The `scroll-timeline-axis` and {{cssxref("scroll-timeline-name")}} properties can also be set using the [`scroll-timeline`](/en-US/docs/Web/CSS/scroll-timeline) shorthand property. ## Syntax ```css /* Logical property values */ scroll-timeline-axis: block; scroll-timeline-axis: inline; /* Non-logical property values */ scroll-timeline-axis: y; scroll-timeline-axis: x; ``` ### Values Allowed values for `scroll-timeline-axis` are: - `block` - : The scrollbar on the block axis of the scroller element, which is the axis in the direction perpendicular to the flow of text within a line. For horizontal writing modes, such as standard English, this is the same as `y`, while for vertical writing modes, it is the same as `x`. This is the default value. - `inline` - : The scrollbar on the inline axis of the scroller element, which is the axis in the direction parallel to the flow of text in a line. For horizontal writing modes, this is the same as `x`, while for vertical writing modes, this is the same as `y`. - `y` - : The scrollbar on the vertical axis of the scroller element. - `x` - : The scrollbar on the horizontal axis of the scroller element. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Defining the axis of the scroll progress timeline In this example, a scroll progress timeline named `--myScroller` is defined using the `scroll-timeline-name` property on the <code>:root</code> element ({{htmlelement("html")}}). This timeline is then applied to the animation on the element with the `animation` class using `animation-timeline: --myScroller`. To demonstrate the effect of `scroll-timeline-axis`, a horizontal (non-default) scrollbar is used in this example to drive the animation. #### HTML The HTML for the example is shown below. ```html <body> <div class="content"></div> <div class="box animation"></div> </body> ``` #### CSS The CSS for the container sets the <code>:root</code> as the source of a scroll progress timeline named `--myScroller` using the `scroll-timeline-name` property. The scroll axis is set using `scroll-timeline-axis: x;` (Chromium) and `scroll-timeline-axis: horizontal;` (Firefox) — this causes the _horizontal scrollbar_ position to determine the animation timeline. The width of the `.content` element is set to a large value to make it overflow the `:root` element. Also worth noting is that the `.animation` element has the timeline applied to it using `animation-timeline: --myScroller;`, and it also has an `animation-duration` applied to it so that the example will work in Firefox. ```css :root { scroll-timeline-name: --myScroller; /* Chromium supports the new x/y syntax */ scroll-timeline-axis: x; /* Firefox still supports the old horizontal/vertical syntax */ scroll-timeline-axis: horizontal; } body { margin: 0; overflow-y: hidden; } .content { height: 100vh; width: 2000px; } .box { width: 100px; height: 100px; border-radius: 10px; background-color: rebeccapurple; position: fixed; top: 25px; left: 25px; } .animation { animation: rotate-appear; animation-timeline: --myScroller; animation-duration: 1ms; /* Firefox requires this to apply the animation */ } @keyframes rotate-appear { from { rotate: 0deg; top: 0%; } to { rotate: 720deg; top: 100%; } } ``` #### Result Scroll the horizontal bar at the bottom to see the square animate as you scroll. {{EmbedLiveSample("Defining_the_axis_of_the_scroll_progress_timeline", "100%", "200px")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`animation-timeline`](/en-US/docs/Web/CSS/animation-timeline) - [`scroll-timeline`](/en-US/docs/Web/CSS/scroll-timeline), [`scroll-timeline-name`](/en-US/docs/Web/CSS/scroll-timeline-name) - {{cssxref("timeline-scope")}} - [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_grammar-error/index.md
--- title: "::grammar-error" slug: Web/CSS/::grammar-error page-type: css-pseudo-element browser-compat: css.selectors.grammar-error --- {{CSSRef}} The **`::grammar-error`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) represents a text segment which the {{glossary("user agent")}} has flagged as grammatically incorrect. ## Allowable properties Only a small subset of CSS properties can be used in a rule with `::grammar-error` in its selector: - {{cssxref("color")}} - {{cssxref("background-color")}} - {{cssxref("cursor")}} - {{cssxref("caret-color")}} - {{cssxref("outline")}} and its longhands - {{cssxref("text-decoration")}} and its associated properties - {{cssxref("text-emphasis-color")}} - {{cssxref("text-shadow")}} ## Syntax ```css ::grammar-error { /* ... */ } ``` ## Examples ### Simple document grammar check In this example, eventual supporting browsers should highlight any flagged grammatical errors with the styles shown. #### HTML ```html <p contenteditable spellcheck="true"> My friends is coming to the party tonight. </p> ``` #### CSS ```css ::grammar-error { text-decoration: underline red; color: red; } ``` #### Result {{EmbedLiveSample('Simple_document_grammar_check', '100%', 60)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("::spelling-error")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/@document/index.md
--- title: "@document" slug: Web/CSS/@document page-type: css-at-rule status: - deprecated - non-standard browser-compat: css.at-rules.document --- {{CSSRef}}{{Deprecated_header}}{{Non-standard_header}} The **`@document`** [CSS](/en-US/docs/Web/CSS) [at-rule](/en-US/docs/Web/CSS/At-rule) restricts the style rules contained within it based on the URL of the document. It is designed primarily for user-defined style sheets, though it can be used on author-defined style sheets, too. ```css @document url("https://www.example.com/") { h1 { color: green; } } ``` ## Syntax An `@document` rule can specify one or more matching functions. If any of the functions apply to a given URL, the rule will take effect on that URL. The functions available are: - `url()` - : Matches an exact URL. - `url-prefix()` - : Matches if the document URL starts with the value provided. - `domain()` - : Matches if the document URL is on the domain provided (or a subdomain of it). - `media-document()` - : Matches the media according to the string in parameter, one of `video`, `image`, `plugin` or `all`. - `regexp()` {{Deprecated_Inline}} {{Non-standard_Inline}} - : Matches if the document URL is matched by the [regular expression](/en-US/docs/Web/JavaScript/Guide/Regular_expressions) provided. The expression must match the entire URL. The values provided to the `url()`, `url-prefix()`, `domain()`, and `media-document()` functions can be optionally enclosed by single or double quotes. The values provided to the `regexp()` function _must_ be enclosed in quotes. Escaped values provided to the `regexp()` function must additionally be escaped from the CSS. For example, a `.` (period) matches any character in regular expressions. To match a literal period, you would first need to escape it using regular expression rules (to `\.`), then escape that string using CSS rules (to `\\.`). `@document` is currently only supported in Firefox; if you wanted to replicate using such functionality in your own non-Firefox browser, you could try using [this polyfill](https://github.com/An-Error94/Handy-Scripts/tree/master/%40document-polyfill) by @An-Error94, which uses a combination of a user script, [data-\* attributes](/en-US/docs/Web/HTML/Global_attributes/data-*), and [attribute selectors](/en-US/docs/Web/CSS/Attribute_selectors). > **Note:** There is a -moz-prefixed version of this property — `@-moz-document`. This has been limited to use only in user and UA sheets in Firefox 59 in Nightly and Beta — an experiment designed to mitigate potential CSS injection attacks (See [Firefox bug 1035091](https://bugzil.la/1035091)). ## Formal syntax ```plain @document [ <url> | url-prefix(<string>) | domain(<string>) | media-document(<string>) | regexp(<string>) ]# { <group-rule-body> } ``` ## Examples ### Specifying document for CSS rule ```css @document url("http://www.w3.org/"), url-prefix("http://www.w3.org/Style/"), domain("mozilla.org"), media-document("video"), regexp("https:.*") { /* CSS rules here apply to: - The page "http://www.w3.org/" - Any page whose URL begins with "http://www.w3.org/Style/" - Any page whose URL's host is "mozilla.org" or ends with ".mozilla.org" - Any standalone video - Any page whose URL starts with "https:" */ /* Make the above-mentioned pages really ugly */ body { color: purple; background: yellow; } } ``` ## Specifications [Initially](https://www.w3.org/TR/2012/WD-css3-conditional-20120911/#at-document) in Level 3, `@document` was [postponed](https://www.w3.org/TR/2012/WD-css3-conditional-20121213/#changes) to Level 4, but then subsequently removed. ## Browser compatibility {{Compat}} ## See also - [Per-site user style sheet rules](https://lists.w3.org/Archives/Public/www-style/2004Aug/0135) on the www-style mailing list.
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/text-transform/index.md
--- title: text-transform slug: Web/CSS/text-transform page-type: css-property browser-compat: css.properties.text-transform --- {{CSSRef}} The **`text-transform`** CSS property specifies how to capitalize an element's text. It can be used to make text appear in all-uppercase or all-lowercase, or with each word capitalized. It also can help improve legibility for ruby. {{EmbedInteractiveExample("pages/css/text-transform.html")}} The `text-transform` property takes into account language-specific case mapping rules such as the following: - In Turkic languages, like Turkish (`tr`), Azerbaijani (`az`), Crimean Tatar (`crh`), Volga Tatar (`tt`), and Bashkir (`ba`), there are two kinds of `i`, with and without the dot, and two case pairings: `i`/`İ` and `ı`/`I`. - In German (`de`), the `ß` becomes `SS` in uppercase. - In Dutch (`nl`), the `ij` digraph becomes `IJ`, even with `text-transform: capitalize`, which only puts the first letter of a word in uppercase. - In Greek (`el`), vowels lose their accent when the whole word is in uppercase (`ά`/`Α`), except for the disjunctive eta (`ή`/`Ή`). Also, diphthongs with an accent on the first vowel lose the accent and gain a diaeresis on the second vowel (`άι`/`ΑΪ`). - In Greek (`el`), the lowercase sigma character has two forms: `σ` and `ς`. `ς` is used only when sigma terminates a word. When applying `text-transform: lowercase` to an uppercase sigma (`Σ`), the browser needs to choose the right lowercase form based on context. - in Irish (`ga`), certain prefixed letters remain in lowercase when the base initial is capitalized, so for example `text-transform: uppercase` will change `ar aon tslí` to `AR AON tSLÍ` and not, as one might expect, `AR AON TSLÍ` (Firefox only). In some cases, a hyphen is also removed upon uppercasing: `an t-uisce` transforms to `AN tUISCE` (and the hyphen is correctly reinserted by `text-transform: lowercase`). The language is defined by the [`lang`](/en-US/docs/Web/HTML/Global_attributes/lang) HTML attribute or the [`xml:lang`](/en-US/docs/Web/SVG/Attribute/xml:lang) XML attribute. > **Note:** Support for language-specific cases varies between browsers, so check the [browser compatibility table](#browser_compatibility). ## Syntax ```css /* Keyword values */ text-transform: none; text-transform: capitalize; text-transform: uppercase; text-transform: lowercase; text-transform: full-width; text-transform: full-size-kana; /* Global values */ text-transform: inherit; text-transform: initial; text-transform: revert; text-transform: revert-layer; text-transform: unset; ``` - `capitalize` - : Is a keyword that converts the first _letter_ of each word to uppercase. Other characters remain unchanged (they retain their original case as written in the element's text). A letter is defined as a character that is part of Unicode's Letter or Number general categories {{experimental_inline}}; thus, any punctuation marks or symbols at the beginning of a word are ignored. > **Note:** Authors should not expect `capitalize` to follow language-specific title casing conventions (such as skipping articles in English). > **Note:** The `capitalize` keyword was under-specified in CSS 1 and CSS 2.1. This resulted in differences between browsers in the way the first letter was calculated (Firefox considered `-` and `_` as letters, but other browsers did not. Both Webkit and Gecko incorrectly considered letter-based symbols like `ⓐ` to be real letters.) By precisely defining the correct behavior, CSS Text Level 3 cleans this mess up. The `capitalize` line in the browser compatibility table contains the version the different engines started to support this now precisely-defined behavior. - `uppercase` - : Is a keyword that converts all characters to uppercase. - `lowercase` - : Is a keyword that converts all characters to lowercase. - `none` - : Is a keyword that prevents the case of all characters from being changed. - `full-width` - : Is a keyword that forces the writing of a character — mainly ideograms and Latin scripts — inside a square, allowing them to be aligned in the usual East Asian scripts (like Chinese or Japanese). - `full-size-kana` - : Generally used for {{htmlelement("ruby")}} annotation text, the keyword converts all small Kana characters to the equivalent full-size Kana, to compensate for legibility issues at the small font sizes typically used in ruby. ## Accessibility concerns Large sections of text set with a `text-transform` value of `uppercase` may be difficult for people with cognitive concerns such as Dyslexia to read. - [MDN Understanding WCAG, Guideline 1.4 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background) - [W3C Understanding WCAG 2.1](https://www.w3.org/TR/WCAG21/#visual-presentation) ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Example using "none" ```html <p> Initial String <strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit…</strong> </p> <p> text-transform: none <strong ><span >Lorem ipsum dolor sit amet, consectetur adipisicing elit…</span ></strong > </p> ``` ```css span { text-transform: none; } strong { float: right; } ``` This demonstrates no text transformation. {{ EmbedLiveSample('Example using "none"', '100%', '100px') }} ### Example using "capitalize" (general) ```html <p> Initial String <strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit…</strong> </p> <p> text-transform: capitalize <strong ><span >Lorem ipsum dolor sit amet, consectetur adipisicing elit…</span ></strong > </p> ``` ```css span { text-transform: capitalize; } strong { float: right; } ``` This demonstrates text capitalization. {{ EmbedLiveSample('Example using "capitalize" (general)', '100%', '100px') }} ### Example using "capitalize" (punctuation) ```html <p> Initial String <strong >(this) "is" [a] –short– -test- «for» *the* _css_ ¿capitalize? ?¡transform!</strong > </p> <p> text-transform: capitalize <strong ><span >(this) "is" [a] –short– -test- «for» *the* _css_ ¿capitalize? ?¡transform!</span ></strong > </p> ``` ```css span { text-transform: capitalize; } strong { float: right; } ``` This demonstrates how initial punctuations of a word are ignored. The keyword target the first letter, that is the first Unicode character part of the Letter or Number general category. {{ EmbedLiveSample('Example using "capitalize" (punctuation)', '100%', '100px') }} ### Example using "capitalize" (Symbols) ```html <p> Initial String <strong>ⓐⓑⓒ (ⓓⓔⓕ) —ⓖⓗⓘ— ⓙkl</strong> </p> <p> text-transform: capitalize <strong><span>ⓐⓑⓒ (ⓓⓔⓕ) —ⓖⓗⓘ— ⓙkl</span></strong> </p> ``` ```css span { text-transform: capitalize; } strong { float: right; } ``` This demonstrates how initial symbols are ignored. The keyword target the first letter, that is the first Unicode character part of the Letter or Number general category. {{ EmbedLiveSample('Example using "capitalize" (symbols)', '100%', '100px') }} ### Example using "capitalize" (Dutch ij digraph) ```html <p> Initial String <strong lang="nl">The Dutch word: "ijsland" starts with a digraph.</strong> </p> <p> text-transform: capitalize <strong ><span lang="nl" >The Dutch word: "ijsland" starts with a digraph.</span ></strong > </p> ``` ```css span { text-transform: capitalize; } strong { float: right; } ``` This demonstrates how the Dutch _ij_ digraph must be handled like one single letter. {{ EmbedLiveSample('Example using "capitalize" (Dutch ij digraph)', '100%', '100px') }} ### Example using "uppercase" (general) ```html <p> Initial String <strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit…</strong> </p> <p> text-transform: uppercase <strong ><span >Lorem ipsum dolor sit amet, consectetur adipisicing elit…</span ></strong > </p> ``` ```css span { text-transform: uppercase; } strong { float: right; } ``` This demonstrates transforming the text to uppercase. {{ EmbedLiveSample('Example using "uppercase" (general)', '100%', '100px') }} ### Example using "uppercase" (Greek vowels) ```html <p> Initial String <strong>Θα πάμε στο "Θεϊκό φαΐ" ή στη "Νεράιδα"</strong> </p> <p> text-transform: uppercase <strong ><span lang="el">Θα πάμε στο "Θεϊκό φαΐ" ή στη "Νεράιδα"</span></strong > </p> ``` ```css span { text-transform: uppercase; } strong { float: right; } ``` This demonstrates how Greek vowels except disjunctive _eta_ should have no accent, and the accent on the first vowel of a vowel pair becomes a diaeresis on the second vowel. {{ EmbedLiveSample('Example using "uppercase" (Greek vowels)', '100%', '100px') }} ### Example using "lowercase" (general) ```html <p> Initial String <strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit…</strong> </p> <p> text-transform: lowercase <strong ><span >Lorem ipsum dolor sit amet, consectetur adipisicing elit…</span ></strong > </p> ``` ```css span { text-transform: lowercase; } strong { float: right; } ``` This demonstrates transforming the text to lowercase. {{ EmbedLiveSample('Example using "lowercase" (general)', '100%', '100px') }} ### Example using "lowercase" (Greek Σ) ```html <p> Initial String <strong>Σ IS A greek LETTER that appears SEVERAL TIMES IN ΟΔΥΣΣΕΥΣ.</strong> </p> <p> text-transform: lowercase <strong ><span >Σ IS A greek LETTER that appears SEVERAL TIMES IN ΟΔΥΣΣΕΥΣ.</span ></strong > </p> ``` ```css span { text-transform: lowercase; } strong { float: right; } ``` This demonstrates how the Greek character sigma (`Σ`) is transformed into the regular lowercase sigma (`σ`) or the word-final variant (`ς`), according the context. {{ EmbedLiveSample('Example using "lowercase" (Greek Σ)', '100%', '100px') }} ### Example using "lowercase" (Lithuanian) ```html <p> Initial String <strong>Ĩ is a Lithuanian LETTER as is J́</strong> </p> <p> text-transform: lowercase <strong><span lang="lt">Ĩ is a Lithuanian LETTER as is J́</span></strong> </p> ``` ```css span { text-transform: lowercase; } strong { float: right; } ``` This demonstrates how the Lithuanian letters `Ĩ` and `J́` retain their dot when transformed to lowercase. {{ EmbedLiveSample('Example using "lowercase" (Lithuanian)', '100%', '100px') }} ### Example using "full-width" (general) ```html <p> Initial String <strong >0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&()*+,-./:;<=>?@{|}~</strong > </p> <p> text-transform: full-width <strong ><span >0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&()*+,-./:;<=>?@{|}~</span ></strong > </p> ``` ```css span { text-transform: full-width; } strong { width: 100%; float: right; } ``` Some characters exist in two formats: normal width and a full-width, with different Unicode code points. The full-width version is used to mix them smoothly with Asian ideographic characters. {{ EmbedLiveSample('Example using "full-width" (general)', '100%', '175px') }} ### Example using "full-width" (Japanese half-width katakana) ```html <p> Initial String <strong>ウェブプログラミングの勉強</strong> </p> <p> text-transform: full-width <strong><span>ウェブプログラミングの勉強</span></strong> </p> ``` ```css span { text-transform: full-width; } strong { width: 100%; float: right; } ``` The Japanese half-width katakana was used to represent katakana in 8-bit character codes. Unlike regular (full-width) katakana characters, a letter with dakuten (voiced sound mark) is represented as two code points, the body of letter and dakuten. The `full-width` combines these into a single code point when converting these characters into full-width. {{ EmbedLiveSample('Example using "full-width" (Japanese half-width katakana)', '100%', '175px') }} ### Example using "full-size-kana" ```html <p>ァィゥェ ォヵㇰヶ ㇱㇲッㇳ ㇴㇵㇶㇷ ㇸㇹㇺャ ュョㇻㇼ ㇽㇾㇿヮ</p> <p>ァィゥェ ォヵㇰヶ ㇱㇲッㇳ ㇴㇵㇶㇷ ㇸㇹㇺャ ュョㇻㇼ ㇽㇾㇿヮ</p> </p> ``` ```css p:nth-of-type(2) { text-transform: full-size-kana; } ``` {{ EmbedLiveSample('Example using "full-size-kana"', '100%', '175px') }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("font-variant")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-inline-end-style/index.md
--- title: border-inline-end-style slug: Web/CSS/border-inline-end-style page-type: css-property browser-compat: css.properties.border-inline-end-style --- {{CSSRef}} The **`border-inline-end-style`** [CSS](/en-US/docs/Web/CSS) property defines the style of the logical inline end border of an element, which maps to a physical border style depending on the element's writing mode, directionality, and text orientation. It corresponds to the {{cssxref("border-top-style")}}, {{cssxref("border-right-style")}}, {{cssxref("border-bottom-style")}}, or {{cssxref("border-left-style")}} property depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. {{EmbedInteractiveExample("pages/css/border-inline-end-style.html")}} ## Syntax ```css /* <'border-style'> values */ border-inline-end-style: dashed; border-inline-end-style: dotted; border-inline-end-style: groove; /* Global values */ border-inline-end-style: inherit; border-inline-end-style: initial; border-inline-end-style: revert; border-inline-end-style: revert-layer; border-inline-end-style: unset; ``` Related properties are {{cssxref("border-block-start-style")}}, {{cssxref("border-block-end-style")}}, and {{cssxref("border-inline-start-style")}}, which define the other border styles of the element. ### Values - `<'border-style'>` - : The line style of the border. See {{ cssxref("border-style") }}. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting inline-end-style #### HTML ```html <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ```css div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; border: 5px solid blue; border-inline-end-style: dashed; } ``` #### Results {{EmbedLiveSample("Examples", 140, 140)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS Logical Properties and Values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values) - This property maps to one of the physical border properties: {{cssxref("border-top-style")}}, {{cssxref("border-right-style")}}, {{cssxref("border-bottom-style")}}, or {{cssxref("border-left-style")}}. - {{cssxref("writing-mode")}}, {{cssxref("direction")}}, {{cssxref("text-orientation")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/contain-intrinsic-block-size/index.md
--- title: contain-intrinsic-block-size slug: Web/CSS/contain-intrinsic-block-size page-type: css-property browser-compat: css.properties.contain-intrinsic-block-size --- {{CSSRef}} The **`contain-intrinsic-block-size`** [CSS](/en-US/docs/Web/CSS) [logical property](/en-US/docs/Web/CSS/CSS_logical_properties_and_values) defines the block size of an element that a browser can use for layout when the element is subject to [size containment](/en-US/docs/Web/CSS/CSS_containment#size_containment). Block size is the size of an element in the dimension perpendicular to the flow of text within a line. In a horizontal [writing mode](/en-US/docs/Web/CSS/writing-mode) like standard English, block size is the vertical dimension (height); in a vertical writing mode, block size is the horizontal dimension. ## Syntax ```css /* Keyword values */ contain-intrinsic-block-size: none; /* <length> values */ contain-intrinsic-block-size: 1000px; contain-intrinsic-block-size: 10rem; /* auto <length> */ contain-intrinsic-block-size: auto 300px; /* Global values */ contain-intrinsic-block-size: inherit; contain-intrinsic-block-size: initial; contain-intrinsic-block-size: revert; contain-intrinsic-block-size: revert-layer; contain-intrinsic-block-size: unset; ``` ### Values The following values can be specified for the intrinsic block size of an element: - `none` - : The element has no intrinsic block size. - `<length>` - : The element has the specified block size, expressed using the ({{cssxref("&lt;length&gt;")}}) data type. - `auto <length>` - : When the element is in size containment and skipping its contents (for example, when it is offscreen and `content-visibility: auto` is set) the block size is remembered from the actual size of the element when it was last able to render its child elements. If the element has never rendered its child elements and hence has no remembered value for the normally rendered element size, or if it is not skipping its contents, the block size is the specified `<length>`. ## Description The property is commonly applied alongside elements that can trigger size containment, such as [`contain: size`](/en-US/docs/Web/CSS/contain) and [`content-visibility`](/en-US/docs/Web/CSS/content-visibility). Size containment allows a user agent to lay out an element as though it had a fixed size. This prevents unnecessary reflows by avoiding the re-rendering of child elements to determine the actual size (thereby improving user experience). By default, size containment treats elements as though they had no contents and may collapse the layout in the same way as if the contents had no width or height. The `contain-intrinsic-block-size` property allows authors to specify an appropriate value to be used as the block-size for layout. The `auto <length>` value allows the block-size of an element to be stored if the element is ever "normally rendered" (with its child elements) and then used instead of the specified value when the element does not have any content. This allows offscreen elements with [`content-visibility: auto`](/en-US/docs/Web/CSS/content-visibility) to benefit from size containment without developers having to be precise in their estimates of element size. The remembered value is not used if the child elements are being rendered; if size containment is enabled, the `<length>` value will be used. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting the intrinsic block size The HTML below defines an element "contained_element" that will be subject to size constraint, and which contains a child element. ```html <div id="contained_element"> <div class="child_element"></div> </div> ``` The CSS below sets the [`content-visibility`](/en-US/docs/Web/CSS/content-visibility) of `contained_element` to `auto`, so if the element is hidden it will be size constrained. The intrinsic block size and inline size that are used when it is size constrained are set at the same time using `contain-intrinsic-block-size` and `contain-intrinsic-inline-size`, respectively. ```css #contained_element { border: 2px solid green; inline-size: 151px; content-visibility: auto; contain-intrinsic-inline-size: 152px; contain-intrinsic-block-size: 52px; } .child_element { border: 1px solid red; background: blue; block-size: 50px; inline-size: 150px; } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [content-visibility: the new CSS property that boosts your rendering performance](https://web.dev/articles/content-visibility) (web.dev) - {{CSSxRef("contain-intrinsic-inline-size")}} - {{CSSxRef("contain-intrinsic-size")}} - {{CSSxRef("contain-intrinsic-width")}} - {{CSSxRef("contain-intrinsic-height")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/-webkit-border-before/index.md
--- title: "-webkit-border-before" slug: Web/CSS/-webkit-border-before page-type: css-shorthand-property status: - non-standard browser-compat: css.properties.-webkit-border-before --- {{CSSRef}}{{Non-standard_header}} The **`-webkit-border-before`** [CSS](/en-US/docs/Web/CSS) property is a shorthand property for setting the individual logical block start border property values in a single place in the style sheet. ## Constituent properties This property is a shorthand for the following CSS properties: - {{cssxref("-webkit-border-before-color")}} - {{cssxref("-webkit-border-before-style")}} - {{cssxref("-webkit-border-before-width")}} ## Syntax ```css /* Border values */ -webkit-border-before: 1px; -webkit-border-before: 2px dotted; -webkit-border-before: medium dashed blue; /* Global values */ -webkit-border-before: inherit; -webkit-border-before: initial; -webkit-border-before: revert; -webkit-border-before: revert-layer; -webkit-border-before: unset; ``` ### Values One or more of the following, in any order: - `<'border-width'>` - : See {{cssxref("border-width")}} - `<'border-style'>` - : See {{cssxref("border-style")}} - `<'color'>` - : See {{cssxref("color")}} ## Description The `-webkit-border-before` property maps to a physical border depending on the element's writing mode, directionality, and text orientation. It corresponds to the {{cssxref("border-top")}}, {{cssxref("border-right")}}, {{cssxref("border-bottom")}}, or {{cssxref("border-left")}} property depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. It relates to {{cssxref("-webkit-border-after")}}, {{cssxref("-webkit-border-start")}}, and {{cssxref("-webkit-border-end")}}, which define the other borders of the element. The standard-track equivalent of this property is {{cssxref("border-block-start")}}. ## Formal definition {{CSSInfo}} ## Formal syntax ```plain -webkit-border-before = <'border-width'> || <'border-style'> || <color> ``` ## Examples ### Applying a border with vertical text #### HTML ```html <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ```css div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-rl; -webkit-border-before: 5px dashed blue; } ``` #### Result {{EmbedLiveSample("Applying_a_border_with_vertical_text", 140, 140)}} ## Specifications Not part of any standard, but it relates to the standards-track {{cssxref("border-block-start")}} property. ## Browser compatibility {{Compat}} ## See also - {{cssxref("border-block-start")}} - The mapped physical properties: {{cssxref("border-top")}}, {{cssxref("border-right")}}, {{cssxref("border-bottom")}}, and {{cssxref("border-left")}} - {{cssxref("writing-mode")}}, {{cssxref("direction")}}, {{cssxref("text-orientation")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_in-range/index.md
--- title: ":in-range" slug: Web/CSS/:in-range page-type: css-pseudo-class browser-compat: css.selectors.in-range --- {{CSSRef}} The **`:in-range`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents an {{htmlelement("input")}} element whose current value is within the range limits specified by the [`min`](/en-US/docs/Web/HTML/Element/input#min) and [`max`](/en-US/docs/Web/HTML/Element/input#max) attributes. {{EmbedInteractiveExample("pages/tabbed/pseudo-class-in-range.html", "tabbed-shorter")}} This pseudo-class is useful for giving the user a visual indication that a field's current value is within the permitted limits. > **Note:** This pseudo-class only applies to elements that have (and can take) a range limitation. In the absence of such a limitation, the element can neither be "in-range" nor "out-of-range." ## Syntax ```css :in-range { /* ... */ } ``` ## Examples ### HTML ```html <form action="" id="form1"> <ul> Values between 1 and 10 are valid. <li> <input id="value1" name="value1" type="number" placeholder="1 to 10" min="1" max="10" value="12" required /> <label for="value1">Your value is </label> </li> </ul> </form> ``` ### CSS ```css li { list-style: none; margin-bottom: 1em; } input { border: 1px solid black; } input:in-range { background-color: rgb(0 255 0 / 25%); } input:out-of-range { background-color: rgb(255 0 0 / 25%); border: 2px solid red; } input:in-range + label::after { content: "okay."; } input:out-of-range + label::after { content: "out of range!"; } ``` ### Result {{EmbedLiveSample('Examples', 600, 140)}} > **Note:** An empty `<input>` does not count as out of range, and will not be selected using the `:out-of-range` pseudo-class selector. The [`:blank`](/en-US/docs/Web/CSS/:blank) pseudo-class exists to select blank inputs, although at the time of writing this is experimental and not well-supported. You could also use the `required` attribute and the [`:invalid`](/en-US/docs/Web/CSS/:invalid) pseudo-class to provide more general logic and styling for making inputs mandatory (`:invalid` will style blank _and_ out-of-range inputs). ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref(":out-of-range")}} - [Form data validation](/en-US/docs/Learn/Forms/Form_validation)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/block-size/index.md
--- title: block-size slug: Web/CSS/block-size page-type: css-property browser-compat: css.properties.block-size --- {{CSSRef}} The **`block-size`** [CSS](/en-US/docs/Web/CSS) property defines the horizontal or vertical size of an element's block, depending on its writing mode. It corresponds to either the {{cssxref("width")}} or the {{cssxref("height")}} property, depending on the value of {{cssxref("writing-mode")}}. If the writing mode is vertically oriented, the value of `block-size` relates to the width of the element; otherwise, it relates to the height of the element. A related property is {{cssxref("inline-size")}}, which defines the other dimension of the element. {{EmbedInteractiveExample("pages/css/block-size.html")}} ## Syntax ```css /* <length> values */ block-size: 300px; block-size: 25em; /* <percentage> values */ block-size: 75%; /* Keyword values */ block-size: max-content; block-size: min-content; block-size: fit-content; block-size: fit-content(20em); block-size: auto; /* Global values */ block-size: inherit; block-size: initial; block-size: revert; block-size: revert-layer; block-size: unset; ``` ### Values The `block-size` property takes the same values as the {{cssxref("width")}} and {{cssxref("height")}} properties. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Block size with vertical text #### HTML ```html <p class="exampleText">Example text</p> ``` #### CSS ```css .exampleText { writing-mode: vertical-rl; background-color: yellow; block-size: 200px; } ``` #### Result {{EmbedLiveSample("Block_size_with_vertical_text")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - The mapped physical properties: {{cssxref("width")}} and {{cssxref("height")}} - {{cssxref("writing-mode")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_font_loading/index.md
--- title: CSS font loading slug: Web/CSS/CSS_font_loading page-type: css-module spec-urls: https://drafts.csswg.org/css-font-loading/ --- {{CSSRef}} The **CSS font loading** module describes events and interfaces used for dynamically loading font resources. ## Reference ### Interfaces - {{domxref("fontFace")}} interface - [`FontFace()`](/en-US/docs/Web/API/FontFace/FontFace) constructor - {{domxref("fontFace.family")}} property - {{domxref("fontFace.style")}} property - {{domxref("fontFace.weight")}} property - {{domxref("fontFace.stretch")}} property - {{domxref("fontFace.unicodeRange")}} property - {{domxref("fontFace.variant")}} property - {{domxref("fontFace.featureSettings")}} property - {{domxref("fontFace.variationSettings")}} property - {{domxref("fontFace.display")}} property - {{domxref("fontFace.ascentOverride")}} property - {{domxref("fontFace.descentOverride")}} property - {{domxref("fontFace.lineGapOverride")}} property - {{domxref("fontFace.load()")}} method (returns a promise) - {{domxref("fontFaceSet")}} interface - {{domxref("fontFaceSetLoadEvent")}} event ## Guides - [CSS font loading API](/en-US/docs/Web/API/CSS_Font_Loading_API) - : Overview of the CSS Font Loading API, which provide events and interfaces for dynamically loading font resources. ## Related concepts - CSS {{cssxref("@font-face")}} at-rule - CSS {{cssxref("@font-feature-values")}} at-rule - {{domxref("CSSFontFaceRule")}} interface - Document {{domxref("document.fonts", "fonts")}} property (returns the {{domxref("FontFaceSet")}} object instance) - WorkerGlobalScope {{domxref("WorkerGlobalScope.fonts", "fonts")}} property (returns the {{domxref("FontFaceSet")}} object instance) - JavaScript {{jsxref("Promise")}} object ## Specifications {{Specifications}} ## See also - [CSS fonts](/en-US/docs/Web/CSS/CSS_fonts) module
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_enabled/index.md
--- title: ":enabled" slug: Web/CSS/:enabled page-type: css-pseudo-class browser-compat: css.selectors.enabled --- {{CSSRef}} The **`:enabled`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents any enabled element. An element is enabled if it can be activated (selected, clicked on, typed into, etc.) or accept focus. The element also has a disabled state, in which it can't be activated or accept focus. {{EmbedInteractiveExample("pages/tabbed/pseudo-class-enabled.html", "tabbed-standard")}} ## Syntax ```plain :enabled ``` ## Examples The following example makes the color of text and button {{htmlElement("input")}}s green when enabled, and gray when disabled. This helps the user understand which elements can be interacted with. ### HTML ```html <form action="url_of_form"> <label for="FirstField">First field (enabled):</label> <input type="text" id="FirstField" value="Lorem" /><br /> <label for="SecondField">Second field (disabled):</label> <input type="text" id="SecondField" value="Ipsum" disabled="disabled" /><br /> <input type="button" value="Submit" /> </form> ``` ### CSS ```css input:enabled { color: #2b2; } input:disabled { color: #aaa; } ``` ### Result {{EmbedLiveSample("Examples", 550, 95)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{Cssxref(":disabled")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/fit-content/index.md
--- title: fit-content slug: Web/CSS/fit-content page-type: css-keyword browser-compat: css.properties.width.fit-content --- {{CSSRef}} The **`fit-content`** behaves as `fit-content(stretch)`. In practice this means that the box will use the available space, but never more than {{cssxref("max-content")}}. When used as laid out box size for {{cssxref("width")}}, {{cssxref("height")}}, {{cssxref("min-width")}}, {{cssxref("min-height")}}, {{cssxref("max-width")}} and {{cssxref("max-height")}} the maximum and minimum sizes refer to the content size. > **Note:** The CSS Sizing specification also defines the {{cssxref("fit-content_function", "fit-content()")}} function. This page details the keyword. ## Syntax ```css width: fit-content; block-size: fit-content; ``` ## Examples ### Using fit-content for box sizing #### HTML ```html <div class="container"> <div class="item">Item</div> <div class="item">Item with more text in it.</div> <div class="item"> Item with more text in it, hopefully we have added enough text so the text will start to wrap. </div> </div> ``` #### CSS ```css .container { border: 2px solid #ccc; padding: 10px; width: 20em; } .item { width: fit-content; background-color: #8ca0ff; padding: 5px; margin-bottom: 1em; } ``` #### Result {{EmbedLiveSample("Using_fit-content_for_box_sizing", "100%", 200)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Related sizing keywords: {{cssxref("min-content")}}, {{cssxref("max-content")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/mask-size/index.md
--- title: mask-size slug: Web/CSS/mask-size page-type: css-property browser-compat: css.properties.mask-size --- {{CSSRef}} The **`mask-size`** [CSS](/en-US/docs/Web/CSS) property specifies the sizes of the mask images. The size of the image can be fully or partially constrained in order to preserve its intrinsic ratio. > **Note:** If the value of this property is not set in a {{cssxref("mask")}} shorthand property that is applied to the element after the `mask-size` CSS property, the value of this property is then reset to its initial value by the shorthand property. ## Syntax ```css /* Keywords syntax */ mask-size: cover; mask-size: contain; /* One-value syntax */ /* the width of the image (height set to 'auto') */ mask-size: 50%; mask-size: 3em; mask-size: 12px; mask-size: auto; /* Two-value syntax */ /* first value: width of the image, second value: height */ mask-size: 50% auto; mask-size: 3em 25%; mask-size: auto 6px; mask-size: auto auto; /* Multiple values */ /* Do not confuse this with mask-size: auto auto */ mask-size: auto, auto; mask-size: 50%, 25%, 25%; mask-size: 6px, auto, contain; /* Global values */ mask-size: inherit; mask-size: initial; mask-size: revert; mask-size: revert-layer; mask-size: unset; ``` One or more `<bg-size>` values, separated by commas. A `<bg-size>` can be specified in one of three ways: - using the keyword `contain` - using the keyword `cover` - using width and height values To specify a size using width and height, you can supply one or two values: - If only one value is given it sets the width, with the height set to `auto`. - If two values are given, the first sets width and the second sets height. Each value can be a `<length>`, a `<percentage>`, or `auto`. ### Values - `<length>` - : A `{{cssxref("&lt;length&gt;")}}` value scales the mask image to the specified length in the corresponding dimension. Negative lengths are not allowed. - `<percentage>` - : A {{cssxref("&lt;percentage&gt;")}} value scales the mask image in the corresponding dimension to the specified percentage of the mask positioning area, which is determined by the value of {{cssxref("mask-origin")}}. The mask positioning area is, by default, the area containing the content of the box and its padding; the area may also be changed to just the content or to the area containing borders, padding and content. Negative percentages are not allowed. - `auto` - : A keyword that scales the mask image in the corresponding directions in order to maintain its intrinsic proportion. - `contain` - : A keyword that scales the image as large as possible and maintains image aspect ratio (image doesn't get squished). The image is _letterboxed_ within the container. The image is automatically centered unless over-ridden by another property such as {{cssxref("mask-position")}}. - `cover` - : A keyword that is the inverse of `contain`. Scales the image as large as possible and maintains image aspect ratio (image doesn't get squished). The image "covers" the entire width or height of the container. When the image and container have different dimensions, _the image is clipped_ either on left/right or at top/bottom. The interpretation of possible values depends on the image's intrinsic dimensions (width and height) and intrinsic proportion (ratio of width and height). A bitmap image always has intrinsic dimensions and an intrinsic proportion. A vector image may have both intrinsic dimensions and thus it has an intrinsic proportion too. It also may have one or no intrinsic dimensions and in either case it might or might not have an intrinsic proportion. Gradients are treated as images with no intrinsic dimensions or intrinsic proportion. The rendered size of the mask image is then computed as follows: - If both components of `mask-size` are specified and are not `auto`: - : The mask image renders at the specified size. - If the `mask-size` is `contain` or `cover`: - : The image is rendered by preserving its intrinsic proportion at the largest size contained within or covering the mask positioning area. If the image has no intrinsic proportion, then it is rendered at the size of the mask positioning area. - If the `mask-size` is `auto` or `auto auto`: - : If the image has both intrinsic dimensions, it is rendered at that size. If it has no intrinsic dimensions and no intrinsic proportion, it is rendered at the size of the mask positioning area. If it has no dimensions but has a proportion, it's rendered as if `contain` had been specified instead. If the image has one intrinsic dimension and a proportion, it's rendered at the size determined by that one dimension and the proportion. If the image has one intrinsic dimension but no proportion, it's rendered using the intrinsic dimension and the corresponding dimension of the mask positioning area. - If `mask-size` has one `auto` component and one non-`auto` component: - : If the image has an intrinsic proportion, then render it using the specified dimension and compute the other dimension from the specified dimension and the intrinsic proportion. If the image has no intrinsic proportion, use the specified dimension for that dimension. For the other dimension, use the image's corresponding intrinsic dimension if there is one. If there is no such intrinsic dimension, use the corresponding dimension of the mask positioning area. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting mask size as a percentage {{EmbedGHLiveSample("css-examples/masking/mask-size.html", '100%', 700)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Clipping and Masking in CSS](https://css-tricks.com/clipping-masking-css/)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_left/index.md
--- title: ":left" slug: Web/CSS/:left page-type: css-pseudo-class browser-compat: css.selectors.left --- {{CSSRef}} The **`:left`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes), used with the {{cssxref("@page")}} [at-rule](/en-US/docs/Web/CSS/At-rule), represents all left-hand pages of a printed document. ```css /* Selects any left-hand pages when printing */ @page :left { margin: 2in 3in; } ``` Whether a given page is "left" or "right" is determined by the major writing direction of the document. For example, if the first page has a major writing direction of left-to-right then it will be a {{Cssxref(":right")}} page; if it has a major writing direction of right-to-left then it will be a `:left` page. > **Note:** This pseudo-class can be used to change only the {{ Cssxref("margin") }}, {{ Cssxref("padding") }}, {{ Cssxref("border") }}, and {{ Cssxref("background") }} properties of the _page box_. All other properties will be ignored, and only the page box, not the document content on the page, will be affected. ## Syntax ```css :left { /* ... */ } ``` ## Examples ### Setting a margin for left-hand pages ```css @page :left { margin: 2in 3in; } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{ Cssxref("@page") }} - Other page-related pseudo-classes: {{ Cssxref(":first") }}, {{ Cssxref(":right") }}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/named-color/index.md
--- title: <named-color> slug: Web/CSS/named-color page-type: css-type browser-compat: css.types.color.named-color --- {{CSSRef}} The **`<named-color>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) is the name of a color, such as `red`, `blue`, `black`, or `lightseagreen`. Syntactically, a `<named-color>` is an [`<ident>`](/en-US/docs/Web/CSS/ident). A `<named-color>` value can be used anywhere a [`<color>`](/en-US/docs/Web/CSS/color_value) can be used. ## Syntax ```css color: red; color: orange; color: tan; color: rebeccapurple; color: transparent; ``` ### Value Named colors consists of standard colors, the [`transparent`](#transparent) and [`currentcolor`](/en-US/docs/Web/CSS/color_value#currentcolor_keyword) keywords. #### Standard colors Basic colors have standard, easy-to-remember names: <table> <thead> <tr> <th scope="col">Keyword</th> <th scope="col">RGB hex value</th> <th scope="col">Sample</th> </tr> </thead> <tbody> <tr> <td><code>black</code></td> <td><code>#000000</code></td> <td style="background: black"></td> </tr> <tr> <td><code>silver</code></td> <td><code>#c0c0c0</code></td> <td style="background: silver"></td> </tr> <tr> <td><code>gray</code></td> <td><code>#808080</code></td> <td style="background: gray"></td> </tr> <tr> <td><code>white</code></td> <td><code>#ffffff</code></td> <td style="background: white"></td> </tr> <tr> <td><code>maroon</code></td> <td><code>#800000</code></td> <td style="background: maroon"></td> </tr> <tr> <td><code>red</code></td> <td><code>#ff0000</code></td> <td style="background: red"></td> </tr> <tr> <td><code>purple</code></td> <td><code>#800080</code></td> <td style="background: purple"></td> </tr> <tr> <td><code>fuchsia</code></td> <td><code>#ff00ff</code></td> <td style="background: fuchsia"></td> </tr> <tr> <td><code>green</code></td> <td><code>#008000</code></td> <td style="background: green"></td> </tr> <tr> <td><code>lime</code></td> <td><code>#00ff00</code></td> <td style="background: lime"></td> </tr> <tr> <td><code>olive</code></td> <td><code>#808000</code></td> <td style="background: olive"></td> </tr> <tr> <td><code>yellow</code></td> <td><code>#ffff00</code></td> <td style="background: yellow"></td> </tr> <tr> <td><code>navy</code></td> <td><code>#000080</code></td> <td style="background: navy"></td> </tr> <tr> <td><code>blue</code></td> <td><code>#0000ff</code></td> <td style="background: blue"></td> </tr> <tr> <td><code>teal</code></td> <td><code>#008080</code></td> <td style="background: teal"></td> </tr> <tr> <td><code>aqua</code></td> <td><code>#00ffff</code></td> <td style="background: aqua"></td> </tr> </tbody> </table> In addition to these 16 colors, about 150 other colors have a keyword associated to them: <table> <thead> <tr> <th scope="col">Keyword</th> <th scope="col">RGB hex value</th> <th scope="col">Sample</th> </tr> </thead> <tbody> <tr> <td><code>aliceblue</code></td> <td><code>#f0f8ff</code></td> <td style="background: aliceblue"></td> </tr> <tr> <td><code>antiquewhite</code></td> <td><code>#faebd7</code></td> <td style="background: antiquewhite"></td> </tr> <tr> <td><code>aqua</code></td> <td><code>#00ffff</code></td> <td style="background: aqua"></td> </tr> <tr> <td><code>aquamarine</code></td> <td><code>#7fffd4</code></td> <td style="background: aquamarine"></td> </tr> <tr> <td><code>azure</code></td> <td><code>#f0ffff</code></td> <td style="background: azure"></td> </tr> <tr> <td><code>beige</code></td> <td><code>#f5f5dc</code></td> <td style="background: beige"></td> </tr> <tr> <td><code>bisque</code></td> <td><code>#ffe4c4</code></td> <td style="background: bisque"></td> </tr> <tr> <td><code>black</code></td> <td><code>#000000</code></td> <td style="background: black"></td> </tr> <tr> <td><code>blanchedalmond</code></td> <td><code>#ffebcd</code></td> <td style="background: blanchedalmond"></td> </tr> <tr> <td><code>blue</code></td> <td><code>#0000ff</code></td> <td style="background: blue"></td> </tr> <tr> <td><code>blueviolet</code></td> <td><code>#8a2be2</code></td> <td style="background: blueviolet"></td> </tr> <tr> <td><code>brown</code></td> <td><code>#a52a2a</code></td> <td style="background: brown"></td> </tr> <tr> <td><code>burlywood</code></td> <td><code>#deb887</code></td> <td style="background: burlywood"></td> </tr> <tr> <td><code>cadetblue</code></td> <td><code>#5f9ea0</code></td> <td style="background: cadetblue"></td> </tr> <tr> <td><code>chartreuse</code></td> <td><code>#7fff00</code></td> <td style="background: chartreuse"></td> </tr> <tr> <td><code>chocolate</code></td> <td><code>#d2691e</code></td> <td style="background: chocolate"></td> </tr> <tr> <td><code>coral</code></td> <td><code>#ff7f50</code></td> <td style="background: coral"></td> </tr> <tr> <td><code>cornflowerblue</code></td> <td><code>#6495ed</code></td> <td style="background: cornflowerblue"></td> </tr> <tr> <td><code>cornsilk</code></td> <td><code>#fff8dc</code></td> <td style="background: cornsilk"></td> </tr> <tr> <td><code>crimson</code></td> <td><code>#dc143c</code></td> <td style="background: crimson"></td> </tr> <tr> <td> <code>cyan</code><br /> </td> <td><code>#00ffff</code> (synonym of <code>aqua</code>)</td> <td style="background: cyan"></td> </tr> <tr> <td><code>darkblue</code></td> <td><code>#00008b</code></td> <td style="background: darkblue"></td> </tr> <tr> <td><code>darkcyan</code></td> <td><code>#008b8b</code></td> <td style="background: darkcyan"></td> </tr> <tr> <td><code>darkgoldenrod</code></td> <td><code>#b8860b</code></td> <td style="background: darkgoldenrod"></td> </tr> <tr> <td><code>darkgray</code></td> <td><code>#a9a9a9</code></td> <td style="background: darkgray"></td> </tr> <tr> <td><code>darkgreen</code></td> <td><code>#006400</code></td> <td style="background: darkgreen"></td> </tr> <tr> <td><code>darkgrey</code></td> <td><code>#a9a9a9</code></td> <td style="background: darkgrey"></td> </tr> <tr> <td><code>darkkhaki</code></td> <td><code>#bdb76b</code></td> <td style="background: darkkhaki"></td> </tr> <tr> <td><code>darkmagenta</code></td> <td><code>#8b008b</code></td> <td style="background: darkmagenta"></td> </tr> <tr> <td><code>darkolivegreen</code></td> <td><code>#556b2f</code></td> <td style="background: darkolivegreen"></td> </tr> <tr> <td><code>darkorange</code></td> <td><code>#ff8c00</code></td> <td style="background: darkorange"></td> </tr> <tr> <td><code>darkorchid</code></td> <td><code>#9932cc</code></td> <td style="background: darkorchid"></td> </tr> <tr> <td><code>darkred</code></td> <td><code>#8b0000</code></td> <td style="background: darkred"></td> </tr> <tr> <td><code>darksalmon</code></td> <td><code>#e9967a</code></td> <td style="background: darksalmon"></td> </tr> <tr> <td><code>darkseagreen</code></td> <td><code>#8fbc8f</code></td> <td style="background: darkseagreen"></td> </tr> <tr> <td><code>darkslateblue</code></td> <td><code>#483d8b</code></td> <td style="background: darkslateblue"></td> </tr> <tr> <td><code>darkslategray</code></td> <td><code>#2f4f4f</code></td> <td style="background: darkslategray"></td> </tr> <tr> <td><code>darkslategrey</code></td> <td><code>#2f4f4f</code></td> <td style="background: darkslategrey"></td> </tr> <tr> <td><code>darkturquoise</code></td> <td><code>#00ced1</code></td> <td style="background: darkturquoise"></td> </tr> <tr> <td><code>darkviolet</code></td> <td><code>#9400d3</code></td> <td style="background: darkviolet"></td> </tr> <tr> <td><code>deeppink</code></td> <td><code>#ff1493</code></td> <td style="background: deeppink"></td> </tr> <tr> <td><code>deepskyblue</code></td> <td><code>#00bfff</code></td> <td style="background: deepskyblue"></td> </tr> <tr> <td><code>dimgray</code></td> <td><code>#696969</code></td> <td style="background: dimgray"></td> </tr> <tr> <td><code>dimgrey</code></td> <td><code>#696969</code></td> <td style="background: dimgrey"></td> </tr> <tr> <td><code>dodgerblue</code></td> <td><code>#1e90ff</code></td> <td style="background: dodgerblue"></td> </tr> <tr> <td><code>firebrick</code></td> <td><code>#b22222</code></td> <td style="background: firebrick"></td> </tr> <tr> <td><code>floralwhite</code></td> <td><code>#fffaf0</code></td> <td style="background: floralwhite"></td> </tr> <tr> <td><code>forestgreen</code></td> <td><code>#228b22</code></td> <td style="background: forestgreen"></td> </tr> <tr> <td><code>fuchsia</code></td> <td><code>#ff00ff</code></td> <td style="background: fuchsia"></td> </tr> <tr> <td><code>gainsboro</code></td> <td><code>#dcdcdc</code></td> <td style="background: gainsboro"></td> </tr> <tr> <td><code>ghostwhite</code></td> <td><code>#f8f8ff</code></td> <td style="background: ghostwhite"></td> </tr> <tr> <td><code>gold</code></td> <td><code>#ffd700</code></td> <td style="background: gold"></td> </tr> <tr> <td><code>goldenrod</code></td> <td><code>#daa520</code></td> <td style="background: goldenrod"></td> </tr> <tr> <td><code>gray</code></td> <td><code>#808080</code></td> <td style="background: gray"></td> </tr> <tr> <td><code>green</code></td> <td><code>#008000</code></td> <td style="background: green"></td> </tr> <tr> <td><code>greenyellow</code></td> <td><code>#adff2f</code></td> <td style="background: greenyellow"></td> </tr> <tr> <td><code>grey</code></td> <td><code>#808080</code> (synonym of <code>gray</code>)</td> <td style="background: grey"></td> </tr> <tr> <td><code>honeydew</code></td> <td><code>#f0fff0</code></td> <td style="background: honeydew"></td> </tr> <tr> <td><code>hotpink</code></td> <td><code>#ff69b4</code></td> <td style="background: hotpink"></td> </tr> <tr> <td><code>indianred</code></td> <td><code>#cd5c5c</code></td> <td style="background: indianred"></td> </tr> <tr> <td><code>indigo</code></td> <td><code>#4b0082</code></td> <td style="background: indigo"></td> </tr> <tr> <td><code>ivory</code></td> <td><code>#fffff0</code></td> <td style="background: ivory"></td> </tr> <tr> <td><code>khaki</code></td> <td><code>#f0e68c</code></td> <td style="background: khaki"></td> </tr> <tr> <td><code>lavender</code></td> <td><code>#e6e6fa</code></td> <td style="background: lavender"></td> </tr> <tr> <td><code>lavenderblush</code></td> <td><code>#fff0f5</code></td> <td style="background: lavenderblush"></td> </tr> <tr> <td><code>lawngreen</code></td> <td><code>#7cfc00</code></td> <td style="background: lawngreen"></td> </tr> <tr> <td><code>lemonchiffon</code></td> <td><code>#fffacd</code></td> <td style="background: lemonchiffon"></td> </tr> <tr> <td><code>lightblue</code></td> <td><code>#add8e6</code></td> <td style="background: lightblue"></td> </tr> <tr> <td><code>lightcoral</code></td> <td><code>#f08080</code></td> <td style="background: lightcoral"></td> </tr> <tr> <td><code>lightcyan</code></td> <td><code>#e0ffff</code></td> <td style="background: lightcyan"></td> </tr> <tr> <td><code>lightgoldenrodyellow</code></td> <td><code>#fafad2</code></td> <td style="background: lightgoldenrodyellow"></td> </tr> <tr> <td><code>lightgray</code></td> <td><code>#d3d3d3</code></td> <td style="background: lightgray"></td> </tr> <tr> <td><code>lightgreen</code></td> <td><code>#90ee90</code></td> <td style="background: lightgreen"></td> </tr> <tr> <td><code>lightgrey</code></td> <td><code>#d3d3d3</code></td> <td style="background: lightgrey"></td> </tr> <tr> <td><code>lightpink</code></td> <td><code>#ffb6c1</code></td> <td style="background: lightpink"></td> </tr> <tr> <td><code>lightsalmon</code></td> <td><code>#ffa07a</code></td> <td style="background: lightsalmon"></td> </tr> <tr> <td><code>lightseagreen</code></td> <td><code>#20b2aa</code></td> <td style="background: lightseagreen"></td> </tr> <tr> <td><code>lightskyblue</code></td> <td><code>#87cefa</code></td> <td style="background: lightskyblue"></td> </tr> <tr> <td><code>lightslategray</code></td> <td><code>#778899</code></td> <td style="background: lightslategray"></td> </tr> <tr> <td><code>lightslategrey</code></td> <td><code>#778899</code></td> <td style="background: lightslategrey"></td> </tr> <tr> <td><code>lightsteelblue</code></td> <td><code>#b0c4de</code></td> <td style="background: lightsteelblue"></td> </tr> <tr> <td><code>lightyellow</code></td> <td><code>#ffffe0</code></td> <td style="background: lightyellow"></td> </tr> <tr> <td><code>lime</code></td> <td><code>#00ff00</code></td> <td style="background: lime"></td> </tr> <tr> <td><code>limegreen</code></td> <td><code>#32cd32</code></td> <td style="background: limegreen"></td> </tr> <tr> <td><code>linen</code></td> <td><code>#faf0e6</code></td> <td style="background: linen"></td> </tr> <tr> <td> <code>magenta</code><br /> </td> <td><code>#ff00ff</code> (synonym of <code>fuchsia</code>)</td> <td style="background: magenta"></td> </tr> <tr> <td><code>maroon</code></td> <td><code>#800000</code></td> <td style="background: maroon"></td> </tr> <tr> <td><code>mediumaquamarine</code></td> <td><code>#66cdaa</code></td> <td style="background: mediumaquamarine"></td> </tr> <tr> <td><code>mediumblue</code></td> <td><code>#0000cd</code></td> <td style="background: mediumblue"></td> </tr> <tr> <td><code>mediumorchid</code></td> <td><code>#ba55d3</code></td> <td style="background: mediumorchid"></td> </tr> <tr> <td><code>mediumpurple</code></td> <td><code>#9370db</code></td> <td style="background: mediumpurple"></td> </tr> <tr> <td><code>mediumseagreen</code></td> <td><code>#3cb371</code></td> <td style="background: mediumseagreen"></td> </tr> <tr> <td><code>mediumslateblue</code></td> <td><code>#7b68ee</code></td> <td style="background: mediumslateblue"></td> </tr> <tr> <td><code>mediumspringgreen</code></td> <td><code>#00fa9a</code></td> <td style="background: mediumspringgreen"></td> </tr> <tr> <td><code>mediumturquoise</code></td> <td><code>#48d1cc</code></td> <td style="background: mediumturquoise"></td> </tr> <tr> <td><code>mediumvioletred</code></td> <td><code>#c71585</code></td> <td style="background: mediumvioletred"></td> </tr> <tr> <td><code>midnightblue</code></td> <td><code>#191970</code></td> <td style="background: midnightblue"></td> </tr> <tr> <td><code>mintcream</code></td> <td><code>#f5fffa</code></td> <td style="background: mintcream"></td> </tr> <tr> <td><code>mistyrose</code></td> <td><code>#ffe4e1</code></td> <td style="background: mistyrose"></td> </tr> <tr> <td><code>moccasin</code></td> <td><code>#ffe4b5</code></td> <td style="background: moccasin"></td> </tr> <tr> <td><code>navajowhite</code></td> <td><code>#ffdead</code></td> <td style="background: navajowhite"></td> </tr> <tr> <td><code>navy</code></td> <td><code>#000080</code></td> <td style="background: navy"></td> </tr> <tr> <td><code>oldlace</code></td> <td><code>#fdf5e6</code></td> <td style="background: oldlace"></td> </tr> <tr> <td><code>olive</code></td> <td><code>#808000</code></td> <td style="background: olive"></td> </tr> <tr> <td><code>olivedrab</code></td> <td><code>#6b8e23</code></td> <td style="background: olivedrab"></td> </tr> <tr> <td><code>orange</code></td> <td><code>#ffa500</code></td> <td style="background: orange"></td> </tr> <tr> <td><code>orangered</code></td> <td><code>#ff4500</code></td> <td style="background: orangered"></td> </tr> <tr> <td><code>orchid</code></td> <td><code>#da70d6</code></td> <td style="background: orchid"></td> </tr> <tr> <td><code>palegoldenrod</code></td> <td><code>#eee8aa</code></td> <td style="background: palegoldenrod"></td> </tr> <tr> <td><code>palegreen</code></td> <td><code>#98fb98</code></td> <td style="background: palegreen"></td> </tr> <tr> <td><code>paleturquoise</code></td> <td><code>#afeeee</code></td> <td style="background: paleturquoise"></td> </tr> <tr> <td><code>palevioletred</code></td> <td><code>#db7093</code></td> <td style="background: palevioletred"></td> </tr> <tr> <td><code>papayawhip</code></td> <td><code>#ffefd5</code></td> <td style="background: papayawhip"></td> </tr> <tr> <td><code>peachpuff</code></td> <td><code>#ffdab9</code></td> <td style="background: peachpuff"></td> </tr> <tr> <td><code>peru</code></td> <td><code>#cd853f</code></td> <td style="background: peru"></td> </tr> <tr> <td><code>pink</code></td> <td><code>#ffc0cb</code></td> <td style="background: pink"></td> </tr> <tr> <td><code>plum</code></td> <td><code>#dda0dd</code></td> <td style="background: plum"></td> </tr> <tr> <td><code>powderblue</code></td> <td><code>#b0e0e6</code></td> <td style="background: powderblue"></td> </tr> <tr> <td><code>purple</code></td> <td><code>#800080</code></td> <td style="background: purple"></td> </tr> <tr> <td> <code>rebeccapurple</code> </td> <td><code>#663399</code></td> <td style="background: rebeccapurple"></td> </tr> <tr> <td><code>red</code></td> <td><code>#ff0000</code></td> <td style="background: red"></td> </tr> <tr> <td><code>rosybrown</code></td> <td><code>#bc8f8f</code></td> <td style="background: rosybrown"></td> </tr> <tr> <td><code>royalblue</code></td> <td><code>#4169e1</code></td> <td style="background: royalblue"></td> </tr> <tr> <td><code>saddlebrown</code></td> <td><code>#8b4513</code></td> <td style="background: saddlebrown"></td> </tr> <tr> <td><code>salmon</code></td> <td><code>#fa8072</code></td> <td style="background: salmon"></td> </tr> <tr> <td><code>sandybrown</code></td> <td><code>#f4a460</code></td> <td style="background: sandybrown"></td> </tr> <tr> <td><code>seagreen</code></td> <td><code>#2e8b57</code></td> <td style="background: seagreen"></td> </tr> <tr> <td><code>seashell</code></td> <td><code>#fff5ee</code></td> <td style="background: seashell"></td> </tr> <tr> <td><code>sienna</code></td> <td><code>#a0522d</code></td> <td style="background: sienna"></td> </tr> <tr> <td><code>silver</code></td> <td><code>#c0c0c0</code></td> <td style="background: silver"></td> </tr> <tr> <td><code>skyblue</code></td> <td><code>#87ceeb</code></td> <td style="background: skyblue"></td> </tr> <tr> <td><code>slateblue</code></td> <td><code>#6a5acd</code></td> <td style="background: slateblue"></td> </tr> <tr> <td><code>slategray</code></td> <td><code>#708090</code></td> <td style="background: slategray"></td> </tr> <tr> <td><code>slategrey</code></td> <td><code>#708090</code></td> <td style="background: slategrey"></td> </tr> <tr> <td><code>snow</code></td> <td><code>#fffafa</code></td> <td style="background: snow"></td> </tr> <tr> <td><code>springgreen</code></td> <td><code>#00ff7f</code></td> <td style="background: springgreen"></td> </tr> <tr> <td><code>steelblue</code></td> <td><code>#4682b4</code></td> <td style="background: steelblue"></td> </tr> <tr> <td><code>tan</code></td> <td><code>#d2b48c</code></td> <td style="background: tan"></td> </tr> <tr> <td><code>teal</code></td> <td><code>#008080</code></td> <td style="background: teal"></td> </tr> <tr> <td><code>thistle</code></td> <td><code>#d8bfd8</code></td> <td style="background: thistle"></td> </tr> <tr> <td><code>tomato</code></td> <td><code>#ff6347</code></td> <td style="background: tomato"></td> </tr> <tr> <td><code>transparent</code></td> <td>See <a href="#transparent">transparent</a>.</td> <td style="background: transparent"></td> </tr> <tr> <td><code>turquoise</code></td> <td><code>#40e0d0</code></td> <td style="background: turquoise"></td> </tr> <tr> <td><code>violet</code></td> <td><code>#ee82ee</code></td> <td style="background: violet"></td> </tr> <tr> <td><code>wheat</code></td> <td><code>#f5deb3</code></td> <td style="background: wheat"></td> </tr> <tr> <td><code>white</code></td> <td><code>#ffffff</code></td> <td style="background: white"></td> </tr> <tr> <td><code>whitesmoke</code></td> <td><code>#f5f5f5</code></td> <td style="background: whitesmoke"></td> </tr> <tr> <td><code>yellow</code></td> <td><code>#ffff00</code></td> <td style="background: yellow"></td> </tr> <tr> <td><code>yellowgreen</code></td> <td><code>#9acd32</code></td> <td style="background: yellowgreen"></td> </tr> <tr> </tbody> </table> Initially, in [CSS Level 1](https://www.w3.org/TR/REC-CSS1/#color-units), only 16 basic colors were defined, with `orange` added in [CSS Level 2](https://www.w3.org/TR/CSS2/syndata.html#value-def-color). Web designers found this list too short, and browser vendors added numerous names for colors based on the X11 color names. In [SVG 1.0](https://www.w3.org/TR/2001/REC-SVG-20010904/), then in [CSS Colors Level 3](https://www.w3.org/TR/css-color-3/#svg-color), these names got standardized, formally defined, and made uniform (some had different spellings that are now aliases). They are called _extended color keywords_, _X11 colors_, or _SVG colors_. In [CSS Colors Level 4](https://www.w3.org/TR/css-color-4/#named-colors), an additional color, `rebeccapurple` was added to honor [web pioneer Eric Meyer](https://meyerweb.com/eric/thoughts/2014/06/19/rebeccapurple/). ### transparent The `transparent` keyword represents a fully transparent color. This makes the background behind the colored item completely visible. Technically, `transparent` is a shortcut for `rgb(0 0 0 / 0%)`. To prevent unexpected behavior, such as in a {{cssxref("gradient")}}, the current CSS spec states that `transparent` should be calculated in the [alpha-premultiplied color space](https://www.w3.org/TR/css-color-4/#interpolation-alpha). However, be aware that older browsers may treat it as black with an alpha value of `0`. The `transparent` keyword wasn't a true color in CSS Level 2 (Revision 1). It was a special keyword that could be used instead of a regular `<color>` value on two CSS properties: {{Cssxref("background")}} and {{Cssxref("border")}}. It was essentially added to allow developers to override an inherited solid color. With the advent of alpha channels in CSS Colors Level 3, `transparent` was redefined as a true color. It can now be used wherever a `<color>` value can be used. ## Description All names specify a color in the [sRGB color space](https://en.wikipedia.org/wiki/SRGB). Although the names more or less describe their respective colors, they are essentially artificial, without a strict rationale behind the terms used. The color keywords all represent plain, solid colors without transparency. Several keywords are aliases for each other: - `aqua` / `cyan` - `fuchsia` / `magenta` - `darkgray` / `darkgrey` - `darkslategray` / `darkslategrey` - `dimgray` / `dimgrey` - `lightgray` / `lightgrey` - `lightslategray` / `lightslategrey` - `gray` / `grey` - `slategray` / `slategrey` Though many keywords have been adapted from [X11](https://en.wikipedia.org/wiki/X_Window_System), their RGB values may differ from the corresponding color on X11 systems since manufacturers sometimes tailor X11 colors to their specific hardware. ## Examples ### Using named colors #### HTML ```html <div id="container"> <div id="one"></div> <div id="two"></div> <div id="three"></div> </div> ``` #### CSS ```css #container { display: flex; justify-content: space-around; background-color: darkslateblue; padding: 20px; } #container > div { height: 100px; width: 100px; margin: 3px; border: 2px solid black; } #one { background-color: red; } #two { background-color: lavender; } #three { background-color: transparent; } ``` #### Result {{EmbedLiveSample("Using named colors")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`<color>`](/en-US/docs/Web/CSS/color_value): the data type of whose definition `<named-color>` is a constituent part.
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_-moz-broken/index.md
--- title: ":-moz-broken" slug: Web/CSS/:-moz-broken page-type: css-pseudo-class status: - non-standard browser-compat: css.selectors.-moz-broken --- {{CSSRef}}{{Non-standard_header}} The **`:-moz-broken`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) is a [Mozilla extension](/en-US/docs/Web/CSS/Mozilla_Extensions) that matches elements representing broken image links. > **Note:** This selector is mainly intended to be used by theme developers. ## Syntax ```css :-moz-broken { /* ... */ } ``` ## Examples ### HTML ```html <img src="broken.jpg" alt="This image is broken. :-(" /> ``` ### CSS ```css :-moz-broken { background: bisque; padding: 8px; } ``` ### Result {{EmbedLiveSample("Examples")}} ## Specifications Not part of any standard. ## Browser compatibility {{Compat}} ## See also - {{cssxref(":-moz-loading")}}, {{cssxref(":-moz-suppressed")}}, {{cssxref(":-moz-user-disabled")}} - [Firefox bug 11011](https://bugzil.la/11011)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/frequency/index.md
--- title: <frequency> slug: Web/CSS/frequency page-type: css-type browser-compat: css.types.frequency --- {{CSSRef}} The **`<frequency>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) represents a frequency dimension, such as the pitch of a speaking voice. It is not currently used in any CSS properties. ## Syntax The `<frequency>` data type consists of a {{cssxref("&lt;number&gt;")}} followed by one of the units listed below. As with all CSS dimensions, there is no space between the unit literal and the number. ### Units - `Hz` - : Represents a frequency in hertz. Examples: `0Hz`, `1500Hz`, `10000Hz`. - `kHz` - : Represents a frequency in kilohertz. Examples: `0kHz`, `1.5kHz`, `10kHz`. > **Note:** Although the number `0` is always the same regardless of unit, the unit may not be omitted. In other words, `0` is invalid and does not represent `0Hz` or `0kHz`. Though the units are case-insensitive, it is good practice to use a capital "H" for `Hz` and `kHz`, as specified in the [SI](https://en.wikipedia.org/wiki/International_System_of_Units). ## Examples Valid frequency values: ```plain example-good 12Hz Positive integer 4.3Hz Non-integer 14KhZ The unit is case-insensitive, though non-SI capitalization is not recommended. +0Hz Zero, with a leading + and a unit -0kHz Zero, with a leading - and a unit ``` Invalid frequency values: ```plain example-bad 12.0 This is a <number>, not an <frequency>, because it is missing a unit. 7 Hz No space is allowed between the number and the unit. 0 Although unitless zero is an allowable <length>, it's an invalid <frequency>. ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("&lt;frequency-percentage&gt;")}} - [CSS Values and Units](/en-US/docs/Web/CSS/CSS_Values_and_Units)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_box_alignment/index.md
--- title: CSS box alignment slug: Web/CSS/CSS_box_alignment page-type: css-module --- {{CSSRef}} The **CSS box alignment** module specifies CSS features that relate to the alignment of boxes in the various CSS box layout models: block layout, table layout, flex layout, and grid layout. The module aims to create a consistent method of alignment across all of CSS. This document details the general concepts found in the specification. > **Note:** The documentation for each layout method will detail how Box Alignment is applied there. ## Older alignment methods CSS traditionally had very limited alignment capabilities. We were able to align text using {{cssxref("text-align")}}, center blocks using auto {{cssxref("margin")}}s, and in table or inline-block layouts using the {{cssxref("vertical-align")}} property. Alignment of text is now covered by the [Inline Layout](https://www.w3.org/TR/css-inline-3/) and [CSS Text](https://www.w3.org/TR/css-text-3/) modules, and for the first time in Box Alignment we have full horizontal and vertical alignment capabilities. If you initially learned [Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout) then you may consider these properties to be part of the Flexbox specification, and some of the properties are indeed listed in Level 1 of Flexbox. However the specification notes that the Box Alignment specification should be referred to as it may add additional capabilities over what is currently in Flexbox. ## Basic examples The following examples demonstrate how some of the Box Alignment Properties are applied in [Grid](/en-US/docs/Web/CSS/CSS_grid_layout) and [Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout). ### CSS grid layout alignment example In this example using Grid Layout, there is extra space in the grid container after laying out the fixed width tracks on the inline (main) axis. This space is distributed using {{cssxref("justify-content")}}. On the block (cross) axis the alignment of the items inside their grid areas is controlled with {{cssxref("align-items")}}. The first item overrides the `align-items` value set on the group by setting {{cssxref("align-self")}} to `center`. {{EmbedGHLiveSample("css-examples/box-alignment/overview/grid-align-items.html", '100%', 700)}} ### Flexbox Alignment Example In this example, three flex items are aligned on the main axis using `justify-content` and on the Cross Axis using `align-items`. The first item overrides the `align-items` set on the group by setting `align-self` to `center`. {{EmbedGHLiveSample("css-examples/box-alignment/overview/flex-align-items.html", '100%', 700)}} ## Key concepts and terminology The specification details some alignment terminology to make it easier to discuss these alignment properties outside their implementation within a particular layout method. There are also some key concepts which are common to all layout methods. ### Relationship to writing modes Alignment is linked to writing modes in that when we align an item we do not consider whether we are aligning it to the physical dimensions of top, right, bottom and left. Instead we describe alignment in terms of the start and end of the particular dimension we are working with. This ensures that alignment works in the same way whichever writing mode the document has. ### Two dimensions of alignment When using the box alignment properties you will align content on one of two axes — the inline (or main) axis, and the block (or cross) axis. The inline axis is the axis along which words in a sentence flow in the writing mode being used — for English, for example, the inline axis is horizontal. The block axis is the axis along which blocks, such as paragraph elements, are laid out and it runs across the Inline axis. ![Inline axis is the left / right, or horizontal, direction. Block axis is vertical, or top / bottom.](two-axes.png) When aligning items on the inline axis you will use the properties which begin with `justify-`: - {{cssxref("justify-items")}} - {{cssxref("justify-self")}} - {{cssxref("justify-content")}} When aligning items on the block axis you will use the properties that begin `align-`: - {{cssxref("align-items")}} - {{cssxref("align-self")}} - {{cssxref("align-content")}} Flexbox adds an additional complication in that the above is true when {{cssxref("flex-direction")}} is set to `row`. The properties are swapped when flexbox is set to `column`. Therefore, when working with flexbox it is easier to think about the main and cross axis rather than inline and block. The `justify-` properties are always used to align on the main axis, the `align-` properties on the cross axis. ### The alignment subject The **alignment subject** is the thing that is being aligned. For `justify-self` or `align-self`, or when setting these values as a group with `justify-items` or `align-items`, this will be the margin box of the element that this property is being used on. The `justify-content` and `align-content` properties differ per layout method. ### The alignment container The **alignment container** is the box the subject is being aligned inside. This will typically be the alignment subject's containing block. An alignment container may contain one or many alignment subjects. The below image shows an alignment container with two alignment subjects inside. ![A box containing two rectangles of the same width but different heights. The two rectangles are top aligned, meaning they both have their top lines about 10px inside the top of the box in which they are contained.](align-container-subjects.png) ### Fallback alignment If you set an alignment that cannot be fulfilled, then the **fallback alignment** will come into play and deal with the available space. This fallback alignment is specified individually for each layout method and detailed on the page for that method. ## Types of alignment There are three different types of alignment that the specification details; these use keyword values. - **Positional alignment**: specifying the position of an alignment subject with relation to its alignment container. - **Baseline alignment**: These keywords define alignment as a relationship among the baselines of multiple alignment subjects within an alignment context. - **Distributed alignment**: These keywords define alignment as a distribution of space among alignment subjects. ### Positional alignment keyword values The following values are defined for positional alignment, and can be used as values for content alignment with `justify-content` and `align-content` and also for self alignment with `justify-self` and `align-self`. - `center` - `start` - `end` - `self-start` - `self-end` - `flex-start` for Flexbox only - `flex-end` for Flexbox only - `left` - `right` Other than the physical values of `left` and `right`, which relate to physical attributes of the screen, all of the other values are logical values and relate to the writing mode of the content. For example, when working in CSS Grid Layout, if you are working in English and set `justify-content` to `start` this will move the items in the inline dimension to the start, which will be the left as sentences in English start on the left. If you were using Arabic, a right to left language, then the same value of `start` would result in the items moving to the right, as sentences in Arabic start on the right-hand side of the page. Both of these examples have `justify-content: start`, however the location of start changes according to the writing mode. ![There are two boxes, each with 3 children of differing heights but similar widths. The first box has three children with the letters A, B, and C. These three boxes are all aligned to the left. The second box has three children with arabic letters in them. Those three boxes are all aligned to the right.](writing-mode-start.png) ### Baseline alignment The Baseline alignment keywords are used to align the baselines of boxes across a group of alignment subjects. They can be used as values for content alignment with `justify-content` and `align-content` and also for self alignment with `justify-self` and `align-self`. - `baseline` - `first baseline` - `last baseline` Baseline content alignment — specifying a baseline alignment value for `justify-content` or `align-content` — works in layout methods that lay items out in rows. The alignment subjects are baseline aligned against each other by adding padding inside the boxes. Baseline self alignment shifts the boxes to align by baseline by adding a margin outside the boxes. Self alignment is when using `justify-self` or `align-self`, or when setting these values as a group with `justify-items` and `align-items`. ### Distributed alignment The **distributed alignment keywords** are used with the `align-content` and `justify-content` properties. These keywords define what happens to any additional space after alignment subjects have been displayed. The values are as follows: - `stretch` - `space-between` - `space-around` - `space-evenly` For example, in Flex Layout items are aligned with `flex-start` initially. Working in a horizontal top to bottom writing mode such as English, with `flex-direction` as `row` the items start on the far left and any available space after displaying the items is placed after the items. ![Three rectangles of different widths are inside a box. They are all aligned to the left side of the containing box, with about 10px between them, and 10px between the left side of the first rectangle and the parent container.](justify-content-start.png) If you set `justify-content: space-between` on the flex container, the available space is now shared out and placed between the items. ![Three rectangles of different widths are inside a box. The first rectangle is aligned to the left side of the containing box, the third rectangle is aligned right, and the middle rectangle is equally spaced between the first and last.](justify-content-space-between.png) There needs to be space available in the dimension you wish to align the items in, in order for these keywords to take effect. With no space, there is nothing to distribute. ## Overflow alignment The `safe` and `unsafe` keywords help define behavior when an alignment subject is larger than the alignment container. The `safe` keyword will align to `start` in the case of a specified alignment causing an overflow, the aim being to avoid "data loss" where part of the item is outside the boundaries of the alignment container and can't be scrolled to. If you specify `unsafe` then the alignment will be honoured even if it would cause such data loss. ## Gaps between boxes The box alignment specification also includes the `gap`, `row-gap`, and `column-gap` properties. These properties enable the setting of a consistent gap between items in a row or column, in any layout method which has items arranged in this way. The `gap` property is a shorthand for `row-gap` and `column-gap`, which allows us to set these properties at once: - {{cssxref("row-gap")}} - {{cssxref("column-gap")}} - {{cssxref("gap")}} In the below example, a grid layout uses the `gap` shorthand to set a `10px` gap between row tracks, and a `2em` gap between column tracks. {{EmbedGHLiveSample("css-examples/box-alignment/overview/grid-gap.html", '100%', 700)}} > **Note:** The early grid implementation included `-gap` properties prefixed with `grid-`. All browsers now support the unprefixed properties, though you may see the following legacy properties in examples and tutorials: {{cssxref("row-gap", "grid-row-gap")}}, {{cssxref("column-gap", "grid-column-gap")}}, and {{cssxref("gap", "grid-gap")}}. The prefixed versions will be maintained as an alias of the unprefixed ones. Be aware that other things may increase the visual gap displayed, for example using the space distribution keywords or adding margins to items. ## Pages detailing individual alignment properties As the CSS box alignment properties are implemented differently depending on the specification they interact with, refer to the following pages for each layout type for details of how to use the alignment properties with it: - [Box alignment in Flexbox](/en-US/docs/Web/CSS/CSS_box_alignment/Box_alignment_in_flexbox) - [Box alignment in CSS Grid Layout](/en-US/docs/Web/CSS/CSS_box_alignment/Box_alignment_in_grid_layout) - [Box alignment in multiple-column layout](/en-US/docs/Web/CSS/CSS_box_alignment/Box_alignment_in_multi-column_layout) - [Box alignment for block, absolutely positioned and table layout](/en-US/docs/Web/CSS/CSS_box_alignment/Box_alignment_in_block_abspos_tables) ## Reference ### CSS Properties - {{cssxref("justify-content")}} - {{cssxref("align-content")}} - {{cssxref("place-content")}} - {{cssxref("justify-items")}} - {{cssxref("align-items")}} - {{cssxref("place-items")}} - {{cssxref("justify-self")}} - {{cssxref("align-self")}} - {{cssxref("place-self")}} - {{cssxref("row-gap")}} - {{cssxref("column-gap")}} - {{cssxref("gap")}} ### Glossary Entries - {{Glossary("Cross axis")}} - {{Glossary("Main axis")}} - {{Glossary("Alignment container")}} - {{Glossary("Alignment subject")}} - {{Glossary("Fallback alignment")}} ## Guides - CSS Flexbox guide: _[Basic concepts of Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox)_ - CSS Flexbox guide: _[Aligning items in a flex container](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Aligning_items_in_a_flex_container)_ - CSS Grid guide: _[Box alignment in CSS Grid layouts](/en-US/docs/Web/CSS/CSS_grid_layout/Box_alignment_in_grid_layout)_ ## External Resources - [CSS Grid, Flexbox and Box alignment](https://www.smashingmagazine.com/2016/11/css-grids-flexbox-box-alignment-new-layout-standard/) - [Thoughts on partial implementations of Box alignment](https://blogs.igalia.com/jfernandez/2017/05/03/can-i-use-css-box-alignment/)
0
data/mdn-content/files/en-us/web/css/css_box_alignment
data/mdn-content/files/en-us/web/css/css_box_alignment/box_alignment_in_multi-column_layout/index.md
--- title: Box alignment in multi-column layout slug: Web/CSS/CSS_box_alignment/Box_alignment_in_multi-column_layout page-type: guide --- {{CSSRef}} The [box alignment](/en-US/docs/Web/CSS/CSS_box_alignment) specification details how alignment works in various layout methods; on this page we explore how Box Alignment works in the context of [multi-column Layout](/en-US/docs/Web/CSS/CSS_multicol_layout). As this page aims to detail things which are specific to Multi-column Layout and Box Alignment, it should be read in conjunction with the main [box alignment](/en-US/docs/Web/CSS/CSS_box_alignment) page which details the common features of Box Alignment across layout methods. In multi-column layout the alignment container is the content box of the multicol container. The alignment subject is the column box. The properties which apply to multi-column layouts are detailed below. > **Note:** Multi-column layout predates the box alignment specification. And the properties listed here, while specified for Multicol, may not be supported in browsers. ## align-content and justify-content The {{cssxref("align-content")}} property applies to the block axis and {{cssxref("justify-content")}} to the inline axis. Any spacing added to the columns due to use of space distribution will be added to the gap between the columns, therefore making the gap larger than might be specified by the {{cssxref("column-gap")}} property. Using a value of `justify-content` other than `normal` or `stretch` will cause column boxes to display at the {{cssxref("column-width")}} specified on the multicol container, and the remaining space distributed according to the value of justify-content. ## column-gap The {{cssxref("column-gap")}} property was specified in earlier versions of the multiple-column layout specification, and has now been unified with the gap properties for other layout methods in box alignment. While other layout methods treat the initial value of column-gap as 0 multicol treats it as 1em, as in general you would not want to have no gap between columns. ## Reference ### CSS Properties - {{cssxref("justify-content")}} - {{cssxref("align-content")}} - {{cssxref("column-gap")}} ### Glossary Entries - [Alignment subject](/en-US/docs/Glossary/Alignment_Subject) - [Alignment container](/en-US/docs/Glossary/Alignment_Container) - [Fallback alignment](/en-US/docs/Glossary/Fallback_Alignment)
0
data/mdn-content/files/en-us/web/css/css_box_alignment
data/mdn-content/files/en-us/web/css/css_box_alignment/box_alignment_in_grid_layout/index.md
--- title: Box alignment in grid layout slug: Web/CSS/CSS_box_alignment/Box_alignment_in_grid_layout page-type: guide --- {{CSSRef}} The [box alignment](/en-US/docs/Web/CSS/CSS_box_alignment) specification details how alignment works in various layout methods. On this page we explore how box alignment works in the context of [CSS grid layout](/en-US/docs/Web/CSS/CSS_grid_layout). As this page aims to detail things which are specific to CSS Grid Layout and Box Alignment, it should be read in conjunction with the main [box alignment](/en-US/docs/Web/CSS/CSS_box_alignment) page which details the common features of box alignment across layout methods. ## Basic example In this example using grid layout, there is extra space in the grid container after laying out the fixed width tracks on the inline (main) axis. This space is distributed using `justify-content`. On the block (cross) axis the alignment of the items inside their grid areas is controlled with `align-items`. The first item overrides the `align-items` value set on the group by setting `align-self` to `center`. {{EmbedGHLiveSample("css-examples/box-alignment/overview/grid-align-items.html", '100%', 500)}} ## Grid axes As a two-dimensional layout method, when working with grid layout we always have two axes on which to align our items. We have access to all of the box alignment properties to help us achieve this. The inline axis is the axis that corresponds to the direction that words in a sentence would run in the writing mode used. Therefore, in a horizontal language such as English or Arabic the inline direction runs horizontally. Should you be in a vertical writing mode the inline axis will run vertically. ![Inline axes are horizontal.](inline_axis.png) To align things on the inline axis you use the properties that start with `justify-`, {{cssxref("justify-content")}}, {{cssxref("justify-items")}} and {{cssxref("justify-self")}}. The block axis crosses the inline axis in the direction that blocks are displayed down the page — for example paragraphs in English are displayed one below the other vertically. This, therefore is the block dimension. To align things on the block axis you use the properties that start with `align-`, {{cssxref("align-content")}}, {{cssxref("align-items")}} and {{cssxref("align-self")}}. ![The block axes are vertical.](block_axis.png) ## Self alignment - {{cssxref("justify-self")}} - {{cssxref("align-self")}} - {{cssxref("place-self")}} - {{cssxref("justify-items")}} - {{cssxref("align-items")}} - {{cssxref("place-items")}} These properties deal with aligning the item inside the grid area it is placed into. The properties `align-items` and `justify-items` are applied to the grid container and set the `align-self` and `justify-self` properties as a group. This means that you can set alignment for all of your grid Items at once, then override any items that need a different alignment by applying the `align-self` or `justify-self` property to the rules for the individual grid Items. The initial value for `align-self` and `justify-self` is `stretch` so the item will stretch over the entire grid area. The exception to this rule is where the item has an intrinsic aspect ratio, for example an image. In this case the item will be aligned to `start` in both dimensions in order that the image is not distorted. ## Content alignment - {{cssxref("justify-content")}} - {{cssxref("align-content")}} - {{cssxref("place-content")}} These properties deal with aligning the tracks of the grid when there is extra space to distribute. This scenario will occur if the tracks that you have defined total less than the total width of the grid container. ## Gap and legacy grid-gap properties - {{cssxref("row-gap")}} - {{cssxref("column-gap")}} - {{cssxref("gap")}} The Grid specification originally contained the definition for the properties {{cssxref("row-gap", "grid-row-gap")}}, {{cssxref("column-gap", "grid-column-gap")}} and {{cssxref("gap", "grid-gap")}}. These have since been moved into the Box Alignment specification and renamed to {{cssxref("row-gap")}}, {{cssxref("column-gap")}}, and {{cssxref("gap")}}. This allows them to be used for other layout methods where a gap between items makes sense. The updated properties have not yet been implemented in all browsers. Therefore, to use the gap properties in grid layout, you should use the `grid-row-gap`, `grid-column-gap` and `grid-gap` versions to ensure full compatibility. You could double up the properties and use both as you would for vendor prefixes. ## Reference ### CSS Properties - {{cssxref("justify-content")}} - {{cssxref("align-content")}} - {{cssxref("place-content")}} - {{cssxref("justify-items")}} - {{cssxref("align-items")}} - {{cssxref("place-items")}} - {{cssxref("justify-self")}} - {{cssxref("align-self")}} - {{cssxref("place-self")}} - {{cssxref("row-gap")}} - {{cssxref("column-gap")}} - {{cssxref("gap")}} ### Glossary Entries - [Cross Axis](/en-US/docs/Glossary/Cross_Axis) - [Main Axis](/en-US/docs/Glossary/Main_Axis) ## Guides - [Alignment in grid layout](/en-US/docs/Web/CSS/CSS_grid_layout/Box_alignment_in_grid_layout) ## External Resources - [CSS Grid, Flexbox and Box Alignment](https://www.smashingmagazine.com/2016/11/css-grids-flexbox-box-alignment-new-layout-standard/) - [Thoughts on partial implementations of Box Alignment](https://blogs.igalia.com/jfernandez/2017/05/03/can-i-use-css-box-alignment/)
0
data/mdn-content/files/en-us/web/css/css_box_alignment
data/mdn-content/files/en-us/web/css/css_box_alignment/box_alignment_in_flexbox/index.md
--- title: Box alignment in flexbox slug: Web/CSS/CSS_box_alignment/Box_alignment_in_flexbox page-type: guide --- {{CSSRef}} The [box alignment](/en-US/docs/Web/CSS/CSS_box_alignment) Specification details how alignment works in various layout methods; on this page, we explore how box alignment works in the context of Flexbox. As this page aims to detail things which are specific to Flexbox and box alignment, it should be read in conjunction with the main [box alignment](/en-US/docs/Web/CSS/CSS_box_alignment) page which details the common features of box alignment across layout methods. ## Basic example In this example, three flex items are aligned on the main axis using {{cssxref("justify-content")}} and on the cross axis using {{cssxref("align-items")}}. The first item overrides the `align-items` values set on the group by setting {{cssxref("align-self")}} to `center`. {{EmbedGHLiveSample("css-examples/box-alignment/overview/flex-align-items.html", '100%', 500)}} ## The axes and flex-direction Flexbox respects the writing mode of the document, therefore if you are working in English and set {{cssxref("justify-content")}} to `flex-end` this will align the items to the end of the flex container. If you are working with {{cssxref("flex-direction")}} set to `row`, this alignment will be in the inline direction. However, in Flexbox you can change the main axis by setting `flex-direction` to `column`. In this case, `justify-content` will align items in the block direction. Therefore it is easiest to think about the main and cross axis when working in Flexbox like so: - The main axis = direction set by `flex-direction` = alignment via `justify-content` - The cross axis = runs across the main axis = alignment via `align-content`, `align-self`/`align-items` ### Main Axis Alignment - {{cssxref("justify-content")}} ### Cross Axis Alignment - {{cssxref("align-self")}} - {{cssxref("align-items")}} - {{cssxref("align-content")}} ### There is no justify-self in Flexbox On the main axis, Flexbox deals with our content as a group. The amount of space required to lay out the items is calculated, and the leftover space is then available for distribution. The `justify-content` property controls how that leftover space is used. Set `justify-content: flex-end` and the extra space is placed before the items, `justify-content: space-around` and it is placed either side of the item in that dimension, etc. This means that a `justify-self` property does not make sense in Flexbox as we are always dealing with moving the entire group of items around. On the cross axis `align-self` makes sense as we potentially have additional space in the flex container in that dimension, in which a single item can be moved to the start and end. ## Alignment and auto margins There is a specific use case in Flexbox where we might think that a `justify-self` property is what we need, and this is when we want to split a set of flex items, perhaps to create a split navigation pattern. For this use case, we can use an `auto` margin. A margin set to `auto` will absorb all available space in its dimension. This is how centering a block with auto margins works. By setting the left and right margin to `auto`, both sides of our block try to take up all of the available space and so push the box into the center. By setting a {{cssxref("margin")}} of `auto` on one item in a set of flex items all aligned to start, we can create a split navigation. This works well with Flexbox and the alignment properties. As soon as there is no space available for the auto margin, the item behaves in the same way as all the other flex items and shrinks to try to fit into space. {{EmbedGHLiveSample("css-examples/box-alignment/flexbox/auto-margins.html", '100%', 500)}} ## The `gap` properties - {{cssxref("row-gap")}} - {{cssxref("column-gap")}} - {{cssxref("gap")}} ### Creating fixed size gaps between items On the main axis, the `column-gap` property creates fixed size gaps between adjacent items. On the cross axis the `row-gap` property creates spacing between adjacent flex lines, therefore `flex-wrap` must also be set to `wrap` for this to have any effect. {{EmbedGHLiveSample("css-examples/box-alignment/flexbox/gap.html", '100%', 700)}} ## Reference ### CSS Properties - {{cssxref("justify-content")}} - {{cssxref("align-content")}} - {{cssxref("place-content")}} - {{cssxref("justify-items")}} - {{cssxref("align-items")}} - {{cssxref("place-items")}} - {{cssxref("align-self")}} - {{cssxref("row-gap")}} - {{cssxref("column-gap")}} - {{cssxref("gap")}} ### Glossary Entries - {{Glossary("Cross axis")}} - {{Glossary("Main axis")}} ## Guides - [Alignment in flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Aligning_items_in_a_flex_container) ## External Resources - [CSS Grid, Flexbox and Box Alignment](https://www.smashingmagazine.com/2016/11/css-grids-flexbox-box-alignment-new-layout-standard/) - [Thoughts on partial implementations of Box Alignment](https://blogs.igalia.com/jfernandez/2017/05/03/can-i-use-css-box-alignment/)
0
data/mdn-content/files/en-us/web/css/css_box_alignment
data/mdn-content/files/en-us/web/css/css_box_alignment/box_alignment_in_block_abspos_tables/index.md
--- title: Box alignment for block, absolutely positioned, and table layouts slug: Web/CSS/CSS_box_alignment/Box_alignment_in_block_abspos_tables page-type: guide --- The [box alignment specification](/en-US/docs/Web/CSS/CSS_box_alignment) details how alignment works in various layout methods. In this page we explore how box alignment works in the context of block layout, including floated, positioned, and table elements. As this page aims to detail things which are specific to block layout and box alignment, it should be read in conjunction with the main [box alignment](/en-US/docs/Web/CSS/CSS_box_alignment) page, which details the common features of box alignment across layout methods. > **Note:** At the time of writing (May 2018), there is no real support for the box alignment properties in block layout. This document details how the specification expects these properties to be implemented for completeness, and is likely to change as the specification and browser implementations develop. ## align-content and justify-content The {{cssxref("justify-content")}} property does not apply to block containers or table cells. The {{cssxref("align-content")}} property applies to the block axis in order to align the contents of the box within its container. If a content distribution method such as `space-between`, `space-around` or `space-evenly` is requested then the fallback alignment will be used, as the content is treated as a single [alignment subject](/en-US/docs/Glossary/Alignment_Subject). ## justify-self The {{cssxref("justify-self")}} property is used to align an item inside its containing block on the inline axis. This property does not apply to floated elements or table cells. ## align-self The {{cssxref("align-self")}} property does not apply to block-level boxes (including floats), because there is more than one item in the block axis. It also does not apply to table cells. ### Absolutely positioned elements The alignment container is the positioned block, accounting for the offset values of top, left, bottom, and right. The normal keyword resolves to `stretch`, unless the positioned item is a replaced element, in which case it resolves to `start`. ## Aligning in these layout methods today As we do not currently have browser support for box alignment in block layout, your options for alignment are either to use one of the existing alignment methods or, to make even a single item inside a container a flex item in order to use the alignment properties as specified in flexbox. Alignment of blocks horizontally prior to flexbox was typically achieved by way of setting auto margins on the block. A {{cssxref("margin")}} of `auto` will absorb all available space in that dimension, therefore setting a left and right margin of auto, you can push a block into the center: ```css .container { width: 20em; margin-left: auto; margin-right: auto; } ``` In table layout, you have access to the {{cssxref("vertical-align")}} property to align the contents of a cell inside that cell. For many use cases, turning the block container into a flex item will give you the alignment capability that you are looking for. In the example below, a container with a single item inside has been turned into a flex container for the purpose of being able to use the alignment properties. {{EmbedGHLiveSample("css-examples/flexbox/alignment/intro.html", '100%', 700)}} ## Reference ### CSS Properties - {{cssxref("justify-content")}} - {{cssxref("align-content")}} - {{cssxref("justify-self")}} - {{cssxref("align-self")}} ### Glossary Entries - [Alignment subject](/en-US/docs/Glossary/Alignment_Subject) - [Alignment container](/en-US/docs/Glossary/Alignment_Container) - [Fallback alignment](/en-US/docs/Glossary/Fallback_Alignment) {{CSSRef}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/appearance/index.md
--- title: appearance slug: Web/CSS/appearance page-type: css-property browser-compat: css.properties.appearance --- {{CSSRef}} The **`appearance`** CSS property is used to display UI elements with platform-specific styling, based on the operating system's theme. {{EmbedInteractiveExample("pages/css/appearance.html")}} Before standardization, this property allowed elements to be shown as widgets, such as buttons or check boxes. It was considered a misfeature and authors are encouraged to use only standard keywords now. > **Note:** If you wish to use this property on websites, you should test it very carefully. Although it is supported in most modern browsers, its implementation varies. In older browsers, even the keyword `none` does not have the same effect on all form elements across different browsers, and some do not support it at all. The differences are smaller in the newest browsers. ## Syntax ```css /* CSS Basic User Interface Module Level 4 values */ appearance: none; appearance: auto; appearance: menulist-button; appearance: textfield; /* Global values */ appearance: inherit; appearance: initial; appearance: revert; appearance: revert-layer; appearance: unset; /* <compat-auto> values have the same effect as 'auto' */ appearance: button; appearance: checkbox; ``` ### Values For the following keywords, the user agent selects the appropriate styling based on the element. Some examples are provided, but the list is not exhaustive. - `none` - : Hides certain features of widgets, such as arrow displayed in select element, indicating that list can be expanded. - `auto` - : Acts as `none` on elements with no special styling. - `<compat-special>` - : One of `menulist-button` or `textfield`. Both of these values are equivalent to `auto` on elements with no special styling. - `<compat-auto>` - : Possible values are `button`, `checkbox`, `listbox`, `menulist`, `meter`, `progress-bar`, `push-button`, `radio`, `searchfield`, `slider-horizontal`, `square-button`, and `textarea`. Keywords which are the equivalent of `auto` for maintaining compatibility with older browsers. #### Non-standard values The following values may be operational on historical browser versions using **`-moz-appearance`** or **`-webkit-appearance`** prefix, but not on the standard **`appearance`** property. <details> <summary>Non-standard values</summary> - Firefox entries indicate support using `-moz-appearance`. - Chrome, Edge and Safari entries below indicate release version support for values used with the `-webkit-appearance` vendor-prefix property. - Values with an asterisk (\*) have clear intents for removal. - For each cell of browser version and value: - `Y{version}`: indicates a value is supported up to and including `{version}` - `N{version}`: support was removed in a release earlier than `{version}` - a blank cell indicates that support was never added | Value | Safari | Firefox | Chrome | Edge | | -------------------------------------- | ------- | ------- | --------- | ------ | | `attachment` | Y(13.1) | | | | | `borderless-attachment` | Y(13.1) | | | | | `button-bevel` | Y(13.1) | N(75) | | N(80) | | `caps-lock-indicator` | Y(13.1) | | | N(80) | | `caret` | Y(13.1) | N(75) | Y(73) | N(80) | | `checkbox-container` | | N(75) | | | | `checkbox-label` | | N(75) | | | | `checkmenuitem` | | N(75) | | | | `color-well` | Y(13.1) | | | | | `continuous-capacity-level-indicator` | Y(13.1) | | | | | `default-button` | Y(13.1) | | | N(80) | | `discrete-capacity-level-indicator` | Y(13.1) | | | | | `inner-spin-button` | Y(13.1) | N(75) | Y(118) \* | Y(119) | | `image-controls-button` | Y(13.1) | | | | | `list-button` | Y(13.1) | | | | | `listitem` | Y(13.1) | N(75) | Y(73) | N(80) | | `media-enter-fullscreen-button` | Y(13.1) | | Y(73) | | | `media-exit-fullscreen-button` | Y(13.1) | | Y(73) | | | `media-fullscreen-volume-slider` | Y(13.1) | | | | | `media-fullscreen-volume-slider-thumb` | Y(13.1) | | | | | `media-mute-button` | Y(13.1) | | | N(80) | | `media-play-button` | Y(13.1) | | | N(80) | | `media-overlay-play-button` | Y(13.1) | | Y(73) | | | `media-return-to-realtime-button` | Y(13.1) | | | | | `media-rewind-button` | Y(13.1) | | | | | `media-seek-back-button` | Y(13.1) | | N(73) | | | `media-seek-forward-button` | Y(13.1) | | N(73) | | | `media-toggle-closed-captions-button` | Y(13.1) | | Y(73) | | | `media-slider` | Y(13.1) | | Y(117) | Y(80) | | `media-sliderthumb` | Y(13.1) | | Y(117) | Y(80) | | `media-volume-slider-container` | Y(13.1) | | Y(73) | | | `media-volume-slider-mute-button` | Y(13.1) | | | | | `media-volume-slider` | Y(13.1) | | Y(117) | Y(80) | | `media-volume-sliderthumb` | Y(13.1) | | Y(117) | Y(80) | | `media-controls-background` | Y(13.1) | | Y(73) | | | `media-controls-dark-bar-background` | Y(13.1) | | | | | `media-controls-fullscreen-background` | Y(13.1) | | Y(73) | | | `media-controls-light-bar-background` | Y(13.1) | | | | | `media-current-time-display` | | | Y(73) | | | `media-time-remaining-display` | Y(13.1) | | Y(73) | | | `menulist-text` | Y(13.1) | N(75) | Y(73) | N(80) | | `menulist-textfield` | Y(13.1) | N(75) | Y(73) | N(80) | | `meterbar` | | Y(100) | | | | `number-input` | | Y(75) | | | | `progress-bar-value` | Y(13.1) | | Y(73) | | | `progressbar` | | Y(100) | | | | `progressbar-vertical` | | Y(75) | | | | `range` | | Y(75) | | | | `range-thumb` | | Y(75) | | | | `rating-level-indicator` | Y(13.1) | | | | | `relevancy-level-indicator` | Y(13.1) | | | | | `scale-horizontal` | | Y(75) | | | | `scalethumbend` | | Y(75) | | | | `scalethumb-horizontal` | | Y(75) | | | | `scalethumbstart` | | Y(75) | | | | `scalethumbtick` | | Y(75) | | | | `scalethumb-vertical` | | Y(75) | | | | `scale-vertical` | | Y(75) | | | | `scrollbarthumb-horizontal` | | Y(75) | | | | `scrollbarthumb-vertical` | | Y(75) | | | | `scrollbartrack-horizontal` | | Y(75) | | | | `scrollbartrack-vertical` | | Y(75) | | | | `searchfield-decoration` | Y(13.1) | | | N(80) | | `searchfield-results-decoration` | Y(13.1) | N(75) | N(73) | N(80) | | `searchfield-results-button` | Y(13.1) | | | N(80) | | `searchfield-cancel-button` | Y(13.1) | N(75) | Y(118) \* | Y(119) | | `snapshotted-plugin-overlay` | Y(13.1) | | | | | `sheet` | | | | | | `slider-vertical` | | | Y(118) \* | Y(119) | | `sliderthumb-horizontal` | | | Y(117) | Y(80) | | `sliderthumb-vertical` | | | Y(117) | Y(80) | | `textfield-multiline` | | Y(100) | | | | `-apple-pay-button` | Y(13.1) | | | | </details> ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Apply custom styling The following example shows how to remove the default styling from a checkbox and select element, and apply custom styling. The appearance of the checkbox is changed to a circle, and the select element shows how to remove the arrow indicating that the list can be expanded. #### HTML ```html <input type="checkbox" /> <input type="checkbox" checked /> <select> <option>default</option> <option>option 2</option> </select> <select class="none"> <option>appearance: none</option> <option>option 2</option> </select> ``` #### CSS ```css input { appearance: none; width: 1em; height: 1em; display: inline-block; background: red; } input:checked { border-radius: 50%; background: green; } select { border: 1px solid black; font-size: 1em; } select.none { appearance: none; } ``` #### Result {{EmbedLiveSample("Apply_custom_styling", 1050, 100)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`prefers-color-scheme`](/en-US/docs/Web/CSS/@media/prefers-color-scheme)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_syntax/index.md
--- title: CSS syntax slug: Web/CSS/CSS_syntax page-type: css-module spec-urls: https://drafts.csswg.org/css-syntax --- {{CSSRef}} The **CSS syntax** module describes, in general terms, the structure and syntax of cascading stylesheets, or CSS. It defines CSS as the language for describing the rendering of structured documents (such as HTML and XML), on the web and elsewhere. This module doesn't define any properties, [data types](/en-US/docs/Web/CSS/CSS_Types), [functions](/en-US/docs/Web/CSS/CSS_Functions), or [at-rules](/en-US/docs/Web/CSS/At-rule). Rather, it elaborates on how all of these features should be defined and how user agents should parse CSS. ## At-rules - none > **Note:** The module explicitly states that {{cssxref("@charset")}} is not an actual at-rule, but rather an unrecognized legacy rule that should be omitted when a stylesheet is grammar-checked. ## Reference ### Key concepts - {{cssxref("at-rule")}} - [character escaping](/en-US/docs/Web/CSS/custom-ident#escaping_characters) - [CSS comments](/en-US/docs/Web/CSS/Comments) - [CSS declaration](/en-US/docs/Web/API/CSS_Object_Model/CSS_Declaration) - [CSS declaration block](/en-US/docs/Web/API/CSS_Object_Model/CSS_Declaration_Block) - [CSS function](/en-US/docs/Web/CSS/CSS_Functions) - [invalid](/en-US/docs/Web/CSS/CSS_syntax/Error_handling) - [style rule](/en-US/docs/Web/API/CSSStyleRule) ### Glossary terms - {{glossary("CSS_Descriptor", "CSS descriptor")}} - {{glossary("parse")}} - {{glossary("stylesheet")}} - {{glossary("whitespace")}} ## Guides - [Syntax](/en-US/docs/Web/CSS/Syntax) - : Overview of CSS syntax, including CSS declarations, declaration blocks, rulesets, and statements. - [Value definition syntax](/en-US/docs/Web/CSS/Value_definition_syntax) - : Explains the formal grammar for defining valid values for CSS properties and functions, along with semantic constraints. A guide for understanding CSS component value types, combinators, and multipliers. - [CSS syntax error handling](/en-US/docs/Web/CSS/CSS_syntax/Error_handling) - : Overview of how the user agent handles invalid CSS. - [Learn CSS first steps: CSS syntax](/en-US/docs/Learn/CSS/First_steps/What_is_CSS#css_syntax) - : Introductory guide to CSS, including an introduction to CSS syntax. ## Related concepts [CSS selectors](/en-US/docs/Web/CSS/CSS_selectors) module: - [CSS specificity](/en-US/docs/Web/CSS/Specificity) [CSS cascade](/en-US/docs/Web/CSS/CSS_cascade) module: - {{cssxref("@import")}} at-rule - {{cssxref("important")}} flag - [Initial values](/en-US/docs/Web/CSS/initial_value) - [Computed values](/en-US/docs/Web/CSS/computed_value) - [Used values](/en-US/docs/Web/CSS/used_value) - [Actual values](/en-US/docs/Web/CSS/actual_value) - [CSS inheritance](/en-US/docs/Web/CSS/Inheritance) - {{Glossary("Property/CSS", "CSS property")}} [CSS custom properties for cascading variables](/en-US/docs/Web/CSS/CSS_cascading_variables) module: - [custom property (`--*`)](/en-US/docs/Web/CSS/--*) - {{cssxref("var")}} function [CSS conditional rules](/en-US/docs/Web/CSS/CSS_conditional_rules) module: - {{cssxref("@media")}} at-rule - {{cssxref("@supports")}} at-rule [CSS Object Model (CSSOM)](/en-US/docs/Web/API/CSS_Object_Model) API: - {{domxref("CSSValue.cssText", "cssText")}} property - {{domxref("CSSStyleSheet.insertRule()", "insertRule(rule)")}} method - {{domxref("CSSStyleSheet.replace()", "replace(text)")}} method [WHATWG](/en-US/docs/Glossary/WHATWG) specification: - {{HTMLElement("style")}} element - {{HTMLElement("link")}} element - [`class`](/en-US/docs/Web/HTML/Global_attributes/class) attribute - [`rel`](/en-US/docs/Web/HTML/Attributes/rel#stylesheet) attribute ## Specifications {{Specifications}} ## See also - [CSS selectors](/en-US/docs/Web/CSS/CSS_selectors) module - [CSS values and units](/en-US/docs/Web/CSS/CSS_Values_and_Units) module
0
data/mdn-content/files/en-us/web/css/css_syntax
data/mdn-content/files/en-us/web/css/css_syntax/error_handling/index.md
--- title: CSS error handling slug: Web/CSS/CSS_syntax/Error_handling page-type: guide --- {{CSSRef}} When an error exists in CSS, such as an invalid value or a missing semicolon, instead of [throwing an error like in JavaScript](/en-US/docs/Web/JavaScript/Reference/Errors), the browser (or other user agent) will gracefully recover. Browsers don't provide CSS-related alerts or otherwise indicate errors have occurred in styles. They just discard invalid content and parse subsequent valid styles. This is a feature of CSS, not a bug. This guide discusses how CSS {{glossary("parser", "parsers")}} discard invalid CSS. ## CSS parser errors When a CSS error is encountered, the browser's {{glossary("parser")}} ignores the line containing the errors, discarding the minimum amount of CSS code before returning to {{glossary("parse", "parsing")}} the CSS as normal. The "error recovery" is just the ignoring or skipping of invalid content. The fact that browsers ignore invalid code enables the use of new CSS features without worrying about anything being broken in older browsers. A browser may not recognize a new feature, but that is okay. The discarding of invalid content without throwing an error allows both old and new syntaxes to coexist in the same ruleset, although bear in mind that they should be specified in that order. For example: ```css div { display: inline-flex; display: inline flex; } ``` The {{cssxref("display")}} property accepts both legacy single value and [multi-keyword syntax](/en-US/docs/Web/CSS/display/multi-keyword_syntax_of_display). Browsers will render the old syntax until they recognize the new syntax as valid, at which point the new syntax will override the old. If a user has an old browser, the valid fallback won't get overwritten by the new CSS, because the browser perceives it as invalid. The type and amount of CSS that a browser ignores due to an error depends on the type of error. Some common error situations are listed below: - For [errors in at-rules](#at-rule_errors), whether a single line or the entire at-rule is ignored (fails) depends on the at-rule and the type of error. - If the [error is an invalid selector](#errors_in_selector_lists), the entire declaration block is ignored. - An [error due to a missing semi-colon](#errors_within_css_declaration_blocks) between property declarations causes an invalid value, in which case, multiple property-value declarations are ignored. - If the [error is a property name or value](#errors_within_css_declaration_blocks), such as an unrecognized property name or invalid data type, the property-value declaration is ignored. - If the [error is due to a missing end-bracket](#errors_with_auto-closed_endings), the extent of what is ignored depends on the browser's ability to parse the error as nested CSS. After parsing each declaration, style rule, at-rule, and so on, the browser checks the parsed content against its expected [grammar](#grammar_check) for that construct. If the content does not match the expected grammar for that construct, the browser considers it invalid and ignores it. ### At-rule errors The `@` symbol, known in CSS specifications as an `<at-keyword-token>`, indicates the beginning of a CSS {{cssxref("at-rule")}}. Once an at-rule begins with the `@` symbol, nothing is considered invalid from the parser's standpoint. Everything up to the first semi-colon (`;`) or the opening curly brace (`{`) is part of the at-rule's prelude. The content of each at-rule is interpreted according to the grammar rules for that particular at-rule. Statement at-rules, such as {{cssxref("@import")}} and {{cssxref("@namespace")}} declarations, contain just a prelude. The semicolon ends the at-rule immediately for [regular at-rules](/en-US/docs/Web/CSS/At-rule#regular). If the contents of the prelude are invalid according to the grammar for that at-rule, the at-rule is ignored, with the browser continuing to parse CSS after it encounters the next semi-colon. For example, if an `@import` at-rule occurs after any CSS declaration other than `@charset`, `@layer` or other `@import` statements, the `@import` declaration is ignored. ```css @import "assets/fonts.css" layer(fonts); @namespace svg url(http://www.w3.org/2000/svg); ``` If the parser encounters a curly brace (`{`) before a semi-colon is encountered, the at-rule is parsed as a block at-rule. Block at-rules, also called [nested at-rules](/en-US/docs/Web/CSS/At-rule#nested), like {{cssxref("@font-face")}} and {{cssxref("@keyframes")}}, contain a block of declarations surrounded by curly braces (`{}`). The opening curly brace informs the browser where the at-rule prelude ends and the at-rule's body starts. The parser looks forward, seeking matching blocks (content surrounded by `()`, `{}`, or `[]`) until it finds a closing curly brace (`}`) that isn't matched by any other curly braces: this closes the body of the at-rule. Different at-rules have different grammar rules, different (or no) descriptors, and different rules for what, if anything, will invalidate the entire at-rule. The expected grammar for [each at-rule](/en-US/docs/Web/CSS/At-rule) and how errors are handled are documented on the respective at-rule page. The handling of invalid content depends on the error. For example, the `@font-face` rule requires both a [`font-family`](/en-US/docs/Web/CSS/@font-face/font-family) and [`src`](/en-US/docs/Web/CSS/@font-face/src) descriptor. If either of these is omitted or invalid, the entire `@font-face` rule is invalid. Including an unrelated descriptor, any other valid font descriptor with an invalid value, or a property style declaration within the `@font-face` nested block will not invalidate the font declaration. As long as the font name and font source are included and valid, any invalid CSS within the at-rule is ignored, but the `@font-face` block is still parsed. While the grammar of the `@keyframe` at-rule is very different from the `@font-face` rule grammar, the type of error still impacts what gets ignored. Important declarations (marked with the {{cssxref("important")}} flag) and properties that can't be animated are ignored in keyframe rules, but they don't impact other styles declared in the same keyframe selector block. Including an invalid keyframe selector (such as a percentage value less than `0%` or greater than `100%`, or a {{cssxref("number")}} omitting the `%`) invalidates the keyframe selector list and therefore the style block is ignored. An invalid keyframe selector only invalidates the invalid selector's style block; it does not invalidate the entire `@keyframe` declaration. Including styles between two keyframe selector blocks, on the other hand, will invalidate the entire `@keyframe` at-rule. Some at-rules are almost always valid. The {{cssxref("@layer")}} at-rule comes in both regular and nested forms. The `@layer` statement syntax contains just the prelude, ending with a semi-colon. Alternatively, the nested syntax has layer styles nested between curly braces coming after the prelude. Omitting a closing curly brace may be a logic error but is not a syntax error. In the case of a missing closing brace in `@layer`, any styles coming after where the closing brace should have been are parsed as being in the cascade layer defined in the at-rule's prelude. The CSS is valid as there are no syntax errors; nothing is discarded. A syntax error may cause the named or anonymous layer to be empty, but the layer is still created. ### Errors in selector lists There are many ways you might make a mistake writing a selector, but only invalid selectors cause a selector list to be invalid (See [invalid selector list](/en-US/docs/Web/CSS/Selector_list#invalid_selector_list)). If you include a {{cssxref("class_selectors", "class")}}, {{cssxref("id_selectors", "id")}}, or {{cssxref("type_selectors", "type")}} selector for a class, id, or element (or custom element) that doesn't exist, it may be a logic error but it's not a syntax error. However, if you have a typo in a pseudo-class or a pseudo-element, it might create an invalid selector, which is an error the parser needs to address. If a selector list contains any invalid selectors, then the entire style block is ignored. There are exceptions: if the invalid selector is within an {{cssxref(":is")}} or {{cssxref(":where")}} pseudo-class (which accept [forgiving selector lists](/en-US/docs/Web/CSS/Selector_list#forgiving_selector_list)) or if the unknown selector is a [`-webkit-` prefixed pseudo-element](#-webkit-_exception), only the unknown selector is ignored as not matching anything. The selector list is not invalidated. Outside of these exceptions, a single invalid or unsupported selector in the selector list will invalidate the entire rule and the entire selector block will be ignored. The browser will then look for the closing curly brace and continue parsing from that point onwards. #### `-webkit-` exception Due to legacy issues from the overuse of browser-specific prefixes in selectors and [property names (and values)](#vendor_prefixes), browsers avoid excessive invalidation of selector lists by treating all [pseudo-elements](/en-US/docs/Web/CSS/Pseudo-elements) that start with a case-insensitive `-webkit-` prefix and don't end with `()` as valid. This means that a pseudo-element like `::-webkit-works-only-in-samsung` will not invalidate a selector list, regardless of which browser the code is running in. In such cases, the pseudo-element may not be recognized or supported by the browser, but it will not cause the entire selector list and its associated style block to be ignored. On the other hand, an unknown prefixed selector with a function notation of `::-webkit-imaginary-function()` will invalidate the entire selector list, and the browser will ignore the entire selector block. ### Errors within CSS declaration blocks When it comes to CSS properties and values within a declaration block, if either the property or the value is invalid, that property-value pair is ignored and discarded. When a user agent parses or interprets a list of declarations, unknown syntax at any point causes the browser's parser to discard only the current declaration. It then continues parsing CSS after the next semicolon or closing curly bracket is encountered, whichever comes first. This example contains an error. The parser ignores the error (and the comments), seeks forward until it encounters a semi-colon, then restarts parsing: ```css-nolint bad p { /* Invalid syntax due to missing semi-colon */ border-color: red background-color: green; /* Valid syntax but likely a logic error */ border-width: 100vh; } ``` The reason the first declaration in this selector block is invalid is because the semi-colon is missing and the declaration is not the last one in the selector block. The property missing the semi-colon is ignored, as is the property-value pair following it because the browser only continues parsing after a semi-colon or closing bracket is encountered. Specifically, the `border-color` value is parsed as `red background-color: green;` which is not a valid {{cssxref("&lt;color&gt;")}} value. The {{cssxref("border-width")}} value of `100vh` is likely a mistake, but it's not an error. As it is syntactically valid, it will be parsed and applied to the elements matching the selector. #### Vendor prefixes Vendor-prefixed property names and property values, when not understood by a browser, are treated as invalid and ignored. Only the individual rules containing an invalid property or value are ignored. The parser looks for the next semi-colon or closing curly brace and then continues parsing from there. You may come across legacy CSS that looks like the following: ```css example-bad /* Prefixed values */ .wrapper { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; display: block flex; } /* Prefixed properties */ .rounded { -webkit-border-radius: 50%; -moz-border-radius: 50%; -ms-border-radius: 50%; -o-border-radius: 50%; border-radius: 50%; } ``` In this example, the last declaration in each block is valid in all browsers — `display: flex;` and `border-radius: 50%;`. Because of the [cascade](/en-US/docs/Learn/CSS/Building_blocks/Cascade_and_inheritance#source_order) [order of appearance](/en-US/docs/Learn/CSS/Building_blocks/Cascade_layers) rule, browsers will apply any prefixed declarations they understand, and then override those values with the standard unprefixed version. > **Note:** Avoid including prefixed properties or property values where possible. If you must use them, declare the prefixed versions before the non-prefixed version as shown above. ### Errors with auto-closed endings If a stylesheet ends while a rule, declaration, function, string, or comment is still open, the parser will automatically close everything that was left unclosed. > **Note:** This is true of external style sheets, selector blocks within an HTML {{HTMLElement("style")}} element, and inline rules within a [`style`](/en-US/docs/Web/HTML/Global_attributes/style) attribute. If the content between the last semi-colon and the end of the stylesheet is valid, even if incomplete, the CSS will be parsed normally. For example, if you fail to close out a `@keyframe` declaration before closing your {{htmlelement("style")}}, the animation is still valid. ```html-nolint example-bad <style> @keyframes move { 100% { transform: translatex(100vw) </style> ``` Here the `move` animation is valid. Failing to properly close CSS statements doesn't necessarily make the statements invalid. That said, do not take advantage of CSS's forgiving nature. Always close all of your statements and style blocks. It makes your CSS easier to read and maintain and ensures that the browser parses the CSS as you intended. #### Unclosed comments Unclosed comments are logic errors, not syntax errors. If a comment starts with `/*` but is not closed, all CSS code until a closing delimiter (`*/`) in a subsequent comment or the end of the stylesheet, whichever comes first, is part of the comment. While an unclosed comment does not invalidate your CSS, it causes the CSS following the opening delimiter (`/*`) to be ignored. ```html example-bad <style> /* this comment is not closed @keyframes move { 0% {transform: translatex(0);} 100% {transform: translatex(100vw);} } </style> <p style="/* another unclosed comment">Parsed as HTML.</p> ``` In this example, the two CSS comments are not closed, but the closing `</style>` tag closes the first comment and the `style` attribute's close quote closes the second comment. ## Grammar check After parsing each declaration, style rule, at-rule, etc., the user agent checks to make sure the grammar follows the rules for that declaration. For example, if a property value is of the wrong data type or a descriptor is not valid for the at-rule being described, the content that does not match the expected grammar is deemed invalid and gets ignored. Each CSS property accepts specific data types. For example, the {{cssxref("background-color")}} property accepts either a valid {{cssxref("&lt;color&gt;")}} or a CSS global keyword. When the value assigned to a property is of the wrong type, such as `background-color: 45deg`, the declaration is invalid and therefore ignored. ### Invalid custom properties Custom properties are generally considered valid when declared, but may create invalid CSS when accessed, i.e. they may be used as a value (via the {{cssxref("var")}} function) for a property that does not accept that value type. The browser parses each custom property when encountered without regard to where the property is consumed. Generally, when a property value is invalid, the declaration is ignored and the property falls back to the last valid value. Invalid computed custom property values, however, work slightly differently. When a `var()` substitution is invalid, the declaration is not ignored and the [initial](/en-US/docs/Web/CSS/initial_value) or [inherited](/en-US/docs/Web/CSS/Inheritance) value of the property is used instead. The property is set to a new value, but possibly not the expected one. Let's look at an example to illustrate this behavior: ```css example-bad :root { --theme-color: 45deg; } body { background-color: var(--theme-color); } ``` In the above code, the custom property declaration is valid. The `background-color` declaration is also valid at compute time. However, when the browser substitutes the custom property in `var(--theme-color)` with `45deg` as a value of the `background-color` property, the grammar is invalid. An {{cssxref("angle")}} is not a valid `background-color` value. In this case, the declaration is not ignored as invalid. Rather, when a custom property is of the wrong type, if the property is inheritable, the value is inherited from its parent. If the property is not inheritable, the default initial value is used. In the case of `background-color`, the property value is not an inherited value, so the inital value of `transparent` is used. To better control the way custom properties fall back, use the {{cssxref("@property")}} at-rule to define the initial value of the property: ```css example-good @property --theme-color { syntax: "<color>"; inherits: false; initial-value: rebeccapurple; } ``` ## See also - [CSS syntax](/en-US/docs/Web/CSS/CSS_syntax) module - [Syntax](/en-US/docs/Web/CSS/Syntax) guide - [Value definition syntax](/en-US/docs/Web/CSS/Value_definition_syntax)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/overlay/index.md
--- title: overlay slug: Web/CSS/overlay page-type: css-property status: - experimental browser-compat: css.properties.overlay --- {{CSSRef}}{{SeeCompatTable}} The **`overlay`** [CSS](/en-US/docs/Web/CSS) property specifies whether an element appearing in the [top layer](/en-US/docs/Glossary/Top_layer) (for example, a shown [popover](/en-US/docs/Web/API/Popover_API) or modal {{htmlelement("dialog")}} element) is actually rendered in the top layer. This property is only relevant within a list of {{cssxref("transition-property")}} values, and only if `allow-discrete` is set as the {{cssxref("transition-behavior")}}. It is important to note that `overlay` can _only_ be set by the browser — author styles cannot change the `overlay` value of any element. You can, however, add `overlay` to the [list of transition properties](/en-US/docs/Web/CSS/transition-property) set on an element. This causes its removal from the top layer to be deferred so it can be animated instead of disappearing immediately. > **Note:** When transitioning `overlay`, you need to set [`transition-behavior: allow-discrete`](/en-US/docs/Web/CSS/transition-behavior) on the transition so that it will animate. `overlay` animations differ from normal [discrete animations](/en-US/docs/Web/CSS/CSS_animated_properties#discrete) in that the visible (i.e. `auto`) state will always be shown for the full duration of the transition, regardless of whether it is the start or end state. ## Syntax ```css /* Keyword values */ overlay: auto; overlay: none; /* Global values */ display: inherit; display: initial; display: revert; display: revert-layer; display: unset; ``` ### Values - `auto` - : The element is rendered in the top layer if it is promoted to the top layer. - `none` - : The element is not rendered in the top layer. ## Formal definition {{cssinfo}} ## Formal syntax {{CSSSyntax}} ## Examples ### Transitioning a popover In this example, a [popover](/en-US/docs/Web/API/Popover_API) is animated as it [transitions](/en-US/docs/Web/CSS/CSS_transitions) from hidden to shown and back again. #### HTML The HTML contains a {{htmlelement("div")}} element declared as a popover using the [popover](/en-US/docs/Web/HTML/Global_attributes/popover) attribute, and a {{htmlelement("button")}} element designated as the popover's display control using its [popovertarget](/en-US/docs/Web/HTML/Element/button#popovertarget) attribute. ```html <button popovertarget="mypopover">Show the popover</button> <div popover="auto" id="mypopover">I'm a Popover! I should animate.</div> ``` #### CSS The `overlay` property is only present in the list of transitioned properties. As `overlay` is a user-agent controlled property, it is not declared in the pre-transition or post-transition states. ```css html { font-family: Arial, Helvetica, sans-serif; } [popover]:popover-open { opacity: 1; transform: scaleX(1); } [popover] { font-size: 1.2rem; padding: 10px; /* Final state of the exit animation */ opacity: 0; transform: scaleX(0); transition: opacity 0.7s, transform 0.7s, overlay 0.7s allow-discrete, display 0.7s allow-discrete; /* Equivalent to transition: all 0.7s allow-discrete; */ } /* Needs to be included after the previous [popover]:popover-open rule to take effect, as the specificity is the same */ @starting-style { [popover]:popover-open { opacity: 0; transform: scaleX(0); } } /* Transition for the popover's backdrop */ [popover]::backdrop { background-color: rgb(0 0 0 / 0%); transition: display 0.7s allow-discrete, overlay 0.7s allow-discrete, background-color 0.7s; /* Equivalent to transition: all 0.7s allow-discrete; */ } [popover]:popover-open::backdrop { background-color: rgb(0 0 0 / 25%); } /* Nesting selectors (&) cannot represent pseudo-elements, so this starting-style rule cannot be nested. */ @starting-style { [popover]:popover-open::backdrop { background-color: rgb(0 0 0 / 0%); } } ``` The two properties we want to animate are [`opacity`](/en-US/docs/Web/CSS/opacity) and [`transform`](/en-US/docs/Web/CSS/transform)): we want the popover to fade in and out while growing and shrinking in the horizontal direction. We set a starting state for these properties on the default hidden state of the popover element (selected via `[popover]`), and an end state on the open state of the popover (selected via the [`:popover-open`](/en-US/docs/Web/CSS/:popover-open) pseudo-class). We then set a [`transition`](/en-US/docs/Web/CSS/transition) property to animate between the two. Because the animated element is being promoted to the [top layer](/en-US/docs/Glossary/Top_layer) when shown and removed from the top layer when hidden, `overlay` is added to the list of transitioned elements. This ensures that the removal of the element from the top layer is deferred until the animation has ended. This doesn't make a huge difference for simple animations such as this one, but in more complex cases not doing this can result in the element being removed from the overlay too quickly, meaning the animation is not smooth or effective. Note that the [`transition-behavior: allow-discrete`](/en-US/docs/Web/CSS/transition-behavior) value is also set in the shorthand to enable discrete transitions. The following steps are also required to get the animation working in both directions: - A starting state for the animation is set inside the [`@starting-style`](/en-US/docs/Web/CSS/@starting-style) at-rule. This is needed to avoid unexpected behavior. By default transitions are not triggered on elements' first style updates, or when the `display` type changes from `none` to another type. `@starting-style` allows you to override that default in a specific controlled fashion. Without this, the entry animation would not occur and the popover would just appear. - `display` is also added to the list of transitioned elements so that the animated element is visible (set to `display: block`) throughout both the entry and exit animation. Without this, the exit animation would not be visible; in effect, the popover would just disappear. Again, `transition-behavior: allow-discrete` is required in this case for the animation to occur. You'll note that we've also included a transition on the [`::backdrop`](/en-US/docs/Web/CSS/::backdrop) that appears behind the popover when it opens, to provide a nice darkening animation. `[popover]:popover-open::backdrop` is needed to select the backdrop when the popover is open. #### Result The code renders as follows: {{ EmbedLiveSample("Transitioning a popover", "100%", "200") }} > **Note:** Because popovers change from `display: none` to `display: block` each time they are shown, the popover transitions from its `@starting-style` styles to its `[popover]:popover-open` styles every time the entry transition occurs. When the popover closes, it transitions from its `[popover]:popover-open` state to the default `[popover]` state. > > It is possible for the style transition on entry and exit to be different in such cases. See our [Demonstration of when starting styles are used](/en-US/docs/Web/CSS/@starting-style#demonstration_of_when_starting_styles_are_used) example for a proof of this. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS transitions](/en-US/docs/Web/CSS/CSS_transitions) module - [`@starting-style`](/en-US/docs/Web/CSS/@starting-style) - [`transition-behavior`](/en-US/docs/Web/CSS/transition-behavior) - [Four new CSS features for smooth entry and exit animations](https://developer.chrome.com/blog/entry-exit-animations/) on developer.chrome.com (2023)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/env/index.md
--- title: env() slug: Web/CSS/env page-type: css-function browser-compat: css.properties.custom-property.env --- {{CSSRef}} The **`env()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) can be used to insert the value of a user-agent defined environment variable into your CSS, in a similar fashion to the {{cssxref("var", "var()")}} function and [custom properties](/en-US/docs/Web/CSS/--*). The difference is that, as well as being user-agent defined rather than author-defined, environment variables are globally scoped to a document, whereas custom properties are scoped to the element(s) on which they are declared. In addition, unlike custom properties, which cannot be used outside of declarations, the `env()` function can be used in place of any part of a property value, or any part of a descriptor (e.g. in [Media query rules](/en-US/docs/Web/CSS/@media)). As the spec evolves, it may also be usable in other places such as selectors. Originally provided by the iOS browser to allow developers to place their content in a safe area of the viewport, the `safe-area-inset-*` values defined in the specification can be used to help ensure content is visible even to viewers using non‑rectangular displays. For example, a common issue solved by `env()` is that of device notifications covering up some of the app user interface. By positioning fixed elements using `env()` you can ensure that they display in a safe area of the viewport. Another use case for `env()` variables is for desktop [Progressive web apps](/en-US/docs/Web/Progressive_web_apps) (PWAs) that use the Window Controls Overlay feature to take advantage of the full application window surface area. Using the `titlebar-area-*` values, they can position elements where the title bar would have been and ensure that content stays clear of the window control buttons. ## Syntax ```css /* Using the four safe area inset values with no fallback values */ env(safe-area-inset-top); env(safe-area-inset-right); env(safe-area-inset-bottom); env(safe-area-inset-left); /* Using them with fallback values */ env(safe-area-inset-top, 20px); env(safe-area-inset-right, 1em); env(safe-area-inset-bottom, 0.5vh); env(safe-area-inset-left, 1.4rem); ``` ### Values - `safe-area-inset-top`, `safe-area-inset-right`, `safe-area-inset-bottom`, `safe-area-inset-left` - : The `safe-area-inset-*` variables are four environment variables that define a rectangle by its top, right, bottom, and left insets from the edge of the viewport, which is safe to put content into without risking it being cut off by the shape of a non‑rectangular display. For rectangular viewports, like your average laptop monitor, their value is equal to zero. For non-rectangular displays — like a round watch face — the four values set by the user agent form a rectangle such that all content inside the rectangle is visible. - `titlebar-area-x`, `titlebar-area-y`, `titlebar-area-width`, `titlebar-area-height` - : The `titlebar-area-*` variables are useful for PWA installed on Desktop devices. When a desktop PWA uses the `window-controls-overlay` [display_override](/en-US/docs/Web/Manifest/display_override) value, then it can use the `titlebar-area-*` variables to make sure content doesn't overlap with the window control buttons (i.e. minimize, maximize, and close). - `keyboard-inset-top`, `keyboard-inset-right`, `keyboard-inset-bottom`, `keyboard-inset-left`, `keyboard-inset-width`, `keyboard-inset-height` - : The `keyboard-inset-*` variables provide information about the on-screen virtual keyboard's appearance. They define a rectangle by its top, right, bottom, and left insets from the edge of the viewport (the width and height insets are calculated from the other insets). To learn more, see the {{domxref("VirtualKeyboard API", "VirtualKeyboard API", "", "nocode")}}. > **Note:** Unlike other CSS properties, user agent-defined property names are case-sensitive. ### Formal syntax {{CSSSyntax}} ## Usage To tell the browser to use the whole available space on the screen, and so enabling us to use the `env()` variables, we need to add a new viewport meta value: ```html <meta name="viewport" content="viewport-fit=cover" /> ``` You can then use `env()` in your CSS: ```css body { padding: env(safe-area-inset-top, 20px) env(safe-area-inset-right, 20px) env( safe-area-inset-bottom, 20px ) env(safe-area-inset-left, 20px); } ``` ## Examples ### Using env() to ensure buttons are not obscured by device UI In the following example `env()` is used to ensure that fixed app toolbar buttons are not obscured by device notifications appearing at the bottom of the screen. On the desktop `safe-area-inset-bottom` is `0`. However, in devices that display notifications at the bottom of the screen, such as iOS, it contains a value that leaves space for the notification to display. This can then be used in the value for {{cssxref("padding-bottom")}} to create a gap that appears natural on that device. ```html <main>Main content of app here</main> <footer> <button>Go here</button> <button>Or here</button> </footer> ``` ```css body { display: flex; flex-direction: column; min-height: 100vh; font: 1em system-ui; } main { flex: 1; background-color: #eee; padding: 1em; } footer { flex: none; display: flex; gap: 1em; justify-content: space-evenly; background: black; padding: 1em 1em calc(1em + env(safe-area-inset-bottom)); /* adds the safe-area-inset-bottom value to the initial 1em of padding. a larger black area will display for a device that has a positive value for this variable. */ position: sticky; bottom: 0; } button { padding: 1em; background: white; color: black; margin: 0; width: 100%; border: none; font: 1em system-ui; } ``` {{EmbedLiveSample("Using_env_to_ensure_buttons_are_not_obscured_by_device_UI", "200px", "500px")}} ### Using the fallback value The below example makes use of the optional second parameter of `env()`, which allows you to provide a fallback value in case the environment variable is not available. ```html <p> If the <code>env()</code> function is supported in your browser, this paragraph's text will have 50px of padding between it and the left border — but not the top, right and bottom. This is because the accompanying CSS is the equivalent of <code>padding: 0 0 0 50px</code>, because, unlike other CSS properties, user agent property names are case-sensitive. </p> ``` ```css p { width: 300px; border: 2px solid red; padding: env(safe-area-inset-top, 50px) env(safe-area-inset-right, 50px) env( safe-area-inset-bottom, 50px ) env(SAFE-AREA-INSET-LEFT, 50px); } ``` {{EmbedLiveSample("Using_the_fallback_value", "350px", "250px")}} ### Example values ```css /* zero for all rectangular user agents */ padding: env(safe-area-inset-bottom, 50px); /* 50px because UA properties are case sensitive */ padding: env(Safe-area-inset-bottom, 50px); /* as if padding: '50px 20px' were set because x is not a valid environment variable */ padding: env(x, 50px 20px); /* ignored because '50px, 20px' is not a valid padding value and x is not a valid environment variable */ padding: env(x, 50px, 20px); ``` The syntax of the fallback, like that of custom properties, allows commas. But, if the property value doesn't support commas, the value is not valid. > **Note:** User agent properties are not reset by the [all](/en-US/docs/Web/CSS/all) property. ### Using env() to ensure content is not obscured by window control buttons in desktop PWAs In the following example `env()` ensures that content displayed in a desktop Progressive Web App that uses the [Window Controls Overlay API](/en-US/docs/Web/API/Window_Controls_Overlay_API) is not obscured by the operating system's window control buttons. The `titlebar-area-*` values define a rectangle where the title bar would normally have been displayed. On devices that do not support the Window Controls Overlay feature, such as mobile devices, the fallback values are used. Here is what a PWA installed on a desktop device normally looks like: ![Illustration of what a PWA installed on desktop normally looks like, with window control buttons, a title bar, and web content below that](desktop-pwa-window.png) With the Window Controls Overlay feature, the web content covers the whole app window surface area, with the window controls and PWA buttons displayed as overlays: ![Illustration of what a PWA installed on desktop looks like with the Window Controls Overlay feature, with window control buttons, no title bar, and web content spanning the whole window](desktop-pwa-window-wco.png) ```html <header>Title of the app here</header> <main>Main content of app here</main> ``` ```css header { position: fixed; left: env(titlebar-area-x); top: env(titlebar-area-y); width: env(titlebar-area-width); height: env(titlebar-area-height); } main { margin-top: env(titlebar-area-height); } ``` > **Note:** Using `position:fixed` makes sure the header does not scroll with the rest of the content, and instead stays aligned with the window control buttons, even on device/browsers that support elastic overscroll (also known as rubber banding). ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("var", "var(…)")}} - [CSS custom properties for cascading variables](/en-US/docs/Web/CSS/CSS_cascading_variables) module - [Custom properties (`--*`): CSS variables](/en-US/docs/Web/CSS/--*) - [Using CSS custom properties (variables)](/en-US/docs/Web/CSS/Using_CSS_custom_properties) - [Customize the window controls overlay of your PWA's title bar](https://web.dev/articles/window-controls-overlay) - [Display content in the title bar](https://docs.microsoft.com/microsoft-edge/progressive-web-apps-chromium/how-to/window-controls-overlay) - [Breaking Out of the Box](https://alistapart.com/article/breaking-out-of-the-box/)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/important/index.md
--- title: "!important" slug: Web/CSS/important page-type: css-keyword --- {{CSSRef}} A `!` delimiter followed by the `important` keyword marks the declaration as important. The `!important` flag alters the rules selecting declarations inside the [cascade](/en-US/docs/Web/CSS/Cascade). A declaration that is not _important_ is called _normal_. To mark a declaration important, add the _important flag_ (`!important`) after the value in the declaration. While white space is allowed between the delimiter and the keyword, the flag is generally written as `!important` without any white space. ```css-nolint selector { property: value; /* normal declaration */ property: value !important; /* important declaration (preferred) */ property: value ! important; /* important declaration (not preferred) */ } ``` The `!important` comes after the value of the property value pair declaration, preceded by at least one space. The important flag must be the last token in the declaration. In other words, there can be white space and comments between the flag and the declaration's ending semicolon, but nothing else. ## Impact on the cascade When it comes to important declarations, the [cascade origin and layer orders](/en-US/docs/Web/CSS/Cascade) are reversed. Without the important flag, declarations in the author's style sheets override declarations in a user's style sheet, which override declarations in the user-agent's default style sheet. When a declaration is important, the order of precedence is reversed. Declarations marked as important in the user-agent style sheets override all important declarations in the user style sheets. Similarly, all important declarations in the user style sheets override all important declarations in the author's style sheets. Finally, all important declarations take precedence over all animations. > **Note:** All important declarations take precedence over all animations. `!important` is not valid within [@keyframes animation](/en-US/docs/Web/CSS/@keyframes) declarations. Reversing the precedence order for important declarations ensures users with special needs, such as personalized color schemes or large fonts, can override author styles when needed by marking some declarations in their user's style sheet as important. It also guarantees malicious extensions can't override important user-agent styles, which might break functionality or negatively impact security. Does anything have precedence over important declarations? Yes, [transitions](/en-US/docs/Web/CSS/CSS_transitions). CSS transitions are a way to control the speed at which the property changes from one value to another. While transitioning from one value to another, a property will not match a specific important declaration. ```css a { color: red !important; background-color: yellow; transition: all 2s linear; } a:hover { color: blue !important; background-color: orange !important; } ``` In this example, the `color` and `background-color` properties will transition to the hovered state over two seconds. Even though default states are normal declarations and hover states are `!important` declarations, the transition does happen. ### Cascade layers Within each of the three origins for style sheets – author, user, and user-agent – normal declarations in unlayered styles override layered style declarations, with the last declared having precedence over the layers declared before it. Important declarations reverse the order of precedence: important declarations in the first layer take precedence over important declarations in the next layer, and so on. Also, all the important declarations have precedence over important declarations made outside any layer. ### Inline styles Inline styles are styles defined using the [`style`](/en-US/docs/Web/HTML/Global_attributes/style) attributes. They can also be normal or important. Inline _normal_ styles take precedence over all _normal_ declarations, no matter the origin. Inline _important_ styles take precedence over all other _important_ author styles, no matter the layer, but important styles from user's or user-agent's style sheets and transitions override them. ### !important and specificity While `!important` is not part of determining specificity, it is related. Important declarations override all other declarations from the same [origin and cascade layer](/en-US/docs/Web/CSS/Cascade). ```css #myElement#myElement#myElement .myClass.myClass p:hover { color: blue; } p { color: red !important; } ``` This example displays a case of over-specifying a selector. No matter how high the selector [specificity](/en-US/docs/Web/CSS/Specificity) matches a normal declaration, an important declaration from the same source and cascade layer will always have precedence. In this case, the paragraph will always be red. When two important declarations from the same origin and layer apply to the same element, browsers select and use the declaration with the highest specificity. ```css #myElement p { color: green !important; } p { color: purple !important; } ``` In this case, the selector specificity matters. Only if the selectors had the same specificity would source order matter. ## Impact on shorthand properties Declaring a shorthand property with `!important` sets all of sub-properties as important. The two following selector style blocks are equivalent: ```css p { background: blue !important; } p { background-image: none !important; background-position: 0 0 !important; background-size: auto auto !important; background-repeat: repeat !important; background-origin: padding-box !important; background-clip: border-box !important; background-attachment: scroll !important; background-color: blue !important; } ``` This example shows one of the several reasons avoiding the important flag is generally recommended. ## Impact on custom properties When the `!important` flag is added to a custom property value declaration, it makes the value assignment important. The `!important` flag is then stripped from the custom property value. The `!important` flag is not passed as part of the custom property value to the [`var()`](/en-US/docs/Web/CSS/var) function. ```css :root { --myColor: red !important; --myColor: blue; } p { color: var(--myColor); } blockquote { color: var(--myColor); color: purple; } ``` ```html hidden <p>This is a paragraph</p> <blockquote>This is a blockquote</blockquote> ``` In this example, the paragraph will be red, not blue, as the custom property value assignment is important. The blockquote will be purple, because the purple normal declaration comes after the normal red declaration. {{ EmbedLiveSample('Impact_on_custom_properties', '500', '250') }} ## Best practices Avoid using `!important` to override specificity. When intentionally creating important declarations for UI requirements, comment in your CSS code to explain to maintainers why they should not override that feature. Even when working to override high-specificity styles not under your control, such as styles in a 3rd party plugin declared with an [id selector](/en-US/docs/Web/CSS/ID_selectors), you don't need to use `!important`. Consider instead importing the 3rd party stylesheet script into a [named or anonymous layer](/en-US/docs/Web/CSS/@layer) as your first cascade layer, instead of using `!important`. As long as the external styles do not include important declarations, your styles will take precedence over the widget styles, no matter the specificity. If you need to override an external stylesheet containing important declarations, create a cascade layer containing the needed overrides, and declare that layer first. ### Accessibility concerns Important styles from a user stylesheet take precedence over the author style sheet's important declarations, meaning adding an `!important` flag to a site's styles will not prevent individual users with special requirements, such as large fonts, from being able to override your styles by adding important styles in their own user's style sheet. ## Browser compatibility This feature is supported in all browsers. ## See also - [CSS Specificity](/en-US/docs/Web/CSS/Specificity) - [CSS Cascade](/en-US/docs/Web/CSS/Cascade)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/animation-range/index.md
--- title: animation-range slug: Web/CSS/animation-range page-type: css-shorthand-property status: - experimental browser-compat: css.properties.animation-range --- {{CSSRef}}{{SeeCompatTable}} The **`animation-range`** [CSS](/en-US/docs/Web/CSS) [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) is used to set the start and end of an animation's attachment range along its timeline, i.e. where along the timeline an animation will start and end. ## Constituent properties This property is a shorthand for the following CSS properties: - [`animation-range-start`](/en-US/docs/Web/CSS/animation-range-start) - [`animation-range-end`](/en-US/docs/Web/CSS/animation-range-end) ## Syntax ```css /* single keyword or length percentage value */ animation-range: normal; /* Equivalent to normal normal */ animation-range: 20%; /* Equivalent to 20% normal */ animation-range: 100px; /* Equivalent to 100px normal */ /* single named timeline range value */ animation-range: cover; /* Equivalent to cover 0% cover 100% */ animation-range: contain; /* Equivalent to contain 0% contain 100% */ animation-range: cover 20%; /* Equivalent to cover 20% cover 100% */ animation-range: contain 100px; /* Equivalent to contain 100px cover 100% */ /* two values for range start and end */ animation-range: normal 25%; animation-range: 25% normal; animation-range: 25% 50%; animation-range: entry exit; /* Equivalent to entry 0% exit 100% */ animation-range: cover cover 200px; /* Equivalent to cover 0% cover 200px */ animation-range: entry 10% exit; /* Equivalent to entry 10% exit 100% */ animation-range: 10% exit 90%; animation-range: entry 10% 90%; ``` The `animation-range` shorthand property can be applied to a container element as a combination of the `<animation-range-start>` and `<animation-range-end>` values. If both the values are specified, they will be interpreted in the order `<animation-range-start>` then `<animation-range-end>`. As shown by the comments in the syntax block above, if only a single value is provided there are a couple of possible interpretations: - If the value is a {{cssxref("length-percentage")}} or `normal`, `<animation-range-start>` will take that value, and `<animation-range-end>` will equal `normal`. - If the value is a named timeline range without a `<length-percentage>` following it, the range will be between that named timeline range at 0% and 100%. - If the value is a named timeline range with a `<length-percentage>` following it, the range will start at that named timeline range and percentage, and end at that named timeline range and 100%. ### Values One or two values representing the [`animation-range-start`](/en-US/docs/Web/CSS/animation-range-start) and/or [`animation-range-end`](/en-US/docs/Web/CSS/animation-range-end). These values can be one of the following: - `normal` - : Represents the start of the timeline in the case of `animation-range-start` and the end of the timeline in the case of `animation-range-end`. This is the default value. - `<length-percentage>` - : A length or percentage value measured from the beginning of the timeline. - `<timeline-range-name>` - : A specific named timeline range inside the overall timeline. Possible values are: - `cover` - : Represents the full range of a _named view progress timeline_ (see [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations) for more details), from the point where the subject element first starts to enter the scroll port's view progress visibility range (0% progress) to the point where it has completely left it (100% progress). - `contain` - : Represents the range of a _named view progress timeline_ where the subject element is fully contained by, or fully contains, the scroll port's view progress visibility range. - If the subject element is smaller than the scrollport, it ranges from the point where the subject element is first completely contained by the scroll port (0% progress), to the point where it is no longer completely contained by the scroll port (100% progress). - If the subject element is larger than the scrollport, it ranges from the point where the subject element first completely covers the scroll port (0% progress), to the point where it no longer completely covers the scroll port (100% progress). - `entry` - : Represents the range of a _named view progress timeline_ from the point where the subject element first starts to enter the scroll port (0% progress), to the point where it has completely entered the scroll port (100%). - `exit` - : Represents the range of a _named view progress timeline_ from the point where the subject element first starts to exit the scroll port (0% progress), to the point where it has completely exited the scroll port (100%). - `entry-crossing` - : Represents the range of a _named view progress timeline_ from the point where the subject element first starts to cross the scroll port's starting edge (0% progress), to the point where it has completely crossed the scroll port's starting edge (100%). - `exit-crossing` - : Represents the range of a _named view progress timeline_ from the point where the subject element first starts to cross the scroll port's end edge (0% progress), to the point where it has completely crossed the scroll port's end edge (100%). In the case of `<timeline-range-name>` values that do not include a `<length-percentage>`, the percentage defaults to `0%` if it is an `animation-range-start` value, and `100%` if it is an `animation-range-end` value. > **Note:** It is quite hard to visualize what these values mean from the descriptions above. Fortunately, the [View Timeline Ranges Visualizer](https://scroll-driven-animations.style/tools/view-timeline/ranges/) shows exactly what they mean in an easy visual format. - `<timeline-range-name> <length-percentage>` - : A combination value that equals the specified percentage or distance through the specified named timeline range, measured from the start of that timeline range. > **Note:** The scroll port (see {{glossary("Scroll container")}} for more details) area known as the view progress visibility range is the area inside which the subject element of a _named view progress timeline_ animation is deemed to be visible. By default, this is the full range of the scrollport, but it can be adjusted using the {{cssxref("view-timeline-inset")}} property. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### View Timeline Ranges Visualizer See the [View Timeline Ranges Visualizer](https://scroll-driven-animations.style/tools/view-timeline/ranges/) for a nice easy visual explanation of what all the value types mean. ### Creating a named view progress timeline with range A view progress timeline named `--subjectReveal` is defined using the `view-timeline` property on a subject element with a `class` of `animation`. This is then set as the timeline for the same element using `animation-timeline: --subjectReveal;`. The result is that the subject element animates as it moves upwards through the document as it is scrolled. An `animation-range` declaration is also set to make the animation begin later than expected, and finish earlier. #### HTML The HTML for the example is shown below. ```html <div class="content"> <h1>Content</h1> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Risus quis varius quam quisque id. Et ligula ullamcorper malesuada proin libero nunc consequat interdum varius. Elit ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at augue. </p> <p> Dolor sed viverra ipsum nunc aliquet. Sed sed risus pretium quam vulputate dignissim. Tortor aliquam nulla facilisi cras. A erat nam at lectus urna duis convallis convallis. Nibh ipsum consequat nisl vel pretium lectus. Sagittis aliquam malesuada bibendum arcu vitae elementum. Malesuada bibendum arcu vitae elementum curabitur vitae nunc sed velit. </p> <div class="subject animation"></div> <p> Adipiscing enim eu turpis egestas pretium aenean pharetra magna ac. Arcu cursus vitae congue mauris rhoncus aenean vel. Sit amet cursus sit amet dictum. Augue neque gravida in fermentum et. Gravida rutrum quisque non tellus orci ac auctor augue mauris. Risus quis varius quam quisque id diam vel quam elementum. Nibh praesent tristique magna sit amet purus gravida quis. Duis ultricies lacus sed turpis tincidunt id aliquet. In egestas erat imperdiet sed euismod nisi. Eget egestas purus viverra accumsan in nisl nisi scelerisque. Netus et malesuada fames ac. </p> </div> ``` #### CSS The `subject` element and its containing `content` element are styled minimally, and the text content is given some basic font settings: ```css .subject { width: 300px; height: 200px; margin: 0 auto; background-color: deeppink; } .content { width: 75%; max-width: 800px; margin: 0 auto; } p, h1 { font-family: Arial, Helvetica, sans-serif; } h1 { font-size: 3rem; } p { font-size: 1.5rem; line-height: 1.5; } ``` The `<div>` with the class of `subject` is also given a class of `animation` — this is where `view-timeline` is set to define a named view progress timeline. It is also given an `animation-timeline` name with the same value to declare that this will be the element animated as the view progress timeline is progressed. We also give it an `animation-range` declaration to make the animation begin later than expected, and finish earlier. Last, an animation is specified on the element that animates its opacity and scale, causing it to fade in and size up as it moves up the scroller. ```css .animation { view-timeline: --subjectReveal block; animation-timeline: --subjectReveal; animation-name: appear; animation-range: entry 10% contain 25%; animation-fill-mode: both; animation-duration: 1ms; /* Firefox requires this to apply the animation */ } @keyframes appear { from { opacity: 0; transform: scaleX(0); } to { opacity: 1, transform: scaleX(1); } } ``` #### Result Scroll to see the subject element being animated. {{EmbedLiveSample("Creating a named view progress timeline with range", "100%", "480px")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`animation-timeline`](/en-US/docs/Web/CSS/animation-timeline) - [`animation-range-end`](/en-US/docs/Web/CSS/animation-range-end), [`animation-range-start`](/en-US/docs/Web/CSS/animation-range-start) - [`scroll-timeline`](/en-US/docs/Web/CSS/scroll-timeline), [`scroll-timeline-axis`](/en-US/docs/Web/CSS/scroll-timeline-axis), [`scroll-timeline-name`](/en-US/docs/Web/CSS/scroll-timeline-name) - {{cssxref("timeline-scope")}} - [`view-timeline-inset`](/en-US/docs/Web/CSS/view-timeline-inset) - [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/flex/index.md
--- title: flex slug: Web/CSS/flex page-type: css-shorthand-property browser-compat: css.properties.flex --- {{CSSRef}} The **`flex`** [CSS](/en-US/docs/Web/CSS) [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) sets how a flex _item_ will grow or shrink to fit the space available in its flex container. {{EmbedInteractiveExample("pages/css/flex.html")}} ## Constituent properties This property is a shorthand for the following CSS properties: - {{cssxref("flex-grow")}} - {{cssxref("flex-shrink")}} - {{cssxref("flex-basis")}} ## Syntax ```css /* Keyword values */ flex: auto; flex: initial; flex: none; /* One value, unitless number: flex-grow flex-basis is then equal to 0. */ flex: 2; /* One value, width/height: flex-basis */ flex: 10em; flex: 30%; flex: min-content; /* Two values: flex-grow | flex-basis */ flex: 1 30px; /* Two values: flex-grow | flex-shrink */ flex: 2 2; /* Three values: flex-grow | flex-shrink | flex-basis */ flex: 2 2 10%; /* Global values */ flex: inherit; flex: initial; flex: revert; flex: revert-layer; flex: unset; ``` The `flex` property may be specified using one, two, or three values. - **One-value syntax:** the value must be one of: - a valid value for {{cssxref("&lt;flex-grow&gt;")}}: then the shorthand expands to `flex: <flex-grow> 1 0`. - a valid value for {{cssxref("&lt;flex-basis&gt;")}}: then the shorthand expands to `flex: 1 1 <flex-basis>`. - the keyword `none` or one of the global keywords. - **Two-value syntax:** - The first value must be a valid value for {{cssxref("flex-grow")}}. - The second value must be one of: - a valid value for {{cssxref("flex-shrink")}}: then the shorthand expands to `flex: <flex-grow> <flex-shrink> 0`. - a valid value for {{cssxref("flex-basis")}}: then the shorthand expands to `flex: <flex-grow> 1 <flex-basis>`. - **Three-value syntax:** the values must be in the following order: 1. a valid value for {{cssxref("flex-grow")}}. 2. a valid value for {{cssxref("flex-shrink")}}. 3. a valid value for {{cssxref("flex-basis")}}. ### Values - `initial` - : The item is sized according to its `width` and `height` properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting "`flex: 0 1 auto`". - `auto` - : The item is sized according to its `width` and `height` properties, but grows to absorb any extra free space in the flex container, and shrinks to its minimum size to fit the container. This is equivalent to setting "`flex: 1 1 auto`". - `none` - : The item is sized according to its `width` and `height` properties. It is fully inflexible: it neither shrinks nor grows in relation to the flex container. This is equivalent to setting "`flex: 0 0 auto`". - `<'flex-grow'>` - : Defines the {{cssxref("flex-grow")}} of the flex item. Negative values are considered invalid. Defaults to `1` when omitted. (initial is `0`) - `<'flex-shrink'>` - : Defines the {{cssxref("flex-shrink")}} of the flex item. Negative values are considered invalid. Defaults to `1` when omitted. (initial is `1`) - `<'flex-basis'>` - : Defines the {{cssxref("flex-basis")}} of the flex item. A preferred size of `0` must have a unit to avoid being interpreted as a flexibility. Defaults to `0` when omitted. (initial is `auto`) ## Description For most purposes, authors should set `flex` to one of the following values: `auto`, `initial`, `none`, or a positive unitless number. To see the effect of these values, try resizing the flex containers below: ```html hidden <div class="flex-container"> <div class="item auto">auto</div> <div class="item auto">auto</div> <div class="item auto">auto</div> </div> <div class="flex-container"> <div class="item auto">auto</div> <div class="item initial">initial</div> <div class="item initial">initial</div> </div> <div class="flex-container"> <div class="item auto">auto</div> <div class="item auto">auto</div> <div class="item none">none</div> </div> <div class="flex-container"> <div class="item initial">initial</div> <div class="item none">none</div> <div class="item none">none</div> </div> <div class="flex-container"> <div class="item four">4</div> <div class="item two">2</div> <div class="item one">1</div> </div> ``` ```css hidden * { box-sizing: border-box; } .flex-container { background-color: #f4f7f8; resize: horizontal; overflow: hidden; display: flex; margin: 1em; } .item { margin: 1em; padding: 0.5em; width: 110px; min-width: 0; background-color: #1b5385; color: white; font-family: monospace; font-size: 13px; } .initial { flex: initial; } .auto { flex: auto; } .none { flex: none; } .four { flex: 4; } .two { flex: 2; } .one { flex: 1; } ``` {{EmbedLiveSample("Description", 1200, 400)}} By default flex items don't shrink below their minimum content size. To change this, set the item's {{cssxref("min-width")}} or {{cssxref("min-height")}}. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting flex: auto This example shows how a flex item with `flex: auto` grows to absorb any free space in the container. #### HTML ```html <div id="flex-container"> <div id="flex-auto">flex: auto (click to toggle raw box)</div> <div id="flex-initial">flex: initial</div> </div> ``` #### CSS ```css #flex-container { display: flex; font-family: Consolas, Arial, sans-serif; } #flex-container > div { padding: 1rem; } #flex-auto { flex: auto; border: 1px solid #f00; } #flex-initial { border: 1px solid #000; } ``` #### JavaScript ```js const flexAuto = document.getElementById("flex-auto"); const flexInitial = document.getElementById("flex-initial"); flexAuto.addEventListener("click", () => { flexInitial.style.display = flexInitial.style.display === "none" ? "block" : "none"; }); ``` #### Result The flex container contains two flex items: - "flex: auto" has a `flex` value of [`auto`](auto) - "flex: initial" has a `flex` value of [`initial`](#initial) The "flex: initial" item takes up as much space as its width requires, but does not expand to take up any more space. All the remaining space is taken up by "flex: auto". When you click "flex: auto", we set "flex: initial"'s {{cssxref("display")}} property to `none`, removing it from the layout. The "flex: auto" item then expands to occupy all the available space in the container. {{EmbedLiveSample('Setting_flex_auto','100%','100')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - CSS Flexbox Guide: _[Basic Concepts of Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox)_ - CSS Flexbox Guide: _[Controlling Ratios of flex items along the main axis](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Controlling_ratios_of_flex_items_along_the_main_axis)_
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/font-variant-numeric/index.md
--- title: font-variant-numeric slug: Web/CSS/font-variant-numeric page-type: css-property browser-compat: css.properties.font-variant-numeric --- {{CSSRef}} The **`font-variant-numeric`** CSS property controls the usage of alternate glyphs for numbers, fractions, and ordinal markers. {{EmbedInteractiveExample("pages/css/font-variant-numeric.html")}} ## Syntax ```css font-variant-numeric: normal; font-variant-numeric: ordinal; font-variant-numeric: slashed-zero; font-variant-numeric: lining-nums; /* <numeric-figure-values> */ font-variant-numeric: oldstyle-nums; /* <numeric-figure-values> */ font-variant-numeric: proportional-nums; /* <numeric-spacing-values> */ font-variant-numeric: tabular-nums; /* <numeric-spacing-values> */ font-variant-numeric: diagonal-fractions; /* <numeric-fraction-values> */ font-variant-numeric: stacked-fractions; /* <numeric-fraction-values> */ font-variant-numeric: oldstyle-nums stacked-fractions; /* Global values */ font-variant-numeric: inherit; font-variant-numeric: initial; font-variant-numeric: revert; font-variant-numeric: revert-layer; font-variant-numeric: unset; ``` This property can take one of two forms: - either the keyword value `normal` - or one or more of the other values listed below, space-separated, in any order. ### Values - `normal` - : This keyword leads to the deactivation of the use of such alternate glyphs. - `ordinal` - : This keyword forces the use of special glyphs for the ordinal markers, like 1st, 2nd, 3rd, 4th in English or a 1a in Italian. It corresponds to the OpenType values `ordn`. - `slashed-zero` - : This keyword forces the use of a 0 with a slash; this is useful when a clear distinction between O and 0 is needed. It corresponds to the OpenType values `zero`. - _`<numeric-figure-values`>_ - : These values control the figures used for numbers. Two values are possible: - `lining-nums` activating the set of figures where numbers are all lying on the baseline. It corresponds to the OpenType values `lnum`. - `oldstyle-nums` activating the set of figures where some numbers, like 3, 4, 7, 9 have descenders. It corresponds to the OpenType values `onum`. - _`<numeric-spacing-values>`_ - : These values controls the sizing of figures used for numbers. Two values are possible: - `proportional-nums` activating the set of figures where numbers are not all of the same size. It corresponds to the OpenType values `pnum`. - `tabular-nums` activating the set of figures where numbers are all of the same size, allowing them to be easily aligned like in tables. It corresponds to the OpenType values `tnum`. - _`<numeric-fraction-values>`_ - : These values controls the glyphs used to display fractions. Two values are possible: - `diagonal-fractions` activating the set of figures where the numerator and denominator are made smaller and separated by a slash. It corresponds to the OpenType values `frac`. - `stacked-fractions` activating the set of figures where the numerator and denominator are made smaller, stacked and separated by a horizontal line. It corresponds to the OpenType values `afrc`. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting ordinal numeric forms {{EmbedGHLiveSample("css-examples/font-features/font-variant-numeric-example.html", '100%', 600)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`font-variant`](/en-US/docs/Web/CSS/font-variant) - [`font-variant-alternates`](/en-US/docs/Web/CSS/font-variant-alternates) - [`font-variant-caps`](/en-US/docs/Web/CSS/font-variant-caps) - [`font-variant-east-asian`](/en-US/docs/Web/CSS/font-variant-east-asian) - [`font-variant-emoji`](/en-US/docs/Web/CSS/font-variant-emoji) - [`font-variant-ligatures`](/en-US/docs/Web/CSS/font-variant-ligatures) - [`font-variant-position`](/en-US/docs/Web/CSS/font-variant-position)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/@charset/index.md
--- title: "@charset" slug: Web/CSS/@charset page-type: css-at-rule browser-compat: css.at-rules.charset --- {{CSSRef}} The **`@charset`** [CSS](/en-US/docs/Web/CSS) rule specifies the character encoding used in the style sheet. Although the first character in `@charset` is the `@` symbol, it is not an [at-rule](/en-US/docs/Web/CSS/At-rule). The [CSS syntax](/en-US/docs/Web/CSS/CSS_syntax) module deprecates this rule, defining it as an unrecognized legacy rule to be dropped when a stylesheet is grammar-checked, but it is [fully supported in all browsers](#browser_compatibility). The following assertions apply to valid `@charset` usage: - The `@charset` rule must be the first element in the style sheet and not be preceded by any character. - `@charset` is not a [nested statement](/en-US/docs/Web/CSS/Syntax#nested_statements) and therefore cannot be used inside [conditional group at-rules](/en-US/docs/Web/CSS/At-rule#conditional_group_rules). - If several `@charset` at-rules are defined, only the first one is used. - `@charset` cannot be used inside a `style` attribute on an HTML element or inside the {{ HTMLElement("style") }} element where the character set of the HTML page is relevant. ```css @charset "utf-8"; ``` This at-rule is useful when using non-{{Glossary("ASCII")}} characters in some CSS properties, like {{ cssxref("content") }}. As there are several ways to define the character encoding of a style sheet, the browser will try the following methods in the following order (and stop as soon as one yields a result): 1. The value of the [Unicode byte-order](https://en.wikipedia.org/wiki/Byte_order_mark) character placed at the beginning of the file. 2. The value given by the `charset` attribute of the `Content-Type:` HTTP header or the equivalent in the protocol used to serve the style sheet. 3. The `@charset` CSS at-rule. 4. Use the character encoding defined by the referring document: the `charset` attribute of the {{ HTMLElement("link") }} element. This method is obsolete and should not be used. 5. Assume that the document is UTF-8. ## Syntax ```css @charset "UTF-8"; @charset "iso-8859-15"; ``` ### Formal syntax ```plain @charset "<charset>"; ``` - _charset_ - : A {{cssxref("&lt;string&gt;")}} denoting the character encoding to be used. It must be the name of a web-safe character encoding defined in the [IANA-registry](https://www.iana.org/assignments/character-sets/character-sets.xhtml), and must be double-quoted, following exactly one space character (U+0020), and immediately terminated with a semicolon. If several names are associated with an encoding, only the one marked with _preferred_ must be used. ## Examples ### Valid and invalid charset declarations ```css-nolint example-good @charset "UTF-8"; /* Set the encoding of the style sheet to Unicode UTF-8 */ ``` ```css-nolint example-bad @charset 'iso-8859-15'; /* Invalid, wrong quotes used */ @charset "UTF-8"; /* Invalid, more than one space */ @charset "UTF-8"; /* Invalid, there is a character (a space) before the at-rule */ @charset UTF-8; /* Invalid, the charset is a CSS <string> and requires double-quotes */ ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Character set](/en-US/docs/Glossary/Character_set) glossary entry - [Unicode](/en-US/docs/Glossary/Unicode) glossary entry
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/opacity/index.md
--- title: opacity slug: Web/CSS/opacity page-type: css-property browser-compat: css.properties.opacity --- {{CSSRef}} The **`opacity`** [CSS](/en-US/docs/Web/CSS) property sets the opacity of an element. Opacity is the degree to which content behind an element is hidden, and is the opposite of transparency. {{EmbedInteractiveExample("pages/css/opacity.html")}} ## Syntax ```css opacity: 0.9; opacity: 90%; /* Global values */ opacity: inherit; opacity: initial; opacity: revert; opacity: revert-layer; opacity: unset; ``` ### Values - `<alpha-value>` - : A {{cssxref("number")}} in the range `0.0` to `1.0`, inclusive, or a {{cssxref("percentage")}} in the range `0%` to `100%`, inclusive, representing the opacity of the channel (that is, the value of its alpha channel). Any value outside the interval, though valid, is clamped to the nearest limit in the range. | Value | Meaning | | ------------------------------------------------------ | ----------------------------------------------------------------------------- | | `0` | The element is fully transparent (that is, invisible). | | Any {{cssxref("number")}} strictly between `0` and `1` | The element is translucent (that is, content behind the element can be seen). | | `1` (default value) | The element is fully opaque (visually solid). | ## Description `opacity` applies to the element as a whole, including its contents, even though the value is not inherited by child elements. Thus, the element and its children all have the same opacity relative to the element's background, even if they have different opacities relative to one another. To change the opacity of a background only, use the {{cssxref("background")}} property with a {{cssxref("color_value", "color value")}} that allows for an alpha channel. For example: ```css background: rgb(0 0 0 / 40%); ``` When `opacity` value is set to `0`, the element and all of its children appear invisible, but they are still part of the DOM. That means they still register [pointer events](/en-US/docs/Web/API/Pointer_events) and, if the elements are in a tabbing order, they do get focus. For good usability, make sure to make such elements visible when they receive user interactions or use the CSS [`pointer-events`](/en-US/docs/Web/CSS/pointer-events) property to disable pointer events and take the element out of the tab order by disabling with the `disabled` attribute or setting [`tab-index="-1"`](/en-US/docs/Web/HTML/Global_attributes/tabindex) for non-form-related interactive elements. Using `opacity` with a value other than `1` places the element in a new [stacking context](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context). Opacity alone should not be used to provide information to screen readers. Use the HTML [`hidden`](/en-US/docs/Web/HTML/Global_attributes/hidden) attribute, CSS [`visibility`](/en-US/docs/Web/CSS/visibility), or CSS [`display`](/en-US/docs/Web/CSS/display) style properties. It's best to avoid using [`aria-hidden`](/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-hidden) attribute, but if the element is hidden with opacity, then hide it from screen readers as well. ### Transitioning opacity When [transitioning](/en-US/docs/Web/CSS/CSS_transitions) the opacity of elements as you add them to the page when content was formerly hidden with [`visibility: hidden`](/en-US/docs/Web/CSS/visibility#hidden), [`display: none`](/en-US/docs/Web/CSS/display#none), or [`content-visibility: hidden`](/en-US/docs/Web/CSS/content-visibility#hidden), you need to include both a [`@starting-style`](/en-US/docs/Web/CSS/@starting-style) and [`transition-behaviour: allow-discrete`](/en-US/docs/Web/CSS/transition-behavior#allow-discrete): ```css .card { transition: opacity 5s, display 5s; background-color: orange; transition-behavior: allow-discrete; @starting-style { opacity: 0; } } .card.hidden { display: none; opacity: 0; } ``` To enable first-style transitions, `@starting-style` rules are needed. In the above code, setting `opacity: 0` in `@starting-style` provides a starting point for the transition when the element receives its initial style update. For more details, see [`@starting-style`](/en-US/docs/Web/CSS/@starting-style). Setting `transition-behavior: allow-discrete` is required to transition to `display: none`. See the [`transition-behavior`](/en-US/docs/Web/CSS/transition-behavior) property for more details. ## Accessibility concerns If text opacity is adjusted, it is important to ensure that the contrast ratio between the color of the text and the background the text is placed over is high enough that people experiencing low vision conditions will be able to read the content of the page. Color contrast ratio is determined by comparing the luminosity of the opacity-adjusted text and background color values. In order to meet current [Web Content Accessibility Guidelines (WCAG)](https://www.w3.org/WAI/standards-guidelines/wcag/), a ratio of 4.5:1 is required for text content and 3:1 for larger text such as headings. Large text is defined as 18.66px and [bold](/en-US/docs/Web/CSS/font-weight) or larger, or 24px or larger. - [WebAIM: Color Contrast Checker](https://webaim.org/resources/contrastchecker/) - [MDN Understanding WCAG, Guideline 1.4 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background) - [Understanding Success Criterion 1.4.3 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html) Various operating systems provide a preference for reducing transparency. To set the `opacity` based on the user's operating systems transparency preferences, use the [`prefers-reduced-transparency`](/en-US/docs/Web/CSS/@media/prefers-reduced-transparency) media query. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting opacity The following example demonstrates how the `opacity` property changes the opacity of the entire element and content, thus making the text very hard to read. #### HTML ```html <div class="light">You can barely see this.</div> <div class="medium">This is easier to see.</div> <div class="heavy">This is very easy to see.</div> ``` #### CSS ```css div { background-color: yellow; font-weight: bold; font-size: 130%; } .light { opacity: 0.2; /* Barely see the text over the background */ } .medium { opacity: 0.5; /* See the text more clearly over the background */ } .heavy { opacity: 0.9; /* See the text very clearly over the background */ } ``` #### Result {{EmbedLiveSample('Setting_opacity', '640', '105')}} ### Setting opacity on hover In the following example opacity is changed on hover, so the striped background image on the parent element shows through the image. #### HTML ```html <div class="wrapper"> <img src="//interactive-examples.mdn.mozilla.net/media/dino.svg" alt="MDN Dino" width="128" height="146" class="opacity" /> </div> ``` #### CSS ```css img.opacity { opacity: 1; } img.opacity:hover { opacity: 0.5; } .wrapper { width: 200px; height: 160px; background-color: #f03cc3; background-image: linear-gradient( 90deg, transparent 50%, rgb(255 255 255 / 50%) 50% ); background-size: 20px 20px; } ``` #### Result {{EmbedLiveSample('Setting_opacity_on_hover', '150', '200')}} ### Styling based on user preferences To style elements based on user's operating systems transparency preferences, use the [`prefers-reduced-transparency`](/en-US/docs/Web/CSS/@media/prefers-reduced-transparency) media query. The following example demonstrates how to use the `prefers-color-scheme` media query to specify the desired `opacity` based on the user's preferences. ```css .element { opacity: 0.5; } @media (prefers-reduced-transparency) { .element { opacity: 1; } } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`prefers-reduced-transparency`](/en-US/docs/Web/CSS/@media/prefers-reduced-transparency) media query - [CSS color](/en-US/docs/Web/CSS/CSS_colors) module
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/scroll-padding-left/index.md
--- title: scroll-padding-left slug: Web/CSS/scroll-padding-left page-type: css-property browser-compat: css.properties.scroll-padding-left --- {{CSSRef}} The `scroll-padding-left` property defines offsets for the left of the _optimal viewing region_ of the scrollport: the region used as the target region for placing things in view of the user. This allows the author to exclude regions of the scrollport that are obscured by other content (such as fixed-positioned toolbars or sidebars) or to put more breathing room between a targeted element and the edges of the scrollport. {{EmbedInteractiveExample("pages/css/scroll-padding-left.html")}} ## Syntax ```css /* Keyword values */ scroll-padding-left: auto; /* <length> values */ scroll-padding-left: 10px; scroll-padding-left: 1em; scroll-padding-left: 10%; /* Global values */ scroll-padding-left: inherit; scroll-padding-left: initial; scroll-padding-left: revert; scroll-padding-left: revert-layer; scroll-padding-left: unset; ``` ### Values - `<length-percentage>` - : An inwards offset from the left edge of the scrollport, as a valid length or a percentage. - `auto` - : The offset is determined by the user agent. This will generally be 0px, but a user agent is able to detect and do something else if a non-zero value is more appropriate. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS scroll snap](/en-US/docs/Web/CSS/CSS_scroll_snap) - [Well-controlled scrolling with CSS scroll snap](https://web.dev/articles/css-scroll-snap)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/inset-block-start/index.md
--- title: inset-block-start slug: Web/CSS/inset-block-start page-type: css-property browser-compat: css.properties.inset-block-start --- {{CSSRef}} The **`inset-block-start`** [CSS](/en-US/docs/Web/CSS) property defines the logical block start offset of an element, which maps to a physical inset depending on the element's writing mode, directionality, and text orientation. It corresponds to the {{cssxref("top")}}, {{cssxref("right")}}, {{cssxref("bottom")}}, or {{cssxref("left")}} property depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. {{EmbedInteractiveExample("pages/css/inset-block-start.html")}} ## Syntax ```css /* <length> values */ inset-block-start: 3px; inset-block-start: 2.4em; /* <percentage>s of the width or height of the containing block */ inset-block-start: 10%; /* Keyword value */ inset-block-start: auto; /* Global values */ inset-block-start: inherit; inset-block-start: initial; inset-block-start: revert; inset-block-start: revert-layer; inset-block-start: unset; ``` ### Values The `inset-block-start` property takes the same values as the {{cssxref("left")}} property. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting block start offset #### HTML ```html <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ```css div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; position: relative; inset-block-start: 20px; background-color: #c8c800; } ``` #### Result {{EmbedLiveSample("Setting_block_start_offset", 140, 140)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - The properties which defines other insets: {{cssxref("inset-block-end")}}, {{cssxref("inset-inline-start")}}, and {{cssxref("inset-inline-end")}} - The mapped physical properties: {{cssxref("top")}}, {{cssxref("right")}}, {{cssxref("bottom")}}, and {{cssxref("left")}} - {{cssxref("writing-mode")}}, {{cssxref("direction")}}, {{cssxref("text-orientation")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/mask-origin/index.md
--- title: mask-origin slug: Web/CSS/mask-origin page-type: css-property browser-compat: css.properties.mask-origin --- {{CSSRef}} The **`mask-origin`** [CSS](/en-US/docs/Web/CSS) property sets the origin of a mask. For elements rendered as a single box, this property specifies the mask positioning area. In other words, this property specifies the origin position of an image specified by the {{cssxref("mask-image")}} CSS property. For elements rendered as multiple boxes, such as inline boxes on several lines or boxes on several pages, it specifies which boxes {{cssxref("box-decoration-break")}} operates upon to determine the mask positioning area. ## Syntax ```css /* Keyword values */ mask-origin: content-box; mask-origin: padding-box; mask-origin: border-box; mask-origin: fill-box; mask-origin: stroke-box; mask-origin: view-box; /* Multiple values */ mask-origin: padding-box, content-box; mask-origin: view-box, fill-box, border-box; /* Non-standard keyword values */ -webkit-mask-origin: content; -webkit-mask-origin: padding; -webkit-mask-origin: border; /* Global values */ mask-origin: inherit; mask-origin: initial; mask-origin: revert; mask-origin: revert-layer; mask-origin: unset; ``` One or more of the keyword values listed below, separated by commas. ### Values - `content-box` - : The position is relative to the content box. - `padding-box` - : The position is relative to the padding box. For single boxes `0 0` is the upper left corner of the padding edge, `100% 100%` is the lower right corner. - `border-box` - : The position is relative to the border box. - `fill-box` - : The position is relative to the object bounding box. - `stroke-box` - : The position is relative to the stroke bounding box. - `view-box` - : Uses the nearest SVG viewport as reference box. If a {{svgattr("viewBox")}} attribute is specified for the element creating the SVG viewport, the reference box is positioned at the origin of the coordinate system established by the `viewBox` attribute and the dimension of the reference box is set to the width and height values of the `viewBox` attribute. - `content` {{non-standard_inline}} - : Same as `content-box`. - `padding` {{non-standard_inline}} - : Same as `padding-box`. - `border` {{non-standard_inline}} - : Same as `border-box`. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting mask origin to border-box Try some of the other possible values by updating the CSS in the box below. {{EmbedGHLiveSample("css-examples/masking/mask-origin.html", '100%', 600)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Clipping and Masking in CSS](https://css-tricks.com/clipping-masking-css/)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-block-end/index.md
--- title: border-block-end slug: Web/CSS/border-block-end page-type: css-shorthand-property browser-compat: css.properties.border-block-end --- {{CSSRef}} The **`border-block-end`** [CSS](/en-US/docs/Web/CSS) property is a [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) for setting the individual logical block-end border property values in a single place in the style sheet. {{EmbedInteractiveExample("pages/css/border-block-end.html")}} ## Constituent properties This property is a shorthand for the following CSS properties: - [`border-block-end-color`](/en-US/docs/Web/CSS/border-block-end-color) - [`border-block-end-style`](/en-US/docs/Web/CSS/border-block-end-style) - [`border-block-end-width`](/en-US/docs/Web/CSS/border-block-end-width) ## Syntax ```css border-block-end: 1px; border-block-end: 2px dotted; border-block-end: medium dashed blue; /* Global values */ border-block-end: inherit; border-block-end: initial; border-block-end: revert; border-block-end: revert-layer; border-block-end: unset; ``` `border-block-end` can be used to set the values for one or more of {{cssxref("border-block-end-width")}}, {{cssxref("border-block-end-style")}}, and {{cssxref("border-block-end-color")}}. The physical border to which it maps depends on the element's writing mode, directionality, and text orientation. It corresponds to the {{cssxref("border-top")}}, {{cssxref("border-right")}}, {{cssxref("border-bottom")}}, or {{cssxref("border-left")}} property depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. Related properties are {{cssxref("border-block-start")}}, {{cssxref("border-inline-start")}}, and {{cssxref("border-inline-end")}}, which define the other borders of the element. ### Values The `border-block-end` is specified with one or more of the following, in any order: - `<'border-width'>` - : The width of the border. See {{cssxref("border-width")}}. - `<'border-style'>` - : The line style of the border. See {{cssxref("border-style")}}. - {{CSSXref("&lt;color&gt;")}} - : The color of the border. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Border with vertical text #### HTML ```html <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ```css div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-rl; border-block-end: 5px dashed blue; } ``` #### Results {{EmbedLiveSample("Border_with_vertical_text", 140, 140)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS Logical Properties and Values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values) - This property maps to one of the physical border properties: {{cssxref("border-top")}}, {{cssxref("border-right")}}, {{cssxref("border-bottom")}}, or {{cssxref("border-left")}}. - {{cssxref("writing-mode")}}, {{cssxref("direction")}}, {{cssxref("text-orientation")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/place-items/index.md
--- title: place-items slug: Web/CSS/place-items page-type: css-shorthand-property browser-compat: css.properties.place-items --- {{CSSRef}} The [CSS](/en-US/docs/Web/CSS) **`place-items`** [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) allows you to align items along both the block and inline directions at once (i.e. the {{CSSxRef("align-items")}} and {{CSSxRef("justify-items")}} properties) in a relevant layout system such as [Grid](/en-US/docs/Web/CSS/CSS_grid_layout) or [Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout). If the second value is not set, the first value is also used for it. {{EmbedInteractiveExample("pages/css/place-items.html")}} ## Constituent properties This property is a shorthand for the following CSS properties: - [`align-items`](/en-US/docs/Web/CSS/align-items) - [`justify-items`](/en-US/docs/Web/CSS/justify-items) ## Syntax ```css /* Keyword values */ place-items: center; place-items: normal start; /* Positional alignment */ place-items: center normal; place-items: start legacy; place-items: end normal; place-items: self-start legacy; place-items: self-end normal; place-items: flex-start legacy; place-items: flex-end normal; /* Baseline alignment */ place-items: baseline normal; place-items: first baseline legacy; place-items: last baseline normal; place-items: stretch legacy; /* Global values */ place-items: inherit; place-items: initial; place-items: revert; place-items: revert-layer; place-items: unset; ``` ### Values One of the following forms: - A single {{cssxref("align-items")}} value, which is used to set alignment in both block and inline directions. - An {{cssxref("align-items")}} value, which sets alignment in the block direction, followed by a {{cssxref("justify-items")}} value, which sets alignment in the inline direction. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Placing items in a flex container In flexbox {{cssxref("justify-self")}} or {{cssxref("justify-items")}} do not apply, as on the main axis items are treated as a group. Therefore, the second value will be ignored. ```css hidden div > div { box-sizing: border-box; border: 2px solid #8c8c8c; width: 50px; display: flex; align-items: center; justify-content: center; } #item1 { background-color: #8cffa0; min-height: 30px; font-size: 2em; } #item2 { background-color: #a0c8ff; min-height: 50px; } #item3 { background-color: #ffa08c; min-height: 40px; } #item4 { background-color: #ffff8c; min-height: 60px; } #item5 { background-color: #ff8cff; min-height: 70px; } #item6 { background-color: #8cffff; min-height: 50px; } select { font-size: 16px; } .row { margin-top: 10px; } ``` ```html hidden <div id="container"> <div id="item1">1</div> <div id="item2">2</div> <div id="item3">3</div> </div> <div class="row"> <label for="values">place-items: </label> <select id="values"> <option value="stretch">stretch</option> <option value="start">start</option> <option value="center">center</option> <option value="end">end</option> <option value="left">left</option> <option value="right">right</option> <option value="auto center">auto center</option> <option value="normal start">normal start</option> <option value="center normal">center normal</option> <option value="start auto">start auto</option> <option value="end normal">end normal</option> <option value="self-start auto">self-start auto</option> <option value="self-end normal">self-end normal</option> <option value="flex-start auto">flex-start auto</option> <option value="flex-end normal">flex-end normal</option> <option value="left auto">left auto</option> <option value="right normal">right normal</option> <option value="baseline normal">baseline normal</option> <option value="first baseline auto">first baseline auto</option> <option value="last baseline normal">last baseline normal</option> <option value="stretch auto">stretch auto</option> </select> </div> ``` ```js hidden const values = document.getElementById("values"); const container = document.getElementById("container"); values.addEventListener("change", (evt) => { container.style.placeItems = evt.target.value; }); ``` #### CSS ```css #container { height: 200px; width: 240px; place-items: stretch; /* You can change this value by selecting another option in the list */ background-color: #8c8c8c; display: flex; } ``` #### Result {{EmbedLiveSample("Placing_items_in_a_flex_container", 260, 290)}} ### Placing items in a grid container The following grid container has items which are smaller than the grid areas they are placed in, therefore `place-items` will move them in the block and inline dimensions. ```css hidden div > div { box-sizing: border-box; border: 2px solid #8c8c8c; } #item1 { background-color: #8cffa0; min-height: 30px; font-size: 2em; } #item2 { background-color: #a0c8ff; min-height: 50px; } #item3 { background-color: #ffa08c; min-height: 40px; } #item4 { background-color: #ffff8c; min-height: 60px; } #item5 { background-color: #ff8cff; min-height: 70px; } #item6 { background-color: #8cffff; min-height: 50px; } select { font-size: 16px; } .row { margin-top: 10px; } ``` ```html hidden <div id="gridcontainer"> <div id="item1">1</div> <div id="item2">2</div> <div id="item3">3</div> <div id="item4">4</div> <div id="item5">5</div> </div> <div class="row"> <label for="gridvalues">place-items: </label> <select id="gridvalues"> <option value="stretch">stretch</option> <option value="start">start</option> <option value="center">center</option> <option value="end">end</option> <option value="left">left</option> <option value="right">right</option> <option value="auto center">auto center</option> <option value="normal start">normal start</option> <option value="center normal">center normal</option> <option value="start auto">start auto</option> <option value="end normal">end normal</option> <option value="self-start auto">self-start auto</option> <option value="self-end normal">self-end normal</option> <option value="flex-start auto">flex-start auto</option> <option value="flex-end normal">flex-end normal</option> <option value="left auto">left auto</option> <option value="right normal">right normal</option> <option value="baseline normal">baseline normal</option> <option value="first baseline auto">first baseline auto</option> <option value="last baseline normal">last baseline normal</option> <option value="stretch auto">stretch auto</option> </select> </div> ``` ```js hidden const values = document.getElementById("gridvalues"); const container = document.getElementById("gridcontainer"); values.addEventListener("change", (evt) => { container.style.placeItems = evt.target.value; }); ``` #### CSS ```css #gridcontainer { height: 200px; width: 240px; place-items: stretch; /* You can change this value by selecting another option in the list */ background-color: #8c8c8c; display: grid; grid-template-columns: repeat(3, 1fr); } #gridcontainer > div { width: 50px; } ``` #### Result {{EmbedLiveSample("Placing_items_in_a_grid_container", 260, 290)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - CSS Flexbox Guide: _[Basic Concepts of Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox)_ - CSS Flexbox Guide: _[Aligning items in a flex container](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Aligning_items_in_a_flex_container)_ - CSS Grid Guide: _[Box alignment in CSS Grid layouts](/en-US/docs/Web/CSS/CSS_grid_layout/Box_alignment_in_grid_layout)_ - [CSS Box Alignment](/en-US/docs/Web/CSS/CSS_box_alignment) - The {{CSSxRef("align-items")}} property - The {{CSSxRef("align-self")}} property - The {{CSSxRef("justify-items")}} property - The {{CSSxRef("justify-self")}} property
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_valid/index.md
--- title: ":valid" slug: Web/CSS/:valid page-type: css-pseudo-class browser-compat: css.selectors.valid --- {{CSSRef}} The **`:valid`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents any {{HTMLElement("input")}} or other {{HTMLElement("form")}} element whose contents [validate](/en-US/docs/Web/HTML/Constraint_validation) successfully. This allows to easily make valid fields adopt an appearance that helps the user confirm that their data is formatted properly. {{EmbedInteractiveExample("pages/tabbed/pseudo-class-valid.html", "tabbed-shorter")}} This pseudo-class is useful for highlighting correct fields for the user. ## Syntax ```css :valid { /* ... */ } ``` ## Examples ### Indicating valid and invalid form fields In this example, we use structures like this, which include extra `<span>`s to generate content on; we'll use these to provide indicators of valid/invalid data: ```html <div> <label for="fname">First name *: </label> <input id="fname" name="fname" type="text" required /> <span></span> </div> ``` To provide these indicators, we use the following CSS: ```css input + span { position: relative; } input + span::before { position: absolute; right: -20px; top: 5px; } input:invalid { border: 2px solid red; } input:invalid + span::before { content: "✖"; color: red; } input:valid + span::before { content: "✓"; color: green; } ``` We set the `<span>`s to `position: relative` so that we can position the generated content relative to them. We then absolutely position different generated content depending on whether the form's data is valid or invalid — a green check or a red cross, respectively. To add a bit of extra urgency to the invalid data, we've also given the inputs a thick red border when invalid. > **Note:** We've used `::before` to add these labels, as we were already using `::after` for the "required" labels. You can try it below: {{EmbedGHLiveSample("learning-area/html/forms/pseudo-classes/valid-invalid.html", '100%', 430)}} Notice how the required text inputs are invalid when empty, but valid when they have something filled in. The email input on the other hand is valid when empty, as it is not required, but invalid when it contains something that is not a proper email address. ## Accessibility concerns The color green is commonly used to indicate valid input. People who have certain types of color blindness will be unable to determine the input's state unless it is accompanied by an additional indicator that does not rely on color to convey meaning. Typically, descriptive text and/or an icon are used. - [MDN Understanding WCAG, Guideline 1.4 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background) - [Understanding Success Criterion 1.4.1 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-without-color.html) ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Other validation-related pseudo-classes: {{ cssxref(":required") }}, {{ cssxref(":optional") }}, {{ cssxref(":invalid") }} - [Form data validation](/en-US/docs/Learn/Forms/Form_validation) - Accessing the [validity state](/en-US/docs/Web/API/ValidityState) from JavaScript
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/cascade/index.md
--- title: Introducing the CSS Cascade slug: Web/CSS/Cascade page-type: guide spec-urls: https://drafts.csswg.org/css-cascade/ --- {{CSSRef}} The **cascade** is an algorithm that defines how user agents combine property values originating from different sources. The cascade defines the origin and layer that takes precedence when declarations in more than one [origin](#origin_types), [cascade layer](/en-US/docs/Web/CSS/@layer), or {{CSSxRef("@scope")}} block set a value for a property on an element. The cascade lies at the core of CSS, as emphasized by the name: _**Cascading**_ Style Sheets. When a [selector](/en-US/docs/Web/CSS/CSS_selectors) matches an element, the property value from the origin with the highest precedence gets applied, even if the selector from a lower precedence origin or layer has greater [specificity](/en-US/docs/Web/CSS/Specificity). This article explains what the cascade is and the order in which {{Glossary("CSS")}} [declarations](/en-US/docs/Web/API/CSSStyleDeclaration) cascade, covering cascade layers and origin type. Understanding origin precedence is key to understanding the cascade. ## Origin types The CSS cascade algorithm's job is to select CSS declarations in order to determine the correct values for CSS properties. CSS declarations come from different origin types: **[User-agent stylesheets](#user-agent_stylesheets)**, **[Author stylesheets](#author_stylesheets)**, and **[User stylesheets](#user_stylesheets)**. Though style sheets come from these different origins and can be within different [layers](/en-US/docs/Web/CSS/@layer) in each of these origins, they overlap in terms of their default scope; to make this work, the cascade algorithm defines how they interact. Before addressing the interactions, we'll define some key terms in the next few sections. ### User-agent stylesheets User-agents, or browsers, have basic style sheets that give default styles to any document. These style sheets are named **user-agent stylesheets**. Most browsers use actual stylesheets for this purpose, while others simulate them in code. The end result is the same. Some browsers let users modify the user-agent stylesheet, but this is rare and not something that can be controlled. Although some constraints on user-agent stylesheets are set by the HTML specification, browsers have a lot of latitude: that means some differences exist between browsers. To simplify the development process, Web developers may use a CSS reset stylesheet, such as [normalize.css](https://github.com/necolas/normalize.css), which sets common properties values to a known state for all browsers before beginning to make alterations to suit their specific needs. Unless the user-agent stylesheet includes an [`!important`](/en-US/docs/Web/CSS/Specificity#the_!important_exception) next to a property, making it "important", styles declared by author styles, including a reset style sheet, take precedence over the user-agent styles, regardless of the specificity of the associated selector. ### Author stylesheets **Author stylesheets** are the most common type of style sheet; these are the styles written by web developers. These styles can reset user-agent styles, as noted above, and define the styles for the design of a given web page or application. The author, or web developer, defines the styles for the document using one or more linked or imported stylesheets, {{HTMLElement('style')}} blocks, and inline styles defined with the [`style`](/en-US/docs/Web/HTML/Global_attributes#style) attribute. These author styles define the look and feel of the website — its theme. ### User stylesheets In most browsers, the user (or reader) of the website can choose to override styles using a custom **user stylesheet** designed to tailor the experience to the user's wishes. Depending on the user agent, [user styles can be configured](https://www.thoughtco.com/user-style-sheet-3469931) directly or added via browser extensions. ### Cascade layers The cascade order is based on origin type. The cascade within each origin type is based on the declaration order of [cascade layers](/en-US/docs/Web/CSS/@layer) within that type. For all origins - user-agent, author, or user - styles can be declared within or outside of named or anonymous layers. When declared using [`layer`, `layer()`](/en-US/docs/Web/CSS/@import) or [`@layer`](/en-US/docs/Web/CSS/@layer), styles are placed into the specified named layer, or into an anonymous layer if no name is provided. Styles declared outside of a layer are treated as being part of an anonymous last declared layer. Let's take a look at cascading origin type before diving into cascade layers within each origin type. ## Cascading order The cascading algorithm determines how to find the value to apply for each property for each document element. The following steps apply to the cascading algorithm: 1. **Relevance**: It first filters all the rules from the different sources to keep only the rules that apply to a given element. That means rules whose selector matches the given element and which are part of an appropriate `media` at-rule. 2. **Origin and importance**: Then it sorts these rules according to their importance, that is, whether or not they are followed by `!important`, and by their origin. Ignoring layers for the moment, the cascade order is as follows: | Order (low to high) | Origin | Importance | | ------------------- | ------------------------ | ------------ | | 1 | user-agent (browser) | normal | | 2 | user | normal | | 3 | author (developer) | normal | | 4 | CSS @keyframe animations | | | 5 | author (developer) | `!important` | | 6 | user | `!important` | | 7 | user-agent (browser) | `!important` | | 8 | CSS transitions | | 3. **Specificity**: In case of equality with an origin, the [specificity](/en-US/docs/Web/CSS/Specificity) of a rule is considered to choose one value or another. The specificity of the selectors are compared, and the declaration with the highest specificity wins. 4. **Scoping proximity**: When two selectors in the origin layer with precedence have the same specificity, the property value within scoped rules with the smallest number of hops up the DOM hierarchy to the scope root wins. See [How `@scope` conflicts are resolved](/en-US/docs/Web/CSS/@scope#how_scope_conflicts_are_resolved) for more details and an example. 5. **Order of appearance**: In the origin with precedence, if there are competing values for a property that are in style block matching selectors of equal specificity and scoping proximity, the last declaration in the style order is applied. The cascade is in ascending order, meaning animations have precedence of normal values, whether those are declared in user, author, or user-agent styles, important values take precedence over animations, and transitions have precedence over important values. > **Note:** **Transitions and animations** > > Property values set by animation {{cssxref('@keyframes')}} are more important than all normal styles (those with no [`!important`](/en-US/docs/Web/CSS/Specificity#the_!important_exception) set). > > Property values being set in a {{cssxref('transition')}} take precedence over all other values set, even those marked with `!important`. The cascade algorithm is applied _before_ the specificity algorithm, meaning if `:root p { color: red;}` is declared in the user stylesheet (line 2) and a less specific `p {color: blue;}` is in the author stylesheet (line 3), the paragraphs will be blue. ## Basic example Before taking a deeper look at how cascade layers impact the cascade, let's look at an example involving multiple sources of CSS across the various origins, and work through the steps of the cascade algorithm: Here we have a user agent style sheet, two author style sheets, and a user stylesheet, with no inline styles within the HTML: **User-agent CSS:** ```css li { margin-left: 10px; } ``` **Author CSS 1:** ```css li { margin-left: 0; } /* This is a reset */ ``` **Author CSS 2:** ```css @media screen { li { margin-left: 3px; } } @media print { li { margin-left: 1px; } } @layer namedLayer { li { margin-left: 5px; } } ``` **User CSS:** ```css .specific { margin-left: 1em; } ``` **HTML:** ```html <ul> <li class="specific">1<sup>st</sup></li> <li>2<sup>nd</sup></li> </ul> ``` In this case, declarations inside `li` and `.specific` rules should apply. Once again, there are five steps in the cascade algorithm, in order: 1. Relevance 2. Origin and importance 3. Specificity 4. Scoping proximity 5. Order of appearance The `1px` is for print media. Due to lack of _relevance_ based on its media type, it is removed from consideration. No declaration is marked as `!important`, so the precedence order is author style sheets over user style sheets over user-agent stylesheet. Based on _origin and importance_, the `1em` from the user stylesheet and the `10px` from the user-agent stylesheet are removed from consideration. Note that even though the user style on `.specific` of `1em` has a higher specificity, it's a normal declaration in a user style sheet. As such, it has a lower precedence than any author styles, and gets removed by the origin and importance step of the algorithm before specificity even comes into play. There are three declarations in author stylesheets: ```css li { margin-left: 0; } /* from author css 1 */ ``` ```css @media screen { li { margin-left: 3px; } } ``` ```css @layer namedLayer { li { margin-left: 5px; } } ``` The last one, the `5px` is part of a cascade layer. Normal declarations in layers have lower precedence than normal styles not in a layer within the same origin type. This is also removed by step 2 of the algorithm, _origin and importance_. This leaves the `0` and the `3px`, which both have the same selector, hence the same _specificity_. Neither of them are inside a `@scope` block, so scoping proximity does not come into play in this example either. We then look at _order of appearance_. The second one, the last of the two unlayered author styles, wins. ```css margin-left: 3px; ``` > **Note:** The declaration defined in the user CSS, while it may have greater specificity, is not chosen as the cascade algorithm's _origin and importance_ is applied before the _specificity_ algorithm. The declaration defined in a cascade layer, though it may come later in the code, will not have precedence either as normal styles in cascade layers have less precedence than normal unlayered styles. _Order of appearance_ only matters when both origin, importance, and specificity are equal. ## Author styles: inline styles, layers, and precedence The [table in Cascading order](#cascading_order) provided a precedence order overview. The table summarized the user-agent, user, and author origin type styles in two lines each with "origin type - normal" and "origin type - !important". The precedence within each origin type is more nuanced. Styles can be contained within layers within their origin type, and, with author styles, there is also the issue of where inline styles land in the cascade order. The order in which layers are declared is important in determining precedence. Normal styles in a layer take precedence over styles declared in prior layers; with normal styles declared outside of any layer taking precedence over normal layered styles regardless of specificity. In this example, the author used CSS's {{CSSXref('@import')}} rule to import five external style sheets within a {{HTMLElement('style')}} information element. ```html <style> @import unlayeredStyles.css; @import AStyles.css layer(A); @import moreUnlayeredStyles.css; @import BStyles.css layer(B); @import CStyles.css layer(C); p { color: red; padding: 1em !important; } </style> ``` and then in the body of the document we have inline styles: ```html <p style="line-height: 1.6em; text-decoration: overline !important;">Hello</p> ``` In the CSS code block above, three cascade layers named "A", "B", and "C", were created, in that order. Three stylesheets were imported directly into layers and two were imported without creating or being assigned to a layer. The "All unlayered styles" in the list below (normal author style precedence - order 4) includes styles from these two stylesheets and the additional unlayered CSS style blocks. In addition, there are two inline styles, a normal `line-height` declaration and an important `text-decoration` declaration: | Order (low to high) | Author style | Importance | | ------------------- | -------------------- | ------------ | | 1 | A - first layer | normal | | 2 | B - second layer | normal | | 3 | C - last layer | normal | | 4 | All unlayered styles | normal | | 5 | inline `style` | normal | | 6 | animations | | | 7 | All unlayered styles | `!important` | | 8 | C - last layer | `!important` | | 9 | B - second layer | `!important` | | 10 | A - first layer | `!important` | | 11 | inline `style` | `!important` | | 12 | transitions | | In all origin types, the non important styles contained in layers have the lowest precedence. In our example, the normal styles associated with the first declared layer (A) have lower precedence than normal styles in the second declared layer (B), which have lower precedence than normal styles in the third declared layer (C). These layered styles have lower precedence than all normal unlayered styles, which includes normal styles from `unlayeredStyles.css`, `moreUnlayeredStyles.css`, and the `color` of `p` in the `<style>` itself. If any of the layered styles in A, B, or C, have selectors with higher specificity matching an element, similar to `:root body p { color: black;}`, it doesn't matter. Those declarations are removed from consideration because of _origin_; normal layered styles have less precedence than normal unlayered styles. If, however, the more specific selector `:root body p { color: black;}` was found in `unlayeredStyles.css`, as both _origin and importance_ have the same precedence, _specificity_ would mean the more specific, black declaration would win. The layer order of precedence is inverted for styles declared as `!important`. Important styles declared in a layer take precedence over important styles declared outside of a layer. Important styles in the first declared layer (A) take precedence over important declarations found in layer B, which takes precedence over C, which have precedence over important declarations in the unlayered styles. ### Inline styles Only relevant to author styles are inline styles, declared with the `style` attribute. Normal inline styles take precedence over any other normal author styles, no matter the specificity of the selector. If `line-height: 2;` were declared in a `:root body p` selector block in any of the five imported stylesheets, the line height would still be `1.6`. Normal inline styles take precedence over any other normal author styles unless the property is being altered by a CSS animation. All important inline styles take precedence over all author styles, important and not, inline and not, layered and not. Important styles also take precedence over animated properties, but not transitioning properties. Three things can override an important inline style: 1) an important user style, 2) an important user agent style, or 3) a property value being transitioned. ### Importance and layers The origin type precedence order is inverted for important styles. Important styles declared outside of any cascade layer have lower precedence than those declared as part of a layer. Important values that come in early layers have precedence over important styles declared in subsequent cascade layers. Take for example the following CSS: ```css p { color: red; } @layer B { :root p { color: blue; } } ``` Even though the red is declared first and has a less specific selector, because unlayered CSS takes precedence over layered CSS, the paragraph will be red. Had we included an inline style on the paragraph setting it to a different color, such as `<p style="color: black">`, the paragraph would be black. When we add `!important` to this bit of CSS, the precedence order is reversed with the stylesheet: ```css p { color: red !important; } @layer B { :root p { color: blue !important; } } ``` Now the paragraph will be blue. The `!important` in the earliest declared layer takes precedence of subsequent layers and unlayered important declarations. If the inline style contained !important, such as `<p style="color: black !important">`, again the paragraph would be black. Inline importance does take precedence over all other author declared `!important` declarations, no matter the specificity. > **Note:** `!important` reverses the precedence of cascade layers. For this reason, rather than using `!important` to override external styles, import frameworks, third party styles, widget stylesheets, etc., into layers, demoting their precedence. `!important` should only be used sparingly, if ever, to guard required styles against later overrides, in the first declared layer. Styles that are transitioning take precedence over all important styles, no matter who or how they are declared. ## Complete cascade order Now that we have a better understanding of origin type and cascade layer precedence, we realize the table in [Cascading order](#cascading_order) could have more accurately been represented by the following table: <table> <thead> <tr><th>Precedence Order <br/>(low to high)</th><th>Style Origin</th><th>Importance</th></tr> </thead> <tbody> <tr><td rowspan="3">1</td><td>user-agent - first declared layer</td><td rowspan="3">normal</td></tr> <tr><td>user-agent - last declared layer</td></tr> <tr><td>user-agent - unlayered styles</td></tr> <tr><td rowspan="3">2</td><td>user - first declared layer</td><td rowspan="3">normal</td></tr> <tr><td>user - last declared layer</td></tr> <tr><td>user - unlayered styles</td></tr> <tr><td rowspan="4">3</td><td>author - first declared layer</td><td rowspan="4">normal</td></tr> <tr><td>author - last declared layer</td></tr> <tr><td>author - unlayered styles</td></tr> <tr><td>inline <code>style</code></td></tr> <tr><td>4</td><td>animations</td><td></td></tr> <tr><td rowspan="4">5</td><td>author - unlayered styles</td><td rowspan="4"><code>!important</code></td></tr> <tr><td>author - last declared layer</td></tr> <tr><td>author - first declared layer</td></tr> <tr><td>inline <code>style</code></td></tr> <tr><td rowspan="3">6</td><td>user - unlayered styles</td><td rowspan="3"><code>!important</td></tr> <tr><td>user - last declared layer</td></tr> <tr><td>user - first declared layer</td></tr> <tr><td rowspan="3">7</td><td>user-agent - unlayered styles</td><td rowspan="3"><code>!important</code></td></tr> <tr><td>user-agent - last declared layer</td></tr> <tr><td>user-agent - first declared layer</td></tr> <tr><td>8</td><td>transitions</td><td></td></tr> </tbody> </table> ## Which CSS entities participate in the cascade Only CSS property/value pair declarations participate in the cascade. This means that [at-rules](/en-US/docs/Web/CSS/At-rule) containing entities other than declarations, such as a {{ cssxref("@font-face")}} rule containing _descriptors_, don't participate in the cascade. For the most part, the properties and descriptors defined in at-rules don't participate in the cascade. Only at-rules as a whole participate in the cascade. For example, within a `@font-face` rule, font names are identified by [`font-family`](/en-US/docs/Web/CSS/@font-face/font-family) descriptors. If several `@font-face` rules with the same descriptor are defined, only the most appropriate `@font-face`, as a whole, is considered. If more than one are identically appropriate, the entire `@font-face` declarations are compared using steps 1, 2, and 4 of the algorithm (there is no specificity when it comes to at-rules). While the declarations contained in most at-rules — such as those in {{cssxref("@media")}}, {{cssxref("@document")}}, or {{cssxref("@supports")}} — participate in the cascade, the at-rule may make an entire selector not relevant, as we saw with the print style in the [basic example](#basic_example). Declarations in {{cssxref("@keyframes")}} don't participate in the cascade. As with `@font-face`, only the `@keyframes` as a whole is selected via the cascade algorithm. The [precedence order of animation is described below](#css_animations_and_the_cascade). When it comes to {{cssxref("@import")}}, the `@import` doesn't participate itself in the cascade, but all of the imported styles do participate. If the `@import` defines a [named or anonymous layer](/en-US/docs/Web/CSS/@layer), the contents of the imported stylesheet are placed into the specified layer. All other CSS imported with `@import` is treated as the last declared layer. This was discussed above. Finally, {{cssxref("@charset")}} obeys specific algorithms and isn't affected by the cascade algorithm. ## CSS animations and the cascade [CSS animations](/en-US/docs/Web/CSS/CSS_animations), using {{ cssxref("@keyframes")}} at-rules, define animations between states. Keyframes don't cascade, meaning that at any given time CSS takes values from only one single {{cssxref("@keyframes")}}, and never mixes multiple ones together. If the several keyframe animations are defined with the same animation name, the last defined `@keyframes` in the origin and layer with the greatest precedence. Only one `@keyframes` definition is used, even if the `@keyframes` animate different property. `@keyframes` with the same name are never combined. ```css p { animation: infinite 5s alternate repeatedName; } @keyframes repeatedName { from { font-size: 1rem; } to { font-size: 3rem; } } @layer A { @keyframes repeatedName { from { background-color: yellow; } to { background-color: orange; } } } @layer B { @keyframes repeatedName { from { color: white; } to { color: black; } } } ``` In this example, there are three separate animation declaration named `repeatedName`. When `animation: infinite 5s alternate repeatedName` is applied to the paragraph, only one animation is applied: the keyframe animation defined in the unlayered CSS takes precedence over the layered keyframe animation declarations based on origin and cascade layer precedence order. In this example, only the element's font size will be animated. > **Note:** There are no important animations, as property declarations in a {{cssxref('@keyframes')}} block that contain `!important` as part of the value are ignored. ## Resetting styles After your content has finished altering styles, it may find itself in a situation where it needs to restore them to a known state. This may happen in cases of animations, theme changes, and so forth. The CSS property {{cssxref("all")}} lets you quickly set (almost) everything in CSS back to a known state. `all` lets you opt to immediately restore all properties to any of their initial (default) state, the state inherited from the previous level of the cascade, a specific origin (the user-agent stylesheet, the author stylesheet, or the user stylesheet), or even to clear the values of the properties entirely. ## Specifications {{Specifications}} ## See also - [A very simple introduction to the CSS cascade](/en-US/docs/Learn/CSS/Building_blocks/Cascade_and_inheritance) - CSS key concepts: - [CSS syntax](/en-US/docs/Web/CSS/Syntax) - [At-rules](/en-US/docs/Web/CSS/At-rule) - [Comments](/en-US/docs/Web/CSS/Comments) - [Specificity](/en-US/docs/Web/CSS/Specificity) - [Inheritance](/en-US/docs/Web/CSS/Inheritance) - [Box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model) - [Layout modes](/en-US/docs/Web/CSS/Layout_mode) - [Visual formatting models](/en-US/docs/Web/CSS/Visual_formatting_model) - [Margin collapsing](/en-US/docs/Web/CSS/CSS_box_model/Mastering_margin_collapsing) - Values - [Initial values](/en-US/docs/Web/CSS/initial_value) - [Computed values](/en-US/docs/Web/CSS/computed_value) - [Used values](/en-US/docs/Web/CSS/used_value) - [Actual values](/en-US/docs/Web/CSS/actual_value) - [Value definition syntax](/en-US/docs/Web/CSS/Value_definition_syntax) - [Shorthand properties](/en-US/docs/Web/CSS/Shorthand_properties) - [Replaced elements](/en-US/docs/Web/CSS/Replaced_element)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/font-optical-sizing/index.md
--- title: font-optical-sizing slug: Web/CSS/font-optical-sizing page-type: css-property browser-compat: css.properties.font-optical-sizing --- {{CSSRef}} The **`font-optical-sizing`** [CSS](/en-US/docs/Web/CSS) property sets whether text rendering is optimized for viewing at different sizes. {{EmbedInteractiveExample("pages/css/font-optical-sizing.html")}} ## Syntax ```css /* keyword values */ font-optical-sizing: none; font-optical-sizing: auto; /* default */ /* Global values */ font-optical-sizing: inherit; font-optical-sizing: initial; font-optical-sizing: revert; font-optical-sizing: revert-layer; font-optical-sizing: unset; ``` ### Values - none - : The browser will not modify the shape of glyphs for optimal viewing. - auto - : The browser will modify the shape of glyphs for optimal viewing. ## Description Optical sizing is enabled by default for fonts that have an optical size variation axis. The optical size variation axis is represented by `opsz` in {{cssxref("font-variation-settings")}}. When optical sizing is used, small text sizes are often rendered with thicker strokes and larger serifs, whereas larger text is often rendered more delicately with more contrast between thicker and thinner strokes. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Disabling optical sizing ```html <p class="optical-sizing"> This paragraph is optically sized. This is the default across browsers. </p> <p class="no-optical-sizing"> This paragraph is not optically sized. You should see a difference in supporting browsers. </p> ``` ```css @font-face { src: url("AmstelvarAlpha-VF.ttf"); font-family: "Amstelvar"; font-style: normal; } p { font-size: 36px; font-family: Amstelvar; } .no-optical-sizing { font-optical-sizing: none; } ``` > **Note:** The font referenced above — which includes optical sizing and is freely-licensed — is good for testing. You can [download it on GitHub](https://github.com/googlefonts/amstelvar/releases). ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("font-size")}} - {{cssxref("font-size-adjust")}} - [Fundamental text and font styling](/en-US/docs/Learn/CSS/Styling_text/Fundamentals)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/mask/index.md
--- title: mask slug: Web/CSS/mask page-type: css-shorthand-property browser-compat: css.properties.mask --- {{CSSRef}} The **`mask`** [CSS](/en-US/docs/Web/CSS) [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) hides an element (partially or fully) by masking or clipping the image at specific points. > **Note:** As well as the properties listed below, the `mask` shorthand also resets {{cssxref("mask-border")}} to its initial value. It is therefore recommended to use the `mask` shorthand rather than other shorthands or the individual properties to override any mask settings earlier in the cascade. This will ensure that `mask-border` has also been reset to allow the new styles to take effect. ## Constituent properties This property is a shorthand for the following CSS properties: - [`mask-clip`](/en-US/docs/Web/CSS/mask-clip) - [`mask-composite`](/en-US/docs/Web/CSS/mask-composite) - [`mask-image`](/en-US/docs/Web/CSS/mask-image) - [`mask-mode`](/en-US/docs/Web/CSS/mask-mode) - [`mask-origin`](/en-US/docs/Web/CSS/mask-origin) - [`mask-position`](/en-US/docs/Web/CSS/mask-position) - [`mask-repeat`](/en-US/docs/Web/CSS/mask-repeat) - [`mask-size`](/en-US/docs/Web/CSS/mask-size) ## Syntax ```css /* Keyword values */ mask: none; /* Image values */ mask: url(mask.png); /* Pixel image used as mask */ mask: url(masks.svg#star); /* Element within SVG graphic used as mask */ /* Combined values */ mask: url(masks.svg#star) luminance; /* Element within SVG graphic used as luminance mask */ mask: url(masks.svg#star) 40px 20px; /* Element within SVG graphic used as mask positioned 40px from the top and 20px from the left */ mask: url(masks.svg#star) 0 0/50px 50px; /* Element within SVG graphic used as mask with a width and height of 50px */ mask: url(masks.svg#star) repeat-x; /* Element within SVG graphic used as horizontally repeated mask */ mask: url(masks.svg#star) stroke-box; /* Element within SVG graphic used as mask extending to the box enclosed by the stroke */ mask: url(masks.svg#star) exclude; /* Element within SVG graphic used as mask and combined with background using non-overlapping parts */ /* Global values */ mask: inherit; mask: initial; mask: revert; mask: revert-layer; mask: unset; /* Multiple masks */ mask: url(masks.svg#star) left / 16px repeat-y, /* Element within SVG graphic is used as a mask on the left-hand side with a width of 16px */ url(masks.svg#circle) right / 16px repeat-y; /* Element within SVG graphic is used as a mask on the right-hand side with a width of 16px */ ``` ### Values - `<mask-reference>` - : Sets the mask image source. See {{cssxref("mask-image")}}. - `<masking-mode>` - : Sets the masking mode of the mask image. See {{cssxref("mask-mode")}}. - `<position>` - : Sets the position of the mask image. See {{cssxref("mask-position")}}. - `<bg-size>` - : Sets the size of the mask image. See {{cssxref("mask-size")}}. - `<repeat-style>` - : Sets the repetition of the mask image. See {{cssxref("mask-repeat")}}. - `<geometry-box>` - : If only one `<geometry-box>` value is given, it sets both {{cssxref("mask-origin")}} and {{cssxref("mask-clip")}}. If two `<geometry-box>` values are present, then the first sets {{cssxref("mask-origin")}} and the second sets {{cssxref("mask-clip")}}. - `<geometry-box> | no-clip` - : Sets the area that is affected by the mask image. See {{cssxref("mask-clip")}}. - `<compositing-operator>` - : Sets the compositing operation used on the current mask layer. See {{cssxref("mask-composite")}}. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Masking an image ```css .target { mask: url(#c1) luminance; } .anothertarget { mask: url(resources.svg#c1) 50px 30px/10px 10px repeat-x exclude; } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{Cssxref("clip-path")}}, {{Cssxref("filter")}} - [CSS Shapes, clipping and masking – and how to use them](https://hacks.mozilla.org/2017/06/css-shapes-clipping-and-masking/) - [Applying SVG effects to HTML content](/en-US/docs/Web/SVG/Applying_SVG_effects_to_HTML_content) - [SVG](/en-US/docs/Web/SVG)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/accent-color/index.md
--- title: accent-color slug: Web/CSS/accent-color page-type: css-property browser-compat: css.properties.accent-color --- {{CSSRef}} The **`accent-color`** [CSS](/en-US/docs/Web/CSS) property sets the {{Glossary("accent")}} color for user-interface controls generated by some elements. {{EmbedInteractiveExample("pages/css/accent-color.html")}} Browsers that support `accent-color` currently apply it to the following HTML elements: - [`<input type="checkbox">`](/en-US/docs/Web/HTML/Element/input/checkbox) - [`<input type="radio">`](/en-US/docs/Web/HTML/Element/input/radio) - [`<input type="range">`](/en-US/docs/Web/HTML/Element/input/range) - [`<progress>`](/en-US/docs/Web/HTML/Element/progress) Each user agent has an accent color, with variations to ensure legibility and contrast. That accent color is not used by every user-interface control nor in every state of the control. The `accent-color` is only applied to user-interface controls that use an accent color in the states where it is applicable. ## Syntax ```css /* Keyword values */ accent-color: auto; /* <color> values */ accent-color: darkred; accent-color: #5729e9; accent-color: rgb(0 200 0); accent-color: hsl(228 4% 24%); /* Global values */ accent-color: inherit; accent-color: initial; accent-color: revert; accent-color: revert-layer; accent-color: unset; ``` ### Values - `auto` - : Represents a UA-chosen color, which should match the accent color of the platform, if any. - {{cssxref("&lt;color&gt;")}} - : Specifies the color to be used as the accent color. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting a custom accent color #### HTML ```html <input type="checkbox" checked /> <input type="checkbox" class="custom" checked /> ``` #### CSS ```css input { accent-color: auto; display: block; width: 30px; height: 30px; } input.custom { accent-color: rebeccapurple; } ``` #### Result {{EmbedLiveSample('Setting_a_custom_accent_color', 500, 200)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("background-color")}}, {{cssxref("border-color")}}, {{cssxref("caret-color")}}, {{cssxref("color")}}, {{cssxref("column-rule-color")}}, {{cssxref("outline-color")}}, {{cssxref("text-decoration-color")}}, {{cssxref("text-emphasis-color")}}, {{cssxref("text-shadow")}}: Other color-related properties - {{cssxref("&lt;color&gt;")}}: Related data type - {{HTMLElement("input")}}: Related HTML element - [Applying color to HTML elements using CSS](/en-US/docs/Web/CSS/CSS_colors/Applying_color)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/inherit/index.md
--- title: inherit slug: Web/CSS/inherit page-type: css-keyword browser-compat: css.types.global_keywords.inherit --- {{CSSRef}} The **`inherit`** CSS keyword causes the element to take the [computed value](/en-US/docs/Web/CSS/computed_value) of the property from its parent element. It can be applied to any CSS property, including the CSS shorthand property {{cssxref("all")}}. For [inherited properties](/en-US/docs/Web/CSS/Inheritance#inherited_properties), this reinforces the default behavior, and is only needed to override another rule. > **Note:** Inheritance is always from the parent element in the document tree, even when the parent element is not the containing block. ## Examples ### Exclude selected elements from a rule ```css /* Make second-level headers green */ h2 { color: green; } /* Leave those in the sidebar alone so they use their parent's color */ #sidebar h2 { color: inherit; } ``` In this example, the `h2` elements inside the sidebar might be different colors. For example, consider one of them that would by the child of a `div` matched by the rule: ```css div#current { color: blue; } ``` Then, it would be blue. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Inheritance](/en-US/docs/Web/CSS/Inheritance) - Use the {{cssxref("initial")}} keyword to set a property to its initial value. - Use the {{cssxref("revert")}} keyword to reset a property to the value established by the user-agent stylesheet (or by user styles, if any exist). - Use the {{cssxref("revert-layer")}} keyword to reset a property to the value established in a previous cascade layer. - Use the {{cssxref("unset")}} keyword to set a property to its inherited value if it inherits or to its initial value if not. - The {{cssxref("all")}} property lets you reset all properties to their initial, inherited, reverted, or unset state at once.
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/length-percentage/index.md
--- title: <length-percentage> slug: Web/CSS/length-percentage page-type: css-type browser-compat: css.types.length-percentage --- {{CSSRef}} The **`<length-percentage>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) represents a value that can be either a {{Cssxref("length")}} or a {{Cssxref("percentage")}}. ## Syntax Refer to the documentation for {{Cssxref("length")}} and {{Cssxref("percentage")}} for details of the individual syntaxes allowed by this type. ## Formal syntax {{csssyntax}} ## Examples ### length-percentage examples The following simple example demonstrates several properties that use `<length-percentage>` values. #### HTML ```html <p>You can use percentages and lengths in so many places.</p> ``` #### CSS ```css p { /* length-percentage examples */ width: 75%; height: 200px; margin: 3rem; padding: 1%; border-radius: 10px 10%; font-size: 250%; line-height: 1.5em; /* length examples */ text-shadow: 1px 1px 1px red; border: 5px solid red; letter-spacing: 3px; /* percentage example */ text-size-adjust: 20%; } ``` #### Result {{EmbedLiveSample('length-percentage_examples', '100%', 320)}} ### Use in calc() Where a `<length-percentage>` is specified as an allowable type, this means that the percentage resolves to a length and therefore can be used in a {{cssxref("calc", "calc()")}} expression. Therefore, all of the following values are acceptable for {{cssxref("width")}}: ```css example-good width: 200px; width: 20%; width: calc(100% - 200px); ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("&lt;percentage&gt;")}} - {{cssxref("&lt;length&gt;")}} - [CSS Values and Units](/en-US/docs/Web/CSS/CSS_Values_and_Units)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/mask-border-outset/index.md
--- title: mask-border-outset slug: Web/CSS/mask-border-outset page-type: css-property browser-compat: css.properties.mask-border-outset --- {{CSSRef}} The **`mask-border-outset`** [CSS](/en-US/docs/Web/CSS) property specifies the distance by which an element's [mask border](/en-US/docs/Web/CSS/mask-border) is set out from its border box. ## Syntax ```css /* <length> value */ mask-border-outset: 1rem; /* <number> value */ mask-border-outset: 1.5; /* top and bottom | left and right */ mask-border-outset: 1 1.2; /* top | left and right | bottom */ mask-border-outset: 30px 2 45px; /* top | right | bottom | left */ mask-border-outset: 7px 12px 14px 5px; /* Global values */ mask-border-outset: inherit; mask-border-outset: initial; mask-border-outset: revert; mask-border-outset: revert-layer; mask-border-outset: unset; ``` The `mask-border-outset` property may be specified as one, two, three, or four values. Each value is a {{cssxref("&lt;length&gt;")}} or {{cssxref("&lt;number&gt;")}}. Negative values are invalid. - When **one** value is specified, it applies the same outset to **all four sides**. - When **two** values are specified, the first outset applies to the **top and bottom**, the second to the **left and right**. - When **three** values are specified, the first outset applies to the **top**, the second to the **left and right**, the third to the **bottom**. - When **four** values are specified, the outsets apply to the **top**, **right**, **bottom**, and **left** in that order (clockwise). ### Values - {{cssxref("&lt;length&gt;")}} - : The size of the mask border outset as a dimension. - {{cssxref("&lt;number&gt;")}} - : The size of the mask border outset as a multiple of the corresponding {{cssxref("border-width")}}. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Basic usage This property doesn't appear to be supported anywhere yet. When it eventually starts to be supported, it will serve to move the mask away from the inner edge of the element's border box — you can use it to make the mask start from part way across the border, rather than the inside of it. ```css mask-border-outset: 1rem; ``` Chromium-based browsers support an outdated version of this property — `mask-box-image-outset` — with a prefix: ```css -webkit-mask-box-image-outset: 1rem; ``` > **Note:** The [`mask-border`](/en-US/docs/Web/CSS/mask-border) page features a working example (using the out-of-date prefixed border mask properties supported in Chromium), so you can get an idea of the effect. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("mask-border")}} - {{cssxref("mask-border-mode")}} - {{cssxref("mask-border-repeat")}} - {{cssxref("mask-border-source")}} - {{cssxref("mask-border-width")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/font-feature-settings/index.md
--- title: font-feature-settings slug: Web/CSS/font-feature-settings page-type: css-property browser-compat: css.properties.font-feature-settings --- {{CSSRef}} The **`font-feature-settings`** CSS property controls advanced typographic features in OpenType fonts. {{EmbedInteractiveExample("pages/css/font-feature-settings.html")}} ## Syntax ```css /* Use the default settings */ font-feature-settings: normal; /* Set values for OpenType feature tags */ font-feature-settings: "smcp"; font-feature-settings: "smcp" on; font-feature-settings: "swsh" 2; font-feature-settings: "smcp", "swsh" 2; /* Global values */ font-feature-settings: inherit; font-feature-settings: initial; font-feature-settings: revert; font-feature-settings: revert-layer; font-feature-settings: unset; ``` Whenever possible, Web authors should instead use the {{cssxref("font-variant")}} shorthand property or an associated longhand property such as {{cssxref("font-variant-ligatures")}}, {{cssxref("font-variant-caps")}}, {{cssxref("font-variant-east-asian")}}, {{cssxref("font-variant-alternates")}}, {{cssxref("font-variant-numeric")}} or {{cssxref("font-variant-position")}}. These lead to more effective, predictable, understandable results than `font-feature-settings`, which is a low-level feature designed to handle special cases where no other way exists to enable or access an OpenType font feature. In particular, `font-feature-settings` shouldn't be used to enable small caps. ### Values This property is specified as either the keyword `normal` or as a comma-separated list of `<feature-tag-value>` values. When rendering text, the list of OpenType `<feature-tag-value>` values are passed to the text layout engine to enable or disable font features. - `normal` - : Indicates that text is laid out using default font settings. This is the default value. - `<feature-tag-value>` - : Represents a space-separated tuple consisting of a tag name and an optional value. The tag name is always a {{cssxref("&lt;string&gt;")}} of four {{Glossary("ASCII")}} characters. If the tag name has more or fewer characters or if it contains characters outside the `U+20` – `U+7E` code point range, the descriptor is invalid. The optional value can be a positive integer or the keyword `on` or `off`. The keywords `on` and `off` are synonyms for the values `1` and `0`, respectively. If no value is set, the default is `1`. For non-boolean OpenType features (e.g., [stylistic alternates](https://learn.microsoft.com/en-ca/typography/opentype/spec/features_pt#tag-salt)), the value implies a particular glyph to be selected; for boolean features, the value turns the feature on or off. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Enabling various font features ```css /* use small-cap alternate glyphs */ .smallcaps { font-feature-settings: "smcp" on; } /* convert both upper and lowercase to small caps (affects punctuation also) */ .allsmallcaps { font-feature-settings: "c2sc", "smcp"; } /* use zeros with a slash through them to differentiate from "O" */ .nicezero { font-feature-settings: "zero"; } /* enable historical forms */ .hist { font-feature-settings: "hist"; } /* disable common ligatures, usually on by default */ .noligs { font-feature-settings: "liga" 0; } /* enable tabular (monospaced) figures */ td.tabular { font-feature-settings: "tnum"; } /* enable automatic fractions */ .fractions { font-feature-settings: "frac"; } /* use the second available swash character */ .swash { font-feature-settings: "swsh" 2; } /* enable stylistic set 7 */ .fancystyle { font-family: Gabriola; font-feature-settings: "ss07"; } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("@font-face/font-display", "font-display")}} - {{cssxref("@font-face/font-family", "font-family")}} - {{cssxref("@font-face/font-stretch", "font-stretch")}} - {{cssxref("@font-face/font-style", "font-style")}} - {{cssxref("@font-face/font-weight", "font-weight")}} - {{cssxref("@font-face/font-variation-settings", "font-variation-settings")}} - {{cssxref("@font-face/src", "src")}} - {{cssxref("@font-face/unicode-range", "unicode-range")}} - [OpenType feature tags](https://docs.microsoft.com/typography/opentype/spec/featurelist) list - [OpenType features in CSS](https://sparanoid.com/lab/opentype-features/)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/attribute_selectors/index.md
--- title: Attribute selectors slug: Web/CSS/Attribute_selectors page-type: css-selector browser-compat: css.selectors.attribute --- {{CSSRef}} The CSS **attribute selector** matches elements based on the element having a given attribute explicitly set, with options for defining an attribute value or substring value match. The case sensitivity of attribute names and values depends on the document language. In HTML, attribute names are case-insensitive, as are spec-defined {{glossary("enumerated")}} values. The [case-insensitive HTML attribute values](https://html.spec.whatwg.org/multipage/semantics-other.html#case-sensitivity-of-selectors) are listed in the HTML spec. For these attributes, the attribute value in the selector is case-insensitive, regardless of whether the value is invalid or the attribute for the element on which it is set is invalid. If the attribute value is case-sensitive, like [`class`](/en-US/docs/Web/HTML/Global_attributes/class), [`id`](/en-US/docs/Web/HTML/Global_attributes/id), and [`data-*`](/en-US/docs/Web/HTML/Global_attributes/data-*) attributes, the attribute selector value match is case-sensitive. Attributes defined outside of the HTML specification, like [`role`](/en-US/docs/Web/Accessibility/ARIA/Roles) and [`aria-*`](/en-US/docs/Web/Accessibility/ARIA/Attributes) attributes, are also case-sensitive. Normally case-sensitive attribute selectors can be made case-insensitive with the inclusion of the case-insensitive modifier (`i`). ```css /* <a> elements with a title attribute */ a[title] { color: purple; } /* <a> elements with an href matching "https://example.org" */ a[href="https://example.org"] { color: green; } /* <a> elements with an href containing "example" */ a[href*="example"] { font-size: 2em; } /* <a> elements with an href ending ".org", case-insensitive */ a[href$=".org" i] { font-style: italic; } /* <a> elements whose class attribute contains the word "logo" */ a[class~="logo"] { padding: 2px; } ``` ## Syntax - `[attr]` - : Represents elements with an attribute name of _attr_. - `[attr=value]` - : Represents elements with an attribute name of _attr_ whose value is exactly _value_. - `[attr~=value]` - : Represents elements with an attribute name of _attr_ whose value is a whitespace-separated list of words, one of which is exactly _value_. - `[attr|=value]` - : Represents elements with an attribute name of _attr_ whose value can be exactly _value_ or can begin with _value_ immediately followed by a hyphen, `-` (U+002D). It is often used for language subcode matches. - `[attr^=value]` - : Represents elements with an attribute name of _attr_ whose value is prefixed (preceded) by _value_. - `[attr$=value]` - : Represents elements with an attribute name of _attr_ whose value is suffixed (followed) by _value_. - `[attr*=value]` - : Represents elements with an attribute name of _attr_ whose value contains at least one occurrence of _value_ within the string. - `[attr operator value i]` - : Adding an `i` (or `I`) before the closing bracket causes the value to be compared case-insensitively (for characters within the {{Glossary("ASCII")}} range). - `[attr operator value s]` {{Experimental_Inline}} - : Adding an `s` (or `S`) before the closing bracket causes the value to be compared case-sensitively (for characters within the {{Glossary("ASCII")}} range). ## Examples ### Links #### CSS ```css a { color: blue; } /* Internal links, beginning with "#" */ a[href^="#"] { background-color: gold; } /* Links with "example" anywhere in the URL */ a[href*="example"] { background-color: silver; } /* Links with "insensitive" anywhere in the URL, regardless of capitalization */ a[href*="insensitive" i] { color: cyan; } /* Links with "cAsE" anywhere in the URL, with matching capitalization */ a[href*="cAsE" s] { color: pink; } /* Links that end in ".org" */ a[href$=".org"] { color: red; } /* Links that start with "https://" and end in ".org" */ a[href^="https://"][href$=".org"] { color: green; } ``` #### HTML ```html <ul> <li><a href="#internal">Internal link</a></li> <li><a href="http://example.com">Example link</a></li> <li><a href="#InSensitive">Insensitive internal link</a></li> <li><a href="http://example.org">Example org link</a></li> <li><a href="https://example.org">Example https org link</a></li> </ul> ``` #### Result {{EmbedLiveSample("Links")}} ### Languages #### CSS ```css /* All divs with a `lang` attribute are bold. */ div[lang] { font-weight: bold; } /* All divs without a `lang` attribute are italicized. */ div:not([lang]) { font-style: italic; } /* All divs in US English are blue. */ div[lang~="en-us"] { color: blue; } /* All divs in Portuguese are green. */ div[lang="pt"] { color: green; } /* All divs in Chinese are red, whether simplified (zh-Hans-CN) or traditional (zh-Hant-TW). */ div[lang|="zh"] { color: red; } /* All divs with a Traditional Chinese `data-lang` are purple. */ /* Note: You could also use hyphenated attributes without double quotes */ div[data-lang="zh-Hant-TW"] { color: purple; } ``` #### HTML ```html <div lang="en-us en-gb en-au en-nz">Hello World!</div> <div lang="pt">Olá Mundo!</div> <div lang="zh-Hans-CN">世界您好!</div> <div lang="zh-Hant-TW">世界您好!</div> <div data-lang="zh-Hant-TW">世界您好!</div> ``` #### Result {{EmbedLiveSample("Languages")}} ### HTML ordered lists The HTML specification requires the [`type`](/en-US/docs/Web/HTML/Element/input#type) attribute to be matched case-insensitively because it is primarily used in the {{HTMLElement("input")}} element. Note that if a modifier is not supported by the user agent, then the selector will not match. #### CSS ```css /* Case-sensitivity depends on document language */ ol[type="a"]:first-child { list-style-type: lower-alpha; background: red; } ol[type="i" s] { list-style-type: lower-alpha; background: lime; } ol[type="I" s] { list-style-type: upper-alpha; background: grey; } ol[type="a" i] { list-style-type: upper-alpha; background: green; } ``` #### HTML ```html <ol type="A"> <li> Red background for case-insensitive matching (default for the type selector) </li> </ol> <ol type="i"> <li>Lime background if `s` modifier is supported (case-sensitive match)</li> </ol> <ol type="I"> <li>Grey background if `s` modifier is supported (case-sensitive match)</li> </ol> <ol type="A"> <li> Green background if `i` modifier is supported (case-insensitive match) </li> </ol> ``` #### Result {{EmbedLiveSample("HTML_ordered_lists")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("attr")}} - Selecting a single element: {{DOMxRef("Document.querySelector()")}}, {{DOMxRef("DocumentFragment.querySelector()")}}, or {{DOMxRef("Element.querySelector()")}} - Selecting all matching elements: {{DOMxRef("Document.querySelectorAll()")}}, {{DOMxRef("DocumentFragment.querySelectorAll()")}}, or {{DOMxRef("Element.querySelectorAll()")}} - [Case-insensitive attribute selector values](https://html.spec.whatwg.org/multipage/semantics-other.html#case-sensitivity-of-selectors) on WHATWG
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/mask-type/index.md
--- title: mask-type slug: Web/CSS/mask-type page-type: css-property browser-compat: css.properties.mask-type --- {{CSSRef}} The **`mask-type`** [CSS](/en-US/docs/Web/CSS) property sets whether an SVG {{svgElement("mask")}} element is used as a _luminance_ or an _alpha_ mask. It applies to the `<mask>` element itself. This property may be overridden by the {{cssxref("mask-mode")}} property, which has the same effect but applies to the element where the mask is used. Alpha masks will generally be faster to render. ## Syntax ```css /* Keyword values */ mask-type: luminance; mask-type: alpha; /* Global values */ mask-type: inherit; mask-type: initial; mask-type: revert; mask-type: revert-layer; mask-type: unset; ``` The `mask-type` property is specified as one of the keyword values listed below. ### Values - `luminance` - : Is a keyword indicating that the associated mask image is a luminance mask, i.e., that its [relative luminance](https://en.wikipedia.org/wiki/Luminance_%28relative%29) values must be used when applying it. - `alpha` - : Is a keyword indicating that the associated mask image is an alpha mask, i.e., that its [alpha channel](https://en.wikipedia.org/wiki/Alpha_compositing) values must be used when applying it. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting an alpha mask #### HTML ```html <div class="redsquare"></div> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="0" height="0"> <defs> <mask id="m" maskContentUnits="objectBoundingBox" style="mask-type:alpha"> <rect x=".1" y=".1" width=".8" height=".8" fill="red" fill-opacity="0.7" /> </mask> </defs> </svg> ``` #### CSS ```css .redsquare { height: 100px; width: 100px; background-color: rgb(128 128 128); border: solid 1px black; mask: url("#m"); } ``` #### Result {{EmbedLiveSample('Setting_an_alpha_mask', '100%', '102')}} ### Setting a luminance mask #### HTML ```html <div class="redsquare"></div> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="0" height="0"> <defs> <mask id="m" maskContentUnits="objectBoundingBox" style="mask-type:luminance"> <rect x=".1" y=".1" width=".8" height=".8" fill="red" fill-opacity="0.7" /> </mask> </defs> </svg> ``` #### CSS ```css .redsquare { height: 100px; width: 100px; background-color: rgb(128 128 128); border: solid 1px black; mask: url("#m"); } ``` #### Result {{EmbedLiveSample('Setting_a_luminance_mask', '100%', '102')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Other mask-related properties: {{cssxref("mask")}}, {{cssxref("mask-mode")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/repeat/index.md
--- title: repeat() slug: Web/CSS/repeat page-type: css-function browser-compat: css.properties.grid-template-columns.repeat --- {{CSSRef}} The **`repeat()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) represents a repeated fragment of the [track list](/en-US/docs/Web/CSS/CSS_grid_layout/Basic_concepts_of_grid_layout), allowing a large number of columns or rows that exhibit a recurring pattern to be written in a more compact form. {{EmbedInteractiveExample("pages/css/function-repeat.html")}} This function can be used in the CSS Grid properties {{cssxref("grid-template-columns")}} and {{cssxref("grid-template-rows")}}. ## Syntax ```css /* <track-repeat> values */ repeat(4, 1fr) repeat(4, [col-start] 250px [col-end]) repeat(4, [col-start] 60% [col-end]) repeat(4, [col-start] 1fr [col-end]) repeat(4, [col-start] min-content [col-end]) repeat(4, [col-start] max-content [col-end]) repeat(4, [col-start] auto [col-end]) repeat(4, [col-start] minmax(100px, 1fr) [col-end]) repeat(4, [col-start] fit-content(200px) [col-end]) repeat(4, 10px [col-start] 30% [col-middle] auto [col-end]) repeat(4, [col-start] min-content [col-middle] max-content [col-end]) /* <auto-repeat> values */ repeat(auto-fill, 250px) repeat(auto-fit, 250px) repeat(auto-fill, [col-start] 250px [col-end]) repeat(auto-fit, [col-start] 250px [col-end]) repeat(auto-fill, [col-start] minmax(100px, 1fr) [col-end]) repeat(auto-fill, 10px [col-start] 30% [col-middle] 400px [col-end]) /* <fixed-repeat> values */ repeat(4, 250px) repeat(4, [col-start] 250px [col-end]) repeat(4, [col-start] 60% [col-end]) repeat(4, [col-start] minmax(100px, 1fr) [col-end]) repeat(4, [col-start] fit-content(200px) [col-end]) repeat(4, 10px [col-start] 30% [col-middle] 400px [col-end]) ``` The `repeat()` function takes two arguments: - **repeat count**: the first argument specifies the number of times that the track list should be repeated. It is specified with an integer value of 1 or more, or with the keyword values [`auto-fill`](#auto-fill) or [`auto-fit`](#auto-fit). These keyword values repeat the set of tracks as many times as is needed to fill the grid container. - **tracks**: the second argument specifies the set of tracks that will be repeated. Fundamentally this consists of one or more values, where each value represents the size of that track. Each size is specified using either a [`<track-size>`](#track-size) value or a [`<fixed-size>`](#fixed-size) value. You can also specify one or more [line names](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_layout_using_named_grid_lines) before or after each track, by providing [`<line-names>`](#line-names) values before and/or after the track size. If you use [`auto-fill`](#auto-fill) or [`auto-fit`](#auto-fit) to set the repeat count, you may only specify track sizes using the [`<fixed-size>`](#fixed-size) type, not the [`<track-size>`](#track-size) type. This give us three main syntax forms for `repeat()`: - `<track-repeat>`, which uses: - an integer to set the repeat count - [`<track-size>`](#track-size) values to set track sizes. - `<auto-repeat>`, which uses - [`auto-fill`](#auto-fill) or [`auto-fit`](#auto-fit) to set the repeat count - [`<fixed-size>`](#fixed-size) to set track sizes. - `<fixed-repeat>`, which uses: - an integer to set the repeat count - [`<fixed-size>`](#fixed-size) values to set track sizes. Then if a property declaration uses `<auto-repeat>`, it is only allowed to use `<fixed-repeat>` for any additional `repeat()` calls. For example, this is invalid, because it combines the `<auto-repeat>` form with the `<track-repeat>` form: ```css example-bad .wrapper { grid-template-columns: repeat(auto-fill, 10px) repeat(2, minmax(min-content, max-content)); } ``` There is a fourth form, `<name-repeat>`, which is used to add line names to subgrids. It only used with the [`subgrid`](/en-US/docs/Web/CSS/CSS_grid_layout/Subgrid) keyword and only specifies line names, not track sizes. ### Values - `<fixed-size>` - : One of the following forms: - a {{cssxref("&lt;length-percentage&gt;")}} value - a {{cssxref("minmax", "minmax()")}} function with: - `min` given as a {{cssxref("&lt;length-percentage&gt;")}} value - `max` given as one of a {{cssxref("&lt;length-percentage&gt;")}} value, a {{cssxref("&lt;flex&gt;")}} value, or one of the following keywords: [`min-content`](#min-content), [`max-content`](#max-content), or [`auto`](#auto) - a {{cssxref("minmax", "minmax()")}} function with: - `min` given as a {{cssxref("&lt;length-percentage&gt;")}} value or one of the following keywords: [`min-content`](#min-content), [`max-content`](#max-content), or [`auto`](#auto) - `max` given as a {{cssxref("&lt;length-percentage&gt;")}} value. - {{cssxref("&lt;flex&gt;")}} - : A non-negative dimension with the unit `fr` specifying the track's flex factor. Each `<flex>`-sized track takes a share of the remaining space in proportion to its flex factor. - {{cssxref("&lt;length&gt;")}} - : A positive integer length. - `<line-names>` - : Zero or more {{cssxref("&lt;custom-ident&gt;")}} values, space-separated and enclosed in square brackets, like this: `[first header-start]`. - {{cssxref("&lt;percentage&gt;")}} - : A non-negative percentage relative to the inline size of the grid container in column grid tracks, and the block size of the grid container in row grid tracks. If the size of the grid container depends on the size of its tracks, then the `<percentage>` must be treated as `auto`. The user-agent may adjust the intrinsic size contributions of the track to the size of the grid container and increase the final size of the track by the minimum amount that would result in honoring the percentage. - `<track-size>` - : One of the following forms: - a {{cssxref("&lt;length-percentage&gt;")}} value, a {{cssxref("&lt;flex&gt;")}} value, or one of the following keywords: [`min-content`](#min-content), [`max-content`](#max-content), or [`auto`](#auto) - a {{cssxref("minmax", "minmax()")}} function with: - `min` given as a {{cssxref("&lt;length-percentage&gt;")}} value, or one of the following keywords: [`min-content`](#min-content), [`max-content`](#max-content), or [`auto`](#auto) - `max` given as a {{cssxref("&lt;length-percentage&gt;")}} value, a {{cssxref("&lt;flex&gt;")}} value, or one of the following keywords: [`min-content`](#min-content), [`max-content`](#max-content), or [`auto`](#auto) - a {{cssxref("fit-content_function", "fit-content()")}} function, passed a {{cssxref("&lt;length-percentage&gt;")}} value. - `auto` - : As a maximum, identical to `max-content`. As a minimum it represents the largest minimum size (as specified by {{cssxref("min-width")}}/{{cssxref("min-height")}}) of the grid items occupying the grid track. - `auto-fill` - : If the grid container has a definite or maximal size in the relevant axis, then the number of repetitions is the largest possible positive integer that does not cause the grid to overflow its grid container. Treating each track as its maximal track sizing function (each independent value used to define `grid-template-rows` or `grid-template-columns`), if that is definite. Otherwise, as its minimum track sizing function, and taking grid-gap into account. If any number of repetitions would overflow, then the repetition is `1`. Otherwise, if the grid container has a definite minimal size in the relevant axis, the number of repetitions is the smallest possible positive integer that fulfills that minimum requirement. Otherwise, the specified track list repeats only once. - `auto-fit` - : Behaves the same as `auto-fill`, except that after placing the grid items any empty repeated tracks are collapsed. An empty track is one with no in-flow grid items placed into or spanning across it. (This can result in all tracks being collapsed, if they're all empty.) A collapsed track is treated as having a single fixed track sizing function of `0px`, and the gutters on either side of it collapse. For the purpose of finding the number of auto-repeated tracks, the user agent floors the track size to a user agent specified value (e.g., `1px`), to avoid division by zero. - `max-content` - : Represents the largest max-content contribution of the grid items occupying the grid track. - `min-content` - : Represents the largest min-content contribution of the grid items occupying the grid track. ## Examples ### Specifying grid columns using repeat() #### HTML ```html <div id="container"> <div>This item is 50 pixels wide.</div> <div>Item with flexible width.</div> <div>This item is 50 pixels wide.</div> <div>Item with flexible width.</div> <div>Inflexible item of 100 pixels width.</div> </div> ``` #### CSS ```css #container { display: grid; grid-template-columns: repeat(2, 50px 1fr) 100px; grid-gap: 5px; box-sizing: border-box; height: 200px; width: 100%; background-color: #8cffa0; padding: 10px; } #container > div { background-color: #8ca0ff; padding: 5px; } ``` #### Result {{EmbedLiveSample("Specifying_grid_columns_using_repeat", "100%", 200)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Related CSS properties: {{cssxref("grid-template")}}, {{cssxref("grid-template-rows")}}, {{cssxref("grid-template-columns")}}, {{cssxref("grid-template-areas")}}, {{cssxref("grid-auto-columns")}}, {{cssxref("grid-auto-rows")}}, {{cssxref("grid-auto-flow")}} - Grid Layout Guide: _[Line-based placement with CSS Grid](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_layout_using_line-based_placement)_ - Grid Layout Guide: _[Grid template areas - Grid definition shorthands](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_template_areas#grid_definition_shorthands)_
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/object-fit/index.md
--- title: object-fit slug: Web/CSS/object-fit page-type: css-property browser-compat: css.properties.object-fit --- {{CSSRef}} The **`object-fit`** [CSS](/en-US/docs/Web/CSS) property sets how the content of a [replaced element](/en-US/docs/Web/CSS/Replaced_element), such as an {{HTMLElement("img")}} or {{HTMLElement("video")}}, should be resized to fit its container. You can alter the alignment of the replaced element's content object within the element's box using the {{cssxref("object-position")}} property. {{EmbedInteractiveExample("pages/css/object-fit.html")}} ## Syntax ```css object-fit: contain; object-fit: cover; object-fit: fill; object-fit: none; object-fit: scale-down; /* Global values */ object-fit: inherit; object-fit: initial; object-fit: revert; object-fit: revert-layer; object-fit: unset; ``` The `object-fit` property is specified as a single keyword chosen from the list of values below. ### Values - `contain` - : The replaced content is scaled to maintain its aspect ratio while fitting within the element's content box. The entire object is made to fill the box, while preserving its aspect ratio, so the object will be ["letterboxed"](<https://en.wikipedia.org/wiki/Letterboxing_(filming)>) if its aspect ratio does not match the aspect ratio of the box. - `cover` - : The replaced content is sized to maintain its aspect ratio while filling the element's entire content box. If the object's aspect ratio does not match the aspect ratio of its box, then the object will be clipped to fit. - `fill` - : The replaced content is sized to fill the element's content box. The entire object will completely fill the box. If the object's aspect ratio does not match the aspect ratio of its box, then the object will be stretched to fit. - `none` - : The replaced content is not resized. - `scale-down` - : The content is sized as if `none` or `contain` were specified, whichever would result in a smaller concrete object size. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting object-fit for an image #### HTML ```html <section> <h2>object-fit: fill</h2> <img class="fill" src="mdn_logo_only_color.png" alt="MDN Logo" /> <img class="fill narrow" src="mdn_logo_only_color.png" alt="MDN Logo" /> <h2>object-fit: contain</h2> <img class="contain" src="mdn_logo_only_color.png" alt="MDN Logo" /> <img class="contain narrow" src="mdn_logo_only_color.png" alt="MDN Logo" /> <h2>object-fit: cover</h2> <img class="cover" src="mdn_logo_only_color.png" alt="MDN Logo" /> <img class="cover narrow" src="mdn_logo_only_color.png" alt="MDN Logo" /> <h2>object-fit: none</h2> <img class="none" src="mdn_logo_only_color.png" alt="MDN Logo" /> <img class="none narrow" src="mdn_logo_only_color.png" alt="MDN Logo" /> <h2>object-fit: scale-down</h2> <img class="scale-down" src="mdn_logo_only_color.png" alt="MDN Logo" /> <img class="scale-down narrow" src="mdn_logo_only_color.png" alt="MDN Logo" /> </section> ``` #### CSS ```css h2 { font-family: Courier New, monospace; font-size: 1em; margin: 1em 0 0.3em; } img { width: 150px; height: 100px; border: 1px solid #000; margin: 10px 0; } .narrow { width: 100px; height: 150px; } .fill { object-fit: fill; } .contain { object-fit: contain; } .cover { object-fit: cover; } .none { object-fit: none; } .scale-down { object-fit: scale-down; } ``` #### Result {{ EmbedLiveSample('Setting_object-fit_for_an_image', 500, 1100) }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Other image-related CSS properties: {{cssxref("object-position")}}, {{cssxref("image-orientation")}}, {{cssxref("image-rendering")}}, {{cssxref("image-resolution")}}. - {{cssxref("background-size")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/-webkit-text-fill-color/index.md
--- title: "-webkit-text-fill-color" slug: Web/CSS/-webkit-text-fill-color page-type: css-property browser-compat: css.properties.-webkit-text-fill-color --- {{CSSRef}} The **`-webkit-text-fill-color`** CSS property specifies the fill [color](/en-US/docs/Web/CSS/color_value) of characters of text. If this property is not set, the value of the {{cssxref("color")}} property is used. ## Syntax ```css /* <color> values */ -webkit-text-fill-color: red; -webkit-text-fill-color: #000000; -webkit-text-fill-color: rgb(100 200 0); /* Global values */ -webkit-text-fill-color: inherit; -webkit-text-fill-color: initial; -webkit-text-fill-color: revert; -webkit-text-fill-color: revert-layer; -webkit-text-fill-color: unset; ``` ### Values - `<color>` - : The foreground fill color of the element's text content. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Changing the fill color #### CSS ```css p { margin: 0; font-size: 3em; -webkit-text-fill-color: green; } ``` #### HTML ```html <p>This text is green.</p> ``` #### Results {{EmbedLiveSample("Changing_the_fill_color", "380px", "60px")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Surfin' Safari blog post announcing this feature](https://webkit.org/blog/85/introducing-text-stroke/) - [CSS-Tricks article explaining this feature](https://css-tricks.com/adding-stroke-to-web-text/) - {{cssxref("-webkit-text-stroke-color")}} - {{cssxref("-webkit-text-stroke-width")}} - {{cssxref("-webkit-text-stroke")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/display-legacy/index.md
--- title: <display-legacy> slug: Web/CSS/display-legacy page-type: css-type browser-compat: - css.properties.display.inline-block - css.properties.display.inline-table - css.properties.display.inline-flex - css.properties.display.inline-grid spec-urls: https://drafts.csswg.org/css-display/#typedef-display-legacy --- {{CSSRef}} CSS 2 used a single-keyword syntax for the `display` property, requiring separate keywords for block-level and inline-level variants of the same layout mode. This page details those values. ## Syntax Valid `<display-legacy>` values: - `inline-block` - : The element generates a block element box that will be flowed with surrounding content as if it were a single inline box (behaving much like a replaced element would). It is equivalent to `inline flow-root`. - `inline-table` - : The `inline-table` value does not have a direct mapping in HTML. It behaves like an HTML {{HTMLElement("table")}} element, but as an inline box, rather than a block-level box. Inside the table box is a block-level context. It is equivalent to `inline table`. - `inline-flex` - : The element behaves like an inline element and lays out its content according to the flexbox model. It is equivalent to `inline flex`. - `inline-grid` - : The element behaves like an inline element and lays out its content according to the grid model. It is equivalent to `inline grid`. ## Formal syntax {{csssyntax}} ## Examples In the below example, we are creating an inline flex container with the legacy keyword inline-flex. ### HTML ```html <div class="container"> <div>Flex Item</div> <div>Flex Item</div> </div> Not a flex item ``` ### CSS ```css .container { display: inline-flex; } ``` ### Result {{EmbedLiveSample("Examples", 300, 150)}} In the new syntax the inline flex container would be created using two values, inline for the outer display type, and flex for the inner display type. ```css .container { display: inline flex; } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("display")}} - {{CSSxRef("&lt;display-outside&gt;")}} - {{CSSxRef("&lt;display-inside&gt;")}} - {{CSSxRef("&lt;display-listitem&gt;")}} - {{CSSxRef("&lt;display-internal&gt;")}} - {{CSSxRef("&lt;display-box&gt;")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/abs/index.md
--- title: abs() slug: Web/CSS/abs page-type: css-function browser-compat: css.types.abs --- {{CSSRef}} The **`abs()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) returns the absolute value of the argument, as the same type as the input. ## Syntax ```css /* property: abs(expression) */ width: abs(20% - 100px); ``` ### Parameters The `abs(x)` function accepts only one value as its parameter. - `x` - : A calculation which resolves to a number. ### Return value The absolute value of `x`. - if `x`'s numeric value is positive or `0⁺`, return `x`. - Otherwise, returns `-1 * x`. ### Formal syntax {{CSSSyntax}} ## Examples ### Positive variables The `abs()` function can be used to ensure that a value is always positive. In the following example a CSS custom property `--font-size` is used as the value of {{CSSxRef("font-size")}}. Wrapping this custom property in `abs()` will convert a negative value to a positive one. ```css h1 { font-size: abs(var(--font-size)); } ``` ### Control gradient angle of direction You can also control the gradient direction using `abs()` function. In the following example, with an angle of -45deg the gradient would start red and transition to blue. By using `abs()` to make the value positive, the gradient will start blue and transition to red. ```css div { --deg: -45deg; background-image: linear-gradient(abs(var(--deg)), blue, red); } ``` ### Backwards compatible fallback In older browsers that lack the support for CSS `abs()` function, you can use the CSS {{CSSxRef("max")}} function to achieve the same result, as shown below: ```css p { line-height: max(var(--lh), -1 * var(--lh)); } ``` We use the {{CSSxRef("max")}} function to return the largest (most positive) value from a list of two values: `var(--lh)` or `-1 * var(--lh)`. Irrespective of whether `--lh` is positive or negative, the calculated return value will always be positive, that is, an absolute number. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("sign")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/padding-bottom/index.md
--- title: padding-bottom slug: Web/CSS/padding-bottom page-type: css-property browser-compat: css.properties.padding-bottom --- {{CSSRef}} The **`padding-bottom`** [CSS](/en-US/docs/Web/CSS) property sets the height of the [padding area](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model#padding_area) on the bottom of an element. {{EmbedInteractiveExample("pages/css/padding-bottom.html")}} An element's padding area is the space between its content and its border. ![The effect of the CSS padding-bottom property on the element box](padding-bottom.svg) > **Note:** The {{cssxref("padding")}} property can be used to set paddings on all four sides of an element with a single declaration. ## Syntax ```css /* <length> values */ padding-bottom: 0.5em; padding-bottom: 0; padding-bottom: 2cm; /* <percentage> value */ padding-bottom: 10%; /* Global values */ padding-bottom: inherit; padding-bottom: initial; padding-bottom: revert; padding-bottom: revert-layer; padding-bottom: unset; ``` The `padding-bottom` property is specified as a single value chosen from the list below. Unlike margins, negative values are not allowed for padding. ### Values - {{cssxref("&lt;length&gt;")}} - : The size of the padding as a fixed value. Must be nonnegative. - {{cssxref("&lt;percentage&gt;")}} - : The size of the padding as a percentage, relative to the inline size (_width_ in a horizontal language, defined by {{cssxref("writing-mode")}}) of the [containing block](/en-US/docs/Web/CSS/Containing_block). Must be nonnegative. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting padding bottom with pixels and percentages ```css .content { padding-bottom: 5%; } .sidebox { padding-bottom: 10px; } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Introduction to the CSS basic box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model) - {{cssxref("padding-top")}}, {{cssxref("padding-right")}}, {{cssxref("padding-left")}} and the {{cssxref("padding")}} shorthand - The mapped logical properties: {{cssxref("padding-block-start")}}, {{cssxref("padding-block-end")}}, {{cssxref("padding-inline-start")}}, and {{cssxref("padding-inline-end")}} and the shorthands {{cssxref("padding-block")}} and {{cssxref("padding-inline")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/padding-bottom/padding-bottom.svg
<svg baseProfile="full" xmlns="http://www.w3.org/2000/svg" width="400" height="130"><defs><pattern id="a" patternUnits="userSpaceOnUse" x="0" y="0" width="105" height="105"><path d="m0 90 15 15M0 75l30 30M0 60l45 45M0 45l60 60M0 30l75 75M0 15l90 90M0 0l105 105M15 0l90 90M30 0l75 75M45 0l60 60M60 0l45 45M75 0l30 30M90 0l15 15"/></pattern></defs><path fill="azure" d="M130 10h140v90H130z"/><path stroke="#000" stroke-dasharray="3 2" fill="#fff" d="M150 30h100v50H150z"/><path fill="beige" d="M160 40h80v30h-80z"/><text x="290" y="24" font-family="sans-serif" font-size="10pt">Padding area</text><path stroke="#000" d="M288 93h-33"/><text x="290" y="48" font-family="sans-serif" font-size="10pt">Border</text><path stroke="#000" d="M288 44h-38"/><text x="290" y="71" font-family="sans-serif" font-size="10pt">Content area</text><path stroke="#000" d="m288 67-58-7"/><text x="290" y="97" font-family="sans-serif" font-size="10pt">Margin area</text><path stroke="#000" d="m288 20-53 15"/><path fill="url(#a)" stroke="#000" d="M150 70h100v10H150z"/><path stroke="#000" d="M200 105V75"/><text x="22" y="120" font-family="sans-serif" font-size="10pt">The height of this area is defined by the padding-bottom value</text><path stroke="#000" d="M136 70h8m-8 10h8m-4-10v10"/><text x="20" y="77" font-family="'courier new',monospace" font-size="10pt">padding-bottom</text></svg>
0