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 | data/mdn-content/files/en-us/web/css/-moz-force-broken-image-icon/index.md | ---
title: "-moz-force-broken-image-icon"
slug: Web/CSS/-moz-force-broken-image-icon
page-type: css-property
status:
- deprecated
- non-standard
browser-compat: css.properties.-moz-force-broken-image-icon
---
{{Non-standard_header}}{{CSSRef}}{{Deprecated_Header}}
The **`-moz-force-broken-image-icon`** extended CSS property can be used to force the broken image icon to be shown even when a broken image has an `alt` attribute.
## Syntax
### Values
- {{cssxref("<integer>")}}
- : A value of `1` means that the broken image icon is shown even if the image has an [`alt`](/en-US/docs/Web/HTML/Element/img#alt) attribute. When the value `0` is used, the image will act as usual and only display the `alt` attribute.
> **Note:** Even if the value is set to `1` the `alt` attribute will still be displayed, alongside the broken image icon.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### HTML
```html
<img src="/broken/image/link.png" alt="Broken image link" />
```
### CSS
```css
img {
-moz-force-broken-image-icon: 1;
height: 100px;
width: 100px;
}
```
### Result
{{EmbedLiveSample('Examples','125','125')}}
> **Note:** Unless the image has a specified height and width the broken image icon will not be displayed but the alt attribute will also be hidden if `-moz-force-broken-image-icon` is set to `1`.
## Notes
- This property will only work in Gecko-based browsers.
- The use of this property is not recommended. A proper `alt` attribute should be used instead.
## Specifications
Not part of any standard.
## Browser compatibility
{{Compat}}
## See also
- [Firefox bug 58646](https://bugzil.la/58646)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/calc-sum/index.md | ---
title: <calc-sum>
slug: Web/CSS/calc-sum
page-type: css-type
browser-compat: css.types.calc-sum
---
{{CSSRef}}
The **`<calc-sum>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) represents an expression which performs a calculation in any [CSS math function](/en-US/docs/Web/CSS/CSS_Functions#math_functions). The expression executes a basic arithmetic operation of addition and subtraction between two values.
## Syntax
The `<calc-sum>` type defines two numeric values and one of the following [arithmetic operators](/en-US/docs/Learn/JavaScript/First_steps/Math#arithmetic_operators) between them.
- `+`
- : Adds two numbers together.
- `-`
- : Subtracts the right number from the left.
### Formal syntax
{{CSSSyntax}}
## Description
The operands in the expression may be any {{cssxref("<length>")}} syntax value. You can use {{cssxref("<length>")}}, {{cssxref("<frequency>")}}, {{cssxref("<angle>")}}, {{cssxref("<time>")}}, {{cssxref("<percentage>")}}, {{cssxref("<number>")}}, or {{cssxref("<integer>")}}.
Different unit types can be used in a single expression. For example, subtracting `px` from `%`, as in `calc(100% - 10px)`, is a valid expression.
Including [CSS variables](/en-US/docs/Web/CSS/CSS_cascading_variables) in `calc-sum` expressions is also allowed. The following code `calc(10px + var(--variable))`, is a valid expression.
The `+` and `-` operators **must be surrounded by {{Glossary("whitespace")}}**. For instance, `calc(50% -8px)` will be parsed as a percentage followed by a negative length — an invalid expression — while `calc(50% - 8px)` is a percentage followed by a subtraction operator and a length. Likewise, `calc(8px + -50%)` is treated as a length followed by an addition operator and a negative percentage.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef("<calc-product>")}}
- {{CSSxRef("<calc-value>")}}
- {{CSSxRef("<calc-constant>")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/backdrop-filter/index.md | ---
title: backdrop-filter
slug: Web/CSS/backdrop-filter
page-type: css-property
browser-compat: css.properties.backdrop-filter
---
{{CSSRef}}
The **`backdrop-filter`** [CSS](/en-US/docs/Web/CSS) property lets you apply graphical effects such as blurring or color shifting to the area behind an element. Because it applies to everything _behind_ the element, to see the effect the element or its background needs to be transparent or partially transparent.
{{EmbedInteractiveExample("pages/css/backdrop-filter.html")}}
## Syntax
```css
/* Keyword value */
backdrop-filter: none;
/* URL to SVG filter */
backdrop-filter: url(commonfilters.svg#filter);
/* <filter-function> values */
backdrop-filter: blur(2px);
backdrop-filter: brightness(60%);
backdrop-filter: contrast(40%);
backdrop-filter: drop-shadow(4px 4px 10px blue);
backdrop-filter: grayscale(30%);
backdrop-filter: hue-rotate(120deg);
backdrop-filter: invert(70%);
backdrop-filter: opacity(20%);
backdrop-filter: sepia(90%);
backdrop-filter: saturate(80%);
/* Multiple filters */
backdrop-filter: url(filters.svg#filter) blur(4px) saturate(150%);
/* Global values */
backdrop-filter: inherit;
backdrop-filter: initial;
backdrop-filter: revert;
backdrop-filter: revert-layer;
backdrop-filter: unset;
```
### Values
- `none`
- : No filter is applied to the backdrop.
- `<filter-function-list>`
- : A space-separated list of {{cssxref("<filter-function>")}}s or an [SVG filter](/en-US/docs/Web/SVG/Element/filter) that will be applied to the backdrop. CSS `<filter-function>`s include {{CSSxRef("filter-function/blur", "blur()")}}, {{CSSxRef("filter-function/brightness", "brightness()")}}, {{CSSxRef("filter-function/contrast", "contrast()")}}, {{CSSxRef("filter-function/drop-shadow", "drop-shadow()")}}, {{CSSxRef("filter-function/grayscale", "grayscale()")}}, {{CSSxRef("filter-function/hue-rotate", "hue-rotate()")}}, {{CSSxRef("filter-function/invert", "invert()")}}, {{CSSxRef("filter-function/opacity", "opacity()")}}, {{CSSxRef("filter-function/saturate", "saturate()")}}, and {{CSSxRef("filter-function/sepia", "sepia()")}}.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### CSS
```css
.box {
background-color: rgb(255 255 255 / 30%);
backdrop-filter: blur(10px);
}
body {
background-image: url("anemones.jpg");
}
```
```css hidden
html,
body {
height: 100%;
width: 100%;
}
.container {
background-size: cover;
align-items: center;
display: flex;
justify-content: center;
height: 100%;
width: 100%;
}
.box {
border-radius: 5px;
font-family: sans-serif;
text-align: center;
max-width: 50%;
max-height: 50%;
padding: 20px 40px;
}
```
### HTML
```html
<div class="container">
<div class="box">
<p>backdrop-filter: blur(10px)</p>
</div>
</div>
```
### Result
{{EmbedLiveSample("Examples", 600, 400)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("filter")}}
- {{cssxref("<filter-function>")}}
- {{cssxref("background-blend-mode")}}, {{cssxref("mix-blend-mode")}}
- [CSS filter effects](/en-US/docs/Web/CSS/CSS_filter_effects)
- [CSS compositing and blending](/en-US/docs/Web/CSS/CSS_compositing_and_blending)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/font-variant-ligatures/index.md | ---
title: font-variant-ligatures
slug: Web/CSS/font-variant-ligatures
page-type: css-property
browser-compat: css.properties.font-variant-ligatures
---
{{CSSRef}}
The **`font-variant-ligatures`** CSS property controls which {{Glossary("ligature", "ligatures")}} and {{Glossary("contextual forms")}} are used in textual content of the elements it applies to. This leads to more harmonized forms in the resulting text.
{{EmbedInteractiveExample("pages/css/font-variant-ligatures.html")}}
## Syntax
```css
/* Keyword values */
font-variant-ligatures: normal;
font-variant-ligatures: none;
font-variant-ligatures: common-ligatures; /* <common-lig-values> */
font-variant-ligatures: no-common-ligatures; /* <common-lig-values> */
font-variant-ligatures: discretionary-ligatures; /* <discretionary-lig-values> */
font-variant-ligatures: no-discretionary-ligatures; /* <discretionary-lig-values> */
font-variant-ligatures: historical-ligatures; /* <historical-lig-values> */
font-variant-ligatures: no-historical-ligatures; /* <historical-lig-values> */
font-variant-ligatures: contextual; /* <contextual-alt-values> */
font-variant-ligatures: no-contextual; /* <contextual-alt-values> */
/* Global values */
font-variant-ligatures: inherit;
font-variant-ligatures: initial;
font-variant-ligatures: revert;
font-variant-ligatures: revert-layer;
font-variant-ligatures: unset;
```
The `font-variant-ligatures` property is specified as one of the keyword values listed below.
### Values
- `normal`
- : This keyword leads to the activation of the usual ligatures and contextual forms needed for correct rendering. The ligatures and forms activated depend on the font, language and kind of script. This is the default value.
- `none`
- : This keyword specifies that all ligatures and contextual forms are disabled, even common ones.
- _`<common-lig-values>`_
- : These values control the most common ligatures, like for `fi`, `ffi`, `th` or similar. They correspond to the OpenType values `liga` and `clig`. Two values are possible:
- `common-ligatures` activating these ligatures. Note that the keyword `normal` activates these ligatures.
- `no-common-ligatures` deactivating these ligatures.
- _`<discretionary-lig-values>`_
- : These values control specific ligatures, specific to the font and defined by the type designer. They correspond to the OpenType values `dlig`. Two values are possible:
- `discretionary-ligatures` activating these ligatures.
- `no-discretionary-ligatures` deactivating the ligatures. Note that the keyword `normal` usually deactivates these ligatures.
- _`<historical-lig-values>`_
- : These values control the ligatures used historically, in old books, like the German tz digraph being displayed as ꜩ. They correspond to the OpenType values `hlig`. Two values are possible:
- `historical-ligatures` activating these ligatures.
- `no-historical-ligatures` deactivating the ligatures. Note that the keyword `normal` usually deactivates these ligatures.
- _`<contextual-alt-values>`_
- : These values control whether letters adapt to their context—that is, whether they adapt to the surrounding letters. These values correspond to the OpenType values `calt`. Two values are possible:
- `contextual` specifies that the contextual alternates are to be used. Note that the keyword `normal` usually activates these ligatures too.
- `no-contextual` prevents their use.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting font ligatures and contextual forms
#### HTML
```html
<link href="//fonts.googleapis.com/css?family=Lora" rel="stylesheet" />
<p class="normal">
normal<br />
if fi ff tf ft jf fj
</p>
<p class="none">
none<br />
if fi ff tf ft jf fj
</p>
<p class="common-ligatures">
common-ligatures<br />
if fi ff tf ft jf fj
</p>
<p class="no-common-ligatures">
no-common-ligatures<br />
if fi ff tf ft jf fj
</p>
<p class="discretionary-ligatures">
discretionary-ligatures<br />
if fi ff tf ft jf fj
</p>
<p class="no-discretionary-ligatures">
no-discretionary-ligatures<br />
if fi ff tf ft jf fj
</p>
<p class="historical-ligatures">
historical-ligatures<br />
if fi ff tf ft jf fj
</p>
<p class="no-historical-ligatures">
no-historical-ligatures<br />
if fi ff tf ft jf fj
</p>
<p class="contextual">
contextual<br />
if fi ff tf ft jf fj
</p>
<p class="no-contextual">
no-contextual<br />
if fi ff tf ft jf fj
</p>
```
#### CSS
```css
p {
font-family: Lora, serif;
}
.normal {
font-variant-ligatures: normal;
}
.none {
font-variant-ligatures: none;
}
.common-ligatures {
font-variant-ligatures: common-ligatures;
}
.no-common-ligatures {
font-variant-ligatures: no-common-ligatures;
}
.discretionary-ligatures {
font-variant-ligatures: discretionary-ligatures;
}
.no-discretionary-ligatures {
font-variant-ligatures: no-discretionary-ligatures;
}
.historical-ligatures {
font-variant-ligatures: historical-ligatures;
}
.no-historical-ligatures {
font-variant-ligatures: no-historical-ligatures;
}
.contextual {
font-variant-ligatures: contextual;
}
.no-contextual {
font-variant-ligatures: no-contextual;
}
```
#### Result
{{ EmbedLiveSample('Setting font ligatures and contextual forms', '', '700') }}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [`font-variant`](/en-US/docs/Web/CSS/font-variant)
- [`font-variant-caps`](/en-US/docs/Web/CSS/font-variant-caps)
- [`font-variant-emoji`](/en-US/docs/Web/CSS/font-variant-emoji)
- [`font-variant-east-asian`](/en-US/docs/Web/CSS/font-variant-east-asian)
- [`font-variant-numeric`](/en-US/docs/Web/CSS/font-variant-numeric)
- [`font-variant-position`](/en-US/docs/Web/CSS/font-variant-position)
- [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/relative-size/index.md | ---
title: <relative-size>
slug: Web/CSS/relative-size
page-type: css-type
spec-urls: https://drafts.csswg.org/css-fonts/#valdef-font-size-relative-size
---
{{CSSRef}}
The **`<relative-size>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) describes relative size keywords. The `<relative-size>` keywords define a size relative to the computed size of the parent element. This data type is used in the {{cssxref("font")}} shorthand and {{cssxref("font-size")}} properties.
## Syntax
```plain
<relative-size> = smaller | larger
```
### Values
The `<relative-size>` data type is defined using a keyword value chosen from the list below.
- `smaller`
- : A relative size one size smaller than the inherited size.
- `larger`
- : A relative size one size larger than the inherited size.
## Description
The `<relative-size>` keywords are relative to the current size of the element. If the inherited size is defined using an {{cssxref("absolute-size")}} keyword, the `<relative-size>` value equates to the adjacent size in the [`<absolute-size>` table](/en-US/docs/Web/CSS/absolute-size#description). Otherwise, the relative increase or decrease in size is between 120% and 150%.
## Examples
### Comparing the keyword values
```html
<ul>
<li class="smaller">font-size: smaller;</li>
<li>font-size is not specified</li>
<li class="larger">font-size: larger;</li>
</ul>
```
```css
li {
margin-bottom: 0.3em;
}
.smaller {
font-size: smaller;
}
.larger {
font-size: larger;
}
```
#### Result
{{EmbedLiveSample('Comparing the keyword values', '100%', 100)}}
## Specifications
{{Specifications}}
## See also
- CSS {{cssxref("absolute-size")}} data type
- CSS {{cssxref("font")}} and {{cssxref("font-size")}} properties
- [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/viewport_concepts/index.md | ---
title: Viewport concepts
slug: Web/CSS/Viewport_concepts
page-type: guide
---
{{CSSRef}}
This article explains the concept of the viewport — what it is, its impact in terms of CSS, SVG, and mobile devices — and differentiates between the visual viewport and the layout viewport.
## What is a viewport?
A viewport represents the area in computer graphics being currently viewed. In web browser terms, it is generally the same as the browser window, excluding the UI, menu bar, etc. That is the part of the document you are viewing.
Documents like this article may be very long. Your viewport is everything that is currently visible, notably, the "what is a viewport" section, and perhaps some of the navigation menu. The size of the viewport depends on the size of the screen, whether the browser is in fullscreen mode or not, and whether or not the user zoomed in. Content outside the viewport, such as the _See Also_ section in this document, is likely to not be visible onscreen until scrolled into view.
- On larger monitors where applications aren't necessarily full screen, the viewport is the size of the browser window.
- On most mobile devices and when the browser is in fullscreen mode, the viewport is the entire screen.
- In fullscreen mode, the viewport is the device screen, the window is the browser window, which can be as big as the viewport or smaller, and the document is the website, which can be much taller or wider than the viewport.
To recap, the viewport is basically the part of the document that is currently visible.
### Viewport sizes are mutable
The width of the viewport is not always the width of the window. If you query the width or height of the window and document in Chrome or Firefox, you may get:
```js
document.documentElement.clientWidth; /* 1200 */
window.innerWidth; /* 1200 */
window.outerWidth; /* 1200 */
```
```js
document.documentElement.clientHeight; /* 800 */
window.innerHeight; /* 800 */
window.outerHeight; /* 900 */
```
There are several DOM properties that can help you query viewport size, and other similar lengths:
- The document element's {{DOMxRef("Element.clientWidth")}} is the inner width of a document in [CSS pixels](/en-US/docs/Web/HTML/Viewport_meta_tag#screen_density), including padding (but not borders, margins, or vertical scrollbars, if present). **This is the viewport width**.
- The {{DOMxRef("Window.innerWidth")}} is the width, in CSS pixels, of the browser window viewport including, if rendered, the vertical scrollbar.
- The {{DOMxRef("Window.outerWidth")}} is the width of the outside of the browser window including all the window {{glossary("chrome")}}.
In an experiment with these, the `innerWidth` and `outerWidth` was seen to be the same, but the `outerHeight` was 100px taller than the `innerHeight`. This is because the `outerHeight` includes the browser chrome: measurements were taken on a browser with an address bar and bookmarks bar totalling 100px in height, but no chrome on the left or right of the window.
The area within the `innerHeight` and `innerWidth` is generally considered the **layout viewport**. The browser chrome is not considered part of the viewport.
When zoomed in, both Firefox and Chrome report the new CSS pixel size for `innerWidth` and `clientWidth`. The values returned for the `outerWidth` and `outerHeight` depend on the browser: Firefox reports the new value in CSS pixels, but Chrome returns the length in the default pixel size. When zoomed in you may get:
```js
document.documentElement.clientWidth; /* 800 */
window.innerWidth; /* 800 */
window.outerWidth; /* 800 in Firefox, 1200 in chrome */
```
```js
document.documentElement.clientHeight; /* 533 */
window.innerHeight; /* 533 */
window.outerHeight; /* 596 in Firefox, 900 in chrome */
```
The viewport was originally 1200 x 800 pixels. Upon zooming in, the viewport became 800 x 533 pixels. This is the _layout viewport_. Sticky headers or footers, with the following styles, will stick to the top and bottom of the _layout viewport_ respectively.
```css
body > header {
position: fixed;
top: 0;
}
body > footer {
position: fixed;
bottom: 0;
}
```
We got the 800 x 533 measurement when we zoomed in using the keyboard. The header and footer stayed flush against the top and bottom of the window. But what if we had pinched-zoomed on a tablet? What if a dynamic keyboard pops open on a phone?
The web contains two viewports, the **layout viewport** and the **visual viewport**. The visual viewport is the part of the web page that is currently visible in the browser and can change. When the user pinch-zooms the page, pops open a dynamic keyboard, or when a previously hidden address bar becomes visible, the visual viewport shrinks but the layout viewport is unchanged.
Sticky headers or footers, as discussed above, stick to the top and bottom of the _layout viewport_, and therefore remain in view when we zoom in with the keyboard. If you pinch-zoom, the layout viewport may not be fully visible. If you magnify from the middle of the layout viewport, the content will expand in all four directions. If you have a sticky header or footer, they will still be stuck to the top or bottom of the layout viewport, but they may not be visible at the top and bottom of the device's screen — which is the visual viewport. The visual viewport is the currently visible portion of the layout viewport. If you scroll down, you are changing the contents of the visual viewport and bringing the bottom of the layout viewport into view, displaying the sticky footer, which will then stay stuck at the bottom.
The visual viewport is the visual portion of a screen not including on-screen keyboards, areas outside of a pinch-zoom area, or other feature that doesn't scale with the dimensions of a page. The visual viewport is the same size as the layout viewport or smaller.
For a page containing iframes, objects, or external SVG, both the containing pages and each included file has their own unique window object. Only the top-level window has a visual viewport that may be distinct from the layout viewport. For included documents, the visual viewport and layout viewport are the same.
### CSS
The layout viewport and visual viewport described above are not the only viewports you will encounter. Any sub-viewport that is fully or partially displayed within the layout viewport is considered a visual viewport.
We generally think of width and height media queries as being relative to the width and height of the browser window. They are actually relative to the viewport, which is the window in the main document but is the intrinsic size of the element's parent in a nested browsing context like objects, iframes and SVG. In CSS, we also have length units based on the viewport size. A `vh` unit is 1% of the layout viewport's height. Similarly, the `vw` unit is 1% of the layout viewport's width.
#### `<iframe>`
Inside an iframe, the visual viewport is the size of the inner width and height of the iframe, rather than the parent document. You can set any height and width on an iframe, but the whole document may not be visible.
If you use viewport length units in your CSS within the iframe document, `1vh` will be 1% of the height of the iframe, and `1vw` will be 1% of the width of the document.
```css
iframe {
width: 50vw;
}
```
If the iframe is set to 50vw, it will be 50% of the width of the `1200px` parent document in our example above, or `600px`, with `1vw` being `6px`. When zoomed in, the iframe shrinks to `400px` and `1vw` becomes `4px`.
A width-based media query within the iframe document is relative to the iframe's viewport.
```css
@media screen and (min-width: 500px) {
p {
color: red;
}
}
```
If the above CSS is included in the iframe, the paragraphs will become red when the user has zoomed in, but this style does not apply in the non-zoomed-in state.
#### SVG
In an SVG document, the viewport is the visible area of the SVG image. You can set any height and width on an SVG, but the whole image might not be visible. The area that is visible is called the viewport. The size of the viewport can be defined using the width and height attributes of the {{SVGElement("svg")}} element.
```html
<svg height="300" width="400"></svg>
```
In this example, the viewport has an aspect ratio of 3:4 and is, by default, 400 by 300 units, with a unit generally being a CSS pixel.
SVG also has an internal coordinate system defined via the [viewBox](/en-US/docs/Web/SVG/Attribute/viewBox) attribute, which is not related to this viewport discussion.
If you include an SVG file in your HTML, the viewport of the SVG is the initial containing block, or the width and height of the SVG container. Using the {{CSSxRef("@media")}} query in your SVG's CSS is relative to that container, not the browser.
```css
@media screen and (min-width: 400px) and (max-width: 500px) {
/* CSS goes here */
}
```
Generally, when you write the above media query, the styles are applied if the viewport, generally the browser window, is between 400px and 500px, inclusive. The width media query in the SVG is based on the element in which the SVG is contained — the {{htmlelement("img")}} if the source is an SVG file, the SVG itself if the SVG is included directly into the HTML, or the parent if the parent element has a width assigned and — not the viewport's width. With the above media query being in our SVG file, the CSS is applied if the SVG container is between 400 and 500px.
### JavaScript
The [Visual Viewport API](/en-US/docs/Web/API/Visual_Viewport_API) provides a mechanism for querying and modifying the properties of the visual viewport.
## Mobile Viewports
Mobile devices come in all shapes and sizes, with screens of differing device pixel ratios. The mobile browser's viewport is the area of the window in which web content can be seen, which is not necessarily the same size as the rendered page. Mobile browsers render pages in a virtual window or viewport, generally at 980px, which is usually wider than the screen, and then shrink the rendered result down so it can all be seen at once. Users can then pan and zoom to see different areas of the page. For example, if a mobile screen has a width of 320px, a website might be rendered with a virtual viewport of 980px, and then it will be shrunk down to fit into the 320px space, which, depending on the design, is illegible for many if not everyone. To tell a mobile browser to use the viewport width instead of the default 980px as the width of the screen, developers can include a viewport meta tag, like the following:
```html
<meta name="viewport" content="width=device-width" />
```
The `width` property controls the size of the viewport. It should preferably be set to `device-width`, which is the width of the screen in CSS pixels at a scale of 100%. There are other properties, including `maximum-scale`, `minimum-scale`, and `user-scalable`, which control whether users can zoom the page in or out, but the default values are the best for accessibility and user experience, so these can be omitted.
## See also
- [Visual Viewport API](/en-US/docs/Web/API/Visual_Viewport_API)
- {{HTMLElement("meta")}}, specifically `<meta name="viewport">`
- [Using the viewport meta tag to control layout on mobile browsers](/en-US/docs/Web/HTML/Viewport_meta_tag)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_doublecolon_-webkit-search-cancel-button/index.md | ---
title: "::-webkit-search-cancel-button"
slug: Web/CSS/::-webkit-search-cancel-button
page-type: css-pseudo-element
status:
- non-standard
browser-compat: css.selectors.-webkit-search-cancel-button
---
{{CSSRef}}{{Non-standard_header}}
The **`::-webkit-search-cancel-button`** CSS [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) represents a button (the "cancel button") at the edge of an {{HTMLElement("input")}} of `type="search"` which clears away the current value of the {{HTMLElement("input")}} element. This button and pseudo-element are non-standard, supported only in WebKit and Blink, hence the vendor prefix. The clear button is only shown on non-empty search {{HTMLElement("input")}} elements.
## Syntax
```css
selector::-webkit-search-cancel-button {
/* ... */
}
```
## Specifications
Not part of any standard.
## Browser compatibility
{{Compat}}
## See also
- {{cssxref('::-webkit-search-results-button')}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/left/index.md | ---
title: left
slug: Web/CSS/left
page-type: css-property
browser-compat: css.properties.left
---
{{CSSRef}}
The **`left`** [CSS](/en-US/docs/Web/CSS) property participates in specifying the horizontal position of a [positioned element](/en-US/docs/Web/CSS/position). It has no effect on non-positioned elements.
{{EmbedInteractiveExample("pages/css/left.html")}}
## Syntax
```css
/* <length> values */
left: 3px;
left: 2.4em;
/* <percentage>s of the width of the containing block */
left: 10%;
/* Keyword value */
left: auto;
/* Global values */
left: inherit;
left: initial;
left: revert;
left: revert-layer;
left: unset;
```
### Values
- {{cssxref("<length>")}}
- : A negative, null, or positive {{cssxref("<length>")}} that represents:
- for _absolutely positioned elements_, the distance to the left edge of the containing block.
- for _relatively positioned elements_, the distance that the element is moved to the right of its normal position.
- {{cssxref("<percentage>")}}
- : A {{cssxref("<percentage>")}} of the containing block's width.
- `auto`
- : Specifies that:
- for _absolutely positioned elements_, the position of the element is based on the {{Cssxref("right")}} property, while `width: auto` is treated as a width based on the content; or if `right` is also `auto`, the element is positioned where it should horizontally be positioned if it were a static element.
- for _relatively positioned elements_, the distance of the element from its normal position is based on the {{Cssxref("right")}} property; or if `right` is also `auto`, the element is not moved horizontally at all.
- `inherit`
- : Specifies that the value is the same as the computed value from its parent element (which might not be its containing block). This computed value is then handled as if it were a {{cssxref("<length>")}}, {{cssxref("<percentage>")}}, or the `auto` keyword.
## Description
The effect of `left` depends on how the element is positioned (i.e., the value of the {{cssxref("position")}} property):
- When `position` is set to `absolute` or `fixed`, the `left` property specifies the distance between the element's outer margin of left edge and the inner border of left edge of its containing block. (The containing block is the ancestor to which the element is relatively positioned.)
- When `position` is set to `relative`, the `left` property specifies the distance the element's left edge is moved to the right from its normal position.
- When `position` is set to `sticky`, the `left` property is used to compute the sticky-constraint rectangle.
- When `position` is set to `static`, the `left` property has _no effect_.
When both `left` and {{cssxref("right")}} are defined, and width constraints don't prevent it, the element will stretch to satisfy both. If the element cannot stretch to satisfy both, the position of the element is _overspecified_. When this is the case, the `left` value has precedence when the container is left-to-right; the `right` value has precedence when the container is right-to-left.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Positioning elements
#### HTML
```html
<div id="wrap">
<div id="example_1">
<pre>
position: absolute;
left: 20px;
top: 20px;
</pre>
<p>
The only containing element for this div is the main window, so it
positions itself in relation to it.
</p>
</div>
<div id="example_2">
<pre>
position: relative;
top: 0;
right: 0;
</pre>
<p>Relative position in relation to its siblings.</p>
</div>
<div id="example_3">
<pre>
float: right;
position: relative;
top: 20px;
left: 20px;
</pre>
<p>Relative to its sibling div above, but removed from flow of content.</p>
<div id="example_4">
<pre>
position: absolute;
bottom: 10px;
right: 20px;
</pre>
<p>Absolute position inside of a parent with relative position</p>
</div>
<div id="example_5">
<pre>
position: absolute;
right: 0;
left: 0;
top: 200px;
</pre>
<p>Absolute position with both left and right declared</p>
</div>
</div>
</div>
```
#### CSS
```css
#wrap {
width: 700px;
margin: 0 auto;
background: #5c5c5c;
}
pre {
white-space: pre;
white-space: pre-wrap;
white-space: pre-line;
word-wrap: break-word;
}
#example_1 {
width: 200px;
height: 200px;
position: absolute;
left: 20px;
top: 20px;
background-color: #d8f5ff;
}
#example_2 {
width: 200px;
height: 200px;
position: relative;
top: 0;
right: 0;
background-color: #c1ffdb;
}
#example_3 {
width: 600px;
height: 400px;
position: relative;
top: 20px;
left: 20px;
background-color: #ffd7c2;
}
#example_4 {
width: 200px;
height: 200px;
position: absolute;
bottom: 10px;
right: 20px;
background-color: #ffc7e4;
}
#example_5 {
position: absolute;
right: 0;
left: 0;
top: 100px;
background-color: #d7ffc2;
}
```
#### Result
{{EmbedLiveSample('Positioning_elements',1200,650)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("inset")}}, the shorthand for all related properties: {{cssxref("top")}}, {{cssxref("bottom")}}, {{cssxref("left")}}, and {{cssxref("right")}}
- The mapped logical properties: {{cssxref("inset-block-start")}}, {{cssxref("inset-block-end")}}, {{cssxref("inset-inline-start")}}, and {{cssxref("inset-inline-end")}} and the shorthands {{cssxref("inset-block")}} and {{cssxref("inset-inline")}}
- {{cssxref("position")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/@keyframes/index.md | ---
title: "@keyframes"
slug: Web/CSS/@keyframes
page-type: css-at-rule
browser-compat: css.at-rules.keyframes
---
{{CSSRef}}
The **`@keyframes`** CSS [at-rule](/en-US/docs/Web/CSS/At-rule) controls the intermediate steps in a CSS animation sequence by defining styles for keyframes (or waypoints) along the animation sequence. This gives more control over the intermediate steps of the animation sequence than [transitions](/en-US/docs/Web/CSS/CSS_transitions).
## Syntax
```css
@keyframes slidein {
from {
transform: translateX(0%);
}
to {
transform: translateX(100%);
}
}
```
### Values
- {{cssxref("custom-ident")}}
- : A name identifying the keyframe list. This must match the identifier production in CSS syntax.
- `from`
- : A starting offset of `0%`.
- `to`
- : An ending offset of `100%`.
- {{cssxref("<percentage>")}}
- : A percentage of the time through the animation sequence at which the specified keyframe should occur.
- `<timeline-range-name>` {{cssxref("<percentage>")}} {{experimental_inline}}
- : A percentage of the time through the specified {{cssxref("animation-range")}} at which the specified keyframe should occur. See [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations) for more information on the kinds of animations that use named timeline ranges.
## Description
To use keyframes, create a `@keyframes` rule with a name that is then used by the {{ cssxref("animation-name") }} property to match an animation to its keyframe declaration. Each `@keyframes` rule contains a style list of keyframe selectors, which specify percentages along the animation when the keyframe occurs, and a block containing the styles for that keyframe.
You can list the keyframe percentages in any order; they will be handled in the order they should occur.
JavaScript can access the `@keyframes` at-rule with the CSS object model interface {{domxref("CSSKeyframesRule")}}.
### Valid keyframe lists
If a keyframe rule doesn't specify the start or end states of the animation (that is, `0%`/`from` and `100%`/`to`), browsers will use the element's existing styles for the start/end states. This can be used to animate an element from its initial state and back.
Properties that can't be animated in keyframe rules are ignored, but supported properties will still be animated.
### Resolving duplicates
If multiple keyframe sets exist for a given name, the last one encountered by the parser is used. `@keyframes` rules don't cascade, so animations never derive keyframes from more than one rule set.
If a given animation time offset is duplicated, all keyframes in the `@keyframes` rule for that percentage are used for that frame. There is cascading within a `@keyframes` rule if multiple keyframes specify the same percentage values.
### When properties are left out of some keyframes
Properties that aren't specified in every keyframe are interpolated if possible — properties that can't be interpolated are dropped from the animation. For example:
```css
@keyframes identifier {
0% {
top: 0;
left: 0;
}
30% {
top: 50px;
}
68%,
72% {
left: 50px;
}
100% {
top: 100px;
left: 100%;
}
}
```
Here, the {{ cssxref("top") }} property animates using the `0%`, `30%`, and `100%` keyframes, and {{ cssxref("left") }} animates using the `0%`, `68%`, `72%` and `100%` keyframes.
### When a keyframe is defined multiple times
If a keyframe is defined multiple times but not all affected properties are in each keyframe, all values specified in these keyframes are considered. For example:
```css
@keyframes identifier {
0% {
top: 0;
}
50% {
top: 30px;
left: 20px;
}
50% {
top: 10px;
}
100% {
top: 0;
}
}
```
In this example, at the `50%` keyframe, the values used are `top: 10px` and `left: 20px`.
Cascading keyframes are supported starting in Firefox 14.
### `!important` in a keyframe
Declarations in a keyframe qualified with `!important` are ignored.
```css
@keyframes important1 {
from {
margin-top: 50px;
}
50% {
margin-top: 150px !important; /* ignored */
}
to {
margin-top: 100px;
}
}
@keyframes important2 {
from {
margin-top: 50px;
margin-bottom: 100px;
}
to {
margin-top: 150px !important; /* ignored */
margin-bottom: 50px;
}
}
```
## Formal syntax
{{csssyntax}}
## Examples
### CSS animation examples
See [Using CSS animations](/en-US/docs/Web/CSS/CSS_animations/Using_CSS_animations) and [Animate elements on scroll with Scroll-driven animations](https://developer.chrome.com/docs/css-ui/scroll-driven-animations) for examples.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("animation-range")}}
- [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations)
- [Using CSS animations](/en-US/docs/Web/CSS/CSS_animations/Using_CSS_animations)
- [CSS animations](/en-US/docs/Web/CSS/CSS_animations) module
- [Animate elements on scroll with Scroll-driven animations](https://developer.chrome.com/docs/css-ui/scroll-driven-animations)
- {{domxref("AnimationEvent")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/inset-inline/index.md | ---
title: inset-inline
slug: Web/CSS/inset-inline
page-type: css-shorthand-property
browser-compat: css.properties.inset-inline
---
{{CSSRef}}
The **`inset-inline`** [CSS](/en-US/docs/Web/CSS) property defines the logical start and end offsets of an element in the inline direction, which maps to physical offsets depending on the element's writing mode, directionality, and text orientation. It corresponds to the {{cssxref("top")}} and {{cssxref("bottom")}}, or {{cssxref("right")}} and {{cssxref("left")}} properties depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}.
{{EmbedInteractiveExample("pages/css/inset-inline.html")}}
## Constituent properties
This property is a shorthand for the following CSS properties:
- {{cssxref("inset-inline-end")}}
- {{cssxref("inset-inline-start")}}
## Syntax
```css
/* <length> values */
inset-inline: 3px 10px;
inset-inline: 2.4em 3em;
inset-inline: 10px; /* value applied to start and end */
/* <percentage>s of the width or height of the containing block */
inset-inline: 10% 5%;
/* Keyword value */
inset-inline: auto;
/* Global values */
inset-inline: inherit;
inset-inline: initial;
inset-inline: revert;
inset-inline: revert-layer;
inset-inline: unset;
```
### Values
The `inset-inline` property takes the same values as the {{cssxref("left")}} property.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting inline start and end offsets
#### 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-inline: 20px 50px;
background-color: #c8c800;
}
```
#### Result
{{EmbedLiveSample("Setting_inline_start_and_end_offsets", 140, 140)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- The mapped physical properties: {{cssxref("top")}}, {{cssxref("right")}}, {{cssxref("bottom")}}, and {{cssxref("left")}}
- The mapped physical shortcut: {{cssxref("inset")}}
- The mapped block shortcut: {{cssxref("inset-block")}}
- {{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/container/index.md | ---
title: container
slug: Web/CSS/container
page-type: css-shorthand-property
browser-compat: css.properties.container
---
{{CSSRef}}
The **container** [shorthand](/en-US/docs/Web/CSS/Shorthand_properties) [CSS](/en-US/docs/Web/CSS) property establishes the element as a query container and specifies the name and type of the [containment context](/en-US/docs/Web/CSS/CSS_containment/Container_queries#naming_containment_contexts) used in a [container query](/en-US/docs/Web/CSS/CSS_containment/Container_queries).
## Constituent properties
This property is a shorthand for the following CSS properties:
- {{Cssxref("container-name")}}
- {{Cssxref("container-type")}}
## Syntax
```css
/* <container-name> */
container: my-layout;
/* <container-name> / <container-type> */
container: my-layout / size;
/* Global Values */
container: inherit;
container: initial;
container: revert;
container: revert-layer;
container: unset;
```
### Values
- `<container-name>`
- : A case-sensitive name for the containment context.
More details on the syntax are covered in the {{cssxref("container-name")}} property page.
- `<container-type>`
- : The type of containment context.
More details on the syntax are covered in the {{cssxref("container-type")}} property page.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{CSSSyntax}}
## Examples
### Establishing inline size containment
Given the following HTML example which is a card component with an image, a title, and some text:
```html
<div class="post">
<div class="card">
<h2>Card title</h2>
<p>Card content</p>
</div>
</div>
```
The explicit way to create a container context is to declare a `container-type` with an optional `container-name`:
```css
.post {
container-type: inline-size;
container-name: sidebar;
}
```
The `container` shorthand is intended to make this simpler to define in a single declaration:
```css
.post {
container: sidebar / inline-size;
}
```
You can then target that container by name using the {{cssxref("@container")}} at-rule:
```css
@container sidebar (min-width: 400px) {
/* <stylesheet> */
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [CSS container queries](/en-US/docs/Web/CSS/CSS_containment/Container_queries)
- [Using container size and style queries](/en-US/docs/Web/CSS/CSS_containment/Container_size_and_style_queries)
- {{Cssxref("@container")}} at-rule
- CSS {{Cssxref("contain")}} property
- CSS {{Cssxref("container-type")}} property
- CSS {{Cssxref("container-name")}} property
- CSS {{cssxref("content-visibility")}} property
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/border-left/index.md | ---
title: border-left
slug: Web/CSS/border-left
page-type: css-shorthand-property
browser-compat: css.properties.border-left
---
{{CSSRef}}
The **`border-left`** [shorthand](/en-US/docs/Web/CSS/Shorthand_properties) [CSS](/en-US/docs/Web/CSS) property sets all the properties of an element's left [border](/en-US/docs/Web/CSS/border).
{{EmbedInteractiveExample("pages/css/border-left.html")}}
As with all shorthand properties, `border-left` always sets the values of all of the properties that it can set, even if they are not specified. It sets those that are not specified to their default values. Consider the following code:
```css
border-left-style: dotted;
border-left: thick green;
```
It is actually the same as this one:
```css
border-left-style: dotted;
border-left: none thick green;
```
The value of {{cssxref("border-left-style")}} given before `border-left` is ignored. Since the default value of {{cssxref("border-left-style")}} is `none`, not specifying the `border-style` part results in no border.
## Constituent properties
This property is a shorthand for the following CSS properties:
- {{cssxref("border-left-color")}}
- {{cssxref("border-left-style")}}
- {{cssxref("border-left-width")}}
## Syntax
```css
border-left: 1px;
border-left: 2px dotted;
border-left: medium dashed blue;
/* Global values */
border-left: inherit;
border-left: initial;
border-left: revert;
border-left: revert-layer;
border-left: unset;
```
The three values of the shorthand property can be specified in any order, and one or two of them may be omitted.
### Values
- `<br-width>`
- : See {{cssxref("border-left-width")}}.
- `<br-style>`
- : See {{cssxref("border-left-style")}}.
- {{cssxref("<color>")}}
- : See {{cssxref("border-left-color")}}.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Applying a left border
#### HTML
```html
<div>This box has a border on the left side.</div>
```
#### CSS
```css
div {
border-left: 4px dashed blue;
background-color: gold;
height: 100px;
width: 100px;
font-weight: bold;
text-align: center;
}
```
#### Results
{{EmbedLiveSample('Applying_a_left_border')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("border")}}
- {{cssxref("border-block")}}
- {{cssxref("outline")}}
- [Backgrounds and borders](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders)
- [Learn CSS: Backgrounds and borders](/en-US/docs/Learn/CSS/Building_blocks/Backgrounds_and_borders)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/initial_value/index.md | ---
title: Initial value
slug: Web/CSS/initial_value
page-type: guide
spec-urls: https://www.w3.org/TR/CSS22/cascade.html#specified-value
---
{{CSSRef}}
The **initial value** of a [CSS](/en-US/docs/Web/CSS) property is its default value, as listed in its definition table in the specification. The usage of the initial value depends on whether a property is inherited or not:
- For [inherited properties](/en-US/docs/Web/CSS/Inheritance#inherited_properties), the initial value is used on the _root element only_, as long as no [specified value](/en-US/docs/Web/CSS/specified_value) is supplied.
- For [non-inherited properties](/en-US/docs/Web/CSS/Inheritance#non-inherited_properties), the initial value is used on _all elements_, as long as no [specified value](/en-US/docs/Web/CSS/specified_value) is supplied.
You can explicitly specify the initial value by using the {{cssxref("initial")}} keyword.
> **Note:** The initial value should not be confused with the value specified by the browser's style sheet.
## Specifications
{{Specifications}}
## See also
- {{cssxref("initial")}}
- 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
- [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/justify-self/index.md | ---
title: justify-self
slug: Web/CSS/justify-self
page-type: css-property
browser-compat: css.properties.justify-self
---
{{CSSRef}}
The [CSS](/en-US/docs/Web/CSS) **`justify-self`** property sets the way a box is justified inside its alignment container along the appropriate axis.
{{EmbedInteractiveExample("pages/css/justify-self.html")}}
The effect of this property is dependent of the layout mode we are in:
- In block-level layouts, it aligns an item inside its containing block on the inline axis.
- For absolutely-positioned elements, it aligns an item inside its containing block on the inline axis, accounting for the offset values of top, left, bottom, and right.
- In table cell layouts, this property is _ignored_. Read more about [alignment in block, absolute positioned and table layout](/en-US/docs/Web/CSS/CSS_box_alignment/Box_alignment_in_block_abspos_tables).
- In flexbox layouts, this property is _ignored_. Read more about [alignment in Flexbox](/en-US/docs/Web/CSS/CSS_box_alignment/Box_alignment_in_flexbox).
- In grid layouts, it aligns an item inside its grid area on the inline axis. Read more about [alignment in grid layouts](/en-US/docs/Web/CSS/CSS_box_alignment/Box_alignment_in_grid_layout).
## Syntax
```css
/* Basic keywords */
justify-self: auto;
justify-self: normal;
justify-self: stretch;
/* Positional alignment */
justify-self: center; /* Pack item around the center */
justify-self: start; /* Pack item from the start */
justify-self: end; /* Pack item from the end */
justify-self: flex-start; /* Equivalent to 'start'. Note that justify-self is ignored in Flexbox layouts. */
justify-self: flex-end; /* Equivalent to 'end'. Note that justify-self is ignored in Flexbox layouts. */
justify-self: self-start;
justify-self: self-end;
justify-self: left; /* Pack item from the left */
justify-self: right; /* Pack item from the right */
/* Baseline alignment */
justify-self: baseline;
justify-self: first baseline;
justify-self: last baseline;
/* Overflow alignment (for positional alignment only) */
justify-self: safe center;
justify-self: unsafe center;
/* Global values */
justify-self: inherit;
justify-self: initial;
justify-self: revert;
justify-self: revert-layer;
justify-self: unset;
```
This property can take one of three different forms:
- Basic keywords: one of the keyword values `normal`, `auto`, or `stretch`.
- Baseline alignment: the `baseline` keyword, plus optionally one of `first` or `last`.
- Positional alignment:
- one of: `center`, `start`, `end`, `flex-start`, `flex-end`, `self-start`, `self-end`, `left`, or `right`.
- Plus optionally `safe` or `unsafe`.
### Values
- `auto`
- : The value used is the value of the `justify-items` property of the parents box, unless the box has no parent, or is absolutely positioned, in these cases, `auto` represents `normal`.
- `normal`
- : The effect of this keyword is dependent of the layout mode we are in:
- In block-level layouts, the keyword is a synonym of `start`.
- In absolutely-positioned layouts, the keyword behaves like `start` on _replaced_ absolutely-positioned boxes, and as `stretch` on _all other_ absolutely-positioned boxes.
- In table cell layouts, this keyword has no meaning as this property is _ignored_.
- In flexbox layouts, this keyword has no meaning as this property is _ignored._
- In grid layouts, this keyword leads to a behavior similar to the one of `stretch`, except for boxes with an aspect ratio or an intrinsic sizes where it behaves like `start`.
- `start`
- : The item is packed flush to each other toward the start edge of the alignment container in the appropriate axis.
- `end`
- : The item is packed flush to each other toward the end edge of the alignment container in the appropriate axis.
- `flex-start`
- : For items that are not children of a flex container, this value is treated like `start`.
- `flex-end`
- : For items that are not children of a flex container, this value is treated like `end`.
- `self-start`
- : The item is packed flush to the edge of the alignment container of the start side of the item, in the appropriate axis.
- `self-end`
- : The item is packed flush to the edge of the alignment container of the end side of the item, in the appropriate axis.
- `center`
- : The items are packed flush to each other toward the center of the alignment container.
- `left`
- : The items are packed flush to each other toward the left edge of the alignment container. If the property's axis is not parallel with the inline axis, this value behaves like `start`.
- `right`
- : The items are packed flush to each other toward the right edge of the alignment container in the appropriate axis. If the property's axis is not parallel with the inline axis, this value behaves like `start`.
- `baseline`, `first baseline`, `last baseline`
- : Specifies participation in first- or last-baseline alignment: aligns the alignment baseline of the box's first or last baseline set with the corresponding baseline in the shared first or last baseline set of all the boxes in its baseline-sharing group.
The fallback alignment for `first baseline` is `start`, the one for `last baseline` is `end`.
- `stretch`
- : If the combined size of the items is less than the size of the alignment container, any `auto`-sized items have their size increased equally (not proportionally), while still respecting the constraints imposed by {{CSSxRef("max-height")}}/{{CSSxRef("max-width")}} (or equivalent functionality), so that the combined size exactly fills the alignment container.
- `safe`
- : If the size of the item overflows the alignment container, the item is instead aligned as if the alignment mode were `start`.
- `unsafe`
- : Regardless of the relative sizes of the item and alignment container, the given alignment value is honored.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Simple demonstration
In the following example we have a simple 2 x 2 grid layout. Initially the grid container is given a `justify-items` value of `stretch` — the default — which causes the grid items to stretch across the entire width of their cells.
The second, third, and fourth grid items are then given different values of `justify-self`, to show how these override the `justify-items` value. These values cause the grid items to span only as wide as their content width, and align in different positions across their cells.
#### HTML
```html
<article class="container">
<span>First child</span>
<span>Second child</span>
<span>Third child</span>
<span>Fourth child</span>
</article>
```
#### CSS
```css
html {
font-family: helvetica, arial, sans-serif;
letter-spacing: 1px;
}
article {
background-color: red;
display: grid;
grid-template-columns: 1fr 1fr;
grid-auto-rows: 40px;
grid-gap: 10px;
margin: 20px;
width: 300px;
justify-items: stretch;
}
span:nth-child(2) {
justify-self: start;
}
span:nth-child(3) {
justify-self: center;
}
span:nth-child(4) {
justify-self: end;
}
article span {
background-color: black;
color: white;
margin: 1px;
text-align: center;
}
article,
span {
padding: 10px;
border-radius: 7px;
}
```
#### Result
{{EmbedLiveSample('Simple_demonstration', '100%', 200)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- 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("justify-items")}} property
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/grid-template-rows/index.md | ---
title: grid-template-rows
slug: Web/CSS/grid-template-rows
page-type: css-property
browser-compat: css.properties.grid-template-rows
---
{{CSSRef}}
The **`grid-template-rows`** CSS property defines the line names and track sizing functions of the {{glossary("grid_row", "grid rows")}}.
{{EmbedInteractiveExample("pages/css/grid-template-rows.html")}}
## Syntax
```css
/* Keyword value */
grid-template-rows: none;
/* <track-list> values */
grid-template-rows: 100px 1fr;
grid-template-rows: [linename] 100px;
grid-template-rows: [linename1] 100px [linename2 linename3];
grid-template-rows: minmax(100px, 1fr);
grid-template-rows: fit-content(40%);
grid-template-rows: repeat(3, 200px);
grid-template-rows: subgrid;
grid-template-rows: masonry;
/* <auto-track-list> values */
grid-template-rows: 200px repeat(auto-fill, 100px) 300px;
grid-template-rows:
minmax(100px, max-content)
repeat(auto-fill, 200px) 20%;
grid-template-rows:
[linename1] 100px [linename2]
repeat(auto-fit, [linename3 linename4] 300px)
100px;
grid-template-rows:
[linename1 linename2] 100px
repeat(auto-fit, [linename1] 300px) [linename3];
/* Global values */
grid-template-rows: inherit;
grid-template-rows: initial;
grid-template-rows: revert;
grid-template-rows: revert-layer;
grid-template-rows: unset;
```
This property may be specified as:
- either the keyword value `none`
- or a `<track-list>` value
- or an `<auto-track-list>` value.
### Values
- `none`
- : Is a keyword meaning that there is no explicit grid. Any rows will be implicitly generated and their size will be determined by the {{cssxref("grid-auto-rows")}} property.
- `[linename]`
- : A [`<custom-ident>`](/en-US/docs/Web/CSS/custom-ident) specifying a name for the line in that location. The ident may be any valid string other than the reserved words `span` and `auto`. Lines may have multiple names separated by a space inside the square brackets, for example `[line-name-a line-name-b]`.
- {{cssxref("<length>")}}
- : Is a non-negative length.
- {{cssxref("<percentage>")}}
- : Is a non-negative {{cssxref("percentage", "<percentage>")}} value, relative to the block size of the grid container. If the size of the grid container depends on the size of its tracks, then the percentage must be treated as `auto` for the purpose of calculating the intrinsic size of the grid container. It must then be resolved against the resulting grid container size for the purpose of laying out the grid and its items. The intrinsic size contributions of the track may be adjusted to the size of the grid container and may increase the final size of the track by the minimum amount that would result in honoring the percentage.
- {{cssxref("<flex_value>","<flex>")}}
- : Is 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. When appearing outside a `minmax()` notation, it implies an automatic minimum (i.e. `minmax(auto, <flex>)`).
- {{cssxref("max-content")}}
- : Is a keyword representing the largest maximal content contribution of the grid items occupying the grid track.
- {{cssxref("min-content")}}
- : Is a keyword representing the largest minimal content contribution of the grid items occupying the grid track.
- {{cssxref("minmax", "minmax(min, max)")}}
- : Is a functional notation that defines a size range, greater than or equal to _min_, and less than or equal to _max_. If _max_ is smaller than _min_, then _max_ is ignored and the function is treated as _min_. As a maximum, a `<flex>` value sets the track's flex factor. It is invalid as a minimum.
- `auto`
- : As a maximum represents the largest {{cssxref("max-content")}} size of the items in that track.
As a minimum represents the largest minimum size of items in that track (specified by the {{cssxref("min-width")}}/{{cssxref("min-height")}} of the items). This is often, though not always, the {{cssxref("min-content")}} size.
If used outside of {{cssxref("minmax", "minmax()")}} notation, `auto` represents the range between the minimum and maximum described above. This behaves similarly to `minmax(min-content,max-content)` in most cases.
> **Note:** `auto` track sizes (and only `auto` track sizes) can be stretched by the {{cssxref("align-content")}} and {{cssxref("justify-content")}} properties. Therefore by default, an `auto` sized track will take up any remaining space in the grid container.
- {{cssxref("fit-content_function", "fit-content( [ <length> | <percentage> ] )")}}
- : Represents the formula `min(max-content, max(auto, argument))`, which is calculated similar to `auto` (i.e. `minmax(auto, max-content)`), except that the track size is clamped at _argument_ if it is greater than the `auto` minimum.
- {{cssxref("repeat", "repeat( [ <positive-integer> | auto-fill | auto-fit ] , <track-list> )")}}
- : Represents a repeated fragment of the track list, allowing a large number of rows that exhibit a recurring pattern to be written in a more compact form.
- [`masonry`](/en-US/docs/Web/CSS/CSS_grid_layout/Masonry_layout) {{Experimental_Inline}}
- : The masonry value indicates that this axis should be laid out according to the masonry algorithm.
- [`subgrid`](/en-US/docs/Web/CSS/CSS_grid_layout/Subgrid)
- : The `subgrid` value indicates that the grid will adopt the spanned portion of its parent grid in that axis. Rather than being specified explicitly, the sizes of the grid rows/columns will be taken from the parent grid's definition.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Specifying grid row sizes
#### HTML
```html
<div id="grid">
<div id="areaA">A</div>
<div id="areaB">B</div>
</div>
```
#### CSS
```css
#grid {
display: grid;
height: 100px;
grid-template-rows: 30px 1fr;
}
#areaA {
background-color: lime;
}
#areaB {
background-color: yellow;
}
```
#### Result
{{EmbedLiveSample("Specifying_grid_row_sizes", "40px", "100px")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- Related CSS properties: {{cssxref("grid-template-columns")}}, {{cssxref("grid-template-areas")}}, {{cssxref("grid-template")}}
- Grid Layout Guide: _[Basic concepts of grid layout - Grid Tracks](/en-US/docs/Web/CSS/CSS_grid_layout/Basic_concepts_of_grid_layout#grid_tracks)_
- Video tutorial: _[Defining a Grid](https://gridbyexample.com/video/series-define-a-grid/)_
- [Subgrid](/en-US/docs/Web/CSS/CSS_grid_layout/Subgrid)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/css_writing_modes/index.md | ---
title: CSS writing modes
slug: Web/CSS/CSS_writing_modes
page-type: css-module
spec-urls: https://drafts.csswg.org/css-writing-modes/
---
{{CSSRef}}
The **CSS writing modes** module defines various international writing modes, such as left-to-right (e.g., used by Latin and Indic scripts), right-to-left (e.g., used by Hebrew or Arabic scripts), bidirectional (used when mixing left-to-right and right-to-left scripts), and vertical (e.g., used by some Asian scripts).
## Reference
### Properties
- {{cssxref("direction")}}
- {{cssxref("glyph-orientation-horizontal")}}
- {{cssxref("text-combine-upright")}}
- {{cssxref("text-orientation")}}
- {{cssxref("unicode-bidi")}}
- {{cssxref("writing-mode")}}
## Specifications
{{Specifications}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/css_positioned_layout/index.md | ---
title: CSS positioned layout
slug: Web/CSS/CSS_positioned_layout
page-type: css-module
spec-urls: https://drafts.csswg.org/css-position/
---
{{CSSRef}}
The **CSS positioned layout** module defines how to position elements on a web page.
## Reference
### Properties
- {{cssxref("top")}}
- {{cssxref("right")}}
- {{cssxref("bottom")}}
- {{cssxref("left")}}
- {{cssxref("inset")}}
- {{cssxref("inset-inline")}}
- {{cssxref("inset-inline-start")}}
- {{cssxref("inset-inline-end")}}
- {{cssxref("inset-block")}}
- {{cssxref("inset-block-start")}}
- {{cssxref("inset-block-end")}}
- {{cssxref("float")}}
- {{cssxref("clear")}}
- {{cssxref("position")}}
- {{cssxref("z-index")}}
- {{cssxref("transform")}}
## Guides
- [Understanding z-index](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index)
- : Presents the notion of stacking context and explains how z-ordering works, with several examples.
## Specifications
{{Specifications}}
| 0 |
data/mdn-content/files/en-us/web/css/css_positioned_layout | data/mdn-content/files/en-us/web/css/css_positioned_layout/understanding_z-index/index.md | ---
title: Understanding z-index
slug: Web/CSS/CSS_positioned_layout/Understanding_z-index
page-type: guide
---
{{CSSRef}}
In the most basic cases, [HTML](/en-US/docs/Web/HTML) pages can be considered two-dimensional, because text, images, and other elements are arranged on the page without overlapping. In this case, there is a single rendering flow, and all elements are aware of the space taken by others. The {{cssxref("z-index")}} attribute lets you adjust the order of the layering of objects when rendering content.
> _In CSS 2.1, each box has a position in three dimensions. In addition to their horizontal and vertical positions, boxes lie along a "z-axis" and are formatted one on top of the other. Z-axis positions are particularly relevant when boxes overlap visually._
(from [CSS 2.1 Section 9.9.1 - Layered presentation](https://www.w3.org/TR/CSS21/visuren.html#z-index))
This means that CSS style rules allow you to position boxes on layers in addition to the default rendering layer (layer 0). The position on an imaginary z-axis of each layer is expressed as an integer representing the stacking order for rendering. Greater numbers mean closer to the observer. Control the position on this z-axis with the CSS `z-index` property.
Using `z-index` appears extremely easy: a single property assigned a single integer number with an easy-to-understand behavior. When `z-index` is applied to complex hierarchies of HTML elements, its behavior can be hard to understand or predict. This is due to complex stacking rules. In fact, a dedicated section has been reserved in the CSS specification [CSS-2.1 Appendix E](https://www.w3.org/TR/CSS21/zindex.html) to explain these rules better.
This guide will try to explain those rules, with some simplification and several examples.
## Articles
1. [Stacking without the z-index property](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_without_z-index): The stacking rules that apply when `z-index` is not used.
2. [Stacking floating elements](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_floating_elements): How floating elements are handled with stacking.
3. [Using z-index](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Using_z-index): How to use `z-index` to change default stacking.
4. [Stacking context](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context): Notes on the stacking context.
## Examples
1. [Stacking context example 1](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_1): 2-level HTML hierarchy, `z-index` on the last level
2. [Stacking context example 2](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_2): 2-level HTML hierarchy, `z-index` on all levels
3. [Stacking context example 3](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_3): 3-level HTML hierarchy, `z-index` on the second level
| 0 |
data/mdn-content/files/en-us/web/css/css_positioned_layout/understanding_z-index | data/mdn-content/files/en-us/web/css/css_positioned_layout/understanding_z-index/stacking_context/index.md | ---
title: Stacking context
slug: Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context
page-type: guide
---
{{CSSRef}}
**Stacking context** is a three-dimensional conceptualization of HTML elements along an imaginary z-axis relative to the user, who is assumed to be facing the viewport or the webpage. HTML elements occupy this space in priority order based on element attributes.
## Description
In the previous article of this guide, [Using z-index](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Using_z-index), we showed that the rendering order of certain elements is influenced by their `z-index` value. This occurs because these elements have special properties which cause them to form a _stacking context_.
A stacking context is formed, anywhere in the document, by any element in the following scenarios:
- Root element of the document (`<html>`).
- Element with a {{cssxref("position")}} value `absolute` or `relative` and {{cssxref("z-index")}} value other than `auto`.
- Element with a {{cssxref("position")}} value `fixed` or `sticky` (sticky for all mobile browsers, but not older desktop browsers).
- Element with a {{cssxref("container-type")}} value `size` or `inline-size` set, intended for [container queries](/en-US/docs/Web/CSS/CSS_containment/Container_queries).
- Element that is a child of a [flex](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox) container, with {{cssxref("z-index")}} value other than `auto`.
- Element that is a child of a {{cssxref("grid")}} container, with {{cssxref("z-index")}} value other than `auto`.
- Element with an {{cssxref("opacity")}} value less than `1` (See [the specification for opacity](https://www.w3.org/TR/css-color-3/#transparency)).
- Element with a {{cssxref("mix-blend-mode")}} value other than `normal`.
- Element with any of the following properties with value other than `none`:
- {{cssxref("transform")}}
- {{cssxref("filter")}}
- {{cssxref("backdrop-filter")}}
- {{cssxref("perspective")}}
- {{cssxref("clip-path")}}
- {{cssxref("mask")}} / {{cssxref("mask-image")}} / {{cssxref("mask-border")}}
- Element with an {{cssxref("isolation")}} value `isolate`.
- Element with a {{cssxref("will-change")}} value specifying any property that would create a stacking context on non-initial value (see [this post](https://dev.opera.com/articles/css-will-change-property/)).
- Element with a {{cssxref("contain")}} value of `layout`, or `paint`, or a composite value that includes either of them (i.e. `contain: strict`, `contain: content`).
- Element placed into the [top layer](/en-US/docs/Glossary/Top_layer) and its corresponding {{cssxref("::backdrop")}}. Examples include [fullscreen](/en-US/docs/Web/API/Fullscreen_API) and [popover](/en-US/docs/Web/API/Popover_API) elements.
Within a stacking context, child elements are stacked according to the same rules explained just above. Importantly, the `z-index` values of its child stacking contexts only have meaning in this parent. Stacking contexts are treated atomically as a single unit in the parent stacking context.
In summary:
- Stacking contexts can be contained in other stacking contexts, and together create a hierarchy of stacking contexts.
- Each stacking context is completely independent of its siblings: only descendant elements are considered when stacking is processed.
- Each stacking context is self-contained: after the element's contents are stacked, the whole element is considered in the stacking order of the parent stacking context.
> **Note:** The hierarchy of stacking contexts is a subset of the hierarchy of HTML elements because only certain elements create stacking contexts. We can say that elements that do not create their own stacking contexts are _assimilated_ by the parent stacking context.
## Example

In this example, every positioned element creates its own stacking context, because of their positioning and `z-index` values. The hierarchy of stacking contexts is organized as follows:
- Root
- DIV #1
- DIV #2
- DIV #3
- DIV #4
- DIV #5
- DIV #6
It is important to note that DIV #4, DIV #5 and DIV #6 are children of DIV #3, so stacking of those elements is completely resolved within DIV #3. Once stacking and rendering within DIV #3 is completed, the whole DIV #3 element is passed for stacking in the root element with respect to its sibling's DIV.
DIV #4 is rendered under DIV #1 because DIV #1's z-index (5) is valid within the stacking context of the root element, while DIV #4's z-index (6) is valid within the stacking context of DIV #3. So, DIV #4 is under DIV #1, because DIV #4 belongs to DIV #3, which has a lower z-index value.
For the same reason DIV #2 (`z-index`: 2) is rendered under DIV#5 (`z-index`: 1) because DIV #5 belongs to DIV #3, which has a higher z-index value.
DIV #3's z-index is 4, but this value is independent from z-index of DIV #4, DIV #5 and DIV #6, because it belongs to a different stacking context.
An easy way to figure out the _rendering order_ of stacked elements along the z-axis is to think of it as a "version number" of sorts, where child elements are minor version numbers underneath their parent's major version numbers. This way we can easily see how an element with a z-index of 1 (DIV #5) is stacked above an element with a z-index of 2 (DIV #2), and how an element with a z-index of 6 (DIV #4) is stacked below an element with a z-index of 5 (DIV #1).
In our example (sorted according to the final rendering order):
- Root
- DIV #2: (`z-index`: 2)
- DIV #3: (`z-index`: 4)
- DIV #5: (`z-index`: 1), stacked under an element (`z-index`: 4), which results in a rendering order of 4.1
- DIV #6: (`z-index`: 3), stacked under an element (`z-index`: 4), which results in a rendering order of 4.3
- DIV #4: (`z-index`: 6), stacked under an element (`z-index`: 4), which results in a rendering order of 4.6
- DIV #1: (`z-index`: 5)
### HTML
```html
<div id="div1">
<h1>Division Element #1</h1>
<code>
position: relative;<br />
z-index: 5;
</code>
</div>
<div id="div2">
<h1>Division Element #2</h1>
<code>
position: relative;<br />
z-index: 2;
</code>
</div>
<div id="div3">
<div id="div4">
<h1>Division Element #4</h1>
<code>
position: relative;<br />
z-index: 6;
</code>
</div>
<h1>Division Element #3</h1>
<code>
position: absolute;<br />
z-index: 4;
</code>
<div id="div5">
<h1>Division Element #5</h1>
<code>
position: relative;<br />
z-index: 1;
</code>
</div>
<div id="div6">
<h1>Division Element #6</h1>
<code>
position: absolute;<br />
z-index: 3;
</code>
</div>
</div>
```
### CSS
```css
* {
margin: 0;
}
html {
padding: 20px;
font:
12px/20px Arial,
sans-serif;
}
div {
opacity: 0.7;
position: relative;
}
h1 {
font: inherit;
font-weight: bold;
}
#div1,
#div2 {
border: 1px dashed #696;
padding: 10px;
background-color: #cfc;
}
#div1 {
z-index: 5;
margin-bottom: 190px;
}
#div2 {
z-index: 2;
}
#div3 {
z-index: 4;
opacity: 1;
position: absolute;
top: 40px;
left: 180px;
width: 330px;
border: 1px dashed #900;
background-color: #fdd;
padding: 40px 20px 20px;
}
#div4,
#div5 {
border: 1px dashed #996;
background-color: #ffc;
}
#div4 {
z-index: 6;
margin-bottom: 15px;
padding: 25px 10px 5px;
}
#div5 {
z-index: 1;
margin-top: 15px;
padding: 5px 10px;
}
#div6 {
z-index: 3;
position: absolute;
top: 20px;
left: 180px;
width: 150px;
height: 125px;
border: 1px dashed #009;
padding-top: 125px;
background-color: #ddf;
text-align: center;
}
```
## Result
{{ EmbedLiveSample('Example', '100%', '396') }}
## See also
- [Stacking without the z-index property](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_without_z-index): The stacking rules that apply when `z-index` is not used.
- [Stacking floating elements](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_floating_elements): How floating elements are handled with stacking.
- [Using z-index](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Using_z-index): How to use `z-index` to change default stacking.
- [Stacking context example 1](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_1): 2-level HTML hierarchy, `z-index` on the last level
- [Stacking context example 2](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_2): 2-level HTML hierarchy, `z-index` on all levels
- [Stacking context example 3](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_3): 3-level HTML hierarchy, `z-index` on the second level
- [Top layer](/en-US/docs/Glossary/Top_layer)
| 0 |
data/mdn-content/files/en-us/web/css/css_positioned_layout/understanding_z-index | data/mdn-content/files/en-us/web/css/css_positioned_layout/understanding_z-index/stacking_without_z-index/index.md | ---
title: Stacking without the z-index property
slug: Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_without_z-index
page-type: guide
---
{{CSSRef}}
When the {{cssxref("z-index")}} property is not specified on any element, elements are stacked in the following order (from bottom to top):
1. The background and borders of the root element.
2. Descendant non-positioned elements, in order of appearance in the HTML.
3. Descendant positioned elements, in order of appearance in the HTML.
See [types of positioning](/en-US/docs/Web/CSS/position#types_of_positioning) for an explanation of positioned and non-positioned elements.
Keep in mind, when the {{cssxref("order")}} property alters rendering from the _order of appearance in the HTML_ within {{cssxref("flex")}} containers, it similarly affects the order for stacking context.
## Example
In this example, DIV #1 through DIV #4 are positioned elements. DIV #5 is static, and so is drawn below the other four elements, even though it comes later in the HTML markup.
### HTML
```html
<div id="abs1" class="absolute">
<strong>DIV #1</strong><br />position: absolute;
</div>
<div id="rel1" class="relative">
<strong>DIV #2</strong><br />position: relative;
</div>
<div id="rel2" class="relative">
<strong>DIV #3</strong><br />position: relative;
</div>
<div id="abs2" class="absolute">
<strong>DIV #4</strong><br />position: absolute;
</div>
<div id="sta1" class="static">
<strong>DIV #5</strong><br />position: static;
</div>
```
### CSS
```css
strong {
font-family: sans-serif;
}
div {
padding: 10px;
border: 1px dashed;
text-align: center;
}
.static {
position: static;
height: 80px;
background-color: #ffc;
border-color: #996;
}
.absolute {
position: absolute;
width: 150px;
height: 350px;
background-color: #fdd;
border-color: #900;
opacity: 0.7;
}
.relative {
position: relative;
height: 80px;
background-color: #cfc;
border-color: #696;
opacity: 0.7;
}
#abs1 {
top: 10px;
left: 10px;
}
#rel1 {
top: 30px;
margin: 0px 50px 0px 50px;
}
#rel2 {
top: 15px;
left: 20px;
margin: 0px 50px 0px 50px;
}
#abs2 {
top: 10px;
right: 10px;
}
#sta1 {
background-color: #ffc;
margin: 0px 50px 0px 50px;
}
```
## Result
{{EmbedLiveSample("Example", 600, 400)}}
## See also
- [Stacking floating elements](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_floating_elements): How floating elements are handled with stacking.
- [Using z-index](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Using_z-index): How to use `z-index` to change default stacking.
- [Stacking context](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context): Notes on the stacking context.
- [Stacking context example 1](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_1): 2-level HTML hierarchy, z-index on the last level
- [Stacking context example 2](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_2): 2-level HTML hierarchy, z-index on all levels
- [Stacking context example 3](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_3): 3-level HTML hierarchy, z-index on the second level
| 0 |
data/mdn-content/files/en-us/web/css/css_positioned_layout/understanding_z-index | data/mdn-content/files/en-us/web/css/css_positioned_layout/understanding_z-index/stacking_context_example_1/index.md | ---
title: Stacking context example 1
slug: Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_1
page-type: guide
---
{{CSSRef}}
## Description
Let's start with a basic example. In the root stacking context, there are two relatively positioned `<div>` elements (DIV #1 and DIV #3) without `z-index` properties. Inside DIV #1, there is an absolutely positioned DIV #2, while in DIV #3, there is an absolutely positioned DIV #4, both without `z-index` properties.
The only stacking context is the root context. Without `z-index` values, elements are stacked in order of occurrence.

If DIV #2 is assigned a positive (non-zero and non-auto) z-index value, it is rendered above all the other DIVs.

Then if DIV #4 is also assigned a positive z-index greater than DIV #2's z-index, it is rendered above all the other DIVs including DIV #2.

In this last example you can see that DIV #2 and DIV #4 are not siblings, because they belong to different parents in the HTML elements' hierarchy. Even so, stacking of DIV #4 with respect of DIV #2 can be controlled through `z-index`. It happens that, since DIV #1 and DIV #3 are not assigned any z-index value, they do not create a stacking context. This means that all their content, including DIV #2 and DIV #4, belongs to the same root stacking context.
In terms of stacking contexts, DIV #1 and DIV #3 are assimilated into the root element, and the resulting hierarchy is the following:
- Root stacking context
- DIV #2 (`z-index`: 1)
- DIV #4 (`z-index`: 2)
> **Note:** DIV #1 and DIV #3 are not translucent. It is important to remember that assigning an opacity less than 1 to a positioned element implicitly creates a stacking context, just like adding a `z-index` value. And this example shows what happens when a parent element does not create a stacking context.
## Example
### HTML
```html
<div id="div1">
<br /><span class="bold">DIV #1</span> <br />position: relative;
<div id="div2">
<br /><span class="bold">DIV #2</span> <br />position: absolute;
<br />z-index: 1;
</div>
</div>
<br />
<div id="div3">
<br /><span class="bold">DIV #3</span> <br />position: relative;
<div id="div4">
<br /><span class="bold">DIV #4</span> <br />position: absolute;
<br />z-index: 2;
</div>
</div>
```
### CSS
```css
.bold {
font-family: Arial;
font-size: 12px;
font-weight: bold;
}
#div1,
#div3 {
height: 80px;
position: relative;
border: 1px dashed #669966;
background-color: #ccffcc;
padding-left: 5px;
}
#div2 {
opacity: 0.8;
z-index: 1;
position: absolute;
width: 150px;
height: 200px;
top: 20px;
left: 170px;
border: 1px dashed #990000;
background-color: #ffdddd;
text-align: center;
}
#div4 {
opacity: 0.8;
z-index: 2;
position: absolute;
width: 200px;
height: 80px;
top: 65px;
left: 50px;
border: 1px dashed #000099;
background-color: #ddddff;
text-align: left;
padding-left: 10px;
}
```
## Result
{{ EmbedLiveSample('Example', '', '300') }}
## See also
- [Stacking without the z-index property](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_without_z-index): The stacking rules that apply when `z-index` is not used.
- [Stacking floating elements](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_floating_elements): How floating elements are handled with stacking.
- [Using z-index](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Using_z-index): How to use `z-index` to change default stacking.
- [Stacking context](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context): Notes on the stacking context.
- [Stacking context example 2](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_2): 2-level HTML hierarchy, `z-index` on all levels
- [Stacking context example 3](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_3): 3-level HTML hierarchy, `z-index` on the second level
| 0 |
data/mdn-content/files/en-us/web/css/css_positioned_layout/understanding_z-index | data/mdn-content/files/en-us/web/css/css_positioned_layout/understanding_z-index/stacking_floating_elements/index.md | ---
title: Stacking floating elements
slug: Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_floating_elements
page-type: guide
---
{{CSSRef}}
For floating elements, the stacking order is a bit different. Floating elements are placed between non-positioned elements and positioned elements:
1. The background and borders of the root element.
2. Descendant non-positioned elements, in order of appearance in the HTML.
3. _Floating elements_.
4. Descendant positioned elements, in order of appearance in the HTML.
See [types of positioning](/en-US/docs/Web/CSS/position#types_of_positioning) for an explanation of positioned and non-positioned elements.
> **Note:** If an `opacity` value is applied to a non-positioned element (i.e., DIV #4 in the example below), something strange happens: the background and border of that block pop up above the floating blocks and the positioned blocks. This is due to a peculiar part of the specification: applying an `opacity` value creates a new stacking context (see [What No One Told You About Z-Index](https://philipwalton.com/articles/what-no-one-told-you-about-z-index/)).
## Example
You can see in this example that the background and border of the non-positioned element (DIV #4) is completely unaffected by floating elements, but the content is affected. This happens according to standard float behavior which can be shown with a rule added to the above list:
1. The background and borders of the root element.
2. Descendant non-positioned elements, in order of appearance in the HTML.
3. Floating elements.
4. _Descendant non-positioned inline elements_.
5. Descendant positioned elements, in order of appearance in the HTML.
### HTML
```html
<div id="abs1"><strong>DIV #1</strong><br />position: absolute;</div>
<div id="flo1"><strong>DIV #2</strong><br />float: left;</div>
<div id="flo2"><strong>DIV #3</strong><br />float: right;</div>
<br />
<div id="sta1"><strong>DIV #4</strong><br />no positioning</div>
<div id="abs2"><strong>DIV #5</strong><br />position: absolute;</div>
<div id="rel1"><strong>DIV #6</strong><br />position: relative;</div>
```
### CSS
```css
div {
padding: 10px;
text-align: center;
}
strong {
font-family: sans-serif;
}
#abs1 {
position: absolute;
width: 150px;
height: 200px;
top: 10px;
right: 140px;
border: 1px dashed #900;
background-color: #fdd;
}
#sta1 {
height: 100px;
border: 1px dashed #996;
background-color: #ffc;
margin: 0px 10px 0px 10px;
text-align: left;
}
#flo1 {
margin: 0px 10px 0px 20px;
float: left;
width: 150px;
height: 200px;
border: 1px dashed #090;
background-color: #cfc;
}
#flo2 {
margin: 0px 20px 0px 10px;
float: right;
width: 150px;
height: 200px;
border: 1px dashed #090;
background-color: #cfc;
}
#abs2 {
position: absolute;
width: 150px;
height: 100px;
top: 80px;
left: 100px;
border: 1px dashed #990;
background-color: #fdd;
}
#rel1 {
position: relative;
border: 1px dashed #996;
background-color: #cff;
margin: 0px 10px 0px 10px;
text-align: left;
}
```
## Result
{{EmbedLiveSample("Example", 600, 250)}}
## See also
- [Stacking without the z-index property](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_without_z-index): The stacking rules that apply when `z-index` is not used.
- [Using z-index](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Using_z-index): How to use `z-index` to change default stacking.
- [Stacking context](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context): Notes on the stacking context.
- [Stacking context example 1](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_1): 2-level HTML hierarchy, z-index on the last level
- [Stacking context example 2](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_2): 2-level HTML hierarchy, z-index on all levels
- [Stacking context example 3](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_3): 3-level HTML hierarchy, z-index on the second level
| 0 |
data/mdn-content/files/en-us/web/css/css_positioned_layout/understanding_z-index | data/mdn-content/files/en-us/web/css/css_positioned_layout/understanding_z-index/using_z-index/index.md | ---
title: Using z-index
slug: Web/CSS/CSS_positioned_layout/Understanding_z-index/Using_z-index
page-type: guide
---
{{CSSRef}}
The first article of this guide, [Stacking without the z-index property](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_without_z-index), explains how stacking is arranged by default. If you want to create a custom stacking order, you can use the {{cssxref("z-index")}} property on a [positioned](/en-US/docs/Web/CSS/position#types_of_positioning) element.
The `z-index` property can be specified with an integer value (positive, zero, or negative), which represents the position of the element along an imaginary z-axis. If you are not familiar with the term 'z-axis', imagine the page as a stack of layers, each one having a number. Layers are rendered in numerical order, with larger numbers above smaller numbers (_X_ represents an arbitrary positive integer):
| Layer | Description |
| ------------ | ------------------------------------- |
| Bottom layer | Farthest from the observer |
| Layer -X | Layers with negative `z-index` values |
| Layer 0 | Default rendering layer |
| Layer X | Layers with positive `z-index` values |
| Top layer | Closest to the observer |
> **Note:**
>
> - When no `z-index` property is specified, elements are rendered on the default rendering layer (Layer 0).
> - If several elements share the same `z-index` value (i.e., they are placed on the same layer), stacking rules explained in the section [Stacking without the z-index property](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_without_z-index) apply.
## Example
In this example, the layers' stacking order is rearranged using `z-index`. The `z-index` of DIV #5 has no effect since it is not a positioned element.
### HTML
```html
<div id="abs1">
<strong>DIV #1</strong>
<br />position: absolute; <br />z-index: 5;
</div>
<div id="rel1">
<strong>DIV #2</strong>
<br />position: relative; <br />z-index: 3;
</div>
<div id="rel2">
<strong>DIV #3</strong>
<br />position: relative; <br />z-index: 2;
</div>
<div id="abs2">
<strong>DIV #4</strong>
<br />position: absolute; <br />z-index: 1;
</div>
<div id="sta1">
<strong>DIV #5</strong>
<br />no positioning <br />z-index: 8;
</div>
```
### CSS
```css
div {
padding: 10px;
opacity: 0.7;
text-align: center;
}
strong {
font-family: sans-serif;
}
#abs1 {
z-index: 5;
position: absolute;
width: 150px;
height: 350px;
top: 10px;
left: 10px;
border: 1px dashed #900;
background-color: #fdd;
}
#rel1 {
z-index: 3;
height: 100px;
position: relative;
top: 30px;
border: 1px dashed #696;
background-color: #cfc;
margin: 0px 50px 0px 50px;
}
#rel2 {
z-index: 2;
height: 100px;
position: relative;
top: 15px;
left: 20px;
border: 1px dashed #696;
background-color: #cfc;
margin: 0px 50px 0px 50px;
}
#abs2 {
z-index: 1;
position: absolute;
width: 150px;
height: 350px;
top: 10px;
right: 10px;
border: 1px dashed #900;
background-color: #fdd;
}
#sta1 {
z-index: 8;
height: 70px;
border: 1px dashed #996;
background-color: #ffc;
margin: 0px 50px 0px 50px;
}
```
## Result
{{EmbedLiveSample("Example", 600, 400)}}
## See also
- [Stacking without the z-index property](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_without_z-index): The stacking rules that apply when `z-index` is not used.
- [Stacking floating elements](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_floating_elements): How floating elements are handled with stacking.
- [Stacking context](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context): Notes on the stacking context.
- [Stacking context example 1](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_1): 2-level HTML hierarchy, z-index on the last level
- [Stacking context example 2](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_2): 2-level HTML hierarchy, z-index on all levels
- [Stacking context example 3](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_3): 3-level HTML hierarchy, z-index on the second level
| 0 |
data/mdn-content/files/en-us/web/css/css_positioned_layout/understanding_z-index | data/mdn-content/files/en-us/web/css/css_positioned_layout/understanding_z-index/stacking_context_example_2/index.md | ---
title: Stacking context example 2
slug: Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_2
page-type: guide
---
{{CSSRef}}
## Description
This is a very simple example, but it is the key for understanding the concept of _stacking context_. There are the same four DIVs of the previous example, but now `z-index` properties are assigned on both levels of the hierarchy.
You can see that DIV #2 (`z-index`: 2) is above DIV #3 (`z-index`: 1), because they both belong to the same stacking context (the root one), so z-index values rule how elements are stacked.
What can be considered strange is that DIV #2 (`z-index`: 2) is above DIV #4 (`z-index`: 10), despite their z-index values. The reason is that they do not belong to the same stacking context. DIV #4 belongs to the stacking context created by DIV #3, and as explained previously DIV #3 (and all its content) is under DIV #2.
To better understand the situation, this is the stacking context hierarchy:
- Root stacking context
- DIV #2 (`z-index`: 2)
- DIV #3 (`z-index`: 1)
- DIV #4 (`z-index`: 10)
> **Note:** It is worth remembering that the HTML hierarchy is different from the stacking context hierarchy. In the stacking context hierarchy, elements that do not create a stacking context are collapsed on their parent.
## Example
### HTML
```html
<div id="div1">
<br />
<span class="bold">DIV #1</span><br />
position: relative;
<div id="div2">
<br />
<span class="bold">DIV #2</span><br />
position: absolute;<br />
z-index: 2;
</div>
</div>
<br />
<div id="div3">
<br />
<span class="bold">DIV #3</span><br />
position: relative;<br />
z-index: 1;
<div id="div4">
<br />
<span class="bold">DIV #4</span><br />
position: absolute;<br />
z-index: 10;
</div>
</div>
```
### CSS
```css
div {
font: 12px Arial;
}
span.bold {
font-weight: bold;
}
#div2 {
z-index: 2;
}
#div3 {
z-index: 1;
}
#div4 {
z-index: 10;
}
#div1,
#div3 {
height: 80px;
position: relative;
border: 1px dashed #669966;
background-color: #ccffcc;
padding-left: 5px;
}
#div2 {
opacity: 0.8;
position: absolute;
width: 150px;
height: 200px;
top: 20px;
left: 170px;
border: 1px dashed #990000;
background-color: #ffdddd;
text-align: center;
}
#div4 {
opacity: 0.8;
position: absolute;
width: 200px;
height: 70px;
top: 65px;
left: 50px;
border: 1px dashed #000099;
background-color: #ddddff;
text-align: left;
padding-left: 10px;
}
```
## Result
{{ EmbedLiveSample('Example', '352', '270') }}
## See also
- [Stacking without the z-index property](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_without_z-index): The stacking rules that apply when `z-index` is not used.
- [Stacking floating elements](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_floating_elements): How floating elements are handled with stacking.
- [Using z-index](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Using_z-index): How to use `z-index` to change default stacking.
- [Stacking context](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context): Notes on the stacking context.
- [Stacking context example 1](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_1): 2-level HTML hierarchy, `z-index` on the last level
- [Stacking context example 3](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_3): 3-level HTML hierarchy, `z-index` on the second level
| 0 |
data/mdn-content/files/en-us/web/css/css_positioned_layout/understanding_z-index | data/mdn-content/files/en-us/web/css/css_positioned_layout/understanding_z-index/stacking_context_example_3/index.md | ---
title: Stacking context example 3
slug: Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_3
page-type: guide
---
{{CSSRef}}
## Description
This last example shows problems that arise when mixing several positioned elements in a multi-level HTML hierarchy and when `z-index` values are assigned using class selectors.
Let's take as an example a three-level hierarchical menu made from several positioned `div` elements. Second-level and third-level `div` elements appear when a user hovers or clicks on their parents. Usually this kind of menu is script-generated either client-side or server-side, so style rules are assigned with a class selector instead of the id selector.
If the three menu levels partially overlap, then managing stacking could become a problem.
The first-level menu is only relatively positioned, so no stacking context is created.
The second-level menu is absolutely positioned inside the parent element. In order to put it above all first-level menus, the `z-index` property is used. The problem is that for each second-level menu, a stacking context is created and each third-level menu belongs to the context of its parent.
So a third-level menu will be stacked under the following second-level menus, because all second-level menus share the same z-index value and the default stacking rules apply.
To better understand the situation, here is the stacking context hierarchy (the three dots "..." represent multiple repetition of the previous line):
- Root stacking context
- LEVEL #1
- LEVEL #2 (`z-index`: 1)
- LEVEL #3
- …
- LEVEL #3
- LEVEL #2 (`z-index`: 1)
- …
- LEVEL #2 (`z-index`: 1)
- LEVEL #1
- …
- LEVEL #1
This problem can be avoided by removing overlapping between different level menus, or by using individual (and different) z-index values assigned through the id selector instead of class selector, or by flattening the HTML hierarchy.
> **Note:** In the source code you will see that second-level and third level menus are made of several `div` elements contained in an absolutely positioned container. This is useful to group and position all of them at once.
## Example
### HTML
```html
<div class="lev1">
<span class="bold">LEVEL #1</span>
<div id="container1">
<div class="lev2">
<br /><span class="bold">LEVEL #2</span> <br />z-index: 1;
<div id="container2">
<div class="lev3"><span class="bold">LEVEL #3</span></div>
<div class="lev3"><span class="bold">LEVEL #3</span></div>
<div class="lev3"><span class="bold">LEVEL #3</span></div>
<div class="lev3"><span class="bold">LEVEL #3</span></div>
<div class="lev3"><span class="bold">LEVEL #3</span></div>
<div class="lev3"><span class="bold">LEVEL #3</span></div>
<div class="lev3"><span class="bold">LEVEL #3</span></div>
<div class="lev3"><span class="bold">LEVEL #3</span></div>
<div class="lev3"><span class="bold">LEVEL #3</span></div>
<div class="lev3"><span class="bold">LEVEL #3</span></div>
<div class="lev3"><span class="bold">LEVEL #3</span></div>
</div>
</div>
<div class="lev2">
<br /><span class="bold">LEVEL #2</span> <br />z-index: 1;
</div>
<div class="lev2">
<br /><span class="bold">LEVEL #2</span> <br />z-index: 1;
</div>
<div class="lev2">
<br /><span class="bold">LEVEL #2</span> <br />z-index: 1;
</div>
</div>
</div>
<div class="lev1">
<span class="bold">LEVEL #1</span>
</div>
<div class="lev1">
<span class="bold">LEVEL #1</span>
</div>
<div class="lev1">
<span class="bold">LEVEL #1</span>
</div>
```
### CSS
```css
div {
font: 12px Arial;
}
span.bold {
font-weight: bold;
}
div.lev1 {
width: 250px;
height: 70px;
position: relative;
border: 2px outset #669966;
background-color: #ccffcc;
padding-left: 5px;
}
#container1 {
z-index: 1;
position: absolute;
top: 30px;
left: 75px;
}
div.lev2 {
opacity: 0.9;
width: 200px;
height: 60px;
position: relative;
border: 2px outset #990000;
background-color: #ffdddd;
padding-left: 5px;
}
#container2 {
z-index: 1;
position: absolute;
top: 20px;
left: 110px;
}
div.lev3 {
z-index: 10;
width: 100px;
position: relative;
border: 2px outset #000099;
background-color: #ddddff;
padding-left: 5px;
}
```
## Result
{{ EmbedLiveSample('Example', '320', '330') }}
## See also
- [Stacking without the z-index property](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_without_z-index): The stacking rules that apply when `z-index` is not used.
- [Stacking floating elements](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_floating_elements): How floating elements are handled with stacking.
- [Using z-index](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Using_z-index): How to use `z-index` to change default stacking.
- [Stacking context](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context): Notes on the stacking context.
- [Stacking context example 1](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_1): 2-level HTML hierarchy, `z-index` on the last level
- [Stacking context example 2](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context_example_2): 2-level HTML hierarchy, `z-index` on all levels
> **Note:** The sample image looks wrong - with the second level 2 overlapping the level 3 menus - because level 2 has opacity, which creates a new stacking context.
> Basically, this whole sample page is incorrect and misleading.
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/list-style-type/index.md | ---
title: list-style-type
slug: Web/CSS/list-style-type
page-type: css-property
browser-compat: css.properties.list-style-type
---
{{CSSRef}}
The **`list-style-type`** [CSS](/en-US/docs/Web/CSS) property sets the marker (such as a disc, character, or custom counter style) of a list item element.
{{EmbedInteractiveExample("pages/css/list-style-type.html")}}
The marker will be [`currentcolor`](/en-US/docs/Web/CSS/color_value#currentcolor_keyword), the same as the computed [color](/en-US/docs/Web/CSS/color_value) of the element it applies to.
Only a few elements ({{HTMLElement("li")}} and {{HTMLElement("summary")}}) have a default value of `display: list-item`. However, the `list-style-type` property may be applied to any element whose {{cssxref("display")}} value is set to `list-item`. Moreover, because this property is inherited, it can be set on a parent element (commonly {{HTMLElement("ol")}} or {{HTMLElement("ul")}}) to make it apply to all list items.
## Syntax
```css
/* Partial list of types */
list-style-type: disc;
list-style-type: circle;
list-style-type: square;
list-style-type: decimal;
list-style-type: georgian;
list-style-type: trad-chinese-informal;
list-style-type: kannada;
/* <string> value */
list-style-type: "-";
/* Identifier matching an @counter-style rule */
list-style-type: custom-counter-style;
/* Keyword value */
list-style-type: none;
/* Global values */
list-style-type: inherit;
list-style-type: initial;
list-style-type: revert;
list-style-type: revert-layer;
list-style-type: unset;
```
The `list-style-type` property may be defined as any one of:
- a `<custom-ident>` value,
- a `symbols()` value,
- a `<string>` value, or
- the keyword `none`.
Note that:
- Some types require a suitable font installed to display as expected.
- The `cjk-ideographic` is identical to `trad-chinese-informal`; it exists for legacy reasons.
### Values
- {{cssxref("custom-ident", "<custom-ident>")}}
- : An identifier matching the value of a {{cssxref("@counter-style")}} or one of the predefined styles:
- {{cssxref("symbols", "symbols()")}}
- : Defines an anonymous style of the list.
- {{cssxref("<string>")}}
- : The specified string will be used as the item's marker.
- `none`
- : No item marker is shown.
- `disc`
- : A filled circle (default value).
- `circle`
- : A hollow circle.
- `square`
- : A filled square.
- `decimal`
- : Decimal numbers, beginning with 1.
- `cjk-decimal`
- : Han decimal numbers.
- `decimal-leading-zero`
- : Decimal numbers, padded by initial zeros.
- `lower-roman`
- : Lowercase roman numerals.
- `upper-roman`
- : Uppercase roman numerals.
- `lower-greek`
- : Lowercase classical Greek.
- `lower-alpha`, `lower-latin`
- : Lowercase {{Glossary("ASCII")}} letters.
- `upper-alpha`, `upper-latin`
- : Uppercase ASCII letters.
- `arabic-indic`, `-moz-arabic-indic`
- : Arabic-Indic numbers.
- `armenian`
- : Traditional Armenian numbering.
- `bengali`, `-moz-bengali`
- : Bengali numbering.
- `cambodian`/`khmer`
- : Cambodian/Khmer numbering.
- `cjk-earthly-branch`, `-moz-cjk-earthly-branch`
- : Han "Earthly Branch" ordinals.
- `cjk-heavenly-stem`, `-moz-cjk-heavenly-stem`
- : Han "Heavenly Stem" ordinals.
- `cjk-ideographic`
- : Identical to `trad-chinese-informal`.
- `devanagari`, `-moz-devanagari`
- : Devanagari numbering.
- `ethiopic-numeric`
- : Ethiopic numbering.
- `georgian`
- : Traditional Georgian numbering.
- `gujarati`, `-moz-gujarati`
- : Gujarati numbering.
- `gurmukhi`, `-moz-gurmukhi`
- : Gurmukhi numbering.
- `hebrew`
- : Traditional Hebrew numbering.
- `hiragana`
- : Dictionary-order hiragana lettering.
- `hiragana-iroha`
- : [Iroha-order](https://en.wikipedia.org/wiki/Iroha) hiragana lettering.
- `japanese-formal`
- : Japanese formal numbering to be used in legal or financial documents. The kanjis are designed so that they can't be modified to look like another correct one.
- `japanese-informal`
- : Japanese informal numbering.
- `kannada`, `-moz-kannada`
- : Kannada numbering.
- `katakana`
- : Dictionary-order katakana lettering.
- `katakana-iroha`
- : [Iroha-order](https://en.wikipedia.org/wiki/Iroha) katakana lettering.
- `korean-hangul-formal`
- : Korean hangul numbering.
- `korean-hanja-formal`
- : Formal Korean Han numbering.
- `korean-hanja-informal`
- : Korean hanja numbering.
- `lao`, `-moz-lao`
- : Laotian numbering.
- `lower-armenian`
- : Lowercase Armenian numbering.
- `malayalam`, `-moz-malayalam`
- : Malayalam numbering.
- `mongolian`
- : Mongolian numbering.
- `myanmar`, `-moz-myanmar`
- : Myanmar (Burmese) numbering.
- `oriya`, `-moz-oriya`
- : Oriya numbering.
- `persian`, `-moz-persian`
- : Persian numbering.
- `simp-chinese-formal`
- : Simplified Chinese formal numbering.
- `simp-chinese-informal`
- : Simplified Chinese informal numbering.
- `tamil`, `-moz-tamil`
- : Tamil numbering.
- `telugu`, `-moz-telugu`
- : Telugu numbering.
- `thai`, `-moz-thai`
- : Thai numbering.
- `tibetan`
- : Tibetan numbering.
- `trad-chinese-formal`
- : Traditional Chinese formal numbering.
- `trad-chinese-informal`
- : Traditional Chinese informal numbering.
- `upper-armenian`
- : Traditional uppercase Armenian numbering.
- `disclosure-open`
- : Symbol indicating that a disclosure widget such as {{HTMLElement("details")}} is opened.
- `disclosure-closed`
- : Symbol indicating that a disclosure widget, like {{HTMLElement("details")}} is closed.
Refer to the [All list style types](#all_list_style_types) example to see the above values in action. Details of all the available counter styles used by various cultures around the world can be found in [Ready-made Counter Styles](https://www.w3.org/TR/predefined-counter-styles/).
### Non-standard extensions
A few predefined types are supported by Mozilla (Firefox) with a `-moz-` prefix.
- `ethiopic-halehame`: `-moz-ethiopic-halehame`
- `ethiopic-halehame-am`: `-moz-ethiopic-halehame-am`
- `ethiopic-halehame-ti-er`: `-moz-ethiopic-halehame-ti-er`
- `ethiopic-halehame-ti-et`: `-moz-ethiopic-halehame-ti-et`
- `ethiopic-numeric`: `-moz-ethiopic-numeric`
- `hangul`: `-moz-hangul`
- `hangul-consonant`: `-moz-hangul-consonant`
- `urdu`: `-moz-urdu`
See the [compatibility table](#browser_compatibility) to check which browsers support which extension.
## Accessibility concerns
Safari will not recognize an ordered or unordered list as a list in the accessibility tree if it has a `list-style-type` value of `none`. This can be resolved by adding `role="list"` to the list's opening tag. To learn more about this and potential workarounds, see [`list-style`](/en-US/docs/Web/CSS/list-style#accessibility_concerns).
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting list item markers
#### HTML
```html
List 1
<ol class="normal">
<li>Hello</li>
<li>World</li>
<li>What's up?</li>
</ol>
List 2
<ol class="shortcut">
<li>Looks</li>
<li>Like</li>
<li>The</li>
<li>Same</li>
</ol>
```
#### CSS
```css
ol.normal {
list-style-type: upper-alpha;
}
/* or use the shortcut "list-style": */
ol.shortcut {
list-style: upper-alpha;
}
```
#### Result
{{EmbedLiveSample("Setting_list_item_markers","200","300")}}
### All list style types
#### HTML
```html
<ol>
<li>Apollo</li>
<li>Hubble</li>
<li>Chandra</li>
<li>Cassini-Huygens</li>
<li>Spitzer</li>
</ol>
<h2>Choose a list style type:</h2>
<div class="container">
<label for="disc">
<input type="radio" id="disc" name="type" value="disc" />disc
</label>
<label for="circle">
<input type="radio" id="circle" name="type" value="circle" />circle
</label>
<label for="square">
<input type="radio" id="square" name="type" value="square" />square
</label>
<label for="decimal">
<input type="radio" id="decimal" name="type" value="decimal" />decimal
</label>
<label for="cjk-decimal">
<input
type="radio"
id="cjk-decimal"
name="type"
value="cjk-decimal" />cjk-decimal
</label>
<label for="decimal-leading-zero">
<input
type="radio"
id="decimal-leading-zero"
name="type"
value="decimal-leading-zero" />decimal-leading-zero
</label>
<label for="lower-roman">
<input
type="radio"
id="lower-roman"
name="type"
value="lower-roman" />lower-roman
</label>
<label for="upper-roman">
<input
type="radio"
id="upper-roman"
name="type"
value="upper-roman" />upper-roman
</label>
<label for="lower-greek">
<input
type="radio"
id="lower-greek"
name="type"
value="lower-greek" />lower-greek
</label>
<label for="lower-alpha">
<input
type="radio"
id="lower-alpha"
name="type"
value="lower-alpha" />lower-alpha, lower-latin
</label>
<label for="upper-alpha">
<input
type="radio"
id="upper-alpha"
name="type"
value="upper-alpha" />upper-alpha, upper-latin
</label>
<label for="arabic-indic">
<input
type="radio"
id="arabic-indic"
name="type"
value="arabic-indic" />arabic-indic
</label>
<label for="armenian">
<input type="radio" id="armenian" name="type" value="armenian" />armenian
</label>
<label for="bengali">
<input type="radio" id="bengali" name="type" value="bengali" />bengali
</label>
<label for="cambodian">
<input type="radio" id="cambodian" name="type" value="cambodian" />cambodian
</label>
<label for="cjk-earthly-branch">
<input
type="radio"
id="cjk-earthly-branch"
name="type"
value="cjk-earthly-branch" />cjk-earthly-branch
</label>
<label for="cjk-heavenly-stem">
<input
type="radio"
id="cjk-heavenly-stem"
name="type"
value="cjk-heavenly-stem" />cjk-heavenly-stem
</label>
<label for="cjk-ideographic">
<input
type="radio"
id="cjk-ideographic"
name="type"
value="cjk-ideographic" />cjk-ideographic
</label>
<label for="devanagari">
<input
type="radio"
id="devanagari"
name="type"
value="devanagari" />devanagari
</label>
<label for="ethiopic-numeric">
<input
type="radio"
id="ethiopic-numeric"
name="type"
value="ethiopic-numeric" />ethiopic-numeric
</label>
<label for="georgian">
<input type="radio" id="georgian" name="type" value="georgian" />georgian
</label>
<label for="gujarati">
<input type="radio" id="gujarati" name="type" value="gujarati" />gujarati
</label>
<label for="gurmukhi">
<input type="radio" id="gurmukhi" name="type" value="gurmukhi" />gurmukhi
</label>
<label for="hebrew">
<input type="radio" id="hebrew" name="type" value="hebrew" />hebrew
</label>
<label for="hiragana">
<input type="radio" id="hiragana" name="type" value="hiragana" />hiragana
</label>
<label for="hiragana-iroha">
<input
type="radio"
id="hiragana-iroha"
name="type"
value="hiragana-iroha" />hiragana-iroha
</label>
<label for="japanese-formal">
<input
type="radio"
id="japanese-formal"
name="type"
value="japanese-formal" />japanese-formal
</label>
<label for="japanese-informal">
<input
type="radio"
id="japanese-informal"
name="type"
value="japanese-informal" />japanese-informal
</label>
<label for="kannada">
<input type="radio" id="kannada" name="type" value="kannada" />kannada
</label>
<label for="katakana">
<input type="radio" id="katakana" name="type" value="katakana" />katakana
</label>
<label for="katakana-iroha">
<input
type="radio"
id="katakana-iroha"
name="type"
value="katakana-iroha" />katakana-iroha
</label>
<label for="khmer">
<input type="radio" id="khmer" name="type" value="khmer" />khmer
</label>
<label for="korean-hangul-formal">
<input
type="radio"
id="korean-hangul-formal"
name="type"
value="korean-hangul-formal" />korean-hangul-formal
</label>
<label for="korean-hanja-formal">
<input
type="radio"
id="korean-hanja-formal"
name="type"
value="korean-hanja-formal" />korean-hanja-formal
</label>
<label for="korean-hanja-informal">
<input
type="radio"
id="korean-hanja-informal"
name="type"
value="korean-hanja-informal" />korean-hanja-informal
</label>
<label for="lao">
<input type="radio" id="lao" name="type" value="lao" />lao
</label>
<label for="lower-armenian">
<input
type="radio"
id="lower-armenian"
name="type"
value="lower-armenian" />lower-armenian
</label>
<label for="malayalam">
<input type="radio" id="malayalam" name="type" value="malayalam" />malayalam
</label>
<label for="mongolian">
<input type="radio" id="mongolian" name="type" value="mongolian" />mongolian
</label>
<label for="myanmar">
<input type="radio" id="myanmar" name="type" value="myanmar" />myanmar
</label>
<label for="oriya">
<input type="radio" id="oriya" name="type" value="oriya" />oriya
</label>
<label for="persian">
<input type="radio" id="persian" name="type" value="persian" />persian
</label>
<label for="simp-chinese-formal">
<input
type="radio"
id="simp-chinese-formal"
name="type"
value="simp-chinese-formal" />simp-chinese-formal
</label>
<label for="simp-chinese-informal">
<input
type="radio"
id="simp-chinese-informal"
name="type"
value="simp-chinese-informal" />simp-chinese-informal
</label>
<label for="tamil">
<input type="radio" id="tamil" name="type" value="tamil" />tamil
</label>
<label for="telugu">
<input type="radio" id="telugu" name="type" value="telugu" />telugu
</label>
<label for="thai">
<input type="radio" id="thai" name="type" value="thai" />thai
</label>
<label for="tibetan">
<input type="radio" id="tibetan" name="type" value="tibetan" />tibetan
</label>
<label for="trad-chinese-formal">
<input
type="radio"
id="trad-chinese-formal"
name="type"
value="trad-chinese-formal" />trad-chinese-formal
</label>
<label for="trad-chinese-informal">
<input
type="radio"
id="trad-chinese-informal"
name="type"
value="trad-chinese-informal" />trad-chinese-informal
</label>
<label for="upper-armenian">
<input
type="radio"
id="upper-armenian"
name="type"
value="upper-armenian" />upper-armenian
</label>
<label for="disclosure-open">
<input
type="radio"
id="disclosure-open"
name="type"
value="disclosure-open" />disclosure-open
</label>
<label for="disclosure-closed">
<input
type="radio"
id="disclosure-closed"
name="type"
value="disclosure-closed" />disclosure-closed
</label>
<label for="-moz-ethiopic-halehame">
<input
type="radio"
id="-moz-ethiopic-halehame"
name="type"
value="-moz-ethiopic-halehame" />-moz-ethiopic-halehame
</label>
<label for="-moz-ethiopic-halehame-am">
<input
type="radio"
id="-moz-ethiopic-halehame-am"
name="type"
value="-moz-ethiopic-halehame-am" />-moz-ethiopic-halehame-am
</label>
<label for="ethiopic-halehame-ti-er">
<input
type="radio"
id="ethiopic-halehame-ti-er"
name="type"
value="ethiopic-halehame-ti-er" />ethiopic-halehame-ti-er
</label>
<label for="ethiopic-halehame-ti-et">
<input
type="radio"
id="ethiopic-halehame-ti-et"
name="type"
value="ethiopic-halehame-ti-et" />ethiopic-halehame-ti-et
</label>
<label for="hangul">
<input type="radio" id="hangul" name="type" value="hangul" />hangul
</label>
<label for="hangul-consonant">
<input
type="radio"
id="hangul-consonant"
name="type"
value="hangul-consonant" />hangul-consonant
</label>
<label for="urdu">
<input type="radio" id="urdu" name="type" value="urdu" />urdu
</label>
<label for="-moz-ethiopic-halehame-ti-er">
<input
type="radio"
id="-moz-ethiopic-halehame-ti-er"
name="type"
value="-moz-ethiopic-halehame-ti-er" />-moz-ethiopic-halehame-ti-er
</label>
<label for="-moz-ethiopic-halehame-ti-et">
<input
type="radio"
id="-moz-ethiopic-halehame-ti-et"
name="type"
value="-moz-ethiopic-halehame-ti-et" />-moz-ethiopic-halehame-ti-et
</label>
<label for="-moz-hangul">
<input
type="radio"
id="-moz-hangul"
name="type"
value="-moz-hangul" />-moz-hangul
</label>
<label for="-moz-hangul-consonant">
<input
type="radio"
id="-moz-hangul-consonant"
name="type"
value="-moz-hangul-consonant" />-moz-hangul-consonant
</label>
<label for="-moz-urdu">
<input type="radio" id="-moz-urdu" name="type" value="-moz-urdu" />-moz-urdu
</label>
</div>
```
#### CSS
```css
ol {
font-size: 1.2rem;
}
.container {
column-count: 3;
}
label {
display: block;
}
input {
margin: 0.4rem;
}
```
#### JavaScript
```js
const container = document.querySelector(".container");
container.addEventListener("change", (event) => {
const list = document.querySelector("ol");
list.setAttribute("style", `list-style-type: ${event.target.value}`);
});
```
#### Result
{{EmbedLiveSample("All_list_style_types", "600", "800")}}
We're not limited to the list style types defined on this page or the specification. The {{cssxref("@counter-style")}} at-rule enables creating [counters using any alphabet](https://r12a.github.io/app-counters/).
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{Cssxref("list-style")}} shorthand property
- {{Cssxref("list-style-image")}} property
- {{Cssxref("list-style-position")}} property
- {{Cssxref("::marker")}} pseudo-element
- [CSS lists and counters](/en-US/docs/Web/CSS/CSS_lists) module
- [CSS counter styles](/en-US/docs/Web/CSS/CSS_counter_styles) module
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/font-variant-position/index.md | ---
title: font-variant-position
slug: Web/CSS/font-variant-position
page-type: css-property
browser-compat: css.properties.font-variant-position
---
{{CSSRef}}
The **`font-variant-position`** CSS property controls the use of alternate, smaller glyphs that are positioned as superscript or subscript.
The glyphs are positioned relative to the baseline of the font, which remains unchanged. These glyphs are typically used in {{HTMLElement("sub")}} and {{HTMLElement("sup")}} elements.
When the usage of these alternate glyphs is activated, if one character in the run doesn't have such a typographically-enhanced glyph, the whole set of characters of the run is rendered using a fallback method, synthesizing these glyphs.
These alternate glyphs share the same em-box and the same baseline as the rest of the font. They are merely graphically enhanced, and have no effect on the line-height and other box characteristics.
## Syntax
```css
/* Keyword values */
font-variant-position: normal;
font-variant-position: sub;
font-variant-position: super;
/* Global values */
font-variant-position: inherit;
font-variant-position: initial;
font-variant-position: revert;
font-variant-position: revert-layer;
font-variant-position: unset;
```
The `font-variant-position` property is specified as one of the keyword values listed below.
### Values
- `normal`
- : Deactivates alternate superscript and subscript glyphs.
- `sub`
- : Activates subscript alternate glyphs. If, in a given run, one such glyph is not available for a character, all the characters in the run are rendered using synthesized glyphs.
- `super`
- : Activates superscript alternate glyphs. If, in a given run, one such glyph is not available for a character, all the characters in the run are rendered using synthesized glyphs.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting superscript and subscript forms
#### HTML
```html
<p class="normal">Normal!</p>
<p class="super">Super!</p>
<p class="sub">Sub!</p>
```
#### CSS
```css
p {
display: inline;
}
.normal {
font-variant-position: normal;
}
.super {
font-variant-position: super;
}
.sub {
font-variant-position: sub;
}
```
#### Result
{{ EmbedLiveSample('Setting_superscript_and_subscript_forms') }}
## 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-numeric`](/en-US/docs/Web/CSS/font-variant-numeric)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_-moz-locale-dir_ltr/index.md | ---
title: ":-moz-locale-dir(ltr)"
slug: Web/CSS/:-moz-locale-dir_ltr
page-type: css-pseudo-class
status:
- non-standard
---
{{CSSRef}}{{Non-standard_header}}
The **`:-moz-locale-dir(ltr)`** [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 an element if the user interface is being displayed left-to-right. This is determined by the preference `intl.uidirection.locale` (where `locale` is the current locale) being set to "ltr".
> **Note:** This selector is mainly used by extensions and themes to adapt the user interface based on the user's locale. (This can vary from window to window, and even from tab to tab.) It also allows extensions to work even when they don't support the user's default locale, since they can support both left-to-right and right-to-left layouts regardless of locale specifics.
> **Warning:** This selector does not work properly from HTML; it always matches, regardless of whether the UI locale is left-to-right or right-to-left.
## Syntax
```css
:-moz-locale-dir(ltr) {
/* ... */
}
```
## Examples
This example doesn't work if you're not using Firefox, and may not work even in Firefox due to an issue with the selector not working properly with HTML content. It was designed for use with `XUL`.
### HTML
```html
<p>If you're using a left-to-right interface, this should be red.</p>
```
### CSS
```css
p:-moz-locale-dir(ltr) {
color: red;
}
```
### Result
{{EmbedLiveSample("Examples")}}
## Specifications
Not part of any standard.
## See also
- {{CSSxRef(":dir", ":dir(…)")}}
- {{CSSxRef(":-moz-locale-dir_rtl", ":-moz-locale-dir(rtl)")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/css_scrollbars_styling/index.md | ---
title: CSS scrollbars styling
slug: Web/CSS/CSS_scrollbars_styling
page-type: css-module
browser-compat:
- css.properties.scrollbar-color
- css.properties.scrollbar-width
spec-urls: https://drafts.csswg.org/css-scrollbars/
---
{{CSSRef}}
The **CSS scrollbars styling** module defines properties that you can use for visual styling of scrollbars. You can customize the width of the scrollbar as required. You can also customize the color of the scrollbar _track_, which is the background of the scrollbar, and the color of the scrollbar _thumb_, which is the draggable handle of the scrollbar.
## Scrollbar styling in action
This example defines a thin scrollbar with a red thumb and an orange track. To view the thumb, you will need to scroll the text. After the scrollbar is visible, hover over it to see the track.
```css hidden
.poem {
width: 300px;
height: 100px;
border: 1px solid;
}
```
```css
.poem {
overflow: scroll;
scrollbar-color: red orange;
scrollbar-width: thin;
}
```
```html hidden
<blockquote class="poem">
<h3>A Small Needful Fact</h3>
<pre>
Is that Eric Garner worked
for some time for the Parks and Rec.
Horticultural Department, which means,
perhaps, that with his very large hands,
perhaps, in all likelihood,
he put gently into the earth
some plants which, most likely,
some of them, in all likelihood,
continue to grow, continue
to do what such plants do, like house
and feed small and necessary creatures,
like being pleasant to touch and smell,
like converting sunlight
into food, like making it easier
for us to breathe.
</pre
>
<p>
- <a href="https://onbeing.org/poetry/a-small-needful-fact/">Ross Gay</a>
</p>
</blockquote>
```
{{EmbedLiveSample("Scrollbar_styling_in_action")}}
> **Note:** When customizing scrollbars, ensure that the thumb and track have enough contrast with the surrounding background. Also ensure that the scrollbar hit area is large enough for people who use touch input.
## Reference
### CSS properties
- {{CSSxRef("scrollbar-width")}}
- {{CSSxRef("scrollbar-color")}}
## Related concepts
- {{CSSxRef("overflow-block")}} CSS property
- {{CSSxRef("overflow-inline")}} CSS property
- {{CSSxRef("overflow-x")}} CSS property
- {{CSSxRef("overflow-y")}} CSS property
- {{CSSxRef("overflow")}} CSS shorthand property
- {{CSSxRef("overflow-clip-margin")}} CSS property
- {{CSSxRef("scrollbar-gutter")}} CSS property
- {{CSSxRef("scroll-behavior")}} CSS property
- {{cssxref("scroll-margin")}} CSS shorthand property
- {{cssxref("scroll-padding")}} CSS shorthand property
- {{cssxref("scroll-snap-align")}} CSS property
- {{cssxref("scroll-snap-stop")}} CSS property
- {{cssxref("scroll-snap-type")}} CSS property
- {{CSSxRef("::-webkit-scrollbar")}} pseudo-element
- {{glossary("scroll container")}} glossary term
- [`scrollbar`](/en-US/docs/Web/Accessibility/ARIA/Roles/scrollbar_role) ARIA role
## Specifications
{{Specifications}}
## See also
- {{cssxref('scroll-timeline')}}, {{cssxref('scroll-timeline-axis')}}, {{cssxref('scroll-timeline-name')}}
- [CSS overflow](/en-US/docs/Web/CSS/CSS_overflow) module
- [CSS scroll snap](/en-US/docs/Web/CSS/CSS_scroll_snap) module
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/margin-inline-start/index.md | ---
title: margin-inline-start
slug: Web/CSS/margin-inline-start
page-type: css-property
browser-compat: css.properties.margin-inline-start
---
{{CSSRef}}
The **`margin-inline-start`** [CSS](/en-US/docs/Web/CSS) property defines the logical inline start margin of an element, which maps to a physical margin depending on the element's writing mode, directionality, and text orientation. It corresponds to the {{cssxref("margin-top")}}, {{cssxref("margin-right")}}, {{cssxref("margin-bottom")}}, or {{cssxref("margin-left")}} property depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}.
{{EmbedInteractiveExample("pages/css/margin-inline-start.html")}}
## Syntax
```css
/* <length> values */
margin-inline-start: 10px; /* An absolute length */
margin-inline-start: 1em; /* relative to the text size */
margin-inline-start: 5%; /* relative to the nearest block container's width */
/* Keyword values */
margin-inline-start: auto;
/* Global values */
margin-inline-start: inherit;
margin-inline-start: initial;
margin-inline-start: revert;
margin-inline-start: revert-layer;
margin-inline-start: unset;
```
It relates to {{cssxref("margin-block-start")}}, {{cssxref("margin-block-end")}}, and {{cssxref("margin-inline-end")}}, which define the other margins of the element.
### Values
The `margin-inline-start` property takes the same values as the {{cssxref("margin-left")}} property.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting inline start margin
#### 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;
margin-inline-start: 20px;
background-color: #c8c800;
}
```
#### Result
{{EmbedLiveSample("Setting_inline_start_margin", 140, 140)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [CSS Logical Properties and Values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values)
- {{cssxref("margin-inline-end")}}
- The mapped physical properties: {{cssxref("margin-top")}}, {{cssxref("margin-right")}}, {{cssxref("margin-bottom")}}, and {{cssxref("margin-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/isolation/index.md | ---
title: isolation
slug: Web/CSS/isolation
page-type: css-property
browser-compat: css.properties.isolation
---
{{CSSRef}}
The **`isolation`** [CSS](/en-US/docs/Web/CSS) property determines whether an element must create a new {{glossary("stacking context")}}.
{{EmbedInteractiveExample("pages/css/isolation.html")}}
This property is especially helpful when used in conjunction with {{cssxref("mix-blend-mode")}} and {{cssxref("z-index")}}.
## Syntax
```css
/* Keyword values */
isolation: auto;
isolation: isolate;
/* Global values */
isolation: inherit;
isolation: initial;
isolation: revert;
isolation: revert-layer;
isolation: unset;
```
The `isolation` property is specified as one of the keyword values listed below.
### Values
- `auto`
- : A new stacking context is created only if one of the properties applied to the element requires it.
- `isolate`
- : A new stacking context must be created.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Forcing a new stacking context for an element
#### HTML
```html
<div class="big-square ">
<div class="isolation-auto">
<div class="small-square">auto</div>
</div>
<div class="isolation-isolate">
<div class="small-square">isolate</div>
</div>
</div>
```
#### CSS
```css
.isolation-auto {
isolation: auto;
}
.isolation-isolate {
isolation: isolate;
}
.big-square {
background-color: rgb(0, 255, 0);
width: 200px;
height: 210px;
}
.small-square {
background-color: rgb(0, 255, 0);
width: 100px;
height: 100px;
border: 1px solid black;
padding: 2px;
mix-blend-mode: difference;
}
```
#### Result
{{ EmbedLiveSample('Forcing_a_new_stacking_context_for_an_element', 230, 230) }}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("<blend-mode>")}}
- {{cssxref("mix-blend-mode")}}, {{cssxref("background-blend-mode")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/calc/index.md | ---
title: calc()
slug: Web/CSS/calc
page-type: css-function
browser-compat: css.types.calc
---
{{CSSRef}}
The **`calc()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) lets you perform calculations when specifying CSS property values. It can be used with {{cssxref("<length>")}}, {{cssxref("<frequency>")}}, {{cssxref("<angle>")}}, {{cssxref("<time>")}}, {{cssxref("<percentage>")}}, {{cssxref("<number>")}}, or {{cssxref("<integer>")}} values.
{{EmbedInteractiveExample("pages/css/function-calc.html")}}
## Syntax
```css
/* property: calc(expression) */
width: calc(100% - 80px);
```
The `calc()` function takes a single expression as its parameter, and the expression's result is used as the value for a CSS property. In this expression, the {{Glossary("operand", "operands")}} can be combined using the {{Glossary("operator", "operators")}} listed below. When the expression contains multiple operands,`calc()` uses the standard [operator precedence rules](/en-US/docs/Learn/JavaScript/First_steps/Math#operator_precedence):
- `+`
- : Adds the specified operands.
- `-`
- : Subtracts the second operand from the first operand.
- `*`
- : Multiplies the specified operands.
- `/`
- : Divides the left-side operand (dividend) by the right-side operand (divisor).
All operands, except those of type {{cssxref("<number>")}}, must be suffixed with an appropriate unit string, such as `px`, `em`, or `%`. You can use a different unit with each operand in your expression. You may also use parentheses to establish computation order when needed.
### Notes
Serializing the arguments inside `calc()` follows the IEEE-754 standard for floating point math which means there's a few cases to be aware of regarding the `infinity` and `NaN` constants.
For more details on how constants are serialized, see the [`calc-constant`](/en-US/docs/Web/CSS/calc-constant) page.
In addition, the following notes apply:
- The `+` and `-` operators **must be surrounded by {{Glossary("whitespace")}}**. For instance, `calc(50% -8px)` will be parsed as "a percentage followed by a negative length" — which is an invalid expression — while `calc(50% - 8px)` is "a percentage followed by a subtraction operator and a length". Likewise, `calc(8px + -50%)` is treated as "a length followed by an addition operator and a negative percentage".
- The `*` and `/` operators do not require whitespace, but adding it for consistency is recommended.
- Math expressions involving percentages for widths and heights on table columns, table column groups, table rows, table row groups, and table cells in both auto and fixed layout tables _may_ be treated as if `auto` had been specified.
- It is permitted to nest `calc()` functions, in which case the inner ones are treated as simple parentheses.
- For lengths, you can't use `0` to mean `0px` (or another length unit); instead, you must use the version with the unit: `margin-top: calc(0px + 20px);` is valid, while `margin-top: calc(0 + 20px);` is invalid.
- The `calc()` function cannot directly substitute the numeric value for percentage types; for instance `calc(100 / 4)%` is invalid, while `calc(100% / 4)` is valid.
### Formal syntax
{{csssyntax}}
## Accessibility concerns
When `calc()` is used for controlling text size, be sure that one of the values includes a [relative length unit](/en-US/docs/Web/CSS/length#relative_length_units), for example:
```css
h1 {
font-size: calc(1.5rem + 3vw);
}
```
This ensures that text size will scale if the page is zoomed.
- [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.4 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-scale.html)
## Usage with integers
When **`calc()`** is used where an {{cssxref("<integer>")}} is expected, the value will be rounded to the nearest integer. For example:
```css
.modal {
z-index: calc(3 / 2);
}
```
This will give `.modal` a final `z-index` value of 2.
## Examples
### Positioning an object on screen with a margin
`calc()` makes it easy to position an object with a set margin. In this example, the CSS creates a banner that stretches across the window, with a 40-pixel gap between both sides of the banner and the edges of the window:
```css
.banner {
position: absolute;
left: 40px;
width: calc(100% - 80px);
border: solid black 1px;
box-shadow: 1px 2px;
background-color: yellow;
padding: 6px;
text-align: center;
box-sizing: border-box;
}
```
```html
<div class="banner">This is a banner!</div>
```
{{EmbedLiveSample('Positioning_an_object_on_screen_with_a_margin', 'auto', '60')}}
### Automatically sizing form fields to fit their container
Another use case for `calc()` is to help ensure that form fields fit in the available space, without extruding past the edge of their container, while maintaining an appropriate margin.
Let's look at some CSS:
```css
input {
padding: 2px;
display: block;
width: calc(100% - 1em);
}
#form-box {
width: calc(100% / 6);
border: 1px solid black;
padding: 4px;
}
```
Here, the form itself is established to use 1/6 of the available window width. Then, to ensure that input fields retain an appropriate size, we use `calc()` again to establish that they should be the width of their container minus 1em. Then, the following HTML makes use of this CSS:
```html
<form>
<div id="form-box">
<label for="misc">Type something:</label>
<input type="text" id="misc" name="misc" />
</div>
</form>
```
{{EmbedLiveSample('Automatically_sizing_form_fields_to_fit_their_container', '700', '80')}}
### Nested `calc()` with CSS Variables
You can also use `calc()` with [CSS variables](/en-US/docs/Web/CSS/CSS_cascading_variables). Consider the following code:
```css
.foo {
--widthA: 100px;
--widthB: calc(var(--widthA) / 2);
--widthC: calc(var(--widthB) / 2);
width: var(--widthC);
}
```
After all variables are expanded, `widthC`'s value will be `calc(calc(100px / 2) / 2)`, then when it's assigned to `.foo`'s width property, all inner `calc()`s (no matter how deeply nested) will be flattened to just parentheses, so the `width` property's value will be eventually `calc((100px / 2) / 2)`, i.e. `25px`. In short: a `calc()` inside of a `calc()` is identical to just parentheses.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef("<calc-constant>")}}
- [CSS functions](/en-US/docs/Web/CSS/CSS_Functions)
- [A Complete Guide to calc() in CSS](https://css-tricks.com/a-complete-guide-to-calc-in-css/) (CSS-Tricks)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/margin-trim/index.md | ---
title: margin-trim
slug: Web/CSS/margin-trim
page-type: css-property
status:
- experimental
browser-compat: css.properties.margin-trim
---
{{CSSRef}}{{SeeCompatTable}}
The `margin-trim` property allows the container to trim the margins of its children where they adjoin the container's edges.
## Syntax
```css
margin-trim: none;
margin-trim: block;
margin-trim: block-start;
margin-trim: block-end;
margin-trim: inline;
margin-trim: inline-start;
margin-trim: inline-end;
/* Global values */
margin-trim: inherit;
margin-trim: initial;
margin-trim: revert;
margin-trim: revert-layer;
margin-trim: unset;
```
### Values
- `none`
- : Margins are not trimmed by the container.
- `block`
- : Margins provided to the block children where they adjoin the container's edges are trimmed to zero without affecting the margins provided to the container.
- `block-start`
- : Margin of the first block child with the container's edge is trimmed to zero.
- `block-end`
- : Margin of last block child with the container's edge is trimmed to zero.
- `inline`
- : Margins provided to the inline children where they adjoin the container's edges are trimmed to zero, without affecting the spacing at the beginning and end of the row.
- `inline-start`
- : Margin between the container's edge and the first inline child is trimmed to zero.
- `inline-end`
- : Margin between the container's edge and the last inline child is trimmed to zero.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Basic usage
Once support is implemented for this property, it will probably work like so:
When you've got a container with some inline children and you want to put a margin between each child but not have it interfere with the spacing at the end of the row, you might do something like this:
```css
article {
background-color: red;
margin: 20px;
padding: 20px;
display: inline-block;
}
article > span {
background-color: black;
color: white;
text-align: center;
padding: 10px;
margin-right: 20px;
margin-left: 30px;
}
```
The problem here is that you'd end up with 20px too much spacing at the right of the row, so you'd maybe do this to fix it:
```css
span:last-child {
margin-right: 0;
margin-left: 0;
}
```
It is a pain having to write another rule to achieve this, and it is also not very flexible. Instead, `margin-trim` could fix it:
```css
article {
margin-trim: inline-end;
/* … */
}
```
Similarly, to remove left margin with the container's edge:
```css
article {
margin-trim: inline-start;
/* … */
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef("margin")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/@font-feature-values/index.md | ---
title: "@font-feature-values"
slug: Web/CSS/@font-feature-values
page-type: css-at-rule
browser-compat: css.at-rules.font-feature-values
---
{{CSSRef}}
The **`@font-feature-values`** [CSS](/en-US/docs/Web/CSS) [at-rule](/en-US/docs/Web/CSS/At-rule) lets you use a common name in the {{cssxref("font-variant-alternates")}} property for features activated differently in OpenType. This can help simplify your CSS when using multiple fonts.
The `@font-feature-values` at-rule may be used either at the top level of your CSS or inside any [CSS conditional-group at-rule](/en-US/docs/Web/CSS/At-rule#conditional_group_rules).
## Syntax
### Feature value blocks
- `@swash`
- : Specifies a feature name that will work with the {{cssxref("font-variant-alternates", "swash()", "#swash()")}} functional notation of {{cssxref("font-variant-alternates")}}. A swash feature value definition allows only one value: `ident1: 2` is valid, but `ident2: 2 4` isn't.
- `@annotation`
- : Specifies a feature name that will work with the {{cssxref("font-variant-alternates", "annotation()", "#annotation()")}} functional notation of {{cssxref("font-variant-alternates")}}. An annotation feature value definition allows only one value: `ident1: 2` is valid, but `ident2: 2 4` isn't.
- `@ornaments`
- : Specifies a feature name that will work with the {{cssxref("font-variant-alternates", "ornaments()", "#ornaments()")}} functional notation of {{cssxref("font-variant-alternates")}}. An ornaments feature value definition allows only one value: `ident1: 2` is valid, but `ident2: 2 4` isn't.
- `@stylistic`
- : Specifies a feature name that will work with the {{cssxref("font-variant-alternates", "stylistic()", "#stylistic()")}} functional notation of {{cssxref("font-variant-alternates")}}. A stylistic feature value definition allows only one value: `ident1: 2` is valid, but `ident2: 2 4` isn't.
- `@styleset`
- : Specifies a feature name that will work with the {{cssxref("font-variant-alternates", "styleset()", "#styleset()")}} functional notation of {{cssxref("font-variant-alternates")}}. A styleset feature value definition allows an unlimited number of values: `ident1: 2 4 12 1` maps to the OpenType values `ss02`, `ss04`, `ss12`, and `ss01`. Note that values higher than `99` are valid, but don't map to any OpenType values and are ignored.
- `@character-variant`
- : Specifies a feature name that will work with the {{cssxref("font-variant-alternates", "character-variant()", "#character-variant()")}} functional notation of {{cssxref("font-variant-alternates")}}. A character-variant feature value definition allows either one or two values: `ident1: 3` maps to `cv03=1`, and `ident2: 2 4` maps to `cv02=4`, but `ident2: 2 4 5` is invalid.
## Formal syntax
{{csssyntax}}
## Examples
### Using @styleset in a @font-feature-values rule
```css
/* At-rule for "nice-style" in Font One */
@font-feature-values Font One {
@styleset {
nice-style: 12;
}
}
/* At-rule for "nice-style" in Font Two */
@font-feature-values Font Two {
@styleset {
nice-style: 4;
}
}
…
/* Apply the at-rules with a single declaration */
.nice-look {
font-variant-alternates: styleset(nice-style);
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- The {{cssxref("font-variant-alternates")}} property that uses values that this at-rule defines.
| 0 |
data/mdn-content/files/en-us/web/css/@font-feature-values | data/mdn-content/files/en-us/web/css/@font-feature-values/font-display/index.md | ---
title: font-display
slug: Web/CSS/@font-feature-values/font-display
page-type: css-at-rule-descriptor
browser-compat: css.at-rules.font-feature-values.font-display
spec-urls: https://drafts.csswg.org/css-fonts/#descdef-font-feature-values-font-display
---
{{CSSRef}}
The **`font-display`** descriptor for the {{cssxref("@font-feature-values")}} at-rule sets the default value of how a font face is displayed based on whether and when it is downloaded. Setting a value for the `font-display` descriptor within a `@font-feature-values` block sets the default value of the `font-display` descriptor for the {{cssxref("@font-face")}} at-rule for all the fonts with the same {{cssxref("@font-face/font-family", "font-family")}} value.
## Syntax
```css
/* Keyword values */
font-display: auto;
font-display: block;
font-display: swap;
font-display: fallback;
font-display: optional;
```
### Values
- `auto`
- : The font display strategy is defined by the user agent.
- `block`
- : Gives the font face a short block period, generally around 3 seconds, and an infinite swap period.
- `swap`
- : Gives the font face an extremely small block period and an infinite swap period.
- `fallback`
- : Gives the font face an extremely small block period and a short swap period.
- `optional`
- : Gives the font face an extremely small block period and no swap period.
## Description
The `font-display` descriptor for `@font-feature-values` determines the font display timeline; it does so by setting a default `font-display` value for `@font-face` for the same `font-family` name. When `font-display` is omitted in `@font-face`, the user agent first looks for the `font-display` value that has been set via `@font-feature-values` for the relevant font-family. If no value is found, the user agent uses the `auto` value for `font-display`, in which case, the user agent determines the font display strategy.
The font display timeline is based on a timer that starts when the user agent attempts to use a specific downloaded font face. The timeline is divided into three periods, as listed below. These periods dictate the rendering behavior of any element that uses the font face.
- Font **block** period: If the font face is not loaded, elements attempting to use the font are rendered with an _invisible_ fallback font face. The browser blocks visible text rendering, saving a space for the to-be-displayed text based on metrics of the fallback font. During the block period, text is not visible. At the end of the block period, if the font has not loaded, the text is rendered in the fallback font.
- Font **swap** period: The swap period occurs after the block period (if there is one) and if the font face has not yet been loaded successfully. Elements attempting to use the not-yet-loaded font are rendered using the next available fallback font face. The formerly invisible fallback font face is painted onto the screen. If the font loads successfully during the swap period, the text that was rendered in the fallback font is updated — or swapped — with the newly loaded font. This step triggers a repaint.
- Font **failure** period: If the font face has not loaded by the time the swap period expires or by the time the block period expires (if there is no swap period, as is the case with `optional`), the user agent treats the font as a failed load. As a result, the content becomes visible in the fallback font.
The `font-display` descriptor allows you to set a default display policy for all `@font-face` rules, including those not under author control, such as third-party `@font-face` rules. When the `font-display` value is set via `@font-feature-values`, it becomes the default `font-display` value, and is applied to the entire font-family. However, any `font-display` value defined within individual `@font-face` blocks will override this default, but only for those blocks where the descriptor is defined.
## Examples
```css
@font-feature-values "Leitura" {
font-display: swap;
@swash {
fancy: 1;
}
}
```
The `font-display` descriptor in this example sets the default `font-display` value for the "Leitura" font to `swap` for all the `@font-face` blocks. Now there might be several `@font-face` blocks importing multiple font files for a single font-family. If one of those `@font-face` blocks includes a `font-display` descriptor, the specified value will be used for that specific font file only. All other blocks not including a `font-display` descriptor will default to `swap` instead of the user-agent's standard default `auto`.
## Specifications
{{Specifications}}
## Browser compatibility
There is no browser implementing this feature.
## See also
- {{cssxref("@font-face/font-display", "font-display")}} descriptor for {{cssxref("@font-face")}} at-rule
- {{cssxref("css_fonts", "CSS fonts")}} module
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/content/index.md | ---
title: content
slug: Web/CSS/content
page-type: css-property
browser-compat: css.properties.content
---
{{CSSRef}}
The **`content`** [CSS](/en-US/docs/Web/CSS) property replaces content with a generated value. It can be used to define what is rendered inside an element or pseudo-element. For elements, the `content` property specifies whether the element renders normally (`normal` or `none`) or is replaced with an image (and associated "alt" text). For pseudo-elements and margin boxes, `content` defines the content as images, text, both, or none, which determines whether the element renders at all.
Objects inserted using the `content` property are **anonymous [replaced elements](/en-US/docs/Web/CSS/Replaced_element)**.
{{EmbedInteractiveExample("pages/tabbed/content.html", "tabbed-shorter")}}
## Syntax
```css
/* Keywords that cannot be combined with other values */
content: normal;
content: none;
/* <content-replacement>: <image> values */
content: url("http://www.example.com/test.png");
content: linear-gradient(#e66465, #9198e5);
content: image-set("image1x.png" 1x, "image2x.png" 2x);
/* speech output: alternative text after a "/" */
content: url("../img/test.png") / "This is the alt text";
/* <string> value */
content: "unparsed text";
/* <counter> values, optionally with <list-style-type> */
content: counter(chapter_counter);
content: counter(chapter_counter, upper-roman);
content: counters(section_counter, ".");
content: counters(section_counter, ".", decimal-leading-zero);
/* attr() value linked to the HTML attribute value */
content: attr(href);
/* <quote> values */
content: open-quote;
content: close-quote;
content: no-open-quote;
content: no-close-quote;
/* <content-list>: a list of content values.
Several values can be used simultaneously */
content: "prefix" url(http://www.example.com/test.png);
content: "prefix" url("/img/test.png") "suffix" / "Alt text";
content: open-quote counter(chapter_counter);
/* Global values */
content: inherit;
content: initial;
content: revert;
content: revert-layer;
content: unset;
```
### Values
The value can be:
- One of two keywords — `none` or `normal`
- `<content-replacement>` when replacing a DOM node. `<content-replacement>` is always an `<image>`.
- A `<content-list>` when replacing pseudo-elements and margin boxes. A content-list is a list of one or more anonymous inline boxes appearing in the order specified. Each `<content-list>` item is either `contents` or of type [`<string>`](#string), [`<image>`](#image), [`<counter>`](#counter), [`<quote>`](#quote), [`<target>`](#target), or [`<leader()>`](#leader).
- An optional alternative text value of a `<string>` or `<counter>`, preceded by a slash (`/`).
The keywords and data types mentioned above are described in more detail below:
- `none`
- : When applied to a pseudo-element, the pseudo-element is not generated.
When applied to an element, the value has no effect.
- `normal`
- : The default value. Computes to `none` for the {{cssxref("::before")}} and {{cssxref("::after")}} pseudo-elements. For other pseudo-elements, the content will be the initial (or normal) content expected for that {{cssxref("::marker")}}, {{cssxref("::placeholder")}}, or {{cssxref("::file-selector-button")}}. For regular elements or page margin boxes, this computes to `contents`.
- `contents` {{Experimental_Inline}}
- : Adds the contents of the element itself to the generated content value.
- {{cssxref("<string>")}}
- : A sequence of characters enclosed in matching single or double quotes. Multiple string values will be concatenated (there is no concatenation operator in CSS).
- {{cssxref("<image>")}}
- : An {{cssxref("<image>")}}, representing an image to display. This can be equal to a {{cssxref("url", "url()")}}, {{cssxref("image/image-set", "image-set()")}}, or {{cssxref("<gradient>")}} data type, or a part of the webpage itself, defined by the {{cssxref("element", "element()")}} function.
- `<counter>`
- : The `<counter>` value is a [CSS counter](/en-US/docs/Web/CSS/CSS_counter_styles/Using_CSS_counters), generally a number produced by computations defined by {{cssxref("<counter-reset>")}} and {{cssxref("<counter-increment>")}} properties. It can be displayed using either the {{cssxref("counter", "counter()")}} or {{cssxref("counters", "counters()")}} function.
- {{cssxref("counter", "counter()")}}
- : The {{cssxref("counter", "counter()")}} function has two forms: 'counter(_name_)' or 'counter(_name_, style)'. The generated text is the value of the innermost counter of the given name in scope at the given pseudo-element. It is formatted in the specified {{cssxref("<list-style-type>")}} (`decimal` by default).
- {{cssxref("counters", "counters()")}}
- : The {{cssxref("counters", "counters()")}} function also has two forms: 'counters(_name_, _string_)' or 'counters(_name_, _string_, _style_)'. The generated text is the value of all counters with the given name in scope at the given pseudo-element, from outermost to innermost, separated by the specified string. The counters are rendered in the indicated {{cssxref("<list-style-type>")}} (`decimal` by default).
- `<quote>`
- : The `<quote>` data type includes language- and position-dependent keywords:
- `open-quote` and `close-quote`
- : These values are replaced by the appropriate string from the {{cssxref("quotes")}} property.
- `no-open-quote` and `no-close-quote`
- : Introduces no content, but increments (decrements) the level of nesting for quotes.
- `<target>` {{Experimental_Inline}}
- : The `<target>` data type includes three target functions, `<target-counter()>`, `<target-counters()>`, and `<target-text()>` that create cross-references obtained from the target end of a link. See [Formal syntax](#formal_syntax).
- `<leader()>` {{Experimental_Inline}}
- : The `<leader()>` data type inclues a leader function: `leader( <leader-type> )`. This function accepts the keyword values `dotted`, `solid`, or `space` (equal to `leader(".")`, `leader("_")`, and `leader(" ")`, respectively), or a `<string>` as a parameter. When supported and used as a value for `content`, the leader-type provided will be inserted as a repeating pattern, visually connecting content across a horizontal line.
- `attr(x)`
- : The `attr(x)` CSS function retrieves the value of an attribute of the selected element, or the pseudo-element's originating element. The value of the element's attribute `x` is an unparsed string representing the attribute name. If there is no attribute `x`, an empty string is returned. The case sensitivity of the attribute name parameter depends on the document language.
- alternative text: `/ <string> | <counter>`
- : Alternative text may be specified for an image or any `<content-list>` items, by appending a forward slash and then a string of text or a counter. The alternative text is intended for speech output by screen-readers, but may also be displayed in some browsers. Note that if the browser does not support alternative text, the `content` declaration will be considered invalid and will be ignored. The {{cssxref("string", "/ <string>")}} or {{cssxref("counter", "/ <counter>")}} data types specify the "alt text" for the element.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
The first five examples create generated content on pseudo-elements. The last three are [examples of element replacement](#element_replacement_with_url).
### Appending strings based on an element's class
This example inserts generated text after the text of elements that have a particular class name. The text is colored red.
#### HTML
```html
<h2>Paperback Best Sellers</h2>
<ol>
<li>Political Thriller</li>
<li class="new-entry">Halloween Stories</li>
<li>My Biography</li>
<li class="new-entry">Vampire Romance</li>
</ol>
```
#### CSS
```css
.new-entry::after {
content: " New!"; /* The leading space creates separation
between the DOM node's content and the generated content
being added. */
color: red;
}
```
#### Result
{{EmbedLiveSample('Appending_strings_based_on_an_elements_class', '100%', 160)}}
### Quotes
This example inserts differently colored quotation marks around quotes.
#### HTML
```html
<p>
According to Sir Tim Berners-Lee,
<q cite="http://www.w3.org/People/Berners-Lee/FAQ.html#Internet">
I was lucky enough to invent the Web at the time when the Internet already
existed - and had for a decade and a half.
</q>
We must understand that there is nothing fundamentally wrong with building on
the contributions of others.
</p>
<p lang="fr-fr">
Mais c'est Magritte qui a dit,
<q lang="fr-fr"> Ceci n'est pas une pipe. </q>.
</p>
```
#### CSS
```css
q {
color: #00f;
}
q::before,
q::after {
font-size: larger;
color: #f00;
background: #ccc;
}
q::before {
content: open-quote;
}
q::after {
content: close-quote;
}
```
#### Result
{{EmbedLiveSample('Quotes', '100%', 200)}}
Note the [type of quotes generated](/en-US/docs/Web/CSS/quotes#auto_quotes) is based on the language. Browsers add open- and close-quotes before and after {{HTMLElement("q")}} elements by default, so the quotes in this example would appear without them being explicitly set. They could have been turned off by setting the respective `content` property values to `no-open-quote` and `no-close-quote`, or by setting them both to `none`. They can also be turned off by setting the {{cssxref("quotes")}} property to `none` instead.
### Adding text to list item counters
This example combines a counter sandwiched between two `<string>`s prepended to all list items, creating a more detailed marker for list items ({{HTMLElement("li")}}) within unordered lists ({{HTMLElement("ol")}}).
#### HTML
```html
<ol>
<li>Dogs</li>
<li>Cats</li>
<li>
Birds
<ol>
<li>Owls</li>
<li>Ducks</li>
<li>Flightless</li>
</ol>
<li>Marsupials</li>
</li>
</ol>
```
#### CSS
```css
ol {
counter-reset: items;
margin-left: 2em;
}
li {
counter-increment: items;
}
li::marker {
content: "item " counters(items, ".", numeric) ": ";
}
```
#### Result
{{EmbedLiveSample('Adding_text_to_list_item_counters', '100%', 200)}}
The generated content on each list item's marker adds the text "item " as a prefix, including a space to separate the prefix from the counter, which is followed by ": ", a colon and an additional space. The {{cssxref("counters", "counters()")}} function defines a numeric `items` counter, in which the numbers of nested ordered lists have their numbers separated with a period (`.`) in most browsers.
### Strings with attribute values
This example is useful for print stylesheets. It uses an [attribute selector](/en-US/docs/Web/CSS/Attribute_selectors) to select every fully qualified secure link, adding the value of the `href` attribute after the link text as the content of the {{cssxref("::after")}} pseudo-element.
#### HTML
```html
<ul>
<li><a href="https://mozilla.com">Mozilla</a></li>
<li><a href="/">MDN</a></li>
<li><a href="https://openwebdocs.org">OpenWebDocs</a></li>
</ul>
```
#### CSS
```css
a[href^="https://"]::after
{
content: " (URL: " attr(href) ")";
color: darkgreen;
}
```
#### Result
{{EmbedLiveSample('Strings_with_attribute_values', '100%', 200)}}
The generated content is the value of the `href` attribute, prepended by "URL: ", with a space, all in parentheses.
### Adding an image with alternative text
This example inserts an image before all links. Two `content` values are provided. The later `content` value includes an image with alternative text that a screen reader can output as speech. If a browser does not support alternative text, this declaration will be considered invalid, with the previous `content` value displaying. This fallback content list includes an image and the message " - alt text is not supported - ".
#### HTML
```html
<a href="https://www.mozilla.org/en-US/">Mozilla Home Page</a>
```
#### CSS
The CSS to show the image and set the alternative text is shown below.
This also sets the font and color for the content.
This will be used on browsers that _display_ the alternative text and in browsers that don't support alternative text and show the fallback `content` value.
```css
a::before {
/* fallback content */
content: url("https://mozorg.cdn.mozilla.net/media/img/favicon.ico")
" - alt text is not supported - ";
/* content with alternative text */
content: url("https://mozorg.cdn.mozilla.net/media/img/favicon.ico") /
" MOZILLA: ";
font:
x-small Arial,
sans-serif;
color: gray;
}
```
#### Result
{{EmbedLiveSample('Adding_an_image_with_alternative_text', '100%', 60)}}
If using a screen reader, it should speak the word "MOZILLA" when it reaches the image. If supported (if the "alt text is not supported" is not showing), you can select the `::before` pseudo-element with your developer tools selection tool, and view the {{glossary("accessible name")}} in the accessibility panel.
In browsers that don't support the alternative text syntax the whole declaration containing the alt text is invalid. In this case, the previous `content` value will be used, showing the image and "alt text is not supported" text.
### Element replacement with `url()`
This example replaces a regular element! The element's contents are replaced with an SVG using the {{cssxref("url", "url()")}} image function.
Pseudo-elements aren't rendered on replaced elements. As this element is replaced, any matching `::after` or `::before` are not generated or applied. To demonstrate this, we include an `::after` declaration block, attempting to add the `id` as generated content. This pseudo-element will not be generated as the element is replaced.
#### HTML
```html
<div id="replaced">This content is replaced!</div>
```
#### CSS
```css
#replaced {
content: url("mdn.svg");
}
/* will not show if element replacement is supported */
div::after {
content: " (" attr(id) ")";
}
```
#### Result
{{EmbedLiveSample('Element_replacement_with_url', '100%',400)}}
When generating content on regular elements (rather than just on pseudo-elements), the entire element is replaced. This means that `::before` and `::after` pseudo-elements are not generated.
### Element replacement with `<gradient>`
This example demonstrates how an element's contents can be replaced by any type of `<image>`, in this case, a CSS gradient. The element's contents are replaced with a {{cssxref("gradient/linear-gradient" ,"linear-gradient()")}}. With {{cssxref("@supports")}}, we provide alt text support and a {{cssxref("gradient/repeating-linear-gradient" ,"repeating-linear-gradient()")}} for browsers that support alt text with element content replacement.
#### HTML
```html
<div id="replaced">I disappear</div>
```
#### CSS
```css
div {
border: 1px solid;
background-color: #ccc;
min-height: 100px;
min-width: 100px;
}
#replaced {
content: linear-gradient(#639f, #c96a);
}
@supports (content: linear-gradient(#000, #fff) / "alt text") {
#replaced {
content: repeating-linear-gradient(blue 0, orange 10%) /
"Gradients and alt text are supported";
}
}
```
#### Result
{{EmbedLiveSample('Element_replacement_with_gradient', '100%', 200)}}
Check the [browser compatibility chart](#browser_compatibility). All browsers support gradients and all browsers support replacing elements with images, but not all browsers support gradients as a `content` value and not all browsers support alt text on replacements. If the browser displays a box with no gradient, replacing elements is supported, but gradients are not supported as a content replacement value. If the element is replaced with a striped gradient, the browser supports both.
### Element replacement with `image-set()`
This example replaces an element's content with a {{cssxref("image/image-set" ,"image-set()")}}. If the users display has normal resolution the `1x.png` will be displayed screens with a higher resolution will display the `2x.png` image.
#### HTML
```html
<div id="replaced">Mozilla</div>
```
#### CSS
```css hidden
div {
width: 100px;
border: 1px solid lightgrey;
}
```
```css-nolint
#replaced {
content: image-set(
"1x.png" 1x,
"2x.png" 2x
);
}
```
#### Result
{{EmbedLiveSample('Element_replacement_with_image-set', '100%', 110)}}
## Accessibility concerns
CSS-generated content is not included in the [DOM](/en-US/docs/Web/API/Document_Object_Model/Introduction). Because of this, it will not be represented in the [accessibility tree](/en-US/docs/Learn/Accessibility/What_is_accessibility#accessibility_apis) and certain assistive technology/browser combinations will not announce it. If the content conveys information that is critical to understanding the page's purpose, it is better to include it in the main document.
If inserted content is not decorative, check that the information is provided to assistive technologies and is also available when CSS is turned off.
- [Accessibility support for CSS generated content – Tink](https://tink.uk/accessibility-support-for-css-generated-content/) (2015)
- [WCAG, Guideline 1.3: Create content that can be presented in different ways](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.3_—_create_content_that_can_be_presented_in_different_ways)
- [Understanding Success Criterion 1.3.1 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/content-structure-separation-programmatic.html)
- [Failure of Success Criterion 1.3.1: inserting non-decorative generated content](https://www.w3.org/TR/2016/NOTE-WCAG20-TECHS-20161007/F87) Techniques for WCAG 2.0
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{Cssxref("::after")}}
- {{Cssxref("::before")}}
- {{Cssxref("::marker")}}
- {{Cssxref("contain")}}
- {{Cssxref("quotes")}}
- {{cssxref("gradient", "<gradient>")}}
- {{cssxref("image/image-set", "image-set()")}}
- {{cssxref("url", "url()")}}
- [Replaced elements](/en-US/docs/Web/CSS/Replaced_element)
- [CSS generated content](/en-US/docs/Web/CSS/CSS_generated_content) 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/content/mdn.svg | <svg xmlns="http://www.w3.org/2000/svg" height="200" width="226.855"><defs><linearGradient gradientTransform="translate(-353.18 -4908.622) scale(6.99647)" gradientUnits="userSpaceOnUse" id="a" y2="701.6" x2="66.7" y1="730.2" x1="66.7"><stop offset="0" style="stop-color:#2075bc;stop-opacity:1"/><stop offset="1" style="stop-color:#29aae1;stop-opacity:1"/></linearGradient><linearGradient gradientTransform="translate(-353.18 -4908.622) scale(6.99647)" gradientUnits="userSpaceOnUse" id="b" y2="701.6" x2="54.6" y1="730.2" x1="54.6"><stop offset="0" style="stop-color:#0a6aa8;stop-opacity:1"/><stop offset="1" style="stop-color:#1699c8;stop-opacity:1"/></linearGradient><linearGradient gradientTransform="translate(-353.18 -4908.622) scale(6.99647)" gradientUnits="userSpaceOnUse" id="c" y2="701.6" x2="70.7" y1="730.2" x1="70.7"><stop offset="0" style="stop-color:#0a6aa8;stop-opacity:1"/><stop offset="1" style="stop-color:#1699c8;stop-opacity:1"/></linearGradient></defs><path style="fill:url(#a)" d="m56.89 0-.353.354L0 22.969V200l56.537-21.555L113.427 200l56.538-21.555L226.855 200V22.969L169.965.354 169.61 0v.354l-56.183 22.261L56.89.354V0zm43.026 42.215c.968.017 1.938.077 2.91.187 7.067 1.767 13.783 4.595 20.85 6.008 6.36-1.767 14.487-3.533 20.494.707 3.887 3.887 7.773 8.48 6.006 14.487 10.954 12.014 34.983 13.427 41.697 22.615 1.06 1.413.353 11.66 2.473 17.668l.707 2.828c-2.12 4.24-7.068 15.9-5.301 13.426-1.767 2.473-3.534 3.18-8.48 2.12-4.24 2.828-6.714 4.24-11.307 6.714-4.947 1.06-15.9-2.474-20.848-3.534-9.187-1.766-9.894.354-18.021 4.594-12.014 6.007-9.541 20.85-14.135 29.33 0 1.06.354 1.766.707 2.826s.707 1.766.707 2.473c-13.78 1.767-27.209-.352-39.576-6.36-9.54-4.593-17.667-11.661-24.381-20.142 1.413-.707 3.178-1.766 4.592-2.473 1.06-.353 2.121-1.06 2.828-1.414H60.07c-3.18-.706-1.413-.353-3.886-.353 2.826-3.18 6.715-6.006 7.068-6.36l.352-.353c-3.534 1.06-8.834 2.474-11.66 5.3 1.06-4.946 4.594-8.128 6.36-12.015-4.24 2.12-8.481 4.949-12.015 8.13 0-3.888 4.595-7.776 6.715-10.956 1.413-2.12 3.534-3.886 4.594-6.36-4.24 1.414-14.135 6.713-18.022 9.186 1.767-6.007 9.895-15.193 14.488-19.787-4.593.353-14.134 6.007-18.021 8.127 0-.353.353-.707 0-1.06 3.18-4.948 12.72-12.721 17.314-16.608-5.3.707-15.9 6.36-20.847 8.127 4.24-7.774 18.374-17.313 25.088-22.967l-16.254 4.24c-2.474 0-4.595 1.766-6.715 1.413 8.48-8.481 25.796-23.322 37.103-30.39 0 0 13.665-9.626 28.184-9.374z"/><path style="fill:url(#b)" d="M56.89 0 0 22.969V200l56.89-21.555v-37.304a85.988 85.988 0 0 1-2.472-2.979 68.24 68.24 0 0 0 2.473-1.33v-2.936c-.21.011-.344.026-.707.026.226-.255.469-.503.707-.752v-3.707c-1.89.797-3.674 1.773-4.948 3.047.823-3.838 3.128-6.615 4.948-9.48v-1.8c-3.761 2.02-7.461 4.566-10.602 7.393 0-3.887 4.595-7.775 6.715-10.955 1.148-1.722 2.753-3.216 3.887-5.04v-1.05c-4.53 1.687-13.615 6.562-17.315 8.916 1.767-6.007 9.895-15.193 14.488-19.787-4.593.353-14.134 6.007-18.021 8.127 0-.353.353-.707 0-1.06 3.18-4.948 12.72-12.721 17.314-16.608-5.3.707-15.9 6.36-20.847 8.127 4.108-7.531 17.444-16.688 24.38-22.395v-.388l-15.546 4.056c-2.474 0-4.595 1.766-6.715 1.413 5.224-5.225 13.802-12.857 22.262-19.604V0z"/><path style="fill:url(#c)" d="m169.965 0-56.537 22.969v22.627c3.386 1.083 6.775 2.12 10.248 2.814 6.36-1.767 14.487-3.533 20.494.707 3.887 3.887 7.773 8.48 6.006 14.487 4.891 5.364 12.39 8.613 19.789 11.386V0zm-26.397 124.818c-4.455.05-6.377 2.037-12.472 5.217-12.014 6.007-9.541 20.85-14.135 29.33 0 1.06.354 1.766.707 2.826s.707 1.766.707 2.473a74.51 74.51 0 0 1-4.947.465V200l56.537-21.555v-49.47c-4.947 1.06-15.9-2.474-20.848-3.534-2.297-.441-4.063-.64-5.549-.623z"/></svg> | 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/scroll-margin/index.md | ---
title: scroll-margin
slug: Web/CSS/scroll-margin
page-type: css-shorthand-property
browser-compat: css.properties.scroll-margin
---
{{CSSRef}}
The **`scroll-margin`** [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) sets all of the scroll margins of an element at once, assigning values much like the [`margin`](/en-US/docs/Web/CSS/margin) property does for margins of an element.
{{EmbedInteractiveExample("pages/css/scroll-margin.html")}}
## Constituent properties
This property is a shorthand for the following CSS properties:
- [`scroll-margin-bottom`](/en-US/docs/Web/CSS/scroll-margin-bottom)
- [`scroll-margin-left`](/en-US/docs/Web/CSS/scroll-margin-left)
- [`scroll-margin-right`](/en-US/docs/Web/CSS/scroll-margin-right)
- [`scroll-margin-top`](/en-US/docs/Web/CSS/scroll-margin-top)
## Syntax
```css
/* <length> values */
scroll-margin: 10px;
scroll-margin: 1em 0.5em 1em 1em;
/* Global values */
scroll-margin: inherit;
scroll-margin: initial;
scroll-margin: revert;
scroll-margin: revert-layer;
scroll-margin: unset;
```
### Values
- {{cssxref("<length>")}}
- : An outset from the corresponding edge of the scroll container.
## Description
You can see the effect of `scroll-margin` by scrolling to a point partway between two of the "pages" of the example's content. The value specified for `scroll-margin` determines how much of the page that's primarily outside the snapport should remain visible.
Thus, the `scroll-margin` values represent outsets defining the scroll snap area that is used for snapping this box to the snapport. The scroll snap area is determined by taking the transformed border box, finding its rectangular bounding box (axis-aligned in the scroll container's coordinate space), then adding the specified outsets.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Simple demonstration
This example implements something very similar to the interactive example above, except that here we'll explain to you how it's implemented.
The aim here is to create four horizontally-scrolling blocks, the second and third of which snap into place, near but not quite at the left of each block.
#### HTML
The HTML that represents the blocks is very simple:
```html
<div class="scroller">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
```
#### CSS
Let's walk through the CSS. The outer container is styled like this:
```css
.scroller {
text-align: left;
width: 250px;
height: 250px;
overflow-x: scroll;
display: flex;
box-sizing: border-box;
border: 1px solid #000;
scroll-snap-type: x mandatory;
}
```
The main parts relevant to the scroll snapping are `overflow-x: scroll`, which makes sure the contents will scroll and not be hidden, and `scroll-snap-type: x mandatory`, which dictates that scroll snapping must occur along the horizontal axis, and the scrolling will always come to rest on a snap point.
The child elements are styled as follows:
```css
.scroller > div {
flex: 0 0 250px;
width: 250px;
background-color: #663399;
color: #fff;
font-size: 30px;
display: flex;
align-items: center;
justify-content: center;
scroll-snap-align: start;
}
.scroller > div:nth-child(2n) {
background-color: #fff;
color: #663399;
}
```
The most relevant part here is `scroll-snap-align: start`, which specifies that the left-hand edges (the "starts" along the x axis, in our case) are the designated snap points.
Last of all we specify the scroll margin-values, a different one for the second and third child elements:
```css
.scroller > div:nth-child(2) {
scroll-margin: 1rem;
}
.scroller > div:nth-child(3) {
scroll-margin: 2rem;
}
```
This means that when scrolling past the middle child elements, the scrolling will snap to `1rem` outside the left edge of the second `<div>`, and `2rems` outside the left edge of the third `<div>`.
> **Note:** Here we are setting `scroll-margin` on all sides at once, but only the start edge is really relevant. It would work just as well here to only set a scroll margin on that one edge, for example with `scroll-margin-inline-start: 1rem`, or `scroll-margin: 0 0 0 1rem`.
#### Result
Try it for yourself:
{{EmbedLiveSample('Simple_demonstration', '100%', 300)}}
## 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/css_backgrounds_and_borders/index.md | ---
title: CSS backgrounds and borders
slug: Web/CSS/CSS_backgrounds_and_borders
page-type: css-module
spec-urls: https://drafts.csswg.org/css-backgrounds/
---
{{CSSRef}}
The **CSS backgrounds and borders** module provides properties for adding borders, rounded corners, and box shadows to elements.
You can add different types of border styles, including borders made of images of any image type, from raster images to CSS gradients. Borders can be square or rounded, and a different radius can be set for each corner. Elements can be rounded whether or not they have a visible border.
Box shadows include inset and outset shadow, single or multiple shadows, and solid or allowed to fade to transparent. An outer box-shadow casts a shadow as if the border-box of the element were opaque. An inner box-shadow casts a shadow as if everything outside the padding edge were opaque. The shadow can be solid or include a spread distance with the shadow color transitioning to transparent.
The properties in this module also let you define whether cells inside a {{HTMLElement("table")}} should have shared or separate borders.
### Backgrounds, borders, and box shadows in action
This sample of borders, backgrounds, and box shadows consists of centered background images made of linear and radial gradients. A series of box shadows make the border appear to "pop". The element on the left has a border image set. The element on the right has a rounded dotted border.
{{EmbedGHLiveSample("css-examples/modules/backgrounds.html", '100%', 430)}}
The background images are defined with {{cssxref("background-image")}}. The images are centered with {{cssxref("background-position")}}. Different values of the {{cssxref("background-clip")}} property for the multiple background images are used to make the background images stay within the content box. The background color gets clipped to the padding box preventing the background from appearing through the transparent sections for the {{cssxref("border-image")}} and the {{cssxref("border-style", "dotted")}} {{cssxref("border")}}. The rounded corners in the element on the right are created using the {{cssxref("border-radius")}} property. A single {{cssxref("box-shadow")}} declaration is used to set all the shadows, both inset and outset.
To see the code for this sample, [view the source on GitHub](https://github.com/mdn/css-examples/blob/main/modules/backgrounds.html).
## Reference
### Properties
- {{cssxref("background-attachment")}}
- {{cssxref("background-clip")}}
- {{cssxref("background-color")}}
- {{cssxref("background-image")}}
- {{cssxref("background-origin")}}
- {{cssxref("background-position")}}
- {{cssxref("background-repeat")}}
- {{cssxref("background-size")}}
- {{cssxref("background")}} shorthand
- {{cssxref("background-position-x")}} {{experimental_inline}}
- {{cssxref("background-position-y")}} {{experimental_inline}}
- {{cssxref("background-position-inline")}} {{experimental_inline}}
- {{cssxref("background-position-block")}} {{experimental_inline}}
- {{cssxref("border-bottom-color")}}
- {{cssxref("border-bottom-style")}}
- {{cssxref("border-bottom-width")}}
- {{cssxref("border-bottom")}} shorthand
- {{cssxref("border-left-color")}}
- {{cssxref("border-left-style")}}
- {{cssxref("border-left-width")}}
- {{cssxref("border-left")}} shorthand
- {{cssxref("border-right-color")}}
- {{cssxref("border-right-style")}}
- {{cssxref("border-right-width")}}
- {{cssxref("border-right")}} shorthand
- {{cssxref("border-top-color")}}
- {{cssxref("border-top-style")}}
- {{cssxref("border-top-width")}}
- {{cssxref("border-top")}} shorthand
- {{cssxref("border-color")}} shorthand
- {{cssxref("border-style")}} shorthand
- {{cssxref("border-width")}} shorthand
- {{cssxref("border")}} shorthand
- {{cssxref("border-collapse")}}
- {{cssxref("border-bottom-left-radius")}}
- {{cssxref("border-bottom-right-radius")}}
- {{cssxref("border-top-left-radius")}}
- {{cssxref("border-top-right-radius")}}
- {{cssxref("border-radius")}} shorthand
- {{cssxref("border-image-outset")}}
- {{cssxref("border-image-repeat")}}
- {{cssxref("border-image-slice")}}
- {{cssxref("border-image-source")}}
- {{cssxref("border-image-width")}}
- {{cssxref("border-image")}} shorthand
- {{cssxref("box-shadow")}}
### Data types
- {{cssxref("line-style")}} enumerated type
## Guides
- [Learn CSS: background and borders](/en-US/docs/Learn/CSS/Building_blocks/Backgrounds_and_borders)
- : Explains how to implement decorative images using CSS background images.
- [Using multiple backgrounds](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders/Using_multiple_backgrounds)
- : Explains how to set one or more backgrounds on an element.
- [Resizing background images](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders/Resizing_background_images)
- : Describes how to change the size and repeating behavior of background images.
- [Learn CSS: the box model](/en-US/docs/Learn/CSS/Building_blocks/The_box_model)
- : Explains how borders, along with other box model properties, impact the CSS box model.
- [Using CSS gradients](/en-US/docs/Web/CSS/CSS_images/Using_CSS_gradients)
- : Explains how to create CSS gradient background images.
## Related concepts
- {{cssxref("border-block-end-color")}} property
- {{cssxref("border-block-start-color")}} property
- {{cssxref("border-inline-end-color")}} property
- {{cssxref("border-inline-start-color")}} property
- {{cssxref("border-block-end-style")}} property
- {{cssxref("border-block-start-style")}} property
- {{cssxref("border-inline-end-style")}} property
- {{cssxref("border-inline-start-style")}} property
- {{cssxref("border-block-end-width")}} property
- {{cssxref("border-block-start-width")}} property
- {{cssxref("border-inline-end-width")}} property
- {{cssxref("border-inline-start-width")}} property
- {{cssxref("border-start-start-radius")}} property
- {{cssxref("border-start-end-radius")}} property
- {{cssxref("border-end-start-radius")}} property
- {{cssxref("border-end-end-radius ")}} property
- {{cssxref("box-sizing")}} property
- {{cssxref("box-decoration-break")}} property
- {{cssxref("text-shadow")}} property
- {{cssxref("url", "url()")}} CSS function
- [`<color>`](/en-US/docs/Web/CSS/color) data type
- [`<image>`](/en-US/docs/Web/CSS/image) data type
- [`<position>`](/en-US/docs/Web/CSS/position) data type
- [`currentcolor`](/en-US/docs/Web/CSS/color_value#currentcolor_keyword) keyword
## Specifications
{{Specifications}}
## See also
- Interactive tools that let you visually create borders images, rounded corners, and box shadows:
- [Border-image generator](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders/Border-image_generator)
- [Border-radius generator](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders/Border-radius_generator)
- [Box-shadow generator](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders/Box-shadow_generator)
- [Applying color to HTML elements using CSS](/en-US/docs/Web/CSS/CSS_colors/Applying_color), including for borders.
- The [`drop-shadow()`](/en-US/docs/Web/CSS/filter-function/drop-shadow) filter function that applies a drop shadow effect to the input image. The function is used by the {{cssxref("filter")}} and {{cssxref("backdrop-filter")}} properties.
| 0 |
data/mdn-content/files/en-us/web/css/css_backgrounds_and_borders | data/mdn-content/files/en-us/web/css/css_backgrounds_and_borders/resizing_background_images/index.md | ---
title: Resizing background images with background-size
slug: Web/CSS/CSS_backgrounds_and_borders/Resizing_background_images
page-type: guide
---
{{CSSRef}}
The **{{cssxref("background-size")}}** CSS property lets you resize the background image of an element, overriding the default behavior of tiling the image at its full size by specifying the width and/or height of the image. By doing so, you can scale the image upward or downward as desired.
## Tiling a large image
Let's consider a large image, a 2982x2808 Firefox logo image. We want (for some reason likely involving horrifyingly bad site design) to tile four copies of this image into a 300x300-pixel element. To do this, we can use a fixed `background-size` value of 150 pixels.
### HTML
```html
<div class="tiledBackground"></div>
```
### CSS
```css
.tiledBackground {
background-image: url(https://www.mozilla.org/media/img/logos/firefox/logo-quantum.9c5e96634f92.png);
background-size: 150px;
width: 300px;
height: 300px;
border: 2px solid;
color: pink;
}
```
### Result
{{EmbedLiveSample("Tiling_a_large_image", 340, 340)}}
## Stretching an image
You can also specify both the horizontal and vertical sizes of the image, like this:
```css
background-size: 300px 150px;
```
The result looks like this:

## Scaling an image up
On the other end of the spectrum, you can scale an image up in the background. Here we scale a 32x32 pixel favicon to 300x300 pixels:

```css
.square2 {
background-image: url(favicon.png);
background-size: 300px;
width: 300px;
height: 300px;
border: 2px solid;
text-shadow: white 0px 0px 2px;
font-size: 16px;
}
```
As you can see, the CSS is actually essentially identical, save the name of the image file.
## Special values: `contain` and `cover`
In addition to {{cssxref("<length>")}} values, the {{cssxref("background-size")}} CSS property offers two special size values, `contain` and `cover`. Let's take a look at these.
### `contain`
The `contain` value specifies that, regardless of the size of the containing box, the background image should be scaled so that each side is as large as possible while not exceeding the length of the corresponding side of the container. Try resizing the example below to see this in action.
#### HTML
```html
<div class="bgSizeContain">
<p>Try resizing this element!</p>
</div>
```
#### CSS
```css
.bgSizeContain {
background-image: url(https://www.mozilla.org/media/img/logos/firefox/logo-quantum.9c5e96634f92.png);
background-size: contain;
width: 160px;
height: 160px;
border: 2px solid;
resize: both;
overflow: scroll;
}
```
#### Result
{{EmbedLiveSample('contain', 250, 250)}}
### `cover`
The `cover` value specifies that the background image should be sized so that it is as small as possible while ensuring that both dimensions are greater than or equal to the corresponding size of the container. Try resizing the example below to see this in action.
#### HTML
```html
<div class="bgSizeCover">
<p>Try resizing this element!</p>
</div>
```
#### CSS
```css
.bgSizeCover {
background-image: url(https://www.mozilla.org/media/img/logos/firefox/logo-quantum.9c5e96634f92.png);
background-size: cover;
width: 160px;
height: 160px;
border: 2px solid;
resize: both;
overflow: scroll;
}
```
#### Result
{{EmbedLiveSample('cover', 250, 250)}}
## See also
- {{cssxref("background-size")}}
- {{cssxref("background")}}
- [Scaling of SVG backgrounds](/en-US/docs/Web/CSS/Scaling_of_SVG_backgrounds)
| 0 |
data/mdn-content/files/en-us/web/css/css_backgrounds_and_borders | data/mdn-content/files/en-us/web/css/css_backgrounds_and_borders/box-shadow_generator/index.md | ---
title: Box-shadow generator
slug: Web/CSS/CSS_backgrounds_and_borders/Box-shadow_generator
page-type: guide
---
{{CSSRef}}
This tool lets you construct CSS {{cssxref("box-shadow")}} effects, to add box shadow effects to your CSS objects.
{{EmbedGHLiveSample("css-examples/tools/box-shadow-generator/", '100%', 900)}}
The box-shadow generator enables you to add one or more box shadows to an element.
On opening the tool, you'll find a rectangle in the top-right section of the tool. That's the element you're going to be applying shadows to. When this element is selected (as it is, when you first load the page) you can apply some basic styling to it:
- Set the element's {{cssxref("color")}} using the color picker tool.
- Give the element a {{cssxref("border")}} using the "border" checkbox.
- Use the sliders to set the element's {{cssxref("top")}}, {{cssxref("left")}}, {{cssxref("width")}}, and {{cssxref("height")}} properties.
To add a box shadow, click the "+" button at the top-left. This adds a shadow, and lists it in the column on the left. Now you can set the values of the new shadow:
- Set the shadow's {{cssxref("color")}} using the color picker tool.
- Set the shadow to be inset using the "inset" checkbox.
- Use the sliders to set the element's position, blur, and spread.
To add another shadow, click "+" again. Now any values you set will apply to this new shadow. Change the order in which these two shadows are applied using the ↑ and ↓ buttons at the top-left. Select the first shadow again by clicking it in column on the left. To update the element's own styles, select it by clicking the button labelled "element" along the top.
You can add {{cssxref("::before")}} and {{cssxref("::after")}} pseudo-elements to the element, and give them box shadows as well. To switch between the element and its pseudo-elements, use the buttons along the top labeled "element", ":before", and ":after".
The box at the bottom-right contains the CSS for the element and any `before::` or `::after` pseudo-elements.
## See also
- [Border-image generator](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders/Border-image_generator)
- : This interactive tool lets you visually create border images (the {{cssxref("border-image")}} property).
- [Border-radius generator](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders/Border-radius_generator)
- : This interactive tool lets you visually create rounded corners (the {{cssxref("border-radius")}} property).
| 0 |
data/mdn-content/files/en-us/web/css/css_backgrounds_and_borders | data/mdn-content/files/en-us/web/css/css_backgrounds_and_borders/border-image_generator/index.md | ---
title: Border-image generator
slug: Web/CSS/CSS_backgrounds_and_borders/Border-image_generator
page-type: guide
---
{{CSSRef}}
This tool can be used to generate CSS {{cssxref("border-image")}} values.
{{EmbedGHLiveSample("css-examples/tools/border-image-generator/", '100%', 1200)}}
## See also
- [Border-radius generator](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders/Border-radius_generator)
- : This interactive tool lets you visually create rounded corners (the {{cssxref("border-radius")}} property).
- [Box-shadow generator](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders/Box-shadow_generator)
- : This interactive tool lets you visually create shadows behind elements (the {{cssxref("box-shadow")}} property).
| 0 |
data/mdn-content/files/en-us/web/css/css_backgrounds_and_borders | data/mdn-content/files/en-us/web/css/css_backgrounds_and_borders/border-radius_generator/index.md | ---
title: Border-radius generator
slug: Web/CSS/CSS_backgrounds_and_borders/Border-radius_generator
page-type: guide
---
{{CSSRef}}
This tool can be used to generate CSS {{cssxref("border-radius")}} effects.
{{EmbedGHLiveSample("css-examples/tools/border-radius-generator/", '100%', 900)}}
## See also
- [Border-image generator](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders/Border-image_generator)
- : This interactive tool lets you visually create border images (the {{cssxref("border-image")}} property).
- [Box-shadow generator](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders/Box-shadow_generator)
- : This interactive tool lets you visually create shadows behind elements (the {{cssxref("box-shadow")}} property).
| 0 |
data/mdn-content/files/en-us/web/css/css_backgrounds_and_borders | data/mdn-content/files/en-us/web/css/css_backgrounds_and_borders/using_multiple_backgrounds/index.md | ---
title: Using multiple backgrounds
slug: Web/CSS/CSS_backgrounds_and_borders/Using_multiple_backgrounds
page-type: guide
---
{{CSSRef}}
You can apply **multiple backgrounds** to elements. These are layered atop one another with the first background you provide on top and the last background listed in the back. Only the last background can include a background color.
Specifying multiple backgrounds is easy:
```css
.myclass {
background:
background1,
background2,
/* …, */ backgroundN;
}
```
You can do this with both the shorthand {{ cssxref("background") }} property and the individual properties thereof except for {{ cssxref("background-color") }}. That is, the following background properties can be specified as a list, one per background: {{ cssxref("background") }}, {{ cssxref("background-attachment") }}, {{ cssxref("background-clip") }}, {{ cssxref("background-image") }}, {{ cssxref("background-origin") }}, {{ cssxref("background-position") }}, {{ cssxref("background-repeat") }}, {{ cssxref("background-size") }}.
## Example
In this example, three backgrounds are stacked: the Firefox logo, an image of bubbles, and a [linear gradient](/en-US/docs/Web/CSS/gradient/linear-gradient):
### HTML
```html
<div class="multi-bg-example"></div>
```
### CSS
```css
.multi-bg-example {
width: 100%;
height: 400px;
background-image: url(firefox.png), url(bubbles.png), linear-gradient(to right, rgb(30
75 115 / 100%), rgb(255 255 255 / 0%));
background-repeat: no-repeat, no-repeat, no-repeat;
background-position:
bottom right,
left,
right;
}
```
### Result
(If image does not appear in CodePen, click the 'Tidy' button in the CSS section)
{{EmbedLiveSample('Example','600','400')}}
As you can see here, the Firefox logo (listed first within {{ cssxref("background-image") }}) is on top, directly above the bubbles graphic, followed by the gradient (listed last) sitting underneath all previous 'images'. Each subsequent sub-property ({{ cssxref("background-repeat") }} and {{ cssxref("background-position") }}) applies to the corresponding backgrounds. So the first listed value for {{ cssxref("background-repeat") }} applies to the first (frontmost) background, and so forth.
## See also
- [Using CSS gradients](/en-US/docs/Web/CSS/CSS_images/Using_CSS_gradients)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/text-decoration-style/index.md | ---
title: text-decoration-style
slug: Web/CSS/text-decoration-style
page-type: css-property
browser-compat: css.properties.text-decoration-style
---
{{CSSRef}}
The **`text-decoration-style`** [CSS](/en-US/docs/Web/CSS) property sets the style of the lines specified by {{ cssxref("text-decoration-line") }}. The style applies to all lines that are set with `text-decoration-line`.
{{EmbedInteractiveExample("pages/css/text-decoration-style.html")}}
If the specified decoration has a specific semantic meaning, like a line-through line meaning that some text has been deleted, authors are encouraged to denote this meaning using an HTML tag, like {{ HTMLElement("del") }} or {{ HTMLElement("s") }}. As browsers can disable styling in some cases, the semantic meaning won't disappear in such a situation.
When setting multiple line-decoration properties at once, it may be more convenient to use the {{cssxref("text-decoration")}} shorthand property instead.
## Syntax
```css
/* Keyword values */
text-decoration-style: solid;
text-decoration-style: double;
text-decoration-style: dotted;
text-decoration-style: dashed;
text-decoration-style: wavy;
/* Global values */
text-decoration-style: inherit;
text-decoration-style: initial;
text-decoration-style: revert;
text-decoration-style: revert-layer;
text-decoration-style: unset;
```
### Values
- solid
- : Draws a single line.
- double
- : Draws a double line.
- dotted
- : Draws a dotted line.
- dashed
- : Draws a dashed line.
- wavy
- : Draws a wavy line.
- \-moz-none {{ non-standard_inline }}
- : Draws no line. Use {{ cssxref("text-decoration-line") }}`: none` instead.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting a wavy underline
The following creates a red wavy underline:
#### CSS
```css
.wavy {
text-decoration-line: underline;
text-decoration-style: wavy;
text-decoration-color: red;
}
```
#### HTML
```html
<p class="wavy">This text has a wavy red line beneath it.</p>
```
#### Results
{{EmbedLiveSample('Setting_a_wavy_underline')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- When setting multiple line-decoration properties at once, it may be more convenient to use the {{cssxref("text-decoration")}} shorthand property instead.
- {{cssxref("text-decoration-line")}}
- {{cssxref("text-decoration-color")}}
- {{cssxref("text-decoration-thickness")}}
- {{cssxref("text-underline-offset")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_user-valid/index.md | ---
title: ":user-valid"
slug: Web/CSS/:user-valid
page-type: css-pseudo-class
browser-compat: css.selectors.user-valid
---
{{CSSRef}}
The **`:user-valid`** CSS [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents any validated form element whose value validates correctly based on its [validation constraints](/en-US/docs/Learn/Forms#constraint_validation). However, unlike {{cssxref(":valid")}} it only matches once the user has interacted with it.
This pseudo-class is applied according to the following rules:
- If the control does not have focus, and the value is valid, apply this pseudo-class.
- If the control has focus, and the value was valid (including empty) when it gained focus, apply this pseudo-class.
- If the control has focus, and the value was invalid when it gained focus, re-validate on every keystroke.
- If the element is required, the preceding rules apply only if the user has changed the value or attempted to submit the form.
The result is that if the control was valid when the user started interacting with it, the validity styling is changed only when the user shifts focus to another control. However, if the user is trying to correct a previously-flagged value, the control shows immediately when the value becomes valid. Required items are flagged as invalid only if the user changes them or attempts to submit an unchanged invalid value.
## Syntax
```css
:user-valid {
/* ... */
}
```
## Examples
### Setting a color and symbol on :user-valid
In the following example, the green border and ✅ only display once the user has interacted with the field.
Try changing the email address to another valid email to see it in action.
```html
<form>
<label for="email">Email *: </label>
<input
id="email"
name="email"
type="email"
value="[email protected]"
required />
<span></span>
</form>
```
```css
input:user-valid {
border: 2px solid green;
}
input:user-valid + span::before {
content: "✓";
color: green;
}
```
{{EmbedLiveSample("Setting_a_color_and_symbol_on_user-valid", 140, 100)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef(":valid")}}
- {{CSSxRef(":invalid")}}
- {{CSSxRef(":required")}}
- {{CSSxRef(":optional")}}
- {{CSSxRef(":user-invalid")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/id_selectors/index.md | ---
title: ID selectors
slug: Web/CSS/ID_selectors
page-type: css-selector
browser-compat: css.selectors.id
---
{{CSSRef}}
The CSS **ID selector** matches an element based on the value of the element's [`id`](/en-US/docs/Web/HTML/Global_attributes/id) attribute. In order for the element to be selected, its `id` attribute must match exactly the value given in the selector.
```css
/* The element with id="demo" */
#demo {
border: red 2px solid;
}
```
## Syntax
```css
#id_value { style properties }
```
Note that syntactically (but not specificity-wise), this is equivalent to the following {{Cssxref("Attribute_selectors", "attribute selector")}}:
```css
[id=id_value] { style properties }
```
## Examples
### CSS
```css
#identified {
background-color: skyblue;
}
```
### HTML
```html
<div id="identified">This div has a special ID on it!</div>
<div>This is just a regular div.</div>
```
### Result
{{EmbedLiveSample("Examples", '100%', 50)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [CSS Selectors](/en-US/docs/Web/CSS/CSS_selectors)
- [Learn CSS: Selectors](/en-US/docs/Learn/CSS/Building_blocks/Selectors)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/contain-intrinsic-width/index.md | ---
title: contain-intrinsic-width
slug: Web/CSS/contain-intrinsic-width
page-type: css-property
browser-compat: css.properties.contain-intrinsic-width
---
{{CSSRef}}
The **`contain-intrinsic-width`** [CSS](/en-US/docs/Web/CSS) property sets the width of an element that a browser will use for layout when the element is subject to [size containment](/en-US/docs/Web/CSS/CSS_containment#size_containment).
## Syntax
```css
/* Keyword values */
contain-intrinsic-width: none;
/* <length> values */
contain-intrinsic-width: 1000px;
contain-intrinsic-width: 10rem;
/* auto <length> */
contain-intrinsic-width: auto 300px;
/* Global values */
contain-intrinsic-width: inherit;
contain-intrinsic-width: initial;
contain-intrinsic-width: revert;
contain-intrinsic-width: revert-layer;
contain-intrinsic-width: unset;
```
### Values
The following values may be specified for an element.
- `none`
- : The element has no intrinsic width.
- `<length>`
- : The element has the specified width ({{cssxref("<length>")}}).
- `auto <length>`
- : A remembered value of the "normally rendered" element width if one exists and the element is skipping its contents (for example, when it is offscreen); otherwise 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), and may also be set using the [`contain-intrinsic-size`](/en-US/docs/Web/CSS/contain-intrinsic-size) [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties).
Size containment allows a user agent to lay out an element as though it had a fixed size, preventing 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-width` property allows authors to specify an appropriate value to be used as the width for layout.
The `auto <length>` value allows the width of the element to be stored if the element is ever "normally rendered" (with its child elements), and then used instead of the specified width when the element is skipping its contents.
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 as 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>` will be used).
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
In addition to the example below, the {{CSSxRef("contain-intrinsic-size")}} page contains a live example that demonstrates the effect of modifying the intrinsic width and height.
### Setting the intrinsic width
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 width and height that are used when it is size constrained are set at the same time using `contain-intrinsic-width` and `contain-intrinsic-height`, respectively.
```css
#contained_element {
border: 2px solid green;
width: 151px;
content-visibility: auto;
contain-intrinsic-width: 152px;
contain-intrinsic-height: 52px;
}
.child_element {
border: 1px solid red;
background: blue;
height: 50px;
width: 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-size")}}
- {{CSSxRef("contain-intrinsic-height")}}
- {{CSSxRef("contain-intrinsic-block-size")}}
- {{CSSxRef("contain-intrinsic-inline-size")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/height/index.md | ---
title: height
slug: Web/CSS/height
page-type: css-property
browser-compat: css.properties.height
---
{{CSSRef}}
The **`height`** CSS property specifies the height of an element. By default, the property defines the height of the [content area](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model#content_area). If {{cssxref("box-sizing")}} is set to `border-box`, however, it instead determines the height of the [border area](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model#border_area).
{{EmbedInteractiveExample("pages/css/height.html")}}
The {{cssxref("min-height")}} and {{cssxref("max-height")}} properties override `height`.
## Syntax
```css
/* <length> values */
height: 120px;
height: 10em;
height: 100vh;
/* <percentage> value */
height: 75%;
/* Keyword values */
height: max-content;
height: min-content;
height: fit-content;
height: fit-content(20em);
height: auto;
/* Global values */
height: inherit;
height: initial;
height: revert;
height: revert-layer;
height: unset;
```
### Values
- {{cssxref("<length>")}}
- : Defines the height as a distance value.
- {{cssxref("<percentage>")}}
- : Defines the height as a percentage of the [containing block](/en-US/docs/Web/CSS/Containing_block)'s height.
- `auto`
- : The browser will calculate and select a height for the specified element.
- `max-content`
- : The intrinsic preferred height.
- `min-content`
- : The intrinsic minimum height.
- `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("<length-percentage>")}})` {{Experimental_Inline}}
- : Uses the fit-content formula with the available space replaced by the specified argument, i.e. `min(max-content, max(min-content, <length-percentage>))`.
- {{cssxref("clamp", "clamp()")}}
- : Enables selecting a middle value within a range of values between a defined minimum and maximum.
## Accessibility concerns
Ensure that elements set with a `height` aren't truncated and/or don't obscure other content when the page is zoomed to increase text size.
- [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.4 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-scale.html)
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting height using pixels and percentages
#### HTML
```html
<div id="taller">I'm 50 pixels tall.</div>
<div id="shorter">I'm 25 pixels tall.</div>
<div id="parent">
<div id="child">I'm half the height of my parent.</div>
</div>
```
#### CSS
```css
div {
width: 250px;
margin-bottom: 5px;
border: 2px solid blue;
}
#taller {
height: 50px;
}
#shorter {
height: 25px;
}
#parent {
height: 100px;
}
#child {
height: 50%;
width: 75%;
}
```
#### Result
{{EmbedLiveSample('Setting_height_using_pixels_and_percentages', 'auto', 240)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [The box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model)
- {{cssxref("width")}}
- {{cssxref("box-sizing")}}
- {{cssxref("min-height")}}, {{cssxref("max-height")}}
- The mapped logical properties: {{cssxref("block-size")}}, {{cssxref("inline-size")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/used_value/index.md | ---
title: Used value
slug: Web/CSS/used_value
page-type: guide
spec-urls: https://www.w3.org/TR/CSS22/cascade.html#used-value
---
{{CSSRef}}
The **used value** of a [CSS](/en-US/docs/Web/CSS) property is its value after all calculations have been performed on the [computed value](/en-US/docs/Web/CSS/computed_value).
After the {{glossary("user agent")}} has finished its calculations, every CSS property has a used value. The used values of dimensions (e.g., {{cssxref("width")}}, {{cssxref("line-height")}}) are in pixels. The used values of shorthand properties (e.g., {{cssxref("background")}}) are consistent with those of their component properties (e.g., {{cssxref("background-color")}} or {{cssxref("background-size")}}) and with {{cssxref("position")}} and {{cssxref("float")}}.
> **Note:** The {{domxref("Window.getComputedStyle", "getComputedStyle()")}} DOM API returns the [resolved value](/en-US/docs/Web/CSS/resolved_value), which may either be the [computed value](/en-US/docs/Web/CSS/computed_value) or the used value, depending on the property.
## Example
This example computes and displays the used `width` value of three elements (updates on resize):
### HTML
```html
<div id="no-width">
<p>No explicit width.</p>
<p class="show-used-width">..</p>
<div id="width-50">
<p>Explicit width: 50%.</p>
<p class="show-used-width">..</p>
<div id="width-inherit">
<p>Explicit width: inherit.</p>
<p class="show-used-width">..</p>
</div>
</div>
</div>
```
### CSS
```css
#no-width {
width: auto;
}
#width-50 {
width: 50%;
}
#width-inherit {
width: inherit;
}
/* Make results easier to see */
div {
border: 1px solid red;
padding: 8px;
}
```
### JavaScript
```js
function updateUsedWidth(id) {
const div = document.getElementById(id);
const par = div.querySelector(".show-used-width");
const wid = window.getComputedStyle(div)["width"];
par.textContent = `Used width: ${wid}.`;
}
function updateAllUsedWidths() {
updateUsedWidth("no-width");
updateUsedWidth("width-50");
updateUsedWidth("width-inherit");
}
updateAllUsedWidths();
window.addEventListener("resize", updateAllUsedWidths);
```
### Result
{{ EmbedLiveSample('Example', '80%', 372) }}
## Difference from computed value
CSS 2.0 defined only _computed value_ as the last step in a property's calculation. Then, CSS 2.1 introduced the distinct definition of used value. An element could then explicitly inherit a width/height of a parent, whose computed value is a percentage. For CSS properties that don't depend on layout (e.g., `display`, `font-size`, or `line-height`), the computed values and used values are the same. The following are the CSS 2.1 properties that do depend on layout, so they have a different computed value and used value: (taken from [CSS 2.1 Changes: Specified, computed, and actual values](https://www.w3.org/TR/CSS2/changes.html#q21.36)):
- `background-position`
- `bottom`, `left`, `right`, `top`
- `height`, `width`
- `margin-bottom`, `margin-left`, `margin-right`, `margin-top`
- `min-height`, `min-width`
- `padding-bottom`, `padding-left`, `padding-right`, `padding-top`
- `text-indent`
## Specifications
{{Specifications}}
## See also
- {{domxref("window.getComputedStyle")}}
- 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](/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**
- [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/css_conditional_rules/index.md | ---
title: CSS conditional rules
slug: Web/CSS/CSS_conditional_rules
page-type: css-module
spec-urls:
- https://www.w3.org/TR/css-conditional-5/
- https://www.w3.org/TR/css-conditional-4/
- https://www.w3.org/TR/css-conditional-3/
---
{{CSSRef}}
The **CSS conditional rules** module defines CSS media and support queries, enabling you to define styles that are only applied if specific conditions are met. The conditional rules defined in this module are based on device, user-agent, and viewport capabilities. With conditional rules, you can target CSS styles based on query values or browser and device features, independent of the document being rendered.
The first CSS conditional rules were [media types](/en-US/docs/Web/CSS/@media#media_types) specifying the intended destination medium for the linked styles, for example `screen` or `print`. These were set as the value of the HTML {{HTMLElement("link")}} and {{HTMLElement("style")}} elements' `media` attributes or as a comma-separated list of media types within an {{cssxref("@import")}} statement or at-rule. The ability to conditionally apply CSS rules has been greatly expanded since the CSS 2.1 and HTML 4.01 implementations that limited conditional queries to a few media types.
CSS conditional rules now include feature queries; the `@supports` at-rule enables targeting CSS styles based on a user-agent's CSS capabilities. Additional conditions include which selector, font-formats, and font-techs are supported.
The CSS conditional rules module also expands `@media` to enable nesting at-rules, with the related [CSS media queries](/en-US/docs/Web/CSS/CSS_media_queries) module removing unused media types and adding many media features and conditions that can be targeted.
The [CSS container queries module](/en-US/docs/Web/CSS/CSS_containment/Container_queries) defines similar conditional rules, but based on an element's parent rather than the viewport.
There are plans to further extend possible queries by adding the generalized conditional rule `@when` and the chained conditional rule `@else`. These two at-rules are not yet supported.
## Reference
### At-rules
- {{cssxref("@media")}}
- {{cssxref("@supports")}}
> **Note:** The CSS conditional rules module introduces two at-rules that have not been implemented: `@else` and `@when`.
### Functions
- [`font-tech()`](/en-US/docs/Web/CSS/@supports#font-tech)
- [`font-format()`](/en-US/docs/Web/CSS/@supports#font-format)
- [`selector()`](/en-US/docs/Web/CSS/@supports#function_syntax)
- [`supports()`](/en-US/docs/Web/CSS/@import#supports-condition)
> **Note:** The CSS conditional rules module introduces a CSS function that has not been implemented: `media()`.
### data types
- [`<media-query>`](/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries#syntax)
- [`<supports-condition>`](/en-US/docs/Web/CSS/@import#importing_css_rules_conditional_on_feature_support)
- `<supports-feature>` (see [`supports()`](/en-US/docs/Web/CSS/@import#supports-condition))
### Interfaces
- {{domxref("CSSConditionRule")}}
- {{domxref("CSSMediaRule")}}
- {{domxref("CSSSupportsRule")}}
- {{domxref("CSS.supports_static", "supports()")}} method
### Terms and glossary definitions
- {{glossary("media/CSS", "Media")}}
- Supports query (See [feature query](/en-US/docs/Web/CSS/CSS_conditional_rules/Using_feature_queries))
- [Conditional group rules](/en-US/docs/Web/CSS/At-rule#conditional_group_rules)
## Guides
- [Using CSS feature queries](/en-US/docs/Web/CSS/CSS_conditional_rules/Using_feature_queries)
- : Selectively applying CSS rules after checking browser support for the specified properties and values via feature queries.
- [Using CSS media queries](/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries)
- : Introduces media queries, their syntax, and the operators and media features that are used to construct media query expressions.
- [Supporting older browsers: feature queries](/en-US/docs/Learn/CSS/CSS_layout/Supporting_Older_Browsers#feature_queries)
- : How to use feature queries to target CSS based on the browser's level of support for web features.
- [Browser feature detection: CSS `@supports`](/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Feature_detection#supports)
- : A look at JavaScript and CSS feature detection, including CSS `@supports`.
## Related concepts
- [CSS cascade and inheritance](/en-US/docs/Web/CSS/CSS_cascade) module
- {{cssxref("@import")}} at-rule
- [CSS media queries](/en-US/docs/Web/CSS/CSS_media_queries) module
- [`<media-feature>`](/en-US/docs/Web/CSS/@media#media_features)
- [`<media-type>`](/en-US/docs/Web/CSS/@media#media_types)
- [`<media-condition>`](/en-US/docs/Web/CSS/@media#logical_operators)
- [`<media-query-list>`](/en-US/docs/Web/SVG/Attribute/media)
- [CSS logical operators](/en-US/docs/Web/CSS/@media#logical_operators) (`not`, `or`, and `and`)
- [CSSOM view](/en-US/docs/Web/CSS/CSSOM_view) module
- {{domxref("CSS")}} API
- {{domxref("CSSGroupingRule")}} API
- {{domxref("MediaQueryList")}} API
- {{domxref("CSSRule")}} API
- {{domxref("MediaList")}} interface
- {{domxref("MediaList.mediaText")}} property
- [CSS syntax](/en-US/docs/Web/CSS/CSS_syntax) module
- {{cssxref("@charset")}} declaration
- {{cssxref("at-rule")}} term
- [`invalid`](/en-US/docs/Web/CSS/CSS_syntax/Error_handling) term
- {{glossary("parse")}} term
- [style rule](/en-US/docs/Web/API/CSSStyleRule) term
- [CSS namespaces](/en-US/docs/Web/CSS/CSS_namespaces) module
- {{cssxref("@namespace")}} at-rule
## Specifications
{{Specifications}}
## See also
- [CSS container queries](/en-US/docs/Web/CSS/CSS_containment/Container_queries) module
- [CSS media queries](/en-US/docs/Web/CSS/CSS_media_queries) module
- [CSS cascade and inheritance](/en-US/docs/Web/CSS/CSS_cascade) module
| 0 |
data/mdn-content/files/en-us/web/css/css_conditional_rules | data/mdn-content/files/en-us/web/css/css_conditional_rules/using_feature_queries/index.md | ---
title: Using feature queries
slug: Web/CSS/CSS_conditional_rules/Using_feature_queries
page-type: guide
---
{{CSSRef}}
**Feature queries** are conditional group rules that test whether the user agent supports or doesn't support one or more CSS features, such as CSS properties and property values. Feature queries give web developers a way to test to see if a browser has support for a certain feature, and then provide CSS that will only run based on the result of that test. In this guide, you will learn how to implement progressive enhancement using feature queries.
Feature queries are created using the CSS at-rule [`@supports`](/en-US/docs/Web/CSS/@supports) (or the `supports()` function within [`@import`](/en-US/docs/Web/CSS/@import) at-rules).
## Syntax
CSS feature queries are part of the [CSS conditional rules](/en-US/docs/Web/CSS/CSS_conditional_rules) module, which also defines the media query [`@media`](/en-US/docs/Web/CSS/@media) at-rule. Feature queries behave similarly to [media queries](/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries). The difference is that with a media query, you are testing something about the environment in which the web page is running, whereas with feature queries you are testing browser support for CSS features.
A feature query consists of the `@supports` at-rule followed by the support condition or a `supports()` function and declaration parameter within an `@import` at-rule declaration:
```css
/* `@supports` at-rule */
@supports <support-condition> {
CSS rules to apply
}
/* `supports()` function */
@import url_to_import supports(<declaration>);
```
For example, we can apply a set of styles or import an entire stylesheet if the user-agent supports `red` as a valid value for the CSS {{cssxref("color")}} property:
```css
/* `@supports` at-rule */
@supports (color: red) {
CSS rules to apply
}
/* `supports()` function */
@import `/css/styles.css` supports(color: red);
```
As another example, if you want to check if a browser supports the `row-gap` property you would write the following feature query. It doesn't matter which value you use in a lot of cases: if all you want is to check that the browser supports this property, then any valid value will do.
{{EmbedGHLiveSample("css-examples/feature-queries/simple.html", '100%', 600)}}
The value part of the property-value pair matters more if you are testing for new values of a particular property. All browsers support `color: red`: this dates back to CSS1. However, there are often additional values added to properties in CSS, like [relative colors](/en-US/docs/Web/CSS/CSS_colors/Relative_colors), which may not be supported. Feature queries enable testing property and value pairs, meaning we can detect support for values.
Expanding on the `color` property example above, here we check if the browser supports the `color: AccentColor` declaration:
```css
/* `@supports` at-rule */
@supports (color: AccentColor) {
CSS rules to apply
}
/* `supports()` function */
@import `/css/styles.css` supports(color: AccentColor);
```
In these examples, we've used feature queries to check if the user-agent supports a specific value of a CSS property, listing the single declaration within parenthesis. You can test for multiple property values or the lack of support.
## Testing for lack of support
In addition to asking the browser if it supports a feature, you can test for the opposite by adding in the `not` keyword:
```css
/* `@supports` at-rule with `not` */
@supports not (property: value) {
CSS rules to apply
}
```
The CSS inside the following example feature query will run if the browser does not support `row-gap`.
{{EmbedGHLiveSample("css-examples/feature-queries/not.html", '100%', 600)}}
## Testing for more than one feature
You may need to test support for more than one property in your feature query. To do so, you can include a list of features to test for, separated by `and` keywords:
```css
/* multiple feature `@supports` at-rule */
@supports (property1: value) and (property2: value) {
CSS rules to apply
}
```
For example, if the CSS you want to run requires that the browser supports CSS Shapes and CSS Grid, you could create a rule that tests browser support for both of these features. The following rule will only return true if `shape-outside: circle()` and `display: grid` are both supported by the browser.
{{EmbedGHLiveSample("css-examples/feature-queries/and.html", '100%', 600)}}
## Testing for at least one of multiple features
You can also use `or` to apply CSS only if one or more declarations are supported:
```css
/* any feature `@supports` at-rule */
@supports (property1: value) or (property2: value) {
CSS rules to apply
}
```
This can be particularly useful if a feature is vendor prefixed, as you can test for the standard property plus any vendor prefixes.
{{EmbedGHLiveSample("css-examples/feature-queries/or.html", '100%', 600)}}
## Additional feature query options
Feature queries are not limited to property-value pairs. You can include [`font-tech()`](/en-US/docs/Web/CSS/@supports#font-tech), [`font-format()`](/en-US/docs/Web/CSS/@supports#font-format), and [`selector()`](/en-US/docs/Web/CSS/@supports#function_syntax) functions in your feature queries to selectively apply CSS based on whether the user-agent supports a specified font technology, font format, or selector syntax, respectively.
For example, the `selector()` function can be used to import a stylesheet for browsers that support a vendor-prefixed pseudo-element:
```css
/* A `selector()` query within a `supports()` function */
@import `/css/webkitShadowStyles.css` supports(selector(::-webkit-inner-spin-button));
```
## Examples
### Browser support test
In this example, we check if the browser supports the `AccentColor` {{cssxref("system-color")}} and use `display: none` to change the default "not supported" message to a "supported" message if the color type is supported.
#### HTML
```html
<p class="accentcolor">
Your browser does <span>not</span> support <code>AccentColor</code> as a color
value.
</p>
```
#### CSS
```css
@supports (color: AccentColor) {
p {
color: green;
border: 2px solid;
}
span {
display: none;
}
}
@supports not (color: AccentColor) {
p {
color: red;
}
}
```
#### Results
{{EmbedLiveSample("Browser support test", "600", "50")}}
## Limitations of feature queries
The `@supports` rule tests to see if browsers can parse one or more property/value pairs, and therefore if they claim to support the associated feature(s). If the property/value pairs are understood by a browser it returns a positive response. Feature queries check that declarations are considered valid by a browser, but can't be used to check if it supports a feature properly without bugs or spec violations. Feature queries cannot test for _partial implementations_.
## Summary
Feature queries are a useful tool for progressively enhancing a site. They enable you to provide a good solution for all browsers, and an enhanced solution for browsers that support newer properties and values.
You don't need to use feature queries to start using new CSS features; CSS error handling means the browser simply ignores CSS it does not yet recognize. However, feature queries are a useful alternative to fallback declarations, and enable writing code once that can eventually be supported everywhere.
### See also
- [CSS conditional rules](/en-US/docs/Web/CSS/CSS_conditional_rules) module
- [Using CSS media queries](/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries)
- [Supporting older browsers: feature queries](/en-US/docs/Learn/CSS/CSS_layout/Supporting_Older_Browsers#feature_queries)
- [Browser feature detection: CSS `@supports`](/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Feature_detection#supports)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_doublecolon_-moz-range-track/index.md | ---
title: "::-moz-range-track"
slug: Web/CSS/::-moz-range-track
page-type: css-pseudo-element
status:
- non-standard
browser-compat: css.selectors.-moz-range-track
---
{{CSSRef}}{{Non-standard_header}}
The **`::-moz-range-track`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) is a [Mozilla extension](/en-US/docs/Web/CSS/Mozilla_Extensions) that represents the _track_ (i.e., groove) in which the indicator slides in an {{HTMLElement("input")}} of `type="range"`.
> **Note:** Using `::-moz-range-track` with anything but an `<input type="range">` doesn't match anything and has no effect.
## Syntax
```css
::-moz-range-track {
/* ... */
}
```
## Examples
### HTML
```html
<input type="range" min="0" max="100" step="5" value="50" />
```
### CSS
```css
input[type="range"]::-moz-range-track {
background-color: green;
}
```
### Result
{{EmbedLiveSample("Examples", 300, 50)}}
A range slider using this style might look something like this:

## Specifications
Not part of any standard.
## Browser compatibility
{{Compat}}
## See also
- The pseudo-elements used by Gecko to style other parts of a range input:
- {{cssxref("::-moz-range-thumb")}} represents the indicator that slides in the groove.
- {{cssxref("::-moz-range-progress")}} represents the lower portion of the track.
- Similar pseudo-elements used by other browsers:
- {{cssxref("::-webkit-slider-runnable-track")}}, pseudo-element supported by WebKit and Blink (Safari, Chrome, and Opera)
- [CSS-Tricks: Styling Cross-Browser Compatible Range Inputs with CSS](https://css-tricks.com/styling-cross-browser-compatible-range-inputs-css/)
- [QuirksMode: Styling and scripting sliders](https://www.quirksmode.org/blog/archives/2015/11/styling_and_scr.html)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/padding-inline-start/index.md | ---
title: padding-inline-start
slug: Web/CSS/padding-inline-start
page-type: css-property
browser-compat: css.properties.padding-inline-start
---
{{CSSRef}}
The **`padding-inline-start`** [CSS](/en-US/docs/Web/CSS) property defines the logical inline start padding of an element, which maps to a physical padding depending on the element's writing mode, directionality, and text orientation.
{{EmbedInteractiveExample("pages/css/padding-inline-start.html")}}
## Syntax
```css
/* <length> values */
padding-inline-start: 10px; /* An absolute length */
padding-inline-start: 1em; /* A length relative to the text size */
/* <percentage> value */
padding-inline-start: 5%; /* A padding relative to the block container's width */
/* Global values */
padding-inline-start: inherit;
padding-inline-start: initial;
padding-inline-start: revert;
padding-inline-start: revert-layer;
padding-inline-start: unset;
```
### Values
- {{cssxref("<length>")}}
- : The size of the padding as a fixed value. Must be nonnegative.
- {{cssxref("<percentage>")}}
- : 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
The `padding-inline-start` property is defined in the specification as taking the same values as the {{cssxref("padding-top")}} property. However, the physical property it maps to depends on the values set for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. Therefore, it could map to {{cssxref("padding-bottom")}}, {{cssxref("padding-right")}}, or {{cssxref("padding-left")}}.
It relates to {{cssxref("padding-block-start")}}, {{cssxref("padding-block-end")}}, and {{cssxref("padding-inline-end")}}, which define the other paddings of the element.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting inline start 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-lr;
padding-inline-start: 20px;
background-color: #c8c800;
}
```
#### Result
{{EmbedLiveSample("Setting_inline_start_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/padding/index.md | ---
title: padding
slug: Web/CSS/padding
page-type: css-shorthand-property
browser-compat: css.properties.padding
---
{{CSSRef}}
The **`padding`** [CSS](/en-US/docs/Web/CSS) [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) sets the [padding area](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model#padding_area) on all four sides of an element at once.
{{EmbedInteractiveExample("pages/css/padding.html")}}
An element's padding area is the space between its content and its border.
> **Note:** Padding creates extra space within an element. In contrast, {{cssxref("margin")}} creates extra space _around_ an element.
## Constituent properties
This property is a shorthand for the following CSS properties:
- {{cssxref("padding-top")}}
- {{cssxref("padding-right")}}
- {{cssxref("padding-bottom")}}
- {{cssxref("padding-left")}}
## Syntax
```css
/* Apply to all four sides */
padding: 1em;
/* top and bottom | left and right */
padding: 5% 10%;
/* top | left and right | bottom */
padding: 1em 2em 2em;
/* top | right | bottom | left */
padding: 5px 1em 0 2em;
/* Global values */
padding: inherit;
padding: initial;
padding: revert;
padding: revert-layer;
padding: unset;
```
The `padding` property may be specified using one, two, three, or four values. Each value is a {{cssxref("<length>")}} or a {{cssxref("<percentage>")}}. Negative values are invalid.
- When **one** value is specified, it applies the same padding to **all four sides**.
- When **two** values are specified, the first padding applies to the **top and bottom**, the second to the **left and right**.
- When **three** values are specified, the first padding applies to the **top**, the second to the **right and left**, the third to the **bottom**.
- When **four** values are specified, the paddings apply to the **top**, **right**, **bottom**, and **left** in that order (clockwise).
### Values
- {{cssxref("<length>")}}
- : The size of the padding as a fixed value.
- {{cssxref("<percentage>")}}
- : 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).
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting padding with pixels
#### HTML
```html
<h4>This element has moderate padding.</h4>
<h3>The padding is huge in this element!</h3>
```
#### CSS
```css
h4 {
background-color: lime;
padding: 20px 50px;
}
h3 {
background-color: cyan;
padding: 110px 50px 50px 110px;
}
```
#### Result
{{EmbedLiveSample('Setting_padding_with_pixels', '100%', 300)}}
### Setting padding with pixels and percentages
```css
padding: 5%; /* All sides: 5% padding */
padding: 10px; /* All sides: 10px padding */
padding: 10px 20px; /* top and bottom: 10px padding */
/* left and right: 20px padding */
padding: 10px 3% 20px; /* top: 10px padding */
/* left and right: 3% padding */
/* bottom: 20px padding */
padding: 1em 3px 30px 5px; /* top: 1em padding */
/* right: 3px padding */
/* bottom: 30px padding */
/* left: 5px padding */
```
## 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-bottom")}}, and {{cssxref("padding-left")}}.
- 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/aspect-ratio/index.md | ---
title: aspect-ratio
slug: Web/CSS/aspect-ratio
page-type: css-property
browser-compat: css.properties.aspect-ratio
---
{{CSSRef}}
The **`aspect-ratio`** [CSS](/en-US/docs/Web/CSS) property allows you to define the desired width-to-height ratio of an element's box. This means that even if the parent container or viewport size changes, the browser will adjust the element's dimensions to maintain the specified width-to-height ratio. The specified aspect ratio is used in the calculation of auto sizes and some other layout functions.
At least one of the box's sizes needs to be automatic in order for `aspect-ratio` to have any effect. If neither the width nor height is an automatic size, then the provided aspect ratio has no effect on the box's preferred sizes.
{{EmbedInteractiveExample("pages/css/aspect-ratio.html")}}
## Syntax
```css
aspect-ratio: 1 / 1;
aspect-ratio: 1;
/* fallback to 'auto' for replaced elements */
aspect-ratio: auto 3/4;
aspect-ratio: 9/6 auto;
/* Global values */
aspect-ratio: inherit;
aspect-ratio: initial;
aspect-ratio: revert;
aspect-ratio: revert-layer;
aspect-ratio: unset;
```
This property is specified as one or both of the keyword auto or a `<ratio>`. If both are given, then If the element is a [replaced element](/en-US/docs/Web/CSS/Replaced_element), such as [`<img>`](/en-US/docs/Web/HTML/Element/img), then the given ratio is used until the content is loaded. After the content is loaded, the `auto` value is applied, so the intrinsic aspect ratio of the loaded content is used.
If the element is not a replaced element, then the given `ratio` is used.
### Values
- `auto`
- : [Replaced elements](/en-US/docs/Web/CSS/Replaced_element) with an intrinsic aspect ratio use _that_ aspect ratio, otherwise the box has no preferred aspect ratio. Size calculations involving intrinsic aspect ratio always work with the content box dimensions.
- {{cssxref("<ratio>")}}
- : The box's preferred aspect ratio is the specified ratio of `width` / `height`. If `height` and the preceding slash character are omitted, `height` defaults to `1`. Size calculations involving preferred aspect ratio work with the dimensions of the box specified by `box-sizing`.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Exploring aspect-ratio effects with fixed width
In this example, the width of the `<div>` elements has been set to `100px` and height to `auto`. Since the width value is fixed here, the `aspect-ratio` property affects only the height of the `<div>` elements to maintain the specified width-to-height ratio.
```html hidden
<div>1/1</div>
<div>0.5</div>
<div>1</div>
<div>1/0.5</div>
<div>16/9</div>
```
```css hidden
div {
display: inline-flex;
background-color: lime;
justify-content: center;
}
```
```css
div {
width: 100px;
height: auto;
}
div:nth-child(1) {
aspect-ratio: 1/1;
}
div:nth-child(2) {
aspect-ratio: 0.5;
}
div:nth-child(3) {
aspect-ratio: 1;
}
div:nth-child(4) {
aspect-ratio: 1/0.5;
}
div:nth-child(5) {
aspect-ratio: 16/9;
}
```
{{EmbedLiveSample('Exploring aspect-ratio effects with fixed width', '100%', '300px')}}
### Fallback to natural aspect ratio
In this example we are using two`<img>` elements. The first element does not have its `src` attribute set to an image file.
```html
<img src="" /> <img src="plumeria.jpg" />
```
The following code sets `3/2` as the preferred aspect ratio and `auto` as a fallback.
```css
img {
display: inline;
width: 200px;
border: 2px dashed red;
background-color: lime;
vertical-align: top;
aspect-ratio: 3/2 auto;
}
```
Note how the first image without replaced content keeps the `3/2` aspect ratio, while the second image after the content is loaded uses the image's natural aspect ratio.
{{EmbedLiveSample('Fallback to natural aspect ratio', '100%', '300px')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Image aspect-ratio: preventing jank](/en-US/docs/Learn/Performance/Multimedia#rendering_strategy_preventing_jank_when_loading_images)
- [Designing an aspect ratio unit for CSS](https://www.smashingmagazine.com/2019/03/aspect-ratio-unit-css/)
- [Setting Height And Width On Images Is Important Again](https://www.smashingmagazine.com/2020/03/setting-height-width-images-important-again/)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/@layer/index.md | ---
title: "@layer"
slug: Web/CSS/@layer
page-type: css-at-rule
browser-compat: css.at-rules.layer
---
{{CSSRef}}
The **`@layer`** [CSS](/en-US/docs/Web/CSS) [at-rule](/en-US/docs/Web/CSS/At-rule) is used to declare a cascade layer and can also be used to define the order of precedence in case of multiple cascade layers.
{{EmbedInteractiveExample("pages/tabbed/at-rule-layer.html", "tabbed-standard")}}
## Syntax
```css
@layer layer-name {rules}
@layer layer-name;
@layer layer-name, layer-name, layer-name;
@layer {rules}
```
where:
- _layer-name_
- : Is the name of the cascade layer.
- _rules_
- : Is the set of CSS rules in the cascade layer.
## Description
Rules within a cascade layer cascade together, giving more control over the cascade to web developers. Any styles not in a layer are gathered together and placed into a single anonymous layer that comes after all the declared layers, named and anonymous. This means that any styles declared outside of a layer will override styles declared in a layer, regardless of specificity.
The `@layer` at-rule is used to create a cascade layer in one of three ways.
The first way is to create a named cascade layer with the CSS rules for that layer inside, like so:
```css
@layer utilities {
.padding-sm {
padding: 0.5rem;
}
.padding-lg {
padding: 0.8rem;
}
}
```
The second way is to create a named cascade layer without assigning any styles. This can be a single layer, as shown below:
```css
@layer utilities;
```
Multiple layers can be defined at once, as shown below:
```css
@layer theme, layout, utilities;
```
This is useful because the initial order in which layers are declared indicates which layer has precedence. As with declarations, the last layer to be listed will win if declarations are found in multiple layers. Therefore, with the preceding example, if a competing rule was found in `theme` and `utilities`, the one in `utilities` would win and be applied.
A rule in `utilities` would be applied _even if it has lower specificity_ than the rule in `theme`. This is because once the layer order has been established, specificity and order of appearance are ignored. This enables the creation of simpler CSS selectors because you do not have to ensure that a selector will have high enough specificity to override competing rules; all you need to ensure is that it appears in a later layer.
> **Note:** Having declared your layer names, thus setting their order, you can add CSS rules to the layer by re-declaring the name. The styles are then appended to the layer and the layer order will not be changed.
The third way is to create a cascade layer with no name. For example:
```css
@layer {
p {
margin-block: 1rem;
}
}
```
This creates an _anonymous cascade layer_. This layer functions in the same way as named layers; however, rules cannot be assigned to it later. The order of precedence for anonymous layers is the order in which layers are declared, named or not, and lower than the styles declared outside of a layer.
Another way to create a cascade layer is by using {{cssxref("@import")}}. In this case, the rules would be in the imported stylesheet. Remember that the `@import` at-rule must precede all other types of rules, except `@charset` and `@layer` rules.
```css
@import "theme.css" layer(utilities);
```
### Nesting layers
Layers may be nested. For example:
```css
@layer framework {
@layer layout {
}
}
```
To append rules to the `layout` layer inside `framework`, join the two names with a `.`.
```css
@layer framework.layout {
p {
margin-block: 1rem;
}
}
```
## Formal syntax
{{csssyntax}}
## Examples
### Simple example
In the following example, two CSS rules are created. One for the {{htmlelement("p")}} element outside of any layer and one inside a layer named `type` for `.box p`.
Without layers, the selector `.box p` would have the highest specificity, and therefore, the text `Hello, world!` will display in green. As the `type` layer comes before the anonymous layer created to hold non-layer content, the text will be purple.
Also notice the order. Even though we declare the non-layered style first, it's still applied _after_ the layer styles.
#### HTML
```html
<div class="box">
<p>Hello, world!</p>
</div>
```
#### CSS
```css
p {
color: rebeccapurple;
}
@layer type {
.box p {
font-weight: bold;
font-size: 1.3em;
color: green;
}
}
```
#### Result
{{EmbedLiveSample("Simple_example")}}
### Assigning rules to existing layers
In the following example, two layers are created with no rules applied, then CSS rules are applied to the two layers. The `base` layer defines a `color`, `border`, `font-size`, and `padding`. The `special` layer defines a different color. As `special` comes last when the layers were defined, the color it provides is used and the text is displayed using `rebeccapurple`. All of the other rules from `base` still apply.
#### HTML
```html
<div class="item">
I am displayed in <code>color: rebeccapurple</code> because the
<code>special</code> layer comes after the <code>base</code> layer. My green
border, font-size, and padding come from the <code>base</code> layer.
</div>
```
#### CSS
```css
@layer base, special;
@layer special {
.item {
color: rebeccapurple;
}
}
@layer base {
.item {
color: green;
border: 5px solid green;
font-size: 1.3em;
padding: 0.5em;
}
}
```
#### Result
{{EmbedLiveSample("Assigning_rules_to_existing_layers")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [`@import`](/en-US/docs/Web/CSS/@import)
- {{domxref("CSSLayerBlockRule")}}
- {{domxref("CSSLayerStatementRule")}}
- [`!important`](/en-US/docs/Web/CSS/important)
- [`revert-layer`](/en-US/docs/Web/CSS/revert-layer)
- [Introducing the CSS cascade](/en-US/docs/Web/CSS/Cascade)
- [Cascade, specificity, and inheritance](/en-US/docs/Learn/CSS/Building_blocks/Cascade_and_inheritance)
- [Cascade layers](/en-US/docs/Learn/CSS/Building_blocks/Cascade_layers)
- [The future of CSS: Cascade layers](https://www.bram.us/2021/09/15/the-future-of-css-cascade-layers-css-at-layer/) on bram.us (2021)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/break-after/index.md | ---
title: break-after
slug: Web/CSS/break-after
page-type: css-property
browser-compat: css.properties.break-after
---
{{CSSRef}}
The **`break-after`** [CSS](/en-US/docs/Web/CSS) property sets how page, column, or region breaks should behave after a generated box. If there is no generated box, the property is ignored.
{{EmbedInteractiveExample("pages/css/break-after.html")}}
## Syntax
```css
/* Generic break values */
break-after: auto;
break-after: avoid;
break-after: always;
break-after: all;
/* Page break values */
break-after: avoid-page;
break-after: page;
break-after: left;
break-after: right;
break-after: recto;
break-after: verso;
/* Column break values */
break-after: avoid-column;
break-after: column;
/* Region break values */
break-after: avoid-region;
break-after: region;
/* Global values */
break-after: inherit;
break-after: initial;
break-after: revert;
break-after: revert-layer;
break-after: unset;
```
Each possible break point (in other words, each element boundary) is affected by three properties: the `break-after` value of the previous element, the {{cssxref("break-before")}} value of the next element, and the {{cssxref("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 one of the element that appears the latest in the flow is taken (i.e., the `break-before` value has precedence over the `break-after` value, which itself 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
#### Generic break values
- `auto`
- : Allows, but does not force, any break (page, column, or region) to be inserted right after the principal box.
- `avoid`
- : Avoids any break (page, column, or region) from being inserted right after the principal box.
- `always` {{experimental_inline}}
- : Forces a page break right after the principal box. The type of this break is that of the immediately-containing fragmentation context. If we are inside a multicol container then it would force a column break, inside paged media (but not inside a multicol container) a page break.
- `all` {{experimental_inline}}
- : Forces a page break right after the principal box. Breaking through all possible fragmentation contexts. So a break inside a multicol container, which was inside a page container would force a column and page break.
#### Page break values
- `avoid-page`
- : Avoids any page break right after the principal box.
- `page`
- : Forces a page break right after the principal box.
- `left`
- : Forces one or two page breaks right after the principal box, whichever will make the next page into a left page. It's the page placed on the left side of the spine of the book or the back side of the page in duplex printing.
- `right`
- : Forces one or two page breaks right after the principal box, whichever will make the next page into a right page. It's the page placed on the right side of the spine of the book or the front side of the page in duplex printing.
- `recto`
- : Forces one or two page breaks right after the principal box, whichever will make the next page into a recto page. (A recto page is a right page in a left-to-right spread or a left page in a right-to-left spread.)
- `verso`
- : Forces one or two page breaks right after the principal box, whichever will make the next page into a verso page. (A verso page is a left page in a left-to-right spread or a right page in a right-to-left spread.)
#### Column break values
- `avoid-column`
- : Avoids any column break right after the principal box.
- `column`
- : Forces a column break right after the principal box.
#### Region break values
- `avoid-region` {{experimental_inline}}
- : Avoids any region break right after the principal box.
- `region` {{experimental_inline}}
- : Forces a region break right after the principal box.
## Page break aliases
For compatibility reasons, the legacy {{cssxref("page-break-after")}} property should be treated by browsers as an alias of `break-after`. This ensures that sites using `page-break-after` continue to work as designed. A subset of values should be aliased as follows:
| page-break-after | break-after |
| ---------------- | ----------- |
| `auto` | `auto` |
| `left` | `left` |
| `right` | `right` |
| `avoid` | `avoid` |
| `always` | `page` |
> **Note:** The `always` value of `page-break-*` was implemented by browsers as a page break, and not as a column break. Therefore the aliasing is to `page`, rather than the `always` value in the Level 4 spec.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Breaking into neat columns
In the following example we have a container that contains an `<h1>` spanning all columns (achieved using `column-span: all`) and a series of `<h2>`s and paragraphs laid out in multiple columns using `column-width: 200px`.
By default, the subheadings and paragraphs were laid out rather messily because the headings were not in a uniform place. However, we used `break-after: column` on the `<p>` elements to force a column break after each one, meaning that you end up with an `<h2>` neatly at the top of each column.
#### HTML
```html
<article>
<h1>Main heading</h1>
<h2>Subheading</h2>
<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>
<h2>Subheading</h2>
<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>
<h2>Subheading</h2>
<p>
Vivamus eleifend metus vitae neque placerat, eget interdum elit mattis.
Donec eu vulputate nibh. Ut turpis leo, malesuada quis nisl nec, volutpat
egestas tellus.
</p>
<h2>Subheading</h2>
<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;
}
h1 {
font-size: 3rem;
letter-spacing: 2px;
column-span: all;
}
h2 {
font-size: 1.2rem;
color: red;
letter-spacing: 1px;
}
p {
line-height: 1.5;
break-after: column;
}
article {
column-width: 200px;
gap: 20px;
}
```
### Result
{{EmbedLiveSample('Breaking_into_neat_columns', '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/overscroll-behavior-inline/index.md | ---
title: overscroll-behavior-inline
slug: Web/CSS/overscroll-behavior-inline
page-type: css-property
browser-compat: css.properties.overscroll-behavior-inline
---
{{CSSRef}}
The **`overscroll-behavior-inline`** CSS property sets the browser's behavior when the inline direction boundary of a scrolling area is reached.
See {{cssxref("overscroll-behavior")}} for a full explanation.
## Syntax
```css
/* Keyword values */
overscroll-behavior-inline: auto; /* default */
overscroll-behavior-inline: contain;
overscroll-behavior-inline: none;
/* Global values */
overscroll-behavior-inline: inherit;
overscroll-behavior-inline: initial;
overscroll-behavior-inline: revert;
overscroll-behavior-inline: revert-layer;
overscroll-behavior-inline: unset;
```
The `overscroll-behavior-inline` property is specified as a keyword chosen from the list of values below.
### Values
- `auto`
- : The default scroll overflow behavior occurs as normal.
- `contain`
- : Default scroll overflow behavior (e.g., "bounce" effects) is observed inside the element where this value is set. However, no {{Glossary("Scroll_chaining", "scroll chaining")}} occurs on neighboring scrolling areas; the underlying elements will not scroll. The `contain` value disables native browser navigation, including the vertical pull-to-refresh gesture and horizontal swipe navigation.
- `none`
- : No scroll chaining occurs to neighboring scrolling areas, and default scroll overflow behavior is prevented.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Preventing inline overscrolling
In this demo we have two block-level boxes, one inside the other. The outer box has a large {{cssxref("width")}} set on it so the page will scroll horizontally. The inner box has a small width (and {{cssxref("height")}}) set on it so it sits comfortably inside the viewport, but its content is given a large width so it will also scroll horizontally.
By default, when the inner box is scrolled and a scroll boundary is reached, the whole page will begin to scroll, which is probably not what we want. To avoid this happening in the inline direction, we've set `overscroll-behavior-inline: contain` on the inner box.
#### HTML
```html
<main>
<div>
<div>
<p>
<code>overscroll-behavior-inline</code> has been used to make it so that
when the scroll boundaries of the yellow inner box are reached, the
whole page does not begin to scroll.
</p>
</div>
</div>
</main>
```
#### CSS
```css
main {
height: 400px;
width: 3000px;
background-color: white;
background-image: repeating-linear-gradient(
to right,
rgb(0 0 0 / 0%) 0px,
rgb(0 0 0 / 0%) 19px,
rgb(0 0 0 / 50%) 20px
);
}
main > div {
height: 300px;
width: 400px;
overflow: auto;
position: relative;
top: 50px;
left: 50px;
overscroll-behavior-inline: contain;
}
div > div {
height: 100%;
width: 1500px;
background-color: yellow;
background-image: repeating-linear-gradient(
to right,
rgb(0 0 0 / 0%) 0px,
rgb(0 0 0 / 0%) 19px,
rgb(0 0 0 / 50%) 20px
);
}
p {
padding: 10px;
background-color: rgb(255 0 0 / 50%);
margin: 0;
width: 360px;
position: relative;
top: 10px;
left: 10px;
}
```
#### Result
{{EmbedLiveSample('Preventing_inline_overscrolling','100%', 500)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Take control of your scroll: customizing pull-to-refresh and overflow effects](https://developer.chrome.com/blog/overscroll-behavior/#demo)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_first-child/index.md | ---
title: ":first-child"
slug: Web/CSS/:first-child
page-type: css-pseudo-class
browser-compat: css.selectors.first-child
---
{{CSSRef}}
The **`:first-child`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents the first element among a group of sibling elements.
{{EmbedInteractiveExample("pages/tabbed/pseudo-class-first-child.html", "tabbed-shorter")}}
## Syntax
```css
:first-child {
/* ... */
}
```
## Examples
### Basic example
#### HTML
```html
<div>
<p>This text is selected!</p>
<p>This text isn't selected.</p>
</div>
<div>
<h2>This text isn't selected: it's not a `p`.</h2>
<p>This text isn't selected.</p>
</div>
```
#### CSS
```css
p:first-child {
color: lime;
background-color: black;
padding: 5px;
}
```
#### Result
{{EmbedLiveSample('Basic_example', 500, 200)}}
### Styling a list
#### HTML
```html
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>
Item 3
<ul>
<li>Item 3.1</li>
<li>Item 3.2</li>
<li>Item 3.3</li>
</ul>
</li>
</ul>
```
#### CSS
```css
ul li {
color: blue;
}
ul li:first-child {
color: red;
font-weight: bold;
}
```
#### Result
{{EmbedLiveSample('Styling_a_list')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef(":-moz-first-node")}} {{Non-standard_Inline}}
- {{CSSxRef(":first-of-type")}}
- {{CSSxRef(":last-child")}}
- {{CSSxRef(":nth-child", ":nth-child()")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/font-variant-east-asian/index.md | ---
title: font-variant-east-asian
slug: Web/CSS/font-variant-east-asian
page-type: css-property
browser-compat: css.properties.font-variant-east-asian
---
{{CSSRef}}
The **`font-variant-east-asian`** CSS property controls the use of alternate glyphs for East Asian scripts, like Japanese and Chinese.
{{EmbedInteractiveExample("pages/css/font-variant-east-asian.html")}}
## Syntax
```css
font-variant-east-asian: normal;
font-variant-east-asian: ruby;
font-variant-east-asian: jis78; /* <east-asian-variant-values> */
font-variant-east-asian: jis83; /* <east-asian-variant-values> */
font-variant-east-asian: jis90; /* <east-asian-variant-values> */
font-variant-east-asian: jis04; /* <east-asian-variant-values> */
font-variant-east-asian: simplified; /* <east-asian-variant-values> */
font-variant-east-asian: traditional; /* <east-asian-variant-values> */
font-variant-east-asian: full-width; /* <east-asian-width-values> */
font-variant-east-asian: proportional-width; /* <east-asian-width-values> */
font-variant-east-asian: ruby full-width jis83;
/* Global values */
font-variant-east-asian: inherit;
font-variant-east-asian: initial;
font-variant-east-asian: revert;
font-variant-east-asian: revert-layer;
font-variant-east-asian: unset;
```
### Values
- `normal`
- : This keyword leads to the deactivation of the use of such alternate glyphs.
- `ruby`
- : This keyword forces the use of special glyphs for ruby characters. As these are usually smaller, font creators often designs specific forms, usually slightly bolder to improve the contrast. This keyword corresponds to the OpenType values `ruby`.
- `<east-asian-variant-values>`
- : These values specify a set of logographic glyph variants which should be used for display. Possible values are:
| Keyword | Standard defining the glyphs | OpenType equivalent |
| ------------- | --------------------------------------------------------------------------- | ------------------- |
| `jis78` | [JIS X 0208:1978](https://en.wikipedia.org/wiki/JIS_X_0208#First_standard) | `jp78` |
| `jis83` | [JIS X 0208:1983](https://en.wikipedia.org/wiki/JIS_X_0208#Second_standard) | `jp83` |
| `jis90` | [JIS X 0208:1990](https://en.wikipedia.org/wiki/JIS_X_0208#Third_standard) | `jp90` |
| `jis04` | [JIS X 0213:2004](https://en.wikipedia.org/wiki/JIS_X_0213) | `jp04` |
| `simplified` | None, use the simplified Chinese glyphs | `smpl` |
| `traditional` | None, use the traditional Chinese glyphs | `trad` |
- `<east-asian-width-values>`
- : These values control the sizing of figures used for East Asian characters. Two values are possible:
- `proportional-width` activating the set of East Asian characters which vary in width. It corresponds to the OpenType values `pwid`.
- `full-width` activating the set of East Asian characters which are all of the same, roughly square, width metric. It corresponds to the OpenType values `fwid`.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting East Asian glyph variants
This example require font "Yu Gothic" installed in your OS, other fonts may not support OpenType features.
#### HTML
```html
<table>
<thead></thead>
<tbody style="border:0;">
<tr>
<th>normal/jis78:</th>
<td>麹町</td>
<td class="jis78">麹町</td>
</tr>
<tr>
<th>normal/ruby:</th>
<td>しんかんせん</td>
<td class="ruby">しんかんせん</td>
</tr>
<tr>
<th>normal/traditional:</th>
<td>大学</td>
<td class="traditional">大学</td>
</tr>
</tbody>
</table>
```
#### CSS
```css
td {
font-family: "Yu Gothic";
font-size: 20px;
}
th {
color: grey;
padding-right: 10px;
}
.ruby {
font-variant-east-asian: ruby;
}
.jis78 {
font-variant-east-asian: jis78;
}
.traditional {
font-variant-east-asian: traditional;
}
```
#### Result
{{EmbedLiveSample('Setting_East_Asian_glyph_variants')}}
## 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-emoji`](/en-US/docs/Web/CSS/font-variant-emoji)
- [`font-variant-ligatures`](/en-US/docs/Web/CSS/font-variant-ligatures)
- [`font-variant-numeric`](/en-US/docs/Web/CSS/font-variant-numeric)
- [`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/font-size-adjust/index.md | ---
title: font-size-adjust
slug: Web/CSS/font-size-adjust
page-type: css-property
browser-compat: css.properties.font-size-adjust
---
{{CSSRef}}
The **`font-size-adjust`** [CSS](/en-US/docs/Web/CSS) property provides a way to modify the size of lowercase letters relative to the size of uppercase letters, which defines the overall {{cssxref("font-size")}}. This property is useful for situations where font fallback can occur.
Legibility can become an issue when the first-choice {{ Cssxref("font-family") }} is unavailable and its replacement fallback font has a significantly different aspect value (height of lowercase letters divided by font size). Legibility of fonts, especially at small font sizes, is determined more by the size of lowercase letters than by the size of uppercase letters. The `font-size-adjust` property is useful for adjusting the font size of fallback fonts to keep the aspect value across fonts consistent, ensuring that the text appears similar regardless of the font used.
## Syntax
```css
/* Keyword */
font-size-adjust: none;
/* One value: <number> or from-font */
font-size-adjust: 0.5;
font-size-adjust: from-font;
/* Two values */
font-size-adjust: ex-height 0.5;
font-size-adjust: ch-width from-font;
/* Global values */
font-size-adjust: inherit;
font-size-adjust: initial;
font-size-adjust: revert;
font-size-adjust: revert-layer;
font-size-adjust: unset;
```
### Values
The `font-size-adjust` property takes as its value the keyword `none`, one (`<number>` or `from-font`), or two (`<font-metric>` and either `<number>` or `from-font`) values.
- `none`
- : No adjustment is applied to the `font-size` value for the fallback font.
- `<font-metric>` {{optional_inline}}
- : Specifies the first-choice font metric to use for adjusting the font size of the fallback font. This parameter accepts one of the keywords listed below. It is an optional parameter, and `ex-height` is used if no `<font-metric>` is specified.
- `ex-height`
- : Uses the ratio of x-height (height of lowercase "x" in a font) to font size (aspect value) to adjust the fallback font size. This keyword value is used to normalize lowercase letters across fonts.
- `cap-height`
- : Uses the ratio of cap-height (height of uppercase letters) to font size to adjust fallback font size. This keyword value is used to normalize uppercase letters across fonts.
- `ch-width`
- : Uses the ratio of the advance width (horizontal space taken up by a character in a font) of the character "0" (ZERO, U+0030) to font size. This keyword value is used to normalize horizontal narrow pitch of fonts.
- `ic-width`
- : Uses the ratio of the advance width of the character "水" (CJK water ideograph, U+6C34) to font size. This keyword value is used to normalize horizontal wide pitch of fonts, particularly those that include CJK (Chinese, Japanese, Korean) characters.
- `ic-height`
- : Uses the ratio of the advance height (vertical space taken up by a character in a font) of the character "水" (CJK water ideograph, U+6C34) to font size. This keyword value is used to normalize vertical wide pitch of fonts, particularly those that include CJK characters.
- {{cssxref("<number>")}}
- : Adjusts the font size used depending on the specified `<font-metric>`. When no `<font-metric>` is specified (in which case the default value `ex-height` is used), the `<number>` value adjusts the font size of the fallback font so that its x-height is the specified multiple of the font size. This value should generally match the aspect value (ratio of x-height to font size) of the first-choice font. This means that the first-choice font, when available, will display consistently across browsers, regardless of their support for `font-size-adjust`.
When a `<font-metric>` value is specified, the `<number>` value adjusts the font size as per the chosen `<font-metric>` to maintain a consistent appearance for the specified font metric across different fonts.
The `<number>` value accepts any number from `0` to infinity. `0` yields text of zero height (that is, the text is hidden). Negative values are invalid.
- `from-font`
- : Uses the `<number>` value for the specified `<font-metric>` from the first available font.
## Description
To ensure compatibility with browsers that don't support `font-size-adjust`, this property is specified as a numeric multiplier of the {{cssxref("font-size")}} property. This number should generally match the aspect value of the first-choice font.
> **Note:** If the specified `<font-metric>` has been overridden in [`@font-face`](/en-US/docs/Web/CSS/@font-face), e.g., by using the [`size-adjust`](/en-US/docs/Web/CSS/@font-face/size-adjust) descriptor, then the overridden metric will be used in the `font-size-adjust` calculation. This means that when `font-size-adjust` and `size-adjust` are applied together, `size-adjust` does not have any effect.
The adjusted font size is calculated using the formula `u = ( m / m′ ) s`, where:
- `m` is the ratio of the specified `<font-metric>` to the first-choice font size.
- `m′` is the ratio of the corresponding `<font-metric>` to the fallback font size.
- `s` is the value of the `font-size` property.
- `u` is the new, adjusted font size for the fallback font.
Consider this example to see how the adjusted font size is calculated. A first-choice font has a `font-size` of `12px` (`s`), and the ratio of `cap-height` to font size is `0.20` (`m`). The `cap-height` to font size ratio in the fallback font is `0.15` (`m′`). The `font-size-adjust` value has been specified as `cap-height 0.20`. If the primary font is unavailable, the adjusted font size of the fallback font will be calculated to be `16px` (`(0.20 / 0.15) * 12`). This will ensure that the `cap-height` of the fallback font is similar to that of the first-choice font when displayed.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Normalizing font size by lowercase and uppercase letters
This example demonstrates how the `font-size-adjust` property can be used to retain the same aspect value across fonts. The Verdana font has a relatively high aspect value of `0.545`, which means that the lowercase letters are relatively tall compared to uppercase letters. This makes the text in small font sizes appear legible. However, the Times font has a lower aspect value of `0.447`, so the text is less legible at small sizes. If Verdana is the first-choice font and Times is the fallback font, specifying the `font-size-adjust` property can help to retain the same aspect value in Times. So if the font falls back to Times, the text will maintain a similar level of legibility as it would have with Verdana.
Similarly, the cap-height to font size ratio in Verdana is `0.73` and that in Times is `0.66`. When `font-size-adjust` property is applied to Times to adjust its uppercase letters to match the ratio in Verdana, the Times font displays in adjusted font size ((0.73 / 0.66) \* 14) `15.48px`.
```html
<p class="verdana">
A: This text uses the Verdana font (14px), which has relatively large
lowercase letters.
</p>
<p class="times">
B: This text uses the Times font (14px), which is hard to read in small sizes.
</p>
<p class="times adjtimesexheight">
C: This text in 14px Times font is adjusted to the same aspect value as the
Verdana font, so lowercase letters are normalized across the two fonts.
</p>
<p class="times adjtimescapheight">
D: This text in 14px Times font is adjusted to the same cap-height to font
size ratio as the Verdana font, so uppercase letters are normalized across the
two fonts.
</p>
```
```css
.times {
font-family: Times, serif;
font-size: 14px;
}
.verdana {
font-family: Verdana, sans-serif;
font-size: 14px;
}
.adjtimesexheight {
font-size-adjust: 0.545;
}
.adjtimescapheight {
font-size-adjust: cap-height 0.73;
}
```
{{ EmbedLiveSample('Normalizing font size by lowercase and uppercase letters', 500, 200) }}
Without `font-size-adjust` in `B`, the switch from Verdana font to Times font could result in a noticeable decrease in legibility due to its lower aspect value.
In `C`, notice that only one value is specified for the `font-size-adjust` property, so the default `<font-metric>` value `ex-height` is used. `D` shows how the font would look compared to `A` if its uppercase letter height is adjusted.
### Determining the aspect value of a font
For a given font, the same content in two side-by-side [`<span>`](/en-US/docs/Web/HTML/Element/span) elements can be used to determine the font's aspect value. If the same font size is used for content in both spans, the spans will match when the `font-size-adjust` value in one span is accurate for the given font.
In the example below, there are three pairs of side-by-side `<span>` elements, each containing the letter "b". The goal is to adjust the `font-size-adjust` property for the right `<span>` in each pair until the borders around the two letters align. The resulting `font-size-adjust` value can be considered the aspect value for the font.
Starting at `0.6` in the first pair and adjusting to `0.5` in the second, we continue adjusting the `font-size-adjust` property value until the borders around the "b" letters align perfectly in the third pair. In this example, the aspect value is determined to be `0.482`.
```html
<div>
<p><span>b</span><span class="adjust1">b</span></p>
0.6
</div>
<div>
<p><span>b</span><span class="adjust2">b</span></p>
0.5
</div>
<div>
<p><span>b</span><span class="adjust3">b</span></p>
0.482
</div>
```
```css hidden
body {
display: flex;
}
div {
text-align: center;
}
p {
margin: 0 30px 10px 30px;
}
```
```css
body {
display: flex;
}
div {
text-align: center;
}
p {
font-family: Futura;
font-size: 50px;
}
span {
border: solid 1px red;
}
.adjust1 {
font-size-adjust: 0.6;
}
.adjust2 {
font-size-adjust: 0.5;
}
.adjust3 {
font-size-adjust: 0.482;
}
```
{{ EmbedLiveSample('Determining the aspect value of a font', 500, 120) }}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("font-size")}}
- {{cssxref("font-weight")}}
- {{cssxref("@font-face/size-adjust", "size-adjust")}} `@font-face` descriptor
- [Learn: 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/inset-block-end/index.md | ---
title: inset-block-end
slug: Web/CSS/inset-block-end
page-type: css-property
browser-compat: css.properties.inset-block-end
---
{{CSSRef}}
The **`inset-block-end`** [CSS](/en-US/docs/Web/CSS) property defines the logical block end 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-end.html")}}
## Syntax
```css
/* <length> values */
inset-block-end: 3px;
inset-block-end: 2.4em;
/* <percentage>s of the width or height of the containing block */
inset-block-end: 10%;
/* Keyword value */
inset-block-end: auto;
/* Global values */
inset-block-end: inherit;
inset-block-end: initial;
inset-block-end: revert;
inset-block-end: revert-layer;
inset-block-end: unset;
```
### Values
The `inset-block-end` property takes the same values as the {{cssxref("left")}} property.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting block end 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-rl;
position: relative;
inset-block-end: 20px;
background-color: #c8c800;
}
```
#### Result
{{EmbedLiveSample("Setting_block_end_offset", 140, 140)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- The properties which defines other insets: {{cssxref("inset-block-start")}}, {{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/_colon_buffering/index.md | ---
title: ":buffering"
slug: Web/CSS/:buffering
page-type: css-pseudo-class
browser-compat: css.selectors.buffering
---
{{CSSRef}}
The **`:buffering`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) selector represents an element that is playable, such as {{htmlelement("audio")}} or {{htmlelement("video")}}, when the playable element is buffering a media resource.
An element is considered as buffering when that element cannot continue playing because it is trying to load media data but does not yet have enough data to begin or continue playback.
For more information, see the [Media buffering, seeking, and time ranges](/en-US/docs/Web/Media/Audio_and_video_delivery/buffering_seeking_time_ranges#seekable) guide.
> **Note:** An element is still considered to be {{cssxref(":playing")}} when it is "buffering".
> If `:buffering` matches an element, `:playing` will also match that element.
## Syntax
```css
:buffering {
/* ... */
}
```
## Examples
### CSS
```css
:buffering {
outline: 5px solid red;
}
video:buffering {
outline: 5px solid blue;
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref(":muted")}}
- {{cssxref(":paused")}}
- {{cssxref(":playing")}}
- {{cssxref(":seeking")}}
- {{cssxref(":stalled")}}
- {{cssxref(":volume-locked")}}
- [CSS selectors](/en-US/docs/Web/CSS/CSS_selectors)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/all/index.md | ---
title: all
slug: Web/CSS/all
page-type: css-shorthand-property
browser-compat: css.properties.all
---
{{CSSRef}}
The **`all`** [shorthand](/en-US/docs/Web/CSS/Shorthand_properties) [CSS](/en-US/docs/Web/CSS) property resets all of an element's properties except {{cssxref("unicode-bidi")}}, {{cssxref("direction")}}, and [CSS Custom Properties](/en-US/docs/Web/CSS/Using_CSS_custom_properties). It can set properties to their initial or inherited values, or to the values specified in another cascade layer or stylesheet origin.
{{EmbedInteractiveExample("pages/css/all.html")}}
## Constituent properties
This property is a shorthand for all CSS properties except for {{cssxref("unicode-bidi")}}, {{cssxref("direction")}}, and [custom properties](/en-US/docs/Web/CSS/Using_CSS_custom_properties).
## Syntax
```css
/* Global values */
all: initial;
all: inherit;
all: unset;
all: revert;
all: revert-layer;
```
The `all` property is specified as one of the CSS global keyword values. Note that none of these values affect the {{cssxref("unicode-bidi")}} and {{cssxref("direction")}} properties.
### Values
- {{cssxref("initial")}}
- : Specifies that all the element's properties should be changed to their [initial values](/en-US/docs/Web/CSS/initial_value).
- {{cssxref("inherit")}}
- : Specifies that all the element's properties should be changed to their [inherited values](/en-US/docs/Web/CSS/Inheritance).
- {{cssxref("unset")}}
- : Specifies that all the element's properties should be changed to their inherited values if they inherit by default, or to their initial values if not.
- {{cssxref("revert")}}
- : Specifies behavior that depends on the stylesheet origin to which the declaration belongs:
- If the rule belongs to the [author origin](/en-US/docs/Web/CSS/Cascade#author_stylesheets), the `revert` value rolls back the [cascade](/en-US/docs/Web/CSS/Cascade) to the user level, so that the [specified values](/en-US/docs/Web/CSS/specified_value) are calculated as if no author-level rules were specified for the element. For purposes of `revert`, the author origin includes the Override and Animation origins.
- If the rule belongs to the [user origin](/en-US/docs/Web/CSS/Cascade#user_stylesheets), the `revert` value rolls back the [cascade](/en-US/docs/Web/CSS/Cascade) to the user-agent level, so that the [specified values](/en-US/docs/Web/CSS/specified_value) are calculated as if no author-level or user-level rules were specified for the element.
- If the rule belongs to the [user-agent origin](/en-US/docs/Web/CSS/Cascade#user-agent_stylesheets), the `revert` value acts like `unset`.
- {{cssxref("revert-layer")}}
- : Specifies that all the element's properties should roll back the cascade to a previous [cascade layer](/en-US/docs/Web/CSS/@layer), if one exists. If no other cascade layer exists, the element's properties will roll back to the matching rule, if one exists, in the current layer or to a previous [style origin](/en-US/docs/Glossary/Style_origin).
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
In this example, the CSS file contains styling for the {{HTMLElement("blockquote")}} element in addition to some styling for the parent `<body>` element. Various outputs in the Results subsection demonstrate how the styling of the `<blockquote>` element is affected when different values are applied to the `all` property inside the `blockquote` rule.
### HTML
```html
<blockquote id="quote">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</blockquote>
Phasellus eget velit sagittis.
```
### CSS
```css
body {
font-size: small;
background-color: #f0f0f0;
color: blue;
margin: 0;
padding: 0;
}
blockquote {
background-color: skyblue;
color: red;
}
```
### Results
#### A. No `all` property
```html hidden
<blockquote id="quote">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</blockquote>
Phasellus eget velit sagittis.
```
```css hidden
body {
font-size: small;
background-color: #f0f0f0;
color: blue;
}
blockquote {
background-color: skyblue;
color: red;
}
```
{{EmbedLiveSample("a._no_all_property", "200", "125")}}
This is the scenario in which no `all` property is set inside the `blockquote` rule. The {{HTMLElement("blockquote")}} element uses the browser's default styling which gives it a margin, together with a specific background and text color as specified in the stylesheet. It also behaves as a _block_ element: the text that follows it is beneath it.
#### B. `all: initial`
```html hidden
<blockquote id="quote">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</blockquote>
Phasellus eget velit sagittis.
```
```css hidden
body {
font-size: small;
background-color: #f0f0f0;
color: blue;
}
blockquote {
background-color: skyblue;
color: red;
all: initial;
}
```
{{EmbedLiveSample("b._all_initial", "200", "125")}}
With the `all` property set to `initial` in the `blockquote` rule, the {{HTMLElement("blockquote")}} element doesn't use the browser default styling anymore: it is an _inline_ element now (initial value), its [`background-color`](/en-US/docs/Web/CSS/background-color#formal_definition) is `transparent` (initial value), its [`font-size`](/en-US/docs/Web/CSS/font-size#formal_definition) is `medium`, and its [`color`](/en-US/docs/Web/CSS/color#formal_definition) is `black` (initial value).
#### C. `all: inherit`
```html hidden
<blockquote id="quote">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</blockquote>
Phasellus eget velit sagittis.
```
```css hidden
body {
font-size: small;
background-color: #f0f0f0;
color: blue;
}
blockquote {
background-color: skyblue;
color: red;
all: inherit;
}
```
{{EmbedLiveSample("c._all_inherit", "200", "125")}}
In this case, the {{HTMLElement("blockquote")}} element doesn't use the browser default styling. Instead, it inherits style values from its parent {{HTMLElement("body")}} element: it is a _block_ element now (inherited value), its {{cssxref("background-color")}} is `#F0F0F0` (inherited value), its {{cssxref("font-size")}} is `small` (inherited value), and its {{cssxref("color")}} is `blue` (inherited value).
#### D. `all: unset`
```html hidden
<blockquote id="quote">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</blockquote>
Phasellus eget velit sagittis.
```
```css hidden
body {
font-size: small;
background-color: #f0f0f0;
color: blue;
}
blockquote {
background-color: skyblue;
color: red;
all: unset;
}
```
{{EmbedLiveSample("d._all_unset", "200", "125")}}
When the `unset` value is applied to the `all` property in the `blockquote` rule, the {{HTMLElement("blockquote")}} element doesn't use the browser default styling. Because [`background-color`](/en-US/docs/Web/CSS/background-color#formal_definition) is a non-inherited property and [`font-size`](/en-US/docs/Web/CSS/font-size#formal_definition) and [`color`](/en-US/docs/Web/CSS/color#formal_definition) are inherited properties, the `<blockquote>` element is an _inline_ element now (initial value), its {{cssxref("background-color")}} is `transparent` (initial value), but its {{cssxref("font-size")}} is still `small` (inherited value), and its {{cssxref("color")}} is `blue` (inherited value).
#### E. `all: revert`
```html hidden
<blockquote id="quote">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</blockquote>
Phasellus eget velit sagittis.
```
```css hidden
body {
font-size: small;
background-color: #f0f0f0;
color: blue;
}
blockquote {
background-color: skyblue;
color: red;
all: revert;
}
```
{{EmbedLiveSample("e._all_revert", "200", "125")}}
When the `all` property is set to `revert` in the `blockquote` rule, the `blockquote` rule is considered to be non-existent and the styling property values are inherited from the ones applied to the parent element `<body>`. So the `<blockquote>` element gets styled as a _block_ element, with {{cssxref("background-color")}} `#F0F0F0`, {{cssxref("font-size")}} `small`, and {{cssxref("color")}} `blue` - all values inherited from the `body` rule.
#### F. `all: revert-layer`
```html hidden
<blockquote id="quote">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</blockquote>
Phasellus eget velit sagittis.
```
```css hidden
body {
font-size: small;
background-color: #f0f0f0;
color: blue;
}
blockquote {
background-color: skyblue;
color: red;
all: revert-layer;
}
```
{{EmbedLiveSample("f._all_revert-layer", "200", "125")}}
There are no cascade layers defined in the CSS file, so the `<blockquote>` element inherits its style from the matching `body` rule. The `<blockquote>` element here is styled as a _block_ element, with {{cssxref("background-color")}} `#F0F0F0`, {{cssxref("font-size")}} `small`, and {{cssxref("color")}} `blue` - all values inherited from the `body` rule. This scenario is an example of the case when `all` set to `revert-layer` behaves the same as when `all` is set to `revert`.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
CSS global keyword values: {{cssxref("initial")}}, {{cssxref("inherit")}}, {{cssxref("unset")}}, {{cssxref("revert")}}, {{cssxref("revert-layer")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/mozilla_extensions/index.md | ---
title: Mozilla vendor-prefixed CSS extensions
slug: Web/CSS/Mozilla_Extensions
page-type: landing-page
status:
- non-standard
---
{{CSSRef}}
Firefox supports a number of _Mozilla extensions to [CSS](/en-US/docs/Web/CSS)_, including properties, values, pseudo-elements and pseudo-classes, at-rules, and media queries. These extensions are prefixed with `-moz-`.
> **Note:** These extensions are mostly experimental or deprecated but kept for backward compatibility. Avoid using them on production websites.
## Mozilla-only properties
- {{CSSxRef("box-align", "-moz-box-align")}} {{deprecated_inline}}
- {{CSSxRef("box-direction", "-moz-box-direction")}} {{deprecated_inline}}
- {{CSSxRef("box-flex", "-moz-box-flex")}} {{deprecated_inline}}
- {{CSSxRef("box-ordinal-group" ,"-moz-box-ordinal-group")}} {{deprecated_inline}}
- {{CSSxRef("box-orient", "-moz-box-orient")}} {{deprecated_inline}}
- {{CSSxRef("box-pack", "-moz-box-pack")}} {{deprecated_inline}}
- {{CSSxRef("-moz-float-edge")}} {{deprecated_inline}}
- {{CSSxRef("-moz-force-broken-image-icon")}} {{deprecated_inline}}
- {{CSSxRef("-moz-image-region")}} {{deprecated_inline}}
- {{CSSxRef("-moz-orient")}} {{non-standard_inline}}
- {{CSSxRef("font-smooth", "-moz-osx-font-smoothing")}} {{non-standard_inline}}
- {{CSSxRef("-moz-user-focus")}} {{non-standard_inline}}
- {{CSSxRef("-moz-user-input")}} {{non-standard_inline}}
- {{CSSxRef("user-modify", "-moz-user-modify")}} {{non-standard_inline}}
## Formerly proprietary properties that are now standard
> **Note:** To maximize the compatibility of your CSS, you should use the unprefixed standard properties instead of the prefixed ones listed below. Once a given property is standardized and implemented without the prefix, the prefixed version is typically dropped after a while.
### A
- {{CSSxRef("animation", "-moz-animation")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("animation-delay", "-moz-animation-delay")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("animation-direction", "-moz-animation-direction")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("animation-duration", "-moz-animation-duration")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("animation-fill-mode", "-moz-animation-fill-mode")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("animation-iteration-count", "-moz-animation-iteration-count")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("animation-name", "-moz-animation-name")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("animation-play-state", "-moz-animation-play-state")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("animation-timing-function","-moz-animation-timing-function")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("appearance","-moz-appearance")}} {{Experimental_Inline}}
### B
- {{CSSxRef("backface-visibility", "-moz-backface-visibility")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("background-clip", "-moz-background-clip")}} {{deprecated_inline}}
- {{CSSxRef("background-origin", "-moz-background-origin")}} {{deprecated_inline}}
- {{CSSxRef("box-decoration-break", "-moz-background-inline-policy")}} {{deprecated_inline}} (No longer supported; use the standard {{CSSxRef("box-decoration-break")}})
- {{CSSxRef("background-size", "-moz-background-size")}} {{deprecated_inline}}
- {{CSSxRef("border-inline-end", "-moz-border-end")}} {{Deprecated_Inline}} (No longer supported; use the standard {{CSSxRef("border-inline-end")}})
- {{CSSxRef("border-inline-color", "-moz-border-end-color")}} {{Deprecated_Inline}} (No longer supported; use the standard {{CSSxRef("border-inline-end-color")}})
- {{CSSxRef("border-inline-style", "-moz-border-end-style")}} {{Deprecated_Inline}} (No longer supported; use the standard {{CSSxRef("border-inline-end-style")}})
- {{CSSxRef("border-inline-width", "-moz-border-end-width")}} {{Deprecated_Inline}} (No longer supported; use the standard {{CSSxRef("border-inline-end-width")}})
- {{CSSxRef("border-image", "-moz-border-image")}} {{Deprecated_Inline}}
- {{CSSxRef("border-inline-start", "-moz-border-start")}} {{Deprecated_Inline}} (No longer supported; use the standard {{CSSxRef("border-inline-start")}})
- {{CSSxRef("border-inline-start-color", "-moz-border-start-color")}} {{Deprecated_Inline}} (No longer supported; use the standard {{CSSxRef("border-inline-start-color")}})
- {{CSSxRef("border-inline-start-style", "-moz-border-start-style")}} {{Deprecated_Inline}} (No longer supported; use the standard {{CSSxRef("border-inline-start-style")}})
- {{CSSxRef("border-inline-start-width", "-moz-border-start-width")}} {{Deprecated_Inline}} (No longer supported; use the standard {{CSSxRef("border-inline-start-width")}})
- {{CSSxRef("box-sizing", "-moz-box-sizing")}} {{Deprecated_Inline}} (Prefixed version still supported)
### C
- {{CSSxRef("clip-path")}} {{Experimental_Inline}} (Applying to more than SVG)
- {{CSSxRef("column-count", "-moz-column-count")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("column-fill", "-moz-column-fill")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("column-gap", "-moz-column-gap")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("column-width", "-moz-column-width")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("column-rule", "-moz-column-rule")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("column-rule-width", "-moz-column-rule-width")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("column-rule-style", "-moz-column-rule-style")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("column-rule-color", "-moz-column-rule-color")}} {{Deprecated_Inline}} (Prefixed version still supported)
### F–M
- {{CSSxRef("filter")}} {{Experimental_Inline}} (Applying to more than SVG)
- {{CSSxRef("font-feature-settings", "-moz-font-feature-settings")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("font-language-override", "-moz-font-language-override")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("hyphens", "-moz-hyphens")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("margin-inline-end", "-moz-margin-end")}} {{Deprecated_Inline}} (No longer supported; use the standard {{CSSxRef("margin-inline-end")}})
- {{CSSxRef("margin-inline-start", "-moz-margin-start")}} {{Deprecated_Inline}} (No longer supported; use the standard {{CSSxRef("margin-inline-start")}})
- {{CSSxRef("mask")}} {{Experimental_Inline}} (Applying to more than SVG)
### O
- {{CSSxRef("opacity", "-moz-opacity")}} {{deprecated_inline}}
- {{CSSxRef("outline", "-moz-outline")}} {{deprecated_inline}}
- {{CSSxRef("outline-color", "-moz-outline-color")}} {{deprecated_inline}}
- {{CSSxRef("outline-offset", "-moz-outline-offset")}} {{deprecated_inline}}
- {{CSSxRef("outline-style", "-moz-outline-style")}} {{deprecated_inline}}
- {{CSSxRef("outline-width", "-moz-outline-width")}} {{deprecated_inline}}
### P
- {{CSSxRef("padding-inline-end", "-moz-padding-end")}} {{Deprecated_Inline}} (No longer supported; use the standard {{CSSxRef("padding-inline-end")}})
- {{CSSxRef("padding-inline-start", "-moz-padding-start")}} {{Deprecated_Inline}} (No longer supported; use the standard {{CSSxRef("padding-inline-start")}})
- {{CSSxRef("perspective", "-moz-perspective")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("perspective-origin", "-moz-perspective-origin")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("pointer-events")}} {{Experimental_Inline}} (Applying to more than SVG)
### T–U
- {{CSSxRef("tab-size", "-moz-tab-size")}} {{Experimental_Inline}}
- {{CSSxRef("text-align-last", "-moz-text-align-last")}} {{deprecated_inline}}
- {{CSSxRef("text-decoration-color", "-moz-text-decoration-color")}} {{deprecated_inline}}
- {{CSSxRef("text-decoration-line", "-moz-text-decoration-line")}} {{deprecated_inline}}
- {{CSSxRef("text-decoration-style", "-moz-text-decoration-style")}} {{deprecated_inline}}
- {{CSSxRef("text-size-adjust", "-moz-text-size-adjust")}} {{Experimental_Inline}}
- {{CSSxRef("transform", "-moz-transform")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("transform-origin", "-moz-transform-origin")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("transform-style", "-moz-transform-style")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("transition", "-moz-transition")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("transition-delay", "-moz-transition-delay")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("transition-duration", "-moz-transition-duration")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("transition-property", "-moz-transition-property")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("transition-timing-function", "-moz-transition-timing-function")}} {{Deprecated_Inline}} (Prefixed version still supported)
- {{CSSxRef("user-select", "-moz-user-select")}} {{Experimental_Inline}}
## Values
### Global values
- {{CSSxRef("initial", "-moz-initial")}}
### -moz-appearance
Property: {{CSSxRef("appearance", "-moz-appearance")}}
- `button`
- `button-arrow-down`
- `button-arrow-next`
- `button-arrow-previous`
- `button-arrow-up`
- `button-bevel`
- `checkbox`
- `checkbox-container`
- `checkbox-label`
- `checkmenuitem`
- `dialog`
- `groupbox`
- `listbox`
- `menuarrow`
- `menucheckbox`
- `menuimage`
- `menuitem`
- `menuitemtext`
- `menulist`
- `menulist-button`
- `menulist-text`
- `menulist-textfield`
- `menupopup`
- `menuradio`
- `menuseparator`
- `-moz-mac-unified-toolbar`
- `-moz-win-borderless-glass`
- `-moz-win-browsertabbar-toolbox`
- `-moz-win-communications-toolbox`
- `-moz-win-glass`
- `-moz-win-media-toolbox`
- `-moz-window-button-box`
- `-moz-window-button-box-maximized`
- `-moz-window-button-close`
- `-moz-window-button-maximize`
- `-moz-window-button-minimize`
- `-moz-window-button-restore`
- `-moz-window-titlebar`
- `-moz-window-titlebar-maximized`
- `progressbar`
- `progresschunk`
- `radio`
- `radio-container`
- `radio-label`
- `radiomenuitem`
- `resizer`
- `resizerpanel`
- `scale-horizontal`
- `scalethumb-horizontal`
- `scalethumb-vertical`
- `scale-vertical`
- `scrollbarbutton-down`
- `scrollbarbutton-left`
- `scrollbarbutton-right`
- `scrollbarbutton-up`
- `scrollbar-small`
- `scrollbarthumb-horizontal`
- `scrollbarthumb-vertical`
- `scrollbartrack-horizontal`
- `scrollbartrack-vertical`
- `separator`
- `spinner`
- `spinner-downbutton`
- `spinner-textfield`
- `spinner-upbutton`
- `statusbar`
- `statusbarpanel`
- `tab`
- `tabpanels`
- `tab-scroll-arrow-back`
- `tab-scroll-arrow-forward`
- `textfield`
- `textfield-multiline`
- `toolbar`
- `toolbarbutton-dropdown`
- `toolbox`
- `tooltip`
- `treeheadercell`
- `treeheadersortarrow`
- `treeitem`
- `treetwisty`
- `treetwistyopen`
- `treeview`
- `window`
### background-image
Property: {{CSSxRef("background-image")}}
#### Gradients
- {{CSSxRef("gradient/linear-gradient","-moz-linear-gradient")}} {{Deprecated_Inline}}
- {{CSSxRef("gradient/radial-gradient","-moz-radial-gradient")}} {{Deprecated_Inline}}
#### Elements
- {{CSSxRef("element","-moz-element")}}
#### Sub-images
- {{CSSxRef("-moz-image-rect")}}
### border-color
Property: {{CSSxRef("border-color")}}
- `-moz-use-text-color` {{deprecated_inline}} (removed in [Firefox bug 1306214](https://bugzil.la/1306214)); use {{CSSxRef("color_value#currentcolor_keyword","currentcolor")}} instead.
### order-style and outline-style
Properties: {{CSSxRef("border-style")}} and {{CSSxRef("outline-style")}}
- `-moz-bg-inset` {{deprecated_inline}}
- `-moz-bg-outset` {{deprecated_inline}}
- `-moz-bg-solid` {{deprecated_inline}}
### <color> keywords
Type: {{CSSxRef("<color>")}}
- `-moz-activehyperlinktext`
- `-moz-hyperlinktext`
- `-moz-visitedhyperlinktext`
- `-moz-buttondefault`
- `-moz-buttonhoverface`
- `-moz-buttonhovertext`
- `-moz-default-background-color`
- `-moz-default-color`
- `-moz-cellhighlight`
- `-moz-cellhighlighttext`
- `-moz-field`
- `-moz-fieldtext`
- `-moz-dialog`
- `-moz-dialogtext`
- `-moz-dragtargetzone`
- `-moz-mac-accentdarkestshadow`
- `-moz-mac-accentdarkshadow`
- `-moz-mac-accentface`
- `-moz-mac-accentlightesthighlight`
- `-moz-mac-accentlightshadow`
- `-moz-mac-accentregularhighlight`
- `-moz-mac-accentregularshadow`
- `-moz-mac-chrome-active`
- `-moz-mac-chrome-inactive`
- `-moz-mac-focusring`
- `-moz-mac-menuselect`
- `-moz-mac-menushadow`
- `-moz-mac-menutextselect`
- `-moz-menuhover`
- `-moz-menuhovertext`
- `-moz-win-communicationstext`
- `-moz-win-mediatext`
- `-moz-nativehyperlinktext`
### display
Property: {{CSSxRef("display")}}
- `-moz-box` {{deprecated_inline}}
- `-moz-inline-block` {{deprecated_inline}}
- `-moz-inline-box` {{Deprecated_Inline}}
- `-moz-inline-grid` {{deprecated_inline}}
- `-moz-inline-stack` {{deprecated_inline}}
- `-moz-inline-table` {{deprecated_inline}}
- `-moz-grid` {{deprecated_inline}}
- `-moz-grid-group` {{deprecated_inline}}
- `-moz-grid-line` {{deprecated_inline}}
- `-moz-groupbox` {{deprecated_inline}}
- `-moz-deck` {{deprecated_inline}}
- `-moz-popup` {{deprecated_inline}}
- `-moz-stack` {{deprecated_inline}}
- `-moz-marker` {{deprecated_inline}}
### empty-cells
Property: {{CSSxRef("empty-cells")}}
- `-moz-show-background` (default value in quirks mode)
### font
Property: {{CSSxRef("font")}}
- `-moz-button`
- `-moz-info`
- `-moz-desktop`
- `-moz-dialog` (also a color)
- `-moz-document`
- `-moz-workspace`
- `-moz-window`
- `-moz-list`
- `-moz-pull-down-menu`
- `-moz-field` (also a color)
### font-family
Property: {{CSSxRef("font-family")}}
- `-moz-fixed`
### image-rendering
Property: {{CSSxRef("image-rendering")}}
- {{CSSxRef("image-rendering","-moz-crisp-edges")}}
### <length>
Type: {{CSSxRef("<length>")}}
- {{CSSxRef("calc", "-moz-calc")}}
### list-style-type
Property: {{CSSxRef("list-style-type")}}
- `-moz-arabic-indic`
- `-moz-bengali`
- `-moz-cjk-earthly-branch`
- `-moz-cjk-heavenly-stem`
- `-moz-devanagari`
- `-moz-ethiopic-halehame`
- `-moz-ethiopic-halehame-am`
- `-moz-ethiopic-halehame-ti-er`
- `-moz-ethiopic-halehame-ti-et`
- `-moz-ethiopic-numeric`
- `-moz-gujarati`
- `-moz-gurmukhi`
- `-moz-hangul`
- `-moz-hangul-consonant`
- `-moz-japanese-formal`
- `-moz-japanese-informal`
- `-moz-kannada`
- `-moz-khmer`
- `-moz-lao`
- `-moz-malayalam`
- `-moz-myanmar`
- `-moz-oriya`
- `-moz-persian`
- `-moz-simp-chinese-formal`
- `-moz-simp-chinese-informal`
- `-moz-tamil`
- `-moz-telugu`
- `-moz-thai`
- `-moz-trad-chinese-formal`
- `-moz-trad-chinese-informal`
- `-moz-urdu`
### text-align
Property: {{CSSxRef("text-align")}}
- `-moz-center`
- `-moz-left`
- `-moz-right`
### text-decoration
Property: {{CSSxRef("text-decoration")}}
- `-moz-anchor-decoration`
### -moz-user-select
Property: {{CSSxRef("user-select", "-moz-user-select")}}
- `-moz-all`
- `-moz-none`
### width, min-width, and max-width
Properties: {{CSSxRef("width")}}, {{CSSxRef("min-width")}}, and {{CSSxRef("max-width")}}
- `-moz-min-content`
- `-moz-fit-content`
- `-moz-max-content`
- `-moz-available`
## Pseudo-elements and pseudo-classes
### A – D
- {{CSSxRef("::-moz-anonymous-block")}}
- {{CSSxRef("::-moz-anonymous-positioned-block")}}
- {{CSSxRef(":is", ":-moz-any")}}
- {{CSSxRef(":any-link", ":-moz-any-link")}} \[Matches `:link` and `:visited`]
- {{CSSxRef(":-moz-broken")}}
- {{CSSxRef("::-moz-canvas")}}
- {{CSSxRef("::-moz-color-swatch")}}
- {{CSSxRef("::-moz-cell-content")}}
- {{CSSxRef(":-moz-drag-over")}}
### F – I
- {{CSSxRef(":-moz-first-node")}}
- {{CSSxRef("::-moz-focus-inner")}}
- {{CSSxRef("::-moz-focus-outer")}}
- {{CSSxRef(":fullscreen", ":-moz-full-screen")}}
- {{CSSxRef(":-moz-full-screen-ancestor")}}
- {{CSSxRef(":-moz-handler-blocked")}}
- {{CSSxRef(":-moz-handler-crashed")}}
- {{CSSxRef(":-moz-handler-disabled")}}
- {{CSSxRef("::-moz-inline-table")}}
### L
- {{CSSxRef(":-moz-last-node")}}
- {{CSSxRef("::-moz-list-bullet")}}
- {{CSSxRef("::-moz-list-number")}}
- {{CSSxRef(":-moz-loading")}}
- {{CSSxRef(":dir_ltr", ":-moz-locale-dir(ltr)")}}
- {{CSSxRef(":dir_rtl", ":-moz-locale-dir(rtl)")}}
- {{CSSxRef(":-moz-lwtheme")}}
- {{CSSxRef(":-moz-lwtheme-brighttext")}}
- {{CSSxRef(":-moz-lwtheme-darktext")}}
### N – R
- {{CSSxRef(":-moz-native-anonymous")}}
- {{CSSxRef(":-moz-only-whitespace")}}
- {{CSSxRef("::-moz-page")}}
- {{CSSxRef("::-moz-page-sequence")}}
- {{CSSxRef("::-moz-pagebreak")}}
- {{CSSxRef("::-moz-pagecontent")}}
- {{CSSxRef(":placeholder-shown", ":-moz-placeholder")}} {{deprecated_inline}}
- {{CSSxRef("::placeholder", "::-moz-placeholder")}} {{deprecated_inline}}
- {{CSSxRef("::-moz-progress-bar")}}
- {{CSSxRef("::-moz-range-progress")}}
- {{CSSxRef("::-moz-range-thumb")}}
- {{CSSxRef("::-moz-range-track")}}
- {{CSSxRef(":-moz-read-only")}}
- {{CSSxRef(":-moz-read-write")}}
### S
- {{CSSxRef("::-moz-scrolled-canvas")}}
- {{CSSxRef("::-moz-scrolled-content")}}
- {{CSSxRef("::-moz-scrolled-page-sequence")}}
- {{CSSxRef("::selection","::-moz-selection")}} {{deprecated_inline}}
- {{CSSxRef(":-moz-submit-invalid")}}
- {{CSSxRef(":-moz-suppressed")}}
- {{CSSxRef("::-moz-svg-foreign-content")}}
### T
- {{CSSxRef("::-moz-table")}}
- {{CSSxRef("::-moz-table-cell")}}
- {{CSSxRef("::-moz-table-column")}}
- {{CSSxRef("::-moz-table-column-group")}}
- {{CSSxRef("::-moz-table-outer")}}
- {{CSSxRef("::-moz-table-row")}}
- {{CSSxRef("::-moz-table-row-group")}}
### U – X
- {{CSSxRef(":user-invalid", ":-moz-ui-invalid")}} {{deprecated_inline}}
- {{CSSxRef(":user-valid", ":-moz-ui-valid")}} {{deprecated_inline}}
- {{CSSxRef(":-moz-user-disabled")}}
- {{CSSxRef("::-moz-viewport")}}
- {{CSSxRef("::-moz-viewport-scroll")}}
- {{CSSxRef(":-moz-window-inactive")}}
## At-rules
- {{CSSxRef("@document", "@-moz-document")}}
## Media features
- {{CSSxRef("@media/-moz-device-pixel-ratio", "-moz-device-pixel-ratio")}} {{deprecated_inline}}
- {{CSSxRef("@media/-moz-os-version", "-moz-os-version")}}
- {{CSSxRef("@media/-moz-touch-enabled", "-moz-touch-enabled")}}
- {{CSSxRef("@media/-moz-windows-glass", "-moz-windows-glass")}}
## Other
- {{CSSxRef("-moz-alt-content")}} (see [Firefox bug 11011](https://bugzil.la/11011))
## See also
- [Vendor Prefix](/en-US/docs/Glossary/Vendor_Prefix) glossary entry
- [WebKit vendor-prefixed CSS extensions](/en-US/docs/Web/CSS/WebKit_Extensions)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/scroll-margin-block-start/index.md | ---
title: scroll-margin-block-start
slug: Web/CSS/scroll-margin-block-start
page-type: css-property
browser-compat: css.properties.scroll-margin-block-start
---
{{CSSRef}}
The `scroll-margin-block-start` property defines the margin of the scroll snap area at the start of the block dimension that is used for snapping this box to the snapport. The scroll snap area is determined by taking the transformed border box, finding its rectangular bounding box (axis-aligned in the scroll container's coordinate space), then adding the specified outsets.
{{EmbedInteractiveExample("pages/css/scroll-margin-block-start.html")}}
## Syntax
```css
/* <length> values */
scroll-margin-block-start: 10px;
scroll-margin-block-start: 1em;
/* Global values */
scroll-margin-block-start: inherit;
scroll-margin-block-start: initial;
scroll-margin-block-start: revert;
scroll-margin-block-start: revert-layer;
scroll-margin-block-start: unset;
```
### Values
- {{CSSXref("<length>")}}
- : An outset from the block start edge of the scroll container.
## 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/will-change/index.md | ---
title: will-change
slug: Web/CSS/will-change
page-type: css-property
browser-compat: css.properties.will-change
---
{{CSSRef}}
The **`will-change`** [CSS](/en-US/docs/Web/CSS) property hints to browsers how an element is expected to change. Browsers may set up optimizations before an element is actually changed. These kinds of optimizations can increase the responsiveness of a page by doing potentially expensive work before they are actually required.
> **Warning:** `will-change` is intended to be used as a last resort, in order to try to deal with existing performance problems. It should not be used to anticipate performance problems.
Proper usage of this property can be a bit tricky:
- _Don't apply will-change to too many elements._ The browser already tries as hard as it can to optimize everything. Some of the stronger optimizations that are likely to be tied to `will-change` end up using a lot of a machine's resources, and when overused like this can cause the page to slow down or consume a lot of resources.
- _Use sparingly._ The normal behavior for optimizations that the browser make is to remove the optimizations as soon as it can and revert back to normal. But adding `will-change` directly in a stylesheet implies that the targeted elements are always a few moments away from changing and the browser will keep the optimizations for much longer time than it would have otherwise. So it is a good practice to switch `will-change` on and off using script code before and after the change occurs.
- _Don't apply will-change to elements to perform premature optimization_. If your page is performing well, don't add the `will-change` property to elements just to wring out a little more speed. `will-change` is intended to be used as something of a last resort, in order to try to deal with existing performance problems. It should not be used to anticipate performance problems. Excessive use of `will-change` will result in excessive memory use and will cause more complex rendering to occur as the browser attempts to prepare for the possible change. This will lead to worse performance.
- _Give it sufficient time to work_. This property is intended as a method for authors to let the user-agent know about properties that are likely to change ahead of time. Then the browser can choose to apply any ahead-of-time optimizations required for the property change before the property change actually happens. So it is important to give the browser some time to actually do the optimizations. Find some way to predict at least slightly ahead of time that something will change, and set `will-change` then.
- _Be aware, that will-change may actually influence the visual appearance of elements_, when used with property values, that create a [stacking context](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context) (e.g. will-change: opacity), as the stacking context is created up front.
## Syntax
```css
/* Keyword values */
will-change: auto;
will-change: scroll-position;
will-change: contents;
will-change: transform; /* Example of <custom-ident> */
will-change: opacity; /* Example of <custom-ident> */
will-change: left, top; /* Example of two <animatable-feature> */
/* Global values */
will-change: inherit;
will-change: initial;
will-change: revert;
will-change: revert-layer;
will-change: unset;
```
### Values
- `auto`
- : This keyword expresses no particular intent; the user agent should apply whatever heuristics and optimizations it normally does.
The `<animatable-feature>` can be one of the following values:
- `scroll-position`
- : Indicates that the author expects to animate or change the scroll position of the element in the near future.
- `contents`
- : Indicates that the author expects to animate or change something about the element's contents in the near future.
- {{cssxref("custom-ident", "<custom-ident>")}}
- : Indicates that the author expects to animate or change the property with the given name on the element in the near future. If the property given is a shorthand, it indicates the expectation for all the longhands the shorthand expands to. It cannot be one of the following values: `unset`, `initial`, `inherit`, `will-change`, `auto`, `scroll-position`, or `contents`. The spec doesn't define the behavior of particular value, but it is common for `transform` to be a compositing layer hint. [Chrome currently takes two actions](https://github.com/operasoftware/devopera/pull/330), given particular CSS property idents: establish a new compositing layer or a new {{Glossary("stacking context")}}.
### Via stylesheet
It may be appropriate to include `will-change` in your style sheet for an application that does page flips on key presses like an album or a slide deck presentation where the pages are large and complex. This will let browser prepare the transition ahead of time and allow for snappy transitions between the pages as soon as the key is pressed. But use caution with the `will-change` property directly in stylesheets. It may cause the browser to keep the optimization in memory for much longer than it is needed.
```css
.slide {
will-change: transform;
}
```
## Formal definition
{{CSSInfo}}
## Formal syntax
{{CSSSyntax}}
## Examples
### Via script
This is an example showing how to apply the `will-change` property through scripting, which is probably what you should be doing in most cases.
```js
const el = document.getElementById("element");
// Set will-change when the element is hovered
el.addEventListener("mouseenter", hintBrowser);
el.addEventListener("animationEnd", removeHint);
function hintBrowser() {
// The optimizable properties that are going to change
// in the animation's keyframes block
this.style.willChange = "transform, opacity";
}
function removeHint() {
this.style.willChange = "auto";
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("transform")}}
- Individual transform properties:
- {{cssxref("translate")}}
- {{cssxref("scale")}}
- {{cssxref("rotate")}}
- Note: there is no individual `skew` property
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/var/index.md | ---
title: var()
slug: Web/CSS/var
page-type: css-function
browser-compat: css.properties.custom-property.var
---
{{CSSRef}}
The **`var()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) can be used to insert the value of a [custom property](/en-US/docs/Web/CSS/--*) (sometimes called a "CSS variable") instead of any part of a value of another property.
{{EmbedInteractiveExample("pages/css/var.html")}}
The `var()` function cannot be used in property names, selectors or anything else besides property values. (Doing so usually produces invalid syntax, or else a value whose meaning has no connection to the variable.)
## Syntax
```css
/* Simple usage */
var(--custom-prop);
/* With fallback */
var(--custom-prop,); /* empty value as fallback */
var(--custom-prop, initial); /* initial value of the property as fallback */
var(--custom-prop, #FF0000);
var(--custom-prop, var(--default-value));
var(--custom-prop, var(--default-value, red));
```
The first argument to the function is the name of the custom property to be substituted. An optional second argument to the function serves as a fallback value. If the custom property referenced by the first argument is invalid, the function uses the second value.
The syntax of the fallback, like that of custom properties, allows commas. For example, `var(--foo, red, blue)` defines a fallback of `red, blue`; that is, anything between the first comma and the end of the function is considered a fallback value.
### Values
- `<custom-property-name>`
- : A custom property's name represented by an identifier that starts with two dashes. Custom properties are solely for use by authors and users; CSS will never give them a meaning beyond what is presented here.
- `<declaration-value>`
- : The custom property's fallback value, which is used in case the custom property is invalid in the used context. This value may contain any character except some characters with special meaning like newlines, unmatched closing brackets, i.e. `)`, `]`, or `}`, top-level semicolons, or exclamation marks. The fallback value can itself be a custom property using the `var()` syntax.
> **Note:** `var(--a,)` is valid, specifying that if the `--a` custom property is invalid or missing, the `var()` should be replaced with nothing.
### Formal syntax
{{CSSSyntax}}
## Examples
### Using a custom property set on :root
#### CSS
```css
:root {
--main-bg-color: pink;
}
body {
background-color: var(--main-bg-color);
}
```
#### Result
{{EmbedLiveSample("Using a custom property set on :root")}}
Here, the value of the `background-color` property has been set via the custom property `--main-bg-color`. So the background color of the HTML body will be pink.
### Using a custom property before it is set
#### CSS
```css
body {
background-color: var(--main-bg-color);
}
:root {
--main-bg-color: pink;
}
```
#### Result
{{EmbedLiveSample("Using a custom property before it is set")}}
In this example, the background color of the HTML body will be pink even though the custom property is set later.
### Using a custom property set in another file
#### HTML
```html
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="1.css" />
<link rel="stylesheet" href="2.css" />
</head>
<body></body>
</html>
```
#### CSS
```css
/* 1.css */
body {
background-color: var(--main-bg-color);
}
```
```css
/* 2.css */
:root {
--main-bg-color: pink;
}
```
#### Result
{{EmbedLiveSample("Using a custom property set in another file")}}
The background color of the HTML body will be pink in this case even though the custom property is declared in another file.
### Custom properties with fallbacks for use when the property has not been set
#### HTML
```html
<div class="component">
<h1 class="header">Header</h1>
<p class="text">Text</p>
</div>
```
#### CSS
```css
/* In the component's style: */
.component .header {
/* header-color isn't set, and so remains blue, the fallback value */
color: var(--header-color, blue);
}
.component .text {
color: var(--text-color, black);
}
/* In the larger application's style: */
.component {
--text-color: #080;
}
```
#### Result
{{EmbedLiveSample("Custom properties with fallbacks for use when the property has not been set")}}
Since `--header-color` isn't set, the text "Header" will be blue, the fallback value.
### Using a custom property as a fallback
#### CSS
```css
:root {
--backup-bg-color: teal;
}
body {
background-color: var(--main-bg-color, var(--backup-bg-color, white));
}
```
#### Result
{{EmbedLiveSample("Using a custom property as a fallback")}}
Since `--main-bg-color` isn't set, the body's `background-color` will fall back to `--backup-bg-color`, which is teal.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("env","env(…)")}} – read‑only environment variables controlled by the user‑agent.
- [Using CSS custom properties (variables)](/en-US/docs/Web/CSS/Using_CSS_custom_properties)
- {{cssxref("@property")}} at-rule
- [CSS custom properties for cascading variables](/en-US/docs/Web/CSS/CSS_cascading_variables) module
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/overflow-clip-margin/index.md | ---
title: overflow-clip-margin
slug: Web/CSS/overflow-clip-margin
page-type: css-property
browser-compat: css.properties.overflow-clip-margin
---
{{CSSRef}}
The **`overflow-clip-margin`** [CSS](/en-US/docs/Web/CSS) property determines how far outside its bounds an element with [`overflow: clip`](/en-US/docs/Web/CSS/overflow) may be painted before being clipped. The bound defined by this property is called the _overflow clip edge_ of the box.
## Syntax
```css
/* <length> values */
overflow-clip-margin: 20px;
overflow-clip-margin: 1em;
/* <visual-box> | <length> */
overflow-clip-margin: content-box 5px;
/* Global values */
overflow-clip-margin: inherit;
overflow-clip-margin: initial;
overflow-clip-margin: revert;
overflow-clip-margin: revert-layer;
overflow-clip-margin: unset;
```
The `<visual-box>` value, which defaults to `padding-box`, specifies the box edge to use as the overflow clip edge origin. The {{cssxref("<length>")}} value specified in `overflow-clip-margin` must be nonnegative.
> **Note:** If the element does not have `overflow: clip` then this property will be ignored.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### HTML
```html
<div class="box">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur.
</div>
```
### CSS
```css
.box {
border: 3px solid black;
width: 250px;
height: 100px;
overflow: clip;
overflow-clip-margin: 20px;
}
```
### Result
{{EmbedLiveSample("Examples", "100%", "280")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- Related CSS properties: {{cssxref("text-overflow")}}, {{cssxref("white-space")}}, {{Cssxref("overflow")}}, {{Cssxref("overflow-inline")}}, {{Cssxref("overflow-x")}}, {{Cssxref("overflow-y")}}, {{Cssxref("clip")}}, {{Cssxref("display")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/border-left-style/index.md | ---
title: border-left-style
slug: Web/CSS/border-left-style
page-type: css-property
browser-compat: css.properties.border-left-style
---
{{CSSRef}}
The **`border-left-style`** [CSS](/en-US/docs/Web/CSS) property sets the line style of an element's left {{cssxref("border")}}.
{{EmbedInteractiveExample("pages/css/border-left-style.html")}}
> **Note:** The specification doesn't define how borders of different styles connect in the corners.
## Syntax
```css
/* Keyword values */
border-left-style: none;
border-left-style: hidden;
border-left-style: dotted;
border-left-style: dashed;
border-left-style: solid;
border-left-style: double;
border-left-style: groove;
border-left-style: ridge;
border-left-style: inset;
border-left-style: outset;
/* Global values */
border-left-style: inherit;
border-left-style: initial;
border-left-style: revert;
border-left-style: revert-layer;
border-left-style: unset;
```
The `border-left-style` property is specified as a single {{cssxref("line-style")}} keyword value.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting border-left-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-left-style example classes */
.b1 {
border-left-style: none;
}
.b2 {
border-left-style: hidden;
}
.b3 {
border-left-style: dotted;
}
.b4 {
border-left-style: dashed;
}
.b5 {
border-left-style: solid;
}
.b6 {
border-left-style: double;
}
.b7 {
border-left-style: groove;
}
.b8 {
border-left-style: ridge;
}
.b9 {
border-left-style: inset;
}
.b10 {
border-left-style: outset;
}
```
#### Result
{{ EmbedLiveSample('Examples', 300, 200) }}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- The other style-related border properties: {{Cssxref("border-bottom-style")}}, {{Cssxref("border-right-style")}}, {{Cssxref("border-top-style")}}, and {{Cssxref("border-style")}}.
- The other left-border-related properties: {{Cssxref("border-left")}}, {{Cssxref("border-left-color")}}, and {{Cssxref("border-left-width")}}.
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/-moz-user-focus/index.md | ---
title: "-moz-user-focus"
slug: Web/CSS/-moz-user-focus
page-type: css-property
status:
- deprecated
- non-standard
browser-compat: css.properties.-moz-user-focus
---
{{CSSRef}} {{deprecated_header}}{{non-standard_header}}
The **`-moz-user-focus`** [CSS](/en-US/docs/Web/CSS) property is used to indicate whether an element can have the focus.
By setting its value to `ignore`, you can disable focusing the element, which means that the user will not be able to activate the element, and the element will be skipped in the tab sequence.
The default is `none`, which disables focussing on the element and removes focus on other elements if there is an attempt to select the element.
## Syntax
```css
/* Keyword values */
-moz-user-focus: none;
-moz-user-focus: normal;
-moz-user-focus: ignore;
/* Global values */
-moz-user-focus: inherit;
-moz-user-focus: initial;
-moz-user-focus: unset;
```
### Values
- `ignore`
- : The element does not accept keyboard focus and will be skipped in the tab order.
- `normal`
- : The element can accept keyboard focus.
- `none`
- : The element does not accept keyboard focus.
Attempting to select the element removes focus from any other element.
## Formal definition
{{CSSInfo}}
## Formal syntax
```plain
-moz-user-focus =
ignore | normal | none
```
## Examples
### HTML
```html
<input class="ignored" value="The user cannot focus on this element." />
```
### CSS
```css
.ignored {
-moz-user-focus: ignore;
}
```
## Specifications
Not part of any standard.
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("-moz-user-input")}}
- {{cssxref("user-modify")}}
- {{cssxref("user-select", "-moz-user-select")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/hyphenate-character/index.md | ---
title: hyphenate-character
slug: Web/CSS/hyphenate-character
page-type: css-property
browser-compat: css.properties.hyphenate-character
---
{{CSSRef}}
The **`hyphenate-character`** [CSS](/en-US/docs/Web/CSS) property sets the character (or string) used at the end of a line before a hyphenation break.
Both automatic and soft hyphens are displayed according to the specified hyphenate-character value.
{{EmbedInteractiveExample("pages/css/hyphenate-character.html")}}
## Syntax
```css
hyphenate-character: <string>;
hyphenate-character: auto;
```
The value either sets the string to use instead of a hyphen, or indicates that the user agent should select an appropriate string based on the current typographic conventions (default).
### Values
- `<string>`
- : The {{cssxref("<string>")}} to use at the end of the line before a hyphenation break.
The user agent may truncate this value if too many characters are used.
- `auto`
- : The user-agent selects an appropriate string based on the content language's typographic conventions.
This is the default property value, and only needs to be explicitly set in order to override a different inherited value.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
This example shows two identical blocks of text that have {{cssxref("hyphens")}} set to ensure that they break wherever needed, and on soft hyphen breaks (created using `­`).
The first block has the value of the hyphen changed to the equals symbol ("`=`").
The second block has no hyphenate-character set, which is equivalent to `hyphenate-character: auto` for user agents that support this property.
### HTML
```html
<dl>
<dt><code>hyphenate-character: "="</code></dt>
<dd id="string" lang="en">Superc­alifragilisticexpialidocious</dd>
<dt><code>hyphenate-character is not set</code></dt>
<dd lang="en">Superc­alifragilisticexpialidocious</dd>
</dl>
```
### CSS
```css
dd {
width: 90px;
border: 1px solid black;
hyphens: auto;
}
dd#string {
-webkit-hyphenate-character: "=";
hyphenate-character: "=";
}
```
### Result
{{EmbedLiveSample("Examples", "100%", 350)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- Related CSS properties: {{cssxref("hyphens")}}, {{cssxref("overflow-wrap")}}.
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/css_scroll-driven_animations/index.md | ---
title: CSS scroll-driven animations
slug: Web/CSS/CSS_scroll-driven_animations
page-type: css-module
spec-urls:
- https://drafts.csswg.org/scroll-animations-1/
- https://drafts.csswg.org/css-animations-2/
- https://drafts.csswg.org/web-animations-2/
---
{{CSSRef}}
The **CSS scroll-driven animations** module provides functionality that builds on top of the [CSS animations module](/en-US/docs/Web/CSS/CSS_animations) and [Web Animations API](/en-US/docs/Web/API/Web_Animations_API). It allows you to animate property values based on a progression along a scroll-based timeline instead of the default time-based document timeline. This means that you can animate an element by scrolling a scrollable element, rather than just by the passing of time.
There are two types of scroll-based timelines:
- _scroll progress timeline_: You progress this timeline by scrolling a scrollable element (_scroller_) from top to bottom (or left to right) and back again. The position in the scroll range is converted into a percentage of progress — 0% at the start and 100% at the end.
- _view progress timeline_: You progress this timeline based on the change in visibility of an element (known as the _subject_) inside a scroller. The visibility of the subject inside the scroller is tracked as a percentage of progress — by default, the timeline is at 0% when the subject is first visible at one edge of the scroller, and 100% when it reaches the opposite edge.
When one of these two timelines is applied to an animated element, the animation progresses along that timeline instead of following the default time-based timeline.
It is possible to adjust the effective placement of the animation along the scroll progress and view progress timelines, i.e., you can define the position at which the animation starts and ends. This can be done in a couple of different ways:
- Start and end animation range values can be applied to the animation to adjust the position of the animation's starting and ending position along the timeline.
- View progress timelines can have a start and/or end inset (or outset) applied to them to adjust the position of the scrollport (see {{glossary("Scroll container")}} for more details) in which the subject element is deemed to be visible. Put another way, this allows you to specify start and/or end inset (or outset) values that offset the position of the timeline itself.
## Scroll-driven animations in action
You can find several tools and demos showing scroll-driven animations in action at [Scroll-driven Animations tools and demos](https://scroll-driven-animations.style/).
## Reference
### Properties
Set the timeline that will control the progress of an animation, and set its attachment range along that timeline:
- {{cssxref("animation-timeline")}}
- {{cssxref("animation-range")}}
- {{cssxref("animation-range-start")}}
- {{cssxref("animation-range-end")}}
Define _named scroll progress timelines_:
- {{cssxref("scroll-timeline")}}
- {{cssxref("scroll-timeline-axis")}}
- {{cssxref("scroll-timeline-name")}}
Define _named view progress timelines_:
- {{cssxref("view-timeline")}}
- {{cssxref("view-timeline-axis")}}
- {{cssxref("view-timeline-inset")}}
- {{cssxref("view-timeline-name")}}
Modify timeline scope:
- {{cssxref("timeline-scope")}}
### At-rules
CSS scroll-driven animations adds the ability to include `<timeline-range-name>`s in {{cssxref("@keyframes")}} blocks, to place keyframes at specific positions inside named timeline ranges.
### Functions
Possible values of the {{cssxref("animation-timeline")}} property for defining _anonymous scroll progress timelines_ and _anonymous view progress timelines_ (i.e. implicitly defined by the browser rather than being explicitly named and defined using the `scroll-timeline-*` and `view-timeline-*` properties):
- [`scroll()`](/en-US/docs/Web/CSS/animation-timeline/scroll)
- [`view()`](/en-US/docs/Web/CSS/animation-timeline/view)
### JavaScript features
- {{domxref("Element.animate()")}}
- {{domxref("AnimationTimeline")}}
- {{domxref("ScrollTimeline")}}
- {{domxref("ViewTimeline")}}
## Specifications
{{Specifications}}
## See also
- [Animate elements on scroll with Scroll-driven animations](https://developer.chrome.com/docs/css-ui/scroll-driven-animations) on developer.chrome.com
- [CSS animations](/en-US/docs/Web/CSS/CSS_animations)
- [Web Animations API](/en-US/docs/Web/API/Web_Animations_API)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/overscroll-behavior/index.md | ---
title: overscroll-behavior
slug: Web/CSS/overscroll-behavior
page-type: css-shorthand-property
browser-compat: css.properties.overscroll-behavior
---
{{CSSRef}}
The **`overscroll-behavior`** CSS property sets what a browser does when reaching the boundary of a scrolling area.
{{EmbedInteractiveExample("pages/css/overscroll-behavior.html")}}
## Constituent properties
This property is a shorthand for the following CSS properties:
- {{Cssxref("overscroll-behavior-x")}}
- {{Cssxref("overscroll-behavior-y")}}
## Syntax
```css
/* Keyword values */
overscroll-behavior: auto; /* default */
overscroll-behavior: contain;
overscroll-behavior: none;
/* Two values */
overscroll-behavior: auto contain;
/* Global values */
overscroll-behavior: inherit;
overscroll-behavior: initial;
overscroll-behavior: revert;
overscroll-behavior: revert-layer;
overscroll-behavior: unset;
```
The `overscroll-behavior` property is specified as one or two keywords chosen from the list of values below.
Two keywords specifies the `overscroll-behavior` value on the `x` and `y` axes respectively. If only one value is specified, both x and y are assumed to have the same value.
### Values
- `auto`
- : The default scroll overflow behavior occurs as normal.
- `contain`
- : Default scroll overflow behavior (e.g., "bounce" effects) is observed inside the element where this value is set. However, no scroll chaining occurs on neighboring scrolling areas; the underlying elements will not scroll. The `contain` value disables native browser navigation, including the vertical pull-to-refresh gesture and horizontal swipe navigation.
- `none`
- : No scroll chaining occurs to neighboring scrolling areas, and default scroll overflow behavior is prevented.
## Description
By default, mobile browsers tend to provide a "bounce" effect or even a page refresh when the top or bottom of a page (or other scroll area) is reached. You may also have noticed that when you have a dialog box with scrolling content at the top of a page that also has scrolling content, once the dialog box's {{Glossary("Scroll_boundary", "scroll boundary")}} is reached, the underlying page will then start to scroll — this is called {{Glossary("Scroll_chaining", "scroll chaining")}}.
In some cases, these behaviors are not desirable. You can use `overscroll-behavior` to get rid of unwanted scroll chaining and the browser's Facebook/Twitter app-inspired "pull to refresh"-type behavior.
Note that this property applies only to {{Glossary("Scroll_container", "scroll containers")}}. In particular, since an [`<iframe>`](/en-US/docs/Web/HTML/Element/iframe) is not a scroll container, setting this property on an iframe has no effect. To control scroll chaining from an iframe, set `overscroll-behavior` on both the [`<html>`](/en-US/docs/Web/HTML/Element/html) and the [`<body>`](/en-US/docs/Web/HTML/Element/body) elements of the iframe's document.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Preventing an underlying element from scrolling
In our [overscroll-behavior example](https://mdn.github.io/css-examples/overscroll-behavior/) (see the [source code](https://github.com/mdn/css-examples/tree/main/overscroll-behavior) also), we present a full-page list of fake contacts, and a dialog box containing a chat window.

Both of these areas scroll; normally if you scrolled the chat window until you hit a scroll boundary, the underlying contacts window would start to scroll too, which is not desirable. This can be stopped using `overscroll-behavior-y` (`overscroll-behavior` would also work) on the chat window, like this:
```css
.messages {
height: 220px;
overflow: auto;
overscroll-behavior-y: contain;
}
```
We also wanted to get rid of the standard overscroll effects when the contacts are scrolled to the top or bottom (e.g. Chrome on Android refreshes the page when you scroll past the top boundary). This can be prevented by setting `overscroll-behavior: none` on the {{htmlelement("html")}} element:
```css
html {
margin: 0;
overscroll-behavior: none;
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Take control of your scroll: customizing pull-to-refresh and overflow effects](https://developer.chrome.com/blog/overscroll-behavior) on developer.chrome.com (2017)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_doublecolon_-webkit-meter-inner-element/index.md | ---
title: "::-webkit-meter-inner-element"
slug: Web/CSS/::-webkit-meter-inner-element
page-type: css-pseudo-element
status:
- non-standard
browser-compat: css.selectors.-webkit-meter-inner-element
---
{{CSSRef}}{{Non-standard_header}}
**`::-webkit-meter-inner-element`** is a proprietary WebKit CSS pseudo-element for selecting and applying styles to the outer containing element of a {{htmlelement("meter")}} element. Additional markup to render the meter element as read-only.
## Syntax
```css
::-webkit-meter-inner-element {
/* ... */
}
```
## Specifications
Not part of any standard.
## Examples
This will only work in WebKit and Blink-based browsers, such as Safari, Chrome, and Chromium-based versions of Edge.
### HTML
```html
Normal: <meter min="0" max="10" value="6">Score 6/10</meter>
<br />
Styled: <meter id="styled" min="0" max="10" value="6">Score 6/10</meter>
```
### CSS
```css
body {
font-family: monospace;
}
.safari meter {
/* Reset the default appearance for Safari only */
/* .safari class is added via JavaScript */
-webkit-appearance: none;
}
#styled::-webkit-meter-inner-element {
-webkit-appearance: inherit;
box-sizing: inherit;
border: 1px dashed #aaa;
}
```
### JavaScript
```js
// Safari requires <meter> elements to have an `appearance` of `none` for custom styling
// using `::-webkit-meter-*` selectors, but `appearance: none` breaks rendering on Chrome.
// Therefore, we must check if the browser is Safari-based.
const is_safari =
navigator.userAgent.includes("AppleWebKit/") &&
!navigator.userAgent.includes("Chrome/");
if (is_safari) {
document.body.classList.add("safari");
}
```
### Result
{{ EmbedLiveSample('Examples') }}
## Browser compatibility
{{Compat}}
## See also
The pseudo-elements used by WebKit/Blink to style other parts of a {{htmlelement("meter")}} element are as follows:
- {{cssxref("::-webkit-meter-bar")}}
- {{cssxref("::-webkit-meter-even-less-good-value")}}
- {{cssxref("::-webkit-meter-optimum-value")}}
- {{cssxref("::-webkit-meter-suboptimum-value")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/text-underline-offset/index.md | ---
title: text-underline-offset
slug: Web/CSS/text-underline-offset
page-type: css-property
browser-compat: css.properties.text-underline-offset
---
{{CSSRef}}
The **`text-underline-offset`** [CSS](/en-US/docs/Web/CSS) property sets the offset distance of an underline text decoration line (applied using {{cssxref("text-decoration")}}) from its original position.
{{EmbedInteractiveExample("pages/css/text-underline-offset.html")}}
`text-underline-offset` is not part of the {{cssxref('text-decoration')}} shorthand. While an element can have multiple `text-decoration` lines, `text-underline-offset` only impacts underlining, and **not** other possible line decoration options such as `overline` or `line-through`.
## Syntax
```css
/* Single keyword */
text-underline-offset: auto;
/* length */
text-underline-offset: 0.1em;
text-underline-offset: 3px;
/* percentage */
text-underline-offset: 20%;
/* Global values */
text-underline-offset: inherit;
text-underline-offset: initial;
text-underline-offset: revert;
text-underline-offset: revert-layer;
text-underline-offset: unset;
```
The `text-underline-offset` property is specified as a single value from the list below.
### Values
- `auto`
- : The browser chooses the appropriate offset for underlines.
- `<length>`
- : Specifies the offset of underlines as a {{cssxref('length')}}, overriding the font file suggestion and the browser default. It is recommended to use `em` units so the offset scales with the font size.
- `<percentage>`
- : Specifies the offset of underlines as a {{cssxref('percentage')}} of **1 em** in the element's font. A percentage inherits as a relative value, and so therefore scales with changes in the font. For a given application of this property, the offset is constant across the whole box that the underline is applied to, even if there are child elements with different font sizes or vertical alignment.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Demonstration of text-underline-offset
```html
<p class="oneline">Here's some text with an offset wavy red underline!</p>
<br />
<p class="twolines">
This text has lines both above and below it. Only the bottom one is offset.
</p>
```
```css
p {
text-decoration: underline wavy red;
text-underline-offset: 1em;
}
.twolines {
text-decoration-color: purple;
text-decoration-line: underline overline;
}
```
{{EmbedLiveSample('Examples')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("text-decoration")}}
- {{cssxref("text-decoration-thickness")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/hyphenate-limit-chars/index.md | ---
title: hyphenate-limit-chars
slug: Web/CSS/hyphenate-limit-chars
page-type: css-property
browser-compat: css.properties.hyphenate-limit-chars
---
{{CSSRef}}
The **`hyphenate-limit-chars`** [CSS](/en-US/docs/Web/CSS) property specifies the minimum word length to allow hyphenation of words as well as the minimum number of characters before and after the hyphen.
This property provides you with fine-grained control over hyphenation in text. This control enables you to avoid awkward hyphenations and set appropriate hyphenation for different languages, which, in turn, allows for better typography.
## Syntax
```css
/* Numeric values */
hyphenate-limit-chars: 10 4 4;
hyphenate-limit-chars: 10 4;
hyphenate-limit-chars: 10;
/* Keyword values */
hyphenate-limit-chars: auto auto auto;
hyphenate-limit-chars: auto auto;
hyphenate-limit-chars: auto;
/* Mix of numeric and keyword values */
hyphenate-limit-chars: 10 auto 4;
hyphenate-limit-chars: 10 auto;
hyphenate-limit-chars: auto 3;
/* Global values */
hyphenate-limit-chars: inherit;
hyphenate-limit-chars: initial;
hyphenate-limit-chars: revert;
hyphenate-limit-chars: revert-layer;
hyphenate-limit-chars: unset;
```
The `hyphenate-limit-chars` property takes 1–3 values that can be numeric or `auto`, as explained below.
### Values
- `x y z`
- : The first value is the minimum word length before words should be hyphenated. The second value is the minimum number of characters before the hyphen. The third value is the minimum number of characters after the hyphen.
- `x y`
- : The first value is the minimum word length before words should be hyphenated. The second value is the minimum number of characters before the hyphen. The minimum number of characters after the hyphen will be set equal to the second value.
- `x`
- : The value is the minimum word length before words should be hyphenated. The minimum number of characters before and after the hyphen will be set to `auto`.
If `auto` is set for any of the values, the user agent will choose an appropriate value for the current layout. Unless the user agent can calculate a better value, the following default values will be used:
- Minimum word length to allow hyphenation: 5
- Minimum number of characters before the hyphen: 2
- Minimum number of characters after the hyphen: 2
Note that if a word is too short to meet the given constraints, it will not be hyphenated. For example, given a value like `hyphenate-limit-chars: auto 3 4`, words shorter than 7 characters will never be hyphenated, since it is impossible to have 3 characters before the hyphen and 4 characters after it.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting hyphenation limits
In this example, we have four boxes each containing the same text. For the purpose of comparison, the first box shows the default hyphenation applied by the browser. The next three boxes demonstrate the result of constraining the browser's default behavior using different `hyphenate-limit-chars` values.
#### HTML
```html
<div class="container">
<p id="ex1">juxtaposition and acknowledgement</p>
<p id="ex2">juxtaposition and acknowledgement</p>
<p id="ex3">juxtaposition and acknowledgement</p>
<p id="ex4">juxtaposition and acknowledgement</p>
</div>
```
#### CSS
```css
.container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
p {
margin: 1rem;
width: 120px;
border: 2px dashed #999;
font-size: 1.5rem;
hyphens: auto;
}
#ex2 {
hyphenate-limit-chars: 14;
}
#ex3 {
hyphenate-limit-chars: 5 9 2;
}
#ex4 {
hyphenate-limit-chars: 5 2 7;
}
```
#### Result
{{EmbedLiveSample("Setting hyphenation limits", "", 200)}}
In the first box, we don't set `hyphenate-limit-chars`, allowing the browser to apply its default algorithm. By default, the browser uses the values `5 2 2` unless it can find better values.
In the second box, we prevent the browser from hyphenating words unless they are at least 14 characters long by setting `hyphenate-limit-chars: 14`. As a result, "juxtaposition" is not hyphenated in the second box because it is only 13 characters long.
In the third box, we constrain the browser to include at least 9 characters before the hyphen by setting `hyphenate-limit-chars: 5 9 2`. The effect is that "acknowledgement" is now hyphenated as "acknowledge-ment" rather than the default version "acknowl-edgement", as shown in the first box.
Note that the browser does not have to include exactly 9 characters before the hyphen: as long as the constraints given in `hyphenate-limit-chars` are satisfied, the browser can break the word in the place it considers best. So in this case, for example, it chooses "acknowledge-ment" rather than the less readable "acknowled-gement".
In the fourth box, we make the browser include at least 7 characters after the hyphen by setting
`hyphenate-limit-chars: 5 2 7`. The effect is that "juxtaposition" is hyphenated as "juxta-position" rather than the default "juxtaposi-tion".
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("hyphens")}}
- [CSS Text module](/en-US/docs/Web/CSS/CSS_text)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/reference/index.md | ---
title: CSS reference
slug: Web/CSS/Reference
page-type: landing-page
---
{{CSSRef}}
Use this **CSS reference** to browse an [alphabetical index](#index) of all of the standard [CSS](/en-US/docs/Web/CSS) properties, [pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes), [pseudo-elements](/en-US/docs/Web/CSS/Pseudo-elements), [data types](/en-US/docs/Web/CSS/CSS_Types), [functional notations](/en-US/docs/Web/CSS/CSS_Functions) and [at-rules](/en-US/docs/Web/CSS/At-rule). You can also browse [key CSS concepts](#concepts) and a list of [selectors organized by type](#selectors). Also included is a brief [DOM-CSS / CSSOM reference](#dom-css_cssom).
## Basic rule syntax
### Style rule syntax
```css
style-rule ::=
selectors-list {
properties-list
}
```
Where:
```css
selectors-list ::=
selector[:pseudo-class] [::pseudo-element]
[, selectors-list]
properties-list ::=
[property : value] [; properties-list]
```
See the index of [_selectors_](#selectors), [_pseudo-classes_](#pseudo), and _[pseudo-elements](#pseudo)_ below. The syntax for each specified _value_ depends on the data type defined for each specified _property_.
#### Style rule examples
```css
strong {
color: red;
}
div.menu-bar li:hover > ul {
display: block;
}
```
For a beginner-level introduction to the syntax of selectors, see our [guide on CSS Selectors](/en-US/docs/Learn/CSS/Building_blocks/Selectors). Be aware that any [syntax](/en-US/docs/Web/CSS/Syntax) error in a rule definition invalidates the entire rule. Invalid rules are ignored by the browser. Note that CSS rule definitions are entirely ({{Glossary("ASCII")}}) [text-based](https://www.w3.org/TR/css-syntax-3/#intro), whereas DOM-CSS / CSSOM (the rule management system) is [object-based](https://www.w3.org/TR/cssom/#introduction).
### At-rule syntax
As the structure of at-rules varies widely, please see [At-rule](/en-US/docs/Web/CSS/At-rule) to find the syntax of the specific one you want.
## Index
> **Note:** This index does not include SVG-exclusive [presentation attributes](/en-US/docs/Web/SVG/Attribute/Presentation), which can be used as CSS properties on [SVG](/en-US/docs/Web/SVG) elements.
> **Note:** The property names in this index do **not** include the JavaScript names which do differ from the CSS standard names.
{{CSS_Ref}}
## Selectors
The following are the various [selectors](/en-US/docs/Web/CSS/CSS_selectors), which allow styles to be conditional based on various features of elements within the DOM.
### Basic selectors
**Basic selectors** are fundamental selectors; these are the most basic selectors that are frequently combined to create other, more complex selectors.
- [Universal selector](/en-US/docs/Web/CSS/Universal_selectors) `*`
- [Type selector](/en-US/docs/Web/CSS/Type_selectors) `elementname`
- [Class selector](/en-US/docs/Web/CSS/Class_selectors) `.classname`
- [ID selector](/en-US/docs/Web/CSS/ID_selectors) `#idname`
- [Attribute selector](/en-US/docs/Web/CSS/Attribute_selectors) `[attr=value]`
### Grouping selectors
- [Selector list](/en-US/docs/Web/CSS/Selector_list) `A, B`
- : Specifies that both `A` and `B` elements are selected. This is a grouping method to select several matching elements.
### Combinators
Combinators are selectors that establish a relationship between two or more simple selectors, such as "`A` is a child of `B`" or "`A` is adjacent to `B`", creating a complex selector.
- [Next-sibling combinator](/en-US/docs/Web/CSS/Next-sibling_combinator) `A + B`
- : Specifies that the elements selected by both `A` and `B` have the same parent and that the element selected by `B` immediately follows the element selected by `A` horizontally.
- [Subsequent-sibling combinator](/en-US/docs/Web/CSS/Subsequent-sibling_combinator) `A ~ B`
- : Specifies that the elements selected by both `A` and `B` share the same parent and that the element selected by `A` comes before—but not necessarily immediately before—the element selected by `B`.
- [Child combinator](/en-US/docs/Web/CSS/Child_combinator) `A > B`
- : Specifies that the element selected by `B` is the direct child of the element selected by `A`.
- [Descendant combinator](/en-US/docs/Web/CSS/Descendant_combinator) `A B`
- : Specifies that the element selected by `B` is a descendant of the element selected by `A`, but is not necessarily a direct child.
- [Column combinator](/en-US/docs/Web/CSS/Column_combinator) `A || B` {{Experimental_Inline}}
- : Specifies that the element selected by `B` is located within the table column specified by `A`. Elements which span multiple columns are considered to be a member of all of those columns.
### Pseudo
- [Pseudo classes](/en-US/docs/Web/CSS/Pseudo-classes) `:`
- : Specifies a special state of the selected element(s).
- [Pseudo elements](/en-US/docs/Web/CSS/Pseudo-elements) `::`
- : Represents entities that are not included in HTML.
> **Callout:**
>
> See also [selectors in the Selectors specification](https://drafts.csswg.org/selectors/) and the [pseudo-element specification](https://drafts.csswg.org/css-pseudo/).
## Concepts
### Syntax and semantics
- [CSS syntax](/en-US/docs/Web/CSS/Syntax)
- [At-rules](/en-US/docs/Web/CSS/At-rule)
- [Cascade](/en-US/docs/Web/CSS/Cascade)
- [Comments](/en-US/docs/Web/CSS/Comments)
- [Descriptor](/en-US/docs/Glossary/CSS_Descriptor)
- [Inheritance](/en-US/docs/Web/CSS/Inheritance)
- [Shorthand properties](/en-US/docs/Web/CSS/Shorthand_properties)
- [Specificity](/en-US/docs/Web/CSS/Specificity)
- [Value definition syntax](/en-US/docs/Web/CSS/Value_definition_syntax)
- [CSS unit and value types](/en-US/docs/Web/CSS/CSS_Values_and_Units)
- [CSS functional notations](/en-US/docs/Web/CSS/CSS_Functions)
### Values
- [Actual value](/en-US/docs/Web/CSS/actual_value)
- [Computed value](/en-US/docs/Web/CSS/computed_value)
- [Initial value](/en-US/docs/Web/CSS/initial_value)
- [Resolved value](/en-US/docs/Web/CSS/resolved_value)
- [Specified value](/en-US/docs/Web/CSS/specified_value)
- [Used value](/en-US/docs/Web/CSS/used_value)
### Layout
- [Block formatting context](/en-US/docs/Web/CSS/CSS_display/Block_formatting_context)
- [Box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model)
- [Containing block](/en-US/docs/Web/CSS/Containing_block)
- [Layout mode](/en-US/docs/Web/CSS/Layout_mode)
- [Margin collapsing](/en-US/docs/Web/CSS/CSS_box_model/Mastering_margin_collapsing)
- [Replaced elements](/en-US/docs/Web/CSS/Replaced_element)
- [Stacking context](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context)
- [Visual formatting model](/en-US/docs/Web/CSS/Visual_formatting_model)
## DOM-CSS / CSSOM
### Major object types
- {{DOMxRef("Document.styleSheets")}}
- `{{DOMxRef("StyleSheetList", "styleSheets", "", 1)}}[i].{{DOMxRef("CSSRuleList", "cssRules", "", 1)}}`
- `cssRules[i].{{DOMxRef("CSSRule.cssText", "cssText", "", 1)}}` (selector & style)
- `cssRules[i].{{DOMxRef("CSSStyleRule.selectorText", "selectorText", "", 1)}}`
- {{DOMxRef("HTMLElement.style")}}
- `HTMLElement.style.{{DOMxRef("CSSStyleDeclaration.cssText", "cssText", "", 1)}}` (just style)
- {{DOMxRef("Element.className")}}
- {{DOMxRef("Element.classList")}}
### Important methods
- {{DOMxRef("CSSStyleSheet.insertRule()")}}
- {{DOMxRef("CSSStyleSheet.deleteRule()")}}
## See also
- [Mozilla CSS extensions](/en-US/docs/Web/CSS/Mozilla_Extensions) (prefixed with `-moz-`)
- [WebKit CSS extensions](/en-US/docs/Web/CSS/WebKit_Extensions) (mostly prefixed with `-webkit-`)
## External Links
- [CSS Indices (w3.org)](https://www.w3.org/TR/CSS/#indices)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/border-image-outset/index.md | ---
title: border-image-outset
slug: Web/CSS/border-image-outset
page-type: css-property
browser-compat: css.properties.border-image-outset
---
{{CSSRef}}
The **`border-image-outset`** [CSS](/en-US/docs/Web/CSS) property sets the distance by which an element's [border image](/en-US/docs/Web/CSS/border-image) is set out from its border box.
The parts of the border image that are rendered outside the element's border box with `border-image-outset` do not trigger overflow scrollbars and don't capture mouse events.
{{EmbedInteractiveExample("pages/css/border-image-outset.html")}}
## Syntax
```css
/* <length> value */
border-image-outset: 1rem;
/* <number> value */
border-image-outset: 1.5;
/* top and bottom | left and right */
border-image-outset: 1 1.2;
/* top | left and right | bottom */
border-image-outset: 30px 2 45px;
/* top | right | bottom | left */
border-image-outset: 7px 12px 14px 5px;
/* Global values */
border-image-outset: inherit;
border-image-outset: initial;
border-image-outset: revert;
border-image-outset: revert-layer;
border-image-outset: unset;
```
The `border-image-outset` property may be specified as one, two, three, or four values. Each value is a {{cssxref("<length>")}} or {{cssxref("<number>")}}. Negative values are invalid and will cause the `border-image-outset` declaration to be ignored.
1. If **one** value is specified, it applies to **all four sides**.
2. If **two** values are specified, the first applies to the **top and bottom** and the second to the **left and right**.
3. If **three** values are specified, the first applies to the **top**, the second to the **left and right**, and the third to the **bottom**.
4. If **four** values are specified, they apply to the **top**, **right**, **bottom**, and **left** in that order (clockwise).
### Values
- {{cssxref("<length>")}}
- : The size of the `border-image` outset as a dimension — a number with a unit.
- {{cssxref("<number>")}}
- : The size of the `border-image` outset as a multiple of the element's corresponding {{cssxref("border-width")}}s. For example, if an element has `border-width: 1em 2px 0 1.5rem`, and `border-image-outset: 2`, the final `border-image-outset` would be calculated as `2em 4px 0 3rem`.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Outsetting a border image
#### HTML
```html
<div id="outset">This element has an outset border image!</div>
```
#### CSS
```css
#outset {
width: 10rem;
background: #cef;
border: 1.4rem solid;
border-image: radial-gradient(#ff2, #55f) 40;
border-image-outset: 1.5; /* 1.5 × 1.4rem = 2.1rem */
margin: 2.1rem;
}
```
#### Result
{{EmbedLiveSample("Outsetting_a_border_image", "auto", 200)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Backgrounds and borders](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders)
- [Learn CSS: Backgrounds and borders](/en-US/docs/Learn/CSS/Building_blocks/Backgrounds_and_borders)
- [Border images in CSS: A key focus area for Interop 2023](/en-US/blog/border-images-interop-2023/) on MDN blog (2023)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/transition-delay/index.md | ---
title: transition-delay
slug: Web/CSS/transition-delay
page-type: css-property
browser-compat: css.properties.transition-delay
---
{{CSSRef}}
The **`transition-delay`** CSS property specifies the duration to wait before starting a property's [transition effect](/en-US/docs/Web/CSS/CSS_transitions/Using_CSS_transitions) when its value changes.
{{EmbedInteractiveExample("pages/css/transition-delay.html")}}
The delay may be zero, positive, or negative:
- A value of `0s` (or `0ms`) will begin the transition effect immediately.
- A positive value will delay the start of the transition effect for the given length of time.
- A negative value will begin the transition effect immediately, and partway through the effect. In other words, the effect will be animated as if it had already been running for the given length of time.
You may specify multiple delays, which is useful when transitioning multiple properties. Each delay will be applied to the corresponding property as specified by the {{cssxref("transition-property")}} property, which acts as a master list. If there are fewer delays specified than in the master list, the list of delay values will be repeated until there are enough. If there are more delays, the list of delay values will be truncated to match the number of properties. In both cases, the CSS declaration remains valid.
## Syntax
```css
/* <time> values */
transition-delay: 3s;
transition-delay: 2s, 4ms;
/* Global values */
transition-delay: inherit;
transition-delay: initial;
transition-delay: revert;
transition-delay: revert-layer;
transition-delay: unset;
```
### Values
- {{cssxref("<time>")}}
- : Denotes the amount of time to wait between a property's value changing and the start of the transition effect.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Example showing different delays
#### HTML
```html
<div class="box delay-1">0.5 seconds</div>
<div class="box delay-2">2 seconds</div>
<div class="box delay-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;
transition-duration: 3s;
}
.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;
transition-duration: 3s;
}
.delay-1 {
transition-delay: 0.5s;
}
.delay-2 {
transition-delay: 2s;
}
.delay-3 {
transition-delay: 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_delays",275,200)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Using CSS transitions](/en-US/docs/Web/CSS/CSS_transitions/Using_CSS_transitions)
- {{domxref("TransitionEvent")}} API
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/flex-shrink/index.md | ---
title: flex-shrink
slug: Web/CSS/flex-shrink
page-type: css-property
browser-compat: css.properties.flex-shrink
---
{{CSSRef}}
The **`flex-shrink`** [CSS](/en-US/docs/Web/CSS) property sets the flex shrink factor of a flex item. If the size of all flex items is larger than the flex container, items shrink to fit according to `flex-shrink`.
In use, `flex-shrink` is used alongside the other flex properties {{cssxref("flex-grow")}} and {{cssxref("flex-basis")}}, and normally defined using the {{cssxref("flex")}} shorthand.
{{EmbedInteractiveExample("pages/css/flex-shrink.html")}}
## Syntax
```css
/* <number> values */
flex-shrink: 2;
flex-shrink: 0.6;
/* Global values */
flex-shrink: inherit;
flex-shrink: initial;
flex-shrink: revert;
flex-shrink: revert-layer;
flex-shrink: unset;
```
The `flex-shrink` property is specified as a single `<number>`.
### Values
- `<number>`
- : See {{cssxref("<number>")}}. Negative values are invalid. Defaults to 1.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting flex item shrink factor
#### HTML
```html
<p>The width of content is 500px; the flex-basis of the flex items is 120px.</p>
<p>A, B, C have flex-shrink:1 set. D and E have flex-shrink:2 set</p>
<p>The width of D and E is less than the others.</p>
<div id="content">
<div class="box" style="background-color:red;">A</div>
<div class="box" style="background-color:lightblue;">B</div>
<div class="box" style="background-color:yellow;">C</div>
<div class="box1" style="background-color:brown;">D</div>
<div class="box1" style="background-color:lightgreen;">E</div>
</div>
```
#### CSS
```css
#content {
display: flex;
width: 500px;
}
#content div {
flex-basis: 120px;
border: 3px solid rgb(0 0 0 / 20%);
}
.box {
flex-shrink: 1;
}
.box1 {
flex-shrink: 2;
}
```
#### Result
{{EmbedLiveSample('Setting_flex_item_shrink_factor', 500, 300)}}
## 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/justify-content/index.md | ---
title: justify-content
slug: Web/CSS/justify-content
page-type: css-property
browser-compat: css.properties.justify-content
---
{{CSSRef}}
The [CSS](/en-US/docs/Web/CSS) **`justify-content`** property defines how the browser distributes space between and around content items along the {{Glossary("Main Axis", "main-axis")}} of a flex container, and the inline axis of a grid container.
The interactive example below demonstrates some of the values using Grid Layout.
{{EmbedInteractiveExample("pages/css/justify-content.html")}}
The alignment is done after the lengths and auto margins are applied, meaning that, if in a [Flexbox layout](/en-US/docs/Web/CSS/CSS_flexible_box_layout) there is at least one flexible element, with {{cssxref("flex-grow")}} different from `0`, it will have no effect as there won't be any available space.
## Syntax
```css
/* Positional alignment */
justify-content: center; /* Pack items around the center */
justify-content: start; /* Pack items from the start */
justify-content: end; /* Pack items from the end */
justify-content: flex-start; /* Pack flex items from the start */
justify-content: flex-end; /* Pack flex items from the end */
justify-content: left; /* Pack items from the left */
justify-content: right; /* Pack items from the right */
/* Baseline alignment */
/* justify-content does not take baseline values */
/* Normal alignment */
justify-content: normal;
/* Distributed alignment */
justify-content: space-between; /* Distribute items evenly
The first item is flush with the start,
the last is flush with the end */
justify-content: space-around; /* Distribute items evenly
Start and end gaps are half the size of the space
between each item */
justify-content: space-evenly; /* Distribute items evenly
Start, in-between, and end gaps have equal sizes */
justify-content: stretch; /* Distribute items evenly
Stretch 'auto'-sized items to fit
the container */
/* Overflow alignment */
justify-content: safe center;
justify-content: unsafe center;
/* Global values */
justify-content: inherit;
justify-content: initial;
justify-content: revert;
justify-content: revert-layer;
justify-content: unset;
```
### Values
- `start`
- : The items are packed flush to each other toward the start edge of the alignment container in the main axis.
- `end`
- : The items are packed flush to each other toward the end edge of the alignment container in the main axis.
- `flex-start`
- : The items are packed flush to each other toward the edge of the alignment container depending on the flex container's main-start side.
This only applies to flex layout items. For items that are not children of a flex container, this value is treated like `start`.
- `flex-end`
- : The items are packed flush to each other toward the edge of the alignment container depending on the flex container's main-end side.
This only applies to flex layout items. For items that are not children of a flex container, this value is treated like `end`.
- `center`
- : The items are packed flush to each other toward the center of the alignment container along the main axis.
- `left`
- : The items are packed flush with each other toward the left edge of the alignment container. When the property's horizontal axis is not parallel with the inline axis, such as when [`flex-direction: column;`](/en-US/docs/Web/CSS/flex-direction) is set, this value behaves like `start`.
- `right`
- : The items are packed flush to each other toward the right edge of the alignment container in the appropriate axis. If the property's axis is not parallel with the inline axis (in a grid container) or the main-axis (in a flexbox container), this value behaves like `start`.
- `normal`
- : Behaves as `stretch`, except in the case of multi-column containers with a non-`auto` [`column-width`](/en-US/docs/Web/CSS/column-width), in which case the columns take their specified `column-width` rather than stretching to fill the container. As `stretch` behaves as `start` in flex containers, `normal` also behaves as `start`.
- `space-between`
- : The items are evenly distributed within the alignment container along the main axis. The spacing between each pair of adjacent items is the same. The first item is flush with the main-start edge, and the last item is flush with the main-end edge.
- `space-around`
- : The items are evenly distributed within the alignment container along the main axis. The spacing between each pair of adjacent items is the same. The empty space before the first and after the last item equals half of the space between each pair of adjacent items.
- `space-evenly`
- : The items are evenly distributed within the alignment container along the main axis. The spacing between each pair of adjacent items, the main-start edge and the first item, and the main-end edge and the last item, are all exactly the same.
- `stretch`
- : If the combined size of the items along the main axis is less than the size of the alignment container, any `auto`-sized items have their size increased equally (not proportionally), while still respecting the constraints imposed by {{cssxref("max-height")}}/{{cssxref("max-width")}} (or equivalent functionality), so that the combined size exactly fills the alignment container along the main axis.
> **Note:** For [flexboxes](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox), the `stretch` value behaves as `flex-start` or `start`. This is because, in flexboxes, stretching is controlled using the {{CSSXref("flex-grow")}} property.
- `safe`
- : If the item overflows the alignment container, then the item is aligned as if the alignment mode is `start`. The desired alignment will not be implemented.
- `unsafe`
- : Even if the item overflows the alignment container, the desired alignment will be implemented. Unlike `safe`, which will ignore the desired alignment in favor of preventing overflow.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting flex item distribution
#### CSS
```css
#container {
display: flex;
justify-content: space-between; /* Can be changed in the live sample */
}
#container > div {
width: 100px;
height: 100px;
background: linear-gradient(-45deg, #788cff, #b4c8ff);
}
```
```html hidden
<div id="container">
<div></div>
<div></div>
<div></div>
</div>
<select id="justifyContent">
<option value="start">start</option>
<option value="end">end</option>
<option value="flex-start">flex-start</option>
<option value="flex-end">flex-end</option>
<option value="center">center</option>
<option value="left">left</option>
<option value="right">right</option>
<option value="space-between" selected>space-between</option>
<option value="space-around">space-around</option>
<option value="space-evenly">space-evenly</option>
<option value="stretch">stretch</option>
</select>
```
```js hidden
const justifyContent = document.getElementById("justifyContent");
justifyContent.addEventListener("change", (evt) => {
document.getElementById("container").style.justifyContent = evt.target.value;
});
```
#### Result
{{EmbedLiveSample("Setting_flex_item_distribution", "100%", 180)}}
## 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)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/box-align/index.md | ---
title: box-align
slug: Web/CSS/box-align
page-type: css-property
status:
- deprecated
- non-standard
browser-compat: css.properties.box-align
---
{{CSSRef}}{{Non-standard_header}}{{Deprecated_Header}}
> **Warning:** This is a property of the original CSS Flexible Box Layout Module draft, and has been replaced by a newer standard.
The **`box-align`** [CSS](/en-US/docs/Web/CSS) property specifies how an element aligns its contents across its layout in a perpendicular direction. The effect of the property is only visible if there is extra space in the box.
See [flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox) for information about the current standard.
The direction of layout depends on the element's orientation: horizontal or vertical.
## Syntax
```css
/* Keyword values */
box-align: start;
box-align: center;
box-align: end;
box-align: baseline;
box-align: stretch;
/* Global values */
box-lines: inherit;
box-lines: initial;
box-lines: unset;
```
The `box-align` property is specified as one of the keyword values listed below.
### Values
- `start`
- : The box aligns contents at the start, leaving any extra space at the end.
- `center`
- : The box aligns contents in the center, dividing any extra space equally between the start and the end.
- `end`
- : The box aligns contents at the end, leaving any extra space at the start.
- `baseline`
- : The box aligns the baselines of the contents (lining up the text). This only applies if the box's orientation is horizontal.
- `stretch`
- : The box stretches the contents so that there is no extra space in the box.
## Notes
The edge of the box designated the _start_ for alignment purposes depends on the box's orientation:
- For horizontal elements, the _start_ is the top edge.
- For vertical elements, the _start_ is the left edge.
The edge opposite to the start is designated the _end_.
If the alignment is set using the element's `align` attribute, then the style is ignored.
## Formal definition
{{cssinfo}}
## Formal syntax
```plain
box-align =
start | center | end | baseline | stretch
```
## Examples
### Setting box alignment
```html
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<title>CSS box-align example</title>
<style>
div.example {
display: box; /* As specified */
display: -moz-box; /* Mozilla */
display: -webkit-box; /* WebKit */
/* Make this box taller than the children,
so there is room for the box-pack */
height: 400px;
/* Make this box wider than the children
so there is room for the box-align */
width: 300px;
/* Children should be oriented vertically */
box-orient: vertical; /* As specified */
-moz-box-orient: vertical; /* Mozilla */
-webkit-box-orient: vertical; /* WebKit */
/* Align children to the horizontal center of this box */
box-align: center; /* As specified */
-moz-box-align: center; /* Mozilla */
-webkit-box-align: center; /* WebKit */
/* Pack children to the bottom of this box */
box-pack: end; /* As specified */
-moz-box-pack: end; /* Mozilla */
-webkit-box-pack: end; /* WebKit */
}
div.example > p {
/* Make children narrower than their parent,
so there is room for the box-align */
width: 200px;
}
</style>
</head>
<body>
<div class="example">
<p>
I will be second from the bottom of div.example, centered horizontally.
</p>
<p>I will be on the bottom of div.example, centered horizontally.</p>
</div>
</body>
</html>
```
## Specifications
Not part of any standard.
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("align-items")}}, {{cssxref("box-orient")}}, {{cssxref("box-direction")}}, {{cssxref("box-pack")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_doublecolon_-webkit-inner-spin-button/index.md | ---
title: "::-webkit-inner-spin-button"
slug: Web/CSS/::-webkit-inner-spin-button
page-type: css-pseudo-element
status:
- non-standard
browser-compat: css.selectors.-webkit-inner-spin-button
---
{{CSSRef}}{{Non-standard_header}}
The **`::-webkit-inner-spin-button`** CSS pseudo-element is used to style the inner part of the spinner button of number picker input elements.
## Syntax
```css
::-webkit-inner-spin-button {
/* ... */
}
```
## Examples
These examples work only in browsers based on WebKit and Blink.
### Changing the cursor in the spin controls
In this example, the CSS {{cssxref("cursor")}} is changed to `pointer` whenever the cursor is positioned over the inner part of the input's spin controls.
#### HTML
```html
<input type="number" />
```
#### CSS
```css
input[type="number"]::-webkit-inner-spin-button {
cursor: pointer;
}
```
#### Result
{{EmbedLiveSample("Changing_the_cursor_in_the_spin_controls", 200, 30)}}
## Specifications
Not part of any standard.
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("::-webkit-textfield-decoration-container")}}
- [Styling Form Controls – WebKit](https://trac.webkit.org/wiki/Styling%20Form%20Controls#inputelement)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/exp/index.md | ---
title: exp()
slug: Web/CSS/exp
page-type: css-function
browser-compat: css.types.exp
---
{{CSSRef}}
The **`exp()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) is an exponential function that takes an number as an argument and returns the mathematical constant `e` raised to the power of the given number.
The mathematical constant [e](<https://en.wikipedia.org/wiki/E_(mathematical_constant)>) is the base of natural logarithms, and is approximately `2.718281828459045`.
The `exp(number)` function contains a calculation which returns the same value as {{CSSxRef("pow", "pow(e, number)")}}.
## Syntax
```css
/* A <number> value */
width: calc(100px * exp(-1)); /* 100px * 0.367879441171442 = 36px */
width: calc(100px * exp(0)); /* 100px * 1 = 100px */
width: calc(100px * exp(1)); /* 100px * 2.718281828459045 = 217px */
```
### Parameter
The `exp(number)` function accepts only one value as its parameter.
- `number`
- : A calculation which resolves to a {{CSSxRef("number")}}. Representing the value to be raised by a power of `e`.
### Return value
Returns a non-negative {{CSSxRef("number")}} representing e<sup>number</sup>, which is the result of calculating `e` raised to the power of `number`.
- If `number` is `-Infinity`, the result is `0`.
- If `number` is `0`, the result is `1`.
- If `number` is `1`, the result is `e` (i.e. `2.718281828459045`).
- If `number` is `Infinity`, the result is `Infinity`.
### Formal syntax
{{CSSSyntax}}
## Examples
### Rotate elements
The `exp()` function can be used to {{CSSxRef("transform-function/rotate", "rotate")}} elements as it return a {{CSSxRef("number")}}.
#### HTML
```html
<div class="box box-1"></div>
<div class="box box-2"></div>
<div class="box box-3"></div>
<div class="box box-4"></div>
<div class="box box-5"></div>
```
#### CSS
```css hidden
body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
gap: 50px;
}
```
```css
div.box {
width: 100px;
height: 100px;
background: linear-gradient(orange, red);
}
div.box-1 {
transform: rotate(calc(1turn * exp(-1))); // 0.3678794411714423turn
}
div.box-2 {
transform: rotate(calc(1turn * exp(-0.75))); // 0.4723665527410147turn
}
div.box-3 {
transform: rotate(calc(1turn * exp(-0.5))); // 0.6065306597126334turn
}
div.box-4 {
transform: rotate(calc(1turn * exp(-0.25))); // 0.7788007830714049turn
}
div.box-5 {
transform: rotate(calc(1turn * exp(0))); // 1turn
}
```
#### Result
{{EmbedLiveSample('Rotate elements', '100%', '200px')}}
### Scale headings by fixed ratio
The `exp()` function can be useful for strategies like CSS modular scale, which relates all the font-sizes on a page to each other by a fixed ratio.
#### HTML
```html
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
```
#### CSS
```css
h1 {
font-size: calc(1rem * exp(1.25)); // 3.4903429574618414rem
}
h2 {
font-size: calc(1rem * exp(1)); // 2.718281828459045rem
}
h3 {
font-size: calc(1rem * exp(0.75)); // 2.117000016612675rem
}
h4 {
font-size: calc(1rem * exp(0.5)); // 1.6487212707001282rem
}
h5 {
font-size: calc(1rem * exp(0.25)); // 1.2840254166877414rem
}
h6 {
font-size: calc(1rem * exp(0)); // 1rem
}
```
#### Result
{{EmbedLiveSample('Scale headings by fixed ratio', '100%', '300px')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef("pow")}}
- {{CSSxRef("sqrt")}}
- {{CSSxRef("hypot")}}
- {{CSSxRef("log")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/scroll-padding-block-end/index.md | ---
title: scroll-padding-block-end
slug: Web/CSS/scroll-padding-block-end
page-type: css-property
browser-compat: css.properties.scroll-padding-block-end
---
{{CSSRef}}
The `scroll-padding-block-end` property defines offsets for the end edge in the block dimension 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-block-end.html")}}
## Syntax
```css
/* Keyword values */
scroll-padding-block-end: auto;
/* <length> values */
scroll-padding-block-end: 10px;
scroll-padding-block-end: 1em;
scroll-padding-block-end: 10%;
/* Global values */
scroll-padding-block-end: inherit;
scroll-padding-block-end: initial;
scroll-padding-block-end: revert;
scroll-padding-block-end: revert-layer;
scroll-padding-block-end: unset;
```
### Values
- `<length-percentage>`
- : An inwards offset from the block end 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/text-underline-position/index.md | ---
title: text-underline-position
slug: Web/CSS/text-underline-position
page-type: css-property
browser-compat: css.properties.text-underline-position
---
{{CSSRef}}
The **`text-underline-position`** [CSS](/en-US/docs/Web/CSS) property specifies the position of the underline which is set using the {{cssxref("text-decoration")}} property's `underline` value.
{{EmbedInteractiveExample("pages/css/text-underline-position.html")}}
## Syntax
```css
/* Single keyword */
text-underline-position: auto;
text-underline-position: under;
text-underline-position: left;
text-underline-position: right;
/* Multiple keywords */
text-underline-position: under left;
text-underline-position: right under;
/* Global values */
text-underline-position: inherit;
text-underline-position: initial;
text-underline-position: revert;
text-underline-position: revert-layer;
text-underline-position: unset;
```
### Values
- `auto`
- : The {{glossary("user agent")}} uses its own algorithm to place the line at or under the alphabetic baseline.
- `from-font`
- : If the font file includes information about a preferred position, use that value. If the font file doesn't include this information, behave as if `auto` was set, with the browser choosing an appropriate position.
- `under`
- : Forces the line to be set below the alphabetic baseline, at a position where it won't cross any descenders. This is useful for ensuring legibility with chemical and mathematical formulas, which make a large use of subscripts.
- `left`
- : In vertical writing-modes, this keyword forces the line to be placed on the _left_ side of the text. In horizontal writing-modes, it is a synonym of `auto`.
- `right`
- : In vertical writing-modes, this keyword forces the line to be placed on the _right_ side of the text. In horizontal writing-modes, it is a synonym of `auto`.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### A simple example
Let's take a couple of simple example paragraphs:
```html
<p class="horizontal">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam consectetur ac
turpis vel laoreet. Nullam volutpat pharetra lorem, sit amet feugiat tortor
volutpat quis. Nam eget sodales quam. Aliquam accumsan tellus ac erat posuere.
</p>
<p class="vertical">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam consectetur ac
turpis vel laoreet. Nullam volutpat pharetra lorem, sit amet feugiat tortor
volutpat quis. Nam eget sodales quam. Aliquam accumsan tellus ac erat posuere.
</p>
```
Our CSS looks like this:
```css
p {
font-size: 1.5rem;
text-transform: capitalize;
text-decoration: underline;
text-decoration-thickness: 2px;
}
.horizontal {
text-underline-position: under;
}
.vertical {
writing-mode: vertical-rl;
text-underline-position: left;
}
```
In this example we set both the paragraphs to have a thick underline. In the horizontal text we use `text-underline-position: under;` to put the underline below all the descenders.
In the text with a vertical [`writing-mode`](/en-US/docs/Web/CSS/writing-mode) set, we can then use values of `left` or `right` to make the underline appear on the left or right of the text as required.
The live example looks like this:
{{EmbedLiveSample('A_simple_example', '100%', 600)}}
### Setting text-underline-position globally
Because the `text-underline-position` property inherits and is not reset by the {{cssxref("text-decoration")}} shorthand property, it may be appropriate to set its value at a global level. For example, the `under` value may be appropriate for a document with lots of chemical and mathematical formulas, which make a large use of subscripts.
```css
:root {
text-underline-position: under;
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- The {{cssxref("text-decoration")}} property is a shorthand for setting most text-decoration properties, including {{cssxref("text-decoration-line")}}, {{cssxref("text-decoration-color")}}, and {{cssxref("text-decoration-style")}}. However, it does not set `text-underline-position`.
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_visited/index.md | ---
title: ":visited"
slug: Web/CSS/:visited
page-type: css-pseudo-class
browser-compat: css.selectors.visited
---
{{CSSRef}}
The **`:visited`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) applies once the link has been visited by the user. For privacy reasons, the styles that can be modified using this selector are very limited. The `:visited` pseudo-class applies only to {{htmlelement("a")}} and {{htmlelement("area")}} elements that have an `href` attribute.
{{EmbedInteractiveExample("pages/tabbed/pseudo-class-visited.html", "tabbed-shorter")}}
Styles defined by the `:visited` and unvisited [`:link`](/en-US/docs/Web/CSS/:link) pseudo-classes can be overridden by any subsequent user-action pseudo-classes ({{cssxref(":hover")}} or {{cssxref(":active")}}) that have at least equal specificity. To style links appropriately, put the `:visited` rule after the `:link` rule but before the `:hover` and `:active` rules, as defined by the _LVHA-order_: `:link` — `:visited` — `:hover` — `:active`. The `:visited` pseudo-class and `:link` pseudo-class are mutually exclusive.
## Privacy restrictions
For privacy reasons, browsers strictly limit which styles you can apply using this pseudo-class, and how they can be used:
- Allowable CSS properties are {{ cssxref("color") }}, {{ cssxref("background-color") }}, {{ cssxref("border-color") }}, {{ cssxref("border-bottom-color") }}, {{ cssxref("border-left-color") }}, {{ cssxref("border-right-color") }}, {{ cssxref("border-top-color") }}, {{ cssxref("column-rule-color") }}, {{ cssxref("outline-color") }}, {{ cssxref("text-decoration-color") }}, and {{ cssxref("text-emphasis-color") }}.
- Allowable SVG attributes are {{SVGAttr("fill")}} and {{SVGAttr("stroke")}}.
- The alpha component of the allowed styles will be ignored. The alpha component of the element's non-`:visited` state will be used instead. In Firefox when the alpha component is `0`, the style set in `:visited` will be ignored entirely.
- Although these styles can change the appearance of colors to the end user, the {{domxref("window.getComputedStyle")}} method will lie and always return the value of the non-`:visited` color.
- The [`<link>`](/en-US/docs/Web/HTML/Element/link) element is never matched by `:visited`.
> **Note:** For more information on these limitations and the reasons behind them, see [Privacy and the :visited selector](/en-US/docs/Web/CSS/Privacy_and_the_:visited_selector).
## Syntax
```css
:visited {
/* ... */
}
```
## Examples
Properties that would otherwise have no color or be transparent cannot be modified with `:visited`. Of the properties that can be set with this pseudo-class, your browser probably has a default value for `color` and `column-rule-color` only. Thus, if you want to modify the other properties, you'll need to give them a base value outside the `:visited` selector.
### HTML
```html
<a href="#test-visited-link">Have you visited this link yet?</a><br />
<a href="">You've already visited this link.</a>
```
### CSS
```css
a {
/* Specify non-transparent defaults to certain properties,
allowing them to be styled with the :visited state */
background-color: white;
border: 1px solid white;
}
a:visited {
background-color: yellow;
border-color: hotpink;
color: hotpink;
}
```
### Result
{{EmbedLiveSample("Examples")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Privacy and the :visited selector](/en-US/docs/Web/CSS/Privacy_and_the_:visited_selector)
- Link-related pseudo-classes: {{cssxref(":link")}}, {{cssxref(":active")}}, {{cssxref(":hover")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/padding-block-start/index.md | ---
title: padding-block-start
slug: Web/CSS/padding-block-start
page-type: css-property
browser-compat: css.properties.padding-block-start
---
{{CSSRef}}
The **`padding-block-start`** [CSS](/en-US/docs/Web/CSS) property defines the logical block start padding of an element, which maps to a physical padding depending on the element's writing mode, directionality, and text orientation.
{{EmbedInteractiveExample("pages/css/padding-block-start.html")}}
## Syntax
```css
/* <length> values */
padding-block-start: 10px; /* An absolute length */
padding-block-start: 1em; /* A length relative to the text size */
/* <percentage> value */
padding-block-start: 5%; /* A padding relative to the block container's width */
/* Global values */
padding-block-start: inherit;
padding-block-start: initial;
padding-block-start: revert;
padding-block-start: revert-layer;
padding-block-start: unset;
```
### Values
- {{cssxref("<length>")}}
- : The size of the padding as a fixed value. Must be nonnegative.
- {{cssxref("<percentage>")}}
- : The size of the padding as a percentage, relative to the [inline-size](/en-US/docs/Web/CSS/CSS_flow_layout/Block_and_inline_layout_in_normal_flow) (_width_ in a horizontal language) of the [containing block](/en-US/docs/Web/CSS/Containing_block). Must be nonnegative.
## Description
The `padding-block-start` property is defined in the specification as taking the same values as the {{cssxref("padding-top")}} property. However, the physical property it maps to depends on the values set for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. Therefore, it could map to {{cssxref("padding-bottom")}}, {{cssxref("padding-right")}}, or {{cssxref("padding-left")}}.
It relates to {{cssxref("padding-block-end")}}, {{cssxref("padding-inline-start")}}, and {{cssxref("padding-inline-end")}}, which define the other paddings of the element.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting block start 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-lr;
padding-block-start: 20px;
background-color: #c8c800;
}
```
#### Result
{{EmbedLiveSample("Setting_block_start_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/background-attachment/index.md | ---
title: background-attachment
slug: Web/CSS/background-attachment
page-type: css-property
browser-compat: css.properties.background-attachment
---
{{CSSRef}}
The **`background-attachment`** [CSS](/en-US/docs/Web/CSS) property sets whether a background image's position is fixed within the {{glossary("viewport")}}, or scrolls with its containing block.
{{EmbedInteractiveExample("pages/css/background-attachment.html")}}
## Syntax
```css
/* Keyword values */
background-attachment: scroll;
background-attachment: fixed;
background-attachment: local;
/* Global values */
background-attachment: inherit;
background-attachment: initial;
background-attachment: revert;
background-attachment: revert-layer;
background-attachment: unset;
```
The `background-attachment` property is specified as one of the keyword values from the list below.
### Values
- `fixed`
- : The background is fixed relative to the viewport. Even if an element has a scrolling mechanism, the background doesn't move with the element. (This is not compatible with {{cssxref("background-clip", "background-clip: text", "#values")}}.)
- `local`
- : The background is fixed relative to the element's contents. If the element has a scrolling mechanism, the background scrolls with the element's contents, and the background painting area and background positioning area are relative to the scrollable area of the element rather than to the border framing them.
- `scroll`
- : The background is fixed relative to the element itself and does not scroll with its contents. (It is effectively attached to the element's border.)
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Simple example
#### HTML
```html
<p>
There were doors all round the hall, but they were all locked; and when Alice
had been all the way down one side and up the other, trying every door, she
walked sadly down the middle, wondering how she was ever to get out again.
</p>
```
#### CSS
```css
p {
background-image: url("starsolid.gif");
background-attachment: fixed;
}
```
#### Result
{{EmbedLiveSample("Simple_example")}}
### Multiple background images
This property supports multiple background images. You can specify a different `<attachment>` for each background, separated by commas. Each image is matched with the corresponding `<attachment>` type, from first specified to last.
#### HTML
```html
<p>
There were doors all round the hall, but they were all locked; and when Alice
had been all the way down one side and up the other, trying every door, she
walked sadly down the middle, wondering how she was ever to get out again.
Suddenly she came upon a little three-legged table, all made of solid glass;
there was nothing on it except a tiny golden key, and Alice's first thought
was that it might belong to one of the doors of the hall; but, alas! either
the locks were too large, or the key was too small, but at any rate it would
not open any of them. However, on the second time round, she came upon a low
curtain she had not noticed before, and behind it was a little door about
fifteen inches high: she tried the little golden key in the lock, and to her
great delight it fitted!
</p>
```
#### CSS
```css
p {
background-image: url("starsolid.gif"), url("startransparent.gif");
background-attachment: fixed, scroll;
background-repeat: no-repeat, repeat-y;
}
```
#### Result
{{EmbedLiveSample("Multiple_background_images")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Using multiple backgrounds](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders/Using_multiple_backgrounds)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/css_namespaces/index.md | ---
title: CSS namespaces
slug: Web/CSS/CSS_namespaces
page-type: css-module
browser-compat: css.at-rules.namespace
---
{{CSSRef}}
The **CSS namespaces** module defines the syntax for using {{glossary("namespace", "namespaces")}} in CSS.
CSS isn't just for styling HTML. A stylesheet may be used to style SVG, MathML, XML, or HTML, each of which has a different namespace or a document containing multiple namespaces.
The [`@namespace`](/en-US/docs/Web/CSS/@namespace) at-rule defined in this module enables distinguishing between same-named elements in different namespaces. Element tag names are not unique to a single language. For example, the `<a>` element isn't limited to HTML. You may want to style the `<a>`s within your SVGs differently from the links in your HTML. You also will likely want to ensure that {{domxref("Document.querySelectorAll", "querySelectorAll(\"a\")")}} selects the right kind of element. Namespacing can help.
The `@namespace` rule is used for declaring a default namespace and for binding namespaces to namespace prefixes. The namespaces module also defines the syntax for using these prefixes to represent namespace-qualified names. That's it. What a name means or if the name is even valid depends on the context and host language.
## Reference
### At-rules
- {{cssxref("@namespace")}}
## Guides
- [Namespaces crash course](/en-US/docs/Web/SVG/Namespaces_Crash_Course)
- : Deep dive into what a namespace is and how they are used in XML and XML-based markup languages.
## Related concepts
- CSS [namespace separator (`|`)](/en-US/docs/Web/CSS/Namespace_separator) combinator
- CSS [type selectors](/en-US/docs/Web/CSS/Type_selectors)
- CSS [universal selector](/en-US/docs/Web/CSS/Universal_selectors)
- {{DOMXRef("CSSNamespaceRule")}} interface
- {{DOMXRef("CSSNamespaceRule.namespaceURI")}} property
- {{DOMXRef("CSSNamespaceRule.prefix")}} property
- [`Document.createAttributeNS()`](/en-US/docs/Web/API/Document/createAttributeNS) method
- [`Document.createElementNS()`](/en-US/docs/Web/API/Document/createElementNS) method
- [`Document.getElementsByTagNameNS()`](/en-US/docs/Web/API/Document/getElementsByTagNameNS) method
- [`Element.getAttributeNodeNS()`](/en-US/docs/Web/API/Element/getAttributeNodeNS) method
- [`Element.getAttributeNS()`](/en-US/docs/Web/API/Element/getAttributeNS) method
- [`Element.getElementsByTagNameNS()`](/en-US/docs/Web/API/Element/getElementsByTagNameNS) method
- [`Element.hasAttributeNS()`](/en-US/docs/Web/API/Element/hasAttributeNS) method
- [`Element.namespaceURI`](/en-US/docs/Web/API/Element/namespaceURI) property
- [`Element.removeAttributeNS()`](/en-US/docs/Web/API/Element/removeAttributeNS) method
- [`Element.setAttributeNS()`](/en-US/docs/Web/API/Element/setAttributeNS) method
- [`Element.setAttributeNodeNS()`](/en-US/docs/Web/API/Element/setAttributeNodeNS) method
- [`NamedNodeMap.getNamedItemNS()`](/en-US/docs/Web/API/NamedNodeMap/getNamedItemNS) method
- [`NamedNodeMap.removeNamedItemNS()`](/en-US/docs/Web/API/NamedNodeMap/removeNamedItemNS) method
- [`NamedNodeMap.setNamedItemNS()`](/en-US/docs/Web/API/NamedNodeMap/setNamedItemNS) method
- {{glossary("Namespace")}} glossary term
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [`<a>`](/en-US/docs/Web/SVG/Element/a#example) SVG element
- [CSS `url()` function](/en-US/docs/Web/CSS/url)
- [CSS at-rules](/en-US/docs/Web/CSS/At-rule)
- [CSS at-rule functions](/en-US/docs/Web/CSS/At-rule-functions)
- [CSS selectors](/en-US/docs/Web/CSS/CSS_selectors)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/border-color/index.md | ---
title: border-color
slug: Web/CSS/border-color
page-type: css-shorthand-property
browser-compat: css.properties.border-color
---
{{CSSRef}}
The **`border-color`** [shorthand](/en-US/docs/Web/CSS/Shorthand_properties) [CSS](/en-US/docs/Web/CSS) property sets the color of an element's border.
{{EmbedInteractiveExample("pages/css/border-color.html")}}
Each side can be set individually using {{CSSxRef("border-top-color")}}, {{CSSxRef("border-right-color")}}, {{CSSxRef("border-bottom-color")}}, and {{CSSxRef("border-left-color")}}; or using the writing mode-aware {{CSSxRef("border-block-start-color")}}, {{CSSxRef("border-block-end-color")}}, {{CSSxRef("border-inline-start-color")}}, and {{CSSxRef("border-inline-end-color")}}.
You can find more information about border colors in [CSS colors](/en-US/docs/Web/CSS/CSS_colors/Applying_color#borders_2).
## Constituent properties
This property is a shorthand for the following CSS properties:
- [`border-bottom-color`](/en-US/docs/Web/CSS/border-bottom-color)
- [`border-left-color`](/en-US/docs/Web/CSS/border-left-color)
- [`border-right-color`](/en-US/docs/Web/CSS/border-right-color)
- [`border-top-color`](/en-US/docs/Web/CSS/border-top-color)
## Syntax
```css
/* <color> values */
border-color: red;
/* top and bottom | left and right */
border-color: red #f015ca;
/* top | left and right | bottom */
border-color: red rgb(240 30 50 / 70%) green;
/* top | right | bottom | left */
border-color: red yellow green blue;
/* Global values */
border-color: inherit;
border-color: initial;
border-color: revert;
border-color: revert-layer;
border-color: unset;
```
The `border-color` property may be specified using one, two, three, or four values.
- When **one** value is specified, it applies the same color to **all four sides**.
- When **two** values are specified, the first color applies to the **top and bottom**, the second to the **left and right**.
- When **three** values are specified, the first color applies to the **top**, the second to the **left and right**, the third to the **bottom**.
- When **four** values are specified, the colors apply to the **top**, **right**, **bottom**, and **left** in that order (clockwise).
### Values
- {{CSSxRef("<color>")}}
- : Defines the color of the border.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Complete border-color usage
#### HTML
```html
<div id="justone">
<p><code>border-color: red;</code> is equivalent to</p>
<ul>
<li><code>border-top-color: red;</code></li>
<li><code>border-right-color: red;</code></li>
<li><code>border-bottom-color: red;</code></li>
<li><code>border-left-color: red;</code></li>
</ul>
</div>
<div id="horzvert">
<p><code>border-color: gold red;</code> is equivalent to</p>
<ul>
<li><code>border-top-color: gold;</code></li>
<li><code>border-right-color: red;</code></li>
<li><code>border-bottom-color: gold;</code></li>
<li><code>border-left-color: red;</code></li>
</ul>
</div>
<div id="topvertbott">
<p><code>border-color: red cyan gold;</code> is equivalent to</p>
<ul>
<li><code>border-top-color: red;</code></li>
<li><code>border-right-color: cyan;</code></li>
<li><code>border-bottom-color: gold;</code></li>
<li><code>border-left-color: cyan;</code></li>
</ul>
</div>
<div id="trbl">
<p><code>border-color: red cyan black gold;</code> is equivalent to</p>
<ul>
<li><code>border-top-color: red;</code></li>
<li><code>border-right-color: cyan;</code></li>
<li><code>border-bottom-color: black;</code></li>
<li><code>border-left-color: gold;</code></li>
</ul>
</div>
```
#### CSS
```css
#justone {
border-color: red;
}
#horzvert {
border-color: gold red;
}
#topvertbott {
border-color: red cyan gold;
}
#trbl {
border-color: red cyan black gold;
}
/* Set width and style for all divs */
div {
border: solid 0.3em;
width: auto;
margin: 0.5em;
padding: 0.5em;
}
ul {
margin: 0;
list-style: none;
}
```
#### Result
{{EmbedLiveSample("Complete_border-color_usage", 600, 700)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- Border-color related CSS properties: {{CSSxRef("border")}}, {{CSSxRef("border-top-color")}}, {{CSSxRef("border-right-color")}}, {{CSSxRef("border-bottom-color")}}, {{CSSxRef("border-left-color")}},
- Other border-related CSS properties: {{CSSxRef("border-width")}}, {{CSSxRef("border-style")}}
- The {{CSSxRef("<color>")}} data type
- Other color-related properties: {{CSSxRef("color")}}, {{CSSxRef("background-color")}}, {{CSSxRef("outline-color")}}, {{CSSxRef("text-decoration-color")}}, {{CSSxRef("text-emphasis-color")}}, {{CSSxRef("text-shadow")}}, {{CSSxRef("caret-color")}}, and {{CSSxRef("column-rule-color")}}
- [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/pointer-events/index.md | ---
title: pointer-events
slug: Web/CSS/pointer-events
page-type: css-property
browser-compat: css.properties.pointer-events
---
{{CSSRef}}
The **`pointer-events`** [CSS](/en-US/docs/Web/CSS) property sets under what circumstances (if any) a particular graphic element can become the [target](/en-US/docs/Web/API/Event/target) of pointer events.
{{EmbedInteractiveExample("pages/css/pointer-events.html")}}
## Syntax
```css
/* Keyword values */
pointer-events: auto;
pointer-events: none;
pointer-events: visiblePainted; /* SVG only */
pointer-events: visibleFill; /* SVG only */
pointer-events: visibleStroke; /* SVG only */
pointer-events: visible; /* SVG only */
pointer-events: painted; /* SVG only */
pointer-events: fill; /* SVG only */
pointer-events: stroke; /* SVG only */
pointer-events: all; /* SVG only */
/* Global values */
pointer-events: inherit;
pointer-events: initial;
pointer-events: revert;
pointer-events: revert-layer;
pointer-events: unset;
```
The `pointer-events` property is specified as a single keyword chosen from the list of values below.
### Values
- `auto`
- : The element behaves as it would if the `pointer-events` property were not specified. In SVG content, this value and the value `visiblePainted` have the same effect.
- `none`
- : The element is never the [target](/en-US/docs/Web/API/Event/target) of pointer events; however, pointer events may target its descendant elements if those descendants have `pointer-events` set to some other value. In these circumstances, pointer events will trigger event listeners on this parent element as appropriate on their way to/from the descendant during the event capture/[bubble](/en-US/docs/Web/API/Event/bubbles) phases.
#### SVG only (experimental for HTML)
- `visiblePainted`
- : SVG only (experimental for HTML). The element can only be the target of a pointer event when the `visibility` property is set to `visible` and e.g. when a mouse cursor is over the interior (i.e., 'fill') of the element and the `fill` property is set to a value other than `none`, or when a mouse cursor is over the perimeter (i.e., 'stroke') of the element and the `stroke` property is set to a value other than `none`.
- `visibleFill`
- : SVG only. The element can only be the target of a pointer event when the `visibility` property is set to `visible` and when e.g. a mouse cursor is over the interior (i.e., fill) of the element. The value of the `fill` property does not affect event processing.
- `visibleStroke`
- : SVG only. The element can only be the target of a pointer event when the `visibility` property is set to `visible` and e.g. when the mouse cursor is over the perimeter (i.e., stroke) of the element. The value of the `stroke` property does not affect event processing.
- `visible`
- : SVG only (experimental for HTML). The element can be the target of a pointer event when the `visibility` property is set to `visible` and e.g. the mouse cursor is over either the interior (i.e., fill) or the perimeter (i.e., stroke) of the element. The values of the `fill` and `stroke` do not affect event processing.
- `painted`
- : SVG only (experimental for HTML). The element can only be the target of a pointer event when e.g. the mouse cursor is over the interior (i.e., 'fill') of the element and the `fill` property is set to a value other than `none`, or when the mouse cursor is over the perimeter (i.e., 'stroke') of the element and the `stroke` property is set to a value other than `none`. The value of the `visibility` property does not affect event processing.
- `fill`
- : SVG only. The element can only be the target of a pointer event when the pointer is over the interior (i.e., fill) of the element. The values of the `fill` and `visibility` properties do not affect event processing.
- `stroke`
- : SVG only. The element can only be the target of a pointer event when the pointer is over the perimeter (i.e., stroke) of the element. The values of the `stroke` and `visibility` properties do not affect event processing.
- `all`
- : SVG only (experimental for HTML). The element can only be the target of a pointer event when the pointer is over the interior (i.e., fill) or the perimeter (i.e., stroke) of the element. The values of the `fill`, `stroke`, and `visibility` properties do not affect event processing.
## Description
When this property is unspecified, the same characteristics of the `visiblePainted` value apply to SVG content.
In addition to indicating that the element is not the target of pointer events, the value `none` instructs the pointer event to go "through" the element and target whatever is "underneath" that element instead.
Note that preventing an element from being the target of pointer events by using `pointer-events` does _not_ necessarily mean that pointer event listeners on that element _cannot_ or _will not_ be triggered. If one of the element's children has `pointer-events` explicitly set to _allow_ that child to be the target of pointer events, then any events targeting that child will pass through the parent as the event travels along the parent chain, and trigger event listeners on the parent as appropriate. Of course any pointer activity at a point on the screen that is covered by the parent but not by the child will not be caught by either the child or the parent (it will go "through" the parent and target whatever is underneath).
Elements with `pointer-events: none` will still receive focus through sequential keyboard navigation using the <kbd>Tab</kbd> key.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Disabling pointer events on all images
This example disables pointer events (clicking, dragging, hovering, etc.) on all images.
```css
img {
pointer-events: none;
}
```
### Disabling pointer events on a single link
This example disables pointer events on the link to `http://example.com`.
#### HTML
```html
<ul>
<li><a href="https://developer.mozilla.org">MDN</a></li>
<li><a href="http://example.com">example.com</a></li>
</ul>
```
#### CSS
```css
a[href="http://example.com"]
{
pointer-events: none;
}
```
#### Result
{{EmbedLiveSample("Disabling_pointer_events_on_a_single_link", "500", "100")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- The SVG attribute {{SVGAttr("pointer-events")}}
- The SVG attribute {{SVGAttr("visibility")}}
- The {{domxref("PointerEvent")}} API
- [WebKit Specs PointerEventsProperty](https://webkit.org/specs/PointerEventsProperty.html) extended for use in (X)HTML content
- {{cssxref("user-select")}} - controls whether the user can select text
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/css_basic_user_interface/index.md | ---
title: CSS basic user interface
slug: Web/CSS/CSS_basic_user_interface
page-type: css-module
spec-urls: https://drafts.csswg.org/css-ui/
---
{{CSSRef}}
The **CSS basic user interface** module lets you define the rendering and functionality of features related to the user interface including outline properties, visual feedback to pointing device and keyboard, and altering the default appearance of UI widgets.
Basic user interface properties can be used to improve user experience and accessibility by providing visual cues to elements that are being interacted with, including styling mouse cursors and keyboard directional focus navigation, and styling caret cursors when an editable element has focus. The module provides for providing outlines to focused (or not) elements without impacting an element's [box model](/en-US/docs/Learn/CSS/Building_blocks/The_box_model#what_is_the_css_box_model) dimensions and styling. This UI module also enables the styling of user interface controls.
### Basic user interface in action
To view how basic user interface properties can alter the appearance of UI features, interact with the elements in this sample. Note that some features in this sample improve usability while others harm user experience.
{{EmbedGHLiveSample("css-examples/modules/basicUI.html", '100%', 320)}}
The CSS {{CSSxRef("outline")}} and {{CSSxRef("outline-offset")}} properties were used to provide feedback to users which element currently has focus. An {{CSSxRef("accent-color")}} provides a theme color to all the form controls. The caret that appears when the text is edit has the same color thanks to the {{CSSxRef("caret-color")}} property. These can all be considered UI improvements.
Some features harm usability. The {{CSSxRef("cursor")}} property was used to change cursors from the browser default which is confusing. The {{CSSxRef("resize")}} property prevents the second {{HTMLElement("textarea")}} from being resizable while the {{CSSxRef("pointer-events")}} property prevents the third `<textarea>` from receiving click events. It is still focusable using the keyboard.
To see the code for this basic user interface sample, [view the source on GitHub](https://github.com/mdn/css-examples/blob/main/modules/basicUI.html).
## Reference
### Properties
- {{CSSxRef("accent-color")}}
- {{CSSxRef("appearance")}}
- {{CSSxRef("caret")}}, shorthand for:
- {{CSSxRef("caret-color")}}
- {{CSSxRef("caret-shape")}}
- {{CSSxRef("cursor")}}
- {{CSSxRef("nav-down")}} {{Experimental_Inline}}
- {{CSSxRef("nav-left")}} {{Experimental_Inline}}
- {{CSSxRef("nav-right")}} {{Experimental_Inline}}
- {{CSSxRef("nav-up")}} {{Experimental_Inline}}
- {{CSSxRef("outline")}}, shorthand for:
- {{CSSxRef("outline-color")}}
- {{CSSxRef("outline-style")}}
- {{CSSxRef("outline-width")}}
- {{CSSxRef("outline-offset")}}
- {{CSSxRef("pointer-events")}}
- {{CSSxRef("resize")}}
- {{CSSxRef("user-select")}}
## Guides
- [Learn forms: advanced form styling](/en-US/docs/Learn/Forms/Advanced_form_styling)
- : Explains how {{CSSxRef("appearance")}} can be used to style form controls.
## Related concepts
- CSS [`cursor`](/en-US/docs/Web/CSS/cursor) property
- SVG [`cursor`](/en-US/docs/Web/SVG/Attribute/cursor) attribute
- CSS {{CSSxRef(":focus")}}, {{CSSxRef(":focus-within")}}, and {{CSSxRef(":focus-visible")}} pseudoclasses
- {{DOMXref("CaretPosition")}} Interface
## Specifications
{{Specifications}}
## See also
- [Tips for Designing Useful and Usable Focus Indicators](https://www.deque.com/blog/give-site-focus-tips-designing-usable-focus-indicators/) (2016)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_disabled/index.md | ---
title: ":disabled"
slug: Web/CSS/:disabled
page-type: css-pseudo-class
browser-compat: css.selectors.disabled
---
{{CSSRef}}
The **`:disabled`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents any disabled element. An element is disabled if it can't be activated (selected, clicked on, typed into, etc.) or accept focus. The element also has an enabled state, in which it can be activated or accept focus.
{{EmbedInteractiveExample("pages/tabbed/pseudo-class-disabled.html", "tabbed-standard")}}
## Syntax
```css
:disabled {
/* ... */
}
```
## Examples
This example shows a basic shipping form. It uses the [JavaScript](/en-US/docs/Web/JavaScript) {{domxref("HTMLElement/change_event", "change")}} event to let the user enable/disable the billing fields.
### HTML
```html
<form action="#">
<fieldset id="shipping">
<legend>Shipping address</legend>
<input type="text" placeholder="Name" />
<input type="text" placeholder="Address" />
<input type="text" placeholder="Zip Code" />
</fieldset>
<br />
<fieldset id="billing">
<legend>Billing address</legend>
<label for="billing-checkbox">Same as shipping address:</label>
<input type="checkbox" id="billing-checkbox" checked />
<br />
<input type="text" placeholder="Name" disabled />
<input type="text" placeholder="Address" disabled />
<input type="text" placeholder="Zip Code" disabled />
</fieldset>
</form>
```
### CSS
```css
input[type="text"]:disabled {
background: #ccc;
}
```
### JavaScript
```js
// Wait for the page to finish loading
document.addEventListener(
"DOMContentLoaded",
() => {
// Attach `change` event listener to checkbox
document.getElementById("billing-checkbox").onchange = toggleBilling;
},
false,
);
function toggleBilling() {
// Select the billing text fields
const billingItems = document.querySelectorAll('#billing input[type="text"]');
// Toggle the billing text fields
billingItems.forEach((item) => {
item.disabled = !item.disabled;
});
}
```
### Result
{{EmbedLiveSample('Examples', 300, 250)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{Cssxref(":enabled")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/layout_cookbook/index.md | ---
title: CSS Layout cookbook
slug: Web/CSS/Layout_cookbook
page-type: landing-page
---
{{CSSRef}}
The CSS layout cookbook aims to bring together recipes for common layout patterns, things you might need to implement in your own sites. In addition to providing code you can use as a starting point in your projects, these recipes highlight the different ways layout specifications can be used, and the choices you can make as a developer.
> **Note:** If you are new to CSS layout then you might first like to take a look at our [CSS layout learning module](/en-US/docs/Learn/CSS/CSS_layout), as this will give you the basic grounding you need to make use of the recipes here.
## The Recipes
| Recipe | Description | Layout Methods |
| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [Media objects](/en-US/docs/Web/CSS/Layout_cookbook/Media_objects) | A two-column box with an image on one side and descriptive text on the other, e.g. a facebook post or tweet. | [CSS Grid](/en-US/docs/Web/CSS/CSS_grid_layout), {{cssxref("float")}} fallback, {{cssxref("fit-content")}} sizing |
| [Columns](/en-US/docs/Web/CSS/Layout_cookbook/Column_layouts) | When to choose multi-column layout, flexbox or grid for your columns. | [CSS Grid](/en-US/docs/Web/CSS/CSS_grid_layout), [Multicol](/en-US/docs/Web/CSS/CSS_multicol_layout), [Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout) |
| [Center an element](/en-US/docs/Web/CSS/Layout_cookbook/Center_an_element) | How to center an item horizontally and vertically. | [Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout), [Box Alignment](/en-US/docs/Web/CSS/CSS_box_alignment) |
| [Sticky footers](/en-US/docs/Web/CSS/Layout_cookbook/Sticky_footers) | Creating a footer which sits at the bottom of the container or viewport when the content is shorter. | [CSS Grid](/en-US/docs/Web/CSS/CSS_grid_layout), [Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout) |
| [Split navigation](/en-US/docs/Web/CSS/Layout_cookbook/Split_Navigation) | A navigation pattern where some links are visually separated from the others. | [Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout), {{cssxref("margin")}} |
| [Breadcrumb navigation](/en-US/docs/Web/CSS/Layout_cookbook/Breadcrumb_Navigation) | Creating a list of links to allow the visitor to navigate back up through the page hierarchy. | [Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout) |
| [List group with badges](/en-US/docs/Web/CSS/Layout_cookbook/List_group_with_badges) | A list of items with a badge to display a count. | [Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout), [Box Alignment](/en-US/docs/Web/CSS/CSS_box_alignment) |
| [Pagination](/en-US/docs/Web/CSS/Layout_cookbook/Pagination) | Links to pages of content (such as search results). | [Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout), [Box Alignment](/en-US/docs/Web/CSS/CSS_box_alignment) |
| [Card](/en-US/docs/Web/CSS/Layout_cookbook/Card) | A card component, which displays in a grid of cards. | [Grid Layout](/en-US/docs/Web/CSS/CSS_grid_layout) |
| [Grid wrapper](/en-US/docs/Web/CSS/Layout_cookbook/Grid_wrapper) | For aligning grid content within a central wrapper, while also allowing items to break out. | [CSS Grid](/en-US/docs/Web/CSS/CSS_grid_layout) |
## Contribute a Recipe
As with all of MDN we would love you to contribute a recipe in the same format as the ones shown above. See the [guide for adding Layout Cookbook recipes](/en-US/docs/Web/CSS/Layout_cookbook/Contribute_a_recipe) for a template and guidelines for writing your own example.
| 0 |
data/mdn-content/files/en-us/web/css/layout_cookbook | data/mdn-content/files/en-us/web/css/layout_cookbook/pagination/index.md | ---
title: Pagination
slug: Web/CSS/Layout_cookbook/Pagination
page-type: guide
browser-compat: css.properties.flex
---
{{CSSRef}}
This cookbook pattern demonstrates the navigation pattern used to display pagination, where the user can move between pages of content such as search results.

## Requirements
The pagination pattern typically displays items in a row. To ensure that the pagination is understandable by people using a screen reader, we mark the items up as a list inside a {{htmlelement("nav")}} element, and then use CSS to display the layout visually as a row.
Typically, the pagination component will be centered horizontally underneath the content.
## Recipe
{{EmbedGHLiveSample("css-examples/css-cookbook/pagination.html", '100%', 720)}}
> **Callout:**
>
> [Download this example](https://github.com/mdn/css-examples/blob/main/css-cookbook/pagination--download.html)
## Choices made
This pattern is laid out using [flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout) — one flex container nested inside another. The {{htmlelement("nav")}} element is designated a flex container in order that we can center the list inside using the {{cssxref("justify-content")}} property.
The list itself also becomes a flex container to lay the items out as a row. To space the items out we can either use a {{cssxref("margin")}} on the flex items or add a {{cssxref("gap")}} on the flex container.
```css
.pagination {
list-style: none;
margin: 0;
padding: 0;
display: flex;
gap: 2px;
}
```
## Accessibility concerns
We want to ensure that a person using a screen reader understands what this navigation does, and where they will go when clicking a link. To help with this we have added [`aria-label="pagination"`](/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label) on the `<nav>` element.
We have also added some additional content that would be read by a screen reader but is hidden visually, and set the [`aria-hidden`](/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-hidden) attribute on the paging arrows.
The "See Also" section at the end of this document has links to related accessibility topics.
## Specifications
{{Specifications}}
## See also
- {{Cssxref("justify-content")}}, {{Cssxref("gap")}}
- [Know your ARIA: 'hidden' vs 'none'](https://www.scottohara.me/blog/2018/05/05/hidden-vs-none.html) (2018)
- [Invisible content just for screen reader users](https://webaim.org/techniques/css/invisiblecontent/#techniques) via WebAIM.org (2020)
- [Writing CSS with accessibility in mind](https://medium.com/@matuzo/writing-css-with-accessibility-in-mind-8514a0007939) (2017)
- [a11y style guide: pagination](https://a11y-style-guide.com/style-guide/section-navigation.html#kssref-navigation-pagination)
| 0 |
data/mdn-content/files/en-us/web/css/layout_cookbook | data/mdn-content/files/en-us/web/css/layout_cookbook/grid_wrapper/index.md | ---
title: Grid wrapper
slug: Web/CSS/Layout_cookbook/Grid_wrapper
page-type: guide
browser-compat: css.properties.grid
---
{{CSSRef}}
The grid wrapper pattern is useful for aligning grid content within a central wrapper while also allowing items to break out and align to the edge of the containing element or page.
## Requirements
Items placed on the grid should be able to align to a horizontally-centered max-width wrapper or the outer edges of the grid, or both.
## Recipe
{{EmbedGHLiveSample("css-examples/css-cookbook/grid-wrapper.html", '100%', 1100)}}
> **Callout:**
>
> [Download this example](https://github.com/mdn/css-examples/blob/main/css-cookbook/grid-wrapper--download.html)
## Choices made
This recipe uses the CSS grid {{cssxref("minmax", "minmax()")}} function to define the grid track sizes in the {{cssxref("grid-template-columns")}} property. For the central columns with a maximum width, we can set a minimum value of `0` or greater and a maximum value that specifies the maximum size the column tracks will grow to. Using [relative](/en-US/docs/Web/CSS/length#relative_length_units_based_on_font) or [absolute](/en-US/docs/Web/CSS/length#absolute_length_units) {{cssxref("length")}} units (pixels, ems, rems) will create a fixed maximum size for the central wrapper, whereas using {{cssxref("percentage")}} values or [viewport units](/en-US/docs/Web/CSS/length#relative_length_units_based_on_viewport) will cause the wrapper to grow or shrink in response to its context.
The outer two columns have a maximum size of `1fr`, meaning that they will each expand to fill the remaining available space in the grid container.
## Useful fallbacks or alternative methods
To center the grid horizontally on the page you can set a `max-width` along with left and right `auto` {{cssxref("margin")}}s:
```css
.grid {
max-width: 96vw; /* Limits the width to 96% of the width of the viewport */
margin: 0 auto; /* horizontally centers the container */
}
```
## Accessibility concerns
Although CSS grid enables positioning items anywhere (within reason), ensuring that your underlying markup follows a logical order is important (see [CSS Grid layout and accessibility](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_layout_and_accessibility) for more details).
## See also
- {{Cssxref("grid-template-columns")}} property
- [CSS grid layout](/en-US/docs/Web/CSS/CSS_grid_layout) module
- [CSS Grid: More flexibility with minmax()](https://css-irl.info/more-flexibility-with-minmax/) (2018)
- [Breaking out with CSS grid](https://rachelandrew.co.uk/archives/2017/06/01/breaking-out-with-css-grid-explained/) (2017)
| 0 |
data/mdn-content/files/en-us/web/css/layout_cookbook | data/mdn-content/files/en-us/web/css/layout_cookbook/breadcrumb_navigation/index.md | ---
title: Breadcrumb navigation
slug: Web/CSS/Layout_cookbook/Breadcrumb_Navigation
page-type: guide
browser-compat: css.properties.flex
---
{{CSSRef}}
Breadcrumb navigation helps the user to understand their location in the website by providing a {{glossary("breadcrumb")}} trail back to the start page. The items typically display inline, with a separator between each item, indicating the hierarchy between individual pages.

## Requirements
Display the hierarchy of the site by displaying inline links, with a separator between the items, indicating the hierarchy between individual pages, with the current page appearing last.
## Recipe
{{EmbedGHLiveSample("css-examples/css-cookbook/breadcrumb-navigation.html", '100%', 530)}}
> **Callout:**
>
> [Download this example](https://github.com/mdn/css-examples/blob/main/css-cookbook/breadcrumb-navigation--download.html)
> **Note:** The example above uses a complex selector to insert content before every `li` except the last one. This could also be achieved using a complex selector targeting all `li` elements except the first:
>
> ```css
> .breadcrumb li:not(:first-child)::before {
> content: "→";
> }
> ```
>
> Feel free to choose the solution that you prefer.
## Choices made
To display list items inline, we use [flexbox layout](/en-US/docs/Learn/CSS/CSS_layout/Flexbox), thus demonstrating how a line of CSS can give us our navigation. The separators are added using [CSS generated content](/en-US/docs/Web/CSS/CSS_generated_content). You could change these to any separator that you like.
## Accessibility concerns
We used the [`aria-label`](/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label) and [`aria-current`](/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current) attributes to help assistive technology users understand what this navigation is and where the current page is in the structure. See the related links for more information.
Be aware that the arrows `→` added via `content` are exposed to screen readers and braille displays.
## See also
- [CSS Flexible Box Layout](/en-US/docs/Web/CSS/CSS_flexible_box_layout)
- [Providing a Breadcrumb Trail](https://www.w3.org/TR/WCAG20-TECHS/G65.html)
- [Using the `aria-current` attribute](https://tink.uk/using-the-aria-current-attribute/)
| 0 |
Subsets and Splits