code
stringlengths
2.5k
150k
kind
stringclasses
1 value
css user-select user-select =========== The `user-select` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property controls whether the user can select text. This doesn't have any effect on content loaded as part of a browser's user interface (its [chrome](https://developer.mozilla.org/en-US/docs/Glossary/Chrome)), except in textboxes. Try it ------ Syntax ------ ``` /\* Keyword values \*/ user-select: none; user-select: auto; user-select: text; user-select: contain; user-select: all; /\* Global values \*/ user-select: inherit; user-select: initial; user-select: revert; user-select: revert-layer; user-select: unset; ``` **Note:** `user-select` is not an inherited property, though the initial `auto` value makes it behave like it is inherited most of the time. WebKit/Chromium-based browsers *do* implement the property as inherited, which violates the behavior described in the spec, and this will bring some issues. Until now, Chromium has chosen to [fix the issues](https://chromium.googlesource.com/chromium/src/+/b01af0b296ecb855aac95c4ed335d188e6eac2de) to make the final behavior meet the specifications. ### Values `none` The text of the element and its sub-elements is not selectable. Note that the [`Selection`](https://developer.mozilla.org/en-US/docs/Web/API/Selection) object can contain these elements. `auto` The used value of `auto` is determined as follows: * On the `::before` and `::after` pseudo elements, the used value is `none` * If the element is an editable element, the used value is `contain` * Otherwise, if the used value of `user-select` on the parent of this element is `all`, the used value is `all` * Otherwise, if the used value of `user-select` on the parent of this element is `none`, the used value is `none` * Otherwise, the used value is `text` `text` The text can be selected by the user. `all` The content of the element shall be selected atomically: If a selection would contain part of the element, then the selection must contain the entire element including all its descendants. If a double-click or context-click occurred in sub-elements, the highest ancestor with this value will be selected. `contain` Enables selection to start within the element; however, the selection will be contained by the bounds of that element. `element` Non-standard (IE-specific alias) Same as `contain`. Supported only in Internet Explorer. **Note:** CSS UI 4 [renames `user-select: element` to `contain`](https://github.com/w3c/csswg-drafts/commit/3f1d9db96fad8d9fc787d3ed66e2d5ad8cfadd05). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` user-select = auto [|](value_definition_syntax#single_bar) text [|](value_definition_syntax#single_bar) none [|](value_definition_syntax#single_bar) contain [|](value_definition_syntax#single_bar) all ``` Examples -------- ### HTML ``` <p>You should be able to select this text.</p> <p class="unselectable">Hey, you can't select this text!</p> <p class="all">Clicking once will select all of this text.</p> ``` ### CSS ``` .unselectable { -webkit-user-select: none; /\* Safari \*/ -ms-user-select: none; /\* IE 10+ \*/ user-select: none; } .all { -webkit-user-select: all; -ms-user-select: all; user-select: all; } ``` **Note:** `-webkit-user-select: all;` doesn't work in Safari; use only "none" or "text", or else it will allow typing in the `<html>` container. See the [browser compatibility table](#browser-compatibility) for up-to-date information. ### Result Specifications -------------- | Specification | | --- | | [CSS Basic User Interface Module Level 4 # content-selection](https://w3c.github.io/csswg-drafts/css-ui/#content-selection) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `user-select` | 54 1 | 79 12 12-79 | 69 49 1 | 10 | 41 15 | 3 2-3 | 54 ≤37 | 54 18 | 79 49 4 | 41 14 | 3 | 6.0 1.0 | | `all` | 53 | 79 | 1 | No | 40 | 16 | 53 | 53 | 4 | 41 | 16 | 6.0 | | `auto` | 1 | 12 | 1 | 10 | 15 | 2 | ≤37 | 18 | 4 | 14 | 3 | 1.0 | | `contain` | No | 12-79 | No | 10 | No | No | No | No | No | No | No | No | | `none` | 1 | 12 | 21 1-65 | 10 | 15 | 2 | ≤37 | 18 | 21 4-65 | 14 | 3 | 1.0 | | `text` | 1 | 12 | 1 | 10 | 15 | 2 Allows typing in the `<html>` container. | ≤37 | 18 | 4 | 14 | 3 Allows typing in the `<html>` container. | 1.0 | See also -------- * [Polyfill for `user-select: contain`](https://github.com/github/user-select-contain-polyfill) * [`::selection`](::selection) pseudo-element * The JavaScript [`Selection`](https://developer.mozilla.org/en-US/docs/Web/API/Selection) object css CSS Lists CSS Lists ========= **CSS Lists** is a module of CSS that defines how lists can be laid out and styled. Reference --------- ### Properties * [`list-style-image`](list-style-image) * [`list-style-type`](list-style-type) * [`list-style-position`](list-style-position) * [`list-style`](list-style) Guides ------ [Consistent list indentation](css_lists_and_counters/consistent_list_indentation) Explains how to achieve consistent list indentation across different browsers. [Using CSS Counters](css_counter_styles/using_css_counters) Explains how to use the CSS counter properties to control list counters. Specifications -------------- | Specification | | --- | | [CSS Lists and Counters Module Level 3](https://drafts.csswg.org/css-lists/) | css :read-only :read-only ========== The `:read-only` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) represents an element (such as `input` or `textarea`) that is not editable by the user. Try it ------ Syntax ------ ``` :read-only ``` Examples -------- ### Confirming form information in read-only/read-write controls One use of `readonly` form controls is to allow the user to check and verify information that they may have entered in an earlier form (for example, shipping details), while still being able to submit the information along with the rest of the form. We do just this in the example below. The `:read-only` pseudo-class is used to remove all the styling that makes the inputs look like clickable fields, making them look more like read-only paragraphs. The `:read-write` pseudo-class on the other hand is used to provide some nicer styling to the editable `<textarea>`. ``` input:-moz-read-only, textarea:-moz-read-only, input:read-only, textarea:read-only { border: 0; box-shadow: none; background-color: white; } textarea:-moz-read-write, textarea:read-write { box-shadow: inset 1px 1px 3px #ccc; border-radius: 5px; } ``` You can find the full source code at [readonly-confirmation.html](https://github.com/mdn/learning-area/blob/main/html/forms/pseudo-classes/readonly-confirmation.html); this renders like so: ### Styling read-only non-form controls This selector doesn't just select [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input)/[`<textarea>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea) elements — it will select *any* element that cannot be edited by the user. ``` <p contenteditable>This paragraph is editable; it is read-write.</p> <p>This paragraph is not editable; it is read-only.</p> ``` ``` p { font-size: 150%; padding: 5px; border-radius: 5px; } p:read-only { background-color: red; color: white; } p:read-write { background-color: lime; } ``` Specifications -------------- | Specification | | --- | | [HTML Standard # selector-read-only](https://html.spec.whatwg.org/multipage/semantics-other.html#selector-read-only) | | [Selectors Level 4 # rw-pseudos](https://w3c.github.io/csswg-drafts/selectors/#rw-pseudos) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:read-only` | 1 | 13 | 78 1.5 | No | 9 | 4 | ≤37 | 18 | 4 | 10.1 | 3.2 | 1.0 | See also -------- * [`:read-write`](:read-write) * HTML [`contenteditable`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#contenteditable) attribute css :not() :not() ====== The `:not()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) represents elements that do not match a list of selectors. Since it prevents specific items from being selected, it is known as the *negation pseudo-class*. Try it ------ The `:not()` pseudo-class has a number of [quirks, tricks, and unexpected results](#description) that you should be aware of before using it. Syntax ------ The `:not()` pseudo-class requires a comma-separated list of one or more selectors as its argument. The list must not contain another negation selector or a [pseudo-element](pseudo-elements). ``` :not( <complex-selector-list> ) ``` Description ----------- There are several unusual effects and outcomes when using `:not()` that you should keep in mind when using it: * Useless selectors can be written using this pseudo-class. For example, `:not(*)` matches any element which is not an element, which is obviously nonsense, so the accompanying rule will never be applied. * This pseudo-class can increase the <specificity> of a rule. For example, `#foo:not(#bar)` will match the same element as the simpler `#foo`, but has the higher specificity of two `id` selectors. * The specificity of the `:not()` pseudo-class is replaced by the specificity of the most specific selector in its comma-separated argument of selectors; providing the same specificity as if it had been written [`:not(:is(argument))`](:is). * `:not(.foo)` will match anything that isn't `.foo`, *including [`<html>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html) and [`<body>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body).* * This selector will match everything that is "not an X". This may be surprising when used with [descendant combinators](descendant_combinator), since there are multiple paths to select a target element. For instance, `body :not(table) a` will still apply to links inside a [`<table>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table), since [`<tr>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tr), [`<tbody>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tbody), [`<th>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th), [`<td>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td), [`<caption>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption), etc. can all match the `:not(table)` part of the selector. * You can negate several selectors at the same time. Example: `:not(.foo, .bar)` is equivalent to `:not(.foo):not(.bar)`. * If any selector passed to the `:not()` pseudo-class is invalid or not supported by the browser, the whole rule will be invalidated. The effective way to overcome this behavior is to use [`:is`](:is) pseudo-class, which accepts a forgiving selector list. For example `:not(.foo, :invalid-pseudo-class)` will invalidate a whole rule, but `:is(:not(.foo), :not(:invalid-pseudo-class))` will match any element that isn't `.foo`. Examples -------- ### Basic set of :not() examples #### HTML ``` <p>I am a paragraph.</p> <p class="fancy">I am so very fancy!</p> <div>I am NOT a paragraph.</div> <h2> <span class="foo">foo inside h2</span> <span class="bar">bar inside h2</span> </h2> ``` #### CSS ``` .fancy { text-shadow: 2px 2px 3px gold; } /\* <p> elements that don't have a class `.fancy` \*/ p:not(.fancy) { color: green; } /\* Elements that are not <p> elements \*/ body :not(p) { text-decoration: underline; } /\* Elements that are not <div> and not <span> elements \*/ body :not(div):not(span) { font-weight: bold; } /\* Elements that are not <div>s or `.fancy` \*/ body :not(div, .fancy) { text-decoration: overline underline; } /\* Elements inside an <h2> that aren't a <span> with a class of `.foo` \*/ h2 :not(span.foo) { color: red; } ``` #### Result Specifications -------------- | Specification | | --- | | [Selectors Level 4 # negation](https://w3c.github.io/csswg-drafts/selectors/#negation) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:not` | 1 | 12 | 1 | 9 | 9.5 | 3.1 | 2 | 18 | 4 | 10.1 | 2 | 1.0 | | `selector_list` | 88 | 88 | 84 | No | 74 | 9 | 88 | 88 | 84 | No | 9 | 15.0 | See also -------- * [Pseudo-classes](pseudo-classes) * [Pseudo-classes and pseudo-elements](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Pseudo-classes_and_pseudo-elements) * Other functional CSS pseudo-classes: + [`:has()`](:has) + [`:is()`](:is) + [`:where()`](:where) css :future :future ======= The `:future` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) selector is a time-dimensional pseudo-class that will match for any element which appears entirely after an element that matches [`:current`](:current). For example in a video with captions which are being displayed by [WebVTT](https://developer.mozilla.org/en-US/docs/Web/API/WebVTT_API). ``` :future(p, span) { display: none; } ``` Syntax ------ ``` :future ``` Examples -------- ### CSS ``` :future(p, span) { display: none; } ``` ### HTML ``` <video controls preload="metadata"> <source src="video.mp4" type="video/mp4" /> <source src="video.webm" type="video/webm" /> <track label="English" kind="subtitles" srclang="en" src="subtitles.vtt" default /> </video> ``` ### WebVTT ``` WEBVTT FILE 1 00:00:03.500 --> 00:00:05.000 This is the first caption 2 00:00:06.000 --> 00:00:09.000 This is the second caption 3 00:00:11.000 --> 00:00:19.000 This is the third caption ``` Specifications -------------- | Specification | | --- | | [Selectors Level 4 # the-future-pseudo](https://w3c.github.io/csswg-drafts/selectors/#the-future-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:future` | No | No | No | No | No | 7 | No | No | No | No | 7 | No | See also -------- * [Web Video Text Tracks Format (WebVTT)](https://developer.mozilla.org/en-US/docs/Web/API/WebVTT_API) * [`:current`](:current) * [`:past`](:past) css element() element() ========= **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `element()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](css_functions) defines an [`<image>`](image) value generated from an arbitrary HTML element. This image is live, meaning that if the HTML element is changed, the CSS properties using the resulting value are automatically updated. A particularly useful scenario for using this would be to render an image in an HTML [`<canvas>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas) element, then use that as a background. On Gecko browsers, you can use the non-standard [`document.mozSetImageElement()`](https://developer.mozilla.org/en-US/docs/Web/API/Document/mozSetImageElement) method to change the element being used as the background for a given CSS background element. Syntax ------ ``` element(id) ``` where: *id* The ID of an element to use as the background, specified using the HTML attribute #*id* on the element. Examples -------- These examples work in builds of Firefox that support `-moz-element()`. ### A somewhat realistic example This example uses a hidden [`<div>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div) as a background. The background element uses a gradient, but also includes text that is rendered as part of the background. ``` <div style="width:400px; height:400px; background:-moz-element(#myBackground1) no-repeat;"> <p>This box uses the element with the #myBackground1 ID as its background!</p> </div> <div style="overflow:hidden; height:0;"> <div id="myBackground1" style="width:1024px; height:1024px; background-image: linear-gradient(to right, red, orange, yellow, white);"> <p style="transform-origin:0 0; rotate: 45deg; color:white;"> This text is part of the background. Cool, huh? </p> </div> </div> ``` The [`<div>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div) element with the ID "myBackground1" is used as the background for the content including the paragraph "This box uses the element with the #myBackground1 ID as its background!". ### Page Preview This [example based on Vincent De Oliveira's](https://iamvdo.me/en/blog/css-element-function) creates a preview of the `<div id="css-source">` inside `<div id="css-result">`. #### HTML ``` <div id="css-source"> <h1>Page Preview</h1> </div> <div id="css-result"></div> ``` #### CSS ``` #css-result { background: -moz-element(#css-source) no-repeat; width: 256px; height: 32px; background-size: 80%; border: dashed; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Image Values and Replaced Content Module Level 4 # element-notation](https://w3c.github.io/csswg-drafts/css-images-4/#element-notation) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `element()` | No | No | 57 29-57 `-moz-element()` is limited to [`background-image`](https://developer.mozilla.org/docs/Web/CSS/background-image), [`background`](https://developer.mozilla.org/docs/Web/CSS/background), [`border-image`](https://developer.mozilla.org/docs/Web/CSS/border-image) and [`border-image-source`](https://developer.mozilla.org/docs/Web/CSS/border-image-source). 4-29 `-moz-element()` is limited to [`background-image`](https://developer.mozilla.org/docs/Web/CSS/background-image) and [`background`](https://developer.mozilla.org/docs/Web/CSS/background). | No | No | No | No | No | 60 29-60 `-moz-element()` is limited to [`background-image`](https://developer.mozilla.org/docs/Web/CSS/background-image), [`background`](https://developer.mozilla.org/docs/Web/CSS/background), [`border-image`](https://developer.mozilla.org/docs/Web/CSS/border-image) and [`border-image-source`](https://developer.mozilla.org/docs/Web/CSS/border-image-source). 4-29 `-moz-element()` is limited to [`background-image`](https://developer.mozilla.org/docs/Web/CSS/background-image) and [`background`](https://developer.mozilla.org/docs/Web/CSS/background). | No | No | No | See also -------- * [`image()`](image/image) * [`image-set()`](image/image-set) * [`<image>`](image) * [`<gradient>`](gradient) * [`element()`](element()) * [`cross-fade()`](cross-fade) * [`document.mozSetImageElement()`](https://developer.mozilla.org/en-US/docs/Web/API/Document/mozSetImageElement)
programming_docs
css CSS Positioned Layout CSS Positioned Layout ===================== **CSS Positioned Layout** is a module of CSS that defines how to position elements on the page. Reference --------- ### Properties * [`top`](top) * [`right`](right) * [`bottom`](bottom) * [`left`](left) * [`inset`](inset) * [`inset-inline`](inset-inline) * [`inset-inline-start`](inset-inline-start) * [`inset-inline-end`](inset-inline-end) * [`inset-block`](inset-block) * [`inset-block-start`](inset-block-start) * [`inset-block-end`](inset-block-end) * [`float`](float) * [`clear`](clear) * [`position`](position) * [`z-index`](z-index) * [`transform`](transform) Guides ------ [Understanding CSS z-index](css_positioning/understanding_z_index) Presents the notion of stacking context and explains how z-ordering works, with several examples. Specifications -------------- | Specification | | --- | | [CSS Positioned Layout Module Level 3](https://drafts.csswg.org/css-position/) | css mask mask ==== The `mask` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [shorthand property](shorthand_properties) hides an element (partially or fully) by masking or clipping the image at specific points. **Note:** As well as the properties listed below, the `mask` shorthand also resets [`mask-border`](mask-border) to its initial value. It is therefore recommended to use the `mask` shorthand rather than other shorthands or the individual properties to override any mask settings earlier in the cascade. This will ensure that `mask-border` has also been reset to allow the new styles to take effect. Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`mask-clip`](mask-clip) * [`mask-composite`](mask-composite) * [`mask-image`](mask-image) * [`mask-mode`](mask-mode) * [`mask-origin`](mask-origin) * [`mask-position`](mask-position) * [`mask-repeat`](mask-repeat) * [`mask-size`](mask-size) Syntax ------ ``` /\* Keyword values \*/ mask: none; /\* Image values \*/ mask: url(mask.png); /\* Pixel image used as mask \*/ mask: url(masks.svg#star); /\* Element within SVG graphic used as mask \*/ /\* Combined values \*/ mask: url(masks.svg#star) luminance; /\* Element within SVG graphic used as luminance mask \*/ mask: url(masks.svg#star) 40px 20px; /\* Element within SVG graphic used as mask positioned 40px from the top and 20px from the left \*/ mask: url(masks.svg#star) 0 0/50px 50px; /\* Element within SVG graphic used as mask with a width and height of 50px \*/ mask: url(masks.svg#star) repeat-x; /\* Element within SVG graphic used as horizontally repeated mask \*/ mask: url(masks.svg#star) stroke-box; /\* Element within SVG graphic used as mask extending to the box enclosed by the stroke \*/ mask: url(masks.svg#star) exclude; /\* Element within SVG graphic used as mask and combined with background using non-overlapping parts \*/ /\* Global values \*/ mask: inherit; mask: initial; mask: revert; mask: revert-layer; mask: unset; /\* Multiple masks \*/ mask: url(masks.svg#star) left / 16px repeat-y, /\* Element within SVG graphic is used as a mask on the left-hand side with a width of 16px \*/ url(masks.svg#circle) right / 16px repeat-y; /\* Element within SVG graphic is used as a mask on the right-hand side with a width of 16px \*/ ``` ### Values `<mask-reference>` Sets the mask image source. See [`mask-image`](mask-image). `<masking-mode>` Sets the masking mode of the mask image. See [`mask-mode`](mask-mode). `<position>` Sets the position of the mask image. See [`mask-position`](mask-position). `<bg-size>` Sets the size of the mask image. See [`mask-size`](mask-size). `<repeat-style>` Sets the repetition of the mask image. See [`mask-repeat`](mask-repeat). `<geometry-box>` If only one `<geometry-box>` value is given, it sets both [`mask-origin`](mask-origin) and [`mask-clip`](mask-clip). If two `<geometry-box>` values are present, then the first sets [`mask-origin`](mask-origin) and the second sets [`mask-clip`](mask-clip). `<geometry-box> | no-clip` Sets the area that is affected by the mask image. See [`mask-clip`](mask-clip). `<compositing-operator>` Sets the compositing operation used on the current mask layer. See [`mask-composite`](mask-composite). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`mask-image`](mask-image): `none` * [`mask-mode`](mask-mode): `match-source` * [`mask-repeat`](mask-repeat): `repeat` * [`mask-position`](mask-position): `center` * [`mask-clip`](mask-clip): `border-box` * [`mask-origin`](mask-origin): `border-box` * [`mask-size`](mask-size): `auto` * [`mask-composite`](mask-composite): `add` | | Applies to | all elements; In SVG, it applies to container elements excluding the [`<defs>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs) element and all graphics elements | | [Inherited](inheritance) | no | | Percentages | as each of the properties of the shorthand:* [`mask-position`](mask-position): refer to size of mask painting area minus size of mask layer image (see the text for [`background-position`](background-position)) | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`mask-image`](mask-image): as specified, but with [`url()`](url) values made absolute * [`mask-mode`](mask-mode): as specified * [`mask-repeat`](mask-repeat): Consists of two keywords, one per dimension * [`mask-position`](mask-position): Consists of two keywords representing the origin and two offsets from that origin, each given as an absolute length (if given a <length>), otherwise as a percentage. * [`mask-clip`](mask-clip): as specified * [`mask-origin`](mask-origin): as specified * [`mask-size`](mask-size): as specified, but with relative lengths converted into absolute lengths * [`mask-composite`](mask-composite): as specified | | Animation type | as each of the properties of the shorthand:* [`mask-image`](mask-image): discrete * [`mask-mode`](mask-mode): discrete * [`mask-repeat`](mask-repeat): discrete * [`mask-position`](mask-position): repeatable list of simple list of length, percentage, or calc * [`mask-clip`](mask-clip): discrete * [`mask-origin`](mask-origin): discrete * [`mask-size`](mask-size): repeatable list of simple list of length, percentage, or calc * [`mask-composite`](mask-composite): discrete | | Creates [stacking context](css_positioning/understanding_z_index/the_stacking_context) | yes | Formal syntax ------------- ``` mask = <mask-layer>[#](value_definition_syntax#hash_mark) <mask-layer> = <mask-reference> [||](value_definition_syntax#double_bar) <position> [[](value_definition_syntax#brackets) / <bg-size> []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) [||](value_definition_syntax#double_bar) <repeat-style> [||](value_definition_syntax#double_bar) <geometry-box> [||](value_definition_syntax#double_bar) [[](value_definition_syntax#brackets) <geometry-box> [|](value_definition_syntax#single_bar) no-clip []](value_definition_syntax#brackets) [||](value_definition_syntax#double_bar) <compositing-operator> [||](value_definition_syntax#double_bar) <masking-mode> <mask-reference> = none [|](value_definition_syntax#single_bar) <image> [|](value_definition_syntax#single_bar) <mask-source> <position> = [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) right []](value_definition_syntax#brackets) [||](value_definition_syntax#double_bar) [[](value_definition_syntax#brackets) top [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) bottom []](value_definition_syntax#brackets) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) <length-percentage> []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) top [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) bottom [|](value_definition_syntax#single_bar) <length-percentage> []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) right []](value_definition_syntax#brackets) <length-percentage> []](value_definition_syntax#brackets) [&&](value_definition_syntax#double_ampersand) [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) top [|](value_definition_syntax#single_bar) bottom []](value_definition_syntax#brackets) <length-percentage> []](value_definition_syntax#brackets) <bg-size> = [[](value_definition_syntax#brackets) [<length-percentage [0,∞]>](length-percentage) [|](value_definition_syntax#single_bar) auto []](value_definition_syntax#brackets)[{1,2}](value_definition_syntax#curly_braces) [|](value_definition_syntax#single_bar) cover [|](value_definition_syntax#single_bar) contain <repeat-style> = repeat-x [|](value_definition_syntax#single_bar) repeat-y [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) repeat [|](value_definition_syntax#single_bar) space [|](value_definition_syntax#single_bar) round [|](value_definition_syntax#single_bar) no-repeat []](value_definition_syntax#brackets)[{1,2}](value_definition_syntax#curly_braces) <geometry-box> = <shape-box> [|](value_definition_syntax#single_bar) fill-box [|](value_definition_syntax#single_bar) stroke-box [|](value_definition_syntax#single_bar) view-box <compositing-operator> = add [|](value_definition_syntax#single_bar) subtract [|](value_definition_syntax#single_bar) intersect [|](value_definition_syntax#single_bar) exclude <masking-mode> = alpha [|](value_definition_syntax#single_bar) luminance [|](value_definition_syntax#single_bar) match-source <image> = <url> [|](value_definition_syntax#single_bar) [<gradient>](gradient) <mask-source> = <url> <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) <shape-box> = <box> [|](value_definition_syntax#single_bar) margin-box <url> = url( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) [|](value_definition_syntax#single_bar) src( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) <box> = border-box [|](value_definition_syntax#single_bar) padding-box [|](value_definition_syntax#single_bar) content-box ``` Examples -------- ### Masking an image ``` .target { mask: url(#c1) luminance; } .anothertarget { mask: url(resources.svg#c1) 50px 30px/10px 10px repeat-x exclude; } ``` Specifications -------------- | Specification | | --- | | [CSS Masking Module Level 1 # the-mask](https://drafts.fxtf.org/css-masking/#the-mask) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `mask` | 1 While the property is recognized, values applied to it don't have any effect. 1 The prefixed property can be used with SVG and HTML with a slightly different syntax, which allows setting the non-standard [`-webkit-mask-attachment`](https://developer.mozilla.org/docs/Web/CSS/-webkit-mask-attachment) property. | 79 While the property is recognized, values applied to it don't have any effect. 79 The prefixed property can be used with SVG and HTML with a slightly different syntax, which allows setting the non-standard [`-webkit-mask-attachment`](https://developer.mozilla.org/docs/Web/CSS/-webkit-mask-attachment) property. 12-79 | 2 From Firefox 10, the default color space when handling masks is sRGB. Previously, the default and only supported color space was linear RGB. This changes the appearance of mask effects, but brings Firefox into compliance with the second edition of the SVG 1.1 specification. | No | 15 While the property is recognized, values applied to it don't have any effect. 15 The prefixed property can be used with SVG and HTML with a slightly different syntax, which allows setting the non-standard [`-webkit-mask-attachment`](https://developer.mozilla.org/docs/Web/CSS/-webkit-mask-attachment) property. | 3.1 While the property is recognized, values applied to it don't have any effect. 3.1 The prefixed property can be used with SVG and HTML with a slightly different syntax, which allows setting the non-standard [`-webkit-mask-attachment`](https://developer.mozilla.org/docs/Web/CSS/-webkit-mask-attachment) property. | 2 While the property is recognized, values applied to it don't have any effect. 2 The prefixed property can be used with SVG and HTML with a slightly different syntax, which allows setting the non-standard [`-webkit-mask-attachment`](https://developer.mozilla.org/docs/Web/CSS/-webkit-mask-attachment) property. | 18 While the property is recognized, values applied to it don't have any effect. 18 The prefixed property can be used with SVG and HTML with a slightly different syntax, which allows setting the non-standard [`-webkit-mask-attachment`](https://developer.mozilla.org/docs/Web/CSS/-webkit-mask-attachment) property. | 4 From Firefox 10, the default color space when handling masks is sRGB. Previously, the default and only supported color space was linear RGB. This changes the appearance of mask effects, but brings Firefox into compliance with the second edition of the SVG 1.1 specification. | 14 While the property is recognized, values applied to it don't have any effect. 14 The prefixed property can be used with SVG and HTML with a slightly different syntax, which allows setting the non-standard [`-webkit-mask-attachment`](https://developer.mozilla.org/docs/Web/CSS/-webkit-mask-attachment) property. | 2 While the property is recognized, values applied to it don't have any effect. 2 The prefixed property can be used with SVG and HTML with a slightly different syntax, which allows setting the non-standard [`-webkit-mask-attachment`](https://developer.mozilla.org/docs/Web/CSS/-webkit-mask-attachment) property. | 1.0 While the property is recognized, values applied to it don't have any effect. 1.0 The prefixed property can be used with SVG and HTML with a slightly different syntax, which allows setting the non-standard [`-webkit-mask-attachment`](https://developer.mozilla.org/docs/Web/CSS/-webkit-mask-attachment) property. | See also -------- * [`clip-path`](clip-path), [`filter`](filter) * [CSS Shapes, clipping and masking – and how to use them](https://hacks.mozilla.org/2017/06/css-shapes-clipping-and-masking/) * [Applying SVG effects to HTML content](https://developer.mozilla.org/en-US/docs/Web/SVG/Applying_SVG_effects_to_HTML_content) * [SVG](https://developer.mozilla.org/en-US/docs/Web/SVG) css padding-block-start padding-block-start =================== The `padding-block-start` [CSS](https://developer.mozilla.org/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. Try it ------ Syntax ------ ``` /\* <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 [`<length>`](length) The size of the padding as a fixed value. Must be nonnegative. [`<percentage>`](percentage) The size of the padding as a percentage, relative to the [inline-size](css_flow_layout/block_and_inline_layout_in_normal_flow) (*width* in a horizontal language) of the [containing block](containing_block). Must be nonnegative. Description ----------- The `padding-block-start` property is defined in the specification as taking the same values as the [`padding-top`](padding-top) property. However, the physical property it maps to depends on the values set for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Therefore, it could map to [`padding-top`](padding-top), [`padding-right`](padding-right), or [`padding-left`](padding-left) It relates to [`padding-block-end`](padding-block-end), [`padding-inline-start`](padding-inline-start), and [`padding-inline-end`](padding-inline-end), which define the other paddings of the element. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | all elements, except `table-row-group`, `table-header-group`, `table-footer-group`, `table-row`, `table-column-group` and `table-column` | | [Inherited](inheritance) | no | | Percentages | logical-width of containing block | | [Computed value](computed_value) | as [`<length>`](length) | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` padding-block-start = <'padding-top'> ``` Examples -------- ### Setting block start padding for vertical text #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; padding-block-start: 20px; background-color: #c8c800; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # padding-properties](https://w3c.github.io/csswg-drafts/css-logical/#padding-properties) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `padding-block-start` | 87 | 87 | 41 | No | 73 | 12.1 | 87 | 87 | 41 | 62 | 12.2 | 14.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * The mapped physical properties: [`padding-top`](padding-top), [`padding-right`](padding-right), [`padding-bottom`](padding-bottom), and [`padding-left`](padding-left) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css scroll-padding-inline-end scroll-padding-inline-end ========================= The `scroll-padding-inline-end` property defines offsets for the end edge in the inline 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. Try it ------ Syntax ------ ``` /\* Keyword values \*/ scroll-padding-inline-end: auto; /\* <length> values \*/ scroll-padding-inline-end: 10px; scroll-padding-inline-end: 1em; scroll-padding-inline-end: 10%; /\* Global values \*/ scroll-padding-inline-end: inherit; scroll-padding-inline-end: initial; scroll-padding-inline-end: revert; scroll-padding-inline-end: revert-layer; scroll-padding-inline-end: unset; ``` ### Values `<length-percentage>` An inwards offset from the inline 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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | scroll containers | | [Inherited](inheritance) | no | | Percentages | relative to the scroll container's scrollport | | [Computed value](computed_value) | as specified | | Animation type | by computed value type | Formal syntax ------------- ``` scroll-padding-inline-end = auto [|](value_definition_syntax#single_bar) [<length-percentage [0,∞]>](length-percentage) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Specifications -------------- | Specification | | --- | | [CSS Scroll Snap Module Level 1 # padding-longhands-logical](https://w3c.github.io/csswg-drafts/css-scroll-snap/#padding-longhands-logical) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scroll-padding-inline-end` | 69 | 79 | 68 | No | 56 | 15 | 69 | 69 | 68 | 48 | 15 | 10.0 | See also -------- * [CSS Scroll Snap](css_scroll_snap) * [Well-Controlled Scrolling with CSS Scroll Snap](https://web.dev/css-scroll-snap/)
programming_docs
css page-break-before page-break-before ================= **Warning:** This property has been replaced by the [`break-before`](break-before) property. The `page-break-before` CSS property adjusts page breaks *before* the current element. This property applies to block elements that generate a box. It won't apply on an empty [`<div>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div) that won't generate a box. ``` /\* Keyword values \*/ page-break-before: auto; page-break-before: always; page-break-before: avoid; page-break-before: left; page-break-before: right; page-break-before: recto; page-break-before: verso; /\* Global values \*/ page-break-before: inherit; page-break-before: initial; page-break-before: revert; page-break-before: revert-layer; page-break-before: unset; ``` Syntax ------ ### Values `auto` Initial value. Automatic page breaks (neither forced nor forbidden). `always` Always force page breaks before the element. `avoid` Avoid page breaks before the element. `left` Force page breaks before the element so that the next page is formatted as 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` Force page breaks before the element so that the next page is formatted as 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` Experimental If pages progress left-to-right, then this acts like `right`. If pages progress right-to-left, then this acts like `left`. `verso` Experimental If pages progress left-to-right, then this acts like `left`. If pages progress right-to-left, then this acts like `right`. Page break aliases ------------------ The `page-break-before` property is now a legacy property, replaced by [`break-before`](break-before). For compatibility reasons, `page-break-before` should be treated by browsers as an alias of `break-before`. This ensures that sites using `page-break-before` continue to work as designed. A subset of values should be aliased as follows: | page-break-before | break-before | | --- | --- | | `auto` | `auto` | | `left` | `left` | | `right` | `right` | | `avoid` | `avoid` | | `always` | `page` | Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | block-level elements in the normal flow of the root element. User agents may also apply it to other elements like `table-row` elements. | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` page-break-before = auto [|](value_definition_syntax#single_bar) always [|](value_definition_syntax#single_bar) avoid [|](value_definition_syntax#single_bar) left [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) inherit ``` Examples -------- ### Avoid a page break before an element ``` /\* Avoid page break before div elements of class note \*/ div.note { page-break-before: avoid; } ``` Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # page](https://w3c.github.io/csswg-drafts/css-logical/#page) | | [CSS Paged Media Module Level 3 # page-break-before](https://w3c.github.io/csswg-drafts/css-page/#page-break-before) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `page-break-before` | 1 | 12 | 1 The values `avoid`, `left`, and `right` are unsupported. | 4 | 7 | 1.2 | 37 | 18 | 4 The values `avoid`, `left`, and `right` are unsupported. | 14 | 1 | 1.0 | See also -------- * [`break-before`](break-before), [`break-after`](break-after), [`break-inside`](break-inside) * [`page-break-after`](page-break-after), [`page-break-inside`](page-break-inside) * [`orphans`](orphans), [`widows`](widows) css justify-self justify-self ============ The [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) `justify-self` property sets the way a box is justified inside its alignment container along the appropriate axis. Try it ------ 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](css_box_alignment/box_alignment_in_block_abspos_tables). * In flexbox layouts, this property is *ignored*. Read more about [alignment in Flexbox](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](css_box_alignment/box_alignment_in_grid_layout). Syntax ------ ``` /\* 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 [`max-height`](max-height)/[`max-width`](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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | block-level boxes, absolutely-positioned boxes, and grid items | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` justify-self = auto [|](value_definition_syntax#single_bar) normal [|](value_definition_syntax#single_bar) stretch [|](value_definition_syntax#single_bar) <baseline-position> [|](value_definition_syntax#single_bar) <overflow-position>[?](value_definition_syntax#question_mark) [[](value_definition_syntax#brackets) <self-position> [|](value_definition_syntax#single_bar) left [|](value_definition_syntax#single_bar) right []](value_definition_syntax#brackets) <baseline-position> = [[](value_definition_syntax#brackets) first [|](value_definition_syntax#single_bar) last []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) [&&](value_definition_syntax#double_ampersand) baseline <overflow-position> = unsafe [|](value_definition_syntax#single_bar) safe <self-position> = center [|](value_definition_syntax#single_bar) start [|](value_definition_syntax#single_bar) end [|](value_definition_syntax#single_bar) self-start [|](value_definition_syntax#single_bar) self-end [|](value_definition_syntax#single_bar) flex-start [|](value_definition_syntax#single_bar) flex-end ``` 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 ``` <article class="container"> <span>First child</span> <span>Second child</span> <span>Third child</span> <span>Fourth child</span> </article> ``` #### 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 Specifications -------------- | Specification | | --- | | [CSS Box Alignment Module Level 3 # justify-self-property](https://w3c.github.io/csswg-drafts/css-align/#justify-self-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `justify-self` | 57 | 16 | 45 | 10 | 44 | 10.1 | 57 | 57 | 45 | 43 | 10.3 | 6.0 | | `flex_context` | 57 | 16 | 45 | No | 44 | 10.1 | 57 | 57 | 45 | 43 | 10.3 | 6.0 | | `grid_context` | 57 | 16 | 45 | 10 Internet Explorer 10 and 11 have the property `-ms-grid-column-align`, which acts in a similar way to `justify-self`. | 44 | 10.1 | 57 | 57 | 45 | 43 | 10.3 | 6.0 | See also -------- * CSS Grid Guide: *[Box alignment in CSS Grid layouts](css_grid_layout/box_alignment_in_css_grid_layout)* * [CSS Box Alignment](css_box_alignment) * The [`justify-items`](justify-items) property css scroll-margin-left scroll-margin-left ================== The `scroll-margin-left` property defines the left margin of 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. Try it ------ Syntax ------ ``` /\* <length> values \*/ scroll-margin-left: 10px; scroll-margin-left: 1em; /\* Global values \*/ scroll-margin-left: inherit; scroll-margin-left: initial; scroll-margin-left: revert; scroll-margin-left: revert-layer; scroll-margin-left: unset; ``` ### Values `<length>` An outset from the left edge of the scroll container. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | by computed value type | Formal syntax ------------- ``` scroll-margin-left = [<length>](length) ``` Specifications -------------- | Specification | | --- | | [CSS Scroll Snap Module Level 1 # margin-longhands-physical](https://w3c.github.io/csswg-drafts/css-scroll-snap/#margin-longhands-physical) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scroll-margin-left` | 69 | 79 | 68 | No | 56 | 14.1 11 Before version 14.1, scroll margin is not applied for scrolls to fragment target or `scrollIntoView()`, see [bug 189265](https://webkit.org/b/189265). | 69 | 69 | 68 | 48 | 14.5 11 Before version 14.5, scroll margin is not applied for scrolls to fragment target or `scrollIntoView()`, see [bug 189265](https://webkit.org/b/189265). | 10.0 | See also -------- * [CSS Scroll Snap](css_scroll_snap) * [Well-Controlled Scrolling with CSS Scroll Snap](https://web.dev/css-scroll-snap/) css text-emphasis text-emphasis ============= The `text-emphasis` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property applies emphasis marks to text (except spaces and control characters). It is a [shorthand](shorthand_properties) for [`text-emphasis-style`](text-emphasis-style) and [`text-emphasis-color`](text-emphasis-color). Try it ------ The `text-emphasis` property is quite different from [`text-decoration`](text-decoration). The `text-decoration` property does not inherit, and the decoration specified is applied across the whole element. However, text-emphasis does inherit, which means it is possible to change emphasis marks for descendants. The size of the emphasis symbol, like ruby symbols, is about 50% of the size of the font, and `text-emphasis` may affect line height when the current leading is not enough for the marks. **Note:** `text-emphasis` doesn't reset the value of [`text-emphasis-position`](text-emphasis-position). This is because if the style and the color of emphasis marks may vary in a text, it is extremely unlikely that their position will. In the very rare cases when this is needed, use the property [`text-emphasis-position`](text-emphasis-position). Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`text-emphasis-color`](text-emphasis-color) * [`text-emphasis-style`](text-emphasis-style) Syntax ------ ``` /\* Initial value \*/ text-emphasis: none; /\* No emphasis marks \*/ /\* <string> value \*/ text-emphasis: "x"; text-emphasis: "点"; text-emphasis: "\25B2"; text-emphasis: "\*" #555; text-emphasis: "foo"; /\* Should NOT use. It may be computed to or rendered as 'f' only \*/ /\* Keywords value \*/ text-emphasis: filled; text-emphasis: open; text-emphasis: filled sesame; text-emphasis: open sesame; /\* Keywords value combined with a color \*/ text-emphasis: filled sesame #555; /\* Global values \*/ text-emphasis: inherit; text-emphasis: initial; text-emphasis: revert; text-emphasis: revert-layer; text-emphasis: unset; ``` ### Values `none` No emphasis marks. `filled` The shape is filled with solid color. If neither `filled` nor `open` is present, this is the default. `open` The shape is hollow. `dot` Display small circles as marks. The filled dot is `'•'` (`U+2022`), and the open dot is `'◦'` (`U+25E6`). `circle` Display large circles as marks. The filled circle is `'●'` (`U+25CF`), and the open circle is `'○'` (`U+25CB`). This is the default shape in horizontal writing modes when no other shape is given. `double-circle` Display double circles as marks. The filled double-circle is `'◉'` (`U+25C9`), and the open double-circle is `'◎'` (`U+25CE`). `triangle` Display triangles as marks. The filled triangle is `'▲'` (`U+25B2`), and the open triangle is `'△'` (`U+25B3`). `sesame` Display sesames as marks. The filled sesame is `'﹅'` (`U+FE45`), and the open sesame is `'﹆'` (`U+FE46`). This is the default shape in vertical writing modes when no other shape is given. `<string>` Display the given string as marks. Authors should not specify more than one *character* in `<string>`. The UA may truncate or ignore strings consisting of more than one grapheme cluster. `<color>` Defines the color of the mark. If no color is present, it defaults to `currentcolor`. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`text-emphasis-style`](text-emphasis-style): `none` * [`text-emphasis-color`](text-emphasis-color): `currentcolor` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`text-emphasis-style`](text-emphasis-style): as specified * [`text-emphasis-color`](text-emphasis-color): computed color | | Animation type | as each of the properties of the shorthand:* [`text-emphasis-color`](text-emphasis-color): a [color](color_value#interpolation) * [`text-emphasis-style`](text-emphasis-style): discrete | Formal syntax ------------- ``` text-emphasis = <'text-emphasis-style'> [||](value_definition_syntax#double_bar) <'text-emphasis-color'> ``` Examples -------- ### A heading with emphasis shape and color This example draws a heading with triangles used to emphasize each character. #### CSS ``` h2 { text-emphasis: triangle #d55; } ``` #### HTML ``` <h2>This is important!</h2> ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Text Decoration Module Level 3 # text-emphasis-property](https://w3c.github.io/csswg-drafts/css-text-decor/#text-emphasis-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `text-emphasis` | 99 25 | 99 79 | 46 | No | 15 | 7 7 | 4.4 | 99 25 | 46 | 14 | 7 7 | 18.0 1.5 | See also -------- * The longhand properties [`text-emphasis-style`](text-emphasis-style), [`text-emphasis-color`](text-emphasis-color). * The [`text-emphasis-position`](text-emphasis-position) property allowing to define the position of the emphasis marks.
programming_docs
css Child combinator Child combinator ================ The **child combinator** (`>`) is placed between two CSS selectors. It matches only those elements matched by the second selector that are the direct children of elements matched by the first. ``` /\* List items that are children of the "my-things" list \*/ ul.my-things > li { margin: 2em; } ``` Elements matched by the second selector must be the immediate children of the elements matched by the first selector. This is stricter than the [descendant combinator](descendant_combinator), which matches all elements matched by the second selector for which there exists an ancestor element matched by the first selector, regardless of the number of "hops" up the DOM. Syntax ------ ``` selector1 > selector2 { style properties } ``` Examples -------- ### CSS ``` span { background-color: aqua; } div > span { background-color: yellow; } ``` ### HTML ``` <div> <span>Span #1, in the div. <span>Span #2, in the span that's in the div.</span> </span> </div> <span>Span #3, not in the div at all.</span> ``` ### Result Specifications -------------- | Specification | | --- | | [Selectors Level 4 # child-combinators](https://w3c.github.io/csswg-drafts/selectors/#child-combinators) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `Child_combinator` | 1 | 12 | 1 | 7 Before Internet Explorer 10, the combinator only works in standards mode. | 4 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | See also -------- * [Descendant combinator](descendant_combinator) css :playing :playing ======== The `:playing` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) selector is a resource state pseudo-class that will match an audio, video, or similar resource that is capable of being "played" or "paused", when that element is "playing". A resource is playing even if in buffering state or paused for any reason other than a user interaction to cause it to be paused. ``` :playing { } ``` Syntax ------ ``` :playing ``` Examples -------- ### CSS ``` :playing { border: 5px solid green; } ``` Specifications -------------- | Specification | | --- | | [Selectors Level 4 # selectordef-playing](https://w3c.github.io/csswg-drafts/selectors/#selectordef-playing) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:playing` | No | No | No | No | No | 15.4 | No | No | No | No | 15.4 | No | See also -------- * [`:paused`](:paused) css border-top-style border-top-style ================ The `border-top-style` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the line style of an element's top [`border`](border). Try it ------ **Note:** The specification doesn't define how borders of different styles connect in the corners. Syntax ------ ``` /\* Keyword values \*/ border-top-style: none; border-top-style: hidden; border-top-style: dotted; border-top-style: dashed; border-top-style: solid; border-top-style: double; border-top-style: groove; border-top-style: ridge; border-top-style: inset; border-top-style: outset; /\* Global values \*/ border-top-style: inherit; border-top-style: initial; border-top-style: revert; border-top-style: revert-layer; border-top-style: unset; ``` The `border-top-style` property is specified as a single keyword chosen from those available for the [`border-style`](border-style) property. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` border-top-style = <line-style> <line-style> = none [|](value_definition_syntax#single_bar) hidden [|](value_definition_syntax#single_bar) dotted [|](value_definition_syntax#single_bar) dashed [|](value_definition_syntax#single_bar) solid [|](value_definition_syntax#single_bar) double [|](value_definition_syntax#single_bar) groove [|](value_definition_syntax#single_bar) ridge [|](value_definition_syntax#single_bar) inset [|](value_definition_syntax#single_bar) outset ``` Examples -------- ### Setting border-top-style #### 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 ``` /\* Define look of the table \*/ table { border-width: 2px; background-color: #52e385; } tr, td { padding: 3px; } /\* border-top-style example classes \*/ .b1 {border-top-style: none;} .b2 {border-top-style: hidden;} .b3 {border-top-style: dotted;} .b4 {border-top-style: dashed;} .b5 {border-top-style: solid;} .b6 {border-top-style: double;} .b7 {border-top-style: groove;} .b8 {border-top-style: ridge;} .b9 {border-top-style: inset;} .b10 {border-top-style: outset;} ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # the-border-style](https://w3c.github.io/csswg-drafts/css-backgrounds/#the-border-style) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-top-style` | 1 | 12 | 1 Before Firefox 50, border styles of rounded corners (with [`border-radius`](https://developer.mozilla.org/docs/Web/CSS/border-radius)) were always rendered as if `border-top-style` was `solid`. This has been fixed in Firefox 50. | 5.5 | 9.2 | 1 | ≤37 | 18 | 4 Before Firefox 50, border styles of rounded corners (with [`border-radius`](https://developer.mozilla.org/docs/Web/CSS/border-radius)) were always rendered as if `border-top-style` was `solid`. This has been fixed in Firefox 50. | 14 | 1 | 1.0 | See also -------- * The other style-related border properties: [`border-left-style`](border-left-style), [`border-right-style`](border-right-style), [`border-bottom-style`](border-bottom-style), and [`border-style`](border-style). * The other top-border-related properties: [`border-top`](border-top), [`border-top-color`](border-top-color), and [`border-top-width`](border-top-width). css :nth-col() :nth-col() ========== **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `:nth-col()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) is designed for tables and grids. It accepts the An+B notation such as used with the [`:nth-child`](:nth-child) selector, using this to target every nth column. The values odd and even are also valid. ``` /\* Selects every odd column in a table \*/ :nth-col(odd) { background-color: pink; } ``` Syntax ------ The `nth-col()` pseudo-class is specified with a single argument, which represents the pattern for matching elements. It uses `:nth-col(An+B)` syntax. See [`:nth-child`](:nth-child) for a more detailed explanation of its syntax. ``` :nth-col(An+B) ``` Examples -------- ### Basic example #### HTML ``` <table> <tr> <td>one</td> <td>two</td> <td>three</td> <td>four</td> </tr> <tr> <td>one</td> <td>two</td> <td>three</td> <td>four</td> </tr> </table> ``` #### CSS ``` td { border: 1px solid #ccc; padding: 0.2em; } /\* Odd columns \*/ :nth-col(2n + 1) { background-color: pink; } ``` #### Result Specifications -------------- **No specification found**No specification data found for `css.selectors.nth-col`. [Check for problems with this page](#on-github) or contribute a missing `spec_url` to [mdn/browser-compat-data](https://github.com/mdn/browser-compat-data). Also make sure the specification is included in [w3c/browser-specs](https://github.com/w3c/browser-specs). Browser compatibility --------------------- No compatibility data found for `css.selectors.nth-col`. [Check for problems with this page](#on-github) or contribute missing data to [mdn/browser-compat-data](https://github.com/mdn/browser-compat-data). See also -------- * [`:nth-child`](:nth-child), [`:nth-last-of-type`](:nth-last-of-type) css grid grid ==== The `grid` CSS property is a [shorthand property](shorthand_properties) that sets all of the explicit and implicit grid properties in a single declaration. Using `grid` you specify one axis using [`grid-template-rows`](grid-template-rows) or [`grid-template-columns`](grid-template-columns), you then specify how content should auto-repeat in the other axis using the implicit grid properties: [`grid-auto-rows`](grid-auto-rows), [`grid-auto-columns`](grid-auto-columns), and [`grid-auto-flow`](grid-auto-flow). Try it ------ **Note:** The sub-properties you don't specify are set to their initial value, as normal for shorthands. Also, the gutter properties are NOT reset by this shorthand. Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`grid-auto-columns`](grid-auto-columns) * [`grid-auto-flow`](grid-auto-flow) * [`grid-auto-rows`](grid-auto-rows) * [`grid-template-areas`](grid-template-areas) * [`grid-template-columns`](grid-template-columns) * [`grid-template-rows`](grid-template-rows) Syntax ------ ``` /\* <'grid-template'> values \*/ grid: none; grid: "a" 100px "b" 1fr; grid: [linename1] "a" 100px [linename2]; grid: "a" 200px "b" min-content; grid: "a" minmax(100px, max-content) "b" 20%; grid: 100px / 200px; grid: minmax(400px, min-content) / repeat(auto-fill, 50px); /\* <'grid-template-rows'> / [ auto-flow && dense? ] <'grid-auto-columns'>? values \*/ grid: 200px / auto-flow; grid: 30% / auto-flow dense; grid: repeat(3, [line1 line2 line3] 200px) / auto-flow 300px; grid: [line1] minmax(20em, max-content) / auto-flow dense 40%; /\* [ auto-flow && dense? ] <'grid-auto-rows'>? / <'grid-template-columns'> values \*/ grid: auto-flow / 200px; grid: auto-flow dense / 30%; grid: auto-flow 300px / repeat(3, [line1 line2 line3] 200px); grid: auto-flow dense 40% / [line1] minmax(20em, max-content); /\* Global values \*/ grid: inherit; grid: initial; grid: revert; grid: revert-layer; grid: unset; ``` ### Values `<'grid-template'>` Defines the [`grid-template`](grid-template) including [`grid-template-columns`](grid-template-columns), [`grid-template-rows`](grid-template-rows) and [`grid-template-areas`](grid-template-areas). `<'grid-template-rows'> / [ auto-flow && dense? ] <'grid-auto-columns'>?` Sets up an auto-flow by setting the row tracks explicitly via the [`grid-template-rows`](grid-template-rows) property (and the [`grid-template-columns`](grid-template-columns) property to `none`) and specifying how to auto-repeat the column tracks via [`grid-auto-columns`](grid-auto-columns) (and setting [`grid-auto-rows`](grid-auto-rows) to `auto`). [`grid-auto-flow`](grid-auto-flow) is also set to `column` accordingly, with `dense` if it's specified. All other `grid` sub-properties are reset to their initial values. `[ auto-flow && dense? ] <'grid-auto-rows'>? / <'grid-template-columns'>` Sets up an auto-flow by setting the column tracks explicitly via the [`grid-template-columns`](grid-template-columns) property (and the [`grid-template-rows`](grid-template-rows) property to `none`) and specifying how to auto-repeat the row tracks via [`grid-auto-rows`](grid-auto-rows) (and setting [`grid-auto-columns`](grid-auto-columns) to `auto`). [`grid-auto-flow`](grid-auto-flow) is also set to `row` accordingly, with `dense` if it's specified. All other `grid` sub-properties are reset to their initial values. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`grid-template-rows`](grid-template-rows): `none` * [`grid-template-columns`](grid-template-columns): `none` * [`grid-template-areas`](grid-template-areas): `none` * [`grid-auto-rows`](grid-auto-rows): `auto` * [`grid-auto-columns`](grid-auto-columns): `auto` * [`grid-auto-flow`](grid-auto-flow): `row` * [`grid-column-gap`](column-gap): `0` * [`grid-row-gap`](row-gap): `0` * [`column-gap`](column-gap): `normal` * [`row-gap`](row-gap): `normal` | | Applies to | grid containers | | [Inherited](inheritance) | no | | Percentages | as each of the properties of the shorthand:* [`grid-template-rows`](grid-template-rows): refer to corresponding dimension of the content area * [`grid-template-columns`](grid-template-columns): refer to corresponding dimension of the content area * [`grid-auto-rows`](grid-auto-rows): refer to corresponding dimension of the content area * [`grid-auto-columns`](grid-auto-columns): refer to corresponding dimension of the content area | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`grid-template-rows`](grid-template-rows): as specified, but with relative lengths converted into absolute lengths * [`grid-template-columns`](grid-template-columns): as specified, but with relative lengths converted into absolute lengths * [`grid-template-areas`](grid-template-areas): as specified * [`grid-auto-rows`](grid-auto-rows): the percentage as specified or the absolute length * [`grid-auto-columns`](grid-auto-columns): the percentage as specified or the absolute length * [`grid-auto-flow`](grid-auto-flow): as specified * [`grid-column-gap`](column-gap): the percentage as specified or the absolute length * [`grid-row-gap`](row-gap): the percentage as specified or the absolute length * [`column-gap`](column-gap): as specified, with <length>s made absolute, and normal computing to zero except on multi-column elements * [`row-gap`](row-gap): as specified, with <length>s made absolute, and normal computing to zero except on multi-column elements | | Animation type | discrete | Formal syntax ------------- ``` grid = <'grid-template'> [|](value_definition_syntax#single_bar) <'grid-template-rows'> / [[](value_definition_syntax#brackets) auto-flow [&&](value_definition_syntax#double_ampersand) dense[?](value_definition_syntax#question_mark) []](value_definition_syntax#brackets) <'grid-auto-columns'>[?](value_definition_syntax#question_mark) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) auto-flow [&&](value_definition_syntax#double_ampersand) dense[?](value_definition_syntax#question_mark) []](value_definition_syntax#brackets) <'grid-auto-rows'>[?](value_definition_syntax#question_mark) / <'grid-template-columns'> ``` Examples -------- ### Creating a grid layout #### HTML ``` <div id="container"> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> </div> ``` #### CSS ``` #container { display: grid; grid: repeat(2, 60px) / auto-flow 80px; } #container > div { background-color: #8ca0ff; width: 50px; height: 50px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Grid Layout Module Level 2 # grid-shorthand](https://w3c.github.io/csswg-drafts/css-grid/#grid-shorthand) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `grid` | 57 | 16 | 52 | No | 44 | 10.1 | 57 | 57 | 52 | 43 | 10.3 | 6.0 This was added early so is out of sync with the equivalent Chromium version. | See also -------- * Related CSS properties: [`grid-template`](grid-template), [`grid-template-rows`](grid-template-rows), [`grid-template-columns`](grid-template-columns), [`grid-template-areas`](grid-template-areas), [`grid-auto-columns`](grid-auto-columns), [`grid-auto-rows`](grid-auto-rows), [`grid-auto-flow`](grid-auto-flow) * Grid Layout Guide: *[Line-based placement with CSS Grid](css_grid_layout/line-based_placement_with_css_grid)* * Grid Layout Guide: *[Grid template areas - Grid definition shorthands](css_grid_layout/grid_template_areas#grid_definition_shorthands)* css <ident> <ident> ======= The `<ident>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) denotes an arbitrary string used as an [identifier](https://developer.mozilla.org/en-US/docs/Glossary/Identifier). Syntax ------ The syntax of `<custom-ident>` is similar to CSS identifiers (such as property names), except that it is [case-sensitive](https://en.wikipedia.org/wiki/Case_sensitivity). It consists of one or more characters, where characters can be any of the following: * any alphabetical character (`A` to `Z`, or `a` to `z`), * any decimal digit (`0` to `9`), * a hyphen (`-`), * an underscore (`_`), * an escaped character (preceded by a backslash, `\`), * a [Unicode](https://en.wikipedia.org/wiki/Unicode) character (in the format of a backslash, `\`, followed by one to six hexadecimal digits, representing its Unicode code point) Note that `id1`, `Id1`, `iD1` and `ID1` are all different identifiers as they are [case-sensitive](https://en.wikipedia.org/wiki/Case_sensitivity). On the other hand, as there are several ways to escape a character, `toto\?` and `toto\3F` are the same identifiers. Examples -------- ### Valid identifiers ``` nono79 A mix of alphanumeric characters and numbers ground-level A mix of alphanumeric characters and a dash -test A dash followed by alphanumeric characters --toto A custom-property like identifier _internal An underscore followed by alphanumeric characters \22 toto A Unicode character followed by a sequence of alphanumeric characters bili\.bob A correctly escaped period ``` ### Invalid identifiers ``` 34rem It must not start with a decimal digit. -12rad It must not start with a dash followed by a decimal digit. bili.bob Only alphanumeric characters, _, and - needn't be escaped. 'bilibob' This would be a [<string>](string). "bilibob" This would be a [<string>](string). ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # css-identifier](https://drafts.csswg.org/css-values/#css-identifier) | Browser compatibility --------------------- See also -------- * [<custom-ident>](custom-ident) * [<dashed-ident>](dashed-ident) css text-align text-align ========== The `text-align` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the horizontal alignment of the inline-level content inside a block element or table-cell box. This means it works like [`vertical-align`](vertical-align) but in the horizontal direction. Try it ------ Syntax ------ ``` /\* Keyword values \*/ text-align: start; text-align: end; text-align: left; text-align: right; text-align: center; text-align: justify; text-align: justify-all; text-align: match-parent; /\* Character-based alignment in a table column \*/ text-align: "."; text-align: "." center; /\* Block alignment values (Non-standard syntax) \*/ text-align: -moz-center; text-align: -webkit-center; /\* Global values \*/ text-align: inherit; text-align: initial; text-align: revert; text-align: revert-layer; text-align: unset; ``` The `text-align` property is specified in one of the following ways: * Using the keyword values `start`, `end`, `left`, `right`, `center`, `justify`, `justify-all`, or `match-parent`. * Using a `<string>` value only, in which case the other value defaults to `right`. * Using both a keyword value and a [`<string>`](#string) value. ### Values `start` The same as `left` if direction is left-to-right and `right` if direction is right-to-left. `end` The same as `right` if direction is left-to-right and `left` if direction is right-to-left. `left` The inline contents are aligned to the left edge of the line box. `right` The inline contents are aligned to the right edge of the line box. `center` The inline contents are centered within the line box. `justify` The inline contents are justified. Text should be spaced to line up its left and right edges to the left and right edges of the line box, except for the last line. `justify-all` Experimental Same as `justify`, but also forces the last line to be justified. `match-parent` Similar to `inherit`, but the values `start` and `end` are calculated according to the parent's [`direction`](direction) and are replaced by the appropriate `left` or `right` value. [`<string>`](string) Experimental When applied to a table cell, specifies the alignment character around which the cell's contents will align. Accessibility concerns ---------------------- The inconsistent spacing between words created by justified text can be problematic for people with cognitive concerns such as Dyslexia. * [MDN Understanding WCAG, Guideline 1.4 explanations](https://developer.mozilla.org/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.8 | Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-visual-presentation.html) Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `start`, or a nameless value that acts as `left` if [`direction`](direction) is `ltr`, `right` if [`direction`](direction) is `rtl` if `start` is not supported by the browser. | | Applies to | block containers | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified, except for the `match-parent` value which is calculated against its parent's `direction` value and results in a computed value of either `left` or `right` | | Animation type | discrete | Formal syntax ------------- ``` text-align = start [|](value_definition_syntax#single_bar) end [|](value_definition_syntax#single_bar) left [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) justify [|](value_definition_syntax#single_bar) match-parent [|](value_definition_syntax#single_bar) justify-all ``` Examples -------- ### Start alignment #### HTML ``` <p class="example"> Integer elementum massa at nulla placerat varius. Suspendisse in libero risus, in interdum massa. Vestibulum ac leo vitae metus faucibus gravida ac in neque. Nullam est eros, suscipit sed dictum quis, accumsan a ligula. </p> ``` #### CSS ``` .example { text-align: start; border: solid; } ``` #### Result ### Centered text #### HTML ``` <p class="example"> Integer elementum massa at nulla placerat varius. Suspendisse in libero risus, in interdum massa. Vestibulum ac leo vitae metus faucibus gravida ac in neque. Nullam est eros, suscipit sed dictum quis, accumsan a ligula. </p> ``` #### CSS ``` .example { text-align: center; border: solid; } ``` #### Result ### Example using "justify" #### HTML ``` <p class="example"> Integer elementum massa at nulla placerat varius. Suspendisse in libero risus, in interdum massa. Vestibulum ac leo vitae metus faucibus gravida ac in neque. Nullam est eros, suscipit sed dictum quis, accumsan a ligula. </p> ``` #### CSS ``` .example { text-align: justify; border: solid; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # text-align](https://w3c.github.io/csswg-drafts/css-logical/#text-align) | | [CSS Text Module Level 3 # text-align-property](https://w3c.github.io/csswg-drafts/css-text/#text-align-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `text-align` | 1 | 12 | 1 | 3 | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | | `block_alignment_values` | 1 | 79 | 1 | No | 15 | 1.3 1 preview | 37 | 18 | 4 | 14 | 1 1 | 1.0 | | `flow_relative_values_start_and_end` | 1 | 79 | 1 | No | 15 | 3.1 | 37 | 18 | 4 | 14 | 2 | 1.0 | | `match-parent` | 16 | 79 | 40 | No | 15 | 15.4 | 37 | 18 | 40 | 14 | 15.4 | 1.0 | See also -------- * [`margin: auto`](margin), [`margin-left: auto`](margin-left), [`vertical-align`](vertical-align)
programming_docs
css CSS Container Queries CSS Container Queries ===================== [CSS containment](css_containment) provides a way to isolate parts of a page and declare to the browser these parts are independent from the rest of the page in terms of styles and layout. If you are creating [a responsive design](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Responsive_Design), you often use [media queries](media_queries) to change the page layout based on the size of the [viewport](https://developer.mozilla.org/en-US/docs/Glossary/Viewport). It's common to group HTML elements into reusable components that have a specific layout depending on the available space in a page. The available space might not only depend on the size of the viewport, but also on the context where a component appears. Container queries allow us to look at a container size and apply styles to the contents based on the size of their container rather than the viewport or other device characteristics. If the container has less space in the surrounding context, you can hide certain elements or use smaller fonts, for example. The illustration below shows how the same card component can be displayed with multiple layouts using container queries: Using container queries ----------------------- To use container queries, you need to declare a **containment context** on an element so that the browser knows you might want to query the dimensions of this container later. To do this, use the [`container-type`](container-type) property a value of `size`, `inline-size`, or `normal`. These values have the following effects: * `size`: the query will be based on the [inline and block](css_logical_properties/basic_concepts#block_and_inline_dimensions) dimensions of the container. Applies layout, style, and size containment to the container. * `inline-size`: the query will be based on the [inline](css_logical_properties/basic_concepts#block_and_inline_dimensions) dimensions of the container. Applies layout, style, and inline-size containment to the element. * `normal`: The element is not a query container for any container size queries, but remains a query container for container style queries. Take the following HTML as an example which is a card component with an image, a title, and some text: ``` <div class="container"> <div class="card"> <img src="image.png" alt="Cat with two different color eyes" /> <h2>Card title</h2> <p>Card content</p> </div> </div> ``` You can create a containment context on the container `<div>` using the `container-type` property: ``` .container { container-type: inline-size; } ``` Once a containment context is created, you can use the [`@container`](@container) at-rule to write a container query. The query in the following example will apply styles to elements based on the size of the nearest ancestor with a containment context. Specifically, this query will apply a larger font size for the card title if the container is wider than `700px`: ``` /\* Default heading styles for the card title \*/ .card h2 { font-size: 1em; } /\* Container query applied if the container is larger than 700px \*/ @container (min-width: 700px) { .card h2 { font-size: 2em; } } ``` If other areas of the page are also containment contexts, you can use the same component in those areas and it will respond to the relevant containment context. This makes reusable components a lot more flexible without needing to know specifically where they will be used each time. For more information on the syntax of container queries, see the [`@container`](@container) page. ### Naming containment contexts In the previous section, a container query applied styles based on the nearest ancestor with a containment context. It's possible to give a containment context a name using the [`container-name`](container-name) property. Once named, the name can be used in a `@container` query so as to target a specific container. The following example creates a containment context with the name `sidebar`: ``` .container { container-type: inline-size; container-name: sidebar; } ``` You can then target this containment context using the `@container` at-rule: ``` @container sidebar (min-width: 700px) { .card { display: grid; grid-template-columns: 2fr 1fr; } } ``` More information on naming containment contexts is available on the [`container-name`](container-name) page. ### Shorthand container syntax The shorthand way of declaring a containment context is to use the `container` property: ``` .container { container: sidebar / inline-size; } ``` For more information on this property, see the [`container`](container) reference. ### Container query length units When applying styles to a container using container queries, you can use container query length units. These units specify a length relative to the dimensions of a query container. Components that use units of length relative to their container are more flexible to use in different containers without having to recalculate concrete length values. The container query length units are: * `cqw`: 1% of a query container's width * `cqh`: 1% of a query container's height * `cqi`: 1% of a query container's inline size * `cqb`: 1% of a query container's block size * `cqmin`: The smaller value of either `cqi` or `cqb` * `cqmax`: The larger value of either `cqi` or `cqb` The following example uses the `cqi` unit to set the font size of a heading based on the inline size of the container: ``` @container (min-width: 700px) { .card h1 { font-size: max(1.5em, 1.23em + 2cqi); } } ``` For more information on these units, see the [Container query length units](length#container_query_length_units) reference. Fallbacks for container queries ------------------------------- For browsers that don't yet support container queries, [`grid`](grid) and [`flex`](flex) can be used to create a similar effect for the card component used on this page. The following example uses a [`grid-template-columns`](grid-template-columns) declaration to create a two-column layout for the card component. ``` .card { display: grid; grid-template-columns: 2fr 1fr; } ``` If you want to use a single-column layout for devices with a smaller viewport, you can use a media query to change the grid template: ``` @media (max-width: 700px) { .card { grid-template-columns: 1fr; } } ``` See also -------- * [Media queries](media_queries) * CSS [`@container`](@container) at-rule * CSS [`contain`](contain) property * CSS [`container`](container) shorthand property * CSS [`container-name`](container-name) property * CSS [`content-visibility`](content-visibility) property * [Say Hello to CSS Container Queries](https://ishadeed.com/article/say-hello-to-css-container-queries/) by Ahmad Shadeed * [Container Queries: a Quick Start Guide](https://www.oddbird.net/2021/04/05/containerqueries/) * [Collection of Container Queries articles](https://github.com/sturobson/Awesome-Container-Queries) css Shorthand properties Shorthand properties ==================== ***Shorthand properties*** are CSS properties that let you set the values of multiple other CSS properties simultaneously. Using a shorthand property, you can write more concise (and often more readable) style sheets, saving time and energy. The CSS specification defines shorthand properties to group the definition of common properties acting on the same theme. For instance, the CSS [`background`](background) property is a shorthand property that's able to define the values of [`background-color`](background-color), [`background-image`](background-image), [`background-repeat`](background-repeat), and [`background-position`](background-position). Similarly, the most common font-related properties can be defined using the shorthand [`font`](font), and the different margins around a box can be defined using the [`margin`](margin) shorthand. Tricky edge cases ----------------- There are a few edge cases to keep in mind when using shorthand properties. ### Omitting properties A value which is not specified is set to its initial value. That means that it **overrides** previously set values. For example: ``` p { background-color: red; background: url(images/bg.gif) no-repeat left top; } ``` This will not set the color of the background to `red` but to the default value for [`background-color`](background-color), which is `transparent`. Only the individual properties values can inherit. As missing values are replaced by their initial value, it is impossible to allow inheritance of individual properties by omitting them. The keyword `inherit` can be applied to a property, but only as a whole, not as a keyword for one value or another. That means that the only way to make some specific value to be inherited is to use the longhand property with the keyword `inherit`. ### Ordering properties Shorthand properties try not to force a specific order for the values of the properties they replace. This works well when these properties use values of different types, as the order has no importance, but this does not work as easily when several properties can have identical values. Two important cases here are: * properties related to the edges of a box, like [`border-style`](border-style), [`margin`](margin) or [`padding`](padding) * properties related to the corners of a box, like [`border-radius`](border-radius) #### Edges of a box Shorthands handling properties related to edges of a box, like [`border-style`](border-style), [`margin`](margin) or [`padding`](padding), always use a consistent 1-to-4-value syntax representing those edges: * **1-value syntax:** `border-width: 1em` — The single value represents all edges: * **2-value syntax:** `border-width: 1em 2em` — The first value represents the vertical, that is top and bottom, edges, the second the horizontal ones, that is the left and right ones: * **3-value syntax:** `border-width: 1em 2em 3em` — The first value represents the top edge, the second, the horizontal, that is left and right, ones, and the third value the bottom edge: * **4-value syntax:** `border-width: 1em 2em 3em 4em` — The four values represent the top, right, bottom and left edges respectively, always in that order, that is clock-wise starting at the top: The initial letter of Top-Right-Bottom-Left matches the order of the consonant of the word *trouble*: TRBL. You can also remember it as the order that the hands would rotate on a clock: `1em` starts in the 12 o'clock position, then `2em` in the 3 o'clock position, then `3em` in the 6 o'clock position, and `4em` in the 9 o'clock position. #### Corners of a box Similarly, shorthands handling properties related to corners of a box, like [`border-radius`](border-radius), always use a consistent 1-to-4-value syntax representing those corners: * **1-value syntax:** `border-radius: 1em` — The single value represents all corners: * **2-value syntax:** `border-radius: 1em 2em` — The first value represents the top left and bottom right corner, the second the top right and bottom left ones: * **3-value syntax:** `border-radius: 1em 2em 3em` — The first value represents the top left corner, the second the top right and bottom left ones, and the third value the bottom right corner: * **4-value syntax:** `border-radius: 1em 2em 3em 4em` — The four values represent the top left, top right, bottom right and bottom left corners respectively, always in that order, that is clock-wise starting at the top left: Background properties --------------------- Consider a background with the following properties ``` background-color: #000; background-image: url(images/bg.gif); background-repeat: no-repeat; background-position: left top; ``` These four declarations can be shortened to just one: ``` background: #000 url(images/bg.gif) no-repeat left top; ``` (The shorthand form is actually the equivalent of the longhand properties above plus `background-attachment: scroll` and, in CSS3, some additional properties.) See [`background`](background) for more detailed information, including CSS3 properties. Font properties --------------- Consider the following declarations: ``` font-style: italic; font-weight: bold; font-size: 0.8em; line-height: 1.2; font-family: Arial, sans-serif; ``` This 5 statements can be shortened to the following: ``` font: italic bold 0.8em/1.2 Arial, sans-serif; ``` This shorthand declaration is actually equivalent to the longhand declarations above plus `font-variant: normal`, `font-size-adjust: none`, and `font-stretch: normal`. Border properties ----------------- With borders, the width, color, and style can be simplified into one declaration. For example, consider the following CSS: ``` border-width: 1px; border-style: solid; border-color: #000; ``` It can be simplified as: ``` border: 1px solid #000; ``` Margin and padding properties ----------------------------- Shorthand versions of margin and padding values work similarly; the margin property allows for shorthand values to be specified using one, two, three, or four values. Consider the following CSS declarations: ``` margin-top: 10px; margin-right: 5px; margin-bottom: 10px; margin-left: 5px; ``` They are the same as the following declaration using the four value shorthand. Note that the values are in clockwise order, beginning at the top: top, right, bottom, then left (TRBL, the consonants in "trouble"). ``` margin: 10px 5px 10px 5px; ``` Margin shorthand rules for one, two, three and four value declarations are: * When **one** value is specified, it applies the same margin to **all four sides**. * When **two** values are specified, the first margin applies to the **top and bottom**, the second to the **left and right**. * When **three** values are specified, the first margin applies to the **top**, the second to the **left and right**, the third to the **bottom**. * When **four** values are specified, the margins apply to the **top**, **right**, **bottom**, and **left** in that order (clockwise). Position properties ------------------- With position, the shorthand versions of top, right, bottom and left can be simplified into one declaration. For example, consider the following CSS: ``` top: 0; right: 20px; bottom: 0; left: 20px; ``` It can be simplified as: ``` inset: 0 20px 0 20px; ``` Just like margins and paddings, the inset values are ordered clockwise - top, right, bottom, then left (TRBL). The universal shorthand property -------------------------------- CSS provides a universal shorthand property, [`all`](all), which applies its value to every property in the document. Its purpose is to change the properties' inheritance model. See [Cascade and inheritance](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Cascade_and_inheritance) or [Introducing the CSS Cascade](cascade) for more information about how inheritance works in CSS. See also -------- * CSS key concepts: + [CSS syntax](syntax) + [At-rules](at-rule) + [Comments](comments) + [Specificity](specificity) + [Inheritance](inheritance) + [Box model](css_box_model/introduction_to_the_css_box_model) + [Layout modes](layout_mode) + [Visual formatting models](visual_formatting_model) + [Margin collapsing](css_box_model/mastering_margin_collapsing) + Values - [Initial values](initial_value) - [Computed values](computed_value) - [Used values](used_value) - [Actual values](actual_value) + [Value definition syntax](value_definition_syntax) + [Replaced elements](replaced_element) * Shorthand properties: + [`all`](all) + [`animation`](animation) + [`background`](background) + [`border`](border) + [`border-block-end`](border-block-end) + [`border-block-start`](border-block-start) + [`border-bottom`](border-bottom) + [`border-color`](border-color) + [`border-image`](border-image) + [`border-inline-end`](border-inline-end) + [`border-inline-start`](border-inline-start) + [`border-left`](border-left) + [`border-radius`](border-radius) + [`border-right`](border-right) + [`border-style`](border-style) + [`border-top`](border-top) + [`border-width`](border-width) + [`column-rule`](column-rule) + [`columns`](columns) + [`contain-intrinsic-size`](contain-intrinsic-size) + [`flex`](flex) + [`flex-flow`](flex-flow) + [`font`](font) + [`gap`](gap) + [`grid`](grid) + [`grid-area`](grid-area) + [`grid-column`](grid-column) + [`grid-row`](grid-row) + [`grid-template`](grid-template) + [`inset`](inset) + [`list-style`](list-style) + [`margin`](margin) + [`mask`](mask) + [`offset`](offset) + [`outline`](outline) + [`overflow`](overflow) + [`padding`](padding) + [`place-content`](place-content) + [`place-items`](place-items) + [`place-self`](place-self) + [`scroll-margin`](scroll-margin) + [`scroll-padding`](scroll-padding) + [`scroll-timeline`](scroll-timeline) + [`text-decoration`](text-decoration) + [`text-emphasis`](text-emphasis) + [`transition`](transition) css border-block-start border-block-start ================== The `border-block-start` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property is a [shorthand property](shorthand_properties) for setting the individual logical block-start border property values in a single place in the style sheet. Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`border-block-start-color`](border-block-start-color) * [`border-block-start-style`](border-block-start-style) * [`border-block-start-width`](border-block-start-width) Syntax ------ ``` border-block-start: 1px; border-block-start: 2px dotted; border-block-start: medium dashed blue; /\* Global values \*/ border-block-start: inherit; border-block-start: initial; border-block-start: revert; border-block-start: revert-layer; border-block-start: unset; ``` `border-block-start` can be used to set the values for one or more of [`border-block-start-width`](border-block-start-width), [`border-block-start-style`](border-block-start-style), and [`border-block-start-color`](border-block-start-color). The physical border to which it maps depends on the element's writing mode, directionality, and text orientation. It corresponds to the [`border-top`](border-top), [`border-right`](border-right), [`border-bottom`](border-bottom), or [`border-left`](border-left) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Related properties are [`border-block-end`](border-block-end), [`border-inline-start`](border-inline-start), and [`border-inline-end`](border-inline-end), which define the other borders of the element. ### Values The `border-block-start` is specified with one or more of the following, in any order: `<'border-width'>` The width of the border. See [`border-width`](border-width). `<'border-style'>` The line style of the border. See [`border-style`](border-style). `<'color'>` The color of the border. See [`color`](color). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`border-width`](border-width): as each of the properties of the shorthand: + [`border-top-width`](border-top-width): `medium` + [`border-right-width`](border-right-width): `medium` + [`border-bottom-width`](border-bottom-width): `medium` + [`border-left-width`](border-left-width): `medium` * [`border-style`](border-style): as each of the properties of the shorthand: + [`border-top-style`](border-top-style): `none` + [`border-right-style`](border-right-style): `none` + [`border-bottom-style`](border-bottom-style): `none` + [`border-left-style`](border-left-style): `none` * [`color`](color): `canvastext` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`border-width`](border-width): as each of the properties of the shorthand: + [`border-bottom-width`](border-bottom-width): the absolute length or `0` if [`border-bottom-style`](border-bottom-style) is `none` or `hidden` + [`border-left-width`](border-left-width): the absolute length or `0` if [`border-left-style`](border-left-style) is `none` or `hidden` + [`border-right-width`](border-right-width): the absolute length or `0` if [`border-right-style`](border-right-style) is `none` or `hidden` + [`border-top-width`](border-top-width): the absolute length or `0` if [`border-top-style`](border-top-style) is `none` or `hidden` * [`border-style`](border-style): as each of the properties of the shorthand: + [`border-bottom-style`](border-bottom-style): as specified + [`border-left-style`](border-left-style): as specified + [`border-right-style`](border-right-style): as specified + [`border-top-style`](border-top-style): as specified * [`border-block-start-color`](border-block-start-color): computed color | | Animation type | as each of the properties of the shorthand:* [`border-block-start-color`](border-block-start-color): a [color](color_value#interpolation) * [`border-block-start-style`](border-block-start-style): discrete * [`border-block-start-width`](border-block-start-width): a [length](length#interpolation) | Formal syntax ------------- ``` border-block-start = <'border-top-width'> [||](value_definition_syntax#double_bar) <'border-top-style'> [||](value_definition_syntax#double_bar) [<color>](color_value) ``` Examples -------- ### Border with vertical text #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-rl; border-block-start: 5px dashed blue; } ``` Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # border-shorthands](https://w3c.github.io/csswg-drafts/css-logical/#border-shorthands) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-block-start` | 69 | 79 | 41 | No | 56 | 12.1 | 69 | 69 | 41 | 48 | 12.2 | 10.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * This property maps to one of the physical border properties: [`border-top`](border-top), [`border-right`](border-right), [`border-bottom`](border-bottom), or [`border-left`](border-left). * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation)
programming_docs
css calc() calc() ====== The `calc()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](css_functions) lets you perform calculations when specifying CSS property values. It can be used with [`<length>`](length), [`<frequency>`](frequency), [`<angle>`](angle), [`<time>`](time), [`<percentage>`](percentage), [`<number>`](number), or [`<integer>`](integer) values. Try it ------ Syntax ------ ``` /\* property: calc(expression) \*/ width: calc(100% - 80px); ``` The `calc()` function takes a single expression as its parameter, with the expression's result used as the value. The expression can be any simple expression combining the following operators, using standard [operator precedence rules](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Math#operator_precedence): `+` Addition. `-` Subtraction. `*` Multiplication. At least one of the arguments must be a [`<number>`](number). `/` Division. The right-hand side must be a [`<number>`](number). The operands in the expression may be any [`<length>`](length) syntax value. You can use different units for each value in your expression, if you wish. You may also use parentheses to establish computation order when needed. ### Notes * The `+` and `-` operators **must be surrounded by [whitespace](https://developer.mozilla.org/en-US/docs/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. * Division by zero results in an error being generated by the HTML parser. * 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 ``` <calc()> = calc( <calc-sum> ) <calc-sum> = <calc-product> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '+' [|](value_definition_syntax#single_bar) '-' []](value_definition_syntax#brackets) <calc-product> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-product> = <calc-value> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '*' [|](value_definition_syntax#single_bar) '/' []](value_definition_syntax#brackets) <calc-value> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-value> = [<number>](number) [|](value_definition_syntax#single_bar) [<dimension>](dimension) [|](value_definition_syntax#single_bar) [<percentage>](percentage) [|](value_definition_syntax#single_bar) <calc-constant> [|](value_definition_syntax#single_bar) ( <calc-sum> ) <calc-constant> = e [|](value_definition_syntax#single_bar) pi [|](value_definition_syntax#single_bar) infinity [|](value_definition_syntax#single_bar) -infinity [|](value_definition_syntax#single_bar) NaN ``` Accessibility concerns ---------------------- When `calc()` is used for controlling text size, be sure that one of the values includes a [relative length unit](length#relative_length_units), for example: ``` 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](https://developer.mozilla.org/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 [`<integer>`](integer) is expected, the value will be rounded to the nearest integer. For example: ``` .modal { z-index: calc(3 / 2); } ``` This will give `.modal` a final `z-index` value of 2. **Note:** The Chrome browser currently won't accept some values returned by `calc()` when an integer is expected. This includes any division, even if it results in an integer, i.e. `z-index: calc(4 / 2);` will not be accepted. 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: ``` .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; } ``` ``` <div class="banner">This is a banner!</div> ``` ### 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: ``` input { padding: 2px; display: block; width: calc(100% - 1em); } #formbox { 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: ``` <form> <div id="formbox"> <label for="misc">Type something:</label> <input type="text" id="misc" name="misc" /> </div> </form> ``` ### Nested `calc()` with CSS Variables You can also use `calc()` with [CSS variables](css_variables). Consider the following code: ``` .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 -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # calc-func](https://w3c.github.io/csswg-drafts/css-values/#calc-func) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `calc` | 26 19 | 12 | 16 ["Before Firefox 59 `calc()` is not supported in `rgb()` and other color functions.", "Before Firefox 57 `calc(1*2*3)` is not parsed successfully.", "Firefox 57 increased the number of places `calc()` could substitute another value. See [bug 1350857](https://bugzil.la/1350857)."] 4-53 | 9 | 15 | 7 6 | ≤37 ≤37 | 28 | 16 ["Before Firefox 59 `calc()` is not supported in `rgb()` and other color functions.", "Before Firefox 57 `calc(1*2*3)` is not parsed successfully.", "Firefox 57 increased the number of places `calc()` could substitute another value. See [bug 1350857](https://bugzil.la/1350857)."] 4-53 | 14 | 7 6 | 1.5 | | `gradient_color_stops` | 19 | 12 | 19 | 9 | 15 | 6 | 37 | 28 | 19 | 15 | 6 | 1.5 | | `nested` | 51 | 16 | 48 | No | 38 | 11 | 51 | 51 | 48 | 41 | 11 | 5.0 | | `number_values` | 31 | 12 | 48 | 9 | 18 | 6 | 4.4.3 | 31 | 48 | 18 | 6 | 2.0 | See also -------- * [CSS functions](css_functions) * [A Complete Guide to calc() in CSS](https://css-tricks.com/a-complete-guide-to-calc-in-css/) (CSS-Tricks) css inset-inline inset-inline ============ The `inset-inline` [CSS](https://developer.mozilla.org/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 [`top`](top) and [`bottom`](bottom), or [`right`](right) and [`left`](left) properties depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`inset-inline-end`](inset-inline-end) * [`inset-inline-start`](inset-inline-start) Syntax ------ ``` /\* <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 [`left`](left) property. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`inset-inline-start`](inset-inline-start): `auto` * [`inset-inline-end`](inset-inline-end): `auto` | | Applies to | positioned elements | | [Inherited](inheritance) | no | | Percentages | logical-width of containing block | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`inset-inline-start`](inset-inline-start): same as box offsets: [`top`](top), [`right`](right), [`bottom`](bottom), [`left`](left) properties except that directions are logical * [`inset-inline-end`](inset-inline-end): same as box offsets: [`top`](top), [`right`](right), [`bottom`](bottom), [`left`](left) properties except that directions are logical | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` inset-inline = [<top>](top)[{1,2}](value_definition_syntax#curly_braces) ``` Examples -------- ### Setting inline start and end offsets #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; position: relative; inset-inline: 20px 50px; background-color: #c8c800; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # propdef-inset-inline](https://w3c.github.io/csswg-drafts/css-logical/#propdef-inset-inline) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `inset-inline` | 87 | 87 | 63 41-63 | No | 73 | 14.1 | 87 | 87 | 63 41-63 | 62 | 14.5 | 14.0 | See also -------- * The mapped physical properties: [`top`](top), [`right`](right), [`bottom`](bottom), and [`left`](left) * The mapped physical shortcut: [`inset`](inset) * The mapped block shortcut: [`inset-block`](inset-block) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css text-align-last text-align-last =============== The `text-align-last` CSS property sets how the last line of a block or a line, right before a forced line break, is aligned. Try it ------ Syntax ------ ``` /\* Keyword values \*/ text-align-last: auto; text-align-last: start; text-align-last: end; text-align-last: left; text-align-last: right; text-align-last: center; text-align-last: justify; /\* Global values \*/ text-align-last: inherit; text-align-last: initial; text-align-last: revert; text-align-last: revert-layer; text-align-last: unset; ``` ### Values `auto` The affected line is aligned per the value of [`text-align`](text-align), unless [`text-align`](text-align) is `justify`, in which case the effect is the same as setting `text-align-last` to `start`. `start` The same as `left` if direction is left-to-right and `right` if direction is right-to-left. `end` The same as `right` if direction is left-to-right and `left` if direction is right-to-left. `left` The inline contents are aligned to the left edge of the line box. `right` The inline contents are aligned to the right edge of the line box. `center` The inline contents are centered within the line box. `justify` The text is justified. Text should line up their left and right edges to the left and right content edges of the paragraph. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | block containers | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` text-align-last = auto [|](value_definition_syntax#single_bar) start [|](value_definition_syntax#single_bar) end [|](value_definition_syntax#single_bar) left [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) justify [|](value_definition_syntax#single_bar) match-parent ``` Examples -------- ### Justifying the last line #### CSS ``` p { font-size: 1.4em; text-align: justify; text-align-last: center; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Text Module Level 3 # text-align-last-property](https://w3c.github.io/csswg-drafts/css-text/#text-align-last-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `text-align-last` | 47 | 12 | 49 12-53 | 5.5 ["IE only supports `text-align-last` when `text-align` is set to `justify`.", "The `start` and `end` values are not supported."] | 34 | 16 | 47 | 47 | 49 14-53 | 34 | 16 | 5.0 | See also -------- * [`text-align`](text-align) css <length> <length> ======== The `<length>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) represents a distance value. Lengths can be used in numerous CSS properties, such as [`width`](width), [`height`](height), [`margin`](margin), [`padding`](padding), [`border-width`](border-width), [`font-size`](font-size), and [`text-shadow`](text-shadow). **Note:** Although [`<percentage>`](percentage) values are usable in some of the same properties that accept `<length>` values, they are not themselves `<length>` values. See [`<length-percentage>`](length-percentage). Syntax ------ The `<length>` data type consists of a [`<number>`](number) followed by one of the units listed below. As with all CSS dimensions, there is no space between the number and the unit literal. Specifying the length unit is optional if the number is `0`. **Note:** Some properties allow negative `<length>` values, while others do not. The [specified value](specified_value) of a length (*specified length*) is represented by its quantity and unit. The [computed value](computed_value) of a length (*computed length*) is the specified length resolved to an absolute length, and its unit is not distinguished. The `<length>` units can be relative or absolute. Relative lengths represent a measurement in terms of some other distance. Depending on the unit, this distance can be the size of a specific character, the [line height](line-height), or the size of the [viewport](https://developer.mozilla.org/en-US/docs/Glossary/Viewport). Style sheets that use relative length units can more easily scale from one output environment to another. **Note:** Child elements do not inherit the relative values as specified for their parent; they inherit the computed values. The relative length units listed here are based on font and viewport. ### Relative length units based on font Font lengths define the `<length>` value in terms of the size of a particular character or font attribute in the font currently in effect in an element or its parent. **Note:** These units, especially `em` and `rem`, are often used to create scalable layouts, which maintain the vertical rhythm of the page even when the user changes the font size. `cap` Experimental Represents the "cap height" (nominal height of capital letters) of the element's [`font`](font). `ch` Represents the width or more precisely the [advance measure](https://developer.mozilla.org/en-US/docs/Glossary/Advance_measure) of the glyph `0` (zero, the Unicode character U+0030) in the element's [`font`](font). In cases where it is impossible or impractical to determine the measure of the `0` glyph, it must be assumed to be `0.5em` wide by `1em` tall. `em` Represents the calculated [`font-size`](font-size) of the element. If used on the [`font-size`](font-size) property itself, it represents the *inherited* font-size of the element. `ex` Represents the [x-height](https://en.wikipedia.org/wiki/X-height) of the element's [`font`](font). In fonts with the `x` letter, this is generally the height of lowercase letters in the font; `1ex ≈ 0.5em` in many fonts. `ic` Equal to the used [advance measure](https://developer.mozilla.org/en-US/docs/Glossary/Advance_measure) of the "水" glyph (CJK water ideograph, U+6C34), found in the font used to render it. `lh` Experimental Non-standard Equal to the computed value of the [`line-height`](line-height) property of the element on which it is used, converted to an absolute length. `rem` Represents the [`font-size`](font-size) of the root element (typically [`<html>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html)). When used within the root element [`font-size`](font-size), it represents its initial value (a common browser default is `16px`, but user-defined preferences may modify this). `rlh` Experimental Non-standard Equal to the computed value of the [`line-height`](line-height) property on the root element (typically [`<html>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html)), converted to an absolute length. When used on the [`font-size`](font-size) or [`line-height`](line-height) properties of the root element, it refers to the properties' initial value. ### Relative length units based on viewport The viewport-percentage length units are based on four different viewport sizes: small, large, dynamic, and default. The allowance for the different viewport sizes is in response to browser interfaces expanding and retracting dynamically and hiding and showing the content underneath. **Small** When you want the smallest possible viewport in response to browser interfaces expanding dynamically, you should use the small viewport size. The small viewport size allows the content you design to fill the entire viewport when browser interfaces are expanded. Choosing this size might also possibly leave empty spaces when browser interfaces retract. For example, an element that is sized using viewport-percentage units based on the small viewport size, the element will fill the screen perfectly without any of its content being obscured when all the dynamic browser interfaces are shown. When those browser interfaces are hidden, however, there might be extra space visible around the element. Therefore, the small viewport-percentage units are "safer" to use in general, but might not produce the most attractive layout after a user starts interacting with the page. The small viewport size is represented by the `sv` prefix and results in the `sv*` viewport-percentage length units. The sizes of the small viewport-percentage units are fixed, and therefore stable, unless the viewport itself is resized. **Large** When you want the largest possible viewport in response to browser interfaces retracting dynamically, you should use the large viewport size. The large viewport size allows the content you design to fill the entire viewport when browser interfaces are retracting. You need to be aware though that the content might get hidden when browser interfaces expand. For example, on mobile phones where the screen real-estate is at a premium, browsers often hide part or all of the title and address bar after a user starts scrolling the page. When an element is sized using a viewport-percentage unit based on the large viewport size, the content of the element will fill the entire visible page when these browser interfaces are hidden. However, when these retractable browser interfaces are shown, they can hide the content that is sized or positioned using the *large* viewport-percentage units. The large viewport unit is represented by the `lv` prefix and results in the `lv*` viewport-percentage units. The sizes of the large viewport-percentage units are fixed, and therefore stable, unless the viewport itself is resized. **Dynamic** When you want the viewport to be automatically sized in response to browser interfaces dynamically expanding or retracting, you can use the dynamic viewport size. The dynamic viewport size allows the content you design to fit exactly within the viewport, irrespective of the presence of dynamic browser interfaces. The dynamic viewport unit is represented by the `dv` prefix and results in the `dv*` viewport-percentage units. The sizes of the dynamic viewport-percentage units are not stable, even when the viewport itself is unchanged. **Note:** While the dynamic viewport size can give you more control and flexibility, using viewport-percentage units based on the dynamic viewport size can cause the content to resize while a user is scrolling a page. This can lead to degradation of the user interface and cause a performance hit. **Default** The default viewport size is defined by the browser. The behavior of the resulting viewport-percentage unit could be equivalent to the viewport-percentage unit based on the small viewport size, the large viewport size, an intermediate size between the two, or the dynamic viewport size. **Note:** For example, a browser might implement the default viewport-percentage unit for height (`vh`) that is equivalent to the large viewport-percentage height unit (`lvh`). If so, this could obscure content on a full-page display while the browser interface is expanded. Viewport-percentage lengths define `<length>` values in percentage relative to the size of the initial [containing block](containing_block), which in turn is based on either the size of the [viewport](https://developer.mozilla.org/en-US/docs/Glossary/Viewport) or the page area, i.e., the visible portion of the document. When the height or width of the initial containing block is changed, the elements that are sized based on them are scaled accordingly. There is a viewport-percentage length unit variant corresponding to each of the viewport sizes, as described below. **Note:** Viewport lengths are invalid in [`@page`](@page) declaration blocks. `vh` Represents a percentage of the height of the viewport's initial [containing block](containing_block). `1vh` is 1% of the viewport height. For example, if the viewport height is `300px`, then a value of `70vh` on a property will be `210px`. For small, large, and dynamic viewport sizes, the respective viewport-percentage units are `svh`, `lvh`, and `dvh`. `vh` represents the viewport-percentage length unit based on the browser default viewport size. `vw` Represents a percentage of the width of the viewport's initial [containing block](containing_block). `1vw` is 1% of the viewport width. For example, if the viewport width is `800px`, then a value of `50vw` on a property will be `400px`. For small, large, and dynamic viewport sizes, the respective viewport-percentage units are `svw`, `lvw`, and `dvw`. `vw` represents the viewport-percentage length unit based on the browser default viewport size. `vmax` Represents in percentage the largest of `vw` and `vh`. For small, large, and dynamic viewport sizes, the respective viewport-percentage units are `svmax`, `lvmax`, and `dvmax`. `vmax` represents the viewport-percentage length unit based on the browser default viewport size. `vmin` Represents in percentage the smallest of `vw` and `vh`. For small, large, and dynamic viewport sizes, the respective viewport-percentage units are `svmin`, `lvmin`, and `dvmin`. `vmin` represents the viewport-percentage length unit based on the browser default viewport size. `vb` Represents percentage of the size of the initial [containing block](containing_block), in the direction of the root element's [block axis](css_logical_properties#block_vs._inline). For small, large, and dynamic viewport sizes, the respective viewport-percentage units are `svb`, `lvb`, and `dvb`, respectively. `vb` represents the viewport-percentage length unit based on the browser default viewport size. `vi` Represents a percentage of the size of the initial [containing block](containing_block), in the direction of the root element's [inline axis](css_logical_properties#block_vs._inline). For small, large, and dynamic viewport sizes, the respective viewport-percentage units are `svi`, `lvi`, and `dvi`. `vi` represents the viewport-percentage length unit based on the browser default viewport size. ### Container query length units When applying styles to a container using container queries, you can use container query length units. These units specify a length relative to the dimensions of a query container. Components that use units of length relative to their container are more flexible to use in different containers without having to recalculate concrete length values. For more information, see [Container queries](css_container_queries). `cqw` Represents a percentage of the width of the query container. `1cqw` is 1% of the query container's width. For example, if the query container's width is `800px`, then a value of `50cqw` on a property will be `400px`. `cqh` Represents a percentage of the height of the query container. `1cqh` is 1% of the query container's height. For example, if the query container's height is `300px`, then a value of `10cqh` on a property will be `30px`. `cqi` Represents a percentage of the inline size of the query container. `1cqi` is 1% of the query container's inline size. For example, if the query container's inline size is `800px`, then a value of `50cqi` on a property will be `400px`. `cqb` Represents a percentage of the block size of the query container. `1cqb` is 1% of the query container's block size. For example, if the query container's block size is `300px`, then a value of `10cqb` on a property will be `30px`. `cqmin` Represents a percentage of the smaller value of either the query container's inline size or block size. `1cqmin` is 1% of the smaller value of either the query container's inline size or block size. For example, if the query container's inline size is `800px` and its block size is `300px`, then a value of `50cqmin` on a property will be `150px`. `cqmax` Represents a percentage of the larger value of either the query container's inline size or block size. `1cqmax` is 1% of the larger value of either the query container's inline size or block size. For example, if the query container's inline size is `800px` and its block size is `300px`, then a value of `50cqmax` on a property will be `400px`. #### Absolute length units Absolute length units represent a physical measurement when the physical properties of the output medium are known, such as for print layout. This is done by anchoring one of the units to a physical unit and then defining the others relative to it. The anchoring is done differently for low-resolution devices, such as screens, versus high-resolution devices, such as printers. For low-dpi devices, the unit `px` represents the physical *reference pixel*; other units are defined relative to it. Thus, `1in` is defined as `96px`, which equals `72pt`. The consequence of this definition is that on such devices, dimensions described in inches (`in`), centimeters (`cm`), or millimeters (`mm`) don't necessarily match the size of the physical unit with the same name. For high-dpi devices, inches (`in`), centimeters (`cm`), and millimeters (`mm`) are the same as their physical counterparts. Therefore, the `px` unit is defined relative to them (1/96 of `1in`). **Note:** Many users increase their [user agent](https://developer.mozilla.org/en-US/docs/Glossary/User_agent)'s default font size to make text more legible. Absolute lengths can cause accessibility problems because they are fixed and do not scale according to user settings. For this reason, prefer relative lengths (such as `em` or `rem`) when setting `font-size`. `px` One pixel. For screen displays, it traditionally represents one device pixel (dot). However, for *printers* and *high-resolution screens*, one CSS pixel implies multiple device pixels. `1px` = 1/96th of `1in`. `cm` One centimeter. `1cm` = `96px/2.54`. `mm` One millimeter. `1mm` = 1/10th of `1cm`. `Q` One quarter of a millimeter. `1Q` = 1/40th of `1cm`. `in` One inch. `1in` = `2.54cm` = `96px`. `pc` One pica. `1pc` = `12pt` = 1/6th of `1in`. `pt` One point. `1pt` = 1/72nd of `1in`. Interpolation ------------- When animated, values of the `<length>` data type are interpolated as real, floating-point numbers. The interpolation happens on the calculated value. The speed of the interpolation is determined by the [timing function](easing-function) associated with the animation. Examples -------- ### Comparing different length units The following example provides you with an input field in which you can enter a `<length>` value (e.g. `300px`, `50%`, `30vw`) to set the width of a result bar that will appear below it once you've pressed the `Enter` or the `Return` key. This allows you to compare and contrast the effect of different length units. #### HTML ``` <div class="outer"> <div class="input-container"> <label for="length">Enter width:</label> <input type="text" id="length" /> </div> <div class="inner"></div> </div> <div class="results"></div> ``` #### CSS ``` html { font-family: sans-serif; font-weight: bold; box-sizing: border-box; } .outer { width: 100%; height: 50px; background-color: #eee; position: relative; } .inner { height: 50px; background-color: #999; box-shadow: inset 3px 3px 5px rgba(255, 255, 255, 0.5), inset -3px -3px 5px rgba(0, 0, 0, 0.5); } .result { height: 20px; box-shadow: inset 3px 3px 5px rgba(255, 255, 255, 0.5), inset -3px -3px 5px rgba(0, 0, 0, 0.5); background-color: orange; display: flex; align-items: center; margin-top: 10px; } .result code { position: absolute; margin-left: 20px; } .results { margin-top: 10px; } .input-container { position: absolute; display: flex; justify-content: flex-start; align-items: center; height: 50px; } label { margin: 0 10px 0 20px; } ``` #### JavaScript ``` const inputDiv = document.querySelector(".inner"); const inputElem = document.querySelector("input"); const resultsDiv = document.querySelector(".results"); inputElem.addEventListener("change", () => { inputDiv.style.width = inputElem.value; const result = document.createElement("div"); result.className = "result"; result.style.width = inputElem.value; result.innerHTML = `<code>width: ${inputElem.value}</code>`; resultsDiv.appendChild(result); inputElem.value = ""; inputElem.focus(); }); ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # lengths](https://w3c.github.io/csswg-drafts/css-values/#lengths) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `Q` | 63 | 79 | 49 | No | 50 | No | 63 | 63 | 49 | 46 | No | 8.0 | | `length` | 1 | 12 | 1 | 3 | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | | `cap` | No | No | 97 | No | No | No | No | No | 97 | No | No | No | | `ch` | 27 | 12 | 1 ["From Firefox 1 to Firefox 3, `ch` was the width of the *M* character.", "From Firefox 1 to Firefox 3, `ch` did not work with [`border-width`](https://developer.mozilla.org/docs/Web/CSS/border-width) and [`outline-width`](https://developer.mozilla.org/docs/Web/CSS/outline-width) CSS properties."] | 9 | 15 | 7 | 4.4 | 27 | 4 | 15 | 7 | 1.5 | | `container_query_length_units` | 105 | 105 | preview | No | 91 | 16 | 105 | 105 | No | 72 | 16 | No | | `ex` | 1 | 12 | 1 | 4 | 3.5 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `ic` | 106 | 106 | 97 | No | 92 | 15.4 | 106 | 106 | 97 | 72 | 15.4 | No | | `lh` | No See [bug 937104](https://crbug.com/937104). | No See [bug 937104](https://crbug.com/937104). | No See [bug 1310170](https://bugzil.la/1310170). | No | No See [bug 937104](https://crbug.com/937104). | No | No See [bug 937104](https://crbug.com/937104). | No See [bug 937104](https://crbug.com/937104). | No See [bug 1310170](https://bugzil.la/1310170). | No See [bug 937104](https://crbug.com/937104). | No | No See [bug 937104](https://crbug.com/937104). | | `rem` | 4 | 12 | 3.6 | 9 | 11.6 | 5 | 2 | 18 | 4 | 12 | 4 | 1.0 | | `rlh` | No See [bug 937104](https://crbug.com/937104). | No See [bug 937104](https://crbug.com/937104). | No See [bug 1310170](https://bugzil.la/1310170). | No | No See [bug 937104](https://crbug.com/937104). | No | No See [bug 937104](https://crbug.com/937104). | No See [bug 937104](https://crbug.com/937104). | No See [bug 1310170](https://bugzil.la/1310170). | No See [bug 937104](https://crbug.com/937104). | No | No See [bug 937104](https://crbug.com/937104). | | `vb` | 108 | 108 | 101 | No | 94 | 15.4 | 108 | 108 | 101 | No | 15.4 | No | | `vh` | 20 | 12 | 19 Starting with version 21, viewport-percentage lengths are invalid in `@page`. | 9 | 20 | 6 | 4.4 | 25 | 19 Starting with version 21, viewport-percentage lengths are invalid in `@page`. | 14 | 6 | 1.5 | | `vi` | 108 | 108 | 101 | No | 94 | 15.4 | 108 | 108 | 101 | No | 15.4 | No | | `viewport_percentage_units_dynamic` | 108 | 108 | 101 | No | 94 | 15.4 | 108 | 108 | 101 | No | 15.4 | No | | `viewport_percentage_units_large` | 108 | 108 | 101 | No | 94 | 15.4 | 108 | 108 | 101 | No | 15.4 | No | | `viewport_percentage_units_small` | 108 | 108 | 101 | No | 94 | 15.4 | 108 | 108 | 101 | No | 15.4 | No | | `vmax` | 26 | 16 | 19 Starting with version 21, viewport-percentage lengths are invalid in `@page`. | No | 15 | 7 | 1.5 | 26 | 19 Starting with version 21, viewport-percentage lengths are invalid in `@page`. | 14 | 7 | 1.5 | | `vmin` | 26 | 12 12 | 19 Starting with version 21, viewport-percentage lengths are invalid in `@page`. | 10 9 | 15 | 7 | 4.4 | 26 | 19 Starting with version 21, viewport-percentage lengths are invalid in `@page`. | 14 | 7 | 1.5 | | `vw` | 20 | 12 | 19 Starting with version 21, viewport-percentage lengths are invalid in `@page`. | 9 | 20 | 6 | 4.4 | 25 | 19 Starting with version 21, viewport-percentage lengths are invalid in `@page`. | 14 | 6 | 1.5 | See also -------- * [CSS values & units tutorial](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units) * [CSS values & units reference](css_values_and_units) * [Box Model](css_box_model)
programming_docs
css border-style border-style ============ The `border-style` [shorthand](shorthand_properties) [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the line style for all four sides of an element's border. Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`border-bottom-style`](border-bottom-style) * [`border-left-style`](border-left-style) * [`border-right-style`](border-right-style) * [`border-top-style`](border-top-style) Syntax ------ ``` /\* Keyword values \*/ border-style: none; border-style: hidden; border-style: dotted; border-style: dashed; border-style: solid; border-style: double; border-style: groove; border-style: ridge; border-style: inset; border-style: outset; /\* top and bottom | left and right \*/ border-style: dotted solid; /\* top | left and right | bottom \*/ border-style: hidden double dashed; /\* top | right | bottom | left \*/ border-style: none solid dotted dashed; /\* Global values \*/ border-style: inherit; border-style: initial; border-style: revert; border-style: revert-layer; border-style: unset; ``` The `border-style` property may be specified using one, two, three, or four values. * When **one** value is specified, it applies the same style to **all four sides**. * When **two** values are specified, the first style applies to the **top and bottom**, the second to the **left and right**. * When **three** values are specified, the first style applies to the **top**, the second to the **left and right**, the third to the **bottom**. * When **four** values are specified, the styles apply to the **top**, **right**, **bottom**, and **left** in that order (clockwise). Each value is a keyword chosen from the list below. ### Values `<line-style>` Describes the style of the border. It can have the following values: `none` Like the `hidden` keyword, displays no border. Unless a [`background-image`](background-image) is set, the computed value of the same side's [`border-width`](border-width) will be `0`, even if the specified value is something else. In the case of table cell and border collapsing, the `none` value has the *lowest* priority: if any other conflicting border is set, it will be displayed. `hidden` Like the `none` keyword, displays no border. Unless a [`background-image`](background-image) is set, the computed value of the same side's [`border-width`](border-width) will be `0`, even if the specified value is something else. In the case of table cell and border collapsing, the `hidden` value has the *highest* priority: if any other conflicting border is set, it won't be displayed. `dotted` Displays a series of rounded dots. The spacing of the dots is not defined by the specification and is implementation-specific. The radius of the dots is half the computed value of the same side's [`border-width`](border-width). `dashed` Displays a series of short square-ended dashes or line segments. The exact size and length of the segments are not defined by the specification and are implementation-specific. `solid` Displays a single, straight, solid line. `double` Displays two straight lines that add up to the pixel size defined by [`border-width`](border-width). `groove` Displays a border with a carved appearance. It is the opposite of `ridge`. `ridge` Displays a border with an extruded appearance. It is the opposite of `groove`. `inset` Displays a border that makes the element appear embedded. It is the opposite of `outset`. When applied to a table cell with [`border-collapse`](border-collapse) set to `collapsed`, this value behaves like `groove`. `outset` Displays a border that makes the element appear embossed. It is the opposite of `inset`. When applied to a table cell with [`border-collapse`](border-collapse) set to `collapsed`, this value behaves like `ridge`. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`border-top-style`](border-top-style): `none` * [`border-right-style`](border-right-style): `none` * [`border-bottom-style`](border-bottom-style): `none` * [`border-left-style`](border-left-style): `none` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`border-bottom-style`](border-bottom-style): as specified * [`border-left-style`](border-left-style): as specified * [`border-right-style`](border-right-style): as specified * [`border-top-style`](border-top-style): as specified | | Animation type | discrete | Formal syntax ------------- ``` border-style = <line-style>[{1,4}](value_definition_syntax#curly_braces) <line-style> = none [|](value_definition_syntax#single_bar) hidden [|](value_definition_syntax#single_bar) dotted [|](value_definition_syntax#single_bar) dashed [|](value_definition_syntax#single_bar) solid [|](value_definition_syntax#single_bar) double [|](value_definition_syntax#single_bar) groove [|](value_definition_syntax#single_bar) ridge [|](value_definition_syntax#single_bar) inset [|](value_definition_syntax#single_bar) outset ``` Examples -------- ### All property values Here is an example of all the property values. #### HTML ``` <pre class="b1">none</pre> <pre class="b2">hidden</pre> <pre class="b3">dotted</pre> <pre class="b4">dashed</pre> <pre class="b5">solid</pre> <pre class="b6">double</pre> <pre class="b7">groove</pre> <pre class="b8">ridge</pre> <pre class="b9">inset</pre> <pre class="b10">outset</pre> ``` #### CSS ``` pre { height: 80px; width: 120px; margin: 20px; padding: 20px; display: inline-block; background-color: palegreen; border-width: 5px; box-sizing: border-box; } /\* border-style example classes \*/ .b1 { border-style: none; } .b2 { border-style: hidden; } .b3 { border-style: dotted; } .b4 { border-style: dashed; } .b5 { border-style: solid; } .b6 { border-style: double; } .b7 { border-style: groove; } .b8 { border-style: ridge; } .b9 { border-style: inset; } .b10 { border-style: outset; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # border-style](https://w3c.github.io/csswg-drafts/css-backgrounds/#border-style) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-style` | 1 | 12 | 1 Before Firefox 50, border styles of rounded corners were always rendered as if `border-style` was solid. This has been fixed in Firefox 50. | 4 | 3.5 | 1 | 3 | 18 | 4 Before Firefox 50, border styles of rounded corners were always rendered as if `border-style` was solid. This has been fixed in Firefox 50. | 14 | 3 | 1.0 | See also -------- * The border-related shorthand CSS properties: [`border`](border), [`border-width`](border-width), [`border-color`](border-color), [`border-radius`](border-radius) css :first :first ====== The `:first` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes), used with the [`@page`](@page) <at-rule>, represents the first page of a printed document. (See [`:first-child`](:first-child) for general first element of a node.) ``` /\* Selects the first page when printing \*/ @page :first { margin-left: 50%; margin-top: 50%; } ``` **Note:** You can't change all CSS properties with this pseudo-class. You can only change the margins, [`orphans`](orphans), [`widows`](widows), and page breaks of the document. Furthermore, you may only use [absolute-length](length#absolute_length_units) units when defining the margins. All other properties will be ignored. Syntax ------ ``` :first ``` Examples -------- ### HTML ``` <p>First Page.</p> <p>Second Page.</p> <button>Print!</button> ``` ### CSS ``` @page :first { margin-left: 50%; margin-top: 50%; } p { page-break-after: always; } ``` ### JavaScript ``` document.querySelector("button").addEventListener("click", () => { window.print(); }); ``` ### Result Press the "Print!" button to print the example. The words on the first page should be somewhere around the center, while other pages will have their contents at the default position. Specifications -------------- | Specification | | --- | | [CSS Paged Media Module Level 3 # left-right-first](https://w3c.github.io/csswg-drafts/css-page/#left-right-first) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:first` | 18 | 12 | No | 8 | 9.2 | 6 | 4.4 | 18 | No | 10.1 | 6 | 1.0 | See also -------- * [`@page`](@page) * Other page-related pseudo-classes: [`:left`](:left), [`:right`](:right) css break-inside break-inside ============ The `break-inside` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets how page, column, or region breaks should behave inside a generated box. If there is no generated box, the property is ignored. ``` /\* Keyword values \*/ break-inside: auto; break-inside: avoid; break-inside: avoid-page; break-inside: avoid-column; break-inside: avoid-region; /\* Global values \*/ break-inside: inherit; break-inside: initial; break-inside: revert; break-inside: revert-layer; break-inside: unset; ``` Each possible break point (in other words, each element boundary) is affected by three properties: the [`break-after`](break-after) value of the previous element, the [`break-before`](break-before) value of the next element, and the `break-inside` value of the containing element. To determine if a break must be done, the following rules are applied: 1. If any of the three concerned values is a *forced break value* (`always`, `left`, `right`, `page`, `column`, or `region`), it has precedence. If more than one of them are such a break, the value of the element that appears the latest in the flow is used. Thus, the `break-before` value has precedence over the `break-after` value, which in turn has precedence over the `break-inside` value. 2. If any of the three concerned values is an *avoid break value* (`avoid`, `avoid-page`, `avoid-region`, or `avoid-column`), no such break will be applied at that point. Once forced breaks have been applied, soft breaks may be added if needed, but not on element boundaries that resolve in a corresponding `avoid` value. Syntax ------ The `break-inside` property is specified as one of the keyword values from the list below. ### Values `auto` Allows, but does not force, any break (page, column, or region) to be inserted within the principal box. `avoid` Avoids any break (page, column, or region) from being inserted within the principal box. `avoid-page` Avoids any page break within the principal box. `avoid-column` Avoids any column break within the principal box. `avoid-region` Experimental Avoids any region break within the principal box. Page break aliases ------------------ For compatibility reasons, the legacy [`page-break-inside`](page-break-inside) property should be treated by browsers as an alias of `break-inside`. This ensures that sites using `page-break-inside` continue to work as designed. A subset of values should be aliased as follows: | page-break-inside | break-inside | | --- | --- | | `auto` | `auto` | | `avoid` | `avoid` | Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | block-level elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` break-inside = auto [|](value_definition_syntax#single_bar) avoid [|](value_definition_syntax#single_bar) avoid-page [|](value_definition_syntax#single_bar) avoid-column [|](value_definition_syntax#single_bar) avoid-region ``` Examples -------- ### Avoiding breaking inside a figure In the following example we have a container that contains an `<h1>` spanning all columns (achieved using `column-span: all`) and a series of paragraphs laid out in multiple columns using `column-width: 200px`. We also have a `<figure>` containing an image and a caption. By default, it is possible for you to get a break between the image and its caption, which is not what we want. To avoid this, we have set `break-inside: avoid` on the `<figure>`, which causes them to always stay together. #### HTML ``` <article> <h1>Main heading</h1> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vitae fringilla mauris. Quisque commodo eget nisi sed pretium. Mauris luctus nec lacus in ultricies. Mauris vitae hendrerit arcu, ac scelerisque lacus. Aliquam lobortis in lacus sit amet posuere. Fusce iaculis urna id neque dapibus, eu lacinia lectus dictum. </p> <figure> <img src="https://media.prod.mdn.mozit.cloud/attachments/2020/07/29/17350/3b4892b7e820122ac6dd7678891d4507/firefox.png" /> <figcaption>The Firefox logo — fox wrapped around the world</figcaption> </figure> <p> Praesent condimentum dui dui, sit amet rutrum diam tincidunt eu. Cras suscipit porta leo sit amet rutrum. Sed vehicula ornare tincidunt. Curabitur a ipsum ac diam mattis volutpat ac ut elit. Nullam luctus justo non vestibulum gravida. Morbi metus libero, pharetra non porttitor a, molestie nec nisi. </p> <p> In finibus viverra enim vel suscipit. Quisque consequat velit eu orci malesuada, ut interdum tortor molestie. Proin sed pellentesque augue. Nam risus justo, faucibus non porta a, congue vel massa. Cras luctus lacus nisl, sed tincidunt velit pharetra ac. Duis suscipit faucibus dui sed ultricies. </p> </article> ``` #### CSS ``` html { font-family: helvetica, arial, sans-serif; } body { width: 80%; margin: 0 auto; } h1 { font-size: 3rem; letter-spacing: 2px; column-span: all; } h1 + p { margin-top: 0; } p { line-height: 1.5; break-after: column; } figure { break-inside: avoid; } img { max-width: 70%; display: block; margin: 0 auto; } figcaption { font-style: italic; font-size: 0.8rem; width: 70%; } article { column-width: 200px; gap: 20px; } ``` ### Result Specifications -------------- | Specification | | --- | | [CSS Fragmentation Module Level 3 # break-within](https://w3c.github.io/csswg-drafts/css-break/#break-within) | | [CSS Regions Module Level 1 # region-flow-break](https://w3c.github.io/csswg-drafts/css-regions/#region-flow-break) | | [CSS Multi-column Layout Module Level 1 # break-before-break-after-break-inside](https://w3c.github.io/csswg-drafts/css-multicol/#break-before-break-after-break-inside) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `break-inside` | 50 | 12 | 65 | 10 | 37 11.1-12.1 | 10 | 50 | 50 | 65 | 37 11.1-12.1 | 10 | 5.0 | | `multicol_context` | 50 | 12 | 65 | 10 | 37 11.1-12.1 | 10 | 50 | 50 | 65 | 37 11.1-12.1 | 10 | 5.0 | | `paged_context` | 50 | 12 | 65 | 10 | 37 11.1-12.1 | 10 | 50 | 50 | 65 | 37 11.1-12.1 | 10 | 5.0 | See also -------- * [Multiple-column Layout](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Multiple-column_Layout) * [Breaking Boxes With CSS Fragmentation](https://www.smashingmagazine.com/2019/02/css-fragmentation/) css top top === The `top` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property participates in specifying the vertical position of a [positioned element](position). It has no effect on non-positioned elements. Try it ------ The effect of `top` depends on how the element is positioned (i.e., the value of the [`position`](position) property): * When `position` is set to `absolute` or `fixed`, the `top` property specifies the distance between the element's outer margin of top edge and the inner border of the top edge of its containing block. * When `position` is set to `relative`, the `top` property specifies the distance the element's top edge is moved below its normal position. * When `position` is set to `sticky`, the `top` property is used to compute the sticky-constraint rectangle. * When `position` is set to `static`, the `top` property has *no effect*. When both `top` and [`bottom`](bottom) are specified, `position` is set to `absolute` or `fixed`, *and* [`height`](height) is unspecified (either `auto` or `100%`) both the `top` and `bottom` distances are respected. In all other situations, if [`height`](height) is constrained in any way or `position` is set to `relative`, the `top` property takes precedence and the `bottom` property is ignored. Syntax ------ ``` /\* <length> values \*/ top: 3px; top: 2.4em; /\* <percentage>s of the height of the containing block \*/ top: 10%; /\* Keyword value \*/ top: auto; /\* Global values \*/ top: inherit; top: initial; top: revert; top: revert-layer; top: unset; ``` ### Values [`<length>`](length) A negative, null, or positive [`<length>`](length) that represents: * for *absolutely positioned elements*, the distance to the top edge of the containing block. * for *relatively positioned elements*, the distance that the element is moved below its normal position. [`<percentage>`](percentage) A [`<percentage>`](percentage) of the containing block's height. `auto` Specifies that: * for *absolutely positioned elements*, the position of the element is based on the [`bottom`](bottom) property, while `height: auto` is treated as a height based on the content; or if `bottom` is also `auto`, the element is positioned where it should vertically 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 [`bottom`](bottom) property; or if `bottom` is also `auto`, the element is not moved vertically 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 [`<length>`](length), [`<percentage>`](percentage), or the `auto` keyword. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | positioned elements | | [Inherited](inheritance) | no | | Percentages | refer to the height of the containing block | | [Computed value](computed_value) | if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, `auto` | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` top = auto [|](value_definition_syntax#single_bar) <length-percentage> <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### A positioned element set 10% from the top ``` body { background: beige; } div { position: absolute; top: 10%; right: 40%; bottom: 20%; left: 15%; background: gold; border: 1px solid blue; } ``` ``` <div>The size of this content is determined by the position of its edges.</div> ``` Specifications -------------- | Specification | | --- | | [CSS Positioned Layout Module Level 3 # insets](https://w3c.github.io/csswg-drafts/css-position/#insets) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `top` | 1 | 12 | 1 | 5 In Internet Explorer versions before 7, when both `top` and `bottom` are specified, the element position is overconstrained and the `top` property has precedence; the computed value of `bottom` is set to `-top`, while its specified value is ignored. | 6 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [`inset`](inset), the shorthand for all related properties: [`top`](top), [`bottom`](bottom), [`left`](left), and [`right`](right) * The mapped logical properties: [`inset-block-start`](inset-block-start), [`inset-block-end`](inset-block-end), [`inset-inline-start`](inset-inline-start), and [`inset-inline-end`](inset-inline-end) and the shorthands [`inset-block`](inset-block) and [`inset-inline`](inset-inline) * [`position`](position)
programming_docs
css line-break line-break ========== The `line-break` CSS property sets how to break lines of Chinese, Japanese, or Korean (CJK) text when working with punctuation and symbols. Try it ------ Syntax ------ ``` /\* Keyword values \*/ line-break: auto; line-break: loose; line-break: normal; line-break: strict; line-break: anywhere; /\* Global values \*/ line-break: inherit; line-break: initial; line-break: revert; line-break: revert-layer; line-break: unset; ``` ### Values `auto` Break text using the default line break rule. `loose` Break text using the least restrictive line break rule. Typically used for short lines, such as in newspapers. `normal` Break text using the most common line break rule. `strict` Break text using the most stringent line break rule. `anywhere` There is a soft wrap opportunity around every typographic character unit, including around any punctuation character or preserved white spaces, or in the middle of words, disregarding any prohibition against line breaks, even those introduced by characters with the GL, WJ, or ZWJ character class or mandated by the [`word-break`](word-break) property. The different wrapping opportunities must not be prioritized. Hyphenation is not applied. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` line-break = auto [|](value_definition_syntax#single_bar) loose [|](value_definition_syntax#single_bar) normal [|](value_definition_syntax#single_bar) strict [|](value_definition_syntax#single_bar) anywhere ``` Examples -------- ### Setting text wrapping See whether the text is wrapped before "々", "ぁ" and "。". #### HTML ``` <div lang="ja"> <p class="wrapbox auto"> auto:<br />そこは湖のほとりで木々が輝いていた。<br />その景色に、美しいなぁと思わずつぶやいた。 </p> <p class="wrapbox loose"> loose:<br />そこは湖のほとりで木々が輝いていた。<br />その景色に、美しいなぁと思わずつぶやいた。 </p> <p class="wrapbox normal"> normal:<br />そこは湖のほとりで木々が輝いていた。<br />その景色に、美しいなぁと思わずつぶやいた。 </p> <p class="wrapbox strict"> strict:<br />そこは湖のほとりで木々が輝いていた。<br />その景色に、美しいなぁと思わずつぶやいた。 </p> <p class="wrapbox anywhere"> anywhere:<br />そこは湖のほとりで木々が輝いていた。<br />その景色に、美しいなぁと思わずつぶやいた。 </p> </div> ``` #### CSS ``` .wrapbox { width: 10em; margin: 0.5em; white-space: normal; vertical-align: top; display: inline-block; } .auto { line-break: auto; } .loose { line-break: loose; } .normal { line-break: normal; } .strict { line-break: strict; } .anywhere { line-break: anywhere; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Text Module Level 3 # line-break-property](https://w3c.github.io/csswg-drafts/css-text/#line-break-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `line-break` | 58 1 | 14 | 69 | 8 5.5 | 45 15 | 11 3 2-3 | 58 ≤37 | 58 18 | 79 | 43 14 | 11 1 | 7.0 1.0 | * [CSS and International text](https://www.w3.org/International/articles/css3-text/) css url() url() ===== The `url()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](css_functions) is used to include a file. The parameter is an absolute URL, a relative URL, a blob URL, or a data URL. The `url()` function can be passed as a parameter of another CSS functions, like the [`attr()`](attr) function. Depending on the property for which it is a value, the resource sought can be an image, font, or a stylesheet. The `url()` functional notation is the value for the `<url>` data type. **Note:** There is a difference between a [URI](https://developer.mozilla.org/en-US/docs/Glossary/URI) and a [URL](https://developer.mozilla.org/en-US/docs/Glossary/URL). A URI identifies a resource. A URL is a type of URI, and describes the *location* of a resource. A URI can be either a URL or a name ([URN](https://developer.mozilla.org/en-US/docs/Glossary/URN)) of a resource. In CSS Level 1, the `url()` functional notation described only true URLs. In CSS Level 2, the definition of `url()` was extended to describe any URI, whether a URL or a URN. Confusingly, this meant that `url()` could be used to create a `<uri>` CSS data type. This change was not only awkward but, debatably, unnecessary, since URNs are almost never used in actual CSS. To alleviate the confusion, CSS Level 3 returned to the narrower, initial definition. Now, `url()` denotes only true `<url>`s. ``` /\* Simple usage \*/ url(https://example.com/images/myImg.jpg); url(data:image/png;base64,iRxVB0…); url(myFont.woff); url(#IDofSVGpath); /\* associated properties \*/ background-image: url("star.gif"); list-style-image: url('../images/bullet.jpg'); content: url("pdficon.jpg"); cursor: url(mycursor.cur); border-image-source: url(/media/diamonds.png); src: url('fantasticfont.woff'); offset-path: url(#path); mask-image: url("masks.svg#mask1"); /\* Properties with fallbacks \*/ cursor: url(pointer.cur), pointer; /\* Associated short-hand properties \*/ background: url('star.gif') bottom right repeat-x blue; border-image: url("/media/diamonds.png") 30 fill / 30px / 30px space; /\* As a parameter in another CSS function \*/ background-image: cross-fade(20% url(first.png), url(second.png)); mask-image: image(url(mask.png), skyblue, linear-gradient(rgba(0, 0, 0, 1.0), transparent)); /\* as part of a non-shorthand multiple value \*/ content: url(star.svg) url(star.svg) url(star.svg) url(star.svg) url(star.svg); /\* at-rules \*/ @document url("https://www.example.com/") { /\* … \*/ } Experimental @import url("https://www.example.com/style.css"); @namespace url(http://www.w3.org/1999/xhtml); ``` Relative URLs, if used, are relative to the URL of the stylesheet (not to the URL of the web page). The `url()` function can be included as a value for [`background`](background), [`background-image`](background-image), [`border`](border), [`border-image`](border-image), [`border-image-source`](border-image-source), [`content`](content), [`cursor`](cursor), [`filter`](filter), [`list-style`](list-style), [`list-style-image`](list-style-image), [`mask`](mask), [`mask-image`](mask-image), [`offset-path`](offset-path), [src](@font-face/src) as part of a <@font-face> block, and [@counter-style/symbol](@counter-style/symbols) Syntax ------ ### Values `<string>` A string which may specify a URL or the ID of an SVG shape. <url> A URL, which is a relative or absolute address, or pointer, to the web resource to be included, or a data URL, optionally in single or double quotes. Quotes are required if the URL includes parentheses, whitespace, or quotes, unless these characters are escaped, or if the address includes control characters above 0x7e. Double quotes cannot occur inside double quotes and single quotes cannot occur inside single quotes unless escaped. The following are all valid and equivalent: ``` <css_property>: url("https://example.com/image.png") <css_property>: url('https://example.com/image.png') <css_property>: url(https://example.com/image.png) ``` If you choose to write the URL without quotes, use a backslash (`\`) before any parentheses, whitespace characters, single quotes (`'`) and double quotes (`"`) that are part of the URL. path References the ID of an [SVG shape](https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Basic_Shapes) — `circle`, `ellipse`, `line`, `path`, `polygon`, `polyline`, or `rect` — using the shape's geometry as the path. `<url-modifier>` Experimental In the future, the `url()` function may support specifying a modifier, an identifier or a functional notation, which alters the meaning of the URL string. This is not supported and not fully defined in the specification. ### Formal syntax ``` url( <string> <url-modifier>\* ) ``` Examples -------- ### A url used in the background property ``` .topbanner { background: url("topbanner.png") #00d no-repeat fixed; } ``` ### A url loading an image as a list bullet ``` ul { list-style: square url(http://www.example.com/redball.png); } ``` ### Usage in the content property #### HTML ``` <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul> ``` #### CSS ``` li::after { content: " - " url(star.gif); } ``` #### Result ### Using a data URL #### HTML ``` <div class="background"></div> ``` #### CSS ``` .background { background: yellow; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='45'%3E%3Cpath d='M10 10h60' stroke='%2300F' stroke-width='5'/%3E%3Cpath d='M10 20h60' stroke='%230F0' stroke-width='5'/%3E%3Cpath d='M10 30h60' stroke='red' stroke-width='5'/%3E%3C/svg%3E"); } ``` ### Usage in filters When a URL is used as a path for a filter, the URL must be one of the following: 1. The path to an SVG file with the ID of the filter appended. 2. the ID of the filter, if the SVG already exists on the page. ``` .blur { filter: url(my-file.svg#svg-blur); /\* the URL of an SVG file used as a filter \*/ } .inline-blur { filter: url(#svg-blur); /\* the ID of an SVG that is embedded in the HTML page \*/ } ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # urls](https://w3c.github.io/csswg-drafts/css-values/#urls) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `url` | 1 | 12 | 1 | 3 | 3.5 | 1 | 4.4 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [`<gradient>`](gradient) * [`element()`](element()) * [`image()`](image/image) * [`image-set()`](image/image-set) * [`cross-fade()`](cross-fade) css background-clip background-clip =============== The `background-clip` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets whether an element's background extends underneath its border box, padding box, or content box. Try it ------ If the element has no [`background-image`](background-image) or [`background-color`](background-color), this property will only have a visual effect when the border has transparent regions or partially opaque regions (due to [`border-style`](border-style) or [`border-image`](border-image)); otherwise, the border masks the difference. **Note:** Because the [root element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html) has a different background painting area, the `background-clip` property has no effect when specified on it. See "[The backgrounds of special elements.](https://drafts.csswg.org/css-backgrounds-3/#special-backgrounds)" **Note:** For documents whose [root element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html) is an HTML element: if the computed value of [`background-image`](background-image) on the root element is `none` and its [`background-color`](background-color) is `transparent`, user agents must instead propagate the computed values of the `background` properties from that element's first HTML [`<body>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body) child element. The used values of that `<body>` element's `background` properties are their initial values, and the propagated values are treated as if they were specified on the root element. It is recommended that authors of HTML documents specify the canvas background for the `<body>` element rather than the HTML element. Syntax ------ ``` /\* Keyword values \*/ background-clip: border-box; background-clip: padding-box; background-clip: content-box; background-clip: text; /\* Global values \*/ background-clip: inherit; background-clip: initial; background-clip: revert; background-clip: revert-layer; background-clip: unset; ``` ### Values `border-box` The background extends to the outside edge of the border (but underneath the border in z-ordering). `padding-box` The background extends to the outside edge of the padding. No background is drawn beneath the border. `content-box` The background is painted within (clipped to) the content box. `text` The background is painted within (clipped to) the foreground text. Accessibility concerns ---------------------- When using `background-clip: text` check that the contrast ratio between the background color and the color of the text placed over it is high enough that people experiencing low vision conditions will be able to read the content of the page. If the background image does not load, this could also lead to the text becoming unreadable. Add a fallback [`background-color`](background-color) to prevent this from happening, and test without the image. Consider using feature queries with [`@supports`](@supports) to test for support of `background-clip: text` and provide an accessible alternative where it is not supported. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `border-box` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` background-clip = <box>[#](value_definition_syntax#hash_mark) <box> = border-box [|](value_definition_syntax#single_bar) padding-box [|](value_definition_syntax#single_bar) content-box ``` Examples -------- ### HTML ``` <p class="border-box">The background extends behind the border.</p> <p class="padding-box"> The background extends to the inside edge of the border. </p> <p class="content-box"> The background extends only to the edge of the content box. </p> <p class="text">The background is clipped to the foreground text.</p> ``` ### CSS ``` p { border: 0.8em darkviolet; border-style: dotted double; margin: 1em 0; padding: 1.4em; background: linear-gradient(60deg, red, yellow, red, yellow, red); font: 900 1.2em sans-serif; text-decoration: underline; } .border-box { background-clip: border-box; } .padding-box { background-clip: padding-box; } .content-box { background-clip: content-box; } .text { background-clip: text; -webkit-background-clip: text; color: rgba(0, 0, 0, 0.2); } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # background-clip](https://w3c.github.io/csswg-drafts/css-backgrounds/#background-clip) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `background-clip` | 1 1 Chrome accepts alternate synonyms to its values: `padding`, `border`, and `content`. | 12 12 Since Edge 79, accepts alternate synonyms to its values: `padding`, `border`, and `content`. | 49 4 1-4 Used the `-moz-background-clip: padding | border` syntax. | 9 In IE 7 and IE 8 of Internet Explorer, this property always behaved like `background-clip: padding` when `overflow` was `hidden`, `auto`, or `scroll`. | 15 Opera accepts alternate synonyms to its values: `padding`, `border`, and `content`. 10.5 | 14 3 Safari accepts alternate synonyms to its values: `padding`, `border`, and `content`. | ≤37 WebView accepts alternate synonyms to its values: `padding`, `border`, and `content`. 4 | 18 18 Chrome accepts alternate synonyms to its values: `padding`, `border`, and `content`. | 49 14 | 14 Opera accepts alternate synonyms to its values: `padding`, `border`, and `content`. 11 | 14 1 Safari accepts alternate synonyms to its values: `padding`, `border`, and `content`. | 1.0 1.0 Samsung Internet accepts alternate synonyms to its values: `padding`, `border`, and `content`. | | `content-box` | 1 | 12 | 4 | 9 In IE 7 and IE 9 of Internet Explorer, it always behaved like `background-clip: padding` if `overflow: hidden | auto | scroll` | 10.5 | 3 | 4 | 18 | 14 | 11 | 1 | 1.0 | | `text` | 3 ["This value is supported with the prefixed version of the property only.", "According to the [WebKit blog](https://webkit.org/blog/164/background-clip-text/), text decorations or shadows are not included in the clipping."] | 15 12 Before Edge 15, this value was supported with the prefixed version of the property only. | 49 | No | 15 ["This value is supported with the prefixed version of the property only.", "According to the [WebKit blog](https://webkit.org/blog/164/background-clip-text/), text decorations or shadows are not included in the clipping."] | 14 4 ["This value is supported with the prefixed version of the property only.", "According to the [WebKit blog](https://webkit.org/blog/164/background-clip-text/), text decorations or shadows are not included in the clipping."] | ≤37 ["This value is supported with the prefixed version of the property only.", "According to the [WebKit blog](https://webkit.org/blog/164/background-clip-text/), text decorations or shadows are not included in the clipping."] | 18 ["This value is supported with the prefixed version of the property only.", "According to the [WebKit blog](https://webkit.org/blog/164/background-clip-text/), text decorations or shadows are not included in the clipping."] | 49 | 14 ["This value is supported with the prefixed version of the property only.", "According to the [WebKit blog](https://webkit.org/blog/164/background-clip-text/), text decorations or shadows are not included in the clipping."] | 14 3.2 ["This value is supported with the prefixed version of the property only.", "According to the [WebKit blog](https://webkit.org/blog/164/background-clip-text/), text decorations or shadows are not included in the clipping."] | 1.0 ["This value is supported with the prefixed version of the property only.", "According to the [WebKit blog](https://webkit.org/blog/164/background-clip-text/), text decorations or shadows are not included in the clipping."] | See also -------- * The [`clip-path`](clip-path) property creates a clipping region that defines what part of an *entire element* should be displayed. * Background properties: [`background`](background), [`background-color`](background-color), [`background-image`](background-image), [`background-origin`](background-origin) * [Introduction to the CSS box model](css_box_model/introduction_to_the_css_box_model) css background-origin background-origin ================= The `background-origin` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the background's origin: from the border start, inside the border, or inside the padding. Try it ------ Note that `background-origin` is ignored when [`background-attachment`](background-attachment) is `fixed`. Syntax ------ ``` /\* Keyword values \*/ background-origin: border-box; background-origin: padding-box; background-origin: content-box; /\* Global values \*/ background-origin: inherit; background-origin: initial; background-origin: revert; background-origin: revert-layer; background-origin: unset; ``` The `background-origin` property is specified as one of the keyword values listed below. ### Values `border-box` The background is positioned relative to the border box. `padding-box` The background is positioned relative to the padding box. `content-box` The background is positioned relative to the content box. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `padding-box` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` background-origin = <box>[#](value_definition_syntax#hash_mark) <box> = border-box [|](value_definition_syntax#single_bar) padding-box [|](value_definition_syntax#single_bar) content-box ``` Examples -------- ### Setting background origins ``` .example { border: 10px double; padding: 10px; background: url("image.jpg"); background-position: center left; background-origin: content-box; } ``` ``` #example2 { border: 4px solid black; padding: 10px; background: url("image.gif"); background-repeat: no-repeat; background-origin: border-box; } ``` ``` div { background-image: url("logo.jpg"), url("mainback.png"); /\* Applies two images to the background \*/ background-position: top right, 0px 0px; background-origin: content-box, padding-box; } ``` ### Using two gradients In this example the box has a thick dotted border. The first gradient uses the `padding-box` as the `background-origin` and therefore the background sits inside the border. The second uses the `content-box` and so only displays behind the content. ``` .box { margin: 10px 0; color: #fff; background: linear-gradient( 90deg, rgba(131, 58, 180, 1) 0%, rgba(253, 29, 29, 0.6) 60%, rgba(252, 176, 69, 1) 100% ), radial-gradient(circle, rgba(255, 255, 255, 1) 0%, rgba(0, 0, 0, 1) 28%); border: 20px dashed black; padding: 20px; width: 400px; background-origin: padding-box, content-box; background-repeat: no-repeat; } ``` ``` <div class="box">Hello!</div> ``` Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # the-background-origin](https://w3c.github.io/csswg-drafts/css-backgrounds/#the-background-origin) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `background-origin` | 1 1 Chrome accepts alternate synonyms to its values: `padding`, `border`, and `content`. | 12 12 Since Edge 79, accepts alternate synonyms to its values: `padding`, `border`, and `content`. | 49 4 1-4 Used the `-moz-background-clip: padding | border` syntax. | 9 In IE 7 and before, Internet explorer was behaving as if `background-origin: border-box` was set. In Internet Explorer 8, as if `background-origin: padding-box`, the regular default value, was set. | 15 Opera accepts alternate synonyms to its values: `padding`, `border`, and `content`. 10.5 | 3 3 Webkit accepts alternate synonyms to its values: `padding`, `border`, and `content`. | 4 4 WebView accepts alternate synonyms to its values: `padding`, `border`, and `content`. | 18 18 Chrome accepts alternate synonyms to its values: `padding`, `border`, and `content`. | 49 14 | 14 Opera accepts alternate synonyms to its values: `padding`, `border`, and `content`. 11 | 1 1 Webkit accepts alternate synonyms to its values: `padding`, `border`, and `content`. | 1.0 1.0 Samsung Internet accepts alternate synonyms to its values: `padding`, `border`, and `content`. | | `content-box` | 1 | 12 | 4 | 9 In IE 7 and IE 9 of Internet Explorer, it always behaved like `background-clip: padding` if `overflow: hidden | auto | scroll`. | 10.5 | 3 | 4 | 18 | 14 | 11 | 1 | 1.0 | See also -------- * [`background-clip`](background-clip)
programming_docs
css rem() rem() ===== **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `rem()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](css_functions) returns a remainder left over when the first parameter is divided by the second parameter, similar to the JavaScript [remainder operator (`%`)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder). The remainder is the value left over when one operand, the dividend, is divided by a second operand, the divisor. It always takes the sign of the dividend. > For example, the CSS `rem(27, 5)` function returns the remainder of `2`. When dividing 27 by 5, the result is 5 with a remainder of 2. The full calculation is `27 / 5 = 5 * 5 + 2`. > > Syntax ------ ``` /\* Unitless <number> \*/ line-height: rem(21, 2); /\* 1 \*/ line-height: rem(14, 5); /\* 4 \*/ line-height: rem(5.5, 2); /\* 1.5 \*/ /\* Unit based <percentage> and <dimension> \*/ margin: rem(14%, 3%); /\* 2% \*/ margin: rem(18px, 5px); /\* 3px \*/ margin: rem(10rem, 6rem); /\* 4rem \*/ margin: rem(26vmin, 7vmin); /\* 5vmin \*/ margin: rem(1000px, 29rem); /\* 72px - if root font-size is 16px \*/ /\* Negative/positive values \*/ rotate: rem(200deg, 30deg); /\* 20deg \*/ rotate: rem(140deg, -90deg); /\* 50deg \*/ rotate: rem(-90deg, 20deg); /\* -10deg \*/ rotate: rem(-55deg, -15deg); /\* -10deg \*/ /\* Calculations \*/ scale: rem(10 * 2, 1.7); /\* 1.3 \*/ rotate: rem(10turn, 18turn / 3); /\* 4turn \*/ transition-duration: rem(20s / 2, 3000ms * 2); /\* 4s \*/ ``` ### Parameter The `rem(dividend, divisor)` function accepts two comma-separated values as its parameters. Both parameters must have the same type, <number>, <dimension>, or <percentage>, for the function to be valid. While the units in the two parameters don't need to be the same, they do need of the same dimension type, such as [`<length>`](length), [`<angle>`](angle), [`<time>`](time), or [`<frequency>`](frequency) to be valid. `dividend` A calculation that resolves to a [`<number>`](number), [`<dimension>`](dimension), or [`<percentage>`](percentage) representing the dividend. `divisor` A calculation that resolves to a [`<number>`](number), [`<dimension>`](dimension), or [`<percentage>`](percentage) representing the divisor. ### Return value Returns a [`<number>`](number), [`<dimension>`](dimension), or [`<percentage>`](percentage) (corresponds to the parameters' type) representing the remainder, that is, the operation left over. * If `divisor` is `0`, the result is `NaN`. * If `dividend` is `infinite`, the result is `NaN`. * If `dividend` is positive the result is positive (`0⁺`), and if `dividend` is negative the result is negative (`0⁻`). ### Formal syntax ``` <rem()> = rem( <calc-sum> , <calc-sum> ) <calc-sum> = <calc-product> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '+' [|](value_definition_syntax#single_bar) '-' []](value_definition_syntax#brackets) <calc-product> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-product> = <calc-value> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '*' [|](value_definition_syntax#single_bar) '/' []](value_definition_syntax#brackets) <calc-value> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-value> = [<number>](number) [|](value_definition_syntax#single_bar) [<dimension>](dimension) [|](value_definition_syntax#single_bar) [<percentage>](percentage) [|](value_definition_syntax#single_bar) <calc-constant> [|](value_definition_syntax#single_bar) ( <calc-sum> ) <calc-constant> = e [|](value_definition_syntax#single_bar) pi [|](value_definition_syntax#single_bar) infinity [|](value_definition_syntax#single_bar) -infinity [|](value_definition_syntax#single_bar) NaN ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # exponent-funcs](https://w3c.github.io/csswg-drafts/css-values/#exponent-funcs) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `rem` | No | No | No | No | No | 15.4 | No | No | No | No | 15.4 | No | See also -------- * [`round()`](round) * `mod` css :link :link ===== The `:link` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) represents an element that has not yet been visited. It matches every unvisited [`<a>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a) or [`<area>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/area) element that has an `href` attribute. Try it ------ Styles defined by the `:link` and [`:visited`](:visited) pseudo-classes can be overridden by any subsequent user-action pseudo-classes ([`:hover`](:hover) or [`:active`](:active)) that have at least equal specificity. To style links appropriately, put the `:link` rule before all other link-related rules, as defined by the *LVHA-order*: `:link` — `:visited` — `:hover` — `:active`. The `:visited` pseudo-class and `:link` pseudo-class are mutually exclusive. **Note:** Use [`:any-link`](:any-link) to select an element independent of whether it has been visited or not. Syntax ------ ``` :link ``` Examples -------- By default, most browsers apply a special [`color`](color) value to visited links. Thus, the links in this example will probably have special font colors only before you visit them. (After that, you'll need to clear your browser history to see them again.) However, the [`background-color`](background-color) values are likely to remain, as most browsers do not set that property on visited links by default. ### HTML ``` <a href="#ordinary-target">This is an ordinary link.</a><br /> <a href="">You've already visited this link.</a><br /> <a>Placeholder link (won't get styled)</a> ``` ### CSS ``` a:link { background-color: gold; color: green; } ``` ### Result Specifications -------------- | Specification | | --- | | [HTML Standard # selector-link](https://html.spec.whatwg.org/multipage/semantics-other.html#selector-link) | | [Selectors Level 4 # link](https://w3c.github.io/csswg-drafts/selectors/#link) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:link` | 1 | 12 | 1 | 3 | 3.5 | 1 | 1.5 | 18 | 4 | 14 | 3.2 | 1.0 | | `not_match_link` | 1 | 12 | 87 | No | 3.5 | 15 | 1.5 | 18 | 87 | 14 | 15 | 1.0 | See also -------- * Link-related pseudo-classes: [`:visited`](:visited), [`:hover`](:hover), [`:active`](:active) css pow() pow() ===== **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `pow()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](css_functions) is an exponential function that returns the value of a base raised to the power of a number. The [`exp()`](exp) function is a special case of `pow()` where the value of the base is the mathematical constant [e](https://en.wikipedia.org/wiki/E_(mathematical_constant)). Syntax ------ ``` /\* A <number> value \*/ width: calc(10px * pow(5, 2)); /\* 10px \* 25 = 250px \*/ width: calc(10px * pow(5, 3)); /\* 10px \* 125 = 1250px \*/ width: calc(10px * pow(2, 10)); /\* 10px \* 1024 = 10240px \*/ ``` ### Parameters The `pow(base, number)` function accepts two comma-separated values as its parameters. `base` A calculation that resolves to a [`<number>`](number), representing the base. `number` A calculation that resolves to a [`<number>`](number), representing the exponent. ### Return value Returns a [`<number>`](number) representing basenumber, that is, `base` raised to the power of `number`. Formal syntax ------------- ``` <pow()> = pow( <calc-sum> , <calc-sum> ) <calc-sum> = <calc-product> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '+' [|](value_definition_syntax#single_bar) '-' []](value_definition_syntax#brackets) <calc-product> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-product> = <calc-value> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '*' [|](value_definition_syntax#single_bar) '/' []](value_definition_syntax#brackets) <calc-value> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-value> = [<number>](number) [|](value_definition_syntax#single_bar) [<dimension>](dimension) [|](value_definition_syntax#single_bar) [<percentage>](percentage) [|](value_definition_syntax#single_bar) <calc-constant> [|](value_definition_syntax#single_bar) ( <calc-sum> ) <calc-constant> = e [|](value_definition_syntax#single_bar) pi [|](value_definition_syntax#single_bar) infinity [|](value_definition_syntax#single_bar) -infinity [|](value_definition_syntax#single_bar) NaN ``` Examples -------- ### Scale headings by fixed ratio The `pow()` 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 ``` <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 ``` h1 { font-size: calc(1rem * pow(1.5, 4)); } h2 { font-size: calc(1rem * pow(1.5, 3)); } h3 { font-size: calc(1rem * pow(1.5, 2)); } h4 { font-size: calc(1rem * pow(1.5, 1)); } h5 { font-size: calc(1rem * pow(1.5, 0)); } h6 { font-size: calc(1rem * pow(1.5, -1)); } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # exponent-funcs](https://w3c.github.io/csswg-drafts/css-values/#exponent-funcs) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `pow` | No | No | No | No | No | 15.4 | No | No | No | No | 15.4 | No | See also -------- * [`sqrt()`](sqrt) * [`hypot()`](hypot) * [`exp()`](exp) * [`log()`](log) css exp() exp() ===== **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `exp()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](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)) represents Euler's number and is the base of natural logarithms, and is approximately `2.718281828459045`. The `exp(number)` function contains a calculation which returns the same value as [`pow(e, number)`](pow). Syntax ------ ``` /\* 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 [`<number>`](number). Representing the value to be raised by a power of `e`. ### Return value Returns a non-negative [`<number>`](number) representing enumber, 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 ``` <exp()> = exp( <calc-sum> ) <calc-sum> = <calc-product> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '+' [|](value_definition_syntax#single_bar) '-' []](value_definition_syntax#brackets) <calc-product> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-product> = <calc-value> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '*' [|](value_definition_syntax#single_bar) '/' []](value_definition_syntax#brackets) <calc-value> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-value> = [<number>](number) [|](value_definition_syntax#single_bar) [<dimension>](dimension) [|](value_definition_syntax#single_bar) [<percentage>](percentage) [|](value_definition_syntax#single_bar) <calc-constant> [|](value_definition_syntax#single_bar) ( <calc-sum> ) <calc-constant> = e [|](value_definition_syntax#single_bar) pi [|](value_definition_syntax#single_bar) infinity [|](value_definition_syntax#single_bar) -infinity [|](value_definition_syntax#single_bar) NaN ``` Examples -------- ### Rotate elements The `exp()` function can be used to [`rotate`](transform-function/rotate) elements as it return a [`<number>`](number). #### 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 ``` 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 ### 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 ``` <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 ``` 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 Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # exponent-funcs](https://w3c.github.io/csswg-drafts/css-values/#exponent-funcs) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `exp` | No | No | No | No | No | 15.4 | No | No | No | No | 15.4 | No | See also -------- * [`pow()`](pow) * [`sqrt()`](sqrt) * [`hypot()`](hypot) * [`log()`](log) css Universal selectors Universal selectors =================== The CSS **universal selector** (`*`) matches elements of any type. ``` /\* Selects all elements \*/ \* { color: green; } ``` The universal selector is a special [type selector](type_selectors) and can therefore be namespaced when using [`@namespace`](@namespace). This is useful when dealing with documents containing multiple namespaces such as HTML with inline SVG or MathML, or XML that mixes multiple vocabularies. * `ns|*` - matches all elements in namespace *ns* * `*|*` - matches all elements * `|*` - matches all elements without any declared namespace Syntax ------ ``` \* { style properties } ``` The asterisk is optional with simple selectors. For instance, `*.warning` and `.warning` are equivalent. Examples -------- ### CSS ``` \* [lang^="en"] { color: green; } \*.warning { color: red; } \*#maincontent { border: 1px solid blue; } .floating { float: left; } /\* automatically clear the next sibling after a floating element \*/ .floating + \* { clear: left; } ``` ### HTML ``` <p class="warning"> <span lang="en-us">A green span</span> in a red paragraph. </p> <p id="maincontent" lang="en-gb"> <span class="warning">A red span</span> in a green paragraph. </p> ``` ### Result ### Namespaces In this example the selector will only match elements in the example namespace. ``` @namespace example url(http://www.example.com); example|\* { color: blue; } ``` Specifications -------------- | Specification | | --- | | [Selectors Level 4 # the-universal-selector](https://w3c.github.io/csswg-drafts/selectors/#the-universal-selector) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `Universal_selectors` | 1 | 12 | 1 | 7 | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | | `namespaces` | 1 | 12 | 1 | 9 | 8 | 1.3 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | See also -------- * [CSS Selectors](css_selectors) * [Learn CSS: Selectors](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors) css scroll-padding-right scroll-padding-right ==================== The `scroll-padding-right` property defines offsets for the right 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. Try it ------ Syntax ------ ``` /\* Keyword values \*/ scroll-padding-right: auto; /\* <length> values \*/ scroll-padding-right: 10px; scroll-padding-right: 1em; scroll-padding-right: 10%; /\* Global values \*/ scroll-padding-right: inherit; scroll-padding-right: initial; scroll-padding-right: revert; scroll-padding-right: revert-layer; scroll-padding-right: unset; ``` ### Values `<length-percentage>` An inwards offset from the top 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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | scroll containers | | [Inherited](inheritance) | no | | Percentages | relative to the scroll container's scrollport | | [Computed value](computed_value) | as specified | | Animation type | by computed value type | Formal syntax ------------- ``` scroll-padding-right = auto [|](value_definition_syntax#single_bar) [<length-percentage [0,∞]>](length-percentage) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Specifications -------------- | Specification | | --- | | [CSS Scroll Snap Module Level 1 # padding-longhands-physical](https://w3c.github.io/csswg-drafts/css-scroll-snap/#padding-longhands-physical) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scroll-padding-right` | 69 | 79 | 68 | No | 56 | 14.1 11-14.1 Scroll padding is not applied for scrolls to fragment target or `scrollIntoView()`, see [bug 179379](https://webkit.org/b/179379). | 69 | 69 | 68 | 48 | 14.5 11-14.5 Scroll padding is not applied for scrolls to fragment target or `scrollIntoView()`, see [bug 179379](https://webkit.org/b/179379). | 10.0 | See also -------- * [CSS Scroll Snap](css_scroll_snap) * [Well-Controlled Scrolling with CSS Scroll Snap](https://web.dev/css-scroll-snap/)
programming_docs
css overscroll-behavior-x overscroll-behavior-x ===================== The `overscroll-behavior-x` CSS property sets the browser's behavior when the horizontal boundary of a scrolling area is reached. See [`overscroll-behavior`](overscroll-behavior) for a full explanation. ``` /\* Keyword values \*/ overscroll-behavior-x: auto; /\* default \*/ overscroll-behavior-x: contain; overscroll-behavior-x: none; /\* Global values \*/ overscroll-behavior-x: inherit; overscroll-behavior-x: initial; overscroll-behavior-x: revert; overscroll-behavior-x: revert-layer; overscroll-behavior-x: unset; ``` Syntax ------ The `overscroll-behavior-x` 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 is observed inside the element this value is set on (e.g. "bounce" effects or refreshes), but no scroll chaining occurs to neighboring scrolling areas, e.g. underlying elements will not scroll. `none` No scroll chaining occurs to neighboring scrolling areas, and default scroll overflow behavior is prevented. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | non-replaced block-level elements and non-replaced inline-block elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` overscroll-behavior-x = contain [|](value_definition_syntax#single_bar) none [|](value_definition_syntax#single_bar) auto ``` Examples -------- ### Preventing an underlying element from scrolling horizontally In our simple [overscroll-behavior-x example](https://mdn.github.io/css-examples/overscroll-behavior/overscroll-behavior-x) (see [source code](https://github.com/mdn/css-examples/blob/main/overscroll-behavior/overscroll-behavior-x.html) also), we have two block-level boxes, one inside the other. The outer box has a large [`width`](width) set on it so the page will scroll horizontally. The inner box has a small width (and [`height`](height)) set on it so it sits comfortably inside the viewport, but its content is given a large `width` so it will 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, you can set `overscroll-behavior-x: contain` on the inner box: ``` main > div { height: 300px; width: 500px; overflow: auto; position: relative; top: 100px; left: 100px; overscroll-behavior-x: contain; } ``` Specifications -------------- | Specification | | --- | | [CSS Overscroll Behavior Module Level 1 # overscroll-behavior-longhands-physical](https://w3c.github.io/csswg-drafts/css-overscroll/#overscroll-behavior-longhands-physical) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `overscroll-behavior-x` | 63 | 18 Currently the `none` value incorrectly behaves as `contain` (allowing for the elastic bounce effect). | 59 | No | 50 | 16 | 63 | 63 | 59 | 46 | 16 | 8.0 | See also -------- * [Take control of your scroll: customizing pull-to-refresh and overflow effects](https://developer.chrome.com/blog/overscroll-behavior/#full-demo) * The mapped logical properties: [`overscroll-behavior-inline`](overscroll-behavior-inline), [`overscroll-behavior-block`](overscroll-behavior-block) css scroll-padding-left scroll-padding-left =================== The `scroll-padding-left` property defines offsets for the left of the *optimal viewing region* of the scrollport: the region used as the target region for placing things in view of the user. This allows the author to exclude regions of the scrollport that are obscured by other content (such as fixed-positioned toolbars or sidebars) or to put more breathing room between a targeted element and the edges of the scrollport. Try it ------ Syntax ------ ``` /\* Keyword values \*/ scroll-padding-left: auto; /\* <length> values \*/ scroll-padding-left: 10px; scroll-padding-left: 1em; scroll-padding-left: 10%; /\* Global values \*/ scroll-padding-left: inherit; scroll-padding-left: initial; scroll-padding-left: revert; scroll-padding-left: revert-layer; scroll-padding-left: unset; ``` ### Values `<length-percentage>` An inwards offset from the left edge of the scrollport, as a valid length or a percentage. `auto` The offset is determined by the user agent. This will generally be 0px, but a user agent is able to detect and do something else if a non-zero value is more appropriate. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | scroll containers | | [Inherited](inheritance) | no | | Percentages | relative to the scroll container's scrollport | | [Computed value](computed_value) | as specified | | Animation type | by computed value type | Formal syntax ------------- ``` scroll-padding-left = auto [|](value_definition_syntax#single_bar) [<length-percentage [0,∞]>](length-percentage) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Specifications -------------- | Specification | | --- | | [CSS Scroll Snap Module Level 1 # padding-longhands-physical](https://w3c.github.io/csswg-drafts/css-scroll-snap/#padding-longhands-physical) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scroll-padding-left` | 69 | 79 | 68 | No | 56 | 14.1 11-14.1 Scroll padding is not applied for scrolls to fragment target or `scrollIntoView()`, see [bug 179379](https://webkit.org/b/179379). | 69 | 69 | 68 | 48 | 14.5 11-14.5 Scroll padding is not applied for scrolls to fragment target or `scrollIntoView()`, see [bug 179379](https://webkit.org/b/179379). | 10.0 | See also -------- * [CSS Scroll Snap](css_scroll_snap) * [Well-Controlled Scrolling with CSS Scroll Snap](https://web.dev/css-scroll-snap/) css Layout mode Layout mode =========== A [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) **layout mode**, sometimes called *layout*, is an algorithm that determines the position and size of boxes based on the way they interact with their sibling and ancestor boxes. There are several of them: * *[Normal flow](css_flow_layout)* — all elements are part of normal flow until you do something to take them out of it. Normal flow includes *block layout*, designed for laying out boxes such as paragraphs and *inline layout*, which lays out inline items such as text. * [*Table layout*](css_table), designed for laying out tables. * *Float layout*, designed to cause an item to position itself left or right with the rest of the content in normal flow wrapping around it. * [*Positioned layout*](css_positioning), designed for positioning elements without much interaction with other elements. * [*Multi-column layout*](css_columns), designed for laying content out in columns as in a newspaper. * [*Flexible box layout*](css_flexible_box_layout), designed for laying out complex pages that can be resized smoothly. * [*Grid layout*](css_grid_layout), designed for laying out elements relative to a fixed grid. **Note:** Not all [CSS properties](index) apply to all *layout modes*. Most of them apply to one or two of them and have no effect if they are set on an element participating in another layout mode. See also -------- * CSS key concepts: + [CSS syntax](syntax) + [At-rules](at-rule) + [Comments](comments) + [Specificity](specificity) + [Inheritance](inheritance) + [Box model](css_box_model/introduction_to_the_css_box_model) + [Visual formatting models](visual_formatting_model) + [Margin collapsing](css_box_model/mastering_margin_collapsing) + Values - [Initial values](initial_value) - [Computed values](computed_value) - [Used values](used_value) - [Actual values](actual_value) + [Value definition syntax](value_definition_syntax) + [Shorthand properties](shorthand_properties) + [Replaced elements](replaced_element) css z-index z-index ======= The `z-index` CSS property sets the z-order of a [positioned](position) element and its descendants or flex items. Overlapping elements with a larger z-index cover those with a smaller one. Try it ------ For a positioned box (that is, one with any `position` other than `static`), the `z-index` property specifies: 1. The stack level of the box in the current [stacking context](css_positioning/understanding_z_index/the_stacking_context). 2. Whether the box establishes a local stacking context. Syntax ------ ``` /\* Keyword value \*/ z-index: auto; /\* <integer> values \*/ z-index: 0; z-index: 3; z-index: 289; z-index: -1; /\* Negative values to lower the priority \*/ /\* Global values \*/ z-index: inherit; z-index: initial; z-index: revert; z-index: revert-layer; z-index: unset; ``` The `z-index` property is specified as either the keyword `auto` or an `<integer>`. ### Values `auto` The box does not establish a new local stacking context. The stack level of the generated box in the current stacking context is `0`. `<integer>` This [`<integer>`](integer) is the stack level of the generated box in the current stacking context. The box also establishes a local stacking context. This means that the z-indexes of descendants are not compared to the z-indexes of elements outside this element. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | positioned elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | an [integer](integer#interpolation) | | Creates [stacking context](css_positioning/understanding_z_index/the_stacking_context) | yes | Formal syntax ------------- ``` z-index = auto [|](value_definition_syntax#single_bar) [<integer>](integer) [|](value_definition_syntax#single_bar) inherit ``` Examples -------- ### Visually layering elements #### HTML ``` <div class="wrapper"> <div class="dashed-box">Dashed box</div> <div class="gold-box">Gold box</div> <div class="green-box">Green box</div> </div> ``` #### CSS ``` .wrapper { position: relative; } .dashed-box { position: relative; z-index: 1; border: dashed; height: 8em; margin-bottom: 1em; margin-top: 2em; } .gold-box { position: absolute; z-index: 3; /\* put .gold-box above .green-box and .dashed-box \*/ background: gold; width: 80%; left: 60px; top: 3em; } .green-box { position: absolute; z-index: 2; /\* put .green-box above .dashed-box \*/ background: lightgreen; width: 20%; left: 65%; top: -25px; height: 7em; opacity: 0.9; } ``` #### Result Specifications -------------- | Specification | | --- | | [Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification # z-index](https://w3c.github.io/csswg-drafts/css2/#z-index) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `z-index` | 1 | 12 | 1 | 4 | 4 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | | `negative_values` | 1 | 12 | 3 | 4 | 4 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * CSS [`position`](position) property * [Understanding CSS z-indexes](css_positioning/understanding_z_index) css Computed value Computed value ============== The **computed value** of a [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property is the value that is transferred from parent to child during inheritance. It is calculated from the [specified value](specified_value) by: 1. Handling the special values [`inherit`](inherit), [`initial`](initial), [`revert`](revert), [`revert-layer`](revert-layer), and [`unset`](unset). 2. Doing the computation needed to reach the value described in the "Computed value" line in the property's definition table. The computation needed to reach a property's computed value typically involves converting relative values (such as those in `em` units or percentages) to absolute values. For example, if an element has specified values `font-size: 16px` and `padding-top: 2em`, then the computed value of `padding-top` is `32px` (double the font size). However, for some properties (those where percentages are relative to something that may require layout to determine, such as `width`, `margin-right`, `text-indent`, and `top`), percentage-specified values turn into percentage-computed values. Additionally, unitless numbers specified on the `line-height` property become the computed value, as specified. The relative values that remain in the computed value become absolute when the [used value](used_value) is determined. **Note:** The [`getComputedStyle()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle) DOM API returns the [resolved value](resolved_value), which may either be the [computed value](computed_value) or the [used value](used_value), depending on the property. Specifications -------------- | Specification | | --- | | [Cascading Style Sheets Level 2 Revision 2 (CSS 2.2) Specification # computed-value](https://www.w3.org/TR/CSS22/cascade.html#computed-value) | See also -------- * [`window.getComputedStyle`](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle) * CSS key concepts: + [CSS syntax](syntax) + [At-rules](at-rule) + [Comments](comments) + [Specificity](specificity) + [Inheritance](inheritance) + [Box model](css_box_model/introduction_to_the_css_box_model) + [Layout modes](layout_mode) + [Visual formatting models](visual_formatting_model) + [Margin collapsing](css_box_model/mastering_margin_collapsing) + Values - [Initial values](initial_value) - [Used values](used_value) - [Actual values](actual_value) + [Value definition syntax](value_definition_syntax) + [Shorthand properties](shorthand_properties) + [Replaced elements](replaced_element) css float float ===== The `float` CSS property places an element on the left or right side of its container, allowing text and inline elements to wrap around it. The element is removed from the normal flow of the page, though still remaining a part of the flow (in contrast to [absolute positioning](position#absolute_positioning)). Try it ------ A *floating element* is one where the computed value of `float` is not `none`. As `float` implies the use of the block layout, it modifies the computed value of the [`display`](display) values, in some cases: | Specified value | Computed value | | --- | --- | | `inline` | `block` | | `inline-block` | `block` | | `inline-table` | `table` | | `table-row` | `block` | | `table-row-group` | `block` | | `table-column` | `block` | | `table-column-group` | `block` | | `table-cell` | `block` | | `table-caption` | `block` | | `table-header-group` | `block` | | `table-footer-group` | `block` | | `inline-flex` | `flex` | | `inline-grid` | `grid` | | *other* | *unchanged* | **Note:** If you're referring to this property from JavaScript as a member of the [`HTMLElement.style`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) object, modern browsers support `float`, but in older browsers you have to spell it as `cssFloat`, with Internet Explorer versions 8 and older using `styleFloat`. This was an exception to the rule, that the name of the DOM member is the camel-case name of the dash-separated CSS name (because "float" is a reserved word in JavaScript, as seen in the need to escape "class" as "className" and escape <label>'s "for" as "htmlFor"). Syntax ------ ``` /\* Keyword values \*/ float: left; float: right; float: none; float: inline-start; float: inline-end; /\* Global values \*/ float: inherit; float: initial; float: revert; float: revert-layer; float: unset; ``` The `float` property is specified as a single keyword, chosen from the list of values below. ### Values `left` The element must float on the left side of its containing block. `right` The element must float on the right side of its containing block. `none` The element must not float. `inline-start` The element must float on the start side of its containing block. That is the left side with `ltr` scripts, and the right side with `rtl` scripts. `inline-end` The element must float on the end side of its containing block. That is the right side with `ltr` scripts, and the left side with `rtl` scripts. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements, but has no effect if the value of [`display`](display) is `none`. | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` float = block-start [|](value_definition_syntax#single_bar) block-end [|](value_definition_syntax#single_bar) inline-start [|](value_definition_syntax#single_bar) inline-end [|](value_definition_syntax#single_bar) snap-block [|](value_definition_syntax#single_bar) <snap-block()> [|](value_definition_syntax#single_bar) snap-inline [|](value_definition_syntax#single_bar) <snap-inline()> [|](value_definition_syntax#single_bar) left [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) top [|](value_definition_syntax#single_bar) bottom [|](value_definition_syntax#single_bar) none [|](value_definition_syntax#single_bar) footnote <snap-block()> = snap-block( [<length>](length) , [[](value_definition_syntax#brackets) start [|](value_definition_syntax#single_bar) end [|](value_definition_syntax#single_bar) near []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <snap-inline()> = snap-inline( [<length>](length) , [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) near []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) ``` Examples -------- ### How floated elements are positioned As mentioned above, when an element is floated, it is taken out of the normal flow of the document (though still remaining part of it). It is shifted to the left, or right, until it touches the edge of its containing box, *or another floated element*. In this example, there are three colored squares. Two are floated left, and one is floated right. Note that the second "left" square is placed to the right of the first. Additional squares would continue to stack to the right, until they filled the containing box, after which they would wrap to the next line. A floated element is at least as tall as its tallest nested floated children. We gave the parent `width: 100%` and floated it to ensure it is tall enough to encompass its floated children, and to make sure it takes up the width of the parent so we don't have to clear its adjacent sibling. #### HTML ``` <section> <div class="left">1</div> <div class="left">2</div> <div class="right">3</div> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi tristique sapien ac erat tincidunt, sit amet dignissim lectus vulputate. Donec id iaculis velit. Aliquam vel malesuada erat. Praesent non magna ac massa aliquet tincidunt vel in massa. Phasellus feugiat est vel leo finibus congue. </p> </section> ``` #### CSS ``` section { box-sizing: border-box; border: 1px solid blue; width: 100%; float: left; } div { margin: 5px; width: 50px; height: 150px; } .left { float: left; background: pink; } .right { float: right; background: cyan; } ``` #### Result ### Clearing floats Sometimes you may want to force an item to move below any floated elements. For instance, you may want paragraphs to remain adjacent to floats, but force headings to be on their own line. See [`clear`](clear) for examples. Specifications -------------- | Specification | | --- | | [Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification # propdef-float](https://w3c.github.io/csswg-drafts/css2/#propdef-float) | | [CSS Logical Properties and Values Level 1 # float-clear](https://w3c.github.io/csswg-drafts/css-logical/#float-clear) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `float` | 1 | 12 | 1 | 4 | 7 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `flow_relative_values` | 70 | 79 | 55 | No | 57 | preview | No | 70 | 55 | No | No | No | See also -------- * [Block formatting context](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context) * Use [`clear`](clear) to force an item to move below a floated element.
programming_docs
css General sibling combinator General sibling combinator ========================== The **general sibling combinator** (`~`) separates two selectors and matches *all iterations* of the second element, that are following the first element (though not necessarily immediately), and are children of the same parent [element](https://developer.mozilla.org/en-US/docs/Glossary/Element). ``` /\* Paragraphs that are siblings of and subsequent to any image \*/ img ~ p { color: red; } ``` Syntax ------ ``` former\_element ~ target\_element { style properties } ``` Examples -------- ### CSS ``` p ~ span { color: red; } ``` ### HTML ``` <span>This is not red.</span> <p>Here is a paragraph.</p> <code>Here is some code.</code> <span>And here is a red span!</span> <span>And this is a red span!</span> <code>More code…</code> <div>How are you?</div> <p>Whatever it may be, keep smiling.</p> <h1>Dream big</h1> <span>And yet again this is a red span!</span> ``` ### Result Specifications -------------- | Specification | | --- | | [Selectors Level 4 # general-sibling-combinators](https://w3c.github.io/csswg-drafts/selectors/#general-sibling-combinators) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `General_sibling_combinator` | 1 | 12 | 1 | 7 Before Internet Explorer 10, the combinator only works in standards mode. | 9 | 3 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [Adjacent sibling combinator](adjacent_sibling_combinator) css :nth-of-type() :nth-of-type() ============== The `:nth-of-type()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) matches elements based on their position among siblings of the same type (tag name). Try it ------ Syntax ------ The `nth-of-type` pseudo-class is specified with a single argument, which represents the pattern for matching elements. See [`:nth-child`](:nth-child) for a more detailed explanation of its syntax. ``` :nth-of-type( <an-plus-b> | even | odd ) ``` Examples -------- ### Basic example #### HTML ``` <div> <div>This element isn't counted.</div> <p>1st paragraph.</p> <p class="fancy">2nd paragraph.</p> <div>This element isn't counted.</div> <p class="fancy">3rd paragraph.</p> <p>4th paragraph.</p> </div> ``` #### CSS ``` /\* Odd paragraphs \*/ p:nth-of-type(2n + 1) { color: red; } /\* Even paragraphs \*/ p:nth-of-type(2n) { color: blue; } /\* First paragraph \*/ p:nth-of-type(1) { font-weight: bold; } /\* This will match the 3rd paragraph as it will match elements which are 2n+1 AND have a class of fancy. The second paragraph has a class of fancy but is not matched as it is not :nth-of-type(2n+1) \*/ p.fancy:nth-of-type(2n + 1) { text-decoration: underline; } ``` #### Result **Note:** There is no way to select the nth-of-class using this selector. The selector looks at the type only when creating the list of matches. You can however apply CSS to an element based on `:nth-of-type` location **and** a class, as shown in the example above. Specifications -------------- | Specification | | --- | | [Selectors Level 4 # nth-of-type-pseudo](https://w3c.github.io/csswg-drafts/selectors/#nth-of-type-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:nth-of-type` | 1 | 12 Before Edge 16, Microsoft Edge treats all unknown elements (such as custom elements) as the same element type. | 3.5 | 9 Internet Explorer treats all unknown elements (such as custom elements) as the same element type. | 9.5 | 3.1 | 2 | 18 | 4 | 10.1 | 2 | 1.0 | See also -------- * [`:nth-child`](:nth-child), [`:nth-last-of-type`](:nth-last-of-type) css inset-block-end inset-block-end =============== The `inset-block-end` [CSS](https://developer.mozilla.org/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 [`top`](top), [`right`](right), [`bottom`](bottom), or [`left`](left) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ Syntax ------ ``` /\* <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 [`left`](left) property. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | positioned elements | | [Inherited](inheritance) | no | | Percentages | logical-height of containing block | | [Computed value](computed_value) | same as box offsets: [`top`](top), [`right`](right), [`bottom`](bottom), [`left`](left) properties except that directions are logical | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` inset-block-end = auto [|](value_definition_syntax#single_bar) <length-percentage> <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Setting block end offset #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-rl; position: relative; inset-block-end: 20px; background-color: #c8c800; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # position-properties](https://w3c.github.io/csswg-drafts/css-logical/#position-properties) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `inset-block-end` | 87 | 87 | 63 41-63 | No | 73 | 14.1 | 87 | 87 | 63 41-63 | 62 | 14.5 | 14.0 | See also -------- * The properties which defines other insets: [`inset-block-start`](inset-block-start), [`inset-inline-start`](inset-inline-start), and [`inset-inline-end`](inset-inline-end) * The mapped physical properties: [`top`](top), [`right`](right), [`bottom`](bottom), and [`left`](left) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css break-after break-after =========== The `break-after` [CSS](https://developer.mozilla.org/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. ``` /\* 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 [`break-before`](break-before) value of the next element, and the [`break-inside`](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. Syntax ------ The `break-after` property is specified as one of the keyword values from the list below. ### 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 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 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` Experimental 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` Experimental 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 Avoids any region break right after the principal box. `region` Experimental Forces a region break right after the principal box. Page break aliases ------------------ For compatibility reasons, the legacy [`page-break-after`](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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | block-level elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` break-after = auto [|](value_definition_syntax#single_bar) avoid [|](value_definition_syntax#single_bar) always [|](value_definition_syntax#single_bar) all [|](value_definition_syntax#single_bar) avoid-page [|](value_definition_syntax#single_bar) page [|](value_definition_syntax#single_bar) left [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) recto [|](value_definition_syntax#single_bar) verso [|](value_definition_syntax#single_bar) avoid-column [|](value_definition_syntax#single_bar) column [|](value_definition_syntax#single_bar) avoid-region [|](value_definition_syntax#single_bar) region ``` 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 ``` <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 ``` 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 Specifications -------------- | Specification | | --- | | [CSS Fragmentation Module Level 3 # break-between](https://w3c.github.io/csswg-drafts/css-break/#break-between) | | [CSS Regions Module Level 1 # region-flow-break](https://w3c.github.io/csswg-drafts/css-regions/#region-flow-break) | | [CSS Multi-column Layout Module Level 1 # break-before-break-after-break-inside](https://w3c.github.io/csswg-drafts/css-multicol/#break-before-break-after-break-inside) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `break-after` | 50 | 12 | 65 | 10 | 37 11.1-12.1 | 10 | 50 | 50 | 65 | 37 11.1-12.1 | 10 | 5.0 | | `multicol_context` | 50 | 12 | 65 Only supported in print mode. See [bug 1675322](https://bugzil.la/1675322). | 10 | 37 11.1-12.1 | No | 50 | 50 | 65 Only supported in print mode. See [bug 1675322](https://bugzil.la/1675322). | 37 11.1-12.1 | No | 5.0 | | `paged_context` | 50 | 12 | 65 | 10 | 37 11.1-12.1 | 10 | 50 | 50 | 65 | 37 11.1-12.1 | 10 | 5.0 | See also -------- * [Multiple-column Layout](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Multiple-column_Layout) * [Breaking Boxes With CSS Fragmentation](https://www.smashingmagazine.com/2019/02/css-fragmentation/) css animation-timeline animation-timeline ================== **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `animation-timeline` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property specifies the timeline that is used to control the progress of an animation. The timeline can be provided by the current position on a scrollbar, in which case it is referred to as a scrollbar timeline. The element that provides the scrollbar timeline can be specified in two ways: * A *named scroll timeline* is one in which the element that will provide the scrollbar timeline is explicitly named, by applying the [`scroll-timeline-name`](scroll-timeline-name) property (or the [`scroll-timeline`](scroll-timeline) shorthand property). The name is then associated with the element to animate using the `animation-timeline` property. * An *anonymous scroll timeline* is set using the [`scroll()`](animation-timeline/scroll) functional notation, which indicates that the element providing the scroll timeline is an ancestor of the element to be animated. The ancestor can either be set as either the root element or the nearest ancestor that has a scroll bar in either axis. Whether the scrollbar uses a scrollbar at the top/bottom or left/right of the element can also be specified. If the selected axis does not have a scrollbar the associated animation timeline will be inactive. The animation timeline can also be set using the [`animation`](animation) shorthand property. Syntax ------ ``` /\* Keyword \*/ animation-timeline: none; animation-timeline: auto; /\* Single animation named timeline \*/ animation-timeline: some_scrollbar_timeline_name; animation-timeline: -specific; animation-timeline: sliding-vertically; /\* Single animation anonymous timeline \*/ animation-timeline: scroll(); animation-timeline: scroll(root inline); /\* Multiple animations \*/ animation-timeline: test1, animation4; animation-timeline: none, -moz-specific, sliding; /\* Global values \*/ animation-timeline: inherit; animation-timeline: initial; animation-timeline: revert; animation-timeline: revert-layer; animation-timeline: unset; ``` ### Values `none` The animation is not associated with a timeline. `auto` The animation's timeline is the document's default [DocumentTimeline](https://developer.mozilla.org/en-US/docs/Web/API/DocumentTimeline). `scroll()` Experimental The "anonymous" timeline is provided by some ancestor of the current element. See [`scroll()`](animation-timeline/scroll) for additional information. `<timeline-name>` A [`<custom-ident>`](custom-ident) or string identifying the named scroll timeline, declared with the [`scroll-timeline-name`](scroll-timeline-name) property (or [`scroll-timeline`](scroll-timeline) shorthand property). If two or more scroll timelines share the same name, the last declared within the cascade will be used. If no matching scroll timeline is found, the animation is not associated with a timeline. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | listEachItemIdentifyerOrNoneAuto | | Animation type | Not animatable | Formal syntax ------------- ``` animation-timeline = <single-animation-timeline>[#](value_definition_syntax#hash_mark) <single-animation-timeline> = auto [|](value_definition_syntax#single_bar) none [|](value_definition_syntax#single_bar) <timeline-name> <timeline-name> = [<custom-ident>](custom-ident) [|](value_definition_syntax#single_bar) [<string>](string) ``` Examples -------- ### Setting a named scroll timeline A scroll timeline named `squareTimeline` is defined using the `scroll-timeline-name` property on the element with id `container`. This is then applied to the animation on the `#square` element using `animation-timeline: squareTimeline`. #### HTML The HTML for the example is shown below. ``` <div id="container"> <div id="square"></div> <div id="stretcher"></div> </div> ``` #### CSS The CSS for the container sets it as the source of a scroll timeline named `squareTimeline` using the `scroll-timeline-name` property (we could also set which scrollbar axis to use with `scroll-timeline-axis`, but there will be only one scrollbar here, and it will be used by default). The height of the container is set to 300px and we also set the container to create a vertical scrollbar if it overflows (below we will use CSS on the "stretcher" element to ensure that it does overflow). ``` #container { height: 300px; overflow-y: scroll; scroll-timeline-name: squareTimeline; position: relative; } ``` The CSS below defines a square that rotates in alternate directions according to the timeline provided by the `animation-timeline` property, which is set to the `squareTimeline` timeline named above. ``` #square { background-color: deeppink; width: 100px; height: 100px; margin-top: 100px; animation-name: rotateAnimation; animation-duration: 3s; animation-direction: alternate; animation-timeline: squareTimeline; position: absolute; bottom: 0; } @keyframes rotateAnimation { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } ``` The "stretcher" CSS simply sets the block height to 600px, which forces the container element to overflow and create scroll bars. Without this element there would be no scrollbar, and hence no scroll timeline to associate with the animation timeline. ``` #stretcher { height: 600px; } ``` #### Result Scroll to see the square element being animated. ### Setting an anonymous scroll timeline The `#square` element is animated using an anonymous scrollbar timeline, which is applied to the element to be animated using the `scroll()` functional notation. The timeline in this particular example is provided by the nearest parent element that has (any) scrollbar, from the scrollbar in the block direction. #### HTML The HTML for the example is shown below. ``` <div id="container"> <div id="square"></div> <div id="stretcher"></div> </div> ``` #### CSS The CSS below defines a square that rotates in alternate directions according to the timeline provided by the `animation-timeline` property. In this case the timeline is provided by `scroll(block nearest)`, which means that it will select the scrollbar in the block direction of the nearest ancestor element that has scrollbars; in this case the vertical scrollbar of the "container" element. Note that the `block nearest` options below are actually the default, so we could instead just have had: `scroll()`. ``` #square { background-color: deeppink; width: 100px; height: 100px; margin-top: 100px; position: absolute; bottom: 0; animation-name: rotateAnimation; animation-duration: 3s; animation-direction: alternate; animation-timeline: scroll(block nearest); } @keyframes rotateAnimation { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } ``` The CSS for the container sets its height to 300px and we also set the container to create a vertical scrollbar if it overflows. The "stretcher" CSS sets the block height to 600px, which forces the container element to overflow. These two together ensure that the container has a vertical scrollbar, which allows it to be used as the source of the anonymous scrollbar timeline. ``` #container { height: 300px; overflow-y: scroll; position: relative; } #stretcher { height: 600px; } ``` #### Result Scroll to see the square element being animated. Specifications -------------- | Specification | | --- | | [CSS Animations Level 2 # animation-timeline](https://w3c.github.io/csswg-drafts/css-animations-2/#animation-timeline) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `animation-timeline` | No | No | 97 | No | No | No | No | No | No | No | No | No | | `scroll` | No | No | 101 Zero scroll range is treated as 100% but should be 0% (see [bug 1780865](https://bugzil.la/1780865)). | No | No | No | No | No | No | No | No | No | See also -------- * [Using CSS animations](css_animations/using_css_animations) * Other related animation properties: [`animation`](animation), [`animation-composition`](animation-composition), [`animation-delay`](animation-delay), [`animation-direction`](animation-direction), [`animation-duration`](animation-duration), [`animation-fill-mode`](animation-fill-mode), [`animation-iteration-count`](animation-iteration-count), [`animation-name`](animation-name), [`animation-play-state`](animation-play-state), [`animation-timing-function`](animation-timing-function)
programming_docs
css text-justify text-justify ============ The `text-justify` CSS property sets what type of justification should be applied to text when [`text-align`](text-align)`: justify;` is set on an element. Syntax ------ ``` text-justify: none; text-justify: auto; text-justify: inter-word; text-justify: inter-character; text-justify: distribute; /\* Deprecated value \*/ /\* Global values \*/ text-justify: inherit; text-justify: initial; text-justify: revert; text-justify: revert-layer; text-justify: unset; ``` ### Values `none` The text justification is turned off. This has the same effect as not setting [`text-align`](text-align) at all, although it is useful if you need to turn justification on and off for some reason. `auto` The browser chooses the best type of justification for the current situation based on a balance between performance and quality, but also on what is most appropriate for the language of the text (e.g., English, CJK languages, etc.). This is the default justification used if `text-justify` is not set at all. `inter-word` The text is justified by adding space between words (effectively varying [`word-spacing`](word-spacing)), which is most appropriate for languages that separate words using spaces, like English or Korean. `inter-character` The text is justified by adding space between characters (effectively varying [`letter-spacing`](letter-spacing)), which is most appropriate for languages like Japanese. `distribute` Deprecated Exhibits the same behavior as `inter-character`; this value is kept for backwards compatibility. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | inline-level and table-cell elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` text-justify = auto [|](value_definition_syntax#single_bar) none [|](value_definition_syntax#single_bar) inter-word [|](value_definition_syntax#single_bar) inter-character ``` Examples -------- ### Demonstration of the different values of text-justify ``` p { font-size: 1.5em; border: 1px solid black; padding: 10px; width: 95%; margin: 10px auto; text-align: justify; } .none { text-justify: none; } .auto { text-justify: auto; } .dist { text-justify: distribute; } .word { text-justify: inter-word; } .char { text-justify: inter-character; } ``` Specifications -------------- | Specification | | --- | | [CSS Text Module Level 3 # text-justify-property](https://w3c.github.io/csswg-drafts/css-text/#text-justify-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `text-justify` | 32 `inter-word` and `distribute` (deprecated) values are supported, but `distribute` behavior is buggy. | 12 Standard values `inter-character` and `none` are supported. The deprecated `distribute` value is also supported. | 55 | 11 Standard values `inter-character` and `none` are supported. The deprecated `distribute` value is also supported. | 19 `inter-word` and `distribute` (deprecated) values are supported, but `distribute` behavior is buggy. | No See [bug 9945](https://webkit.org/b/99945). | No | 32 `inter-word` and `distribute` (deprecated) values are supported, but `distribute` behavior is buggy. | 55 | No | No See [bug 9945](https://webkit.org/b/99945). | No | See also -------- * [`text-align`](text-align) css scroll-padding-block-end scroll-padding-block-end ======================== 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. Try it ------ Syntax ------ ``` /\* 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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | scroll containers | | [Inherited](inheritance) | no | | Percentages | relative to the scroll container's scrollport | | [Computed value](computed_value) | as specified | | Animation type | by computed value type | Formal syntax ------------- ``` scroll-padding-block-end = auto [|](value_definition_syntax#single_bar) [<length-percentage [0,∞]>](length-percentage) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Specifications -------------- | Specification | | --- | | [CSS Scroll Snap Module Level 1 # padding-longhands-logical](https://w3c.github.io/csswg-drafts/css-scroll-snap/#padding-longhands-logical) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scroll-padding-block-end` | 69 | 79 | 68 | No | 56 | 15 | 69 | 69 | 68 | 48 | 15 | 10.0 | See also -------- * [CSS Scroll Snap](css_scroll_snap) * [Well-Controlled Scrolling with CSS Scroll Snap](https://web.dev/css-scroll-snap/) css margin-trim margin-trim =========== **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `margin-trim` property allows the container to trim the margins of its children where they adjoin the container's edges. Syntax ------ ``` 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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | Block containers and multi-column containers. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` margin-trim = none [|](value_definition_syntax#single_bar) block [|](value_definition_syntax#single_bar) inline [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) block-start [||](value_definition_syntax#double_bar) inline-start [||](value_definition_syntax#double_bar) block-end [||](value_definition_syntax#double_bar) inline-end []](value_definition_syntax#brackets) ``` 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: ``` 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: ``` 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: ``` article { margin-trim: inline-end; /\* … \*/ } ``` Similarly, to remove left margin with the container's edge: ``` article { margin-trim: inline-start; /\* … \*/ } ``` Specifications -------------- | Specification | | --- | | [CSS Box Model Module Level 4 # margin-trim](https://w3c.github.io/csswg-drafts/css-box-4/#margin-trim) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `margin-trim` | No | No | No See [bug 1506241](https://bugzil.la/1506241). | No | No | No | No | No | No See [bug 1506241](https://bugzil.la/1506241). | No | No | No | See also -------- * [`margin`](margin) css grid-template-areas grid-template-areas =================== The `grid-template-areas` CSS property specifies named [grid areas](https://developer.mozilla.org/en-US/docs/Glossary/Grid_Areas), establishing the cells in the grid and assigning them names. Try it ------ Those areas are not associated with any particular grid item, but can be referenced from the grid-placement properties [`grid-row-start`](grid-row-start), [`grid-row-end`](grid-row-end), [`grid-column-start`](grid-column-start), [`grid-column-end`](grid-column-end), and their shorthands [`grid-row`](grid-row), [`grid-column`](grid-column), and [`grid-area`](grid-area). Syntax ------ ``` /\* Keyword value \*/ grid-template-areas: none; /\* <string> values \*/ grid-template-areas: "a b"; grid-template-areas: "a b b" "a c d"; /\* Global values \*/ grid-template-areas: inherit; grid-template-areas: initial; grid-template-areas: revert; grid-template-areas: revert-layer; grid-template-areas: unset; ``` ### Values `none` The grid container doesn't define any named grid areas. `[`<string>`](string)+` A row is created for every separate string listed, and a column is created for each cell in the string. Multiple cell tokens with the same name within and between rows create a single named grid area that spans the corresponding grid cells. Unless those cells form a rectangle, the declaration is invalid. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | grid containers | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` grid-template-areas = none [|](value_definition_syntax#single_bar) [<string>](string)[+](value_definition_syntax#plus) ``` Examples -------- ### Specifying named grid areas #### HTML ``` <section id="page"> <header>Header</header> <nav>Navigation</nav> <main>Main area</main> <footer>Footer</footer> </section> ``` #### CSS ``` #page { display: grid; width: 100%; height: 250px; grid-template-areas: "head head" "nav main" "nav foot"; grid-template-rows: 50px 1fr 30px; grid-template-columns: 150px 1fr; } #page > header { grid-area: head; background-color: #8ca0ff; } #page > nav { grid-area: nav; background-color: #ffa08c; } #page > main { grid-area: main; background-color: #ffff64; } #page > footer { grid-area: foot; background-color: #8cffa0; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Grid Layout Module Level 2 # grid-template-areas-property](https://w3c.github.io/csswg-drafts/css-grid/#grid-template-areas-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `grid-template-areas` | 57 | 16 | 52 | No | 44 | 10.1 | 57 | 57 | 52 | 43 | 10.3 | 6.0 | See also -------- * Related CSS properties: [`grid-template-rows`](grid-template-rows), [`grid-template-columns`](grid-template-columns), [`grid-template`](grid-template) * Grid Layout Guide: *[Grid template areas](css_grid_layout/grid_template_areas)* * Video tutorial: *[Grid Template Areas](https://gridbyexample.com/video/grid-template-areas/)* css mask-size mask-size ========= The `mask-size` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property specifies the sizes of the mask images. The size of the image can be fully or partially constrained in order to preserve its intrinsic ratio. ``` /\* Keywords syntax \*/ mask-size: cover; mask-size: contain; /\* One-value syntax \*/ /\* the width of the image (height set to 'auto') \*/ mask-size: 50%; mask-size: 3em; mask-size: 12px; mask-size: auto; /\* Two-value syntax \*/ /\* first value: width of the image, second value: height \*/ mask-size: 50% auto; mask-size: 3em 25%; mask-size: auto 6px; mask-size: auto auto; /\* Multiple values \*/ /\* Do not confuse this with mask-size: auto auto \*/ mask-size: auto, auto; mask-size: 50%, 25%, 25%; mask-size: 6px, auto, contain; /\* Global values \*/ mask-size: inherit; mask-size: initial; mask-size: revert; mask-size: revert-layer; mask-size: unset; ``` **Note:** If the value of this property is not set in a [`mask`](mask) shorthand property that is applied to the element after the `mask-size` CSS property, the value of this property is then reset to its initial value by the shorthand property. Syntax ------ One or more `<bg-size>` values, separated by commas. A `<bg-size>` can be specified in one of three ways: * using the keyword `contain` * using the keyword `cover` * using width and height values To specify a size using width and height, you can supply one or two values: * If only one value is given it sets the width, with the height set to `auto`. * If two values are given, the first sets width and the second sets height. Each value can be a `<length>`, a `<percentage>`, or `auto`. ### Values `<length>` A `[`<length>`](length)` value scales the mask image to the specified length in the corresponding dimension. Negative lengths are not allowed. `<percentage>` A [`<percentage>`](percentage) value scales the mask image in the corresponding dimension to the specified percentage of the mask positioning area, which is determined by the value of [`mask-origin`](mask-origin). The mask positioning area is, by default, the area containing the content of the box and its padding; the area may also be changed to just the content or to the area containing borders, padding and content. Negative percentages are not allowed. `auto` A keyword that scales the mask image in the corresponding directions in order to maintain its intrinsic proportion. `contain` A keyword that scales the image as large as possible and maintains image aspect ratio (image doesn't get squished). The image is *letterboxed* within the container. The image is automatically centered unless over-ridden by another property such as [`mask-position`](mask-position). `cover` A keyword that is the inverse of `contain`. Scales the image as large as possible and maintains image aspect ratio (image doesn't get squished). The image "covers" the entire width or height of the container. When the image and container have different dimensions, *the image is clipped* either on left/right or at top/bottom. The interpretation of possible values depends on the image's intrinsic dimensions (width and height) and intrinsic proportion (ratio of width and height). A bitmap image always has intrinsic dimensions and an intrinsic proportion. A vector image may have both intrinsic dimensions and thus it has an intrinsic proportion too. It also may have one or no intrinsic dimensions and in either case it might or might not have an intrinsic proportion. Gradients are treated as images with no intrinsic dimensions or intrinsic proportion. The rendered size of the mask image is then computed as follows: If both components of `mask-size` are specified and are not `auto`: The mask image renders at the specified size. If the `mask-size` is `contain` or `cover`: The image is rendered by preserving its intrinsic proportion at the largest size contained within or covering the mask positioning area. If the image has no intrinsic proportion, then it is rendered at the size of the mask positioning area. If the `mask-size` is `auto` or `auto auto`: If the image has both intrinsic dimensions, it is rendered at that size. If it has no intrinsic dimensions and no intrinsic proportion, it is rendered at the size of the mask positioning area. If it has no dimensions but has a proportion, it's rendered as if `contain` had been specified instead. If the image has one intrinsic dimension and a proportion, it's rendered at the size determined by that one dimension and the proportion. If the image has one intrinsic dimension but no proportion, it's rendered using the intrinsic dimension and the corresponding dimension of the mask positioning area. If `mask-size` has one `auto` component and one non-`auto` component: If the image has an intrinsic proportion, then render it using the specified dimension and compute the other dimension from the specified dimension and the intrinsic proportion. If the image has no intrinsic proportion, use the specified dimension for that dimension. For the other dimension, use the image's corresponding intrinsic dimension if there is one. If there is no such intrinsic dimension, use the corresponding dimension of the mask positioning area. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | all elements; In SVG, it applies to container elements excluding the [`<defs>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs) element and all graphics elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified, but with relative lengths converted into absolute lengths | | Animation type | repeatable list of simple list of length, percentage, or calc | Formal syntax ------------- ``` mask-size = <bg-size>[#](value_definition_syntax#hash_mark) <bg-size> = [[](value_definition_syntax#brackets) [<length-percentage [0,∞]>](length-percentage) [|](value_definition_syntax#single_bar) auto []](value_definition_syntax#brackets)[{1,2}](value_definition_syntax#curly_braces) [|](value_definition_syntax#single_bar) cover [|](value_definition_syntax#single_bar) contain <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Setting mask size as a percentage Specifications -------------- | Specification | | --- | | [CSS Masking Module Level 1 # the-mask-size](https://drafts.fxtf.org/css-masking/#the-mask-size) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `mask-size` | 4 | 79 18-79 | 53 | No | 15 | 15.4 4 | 4.4 | 18 | 53 | 14 | 15.4 2 | 1.0 | See also -------- * [Clipping and Masking in CSS](https://css-tricks.com/clipping-masking-css/)
programming_docs
css column-fill column-fill =========== The `column-fill` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property controls how an element's contents are balanced when broken into columns. Try it ------ Syntax ------ ``` /\* Keyword values \*/ column-fill: auto; column-fill: balance; column-fill: balance-all; /\* Global values \*/ column-fill: inherit; column-fill: initial; column-fill: revert; column-fill: revert-layer; column-fill: unset; ``` The `column-fill` property is specified as one of the keyword values listed below. The initial value is `balance` so the content will be balanced across the columns. ### Values `auto` Columns are filled sequentially. Content takes up only the room it needs, possibly resulting in some columns remaining empty. `balance` Content is equally divided between columns. In fragmented contexts, such as [paged media](https://developer.mozilla.org/en-US/docs/Web/CSS/Paged_Media), only the last fragment is balanced. Therefore in paged media, only the last page would be balanced. `balance-all` Experimental Content is equally divided between columns. In fragmented contexts, such as [paged media](https://developer.mozilla.org/en-US/docs/Web/CSS/Paged_Media), all fragments are balanced. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `balance` | | Applies to | multicol elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` column-fill = auto [|](value_definition_syntax#single_bar) balance [|](value_definition_syntax#single_bar) balance-all ``` Example ------- ### Balancing column content #### HTML ``` <p class="fill-auto"> This paragraph fills columns one at a time. Since all of the text can fit in the first column, the others are empty. </p> <p class="fill-balance"> This paragraph attempts to balance the amount of content in each column. </p> ``` #### CSS ``` p { height: 7em; background: #ff9; columns: 3; column-rule: 1px solid; } p.fill-auto { column-fill: auto; } p.fill-balance { column-fill: balance; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Multi-column Layout Module Level 1 # cf](https://w3c.github.io/csswg-drafts/css-multicol/#cf) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `column-fill` | 50 | 12 | 52 13-74 | 10 | 37 | 9 8 | 50 | 50 | 52 14 | 37 | 9 8 | 5.0 | | `balance-all` | No See [bug 909596](https://crbug.com/909596). | No See [bug 909596](https://crbug.com/909596). | No | No | No See [bug 909596](https://crbug.com/909596). | No | No See [bug 909596](https://crbug.com/909596). | No See [bug 909596](https://crbug.com/909596). | No | No See [bug 909596](https://crbug.com/909596). | No | No See [bug 909596](https://crbug.com/909596). | **Warning:** There are some interoperability issues and bugs with `column-fill` across browsers, due to unresolved issues in the specification. In particular, when using `column-fill: auto` to fill columns sequentially, Chrome will only consult this property if the multicol container has a size in the block dimension (e.g., height in a horizontal writing mode). Firefox will always consult this property, therefore filling the first column with all of the content in cases where there is no size. See also -------- * [Multiple-column Layout](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Multiple-column_Layout) * [`column-count`](column-count) * [`column-width`](column-width) css padding-block padding-block ============= The `padding-block` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [shorthand property](shorthand_properties) defines the logical block start and end padding of an element, which maps to physical padding properties depending on the element's writing mode, directionality, and text orientation. Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`padding-block-end`](padding-block-end) * [`padding-block-start`](padding-block-start) Syntax ------ ``` /\* <length> values \*/ padding-block: 10px 20px; /\* An absolute length \*/ padding-block: 1em 2em; /\* relative to the text size \*/ padding-block: 10px; /\* sets both start and end values \*/ /\* <percentage> values \*/ padding-block: 5% 2%; /\* relative to the nearest block container's width \*/ /\* Global values \*/ padding-block: inherit; padding-block: initial; padding-block: revert; padding-block: unset; ``` The `padding-block` property may be specified with one or two values. If one value is given, it is used as the value for both [`padding-block-start`](padding-block-start) and [`padding-block-end`](padding-block-end). If two values are given, the first is used for [`padding-block-start`](padding-block-start) and the second for [`padding-block-end`](padding-block-end). ### Values The `padding-block` property takes the same values as the [`padding-left`](padding-left) property. Description ----------- These values corresponds to the [`padding-top`](padding-top) and [`padding-bottom`](padding-bottom), or [`padding-right`](padding-right), and [`padding-left`](padding-left) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`padding-block-start`](padding-block-start): `0` * [`padding-block-end`](padding-block-end): `0` | | Applies to | all elements, except `table-row-group`, `table-header-group`, `table-footer-group`, `table-row`, `table-column-group` and `table-column` | | [Inherited](inheritance) | no | | Percentages | logical-width of containing block | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`padding-block-start`](padding-block-start): as [`<length>`](length) * [`padding-block-end`](padding-block-end): as [`<length>`](length) | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` padding-block = <'padding-top'>[{1,2}](value_definition_syntax#curly_braces) ``` Examples -------- ### Setting block padding for vertical text #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-rl; padding-block: 20px 40px; background-color: #c8c800; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # propdef-padding-block](https://w3c.github.io/csswg-drafts/css-logical/#propdef-padding-block) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `padding-block` | 87 | 87 | 66 | No | 73 | 14.1 | 87 | 87 | 66 | 62 | 14.5 | 14.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * The mapped physical properties: [`padding-top`](padding-top), [`padding-right`](padding-right), [`padding-bottom`](padding-bottom), and [`padding-left`](padding-left) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css animation-delay animation-delay =============== The `animation-delay` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property specifies the amount of time to wait from applying the animation to an element before beginning to perform the animation. The animation can start later, immediately from its beginning, or immediately and partway through the animation. Try it ------ It is often convenient to use the shorthand property [`animation`](animation) to set all animation properties at once. Syntax ------ ``` /\* Single animation \*/ animation-delay: 3s; animation-delay: 0s; animation-delay: -1500ms; /\* Multiple animations \*/ animation-delay: 2.1s, 480ms; /\* Global values \*/ animation-delay: inherit; animation-delay: initial; animation-delay: revert; animation-delay: revert-layer; animation-delay: unset; ``` ### Values `[`<time>`](time)` The time offset, from the moment at which the animation is applied to the element, at which the animation should begin. This may be specified in either seconds (`s`) or milliseconds (`ms`). The unit is required. A positive value indicates that the animation should begin after the specified amount of time has elapsed. A value of `0s`, which is the default, indicates that the animation should begin as soon as it's applied. A negative value causes the animation to begin immediately, but partway through its cycle. For example, if you specify `-1s` as the animation delay time, the animation will begin immediately but will start 1 second into the animation sequence. If you specify a negative value for the animation delay, but the starting value is implicit, the starting value is taken from the moment the animation is applied to the element. **Note:** When you specify multiple comma-separated values on an `animation-*` property, they are applied to the animations in the order in which the [`animation-name`](animation-name)s appear. For situations where the number of animations and `animation-*` property values do not match, see [Setting multiple animation property values](css_animations/using_css_animations#setting_multiple_animation_property_values). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0s` | | Applies to | all elements, [`::before`](::before) and [`::after`](::after) <pseudo-elements> | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | Not animatable | Formal syntax ------------- ``` animation-delay = [[](value_definition_syntax#brackets) <'animation-delay-start'> <'animation-delay-end'>[?](value_definition_syntax#question_mark) [|](value_definition_syntax#single_bar) [<timeline-range-name>](timeline-range-name) []](value_definition_syntax#brackets)[#](value_definition_syntax#hash_mark) ``` Examples -------- ### Setting an animation delay This animation has a delay of 2 seconds. #### HTML ``` <div class="box"></div> ``` #### CSS ``` .box { background-color: rebeccapurple; border-radius: 10px; width: 100px; height: 100px; } .box:hover { animation-name: rotate; animation-duration: 0.7s; animation-delay: 2s; } @keyframes rotate { 0% { transform: rotate(0); } 100% { transform: rotate(360deg); } } ``` #### Result Hover over the rectangle to start the animation. See [CSS animations](css_animations/using_css_animations) for examples. Specifications -------------- | Specification | | --- | | [CSS Animations Level 1 # animation-delay](https://w3c.github.io/csswg-drafts/css-animations/#animation-delay) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `animation-delay` | 43 3 | 12 12 | 49 16 Before Firefox 57, Firefox does not repaint elements outside the viewport that are animated into the viewport with a delay. This bug affects only some platforms, such as Windows. 5 | 10 | 30 15 12.1-15 12-15 | 9 4 | 43 ≤37 | 43 18 | 49 16 5 | 30 14 12.1-14 12-14 | 9 3.2 | 4.0 1.0 | See also -------- * [Using CSS animations](css_animations/using_css_animations) * JavaScript [`AnimationEvent`](https://developer.mozilla.org/en-US/docs/Web/API/AnimationEvent) API * Other related animation properties: [`animation`](animation), [`animation-composition`](animation-composition), [`animation-direction`](animation-direction), [`animation-duration`](animation-duration), [`animation-fill-mode`](animation-fill-mode), [`animation-iteration-count`](animation-iteration-count), [`animation-name`](animation-name), [`animation-play-state`](animation-play-state), [`animation-timeline`](animation-timeline), [`animation-timing-function`](animation-timing-function) css padding-inline-start padding-inline-start ==================== The `padding-inline-start` [CSS](https://developer.mozilla.org/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. Try it ------ Syntax ------ ``` /\* <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 [`<length>`](length) The size of the padding as a fixed value. Must be nonnegative. [`<percentage>`](percentage) The size of the padding as a percentage, relative to the inline size (*width* in a horizontal language, defined by [`writing-mode`](writing-mode)) of the [containing block](containing_block). Must be nonnegative. Description ----------- The `padding-inline-start` property is defined in the specification as taking the same values as the [`padding-top`](padding-top) property. However, the physical property it maps to depends on the values set for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Therefore, it could map to [`padding-top`](padding-top), [`padding-right`](padding-right), or [`padding-left`](padding-left) It relates to [`padding-block-start`](padding-block-start), [`padding-block-end`](padding-block-end), and [`padding-inline-end`](padding-inline-end), which define the other paddings of the element. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | all elements, except `table-row-group`, `table-header-group`, `table-footer-group`, `table-row`, `table-column-group` and `table-column` | | [Inherited](inheritance) | no | | Percentages | logical-width of containing block | | [Computed value](computed_value) | as [`<length>`](length) | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` padding-inline-start = <'padding-top'> ``` Examples -------- ### Setting inline start padding for vertical text #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; padding-inline-start: 20px; background-color: #c8c800; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # padding-properties](https://w3c.github.io/csswg-drafts/css-logical/#padding-properties) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `padding-inline-start` | 87 2 | 87 79 | 41 3 | No | 73 15 | 12.1 3 | 87 2 | 87 18 | 41 4 | 62 14 | 12.2 3 | 14.0 1.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * The mapped physical properties: [`padding-top`](padding-top), [`padding-right`](padding-right), [`padding-bottom`](padding-bottom), and [`padding-left`](padding-left) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css <time> <time> ====== The `<time>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) represents a time value expressed in seconds or milliseconds. It is used in [`animation`](animation), [`transition`](transition), and related properties. Syntax ------ The `<time>` data type consists of a [`<number>`](number) followed by one of the units listed below. Optionally, it may be preceded by a single `+` or `-` sign. As with all dimensions, there is no space between the unit literal and the number. **Note:** Although the number `0` is always the same regardless of unit, the unit may not be omitted. In other words, `0` is invalid and does not represent `0s` or `0ms`. ### Units `s` Represents a time in seconds. Examples: `0s`, `1.5s`, `-60s`. `ms` Represents a time in milliseconds. Examples: `0ms`, `150.25ms`, `-60000ms`. **Note:** Conversion between `s` and `ms` follows the logical `1s` = `1000ms`. Examples -------- ### Valid times ``` 12s Positive integer -456ms Negative integer 4.3ms Non-integer 14mS The unit is case-insensitive, although capital letters are not recommended. +0s Zero with a leading + and a unit -0ms Zero with a leading - and a unit ``` ### Invalid times ``` 0 Although unitless zero is allowed for <length>s, it's invalid for <time>s. 12.0 This is a <number>, not a <time>, because it's missing a unit. 7 ms No space is allowed between the number and the unit. ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # time](https://w3c.github.io/csswg-drafts/css-values/#time) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `time` | 1 | 12 | 4 | 9 | 10.1 | 3.1 | 2 | 18 | 4 | 10.1 | 2 | 1.0 | See also -------- * [`<time-percentage>`](time-percentage) * [CSS Values and Units](css_values_and_units) css text-combine-upright text-combine-upright ==================== The `text-combine-upright` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the combination of characters into the space of a single character. If the combined text is wider than 1em, the user agent must fit the contents within 1em. The resulting composition is treated as a single upright glyph for layout and decoration. This property only has an effect in vertical writing modes. This is used to produce an effect that is known as tate-chū-yoko 縦中横 in Japanese, or as 橫向文字 in Chinese. Try it ------ Syntax ------ ``` /\* Keyword values \*/ text-combine-upright: none; text-combine-upright: all; /\* Digits values \*/ text-combine-upright: digits; /\* fits 2 consecutive digits horizontally inside vertical text \*/ text-combine-upright: digits 4; /\* fits up to 4 consecutive digits horizontally inside vertical text \*/ /\* Global values \*/ text-combine-upright: inherit; text-combine-upright: initial; text-combine-upright: revert; text-combine-upright: revert-layer; text-combine-upright: unset; ``` ### Values `none` There is no special processing. `all` Attempts to typeset all consecutive characters within the box horizontally, such that they take up the space of a single character within the vertical line of the box. `digits <integer>?` Attempts to display a sequence of consecutive ASCII digits (U+0030–U+0039) that has as many or fewer characters than the specified integer, such that it takes up the space of a single character within the vertical line box. If the integer is omitted, it computes to 2. Integers outside the range of 2-4 are invalid. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | non-replaced inline elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | specified keyword, plus integer if 'digits' | | Animation type | Not animatable | Formal syntax ------------- ``` text-combine-upright = none [|](value_definition_syntax#single_bar) all [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) digits [<integer [2,4]>](integer)[?](value_definition_syntax#question_mark) []](value_definition_syntax#brackets) ``` Examples -------- ### Example using "digits" The digits value requires less markup than the all value when digits are being combined, but it is currently not very widely supported by browsers. #### HTML ``` <p lang="ja" class="exampleText">平成20年4月16日に</p> ``` #### CSS ``` .exampleText { writing-mode: vertical-lr; text-combine-upright: digits 2; font: 36px serif; } ``` #### Results | Screenshot | Live sample | | --- | --- | | | | ### Example using "all" The all value requires markup around every piece of horizontal text, but it is currently supported by more browsers than the digits value. #### HTML ``` <p lang="zh-Hant"> 民國<span class="num">105</span>年<span class="num">4</span>月<span class="num" >29</span >日 </p> ``` #### CSS ``` html { writing-mode: vertical-rl; font: 24px serif; } .num { text-combine-upright: all; } ``` #### Results | Screenshot | Live sample | | --- | --- | | | | Specifications -------------- | Specification | | --- | | [CSS Writing Modes Level 4 # text-combine-upright](https://w3c.github.io/csswg-drafts/css-writing-modes/#text-combine-upright) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `text-combine-upright` | 48 9 This property was initially named `-webkit-text-combine` according to a [2011 version of the CSS3 Writing Modes specification](https://www.w3.org/TR/2011/WD-css3-writing-modes-20110531/#text-combine), supporting the values `none` and `horizontal` without `digits`. | 15-79 12-79 | 48 Before version 81, Firefox implemented the property as animatable. This was corrected to spec in 81. | 11 | 35 15 This property was initially named `-webkit-text-combine` according to a [2011 version of the CSS3 Writing Modes specification](https://www.w3.org/TR/2011/WD-css3-writing-modes-20110531/#text-combine), supporting the values `none` and `horizontal` without `digits`. | 5.1 This property was initially named `-webkit-text-combine` according to a [2011 version of the CSS3 Writing Modes specification](https://www.w3.org/TR/2011/WD-css3-writing-modes-20110531/#text-combine), supporting the values `none` and `horizontal` without `digits`. preview | 48 ≤37 This property was initially named `-webkit-text-combine` according to a [2011 version of the CSS3 Writing Modes specification](https://www.w3.org/TR/2011/WD-css3-writing-modes-20110531/#text-combine), supporting the values `none` and `horizontal` without `digits`. | 48 18 This property was initially named `-webkit-text-combine` according to a [2011 version of the CSS3 Writing Modes specification](https://www.w3.org/TR/2011/WD-css3-writing-modes-20110531/#text-combine), supporting the values `none` and `horizontal` without `digits`. | 48 Before version 81, Firefox implemented the property as animatable. This was corrected to spec in 81. | 35 14 This property was initially named `-webkit-text-combine` according to a [2011 version of the CSS3 Writing Modes specification](https://www.w3.org/TR/2011/WD-css3-writing-modes-20110531/#text-combine), supporting the values `none` and `horizontal` without `digits`. | 15.4 5 This property was initially named `-webkit-text-combine` according to a [2011 version of the CSS3 Writing Modes specification](https://www.w3.org/TR/2011/WD-css3-writing-modes-20110531/#text-combine), supporting the values `none` and `horizontal` without `digits`. | 5.0 1.0 This property was initially named `-webkit-text-combine` according to a [2011 version of the CSS3 Writing Modes specification](https://www.w3.org/TR/2011/WD-css3-writing-modes-20110531/#text-combine), supporting the values `none` and `horizontal` without `digits`. | | `digits` | No | 15-79 12-79 | No | 11 | No | No | No | No | No | No | No | No | See also -------- * [`writing-mode`](writing-mode), [`text-orientation`](text-orientation)
programming_docs
css <display-outside> <display-outside> ================= The `<display-outside>` keywords specify the element's outer [`display`](display) type, which is essentially its role in flow layout. These keywords are used as values of the `display` property, and can be used for legacy purposes as a single keyword, or as defined in the Level 3 specification alongside a value from the [`<display-inside>`](display-inside) keywords. Syntax ------ Valid `<display-outside>` values: `block` The element generates a block element box, generating line breaks both before and after the element when in the normal flow. `inline` The element generates one or more inline element boxes that do not generate line breaks before or after themselves. In normal flow, the next element will be on the same line if there is space. **Note:** Browsers that support the two value syntax, on finding the outer value only, such as when `display: block` or `display: inline` is specified, will set the inner value to `flow`. This will result in expected behavior; for example if you specify an element to be block, you would expect that the children of that element would participate in block and inline normal flow layout. Formal syntax ------------- ``` <display-outside> = block [|](value_definition_syntax#single_bar) inline [|](value_definition_syntax#single_bar) run-in ``` Examples -------- In the following example, span elements (normally displayed as inline elements) are set to `display: block` and so break onto new lines and expand to fill their container in the inline dimension. ### HTML ``` <span>span 1</span> <span>span 2</span> ``` ### CSS ``` span { display: block; border: 1px solid rebeccapurple; } ``` ### Result Specifications -------------- | Specification | | --- | | [CSS Display Module Level 3 # typedef-display-outside](https://w3c.github.io/csswg-drafts/css-display/#typedef-display-outside) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `display-outside` | 1 | 12 | 1 | 4 | 7 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | See also -------- * [`display`](display) + [`<display-inside>`](display-inside) + [`<display-listitem>`](display-listitem) + [`<display-internal>`](display-internal) + [`<display-box>`](display-box) + [`<display-legacy>`](display-legacy) * [Block and Inline layout in Normal Flow](css_flow_layout/block_and_inline_layout_in_normal_flow) * [Formatting Contexts explained](css_flow_layout/intro_to_formatting_contexts) css overflow-clip-margin overflow-clip-margin ==================== The `overflow-clip-margin` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property determines how far outside its bounds an element with [`overflow: clip`](overflow) may be painted before being clipped. Syntax ------ ``` overflow-clip-margin: 20px; overflow-clip-margin: 1em; /\* Global values \*/ overflow-clip-margin: inherit; overflow-clip-margin: initial; overflow-clip-margin: revert; overflow-clip-margin: revert-layer; overflow-clip-margin: unset; ``` The `overflow-clip-margin` property is specified as a length, negative values are not allowed. **Note:** If the element does not have `overflow: clip` then this property will be ignored. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0px` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | the computed | | Animation type | discrete | Formal syntax ------------- ``` overflow-clip-margin = <visual-box> [||](value_definition_syntax#double_bar) [<length [0,∞]>](length) <visual-box> = content-box [|](value_definition_syntax#single_bar) padding-box [|](value_definition_syntax#single_bar) border-box ``` Examples -------- ### 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 ``` .box { border: 3px solid black; width: 250px; height: 100px; overflow: clip; overflow-clip-margin: 20px; } ``` ### Result Specifications -------------- | Specification | | --- | | [CSS Overflow Module Level 3 # overflow-clip-margin](https://w3c.github.io/csswg-drafts/css-overflow/#overflow-clip-margin) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `overflow-clip-margin` | 90 Only works when both axes are using `overflow: clip`. See [bug 1354474](https://crbug.com/1354474). | 90 Only works when both axes are using `overflow: clip`. See [bug 1354474](https://crbug.com/1354474). | 102 Only supports using a length, not a visual box. See [bug 1661582](https://bugzil.la/1661582). | No | 76 Only works when both axes are using `overflow: clip`. See [bug 1354474](https://crbug.com/1354474). | No | 90 Only works when both axes are using `overflow: clip`. See [bug 1354474](https://crbug.com/1354474). | 90 Only works when both axes are using `overflow: clip`. See [bug 1354474](https://crbug.com/1354474). | 102 Only supports using a length, not a visual box. See [bug 1661582](https://bugzil.la/1661582). | 64 Only works when both axes are using `overflow: clip`. See [bug 1354474](https://crbug.com/1354474). | No | 15.0 Only works when both axes are using `overflow: clip`. See [bug 1354474](https://crbug.com/1354474). | See also -------- * Related CSS properties: [`text-overflow`](text-overflow), [`white-space`](white-space), [`overflow`](overflow), [`overflow-inline`](overflow-inline), [`overflow-x`](overflow-x), [`overflow-y`](overflow-y), [`clip`](clip), [`display`](display) css column-gap column-gap ========== The `column-gap` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the size of the gap ([gutter](https://developer.mozilla.org/en-US/docs/Glossary/Gutters)) between an element's columns. Try it ------ Initially a part of [Multi-column Layout](css_columns), the definition of `column-gap` has been broadened to include multiple layout methods. Now specified in [Box Alignment](css_box_alignment), it may be used in Multi-column, Flexible Box, and Grid layouts. Note that `grid-column-gap` is an alias for this property. Syntax ------ ``` /\* Keyword value \*/ column-gap: normal; /\* <length> values \*/ column-gap: 3px; column-gap: 2.5em; /\* <percentage> value \*/ column-gap: 3%; /\* Global values \*/ column-gap: inherit; column-gap: initial; column-gap: revert; column-gap: revert-layer; column-gap: unset; ``` The `column-gap` property is specified as one of the values listed below. ### Values `normal` The browser's default spacing is used between columns. For multi-column layout this is specified as `1em`. For all other layout types it is 0. [`<length>`](length) The size of the gap between columns, defined as a [`<length>`](length). The [`<length>`](length) property's value must be non-negative. [`<percentage>`](percentage) The size of the gap between columns, defined as a [`<percentage>`](percentage). The [`<percentage>`](percentage) property's value must be non-negative. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | multi-column elements, flex containers, grid containers | | [Inherited](inheritance) | no | | Percentages | refer to corresponding dimension of the content area | | [Computed value](computed_value) | as specified, with <length>s made absolute, and normal computing to zero except on multi-column elements | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` column-gap = normal [|](value_definition_syntax#single_bar) [<length-percentage [0,∞]>](length-percentage) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Flex layout #### HTML ``` <div id="flexbox"> <div></div> <div></div> <div></div> </div> ``` #### CSS ``` #flexbox { display: flex; height: 100px; column-gap: 20px; } #flexbox > div { border: 1px solid green; background-color: lime; flex: auto; } ``` #### Result ### Grid layout #### HTML ``` <div id="grid"> <div></div> <div></div> <div></div> </div> ``` #### CSS ``` #grid { display: grid; height: 100px; grid-template-columns: repeat(3, 1fr); grid-template-rows: 100px; column-gap: 20px; } #grid > div { border: 1px solid green; background-color: lime; } ``` #### Result ### Multi-column layout #### HTML ``` <p class="content-box"> This is some multi-column text with a 40px column gap created with the CSS `column-gap` property. Don't you think that's fun and exciting? I sure do! </p> ``` #### CSS ``` .content-box { column-count: 3; column-gap: 40px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Box Alignment Module Level 3 # column-row-gap](https://w3c.github.io/csswg-drafts/css-align/#column-row-gap) | | [CSS Grid Layout Module Level 2 # gutters](https://w3c.github.io/csswg-drafts/css-grid/#gutters) | | [CSS Multi-column Layout Module Level 1 # column-gap](https://w3c.github.io/csswg-drafts/css-multicol/#column-gap) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `column-gap` | 1 | 12 | 1.5 | 10 | 11.1 | 3 | 4.4 | 18 | 4 | 11.1 | 2 | 1.0 | | `flex_context` | 84 | 84 | 63 | No | 70 | 14.1 | 84 | 84 | 63 | 60 | 14.5 | 14.0 | | `grid_context` | 66 57 | 16 16 | 61 52 | No | 53 44 | 12 10.1 | 66 57 | 66 57 | 61 52 | 47 43 | 12 10.3 | 9.0 6.0 | | `multicol_context` | 50 1 | 12 12 | 52 1.5-74 Before Firefox 3, the default value for the `normal` keyword was `0` and not `1em`. | 10 | 37 15 11.1-15 | 10 3 | 50 ≤37 | 50 18 | 52 4 | 37 14 11.1-14 | 10 3 | 5.0 1.0 | See also -------- * Related CSS properties: [`row-gap`](row-gap), [`gap`](gap) * Grid Layout Guide: *[Basic concepts of grid layout - Gutters](css_grid_layout/basic_concepts_of_grid_layout#gutters)* * Multi-column Layout Guide: *[Styling Columns](css_columns/styling_columns)* css :dir() :dir() ====== The `:dir()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) matches elements based on the directionality of the text contained in them. ``` /\* Selects any element with right-to-left text \*/ :dir(rtl) { background-color: red; } ``` The `:dir()` pseudo-class uses only the *semantic* value of the directionality, i.e., the one defined in the document itself. It doesn't account for *styling* directionality, i.e., the directionality set by CSS properties such as [`direction`](direction). **Note:** Be aware that the behavior of the `:dir()` pseudo-class is not equivalent to the `[dir=…]` [attribute selectors](attribute_selectors). The latter match the HTML [`dir`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#dir) attribute, and ignore elements that lack it — even if they inherit a direction from their parent. (Similarly, `[dir=rtl]` and `[dir=ltr]` won't match the `auto` value.) In contrast, `:dir()` will match the value calculated by the [user agent](https://developer.mozilla.org/en-US/docs/Glossary/User_agent), even if inherited. **Note:** In HTML, the direction is determined by the [`dir`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#dir) attribute. Other document types may have different methods. Syntax ------ The `:dir()` pseudo-class requires one parameter, representing the text directionality you want to target. ``` :dir( [ ltr | rtl ] ) ``` ### Parameters `ltr` Target left-to-right elements. `rtl` Target right-to-left elements. Examples -------- ### HTML ``` <div dir="rtl"> <span>test1</span> <div dir="ltr"> test2 <div dir="auto">עִבְרִית</div> </div> </div> ``` ### CSS ``` :dir(ltr) { background-color: yellow; } :dir(rtl) { background-color: powderblue; } ``` ### Result Specifications -------------- | Specification | | --- | | [HTML Standard # selector-ltr](https://html.spec.whatwg.org/multipage/semantics-other.html#selector-ltr) | | [Selectors Level 4 # the-dir-pseudo](https://w3c.github.io/csswg-drafts/selectors/#the-dir-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:dir` | No | No | 49 17-53 | No | No | No | No | No | 49 17-53 | No | No | No | See also -------- * Language-related pseudo-classes: [`:lang`](:lang), [`:dir`](:dir) * HTML [`lang`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#lang) attribute * HTML [`translate`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#translate) attribute css Replaced elements Replaced elements ================= In [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS), a **replaced element** is an element whose representation is outside the scope of CSS; they're external objects whose representation is independent of the CSS formatting model. Put in simpler terms, they're elements whose contents are not affected by the current document's styles. The position of the replaced element can be affected using CSS, but not the contents of the replaced element itself. Some replaced elements, such as [`<iframe>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe) elements, may have stylesheets of their own, but they don't inherit the styles of the parent document. The only other impact CSS can have on a replaced element is that there are properties which support controlling the positioning of the element's content within its box. See [Controlling object position within the content box](#controlling_object_position_within_the_content_box) for further information. Replaced elements ----------------- Typical replaced elements are: * [`<iframe>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe) * [`<video>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video) * [`<embed>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed) * [`<img>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img) Some elements are treated as replaced elements only in specific cases: * [`<option>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option) * [`<audio>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio) * [`<canvas>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas) * [`<object>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object) * [`<applet>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/applet) HTML spec also says that an [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) element can be replaced, because [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) elements of the `"image"` type are replaced elements similar to [`<img>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img). However, other form controls, including other types of [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) elements, are explicitly listed as non-replaced elements (the spec describes their default platform-specific rendering with the term "Widgets"). Objects inserted using the CSS [`content`](content) property are *anonymous replaced elements*. They are "anonymous" because they don't exist in the HTML markup. Using CSS with replaced elements -------------------------------- CSS handles replaced elements specifically in some cases, like when calculating margins and some `auto` values. Note that some replaced elements, but not all, have intrinsic dimensions or a defined baseline, which is used by some CSS properties, such as [`vertical-align`](vertical-align). Only replaced elements can ever have intrinsic dimensions. ### Controlling object position within the content box Certain CSS properties can be used to specify how the object contained within the replaced element should be positioned within the element's box area. These are defined by the [CSS Images](https://drafts.csswg.org/css-images/) specification: [`object-fit`](object-fit) Specifies how the replaced element's content object should be fitted to the containing element's box. [`object-position`](object-position) Specifies the alignment of the replaced element's content object within the element's box. See also -------- * [HTML Spec](https://html.spec.whatwg.org/multipage/rendering.html#replaced-elements) * [Void elements](https://developer.mozilla.org/en-US/docs/Glossary/Void_element) * CSS key concepts: + [CSS syntax](syntax) + [At-rules](at-rule) + [Comments](comments) + [Specificity](specificity) + [Inheritance](inheritance) + [Box model](css_box_model/introduction_to_the_css_box_model) + [Layout modes](layout_mode) + [Visual formatting models](visual_formatting_model) + [Margin collapsing](css_box_model/mastering_margin_collapsing) + Values - [Initial values](initial_value) - [Computed values](computed_value) - [Used values](used_value) - [Actual values](actual_value) + [Value definition syntax](value_definition_syntax) + [Shorthand properties](shorthand_properties) css :empty :empty ====== The `:empty` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) represents any element that has no children. Children can be either element nodes or text (including whitespace). Comments, processing instructions, and CSS [`content`](content) do not affect whether an element is considered empty. Try it ------ **Note:** In [Selectors Level 4](https://drafts.csswg.org/selectors-4/#the-empty-pseudo), the `:empty` pseudo-class was changed to act like [`:-moz-only-whitespace`](:-moz-only-whitespace), but no browser currently supports this yet. Syntax ------ ``` :empty ``` Examples -------- ### HTML ``` <div class="box"><!-- I will be lime. --></div> <div class="box">I will be pink.</div> <div class="box"> <!-- I will be pink in older browsers because of the whitespace around this comment. --> </div> <div class="box"> <p> <!-- I will be pink in all browsers because of the non-collapsible whitespace and elements around this comment. --> </p> </div> ``` ### CSS ``` .box { background: pink; height: 80px; width: 80px; } .box:empty { background: lime; } ``` ### Result Accessibility concerns ---------------------- Assistive technology such as screen readers cannot parse interactive content that is empty. All interactive content must have an accessible name, which is created by providing a text value for the interactive control's parent element ([anchors](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a), [buttons](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button), etc.). Accessible names expose the interactive control to the [accessibility tree](https://developer.mozilla.org/en-US/docs/Learn/Accessibility/What_is_accessibility#accessibility_apis), an API that communicates information useful for assistive technologies. The text that provides the interactive control's accessible name can be hidden using [a combination of properties](https://gomakethings.com/hidden-content-for-better-a11y/#hiding-the-link) that remove it visually from the screen but keep it parsable by assistive technology. This is commonly used for buttons that rely solely on an icon to convey purpose. * [What is an accessible name? | The Paciello Group](https://www.tpgi.com/what-is-an-accessible-name/) * [Hidden content for better a11y | Go Make Things](https://gomakethings.com/hidden-content-for-better-a11y/) * [MDN Understanding WCAG, Guideline 2.4 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Operable#guideline_2.4_%e2%80%94_navigable_provide_ways_to_help_users_navigate_find_content_and_determine_where_they_are) * [Understanding Success Criterion 2.4.4 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/navigation-mechanisms-refs.html) Specifications -------------- | Specification | | --- | | [Selectors Level 4 # the-empty-pseudo](https://w3c.github.io/csswg-drafts/selectors/#the-empty-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:empty` | 1 | 12 | 1 | 9 | 9.5 | 3.1 | 2 | 18 | 4 | 10.1 | 2 | 1.0 | | `matches_whitespace` | No | No | No See [bug 1106296](https://bugzil.la/1106296). | No | No | No | No | No | No See [bug 1106296](https://bugzil.la/1106296). | No | No | No | See also -------- * [`:-moz-only-whitespace`](:-moz-only-whitespace) Non-standard – The [prefixed](https://developer.mozilla.org/en-US/docs/Glossary/Vendor_Prefix) implementation of the changes in [Selectors Level 4](https://drafts.csswg.org/selectors-4/#the-empty-pseudo) * [`:blank`](:blank) Experimental
programming_docs
css widows widows ====== The `widows` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the minimum number of lines in a block container that must be shown at the *top* of a [page](https://developer.mozilla.org/en-US/docs/Web/CSS/Paged_Media), region, or [column](css_columns). ``` /\* <integer> values \*/ widows: 2; widows: 3; /\* Global values \*/ widows: inherit; widows: initial; widows: revert; widows: revert-layer; widows: unset; ``` In typography, a *widow* is the last line of a paragraph that appears alone at the top of a page. (The paragraph is continued from a prior page.) Syntax ------ ### Values [`<integer>`](integer) The minimum number of lines that can stay by themselves at the top of a new fragment after a fragmentation break. The value must be positive. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `2` | | Applies to | block container elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` widows = [<integer [0,∞]>](integer) ``` Examples -------- ### Controlling column widows #### HTML ``` <div> <p>This is the first paragraph containing some text.</p> <p> This is the second paragraph containing some more text than the first one. It is used to demonstrate how widows work. </p> <p> This is the third paragraph. It has a little bit more text than the first one. </p> </div> ``` #### CSS ``` div { background-color: #8cffa0; columns: 3; widows: 2; } p { background-color: #8ca0ff; } p:first-child { margin-top: 0; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Fragmentation Module Level 3 # widows-orphans](https://w3c.github.io/csswg-drafts/css-break/#widows-orphans) | | [CSS Multi-column Layout Module Level 1 # filling-columns](https://w3c.github.io/csswg-drafts/css-multicol/#filling-columns) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `widows` | 25 | 12 | No | 8 | 9.2 | 1.3 | 4.4 | 25 | No | 14 | 1 | 1.5 | See also -------- * [`orphans`](orphans) * [Paged media](https://developer.mozilla.org/en-US/docs/Web/CSS/Paged_Media) css mask-repeat mask-repeat =========== The `mask-repeat` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets how mask images are repeated. A mask image can be repeated along the horizontal axis, the vertical axis, both axes, or not repeated at all. ``` /\* One-value syntax \*/ mask-repeat: repeat-x; mask-repeat: repeat-y; mask-repeat: repeat; mask-repeat: space; mask-repeat: round; mask-repeat: no-repeat; /\* Two-value syntax: horizontal | vertical \*/ mask-repeat: repeat space; mask-repeat: repeat repeat; mask-repeat: round space; mask-repeat: no-repeat round; /\* Multiple values \*/ mask-repeat: space round, no-repeat; mask-repeat: round repeat, space, repeat-x; /\* Global values \*/ mask-repeat: inherit; mask-repeat: initial; mask-repeat: revert; mask-repeat: revert-layer; mask-repeat: unset; ``` By default, the repeated images are clipped to the size of the element, but they can be scaled to fit (using `round`) or evenly distributed from end to end (using `space`). Syntax ------ One or more `<repeat-style>` values, separated by commas. ### Values `<repeat-style>` The one-value syntax is a shorthand for the full two-value syntax: | Single value | Two-value equivalent | | --- | --- | | `repeat-x` | `repeat no-repeat` | | `repeat-y` | `no-repeat repeat` | | `repeat` | `repeat repeat` | | `space` | `space space` | | `round` | `round round` | | `no-repeat` | `no-repeat no-repeat` | In the two-value syntax, the first value represents the horizontal repetition behavior and the second value represents the vertical behavior. Here is an explanation of how each option works for either direction: | | | | --- | --- | | `repeat` | The image is repeated as much as needed to cover the whole mask painting area. The last image will be clipped if it doesn't fit. | | `space` | The image is repeated as much as possible without clipping. The first and last images are pinned to either side of the element, and whitespace is distributed evenly between the images. The [`mask-position`](mask-position) property is ignored unless only one image can be displayed without clipping. The only case where clipping happens using `space` is when there isn't enough room to display one image. | | `round` | As the allowed space increases in size, the repeated images will stretch (leaving no gaps) until there is room for another one to be added. When the next image is added, all of the current ones compress to allow room. Example: An image with an original width of 260px, repeated three times, might stretch until each repetition is 300px wide, and then another image will be added. They will then compress to 225px. | | `no-repeat` | The image is not repeated (and hence the mask painting area will not necessarily be entirely covered). The position of the non-repeated mask image is defined by the [`mask-position`](mask-position) CSS property. | Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `repeat` | | Applies to | all elements; In SVG, it applies to container elements excluding the [`<defs>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs) element and all graphics elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | Consists of two keywords, one per dimension | | Animation type | discrete | Formal syntax ------------- ``` mask-repeat = <repeat-style>[#](value_definition_syntax#hash_mark) <repeat-style> = repeat-x [|](value_definition_syntax#single_bar) repeat-y [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) repeat [|](value_definition_syntax#single_bar) space [|](value_definition_syntax#single_bar) round [|](value_definition_syntax#single_bar) no-repeat []](value_definition_syntax#brackets)[{1,2}](value_definition_syntax#curly_braces) ``` Examples -------- ### Setting repeat for a single mask ### Multiple mask image support You can specify a different `<repeat-style>` for each mask image, separated by commas: ``` .examplethree { mask-image: url("mask1.png"), url("mask2.png"); mask-repeat: repeat-x, repeat-y; } ``` Each image is matched with the corresponding repeat style, from first specified to last. Specifications -------------- | Specification | | --- | | [CSS Masking Module Level 1 # the-mask-repeat](https://drafts.fxtf.org/css-masking/#the-mask-repeat) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `mask-repeat` | 1 | 79 18-79 | 53 | No | 15 | 15.4 3.1 | 2 | 18 | 53 | 14 | 15.4 2 | 1.0 | See also -------- * [Clipping and Masking in CSS](https://css-tricks.com/clipping-masking-css/) css font-feature-settings font-feature-settings ===================== The `font-feature-settings` CSS property controls advanced typographic features in OpenType fonts. Try it ------ Syntax ------ ``` /\* Use the default settings \*/ font-feature-settings: normal; /\* Set values for OpenType feature tags \*/ font-feature-settings: "smcp"; font-feature-settings: "smcp" on; font-feature-settings: "swsh" 2; font-feature-settings: "smcp", "swsh" 2; /\* Global values \*/ font-feature-settings: inherit; font-feature-settings: initial; font-feature-settings: revert; font-feature-settings: revert-layer; font-feature-settings: unset; ``` Whenever possible, Web authors should instead use the [`font-variant`](font-variant) shorthand property or an associated longhand property such as [`font-variant-ligatures`](font-variant-ligatures), [`font-variant-caps`](font-variant-caps), [`font-variant-east-asian`](font-variant-east-asian), [`font-variant-alternates`](font-variant-alternates), [`font-variant-numeric`](font-variant-numeric) or [`font-variant-position`](font-variant-position). These lead to more effective, predictable, understandable results than `font-feature-settings`, which is a low-level feature designed to handle special cases where no other way exists to enable or access an OpenType font feature. In particular, `font-feature-settings` shouldn't be used to enable small caps. ### Values `normal` Text is laid out using default settings. `<feature-tag-value>` When rendering text, the list of OpenType feature tag value is passed to the text layout engine to enable or disable font features. The tag is always a [`<string>`](string) of 4 ASCII characters. If it has more or less characters, or if it contains characters outside the `U+20` – `U+7E` codepoint range, the whole property is invalid. The value is a positive integer. The two keywords `on` and `off` are synonyms for `1` and `0` respectively. If no value is set, the default is `1`. For non-Boolean OpenType features (e.g. [stylistic alternates](https://docs.microsoft.com/typography/opentype/spec/features_pt)), the value implies a particular glyph to be selected; for Boolean values, it is a switch. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` font-feature-settings = normal [|](value_definition_syntax#single_bar) <feature-tag-value>[#](value_definition_syntax#hash_mark) <feature-tag-value> = [<string>](string) [[](value_definition_syntax#brackets) [<integer>](integer) [|](value_definition_syntax#single_bar) on [|](value_definition_syntax#single_bar) off []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ``` Examples -------- ### Enabling various font features ``` /\* use small-cap alternate glyphs \*/ .smallcaps { font-feature-settings: "smcp" on; } /\* convert both upper and lowercase to small caps (affects punctuation also) \*/ .allsmallcaps { font-feature-settings: "c2sc", "smcp"; } /\* use zeros with a slash through them to differentiate from "O" \*/ .nicezero { font-feature-settings: "zero"; } /\* enable historical forms \*/ .hist { font-feature-settings: "hist"; } /\* disable common ligatures, usually on by default \*/ .noligs { font-feature-settings: "liga" 0; } /\* enable tabular (monospaced) figures \*/ td.tabular { font-feature-settings: "tnum"; } /\* enable automatic fractions \*/ .fractions { font-feature-settings: "frac"; } /\* use the second available swash character \*/ .swash { font-feature-settings: "swsh" 2; } /\* enable stylistic set 7 \*/ .fancystyle { font-family: Gabriola; font-feature-settings: "ss07"; } ``` Specifications -------------- | Specification | | --- | | [CSS Fonts Module Level 4 # font-feature-settings-prop](https://w3c.github.io/csswg-drafts/css-fonts/#font-feature-settings-prop) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `font-feature-settings` | 48 16 | 15 | 34 The [ISO/IEC CD 14496-22 3rd edition](https://mpeg.chiariglione.org/standards/mpeg-4/open-font-format/text-isoiec-cd-14496-22-3rd-edition) suggests using the `ssty` feature to provide glyph variants more suitable for use in scripts (for example primes used as superscripts). Starting with Firefox 29, this is done automatically by the [MathML](https://developer.mozilla.org/docs/Web/MathML) rendering engine. The ISO/IEC CD 14496-22 3rd edition also suggests applying the `dtls` feature to letters when placing mathematical accents to get dotless forms (for example dotless i, j with a hat). Starting with Firefox 35, this is done automatically by the MathML rendering engine. You can override the default values determined by the MathML rendering engine with CSS. 15 From Firefox 4 to Firefox 14 (inclusive), Firefox supported an older, slightly different syntax. See [OpenType Font Feature support in Firefox 4](https://hacks.mozilla.org/2010/11/firefox-4-font-feature-support/). | 10 | 35 15 | 9.1 | 4.4 | 48 | 34 The [ISO/IEC CD 14496-22 3rd edition](https://mpeg.chiariglione.org/standards/mpeg-4/open-font-format/text-isoiec-cd-14496-22-3rd-edition) suggests using the `ssty` feature to provide glyph variants more suitable for use in scripts (for example primes used as superscripts). Starting with Firefox 29, this is done automatically by the [MathML](https://developer.mozilla.org/docs/Web/MathML) rendering engine. The ISO/IEC CD 14496-22 3rd edition also suggests applying the `dtls` feature to letters when placing mathematical accents to get dotless forms (for example dotless i, j with a hat). Starting with Firefox 35, this is done automatically by the MathML rendering engine. You can override the default values determined by the MathML rendering engine with CSS. 15 From Firefox 4 to Firefox 14 (inclusive), Firefox supported an older, slightly different syntax. See [OpenType Font Feature support in Firefox 4](https://hacks.mozilla.org/2010/11/firefox-4-font-feature-support/). | 35 14 | 9.3 | 5.0 | See also -------- * [`font-display`](@font-face/font-display) * [`font-family`](@font-face/font-family) * [`font-stretch`](@font-face/font-stretch) * [`font-style`](@font-face/font-style) * [`font-weight`](@font-face/font-weight) * [`font-variant`](@font-face) * [`font-variation-settings`](@font-face/font-variation-settings) * [`src`](@font-face/src) * [`unicode-range`](@font-face/unicode-range) * [OpenType Feature Tags](https://docs.microsoft.com/typography/opentype/spec/featurelist) list css max-height max-height ========== The `max-height` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the maximum height of an element. It prevents the [used value](used_value) of the [`height`](height) property from becoming larger than the value specified for `max-height`. Try it ------ `max-height` overrides [`height`](height), but [`min-height`](min-height) overrides `max-height`. Syntax ------ ``` /\* <length> value \*/ max-height: 3.5em; /\* <percentage> value \*/ max-height: 75%; /\* Keyword values \*/ max-height: none; max-height: max-content; max-height: min-content; max-height: fit-content(20em); /\* Global values \*/ max-height: inherit; max-height: initial; max-height: revert; max-height: revert-layer; max-height: unset; ``` ### Values [`<length>`](length) Defines the `max-height` as an absolute value. [`<percentage>`](percentage) Defines the `max-height` as a percentage of the containing block's height. `none` No limit on the size of the box. `max-content` The intrinsic preferred `max-height`. `min-content` The intrinsic minimum `max-height`. `fit-content([`<length-percentage>`](length-percentage))` Uses the `fit-content` formula with the available space replaced by the specified argument, i.e. `min(max-content, max(min-content, argument))`. Accessibility concerns ---------------------- Ensure that elements set with a `max-height` are not truncated and/or do not obscure other content when the page is zoomed to increase text size. * [MDN Understanding WCAG, Guideline 1.4 explanations](https://developer.mozilla.org/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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements but non-replaced inline elements, table columns, and column groups | | [Inherited](inheritance) | no | | Percentages | The percentage is calculated with respect to the height of the generated box's containing block. If the height of the containing block is not specified explicitly (i.e., it depends on content height), and this element is not absolutely positioned, the percentage value is treated as `none`. | | [Computed value](computed_value) | the percentage as specified or the absolute length or `none` | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` max-height = none [|](value_definition_syntax#single_bar) [<length-percentage [0,∞]>](length-percentage) [|](value_definition_syntax#single_bar) min-content [|](value_definition_syntax#single_bar) max-content [|](value_definition_syntax#single_bar) fit-content( [<length-percentage [0,∞]>](length-percentage) ) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Setting max-height using percentage and keyword values ``` table { max-height: 75%; } form { max-height: none; } ``` Specifications -------------- | Specification | | --- | | [CSS Box Sizing Module Level 4 # width-height-keywords](https://w3c.github.io/csswg-drafts/css-sizing-4/#width-height-keywords) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `max-height` | 18 | 12 | 1 CSS 2.1 leaves the behavior of `max-height` with [`table`](https://developer.mozilla.org/docs/Web/HTML/Element/table) undefined. Firefox supports applying `max-height` to `table` elements. | 7 | 7 CSS 2.1 leaves the behavior of `max-height` with [`table`](https://developer.mozilla.org/docs/Web/HTML/Element/table) undefined. Opera supports applying `max-height` to `table` elements. | 1.3 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | | `fit-content` | 46 25 | 79 79 | 3 Firefox implements the definitions given in CSS3 Basic Box. This defines `available` and not `fit-available`. Also, the definition of `fit-content` is simpler than in CSS3 Sizing. | No | 44 | 11 7 2 | 46 4.4 | 46 25 | 4 Firefox implements the definitions given in CSS3 Basic Box. This defines `available` and not `fit-available`. Also, the definition of `fit-content` is simpler than in CSS3 Sizing. | 43 | 11 7 1 | 5.0 1.5 | | `fit-content_function` | No | No | 91 | No | No | No | No | No | No | No | No | No | | `max-content` | 46 | 79 | 66 3 | No | 44 | 11 9 | 46 | 46 | 66 4 | 43 | 11 9 | 5.0 | | `min-content` | 46 | 79 | 66 3 | No | 44 | 11 9 | 46 | 46 | 66 4 | 43 | 11 9 | 5.0 | | `stretch` | 28 | 79 | No | No | 15 | No | 4.4 | 28 | No | 15 | No | 1.5 | See also -------- * [The box model](css_box_model/introduction_to_the_css_box_model), [`box-sizing`](box-sizing) * [`height`](height), [`min-height`](min-height) * The mapped logical properties: [`max-inline-size`](max-inline-size), [`max-block-size`](max-block-size) css <hex-color> <hex-color> =========== The `<hex-color>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) is a notation for describing the *hexadecimal color syntax* of an [sRGB](https://developer.mozilla.org/en-US/docs/Glossary/RGB) color using its primary color components (red, green, blue) written as hexadecimal numbers, as well as its transparency. It can be used everywhere a [`<color>`](color_value) type is allowed. A `<hex-color>` value can be used everywhere where a [`<color>`](color_value) can be used. Syntax ------ ``` #RGB // The three-value syntax #RGBA // The four-value syntax #RRGGBB // The six-value syntax #RRGGBBAA // The eight-value syntax ``` ### Value `R` or `RR` The *red* component of the color, as a case-insensitive hexadecimal number between `0` and `ff` (255)). If there is only one number, it is duplicated: `1` means `11`. `G` or `GG` The *green* component of the color, as a case-insensitive hexadecimal number between `0` and `ff` (255)). If there is only one number, it is duplicated: `c` means `cc`. `B` or `BB` The *blue* component of the color, as a case-insensitive hexadecimal number between `0` and `ff` (255)). If there is only one number, it is duplicated: `9` means `99`. `A` or `AA` Optional The *alpha* component of the color, indicating its transparency, as a case-insensitive hexadecimal number between `0` and `ff` (255)). If there is only one number, it is duplicated: `e` means `ee`. `0` represents a fully transparent color, and `ff` a fully opaque one. **Note:** The syntax is case-insensitive `#00ff00` is the same as `#00FF00`. Examples -------- ``` <p>Hexadecimal syntax for a fully opaque hot pink</p> #f09 <div class="c1"></div> #F09 <div class="c2"></div> #ff0099 <div class="c3"></div> #FF0099 <div class="c4"></div> ``` ``` div { width: 40px; height: 40px; } .c1 { background: #f09; } .c2 { background: #f09; } .c3 { background: #ff0099; } .c4 { background: #ff0099; } ``` Specifications -------------- | Specification | | --- | | [CSS Color Module Level 4 # hex-notation](https://w3c.github.io/csswg-drafts/css-color/#hex-notation) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `hex-color` | 1 | 12 | 1 | 3 | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | | `alpha_hexadecimal_notation` | 62 | 79 | 49 | No | 49 | 10 | 62 | 62 | 49 | 47 | 9.3 | 8.0 | See also -------- * [`<color>`](color_value) the data type these values belong to. * [`rgb()`](color_value/rgb), the function allowing to set the three components of the color, as well as its transparency, using decimal values.
programming_docs
css font-variant-east-asian font-variant-east-asian ======================= The `font-variant-east-asian` CSS property controls the use of alternate glyphs for East Asian scripts, like Japanese and Chinese. Try it ------ Syntax ------ ``` 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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` font-variant-east-asian = normal [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) <east-asian-variant-values> [||](value_definition_syntax#double_bar) <east-asian-width-values> [||](value_definition_syntax#double_bar) ruby []](value_definition_syntax#brackets) <east-asian-variant-values> = jis78 [|](value_definition_syntax#single_bar) jis83 [|](value_definition_syntax#single_bar) jis90 [|](value_definition_syntax#single_bar) jis04 [|](value_definition_syntax#single_bar) simplified [|](value_definition_syntax#single_bar) traditional <east-asian-width-values> = full-width [|](value_definition_syntax#single_bar) proportional-width ``` Examples -------- ### Setting East Asian glyph variants This example require font "Yu Gothic" installed in your OS, other fonts may not support OpenType features. #### 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 ``` 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 Specifications -------------- | Specification | | --- | | [CSS Fonts Module Level 4 # font-variant-east-asian-prop](https://w3c.github.io/csswg-drafts/css-fonts/#font-variant-east-asian-prop) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `font-variant-east-asian` | 63 | 79 | 34 | No | 50 | 9.1 | 63 | 63 | 34 | 46 | 9.3 | 8.0 | See also -------- * [`font-variant`](font-variant) * [`font-variant-alternates`](font-variant-alternates) * [`font-variant-caps`](font-variant-caps) * [`font-variant-emoji`](font-variant-emoji) * [`font-variant-ligatures`](font-variant-ligatures) * [`font-variant-numeric`](font-variant-numeric) * [`font-variant-position`](font-variant-position) css <dashed-ident> <dashed-ident> ============== The `<dashed-ident>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) denotes an arbitrary string used as an [identifier](https://developer.mozilla.org/en-US/docs/Glossary/Identifier). Syntax ------ The syntax of `<dashed-ident>` is similar to CSS identifiers (such as property names), except that it is [case-sensitive](https://en.wikipedia.org/wiki/Case_sensitivity). It starts with two dashes, followed by the user-defined identifier. The double dash at the beginning makes them easily identifiable when reading through a CSS code block. Just like [`<custom-ident>`](custom-ident) `<dashed-ident>`s are defined by the user, but unlike `<custom-ident>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) will never define a `<dashed-ident>`. Examples -------- ### Using with CSS custom properties When `<dashed-ident>` is used with [CSS custom properties](using_css_custom_properties), the property is declared first and then used within a [CSS var() function](var()). ``` html { --primary-color: red; --secondary-color: blue; --tertiary-color: green; } h1, h4 { color: var(--primary-color); } h2, h5 { color: var(--secondary-color); } h3, h6 { color: var(--tertiary-color); } ``` ### Using with @color-profile When `<dashed-ident>` is used with the <@color-profile> at-rule, the at-rule is declared first and then used within a [CSS color() function](color_value/color). ``` @color-profile --my-color-profile { src: url("https://example.org/SWOP2006\_Coated5v2.icc"); } .header { background-color: color(--my-color-profile 0% 70% 20% 0%); } ``` ### Using with @font-palette-values When `<dashed-ident>` is used with the <@font-palette-values> at-rule, the at-rule is declared first and then used as the value for the <font-palette> property. ``` @font-palette-values --my-palette { font-family: Bixa; base-palette: 1; override-colors: 0 #ff0000; } h1, h2, h3, h4 { font-palette: --my-palette; } ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # dashed-idents](https://drafts.csswg.org/css-values/#dashed-idents) | Browser compatibility --------------------- See also -------- * [<ident>](ident) * [<custom-ident>](custom-ident) css animation-timing-function animation-timing-function ========================= The `animation-timing-function` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets how an animation progresses through the duration of each cycle. Try it ------ It is often convenient to use the shorthand property [`animation`](animation) to set all animation properties at once. Syntax ------ ``` /\* Keyword values \*/ animation-timing-function: ease; animation-timing-function: ease-in; animation-timing-function: ease-out; animation-timing-function: ease-in-out; animation-timing-function: linear; animation-timing-function: step-start; animation-timing-function: step-end; /\* Function values \*/ animation-timing-function: cubic-bezier(0.1, 0.7, 1, 0.1); animation-timing-function: steps(4, end); /\* Steps Function keywords \*/ animation-timing-function: steps(4, jump-start); animation-timing-function: steps(10, jump-end); animation-timing-function: steps(20, jump-none); animation-timing-function: steps(5, jump-both); animation-timing-function: steps(6, start); animation-timing-function: steps(8, end); /\* Multiple animations \*/ animation-timing-function: ease, step-start, cubic-bezier(0.1, 0.7, 1, 0.1); /\* Global values \*/ animation-timing-function: inherit; animation-timing-function: initial; animation-timing-function: revert; animation-timing-function: revert-layer; animation-timing-function: unset; ``` **Note:** When you specify multiple comma-separated values on an `animation-*` property, they are applied to the animations in the order in which the [`animation-name`](animation-name)s appear. For situations where the number of animations and `animation-*` property values do not match, see [Setting multiple animation property values](css_animations/using_css_animations#setting_multiple_animation_property_values). ### Values [`<easing-function>`](easing-function) The easing function that corresponds to a given animation, as determined by [`animation-name`](animation-name). The non-step keyword values (ease, linear, ease-in-out, etc.) each represent cubic Bézier curve with fixed four point values, with the cubic-bezier() function value allowing for a non-predefined value. The step timing functions divides the input time into a specified number of intervals that are equal in length. It is defined by a number of steps and a step position. `ease` Equal to `cubic-bezier(0.25, 0.1, 0.25, 1.0)`, the default value, increases in velocity towards the middle of the animation, slowing back down at the end. `linear` Equal to `cubic-bezier(0.0, 0.0, 1.0, 1.0)`, animates at an even speed. `ease-in` Equal to `cubic-bezier(0.42, 0, 1.0, 1.0)`, starts off slowly, with the speed of the transition of the animating property increasing until complete. `ease-out` Equal to `cubic-bezier(0, 0, 0.58, 1.0)`, starts quickly, slowing down the animation continues. `ease-in-out` Equal to `cubic-bezier(0.42, 0, 0.58, 1.0)`, with the animating properties slowly transitioning, speeding up, and then slowing down again. `cubic-bezier(p1, p2, p3, p4)` An author defined cubic-bezier curve, where the p1 and p3 values must be in the range of 0 to 1. `steps(n, <jumpterm>)` Displays an animation iteration along *n* stops along the transition, displaying each stop for equal lengths of time. For example, if *n* is 5, there are 5 steps. Whether the animation holds temporarily at 0%, 20%, 40%, 60% and 80%, on the 20%, 40%, 60%, 80% and 100%, or makes 5 stops between the 0% and 100% along the animation, or makes 5 stops including the 0% and 100% marks (on the 0%, 25%, 50%, 75%, and 100%) depends on which of the following jump terms is used: `jump-start` Denotes a left-continuous function, so that the first jump happens when the animation begins; `jump-end` Denotes a right-continuous function, so that the last jump happens when the animation ends; `jump-none` There is no jump on either end. Instead, holding at both the 0% mark and the 100% mark, each for 1/n of the duration. `jump-both` Includes pauses at both the 0% and 100% marks, effectively adding a step during the animation iteration. `start` Same as `jump-start`. `end` Same as `jump-end`. `step-start` Equal to `steps(1, jump-start)` `step-end` Equal to `steps(1, jump-end)` Description ----------- Timing functions may be specified on individual keyframes in a <@keyframes> rule. If no `animation-timing-function` is specified on a keyframe, the corresponding value of `animation-timing-function` from the element to which the animation is applied is used for that keyframe. Within a keyframe, `animation-timing-function` is an at-rule-specific descriptor, not the property of the same name. The timing is not being animated. Rather, a keyframe's timing function is applied on a property-by-property basis from the keyframe on which it is specified until the next keyframe specifying that property, or until the end of the animation if there is no subsequent keyframe specifying that property. As a result, an `animation-timing-function` specified on the `100%` or `to` keyframe will never be used. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `ease` | | Applies to | all elements, [`::before`](::before) and [`::after`](::after) <pseudo-elements> | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | Not animatable | Formal syntax ------------- ``` animation-timing-function = <easing-function>[#](value_definition_syntax#hash_mark) <easing-function> = linear [|](value_definition_syntax#single_bar) <linear-easing-function> [|](value_definition_syntax#single_bar) <cubic-bezier-easing-function> [|](value_definition_syntax#single_bar) <step-easing-function> <linear-easing-function> = linear( <linear-stop-list> ) <cubic-bezier-easing-function> = ease [|](value_definition_syntax#single_bar) ease-in [|](value_definition_syntax#single_bar) ease-out [|](value_definition_syntax#single_bar) ease-in-out [|](value_definition_syntax#single_bar) cubic-bezier( [<number [0,1]>](number) , [<number>](number) , [<number [0,1]>](number) , [<number>](number) ) <step-easing-function> = step-start [|](value_definition_syntax#single_bar) step-end [|](value_definition_syntax#single_bar) steps( [<integer>](integer) [[](value_definition_syntax#brackets), <step-position> []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <linear-stop-list> = [[](value_definition_syntax#brackets) <linear-stop> []](value_definition_syntax#brackets)[#](value_definition_syntax#hash_mark) <step-position> = jump-start [|](value_definition_syntax#single_bar) jump-end [|](value_definition_syntax#single_bar) jump-none [|](value_definition_syntax#single_bar) jump-both [|](value_definition_syntax#single_bar) start [|](value_definition_syntax#single_bar) end <linear-stop> = [<number>](number) [&&](value_definition_syntax#double_ampersand) <linear-stop-length>[?](value_definition_syntax#question_mark) <linear-stop-length> = [<percentage>](percentage)[{1,2}](value_definition_syntax#curly_braces) ``` Examples -------- ### Cubic-Bezier examples ``` .ease { animation-timing-function: ease; } .easein { animation-timing-function: ease-in; } .easeout { animation-timing-function: ease-out; } .easeinout { animation-timing-function: ease-in-out; } .linear { animation-timing-function: linear; } .cb { animation-timing-function: cubic-bezier(0.2, -2, 0.8, 2); } ``` ### Step examples ``` .jump-start { animation-timing-function: steps(5, jump-start); } .jump-end { animation-timing-function: steps(5, jump-end); } .jump-none { animation-timing-function: steps(5, jump-none); } .jump-both { animation-timing-function: steps(5, jump-both); } .start { animation-timing-function: steps(5, start); } .end { animation-timing-function: steps(5, end); } .step-start { animation-timing-function: step-start; } .step-end { animation-timing-function: step-end; } ``` Specifications -------------- | Specification | | --- | | [CSS Animations Level 1 # animation-timing-function](https://w3c.github.io/csswg-drafts/css-animations/#animation-timing-function) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `animation-timing-function` | 43 3 | 12 12 | 49 16 5 | 10 | 30 15 12.1-15 12-15 | 9 4 | 43 ≤37 | 43 18 | 49 16 5 | 30 14 12.1-14 12-14 | 9 3.2 | 4.0 1.0 | | `jump` | 77 | 79 | 65 | No | 64 | 14 | 77 | 77 | 65 | 55 | 14 | 12.0 | See also -------- * [Using CSS animations](css_animations/using_css_animations) * [`<easing-function>`](easing-function) * JavaScript [`AnimationEvent`](https://developer.mozilla.org/en-US/docs/Web/API/AnimationEvent) API * [cubic-bezier.com](https://cubic-bezier.com) * Other related animation properties: [`animation`](animation), [`animation-composition`](animation-composition), [`animation-delay`](animation-delay), [`animation-direction`](animation-direction), [`animation-duration`](animation-duration), [`animation-fill-mode`](animation-fill-mode), [`animation-iteration-count`](animation-iteration-count), [`animation-name`](animation-name), [`animation-play-state`](animation-play-state), [`animation-timeline`](animation-timeline) css ::-webkit-scrollbar ::-webkit-scrollbar =================== **Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future. The `::-webkit-scrollbar` CSS pseudo-element affects the style of an element's scrollbar when it has `overflow:scroll;` set. **Note:** If `overflow:scroll;` is not set, no scrollbar is displayed. **Note:** `::-webkit-scrollbar` is only available in [Blink](https://www.chromium.org/blink/)- and [WebKit](https://webkit.org)-based browsers (e.g., Chrome, Edge, Opera, Safari, all browsers on iOS, and [others](https://en.wikipedia.org/wiki/List_of_web_browsers#WebKit-based)). A standardized method of styling scrollbars is available with [`scrollbar-color`](scrollbar-color) and [`scrollbar-width`](scrollbar-width). CSS Scrollbar Selectors ----------------------- You can use the following pseudo-elements to customize various parts of the scrollbar for WebKit browsers: * `::-webkit-scrollbar` — the entire scrollbar. * `::-webkit-scrollbar-button` — the buttons on the scrollbar (arrows pointing upwards and downwards that scroll one line at a time). * `::-webkit-scrollbar:horizontal{}` — the horizontal scrollbar. * `::-webkit-scrollbar-thumb` — the draggable scrolling handle. * `::-webkit-scrollbar-track` — the track (progress bar) of the scrollbar, where there is a gray bar on top of a white bar. * `::-webkit-scrollbar-track-piece` — the part of the track (progress bar) not covered by the handle. * `::-webkit-scrollbar:vertical{}` — the vertical scrollbar. * `::-webkit-scrollbar-corner` — the bottom corner of the scrollbar, where both horizontal and vertical scrollbars meet. This is often the bottom-right corner of the browser window. * `::-webkit-resizer` — the draggable resizing handle that appears at the bottom corner of some elements. Examples -------- ### CSS ``` .visible-scrollbar, .invisible-scrollbar, .mostly-customized-scrollbar { display: block; width: 10em; overflow: auto; height: 2em; } .invisible-scrollbar::-webkit-scrollbar { display: none; } /\* Demonstrate a "mostly customized" scrollbar \* (won't be visible otherwise if width/height is specified) \*/ .mostly-customized-scrollbar::-webkit-scrollbar { width: 5px; height: 8px; background-color: #aaa; /\* or add it to the track \*/ } /\* Add a thumb \*/ .mostly-customized-scrollbar::-webkit-scrollbar-thumb { background: #000; } ``` ### HTML ``` <div class="visible-scrollbar"> Etiam sagittis sem sed lacus laoreet, eu fermentum eros auctor. Proin at nulla elementum, consectetur ex eget, commodo ante. Sed eros mi, bibendum ut dignissim et, maximus eget nibh. Phasellus blandit quam turpis, at mollis velit pretium ut. Nunc consequat efficitur ultrices. Nullam hendrerit posuere est. Nulla libero sapien, egestas ac felis porta, cursus ultricies quam. Vestibulum tincidunt accumsan sapien, a fringilla dui semper in. Vivamus consectetur ipsum a ornare blandit. Aenean tempus at lorem sit amet faucibus. Curabitur nibh justo, faucibus sed velit cursus, mattis cursus dolor. Pellentesque id pretium est. Quisque convallis nisi a diam malesuada mollis. Aliquam at enim ligula. </div> <div class="invisible-scrollbar"> Thisisaveeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerylongword </div> <div class="mostly-customized-scrollbar"> Thisisaveeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerylongword<br /> And pretty tall<br /> thing with weird scrollbars.<br /> Who thought scrollbars could be made weeeeird? </div> ``` ### Result Specifications -------------- Not part of any standard. Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `::-webkit-scrollbar` | 2 | 79 | No See [bug 1432935](https://bugzil.la/1432935). | No | 15 | 4 | ≤37 | 18 | No See [bug 1432935](https://bugzil.la/1432935). | 14 | 3.2 | 1.0 | | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `::-webkit-scrollbar` | 2 | 79 | No See [bug 1432935](https://bugzil.la/1432935). | No | 15 | 4 | ≤37 | 18 | No See [bug 1432935](https://bugzil.la/1432935). | 14 | 3-13 | 1.0 | | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `::-webkit-scrollbar` | 2 | 79 | No See [bug 1432935](https://bugzil.la/1432935). | No | 15 | 4 | ≤37 | 18 | No See [bug 1432935](https://bugzil.la/1432935). | 14 | 3-13 | 1.0 | | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `::-webkit-scrollbar` | 2 | 79 | No See [bug 1432935](https://bugzil.la/1432935). | No | 15 | 4 | ≤37 | 18 | No See [bug 1432935](https://bugzil.la/1432935). | 14 | 3-13 | 1.0 | | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `::-webkit-scrollbar` | 2 | 79 | No See [bug 1432935](https://bugzil.la/1432935). | No | 15 | 4 | ≤37 | 18 | No See [bug 1432935](https://bugzil.la/1432935). | 14 | 3-13 | 1.0 | | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `::-webkit-scrollbar` | 2 | 79 | No See [bug 1432935](https://bugzil.la/1432935). | No | 15 | 4 | ≤37 | 18 | No See [bug 1432935](https://bugzil.la/1432935). | 14 | 3-13 | 1.0 | | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `::-webkit-scrollbar` | 2 | 79 | No See [bug 1432935](https://bugzil.la/1432935). | No | 15 | 4 | ≤37 | 18 | No See [bug 1432935](https://bugzil.la/1432935). | 14 | 3 From Safari 13, only `display: none` works with this pseudo-element. Other styles have no effect. | 1.0 | ### css.selectors.-webkit-scrollbar BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. ### css.selectors.-webkit-scrollbar-button BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. ### css.selectors.-webkit-scrollbar-thumb BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. ### css.selectors.-webkit-scrollbar-track BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. ### css.selectors.-webkit-scrollbar-track-piece BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. ### css.selectors.-webkit-scrollbar-corner BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. ### css.selectors.-webkit-resizer BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. See also -------- * WebKit blog on [Styling Scrollbars](https://webkit.org/blog/363/styling-scrollbars/) * [`scrollbar-width`](scrollbar-width) * [`scrollbar-color`](scrollbar-color)
programming_docs
css Descendant combinator Descendant combinator ===================== The **descendant combinator** — typically represented by a single space (" ") character — combines two selectors such that elements matched by the second selector are selected if they have an ancestor (parent, parent's parent, parent's parent's parent, etc.) element matching the first selector. Selectors that utilize a descendant combinator are called *descendant selectors*. ``` /\* List items that are descendants of the "my-things" list \*/ ul.my-things li { margin: 2em; } ``` The descendant combinator is technically one or more [CSS](https://developer.mozilla.org/en-US/docs/Glossary/CSS) white space characters — the space character and/or one of four control characters: carriage return, form feed, new line, and tab characters — between two selectors in the absence of another combinator. Additionally, the white space characters of which the combinator is comprised may contain any number of CSS comments. Syntax ------ ``` selector1 selector2 { /\* property declarations \*/ } ``` Examples -------- ### CSS ``` li { list-style-type: disc; } li li { list-style-type: circle; } ``` ### HTML ``` <ul> <li> <div>Item 1</div> <ul> <li>Subitem A</li> <li>Subitem B</li> </ul> </li> <li> <div>Item 2</div> <ul> <li>Subitem A</li> <li>Subitem B</li> </ul> </li> </ul> ``` ### Result Specifications -------------- | Specification | | --- | | [Selectors Level 4 # descendant-combinators](https://w3c.github.io/csswg-drafts/selectors/#descendant-combinators) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `Descendant_combinator` | 1 Since Chrome 61, `>>>` is aliased to this selector [since its use as the 'shadow-piercing descendant combinator' was deprecated](https://developers.google.com/web/updates/2017/06/chrome-60-deprecations#make_shadow-piercing_descendant_combinator_behave_like_descendent_combinator). | 12 | 1 | 3 | 3.5 | 1 | 4.4 Since Chrome 61, `>>>` is aliased to this selector [since its use as the 'shadow-piercing descendant combinator' was deprecated](https://developers.google.com/web/updates/2017/06/chrome-60-deprecations#make_shadow-piercing_descendant_combinator_behave_like_descendent_combinator). | 18 Since Chrome 61, `>>>` is aliased to this selector [since its use as the 'shadow-piercing descendant combinator' was deprecated](https://developers.google.com/web/updates/2017/06/chrome-60-deprecations#make_shadow-piercing_descendant_combinator_behave_like_descendent_combinator). | 4 | 10.1 | 1 | 1.0 Since Samsung Internet 8.0, `>>>` is aliased to this selector [since its use as the 'shadow-piercing descendant combinator' was deprecated](https://developers.google.com/web/updates/2017/06/chrome-60-deprecations#make_shadow-piercing_descendant_combinator_behave_like_descendent_combinator). | | `two_greater_than_syntax` | No | No | No | No | No | 10-11.1 | No | No | No | No | 10-11.3 | No | See also -------- * [Child combinator](child_combinator) css transition-duration transition-duration =================== The `transition-duration` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the length of time a transition animation should take to complete. By default, the value is `0s`, meaning that no animation will occur. Try it ------ You may specify multiple durations; each duration will be applied to the corresponding property as specified by the [`transition-property`](transition-property) property, which acts as a master list. If there are fewer durations specified than in the master list, the user agent repeat the list of durations. If there are more durations, the list is truncated to the right size. In both case the CSS declaration stays valid. Syntax ------ ``` /\* <time> values \*/ transition-duration: 6s; transition-duration: 120ms; transition-duration: 1s, 15s; transition-duration: 10s, 30s, 230ms; /\* Global values \*/ transition-duration: inherit; transition-duration: initial; transition-duration: revert; transition-duration: revert-layer; transition-duration: unset; ``` ### Values `<time>` Is a [`<time>`](time) denoting the amount of time the transition from the old value of a property to the new value should take. A time of `0s` indicates that no transition will happen, that is the switch between the two states will be instantaneous. A negative value for the time renders the declaration invalid. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0s` | | Applies to | all elements, [`::before`](::before) and [`::after`](::after) <pseudo-elements> | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` transition-duration = [<time [0s,∞]>](time)[#](value_definition_syntax#hash_mark) ``` Examples -------- ### Example showing different durations #### HTML ``` <div class="box duration-1">0.5 seconds</div> <div class="box duration-2">2 seconds</div> <div class="box duration-3">4 seconds</div> <button id="change">Change</button> ``` #### CSS ``` .box { margin: 20px; padding: 10px; display: inline-block; width: 100px; height: 100px; background-color: red; font-size: 18px; transition-property: background-color font-size transform color; transition-timing-function: ease-in-out; } .transformed-state { transform: rotate(270deg); background-color: blue; color: yellow; font-size: 12px; transition-property: background-color font-size transform color; transition-timing-function: ease-in-out; } .duration-1 { transition-duration: 0.5s; } .duration-2 { transition-duration: 2s; } .duration-3 { transition-duration: 4s; } ``` #### JavaScript ``` 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 Specifications -------------- | Specification | | --- | | [CSS Transitions # transition-duration-property](https://w3c.github.io/csswg-drafts/css-transitions/#transition-duration-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `transition-duration` | 26 1 | 12 12 | 49 16 4 | 10 10 | 15 12.1 10-15 | 9 3.1 | 4.4 2 | 26 18 | 49 16 4 | 14 12.1 10.1-14 | 9 2 | 1.5 1.0 | See also -------- * [Using CSS transitions](css_transitions/using_css_transitions) * [`transition`](transition) * [`transition-property`](transition-property) * [`transition-timing-function`](transition-timing-function) * [`transition-delay`](transition-delay) * [`TransitionEvent`](https://developer.mozilla.org/en-US/docs/Web/API/TransitionEvent) css :past :past ===== The `:past` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) selector is a time-dimensional pseudo-class that will match for any element which appears entirely before an element that matches [`:current`](:current). For example in a video with captions which are being displayed by [WebVTT](https://developer.mozilla.org/en-US/docs/Web/API/WebVTT_API). ``` :past(p, span) { display: none; } ``` Syntax ------ ``` :past ``` Examples -------- ### CSS ``` :past(p, span) { display: none; } ``` ### HTML ``` <video controls preload="metadata"> <source src="video.mp4" type="video/mp4" /> <source src="video.webm" type="video/webm" /> <track label="English" kind="subtitles" srclang="en" src="subtitles.vtt" default /> </video> ``` ### WebVTT ``` WEBVTT FILE 1 00:00:03.500 --> 00:00:05.000 This is the first caption 2 00:00:06.000 --> 00:00:09.000 This is the second caption 3 00:00:11.000 --> 00:00:19.000 This is the third caption ``` Specifications -------------- | Specification | | --- | | [Selectors Level 4 # the-past-pseudo](https://w3c.github.io/csswg-drafts/selectors/#the-past-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:past` | No | No | No | No | No | 7 | No | No | No | No | 7 | No | See also -------- * [Web Video Text Tracks Format (WebVTT)](https://developer.mozilla.org/en-US/docs/Web/API/WebVTT_API) * [`:current`](:current) * [`:future`](:future) css font font ==== The `font` CSS [shorthand property](shorthand_properties) sets all the different properties of an element's font. Alternatively, it sets an element's font to a system font. Try it ------ As with any shorthand property, any individual value that is not specified is set to its corresponding initial value (possibly overriding values previously set using non-shorthand properties). Though not directly settable by `font`, the longhands [`font-size-adjust`](font-size-adjust) and [`font-kerning`](font-kerning) are also reset to their initial values. Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`font-family`](font-family) * [`font-size`](font-size) * [`font-stretch`](font-stretch) * [`font-style`](font-style) * [`font-variant`](font-variant) * [`font-weight`](font-weight) * [`line-height`](line-height) Syntax ------ The `font` property may be specified as either a single keyword, which will select a system font, or as a shorthand for various font-related properties. If `font` is specified as a system keyword, it must be one of: `caption`, `icon`, `menu`, `message-box`, `small-caption`, `status-bar`. If `font` is specified as a shorthand for several font-related properties, then: * it must include values for: + [`<font-size>`](font-size) + [`<font-family>`](font-family) * it may optionally include values for: + [`<font-style>`](font-style) + [`<font-variant>`](font-variant) + [`<font-weight>`](font-weight) + [`<font-stretch>`](font-stretch) + [`<line-height>`](line-height) * `font-style`, `font-variant` and `font-weight` must precede `font-size` * `font-variant` may only specify the values defined in CSS 2.1, that is `normal` and `small-caps` * `font-stretch` may only be a single keyword value. * `line-height` must immediately follow `font-size`, preceded by "/", like this: "`16px/3`" * `font-family` must be the last value specified. ### Values `<'font-style'>` See the [`font-style`](font-style) CSS property. `<'font-variant'>` See the [`font-variant`](font-variant) CSS property. `<'font-weight'>` See the [`font-weight`](font-weight) CSS property. `<'font-stretch'>` See the [`font-stretch`](font-stretch) CSS property. `<'font-size'>` See the [`font-size`](font-size) CSS property. `<'line-height'>` See the [`line-height`](line-height) CSS property. `<'font-family'>` See the [`font-family`](font-family) CSS property. #### System font values `caption` The system font used for captioned controls (e.g., buttons, drop-downs, etc.). `icon` The system font used to label icons. `menu` The system font used in menus (e.g., dropdown menus and menu lists). `message-box` The system font used in dialog boxes. `small-caption` The system font used for labeling small controls. `status-bar` The system font used in window status bars. Prefixed system font keywords Browsers often implement several more, prefixed, keywords: Gecko implements `-moz-window`, `-moz-document`, `-moz-desktop`, `-moz-info`, `-moz-dialog`, `-moz-button`, `-moz-pull-down-menu`, `-moz-list`, and `-moz-field`. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`font-style`](font-style): `normal` * [`font-variant`](font-variant): `normal` * [`font-weight`](font-weight): `normal` * [`font-stretch`](font-stretch): `normal` * [`font-size`](font-size): `medium` * [`line-height`](line-height): `normal` * [`font-family`](font-family): depends on user agent | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | yes | | Percentages | as each of the properties of the shorthand:* [`font-size`](font-size): refer to the parent element's font size * [`line-height`](line-height): refer to the font size of the element itself | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`font-style`](font-style): as specified * [`font-variant`](font-variant): as specified * [`font-weight`](font-weight): the keyword or the numerical value as specified, with `bolder` and `lighter` transformed to the real value * [`font-stretch`](font-stretch): as specified * [`font-size`](font-size): as specified, but with relative lengths converted into absolute lengths * [`line-height`](line-height): for percentage and length values, the absolute length, otherwise as specified * [`font-family`](font-family): as specified | | Animation type | as each of the properties of the shorthand:* [`font-style`](font-style): discrete * [`font-variant`](font-variant): discrete * [`font-weight`](font-weight): a [font weight](font-weight#interpolation) * [`font-stretch`](font-stretch): a [font stretch](font-stretch#interpolation) * [`font-size`](font-size): a [length](length#interpolation) * [`line-height`](line-height): either number or length * [`font-family`](font-family): discrete | Formal syntax ------------- ``` font = [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) <'font-style'> [||](value_definition_syntax#double_bar) <font-variant-css2> [||](value_definition_syntax#double_bar) <'font-weight'> [||](value_definition_syntax#double_bar) <font-stretch-css3> []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) <'font-size'> [[](value_definition_syntax#brackets) / <'line-height'> []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) <'font-family'> []](value_definition_syntax#brackets) [|](value_definition_syntax#single_bar) caption [|](value_definition_syntax#single_bar) icon [|](value_definition_syntax#single_bar) menu [|](value_definition_syntax#single_bar) message-box [|](value_definition_syntax#single_bar) small-caption [|](value_definition_syntax#single_bar) status-bar <font-variant-css2> = normal [|](value_definition_syntax#single_bar) small-caps <font-stretch-css3> = normal [|](value_definition_syntax#single_bar) ultra-condensed [|](value_definition_syntax#single_bar) extra-condensed [|](value_definition_syntax#single_bar) condensed [|](value_definition_syntax#single_bar) semi-condensed [|](value_definition_syntax#single_bar) semi-expanded [|](value_definition_syntax#single_bar) expanded [|](value_definition_syntax#single_bar) extra-expanded [|](value_definition_syntax#single_bar) ultra-expanded ``` Examples -------- ### Setting font properties ``` /\* Set the font size to 12px and the line height to 14px. Set the font family to sans-serif \*/ p { font: 12px/14px sans-serif; } /\* Set the font size to 80% of the parent element or default value (if no parent element present). Set the font family to sans-serif \*/ p { font: 80% sans-serif; } /\* Set the font weight to bold, the font-style to italic, the font size to large, and the font family to serif. \*/ p { font: bold italic large serif; } /\* Use the same font as the status bar of the window \*/ p { font: status-bar; } ``` ### Live sample Specifications -------------- | Specification | | --- | | [CSS Fonts Module Level 4 # font-prop](https://w3c.github.io/csswg-drafts/css-fonts/#font-prop) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `font` | 1 | 12 | 1 | 3 | 3.5 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | | `font_stretch_support` | 60 | 79 | 43 | No | 47 | 11 | 60 | 60 | 43 | 44 | 11 | 8.0 | | `system_fonts` | 1 | 12 | 1 | 4 | 6 | 1 | 37 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [`font-style`](font-style) * [`font-weight`](font-weight) * [Fundamental text and font styling](https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text/Fundamentals) css math-style math-style ========== **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `math-style` property indicates whether MathML equations should render with normal or compact height. Syntax ------ ``` /\* Keyword values \*/ math-style: normal; math-style: compact; /\* Global values \*/ math-style: inherit; math-style: initial; math-style: revert; math-style: revert-layer; math-style: unset; ``` ### Values `normal` The initial value, indicates normal rendering. `compact` The math layout on descendants tries to minimize the logical height. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | Not animatable | Formal syntax ------------- ``` math-style = normal [|](value_definition_syntax#single_bar) compact ``` Examples -------- ### CSS ``` math { math-style: compact; } ``` Specifications -------------- | Specification | | --- | | [MathML Core # the-math-style-property](https://w3c.github.io/mathml-core/#the-math-style-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `math-style` | 83 | 83 | 83 | No | 69 | 14.1 | No | 83 | No | No | 14.5 | No | See also -------- * [`math-depth`](math-depth) * [`font-size`](font-size) css grid-auto-rows grid-auto-rows ============== The `grid-auto-rows` CSS property specifies the size of an implicitly-created grid row [track](https://developer.mozilla.org/en-US/docs/Glossary/Grid_Tracks) or pattern of tracks. Try it ------ If a grid item is positioned into a row that is not explicitly sized by [`grid-template-rows`](grid-template-rows), implicit [grid](https://developer.mozilla.org/en-US/docs/Glossary/Grid) tracks are created to hold it. This can happen either by explicitly positioning into a row that is out of range, or by the auto-placement algorithm creating additional rows. Syntax ------ ``` /\* Keyword values \*/ grid-auto-rows: min-content; grid-auto-rows: max-content; grid-auto-rows: auto; /\* <length> values \*/ grid-auto-rows: 100px; grid-auto-rows: 20cm; grid-auto-rows: 50vmax; /\* <percentage> values \*/ grid-auto-rows: 10%; grid-auto-rows: 33.3%; /\* <flex> values \*/ grid-auto-rows: 0.5fr; grid-auto-rows: 3fr; /\* minmax() values \*/ grid-auto-rows: minmax(100px, auto); grid-auto-rows: minmax(max-content, 2fr); grid-auto-rows: minmax(20%, 80vmax); /\* fit-content() values \*/ grid-auto-rows: fit-content(400px); grid-auto-rows: fit-content(5cm); grid-auto-rows: fit-content(20%); /\* multiple track-size values \*/ grid-auto-rows: min-content max-content auto; grid-auto-rows: 100px 150px 390px; grid-auto-rows: 10% 33.3%; grid-auto-rows: 0.5fr 3fr 1fr; grid-auto-rows: minmax(100px, auto) minmax(max-content, 2fr) minmax(20%, 80vmax); grid-auto-rows: 100px minmax(100px, auto) 10% 0.5fr fit-content(400px); /\* Global values \*/ grid-auto-rows: inherit; grid-auto-rows: initial; grid-auto-rows: revert; grid-auto-rows: revert-layer; grid-auto-rows: unset; ``` ### Values [`<length>`](length) Is a non-negative length. [`<percentage>`](percentage) Is a non-negative [`<percentage>`](percentage) value relative to the block size of the grid container. If the block size of the grid container is indefinite, the percentage value is treated like `auto`. [`<flex>`](flex_value) 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>)`). [`max-content`](max-content) Is a keyword representing the largest maximal content contribution of the grid items occupying the grid track. [`min-content`](min-content) Is a keyword representing the largest minimal content contribution of the grid items occupying the grid track. [`minmax(min, max)`](minmax) 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. As a minimum, it is treated as zero (or minimal content, if the grid container is sized under a minimal content constraint). [`fit-content( [ <length> | <percentage> ] )`](fit-content_function) 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. `auto` Is a keyword that is identical to maximal content if it's a maximum. As a minimum it represents the largest minimum size (as specified by [`min-width`](min-width)/[`min-height`](min-height)) of the grid items occupying the grid track. **Note:** `auto` track sizes (and only `auto` track sizes) can be stretched by the [`align-content`](align-content) and [`justify-content`](justify-content) properties. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | grid containers | | [Inherited](inheritance) | no | | Percentages | refer to corresponding dimension of the content area | | [Computed value](computed_value) | the percentage as specified or the absolute length | | Animation type | discrete | Formal syntax ------------- ``` grid-auto-rows = <track-size>[+](value_definition_syntax#plus) <track-size> = <track-breadth> [|](value_definition_syntax#single_bar) minmax( <inflexible-breadth> , <track-breadth> ) [|](value_definition_syntax#single_bar) fit-content( <length-percentage> ) <track-breadth> = <length-percentage> [|](value_definition_syntax#single_bar) [<flex>](flex) [|](value_definition_syntax#single_bar) min-content [|](value_definition_syntax#single_bar) max-content [|](value_definition_syntax#single_bar) auto <inflexible-breadth> = <length-percentage> [|](value_definition_syntax#single_bar) min-content [|](value_definition_syntax#single_bar) max-content [|](value_definition_syntax#single_bar) auto <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Setting grid row size #### HTML ``` <div id="grid"> <div id="item1"></div> <div id="item2"></div> <div id="item3"></div> </div> ``` #### CSS ``` #grid { width: 200px; display: grid; grid-template-areas: "a a"; gap: 10px; grid-auto-rows: 100px; } #grid > div { background-color: lime; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Grid Layout Module Level 2 # auto-tracks](https://w3c.github.io/csswg-drafts/css-grid/#auto-tracks) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `grid-auto-rows` | 57 | 16 12-79 | 70 52-70 Does not accept multiple track-size values. See [bug 1339672](https://bugzil.la/1339672). | 10 | 44 | 10.1 | 57 | 57 | 79 52-79 Does not accept multiple track-size values. See [bug 1339672](https://bugzil.la/1339672). | 43 | 10.3 | 6.0 | See also -------- * Related CSS properties: [`grid-auto-columns`](grid-auto-columns), [`grid-auto-flow`](grid-auto-flow), [`grid`](grid) * Grid Layout Guide: *[Auto-placement in grid layout - sizing rows in the implicit grid](css_grid_layout/auto-placement_in_css_grid_layout#sizing_rows_in_the_implicit_grid)* * Video tutorial: *[Introducing Grid auto-placement and order](https://gridbyexample.com/video/series-auto-placement-order/)*
programming_docs
css :focus :focus ====== The `:focus` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) represents an element (such as a form input) that has received focus. It is generally triggered when the user clicks or taps on an element or selects it with the keyboard's `Tab` key. Try it ------ **Note:** This pseudo-class applies only to the focused element itself. Use [`:focus-within`](:focus-within) if you want to select an element that *contains* a focused element. Syntax ------ ``` :focus ``` Examples -------- ### HTML ``` <div><input class="red-input" value="I'll be red when focused." /></div> <div><input class="blue-input" value="I'll be blue when focused." /></div> ``` ### CSS ``` .red-input:focus { background: yellow; color: red; } .blue-input:focus { background: yellow; color: blue; } ``` ### Result Accessibility concerns ---------------------- Make sure the visual focus indicator can be seen by people with low vision. This will also benefit anyone use a screen in a brightly lit space (like outside in the sun). [WCAG 2.1 SC 1.4.11 Non-Text Contrast](https://www.w3.org/WAI/WCAG21/Understanding/non-text-contrast.html) requires that the visual focus indicator be at least 3 to 1. * Accessible Visual Focus Indicators: [Give Your Site Some Focus! Tips for Designing Useful and Usable Focus Indicators](https://www.deque.com/blog/give-site-focus-tips-designing-usable-focus-indicators/) ### `:focus { outline: none; }` Never just remove the focus outline (visible focus indicator) without replacing it with a focus outline that will pass [WCAG 2.1 SC 1.4.11 Non-Text Contrast](https://www.w3.org/WAI/WCAG21/Understanding/non-text-contrast.html). * Quick Tip: [Never remove CSS outlines](https://www.a11yproject.com/posts/never-remove-css-outlines/) Specifications -------------- | Specification | | --- | | [HTML Standard # selector-focus](https://html.spec.whatwg.org/multipage/semantics-other.html#selector-focus) | | [Selectors Level 4 # focus-pseudo](https://w3c.github.io/csswg-drafts/selectors/#focus-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:focus` | 1 | 12 | 1 | 8 | 7 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | See also -------- * [`:focus-visible`](:focus-visible) * [`:focus-within`](:focus-within) css margin-inline margin-inline ============= The `margin-inline` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [shorthand property](shorthand_properties) is a shorthand property that defines both the logical inline start and end margins of an element, which maps to physical margins depending on the element's writing mode, directionality, and text orientation. Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`margin-inline-start`](margin-inline-start) * [`margin-inline-end`](margin-inline-end) Syntax ------ ``` /\* <length> values \*/ margin-inline: 10px 20px; /\* An absolute length \*/ margin-inline: 1em 2em; /\* relative to the text size \*/ margin-inline: 5% 2%; /\* relative to the nearest block container's width \*/ margin-inline: 10px; /\* sets both start and end values \*/ /\* Keyword values \*/ margin-inline: auto; /\* Global values \*/ margin-inline: inherit; margin-inline: initial; margin-inline: revert; margin-inline: revert-layer; margin-inline: unset; ``` This property corresponds to the [`margin-top`](margin-top) and [`margin-bottom`](margin-bottom), or the [`margin-right`](margin-right) and [`margin-left`](margin-left) properties, depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). The `margin-inline` property may be specified using one or two values. * When **one** value is specified, it applies the same margin to **both start and end**. * When **two** values are specified, the first margin applies to the **start**, the second to the **end**. ### Values The `margin-inline` property takes the same values as the [`margin`](margin#values) property. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`margin-inline-start`](margin-inline-start): `0` * [`margin-inline-end`](margin-inline-end): `0` | | Applies to | same as [`margin`](margin) | | [Inherited](inheritance) | no | | Percentages | depends on layout model | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`margin-inline-start`](margin-inline-start): if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, `auto` * [`margin-inline-end`](margin-inline-end): if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, `auto` | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` margin-inline = <'margin-top'>[{1,2}](value_definition_syntax#curly_braces) ``` Examples -------- ### Setting inline start and end margins #### CSS ``` div { background-color: yellow; width: 120px; height: auto; border: 1px solid green; } p { margin: 0; margin-inline: 20px 40px; background-color: tan; } .verticalExample { writing-mode: vertical-rl; } ``` #### HTML ``` <div> <p>Example text</p> </div> <div class="verticalExample"> <p>Example text</p> </div> ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # propdef-margin-inline](https://w3c.github.io/csswg-drafts/css-logical/#propdef-margin-inline) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `margin-inline` | 87 | 87 | 66 | No | 73 | 14.1 | 87 | 87 | 66 | 62 | 14.5 | 14.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * The mapped physical properties: [`margin-top`](margin-top), [`margin-right`](margin-right), [`margin-bottom`](margin-bottom), and [`margin-left`](margin-left) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css outline outline ======= The `outline` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [shorthand property](shorthand_properties) sets most of the outline properties in a single declaration. Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`outline-color`](outline-color) * [`outline-style`](outline-style) * [`outline-width`](outline-width) Syntax ------ ``` /\* style \*/ outline: solid; /\* color | style \*/ outline: #f66 dashed; /\* style | width \*/ outline: inset thick; /\* color | style | width \*/ outline: green solid 3px; /\* Global values \*/ outline: inherit; outline: initial; outline: revert; outline: revert-layer; outline: unset; ``` The `outline` property may be specified using one, two, or three of the values listed below. The order of the values does not matter. As with all shorthand properties, any omitted sub-values will be set to their [initial value](initial_value). **Note:** The outline will be invisible for many elements if its style is not defined. This is because the style defaults to `none`. A notable exception is `input` elements, which are given default styling by browsers. ### Values `<'outline-color'>` Sets the color of the outline. Defaults to `invert` for browsers supporting it, `currentcolor` for the others. See [`outline-color`](outline-color). `<'outline-style'>` Sets the style of the outline. Defaults to `none` if absent. See [`outline-style`](outline-style). `<'outline-width'>` Sets the thickness of the outline. Defaults to `medium` if absent. See [`outline-width`](outline-width). Description ----------- Outline is a line outside of the element's <border>. Unlike other areas of the box, outlines don't take up space, so they don't affect the layout of the document in any way. There are a few properties that affect an outline's appearance. It is possible to change the style, color, and width using the `outline` property, the distance from the border using the [`outline-offset`](outline-offset) property, and corner angles using the [`border-radius`](border-radius) property. An outline is not required to be rectangular: While dealing with multiline text, some browsers will draw an outline for each line box separately, while others will wrap the whole text with a single outline. Accessibility concerns ---------------------- Assigning `outline` a value of `0` or `none` will remove the browser's default focus style. If an element can be interacted with it must have a visible focus indicator. Provide obvious focus styling if the default focus style is removed. * [How to Design Useful and Usable Focus Indicators](https://www.deque.com/blog/give-site-focus-tips-designing-usable-focus-indicators/) * WCAG 2.1: [Understanding Success Criterion 2.4.7: Focus Visible](https://www.w3.org/WAI/WCAG21/Understanding/focus-visible.html) Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`outline-color`](outline-color): `invert`, for browsers supporting it, `currentColor` for the other * [`outline-style`](outline-style): `none` * [`outline-width`](outline-width): `medium` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`outline-color`](outline-color): For the keyword `invert`, the computed value is `invert`. For the color value, if the value is translucent, the computed value will be the `rgba()` corresponding one. If it isn't, it will be the `rgb()` corresponding one. The `transparent` keyword maps to `rgba(0,0,0,0)`. * [`outline-width`](outline-width): an absolute length; if the keyword `none` is specified, the computed value is `0` * [`outline-style`](outline-style): as specified | | Animation type | as each of the properties of the shorthand:* [`outline-color`](outline-color): a [color](color_value#interpolation) * [`outline-width`](outline-width): a [length](length#interpolation) * [`outline-style`](outline-style): discrete | Formal syntax ------------- ``` outline = <'outline-color'> [||](value_definition_syntax#double_bar) <'outline-style'> [||](value_definition_syntax#double_bar) <'outline-width'> ``` Examples -------- ### Using outline to set a focus style #### HTML ``` <a href="#">This link has a special focus style.</a> ``` #### CSS ``` a { border: 1px solid; border-radius: 3px; display: inline-block; margin: 10px; padding: 5px; } a:focus { outline: 4px dotted #e73; outline-offset: 4px; background: #ffa; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Basic User Interface Module Level 4 # outline](https://w3c.github.io/csswg-drafts/css-ui/#outline) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `outline` | 94 1-94 Before Chrome 94, `outline` does not follow the shape of `border-radius`. | 94 12-94 Before Edge 94, `outline` does not follow the shape of `border-radius`. | 88 1.5-88 Before Firefox 88, `outline` does not follow the shape of `border-radius`. 1-3.6 | 8 | 80 7-80 Before Opera 80, `outline` does not follow the shape of `border-radius`. | 1.2 `outline` does not follow the shape of `border-radius`. See [bug 20807](https://webkit.org/b/20807). | 94 1-94 Before Chrome 94, `outline` does not follow the shape of `border-radius`. | 94 18-94 Before Chrome 94, `outline` does not follow the shape of `border-radius`. | 88 4-88 Before Firefox 88, `outline` does not follow the shape of `border-radius`. | 10.1 | 1 `outline` does not follow the shape of `border-radius`. See [bug 20807](https://webkit.org/b/20807). | 1.0 | | `invert` | No | 12-79 | 1-3 | 8 | 7-15 | No | No | No | No | No | No | No | See also -------- * [`outline-color`](outline-color) * [`outline-style`](outline-style) * [`outline-width`](outline-width) css container container ========= The **container** [shorthand](shorthand_properties) [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property establishes the element as a query container and specifies the name or name for the [containment context](css_container_queries#naming_containment_contexts) used in a [container query](css_container_queries). Syntax ------ ``` container: <container-name> / <container-type>; ``` ### Values * `<container-name>`: A case-sensitive name for the containment context. More details on the syntax are covered in the [`container-name`](container-name) property page. * `<container-type>`: The type of containment context. More details on the syntax are covered in the [`container-type`](container-type) property page. Example ------- Given the following HTML example which is a card component with an image, a title, and some text: ``` <div class="container"> <div class="card"> <img src="image.png" alt="An awesome picture of a cat" /> <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`: ``` .container { container-type: inline-size; container-name: sidebar; } ``` The `container` shorthand is intended to make this simpler to define in a single declaration: ``` .container { container: sidebar / inline-size; } ``` You can then target that container by name using the [`@container`](@container) at-rule: ``` @container sidebar (min-width: 400px) { /\* <stylesheet> \*/ } ``` For more information on container queries, see the [CSS Container Queries](css_container_queries) page. Specifications -------------- | Specification | | --- | | [CSS Containment Module Level 3 # container-shorthand](https://w3c.github.io/csswg-drafts/css-contain-3/#container-shorthand) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `container` | 105 | 105 | preview | No | 91 | 16 | 105 | 105 | No | 72 | 16 | No | See also -------- * [CSS container queries](css_container_queries) * [`@container`](@container) at-rule * CSS [`contain`](contain) property * CSS [`container-type`](container-type) property * CSS [`container-name`](container-name) property * CSS [`content-visibility`](content-visibility) property css border-left-color border-left-color ================= The `border-left-color` CSS property sets the color of an element's left <border>. It can also be set with the shorthand CSS properties [`border-color`](border-color) or [`border-left`](border-left). Try it ------ Syntax ------ ``` /\* <color> values \*/ border-left-color: red; border-left-color: #ffbb00; border-left-color: rgb(255 0 0); border-left-color: hsl(100deg 50% 25% / 0.75); border-left-color: currentcolor; border-left-color: transparent; /\* Global values \*/ border-left-color: inherit; border-left-color: initial; border-left-color: revert; border-left-color: revert-layer; border-left-color: unset; ``` The `border-left-color` property is specified as a single value. ### Values [`<color>`](color_value) The color of the left border. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `currentcolor` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | computed color | | Animation type | a [color](color_value#interpolation) | Formal syntax ------------- ``` border-left-color = [<color>](color_value) ``` Examples -------- ### A simple div with a border #### HTML ``` <div class="mybox"> <p> This is a box with a border around it. Note which side of the box is <span class="redtext">red</span>. </p> </div> ``` #### CSS ``` .mybox { border: solid 0.3em gold; border-left-color: red; width: auto; } .redtext { color: red; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # border-color](https://w3c.github.io/csswg-drafts/css-backgrounds/#border-color) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-left-color` | 1 | 12 | 1 Firefox also supports the non-standard `-moz-border-left-colors` CSS property that sets the bottom border to multiple colors. | 4 | 3.5 | 1 | 4.4 | 18 | 4 Firefox also supports the non-standard `-moz-border-left-colors` CSS property that sets the bottom border to multiple colors. | 10.1 | 1 | 1.0 | See also -------- * The border-related CSS shorthand properties: [`border`](border), [`border-left`](border-left), and [`border-color`](border-color). * The color-related CSS properties for the other borders: [`border-right-color`](border-right-color), [`border-bottom-color`](border-bottom-color), and [`border-top-color`](border-top-color). * The other border-related CSS properties applying to the same border: [`border-left-style`](border-left-style) and [`border-left-width`](border-left-width). css page-break-after page-break-after ================ **Warning:** This property has been replaced by the [`break-after`](break-after) property. The `page-break-after` CSS property adjusts page breaks *after* the current element. ``` /\* Keyword values \*/ page-break-after: auto; page-break-after: always; page-break-after: avoid; page-break-after: left; page-break-after: right; page-break-after: recto; page-break-after: verso; /\* Global values \*/ page-break-after: inherit; page-break-after: initial; page-break-after: revert; page-break-after: revert-layer; page-break-after: unset; ``` This property applies to block elements that generate a box. It won't apply on an empty [`<div>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div) that won't generate a box. Syntax ------ ### Values `auto` Initial value. Automatic page breaks (neither forced nor forbidden). `always` Always force page breaks after the element. `avoid` Avoid page breaks after the element. `left` Force page breaks after the element so that the next page is formatted as 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` Force page breaks after the element so that the next page is formatted as 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` Experimental If pages progress left-to-right, then this acts like `right`. If pages progress right-to-left, then this acts like `left`. `verso` Experimental If pages progress left-to-right, then this acts like `left`. If pages progress right-to-left, then this acts like `right`. Page break aliases ------------------ The `page-break-after` property is now a legacy property, replaced by [`break-after`](break-after). For compatibility reasons, `page-break-after` 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` | Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | block-level elements in the normal flow of the root element. User agents may also apply it to other elements like `table-row` elements. | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` page-break-after = auto [|](value_definition_syntax#single_bar) always [|](value_definition_syntax#single_bar) avoid [|](value_definition_syntax#single_bar) left [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) inherit ``` Examples -------- ### Setting a page break after footnotes ``` /\* move to a new page after footnotes \*/ div.footnotes { page-break-after: always; } ``` Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # page](https://w3c.github.io/csswg-drafts/css-logical/#page) | | [CSS Paged Media Module Level 3 # page-break-after](https://w3c.github.io/csswg-drafts/css-page/#page-break-after) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `page-break-after` | 1 | 12 | 1 The values `avoid`, `left`, and `right` are unsupported. | 4 | 7 | 1.2 | 37 | 18 | 4 The values `avoid`, `left`, and `right` are unsupported. | 14 | 1 | 1.0 | See also -------- * [`break-before`](break-before), [`break-after`](break-after), [`break-inside`](break-inside) * [`page-break-before`](page-break-before), [`page-break-inside`](page-break-inside) * [`orphans`](orphans), [`widows`](widows)
programming_docs
css text-transform text-transform ============== The `text-transform` CSS property specifies how to capitalize an element's text. It can be used to make text appear in all-uppercase or all-lowercase, or with each word capitalized. It also can help improve legibility for ruby. Try it ------ The `text-transform` property takes into account language-specific case mapping rules such as the following: * In Turkic languages, like Turkish (`tr`), Azerbaijani (`az`), Crimean Tatar (`crh`), Volga Tatar (`tt`), and Bashkir (`ba`), there are two kinds of `i`, with and without the dot, and two case pairings: `i`/`İ` and `ı`/`I`. * In German (`de`), the `ß` becomes `SS` in uppercase. * In Dutch (`nl`), the `ij` digraph becomes `IJ`, even with `text-transform: capitalize`, which only puts the first letter of a word in uppercase. * In Greek (`el`), vowels lose their accent when the whole word is in uppercase (`ά`/`Α`), except for the disjunctive eta (`ή`/`Ή`). Also, diphthongs with an accent on the first vowel lose the accent and gain a diaeresis on the second vowel (`άι`/`ΑΪ`). * In Greek (`el`), the lowercase sigma character has two forms: `σ` and `ς`. `ς` is used only when sigma terminates a word. When applying `text-transform: lowercase` to an uppercase sigma (`Σ`), the browser needs to choose the right lowercase form based on context. * in Irish (`ga`), certain prefixed letters remain in lowercase when the base initial is capitalized, so for example `text-transform: uppercase` will change `ar aon tslí` to `AR AON tSLÍ` and not, as one might expect, `AR AON TSLÍ` (Firefox only). In some cases, a hyphen is also removed upon uppercasing: `an t-uisce` transforms to `AN tUISCE` (and the hyphen is correctly reinserted by `text-transform: lowercase`). The language is defined by the [`lang`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang) HTML attribute or the [`xml:lang`](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/xml:lang) XML attribute. **Note:** Support for language-specific cases varies between browsers, so check the [browser compatibility table](#browser_compatibility). Syntax ------ ``` /\* Keyword values \*/ text-transform: none; text-transform: capitalize; text-transform: uppercase; text-transform: lowercase; text-transform: full-width; text-transform: full-size-kana; /\* Global values \*/ text-transform: inherit; text-transform: initial; text-transform: revert; text-transform: revert-layer; text-transform: unset; ``` `capitalize` Is a keyword that converts the first *letter* of each word to uppercase. Other characters remain unchanged (they retain their original case as written in the element's text). A letter is defined as a character that is part of Unicode's Letter or Number general categories Experimental ; thus, any punctuation marks or symbols at the beginning of a word are ignored. **Note:** Authors should not expect `capitalize` to follow language-specific title casing conventions (such as skipping articles in English). **Note:** The `capitalize` keyword was under-specified in CSS 1 and CSS 2.1. This resulted in differences between browsers in the way the first letter was calculated (Firefox considered `-` and `_` as letters, but other browsers did not. Both Webkit and Gecko incorrectly considered letter-based symbols like `ⓐ` to be real letters. Internet Explorer 9 was the closest to the CSS 2 definition, but with some weird cases.) By precisely defining the correct behavior, CSS Text Level 3 cleans this mess up. The `capitalize` line in the browser compatibility table contains the version the different engines started to support this now precisely-defined behavior. `uppercase` Is a keyword that converts all characters to uppercase. `lowercase` Is a keyword that converts all characters to lowercase. `none` Is a keyword that prevents the case of all characters from being changed. `full-width` Is a keyword that forces the writing of a character — mainly ideograms and Latin scripts — inside a square, allowing them to be aligned in the usual East Asian scripts (like Chinese or Japanese). `full-size-kana` Generally used for [`<ruby>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ruby) annotation text, the keyword converts all small Kana characters to the equivalent full-size Kana, to compensate for legibility issues at the small font sizes typically used in ruby. Accessibility concerns ---------------------- Large sections of text set with a `text-transform` value of `uppercase` may be difficult for people with cognitive concerns such as Dyslexia to read. * [MDN Understanding WCAG, Guideline 1.4 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background) * [W3C Understanding WCAG 2.1](https://www.w3.org/TR/WCAG21/#visual-presentation) Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` text-transform = none [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) capitalize [|](value_definition_syntax#single_bar) uppercase [|](value_definition_syntax#single_bar) lowercase []](value_definition_syntax#brackets) [||](value_definition_syntax#double_bar) full-width [||](value_definition_syntax#double_bar) full-size-kana [|](value_definition_syntax#single_bar) math-auto [|](value_definition_syntax#single_bar) math-bold [|](value_definition_syntax#single_bar) math-italic [|](value_definition_syntax#single_bar) math-bold-italic [|](value_definition_syntax#single_bar) math-double-struck [|](value_definition_syntax#single_bar) math-bold-fraktur [|](value_definition_syntax#single_bar) math-script [|](value_definition_syntax#single_bar) math-bold-script [|](value_definition_syntax#single_bar) math-fraktur [|](value_definition_syntax#single_bar) math-sans-serif [|](value_definition_syntax#single_bar) math-bold-sans-serif [|](value_definition_syntax#single_bar) math-sans-serif-italic [|](value_definition_syntax#single_bar) math-sans-serif-bold-italic [|](value_definition_syntax#single_bar) math-monospace [|](value_definition_syntax#single_bar) math-initial [|](value_definition_syntax#single_bar) math-tailed [|](value_definition_syntax#single_bar) math-looped [|](value_definition_syntax#single_bar) math-stretched ``` Examples -------- ### Example using "none" ``` <p> Initial String <strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit…</strong> </p> <p> text-transform: none <strong><span>Lorem ipsum dolor sit amet, consectetur adipisicing elit…</span></strong> </p> ``` ``` span { text-transform: none; } strong { float: right; } ``` This demonstrates no text transformation. ### Example using "capitalize" (general) ``` <p> Initial String <strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit…</strong> </p> <p> text-transform: capitalize <strong><span>Lorem ipsum dolor sit amet, consectetur adipisicing elit…</span></strong> </p> ``` ``` span { text-transform: capitalize; } strong { float: right; } ``` This demonstrates text capitalization. ### Example using "capitalize" (punctuation) ``` <p> Initial String <strong>(this) "is" [a] –short– -test- «for» *the* _css_ ¿capitalize? ?¡transform!</strong> </p> <p> text-transform: capitalize <strong><span>(this) "is" [a] –short– -test- «for» *the* _css_ ¿capitalize? ?¡transform!</span></strong> </p> ``` ``` span { text-transform: capitalize; } strong { float: right; } ``` This demonstrates how initial punctuations of a word are ignored. The keyword target the first letter, that is the first Unicode character part of the Letter or Number general category. ### Example using "capitalize" (Symbols) ``` <p> Initial String <strong>ⓐⓑⓒ (ⓓⓔⓕ) —ⓖⓗⓘ— ⓙkl</strong> </p> <p> text-transform: capitalize <strong><span>ⓐⓑⓒ (ⓓⓔⓕ) —ⓖⓗⓘ— ⓙkl</span></strong> </p> ``` ``` span { text-transform: capitalize; } strong { float: right; } ``` This demonstrates how initial symbols are ignored. The keyword target the first letter, that is the first Unicode character part of the Letter or Number general category. ### Example using "capitalize" (Dutch ij digraph) ``` <p> Initial String <strong lang="nl">The Dutch word: "ijsland" starts with a digraph.</strong> </p> <p> text-transform: capitalize <strong><span lang="nl">The Dutch word: "ijsland" starts with a digraph.</span></strong> </p> ``` ``` span { text-transform: capitalize; } strong { float: right; } ``` This demonstrates how the Dutch *ij* digraph must be handled like one single letter. ### Example using "uppercase" (general) ``` <p> Initial String <strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit…</strong> </p> <p> text-transform: uppercase <strong><span>Lorem ipsum dolor sit amet, consectetur adipisicing elit…</span></strong> </p> ``` ``` span { text-transform: uppercase; } strong { float: right; } ``` This demonstrates transforming the text to uppercase. ### Example using "uppercase" (Greek vowels) ``` <p> Initial String <strong>Θα πάμε στο "Θεϊκό φαΐ" ή στη "Νεράιδα"</strong> </p> <p> text-transform: uppercase <strong><span lang="el">Θα πάμε στο "Θεϊκό φαΐ" ή στη "Νεράιδα"</span></strong> </p> ``` ``` span { text-transform: uppercase; } strong { float: right; } ``` This demonstrates how Greek vowels except disjunctive *eta* should have no accent, and the accent on the first vowel of a vowel pair becomes a diaeresis on the second vowel. ### Example using "lowercase" (general) ``` <p> Initial String <strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit…</strong> </p> <p> text-transform: lowercase <strong><span>Lorem ipsum dolor sit amet, consectetur adipisicing elit…</span></strong> </p> ``` ``` span { text-transform: lowercase; } strong { float: right; } ``` This demonstrates transforming the text to lowercase. ### Example using "lowercase" (Greek Σ) ``` <p> Initial String <strong>Σ IS A greek LETTER that appears SEVERAL TIMES IN ΟΔΥΣΣΕΥΣ.</strong> </p> <p> text-transform: lowercase <strong><span>Σ IS A greek LETTER that appears SEVERAL TIMES IN ΟΔΥΣΣΕΥΣ.</span></strong> </p> ``` ``` span { text-transform: lowercase; } strong { float: right; } ``` This demonstrates how the Greek character sigma (`Σ`) is transformed into the regular lowercase sigma (`σ`) or the word-final variant (`ς`), according the context. ### Example using "lowercase" (Lithuanian) ``` <p> Initial String <strong>Ĩ is a Lithuanian LETTER as is J́</strong> </p> <p> text-transform: lowercase <strong><span lang="lt">Ĩ is a Lithuanian LETTER as is J́</span></strong> </p> ``` ``` span { text-transform: lowercase; } strong { float: right; } ``` This demonstrates how the Lithuanian letters `Ĩ` and `J́` retain their dot when transformed to lowercase. ### Example using "full-width" (general) ``` <p> Initial String <strong>0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&()*+,-./:;<=>?@{|}~</strong> </p> <p> text-transform: full-width <strong><span>0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&()*+,-./:;<=>?@{|}~</span></strong> </p> ``` ``` span { text-transform: full-width; } strong { width: 100%; float: right; } ``` Some characters exist in two formats: normal width and a full-width, with different Unicode code points. The full-width version is used to mix them smoothly with Asian ideographic characters. ### Example using "full-width" (Japanese half-width katakana) ``` <p> Initial String <strong>ウェブプログラミングの勉強</strong> </p> <p> text-transform: full-width <strong><span>ウェブプログラミングの勉強</span></strong> </p> ``` ``` span { text-transform: full-width; } strong { width: 100%; float: right; } ``` The Japanese half-width katakana was used to represent katakana in 8-bit character codes. Unlike regular (full-width) katakana characters, a letter with dakuten (voiced sound mark) is represented as two code points, the body of letter and dakuten. The `full-width` combines these into a single code point when converting these characters into full-width. ### Example using "full-size-kana" ``` <p>ァィゥェ ォヵㇰヶ ㇱㇲッㇳ ㇴㇵㇶㇷ ㇸㇹㇺャ ュョㇻㇼ ㇽㇾㇿヮ</p> <p>ァィゥェ ォヵㇰヶ ㇱㇲッㇳ ㇴㇵㇶㇷ ㇸㇹㇺャ ュョㇻㇼ ㇽㇾㇿヮ</p> </p> ``` ``` p:nth-of-type(2) { text-transform: full-size-kana; } ``` Specifications -------------- | Specification | | --- | | [CSS Text Module Level 3 # text-transform](https://w3c.github.io/csswg-drafts/css-text/#text-transform) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `text-transform` | 1 The `text-transform` property does not work for `::first-line` pseudo-elements (nor for the one-colon syntax). See [Chromium bug 129669](https://crbug.com/129669). | 12 | 1 | 4 | 7 Since Opera 15, the `text-transform` property does not work for `::first-line` pseudo-elements (nor for the one-colon syntax). See [Chromium bug 129669](https://crbug.com/129669). | 1 The `text-transform` property does not work for `::first-line` pseudo-elements (also not for the old one-colon syntax). See [WebKit bug 3409](https://webkit.org/b/3409). | 4.4 The `text-transform` property does not work for `::first-line` pseudo-elements (nor for the one-colon syntax). See [Chromium bug 129669](https://crbug.com/129669). | 18 The `text-transform` property does not work for `::first-line` pseudo-elements (nor for the one-colon syntax). See [Chromium bug 129669](https://crbug.com/129669). | 4 | 11 | 1 The `text-transform` property does not work for `::first-line` pseudo-elements (also not for the old one-colon syntax). See [WebKit bug 3409](https://webkit.org/b/3409). | 1.0 The `text-transform` property does not work for `::first-line` pseudo-elements (nor for the one-colon syntax). See [Chromium bug 129669](https://crbug.com/129669). | | `capitalize` | 1 | 12 | 1 Before Firefox 14, some punctuation characters could interfere with correct capitalization. See [bug 731536](https://bugzil.la/731536). | 4 | 7 | 1 | 4.4 | 18 | 4 Before Firefox 14, some punctuation characters could interfere with correct capitalization. See [bug 731536](https://bugzil.la/731536). | 11 | 1 | 1.0 | | `dutch_ij_digraph` | No | No | 14 | No | No | No | No | No | 14 | No | No | No | | `full-size-kana` | No | No | 64 | No | No | No | No | No | 64 | No | No | No | | `full-width` | No | No | 19 | No | No | No | No | No | 19 | No | No | No | | `greek_accented_characters` | 34 | 79 | 15 | No | 21 | No | 4.4 | 34 | 15 | 21 | No | 2.0 | | `lowercase_sigma` | 30 | 12 | 14 | 4 | 17 | 6 | 4.4 | 30 | 14 | 18 | 6 | 2.0 | | `math-auto` | 84 | 84 | No | No | 70 | No | No | 84 | No | No | No | No | | `turkic_is` | 31 | 12 | 14 | 4 | 18 | 8 | 4.4.3 | 31 | 14 | 18 | 8 | 2.0 | | `uppercase_eszett` | 1 | 18 | 1 | No | 7 | 1 | 4.4 | 18 | 4 | 11 | 1 | 1.0 | See also -------- * [`font-variant`](font-variant) css scrollbar-color scrollbar-color =============== The `scrollbar-color` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the color of the scrollbar track and thumb. The **track** refers to the background of the scrollbar, which is generally fixed regardless of the scrolling position. The **thumb** refers to the moving part of the scrollbar, which usually floats on top of the track. Syntax ------ ``` /\* Keyword values \*/ scrollbar-color: auto; /\* <color> values \*/ scrollbar-color: rebeccapurple green; /\* Two valid colors. The first applies to the thumb of the scrollbar, the second to the track. \*/ /\* Global values \*/ scrollbar-color: inherit; scrollbar-color: initial; scrollbar-color: revert; scrollbar-color: revert-layer; scrollbar-color: unset; ``` ### Values `<scrollbar-color>` Defines the color of the scrollbar. | | | | --- | --- | | `auto` | Default platform rendering for the track portion of the scrollbar, in the absence of any other related scrollbar color properties. | | `<color> <color>` | Applies the first color to the scrollbar thumb, the second to the scrollbar track. | **Note:** User Agents must apply any `scrollbar-color` value set on the root element to the viewport. Accessibility concerns ---------------------- When using `scrollbar-color` property with specific color values, authors should ensure the specified colors have enough contrast between them. For keyword values, UAs should ensure the colors they use have enough contrast. See [Techniques for WCAG 2.0: G183: Using a contrast ratio of 3:1](https://www.w3.org/TR/WCAG20-TECHS/G183.html). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | scrolling boxes | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | a [color](color_value#interpolation) | Formal syntax ------------- ``` scrollbar-color = auto [|](value_definition_syntax#single_bar) [<color>](color_value)[{2}](value_definition_syntax#curly_braces) ``` Examples -------- ### Coloring overflow scrollbars #### CSS ``` .scroller { width: 300px; height: 100px; overflow-y: scroll; scrollbar-color: rebeccapurple green; } ``` #### HTML ``` <div class="scroller"> Veggies es bonus vobis, proinde vos postulo essum magis kohlrabi welsh onion daikon amaranth tatsoi tomatillo melon azuki bean garlic. Gumbo beet greens corn soko endive gumbo gourd. Parsley shallot courgette tatsoi pea sprouts fava bean collard greens dandelion okra wakame tomato. Dandelion cucumber earthnut pea peanut soko zucchini. </div> ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Scrollbars Styling Module Level 1 # scrollbar-color](https://w3c.github.io/csswg-drafts/css-scrollbars/#scrollbar-color) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scrollbar-color` | No See [bug 891944](https://crbug.com/891944). | No See [bug 891944](https://crbug.com/891944). | 64 On macOS, you need to set the *General* > *Show scroll bars* setting in System Preferences to "Always" for this property to have any effect. | No | No See [bug 891944](https://crbug.com/891944). | No See [bug 231590](https://webkit.org/b/231590). | No See [bug 891944](https://crbug.com/891944). | No See [bug 891944](https://crbug.com/891944). | 64 | No See [bug 891944](https://crbug.com/891944). | No See [bug 231590](https://webkit.org/b/231590). | No See [bug 891944](https://crbug.com/891944). | See also -------- * [`scrollbar-width`](scrollbar-width) * [`overflow`](overflow)
programming_docs
css transition-property transition-property =================== The `transition-property` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the CSS properties to which a [transition effect](css_transitions/using_css_transitions) should be applied. Try it ------ **Note:** The [set of properties that can be animated](css_animated_properties) is subject to change. As such, you should avoid including any properties in the list that don't currently animate, as someday they might, causing unexpected results. If you specify a shorthand property (e.g., [`background`](background)), all of its longhand sub-properties that can be animated will be. Syntax ------ ``` /\* Keyword values \*/ transition-property: none; transition-property: all; /\* <custom-ident> values \*/ transition-property: test_05; transition-property: -specific; transition-property: sliding-vertically; /\* Multiple values \*/ transition-property: test1, animation4; transition-property: all, height, color; transition-property: all, -moz-specific, sliding; /\* Global values \*/ transition-property: inherit; transition-property: initial; transition-property: revert; transition-property: revert-layer; transition-property: unset; ``` ### Values `none` No properties will transition. `all` All properties that can transition will. [`<custom-ident>`](custom-ident) A string identifying the property to which a transition effect should be applied when its value changes. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | all | | Applies to | all elements, [`::before`](::before) and [`::after`](::after) <pseudo-elements> | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` transition-property = none [|](value_definition_syntax#single_bar) <single-transition-property>[#](value_definition_syntax#hash_mark) <single-transition-property> = all [|](value_definition_syntax#single_bar) [<custom-ident>](custom-ident) ``` Examples -------- ### Simple example This example performs a four-second font size transition when the user hovers over the element, the `transition-property` is the `font-size`. #### HTML ``` <a class="target">Hover over me</a> ``` #### CSS ``` .target { font-size: 14px; transition-property: font-size; transition-duration: 4s; } .target:hover { font-size: 36px; } ``` You will find more examples of `transition-property` included in the main [CSS transitions](css_transitions/using_css_transitions) article. Specifications -------------- | Specification | | --- | | [CSS Transitions # transition-property-property](https://w3c.github.io/csswg-drafts/css-transitions/#transition-property-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `IDENT_value` | 1 | 12 | 16 | 10 | 15 | 4 | ≤37 | 18 | 16 | 14 | 3 | 1.0 | | `transition-property` | 26 1 | 12 12 | 49 16 4 | 10 10 | 15 12.1 11.6-15 | 9 3.1 | ≤37 4.4 | 26 18 | 49 16 4 | 14 12.1 12-14 | 9 2 | 1.5 1.0 | See also -------- * [Using CSS transitions](css_transitions/using_css_transitions) * [`transition`](transition) * [`transition-duration`](transition-duration) * [`transition-timing-function`](transition-timing-function) * [`transition-delay`](transition-delay) * [`TransitionEvent`](https://developer.mozilla.org/en-US/docs/Web/API/TransitionEvent) css columns columns ======= The `columns` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) shorthand property sets the number of columns to use when drawing an element's contents, as well as those columns' widths. Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`column-count`](column-count) * [`column-width`](column-width) Syntax ------ ``` /\* Column width \*/ columns: 18em; /\* Column count \*/ columns: auto; columns: 2; /\* Both column width and count \*/ columns: 2 auto; columns: auto 12em; columns: auto auto; /\* Global values \*/ columns: inherit; columns: initial; columns: revert; columns: revert-layer; columns: unset; ``` The `columns` property may be specified as one or two of the values listed below, in any order. ### Values `<'column-width'>` The ideal column width, defined as a [`<length>`](length) or the keyword `auto`. The actual width may be wider or narrower to fit the available space. See [`column-width`](column-width). `<'column-count'>` The ideal number of columns into which the element's content should be flowed, defined as an [`<integer>`](integer) or the keyword `auto`. If neither this value nor the column's width are `auto`, it merely indicates the maximum allowable number of columns. See [`column-count`](column-count). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`column-width`](column-width): `auto` * [`column-count`](column-count): `auto` | | Applies to | Block containers except table wrapper boxes | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`column-width`](column-width): the absolute length, zero or larger * [`column-count`](column-count): as specified | | Animation type | as each of the properties of the shorthand:* [`column-width`](column-width): a [length](length#interpolation) * [`column-count`](column-count): an [integer](integer#interpolation) | Formal syntax ------------- ``` columns = <'column-width'> [||](value_definition_syntax#double_bar) <'column-count'> ``` Examples -------- ### Setting three equal columns #### HTML ``` <p class="content-box"> This is a bunch of text split into three columns using the CSS `columns` property. The text is equally distributed over the columns. </p> ``` #### CSS ``` .content-box { columns: 3 auto; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Multi-column Layout Module Level 1 # columns](https://w3c.github.io/csswg-drafts/css-multicol/#columns) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `columns` | 50 50 | 12 12 | 52 9-74 Before version 37, multiple columns didn't work with `display: table-caption` elements. | 10 | 15 11.1 | 9 3 | 50 2 | 50 | 52 22 Before version 37, multiple columns didn't work with `display: table-caption` elements. | 14 11.1 | 9 3.2 | 5.0 | See also -------- * [`widows`](widows) * [`orphans`](orphans) * [Paged media](https://developer.mozilla.org/en-US/docs/Web/CSS/Paged_Media) * [Multiple-column Layout](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Multiple-column_Layout) css :current :current ======== The `:current` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) selector is a time-dimensional pseudo-class that represents an element or the ancestor of an element that is currently being displayed. For example, this pseudo-class can be used to represent a video that is being displayed with captions by [WebVTT](https://developer.mozilla.org/en-US/docs/Web/API/WebVTT_API). ``` :current(p, span) { background-color: yellow; } ``` Syntax ------ Error: could not find syntax for this itemExamples -------- ### CSS ``` :current(p, span) { background-color: yellow; } ``` ### HTML ``` <video controls preload="metadata"> <source src="video.mp4" type="video/mp4" /> <source src="video.webm" type="video/webm" /> <track label="English" kind="subtitles" srclang="en" src="subtitles.vtt" default> </video> ``` ### WebVTT ``` WEBVTT FILE 1 00:00:03.500 --> 00:00:05.000 This is the first caption 2 00:00:06.000 --> 00:00:09.000 This is the second caption 3 00:00:11.000 --> 00:00:19.000 This is the third caption ``` Specifications -------------- **No specification found**No specification data found for `css.selectors.current`. [Check for problems with this page](#on-github) or contribute a missing `spec_url` to [mdn/browser-compat-data](https://github.com/mdn/browser-compat-data). Also make sure the specification is included in [w3c/browser-specs](https://github.com/w3c/browser-specs). Browser compatibility --------------------- No compatibility data found for `css.selectors.current`. [Check for problems with this page](#on-github) or contribute missing data to [mdn/browser-compat-data](https://github.com/mdn/browser-compat-data). See also -------- * [Web Video Text Tracks Format (WebVTT)](https://developer.mozilla.org/en-US/docs/Web/API/WebVTT_API) * [`:past`](:past) * [`:future`](:future) css border-left-width border-left-width ================= The `border-left-width` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the width of the left border of an element. Try it ------ Syntax ------ ``` /\* Keyword values \*/ border-left-width: thin; border-left-width: medium; border-left-width: thick; /\* <length> values \*/ border-left-width: 10em; border-left-width: 3vmax; border-left-width: 6px; /\* Global keywords \*/ border-left-width: inherit; border-left-width: initial; border-left-width: revert; border-left-width: revert-layer; border-left-width: unset; ``` ### Values `<line-width>` Defines the width of the border, either as an explicit nonnegative [`<length>`](length) or a keyword. If it's a keyword, it must be one of the following values: * `thin` * `medium` * `thick` **Note:** Because the specification doesn't define the exact thickness denoted by each keyword, the precise result when using one of them is implementation-specific. Nevertheless, they always follow the pattern `thin ≤ medium ≤ thick`, and the values are constant within a single document. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `medium` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | the absolute length or `0` if [`border-left-style`](border-left-style) is `none` or `hidden` | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` border-left-width = <line-width> <line-width> = [<length [0,∞]>](length) [|](value_definition_syntax#single_bar) thin [|](value_definition_syntax#single_bar) medium [|](value_definition_syntax#single_bar) thick ``` Examples -------- ### Comparing border widths #### HTML ``` <div>Element 1</div> <div>Element 2</div> ``` #### CSS ``` div { border: 1px solid red; margin: 1em 0; } div:nth-child(1) { border-left-width: thick; } div:nth-child(2) { border-left-width: 2em; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # the-border-width](https://w3c.github.io/csswg-drafts/css-backgrounds/#the-border-width) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-left-width` | 1 | 12 | 1 | 4 | 3.5 | 1 | 2.2 | 18 | 4 | 10.1 | 1 | 1.0 | See also -------- * The other border-width-related CSS properties: [`border-top-width`](border-top-width), [`border-right-width`](border-right-width), [`border-bottom-width`](border-bottom-width), and [`border-width`](border-width). * The other border-left-related CSS properties: [`border`](border), [`border-left`](border-left), [`border-left-style`](border-left-style), and [`border-left-color`](border-left-color). css grid-auto-columns grid-auto-columns ================= The `grid-auto-columns` CSS property specifies the size of an implicitly-created grid column [track](https://developer.mozilla.org/en-US/docs/Glossary/Grid_Tracks) or pattern of tracks. Try it ------ If a grid item is positioned into a column that is not explicitly sized by [`grid-template-columns`](grid-template-columns), implicit [grid](https://developer.mozilla.org/en-US/docs/Glossary/Grid) tracks are created to hold it. This can happen either by explicitly positioning into a column that is out of range, or by the auto-placement algorithm creating additional columns. Syntax ------ ``` /\* Keyword values \*/ grid-auto-columns: min-content; grid-auto-columns: max-content; grid-auto-columns: auto; /\* <length> values \*/ grid-auto-columns: 100px; grid-auto-columns: 20cm; grid-auto-columns: 50vmax; /\* <percentage> values \*/ grid-auto-columns: 10%; grid-auto-columns: 33.3%; /\* <flex> values \*/ grid-auto-columns: 0.5fr; grid-auto-columns: 3fr; /\* minmax() values \*/ grid-auto-columns: minmax(100px, auto); grid-auto-columns: minmax(max-content, 2fr); grid-auto-columns: minmax(20%, 80vmax); /\* fit-content() values \*/ grid-auto-columns: fit-content(400px); grid-auto-columns: fit-content(5cm); grid-auto-columns: fit-content(20%); /\* multiple track-size values \*/ grid-auto-columns: min-content max-content auto; grid-auto-columns: 100px 150px 390px; grid-auto-columns: 10% 33.3%; grid-auto-columns: 0.5fr 3fr 1fr; grid-auto-columns: minmax(100px, auto) minmax(max-content, 2fr) minmax(20%, 80vmax); grid-auto-columns: 100px minmax(100px, auto) 10% 0.5fr fit-content(400px); /\* Global values \*/ grid-auto-columns: inherit; grid-auto-columns: initial; grid-auto-columns: revert; grid-auto-columns: revert-layer; grid-auto-columns: unset; ``` ### Values [`<length>`](length) Is a non-negative length. [`<percentage>`](percentage) Is a non-negative [`<percentage>`](percentage) value relative to the block size of the grid container. If the block size of the grid container is indefinite, the percentage value is treated like `auto`. [`<flex>`](flex_value) 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>)`). [`max-content`](max-content) Is a keyword representing the largest maximal content contribution of the grid items occupying the grid track. [`min-content`](min-content) Is a keyword representing the largest minimal content contribution of the grid items occupying the grid track. [`minmax(min, max)`](minmax) 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. As a minimum, it is treated as zero (or minimal content, if the grid container is sized under a minimal content constraint). [`fit-content( [ <length> | <percentage> ] )`](fit-content_function) 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. `auto` Is a keyword that is identical to maximal content if it's a maximum. As a minimum it represents the largest minimum size (as specified by [`min-width`](min-width)/[`min-height`](min-height)) of the grid items occupying the grid track. **Note:** `auto` track sizes (and only `auto` track sizes) can be stretched by the [`align-content`](align-content) and [`justify-content`](justify-content) properties. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | grid containers | | [Inherited](inheritance) | no | | Percentages | refer to corresponding dimension of the content area | | [Computed value](computed_value) | the percentage as specified or the absolute length | | Animation type | discrete | Formal syntax ------------- ``` grid-auto-columns = <track-size>[+](value_definition_syntax#plus) <track-size> = <track-breadth> [|](value_definition_syntax#single_bar) minmax( <inflexible-breadth> , <track-breadth> ) [|](value_definition_syntax#single_bar) fit-content( <length-percentage> ) <track-breadth> = <length-percentage> [|](value_definition_syntax#single_bar) [<flex>](flex) [|](value_definition_syntax#single_bar) min-content [|](value_definition_syntax#single_bar) max-content [|](value_definition_syntax#single_bar) auto <inflexible-breadth> = <length-percentage> [|](value_definition_syntax#single_bar) min-content [|](value_definition_syntax#single_bar) max-content [|](value_definition_syntax#single_bar) auto <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Setting grid column size #### HTML ``` <div id="grid"> <div id="item1"></div> <div id="item2"></div> <div id="item3"></div> </div> ``` #### CSS ``` #grid { height: 100px; display: grid; grid-template-areas: "a a"; gap: 10px; grid-auto-columns: 200px; } #grid > div { background-color: lime; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Grid Layout Module Level 2 # auto-tracks](https://w3c.github.io/csswg-drafts/css-grid/#auto-tracks) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `grid-auto-columns` | 57 | 16 12-79 | 70 52-70 Does not accept multiple track-size values. See [bug 1339672](https://bugzil.la/1339672). | 10 | 44 | 10.1 | 57 | 57 | 79 52-79 Does not accept multiple track-size values. See [bug 1339672](https://bugzil.la/1339672). | 43 | 10.3 | 6.0 | See also -------- * Related CSS properties: [`grid-auto-rows`](grid-auto-rows), [`grid-auto-flow`](grid-auto-flow), [`grid`](grid) * Grid Layout Guide: *[Auto-placement in grid layout - sizing rows in the implicit grid](css_grid_layout/auto-placement_in_css_grid_layout#sizing_rows_in_the_implicit_grid)* * Video tutorial: *[Introducing Grid auto-placement and order](https://gridbyexample.com/video/series-auto-placement-order/)* css <string> <string> ======== The `<string>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) represents a sequence of characters. Strings are used in numerous CSS properties, such as [`content`](content), [`font-family`](font-family), and [`quotes`](quotes). Syntax ------ The `<string>` data type is composed of any number of [Unicode](https://en.wikipedia.org/wiki/Unicode) characters surrounded by either double (`"`) or single (`'`) quotes. Most characters can be represented literally. All characters can also be represented with their respective [Unicode code points](https://en.wikipedia.org/wiki/Unicode#Code_point_planes_and_blocks) in hexadecimal, in which case they are preceded by a backslash (`\`). For example, `\22` represents a double quote, `\27` a single quote (`'`), and `\A9` the copyright symbol (`©`). Importantly, certain characters which would otherwise be invalid can be escaped with a backslash. These include double quotes when used inside a double-quoted string, single quotes when used inside a single-quoted string, and the backslash itself. For example, `\\` will create a single backslash. To output new lines, you must escape them with a line feed character such as `\A` or `\00000A`. In your code, however, strings can span multiple lines, in which case each new line must be escaped with a `\` as the last character of the line. However, to get new lines, you must also set the [`white-space`](white-space) property to appropriate value. **Note:** [HTML entities](https://developer.mozilla.org/en-US/docs/Glossary/Entity) (such as `&nbsp;` or `&#8212;`) cannot be used in a CSS `<string>`. Examples -------- ### Examples of valid strings ``` /\* Simple strings \*/ "This string is demarcated by double quotes." 'This string is demarcated by single quotes.' /\* Character escaping \*/ "This is a string with \" an escaped double quote." "This string also has \22 an escaped double quote." 'This is a string with \' an escaped single quote.' 'This string also has \27 an escaped single quote.' "This is a string with \\ an escaped backslash." /\* New line in a string \*/ "This string has a \Aline break in it." /\* String spanning two lines of code (these two strings will have identical output) \*/ "A really long \ awesome string" "A really long awesome string" ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # strings](https://w3c.github.io/csswg-drafts/css-values/#strings) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `string` | 1 | 12 | 1 | 3 | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | | `unicode_escaped_characters` | 1 | 12 | 1 | 6 | 7 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | See also -------- * [CSS Units and Values](css_values_and_units) * [CSS Basic Data Types](css_types) * [Introduction to CSS: Values and Units](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units)
programming_docs
css font-variant-alternates font-variant-alternates ======================= The `font-variant-alternates` CSS property controls the usage of alternate glyphs. These alternate glyphs may be referenced by alternative names defined in [`@font-feature-values`](@font-feature-values). ``` /\* Keyword values \*/ font-variant-alternates: normal; font-variant-alternates: historical-forms; /\* Functional notation values \*/ font-variant-alternates: stylistic(user-defined-ident); font-variant-alternates: styleset(user-defined-ident); font-variant-alternates: character-variant(user-defined-ident); font-variant-alternates: swash(user-defined-ident); font-variant-alternates: ornaments(user-defined-ident); font-variant-alternates: annotation(user-defined-ident); font-variant-alternates: swash(ident1) annotation(ident2); /\* Global values \*/ font-variant-alternates: inherit; font-variant-alternates: initial; font-variant-alternates: revert; font-variant-alternates: revert-layer; font-variant-alternates: unset; ``` The [`@font-feature-values`](@font-feature-values) at-rule can define names for alternative glyph functions (`stylistic`, `styleset`, `character-variant`, `swash`, `ornament` or `annotation`), associating the name with OpenType parameters. This property allows those human-readable names (defined in [`@font-feature-values`](@font-feature-values)) in the stylesheet. Syntax ------ This property may take one of two forms: * either the keyword `normal` * or one or more of the other keywords and functions listed below, space-separated, in any order. ### Values `normal` This keyword deactivates alternate glyphs. `historical-forms` This keyword enables historical forms — glyphs that were common in the past but not today. It corresponds to the OpenType value `hist`. `stylistic()` This function enables stylistic alternates for individual characters. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `salt`, like `salt 2`. `styleset()` This function enables stylistic alternatives for sets of characters. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `ssXY`, like `ss02`. `character-variant()` This function enables specific stylistic alternatives for characters. It is similar to `styleset()`, but doesn't create coherent glyphs for a set of characters; individual characters will have independent and not necessarily coherent styles. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `cvXY`, like `cv02`. `swash()` This function enables [swash](https://en.wikipedia.org/wiki/Swash_%28typography%29) glyphs. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType values `swsh` and `cswh`, like `swsh 2` and `cswh 2`. `ornaments()` This function enables ornaments, like [fleurons](https://en.wikipedia.org/wiki/Fleuron_%28typography%29) and other dingbat glyphs. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `ornm`, like `ornm 2`. **Note:** In order to preserve text semantics, font designers should include ornaments that don't match Unicode dingbat characters as ornamental variants of the bullet character (U+2022). Be aware that some existing fonts don't follow this advice. `annotation()` This function enables annotations, like circled digits or inverted characters. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `nalt`, like `nalt 2`. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` font-variant-alternates = normal [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) stylistic( <feature-value-name> ) [||](value_definition_syntax#double_bar) historical-forms [||](value_definition_syntax#double_bar) styleset( <feature-value-name>[#](value_definition_syntax#hash_mark) ) [||](value_definition_syntax#double_bar) character-variant( <feature-value-name>[#](value_definition_syntax#hash_mark) ) [||](value_definition_syntax#double_bar) swash( <feature-value-name> ) [||](value_definition_syntax#double_bar) ornaments( <feature-value-name> ) [||](value_definition_syntax#double_bar) annotation( <feature-value-name> ) []](value_definition_syntax#brackets) <feature-value-name> = [<ident>](ident) ``` Examples -------- ### Enabling swash glyphs #### HTML ``` <p> A Fancy Swash</p> <p class="variant"> A Fancy Swash</p> ``` #### CSS ``` @font-face { font-family: MonteCarlo; src: url(MonteCarlo-Regular.ttf); } @font-feature-values "MonteCarlo" { @swash { fancy: 1; } } p { font-family: "MonteCarlo"; font-size: 1.5rem; } .variant { font-feature-settings: "swsh" 1; font-variant-alternates: swash(fancy); } ``` **Note:** For this example to work you need to load the MonteCarlo font which is licensed under the [SIL Open Font License Version 1.1](http://scripts.sil.org/OFL). Download at <https://github.com/googlefonts/monte-carlo>. More fonts are available in the [Google Font corpus](https://github.com/google/fonts). However, note that fonts loaded from Google Fonts directly (for example, using `@import url("https://fonts.googleapis.com/css2?family=MonteCarlo");`) won't work. Google Fonts hosted fonts seem to strip the swash feature. Specifications -------------- | Specification | | --- | | [CSS Fonts Module Level 4 # font-variant-alternates-prop](https://w3c.github.io/csswg-drafts/css-fonts/#font-variant-alternates-prop) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `font-variant-alternates` | No See [bug 716567](https://crbug.com/716567). | No See [bug 716567](https://crbug.com/716567). | 34 | No | No See [bug 716567](https://crbug.com/716567). | 9.1 | No See [bug 716567](https://crbug.com/716567). | No See [bug 716567](https://crbug.com/716567). | 34 | No See [bug 716567](https://crbug.com/716567). | 9.3 | No See [bug 716567](https://crbug.com/716567). | | `annotation` | No | No | 34 | No | No | preview | No | No | 34 | No | No | No | | `character_variant` | No | No | 34 | No | No | preview | No | No | 34 | No | No | No | | `ornaments` | No | No | 34 | No | No | preview | No | No | 34 | No | No | No | | `styleset` | No | No | 34 | No | No | preview | No | No | 34 | No | No | No | | `stylistic` | No | No | 34 | No | No | preview | No | No | 34 | No | No | No | | `swash` | No | No | 34 | No | No | preview | No | No | 34 | No | No | No | See also -------- * [`font-variant`](font-variant) * [`font-variant-caps`](font-variant-caps) * [`font-variant-east-asian`](font-variant-east-asian) * [`font-variant-emoji`](font-variant-emoji) * [`font-variant-ligatures`](font-variant-ligatures) * [`font-variant-numeric`](font-variant-numeric) * [`font-variant-position`](font-variant-position) * [`@font-feature-values`](@font-feature-values) css <easing-function> <easing-function> ================= The `<easing-function>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) denotes a mathematical function that describes the rate at which a numerical value changes. This transition between two values may be applied in different situations. It may be used to describe how fast values change during animations. This lets you vary the animation's speed over the course of its duration. It may also be used to interpolate between two colors in a color gradient. You can specify an easing function for CSS [transition](transition-timing-function) and [animation](animation-timing-function) properties. Syntax ------ ``` /\* linear function and keyword \*/ /\* linear(<list-of-points>) \*/ linear(1, -0.5, 0); linear; /\* cubic-bezier function and keywords \*/ /\* cubic-bezier(<x1>, <y1>, <x2>, <y2>) \*/ cubic-bezier(0.42, 0.0, 1.0, 1.0); ease; ease-in; ease-out; ease-in-out; /\* steps function and keywords \*/ /\* steps(<number-of-steps>, <direction>) \*/ steps(4, end); step-start; step-end; ``` ### Values *list-of-points* List of linear stops *x1, y1, x2, y2* [`<number>`](number) values representing the abscissas and ordinates of the [P1 and P2 points](#cubic_b%C3%A9zier_functions) defining the cubic Bézier curve. x1 and x2 must be in the range `[0, 1]`, otherwise the value is invalid. `ease` Indicates that the interpolation starts slowly, accelerates sharply, and then slows gradually towards the end. This keyword represents the easing function `cubic-bezier(0.25, 0.1, 0.25, 1.0)`. It is similar to [`ease-in-out`](#ease-in-out), though it accelerates more sharply at the beginning. `ease-in` Indicates that the interpolation starts slowly, then progressively speeds up until the end, at which point it stops abruptly. This keyword represents the easing function `cubic-bezier(0.42, 0.0, 1.0, 1.0)`. `ease-in-out` Indicates that the interpolation starts slowly, speeds up, and then slows down towards the end. This keyword represents the easing function `cubic-bezier(0.42, 0.0, 0.58, 1.0)`. At the beginning, it behaves like the [`ease-in`](#ease-in) function; at the end, it is like the [`ease-out`](#ease-out) function. `ease-out` Indicates that the interpolation starts abruptly and then progressively slows down towards the end. This keyword represents the easing function `cubic-bezier(0.0, 0.0, 0.58, 1.0)`. *number-of-steps* A strictly positive [`<integer>`](integer), representing the amount of equidistant treads composing the stepping function. *direction* One of the following keywords that indicate when the jumps occur: * `jump-start` denotes that the first step or jump happens when the interpolation begins. * `jump-end` denotes that the last step or jump happens when the interpolation ends. * `jump-both` denotes that jumps occur at both the 0% and 100% marks, effectively adding a step during the interpolation iteration. * `jump-none` denotes no jump on either end. Instead, holding at both the 0% mark and the 100% mark, each for 1/n of the duration. * `start` is the equivalent of `jump-start`. * `end` is the equivalent of `jump-end`. This is the default. `step-start` Indicates that the interpolation jumps immediately to its final state, where it stays until the end. This keyword represents the easing function `steps(1, jump-start)` or `steps(1, start)`. `step-end` Indicates that the interpolation stays in its initial state until the end, at which point it jumps directly to its final state. This keyword represents the easing function `steps(1, jump-end)` or `steps(1, end)`. Description ----------- There are three types of easing functions: * [Linear](#linear_easing_function) * [Cubic Bézier](#cubic_b%C3%A9zier_easing_function) * [Step](#step_easing_function) ### Linear easing function The `linear()` function defines a piecewise linear function that interpolates linearly between its points, allowing you to approximate more complex animations like bounce and elastic effects. The interpolation is done at a constant rate from beginning to end. A typical use of the `linear()` function is to provide many points to create the illusion of a curve. When you define the `linear()` function, you specify the *linear easing points* as a list, as in, `linear(0, 0.25, 1)`. This `linear()` function produces an easing function that moves linearly from `0`, to `0.25`, then to `1`. Consider another example of the function: `linear(0, 0.25 75%, 1)`. This produces a linear easing function that spends 75% of the time transitioning from `0` to `.25` and the last 25% transitioning from `.25` to `1`. The `linear` keyword produces a `linear()` function with two points. This is equivalent to the easing function `cubic-bezier(0.0, 0.0, 1.0, 1.0)`. ### Cubic Bézier easing function The `cubic-bezier()` functional notation defines a cubic [Bézier curve](https://developer.mozilla.org/en-US/docs/Glossary/Bezier_curve). The easing functions in the cubic-bezier subset of easing functions are often called "smooth" easing functions because they can be used to smooth down the start and end of the [interpolation](https://developer.mozilla.org/en-US/docs/Glossary/Interpolation). They correlate an input ratio to an output ratio, both expressed as [`<number>`](number)s. For these values, `0.0` represents the initial state, and `1.0` represents the final state. A cubic Bézier curve is defined by four points: P0, P1, P2, and P3. * The points P0 and P3 represent the start and the end of the curve. In CSS, these points are fixed as the coordinates are ratios (the abscissa the ratio of time, the ordinate the ratio of the output range). * P0 is `(0, 0)` and represents the initial time or position and the initial state. * P3 is `(1, 1)` and represents the final time or position and the final state. Not all cubic Bézier curves are suitable as easing functions because not all are [mathematical functions](https://en.wikipedia.org/wiki/Function_%28mathematics%29); i.e., curves that for a given abscissa have zero or one value. With P0 and P3 fixed as defined by CSS, a cubic Bézier curve is a function, and is therefore valid, if and only if the abscissas of P1 and P2 are both in the `[0, 1]` range. Cubic Bézier curves with the P1 or P2 ordinate outside the `[0, 1]` range can cause the value to go farther than the final state and then return. In animations, for some properties, such as [`left`](left) or [`right`](right), this creates a kind of "bouncing" effect. However, certain properties will restrict the output if it goes outside an allowable range. For example, a color component greater than `255` or smaller than `0` will be clipped to the closest allowed value (`255` and `0`, respectively). Some `cubic-bezier()` curves exhibit this property. When you specify an invalid `cubic-bezier` curve, CSS ignores the whole property. The `cubic-bezier()` function can also be specified using these keywords, each of which represent a specific `cubic-bezier()` notation: [`ease`](#ease), [`ease-in`](#ease-in), [`ease-out`](#ease-out), and [`ease-in-out`](#ease-in-out). ### Step easing function The `steps()` functional notation defines a [step function](https://en.wikipedia.org/wiki/Step_function) that divides the domain of output values in equidistant steps. This subclass of step functions are sometimes also called *staircase functions*. These are a few examples illustrating the `steps()` function: ``` steps(2, jump-start) steps(2, start) ``` ``` steps(4, jump-end) steps(4, end) ``` ``` steps(5, jump-none) ``` ``` steps(3, jump-both) ``` The `steps()` function can also be specified using these keywords, each of which represent a specific `steps()` notation: [`step-start`](#step-start) and [`step-end`](#step-end). Formal syntax ------------- ``` <easing-function> = linear [|](value_definition_syntax#single_bar) <linear-easing-function> [|](value_definition_syntax#single_bar) <cubic-bezier-easing-function> [|](value_definition_syntax#single_bar) <step-easing-function> <linear-easing-function> = linear( <linear-stop-list> ) <cubic-bezier-easing-function> = ease [|](value_definition_syntax#single_bar) ease-in [|](value_definition_syntax#single_bar) ease-out [|](value_definition_syntax#single_bar) ease-in-out [|](value_definition_syntax#single_bar) cubic-bezier( [<number [0,1]>](number) , [<number>](number) , [<number [0,1]>](number) , [<number>](number) ) <step-easing-function> = step-start [|](value_definition_syntax#single_bar) step-end [|](value_definition_syntax#single_bar) steps( [<integer>](integer) [[](value_definition_syntax#brackets), <step-position> []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <linear-stop-list> = [[](value_definition_syntax#brackets) <linear-stop> []](value_definition_syntax#brackets)[#](value_definition_syntax#hash_mark) <step-position> = jump-start [|](value_definition_syntax#single_bar) jump-end [|](value_definition_syntax#single_bar) jump-none [|](value_definition_syntax#single_bar) jump-both [|](value_definition_syntax#single_bar) start [|](value_definition_syntax#single_bar) end <linear-stop> = [<number>](number) [&&](value_definition_syntax#double_ampersand) <linear-stop-length>[?](value_definition_syntax#question_mark) <linear-stop-length> = [<percentage>](percentage)[{1,2}](value_definition_syntax#curly_braces) ``` Examples -------- ### Comparing the easing functions This example provides an easy comparison between the different easing functions using an animation. From the drop-down menu, you can select an easing function – there are a couple of keywords and some `cubic-bezier()` and `steps()` options. After selecting an option, you can start and stop the animation using the provided button. #### HTML ``` <div> <div></div> </div> <ul> <li> <button class="animation-button">Start animation</button> </li> <li> <label for="easing-select">Choose an easing function:</label> <select id="easing-select"> <option selected>linear</option> <option>linear(0, 0.5 50%, 1)</option> <option>ease</option> <option>ease-in</option> <option>ease-in-out</option> <option>ease-out</option> <option>cubic-bezier(0.1, -0.6, 0.2, 0)</option> <option>cubic-bezier(0, 1.1, 0.8, 4)</option> <option>steps(5, end)</option> <option>steps(3, start)</option> <option>steps(4)</option> </select> </li> </ul> ``` #### CSS ``` body > div { position: relative; height: 100px; } div > div { position: absolute; width: 50px; height: 50px; background-color: blue; background-image: radial-gradient( circle at 10px 10px, rgba(25, 255, 255, 0.8), rgba(25, 255, 255, 0.4) ); border-radius: 50%; top: 25px; animation: 1.5s infinite alternate; } @keyframes move-right { from { left: 10%; } to { left: 90%; } } li { display: flex; align-items: center; justify-content: center; margin-bottom: 20px; } ``` #### JavaScript ``` const selectElem = document.querySelector('select'); const startBtn = document.querySelector('button'); const divElem = document.querySelector('div > div'); startBtn.addEventListener('click', () => { if (startBtn.textContent === 'Start animation') { divElem.style.animationName = 'move-right'; startBtn.textContent = 'Stop animation'; divElem.style.animationTimingFunction = selectElem.value; } else { divElem.style.animationName = 'unset'; startBtn.textContent = 'Start animation'; } }); selectElem.addEventListener('change', () => { divElem.style.animationTimingFunction = selectElem.value; }); ``` #### Result ### Using the cubic-bezier() function These cubic Bézier curves are valid for use in CSS: ``` /\* The canonical Bézier curve with four <number> in the [0,1] range. \*/ cubic-bezier(0.1, 0.7, 1.0, 0.1) /\* Using <integer> is valid because any <integer> is also a <number>. \*/ cubic-bezier(0, 0, 1, 1) /\* Negative values for ordinates are valid, leading to bouncing effects.\*/ cubic-bezier(0.1, -0.6, 0.2, 0) /\* Values greater than 1.0 for ordinates are also valid. \*/ cubic-bezier(0, 1.1, 0.8, 4) ``` These cubic Bézier curves definitions are invalid: ``` /\* Though the animated output type may be a color, Bézier curves work with numerical ratios.\*/ cubic-bezier(0.1, red, 1.0, green) /\* Abscissas must be in the [0, 1] range or the curve is not a function of time. \*/ cubic-bezier(2.45, 0.6, 4, 0.1) /\* The two points must be defined, there is no default value. \*/ cubic-bezier(0.3, 2.1) /\* Abscissas must be in the [0, 1] range or the curve is not a function of time. \*/ cubic-bezier(-1.9, 0.3, -0.2, 2.1) ``` ### Using the steps() function These easing functions are valid: ``` /\* There are 5 treads, the last one happens right before the end of the animation. \*/ steps(5, end) /\* A two-step staircase, the first one happening at the start of the animation. \*/ steps(2, start) /\* The second parameter is optional. \*/ steps(2) ``` **Note:** If the animation contains multiple stops, then the steps specified in the `steps()` function will apply to each section. Therefore, an animation with three segments and `steps(2)` will contain 6 steps in total, 2 per segment. These easing functions are invalid: ``` /\* The first parameter must be an <integer> and cannot be a real value, even if it is equal to one. \*/ steps(2.0, jump-end) /\* The amount of steps must be non-negative. \*/ steps(-3, start) /\* There must be at least one step.\*/ steps(0, jump-none) ``` Specifications -------------- | Specification | | --- | | [CSS Easing Functions Level 1 # easing-functions](https://w3c.github.io/csswg-drafts/css-easing/#easing-functions) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `easing-function` | 4 | 12 | 4 | 10 | 10.5 | 3.1 | 4 | 18 | 4 | 11 | 2 | 1.0 | | `cubic-bezier` | 16 | 12 | 4 | 10 | 12.1 | 6 | 4.4 | 18 | 4 | 14 | 6 | 1.0 | | `linear-function` | No | No | 104 | No | No | No | No | No | No | No | No | No | | `steps` | 8 | 12 | 4 | 10 | 12.1 | 5.1 | 4 | 18 | 4 | 14 | 5 | 1.0 | See also -------- * [CSS Animations](css_animations) * [CSS Transitions](css_transitions) * [cubic-bezier](https://cubic-bezier.com/)
programming_docs
css animation-composition animation-composition ===================== **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `animation-composition` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property specifies the [composite operation](https://developer.mozilla.org/en-US/docs/Glossary/Composite_operation) to use when multiple animations affect the same property simultaneously. Syntax ------ ``` /\* Single animation \*/ animation-composition: replace; animation-composition: add; animation-composition: accumulate; /\* Multiple animations \*/ animation-composition: replace, add; animation-composition: add, accumulate; animation-composition: replace, add, accumulate; /\* Global values \*/ animation-composition: inherit; animation-composition: initial; animation-composition: revert; animation-composition: revert-layer; animation-composition: unset; ``` **Note:** When you specify multiple comma-separated values on an `animation-*` property, they will be applied to the animations in the order in which the [`animation-name`](animation-name)s appear. If the number of animations and compositions differ, the values listed in the `animation-composition` property will cycle from the first to the last `animation-name`, looping until all the animations have an assigned `animation-composition` value. For more information, see [Setting multiple animation property values](css_animations/using_css_animations#setting_multiple_animation_property_values). ### Values `replace` The effect value overrides the underlying value of the property. This is the default value. `add` The effect value builds on the underlying value of the property. This operation produces an additive effect. For animation types where the addition operation is not commutative, the order of the operands is the underlying value followed by the effect value. `accumulate` The effect and underlying values are combined. For animation types where the addition operation is not commutative, the order of the operands is the underlying value followed by the effect value. Description ----------- Each property that is targeted by the <@keyframes> at-rule is associated with an effect stack. The value of the effect stack is calculated by combining the *underlying value* of a property in a CSS style rule with the *effect value* of that property in the keyframe. The `animation-composition` property helps to specify how to combine the underlying value with the effect value. For example, in the CSS below, `blur(5px)` is the underlying value, and `blur(10px)` is the effect value. The `animation-composition` property specifies the operation to perform to produce the final effect value after compositing the effect of the underlying value and the effect value. ``` .icon:hover { filter: blur(5px); animation: 3s infinite pulse; animation-composition: add; } @keyframes pulse { 0% { filter: blur(10px); } 100% { filter: blur(20px); } } ``` Consider different values for the `animation-composition` property in the above example. The final effect value in each of those cases will be calculated as explained below: * With `replace`, `blur(10px)` will replace `blur(5px)` in the `0%` keyframe. This is the default behavior of the property. * With `add`, the composite effect value in the `0%` keyframe will be `blur(5px) blur(10px)`. * With `accumulate`, the composite effect value in `0%` keyframe will be `blur(15px)`. **Note:** A composite operation can also be specified in a keyframe. In that case, the specified composite operation is used for each property first within that keyframe and then on each property in the next keyframe. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `replace` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | Not animatable | Formal syntax ------------- ``` animation-composition = <single-animation-composition>[#](value_definition_syntax#hash_mark) <single-animation-composition> = replace [|](value_definition_syntax#single_bar) add [|](value_definition_syntax#single_bar) accumulate ``` Examples -------- ### Understanding the animation-composition values The example below shows the effect of different `animation-composition` values side-by-side. #### HTML ``` <div class="container"> replace <div id="replace" class="target"></div> </div> <div class="container"> add <div id="add" class="target"></div> </div> <div class="container"> accumulate <div id="accumulate" class="target"></div> </div> ``` #### CSS Here the underlying value is `translateX(50px) rotate(45deg)`. ``` @keyframes slide { 20%, 40% { transform: translateX(100px); background: yellow; } 80%, 100% { transform: translateX(150px); background: orange; } } .container { width: 240px; height: 220px; background: cyan; display: inline-block; } .target { width: 20px; height: 50px; background: green; border-radius: 10px; transform: translateX(50px) rotate(45deg); animation: slide 5s linear infinite; } .target:hover { animation-play-state: paused; } #replace { animation-composition: replace; } #add { animation-composition: add; } #accumulate { animation-composition: accumulate; } ``` #### Result * With `replace`, the final effect value for the `transform` property in the `0%, 20%` keyframe is `translateX(100px)` (completely replacing the underlying value `translateX(50px) rotate(45deg)`). In this case, the element rotates from 45deg to 0deg as it animates from the default value set on the element itself to the non-rotated value set at the 0% mark. This is the default behavior. * With `add`, the final effect value for the `transform` property in the `0%, 20%` keyframe is `translateX(50px) rotate(45deg)` followed by `translateX(100px)`. So the element is moved `50px` to the right, rotated `45deg`, then translated `100px` more along the redirected X axis. * With `accumulate`, the final effect value in the `0%, 20%` keyframe is `translateX(150px) rotate(45deg)`. This means that the two X-axis translation values of `50px` and `100px` are combined or "accumulated". Specifications -------------- | Specification | | --- | | [CSS Animations Level 2 # animation-composition](https://w3c.github.io/csswg-drafts/css-animations-2/#animation-composition) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `animation-composition` | No | No | 104 | No | No | 16 | No | No | No | No | 16 | No | See also -------- * [Using CSS animations](css_animations/using_css_animations) * [Composite property of KeyFrameEffect](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/composite) * Other related animation properties: [`animation`](animation), [`animation-delay`](animation-delay), [`animation-direction`](animation-direction), [`animation-duration`](animation-duration), [`animation-fill-mode`](animation-fill-mode), [`animation-iteration-count`](animation-iteration-count), [`animation-name`](animation-name), [`animation-play-state`](animation-play-state), [`animation-timeline`](animation-timeline), [`animation-timing-function`](animation-timing-function) css scrollbar-width scrollbar-width =============== The `scrollbar-width` property allows the author to set the maximum thickness of an element's scrollbars when they are shown. Syntax ------ ``` /\* Keyword values \*/ scrollbar-width: auto; scrollbar-width: thin; scrollbar-width: none; /\* Global values \*/ scrollbar-width: inherit; scrollbar-width: initial; scrollbar-width: revert; scrollbar-width: revert-layer; scrollbar-width: unset; ``` ### Values *<scrollbar-width>* Defines the width of the scrollbar as a keyword. It must be one of the following values: | | | | --- | --- | | `auto` | The default scrollbar width for the platform. | | `thin` | A thin scrollbar width variant on platforms that provide that option, or a thinner scrollbar than the default platform scrollbar width. | | `none` | No scrollbar shown, however the element will still be scrollable. | **Note:** User Agents must apply any `scrollbar-width` value set on the root element to the viewport. Accessibility concerns ---------------------- Use this property with caution — setting `scrollbar-width` to `thin` or `none` can make content hard or impossible to scroll if the author does not provide an alternative scrolling mechanism. While swiping gestures or mouse wheels can enable scrolling on such content, some devices have no scroll alternative. WCAG criterion 2.1.1 (Keyboard) has been in place for a long time to advise on basic keyboard accessibility, and this should include scrolling of content areas. And introduced in WCAG 2.1, criterion 2.5.5 (Target Size) advises that touch targets should be at least 44px in width and height (although the problem is compounded on high-resolution screens; thorough testing is advised). * [MDN Understanding WCAG, Guideline 2.1 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Operable#guideline_2.1_%E2%80%94_keyboard_accessible_make_all_functionality_available_from_a_keyboard) * [MDN Understanding WCAG, Guideline 2.5 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Operable#guideline_2.5_input_modalities_make_it_easier_for_users_to_operate_functionality_through_various_inputs_beyond_keyboard.s/) * [Understanding Success Criterion 2.1.1 | W3C Understanding WCAG 2.1](https://www.w3.org/WAI/WCAG21/Understanding/keyboard) * [Understanding Success Criterion 2.5.5 | W3C Understanding WCAG 2.1](https://www.w3.org/WAI/WCAG21/Understanding/target-size.html) Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | scrolling boxes | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` scrollbar-width = auto [|](value_definition_syntax#single_bar) thin [|](value_definition_syntax#single_bar) none ``` Examples -------- ### Sizing overflow scrollbars #### CSS ``` .scroller { width: 300px; height: 100px; overflow-y: scroll; scrollbar-width: thin; } ``` #### HTML ``` <div class="scroller"> Veggies es bonus vobis, proinde vos postulo essum magis kohlrabi welsh onion daikon amaranth tatsoi tomatillo melon azuki bean garlic. Gumbo beet greens corn soko endive gumbo gourd. Parsley shallot courgette tatsoi pea sprouts fava bean collard greens dandelion okra wakame tomato. Dandelion cucumber earthnut pea peanut soko zucchini. </div> ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Scrollbars Styling Module Level 1 # scrollbar-width](https://w3c.github.io/csswg-drafts/css-scrollbars/#scrollbar-width) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scrollbar-width` | No See [bug 891944](https://crbug.com/891944). | No See [bug 891944](https://crbug.com/891944). | 64 | No | No See [bug 891944](https://crbug.com/891944). | No See [bug 231588](https://webkit.org/b/231588). | No See [bug 891944](https://crbug.com/891944). | No See [bug 891944](https://crbug.com/891944). | 64 | No See [bug 891944](https://crbug.com/891944). | No See [bug 231588](https://webkit.org/b/231588). | No See [bug 891944](https://crbug.com/891944). | See also -------- * `-ms-overflow-style` * [`::-webkit-scrollbar`](::-webkit-scrollbar) css bottom bottom ====== The `bottom` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property participates in setting the vertical position of a [positioned element](position). It has no effect on non-positioned elements. Try it ------ The effect of `bottom` depends on how the element is positioned (i.e., the value of the [`position`](position) property): * When `position` is set to `absolute` or `fixed`, the `bottom` property specifies the distance between the element's outer margin of bottom edge and the inner border of the bottom edge of its containing block. * When `position` is set to `relative`, the `bottom` property specifies the distance the element's bottom edge is moved above its normal position. * When `position` is set to `sticky`, the `bottom` property is used to compute the sticky-constraint rectangle. * When `position` is set to `static`, the `bottom` property has *no effect*. When both [`top`](top) and `bottom` are specified, `position` is set to `absolute` or `fixed`, *and* [`height`](height) is unspecified (either `auto` or `100%`) both the `top` and `bottom` distances are respected. In all other situations, if [`height`](height) is constrained in any way or `position` is set to `relative`, the `top` property takes precedence and the `bottom` property is ignored. Syntax ------ ``` /\* <length> values \*/ bottom: 3px; bottom: 2.4em; /\* <percentage>s of the height of the containing block \*/ bottom: 10%; /\* Keyword value \*/ bottom: auto; /\* Global values \*/ bottom: inherit; bottom: initial; bottom: revert; bottom: revert-layer; bottom: unset; ``` ### Values [`<length>`](length) A negative, null, or positive [`<length>`](length) that represents: * for *absolutely positioned elements*, the distance to the bottom edge of the containing block. * for *relatively positioned elements*, the distance that the element is moved above its normal position. [`<percentage>`](percentage) A [`<percentage>`](percentage) of the containing block's height. `auto` Specifies that: * for *absolutely positioned elements*, the position of the element is based on the [`top`](top) property, while `height: auto` is treated as a height based on the content; or if `top` is also `auto`, the element is positioned where it should vertically 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 [`top`](top) property; or if `top` is also `auto`, the element is not moved vertically 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 [`<length>`](length), [`<percentage>`](percentage), or the `auto` keyword. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | positioned elements | | [Inherited](inheritance) | no | | Percentages | refer to the height of the containing block | | [Computed value](computed_value) | if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, `auto` | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` bottom = auto [|](value_definition_syntax#single_bar) <length-percentage> <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Absolute and fixed positioning This example demonstrates the difference in behavior of the `bottom` property, when [`position`](position) is `absolute` versus `fixed`. #### HTML ``` <p> This<br />is<br />some<br />tall,<br />tall,<br />tall,<br />tall,<br />tall<br />content. </p> <div class="fixed"><p>Fixed</p></div> <div class="absolute"><p>Absolute</p></div> ``` #### CSS ``` p { font-size: 30px; line-height: 2em; } div { width: 48%; text-align: center; background: rgba(55, 55, 55, 0.2); border: 1px solid blue; } .absolute { position: absolute; bottom: 0; left: 0; } .fixed { position: fixed; bottom: 0; right: 0; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Positioned Layout Module Level 3 # insets](https://w3c.github.io/csswg-drafts/css-position/#insets) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `bottom` | 1 | 12 | 1 | 5 In Internet Explorer versions before 7, when both `top` and `bottom` are specified, the element position is overconstrained and the `top` property has precedence; the computed value of `bottom` is set to `-top`, while its specified value is ignored. | 6 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [`inset`](inset), the shorthand for all related properties: [`top`](top), [`bottom`](bottom), [`left`](left), and [`right`](right) * The mapped logical properties: [`inset-block-start`](inset-block-start), [`inset-block-end`](inset-block-end), [`inset-inline-start`](inset-inline-start), and [`inset-inline-end`](inset-inline-end) and the shorthands [`inset-block`](inset-block) and [`inset-inline`](inset-inline) * [`position`](position) css <color> <color> ======= The `<color>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) represents a color. A `<color>` may also include an [alpha-channel](https://en.wikipedia.org/wiki/Alpha_compositing) *transparency value*, indicating how the color should [composite](https://www.w3.org/TR/compositing-1/#simplealphacompositing) with its background. A `<color>` can be defined in any of the following ways: * Using a keyword (such as `blue` or `transparent`). All existing keywords specify a color in the [sRGB color space](https://en.wikipedia.org/wiki/SRGB). * Using the [RGB cubic-coordinate](https://en.wikipedia.org/wiki/RGB_color_model#Geometric_representation) system (via the #-hexadecimal or the `rgb()` functional notation). These always specify a color in the [sRGB color space](https://en.wikipedia.org/wiki/SRGB). * Using the [HSL cylindrical-coordinate](https://en.wikipedia.org/wiki/HSL_and_HSV) system (via the [`hsl()`](color_value/hsl) functional notation). These always specify a color in the [sRGB color space](https://en.wikipedia.org/wiki/SRGB). * Using the [HWB cylindrical-coordinate](https://en.wikipedia.org/wiki/HWB_color_model) system (via the [`hwb()`](color_value/hwb) functional notation). These always specify a color in the [sRGB color space](https://en.wikipedia.org/wiki/SRGB). * Using the [LCH cylindrical coordinate system](https://en.wikipedia.org/wiki/CIELAB_color_space#Cylindrical_representation:_CIELCh_or_CIEHLC), via the [`lch()`](color_value/lch) functional notation. This can specify any visible color. * Using the [Lab coordinate system](https://en.wikipedia.org/wiki/CIELAB_color_space), via the [`lab()`](color_value/lab) functional notation. This can specify any visible color. * Using the [`color()`](color_value/color) functional notation, to specify a color in a variety of predefined or custom color spaces. **Note:** This article describes the `<color>` data type in detail. To learn more about using color in HTML, see [Applying color to HTML elements using CSS](css_colors/applying_color). Syntax ------ The `<color>` data type is specified using one of the options listed below. **Note:** Although `<color>` values are precisely defined, their actual appearance may vary (sometimes significantly) from device to device. This is because most devices are not calibrated, and some browsers do not support output devices' [color profiles](https://en.wikipedia.org/wiki/ICC_profile). ### Named colors Named colors are case-insensitive identifiers that represent a specific color, such as `red`, `blue`, `black`, or `lightseagreen`. Although the names more or less describe their respective colors, they are essentially artificial, without a strict rationale behind the names used. The complete list of such keywords is available [here](named-color). ### currentcolor keyword The `currentcolor` keyword represents the value of an element's [`color`](color) property. This lets you use the `color` value on properties that do not receive it by default. If `currentcolor` is used as the value of the `color` property, it instead takes its value from the inherited value of the `color` property. ``` <div style="color: blue; border: 1px dashed currentcolor;"> The color of this text is blue. <div style="background: currentcolor; height:9px;"></div> This block is surrounded by a blue border. </div> ``` ### RGB color model The RGB color model defines a given color in the [sRGB color space](https://en.wikipedia.org/wiki/SRGB) according to its red, green, and blue components. An optional alpha component represents the color's transparency. RGB colors can be expressed through both hexadecimal (prefixed with `#`) and functional (`rgb()`, `rgba()`) notations. [Hexadecimal notation](hex-color): `#RGB[A]` or`#RRGGBB[AA]` `R` (red), `G` (green), `B` (blue), and `A` (alpha) are hexadecimal characters (0–9, A–F). `A` is optional. For example, `#ff0000` is equivalent to `#ff0000ff`. The three-digit notation (`#RGB`) is a shorter version of the six-digit form (`#RRGGBB`). For example, `#f09` is the same color as `#ff0099`. Likewise, the four-digit RGB notation (`#RGBA`) is a shorter version of the eight-digit form (`#RRGGBBAA`). For example, `#0f38` is the same color as `#00ff3388`. [`rgb()`](color_value/rgb) or [`rgba()`](color_value/rgb): `rgb[a](R, G, B[, A])` or `rgb[a](R G B[ / A])` `R` (red), `G` (green), and `B` (blue) can be either [`<number>`](number)s or [`<percentage>`](percentage)s, where the number `255` corresponds to `100%`. `A` (alpha) can be a [`<number>`](number) between `0` and `1`, or a [`<percentage>`](percentage), where the number `1` corresponds to `100%` (full opacity). ### HSL color model The HSL color model defines a given color in the [sRGB color space](https://en.wikipedia.org/wiki/SRGB) according to its hue, saturation, and lightness components. An optional alpha component represents the color's transparency. Many designers find HSL more intuitive than RGB, since it allows hue, saturation, and lightness to each be adjusted independently. HSL can also make it easier to create a set of matching colors (such as when you want multiple shades of a single hue). However, using HSL to create color variations can produce surprising results, as it is not [perceptually uniform](https://en.wikipedia.org/wiki/Color_difference#Tolerance). For example, both `hsl(240 100% 50%)` and `hsl(60 100% 50%)` have the same lightness, even though the former is much darker than the latter. HSL colors are expressed through the functional [`hsl()`](color_value/hsl) notation. **Note:** The legacy [`hsla()`](color_value/hsl) syntax is an alias for `hsl()`, accepting the same parameters and behaving in the same way. ### HWB color model Similar to HSL color model, the HWB color model defines a given color in the [sRGB color space](https://en.wikipedia.org/wiki/SRGB) according to its hue, whiteness and blackness components. As with HSL, HWB can be more intuitive to use than RGB. A hue is specified in the same way, followed by the amount of whiteness and blackness, respectively, in percentage values. This function also accepts an alpha value. **Note:** There is **no** separate `hwba()` function as there is with HSL, the alpha value is an optional parameter, if it is not specified an alpha value of 1 (or 100%) is used. To specify this value a forward slash (`/`) must follow the blackness value before the alpha value is specified. HWB colors are expressed through the functional `hwb()` notation. **Note:** The HWB function does **not** use commas to separate its values as with previous color functions. [`hwb()`](color_value/hwb): `hwb(H W B[ / A])` Same as HSL: `H` (hue) is an [`<angle>`](angle) of the color circle given in `deg`s, `rad`s, `grad`s, or `turn`s in the [CSS Color](https://drafts.csswg.org/css-color/#the-hsl-notation) specification. When written as a unitless [`<number>`](number), it is interpreted as degrees, as specified in the [CSS Color Level 3](https://drafts.csswg.org/css-color-3/#hsl-color) specification. By definition, red=0deg=360deg, with the other colors spread around the circle, so green=120deg, blue=240deg, etc. As an `<angle>`, it implicitly wraps around such that -120deg=240deg, 480deg=120deg, -1turn=1turn, etc. `W` (whiteness) and `B` (blackness) are percentages. These two colors mix, so you would need `0%` **whiteness** and `100%` **blackness** to produce the color black. And vice versa `100%` whiteness and `0%` blackness for the color white. `50%` of both values renders a mid-grey and any other variations a shade of the hue specified. `A` (alpha), optional, can be a [`<number>`](number) between `0` and `1`, or a [`<percentage>`](percentage), where the number `1` corresponds to `100%` (full opacity). When specifying an alpha value it must be preceded with a forward slash (`/`). ### System Colors In *forced colors mode* (detectable with the [forced-colors](@media/forced-colors) media query), most colors are restricted into a user- and browser-defined palette. These system colors are exposed by the following keywords, which can be used to ensure that the rest of the page integrates well with the restricted palette. These values may also be used in other contexts, but are not widely supported by browsers. The keywords in the following list are defined by the CSS Color Module Level 4 specification: `AccentColor`, `AccentColorText`, `ActiveText`, `ButtonBorder`, `ButtonFace`, `ButtonText`, `Canvas`, `CanvasText`, `Field`, `FieldText`, `GrayText`, `Highlight`, `HighlightText`, `LinkText`, `Mark`, `MarkText`, `SelectedItem`, `SelectedItemText`, `VisitedText`. **Note:** Note that these keywords are *case-insensitive*, but are listed here with mixed case for readability. ### Lab colors CSS Color 4 introduced Lab colors. Lab colors are specified via the [`lab()`](color_value/lab) functional notation. They are not limited to a specific color space, and can represent the entire spectrum of human vision. ### LCH color model CSS Color 4 introduced LCH colors. LCH colors are specified via the [`lch()`](color_value/lch) functional notation. They are not limited to a specific color space, and can represent the entire spectrum of human vision. In fact, LCH is the polar form of Lab. It is more human friendly than Lab, as its chroma and hue components specify qualities of the desired color, as opposed to mixing. It is similar to HSL in that way, although it is far more perceptually uniform. Unlike HSL that describes both `hsl(60 100% 50%)` and `hsl(240 100% 50%)` as having the same lightness, LCH (and Lab) correctly ascribes different lightnesses to them: the former (yellow) has an L of 97.6 and the latter (blue) an L of 29.6. Therefore, LCH can be used to create palettes across entirely different colors, with predictable results. Please note that LCH hue is not the same as HSL hue and LCH chroma is not the same as HSL saturation, although they do share some conceptual similarities. ### color() colors CSS Color 4 introduced this notation. Colors specified via the [`color()`](color_value/color) function can specify a color in any of the predefined color spaces, as well as custom color spaces, defined via the [`@color-profile`](@color-profile) rule. Interpolation ------------- In animations and [gradients](css_images/using_css_gradients), `<color>` values are [interpolated](https://developer.mozilla.org/en-US/docs/Glossary/Interpolation) on each of their red, green, and blue components. Each component is interpolated as a real, floating-point number. Note that interpolation of colors happens in the [alpha-premultiplied sRGBA color space](https://www.w3.org/TR/css-color-4/#interpolation-alpha) to prevent unexpected gray colors from appearing. In animations, the interpolation's speed is determined by the [timing function](easing-function). Accessibility considerations ---------------------------- Some people have difficulty distinguishing colors. The [WCAG 2.0](https://www.w3.org/TR/WCAG/#visual-audio-contrast) recommendation strongly advises against using color as the only means of conveying a specific message, action, or result. See [Color and color contrast](https://developer.mozilla.org/en-US/docs/Learn/Accessibility/CSS_and_JavaScript#color_and_color_contrast) for more information. Formal syntax ------------- ``` <color> = <absolute-color-base> [|](value_definition_syntax#single_bar) currentcolor [|](value_definition_syntax#single_bar) [<system-color>](system-color) <absolute-color-base> = [<hex-color>](hex-color) [|](value_definition_syntax#single_bar) <absolute-color-function> [|](value_definition_syntax#single_bar) [<named-color>](named-color) [|](value_definition_syntax#single_bar) transparent <absolute-color-function> = <rgb()> [|](value_definition_syntax#single_bar) [<rgba()>](rgba()) [|](value_definition_syntax#single_bar) <hsl()> [|](value_definition_syntax#single_bar) [<hsla()>](hsla()) [|](value_definition_syntax#single_bar) <hwb()> [|](value_definition_syntax#single_bar) <lab()> [|](value_definition_syntax#single_bar) <lch()> [|](value_definition_syntax#single_bar) <oklab()> [|](value_definition_syntax#single_bar) <oklch()> [|](value_definition_syntax#single_bar) <color()> <rgb()> = rgb( [[](value_definition_syntax#brackets) [<percentage>](percentage) [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets)[{3}](value_definition_syntax#curly_braces) [[](value_definition_syntax#brackets) / [[](value_definition_syntax#brackets) <alpha-value> [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) [|](value_definition_syntax#single_bar) rgb( [[](value_definition_syntax#brackets) [<number>](number) [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets)[{3}](value_definition_syntax#curly_braces) [[](value_definition_syntax#brackets) / [[](value_definition_syntax#brackets) <alpha-value> [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <hsl()> = hsl( [[](value_definition_syntax#brackets) <hue> [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) [<percentage>](percentage) [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) [<percentage>](percentage) [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) / [[](value_definition_syntax#brackets) <alpha-value> [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <hwb()> = hwb( [[](value_definition_syntax#brackets) <hue> [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) [<percentage>](percentage) [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) [<percentage>](percentage) [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) / [[](value_definition_syntax#brackets) <alpha-value> [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <lab()> = lab( [[](value_definition_syntax#brackets) [<percentage>](percentage) [|](value_definition_syntax#single_bar) [<number>](number) [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) [<percentage>](percentage) [|](value_definition_syntax#single_bar) [<number>](number) [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) [<percentage>](percentage) [|](value_definition_syntax#single_bar) [<number>](number) [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) / [[](value_definition_syntax#brackets) <alpha-value> [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <lch()> = lch( [[](value_definition_syntax#brackets) [<percentage>](percentage) [|](value_definition_syntax#single_bar) [<number>](number) [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) [<percentage>](percentage) [|](value_definition_syntax#single_bar) [<number>](number) [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) <hue> [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) / [[](value_definition_syntax#brackets) <alpha-value> [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <oklab()> = oklab( [[](value_definition_syntax#brackets) [<percentage>](percentage) [|](value_definition_syntax#single_bar) [<number>](number) [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) [<percentage>](percentage) [|](value_definition_syntax#single_bar) [<number>](number) [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) [<percentage>](percentage) [|](value_definition_syntax#single_bar) [<number>](number) [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) / [[](value_definition_syntax#brackets) <alpha-value> [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <oklch()> = oklch( [[](value_definition_syntax#brackets) [<percentage>](percentage) [|](value_definition_syntax#single_bar) [<number>](number) [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) [<percentage>](percentage) [|](value_definition_syntax#single_bar) [<number>](number) [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) <hue> [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) / [[](value_definition_syntax#brackets) <alpha-value> [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <color()> = color( <colorspace-params> [[](value_definition_syntax#brackets) / [[](value_definition_syntax#brackets) <alpha-value> [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <alpha-value> = [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) <hue> = [<number>](number) [|](value_definition_syntax#single_bar) [<angle>](angle) <colorspace-params> = <predefined-rgb-params> [|](value_definition_syntax#single_bar) <xyz-params> <predefined-rgb-params> = <predefined-rgb> [[](value_definition_syntax#brackets) [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets)[{3}](value_definition_syntax#curly_braces) <xyz-params> = <xyz-space> [[](value_definition_syntax#brackets) [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) [|](value_definition_syntax#single_bar) none []](value_definition_syntax#brackets)[{3}](value_definition_syntax#curly_braces) <predefined-rgb> = srgb [|](value_definition_syntax#single_bar) srgb-linear [|](value_definition_syntax#single_bar) display-p3 [|](value_definition_syntax#single_bar) a98-rgb [|](value_definition_syntax#single_bar) prophoto-rgb [|](value_definition_syntax#single_bar) rec2020 <xyz-space> = xyz [|](value_definition_syntax#single_bar) xyz-d50 [|](value_definition_syntax#single_bar) xyz-d65 ``` Examples -------- ### Color value tester In this example we provide a `<div>` and a text input. Entering a valid color into the input causes the `<div>` to adopt that color, allowing you to test our color values. #### HTML ``` <div></div> <hr /> <label for="color">Enter a valid color value:</label> <input type="text" id="color" /> ``` #### CSS ``` div { width: 100%; height: 200px; } ``` #### Result ### RGB syntax variations This example shows the many ways in which a single color can be created with the various RGB color syntaxes. ``` /\* These syntax variations all specify the same color: a fully opaque hot pink. \*/ /\* Hexadecimal syntax \*/ #f09 #F09 #ff0099 #FF0099 /\* Functional syntax \*/ rgb(255,0,153) rgb(255, 0, 153) rgb(255, 0, 153.0) rgb(100%,0%,60%) rgb(100%, 0%, 60%) rgb(100%, 0, 60%) /\* ERROR! Don't mix numbers and percentages. \*/ rgb(255 0 153) /\* Hexadecimal syntax with alpha value \*/ #f09f #F09F #ff0099ff #FF0099FF /\* Functional syntax with alpha value \*/ rgb(255, 0, 153, 1) rgb(255, 0, 153, .5) rgb(255, 0, 153, 0.5) rgb(255, 0, 153, 100%) /\* Whitespace syntax \*/ rgb(255 0 153 / 1) rgb(255 0 153 / 100%) /\* Functional syntax with floats value \*/ rgb(255, 0, 153.6, 1) rgb(2.55e2, 0e0, 1.53e2, 1e2%) ``` ### RGB transparency variations ``` /\* Hexadecimal syntax \*/ #3a30 /\* 0% opaque green \*/ #3a3f /\* full opaque green \*/ #33aa3300 /\* 0% opaque green \*/ #33aa3380 /\* 50% opaque green \*/ /\* Functional syntax \*/ rgba(51, 170, 51, 0.1) /\* 10% opaque green \*/ rgba(51, 170, 51, 0.4) /\* 40% opaque green \*/ rgba(51, 170, 51, 0.7) /\* 70% opaque green \*/ rgba(51, 170, 51, 1) /\* full opaque green \*/ /\* Whitespace syntax \*/ rgba(51 170 51 / 0.4) /\* 40% opaque green \*/ rgba(51 170 51 / 40%) /\* 40% opaque green \*/ /\* Functional syntax with floats value \*/ rgba(51, 170, 51.6, 1) rgba(5.1e1, 1.7e2, 5.1e1, 1e2%) ``` ### HSL syntax variations ``` /\* These examples all specify the same color: a lavender. \*/ hsl(270,60%,70%) hsl(270, 60%, 70%) hsl(270 60% 70%) hsl(270deg, 60%, 70%) hsl(4.71239rad, 60%, 70%) hsl(0.75turn, 60%, 70%) /\* These examples all specify the same color: a lavender that is 15% opaque. \*/ hsl(270, 60%, 50%, 0.15) hsl(270, 60%, 50%, 0.15) hsl(270, 60%, 50%, 15%) hsl(270 60% 50% / 0.15) hsl(270 60% 50% / 15%) ``` ### HWB syntax variations ``` /\* These examples all specify varying shades of a lime green. \*/ hwb(90 10% 10%) hwb(90 50% 10%) hwb(90deg 10% 10%) hwb(1.5708rad 60% 0%) hwb(0.25turn 0% 40%) /\* Same lime green but with an alpha value \*/ hwb(90 10% 10% / 0.5) hwb(90 10% 10% / 50%) ``` ### Fully saturated colors | Notation | Description | Live | | --- | --- | --- | | `hsl(0, 100%, 50%)` | red | | | `hsl(30, 100%, 50%)` | orange | | | `hsl(60, 100%, 50%)` | yellow | | | `hsl(90, 100%, 50%)` | lime green | | | `hsl(120, 100%, 50%)` | green | | | `hsl(150, 100%, 50%)` | blue-green | | | `hsl(180, 100%, 50%)` | cyan | | | `hsl(210, 100%, 50%)` | sky blue | | | `hsl(240, 100%, 50%)` | blue | | | `hsl(270, 100%, 50%)` | purple | | | `hsl(300, 100%, 50%)` | magenta | | | `hsl(330, 100%, 50%)` | pink | | | `hsl(360, 100%, 50%)` | red | | ### Lighter and darker greens | Notation | Description | Live | | --- | --- | --- | | `hsl(120, 100%, 0%)` | black | | | `hsl(120, 100%, 20%)` | | | | `hsl(120, 100%, 40%)` | | | | `hsl(120, 100%, 60%)` | | | | `hsl(120, 100%, 80%)` | | | | `hsl(120, 100%, 100%)` | white | | ### Saturated and desaturated greens | Notation | Description | Live | | --- | --- | --- | | `hsl(120, 100%, 50%)` | green | | | `hsl(120, 80%, 50%)` | | | | `hsl(120, 60%, 50%)` | | | | `hsl(120, 40%, 50%)` | | | | `hsl(120, 20%, 50%)` | | | | `hsl(120, 0%, 50%)` | gray | | ### HSL transparency variations ``` hsl(240 100% 50% / 0.05) /\* 5% opaque blue \*/ hsl(240 100% 50% / 0.4) /\* 40% opaque blue \*/ hsl(240 100% 50% / 0.7) /\* 70% opaque blue \*/ hsl(240 100% 50% / 1) /\* full opaque blue \*/ /\* Comma syntax \*/ hsl(240, 100%, 50%, 0.05) /\* 5% opaque blue \*/ /\* Percentage value for alpha \*/ hsl(240 100% 50% / 5%) /\* 5% opaque blue \*/ ``` Specifications -------------- | Specification | | --- | | [CSS Color Module Level 4 # color-syntax](https://w3c.github.io/csswg-drafts/css-color/#color-syntax) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `color_value` | 1 | 12 | 1 | 3 | 3.5 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `color` | No | No | No | No | No | 15 10.1-15 Only supports `display-p3` and `srgb` predefined color profiles. | No | No | No | No | 15 10.3-15 Only supports `display-p3` and `srgb` predefined color profiles. | No | | `color-contrast` | No | No | No | No | No | 15 | No | No | No | No | 15 | No | | `color-mix` | No | No | 88 | No | No | 15 | No | No | No | No | 15 | No | | `currentcolor` | 1 | 12 | 1.5 | 9 | 9.5 | 4 | 37 | 18 | 4 | 14 | 3.2 | 1.0 | | `hsl` | 1 | 12 | 1 | 9 | 9.5 | 3.1 | ≤37 | 18 | 4 | 10.1 | 2 | 1.0 | | `hsla` | 1 | 12 | 3 | 9 | 10 | 3.1 | ≤37 | 18 | 4 | 10.1 | 2 | 1.0 | | `hwb` | 101 | 101 | 96 | No | 87 | 15 | 101 | 101 | 96 | 70 | 15 | 19.0 | | `lab` | No | No | No | No | No | 15 | No | No | No | No | 15 | No | | `lch` | No | No | No | No | No | 15 | No | No | No | No | 15 | No | | `named-color` | 1 | 12 | 1 | 3 Internet Explorer 8 and later support gray color keywords spelled with an *e* (`grey`, `darkgrey`, `darkslategrey`, `dimgrey`, `lightgrey`, and `lightslategrey`). Internet Explorer 3 to Internet Explorer 7 only support the keywords spelled with *a* (`gray`, `darkgray`, `darkslategray`, `dimgray`, `lightgray`, and `lightslategray`). | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | | `oklab` | No | No | No | No | No | 15.4 | No | No | No | No | 15.4 | No | | `oklch` | No | No | No | No | No | 15.4 | No | No | No | No | 15.4 | No | | `rgb` | 1 | 12 | 1 | 4 | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | | `rgb_hexadecimal_notation` | 1 | 12 | 1 | 3 | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | | `rgba` | 1 | 12 | 3 | 9 | 10 | 3.1 | ≤37 | 18 | 4 | 10.1 | 2 | 1.0 | | `system-color` | 1 | 12 | 1 | 3 | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | | `transparent` | 1 | 12 | 3 | 9 | 10 | 3.1 | 37 | 18 | 4 | 10.1 | 2 | 1.0 | See also -------- * The [`opacity`](opacity) property lets you define transparency at the element level. * Some common properties that use this data type: [`color`](color), [`background-color`](background-color), [`border-color`](border-color), [`box-shadow`](box-shadow), [`outline-color`](outline-color), [`text-shadow`](text-shadow) * [Applying color to HTML elements using CSS](css_colors/applying_color)
programming_docs
css forced-color-adjust forced-color-adjust =================== The `forced-color-adjust` CSS property allows authors to opt certain elements out of forced colors mode. This then restores the control of those values to CSS. Syntax ------ ``` forced-color-adjust: auto; forced-color-adjust: none; /\* Global values \*/ forced-color-adjust: inherit; forced-color-adjust: initial; forced-color-adjust: revert; forced-color-adjust: revert-layer; forced-color-adjust: unset; ``` The `forced-color-adjust` property's value must be one of the following keywords. ### Values `auto` The element's colors are adjusted by the [user agent](https://developer.mozilla.org/en-US/docs/Glossary/User_agent) in forced colors mode. This is the default. `none` The element's colors are not automatically adjusted by the [user agent](https://developer.mozilla.org/en-US/docs/Glossary/User_agent) in forced colors mode. Usage notes ----------- This property should only be used to makes changes that will support a user's color and contrast requirements. For example, if you become aware that the color optimizations made by the [user agent](https://developer.mozilla.org/en-US/docs/Glossary/User_agent) result in a poor experience when in a high contrast or dark mode. Using this property would enable tweaking of the result in that mode to provide a better experience. **It should not be used to prevent user choices being respected**. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | all elements and text | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | Not animatable | Formal syntax ------------- ``` forced-color-adjust = auto [|](value_definition_syntax#single_bar) none [|](value_definition_syntax#single_bar) preserve-parent-color ``` Examples -------- ### Preserving colors In the example below the first box will use the color scheme that the user has set. For example in Windows High Contrast mode black scheme it will have a black background and white text. The second box will preserve the site colors set on the `.box` class. By using the [`forced-colors`](@media/forced-colors) media feature you could add any other optimizations for forced color mode alongside the `forced-color-adjust` property. #### CSS ``` .box { border: 5px solid grey; background-color: #ccc; width: 300px; margin: 20px; padding: 10px; } @media (forced-colors: active) { .forced { forced-color-adjust: none; } } ``` #### HTML ``` <div class="box"> <p>This is a box which should use your color preferences.</p> </div> <div class="box forced"> <p>This is a box which should stay the colors set by the site.</p> </div> ``` #### Result The following screenshot shows the image above in Windows High Contrast Mode: Specifications -------------- | Specification | | --- | | [CSS Color Adjustment Module Level 1 # forced-color-adjust-prop](https://w3c.github.io/csswg-drafts/css-color-adjust/#forced-color-adjust-prop) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `forced-color-adjust` | 89 | 79 12 | No | 10 | No | No | No | No | No | No | No | No | See also -------- * [Applying color to HTML elements using CSS](css_colors/applying_color) * [Styling for Windows high contrast with standards for forced colors.](https://blogs.windows.com/msedgedev/2020/09/17/styling-for-windows-high-contrast-with-new-standards-for-forced-colors/) * [`print-color-adjust`](print-color-adjust) css <display-box> <display-box> ============= These keywords define whether an element generates display boxes at all. Syntax ------ Valid `<display-box>` values: `contents` These elements don't produce a specific box by themselves. They are replaced by their pseudo-box and their child boxes. Please note that the CSS Display Level 3 spec defines how the `contents` value should affect "unusual elements" — elements that aren't rendered purely by CSS box concepts such as replaced elements. See [Appendix B: Effects of display: contents on Unusual Elements](https://drafts.csswg.org/css-display/#unbox) for more details. *Due to a bug in browsers this will currently remove the element from the accessibility tree — screen readers will not look at what's inside. See the [Accessibility concerns](#accessibility_concerns) section below for more details.* `none` Turns off the display of an element so that it has no effect on layout (the document is rendered as though the element did not exist). All descendant elements also have their display turned off. To have an element take up the space that it would normally take, but without actually rendering anything, use the [`visibility`](visibility) property instead. Accessibility concerns ---------------------- Current implementations in most browsers will remove from the [accessibility tree](https://developer.mozilla.org/en-US/docs/Learn/Accessibility/What_is_accessibility#accessibility_apis) any element with a `display` value of `contents`. This will cause the element — and in some browser versions, its descendant elements — to no longer be announced by screen reading technology. This is incorrect behavior according to the [CSSWG specification](https://drafts.csswg.org/css-display/#the-display-properties). * [More accessible markup with display: contents | Hidde de Vries](https://hidde.blog/more-accessible-markup-with-display-contents/) * [Display: Contents Is Not a CSS Reset | Adrian Roselli](https://adrianroselli.com/2018/05/display-contents-is-not-a-css-reset.html) Formal syntax ------------- ``` <display-box> = contents [|](value_definition_syntax#single_bar) none ``` Examples -------- In this first example, the paragraph with a class of secret is set to `display: none`; the box and any content is now not rendered. ### display: none #### HTML ``` <p>Visible text</p> <p class="secret">Invisible text</p> ``` #### CSS ``` p.secret { display: none; } ``` #### Result ### display: contents In this example the outer [`<div>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div) has a 2-pixel red border and a width of 300px. However it also has `display: contents` specified therefore this `<div>` will not be rendered, the border and width will no longer apply, and the child element will be displayed as if the parent had never existed. #### HTML ``` <div class="outer"> <div>Inner div.</div> </div> ``` #### CSS ``` .outer { border: 2px solid red; width: 300px; display: contents; } .outer > div { border: 1px solid green; } ``` #### Result Specifications -------------- **No specification found**No specification data found for `css.properties.display.contents`. [Check for problems with this page](#on-github) or contribute a missing `spec_url` to [mdn/browser-compat-data](https://github.com/mdn/browser-compat-data). Also make sure the specification is included in [w3c/browser-specs](https://github.com/w3c/browser-specs). Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `display-box` | 65 | 79 | 37 | No | 52 | 11.1 | 65 | 65 | 37 | 47 | 11.3 | 9.0 | | `contents_unusual` | 65 | 79 | 59 | No | 52 | No | 65 | 65 | 59 | 47 | No | 9.0 | See also -------- * [`display`](display) + [`<display-outside>`](display-outside) + [`<display-inside>`](display-inside) + [`<display-listitem>`](display-listitem) + [`<display-internal>`](display-internal) + [`<display-legacy>`](display-legacy) * [Display: Contents Is Not a CSS Reset | Adrian Roselli](https://adrianroselli.com/2018/05/display-contents-is-not-a-css-reset.html) * [More accessible markup with display: contents — hiddedevries.nl](https://hidde.blog/more-accessible-markup-with-display-contents/) css margin-block margin-block ============ The `margin-block` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [shorthand property](shorthand_properties) defines the logical block start and end margins of an element, which maps to physical margins depending on the element's writing mode, directionality, and text orientation. Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`margin-block-start`](margin-block-start) * [`margin-block-end`](margin-block-end) Syntax ------ ``` /\* <length> values \*/ margin-block: 10px 20px; /\* An absolute length \*/ margin-block: 1em 2em; /\* relative to the text size \*/ margin-block: 5% 2%; /\* relative to the nearest block container's width \*/ margin-block: 10px; /\* sets both start and end values \*/ /\* Keyword values \*/ margin-block: auto; /\* Global values \*/ margin-block: inherit; margin-block: initial; margin-block: revert; margin-block: revert-layer; margin-block: unset; ``` This property corresponds to the [`margin-top`](margin-top) and [`margin-bottom`](margin-bottom), or the [`margin-right`](margin-right) and [`margin-left`](margin-left) properties, depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). The `margin-block` property may be specified using one or two values. * When **one** value is specified, it applies the same margin to **both start and end**. * When **two** values are specified, the first margin applies to the **start**, the second to the **end**. ### Values The `margin-block` property takes the same values as the [`margin`](margin#values) property. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`margin-block-start`](margin-block-start): `0` * [`margin-block-end`](margin-block-end): `0` | | Applies to | same as [`margin`](margin) | | [Inherited](inheritance) | no | | Percentages | depends on layout model | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`margin-block-start`](margin-block-start): if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, `auto` * [`margin-block-end`](margin-block-end): if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, `auto` | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` margin-block = <'margin-top'>[{1,2}](value_definition_syntax#curly_braces) ``` Examples -------- ### Setting block start and end margins #### CSS ``` div { background-color: yellow; width: 120px; height: auto; border: 1px solid green; } p { margin: 0; margin-block: 20px 40px; background-color: tan; } .verticalExample { writing-mode: vertical-rl; } ``` #### HTML ``` <div> <p>Example text</p> </div> <div class="verticalExample"> <p>Example text</p> </div> ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # propdef-margin-block](https://w3c.github.io/csswg-drafts/css-logical/#propdef-margin-block) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `margin-block` | 87 | 87 | 66 | No | 73 | 14.1 | 87 | 87 | 66 | 62 | 14.5 | 14.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * The mapped physical properties: [`margin-top`](margin-top), [`margin-right`](margin-right), [`margin-bottom`](margin-bottom), and [`margin-left`](margin-left) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css print-color-adjust print-color-adjust ================== The `print-color-adjust` CSS property sets what, if anything, the [user agent](https://developer.mozilla.org/en-US/docs/Glossary/User_agent) may do to optimize the appearance of the element on the output device. By default, the browser is allowed to make any adjustments to the element's appearance it determines to be necessary and prudent given the type and capabilities of the output device. Syntax ------ ``` print-color-adjust: economy; print-color-adjust: exact; /\* Global values \*/ print-color-adjust: inherit; print-color-adjust: initial; print-color-adjust: revert; print-color-adjust: revert-layer; print-color-adjust: unset; ``` The `print-color-adjust` property's value must be one of the following keywords. ### Values `economy` The user agent is allowed to make adjustments to the element as it deems appropriate and prudent in order to optimize the output for the device it's being rendered for. For example, when printing, a browser might opt to leave out all background images and to adjust text colors to be sure the contrast is optimized for reading on white paper. This is the default. `exact` The element's content has been specifically and carefully crafted to use colors, images, and styles in a thoughtful and/or important way, such that being altered by the browser might actually make things worse rather than better. The appearance of the content should not be changed except by the user's request. For example, a page might include a list of information with rows whose background colors alternate between white and a light grey. Removing the background color would decrease the legibility of the content. Usage notes ----------- There are a number of reasons a browser might wish to deviate from the specified appearance, such as: * The content uses text and background colors that will be too similar on the output device for legibility purposes. * If the output device is a printer, and to save ink, dark or extremely dense background images might be removed. * When printing a page, the browser might want to replace light-colored text on a dark background with dark text on a white background. Any options the user agent offers the user to allow them to control the use of color and images will take priority over the value of `print-color-adjust`. In other words, there isn't any guarantee that `print-color-adjust` will do anything. Not only can the user override the behavior, but each user agent is allowed to decide for itself how to handle `print-color-adjust` in any given situation. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `economy` | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` print-color-adjust = economy [|](value_definition_syntax#single_bar) exact ``` Examples -------- ### Preserving low contrast In this example, a box is shown which uses a [`background-image`](background-image) and a translucent [`linear-gradient()`](gradient/linear-gradient) function atop a black background color to have a dark blue gradient behind medium red text. For whatever reason, this is the desired appearance in any rendering environment, including on paper, so we also use `print-color-adjust: exact` to tell the browser not to make color or style adjustments to the box when rendering it. #### CSS ``` .my-box { background-color: black; background-image: linear-gradient( rgba(0, 0, 180, 0.5), rgba(70, 140, 220, 0.5) ); color: #900; width: 15rem; height: 6rem; text-align: center; font: 24px "Helvetica", sans-serif; display: flex; align-items: center; justify-content: center; print-color-adjust: exact; } ``` #### HTML ``` <div class="my-box"> <p>Need more contrast!</p> </div> ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Color Adjustment Module Level 1 # propdef-print-color-adjust](https://w3c.github.io/csswg-drafts/css-color-adjust/#propdef-print-color-adjust) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `print-color-adjust` | 17 ["Chrome does not print backgrounds of the [`<body>`](https://developer.mozilla.org/docs/Web/HTML/Element/body) element. If this property is set to `exact` for the `<body>` element, it will apply only to its descendants.", "Before version 26, if background images are clipped (for example, when using `background-image` sprites) and `-webkit-print-color-adjust` is set to `exact`, then backgrounds will appear distorted when printed. Solid backgrounds and background images that are not clipped (i.e., backgrounds that have narrower and shorter than the element to which they are applied) are printed correctly. See [Chromium bug 131054](https://crbug.com/131054)."] | 79 Edge does not print backgrounds of the [`<body>`](https://developer.mozilla.org/docs/Web/HTML/Element/body) element. If this property is set to `exact` for the `<body>` element, it will apply only to its descendants. | 97 48 | No | 15 Opera does not print backgrounds of the [`<body>`](https://developer.mozilla.org/docs/Web/HTML/Element/body) element. If this property is set to `exact` for the `<body>` element, it will apply only to its descendants. | 15.4 6 Safari does not print backgrounds of the [`<body>`](https://developer.mozilla.org/docs/Web/HTML/Element/body) element. If this property is set to `exact` for the `<body>` element, it will apply only to its descendants. | 4.4 WebView does not print backgrounds of the [`<body>`](https://developer.mozilla.org/docs/Web/HTML/Element/body) element. If this property is set to `exact` for the `<body>` element, it will apply only to its descendants. | 18 ["Chrome does not print backgrounds of the [`<body>`](https://developer.mozilla.org/docs/Web/HTML/Element/body) element. If this property is set to `exact` for the `<body>` element, it will apply only to its descendants.", "Before version 26, if background images are clipped (for example, when using `background-image` sprites) and `-webkit-print-color-adjust` is set to `exact`, then backgrounds will appear distorted when printed. Solid backgrounds and background images that are not clipped (i.e., backgrounds that have narrower and shorter than the element to which they are applied) are printed correctly. See [Chromium bug 131054](https://crbug.com/131054)."] | 97 48 | 15 Opera does not print backgrounds of the [`<body>`](https://developer.mozilla.org/docs/Web/HTML/Element/body) element. If this property is set to `exact` for the `<body>` element, it will apply only to its descendants. | 15.4 6 Safari does not print backgrounds of the [`<body>`](https://developer.mozilla.org/docs/Web/HTML/Element/body) element. If this property is set to `exact` for the `<body>` element, it will apply only to its descendants. | 1.0 ["Samsung Internet does not print backgrounds of the [`<body>`](https://developer.mozilla.org/docs/Web/HTML/Element/body) element. If this property is set to `exact` for the `<body>` element, it will apply only to its descendants.", "In version 1, if background images are clipped (for example, when using `background-image` sprites) and `-webkit-print-color-adjust` is set to `exact`, then backgrounds will appear distorted when printed. Solid backgrounds and background images that are not clipped (i.e., backgrounds that have narrower and shorter than the element to which they are applied) are printed correctly. See [Chromium bug 131054](https://crbug.com/131054)."] | See also -------- * [Applying color to HTML elements using CSS](css_colors/applying_color) * Other color-related properties: [`color`](color), [`background-color`](background-color), [`border-color`](border-color), [`outline-color`](outline-color), [`text-decoration-color`](text-decoration-color), [`text-emphasis-color`](text-emphasis-color), [`text-shadow`](text-shadow), [`caret-color`](caret-color), and [`column-rule-color`](column-rule-color) * [`background-image`](background-image)
programming_docs
css display display ======= The `display` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets whether an element is treated as a [block or inline element](css_flow_layout) and the layout used for its children, such as [flow layout](css_flow_layout), [grid](css_grid_layout) or [flex](css_flexible_box_layout). Formally, the `display` property sets an element's inner and outer *display types*. The outer type sets an element's participation in [flow layout](css_flow_layout); the inner type sets the layout of children. Some values of `display` are fully defined in their own individual specifications; for example the detail of what happens when `display: flex` is declared is defined in the CSS Flexible Box Model specification. Try it ------ Syntax ------ The CSS `display` property is specified using keyword values. ``` /\* precomposed values \*/ display: block; display: inline; display: inline-block; display: flex; display: inline-flex; display: grid; display: inline-grid; display: flow-root; /\* box generation \*/ display: none; display: contents; /\* two-value syntax \*/ display: block flow; display: inline flow; display: inline flow-root; display: block flex; display: inline flex; display: block grid; display: inline grid; display: block flow-root; /\* other values \*/ display: table; display: table-row; /\* all table elements have an equivalent CSS display value \*/ display: list-item; /\* Global values \*/ display: inherit; display: initial; display: revert; display: revert-layer; display: unset; ``` Grouped values -------------- The keyword values can be grouped into six value categories. ### Outside [`<display-outside>`](display-outside) These keywords specify the element's outer display type, which is essentially its role in flow layout: `block` The element generates a block element box, generating line breaks both before and after the element when in the normal flow. `inline` The element generates one or more inline element boxes that do not generate line breaks before or after themselves. In normal flow, the next element will be on the same line if there is space. **Note:** Browsers that support the two-value syntax, on finding the outer value only, such as when `display: block` or `display: inline` is specified, will set the inner value to `flow`. This will result in expected behavior; for example, if you specify an element to be block, you would expect that the children of that element would participate in block and inline normal flow layout. ### Inside [`<display-inside>`](display-inside) These keywords specify the element's inner display type, which defines the type of formatting context that its contents are laid out in (assuming it is a non-replaced element): `flow` Experimental The element lays out its contents using flow layout (block-and-inline layout). If its outer display type is `inline` or `run-in`, and it is participating in a block or inline formatting context, then it generates an inline box. Otherwise it generates a block container box. Depending on the value of other properties (such as [`position`](position), [`float`](float), or [`overflow`](overflow)) and whether it is itself participating in a block or inline formatting context, it either establishes a new [block formatting context](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context) (BFC) for its contents or integrates its contents into its parent formatting context. `flow-root` The element generates a block element box that establishes a new [block formatting context](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context), defining where the formatting root lies. `table` These elements behave like HTML [`<table>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table) elements. It defines a block-level box. `flex` The element behaves like a block element and lays out its content according to the [flexbox model](css_flexible_box_layout). `grid` The element behaves like a block element and lays out its content according to the [grid model](css_grid_layout/basic_concepts_of_grid_layout). `ruby` Experimental The element behaves like an inline element and lays out its content according to the ruby formatting model. It behaves like the corresponding HTML [`<ruby>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ruby) elements. **Note:** Browsers that support the two-value syntax, on finding the inner value only, such as when `display: flex` or `display: grid` is specified, will set their outer value to `block`. This will result in expected behavior; for example, if you specify an element to be `display: grid`, you would expect that the box created on the grid container would be a block-level box. ### List Item [`<display-listitem>`](display-listitem) The element generates a block box for the content and a separate list-item inline box. A single value of `list-item` will cause the element to behave like a list item. This can be used together with [`list-style-type`](list-style-type) and [`list-style-position`](list-style-position). `list-item` can also be combined with any [`<display-outside>`](display-outside) keyword and the `flow` or `flow-root` [`<display-inside>`](display-inside) keywords. **Note:** In browsers that support the two-value syntax, if no inner value is specified, it will default to `flow`. If no outer value is specified, the principal box will have an outer display type of `block`. ### Internal [`<display-internal>`](display-internal) Some layout models such as `table` and `ruby` have a complex internal structure, with several different roles that their children and descendants can fill. This section defines those "internal" display values, which only have meaning within that particular layout mode. `table-row-group` These elements behave like [`<tbody>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tbody) HTML elements. `table-header-group` These elements behave like [`<thead>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/thead) HTML elements. `table-footer-group` These elements behave like [`<tfoot>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tfoot) HTML elements. `table-row` These elements behave like [`<tr>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tr) HTML elements. `table-cell` These elements behave like [`<td>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td) HTML elements. `table-column-group` These elements behave like [`<colgroup>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/colgroup) HTML elements. `table-column` These elements behave like [`<col>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/col) HTML elements. `table-caption` These elements behave like [`<caption>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption) HTML elements. `ruby-base` Experimental These elements behave like [`<rb>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/rb) HTML elements. `ruby-text` Experimental These elements behave like [`<rt>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/rt) HTML elements. `ruby-base-container` Experimental These elements are generated as anonymous boxes. `ruby-text-container` Experimental These elements behave like [`<rtc>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/rtc) HTML elements. ### Box [`<display-box>`](display-box) These values define whether an element generates display boxes at all. `contents` These elements don't produce a specific box by themselves. They are replaced by their pseudo-box and their child boxes. Please note that the CSS Display Level 3 spec defines how the `contents` value should affect "unusual elements" — elements that aren't rendered purely by CSS box concepts such as replaced elements. See [Appendix B: Effects of display: contents on Unusual Elements](https://drafts.csswg.org/css-display/#unbox) for more details. `none` Turns off the display of an element so that it has no effect on layout (the document is rendered as though the element did not exist). All descendant elements also have their display turned off. To have an element take up the space that it would normally take, but without actually rendering anything, use the [`visibility`](visibility) property instead. ### Precomposed [`<display-legacy>`](display-legacy) CSS 2 used a single-keyword, precomposed syntax for the `display` property, requiring separate keywords for block-level and inline-level variants of the same layout mode. `inline-block` The element generates a block element box that will be flowed with surrounding content as if it were a single inline box (behaving much like a replaced element would). It is equivalent to `inline flow-root`. `inline-table` The `inline-table` value does not have a direct mapping in HTML. It behaves like an HTML [`<table>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table) element, but as an inline box, rather than a block-level box. Inside the table box is a block-level context. It is equivalent to `inline table`. `inline-flex` The element behaves like an inline element and lays out its content according to the flexbox model. It is equivalent to `inline flex`. `inline-grid` The element behaves like an inline element and lays out its content according to the grid model. It is equivalent to `inline grid`. ### Which syntax should you use now? The Level 3 specification details two values for the `display` property — enabling the specification of the outer and inner display type explicitly — but this is not yet well-supported by browsers. The precomposed `<display-legacy>` methods allow the same results with single keyword values, and should be favoured by developers until the two keyword values are better supported. For example, using two values you might specify an inline flex container as follows: ``` .container { display: inline flex; } ``` This can currently be specified using a single value. ``` .container { display: inline-flex; } ``` For more information on these changes to the specification, see the article [Adapting to the new two-value syntax of display](display/two-value_syntax_of_display). ### Global ``` /\* Global values \*/ display: inherit; display: initial; display: unset; ``` Description ----------- The individual pages for the different types of value that `display` can have set on it feature multiple examples of those values in action — see the [Syntax](#syntax) section. In addition, see the following material, which covers the various values of display in depth. * [Adapting to the new two-value syntax of display](display/two-value_syntax_of_display) ### CSS Flow Layout (display: block, display: inline) * [Block and Inline Layout in Normal Flow](css_flow_layout/block_and_inline_layout_in_normal_flow) * [Flow Layout and Overflow](css_flow_layout/flow_layout_and_overflow) * [Flow Layout and Writing Modes](css_flow_layout/flow_layout_and_writing_modes) * [Formatting Contexts Explained](css_flow_layout/intro_to_formatting_contexts) * [In Flow and Out of Flow](css_flow_layout/in_flow_and_out_of_flow) ### display: flex * [Basic concepts of flexbox](css_flexible_box_layout/basic_concepts_of_flexbox) * [Aligning Items in a Flex Container](css_flexible_box_layout/aligning_items_in_a_flex_container) * [Controlling Ratios of Flex Items Along the Main Axis](css_flexible_box_layout/controlling_ratios_of_flex_items_along_the_main_ax) * [Mastering Wrapping of Flex Items](css_flexible_box_layout/mastering_wrapping_of_flex_items) * [Ordering Flex Items](css_flexible_box_layout/ordering_flex_items) * [Relationship of flexbox to other layout methods](css_flexible_box_layout/relationship_of_flexbox_to_other_layout_methods) * [Typical use cases of Flexbox](css_flexible_box_layout/typical_use_cases_of_flexbox) ### display: grid * [Basic Concepts of Grid Layout](css_grid_layout/basic_concepts_of_grid_layout) * [Relationship to other layout methods](css_grid_layout/relationship_of_grid_layout) * [Line-based placement](css_grid_layout/line-based_placement_with_css_grid) * [Grid template areas](css_grid_layout/grid_template_areas) * [Layout using named grid lines](css_grid_layout/layout_using_named_grid_lines) * [Auto-placement in grid layout](css_grid_layout/auto-placement_in_css_grid_layout) * [Box alignment in grid layout](css_grid_layout/box_alignment_in_css_grid_layout) * [Grids, logical values and writing modes](css_grid_layout/css_grid_logical_values_and_writing_modes) * [CSS Grid Layout and Accessibility](css_grid_layout/css_grid_layout_and_accessibility) * [CSS Grid Layout and Progressive Enhancement](css_grid_layout/css_grid_and_progressive_enhancement) * [Realizing common layouts using grids](css_grid_layout/realizing_common_layouts_using_css_grid_layout) Accessibility concerns ---------------------- ### display: none Using a `display` value of `none` on an element will remove it from the [accessibility tree](https://developer.mozilla.org/en-US/docs/Learn/Accessibility/What_is_accessibility#accessibility_apis). This will cause the element and all its descendant elements to no longer be announced by screen reading technology. If you want to visually hide the element, a more accessible alternative is to use [a combination of properties](https://gomakethings.com/hidden-content-for-better-a11y/#hiding-the-link) to remove it visually from the screen but keep it parsable by assistive technology such as screen readers. ### display: contents Current implementations in some browsers will remove from the [accessibility tree](https://developer.mozilla.org/en-US/docs/Learn/Accessibility/What_is_accessibility#accessibility_apis) any element with a `display` value of `contents` (but descendants will remain). This will cause the element itself to no longer be announced by screen reading technology. This is incorrect behavior according to the [CSS specification](https://drafts.csswg.org/css-display/#valdef-display-contents). * [More accessible markup with display: contents | Hidde de Vries](https://hidde.blog/more-accessible-markup-with-display-contents/) * [Display: Contents Is Not a CSS Reset | Adrian Roselli](https://adrianroselli.com/2018/05/display-contents-is-not-a-css-reset.html) ### Tables Changing the `display` value of a [`<table>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table) element to `block`, `grid`, or `flex` will alter its representation in the [accessibility tree](https://developer.mozilla.org/en-US/docs/Learn/Accessibility/What_is_accessibility#accessibility_apis). This will cause the table to no longer be announced properly by screen reading technology. * [Short note on what CSS display properties do to table semantics — The Paciello Group](https://www.tpgi.com/short-note-on-what-css-display-properties-do-to-table-semantics/) * [Hidden content for better a11y | Go Make Things](https://gomakethings.com/hidden-content-for-better-a11y/) * [MDN Understanding WCAG, Guideline 1.3 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.3_%e2%80%94_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) Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `inline` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as the specified value, except for positioned and floating elements and the root element. In both cases the computed value may be a keyword other than the one specified. | | Animation type | Not animatable | Formal syntax ------------- ``` display = [[](value_definition_syntax#brackets) <display-outside> [||](value_definition_syntax#double_bar) <display-inside> []](value_definition_syntax#brackets) [|](value_definition_syntax#single_bar) <display-listitem> [|](value_definition_syntax#single_bar) <display-internal> [|](value_definition_syntax#single_bar) <display-box> [|](value_definition_syntax#single_bar) <display-legacy> [|](value_definition_syntax#single_bar) <display-outside> [||](value_definition_syntax#double_bar) [[](value_definition_syntax#brackets) <display-inside> [|](value_definition_syntax#single_bar) math []](value_definition_syntax#brackets) <display-outside> = block [|](value_definition_syntax#single_bar) inline [|](value_definition_syntax#single_bar) run-in <display-inside> = flow [|](value_definition_syntax#single_bar) flow-root [|](value_definition_syntax#single_bar) table [|](value_definition_syntax#single_bar) flex [|](value_definition_syntax#single_bar) grid [|](value_definition_syntax#single_bar) ruby <display-listitem> = <display-outside>[?](value_definition_syntax#question_mark) [&&](value_definition_syntax#double_ampersand) [[](value_definition_syntax#brackets) flow [|](value_definition_syntax#single_bar) flow-root []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) [&&](value_definition_syntax#double_ampersand) list-item <display-internal> = table-row-group [|](value_definition_syntax#single_bar) table-header-group [|](value_definition_syntax#single_bar) table-footer-group [|](value_definition_syntax#single_bar) table-row [|](value_definition_syntax#single_bar) table-cell [|](value_definition_syntax#single_bar) table-column-group [|](value_definition_syntax#single_bar) table-column [|](value_definition_syntax#single_bar) table-caption [|](value_definition_syntax#single_bar) ruby-base [|](value_definition_syntax#single_bar) ruby-text [|](value_definition_syntax#single_bar) ruby-base-container [|](value_definition_syntax#single_bar) ruby-text-container <display-box> = contents [|](value_definition_syntax#single_bar) none <display-legacy> = inline-block [|](value_definition_syntax#single_bar) inline-table [|](value_definition_syntax#single_bar) inline-flex [|](value_definition_syntax#single_bar) inline-grid ``` Examples -------- ### display value comparison In this example we have two block-level container elements, each one with three inline children. Below that, we have a select menu that allows you to apply different `display` values to the containers, allowing you to compare and contrast how the different values affect the element's layout, and that of their children. We've included [`padding`](padding) and [`background-color`](background-color) on the containers and their children, so that it is easier to see the effect the display values are having. **Note:** We've not included any of the modern two-value syntax, as support for that is still fairly limited. #### HTML ``` <article class="container"> <span>First</span> <span>Second</span> <span>Third</span> </article> <article class="container"> <span>First</span> <span>Second</span> <span>Third</span> </article> <div> <label for="display">Choose a display value:</label> <select id="display"> <option selected>block</option> <option>inline</option> <option>inline-block</option> <option>none</option> <option>flex</option> <option>inline-flex</option> <option>grid</option> <option>inline-grid</option> <option>table</option> <option>list-item</option> </select> </div> ``` #### CSS ``` html { font-family: helvetica, arial, sans-serif; letter-spacing: 1px; padding-top: 10px; } article { background-color: red; } article span { background-color: black; color: white; margin: 1px; } article, span { padding: 10px; border-radius: 7px; } article, div { margin: 20px; } ``` #### JavaScript ``` const articles = document.querySelectorAll('.container'); const select = document.querySelector('select'); function updateDisplay() { articles.forEach((article) => { article.style.display = select.value; }); } select.addEventListener('change', updateDisplay); updateDisplay(); ``` #### Result **Note:** You can find more examples in the pages for each separate display data type, linked above. Specifications -------------- | Specification | | --- | | [CSS Display Module Level 3 # the-display-properties](https://w3c.github.io/csswg-drafts/css-display/#the-display-properties) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `display` | 1 | 12 | 1 | 4 | 7 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | | `contents` | 65 | 79 | 37 | No | 52 | 11.1 | 65 | 65 | 37 | 47 | 11.3 | 9.0 | | `display-outside` | 1 | 12 | 1 | 4 | 7 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `flex` | 29 21 | 12 | 20 Firefox 28 added multi-line flexbox support. | 11 IE incorrectly positions inline block content inside flex containers. See the [discussion on Microsoft Answers](https://answers.microsoft.com/en-us/ie/forum/ie11-iewindows_10/inline-block-content-in-a-flex-container-not/deea64e2-933b-4bd2-a98c-62be16d04b57). 8 IE incorrectly positions inline block content inside flex containers. See the [discussion on Microsoft Answers](https://answers.microsoft.com/en-us/ie/forum/ie11-iewindows_10/inline-block-content-in-a-flex-container-not/deea64e2-933b-4bd2-a98c-62be16d04b57). | 16 15 12.1-15 | 9 7 | ≤37 4.4 | 29 25 | 20 Firefox 28 added multi-line flexbox support. | 16 14 12.1-14 | 9 7 | 2.0 1.5 | | `flow-root` | 58 | 79 | 53 | No | 45 | 13 | 58 | 58 | 53 | 43 | 13 | 7.0 | | `grid` | 57 | 16 12 | 52 | 10 Internet Explorer implements an older version of the specification. | 44 | 10.1 | 57 | 57 | 52 | 43 | 10.3 | 6.0 Samsung Internet added this earlier than the corresponding Chrome version would indicate. | | `inline-block` | 1 | 12 | 1 | 8 6 Until Internet Explorer 8, `inline-block` is only for natural inline elements. | 7 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | | `inline-flex` | 29 21 | 12 | 20 Firefox 28 added multi-line flexbox support. | 11 8 | 16 15 | 9 7 | ≤37 4.4 | 29 25 | 20 Firefox 28 added multi-line flexbox support. | 16 14 | 9 7 | 2.0 1.5 | | `inline-grid` | 57 | 16 12 | 52 | 10 Internet Explorer implements an older version of the specification. | 44 | 10.1 | 57 | 57 | 52 | 43 | 10.3 | 6.0 Samsung Internet added this earlier than the corresponding Chrome version would indicate. | | `inline-table` | 1 | 12 | 3 | 8 | 7 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | | `list-item` | 1 | 12 | 1 | 6 | 7 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | | `math` | 87 | 87 | No | No | 73 | No | No | 87 | No | No | No | No | | `multi-keyword_values` | No | No | 70 | No | No | 15 | No | No | No | No | 15 | No | | `none` | 1 Chrome 65 stopped creating layout objects for elements inside an `<iframe>` with `display:none` applied. | 12 | 1 | 4 | 7 Opera 52 stopped creating layout objects for elements inside an `<iframe>` with `display:none` applied. | 1 | ≤37 WebView 65 stopped creating layout objects for elements inside an `<iframe>` with `display:none` applied. | 18 Chrome 65 stopped creating layout objects for elements inside an `<iframe>` with `display:none` applied. | 4 | 10.1 Opera Android 47 stopped creating layout objects for elements inside an `<iframe>` with `display:none` applied. | 1 | 1.0 Chrome 65 stopped creating layout objects for elements inside an `<iframe>` with `display:none` applied. | | `ruby_values` | No | 12-79 | 38 | 7 | No | No | No | No | 38 | No | No | No | | `table_values` | 1 | 12 | 1 | 8 | 7 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [Block and inline layout in normal flow](css_flow_layout/block_and_inline_layout_in_normal_flow) * [Introduction to formatting contexts](css_flow_layout/intro_to_formatting_contexts) * [`visibility`](visibility), [`float`](float), [`position`](position) * [`grid`](grid), [`flex`](flex)
programming_docs
css :nth-last-of-type() :nth-last-of-type() =================== The `:nth-last-of-type()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) matches elements based on their position among siblings of the same type (tag name), counting from the end. Try it ------ Syntax ------ The `nth-last-of-type` pseudo-class is specified with a single argument, which represents the pattern for matching elements, counting from the end. See [`:nth-last-child`](:nth-last-child) for a more detailed explanation of its syntax. ``` :nth-last-of-type( <an-plus-b> | even | odd ) ``` Examples -------- ### HTML ``` <div> <span>This is a span.</span> <span>This is another span.</span> <em>This is emphasized.</em> <span>Wow, this span gets limed!!!</span> <del>This is struck through.</del> <span>Here is one last span.</span> </div> ``` ### CSS ``` span:nth-last-of-type(2) { background-color: lime; } ``` ### Result Specifications -------------- | Specification | | --- | | [Selectors Level 4 # nth-last-of-type-pseudo](https://w3c.github.io/csswg-drafts/selectors/#nth-last-of-type-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:nth-last-of-type` | 4 | 12 Before Edge 16, Microsoft Edge treats all unknown elements (such as custom elements) as the same element type. | 3.5 | 9 Internet Explorer treats all unknown elements (such as custom elements) as the same element type. | 9.5 | 3.1 | 2 | 18 | 4 | 10.1 | 2 | 1.0 | See also -------- * [`:nth-last-child`](:nth-last-child), [`:nth-of-type`](:nth-of-type) css <number> <number> ======== The `<number>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) represents a number, being either an integer or a number with a fractional component. Syntax ------ The syntax of `<number>` extends the syntax of [`<integer>`](integer). A fractional value is represented by a `.` followed by one or more decimal digits, and may be appended to an integer. There is no unit associated with numbers. Interpolation ------------- When animated, values of the `<number>` CSS data type are interpolated as real, floating-point numbers. The speed of the interpolation is determined by the [timing function](easing-function) associated with the animation. Examples -------- ### Valid numbers ``` 12 A raw <integer> is also a <number>. 4.01 Positive fraction -456.8 Negative fraction 0.0 Zero +0.0 Zero, with a leading + -0.0 Zero, with a leading - .60 Fractional number without a leading zero 10e3 Scientific notation -3.4e-2 Complicated scientific notation ``` ### Invalid numbers ``` 12. Decimal points must be followed by at least one digit. +-12.2 Only one leading +/- is allowed. 12.1.1 Only one decimal point is allowed. ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # numbers](https://w3c.github.io/csswg-drafts/css-values/#numbers) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `number` | 1 | 12 | 1 | 5 | 2 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `scientific_notation` | 43 | 12 | 29 | 11 | 30 | 10.1 | 43 | 43 | 29 | 30 | 10.3 | 4.0 | See also -------- * [`<integer>`](integer) css grid-row grid-row ======== The `grid-row` CSS [shorthand property](shorthand_properties) specifies a grid item's size and location within a [grid row](https://developer.mozilla.org/en-US/docs/Glossary/Grid_Row) by contributing a line, a span, or nothing (automatic) to its grid placement, thereby specifying the inline-start and inline-end edge of its [grid area](https://developer.mozilla.org/en-US/docs/Glossary/Grid_Areas). Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`grid-row-end`](grid-row-end) * [`grid-row-start`](grid-row-start) Syntax ------ ``` /\* Keyword values \*/ grid-row: auto; grid-row: auto / auto; /\* <custom-ident> values \*/ grid-row: somegridarea; grid-row: somegridarea / someothergridarea; /\* <integer> + <custom-ident> values \*/ grid-row: somegridarea 4; grid-row: 4 somegridarea / 6; /\* span + <integer> + <custom-ident> values \*/ grid-row: span 3; grid-row: span somegridarea; grid-row: 5 somegridarea span; grid-row: span 3 / 6; grid-row: span somegridarea / span someothergridarea; grid-row: 5 somegridarea span / 2 span; /\* Global values \*/ grid-row: inherit; grid-row: initial; grid-row: revert; grid-row: revert-layer; grid-row: unset; ``` This property is specified as one or two `<grid-line>` values. If two `<grid-line>` values are given, they are separated by `/`. The `grid-row-start` longhand is set to the value before the slash, and the `grid-row-end` longhand is set to the value after the slash. Each `<grid-line>` value can be specified as: * either the `auto` keyword * or a `<custom-ident>` value * or an `<integer>` value * or both `<custom-ident>` and `<integer>`, separated by a space * or the keyword `span` together with either a `<custom-ident>` or an `<integer>` or both. ### Values `auto` Is a keyword indicating that the property contributes nothing to the grid item's placement, indicating auto-placement, an automatic span, or a default span of `1`. `<custom-ident>` If there is a named line with the name `<custom-ident>-start`/`<custom-ident>-end`, it contributes the first such line to the grid item's placement. **Note:** Named grid areas automatically generate implicit named lines of this form, so specifying `grid-row: foo;` will choose the start/end edge of that named grid area (unless another line named `foo-start`/`foo-end` was explicitly specified before it). Otherwise, this is treated as if the integer `1` had been specified along with the `<custom-ident>`. `<integer> && <custom-ident>?` Contributes the nth grid line to the grid item's placement. If a negative integer is given, it instead counts in reverse, starting from the end edge of the explicit grid. If a name is given as a `<custom-ident>`, only lines with that name are counted. If not enough lines with that name exist, all implicit grid lines are assumed to have that name for the purpose of finding this position. An [`<integer>`](integer) value of `0` is invalid. `span && [ <integer> || <custom-ident> ]` Contributes a grid span to the grid item's placement such that the corresponding edge of the grid item's grid area is n lines from the opposite edge. If a name is given as a `<custom-ident>`, only lines with that name are counted. If not enough lines with that name exist, all implicit grid lines on the side of the explicit grid corresponding to the search direction are assumed to have that name for the purpose of counting this span. If the `<integer>` is omitted, it defaults to `1`. Negative integers or 0 are invalid. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`grid-row-start`](grid-row-start): `auto` * [`grid-row-end`](grid-row-end): `auto` | | Applies to | grid items and absolutely-positioned boxes whose containing block is a grid container | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`grid-row-start`](grid-row-start): as specified * [`grid-row-end`](grid-row-end): as specified | | Animation type | discrete | Formal syntax ------------- ``` grid-row = <grid-line> [[](value_definition_syntax#brackets) / <grid-line> []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) <grid-line> = auto [|](value_definition_syntax#single_bar) [<custom-ident>](custom-ident) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) [<integer [-∞,-1]>](integer) [|](value_definition_syntax#single_bar) [<integer [1,∞]>](integer) []](value_definition_syntax#brackets) [&&](value_definition_syntax#double_ampersand) [<custom-ident>](custom-ident)[?](value_definition_syntax#question_mark) []](value_definition_syntax#brackets) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) span [&&](value_definition_syntax#double_ampersand) [[](value_definition_syntax#brackets) [<integer [1,∞]>](integer) [||](value_definition_syntax#double_bar) [<custom-ident>](custom-ident) []](value_definition_syntax#brackets) []](value_definition_syntax#brackets) ``` Examples -------- ### Setting grid row size and location #### HTML ``` <div id="grid"> <div id="item1"></div> <div id="item2"></div> <div id="item3"></div> </div> ``` #### CSS ``` #grid { display: grid; height: 200px; grid-template-columns: 200px; grid-template-rows: repeat(6, 1fr); } #item1 { background-color: lime; } #item2 { background-color: yellow; grid-row: 2 / 4; } #item3 { background-color: blue; grid-row: span 2 / 7; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Grid Layout Module Level 2 # placement-shorthands](https://w3c.github.io/csswg-drafts/css-grid/#placement-shorthands) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `grid-row` | 57 | 16 | 52 | No | 44 | 10.1 | 57 | 57 | 52 | 43 | 10.3 | 6.0 | See also -------- * Related CSS properties: [`grid-row-start`](grid-row-start), [`grid-row-end`](grid-row-end), [`grid-column`](grid-column), [`grid-column-start`](grid-column-start), [`grid-column-end`](grid-column-end) * Grid Layout Guide: *[Line-based placement with CSS Grid](css_grid_layout/line-based_placement_with_css_grid)* * Video tutorial: *[Line-based placement](https://gridbyexample.com/video/series-line-based-placement/)* css background-position-y background-position-y ===================== The `background-position-y` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the initial vertical position for each background image. The position is relative to the position layer set by [`background-origin`](background-origin). Try it ------ The value of this property is overridden by any declaration of the [`background`](background) or [`background-position`](background-position) shorthand properties applied to the element after it. Syntax ------ ``` /\* Keyword values \*/ background-position-y: top; background-position-y: center; background-position-y: bottom; /\* <percentage> values \*/ background-position-y: 25%; /\* <length> values \*/ background-position-y: 0px; background-position-y: 1cm; background-position-y: 8em; /\* Side-relative values \*/ background-position-y: bottom 3px; background-position-y: bottom 10%; /\* Multiple values \*/ background-position-y: 0px, center; /\* Global values \*/ background-position-y: inherit; background-position-y: initial; background-position-y: revert; background-position-y: revert-layer; background-position-y: unset; ``` The `background-position-y` property is specified as one or more values, separated by commas. ### Values `top` Aligns the top edge of the background image with the top edge of the background position layer. `center` Aligns the vertical center of the background image with the vertical center of the background position layer. `bottom` Aligns the bottom edge of the background image with the bottom edge of the background position layer. [`<length>`](length) The offset of the given background image's horizontal edge from the corresponding background position layer's top horizontal edge. (Some browsers allow assigning the bottom edge for offset). [`<percentage>`](percentage) The offset of the given background image's vertical position relative to the container. A value of 0% means that the top edge of the background image is aligned with the top edge of the container, and a value of 100% means that the *bottom* edge of the background image is aligned with the *bottom* edge of the container, thus a value of 50% vertically centers the background image. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0%` | | Applies to | all elements | | [Inherited](inheritance) | no | | Percentages | refer to height of background positioning area minus height of background image | | [Computed value](computed_value) | A list, each item consisting of: an offset given as a combination of an absolute length and a percentage, plus an origin keyword | | Animation type | discrete | Formal syntax ------------- ``` background-position-y = [[](value_definition_syntax#brackets) center [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) top [|](value_definition_syntax#single_bar) bottom [|](value_definition_syntax#single_bar) y-start [|](value_definition_syntax#single_bar) y-end []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) <length-percentage>[?](value_definition_syntax#question_mark) ]! []](value_definition_syntax#brackets)[#](value_definition_syntax#hash_mark) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Basic example The following example shows a simple background image implementation, with background-position-x and background-position-y used to define the image's horizontal and vertical positions separately. #### HTML ``` <div></div> ``` #### CSS ``` div { width: 300px; height: 300px; background-color: skyblue; background-image: url(https://media.prod.mdn.mozit.cloud/attachments/2020/07/29/17350/3b4892b7e820122ac6dd7678891d4507/firefox.png); background-repeat: no-repeat; background-position-x: center; background-position-y: bottom 10px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 4 # background-position-longhands](https://w3c.github.io/csswg-drafts/css-backgrounds-4/#background-position-longhands) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `2_value_syntax` | No | 12-79 | 49 | 9 | No | 15.4 | No | No | 49 | No | 15.4 | No | | `background-position-y` | 1 | 12 | 49 | 6 | 15 | 1 | ≤37 | 18 | 49 | 14 | 1 | 1.0 | See also -------- * [`background-position`](background-position) * [`background-position-x`](background-position-x) * `background-position-inline` * `background-position-block` * [Using multiple backgrounds](css_backgrounds_and_borders/using_multiple_backgrounds) css offset-rotate offset-rotate ============= The `offset-rotate` CSS property defines the orientation/direction of the element as it is positioned along the [`offset-path`](offset-path). Try it ------ **Note:** Early versions of the spec called this property `motion-rotation`. Syntax ------ ``` /\* Follow the path direction, with optional additional angle \*/ offset-rotate: auto; offset-rotate: auto 45deg; /\* Follow the path direction but facing the opposite direction of `auto` \*/ offset-rotate: reverse; /\* Keep a constant rotation regardless the position on the path \*/ offset-rotate: 90deg; offset-rotate: 0.5turn; /\* Global values \*/ offset-rotate: inherit; offset-rotate: initial; offset-rotate: revert; offset-rotate: revert-layer; offset-rotate: unset; ``` `auto` The element is rotated by the angle of the direction of the [`offset-path`](offset-path), relative to the positive x-axis. This is the default value. `[`<angle>`](angle)` The element has a constant clockwise rotation transformation applied to it by the specified rotation angle. `auto <angle>` If `auto` is followed by an [`<angle>`](angle), the computed value of the angle is added to the computed value of `auto`. `reverse` The element is rotated similar to `auto`, except it faces the opposite direction. It is the same as specifying a value of `auto 180deg`. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | transformable elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | as <angle>, <basic-shape> or <path()> | Formal syntax ------------- ``` offset-rotate = [[](value_definition_syntax#brackets) auto [|](value_definition_syntax#single_bar) reverse []](value_definition_syntax#brackets) [||](value_definition_syntax#double_bar) [<angle>](angle) ``` Examples -------- ### Setting element orientation along its offset path #### HTML ``` <div></div> <div></div> <div></div> ``` #### CSS ``` div { width: 40px; height: 40px; background: #2bc4a2; margin: 20px; clip-path: polygon(0% 0%, 70% 0%, 100% 50%, 70% 100%, 0% 100%, 30% 50%); animation: move 5000ms infinite alternate ease-in-out; offset-path: path("M20,20 C20,50 180,-10 180,20"); } div:nth-child(1) { offset-rotate: auto; } div:nth-child(2) { offset-rotate: auto 90deg; } div:nth-child(3) { offset-rotate: 30deg; } @keyframes move { 100% { offset-distance: 100%; } } ``` #### Result Specifications -------------- | Specification | | --- | | [Motion Path Module Level 1 # offset-rotate-property](https://drafts.fxtf.org/motion/#offset-rotate-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `offset-rotate` | 56 55 46 | 79 79 79 | 72 | No | 43 42 33 | preview | 56 55 46 | 56 55 46 | No | 43 42 33 | No | 6.0 6.0 5.0 | See also -------- * [`offset`](offset) * [`offset-anchor`](offset-anchor) * [`offset-distance`](offset-distance) * [`offset-path`](offset-path) * [`offset-position`](offset-position) css position position ======== The `position` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets how an element is positioned in a document. The [`top`](top), [`right`](right), [`bottom`](bottom), and [`left`](left) properties determine the final location of positioned elements. Try it ------ Syntax ------ ``` position: static; position: relative; position: absolute; position: fixed; position: sticky; /\* Global values \*/ position: inherit; position: initial; position: revert; position: revert-layer; position: unset; ``` ### Values `static` The element is positioned according to the normal flow of the document. The [`top`](top), [`right`](right), [`bottom`](bottom), [`left`](left), and [`z-index`](z-index) properties have *no effect*. This is the default value. `relative` The element is positioned according to the normal flow of the document, and then offset *relative to itself* based on the values of `top`, `right`, `bottom`, and `left`. The offset does not affect the position of any other elements; thus, the space given for the element in the page layout is the same as if position were `static`. This value creates a new [stacking context](css_positioning/understanding_z_index/the_stacking_context) when the value of `z-index` is not `auto`. Its effect on `table-*-group`, `table-row`, `table-column`, `table-cell`, and `table-caption` elements is undefined. `absolute` The element is removed from the normal document flow, and no space is created for the element in the page layout. It is positioned relative to its closest [positioned](#types_of_positioning) ancestor, if any; otherwise, it is placed relative to the initial [containing block](containing_block). Its final position is determined by the values of `top`, `right`, `bottom`, and `left`. This value creates a new [stacking context](css_positioning/understanding_z_index/the_stacking_context) when the value of `z-index` is not `auto`. The margins of absolutely positioned boxes do not [collapse](css_box_model/mastering_margin_collapsing) with other margins. `fixed` The element is removed from the normal document flow, and no space is created for the element in the page layout. It is positioned relative to the initial [containing block](containing_block) established by the [viewport](https://developer.mozilla.org/en-US/docs/Glossary/Viewport), except when one of its ancestors has a `transform`, `perspective`, or `filter` property set to something other than `none` (see the [CSS Transforms Spec](https://www.w3.org/TR/css-transforms-1/#propdef-transform)), or the [`will-change`](will-change) property is set to `transform`, in which case that ancestor behaves as the containing block. (Note that there are browser inconsistencies with `perspective` and `filter` contributing to containing block formation.) Its final position is determined by the values of `top`, `right`, `bottom`, and `left`. This value always creates a new [stacking context](css_positioning/understanding_z_index/the_stacking_context). In printed documents, the element is placed in the same position on *every page*. `sticky` The element is positioned according to the normal flow of the document, and then offset relative to its *nearest scrolling ancestor* and [containing block](containing_block) (nearest block-level ancestor), including table-related elements, based on the values of `top`, `right`, `bottom`, and `left`. The offset does not affect the position of any other elements. This value always creates a new [stacking context](css_positioning/understanding_z_index/the_stacking_context). Note that a sticky element "sticks" to its nearest ancestor that has a "scrolling mechanism" (created when `overflow` is `hidden`, `scroll`, `auto`, or `overlay`), even if that ancestor isn't the nearest actually scrolling ancestor. Description ----------- ### Types of positioning * A **positioned element** is an element whose [computed](computed_value) `position` value is either `relative`, `absolute`, `fixed`, or `sticky`. (In other words, it's anything except `static`.) * A **relatively positioned element** is an element whose [computed](computed_value) `position` value is `relative`. The [`top`](top) and [`bottom`](bottom) properties specify the vertical offset from its normal position; the [`left`](left) and [`right`](right) properties specify the horizontal offset. * An **absolutely positioned element** is an element whose [computed](computed_value) `position` value is `absolute` or `fixed`. The [`top`](top), [`right`](right), [`bottom`](bottom), and [`left`](left) properties specify offsets from the edges of the element's [containing block](containing_block). (The containing block is the ancestor relative to which the element is positioned.) If the element has margins, they are added to the offset. The element establishes a new [block formatting context](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context) (BFC) for its contents. * A **stickily positioned element** is an element whose [computed](computed_value) `position` value is `sticky`. It's treated as relatively positioned until its [containing block](containing_block) crosses a specified threshold (such as setting [`top`](top) to value other than auto) within its flow root (or the container it scrolls within), at which point it is treated as "stuck" until meeting the opposite edge of its [containing block](containing_block). Most of the time, absolutely positioned elements that have [`height`](height) and [`width`](width) set to `auto` are sized so as to fit their contents. However, non-[replaced](replaced_element), absolutely positioned elements can be made to fill the available vertical space by specifying both [`top`](top) and [`bottom`](bottom) and leaving [`height`](height) unspecified (that is, `auto`). They can likewise be made to fill the available horizontal space by specifying both [`left`](left) and [`right`](right) and leaving [`width`](width) as `auto`. Except for the case just described (of absolutely positioned elements filling the available space): * If both `top` and `bottom` are specified (technically, not `auto`), `top` wins. * If both `left` and `right` are specified, `left` wins when [`direction`](direction) is `ltr` (English, horizontal Japanese, etc.) and `right` wins when [`direction`](direction) is `rtl` (Persian, Arabic, Hebrew, etc.). Accessibility concerns ---------------------- Ensure that elements positioned with an `absolute` or `fixed` value do not obscure other content when the page is zoomed to increase text size. * [MDN Understanding WCAG, Guideline 1.4 explanations](https://developer.mozilla.org/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) * [Visual Presentation: Understanding SC 1.4.8 | Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-visual-presentation.html) ### Performance & Accessibility Scrolling elements containing `fixed` or `sticky` content can cause performance and accessibility issues. As a user scrolls, the browser must repaint the sticky or fixed content in a new location. Depending on the content needing to be repainted, the browser performance, and the device's processing speed, the browser may not be able to manage repaints at 60 fps, causing accessibility concerns for people with sensitivities and jank for everyone. One solution is to add [`will-change: transform`](will-change) to the positioned elements to render the element in its own layer, improving repaint speed and therefore improving performance and accessibility. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `static` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | | Creates [stacking context](css_positioning/understanding_z_index/the_stacking_context) | yes | Formal syntax ------------- ``` position = static [|](value_definition_syntax#single_bar) relative [|](value_definition_syntax#single_bar) absolute [|](value_definition_syntax#single_bar) sticky [|](value_definition_syntax#single_bar) fixed [|](value_definition_syntax#single_bar) running( ) ``` Examples -------- ### Relative positioning Relatively positioned elements are offset a given amount from their normal position within the document, but without the offset affecting other elements. In the example below, note how the other elements are placed as if "Two" were taking up the space of its normal location. #### HTML ``` <div class="box" id="one">One</div> <div class="box" id="two">Two</div> <div class="box" id="three">Three</div> <div class="box" id="four">Four</div> ``` #### CSS ``` \* { box-sizing: border-box; } .box { display: inline-block; width: 100px; height: 100px; background: red; color: white; } #two { position: relative; top: 20px; left: 20px; background: blue; } ``` ### Absolute positioning Elements that are relatively positioned remain in the normal flow of the document. In contrast, an element that is absolutely positioned is taken out of the flow; thus, other elements are positioned as if it did not exist. The absolutely positioned element is positioned relative to its *nearest positioned ancestor* (i.e., the nearest ancestor that is not `static`). If a positioned ancestor doesn't exist, it is positioned relative to the ICB (initial containing block — see also the [W3C definition](https://www.w3.org/TR/CSS2/visudet.html#containing-block-details)), which is the containing block of the document's root element. #### HTML ``` <h1>Absolute positioning</h1> <p> I am a basic block level element. My adjacent block level elements sit on new lines below me. </p> <p class="positioned"> By default we span 100% of the width of our parent element, and we are as tall as our child content. Our total width and height is our content + padding + border width/height. </p> <p> We are separated by our margins. Because of margin collapsing, we are separated by the width of one of our margins, not both. </p> <p> inline elements <span>like this one</span> and <span>this one</span> sit on the same line as one another, and adjacent text nodes, if there is space on the same line. Overflowing inline elements <span>wrap onto a new line if possible — like this one containing text</span>, or just go on to a new line if not, much like this image will do: <img src="long.jpg" /> </p> ``` #### CSS ``` \* { box-sizing: border-box; } body { width: 500px; margin: 0 auto; } p { background: aqua; border: 3px solid blue; padding: 10px; margin: 10px; } span { background: red; border: 1px solid black; } .positioned { position: absolute; background: yellow; top: 30px; left: 30px; } ``` #### Result ### Fixed positioning Fixed positioning is similar to absolute positioning, with the exception that the element's [containing block](containing_block) is the initial containing block established by the *viewport*, unless any ancestor has `transform`, `perspective`, or `filter` property set to something other than `none` (see [CSS Transforms Spec](https://www.w3.org/TR/css-transforms-1/#propdef-transform)), which then causes that ancestor to take the place of the elements [containing block](containing_block). This can be used to create a "floating" element that stays in the same position regardless of scrolling. In the example below, box "One" is fixed at 80 pixels from the top of the page and 10 pixels from the left. Even after scrolling, it remains in the same place relative to the viewport. Also, when the [`will-change`](will-change) property is set to `transform`, a new containing block is established. #### HTML ``` <div class="outer"> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam congue tortor eget pulvinar lobortis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nam ac dolor augue. Pellentesque mi mi, laoreet et dolor sit amet, ultrices varius risus. Nam vitae iaculis elit. Aliquam mollis interdum libero. Sed sodales placerat egestas. Vestibulum ut arcu aliquam purus viverra dictum vel sit amet mi. Duis nisl mauris, aliquam sit amet luctus eget, dapibus in enim. Sed velit augue, pretium a sem aliquam, congue porttitor tortor. Sed tempor nisl a lorem consequat, id maximus erat aliquet. Sed sagittis porta libero sed condimentum. Aliquam finibus lectus nec ante congue rutrum. Curabitur quam quam, accumsan id ultrices ultrices, tempor et tellus. </p> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam congue tortor eget pulvinar lobortis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nam ac dolor augue. Pellentesque mi mi, laoreet et dolor sit amet, ultrices varius risus. Nam vitae iaculis elit. Aliquam mollis interdum libero. Sed sodales placerat egestas. Vestibulum ut arcu aliquam purus viverra dictum vel sit amet mi. Duis nisl mauris, aliquam sit amet luctus eget, dapibus in enim. Sed velit augue, pretium a sem aliquam, congue porttitor tortor. Sed tempor nisl a lorem consequat, id maximus erat aliquet. Sed sagittis porta libero sed condimentum. Aliquam finibus lectus nec ante congue rutrum. Curabitur quam quam, accumsan id ultrices ultrices, tempor et tellus. </p> <div class="box" id="one">One</div> </div> ``` #### CSS ``` \* { box-sizing: border-box; } .box { width: 100px; height: 100px; background: red; color: white; } #one { position: fixed; top: 80px; left: 10px; background: blue; } .outer { width: 500px; height: 300px; overflow: scroll; padding-left: 150px; } ``` #### Result ### Sticky positioning Sticky positioning can be thought of as a hybrid of relative and fixed positioning when its nearest scrolling ancestor is the viewport. A stickily positioned element is treated as relatively positioned until it crosses a specified threshold, at which point it is treated as fixed until it reaches the boundary of its parent. For example: ``` #one { position: sticky; top: 10px; } ``` The above CSS rule would position the element with id *one* relatively until the viewport was scrolled such that the element would be less than 10 pixels from the top. Beyond that threshold, the element would be fixed to 10 pixels from the top. A common use for sticky positioning is for the headings in an alphabetized list. The "B" heading will appear just below the items that begin with "A" until they are scrolled offscreen. Rather than sliding offscreen with the rest of the content, the "B" heading will then remain fixed to the top of the viewport until all the "B" items have scrolled offscreen, at which point it will be covered up by the "C" heading, and so on. You must specify a threshold with at least one of `top`, `right`, `bottom`, or `left` for sticky positioning to behave as expected. Otherwise, it will be indistinguishable from relative positioning. #### HTML ``` <dl> <div> <dt>A</dt> <dd>Andrew W.K.</dd> <dd>Apparat</dd> <dd>Arcade Fire</dd> <dd>At The Drive-In</dd> <dd>Aziz Ansari</dd> </div> <div> <dt>C</dt> <dd>Chromeo</dd> <dd>Common</dd> <dd>Converge</dd> <dd>Crystal Castles</dd> <dd>Cursive</dd> </div> <div> <dt>E</dt> <dd>Explosions In The Sky</dd> </div> <div> <dt>T</dt> <dd>Ted Leo &amp; The Pharmacists</dd> <dd>T-Pain</dd> <dd>Thrice</dd> <dd>TV On The Radio</dd> <dd>Two Gallants</dd> </div> </dl> ``` #### CSS ``` \* { box-sizing: border-box; } dl > div { background: #fff; padding: 24px 0 0 0; } dt { background: #b8c1c8; border-bottom: 1px solid #989ea4; border-top: 1px solid #717d85; color: #fff; font: bold 18px/21px Helvetica, Arial, sans-serif; margin: 0; padding: 2px 0 0 12px; position: -webkit-sticky; position: sticky; top: -1px; } dd { font: bold 20px/45px Helvetica, Arial, sans-serif; margin: 0; padding: 0 0 0 12px; white-space: nowrap; } dd + dd { border-top: 1px solid #ccc; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Positioned Layout Module Level 3 # position-property](https://w3c.github.io/csswg-drafts/css-position/#position-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `position` | 1 | 12 | 1 ["Before Firefox 57, absolute positioning did not work correctly when applied to elements inside tables that have [`border-collapse`](https://developer.mozilla.org/docs/Web/CSS/border-collapse) applied to them ([bug 1379306](https://bugzil.la/1379306)).", "Before Firefox 30, absolute positioning of table rows and row groups was not supported ([bug 63895](https://bugzil.la/63895))."] | 4 | 4 | 1 | ≤37 | 18 | 4 ["Before Firefox 57, absolute positioning did not work correctly when applied to elements inside tables that have [`border-collapse`](https://developer.mozilla.org/docs/Web/CSS/border-collapse) applied to them ([bug 1379306](https://bugzil.la/1379306)).", "Before Firefox 30, absolute positioning of table rows and row groups was not supported ([bug 63895](https://bugzil.la/63895))."] | 14 | 1 | 1.0 | | `absolutely_positioned_flex_children` | 52 | 12 | 52 | 10 | 39 | 11 | 52 | 52 | 52 | 41 | 11 | 6.0 | | `fixed` | 1 | 12 | 1 Before Firefox 44, `position: fixed` didn't create a stacking context in most cases. Firefox and the specification have been modified to mimic Chrome and Safari's long-time behavior. | 7 In Internet Explorer, fixed positioning doesn't work if the document is in [quirks mode](https://developer.mozilla.org/docs/Web/HTML/Quirks_Mode_and_Standards_Mode). | 4 | 1 | ≤37 | 18 | 4 Before Firefox 44, `position: fixed` didn't create a stacking context in most cases. Firefox and the specification have been modified to mimic Chrome and Safari's long-time behavior. | 14 | 1 | 1.0 | | `position_sticky_table_elements` | 56 | 16 | 59 Borders do not display on table headers if [`border-collapse`](https://developer.mozilla.org/docs/Web/CSS/border-collapse) is set to `collapse` ([bug 1727594](https://bugzil.la/1727594)). | No | 43 | 8 | 56 | 56 | 59 Borders do not display on table headers if [`border-collapse`](https://developer.mozilla.org/docs/Web/CSS/border-collapse) is set to `collapse` ([bug 1727594](https://bugzil.la/1727594)). | 43 | 8 | 6.0 | | `sticky` | 56 | 16 | 32 | No | 43 | 13 7 | 56 | 56 | 32 | 43 | 13 7 | 6.0 | See also -------- * [Learn CSS: Positioning](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Positioning)
programming_docs
css white-space white-space =========== The `white-space` CSS property sets how [white space](https://developer.mozilla.org/en-US/docs/Glossary/Whitespace) inside an element is handled. Try it ------ The property specifies two things: * Whether and how white space is [collapsed](#collapsing_of_white_space). * Whether lines may wrap at soft-wrap opportunities. **Note:** To make words break *within themselves*, use [`overflow-wrap`](overflow-wrap), [`word-break`](word-break), or [`hyphens`](hyphens) instead. Syntax ------ ``` /\* Keyword values \*/ white-space: normal; white-space: nowrap; white-space: pre; white-space: pre-wrap; white-space: pre-line; white-space: break-spaces; /\* Global values \*/ white-space: inherit; white-space: initial; white-space: revert; white-space: revert-layer; white-space: unset; ``` The `white-space` property is specified as a single keyword chosen from the list of values below. ### Values `normal` Sequences of white space are [collapsed](#collapsing_of_white_space). Newline characters in the source are handled the same as other white space. Lines are broken as necessary to fill line boxes. `nowrap` [Collapses](#collapsing_of_white_space) white space as for `normal`, but suppresses line breaks (text wrapping) within the source. `pre` Sequences of white space are preserved. Lines are only broken at newline characters in the source and at [`<br>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/br) elements. `pre-wrap` Sequences of white space are preserved. Lines are broken at newline characters, at [`<br>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/br), and as necessary to fill line boxes. `pre-line` Sequences of white space are [collapsed](#collapsing_of_white_space). Lines are broken at newline characters, at [`<br>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/br), and as necessary to fill line boxes. `break-spaces` The behavior is identical to that of `pre-wrap`, except that: * Any sequence of preserved white space always takes up space, including at the end of the line. * A line breaking opportunity exists after every preserved white space character, including between white space characters. * Such preserved spaces take up space and do not hang, and thus affect the box's intrinsic sizes (min-content size and max-content size). The following table summarizes the behavior of the various `white-space` values: | | New lines | Spaces and tabs | Text wrapping | End-of-line spaces | End-of-line other space separators | | --- | --- | --- | --- | --- | --- | | `normal` | Collapse | Collapse | Wrap | Remove | Hang | | `nowrap` | Collapse | Collapse | No wrap | Remove | Hang | | `pre` | Preserve | Preserve | No wrap | Preserve | No wrap | | `pre-wrap` | Preserve | Preserve | Wrap | Hang | Hang | | `pre-line` | Preserve | Collapse | Wrap | Remove | Hang | | `break-spaces` | Preserve | Preserve | Wrap | Wrap | Wrap | **Note:** There is a distinction made between **spaces** and **other space separators**. These are defined as follows: spaces Spaces (U+0020), tabs (U+0009), and segment breaks (such as newlines). other space separators All other space separators defined in Unicode, other than those already defined as spaces. Where white space is said to *hang*, this can affect the size of the box when measured for intrinsic sizing. Collapsing of white space ------------------------- The CSS Text specification contains a [Collapsing and Transformation](https://drafts.csswg.org/css-text-3/#white-space-phase-1) section that precisely defines what "white space is collapsed" means, including an example with an illustration. Usually, it means reducing sequences of multiple white-space characters down to a single space character — though in some cases it means reducing them to no character (the empty string). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` white-space = normal [|](value_definition_syntax#single_bar) pre [|](value_definition_syntax#single_bar) nowrap [|](value_definition_syntax#single_bar) pre-wrap [|](value_definition_syntax#single_bar) break-spaces [|](value_definition_syntax#single_bar) pre-line ``` Examples -------- ### Basic example ``` code { white-space: pre; } ``` ### Line breaks inside <pre> elements ``` pre { white-space: pre-wrap; } ``` ### In action #### HTML ``` <p> Lorem ipsum dolor sit amet, consectetur adipiscing 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. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </p> ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Text Module Level 3 # white-space-property](https://w3c.github.io/csswg-drafts/css-text/#white-space-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `white-space` | 1 | 12 | 1 | 5.5 | 4 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `break-spaces` | 76 | 79 | 69 | No | 62 | 13.1 | 76 | 76 | No | 54 | 13.4 | 12.0 | | `nowrap` | 1 | 12 | 1 | 5.5 | 4 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `pre` | 1 | 12 | 1 | 6 | 4 | 1 | 37 | 18 | 4 | 14 | 1 | 1.0 | | `pre-line` | 1 | 12 | 3.5 | 8 | 9.5 | 3 | 37 | 18 | 4 | 14 | 1 | 1.0 | | `pre-wrap` | 1 | 12 | 3 1-3.6 | 8 From Internet Explorer 5.5 to 7, `word-wrap: break-word;` can be used for line breaks in `pre` elements. | 8 | 3 | 37 | 18 | 4 | 14 | 1 | 1.0 | | `svg_support` | No | 12-79 | 36 | 10 | No | No | No | No | 36 | No | No | No | | `textarea_support` | 1 | 12 | 36 | 5.5 | 4 | 1 | 37 | 18 | 36 | 14 | 1 | 1.0 | See also -------- * Properties that define how words break *within themselves*: [`overflow-wrap`](overflow-wrap), [`word-break`](word-break), [`hyphens`](hyphens) css ::selection ::selection =========== The `::selection` CSS [pseudo-element](pseudo-elements) applies styles to the part of a document that has been highlighted by the user (such as clicking and dragging the mouse across text). Try it ------ Allowable properties -------------------- Only certain CSS properties can be used with `::selection`: * [`color`](color) * [`background-color`](background-color) * [`text-decoration`](text-decoration) and its associated properties * [`text-shadow`](text-shadow) * [`-webkit-text-stroke-color`](-webkit-text-stroke-color), [`-webkit-text-fill-color`](-webkit-text-fill-color) and [`-webkit-text-stroke-width`](-webkit-text-stroke-width) In particular, [`background-image`](background-image) is ignored. Syntax ------ ``` ::selection ``` Examples -------- ### HTML ``` This text has special styles when you highlight it. <p>Also try selecting text in this paragraph.</p> ``` ### CSS ``` /\* Make selected text gold on a red background \*/ ::selection { color: gold; background-color: red; } /\* Make selected text in a paragraph white on a blue background \*/ p::selection { color: white; background-color: blue; } ``` ### Result Accessibility concerns ---------------------- **Don't override selected text styles for purely aesthetic reasons** — users can customize them to suit their needs. For people experiencing cognitive concerns or who are less technologically literate, unexpected changes to selection styles may hurt their understanding of the functionality. If overridden, it is important to ensure that the **contrast ratio** between the text and background colors of the selection is high enough that people experiencing low vision conditions can read it. Color contrast ratio is found by comparing the luminosity of the selected text and the selected text background colors. To meet current [Web Content Accessibility Guidelines (WCAG)](https://www.w3.org/WAI/standards-guidelines/wcag/), text content must have a contrast ratio of **4.5:1**, or 3:1 for larger text such as headings. (WCAG defines large text as between `18.66px` and `24px` and [bold](font-weight), or `24px` or larger.) * [WebAIM: Color Contrast Checker](https://webaim.org/resources/contrastchecker/) * [MDN Understanding WCAG, Guideline 1.4 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background) * [Understanding Success Criterion 1.4.3 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html) Specifications -------------- | Specification | | --- | | [CSS Pseudo-Elements Module Level 4 # selectordef-selection](https://w3c.github.io/csswg-drafts/css-pseudo/#selectordef-selection) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `::selection` | 1 | 12 | 62 1 | 9 | 9.5 | 1.1 | 37 | 18 | 62 4 | 14 | No | 1.0 | See also -------- * [`pointer-events`](pointer-events) - control which events are active on the element css animation animation ========= The `animation` [shorthand](shorthand_properties) [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property applies an animation between styles. It is a shorthand for [`animation-name`](animation-name), [`animation-duration`](animation-duration), [`animation-timing-function`](animation-timing-function), [`animation-delay`](animation-delay), [`animation-iteration-count`](animation-iteration-count), [`animation-direction`](animation-direction), [`animation-fill-mode`](animation-fill-mode), and [`animation-play-state`](animation-play-state). A [description of which properties are animatable](css_animated_properties) is available; it's worth noting that this description is also valid for [CSS transitions](css_transitions/using_css_transitions). Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`animation-delay`](animation-delay) * [`animation-direction`](animation-direction) * [`animation-duration`](animation-duration) * [`animation-fill-mode`](animation-fill-mode) * [`animation-iteration-count`](animation-iteration-count) * [`animation-name`](animation-name) * [`animation-play-state`](animation-play-state) * [`animation-timing-function`](animation-timing-function) Syntax ------ ``` /\* @keyframes duration | easing-function | delay | iteration-count | direction | fill-mode | play-state | name \*/ animation: 3s ease-in 1s 2 reverse both paused slidein; /\* @keyframes duration | easing-function | delay | name \*/ animation: 3s linear 1s slidein; /\* two animations \*/ animation: 3s linear slidein, 3s ease-out 5s slideout; ``` The `animation` property is specified as one or more single animations, separated by commas. Each individual animation is specified as: * zero, one, or two occurrences of the [`<time>`](time) value * zero or one occurrences of the following values: + [`<single-easing-function>`](animation#single-easing-function) + [`<single-animation-iteration-count>`](animation#single-animation-iteration-count) + [`<single-animation-direction>`](animation#single-animation-direction) + [`<single-animation-fill-mode>`](animation#single-animation-fill-mode) + [`<single-animation-play-state>`](animation#single-animation-play-state) * an optional name for the animation, which may be `none`, a [`<custom-ident>`](custom-ident), or a [`<string>`](string) ### Values `<single-easing-function>` Determines the type of transition. The value must be one of those available in [`<easing-function>`](easing-function). `<single-animation-iteration-count>` The number of times the animation is played. The value must be one of those available in [`animation-iteration-count`](animation-iteration-count). `<single-animation-direction>` The direction in which the animation is played. The value must be one of those available in [`animation-direction`](animation-direction). `<single-animation-fill-mode>` Determines how styles should be applied to the animation's target before and after its execution. The value must be one of those available in [`animation-fill-mode`](animation-fill-mode). `<single-animation-play-state>` Determines whether the animation is playing or not. The value must be one of those available in [`animation-play-state`](animation-play-state). Description ----------- The order of time values within each animation definition is important: the first value that can be parsed as a [`<time>`](time) is assigned to the [`animation-duration`](animation-duration), and the second one is assigned to [`animation-delay`](animation-delay). The order of other values within each animation definition is also important for distinguishing an [`animation-name`](animation-name) value from other values. If a value in the `animation` shorthand can be parsed as a value for an animation property other than `animation-name`, then the value will be applied to that property first and not to `animation-name`. For this reason, the recommended practice is to specify a value for `animation-name` as the last value in a list of values when using the `animation` shorthand; this holds true even when you specify multiple, comma-separated animations using the `animation` shorthand. An `animation-name` value is not required to be declared in the `animation` shorthand property. If no name exists, there is no animation to apply on any of the properties. When the `animation-duration` value is omitted from the `animation` shorthand property, the value for this property defaults to `0s`. In this case, the animation will still occur (the [`animationStart`](https://developer.mozilla.org/en-US/docs/Web/API/Element/animationstart_event) and [`animationEnd`](https://developer.mozilla.org/en-US/docs/Web/API/Element/animationend_event) events will be fired) but no animation will be visible. Accessibility concerns ---------------------- Blinking and flashing animation can be problematic for people with cognitive concerns such as Attention Deficit Hyperactivity Disorder (ADHD). Additionally, certain kinds of motion can be a trigger for Vestibular disorders, epilepsy, and migraine and Scotopic sensitivity. Consider providing a mechanism for pausing or disabling animation as well as using the [Reduced Motion Media Query](@media/prefers-reduced-motion) to create a complimentary experience for users who have expressed a preference for reduced animated experiences. * [Designing Safer Web Animation For Motion Sensitivity · An A List Apart Article](https://alistapart.com/article/designing-safer-web-animation-for-motion-sensitivity/) * [An Introduction to the Reduced Motion Media Query | CSS-Tricks](https://css-tricks.com/introduction-reduced-motion-media-query/) * [Responsive Design for Motion | WebKit](https://webkit.org/blog/7551/responsive-design-for-motion/) * [MDN Understanding WCAG, Guideline 2.2 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Operable#guideline_2.2_%e2%80%94_enough_time_provide_users_enough_time_to_read_and_use_content) * [Understanding Success Criterion 2.2.2 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/time-limits-pause.html) Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`animation-name`](animation-name): `none` * [`animation-duration`](animation-duration): `0s` * [`animation-timing-function`](animation-timing-function): `ease` * [`animation-delay`](animation-delay): `0s` * [`animation-iteration-count`](animation-iteration-count): `1` * [`animation-direction`](animation-direction): `normal` * [`animation-fill-mode`](animation-fill-mode): `none` * [`animation-play-state`](animation-play-state): `running` * [`animation-timeline`](animation-timeline): `auto` | | Applies to | all elements, [`::before`](::before) and [`::after`](::after) <pseudo-elements> | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`animation-name`](animation-name): as specified * [`animation-duration`](animation-duration): as specified * [`animation-timing-function`](animation-timing-function): as specified * [`animation-delay`](animation-delay): as specified * [`animation-direction`](animation-direction): as specified * [`animation-iteration-count`](animation-iteration-count): as specified * [`animation-fill-mode`](animation-fill-mode): as specified * [`animation-play-state`](animation-play-state): as specified * [`animation-timeline`](animation-timeline): listEachItemIdentifyerOrNoneAuto | | Animation type | Not animatable | Formal syntax ------------- ``` animation = <single-animation>[#](value_definition_syntax#hash_mark) <single-animation> = [<time>](time) [||](value_definition_syntax#double_bar) <easing-function> [||](value_definition_syntax#double_bar) [<time>](time) [||](value_definition_syntax#double_bar) <single-animation-iteration-count> [||](value_definition_syntax#double_bar) <single-animation-direction> [||](value_definition_syntax#double_bar) <single-animation-fill-mode> [||](value_definition_syntax#double_bar) <single-animation-play-state> [||](value_definition_syntax#double_bar) [[](value_definition_syntax#brackets) none [|](value_definition_syntax#single_bar) <keyframes-name> []](value_definition_syntax#brackets) <easing-function> = linear [|](value_definition_syntax#single_bar) <linear-easing-function> [|](value_definition_syntax#single_bar) <cubic-bezier-easing-function> [|](value_definition_syntax#single_bar) <step-easing-function> <single-animation-iteration-count> = infinite [|](value_definition_syntax#single_bar) [<number [0,∞]>](number) <single-animation-direction> = normal [|](value_definition_syntax#single_bar) reverse [|](value_definition_syntax#single_bar) alternate [|](value_definition_syntax#single_bar) alternate-reverse <single-animation-fill-mode> = none [|](value_definition_syntax#single_bar) forwards [|](value_definition_syntax#single_bar) backwards [|](value_definition_syntax#single_bar) both <single-animation-play-state> = running [|](value_definition_syntax#single_bar) paused <keyframes-name> = [<custom-ident>](custom-ident) [|](value_definition_syntax#single_bar) [<string>](string) <linear-easing-function> = linear( <linear-stop-list> ) <cubic-bezier-easing-function> = ease [|](value_definition_syntax#single_bar) ease-in [|](value_definition_syntax#single_bar) ease-out [|](value_definition_syntax#single_bar) ease-in-out [|](value_definition_syntax#single_bar) cubic-bezier( [<number [0,1]>](number) , [<number>](number) , [<number [0,1]>](number) , [<number>](number) ) <step-easing-function> = step-start [|](value_definition_syntax#single_bar) step-end [|](value_definition_syntax#single_bar) steps( [<integer>](integer) [[](value_definition_syntax#brackets), <step-position> []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <linear-stop-list> = [[](value_definition_syntax#brackets) <linear-stop> []](value_definition_syntax#brackets)[#](value_definition_syntax#hash_mark) <step-position> = jump-start [|](value_definition_syntax#single_bar) jump-end [|](value_definition_syntax#single_bar) jump-none [|](value_definition_syntax#single_bar) jump-both [|](value_definition_syntax#single_bar) start [|](value_definition_syntax#single_bar) end <linear-stop> = [<number>](number) [&&](value_definition_syntax#double_ampersand) <linear-stop-length>[?](value_definition_syntax#question_mark) <linear-stop-length> = [<percentage>](percentage)[{1,2}](value_definition_syntax#curly_braces) ``` Examples -------- **Note:** Animating [CSS Box Model](css_box_model) properties is discouraged. Animating any box model property is inherently CPU intensive; consider animating the <transform> property instead. ### Sun Rise Here we animate a yellow sun across a light blue sky. The sun rises to the center of the viewport and then falls out of sight. ``` <div class="sun"></div> ``` ``` :root { overflow: hidden; /\* hides any part of the sun below the horizon \*/ background-color: lightblue; display: flex; justify-content: center; /\* centers the sun in the background \*/ } .sun { background-color: yellow; border-radius: 50%; /\* creates a circular background \*/ height: 100vh; /\* makes the sun the size of the viewport \*/ aspect-ratio: 1 / 1; animation: 4s linear 0s infinite alternate sun-rise; } @keyframes sun-rise { from { /\* pushes the sun down past the viewport \*/ transform: translateY(110vh); } to { /\* returns the sun to its default position \*/ transform: translateY(0); } } ``` ### Animating Multiple Properties Adding onto the sun animation in the previous example, we add a second animation changing the color of the sun as it rises and sets. The sun starts off dark red when it is below the horizon and changes to a bright orange as it reaches the top. ``` <div class="sun"></div> ``` ``` :root { overflow: hidden; background-color: lightblue; display: flex; justify-content: center; } .sun { background-color: yellow; border-radius: 50%; height: 100vh; aspect-ratio: 1 / 1; animation: 4s linear 0s infinite alternate animating-multiple-properties; } /\* it is possible to animate multiple properties in a single animation \*/ @keyframes animating-multiple-properties { from { transform: translateY(110vh); background-color: red; filter: brightness(75%); } to { transform: translateY(0); background-color: orange; /\* unset properties i.e. 'filter' will revert to default values \*/ } } ``` ### Applying Multiple Animations Here is a sun that rises and falls on a lightblue background. The sun gradually rotates through a rainbow of colors. The timing of the sun's position and color are independent. ``` <div class="sun"></div> ``` ``` :root { overflow: hidden; background-color: lightblue; display: flex; justify-content: center; } .sun { background-color: yellow; border-radius: 50%; height: 100vh; aspect-ratio: 1 / 1; /\* multiple animations are separated by commas \*/ animation: 4s linear 0s infinite alternate rise, /\* animation parameters are set independently \*/ 24s linear 0s infinite psychedelic; } @keyframes rise { from { transform: translateY(110vh); } to { transform: translateY(0); } } @keyframes psychedelic { from { filter: hue-rotate(0deg); } to { filter: hue-rotate(360deg); } } ``` ### Cascading Multiple Animations Here is a yellow sun on a lightblue background. The sun bounces between the left and right sides of the viewport. The sun remains in the viewport even though a rise animation is defined. The rise animation's transform property is 'overwritten' by the bounce animation. ``` <div class="sun"></div> ``` ``` :root { overflow: hidden; background-color: lightblue; display: flex; justify-content: center; } .sun { background-color: yellow; border-radius: 50%; height: 100vh; aspect-ratio: 1 / 1; /\* animations declared later in the cascade will override the properties of previously declared animations \*/ animation: 4s linear 0s infinite alternate rise, /\* bounce 'overwrites' the transform set by rise \*/ 4s linear 0s infinite alternate bounce; /\* hence the sun only moves horizontally \*/ } @keyframes rise { from { transform: translateY(110vh); } to { transform: translateY(0); } } @keyframes bounce { from { transform: translateX(-50vw); } to { transform: translateX(50vw); } } ``` See [Using CSS animations](css_animations/using_css_animations#examples) for additional examples. Specifications -------------- | Specification | | --- | | [CSS Animations Level 1 # animation](https://w3c.github.io/csswg-drafts/css-animations/#animation) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `animation` | 43 3 | 12 12 | 49 16 5 | 10 | 30 15 12.1-15 12-15 | 9 4 | 43 2 The [`animation-fill-mode`](https://developer.mozilla.org/docs/Web/CSS/animation-fill-mode) property is not supported in Android browsers below 2.3. | 43 18 | 49 16 5 | 30 14 12.1-14 12-14 | 9 3.2 | 4.0 1.0 | See also -------- * [Using CSS animations](css_animations/using_css_animations) * JavaScript [`AnimationEvent`](https://developer.mozilla.org/en-US/docs/Web/API/AnimationEvent) API
programming_docs
css :target :target ======= The `:target` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) represents a unique element (the *target element*) with an [`id`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#id) matching the URL's fragment. ``` /\* Selects an element with an ID matching the current URL's fragment \*/ :target { border: 2px solid black; } ``` For example, the following URL has a fragment (denoted by the *#* sign) that points to an element called `section2`: ``` http://www.example.com/index.html#section2 ``` The following element would be selected by a `:target` selector when the current URL is equal to the above: ``` <section id="section2">Example</section> ``` Syntax ------ ``` :target ``` Examples -------- ### A table of contents The `:target` pseudo-class can be used to highlight the portion of a page that has been linked to from a table of contents. #### HTML ``` <h3>Table of Contents</h3> <ol> <li><a href="#p1">Jump to the first paragraph!</a></li> <li><a href="#p2">Jump to the second paragraph!</a></li> <li> <a href="#nowhere"> This link goes nowhere, because the target doesn't exist. </a> </li> </ol> <h3>My Fun Article</h3> <p id="p1"> You can target <i>this paragraph</i> using a URL fragment. Click on the link above to try out! </p> <p id="p2"> This is <i>another paragraph</i>, also accessible from the links above. Isn't that delightful? </p> ``` #### CSS ``` p:target { background-color: gold; } /\* Add a pseudo-element inside the target element \*/ p:target::before { font: 70% sans-serif; content: "►"; color: limegreen; margin-right: 0.25em; } /\* Style italic elements within the target element \*/ p:target i { color: red; } ``` #### Result ### Pure-CSS lightbox You can use the `:target` pseudo-class to create a lightbox without using any JavaScript. This technique relies on the ability of anchor links to point to elements that are initially hidden on the page. Once targeted, the CSS changes their `display` so that they are shown. **Note:** A more complete pure-CSS lightbox based on the `:target` pseudo-class is [available on GitHub](https://github.com/madmurphy/takefive.css/) ([demo](https://madmurphy.github.io/takefive.css/)). #### HTML ``` <ul> <li><a href="#example1">Open example #1</a></li> <li><a href="#example2">Open example #2</a></li> </ul> <div class="lightbox" id="example1"> <figure> <a href="#" class="close"></a> <figcaption> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec felis enim, placerat id eleifend eu, semper vel sem. </figcaption> </figure> </div> <div class="lightbox" id="example2"> <figure> <a href="#" class="close"></a> <figcaption> Cras risus odio, pharetra nec ultricies et, mollis ac augue. Nunc et diam quis sapien dignissim auctor. Quisque quis neque arcu, nec gravida magna. </figcaption> </figure> </div> ``` #### CSS ``` /\* Unopened lightbox \*/ .lightbox { display: none; } /\* Opened lightbox \*/ .lightbox:target { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; } /\* Lightbox content \*/ .lightbox figcaption { width: 25rem; position: relative; padding: 1.5em; background-color: lightpink; } /\* Close button \*/ .lightbox .close { position: relative; display: block; } .lightbox .close::after { right: -1rem; top: -1rem; width: 2rem; height: 2rem; position: absolute; display: flex; z-index: 1; align-items: center; justify-content: center; background-color: black; border-radius: 50%; color: white; content: "×"; cursor: pointer; } /\* Lightbox overlay \*/ .lightbox .close::before { left: 0; top: 0; width: 100%; height: 100%; position: fixed; background-color: rgba(0, 0, 0, 0.7); content: ""; cursor: default; } ``` #### Result Specifications -------------- | Specification | | --- | | [HTML Standard # selector-target](https://html.spec.whatwg.org/multipage/semantics-other.html#selector-target) | | [Selectors Level 4 # the-target-pseudo](https://w3c.github.io/csswg-drafts/selectors/#the-target-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:target` | 1 | 12 | 1 | 9 | 9.5 | 1.3 | 2 | 18 | 4 | 10.1 | 2 | 1.0 | See also -------- * [Using the :target pseudo-class in selectors](css_selectors/using_the_:target_pseudo-class_in_selectors) css CSS Functional Notation CSS Functional Notation ======================= **CSS functional notation** is a type of [CSS value](css_values_and_units) that can represent more complex data types or invoke special data processing or calculations. Syntax ------ ``` selector { property: functional-notation([argument]? [, argument]!); } ``` The syntax starts with the **name of the functional notation**, followed by a left parenthesis `(`. Next up are the notation argument(s), and the function is finished off with a closing parenthesis `)`. Functions can take multiple arguments, which are formatted similarly to CSS property values. Whitespace is allowed, but they are optional inside the parentheses. In some functional notations multiple arguments are separated by commas, while others use spaces. Transform functions ------------------- The [`<transform-function>`](transform-function) CSS [data type](css_types) represent appearance transformation. It is used as a value of [`transform`](transform) property. ### Translate functions [`translatex()`](transform-function/translatex) Translates an element horizontally. [`translatey()`](transform-function/translatey) Translates an element vertically. [`translatez()`](transform-function/translatez) Translates an element along the z-axis. [`translate()`](transform-function/translate) Translates an element on the 2D plane. [`translate3d()`](transform-function/translate3d) Translates an element in 3D space. ### Rotation functions [`rotatex()`](transform-function/rotatex) Rotates an element around the horizontal axis. [`rotatey()`](transform-function/rotatey) Rotates an element around the vertical axis. [`rotatez()`](transform-function/rotatez) Rotates an element around the z-axis. [`rotate()`](transform-function/rotate) Rotates an element around a fixed point on the 2D plane. [`rotate3d()`](transform-function/rotate3d) Rotates an element around a fixed axis in 3D space. ### Scaling functions [`scalex()`](transform-function/scalex) Scales an element up or down horizontally. [`scaley()`](transform-function/scaley) Scales an element up or down vertically. [`scalez()`](transform-function/scalez) Scales an element up or down along the z-axis. [`scale()`](transform-function/scale) Scales an element up or down on the 2D plane. [`scale3d()`](transform-function/scale3d) Scales an element up or down in 3D space. ### Skew functions [`skewx()`](transform-function/skewx) Skews an element in the horizontal direction. [`skewy()`](transform-function/skewy) Skews an element in the vertical direction. [`skew()`](transform-function/skew) Skews an element on the 2D plane. ### Matrix functions [`matrix()`](transform-function/matrix) Describes a homogeneous 2D transformation matrix. [`matrix3d()`](transform-function/matrix3d) Describes a 3D transformation as a 4×4 homogeneous matrix. ### Perspective functions [`perspective()`](transform-function/perspective) Sets the distance between the user and the z=0 plane. Math functions -------------- The math functions allow CSS numeric values to be written as mathematical expressions. ### Basic arithmetic [`calc()`](calc) Performs basic arithmetic calculations on numerical values. ### Comparison functions [`min()`](min) Calculates the smallest of a list of values. [`max()`](max) Calculates the largest of a list of values. [`clamp()`](clamp) Calculates the central of a minimum, central, and maximum values. ### Stepped value functions [`round()`](round) Experimental Calculates a rounded number based on a rounding strategy. `mod()` Experimental Calculates a modulus (with the same sign as the divisor) when dividing one number by another. [`rem()`](rem) Experimental Calculates a remainder (with the same sign as the dividend) when dividing one number by another. ### Trigonometric functions [`sin()`](sin) Calculates the trigonometric sine of a number. [`cos()`](cos) Calculates the trigonometric cosine of a number. [`tan()`](tan) Calculates the trigonometric tangent of a number. [`asin()`](asin) Calculates the trigonometric inverse sine of a number. [`acos()`](acos) Calculates the trigonometric inverse cosine of a number. [`atan()`](atan) Calculates the trigonometric inverse tangent of a number. [`atan2()`](atan2) Calculates the trigonometric inverse tangent of two-numbers in a plane. ### Exponential functions [`pow()`](pow) Experimental Calculates the base raised to the power of a number. [`sqrt()`](sqrt) Experimental Calculates the square root of a number. [`hypot()`](hypot) Experimental Calculates the square root of the sum of the squares of its arguments. [`log()`](log) Experimental Calculates the logarithm of a number. [`exp()`](exp) Experimental Calculates `e` raised to the power of a number. ### Sign-related functions [`abs()`](abs) Experimental Calculates the absolute value of a number. [`sign()`](sign) Experimental Calculates the sign (positive or negative) of the number. Filter functions ---------------- The [`<filter-function>`](filter-function) CSS [data type](css_types) represents a graphical effect that can change the appearance of an input image. It is used in the [`filter`](filter) and [`backdrop-filter`](backdrop-filter) properties. [`blur()`](filter-function/blur) Increases the image gaussian blur. [`brightness()`](filter-function/brightness) Brightens or darkens an image. [`contrast()`](filter-function/contrast) Increases or decreases the image contrast. [`drop-shadow()`](filter-function/drop-shadow) Applies a drop shadow behind an image. [`grayscale()`](filter-function/grayscale) Converts an image to grayscale. [`hue-rotate()`](filter-function/hue-rotate) Changes the overall hue of an image. [`invert()`](filter-function/invert) Inverts the colors of an image. [`opacity()`](filter-function/opacity) Adds transparency to an image. [`saturate()`](filter-function/saturate) Changes the overall saturation of an image. [`sepia()`](filter-function/sepia) Increases the sepia of an image. Color functions --------------- The [`<color>`](color_value) CSS [data type](css_types) specifies different color representations. [`rgb()`](color_value/rgb) Defines a given color according to its red, green, blue and alpha (transparency) components. [`hsl()`](color_value/hsl) Defines a given color according to its hue, saturation, lightness and alpha (transparency) components. [`hwb()`](color_value/hwb) Defines a given color according to its hue, whiteness and blackness components. [`lch()`](color_value/lch) Experimental Defines a given color according to its lightness, chroma and hue components. [`oklch()`](color_value/oklch) Experimental Defines a given color according to its lightness, chroma, hue and alpha (transparency) components. [`lab()`](color_value/lab) Experimental Defines a given color according to its lightness, a-axis distance and b-axis distance in the lab colorspace. [`oklab()`](color_value/oklab) Experimental Defines a given color according to its lightness, a-axis distance, b-axis distance in the lab colorspace and alpha (transparency). [`color()`](color_value/color) Experimental Specifies a particular, specified colorspace rather than the implicit sRGB colorspace. [`color-mix()`](color_value/color-mix) Experimental Mixes two color values in a given colorspace by a given amount. [`color-contrast()`](color_value/color-contrast) Experimental Selects the highest color contrast from a list of colors, compare to a base color value. [`device-cmyk()`](color_value/device-cmyk) Experimental Defines CMYK colors in a device-independent way. Image functions --------------- The [`<image>`](image) CSS [data type](css_types) provides graphical representation of images or gradients. ### Gradient functions [`linear-gradient()`](gradient/linear-gradient) Linear gradients transition colors progressively along an imaginary line. [`radial-gradient()`](gradient/radial-gradient) Radial gradients transition colors progressively from a center point (origin). [`conic-gradient()`](gradient/conic-gradient) Conic gradients transition colors progressively around a circle. [`repeating-linear-gradient()`](gradient/repeating-linear-gradient) Is similar to `linear-gradient()` and takes the same arguments, but it repeats the color stops infinitely in all directions so as to cover its entire container. [`repeating-radial-gradient()`](gradient/repeating-radial-gradient) Is similar to `radial-gradient()` and takes the same arguments, but it repeats the color stops infinitely in all directions so as to cover its entire container. [`repeating-conic-gradient()`](gradient/repeating-conic-gradient) Is similar to `conic-gradient()` and takes the same arguments, but it repeats the color stops infinitely in all directions so as to cover its entire container. ### Image functions [`image()`](image/image) Experimental Defines an [`<image>`](image) in a similar fashion to the [`url()`](url) function, but with added functionality including specifying the image's directionality and fallback images for when the preferred image is not supported. [`image-set()`](image/image-set) Picks the most appropriate CSS image from a given set, primarily for high pixel density screens. [`cross-fade()`](cross-fade) Blends two or more images at a defined transparency. [`element()`](element()) Experimental Defines an [`<image>`](image) value generated from an arbitrary HTML element. [`paint()`](image/paint) Defines an [`<image>`](image) value generated with a PaintWorklet. Counter functions ----------------- CSS counter functions are generally used with the [`content`](content) property, although in theory, they may be used wherever a [`<string>`](string) is supported. [`counter()`](counter) Returns a string representing the current value of the named counter if there is one. [`counters()`](counters) Enables nested counters, returning a concatenated string representing the current values of the named counters, if there are any. [`symbols()`](@counter-style/symbols) Defines the counter styles inline, directly as the value of a property. Shape functions --------------- The [`<basic-shape>`](basic-shape) CSS [data type](css_types) represents a graphical shape. It is used in the [`clip-path`](clip-path), [`offset-path`](offset-path), and [`shape-outside`](shape-outside) properties. [`circle()`](basic-shape/circle) Defines a circle shape. [`ellipse()`](basic-shape/ellipse) Defines an ellipse shape. [`inset()`](basic-shape/inset) Defines an inset rectangle shape. [`polygon()`](basic-shape/polygon) Defines a polygon shape. [`path()`](path) Accepts an SVG path string to enable a shape to be drawn. Reference functions ------------------- The following functions are used as a value of properties to reference a value defined elsewhere. [`attr()`](attr) Uses the attributes defined on HTML element. [`env()`](env) Uses the user-agent defined as environment variable. [`url()`](url) Uses a file from the specified URL. [`var()`](var()) Uses the custom property value instead of any part of a value of another property. Grid functions -------------- The following functions are used to define a [CSS Grid](css_grid_layout). [`fit-content()`](fit-content) Clamps a given size to an available size according to the formula `min(maximum size, max(minimum size, argument))`. [`minmax()`](minmax) Defines a size range greater-than or equal-to *min* and less-than or equal-to *max*. [`repeat()`](repeat) Represents a repeated fragment of the track list, allowing a large number of columns or rows that exhibit a recurring pattern. Font functions -------------- CSS font functions are used with the [`font-variant-alternates`](font-variant-alternates) property to control the use of alternate glyphs. `stylistic()` Enables stylistic alternates for individual characters. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `salt`, like `salt 2`. `styleset()` Enables stylistic alternatives for sets of characters. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `ssXY`, such as `ss02`. `character-variant()` Enables specific stylistic alternatives for characters. It is similar to `styleset()`, but doesn't create coherent glyphs for a set of characters; individual characters will have independent and not necessarily coherent styles. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `cvXY`, such as `cv02`. `swash()` Enables [swash](https://en.wikipedia.org/wiki/Swash_%28typography%29) glyphs. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType values `swsh` and `cswh`, such as `swsh 2` and `cswh 2`. `ornaments()` Enables ornaments such as [fleurons](https://en.wikipedia.org/wiki/Fleuron_%28typography%29) and other dingbat glyphs. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `ornm`, such as `ornm 2`. `annotation()` Enables annotations such as circled digits or inverted characters. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `nalt`, such as `nalt 2`. Animation functions ------------------- This function can be used to provide the timeline for an animation. [`scroll()`](animation-timeline/scroll) Experimental Sets the [`animation-timeline`](animation-timeline) of an element to depend on scrollbar on a particular axis of either the nearest parent (with that scrollbar), or the root container. Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4](https://drafts.csswg.org/css-values/) | | [CSS Color Module Level 4](https://drafts.csswg.org/css-color/) | | [CSS Images Module Level 3](https://drafts.csswg.org/css-images/) | See also -------- * [CSS Values and Units](css_values_and_units) * [Introduction to CSS: Values and Units](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units) css container-name container-name ============== The **container-name** [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property specifies a list of query container names used by the <@container> at-rule in a [container query](css_container_queries). A container query will apply styles to elements based on the size of the nearest ancestor with a containment context. When a containment context is given a name, it can be specifically targeted using the [`@container`](@container) at-rule instead of the nearest ancestor with containment. Syntax ------ ``` container-name: <container-name>; ``` ### Values * `<container-name>` is a case-sensitive string that is used to identify the container. The following conditions apply: + The name can be any valid [`<custom-ident>`](custom-ident), but must not equal `default`. + The name value must not be in quotes. + The dashed ident intended to denote author-defined identifiers (e.g., `--container-name`) is permitted. + A list of multiple names separated by a space is allowed. Examples -------- ### Using a container name Given the following HTML example which is a card component with an image, a title, author details, and some text: ``` <div class="card"> <div class="post-meta"> <h2>Card title</h2> <img src="image.png" alt="Cat with two different color eyes" /> <p>Author <a href="https://example.com">website</a> details.</p> </div> <div class="post-excerpt"> <p> A preview of my <a href="https://example.com">blog post</a> about cats. </p> </div> </div> ``` To create a containment context, add the `container-type` property to an element in CSS. The following example creates two containment contexts, one for the card meta information and one for the post excerpt: **Note:** A shorthand syntax for these declarations are described in the [`container`](container) page. ``` .post-meta { container-type: inline-size; } .post-excerpt { container-type: inline-size; container-name: excerpt; } ``` Writing a container query via the [`@container`](@container) at-rule will apply styles to the elements of the container when the query evaluates to true. The following example has two container queries, one that will apply only to the contents of the `.post-excerpt` element and one that will apply to both the `.post-meta` and `.post-excerpt` contents: ``` @container excerpt (min-width: 400px) { a { font-family: monospace; } } @container (min-width: 400px) { p { font-size: 2rem; } } ``` For more information on writing container queries, see the [CSS Container Queries](css_container_queries) page. ### Using multiple container names You can also provide multiple names to a container context separated by a space: ``` .post-meta { container-type: inline-size; container-name: meta card; } ``` This will allow you to target the container using either name in the [`@container`](@container) at-rule. This is useful if you want to target the same container with multiple container queries where either condition could be true: ``` @container meta (max-width: 500px) { li { visibility: hidden; } } @container nav (orientation: landscape) { h2 { font-size: 1.5em; } } ``` Specifications -------------- | Specification | | --- | | [CSS Containment Module Level 3 # container-name](https://w3c.github.io/csswg-drafts/css-contain-3/#container-name) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `container-name` | 105 | 105 | preview | No | 91 | 16 | 105 | 105 | No | 72 | 16 | No | See also -------- * [CSS container queries](css_container_queries) * [`@container`](@container) at-rule * CSS [`container`](container) shorthand property * CSS [`container-type`](container-type) property * CSS [`content-visibility`](content-visibility) property
programming_docs
css will-change will-change =========== The `will-change` [CSS](https://developer.mozilla.org/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. ``` /\* 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; ``` 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](css_positioning/understanding_z_index/the_stacking_context) (e.g. will-change: opacity), as the stacking context is created up front. Syntax ------ ### 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. [`<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 [stacking context](https://developer.mozilla.org/en-US/docs/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. ``` .slide { will-change: transform; } ``` Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` will-change = auto [|](value_definition_syntax#single_bar) <animateable-feature>[#](value_definition_syntax#hash_mark) <animateable-feature> = scroll-position [|](value_definition_syntax#single_bar) contents [|](value_definition_syntax#single_bar) [<custom-ident>](custom-ident) ``` 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. ``` 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 -------------- | Specification | | --- | | [CSS Will Change Module Level 1 # will-change](https://w3c.github.io/csswg-drafts/css-will-change/#will-change) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `will-change` | 36 | 79 | 36 | No | 24 | 9.1 | 37 | 36 | 36 | 24 | 9.3 | 3.0 | See also -------- * [`transform`](transform) * Individual transform properties: + [`translate`](translate) + [`scale`](scale) + [`rotate`](rotate) + Note: there is no individual `skew` property css Inheritance Inheritance =========== In CSS, **inheritance** controls what happens when no value is specified for a property on an element. CSS properties can be categorized in two types: * **inherited properties**, which by default are set to the [computed value](computed_value) of the parent element * **non-inherited properties**, which by default are set to [initial value](initial_value) of the property Refer to [any CSS property](reference#keyword_index) definition to see whether a specific property inherits by default ("Inherited: yes") or not ("Inherited: no"). Inherited properties -------------------- When no value for an **inherited property** has been specified on an element, the element gets the [computed value](computed_value) of that property on its parent element. Only the root element of the document gets the [initial value](initial_value) given in the property's summary. A typical example of an inherited property is the [`color`](color) property. Consider the following style rules and the markup: ``` p { color: green; } ``` ``` <p>This paragraph has <em>emphasized text</em> in it.</p> ``` The words "emphasized text" will appear green, since the `em` element has inherited the value of the [`color`](color) property from the `p` element. It does *not* get the initial value of the property (which is the color that is used for the root element when the page specifies no color). Non-inherited properties ------------------------ When no value for a **non-inherited property** has been specified on an element, the element gets the [initial value](initial_value) of that property (as specified in the property's summary). A typical example of a non-inherited property is the [`border`](border) property. Consider the following style rules and the markup: ``` p { border: medium solid; } ``` ``` <p>This paragraph has <em>emphasized text</em> in it.</p> ``` The words "emphasized text" will not have another border (since the initial value of [`border-style`](border-style) is `none`). Notes ----- The [`inherit`](inherit) keyword allows authors to explicitly specify inheritance. It works on both inherited and non-inherited properties. You can control inheritance for all properties at once using the [`all`](all) shorthand property, which applies its value to all properties. For example: ``` p { all: revert; font-size: 200%; font-weight: bold; } ``` This reverts the style of the paragraphs' [`font`](font) property to the user agent's default unless a user stylesheet exists, in which case that is used instead. Then it doubles the font size and applies a [`font-weight`](font-weight) of `"bold"`. ### Overriding inheritance, an example Using our previous example with [`border`](border), if we explicitly set the inheritance with `inherit`, we get the following: ``` p { border: medium solid; } em { border: inherit; } ``` ``` <p>This paragraph has <em>emphasized text</em> in it.</p> ``` We can see here another border around the word "emphasized text". See also -------- * CSS values for controlling inheritance: [`inherit`](inherit), [`initial`](initial), [`revert`](revert), [`revert-layer`](revert-layer), and [`unset`](unset) * [Introducing the CSS cascade](cascade) * [Cascade, specificity, and inheritance](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Cascade_and_inheritance) * CSS key concepts: + [CSS syntax](syntax) + [At-rules](at-rule) + [Comments](comments) + [Specificity](specificity) + [Box model](css_box_model/introduction_to_the_css_box_model) + [Layout modes](layout_mode) + [Visual formatting models](visual_formatting_model) + [Margin collapsing](css_box_model/mastering_margin_collapsing) + Values - [Initial values](initial_value) - [Computed values](computed_value) - [Used values](used_value) - [Actual values](actual_value) + [Value definition syntax](value_definition_syntax) + [Shorthand properties](shorthand_properties) + [Replaced elements](replaced_element) css overflow-y overflow-y ========== The `overflow-y` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets what shows when content overflows a block-level element's top and bottom edges. This may be nothing, a scroll bar, or the overflow content. Try it ------ Syntax ------ ``` /\* Keyword values \*/ overflow-y: visible; overflow-y: hidden; overflow-y: clip; overflow-y: scroll; overflow-y: auto; /\* Global values \*/ overflow-y: inherit; overflow-y: initial; overflow-y: revert; overflow-y: revert-layer; overflow-y: unset; ``` The `overflow-y` property is specified as a single keyword chosen from the list of values below. If [`overflow-x`](overflow-x) is `hidden`, `scroll` or `auto` and this property is `visible` (default) it will implicitly compute to `auto`. ### Values `visible` Content is not clipped and may be rendered outside the padding box's top and bottom edges. `hidden` Content is clipped if necessary to fit vertically in the padding box. No scrollbars are provided. `clip` Like for `hidden`, the content is clipped to the element's padding box. The difference between `clip` and `hidden` is that the `clip` keyword also forbids all scrolling, including programmatic scrolling. The box is not a scroll container, and does not start a new formatting context. If you wish to start a new formatting context, you can use [`display: flow-root`](display#flow-root) to do so. `scroll` Content is clipped if necessary to fit vertically in the padding box. Browsers display scrollbars whether or not any content is actually clipped. (This prevents scrollbars from appearing or disappearing when the content changes.) Printers may still print overflowing content. `auto` Depends on the user agent. If content fits inside the padding box, it looks the same as `visible`, but still establishes a new block-formatting context. Desktop browsers provide scrollbars if content overflows. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `visible` | | Applies to | Block-containers, flex containers, and grid containers | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified, except with `visible`/`clip` computing to `auto`/`hidden` respectively if one of [`overflow-x`](overflow-x) or [`overflow-y`](overflow-y) is neither `visible` nor clip | | Animation type | discrete | Formal syntax ------------- ``` overflow-y = visible [|](value_definition_syntax#single_bar) hidden [|](value_definition_syntax#single_bar) clip [|](value_definition_syntax#single_bar) scroll [|](value_definition_syntax#single_bar) auto ``` Examples -------- ### Setting overflow-y behavior #### HTML ``` <ul> <li> <code>overflow-y:hidden</code> — hides the text outside the box <div id="div1"> 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> </li> <li> <code>overflow-y:scroll</code> — always adds a scrollbar <div id="div2"> 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> </li> <li> <code>overflow-y:visible</code> — displays the text outside the box if needed <div id="div3"> 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> </li> <li> <code>overflow-y:auto</code> — on most browser, equivalent to <code>scroll</code> <div id="div4"> 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> </li> </ul> ``` #### CSS ``` #div1, #div2, #div3, #div4 { border: 1px solid black; width: 250px; height: 100px; } #div1 { overflow-y: hidden; margin-bottom: 12px; } #div2 { overflow-y: scroll; margin-bottom: 12px; } #div3 { overflow-y: visible; margin-bottom: 120px; } #div4 { overflow-y: auto; margin-bottom: 120px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Overflow Module Level 3 # overflow-properties](https://w3c.github.io/csswg-drafts/css-overflow/#overflow-properties) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `overflow-y` | 1 | 12 | 3.5 | 8 5 | 9.5 | 3 | 4.4 | 18 | 4 | 14 | 1 | 1.0 | | `clip` | 90 | 90 | 81 3.5-81 | No | 76 | 16 | 90 | 90 | 81 4-81 | No | 16 | 15.0 | See also -------- * Related CSS properties: [`text-overflow`](text-overflow), [`white-space`](white-space), [`overflow`](overflow), [`overflow-x`](overflow-x), [`clip`](clip), [`display`](display) css hypot() hypot() ======= **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `hypot()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](css_functions) is an exponential function that returns the [square root](https://en.wikipedia.org/wiki/Square_root) of the sum of squares of its parameters. While [`pow()`](pow) and [`sqrt()`](sqrt) only work on unitless numbers, `hypot()` accepts values with units, but they all must have the same [type](css_types). Syntax ------ ``` /\* A <number> value \*/ width: hypot(2em); /\* 2em \*/ width: hypot(3em, 4em); /\* 5em \*/ width: hypot(30px, 40px); /\* 50px \*/ width: hypot(48px, 64px); /\* 80px \*/ width: hypot(3px, 4px, 5px); /\* 7.0710678118654755px \*/ ``` ### Parameters The `hypot(x [, ...]#)` function accepts one or more comma-separated calculations as its parameters. `x`, `x2`, ..., `xN` A calculation that resolves to a [`<number>`](number), [`<dimension>`](dimension), or [`<percentage>`](percentage). ### Return value Returns a [`<number>`](number), [`<dimension>`](dimension), or [`<percentage>`](percentage) (based on the inputs), which is the square root of the sum of squares of its parameters. * If any of the inputs is `infinite`, the result is `+∞`. * If a single parameter is provided, the result is the absolute value of its input. `hypot(2em)` and `hypot(-2em)` both resolve to `2em`. ### Formal syntax ``` <hypot()> = hypot( <calc-sum>[#](value_definition_syntax#hash_mark) ) <calc-sum> = <calc-product> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '+' [|](value_definition_syntax#single_bar) '-' []](value_definition_syntax#brackets) <calc-product> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-product> = <calc-value> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '*' [|](value_definition_syntax#single_bar) '/' []](value_definition_syntax#brackets) <calc-value> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-value> = [<number>](number) [|](value_definition_syntax#single_bar) [<dimension>](dimension) [|](value_definition_syntax#single_bar) [<percentage>](percentage) [|](value_definition_syntax#single_bar) <calc-constant> [|](value_definition_syntax#single_bar) ( <calc-sum> ) <calc-constant> = e [|](value_definition_syntax#single_bar) pi [|](value_definition_syntax#single_bar) infinity [|](value_definition_syntax#single_bar) -infinity [|](value_definition_syntax#single_bar) NaN ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # exponent-funcs](https://w3c.github.io/csswg-drafts/css-values/#exponent-funcs) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `hypot` | No | No | No | No | No | 15.4 | No | No | No | No | 15.4 | No | See also -------- * [`pow()`](pow) * [`sqrt()`](sqrt) * [`log()`](log) * [`exp()`](exp)
programming_docs
css font-family font-family =========== The `font-family` CSS property specifies a prioritized list of one or more font family names and/or generic family names for the selected element. Try it ------ Values are separated by commas to indicate that they are alternatives. The browser will select the first font in the list that is installed or that can be downloaded using a [`@font-face`](@font-face) at-rule. It is often convenient to use the shorthand property [`font`](font) to set `font-size` and other font related properties all at once. You should always include at least one generic family name in a `font-family` list, since there's no guarantee that any given font is available. This lets the browser select an acceptable fallback font when necessary. The `font-family` property specifies a list of fonts, from highest priority to lowest. Font selection *does not* stop at the first font in the list that is on the user's system. Rather, font selection is done *one character at a time*, so that if an available font does not have a glyph for a needed character, the latter fonts are tried. When a font is only available in some [styles](font-style), [variants](font-variant), or [sizes](font-size), those properties may also influence which font family is chosen. Syntax ------ ``` /\* A font family name and a generic family name \*/ font-family: "Gill Sans Extrabold", sans-serif; font-family: "Goudy Bookletter 1911", sans-serif; /\* A generic family name only \*/ font-family: serif; font-family: sans-serif; font-family: monospace; font-family: cursive; font-family: fantasy; font-family: system-ui; font-family: ui-serif; font-family: ui-sans-serif; font-family: ui-monospace; font-family: ui-rounded; font-family: emoji; font-family: math; font-family: fangsong; /\* Global values \*/ font-family: inherit; font-family: initial; font-family: revert; font-family: revert-layer; font-family: unset; ``` The `font-family` property lists one or more font families, separated by commas. Each font family is specified as either a `<family-name>` or a `<generic-name>` value. The example below lists two font families, the first with a `<family-name>` and the second with a `<generic-name>`: ``` font-family: "Gill Sans Extrabold", sans-serif; ``` ### Values `<family-name>` The name of a font family. For example, "Times" and "Helvetica" are font families. Font family names containing whitespace should be quoted. For example: "Comic Sans MS". `<generic-name>` Generic font families are a fallback mechanism, a means of preserving some of the style sheet author's intent when none of the specified fonts are available. Generic family names are keywords and must not be quoted. A generic font family should be the last item in the list of font family names. The following keywords are defined: `serif` Glyphs have finishing strokes, flared or tapering ends, or have actual serifed endings. For example: Lucida Bright, Lucida Fax, Palatino, Palatino Linotype, Palladio, URW Palladio, serif. `sans-serif` Glyphs have stroke endings that are plain. For example: Open Sans, Fira Sans, Lucida Sans, Lucida Sans Unicode, Trebuchet MS, Liberation Sans, Nimbus Sans L, sans-serif. `monospace` All glyphs have the same fixed width. For example: Fira Mono, DejaVu Sans Mono, Menlo, Consolas, Liberation Mono, Monaco, Lucida Console, monospace. `cursive` Glyphs in cursive fonts generally have either joining strokes or other cursive characteristics beyond those of italic typefaces. The glyphs are partially or completely connected, and the result looks more like handwritten pen or brush writing than printed letter work. For example: Brush Script MT, Brush Script Std, Lucida Calligraphy, Lucida Handwriting, Apple Chancery, cursive. `fantasy` Fantasy fonts are primarily decorative fonts that contain playful representations of characters. For example: Papyrus, Herculanum, Party LET, Curlz MT, Harrington, fantasy. `system-ui` Glyphs are taken from the default user interface font on a given platform. Because typographic traditions vary widely across the world, this generic is provided for typefaces that don't map cleanly into the other generics. `ui-serif` The default user interface serif font. `ui-sans-serif` The default user interface sans-serif font. `ui-monospace` The default user interface monospace font. `ui-rounded` The default user interface font that has rounded features. `math` This is for the particular stylistic concerns of representing mathematics: superscript and subscript, brackets that cross several lines, nesting expressions, and double struck glyphs with distinct meanings. `emoji` Fonts that are specifically designed to render emoji. `fangsong` A particular style of Chinese characters that are between serif-style Song and cursive-style Kai forms. This style is often used for government documents. ### Valid family names Font family names must either be given quoted as strings, or unquoted as a sequence of one or more identifiers. This means that punctuation characters and digits at the start of each token must be escaped in unquoted font family names. It is a **good practice** to quote font family names that contain white space, digits, or punctuation characters other than hyphens. For example, the following declarations are valid: ``` font-family: "Goudy Bookletter 1911", sans-serif; ``` The following declarations are **invalid**: ``` font-family: Goudy Bookletter 1911, sans-serif; font-family: Red/Black, sans-serif; font-family: "Lucida" Grande, sans-serif; font-family: Ahem!, sans-serif; font-family: test@foo, sans-serif; font-family: #POUND, sans-serif; font-family: Hawaii 5-0, sans-serif; ``` The following example is technically **valid** but is not recommended: ``` font-family: Gill Sans Extrabold, sans-serif; ``` Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | depends on user agent | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` font-family = [[](value_definition_syntax#brackets) [<family-name>](family-name) [|](value_definition_syntax#single_bar) [<generic-family>](generic-family) []](value_definition_syntax#brackets)[#](value_definition_syntax#hash_mark) ``` Examples -------- ### Some common font families ``` .serif { font-family: Times, "Times New Roman", Georgia, serif; } .sansserif { font-family: Verdana, Arial, Helvetica, sans-serif; } .monospace { font-family: "Lucida Console", Courier, monospace; } .cursive { font-family: cursive; } .fantasy { font-family: fantasy; } .emoji { font-family: emoji; } .math { font-family: math; } .fangsong { font-family: fangsong; } ``` Specifications -------------- | Specification | | --- | | [CSS Fonts Module Level 4 # generic-font-families](https://w3c.github.io/csswg-drafts/css-fonts/#generic-font-families) | | [CSS Fonts Module Level 4 # font-family-prop](https://w3c.github.io/csswg-drafts/css-fonts/#font-family-prop) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `font-family` | 1 | 12 | 1 Not supported on `option` elements. See [bug 1536148](https://bugzil.la/1536148). | 3 | 3.5 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `math` | 103 | 103 | No | No | 89 | No | No | 103 | No | No | No | No | | `system-ui` | 56 | 79 | 92 43 Supported on macOS only. | No | 43 | 11 9 | 56 | 56 | 92 | 43 | 11 9 | 6.0 | See also -------- * [`font-style`](font-style) * [`font-weight`](font-weight) * [Fundamental text and font styling](https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text/Fundamentals) css animation-play-state animation-play-state ==================== The `animation-play-state` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets whether an animation is running or paused. Try it ------ Resuming a paused animation will start the animation from where it left off at the time it was paused, rather than starting over from the beginning of the animation sequence. Syntax ------ ``` /\* Single animation \*/ animation-play-state: running; animation-play-state: paused; /\* Multiple animations \*/ animation-play-state: paused, running, running; /\* Global values \*/ animation-play-state: inherit; animation-play-state: initial; animation-play-state: revert; animation-play-state: revert-layer; animation-play-state: unset; ``` ### Values `running` The **animation** is currently **playing**. `paused` The **animation** is currently **paused**. **Note:** When you specify multiple comma-separated values on an `animation-*` property, they are applied to the animations in the order in which the [`animation-name`](animation-name)s appear. For situations where the number of animations and `animation-*` property values do not match, see [Setting multiple animation property values](css_animations/using_css_animations#setting_multiple_animation_property_values). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `running` | | Applies to | all elements, [`::before`](::before) and [`::after`](::after) <pseudo-elements> | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | Not animatable | Formal syntax ------------- ``` animation-play-state = <single-animation-play-state>[#](value_definition_syntax#hash_mark) <single-animation-play-state> = running [|](value_definition_syntax#single_bar) paused ``` Examples -------- ### Pausing an animation This animation is paused, but runs when you hover over it. #### HTML ``` <div class="box"></div> ``` #### CSS ``` .box { background-color: rebeccapurple; border-radius: 10px; width: 100px; height: 100px; animation-name: rotate; animation-duration: 0.7s; animation-iteration-count: infinite; animation-play-state: paused; } .box:hover { animation-play-state: running; } @keyframes rotate { 0% { transform: rotate(0); } 100% { transform: rotate(360deg); } } ``` #### Result Hover over the rectangle to play the animation. See [CSS animations](css_animations/using_css_animations) for examples. Specifications -------------- | Specification | | --- | | [CSS Animations Level 1 # animation-play-state](https://w3c.github.io/csswg-drafts/css-animations/#animation-play-state) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `animation-play-state` | 43 3 | 12 12 | 49 16 5 | 10 | 30 15 12.1-15 12-15 | 9 4 | 43 ≤37 | 43 18 | 49 16 5 | 30 14 12.1-14 12-14 | 9 2 | 4.0 1.0 | See also -------- * [Using CSS animations](css_animations/using_css_animations) * JavaScript [`AnimationEvent`](https://developer.mozilla.org/en-US/docs/Web/API/AnimationEvent) API * Other related animation properties: [`animation`](animation), [`animation-composition`](animation-composition), [`animation-delay`](animation-delay), [`animation-direction`](animation-direction), [`animation-duration`](animation-duration), [`animation-fill-mode`](animation-fill-mode), [`animation-iteration-count`](animation-iteration-count), [`animation-name`](animation-name), [`animation-timeline`](animation-timeline), [`animation-timing-function`](animation-timing-function) css color-scheme color-scheme ============ The `color-scheme` CSS property allows an element to indicate which color schemes it can comfortably be rendered in. Common choices for operating system color schemes are "light" and "dark", or "day mode" and "night mode". When a user selects one of these color schemes, the operating system makes adjustments to the user interface. This includes form controls, scrollbars, and the used values of CSS system colors. Try it ------ Syntax ------ ``` color-scheme: normal; color-scheme: light; color-scheme: dark; color-scheme: light dark; color-scheme: only light; /\* Global values \*/ color-scheme: inherit; color-scheme: initial; color-scheme: revert; color-scheme: revert-layer; color-scheme: unset; ``` The `color-scheme` property's value must be one of the following keywords. ### Values `normal` Indicates that the element isn't aware of any color schemes, and so should be rendered using the browser's default color scheme. `light` Indicates that the element can be rendered using the operating system light color scheme. `dark` Indicates that the element can be rendered using the operating system dark color scheme. `only` Forbids the user agent from overriding the color scheme for the element. Can be used to turn off color overrides caused by Chrome's [Auto Dark Theme](https://developer.chrome.com/blog/auto-dark-theme/#per-element-opt-out), by applying `color-scheme: only light;` on a specific element or `:root`. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | all elements and text | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` color-scheme = normal [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) light [|](value_definition_syntax#single_bar) dark [|](value_definition_syntax#single_bar) [<custom-ident>](custom-ident) []](value_definition_syntax#brackets)[+](value_definition_syntax#plus) [&&](value_definition_syntax#double_ampersand) only[?](value_definition_syntax#question_mark) ``` Examples -------- ### Adapting to color schemes To opt the entire page into the user's color scheme preferences declare `color-scheme` on the [`:root`](:root) element. ``` :root { color-scheme: light dark; } ``` Specifications -------------- | Specification | | --- | | [CSS Color Adjustment Module Level 1 # color-scheme-prop](https://w3c.github.io/csswg-drafts/css-color-adjust/#color-scheme-prop) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `color-scheme` | 81 | 81 | 96 | No | 68 | 13 | 81 | 81 | 96 | 58 | 13 | 13.0 | | `only_dark` | No | No | No | No | No | 13 | No | No | No | No | 13 | No | | `only_light` | 81-85 | 81-85 | No | No | 68-71 | 13 | No | 81-85 | No | 58-60 | 13 | 13.0-14.0 | See also -------- * [`prefers-color-scheme`](@media/prefers-color-scheme) media query to detect user preferences for color schemes. * [Applying color to HTML elements using CSS](css_colors/applying_color) * Other color-related properties: [`color`](color), [`background-color`](background-color), [`border-color`](border-color), [`outline-color`](outline-color), [`text-decoration-color`](text-decoration-color), [`text-emphasis-color`](text-emphasis-color), [`text-shadow`](text-shadow), [`caret-color`](caret-color), and [`column-rule-color`](column-rule-color) * [`background-image`](background-image) * [`print-color-adjust`](print-color-adjust) css place-content place-content ============= The `place-content` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [shorthand property](shorthand_properties) allows you to align content along both the block and inline directions at once (i.e. the [`align-content`](align-content) and [`justify-content`](justify-content) properties) in a relevant layout system such as [Grid](css_grid_layout) or [Flexbox](css_flexible_box_layout). Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`align-content`](align-content) * [`justify-content`](justify-content) Syntax ------ ``` /\* Positional alignment \*/ /\* align-content does not take left and right values \*/ place-content: center start; place-content: start center; place-content: end left; place-content: flex-start center; place-content: flex-end center; /\* Baseline alignment \*/ /\* justify-content does not take baseline values \*/ place-content: baseline center; place-content: first baseline space-evenly; place-content: last baseline right; /\* Distributed alignment \*/ place-content: space-between space-evenly; place-content: space-around space-evenly; place-content: space-evenly stretch; place-content: stretch space-evenly; /\* Global values \*/ place-content: inherit; place-content: initial; place-content: revert; place-content: revert-layer; place-content: unset; ``` The first value is the [`align-content`](align-content) property value, the second the [`justify-content`](justify-content) one. **Note:** If the second value is not present, the first value is used for both, provided it is a valid value for both. If it is invalid for one or the other, the whole value will be invalid. ### Values `start` The items are packed flush to each other toward the start edge of the alignment container in the appropriate axis. `end` The items are packed flush to each other toward the end edge of the alignment container in the appropriate 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 or cross-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 or cross-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. `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`. `space-between` The items are evenly distributed within the alignment container. 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. `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`. `space-around` The items are evenly distributed within the alignment container. 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. 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 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 [`max-height`](max-height)/[`max-width`](max-width) (or equivalent functionality), so that the combined size exactly fills the alignment container `safe` Used alongside an alignment keyword. If the chosen keyword means that the item overflows the alignment container causing data loss, the item is instead aligned as if the alignment mode were `start`. `unsafe` Used alongside an alignment keyword. Regardless of the relative sizes of the item and alignment container, and regardless of whether overflow which causes data loss might happen, the given alignment value is honored. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`align-content`](align-content): `normal` * [`justify-content`](justify-content): `normal` | | Applies to | multi-line flex containers | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`align-content`](align-content): as specified * [`justify-content`](justify-content): as specified | | Animation type | discrete | Formal syntax ------------- ``` place-content = <'align-content'> <'justify-content'>[?](value_definition_syntax#question_mark) ``` Examples -------- ### Placing content in a flex container #### HTML ``` <div id="container"> <div class="small">Lorem</div> <div class="small">Lorem<br />ipsum</div> <div class="large">Lorem</div> <div class="large">Lorem<br />ipsum</div> <div class="large"></div> <div class="large"></div> </div> ``` #### CSS ``` #container { display: flex; height: 240px; width: 240px; flex-wrap: wrap; background-color: #8c8c8c; writing-mode: horizontal-tb; /\* Can be changed in the live sample \*/ direction: ltr; /\* Can be changed in the live sample \*/ place-content: flex-end center; /\* Can be changed in the live sample \*/ } div > div { border: 2px solid #8c8c8c; width: 50px; background-color: #a0c8ff; } .small { font-size: 12px; height: 40px; } .large { font-size: 14px; height: 50px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Box Alignment Module Level 3 # place-content](https://w3c.github.io/csswg-drafts/css-align/#place-content) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `place-content` | 59 | 79 | 45 | No | 46 | 9 | 59 | 59 | 45 | 43 | 9 | 7.0 | | `flex_context` | 59 | 79 | 45 Starting with version 60, you can only specify a single value if it is valid for both `align-content` and `justify-content`. | No | 46 | 9 | 59 | 59 | 45 Starting with version 60, you can only specify a single value if it is valid for both `align-content` and `justify-content`. | 43 | 9 | 7.0 | | `grid_context` | 59 | 79 | 53 Starting with version 60, you can only specify a single value if it is valid for both `align-content` and `justify-content`. | No | 46 | 11 | 59 | 59 | 53 Starting with version 60, you can only specify a single value if it is valid for both `align-content` and `justify-content`. | 43 | 11 | 7.0 | See also -------- * CSS Flexbox Guide: *[Basic Concepts of Flexbox](css_flexible_box_layout/basic_concepts_of_flexbox)* * CSS Flexbox Guide: *[Aligning items in a flex container](css_flexible_box_layout/aligning_items_in_a_flex_container)* * CSS Grid Guide: *[Box alignment in CSS Grid layouts](css_grid_layout/box_alignment_in_css_grid_layout)* * [CSS Box Alignment](css_box_alignment) * The [`align-content`](align-content) property * The [`justify-content`](justify-content) property
programming_docs
css page-break-inside page-break-inside ================= **Warning:** This property has been replaced by the [`break-inside`](break-inside) property. The `page-break-inside` CSS property adjusts page breaks *inside* the current element. ``` /\* Keyword values \*/ page-break-inside: auto; page-break-inside: avoid; /\* Global values \*/ page-break-inside: inherit; page-break-inside: initial; page-break-inside: revert; page-break-inside: revert-layer; page-break-inside: unset; ``` Syntax ------ ### Values `auto` Initial value. Automatic page breaks (neither forced nor forbidden). `avoid` Avoid page breaks inside the element. Page break aliases ------------------ The `page-break-inside` property is now a legacy property, replaced by [`break-inside`](break-inside). For compatibility reasons, `page-break-inside` should be treated by browsers as an alias of `break-inside`. This ensures that sites using `page-break-inside` continue to work as designed. A subset of values should be aliased as follows: | page-break-inside | break-inside | | --- | --- | | `auto` | `auto` | | `avoid` | `avoid` | Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | block-level elements in the normal flow of the root element. User agents may also apply it to other elements like `table-row` elements. | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` page-break-inside = avoid [|](value_definition_syntax#single_bar) auto [|](value_definition_syntax#single_bar) inherit ``` Examples -------- ### Avoiding page breaks inside elements #### HTML ``` <div class="page"> <p>This is the first paragraph.</p> <section class="list"> <span>A list</span> <ol> <li>one</li> <!-- <li>two</li> --> </ol> </section> <ul> <li>one</li> <!-- <li>two</li> --> </ul> <p>This is the second paragraph.</p> <p>This is the third paragraph, it contains more text.</p> <p> This is the fourth paragraph. It has a little bit more text than the third one. </p> </div> ``` #### CSS ``` .page { background-color: #8cffa0; height: 90px; width: 200px; columns: 1; column-width: 100px; } .list, ol, ul, p { break-inside: avoid; } p { background-color: #8ca0ff; } ol, ul, .list { margin: 0.5em 0; display: block; background-color: orange; } p:first-child { margin-top: 0; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Paged Media Module Level 3 # page-break-inside](https://w3c.github.io/csswg-drafts/css-page/#page-break-inside) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `page-break-inside` | 1 | 12 | 19 Until Firefox 25, `page-break-inside: avoid` did not work with the height of a block. | 8 | 7 | 1.3 | 37 | 18 | 19 Until Firefox 25, `page-break-inside: avoid` did not work with the height of a block. | 14 | 1 | 1.0 | See also -------- * [`break-before`](break-before), [`break-after`](break-after), [`break-inside`](break-inside) * [`page-break-after`](page-break-after), [`page-break-before`](page-break-before) * [`orphans`](orphans), [`widows`](widows) css CSS Counter Styles CSS Counter Styles ================== **CSS Counter Styles** is a module of CSS that lets you define your own counter styles. Reference --------- ### Properties * [`counter-increment`](counter-increment) * [`counter-reset`](counter-reset) ### Functions * [`symbols()`](@counter-style/symbols) ### At-rules * [`@counter-style`](@counter-style) + [`system`](@counter-style/system) + [`additive-symbols`](@counter-style/additive-symbols) + [`negative`](@counter-style/negative) + [`prefix`](@counter-style/prefix) + [`suffix`](@counter-style/suffix) + [`range`](@counter-style/range) + [`pad`](@counter-style/pad) + [`speak-as`](@counter-style/speak-as) + [`fallback`](@counter-style/fallback) Guides ------ [Using CSS counters](css_counter_styles/using_css_counters) Describes how to use counters to number any HTML element or to perform complex counting. Specifications -------------- | Specification | | --- | | [CSS Counter Styles Level 3 # the-counter-style-rule](https://w3c.github.io/csswg-drafts/css-counter-styles/#the-counter-style-rule) | | [CSS Lists and Counters Module Level 3 # increment-set](https://w3c.github.io/csswg-drafts/css-lists/#increment-set) | | [CSS Lists and Counters Module Level 3 # counter-reset](https://w3c.github.io/csswg-drafts/css-lists/#counter-reset) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `CSS_Counter_Styles` | 2 | 12 | 1 | 8 | 9.2 | 3 | 4.4 | 18 | 25 | 10.1 | 1 | 1.0 | | `reset_does_not_affect_siblings` | No | No | 82 | No | No | No | No | No | 82 | No | No | No | | `reversed` | No | No | 96 | No | No | No | No | No | 96 | No | No | No | | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `CSS_Counter_Styles` | 2 | 12 | 1 | 8 | 9.2 | 3 | 4.4 | 18 | 25 | 10.1 | 1 | 1.0 | | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `CSS_Counter_Styles` | 91 | 91 | 33 | No | 77 | No See [bug 167645](https://webkit.org/b/167645). | 91 | 91 | 33 | 64 | No See [bug 167645](https://webkit.org/b/167645). | 16.0 | | `additive-symbols` | 91 | 91 | 33 | No | 77 | No | 91 | 91 | 33 | 64 | No | 16.0 | | `fallback` | 91 | 91 | 33 | No | 77 | No | 91 | 91 | 33 | 64 | No | 16.0 | | `negative` | 91 | 91 | 33 | No | 77 | No | 91 | 91 | 33 | 64 | No | 16.0 | | `pad` | 91 | 91 | 33 | No | 77 | No | 91 | 91 | 33 | 64 | No | 16.0 | | `prefix` | 91 | 91 | 33 | No | 77 | No | 91 | 91 | 33 | 64 | No | 16.0 | | `range` | 91 | 91 | 33 | No | 77 | No | 91 | 91 | 33 | 64 | No | 16.0 | | `speak-as` | No | No | 33 | No | No | No | No | No | 33 | No | No | No | | `suffix` | 91 | 91 | 33 | No | 77 | No | 91 | 91 | 33 | 64 | No | 16.0 | | `symbols` | 91 Does not support `<image>` as a value for the `symbols` descriptor. | 91 Does not support `<image>` as a value for the `symbols` descriptor. | 33 Does not support `<image>` as a value for the `symbols` descriptor. | No | 77 Does not support `<image>` as a value for the `symbols` descriptor. | No | 91 Does not support `<image>` as a value for the `symbols` descriptor. | 91 Does not support `<image>` as a value for the `symbols` descriptor. | 33 Does not support `<image>` as a value for the `symbols` descriptor. | 64 Does not support `<image>` as a value for the `symbols` descriptor. | No | 16.0 Does not support `<image>` as a value for the `symbols` descriptor. | | `system` | 91 | 91 | 33 | No | 77 | No | 91 | 91 | 33 | 64 | No | 16.0 | ### css.at-rules.counter-style BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. ### css.properties.counter-increment BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. ### css.properties.counter-reset BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. css ID selectors ID selectors ============ The CSS **ID selector** matches an element based on the value of the element's [`id`](https://developer.mozilla.org/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. ``` /\* The element with id="demo" \*/ #demo { border: red 2px solid; } ``` Syntax ------ ``` #id\_value { style properties } ``` Note that syntactically (but not specificity-wise), this is equivalent to the following [`attribute selector`](attribute_selectors): ``` [id=id\_value] { style properties } ``` Examples -------- ### CSS ``` #identified { background-color: skyblue; } ``` ### HTML ``` <div id="identified">This div has a special ID on it!</div> <div>This is just a regular div.</div> ``` ### Result Specifications -------------- | Specification | | --- | | [Selectors Level 4 # id-selectors](https://w3c.github.io/csswg-drafts/selectors/#id-selectors) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `ID_selectors` | 1 | 12 | 1 | 3 | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | See also -------- * [CSS Selectors](css_selectors) * [Learn CSS: Selectors](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors) css counter() counter() ========= The `counter()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](css_functions) returns a string representing the current value of the named counter, if there is one. It is generally used in the [`content`](content) property of <pseudo-elements>, but can theoretically be used anywhere a [`<string>`](string) value is supported. Try it ------ Syntax ------ ``` /\* Simple usage \*/ counter(countername); /\* changing the counter display \*/ counter(countername, upper-roman) ``` A [counter](css_counter_styles/using_css_counters) has no visible effect by itself. The `counter()` function (and [`counters()`](counters) function) is what makes it useful by returning developer defined strings (or images). ### Values [`<custom-ident>`](custom-ident) A name identifying the counter, which is the same case-sensitive name used for the [`counter-reset`](counter-reset) and [`counter-increment`](counter-increment). The name cannot start with two dashes and can't be `none`, `unset`, `initial`, or `inherit`. `<counter-style>` A [`<list-style-type>`](list-style-type) name, [`<@counter-style>`](@counter-style) name or [`symbols()`](@counter-style/symbols) function, where a counter style name is a `numeric`, `alphabetic`, or `symbolic` simple predefined counter style, a complex longhand east Asian or Ethiopic predefined counter style, or other [predefined counter style](css_counter_styles). If omitted, the counter-style defaults to `decimal`. ### Formal syntax ``` <counter()> = counter( [<counter-name>](counter-name) , <counter-style>[?](value_definition_syntax#question_mark) ) <counter-style> = [<counter-style-name>](counter-style-name) [|](value_definition_syntax#single_bar) <symbols()> <symbols()> = symbols( <symbols-type>[?](value_definition_syntax#question_mark) [[](value_definition_syntax#brackets) [<string>](string) [|](value_definition_syntax#single_bar) <image> []](value_definition_syntax#brackets)[+](value_definition_syntax#plus) ) <symbols-type> = cyclic [|](value_definition_syntax#single_bar) numeric [|](value_definition_syntax#single_bar) alphabetic [|](value_definition_syntax#single_bar) symbolic [|](value_definition_syntax#single_bar) fixed <image> = <url> [|](value_definition_syntax#single_bar) [<gradient>](gradient) <url> = url( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) [|](value_definition_syntax#single_bar) src( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) ``` Examples -------- ### default value compared to upper Roman #### HTML ``` <ol> <li></li> <li></li> <li></li> </ol> ``` #### CSS ``` ol { counter-reset: listCounter; } li { counter-increment: listCounter; } li::after { content: "[" counter(listCounter) "] == [" counter(listCounter, upper-roman) "]"; } ``` #### Result ### decimal-leading-zero compared to lower-alpha #### HTML ``` <ol> <li></li> <li></li> <li></li> </ol> ``` #### CSS ``` ol { counter-reset: count; } li { counter-increment: count; } li::after { content: "[" counter(count, decimal-leading-zero) "] == [" counter( count, lower-alpha ) "]"; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Lists and Counters Module Level 3 # counter-functions](https://w3c.github.io/csswg-drafts/css-lists/#counter-functions) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `counter` | 1 | 12 | 1 | 8 | 9.2 | 3 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | See also -------- * [Using CSS Counters](css_counter_styles/using_css_counters) * [`counter-reset`](counter-reset) * [`counter-set`](counter-set) * [`counter-increment`](counter-increment) * [`@counter-style`](@counter-style) * CSS [`counters()`](counters) function css content-visibility content-visibility ================== The `content-visibility` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property controls whether or not an element renders its contents at all, along with forcing a strong set of containments, allowing user agents to potentially omit large swathes of layout and rendering work until it becomes needed. It enables the user agent to skip an element's rendering work (including layout and painting) until it is needed — which makes the initial page load much faster. **Note:** The [`contentvisibilityautostatechanged`](https://developer.mozilla.org/en-US/docs/Web/API/Element/contentvisibilityautostatechanged_event) event fires on any element with `content-visibility: auto` set on it when its rendering work starts or stops being skipped. This provides a convenient way for an app's code to start or stop rendering processes (e.g. drawing on a [`<canvas>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas)) when they are not needed, thereby conserving processing power. Syntax ------ ``` /\* Keyword values \*/ content-visibility: visible; content-visibility: hidden; content-visibility: auto; /\* Global values \*/ content-visibility: inherit; content-visibility: initial; content-visibility: revert; content-visibility: revert-layer; content-visibility: unset; ``` ### Values `visible` No effect. The element's contents are laid out and rendered as normal. `hidden` The element [skips its contents](css_containment#skips_its_contents). The skipped contents must not be accessible to user-agent features, such as find-in-page, tab-order navigation, etc., nor be selectable or focusable. This is similar to giving the contents `display: none`. `auto` The element turns on layout containment, style containment, and paint containment. If the element is not [relevant to the user](css_containment#relevant_to_the_user), it also skips its contents. Unlike hidden, the skipped contents must still be available as normal to user-agent features such as find-in-page, tab order navigation, etc., and must be focusable and selectable as normal. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `visible` | | Applies to | elementsForWhichLayoutContainmentCanApply | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Accessibility concerns ---------------------- Prior to Chromium 90, offscreen headers and landmark roles within `content-visibility: auto` were not exposed to a11y tools. As of Chromium 90, this has been corrected, and off-screen content within a `content-visibility: auto` element remains in the document object model and the accessibility tree. This allows improving page performance with `content-visibility: auto` without negatively impacting accessibility. However, one caveat to keep in mind is that, since styles for off-screen content are not rendered, elements intentionally hidden with `display: none` or `visibility: hidden` *will still appear in the accessibility tree*. If you don't want an element to appear in the accessibility tree, use `aria-hidden="true"`. Examples -------- ### Using auto to reduce rendering cost of long pages The following example shows the use of auto to skip painting and rendering of off-screen sections. This helps with both load and interactions on the page, since the content outside of the viewport is not rendered. ``` <style> section { content-visibility: auto; contain-intrinsic-size: 0 500px; } <section>… <section>… <section>… <section>… … ``` ### Using hidden to manually manage visibility The following example shows that it is possible to manage visibility in script. The added benefit of using `content-visibility: hidden` instead of, for example, `display: none` is that rendered content when hidden with `content-visibility` will preserve rendering state. This means that if the content is shown again, it will render quicker than the alternative. ``` <style> .hidden { content-visibility: hidden; /* when hidden, we want the element to size as if it had one child of 0x500px size */ contain-intrinsic-size: 0 500px; } .visible { content-visibility: visible; /* this is here to avoid layout shift when switching between .hidden and .visible */ contain: style layout paint; } <div class=hidden>… <div class=visible>… <div class=hidden>… <div class=hidden>… ``` Specifications -------------- | Specification | | --- | | [CSS Containment Module Level 2 # content-visibility](https://w3c.github.io/csswg-drafts/css-contain/#content-visibility) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `content-visibility` | 85 | 85 | No | No | 71 | No | 85 | 85 | No | 60 | No | 14.0 | See also -------- * [CSS Containment](css_containment) * [content-visibility: the new CSS property that boosts your rendering performance](https://web.dev/content-visibility/) (web.dev) * The [`contentvisibilityautostatechanged`](https://developer.mozilla.org/en-US/docs/Web/API/Element/contentvisibilityautostatechanged_event) event css <custom-ident> <custom-ident> ============== The `<custom-ident>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) denotes an arbitrary user-defined string used as an [identifier](https://developer.mozilla.org/en-US/docs/Glossary/Identifier). It is case-sensitive, and certain values are forbidden in various contexts to prevent ambiguity. Syntax ------ The syntax of `<custom-ident>` is similar to CSS identifiers (such as property names), except that it is [case-sensitive](https://en.wikipedia.org/wiki/Case_sensitivity). It consists of one or more characters, where characters can be any of the following: * any alphabetical character (`A` to `Z`, or `a` to `z`), * any decimal digit (`0` to `9`), * a hyphen (`-`), * an underscore (`_`), * an escaped character (preceded by a backslash, `\`), * a [Unicode](https://en.wikipedia.org/wiki/Unicode) character (in the format of a backslash, `\`, followed by one to six hexadecimal digits, representing its Unicode code point) Note that `id1`, `Id1`, `iD1` and `ID1` are all different identifiers as they are [case-sensitive](https://en.wikipedia.org/wiki/Case_sensitivity). On the other hand, as there are several ways to escape a character, `toto\?` and `toto\3F` are the same identifiers. ### Forbidden values A `<custom-ident>` must not be placed between single or double quotes as this would be identical to a [`<string>`](string). Moreover, the first character must not be a decimal digit, nor a hyphen (`-`) followed by a decimal digit or another hyphen. To prevent ambiguity, each property that uses `<custom-ident>` forbids the use of specific values: [`animation-name`](animation-name) Forbids the global CSS values (`unset`, `initial`, and `inherit`), as well as `none`. [`counter-reset`](counter-reset), [`counter-increment`](counter-increment) Forbids the global CSS values (`unset`, `initial`, and `inherit`), as well as `none`. [`@counter-style`](@counter-style), [`list-style-type`](list-style-type) Forbids the global CSS values (`unset`, `initial`, and `inherit`), as well as the values: * `none` * `inline` * `outside` Also, quite a few predefined values are implemented by the different browsers: * `disc` * `circle` * `square` * `decimal` * `cjk-decimal` * `decimal-leading-zero` * `lower-roman` * `upper-roman` * `lower-greek` * `lower-alpha` * `lower-latin` * `upper-alpha` * `upper-latin` * `arabic-indic` * `armenian` * `bengali` * `cambodian` * `cjk-earthly-branch` * `cjk-heavenly-stem` * `cjk-ideographic` * `devanagari` * `ethiopic-numeric` * `georgian` * `gujarati` * `gurmukhi` * `hebrew` * `hiragana` * `hiragana-iroha` * `japanese-formal` * `japanese-informal` * `kannada` * `katakana` * `katakana-iroha` * `khmer` * `korean-hangul-formal` * `korean-hanja-formal` * `korean-hanja-informal` * `lao` * `lower-armenian` * `malayalam` * `mongolian` * `myanmar` * `oriya` * `persian` * `simp-chinese-formal` * `simp-chinese-informal` * `tamil` * `telugu` * `thai` * `tibetan` * `trad-chinese-formal` * `trad-chinese-informal` * `upper-armenian` * `disclosure-open` * `disclosure-close` [`grid-row-start`](grid-row-start), [`grid-row-end`](grid-row-end), [`grid-column-start`](grid-column-start), [`grid-column-end`](grid-column-end) Forbids the `span` value. [`will-change`](will-change) Forbids the global CSS values (`unset`, `initial`, and `inherit`), as well as the values `will-change`, `auto`, `scroll-position`, and `contents`. Examples -------- ### Valid identifiers ``` nono79 A mix of alphanumeric characters and numbers ground-level A mix of alphanumeric characters and a dash -test A dash followed by alphanumeric characters _internal An underscore followed by alphanumeric characters \22 toto A Unicode character followed by a sequence of alphanumeric characters bili\.bob A correctly escaped period ``` ### Invalid identifiers ``` 34rem It must not start with a decimal digit. -12rad It must not start with a dash followed by a decimal digit. bili.bob Only alphanumeric characters, _, and - needn't be escaped. --toto It must not start with two dashes. This would be a custom property. 'bilibob' This would be a <string>. "bilibob" This would be a <string>. ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # custom-idents](https://drafts.csswg.org/css-values/#custom-idents) | | [CSS Will Change Module Level 1 # valdef-will-change-custom-ident](https://drafts.csswg.org/css-will-change/#valdef-will-change-custom-ident) | | [CSS Counter Styles Level 3 # typedef-counter-style-name](https://drafts.csswg.org/css-counter-styles/#typedef-counter-style-name) | | [CSS Lists and Counters Module Level 3 # counter-properties](https://drafts.csswg.org/css-lists/#counter-properties) | Browser compatibility --------------------- See also -------- * [<ident>](ident) * [<dashed-ident>](dashed-ident)
programming_docs
css counter-set counter-set =========== The `counter-set` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets a [CSS counter](css_counter_styles/using_css_counters) to a given value. It manipulates the value of existing counters, and will only create new counters if there isn't already a counter of the given name on the element. Try it ------ **Note:** The counter's value can be incremented or decremented using the [`counter-increment`](counter-increment) CSS property. Syntax ------ ``` /\* Set "my-counter" to 0 \*/ counter-set: my-counter; /\* Set "my-counter" to -1 \*/ counter-set: my-counter -1; /\* Set "counter1" to 1, and "counter2" to 4 \*/ counter-set: counter1 1 counter2 4; /\* Cancel any counter that could have been set in less specific rules \*/ counter-set: none; /\* Global values \*/ counter-set: inherit; counter-set: initial; counter-set: revert; counter-set: revert-layer; counter-set: unset; ``` The `counter-set` property is specified as either one of the following: * A `<custom-ident>` naming the counter, followed optionally by an `<integer>`. You may specify as many counters to reset as you want, with each name or name-number pair separated by a space. * The keyword value `none`. ### Values [`<custom-ident>`](custom-ident) The name of the counter to set. [`<integer>`](integer) The value to set the counter to on each occurrence of the element. Defaults to `0` if not specified. If there isn't currently a counter of the given name on the element, the element will create a new counter of the given name with a starting value of 0 (though it may then immediately set or increment that value to something different). `none` No counter set is to be performed. This can be used to override a `counter-set` defined in a less specific rule. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` counter-set = [[](value_definition_syntax#brackets) [<counter-name>](counter-name) [<integer>](integer)[?](value_definition_syntax#question_mark) []](value_definition_syntax#brackets)[+](value_definition_syntax#plus) [|](value_definition_syntax#single_bar) none ``` Examples -------- ### Setting named counters ``` h1 { counter-set: chapter section 1 page; /\* Sets the chapter and page counters to 0, and the section counter to 1 \*/ } ``` Specifications -------------- | Specification | | --- | | [CSS Lists and Counters Module Level 3 # propdef-counter-set](https://w3c.github.io/csswg-drafts/css-lists/#propdef-counter-set) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `counter-set` | 85 | 85 | 68 | No | 71 | No | 85 | 85 | 68 | 60 | No | 14.0 | See also -------- * [Using CSS Counters](css_counter_styles/using_css_counters) * [`counter-increment`](counter-increment) * [`counter-reset`](counter-reset) * [`@counter-style`](@counter-style) * [`counter()`](counter) and [`counters()`](counters) functions * [`content`](content) property css perspective-origin perspective-origin ================== The `perspective-origin` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property determines the position at which the viewer is looking. It is used as the *vanishing point* by the [`perspective`](perspective) property. Try it ------ The `perspective-origin` and [`perspective`](perspective) properties are attached to the parent of a child transformed in 3-dimensional space, unlike the [`perspective()`](transform-function/perspective) transform function which is placed on the element being transformed. Syntax ------ ``` /\* One-value syntax \*/ perspective-origin: x-position; /\* Two-value syntax \*/ perspective-origin: x-position y-position; /\* When both x-position and y-position are keywords, the following is also valid \*/ perspective-origin: y-position x-position; /\* Global values \*/ perspective-origin: inherit; perspective-origin: initial; perspective-origin: revert; perspective-origin: revert-layer; perspective-origin: unset; ``` ### Values *x-position* Indicates the position of the abscissa of the *vanishing point*. It can have one of the following values: * [`<length-percentage>`](length-percentage) indicating the position as an absolute length value or relative to the width of the element. The value may be negative. * `left`, a keyword being a shortcut for the `0` length value. * `center`, a keyword being a shortcut for the `50%` percentage value. * `right`, a keyword being a shortcut for the `100%` percentage value. *y-position* Indicates the position of the ordinate of the *vanishing point*. It can have one of the following values: * [`<length-percentage>`](length-percentage) indicating the position as an absolute length value or relative to the height of the element. The value may be negative. * `top`, a keyword being a shortcut for the `0` length value. * `center`, a keyword being a shortcut for the `50%` percentage value. * `bottom`, a keyword being a shortcut for the `100%` percentage value. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `50% 50%` | | Applies to | transformable elements | | [Inherited](inheritance) | no | | Percentages | refer to the size of bounding box | | [Computed value](computed_value) | for [`<length>`](length) the absolute value, otherwise a percentage | | Animation type | simple list of length, percentage, or calc | Formal syntax ------------- ``` perspective-origin = <position> <position> = [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) right []](value_definition_syntax#brackets) [||](value_definition_syntax#double_bar) [[](value_definition_syntax#brackets) top [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) bottom []](value_definition_syntax#brackets) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) <length-percentage> []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) top [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) bottom [|](value_definition_syntax#single_bar) <length-percentage> []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) right []](value_definition_syntax#brackets) <length-percentage> []](value_definition_syntax#brackets) [&&](value_definition_syntax#double_ampersand) [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) top [|](value_definition_syntax#single_bar) bottom []](value_definition_syntax#brackets) <length-percentage> []](value_definition_syntax#brackets) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Changing the perspective origin An example showing how to change `perspective-origin` is given in [Using CSS transforms > Changing the perspective origin](css_transforms/using_css_transforms#changing_the_perspective_origin). Specifications -------------- | Specification | | --- | | [CSS Transforms Module Level 2 # perspective-origin-property](https://w3c.github.io/csswg-drafts/css-transforms-2/#perspective-origin-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `perspective-origin` | 36 12 | 12 12 | 49 16 10 | 10 | 23 15 | 9 4 | 4.4 3 | 36 18 | 49 16 10 | 24 14 | 9 2 | 3.0 1.0 | See also -------- * [Using CSS Transforms](css_transforms/using_css_transforms) * [`transform-style`](transform-style) * [`<transform-function>`](transform-function) * [`perspective`](perspective) * [`transform: perspective()`](transform-function/perspective) function css touch-action touch-action ============ The `touch-action` CSS property sets how an element's region can be manipulated by a touchscreen user (for example, by zooming features built into the browser). ``` /\* Keyword values \*/ touch-action: auto; touch-action: none; touch-action: pan-x; touch-action: pan-left; touch-action: pan-right; touch-action: pan-y; touch-action: pan-up; touch-action: pan-down; touch-action: pinch-zoom; touch-action: manipulation; /\* Global values \*/ touch-action: inherit; touch-action: initial; touch-action: revert; touch-action: revert-layer; touch-action: unset; ``` By default, panning (scrolling) and pinching gestures are handled exclusively by the browser. An application using [Pointer events](https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events) will receive a [`pointercancel`](https://developer.mozilla.org/en-US/docs/Web/API/Element/pointercancel_event) event when the browser starts handling a touch gesture. By explicitly specifying which gestures should be handled by the browser, an application can supply its own behavior in [`pointermove`](https://developer.mozilla.org/en-US/docs/Web/API/Element/pointermove_event) and [`pointerup`](https://developer.mozilla.org/en-US/docs/Web/API/Element/pointerup_event) listeners for the remaining gestures. Applications using [Touch events](https://developer.mozilla.org/en-US/docs/Web/API/Touch_events) disable the browser handling of gestures by calling [`preventDefault()`](https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault), but should also use `touch-action` to ensure the browser knows the intent of the application before any event listeners have been invoked. When a gesture is started, the browser intersects the `touch-action` values of the touched element and its ancestors, up to the one that implements the gesture (in other words, the first containing scrolling element). This means that in practice, `touch-action` is typically applied only to top-level elements which have some custom behavior, without needing to specify `touch-action` explicitly on any of that element's descendants. **Note:** After a gesture starts, changes to `touch-action` will not have any impact on the behavior of the current gesture. Syntax ------ The `touch-action` property may be specified as either: * One of the keywords `auto`, `none`, [`manipulation`](#manipulation), *or* * One of the keywords `pan-x`, `pan-left`, `pan-right`, and/or one of the keywords `pan-y`, `pan-up`, `pan-down`, plus optionally the keyword `pinch-zoom`. ### Values `auto` Enable browser handling of all panning and zooming gestures. `none` Disable browser handling of all panning and zooming gestures. `pan-x` Enable single-finger horizontal panning gestures. May be combined with **pan-y**, **pan-up**, **pan-down** and/or **pinch-zoom**. `pan-y` Enable single-finger vertical panning gestures. May be combined with **pan-x**, **pan-left**, **pan-right** and/or **pinch-zoom**. `manipulation` Enable panning and pinch zoom gestures, but disable additional non-standard gestures such as double-tap to zoom. Disabling double-tap to zoom removes the need for browsers to delay the generation of **click** events when the user taps the screen. This is an alias for "**pan-x pan-y pinch-zoom**" (which, for compatibility, is itself still valid). `pan-left`, `pan-right`, `pan-up`, `pan-down` Experimental Enable single-finger gestures that begin by scrolling in the given direction(s). Once scrolling has started, the direction may still be reversed. Note that scrolling "up" (**pan-up**) means that the user is dragging their finger downward on the screen surface, and likewise **pan-left** means the user is dragging their finger to the right. Multiple directions may be combined except when there is a simpler representation (for example, **"pan-left pan-right**" is invalid since "**pan-x**" is simpler, but "**pan-left pan-down**" is valid). `pinch-zoom` Enable multi-finger panning and zooming of the page. This may be combined with any of the **pan-** values. Accessibility concerns ---------------------- A declaration of `touch-action: none;` may inhibit operating a browser's zooming capabilities. This will prevent people experiencing low vision conditions from being able to read and understand page content. * [MDN Understanding WCAG, Guideline 1.4 explanations](https://developer.mozilla.org/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 | Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-scale.html) Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | all elements except: non-replaced inline elements, table rows, row groups, table columns, and column groups | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` touch-action = auto [|](value_definition_syntax#single_bar) none [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) pan-x [|](value_definition_syntax#single_bar) pan-left [|](value_definition_syntax#single_bar) pan-right []](value_definition_syntax#brackets) [||](value_definition_syntax#double_bar) [[](value_definition_syntax#brackets) pan-y [|](value_definition_syntax#single_bar) pan-up [|](value_definition_syntax#single_bar) pan-down []](value_definition_syntax#brackets) [||](value_definition_syntax#double_bar) pinch-zoom []](value_definition_syntax#brackets) [|](value_definition_syntax#single_bar) manipulation ``` Examples -------- ### Disabling all gestures The most common usage is to disable all gestures on an element (and its non-scrollable descendants) that provides its own dragging and zooming behavior – such as a map or game surface. #### HTML ``` <div id="map"></div> ``` #### CSS ``` #map { height: 150vh; width: 70vw; background: linear-gradient(blue, green); touch-action: none; } ``` #### Result Specifications -------------- | Specification | | --- | | [Compatibility Standard # touch-action](https://compat.spec.whatwg.org/#touch-action) | | [Pointer Events # the-touch-action-css-property](https://w3c.github.io/pointerevents/#the-touch-action-css-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `touch-action` | 36 | 12 | 52 Not applicable to Firefox platforms that support neither pointer nor touch events. | 11 10 | 23 | 13 | 37 | 36 | 52 | 24 | 9.3 | 3.0 | | `axis-pan` | 36 | 12 | 52 Not applicable to Firefox platforms that support neither pointer nor touch events. | 11 10 | 23 | 13 | 37 | 36 | 52 | 24 | 13 | 3.0 | | `double-tap-zoom` | No | 12-79 | No | 11 10 | No | No | No | No | No | No | No | No | | `manipulation` | 36 | 12 | 52 Not applicable to Firefox platforms that support neither pointer nor touch events. | 11 10 | 23 | 13 | 37 | 36 | 52 | 24 | 9.3 | 3.0 | | `none` | 36 | 12 | 52 Not applicable to Firefox platforms that support neither pointer nor touch events. | 11 10 | 23 | 13 | 37 | 36 | 52 | 24 | 13 | 3.0 | | `pinch-zoom` | 56 | 12 | 85 Not applicable to Firefox platforms that support neither pointer nor touch events. | 11 10 | 43 | 13 | 56 | 56 | 85 Not applicable to Firefox platforms that support neither pointer nor touch events. | 43 | 13 | 6.0 | | `unidirectional-pan` | 55 | 79 | No See [bug 1285685](https://bugzil.la/1285685). | No | 42 | No | 55 | 55 | No See [bug 1285685](https://bugzil.la/1285685). | 42 | No | 6.0 | See also -------- * [`pointer-events`](pointer-events) * [`Pointer Events`](https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events) * WebKit Blog [More Responsive Tapping on iOS](https://webkit.org/blog/5610/more-responsive-tapping-on-ios/) * Google Developers Blog [Making touch scrolling fast by default](https://developer.chrome.com/blog/scrolling-intervention/) * [Scroll Snap](css_scroll_snap) css margin-block-end margin-block-end ================ The `margin-block-end` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the logical block end margin of an element, which maps to a physical margin depending on the element's writing mode, directionality, and text orientation. Try it ------ Syntax ------ ``` /\* <length> values \*/ margin-block-end: 10px; /\* An absolute length \*/ margin-block-end: 1em; /\* relative to the text size \*/ margin-block-end: 5%; /\* relative to the nearest block container's width \*/ /\* Keyword values \*/ margin-block-end: auto; /\* Global values \*/ margin-block-end: inherit; margin-block-end: initial; margin-block-end: revert; margin-block-end: revert-layer; margin-block-end: unset; ``` It corresponds to the [`margin-top`](margin-top), [`margin-right`](margin-right), [`margin-bottom`](margin-bottom), or [`margin-left`](margin-left) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). It relates to [`margin-block-start`](margin-block-start), [`margin-inline-start`](margin-inline-start), and [`margin-inline-end`](margin-inline-end), which define the other margins of the element. ### Values The `margin-block-end` property takes the same values as the [`margin-left`](margin-left) property. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | same as [`margin`](margin) | | [Inherited](inheritance) | no | | Percentages | depends on layout model | | [Computed value](computed_value) | if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, `auto` | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` margin-block-end = <'margin-top'> ``` Examples -------- ### Setting block end margin #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-rl; margin-block-end: 20px; background-color: #c8c800; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # margin-properties](https://w3c.github.io/csswg-drafts/css-logical/#margin-properties) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `margin-block-end` | 87 | 87 | 41 | No | 73 | 12.1 | 87 | 87 | 41 | 62 | 12.2 | 14.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * The mapped physical properties: [`margin-top`](margin-top), [`margin-right`](margin-right), [`margin-bottom`](margin-bottom), and [`margin-left`](margin-left) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation)
programming_docs
css line-height-step line-height-step ================ **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `line-height-step` CSS property sets the step unit for line box heights. When the property is set, line box heights are rounded up to the closest multiple of the unit. ``` /\* Point values \*/ line-height-step: 18pt; /\* Global values \*/ line-height-step: inherit; line-height-step: initial; line-height-step: revert; line-height-step: revert-layer; line-height-step: unset; ``` Syntax ------ The `line-height-step` property is specified as any one of the following: * a `<length>`. ### Values `<length>` The specified [`<length>`](length) is used in the calculation of the line box height step. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | block containers | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | absolute [`<length>`](length) | | Animation type | discrete | Formal syntax ------------- ``` line-height-step = [<length [0,∞]>](length) ``` Examples -------- ### Setting step unit for line box height In the following example, the height of line box in each paragraph is rounded up to the step unit. The line box in `<h1>` does not fit into one step unit and thus occupies two, but it is still centered within the two step unit. ``` :root { font-size: 12pt; --my-grid: 18pt; line-height-step: var(--my-grid); } h1 { font-size: 20pt; margin-top: calc(2 * var(--my-grid)); } ``` The result of these rules is shown below in the following screenshot: Specifications -------------- | Specification | | --- | | [CSS Rhythmic Sizing # line-height-step](https://w3c.github.io/csswg-drafts/css-rhythm/#line-height-step) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `line-height-step` | 60 | 79 | No | No | 47 | No | No | 60 | No | No | No | No | See also -------- * [`font`](font) * [`font-size`](font-size) * [`line-height`](line-height) css font-variant-emoji font-variant-emoji ================== The `font-variant-emoji` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property specifies the default presentation style for displaying emojis. Traditionally, this was done by appending a *Variation Selector*, `U+FE0E` for text and `U+FE0F` for emoji, to the emoji codepoint. Only emojis listed as contributing to a [Unicode emoji presentation sequence](https://www.unicode.org/emoji/charts/emoji-variants.html) are affected by this property. Syntax ------ ``` /\* Keyword values \*/ font-variant-emoji: normal; font-variant-emoji: text; font-variant-emoji: emoji; font-variant-emoji: unicode; /\* Global values \*/ font-variant-emoji: inherit; font-variant-emoji: initial; font-variant-emoji: revert; font-variant-emoji: revert-layer; font-variant-emoji: unset; ``` The `font-variant-emoji` property is specified using a single keyword value from the list below. ### Values `normal` Allows a browser to choose how to display the emoji. This often follows the operating system setting. `text` Renders the emoji as if it were using the unicode text variation selector (`U+FE0E`). `emoji` Renders the emoji as if it were using the unicode emoji variation selector (`U+FE0F`). `unicode` Renders the emoji in accordance with the [Emoji presentation properties](https://www.unicode.org/reports/tr51/tr51-23.html#Emoji_Presentation). If the `U+FE0E` or `U+FE0F` variation selector is present, then it will override this value setting. Formal definition ----------------- Value not found in DB!Formal syntax ------------- ``` font-variant-emoji = normal [|](value_definition_syntax#single_bar) text [|](value_definition_syntax#single_bar) emoji [|](value_definition_syntax#single_bar) unicode ``` Examples -------- ### Changing the way an emoji is displayed This example shows how you can render an emoji in its `text` or `emoji` presentation. #### HTML ``` <section class="emojis"> <div class="emoji"> <h2>text presentation</h2> <div class="text-presentation">☎</div> </div> <div class="emoji"> <h2>emoji presentation</h2> <div class="emoji-presentation">☎</div> </div> </section> ``` #### CSS ``` .text-presentation { font-variant-emoji: text; } .emoji-presentation { font-variant-emoji: emoji; } ``` #### Result Accessibility concerns ---------------------- While the use of emojis may seem fun, you should consider their impact on accessibility, specifically for users with visual and cognitive impairments. Consider the following factors while using emojis: * Display on screen-readers: Screen-readers will read out the alt text of an emoji. Keep this in mind to consider the position of an emoji in the content. Repeated and overuse of emojis will have a detrimental effect on screen-reader users. It is better to use emojis than emoticons; emoticons will be read out as punctuation characters. * Contrast with background: When using emojis, consider their colors and how that will work with the background color, especially if you have background colors that can change, such as light/dark modes. * Intent of use: Do not use emojis to replace words because your understanding of the emoji meaning may differ from that of the users'. Also consider that emojis might have different meanings in different cultures and geographies. Our recommendation is to preferably limit usage to commonly known emojis. Specifications -------------- | Specification | | --- | | [CSS Fonts Module Level 4 # font-variant-emoji-prop](https://w3c.github.io/csswg-drafts/css-fonts/#font-variant-emoji-prop) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `font-variant-emoji` | No | No | 108 | No | No | No | No | No | 108 | No | No | No | See also -------- * <font-variant> * <font-variant-alternates> * <font-variant-caps> * <font-variant-east-asian> * <font-variant-ligatures> * <font-variant-numeric> * [Emojis and accessibility: How to use them properly](https://uxdesign.cc/emojis-in-accessibility-how-to-use-them-properly-66b73986b803) css padding padding ======= The `padding` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [shorthand property](shorthand_properties) sets the [padding area](css_box_model/introduction_to_the_css_box_model#padding_area) on all four sides of an element at once. Try it ------ An element's padding area is the space between its content and its border. **Note:** Padding creates extra space within an element. In contrast, [`margin`](margin) creates extra space *around* an element. Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`padding-bottom`](padding-bottom) * [`padding-left`](padding-left) * [`padding-right`](padding-right) * [`padding-top`](padding-top) Syntax ------ ``` /\* 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 [`<length>`](length) or a [`<percentage>`](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 [`<length>`](length) The size of the padding as a fixed value. [`<percentage>`](percentage) The size of the padding as a percentage, relative to the inline size (*width* in a horizontal language, defined by [`writing-mode`](writing-mode)) of the [containing block](containing_block). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`padding-bottom`](padding-bottom): `0` * [`padding-left`](padding-left): `0` * [`padding-right`](padding-right): `0` * [`padding-top`](padding-top): `0` | | Applies to | all elements, except `table-row-group`, `table-header-group`, `table-footer-group`, `table-row`, `table-column-group` and `table-column`. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | Percentages | refer to the width of the containing block | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`padding-bottom`](padding-bottom): the percentage as specified or the absolute length * [`padding-left`](padding-left): the percentage as specified or the absolute length * [`padding-right`](padding-right): the percentage as specified or the absolute length * [`padding-top`](padding-top): the percentage as specified or the absolute length | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` padding = <'padding-top'>[{1,4}](value_definition_syntax#curly_braces) ``` Examples -------- ### Setting padding with pixels #### HTML ``` <h4>This element has moderate padding.</h4> <h3>The padding is huge in this element!</h3> ``` #### CSS ``` h4 { background-color: lime; padding: 20px 50px; } h3 { background-color: cyan; padding: 110px 50px 50px 110px; } ``` #### Result ### Setting padding with pixels and percentages ``` 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 -------------- | Specification | | --- | | [CSS Box Model Module Level 3 # padding-shorthand](https://w3c.github.io/csswg-drafts/css-box/#padding-shorthand) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `padding` | 1 | 12 | 1 | 4 | 3.5 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [Introduction to the CSS basic box model](css_box_model/introduction_to_the_css_box_model) * [`padding-top`](padding-top), [`padding-right`](padding-right), [`padding-bottom`](padding-bottom), and [`padding-left`](padding-left). * The mapped logical properties: [`padding-block-start`](padding-block-start), [`padding-block-end`](padding-block-end), [`padding-inline-start`](padding-inline-start), and [`padding-inline-end`](padding-inline-end) and the shorthands [`padding-block`](padding-block) and [`padding-inline`](padding-inline) css column-rule column-rule =========== The `column-rule` [shorthand](shorthand_properties) [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the width, style, and color of the line drawn between columns in a multi-column layout. Try it ------ It is a [shorthand property](shorthand_properties) that sets the individual `column-rule-*` properties in a single, convenient declaration: [`column-rule-width`](column-rule-width), [`column-rule-style`](column-rule-style), and [`column-rule-color`](column-rule-color). **Note:** As with all shorthand properties, any individual value that is not specified is set to its corresponding initial value (possibly overriding values previously set using non-shorthand properties). Syntax ------ ``` column-rule: dotted; column-rule: solid 8px; column-rule: solid blue; column-rule: thick inset blue; /\* Global values \*/ column-rule: inherit; column-rule: initial; column-rule: revert; column-rule: revert-layer; column-rule: unset; ``` The `column-rule` property is specified as one, two, or three of the values listed below, in any order. ### Values `<'column-rule-width'>` Is a [`<length>`](length) or one of the three keywords, `thin`, `medium`, or `thick`. See [`border-width`](border-width) for details. `<'column-rule-style'>` See [`border-style`](border-style) for possible values and details. `<'column-rule-color'>` Is a [`<color>`](color_value) value. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`column-rule-width`](column-rule-width): `medium` * [`column-rule-style`](column-rule-style): `none` * [`column-rule-color`](column-rule-color): `currentcolor` | | Applies to | multicol elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`column-rule-color`](column-rule-color): computed color * [`column-rule-style`](column-rule-style): as specified * [`column-rule-width`](column-rule-width): the absolute length; `0` if the [`column-rule-style`](column-rule-style) is `none` or `hidden` | | Animation type | as each of the properties of the shorthand:* [`column-rule-color`](column-rule-color): a [color](color_value#interpolation) * [`column-rule-style`](column-rule-style): discrete * [`column-rule-width`](column-rule-width): a [length](length#interpolation) | Formal syntax ------------- ``` column-rule = <'column-rule-width'> [||](value_definition_syntax#double_bar) <'column-rule-style'> [||](value_definition_syntax#double_bar) <'column-rule-color'> ``` Examples -------- ### Example 1 ``` /\* Same as "medium dotted currentcolor" \*/ p.foo { column-rule: dotted; } /\* Same as "medium solid blue" \*/ p.bar { column-rule: solid blue; } /\* Same as "8px solid currentcolor" \*/ p.baz { column-rule: solid 8px; } p.abc { column-rule: thick inset blue; } ``` ### Example 2 #### HTML ``` <p class="content-box"> This is a bunch of text split into three columns. Take note of how the `column-rule` property is used to adjust the style, width, and color of the rule that appears between the columns. </p> ``` #### CSS ``` .content-box { padding: 0.3em; background: #ff7; column-count: 3; column-rule: inset 2px #33f; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Multi-column Layout Module Level 1 # column-rule](https://w3c.github.io/csswg-drafts/css-multicol/#column-rule) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `column-rule` | 50 1 | 12 12 | 52 3.5-74 Before Firefox 3, the default value for the `normal` keyword was `0` and not `1em`. | 10 | 15 11.1 | 9 3 | 50 ≤37 | 50 18 | 52 4 | 14 11.1 | 9 1 | 5.0 1.0 | See also -------- * [Multiple-column Layout](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Multiple-column_Layout) * [`column-rule-style`](column-rule-style) * [`column-rule-width`](column-rule-width) * [`column-rule-color`](column-rule-color) css Pseudo-classes Pseudo-classes ============== A [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) ***pseudo-class*** is a keyword added to a selector that specifies a special state of the selected element(s). For example, the pseudo-class [`:hover`](:hover) can be used to select a button when a user's pointer hovers over the button and this selected button can then be styled. ``` /\* Any button over which the user's pointer is hovering \*/ button:hover { color: blue; } ``` A pseudo-class consists of a colon (`:`) followed by the pseudo-class name (e.g., `:hover`). A functional pseudo-class also contains a pair of parenthesis to define the arguments (e.g., `:dir()`). The element that a pseudo-class is attached to is defined as an *anchor element* (e.g., `button` in case `button:hover`). Pseudo-classes let you apply a style to an element not only in relation to the content of the document tree, but also in relation to external factors like the history of the navigator ([`:visited`](:visited), for example), the status of its content (like [`:checked`](:checked) on certain form elements), or the position of the mouse (like [`:hover`](:hover), which lets you know if the mouse is over an element or not). **Note:** In contrast to pseudo-classes, <pseudo-elements> can be used to style a *specific part* of an element. Element display state pseudo-classes ------------------------------------ These pseudo-classes enable the selection of elements based on their display states. [`:fullscreen`](:fullscreen) Matches an element that is currently in fullscreen mode. [`:modal`](:modal) Matches an element that is in a state in which it excludes all interaction with elements outside it until the interaction has been dismissed. [`:picture-in-picture`](:picture-in-picture) Matches an element that is currently in picture-in-picture mode. Input pseudo-classes -------------------- These pseudo-classes relate to form elements, and enable selecting elements based on HTML attributes and the state that the field is in before and after interaction. [`:autofill`](:autofill) Matches when an [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) has been autofilled by the browser. [`:enabled`](:enabled) Represents a user interface element that is in an enabled state. [`:disabled`](:disabled) Represents a user interface element that is in a disabled state. [`:read-only`](:read-only) Represents any element that cannot be changed by the user. [`:read-write`](:read-write) Represents any element that is user-editable. [`:placeholder-shown`](:placeholder-shown) Matches an input element that is displaying placeholder text. For example, it will match the `placeholder` attribute in the [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) and [`<textarea>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea) elements. [`:default`](:default) Matches one or more UI elements that are the default among a set of elements. [`:checked`](:checked) Matches when elements such as checkboxes and radio buttons are toggled on. [`:indeterminate`](:indeterminate) Matches UI elements when they are in an indeterminate state. [`:blank`](:blank) Matches a user-input element which is empty, containing an empty string or other null input. [`:valid`](:valid) Matches an element with valid contents. For example, an input element with the type 'email' that contains a validly formed email address or an empty value if the control is not required. [`:invalid`](:invalid) Matches an element with invalid contents. For example, an input element with type 'email' with a name entered. [`:in-range`](:in-range) Applies to elements with range limitations. For example, a slider control when the selected value is in the allowed range. [`:out-of-range`](:out-of-range) Applies to elements with range limitations. For example, a slider control when the selected value is outside the allowed range. [`:required`](:required) Matches when a form element is required. [`:optional`](:optional) Matches when a form element is optional. [`:user-invalid`](:user-invalid) Represents an element with incorrect input, but only when the user has interacted with it. Linguistic pseudo-classes ------------------------- These pseudo-classes reflect the document language and enable the selection of elements based on language or script direction. [`:dir()`](:dir) The directionality pseudo-class selects an element based on its directionality as determined by the document language. [`:lang()`](:lang) Select an element based on its content language. Location pseudo-classes ----------------------- These pseudo-classes relate to links, and to targeted elements within the current document. [`:any-link`](:any-link) Matches an element if the element would match either [`:link`](:link) or [`:visited`](:visited). [`:link`](:link) Matches links that have not yet been visited. [`:visited`](:visited) Matches links that have been visited. [`:local-link`](:local-link) Matches links whose absolute URL is the same as the target URL. For example, anchor links to the same page. [`:target`](:target) Matches the element which is the target of the document URL. [`:target-within`](:target-within) Matches elements which are the target of the document URL, but also elements which have a descendant which is the target of the document URL. [`:scope`](:scope) Represents elements that are a reference point for selectors to match against. Resource state pseudo-classes ----------------------------- These pseudo-classes apply to media that is capable of being in a state where it would be described as playing, such as a video. [`:playing`](:playing) Represents a media element that is capable of playing when that element is playing. [`:paused`](:paused) Represents a media element that is capable of playing when that element is paused. Time-dimensional pseudo-classes ------------------------------- These pseudo-classes apply when viewing something which has timing, such as a [WebVTT](https://developer.mozilla.org/en-US/docs/Web/API/WebVTT_API) caption track. [`:current`](:current) Represents the element or ancestor of the element that is being displayed. [`:past`](:past) Represents an element that occurs entirely before the [`:current`](:current) element. [`:future`](:future) Represents an element that occurs entirely after the [`:current`](:current) element. Tree-structural pseudo-classes ------------------------------ These pseudo-classes relate to the location of an element within the document tree. [`:root`](:root) Represents an element that is the root of the document. In HTML this is usually the `<html>` element. [`:empty`](:empty) Represents an element with no children other than white-space characters. [`:nth-child`](:nth-child) Uses `An+B` notation to select elements from a list of sibling elements. [`:nth-last-child`](:nth-last-child) Uses `An+B` notation to select elements from a list of sibling elements, counting backwards from the end of the list. [`:first-child`](:first-child) Matches an element that is the first of its siblings. [`:last-child`](:last-child) Matches an element that is the last of its siblings. [`:only-child`](:only-child) Matches an element that has no siblings. For example, a list item with no other list items in that list. [`:nth-of-type`](:nth-of-type) Uses `An+B` notation to select elements from a list of sibling elements that match a certain type from a list of sibling elements. [`:nth-last-of-type`](:nth-last-of-type) Uses `An+B` notation to select elements from a list of sibling elements that match a certain type from a list of sibling elements counting backwards from the end of the list. [`:first-of-type`](:first-of-type) Matches an element that is the first of its siblings, and also matches a certain type selector. [`:last-of-type`](:last-of-type) Matches an element that is the last of its siblings, and also matches a certain type selector. [`:only-of-type`](:only-of-type) Matches an element that has no siblings of the chosen type selector. User action pseudo-classes -------------------------- These pseudo-classes require some interaction by the user in order for them to apply, such as holding a mouse pointer over an element. [`:hover`](:hover) Matches when a user designates an item with a pointing device, such as holding the mouse pointer over the item. [`:active`](:active) Matches when an item is being activated by the user. For example, when the item is clicked on. [`:focus`](:focus) Matches when an element has focus. [`:focus-visible`](:focus-visible) Matches when an element has focus and the user agent identifies that the element should be visibly focused. [`:focus-within`](:focus-within) Matches an element to which [`:focus`](:focus) applies, plus any element that has a descendant to which [`:focus`](:focus) applies. Functional pseudo-classes ------------------------- These pseudo-classes accept a [selector list](selector_list#selector_list) or [forgiving selector list](selector_list#forgiving_selector_list) as a parameter. [`:is()`](:is) The matches-any pseudo-class matches any element that matches any of the selectors in the list provided. The list is forgiving. [`:not()`](:not) The negation, or matches-none, pseudo-class represents any element that is not represented by its argument. [`:where()`](:where) The specificity-adjustment pseudo-class matches any element that matches any of the selectors in the list provided without adding any specificity weight. The list is forgiving. [`:has()`](:has) The relational pseudo-class represents an element if any of the relative selectors match when anchored against the attached element. Syntax ------ ``` selector:pseudo-class { property: value; } ``` Like regular classes, you can chain together as many pseudo-classes as you want in a selector. Alphabetical index ------------------ Pseudo-classes defined by a set of CSS specifications include the following: A * [`:active`](:active) * [`:any-link`](:any-link) * [`:autofill`](:autofill) B * [`:blank`](:blank) Experimental C * [`:checked`](:checked) * [`:current`](:current) Experimental D * [`:default`](:default) * [`:defined`](:defined) * [`:dir()`](:dir) Experimental * [`:disabled`](:disabled) E * [`:empty`](:empty) * [`:enabled`](:enabled) F * [`:first`](:first) * [`:first-child`](:first-child) * [`:first-of-type`](:first-of-type) * [`:fullscreen`](:fullscreen) * [`:future`](:future) Experimental * [`:focus`](:focus) * [`:focus-visible`](:focus-visible) * [`:focus-within`](:focus-within) H * [`:has()`](:has) Experimental * [`:host`](:host) * [`:host()`](:host) * [`:host-context()`](:host-context) Experimental * [`:hover`](:hover) I * [`:indeterminate`](:indeterminate) * [`:in-range`](:in-range) * [`:invalid`](:invalid) * [`:is()`](:is) L * [`:lang()`](:lang) * [`:last-child`](:last-child) * [`:last-of-type`](:last-of-type) * [`:left`](:left) * [`:link`](:link) * [`:local-link`](:local-link) Experimental M * [`:modal`](:modal) N * [`:not()`](:not) * [`:nth-child()`](:nth-child) * [`:nth-col()`](:nth-col) Experimental * [`:nth-last-child()`](:nth-last-child) * [`:nth-last-col()`](:nth-last-col) Experimental * [`:nth-last-of-type()`](:nth-last-of-type) * [`:nth-of-type()`](:nth-of-type) O * [`:only-child`](:only-child) * [`:only-of-type`](:only-of-type) * [`:optional`](:optional) * [`:out-of-range`](:out-of-range) P * [`:past`](:past) Experimental * [`:picture-in-picture`](:picture-in-picture) * [`:placeholder-shown`](:placeholder-shown) * [`:paused`](:paused) * [`:playing`](:playing) R * [`:read-only`](:read-only) * [`:read-write`](:read-write) * [`:required`](:required) * [`:right`](:right) * [`:root`](:root) S * [`:scope`](:scope) * `:state()` Experimental T * [`:target`](:target) * [`:target-within`](:target-within) Experimental U * [`:user-invalid`](:user-invalid) Experimental V * [`:valid`](:valid) * [`:visited`](:visited) W * [`:where()`](:where) Specifications -------------- | Specification | | --- | | [HTML Standard # pseudo-classes](https://html.spec.whatwg.org/multipage/#pseudo-classes) | | [Selectors Level 4](https://drafts.csswg.org/selectors/) | | [CSS Basic User Interface Module Level 4](https://drafts.csswg.org/css-ui/) | See also -------- * [Pseudo-elements](pseudo-elements)
programming_docs
css fit-content() fit-content() ============= The `fit-content()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](css_functions) clamps a given size to an available size according to the formula `min(maximum size, max(minimum size, argument))`. Try it ------ The function can be used as a track size in [CSS Grid](css_grid_layout) properties, where the maximum size is defined by `max-content` and the minimum size by `auto`, which is calculated similar to `auto` (i.e., [`minmax(auto, max-content)`](minmax)), except that the track size is clamped at *argument* if it is greater than the `auto` minimum. See the [`grid-template-columns`](grid-template-columns) page for more information on the `max-content` and `auto` keywords. The `fit-content()` function can also be used as laid out box size for [`width`](width), [`height`](height), [`min-width`](min-width), [`min-height`](min-height), [`max-width`](max-width) and [`max-height`](max-height), where the maximum and minimum sizes refer to the content size. Syntax ------ The `fit-content()` function accepts a `<length>` or a `<percentage>` as an argument. ``` /\* <length> values \*/ fit-content(200px) fit-content(5cm) fit-content(30vw) fit-content(100ch) /\* <percentage> value \*/ fit-content(40%) ``` ### Values [`<length>`](length) An absolute length. [`<percentage>`](percentage) A percentage relative to the available space in the given axis. In grid properties it is relative to the inline size of the grid container in column tracks and to the block size of the grid container for row tracks. Otherwise it is relative to the available inline size or block size of the laid out box depending on the writing mode. Examples -------- ### Sizing grid columns with fit-content #### HTML ``` <div id="container"> <div>Item as wide as the content.</div> <div> Item with more text in it. Because the contents of it are wider than the maximum width, it is clamped at 300 pixels. </div> <div>Flexible item</div> </div> ``` #### CSS ``` #container { display: grid; grid-template-columns: fit-content(300px) fit-content(300px) 1fr; grid-gap: 5px; box-sizing: border-box; height: 200px; width: 100%; background-color: #8cffa0; padding: 10px; } #container > div { background-color: #8ca0ff; padding: 5px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Box Sizing Module Level 4 # sizing-values](https://w3c.github.io/csswg-drafts/css-sizing-4/#sizing-values) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `fit-content_function` | 57 | 16 | 52 | No | 44 | 10.1 | 57 | 57 | 52 | 43 | 10.3 | 6.0 | | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `fit-content_function` | No | No | 91 | No | No | No | No | No | No | No | No | No | ### css.properties.width.fit-content\_function BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. ### css.properties.grid-template-columns.fit-content BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. See also -------- * Related sizing keywords: [`min-content`](min-content), [`max-content`](max-content) * Related CSS Grid properties: [`grid-template`](grid-template), [`grid-template-rows`](grid-template-rows), [`grid-template-columns`](grid-template-columns), [`grid-template-areas`](grid-template-areas), [`grid-auto-columns`](grid-auto-columns), [`grid-auto-rows`](grid-auto-rows), [`grid-auto-flow`](grid-auto-flow) * Grid Layout Guide: *[Line-based placement with CSS Grid](css_grid_layout/line-based_placement_with_css_grid)* * Grid Layout Guide: *[Grid template areas - Grid definition shorthands](css_grid_layout/grid_template_areas#grid_definition_shorthands)* css background-position background-position =================== The `background-position` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the initial position for each background image. The position is relative to the position layer set by [`background-origin`](background-origin). Try it ------ Syntax ------ ``` /\* Keyword values \*/ background-position: top; background-position: bottom; background-position: left; background-position: right; background-position: center; /\* <percentage> values \*/ background-position: 25% 75%; /\* <length> values \*/ background-position: 0 0; background-position: 1cm 2cm; background-position: 10ch 8em; /\* Multiple images \*/ background-position: 0 0, center; /\* Edge offsets values \*/ background-position: bottom 10px right 20px; background-position: right 3em bottom 10px; background-position: bottom 10px right; background-position: top right 10px; /\* Global values \*/ background-position: inherit; background-position: initial; background-position: revert; background-position: revert-layer; background-position: unset; ``` The `background-position` property is specified as one or more `<position>` values, separated by commas. ### Values `<position>` A [`<position>`](position_value). A position defines an x/y coordinate, to place an item relative to the edges of an element's box. It can be defined using one to four values. If two non-keyword values are used, the first value represents the horizontal position and the second represents the vertical position. If only one value is specified, the second value is assumed to be `center`. If three or four values are used, the length-percentage values are offsets for the preceding keyword value(s). **1-value syntax:** the value may be: * The keyword value `center`, which centers the image. * One of the keyword values `top`, `left`, `bottom`, `right`. This specifies an edge against which to place the item. The other dimension is then set to 50%, so the item is placed in the middle of the edge specified. * A [`<length>`](length) or [`<percentage>`](percentage). This specifies the X coordinate relative to the left edge, with the Y coordinate set to 50%. **2-value syntax:** one value defines X and the other defines Y. Each value may be: * One of the keyword values `top`, `left`, `bottom`, `right`. If `left` or `right` are given here, then this defines X and the other given value defines Y. If `top` or `bottom` are given, then this defines Y and the other value defines X. * A [`<length>`](length) or [`<percentage>`](percentage). If the other value is `left` or `right`, then this value defines Y, relative to the top edge. If the other value is `top` or `bottom`, then this value defines X, relative to the left edge. If both values are `<length>` or `<percentage>` values, then the first defines X and the second Y. * Note that: If one value is `top` or `bottom`, then the other value may not be `top` or `bottom`. If one value is `left` or `right`, then the other value may not be `left` or `right`. This means, e.g., that `top top` and `left right` are not valid. * Order: when pairing keywords, placement is not important as the browser can reorder it, the value `top left` or `left top` will yield the same result. With pairing [`<length>`](length) or [`<percentage>`](percentage) with a keyword the placement is important, the value defining X should come first followed by Y, the value `right 20px` is not the same as `20px right` the former is valid but the latter is invalid. The value `left 20%` or `20% bottom` is valid as X and Y values are clearly defined and the placement is right. * The default value is `left top` or `0% 0%`. **3-value syntax:** Two values are keyword values, and the third is the offset for the preceding value: * The first value is one of the keyword values `top`, `left`, `bottom`, `right`, or `center`. If `left` or `right` are given here, then this defines X. If `top` or `bottom` are given, then this defines Y and the other keyword value defines X. * The [`<length>`](length) or [`<percentage>`](percentage) value, if it is the second value, is the offset for the first value. If it is the third value, it is the offset for the second value. * The single length or percentage value is an offset for the keyword value that precedes it. The combination of one keyword with two [`<length>`](length) or [`<percentage>`](percentage) values is not valid. **4-value syntax:** The first and third values are keyword value defining X and Y. The second and fourth values are offsets for the preceding X and Y keyword values: * The first value and third values one of the keyword values `top`, `left`, `bottom`, `right`. If `left` or `right` are given here, then this defines X. If `top` or `bottom` are given, then this defines Y and the other keyword value defines X. * The second and fourth values are [`<length>`](length) or [`<percentage>`](percentage) values. The second value is the offset for the first keyword. The fourth value is the offset for the second keyword. ### Regarding Percentages The percentage offset of the given background image's position is relative to the container. A value of 0% means that the left (or top) edge of the background image is aligned with the corresponding left (or top) edge of the container, or the 0% mark of the image will be on the 0% mark of the container. A value of 100% means that the *right* (or *bottom*) edge of the background image is aligned with the *right* (or *bottom*) edge of the container, or the 100% mark of the image will be on the 100% mark of the container. Thus a value of 50% horizontally or vertically centers the background image as the 50% of the image will be at the 50% mark of the container. Similarly, `background-position: 25% 75%` means the spot on the image that is 25% from the left and 75% from the top will be placed at the spot of the container that is 25% from the container's left and 75% from the container's top. Essentially what happens is the background image dimension is *subtracted* from the corresponding container dimension, and then a percentage of the resulting value is used as the direct offset from the left (or top) edge. ``` (container width - image width) * (position x%) = (x offset value) (container height - image height) * (position y%) = (y offset value) ``` Using the X axis for an example, let's say we have an image that is 300px wide and we are using it in a container that is 100px wide, with background-size set to auto: ``` 100px - 300px = -200px (container & image difference) ``` So that with position percentages of -25%, 0%, 50%, 100%, 125%, we get these image-to-container edge offset values: ``` -200px * -25% = 50px -200px * 0% = 0px -200px * 50% = -100px -200px * 100% = -200px -200px * 125% = -250px ``` So with these resultant values for our example, the **left edge** of the **image** is offset from the **left edge** of the **container** by: * + 50px (putting the left image edge in the center of the 100-pixel-wide container) * 0px (left image edge coincident with the left container edge) * -100px (left image edge 100px to the left of the container, in this example that means the middle 100px image area is centered in the container) * -200px (left image edge 200px to the left of the container, in this example that means the right image edge is coincident with the right container edge) * -250px (left image edge 250px to the left of the container, in this example that puts the right edge of the 300px-wide image in the center of the container) It's worth mentioning that if your background-size is equal to the container size for a given axis, then a *percentage* position for that axis will have no effect because the "container-image difference" will be zero. You will need to offset using absolute values. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0% 0%` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | Percentages | refer to the size of the background positioning area minus size of background image; size refers to the width for horizontal offsets and to the height for vertical offsets | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`background-position-x`](background-position-x): A list, each item consisting of: an offset given as a combination of an absolute length and a percentage, plus an origin keyword * [`background-position-y`](background-position-y): A list, each item consisting of: an offset given as a combination of an absolute length and a percentage, plus an origin keyword | | Animation type | repeatable list of simple list of length, percentage, or calc | Formal syntax ------------- ``` background-position = <bg-position>[#](value_definition_syntax#hash_mark) <bg-position> = [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) top [|](value_definition_syntax#single_bar) bottom [|](value_definition_syntax#single_bar) <length-percentage> []](value_definition_syntax#brackets) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) <length-percentage> []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) top [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) bottom [|](value_definition_syntax#single_bar) <length-percentage> []](value_definition_syntax#brackets) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) center [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) right []](value_definition_syntax#brackets) <length-percentage>[?](value_definition_syntax#question_mark) []](value_definition_syntax#brackets) [&&](value_definition_syntax#double_ampersand) [[](value_definition_syntax#brackets) center [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) top [|](value_definition_syntax#single_bar) bottom []](value_definition_syntax#brackets) <length-percentage>[?](value_definition_syntax#question_mark) []](value_definition_syntax#brackets) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Positioning background images Each of these three examples uses the [`background`](background) property to create a yellow, rectangular element containing a star image. In each example, the star is in a different position. The third example illustrates how to specify positions for two different background images within one element. #### HTML ``` <div class="exampleone">Example One</div> <div class="exampletwo">Example Two</div> <div class="examplethree">Example Three</div> ``` #### CSS ``` /\* Shared among all <div>s \*/ div { background-color: #ffee99; background-repeat: no-repeat; width: 300px; height: 80px; margin-bottom: 12px; } /\* These examples use the `background` shorthand property \*/ .exampleone { background: url("startransparent.gif") #ffee99 2.5cm bottom no-repeat; } .exampletwo { background: url("startransparent.gif") #ffee99 left 4em bottom 1em no-repeat; } /\* Multiple background images: Each image is matched with the corresponding position, from first specified to last. \*/ .examplethree { background-image: url("startransparent.gif"), url("catfront.png"); background-position: 0px 0px, right 3em bottom 2em; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # background-position](https://w3c.github.io/csswg-drafts/css-backgrounds/#background-position) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `4_value_syntax` | 25 | 12 | 13 | 9 | 10.5 | 7 | 4.4 | 25 | 14 | 14 | 7 | 1.5 | | `background-position` | 1 | 12 | 1 | 4 | 3.5 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | | `multiple_backgrounds` | 1 | 12 | 3.6 | 9 | 10.5 | 1.3 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [`background-position-x`](background-position-x) * [`background-position-y`](background-position-y) * [Using multiple backgrounds](css_backgrounds_and_borders/using_multiple_backgrounds) * [`transform-origin`](transform-origin) css resize resize ====== The `resize` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets whether an element is resizable, and if so, in which directions. Try it ------ `resize` does not apply to the following: * Inline elements * Block elements for which the [`overflow`](overflow) property is set to `visible` Syntax ------ ``` /\* Keyword values \*/ resize: none; resize: both; resize: horizontal; resize: vertical; resize: block; resize: inline; /\* Global values \*/ resize: inherit; resize: initial; resize: revert; resize: revert-layer; resize: unset; ``` The `resize` property is specified as a single keyword value from the list below. ### Values `none` The element offers no user-controllable method for resizing it. `both` The element displays a mechanism for allowing the user to resize it, which may be resized both horizontally and vertically. `horizontal` The element displays a mechanism for allowing the user to resize it in the *horizontal* direction. `vertical` The element displays a mechanism for allowing the user to resize it in the *vertical* direction. `block` Experimental The element displays a mechanism for allowing the user to resize it in the *block* direction (either horizontally or vertically, depending on the [`writing-mode`](writing-mode) and [`direction`](direction) value). `inline` Experimental The element displays a mechanism for allowing the user to resize it in the *inline* direction (either horizontally or vertically, depending on the [`writing-mode`](writing-mode) and [`direction`](direction) value). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | elements with [`overflow`](overflow) other than `visible`, and optionally replaced elements representing images or videos, and iframes | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` resize = none [|](value_definition_syntax#single_bar) both [|](value_definition_syntax#single_bar) horizontal [|](value_definition_syntax#single_bar) vertical [|](value_definition_syntax#single_bar) block [|](value_definition_syntax#single_bar) inline ``` Examples -------- ### Disabling resizability of textareas In many browsers, [`<textarea>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea) elements are resizable by default. You may override this behavior with the `resize` property. #### HTML ``` <textarea>Type some text here.</textarea> ``` #### CSS ``` textarea { resize: none; /\* Disables resizability \*/ } ``` #### Result ### Using resize with arbitrary elements You can use the `resize` property to make any element resizable. In the example below, a resizable [`<div>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div) contains a resizable paragraph ([`<p>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p) element). #### HTML ``` <div class="resizable"> <p class="resizable"> This paragraph is resizable in all directions, because the CSS `resize` property is set to `both` on this element. </p> </div> ``` #### CSS ``` .resizable { resize: both; overflow: scroll; border: 1px solid black; } div { height: 300px; width: 300px; } p { height: 200px; width: 200px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Basic User Interface Module Level 4 # resize](https://w3c.github.io/csswg-drafts/css-ui/#resize) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `resize` | 1 | 79 | 4 | No | 12.1 | 3 | 37 | 18 | 4 | 14 | 1 | 1.0 | | `block_level_support` | 4 | 79 | 5 `resize` doesn't have any effect on [`<iframe>`](https://developer.mozilla.org/docs/Web/HTML/Element/iframe). See [bug 680823](https://bugzil.la/680823)) | No | 15 | 4 | 37 | 18 | 5 `resize` doesn't have any effect on [`<iframe>`](https://developer.mozilla.org/docs/Web/HTML/Element/iframe). See [bug 680823](https://bugzil.la/680823)) | 14 | 3.2 | 1.0 | | `flow_relative_support` | 70 | 79 | 63 | No | 57 | 16 | No | 70 | 63 | No | 16 | No | See also -------- * [`<textarea>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea)
programming_docs
css :has() :has() ====== The functional `:has()` CSS [pseudo-class](pseudo-classes) represents an element if any of the [relative selectors](css_selectors#relative_selector) that are passed as an argument match at least one element when anchored against this element. This pseudo-class presents a way of selecting a parent element or a previous sibling element with respect to a reference element by taking a [relative selector list](selector_list#relative_selector_list) as an argument. ``` /\* Selects an h1 heading with a paragraph element that immediately follows the h1 and applies the style to h1 \*/ h1:has(+ p) { margin-bottom: 0; } ``` The `:has()` pseudo-class takes on the <specificity> of the most specific selector in its arguments the same way as [`:is()`](:is) and [`:not()`](:not) do. Syntax ------ ``` :has( <relative-selector-list> ) ``` If the `:has()` pseudo-class itself is not supported in a browser, the entire selector block will fail unless `:has()` is in a forgiving selector list, such as in [`:is()`](:is) and [`:where()`](:where)). The `:has()` pseudo-class cannot be nested within another `:has()`. This is because many pseudo-elements exist conditionally based on the styling of their ancestors and allowing these to be queried by `:has()` can introduce cyclic querying. Pseudo-elements are also not valid selectors within `:has()` and pseudo-elements are not valid anchors for `:has()`. Examples -------- ### With the sibling combinator The `:has()` style declaration in the following example adjusts the spacing after `<h1>` headings if they are immediately followed by an `<h2>` heading. #### HTML ``` <section> <article> <h1>Morning Times</h1> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> </article> <article> <h1>Morning Times</h1> <h2>Delivering you news every morning</h2> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> </article> </section> ``` #### CSS ``` h1, h2 { margin: 0 0 1.0rem 0; } h1:has(+ h2) { margin: 0 0 0.25rem 0; } ``` #### Result This example shows two similar texts side-by-side for comparison – the left one with an `H1` heading followed by a paragraph and the right one with an `H1` heading followed by an `H2` heading and then a paragraph. In the example on the right, `:has()` helps to select the `H1` element that is immediately followed by an `H2` element (indicated by the adjacent sibling combinator[`+`](adjacent_sibling_combinator)) and the CSS rule reduces the spacing after such an `H1` element. Without the `:has()` pseudo-class, you cannot use CSS selectors to select a preceding sibling of a different type or a parent element. ### With the :is() pseudo-class This example builds on the previous example to show how to select multiple elements with `:has()`. #### HTML ``` <section> <article> <h1>Morning Times</h1> <h2>Delivering you news every morning</h2> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> </article> <article> <h1>Morning Times</h1> <h2>Delivering you news every morning</h2> <h3>8:00 am</h3> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> </article> </section> ``` #### CSS ``` h1, h2, h3 { margin: 0 0 1.0rem 0; } :is(h1, h2, h3):has(+ :is(h2, h3, h4)) { margin: 0 0 0.25rem 0; } ``` #### Result Here, the first [`:is()`](:is) pseudo-class is used to select any of the heading elements in the list. The second `:is()` pseudo-class is used to pass a list of adjacent sibling selectors as an argument to `:has()`. The `:has()` pseudo-class helps to select any `H1`, `H2`, or `H3` element that is immediately followed by (indicated by [`+`](adjacent_sibling_combinator)) an `H2`, `H3`, or `H4` element and the CSS rule reduces the spacing after such `H1`, `H2`, or `H3` elements. This selector could have also been written as: ``` :is(h1, h2, h3):has(+ h2, + h3, + h4) { margin: 0 0 0.25rem 0; } ``` ### Logical operations The `:has()` relational selector can be used to check if one of the multiple features is true or if all the features are true. By using comma-separated values inside the `:has()` relational selector, you are checking to see if any of the parameters exist. `x:has(a, b)` will style `x` if descendant `a` OR `b` exists. By chaining together multiple `:has()` relational selectors together, you are checking to see if all of the parameters exist. `x:has(a):has(b)` will style `x` if descendant `a` AND `b` exist. ``` body:has(video, audio) { /\* styles to apply if the content contains audio OR video \*/ } body:has(video):has(audio) { /\* styles to apply if the content contains both audio AND video \*/ } ``` Specifications -------------- | Specification | | --- | | [Selectors Level 4 # relational](https://w3c.github.io/csswg-drafts/selectors/#relational) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:has` | 105 | 105 | 103 | No | 91 | 15.4 | 105 | 105 | No | 72 | 15.4 | No | See also -------- * [`:is()`](:is), [`:where()`](:where), [`:not()`](:not) * [CSS selectors](css_selectors) * [CSS combinators](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Combinators) * [Selector list](selector_list) * [Locating DOM elements using selectors](https://developer.mozilla.org/en-US/docs/Web/API/Document_object_model/Locating_DOM_elements_using_selectors) css rotate rotate ====== The `rotate` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property allows you to specify rotation transforms individually and independently of the [`transform`](transform) property. This maps better to typical user interface usage, and saves having to remember the exact order of transform functions to specify in the `transform` property. Try it ------ Syntax ------ ``` /\* Keyword values \*/ rotate: none; /\* Angle value \*/ rotate: 90deg; rotate: 0.25turn; rotate: 1.57rad; /\* x, y, or z axis name plus angle \*/ rotate: x 90deg; rotate: y 0.25turn; rotate: z 1.57rad; /\* Vector plus angle value \*/ rotate: 1 1 1 90deg; /\* Global values \*/ rotate: inherit; rotate: initial; rotate: revert; rotate: revert-layer; rotate: unset; ``` ### Values angle value An [`<angle>`](angle) specifying the angle to rotate the affected element through, around the Z axis. Equivalent to a `rotate()` (2D rotation) function. x, y, or z axis name plus angle value The name of the axis you want to rotate the affected element around (`"x"`, "`y`", or "`z"`), plus an [`<angle>`](angle) specifying the angle to rotate the element through. Equivalent to a `rotateX()`/`rotateY()`/`rotateZ()` (3D rotation) function. vector plus angle value Three [`<number>`](number)s representing an origin-centered vector that defines a line around which you want to rotate the element, plus an [`<angle>`](angle) specifying the angle to rotate the element through. Equivalent to a `rotate3d()` (3D rotation) function. `none` Specifies that no rotation should be applied. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | transformable elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | a transform | | Creates [stacking context](css_positioning/understanding_z_index/the_stacking_context) | yes | Formal syntax ------------- ``` rotate = none [|](value_definition_syntax#single_bar) [<angle>](angle) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) x [|](value_definition_syntax#single_bar) y [|](value_definition_syntax#single_bar) z [|](value_definition_syntax#single_bar) [<number>](number)[{3}](value_definition_syntax#curly_braces) []](value_definition_syntax#brackets) [&&](value_definition_syntax#double_ampersand) [<angle>](angle) ``` Examples -------- ### Rotating an element on hover The following example shows how to use the `rotate` property to rotate an element along various axes on hover. The first box rotates 90 degrees on the Z axis hover, the second rotates 180 degrees on the Y axis on hover, and the third rotates 360 degrees on hover around a vector defined by coordinates. #### HTML ``` <div class="box" id="box1">rotate Z</div> <div class="box" id="box2">rotate Y</div> <div class="box" id="box3">vector & angle</div> ``` #### CSS ``` .box { display: inline-block; margin: 1em; min-width: 6.5em; line-height: 6.5em; text-align: center; transition: 1s ease-in-out; border: 0.25em dotted; } #box1:hover { rotate: 90deg; } #box2:hover { rotate: y 180deg; } #box3:hover { rotate: 1 2 1 360deg; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Transforms Module Level 2 # individual-transforms](https://w3c.github.io/csswg-drafts/css-transforms-2/#individual-transforms) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `rotate` | 104 | 104 | 72 | No | 90 | 14.1 | 104 | 104 | 79 | 71 | 14.5 | No | | `x_y_z_angle` | 104 | 104 | 72 | No | 90 | preview | 104 | 104 | 79 | 71 | No | No | See also -------- * [`translate`](translate) * [`scale`](scale) * [`transform`](transform) Note: `skew` is not an independent `transform` value css scroll-padding-bottom scroll-padding-bottom ===================== The `scroll-padding-bottom` property defines offsets for the bottom 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. Try it ------ Syntax ------ ``` /\* Keyword values \*/ scroll-padding-bottom: auto; /\* <length> values \*/ scroll-padding-bottom: 10px; scroll-padding-bottom: 1em; scroll-padding-bottom: 10%; /\* Global values \*/ scroll-padding-bottom: inherit; scroll-padding-bottom: initial; scroll-padding-bottom: revert; scroll-padding-bottom: revert-layer; scroll-padding-bottom: unset; ``` ### Values `<length-percentage>` An inwards offset from the bottom 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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | scroll containers | | [Inherited](inheritance) | no | | Percentages | relative to the scroll container's scrollport | | [Computed value](computed_value) | as specified | | Animation type | by computed value type | Formal syntax ------------- ``` scroll-padding-bottom = auto [|](value_definition_syntax#single_bar) [<length-percentage [0,∞]>](length-percentage) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Specifications -------------- | Specification | | --- | | [CSS Scroll Snap Module Level 1 # padding-longhands-physical](https://w3c.github.io/csswg-drafts/css-scroll-snap/#padding-longhands-physical) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scroll-padding-bottom` | 69 | 79 | 68 | No | 56 | 14.1 11-14.1 Scroll padding is not applied for scrolls to fragment target or `scrollIntoView()`, see [bug 179379](https://webkit.org/b/179379). | 69 | 69 | 68 | 48 | 14.5 11-14.5 Scroll padding is not applied for scrolls to fragment target or `scrollIntoView()`, see [bug 179379](https://webkit.org/b/179379). | 10.0 | See also -------- * [CSS Scroll Snap](css_scroll_snap) * [Well-Controlled Scrolling with CSS Scroll Snap](https://web.dev/css-scroll-snap/) css :host() :host() ======= The `:host()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) function selects the shadow host of the [shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM) containing the CSS it is used inside (so you can select a custom element from inside its shadow DOM) — but only if the selector given as the function's parameter matches the shadow host. The most obvious use of this is to put a class name only on certain custom element instances, and then include the relevant class selector as the function argument. You can't use this with a descendant selector expression to select only instances of the custom element that are inside a particular ancestor. That's the job of [`:host-context()`](:host-context). **Note:** This has no effect when used outside a shadow DOM. ``` /\* Selects a shadow root host, only if it is matched by the selector argument \*/ :host(.special-custom-element) { font-weight: bold; } ``` Syntax ------ ``` :host( <compound-selector> ) ``` Examples -------- ### Selectively styling shadow hosts The following snippets are taken from our [host-selectors example](https://github.com/mdn/web-components-examples/tree/main/host-selectors) ([see it live also](https://mdn.github.io/web-components-examples/host-selectors/)). In this example we have a simple custom element — `<context-span>` — that you can wrap around text: ``` <h1> Host selectors <a href="#"><context-span>example</context-span></a> </h1> ``` Inside the element's constructor, we create `style` and `span` elements, fill the `span` with the content of the custom element, and fill the `style` element with some CSS rules: ``` const style = document.createElement("style"); const span = document.createElement("span"); span.textContent = this.textContent; const shadowRoot = this.attachShadow({ mode: "open" }); shadowRoot.appendChild(style); shadowRoot.appendChild(span); style.textContent = "span:hover { text-decoration: underline; }" + ":host-context(h1) { font-style: italic; }" + ':host-context(h1):after { content: " - no links in headers!" }' + ":host-context(article, aside) { color: gray; }" + ":host(.footer) { color : red; }" + ":host { background: rgba(0,0,0,0.1); padding: 2px 5px; }"; ``` The `:host(.footer) { color : red; }` rule styles all instances of the `<context-span>` element (the shadow host in this instance) in the document that have the `footer` class set on them — we've used it to give instances of the element inside the [`<footer>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/footer) a special color. Specifications -------------- | Specification | | --- | | [CSS Scoping Module Level 1 # host-selector](https://w3c.github.io/csswg-drafts/css-scoping/#host-selector) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:host_function` | 54 | 79 | 63 | No | 41 | 10 Certain CSS selectors do not work (:host > .local-child) and styling slotted content (::slotted) is buggy. | 54 | 54 | 63 | 41 | 10 Certain CSS selectors do not work (:host > .local-child) and styling slotted content (::slotted) is buggy. | 6.0 | See also -------- * [Web components](https://developer.mozilla.org/en-US/docs/Web/Web_Components) * [`:host`](:host) * [`:host-context()`](:host-context) css quotes quotes ====== The `quotes` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets how the browser should render quotation marks that are added using the `open-quotes` or `close-quotes` values of the CSS [`content`](content) property. Try it ------ Syntax ------ ``` /\* Keyword value \*/ quotes: none; quotes: auto; /\* <string> values \*/ quotes: "«" "»"; /\* Set open-quote and close-quote to the French quotation marks \*/ quotes: "«" "»" "‹" "›"; /\* Set two levels of quotation marks \*/ /\* Global values \*/ quotes: inherit; quotes: initial; quotes: revert; quotes: revert-layer; quotes: unset; ``` ### Values `none` The `open-quote` and `close-quote` values of the [`content`](content) property produce no quotation marks. `auto` Appropriate quote marks will be used for whatever language value is set on the selected elements (i.e. via the [`lang`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#lang) attribute). `[<string> <string>]+` One or more pairs of [`<string>`](string) values for `open-quote` and `close-quote`. The first pair represents the outer level of quotation, the second pair is for the first nested level, next pair for third level and so on. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | depends on user agent | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` quotes = auto [|](value_definition_syntax#single_bar) none [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) [<string>](string) [<string>](string) []](value_definition_syntax#brackets)[+](value_definition_syntax#plus) ``` Examples -------- ### Basic quote marks #### HTML ``` <q>To be or not to be. That's the question!</q> ``` #### CSS ``` q { quotes: '"' '"' "'" "'"; } q::before { content: open-quote; } q::after { content: close-quote; } ``` #### Result ### Auto quotes For most browsers, the default value of `quotes` is `auto` (Firefox 70+), or the browser otherwise had this default behavior (Chromiums, Safari, Edge), so this example works without it being explicitly being set. #### HTML ``` <div lang="fr"> <q>Ceci est une citation française.</q> <div> <hr /> <div lang="ru"> <q>Это русская цитата</q> <div> <hr /> <div lang="de"> <q>Dies ist ein deutsches Zitat</q> <div> <hr /> <div lang="en"> <q>This is an English quote.</q> <div></div> </div> </div> </div> </div> </div> </div> </div> ``` #### CSS ``` /\*q { quotes: auto; }\*/ ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Generated Content Module Level 3 # quotes](https://w3c.github.io/csswg-drafts/css-content/#quotes) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `quotes` | 11 | 12 | 1.5 | 8 | 4 | 9 | 37 | 18 | 4 | 14 | 9 | 1.0 | | `quotes_auto` | 87 | 87 | 70 | No This value is not supported, but the default browser behavior is to choose appropriate quotes for the user's language setting | 73 | preview This value is not supported, but the default browser behavior is to choose appropriate quotes for the user's language setting | 87 | 87 | No | No This value is not supported, but the default browser behavior is to choose appropriate quotes for the user's language setting | No This value is not supported, but the default browser behavior is to choose appropriate quotes for the user's language setting | 14.0 | See also -------- * [`contain`](contain) * [`content`](content)
programming_docs
css margin margin ====== The `margin` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) shorthand property sets the [margin area](css_box_model/introduction_to_the_css_box_model#margin_area) on all four sides of an element. Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`margin-top`](margin-top) * [`margin-right`](margin-right) * [`margin-bottom`](margin-bottom) * [`margin-left`](margin-left) Syntax ------ ``` /\* Apply to all four sides \*/ margin: 1em; margin: -3px; /\* top and bottom | left and right \*/ margin: 5% auto; /\* top | left and right | bottom \*/ margin: 1em auto 2em; /\* top | right | bottom | left \*/ margin: 2px 1em 0 auto; /\* Global values \*/ margin: inherit; margin: initial; margin: revert; margin: revert-layer; margin: unset; ``` The `margin` property may be specified using one, two, three, or four values. Each value is a [`<length>`](length), a [`<percentage>`](percentage), or the keyword `auto`. Negative values draw the element closer to its neighbors than it would be by default. * When **one** value is specified, it applies the same margin to **all four sides**. * When **two** values are specified, the first margin applies to the **top and bottom**, the second to the **left and right**. * When **three** values are specified, the first margin applies to the **top**, the second to the **right and left**, the third to the **bottom**. * When **four** values are specified, the margins apply to the **top**, **right**, **bottom**, and **left** in that order (clockwise). ### Values [`<length>`](length) The size of the margin as a fixed value. [`<percentage>`](percentage) The size of the margin as a percentage, relative to the inline size (*width* in a horizontal language, defined by [`writing-mode`](writing-mode)) of the [containing block](containing_block). `auto` The browser selects a suitable margin to use. For example, in certain cases this value can be used to center an element. Description ----------- This property can be used to set a margin on all four sides of an element. Margins create extra space *around* an element, unlike [`padding`](padding), which creates extra space *within* an element. The top and bottom margins have no effect on *non-[replaced](replaced_element)* inline elements, such as [`<span>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span) or [`<code>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/code). ### Horizontal centering To center something horizontally in modern browsers, you can use [`display`](display)`: flex;` [`justify-content`](justify-content)`: center;`. However, in older browsers like IE8-9 that do not support Flexible Box Layout, these are not available. In order to center an element inside its parent, use `margin: 0 auto;`. ### Margin collapsing Elements' top and bottom margins are sometimes collapsed into a single margin that is equal to the larger of the two margins. See [Mastering margin collapsing](css_box_model/mastering_margin_collapsing) for more information. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`margin-bottom`](margin-bottom): `0` * [`margin-left`](margin-left): `0` * [`margin-right`](margin-right): `0` * [`margin-top`](margin-top): `0` | | Applies to | all elements, except elements with table [`display`](display) types other than `table-caption`, `table` and `inline-table`. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | Percentages | refer to the width of the containing block | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`margin-bottom`](margin-bottom): the percentage as specified or the absolute length * [`margin-left`](margin-left): the percentage as specified or the absolute length * [`margin-right`](margin-right): the percentage as specified or the absolute length * [`margin-top`](margin-top): the percentage as specified or the absolute length | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` margin = <'margin-top'>[{1,4}](value_definition_syntax#curly_braces) ``` Examples -------- ### Simple example #### HTML ``` <div class="center">This element is centered.</div> <div class="outside">This element is positioned outside of its container.</div> ``` #### CSS ``` .center { margin: auto; background: lime; width: 66%; } .outside { margin: 3rem 0 0 -3rem; background: cyan; width: 66%; } ``` ### More examples ``` margin: 5%; /\* All sides: 5% margin \*/ margin: 10px; /\* All sides: 10px margin \*/ margin: 1.6em 20px; /\* top and bottom: 1.6em margin \*/ /\* left and right: 20px margin \*/ margin: 10px 3% -1em; /\* top: 10px margin \*/ /\* left and right: 3% margin \*/ /\* bottom: -1em margin \*/ margin: 10px 3px 30px 5px; /\* top: 10px margin \*/ /\* right: 3px margin \*/ /\* bottom: 30px margin \*/ /\* left: 5px margin \*/ margin: 2em auto; /\* top and bottom: 2em margin \*/ /\* Box is horizontally centered \*/ margin: auto; /\* top and bottom: 0 margin \*/ /\* Box is horizontally centered \*/ ``` Specifications -------------- | Specification | | --- | | [CSS Box Model Module Level 3 # margin](https://w3c.github.io/csswg-drafts/css-box/#margin) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `margin` | 1 | 12 | 1 | 3 | 3.5 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `auto` | 1 | 12 The `auto` value is not supported in quirks mode. | 1 | 6 The `auto` value is not supported in quirks mode. | 3.5 | 1 | 37 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [Introduction to the CSS basic box model](css_box_model/introduction_to_the_css_box_model) * [Margin collapsing](css_box_model/mastering_margin_collapsing) * [`margin-top`](margin-top), [`margin-right`](margin-right), [`margin-bottom`](margin-bottom), and [`margin-left`](margin-left) * The mapped logical properties: [`margin-block-start`](margin-block-start), [`margin-block-end`](margin-block-end), [`margin-inline-start`](margin-inline-start), and [`margin-inline-end`](margin-inline-end) and the shorthands [`margin-block`](margin-block) and [`margin-inline`](margin-inline) css border-inline-start-width border-inline-start-width ========================= The `border-inline-start-width` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the width of the logical inline-start border of an element, which maps to a physical border width depending on the element's writing mode, directionality, and text orientation. It corresponds to the [`border-top-width`](border-top-width), [`border-right-width`](border-right-width), [`border-bottom-width`](border-bottom-width), or [`border-left-width`](border-left-width) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ Syntax ------ ``` /\* <'border-width'> values \*/ border-inline-start-width: 5px; border-inline-start-width: thick; /\* Global values \*/ border-inline-start-width: inherit; border-inline-start-width: initial; border-inline-start-width: revert; border-inline-start-width: revert-layer; border-inline-start-width: unset; ``` Related properties are [`border-block-start-width`](border-block-start-width), [`border-block-end-width`](border-block-end-width), and [`border-inline-end-width`](border-inline-end-width), which define the other border widths of the element. ### Values `<'border-width'>` The width of the border. See [`border-width`](border-width). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `medium` | | Applies to | all elements | | [Inherited](inheritance) | no | | Percentages | logical-width of containing block | | [Computed value](computed_value) | absolute length; `0` if the border style is `none` or `hidden` | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` border-inline-start-width = <'border-top-width'> ``` Examples -------- ### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` ### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; border: 1px solid blue; border-inline-start-width: 5px; } ``` Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # border-width](https://w3c.github.io/csswg-drafts/css-logical/#border-width) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-inline-start-width` | 69 | 79 | 41 | No | 56 | 12.1 | 69 | 69 | 41 | 48 | 12.2 | 10.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * This property maps to one of the physical border properties: [`border-top-width`](border-top-width), [`border-right-width`](border-right-width), [`border-bottom-width`](border-bottom-width), and [`border-left-width`](border-left-width) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css Layout and the containing block Layout and the containing block =============================== The size and position of an element are often impacted by its **containing block**. Most often, the containing block is the [content area](css_box_model/introduction_to_the_css_box_model#content_area) of an element's nearest [block-level](https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements) ancestor, but this is not always the case. In this article, we examine the factors that determine an element's containing block. When a user agent (such as your browser) lays out a document, it generates a box for every element. Each box is divided into four areas: 1. Content area 2. Padding area 3. Border area 4. Margin area Many developers believe that the containing block of an element is always the content area of its parent, but that isn't necessarily true. Let's investigate the factors that determine what an element's containing block is. Effects of the containing block ------------------------------- Before learning what determines the containing block of an element, it's useful to know why it matters in the first place. The size and position of an element are often impacted by its containing block. Percentage values that are applied to the [`width`](width), [`height`](height), [`padding`](padding), [`margin`](margin), and offset properties of an absolutely positioned element (i.e., which has its [`position`](position) set to `absolute` or `fixed`) are computed from the element's containing block. Identifying the containing block -------------------------------- The process for identifying the containing block depends entirely on the value of the element's [`position`](position) property: 1. If the `position` property is `static`, `relative`, or `sticky`, the containing block is formed by the edge of the *content box* of the nearest ancestor element that is either **a block container** (such as an inline-block, block, or list-item element) or **establishes a formatting context** (such as a table container, flex container, grid container, or the block container itself). 2. If the `position` property is `absolute`, the containing block is formed by the edge of the *padding box* of the nearest ancestor element that has a `position` value other than `static` (`fixed`, `absolute`, `relative`, or `sticky`). 3. If the `position` property is `fixed`, the containing block is established by the [viewport](https://developer.mozilla.org/en-US/docs/Glossary/Viewport) (in the case of continuous media) or the page area (in the case of paged media). 4. If the `position` property is `absolute` or `fixed`, the containing block may also be formed by the edge of the *padding box* of the nearest ancestor element that has the following: 1. A [`transform`](transform) or [`perspective`](perspective) value other than `none` 2. A [`will-change`](will-change) value of `transform` or `perspective` 3. A [`filter`](filter) value other than `none` or a `will-change` value of `filter` (only works on Firefox). 4. A [`contain`](contain) value of `paint` (e.g. `contain: paint;`) 5. A [`backdrop-filter`](backdrop-filter) other than `none` (e.g. `backdrop-filter: blur(10px);`) **Note:** The containing block in which the root element ([`<html>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html)) resides is a rectangle called the **initial containing block**. It has the dimensions of the viewport (for continuous media) or the page area (for paged media). Calculating percentage values from the containing block ------------------------------------------------------- As noted above, when certain properties are given a percentage value, the computed value depends on the element's containing block. The properties that work this way are **box model properties** and **offset properties**: 1. The [`height`](height), [`top`](top), and [`bottom`](bottom) properties compute percentage values from the `height` of the containing block. 2. The [`width`](width), [`left`](left), [`right`](right), [`padding`](padding), and [`margin`](margin) properties compute percentage values from the `width` of the containing block. Some examples ------------- The HTML code for all our examples is: ``` <body> <section> <p>This is a paragraph!</p> </section> </body> ``` Only the CSS is altered in each instance below. ### Example 1 In this example, the paragraph is statically positioned, so its containing block is [`<section>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/section) because it's the nearest ancestor that is a block container. ``` body { background: beige; } section { display: block; width: 400px; height: 160px; background: lightgray; } p { width: 50%; /\* == 400px \* .5 = 200px \*/ height: 25%; /\* == 160px \* .25 = 40px \*/ margin: 5%; /\* == 400px \* .05 = 20px \*/ padding: 5%; /\* == 400px \* .05 = 20px \*/ background: cyan; } ``` ### Example 2 In this example, the paragraph's containing block is the [`<body>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body) element, because `<section>` is not a block container (because of `display: inline`) and doesn't establish a formatting context. ``` body { background: beige; } section { display: inline; background: lightgray; } p { width: 50%; /\* == half the body's width \*/ height: 200px; /\* Note: a percentage would be 0 \*/ background: cyan; } ``` ### Example 3 In this example, the paragraph's containing block is `<section>` because the latter's `position` is `absolute`. The paragraph's percentage values are affected by the `padding` of its containing block, though if the containing block's [`box-sizing`](box-sizing) value were `border-box` this would not be the case. ``` body { background: beige; } section { position: absolute; left: 30px; top: 30px; width: 400px; height: 160px; padding: 30px 20px; background: lightgray; } p { position: absolute; width: 50%; /\* == (400px + 20px + 20px) \* .5 = 220px \*/ height: 25%; /\* == (160px + 30px + 30px) \* .25 = 55px \*/ margin: 5%; /\* == (400px + 20px + 20px) \* .05 = 22px \*/ padding: 5%; /\* == (400px + 20px + 20px) \* .05 = 22px \*/ background: cyan; } ``` ### Example 4 In this example, the paragraph's `position` is `fixed`, so its containing block is the initial containing block (on screens, the viewport). Thus, the paragraph's dimensions change based on the size of the browser window. ``` body { background: beige; } section { width: 400px; height: 480px; margin: 30px; padding: 15px; background: lightgray; } p { position: fixed; width: 50%; /\* == (50vw - (width of vertical scrollbar)) \*/ height: 50%; /\* == (50vh - (height of horizontal scrollbar)) \*/ margin: 5%; /\* == (5vw - (width of vertical scrollbar)) \*/ padding: 5%; /\* == (5vw - (width of vertical scrollbar)) \*/ background: cyan; } ``` ### Example 5 In this example, the paragraph's `position` is `absolute`, so its containing block is `<section>`, which is the nearest ancestor with a [`transform`](transform) property that isn't `none`. ``` body { background: beige; } section { transform: rotate(0deg); width: 400px; height: 160px; background: lightgray; } p { position: absolute; left: 80px; top: 30px; width: 50%; /\* == 200px \*/ height: 25%; /\* == 40px \*/ margin: 5%; /\* == 20px \*/ padding: 5%; /\* == 20px \*/ background: cyan; } ``` See also -------- * The [`all`](all) property resets all CSS declarations to a given known state * CSS key concepts: + [CSS syntax](syntax) + [At-rules](at-rule) + [Comments](comments) + [Specificity](specificity) + [Inheritance](inheritance) + [Box model](css_box_model/introduction_to_the_css_box_model) + [Layout modes](layout_mode) + [Visual formatting models](visual_formatting_model) + [Margin collapsing](css_box_model/mastering_margin_collapsing) + Values - [Initial values](initial_value) - [Computed values](computed_value) - [Used values](used_value) - [Actual values](actual_value) + [Value definition syntax](value_definition_syntax) + [Shorthand properties](shorthand_properties) + [Replaced elements](replaced_element) css mask-border-source mask-border-source ================== The `mask-border-source` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the source image used to create an element's [mask border](mask-border). The [`mask-border-slice`](mask-border-slice) property is used to divide the source image into regions, which are then dynamically applied to the final mask border. Syntax ------ ``` /\* Keyword value \*/ mask-border-source: none; /\* <image> values \*/ mask-border-source: url(image.jpg); mask-border-source: linear-gradient(to top, red, yellow); /\* Global values \*/ mask-border-source: inherit; mask-border-source: initial; mask-border-source: revert; mask-border-source: revert-layer; mask-border-source: unset; ``` ### Values `none` No mask border is used. [`<image>`](image) Image reference to use for the mask border. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements; In SVG, it applies to container elements excluding the [`<defs>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs) element and all graphics elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified, but with [`url()`](url) values made absolute | | Animation type | discrete | Formal syntax ------------- ``` mask-border-source = none [|](value_definition_syntax#single_bar) <image> <image> = <url> [|](value_definition_syntax#single_bar) [<gradient>](gradient) <url> = url( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) [|](value_definition_syntax#single_bar) src( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) ``` Examples -------- ### Basic usage This property doesn't appear to be supported anywhere yet. When it eventually starts to be supported, it will serve to define the source of the border mask. ``` mask-border-source: url(image.jpg); ``` Chromium-based browsers support an outdated version of this property — `mask-box-image-source` — with a prefix: ``` -webkit-mask-box-image-source: url(image.jpg); ``` **Note:** The [`mask-border`](mask-border) page features a working example (using the out-of-date prefixed border mask properties supported in Chromium), so you can get an idea of the effect. Specifications -------------- | Specification | | --- | | [CSS Masking Module Level 1 # the-mask-border-source](https://drafts.fxtf.org/css-masking/#the-mask-border-source) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `mask-border-source` | 1 | 79 | No See [bug 877294](https://bugzil.la/877294). | No | 15 | 3.1 | 4.4 | 18 | No See [bug 877294](https://bugzil.la/877294). | 14 | 3 | 1.0 | See also -------- * [`mask-border`](mask-border) * [`mask-border-mode`](mask-border-mode) * [`mask-border-outset`](mask-border-outset) * [`mask-border-repeat`](mask-border-repeat) * [`mask-border-width`](mask-border-width)
programming_docs
css border-block-style border-block-style ================== The `border-block-style` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the style of the logical block borders of an element, which maps to a physical border style depending on the element's writing mode, directionality, and text orientation. It corresponds to the [`border-top-style`](border-top-style) and [`border-bottom-style`](border-bottom-style), or [`border-left-style`](border-left-style) and [`border-right-style`](border-right-style) properties depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ The border style in the other dimension can be set with [`border-inline-style`](border-inline-style), which sets [`border-inline-start-style`](border-inline-start-style), and [`border-inline-end-style`](border-inline-end-style). Syntax ------ ``` /\* <'border-style'> values \*/ border-block-style: dashed; border-block-style: dotted; border-block-style: groove; /\* Global values \*/ border-block-style: inherit; border-block-style: initial; border-block-style: revert; border-block-style: revert-layer; border-block-style: unset; ``` ### Values `<'border-style'>` The line style of the border. See [`border-style`](border-style). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` border-block-style = <'border-top-style'>[{1,2}](value_definition_syntax#curly_braces) ``` Examples -------- ### Dashed border with vertical text #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; border: 5px solid blue; border-block-style: dashed; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # propdef-border-block-style](https://w3c.github.io/csswg-drafts/css-logical/#propdef-border-block-style) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-block-style` | 87 | 87 | 66 | No | 73 | 14.1 | 87 | 87 | 66 | 62 | 14.5 | 14.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * This property maps to one of the physical border properties: [`border-top-style`](border-top-style), [`border-right-style`](border-right-style), [`border-bottom-style`](border-bottom-style), or [`border-left-style`](border-left-style). * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css border-image-width border-image-width ================== The `border-image-width` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the width of an element's [border image](border-image). Try it ------ If this property's value is greater than the element's [`border-width`](border-width), the border image will extend beyond the padding (and/or content) edge. Syntax ------ ``` /\* Keyword value \*/ border-image-width: auto; /\* <length> value \*/ border-image-width: 1rem; /\* <percentage> value \*/ border-image-width: 25%; /\* <number> value \*/ border-image-width: 3; /\* top and bottom | left and right \*/ border-image-width: 2em 3em; /\* top | left and right | bottom \*/ border-image-width: 5% 15% 10%; /\* top | right | bottom | left \*/ border-image-width: 5% 2em 10% auto; /\* Global values \*/ border-image-width: inherit; border-image-width: initial; border-image-width: revert; border-image-width: revert-layer; border-image-width: unset; ``` The `border-image-width` property may be specified using one, two, three, or four values chosen from the list of values below. * When **one** value is specified, it applies the same width to **all four sides**. * When **two** values are specified, the first width applies to the **top and bottom**, the second to the **left and right**. * When **three** values are specified, the first width applies to the **top**, the second to the **left and right**, the third to the **bottom**. * When **four** values are specified, the widths apply to the **top**, **right**, **bottom**, and **left** in that order (clockwise). ### Values `<length-percentage>` The width of the border, specified as a [`<length>`](length) or a [`<percentage>`](percentage). Percentages are relative to the *width* of the border image area for horizontal offsets and the *height* of the border image area for vertical offsets. Must not be negative. `<number>` The width of the border, specified as a multiple of the corresponding [`border-width`](border-width). Must not be negative. `auto` The width of the border is made equal to the intrinsic width or height (whichever is applicable) of the corresponding [`border-image-slice`](border-image-slice). If the image does not have the required intrinsic dimension, the corresponding `border-width` is used instead. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `1` | | Applies to | all elements, except internal table elements when [`border-collapse`](border-collapse) is `collapse`. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | Percentages | refer to the width or height of the border image area | | [Computed value](computed_value) | as specified, but with relative lengths converted into absolute lengths | | Animation type | by computed value type | Formal syntax ------------- ``` border-image-width = [[](value_definition_syntax#brackets) [<length-percentage [0,∞]>](length-percentage) [|](value_definition_syntax#single_bar) [<number [0,∞]>](number) [|](value_definition_syntax#single_bar) auto []](value_definition_syntax#brackets)[{1,4}](value_definition_syntax#curly_braces) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Tiling a border image This example creates a border image using the following ".png" file, which is 90 by 90 pixels: Thus, each circle in the source image is 30 by 30 pixels. #### HTML ``` <p> Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. </p> ``` #### CSS ``` p { border: 20px solid; border-image: url("border.png") 30 round; border-image-width: 16px; padding: 40px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # the-border-image-width](https://w3c.github.io/csswg-drafts/css-backgrounds/#the-border-image-width) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-image-width` | 15 | 12 | 13 | 11 | 15 | 6 | 4.4 | 18 | 14 | 14 | 6 | 1.0 | See also -------- * [Backgrounds and borders](css_backgrounds_and_borders) * [Learn CSS: Backgrounds and borders](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Backgrounds_and_borders) css height height ====== The `height` CSS property specifies the height of an element. By default, the property defines the height of the [content area](css_box_model/introduction_to_the_css_box_model#content_area). If [`box-sizing`](box-sizing) is set to `border-box`, however, it instead determines the height of the [border area](css_box_model/introduction_to_the_css_box_model#border_area). Try it ------ The [`min-height`](min-height) and [`max-height`](max-height) properties override `height`. Syntax ------ ``` /\* <length> values \*/ height: 120px; height: 10em; height: 100vh; /\* <percentage> value \*/ height: 75%; /\* Keyword values \*/ height: max-content; height: min-content; height: fit-content(20em); height: auto; /\* Global values \*/ height: inherit; height: initial; height: revert; height: revert-layer; height: unset; ``` ### Values [`<length>`](length) Defines the height as an absolute value. [`<percentage>`](percentage) Defines the height as a percentage of the 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` Box will use the available space, but never more than `max-content` `fit-content([`<length-percentage>`](length-percentage))` Uses the fit-content formula with the available space replaced by the specified argument, i.e. `min(max-content, max(min-content, <length-percentage>))` [`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](https://developer.mozilla.org/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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | all elements but non-replaced inline elements, table columns, and column groups | | [Inherited](inheritance) | no | | Percentages | The percentage is calculated with respect to the height of the generated box's containing block. If the height of the containing block is not specified explicitly (i.e., it depends on content height), and this element is not absolutely positioned, the value computes to `auto`. A percentage height on the root element is relative to the initial containing block. | | [Computed value](computed_value) | a percentage or `auto` or the absolute length | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` height = auto [|](value_definition_syntax#single_bar) [<length-percentage [0,∞]>](length-percentage) [|](value_definition_syntax#single_bar) min-content [|](value_definition_syntax#single_bar) max-content [|](value_definition_syntax#single_bar) fit-content( [<length-percentage [0,∞]>](length-percentage) ) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Setting height using pixels and percentages #### 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 ``` 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 Specifications -------------- | Specification | | --- | | [CSS Box Sizing Module Level 3 # preferred-size-properties](https://w3c.github.io/csswg-drafts/css-sizing/#preferred-size-properties) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `height` | 1 | 12 | 1 | 4 | 7 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `fit-content` | 46 | 79 | No | No | 33 | 11 9 | 46 | 46 | No | 33 | 11 9 | 5.0 | | `fit-content_function` | No | No | 91 | No | No | No | No | No | No | No | No | No | | `max-content` | 46 | 79 | 66 3 | No | 44 | 11 | 46 | 46 | 66 4 | 43 | 11 | 5.0 | | `min-content` | 46 | 79 | 66 3 | No | 44 | 11 | 46 | 46 | 66 4 | 43 | 11 | 5.0 | | `stretch` | 28 | 79 | No | No | 15 | 9 | 4.4 | 28 | No | 15 | 9 | 5.0 | See also -------- * [The box model](css_box_model/introduction_to_the_css_box_model) * [`width`](width) * [`box-sizing`](box-sizing) * [`min-height`](min-height), [`max-height`](max-height) * The mapped logical properties: [`block-size`](block-size), [`inline-size`](inline-size) css inset inset ===== The `inset` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property is a shorthand that corresponds to the [`top`](top), [`right`](right), [`bottom`](bottom), and/or [`left`](left) properties. It has the same multi-value syntax of the [`margin`](margin) shorthand. Try it ------ While part of the *CSS Logical Properties* specification, it does not define *logical* offsets. It defines *physical* offsets, regardless of the element's writing mode, directionality, and text orientation. Syntax ------ ``` /\* <length> values \*/ inset: 10px; /\* value applied to all edges \*/ inset: 4px 8px; /\* top/bottom left/right \*/ inset: 5px 15px 10px; /\* top left/right bottom \*/ inset: 2.4em 3em 3em 3em; /\* top right bottom left \*/ /\* <percentage>s of the width (left/right) or height (top/bottom) of the containing block \*/ inset: 10% 5% 5% 5%; /\* Keyword value \*/ inset: auto; /\* Global values \*/ inset: inherit; inset: initial; inset: revert; inset: revert-layer; inset: unset; ``` ### Values The `inset` property takes the same values as the [`left`](left) property. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`top`](top): `auto` * [`bottom`](bottom): `auto` * [`left`](left): `auto` * [`right`](right): `auto` | | Applies to | positioned elements | | [Inherited](inheritance) | no | | Percentages | relative to the containing block’s size in the corresponding axis (e.g. width for left or right, height for top or bottom) | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`top`](top): if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, `auto` * [`bottom`](bottom): if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, `auto` * [`left`](left): if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, `auto` * [`right`](right): if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, `auto` | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` inset = [<top>](top)[{1,4}](value_definition_syntax#curly_braces) ``` Examples -------- ### Setting offsets for an element #### HTML ``` <div> <span class="exampleText">Example text</span> </div> ``` #### CSS ``` div { background-color: yellow; width: 150px; height: 120px; position: relative; } .exampleText { writing-mode: sideways-rl; position: absolute; inset: 20px 40px 30px 10px; background-color: #c8c800; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # propdef-inset](https://w3c.github.io/csswg-drafts/css-logical/#propdef-inset) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `inset` | 87 | 87 | 66 | No | 73 | 14.1 | 87 | 87 | 66 | 62 | 14.5 | 14.0 | See also -------- * The longhand box offset properties: [`top`](top), [`right`](right), [`bottom`](bottom), and [`left`](left). * The mapped logical shorthands: [`inset-block`](inset-block) and [`inset-inline`](inset-inline) * The [`margin`](margin) shorthand multi-value syntax. css ::before ::before ======== In CSS, `::before` creates a [pseudo-element](pseudo-elements) that is the first child of the selected element. It is often used to add cosmetic content to an element with the [`content`](content) property. It is inline by default. Try it ------ **Note:** The pseudo-elements generated by `::before` and `::after` are [contained by the element's formatting box](https://www.w3.org/TR/CSS2/generate.html#before-after-content), and thus don't apply to *[replaced elements](replaced_element)* such as [`<img>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img), or to [`<br>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/br) elements. Syntax ------ ``` ::before ``` **Note:** [Selectors Level 3](https://drafts.csswg.org/selectors-3/#gen-content) introduced the double-colon notation `::before` to distinguish <pseudo-classes> from <pseudo-elements>. Browsers also accept single-colon notation`:before`, introduced in CSS2. Examples -------- ### Adding quotation marks One simple example of using `::before` pseudo-elements is to provide quotation marks. Here we use both `::before` and `[`::after`](::after)` to insert quotation characters. #### HTML ``` <q>Some quotes</q>, he said, <q>are better than none.</q> ``` #### CSS ``` q::before { content: "«"; color: blue; } q::after { content: "»"; color: red; } ``` #### Result ### Decorative example We can style text or images in the [`content`](content) property almost any way we want. #### HTML ``` <span class="ribbon">Notice where the orange box is.</span> ``` #### CSS ``` .ribbon { background-color: #5bc8f7; } .ribbon::before { content: "Look at this orange box."; background-color: #ffba10; border-color: black; border-style: dotted; } ``` #### Result ### To-do list In this example we will create a simple to-do list using pseudo-elements. This method can often be used to add small touches to the UI and improve user experience. #### HTML ``` <ul> <li>Buy milk</li> <li>Take the dog for a walk</li> <li>Exercise</li> <li>Write code</li> <li>Play music</li> <li>Relax</li> </ul> ``` #### CSS ``` li { list-style-type: none; position: relative; margin: 2px; padding: 0.5em 0.5em 0.5em 2em; background: lightgrey; font-family: sans-serif; } li.done { background: #ccff99; } li.done::before { content: ""; position: absolute; border-color: #009933; border-style: solid; border-width: 0 0.3em 0.25em 0; height: 1em; top: 1.3em; left: 0.6em; margin-top: -1em; transform: rotate(45deg); width: 0.5em; } ``` #### JavaScript ``` const list = document.querySelector("ul"); list.addEventListener( "click", (ev) => { if (ev.target.tagName === "LI") { ev.target.classList.toggle("done"); } }, false ); ``` Here is the above code example running live. Note that there are no icons used, and the check-mark is actually the `::before` that has been styled in CSS. Go ahead and get some stuff done. #### Result ### Special characters As this is CSS; not HTML, you can **not** use markup entities in content values. If you need to use a special character, and can not enter it literally into your CSS content string, use a unicode escape sequence, consisting of a backslash followed by the hexadecimal unicode value. #### HTML ``` <ol> <li>Crack Eggs into bowl</li> <li>Add Milk</li> <li>Add Flour</li> <li aria-current="step">Mix thoroughly into a smooth batter</li> <li>Pour a ladleful of batter onto a hot, greased, flat frying pan</li> <li>Fry until the top of the pancake loses its gloss</li> <li>Flip it over and fry for a couple more minutes</li> <li>serve with your favorite topping</li> </ol> ``` #### CSS ``` li { padding: 0.5em; } li[aria-current="step"] { font-weight: bold; } li[aria-current="step"]::after { content: " \21E6"; /\* Hexadecimal for Unicode Leftwards white arrow\*/ display: inline; } ``` #### Result Accessibility concerns ---------------------- Using a `::before` pseudo-element to add content is discouraged, as it is not reliably accessible to screen readers. Specifications -------------- | Specification | | --- | | [CSS Pseudo-Elements Module Level 4 # generated-content](https://w3c.github.io/csswg-drafts/css-pseudo/#generated-content) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `::before` | 1 1 | 12 12 | 1.5 ["Before Firefox 57, Firefox had a bug where `::before` pseudo-elements were still generated, even if the [`content`](https://developer.mozilla.org/docs/Web/CSS/content) property value were set to `normal` or `none`.", "Before Firefox 3.5, only the CSS level 2 behavior of `:before` was supported, which disallowed [`position`](https://developer.mozilla.org/docs/Web/CSS/position), [`float`](https://developer.mozilla.org/docs/Web/CSS/float), `list-style-*` and some `display` properties."] 1 | 9 8 | 7 4 | 4 4 | ≤37 ≤37 | 18 18 | 4 Before Firefox 57, Firefox had a bug where `::before` pseudo-elements were still generated, even if the [`content`](https://developer.mozilla.org/docs/Web/CSS/content) property value were set to `normal` or `none`. 4 | 10.1 10.1 | 3 3 | 1.0 1.0 | | `animation_and_transition_support` | 26 | 12 | 4 | No | 15 | No | 4.4 | 26 | 4 | 14 | No | 1.5 | See also -------- * [`::after`](::after) * [`content`](content)
programming_docs
css @layer @layer ====== The `@layer` [CSS](https://developer.mozilla.org/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. Syntax ------ ``` @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: ``` @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: ``` @layer utilities; ``` Multiple layers can be defined at once, as shown below: ``` @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: ``` @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 [`@import`](@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. ``` @import "theme.css" layer(utilities); ``` ### Nesting layers Layers may be nested. For example: ``` @layer framework { @layer layout { } } ``` To append rules to the `layout` layer inside `framework`, join the two names with a `.`. ``` @layer framework.layout { p { margin-block: 1rem; } } ``` Formal syntax ------------- ``` @layer = @layer <layer-name>[?](value_definition_syntax#question_mark) { [<stylesheet>](stylesheet) } [|](value_definition_syntax#single_bar) @layer <layer-name>[#](value_definition_syntax#hash_mark) ; <layer-name> = [<ident>](ident) [[](value_definition_syntax#brackets) '.' [<ident>](ident) []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) ``` Examples -------- ### Simple example In the following example, two CSS rules are created. One for the [`<p>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/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 ``` <div class="box"> <p>Hello, world!</p> </div> ``` #### CSS ``` p { color: rebeccapurple; } @layer type { .box p { font-weight: bold; font-size: 1.3em; color: green; } } ``` #### Result ### 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 ``` <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 ``` @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 Specifications -------------- | Specification | | --- | | [CSS Cascading and Inheritance Level 5 # layering](https://w3c.github.io/csswg-drafts/css-cascade-5/#layering) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `@layer` | 99 | 99 | 97 | No | 85 | 15.4 | 99 | 99 | 97 | 68 | 15.4 | 18.0 | See also -------- * [`@import`](@import) * [The `!important` flag](important) * [The `revert-layer` keyword](revert-layer) * [Introducing the CSS Cascade](cascade) * [CSS building block: cascade and inheritance](https://developer.mozilla.org/en-US/docs/Web/Learn/CSS/Building_blocks/Cascade_and_inheritance) * [CSS building block: cascade layers](https://developer.mozilla.org/en-US/docs/Web/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/) css ::first-line ::first-line ============ The `::first-line` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-element](pseudo-elements) applies styles to the first line of a [block-level element](visual_formatting_model#block-level_elements_and_block_boxes). Try it ------ The effects of `::first-line` are limited by the length and content of the first line of text in the element. The length of the first line depends on many factors, including the width of the element, the width of the document, and the font size of the text. `::first-line` has no effect when the first child of the element, which would be the first part of the first line, is an inline block-level element, such as an inline table. **Note:** [Selectors Level 3](https://drafts.csswg.org/selectors-3/#first-line) introduced the double-colon notation (`::`) to distinguish <pseudo-classes> from <pseudo-elements>, which are single-colon `:`. Browsers accept both `::first-line` and `:first-line`, which was introduced in CSS2. Allowable properties -------------------- Only a small subset of CSS properties can be used with the `::first-line` pseudo-element: * All font-related properties: [`font`](font), [`font-kerning`](font-kerning), [`font-style`](font-style), [`font-variant`](font-variant), [`font-variant-numeric`](font-variant-numeric), [`font-variant-position`](font-variant-position), [`font-variant-east-asian`](font-variant-east-asian), [`font-variant-caps`](font-variant-caps), [`font-variant-alternates`](font-variant-alternates), [`font-variant-ligatures`](font-variant-ligatures), [`font-synthesis`](font-synthesis), [`font-feature-settings`](font-feature-settings), [`font-language-override`](font-language-override), [`font-weight`](font-weight), [`font-size`](font-size), [`font-size-adjust`](font-size-adjust), [`font-stretch`](font-stretch), and [`font-family`](font-family) * All background-related properties: [`background-color`](background-color), [`background-clip`](background-clip), [`background-image`](background-image), [`background-origin`](background-origin), [`background-position`](background-position), [`background-repeat`](background-repeat), [`background-size`](background-size), [`background-attachment`](background-attachment), and [`background-blend-mode`](background-blend-mode) * The [`color`](color) property * [`word-spacing`](word-spacing), [`letter-spacing`](letter-spacing), [`text-decoration`](text-decoration), [`text-transform`](text-transform), and [`line-height`](line-height) * [`text-shadow`](text-shadow), [`text-decoration`](text-decoration), [`text-decoration-color`](text-decoration-color), [`text-decoration-line`](text-decoration-line), [`text-decoration-style`](text-decoration-style), and [`vertical-align`](vertical-align). Syntax ------ ``` ::first-line ``` Examples -------- ### HTML ``` <p> Styles will only be applied to the first line of this paragraph. After that, all text will be styled like normal. See what I mean? </p> <span> The first line of this text will not receive special styling because it is not a block-level element. </span> ``` ### CSS ``` ::first-line { color: blue; text-transform: uppercase; /\* WARNING: DO NOT USE THESE \*/ /\* Many properties are invalid in ::first-line pseudo-elements \*/ margin-left: 20px; text-indent: 20px; } ``` ### Result Specifications -------------- | Specification | | --- | | [CSS Pseudo-Elements Module Level 4 # first-line-pseudo](https://w3c.github.io/csswg-drafts/css-pseudo/#first-line-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `::first-line` | 1 Before Chrome 62, the [`text-transform`](https://developer.mozilla.org/docs/Web/CSS/text-transform) property does not work on `::first-line` pseudo-elements. See [Chromium bug 129669](https://crbug.com/129669). 1 Before Chrome 62, the [`text-transform`](https://developer.mozilla.org/docs/Web/CSS/text-transform) property does not work on `::first-line` pseudo-elements. See [Chromium bug 129669](https://crbug.com/129669). | 12 12 | 1 1 | 9 5.5 | 7 From Opera 15 to Opera 49 (exclusive), the [`text-transform`](https://developer.mozilla.org/docs/Web/CSS/text-transform) property does not work on `::first-line` or `:first-line` pseudo-elements. See [Chromium bug 129669](https://crbug.com/129669). 3.5 From Opera 15 to Opera 49 (exclusive), the [`text-transform`](https://developer.mozilla.org/docs/Web/CSS/text-transform) property does not work on `::first-line` or `:first-line` pseudo-elements. See [Chromium bug 129669](https://crbug.com/129669). | 1 The [`text-transform`](https://developer.mozilla.org/docs/Web/CSS/text-transform) property does not work for `::first-line` or `:first-line` pseudo-elements. See [WebKit bug 3409](https://webkit.org/b/3409). 1 The [`text-transform`](https://developer.mozilla.org/docs/Web/CSS/text-transform) property does not work for `::first-line` or `:first-line` pseudo-elements. See [WebKit bug 3409](https://webkit.org/b/3409). | ≤37 Before WebView 62, the [`text-transform`](https://developer.mozilla.org/docs/Web/CSS/text-transform) property does not work on `::first-line` pseudo-elements. See [Chromium bug 129669](https://crbug.com/129669). ≤37 Before WebView 62, the [`text-transform`](https://developer.mozilla.org/docs/Web/CSS/text-transform) property does not work on `::first-line` pseudo-elements. See [Chromium bug 129669](https://crbug.com/129669). | 18 Before Chrome 62, the [`text-transform`](https://developer.mozilla.org/docs/Web/CSS/text-transform) property does not work on `::first-line` pseudo-elements. See [Chromium bug 129669](https://crbug.com/129669). 18 Before Chrome 62, the [`text-transform`](https://developer.mozilla.org/docs/Web/CSS/text-transform) property does not work on `::first-line` pseudo-elements. See [Chromium bug 129669](https://crbug.com/129669). | 4 4 | 10.1 From Opera 15 to Opera 49 (exclusive), the [`text-transform`](https://developer.mozilla.org/docs/Web/CSS/text-transform) property does not work on `::first-line` or `:first-line` pseudo-elements. See [Chromium bug 129669](https://crbug.com/129669). 10.1 From Opera 15 to Opera 49 (exclusive), the [`text-transform`](https://developer.mozilla.org/docs/Web/CSS/text-transform) property does not work on `::first-line` or `:first-line` pseudo-elements. See [Chromium bug 129669](https://crbug.com/129669). | 1 The [`text-transform`](https://developer.mozilla.org/docs/Web/CSS/text-transform) property does not work for `::first-line` or `:first-line` pseudo-elements. See [WebKit bug 3409](https://webkit.org/b/3409). 1 The [`text-transform`](https://developer.mozilla.org/docs/Web/CSS/text-transform) property does not work for `::first-line` or `:first-line` pseudo-elements. See [WebKit bug 3409](https://webkit.org/b/3409). | 1.0 Before Samsung Internet 8.0, the [`text-transform`](https://developer.mozilla.org/docs/Web/CSS/text-transform) property does not work on `::first-line` pseudo-elements. See [Chromium bug 129669](https://crbug.com/129669). 1.0 Before Samsung Internet 8.0, the [`text-transform`](https://developer.mozilla.org/docs/Web/CSS/text-transform) property does not work on `::first-line` pseudo-elements. See [Chromium bug 129669](https://crbug.com/129669). | See also -------- * [`::first-letter`](::first-letter) css masonry-auto-flow masonry-auto-flow ================= **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `masonry-auto-flow` CSS property modifies how items are placed when using [masonry](css_grid_layout/masonry_layout) in [CSS Grid Layout](css_grid_layout). Syntax ------ ``` /\* Keyword values \*/ masonry-auto-flow: pack; masonry-auto-flow: next; masonry-auto-flow: ordered; masonry-auto-flow: definite-first; masonry-auto-flow: next ordered; /\* Global values \*/ masonry-auto-flow: inherit; masonry-auto-flow: initial; masonry-auto-flow: revert; masonry-auto-flow: revert-layer; masonry-auto-flow: unset; ``` This property may take one of two forms: * A single keyword: one of `pack`, `next`, `definite-first`, or `ordered` * Two keywords, for example `next ordered`. ### Values `pack` As per the default masonry algorithm, items will be placed into the track with the most room. `next` Items will be placed one after the other in the grid axis. `definite-first` Display as in the default masonry algorithm, placing items with a definite place first before placing other masonry items. `ordered` Ignore any items with a definite placement, and place everything according to order-modified document order. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `pack` | | Applies to | Grid containers with masonry layout | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` masonry-auto-flow = [[](value_definition_syntax#brackets) pack [|](value_definition_syntax#single_bar) next []](value_definition_syntax#brackets) [||](value_definition_syntax#double_bar) [[](value_definition_syntax#brackets) definite-first [|](value_definition_syntax#single_bar) ordered []](value_definition_syntax#brackets) ``` Examples -------- ### Using the next keyword #### HTML ``` <div id="grid"> <div id="item1"></div> <div id="item2"></div> <div id="item3"></div> <div id="item4"></div> <div id="item5"></div> </div> <select id="flow"> <option value="pack">pack</option> <option value="next">next</option> </select> ``` #### CSS ``` #grid { height: 200px; width: 200px; display: grid; gap: 10px; grid-template-columns: repeat(3, 1fr); grid-template-rows: masonry; masonry-auto-flow: pack; } #item1 { background-color: lime; height: 2em; } #item2 { background-color: yellow; } #item3 { background-color: blue; height: 3em; } #item4 { background-color: red; height: 2.5em; } #item5 { background-color: aqua; height: 4em; } ``` ``` const selectElem = document.querySelector('select'); function changeMasonryFlow() { const grid = document.getElementById("grid"); const direction = document.getElementById("flow"); const masonryAutoFlow = direction.value === "pack" ? "pack" : "next"; grid.style.masonryAutoFlow = masonryAutoFlow; } selectElem.addEventListener('change', changeMasonryFlow); ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Grid Layout Module Level 3 # masonry-auto-flow](https://w3c.github.io/csswg-drafts/css-grid-3/#masonry-auto-flow) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `masonry-auto-flow` | No | No | No | No | No | No | No | No | No | No | No | No | See also -------- * Related CSS properties: [`align-tracks`](align-tracks), [`justify-tracks`](justify-tracks) css scrollbar-gutter scrollbar-gutter ================ The `scrollbar-gutter` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property allows authors to reserve space for the scrollbar, preventing unwanted layout changes as the content grows while also avoiding unnecessary visuals when scrolling isn't needed. An element's *scrollbar gutter* is the space between the inner border edge and the outer padding edge, where the browser may display a scrollbar. If no scrollbar is present, the gutter will be painted as an extension of the padding. The browser determines whether *classic* scrollbars or *overlay* scrollbars are used: * Classic scrollbars are always placed in a gutter, consuming space when present. * Overlay scrollbars are placed over the content, not in a gutter, and are usually partially transparent. Syntax ------ ``` /\* Initial value \*/ scrollbar-gutter: auto; /\* "stable" keyword, with optional modifier \*/ scrollbar-gutter: stable; scrollbar-gutter: stable both-edges; /\* Global values \*/ scrollbar-gutter: inherit; scrollbar-gutter: initial; scrollbar-gutter: revert; scrollbar-gutter: revert-layer; scrollbar-gutter: unset; ``` ### Values `auto` The initial value. Classic scrollbars create a gutter when `overflow` is `scroll`, or when `overflow` is `auto` and the box is overflowing. Overlay scrollbars do not consume space. `stable` When using classic scrollbars, the gutter will be present if `overflow` is `auto`, `scroll`, or `hidden` even if the box is not overflowing. When using overlay scrollbars, the gutter will not be present. `both-edges` If a gutter would be present on one of the inline start/end edges of the box, another will be present on the opposite edge as well. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | scrolling boxes | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` scrollbar-gutter = auto [|](value_definition_syntax#single_bar) stable [&&](value_definition_syntax#double_ampersand) both-edges[?](value_definition_syntax#question_mark) ``` Examples -------- The examples below show how the different values for the `scrollbar-gutter` property would affect a scrollable `div` element (`.container`) with one or more paragraphs contained within. **Note:** In the images for the examples, the user's system settings are set to classic scrollbars (always shown). ### Example 1 Prevent unneeded layout changes as the content growing or shrinking causes the scrollbar to appear/disappear, a space is reserved for it. ``` .container { scrollbar-gutter: stable; } ``` ### Example 2 Add symmetric spacing to both sides of the box so the content is centered: ``` .container { scrollbar-gutter: stable both-edges; } ``` ### Example 3 Align the contents of a non-scrolling element and a scrolling one adjacent to it: This example shows two divs side by side. The one on the left has no scroll, but the one on the right does. Both have `scrollbar-gutter` applied, which also reserves space for the div on the left which doesn't have scrollable content. This is a good technique to use to keep the width of content consistent. ``` .container1 { overflow: hidden; scrollbar-gutter: stable; } .container2 { scrollbar-gutter: stable; } ``` ### Overlay scrollbars For reference, this image shows the same div as above, but with the user's system settings set to overlay scrollbars. Note here the scrollbar will only show when the user is scrolling and on top of the content, so no space is reserved for it and the `scrollbar-gutter` property has no effect. Specifications -------------- | Specification | | --- | | [CSS Overflow Module Level 3 # scrollbar-gutter-property](https://w3c.github.io/csswg-drafts/css-overflow/#scrollbar-gutter-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scrollbar-gutter` | 94 | 94 | 97 | No | 80 | No See [bug 167335](https://webkit.org/b/167335). | 94 | 94 | 97 | 66 | No See [bug 167335](https://webkit.org/b/167335). | 17.0 | See also -------- * [`scrollbar-width`](scrollbar-width) * [`overflow`](overflow)
programming_docs
css inset-block inset-block =========== The `inset-block` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the logical block start and end offsets of an element, which maps to physical offsets depending on the element's writing mode, directionality, and text orientation. It corresponds to the [`top`](top) and [`bottom`](bottom), or [`right`](right) and [`left`](left) properties depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`inset-block-end`](inset-block-end) * [`inset-block-start`](inset-block-start) Syntax ------ ``` /\* <length> values \*/ inset-block: 3px 10px; inset-block: 2.4em 3em; inset-block: 10px; /\* value applied to start and end \*/ /\* <percentage>s of the width or height of the containing block \*/ inset-block: 10% 5%; /\* Keyword value \*/ inset-block: auto; /\* Global values \*/ inset-block: inherit; inset-block: initial; inset-block: revert; inset-block: revert-layer; inset-block: unset; ``` ### Values The `inset-block` property takes the same values as the [`left`](left) property. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`inset-block-start`](inset-block-start): `auto` * [`inset-block-end`](inset-block-end): `auto` | | Applies to | positioned elements | | [Inherited](inheritance) | no | | Percentages | logical-height of containing block | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`inset-block-start`](inset-block-start): same as box offsets: [`top`](top), [`right`](right), [`bottom`](bottom), [`left`](left) properties except that directions are logical * [`inset-block-end`](inset-block-end): same as box offsets: [`top`](top), [`right`](right), [`bottom`](bottom), [`left`](left) properties except that directions are logical | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` inset-block = [<top>](top)[{1,2}](value_definition_syntax#curly_braces) ``` Examples -------- ### Setting block start and end offsets #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; position: relative; inset-block: 20px 50px; background-color: #c8c800; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # propdef-inset-block](https://w3c.github.io/csswg-drafts/css-logical/#propdef-inset-block) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `inset-block` | 87 | 87 | 63 41-63 | No | 73 | 14.1 | 87 | 87 | 63 41-63 | 62 | 14.5 | 14.0 | See also -------- * The mapped physical properties: [`top`](top), [`right`](right), [`bottom`](bottom), and [`left`](left) * The mapped physical shortcut: [`inset`](inset) * The mapped inline shortcut: [`inset-inline`](inset-inline) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css contain-intrinsic-size contain-intrinsic-size ====================== The `contain-intrinsic-size` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [shorthand property](shorthand_properties) sets the size of an element that a browser will use for layout when the element is subject to [size containment](css_containment#size_containment). Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`contain-intrinsic-width`](contain-intrinsic-width) * [`contain-intrinsic-height`](contain-intrinsic-height) Syntax ------ ``` /\* Keyword values \*/ contain-intrinsic-width: none; /\* <length> values \*/ contain-intrinsic-size: 1000px; contain-intrinsic-size: 10rem; /\* width | height \*/ contain-intrinsic-size: 1000px 1.5em; /\* auto <length> \*/ contain-intrinsic-size: auto 300px; /\* auto width | auto height \*/ contain-intrinsic-size: auto 300px auto 4rem; /\* Global values \*/ contain-intrinsic-size: inherit; contain-intrinsic-size: initial; contain-intrinsic-size: revert; contain-intrinsic-size: unset; ``` ### Values Either one or two of the following values may be specified for an element. If two values are specified, the first value applies to the width, and the second to the height. If a single value is specified, it applies to both width and height. `none` The element has no intrinsic size in the given dimension(s). `<length>` The element has the specified [`<length>`](length) in the given dimension(s). `auto <length>` A remembered value of the "normally rendered" element size 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`](contain) and [`content-visibility`](content-visibility). Size containment allows a user agent to layout 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-size` property allows authors to specify an appropriate value to be used as the size for layout. The `auto <length>` value allows the size of the element to be stored if the element is ever "normally rendered" (with its child elements), and then used instead of the specified length when the element is skipping its contents. This allows offscreen elements with [`content-visibility: auto`](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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`contain-intrinsic-width`](contain-intrinsic-width): `none` * [`contain-intrinsic-height`](contain-intrinsic-height): `none` | | Applies to | elements for which size containment can apply | | [Inherited](inheritance) | no | | Percentages | as each of the properties of the shorthand:* [`contain-intrinsic-width`](contain-intrinsic-width): no * [`contain-intrinsic-height`](contain-intrinsic-height): no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`contain-intrinsic-width`](contain-intrinsic-width): as specified, with <length>s values computed * [`contain-intrinsic-height`](contain-intrinsic-height): as specified, with <length>s values computed | | Animation type | as each of the properties of the shorthand:* [`contain-intrinsic-width`](contain-intrinsic-width): by computed value type * [`contain-intrinsic-height`](contain-intrinsic-height): by computed value type | Formal syntax ------------- ``` contain-intrinsic-size = [[](value_definition_syntax#brackets) none [|](value_definition_syntax#single_bar) [<length>](length) [|](value_definition_syntax#single_bar) auto [<length>](length) []](value_definition_syntax#brackets)[{1,2}](value_definition_syntax#curly_braces) ``` Examples -------- ### Setting the intrinsic size This example provides selection lists that can be used to modify `contain-intrinsic-size`, `content-visibility` and `contain` on an element in order to observe the effect of the different settings. #### CSS ``` #contained\_element { border: 2px solid green; width: 120px; } .child\_element { border: 1px solid red; background: blue; height: 50px; width: 150px; } ``` #### JavaScript The code below adds styles to, and removes styles from, the containing element based on the selected options. ``` const containedElement = document.querySelector("#contained\_element"); const intrinsicSizeSelector = document.querySelector( "#contain\_intrinsic\_size\_selector" ); const containSelector = document.querySelector("#contain\_selector"); const contentVisibilitySelector = document.querySelector( "#content\_visibility\_selector" ); containedElement.style["contain-intrinsic-size"] = intrinsicSizeSelector.options[intrinsicSizeSelector.selectedIndex].text; containedElement.style["contain"] = containSelector.options[containSelector.selectedIndex].text; containedElement.style["content-visibility"] = contentVisibilitySelector.options[ contentVisibilitySelector.selectedIndex ].text; intrinsicSizeSelector.addEventListener("change", () => { containedElement.style["contain-intrinsic-size"] = intrinsicSizeSelector.options[intrinsicSizeSelector.selectedIndex].text; }); containSelector.addEventListener("change", () => { containedElement.style["contain"] = containSelector.options[containSelector.selectedIndex].text; }); contentVisibilitySelector.addEventListener("change", () => { containedElement.style["content-visibility"] = contentVisibilitySelector.options[ contentVisibilitySelector.selectedIndex ].text; }); ``` #### HTML The HTML defines two buttons, a container element that is subject to containment via the `content-visibility` property. ``` <p> <label for="contain\_intrinsic\_size\_selector">contain-intrinsic-size:</label> <select id="contain\_intrinsic\_size\_selector"> <option>none</option> <option>40px 130px</option> <option>auto 40px auto 130px</option> </select>;<br/> <label for="contain\_selector">contain:</label> <select id="contain\_selector"> <option>none</option> <option>size</option> <option>strict</option> </select>;<br/> <label for="content\_visibility\_selector">content-visibility:</label> <select id="content\_visibility\_selector"> <option>visible</option> <option>auto</option> <option>hidden</option> </select>; </p> <div id="contained\_element"> <div class="child\_element"></div> </div> ``` #### Result Use the selectors to apply the given styles to the containing `div` element. Note that when `content-visibility` is `visible` or `auto`, changing `contain-intrinsic-size` makes no difference. However if the content is hidden, having a `contain-intrinsic-size` of `none` collapses the parent element as though its child element had no size. Specifications -------------- | Specification | | --- | | [CSS Box Sizing Module Level 4 # propdef-contain-intrinsic-size](https://w3c.github.io/csswg-drafts/css-sizing-4/#propdef-contain-intrinsic-size) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `contain-intrinsic-size` | 83 | 83 | 107 | No | 69 | No | 83 | 83 | 107 | 59 | No | 13.0 | See also -------- * [content-visibility: the new CSS property that boosts your rendering performance](https://web.dev/content-visibility/) (web.dev) * [`contain-intrinsic-block-size`](contain-intrinsic-block-size) * [`contain-intrinsic-inline-size`](contain-intrinsic-inline-size) css scroll-padding scroll-padding ============== The `scroll-padding` [shorthand property](shorthand_properties) sets scroll padding on all sides of an element at once, much like the [`padding`](padding) property does for padding on an element. Try it ------ The `scroll-padding-*` properties define offsets for 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. Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`scroll-padding-bottom`](scroll-padding-bottom) * [`scroll-padding-left`](scroll-padding-left) * [`scroll-padding-right`](scroll-padding-right) * [`scroll-padding-top`](scroll-padding-top) Syntax ------ ``` /\* Keyword values \*/ scroll-padding: auto; /\* <length> values \*/ scroll-padding: 10px; scroll-padding: 1em 0.5em 1em 1em; scroll-padding: 10%; /\* Global values \*/ scroll-padding: inherit; scroll-padding: initial; scroll-padding: revert; scroll-padding: revert-layer; scroll-padding: unset; ``` ### Values [`<length-percentage>`](length-percentage) An inwards offset from the corresponding edge of the scrollport, as a valid [`<length>`](length) or a [`<percentage>`](percentage). `auto` The offset is determined by the user agent. This will generally be `0px`, but the user agent is free to detect and do something else if a non-zero value is more appropriate. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`scroll-padding-bottom`](scroll-padding-bottom): `auto` * [`scroll-padding-left`](scroll-padding-left): `auto` * [`scroll-padding-right`](scroll-padding-right): `auto` * [`scroll-padding-top`](scroll-padding-top): `auto` | | Applies to | scroll containers | | [Inherited](inheritance) | no | | Percentages | relative to the scroll container's scrollport | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`scroll-padding-bottom`](scroll-padding-bottom): as specified * [`scroll-padding-left`](scroll-padding-left): as specified * [`scroll-padding-right`](scroll-padding-right): as specified * [`scroll-padding-top`](scroll-padding-top): as specified | | Animation type | by computed value type | Formal syntax ------------- ``` scroll-padding = [[](value_definition_syntax#brackets) auto [|](value_definition_syntax#single_bar) [<length-percentage [0,∞]>](length-percentage) []](value_definition_syntax#brackets)[{1,4}](value_definition_syntax#curly_braces) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Specifications -------------- | Specification | | --- | | [CSS Scroll Snap Module Level 1 # scroll-padding](https://w3c.github.io/csswg-drafts/css-scroll-snap/#scroll-padding) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scroll-padding` | 69 | 79 | 68 | No | 56 | 14.1 11-14.1 Scroll padding is not applied for scrolls to fragment target or `scrollIntoView()`, see [bug 179379](https://webkit.org/b/179379). | 69 | 69 | 68 | 48 | 14.5 11-14.5 Scroll padding is not applied for scrolls to fragment target or `scrollIntoView()`, see [bug 179379](https://webkit.org/b/179379). | 10.0 | See also -------- * [CSS Scroll Snap](css_scroll_snap) * [Well-Controlled Scrolling with CSS Scroll Snap](https://web.dev/css-scroll-snap/) css CSS Custom Properties for Cascading Variables CSS Custom Properties for Cascading Variables ============================================= **CSS Custom Properties for Cascading Variables** is a [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) module that allows for the creation of custom properties that can be used over and over. Reference --------- ### Properties * [`--*`](--*) Specifications -------------- | Specification | | --- | | [CSS Custom Properties for Cascading Variables Module Level 1](https://drafts.csswg.org/css-variables/) | css border-inline-start-color border-inline-start-color ========================= The `border-inline-start-color` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the color of the logical inline start border of an element, which maps to a physical border color depending on the element's writing mode, directionality, and text orientation. It corresponds to the [`border-top-color`](border-top-color), [`border-right-color`](border-right-color), [`border-bottom-color`](border-bottom-color), or [`border-left-color`](border-left-color) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ Syntax ------ ``` border-inline-start-color: red; border-inline-start-color: #ee4141; /\* Global values \*/ border-inline-start-color: inherit; border-inline-start-color: initial; border-inline-start-color: revert; border-inline-start-color: revert-layer; border-inline-start-color: unset; ``` Related properties are [`border-block-start-color`](border-block-start-color), [`border-block-end-color`](border-block-end-color), and [`border-inline-end-color`](border-inline-end-color), which define the other border colors of the element. ### Values `<'color'>` The color of the border. See [`color`](color). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `currentcolor` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | computed color | | Animation type | a [color](color_value#interpolation) | Formal syntax ------------- ``` border-inline-start-color = <'border-top-color'> ``` Examples -------- ### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` ### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; border: 10px solid blue; border-inline-start-color: red; } ``` Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # border-color](https://w3c.github.io/csswg-drafts/css-logical/#border-color) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-inline-start-color` | 69 | 79 | 41 3 | No | 56 | 12.1 | 69 | 69 | 41 4 | 48 | 12.2 | 10.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * This property maps to one of the physical border properties: [`border-top-color`](border-top-color), [`border-right-color`](border-right-color), [`border-bottom-color`](border-bottom-color), and [`border-left-color`](border-left-color) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css :invalid :invalid ======== The `:invalid` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) represents any [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form), [`<fieldset>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/fieldset), [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) or other [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form) element whose contents fail to [validate](https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation). Try it ------ This pseudo-class is useful for highlighting field errors for the user. Syntax ------ ``` :invalid ``` Examples -------- ### Coloring elements to show validation #### HTML ``` <form> <div class="field"> <label for="url\_input">Enter a URL:</label> <input type="url" id="url\_input" /> </div> <div class="field"> <label for="email\_input">Enter an email address:</label> <input type="email" id="email\_input" required /> </div> </form> ``` #### CSS ``` label { display: block; margin: 1px; padding: 1px; } .field { margin: 1px; padding: 1px; } input:invalid { background-color: #ffdddd; } form:invalid { border: 5px solid #ffdddd; } input:valid { background-color: #ddffdd; } form:valid { border: 5px solid #ddffdd; } input:required { border-color: #800000; border-width: 3px; } input:required:invalid { border-color: #c00000; } ``` #### Result ### Showing sections in stages In this example we use `:invalid` along with `~`, the [general sibling combinator](general_sibling_combinator), to make a form appear in stages, so the form initially shows the first item to complete, and when the user completes each item the form displays the next one. When the whole form is complete the user can submit it. #### HTML ``` <form> <fieldset> <label for="form-name">Name</label><br /> <input type="text" name="name" id="form-name" required /> </fieldset> <fieldset> <label for="form-email">Email Address</label><br /> <input type="email" name="email" id="form-email" required /> </fieldset> <fieldset> <label for="form-message">Message</label><br /> <textarea name="message" id="form-message" required></textarea> </fieldset> <button type="submit" name="send">Submit</button> </form> ``` #### CSS ``` /\* Hide the fieldset after an invalid fieldset \*/ fieldset:invalid ~ fieldset { display: none; } /\* Dim and disable the button while the form is invalid \*/ form:invalid button { opacity: 0.3; pointer-events: none; } input, textarea { box-sizing: border-box; width: 100%; font-family: monospace; padding: 0.25em 0.5em; } button { width: 100%; border: thin solid darkgrey; font-size: 1.25em; background-color: darkgrey; color: white; } ``` #### Result Accessibility concerns ---------------------- The color red is commonly used to indicate invalid input. People who have certain types of color blindness will be unable to determine the input's state unless it is accompanied by an additional indicator that does not rely on color to convey meaning. Typically, descriptive text and/or an icon are used. * [MDN Understanding WCAG, Guideline 1.4 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background) * [Understanding Success Criterion 1.4.1 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-without-color.html) Notes ----- ### Radio buttons If any one of the radio buttons in a group is `required`, the `:invalid` pseudo-class is applied to all of them if none of the buttons in the group is selected. (Grouped radio buttons share the same value for their `name` attribute.) ### Gecko defaults By default, Gecko does not apply a style to the `:invalid` pseudo-class. However, it does apply a style (a red "glow" using the [`box-shadow`](box-shadow) property) to the [`:user-invalid`](:user-invalid) pseudo-class, which applies in a subset of cases for `:invalid`. Specifications -------------- | Specification | | --- | | [HTML Standard # selector-invalid](https://html.spec.whatwg.org/multipage/semantics-other.html#selector-invalid) | | [Selectors Level 4 # validity-pseudos](https://w3c.github.io/csswg-drafts/selectors/#validity-pseudos) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:invalid` | 10 | 12 | 4 | 10 | 10 | 5 | 37 | 18 | 4 | 10.1 | 5 | 1.0 | | `form` | 40 | 79 | 13 | No | 27 | 9 | 40 | 40 | 14 | 27 | 9 | 4.0 | See also -------- * Other validation-related pseudo-classes: [`:required`](:required), [`:optional`](:optional), [`:valid`](:valid) * Related Mozilla pseudo-classes: [`:user-invalid`](:user-invalid), [`:-moz-submit-invalid`](:-moz-submit-invalid) * [Form data validation](https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation) * Accessing the [validity state](https://developer.mozilla.org/en-US/docs/Web/API/ValidityState) from JavaScript
programming_docs
css border-inline-end border-inline-end ================= The `border-inline-end` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property is a [shorthand property](shorthand_properties) for setting the individual logical inline-end border property values in a single place in the style sheet. Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`border-inline-end-color`](border-inline-end-color) * [`border-inline-end-style`](border-inline-end-style) * [`border-inline-end-width`](border-inline-end-width) Syntax ------ ``` border-inline-end: 1px; border-inline-end: 2px dashed; border-inline-end: medium dashed blue; /\* Global values \*/ border-inline-end: inherit; border-inline-end: initial; border-inline-end: revert; border-inline-end: revert-layer; border-inline-end: unset; ``` The physical border to which `border-inline-end` maps depends on the element's writing mode, directionality, and text orientation. It corresponds to the [`border-top`](border-top), [`border-right`](border-right), [`border-bottom`](border-bottom), or [`border-left`](border-left) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Related properties are [`border-block-start`](border-block-start), [`border-block-end`](border-block-end), and [`border-inline-start`](border-inline-start), which define the other borders of the element. ### Values The `border-inline-end` is specified with one or more of the following, in any order: `<'border-width'>` The width of the border. See [`border-width`](border-width). `<'border-style'>` The line style of the border. See [`border-style`](border-style). `<'color'>` The color of the border. See [`color`](color). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`border-width`](border-width): as each of the properties of the shorthand: + [`border-top-width`](border-top-width): `medium` + [`border-right-width`](border-right-width): `medium` + [`border-bottom-width`](border-bottom-width): `medium` + [`border-left-width`](border-left-width): `medium` * [`border-style`](border-style): as each of the properties of the shorthand: + [`border-top-style`](border-top-style): `none` + [`border-right-style`](border-right-style): `none` + [`border-bottom-style`](border-bottom-style): `none` + [`border-left-style`](border-left-style): `none` * [`color`](color): `canvastext` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`border-width`](border-width): as each of the properties of the shorthand: + [`border-bottom-width`](border-bottom-width): the absolute length or `0` if [`border-bottom-style`](border-bottom-style) is `none` or `hidden` + [`border-left-width`](border-left-width): the absolute length or `0` if [`border-left-style`](border-left-style) is `none` or `hidden` + [`border-right-width`](border-right-width): the absolute length or `0` if [`border-right-style`](border-right-style) is `none` or `hidden` + [`border-top-width`](border-top-width): the absolute length or `0` if [`border-top-style`](border-top-style) is `none` or `hidden` * [`border-style`](border-style): as each of the properties of the shorthand: + [`border-bottom-style`](border-bottom-style): as specified + [`border-left-style`](border-left-style): as specified + [`border-right-style`](border-right-style): as specified + [`border-top-style`](border-top-style): as specified * [`border-inline-end-color`](border-inline-end-color): computed color | | Animation type | as each of the properties of the shorthand:* [`border-inline-end-color`](border-inline-end-color): a [color](color_value#interpolation) * [`border-inline-end-style`](border-inline-end-style): discrete * [`border-inline-end-width`](border-inline-end-width): a [length](length#interpolation) | Formal syntax ------------- ``` border-inline-end = <'border-top-width'> [||](value_definition_syntax#double_bar) <'border-top-style'> [||](value_definition_syntax#double_bar) [<color>](color_value) ``` Examples -------- ### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` ### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-rl; border-inline-end: 5px dashed blue; } ``` Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # border-shorthands](https://w3c.github.io/csswg-drafts/css-logical/#border-shorthands) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-inline-end` | 69 | 79 | 41 | No | 56 | 12.1 | 69 | 69 | 41 | 48 | 12.2 | 10.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * This property maps to one of the physical border properties: [`border-top`](border-top), [`border-right`](border-right), [`border-bottom`](border-bottom), or [`border-left`](border-left). * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css :indeterminate :indeterminate ============== The `:indeterminate` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) represents any form element whose state is indeterminate, such as checkboxes which have their HTML [`indeterminate`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#indeterminate) attribute set to `true`, radio buttons which are members of a group in which all radio buttons are unchecked, and indeterminate [`<progress>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress) elements. ``` /\* Selects any <input> whose state is indeterminate \*/ input:indeterminate { background: lime; } ``` Elements targeted by this selector are: * [`<input type="checkbox">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox) elements whose `indeterminate` property is set to `true` by [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript) * [`<input type="radio">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio) elements, when all radio buttons with the same `name` value in the form are unchecked * [`<progress>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress) elements in an indeterminate state Syntax ------ ``` :indeterminate ``` Examples -------- ### Checkbox & radio button This example applies special styles to the labels associated with indeterminate form fields. #### HTML ``` <fieldset> <legend>Checkbox</legend> <div> <input type="checkbox" id="checkbox" /> <label for="checkbox">This checkbox label starts out lime.</label> </div> </fieldset> <fieldset> <legend>Radio</legend> <div> <input type="radio" id="radio1" name="radioButton" value="val1" /> <label for="radio1">First radio label starts out lime.</label> </div> <div> <input type="radio" id="radio2" name="radioButton" value="val2" /> <label for="radio2">Second radio label also starts out lime.</label> </div> </fieldset> ``` #### CSS ``` input:indeterminate + label { background: lime; } ``` #### JavaScript ``` const inputs = document.getElementsByTagName("input"); for (let i = 0; i < inputs.length; i++) { inputs[i].indeterminate = true; } ``` #### Result ### Progress bar #### HTML ``` <progress></progress> ``` #### CSS ``` progress { margin: 4px; } progress:indeterminate { width: 80vw; height: 20px; } ``` #### Result Specifications -------------- | Specification | | --- | | [HTML Standard # selector-indeterminate](https://html.spec.whatwg.org/multipage/semantics-other.html#selector-indeterminate) | | [Selectors Level 4 # indeterminate](https://w3c.github.io/csswg-drafts/selectors/#indeterminate) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:indeterminate` | 1 | 12 | 2 | 10 | 9 | 3 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | | `checkbox` | 1 | 12 | 3.6 | 10 | 10.6 | 3 | ≤37 | 18 | 4 | 11 | 1 | 1.0 | | `progress` | 6 | 12 | 6 | 10 | 15 | 5.1 | 37 | 18 | 6 | 14 | 5 | 1.0 | | `radio` | 39 | 79 | 51 | No | 26 | No See [WebKit bug 156270](https://webkit.org/b/156270). | 39 | 39 | 51 | 26 | No See [WebKit bug 156270](https://webkit.org/b/156270). | 4.0 | See also -------- * [Web forms — Working with user data](https://developer.mozilla.org/en-US/docs/Learn/Forms) * [Styling web forms](https://developer.mozilla.org/en-US/docs/Learn/Forms/Styling_web_forms) * The [`<input type="checkbox">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox) element's [`indeterminate`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#indeterminate) attribute * [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) and the [`HTMLInputElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) interface which implements it. * The [`:checked`](:checked) CSS selector lets you style checkboxes based on whether they're checked or not css min-width min-width ========= The `min-width` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the minimum width of an element. It prevents the [used value](used_value) of the [`width`](width) property from becoming smaller than the value specified for `min-width`. Try it ------ The element's width is set to the value of `min-width` whenever `min-width` is larger than [`max-width`](max-width) or [`width`](width). Syntax ------ ``` /\* <length> value \*/ min-width: 3.5em; /\* <percentage> value \*/ min-width: 10%; /\* Keyword values \*/ min-width: max-content; min-width: min-content; min-width: fit-content(20em); /\* Global values \*/ min-width: inherit; min-width: initial; min-width: revert; min-width: revert-layer; min-width: unset; ``` ### Values [`<length>`](length) Defines the `min-width` as an absolute value. [`<percentage>`](percentage) Defines the `min-width` as a percentage of the containing block's width. `auto` The browser will calculate and select a `min-width` for the specified element. `max-content` The intrinsic preferred `min-width`. `min-content` The intrinsic minimum `min-width`. `fit-content([`<length-percentage>`](length-percentage))` Uses the `fit-content` formula with the available space replaced by the specified argument, i.e. `min(max-content, max(min-content, argument))`. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | all elements but non-replaced inline elements, table rows, and row groups | | [Inherited](inheritance) | no | | Percentages | refer to the width of the containing block | | [Computed value](computed_value) | the percentage as specified or the absolute length | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` min-width = auto [|](value_definition_syntax#single_bar) [<length-percentage [0,∞]>](length-percentage) [|](value_definition_syntax#single_bar) min-content [|](value_definition_syntax#single_bar) max-content [|](value_definition_syntax#single_bar) fit-content( [<length-percentage [0,∞]>](length-percentage) ) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Setting minimum element width ``` table { min-width: 75%; } form { min-width: 0; } ``` Specifications -------------- | Specification | | --- | | [CSS Box Sizing Module Level 3 # min-size-properties](https://w3c.github.io/csswg-drafts/css-sizing/#min-size-properties) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `min-width` | 1 | 12 | 1 CSS 2.1 leaves the behavior of `min-width` with [`table`](https://developer.mozilla.org/docs/Web/HTML/Element/table) undefined. Firefox supports applying `min-width` to `table` elements. | 7 | 4 CSS 2.1 leaves the behavior of `min-width` with [`table`](https://developer.mozilla.org/docs/Web/HTML/Element/table) undefined. Opera supports applying `min-width` to `table` elements. | 1 | 4.4 | 18 | 4 CSS 2.1 leaves the behavior of `min-width` with [`table`](https://developer.mozilla.org/docs/Web/HTML/Element/table) undefined. Firefox supports applying `min-width` to `table` elements. | 10.1 | 1 | 1.0 | | `auto` | 21 Chrome uses `auto` as the initial value for `min-width`. | 12 Edge uses `auto` as the initial value for `min-width`. | 34 16-22 Firefox 18 and later (until the value was removed), used `auto` as the initial value for `min-width`. | No | 12.1 Opera uses `auto` as the initial value for `min-width`. | 7 | 37 Chrome uses `auto` as the initial value for `min-width`. | 25 Chrome uses `auto` as the initial value for `min-width`. | 34 16-22 Firefox 18 and later (until the value was removed), used `auto` as the initial value for `min-width`. | 14 Opera uses `auto` as the initial value for `min-width`. | 7 | 1.5 Samsung Internet uses `auto` as the initial value for `min-width`. | | `fit-content` | 46 25 | 79 79 | 3 Firefox implements the definitions given in CSS3 Basic Box. This defines `available` and not `fit-available`. Also, the definition of `fit-content` is simpler than in CSS3 Sizing. | No | 33 15 | 11 7 | 46 ≤37 | 46 | 4 Firefox implements the definitions given in CSS3 Basic Box. This defines `available` and not `fit-available`. Also, the definition of `fit-content` is simpler than in CSS3 Sizing. | 33 | 11 7 | 5.0 | | `fit-content_function` | No | No | 91 | No | No | No | No | No | No | No | No | No | | `max-content` | 46 25 | 79 79 | 66 3 | No | 33 15 | 11 2 | 46 ≤37 | 46 | 66 4 | 33 | 11 1 | 5.0 | | `min-content` | 46 25 25-48 | 79 79 | 66 3 | No | 33 ≤15 ≤15-35 | 11 2 | 46 4.4 4.4-48 | 46 25 25-48 | 66 4 | 33 ≤14 ≤14-35 | 11 1 | 5.0 1.5 1.5-5.0 | | `stretch` | 22 | 79 | No | No | 15 | No | 4.4 | 25 | No | 14 | No | 1.5 | See also -------- * [`width`](width), [`max-width`](max-width) * The [box model](css_box_model/introduction_to_the_css_box_model), [`box-sizing`](box-sizing) css orphans orphans ======= The `orphans` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the minimum number of lines in a block container that must be shown at the *bottom* of a [page](https://developer.mozilla.org/en-US/docs/Web/CSS/Paged_Media), region, or [column](css_columns). ``` /\* <integer> values \*/ orphans: 2; orphans: 3; /\* Global values \*/ orphans: inherit; orphans: initial; orphans: revert; orphans: revert-layer; orphans: unset; ``` In typography, an *orphan* is the first line of a paragraph that appears alone at the bottom of a page. (The paragraph continues on a following page.) Syntax ------ ### Values [`<integer>`](integer) The minimum number of lines that can stay by themselves at the bottom of a fragment before a fragmentation break. The value must be positive. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `2` | | Applies to | block container elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` orphans = [<integer [0,∞]>](integer) ``` Examples -------- ### Setting a minimum orphan size of three lines #### HTML ``` <div> <p>This is the first paragraph containing some text.</p> <p> This is the second paragraph containing some more text than the first one. It is used to demonstrate how orphans work. </p> <p> This is the third paragraph. It has a little bit more text than the first one. </p> </div> ``` #### CSS ``` div { background-color: #8cffa0; height: 150px; columns: 3; orphans: 3; } p { background-color: #8ca0ff; } p:first-child { margin-top: 0; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Fragmentation Module Level 3 # widows-orphans](https://w3c.github.io/csswg-drafts/css-break/#widows-orphans) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `orphans` | 25 | 12 | No | 8 | 9.2 | 1.3 | 4.4 | 25 | No | 14 | 1 | 1.5 | See also -------- * [`widows`](widows) * [Paged media](https://developer.mozilla.org/en-US/docs/Web/CSS/Paged_Media) css <resolution> <resolution> ============ The `<resolution>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types), used for describing [resolutions](@media/resolution) in [media queries](media_queries), denotes the pixel density of an output device, i.e., its resolution. On screens, the units are related to *CSS* inches, centimeters, or pixels, not physical values. Syntax ------ The `<resolution>` data type consists of a strictly positive [`<number>`](number) followed by one of the units listed below. As with all CSS dimensions, there is no space between the unit literal and the number. ### Units `dpi` Represents the number of [dots per inch](https://en.wikipedia.org/wiki/Dots_per_inch). Screens typically contains 72 or 96 dots per inch, but the dpi for printed documents is usually much greater. As 1 inch is 2.54 cm, `1dpi ≈ 0.39dpcm`. `dpcm` Represents the number of [dots per centimeter](https://en.wikipedia.org/wiki/Dots_per_inch). As 1 inch is 2.54 cm, `1dpcm ≈ 2.54dpi`. `dppx` Represents the number of dots per [`px`](length#px) unit. Due to the 1:96 fixed ratio of CSS `in` to CSS `px`, `1dppx` is equivalent to `96dpi`, which corresponds to the default resolution of images displayed in CSS as defined by [`image-resolution`](image-resolution). `x` Alias for `dppx`. **Note:** Although the number `0` is always the same regardless of unit, the unit may not be omitted. In other words, `0` is invalid and does not represent `0dpi`, `0dpcm`, or `0dppx`. Examples -------- ### Use in a media query ``` @media print and (min-resolution: 300dpi) { /\* … \*/ } ``` ### Valid resolutions ``` 96dpi 50.82dpcm 3dppx ``` ### Invalid resolutions ``` 72 dpi Spaces are not allowed between the number and the unit. ten dpi The number must use digits only. 0 The unit is required. ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # resolution](https://w3c.github.io/csswg-drafts/css-values/#resolution) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `resolution` | 29 | 12 | 8 3.5 Supports [`<integer>`](https://developer.mozilla.org/docs/Web/CSS/integer) values only. | 9 | 9.5 | No See [bug 78087](https://webkit.org/b/78087). | 4.4 | 29 | 8 4 Supports [`<integer>`](https://developer.mozilla.org/docs/Web/CSS/integer) values only. | 10.1 | No See [bug 78087](https://webkit.org/b/78087). | 2.0 | | `dpcm` | 29 | 12 | 8 | 9 | 16 10-15 | No | 4.4 | 29 | 8 | 16 10.1-14 | No | 2.0 | | `dpi` | 29 | 12 | 8 | 9 | 16 10-15 | No | 4.4 | 29 | 8 | 16 10.1-14 | No | 2.0 | | `dppx` | 29 | 12 | 16 | No | 12.1 | No | 4.4 | 29 | 16 | 12.1 | No | 2.0 | | `x` | 68 | 79 | 62 | No | 55 | No | 68 | 68 | 62 | 48 | No | 10.0 | See also -------- * [resolution](@media/resolution) media feature * The [`image-resolution`](image-resolution) property * [Using @media queries](media_queries/using_media_queries)
programming_docs
css column-span column-span =========== The `column-span` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property makes it possible for an element to span across all columns when its value is set to `all`. Try it ------ ``` /\* Keyword values \*/ column-span: none; column-span: all; /\* Global values \*/ column-span: inherit; column-span: initial; column-span: revert; column-span: revert-layer; column-span: unset; ``` An element that spans more than one column is called a **spanning element**. Syntax ------ The `column-span` property is specified as one of the keyword values listed below. ### Values `none` The element does not span multiple columns. `all` The element spans across all columns. Content in the normal flow that appears before the element is automatically balanced across all columns before the element appears. The element establishes a new block formatting context. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | in-flow block-level elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` column-span = none [|](value_definition_syntax#single_bar) all ``` Examples -------- ### Making a heading span columns In this example, the heading is made to span across all the columns of the article. #### HTML ``` <article> <h2>Header spanning all of the columns</h2> <p> The h2 should span all the columns. The rest of the text should be distributed among the columns. </p> <p> This is a bunch of text split into three columns using the CSS `columns` property. The text is equally distributed over the columns. </p> <p> This is a bunch of text split into three columns using the CSS `columns` property. The text is equally distributed over the columns. </p> <p> This is a bunch of text split into three columns using the CSS `columns` property. The text is equally distributed over the columns. </p> <p> This is a bunch of text split into three columns using the CSS `columns` property. The text is equally distributed over the columns. </p> </article> ``` #### CSS ``` article { columns: 3; } h2 { column-span: all; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Multi-column Layout Module Level 1 # column-span](https://w3c.github.io/csswg-drafts/css-multicol/#column-span) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `column-span` | 50 6 | 12 12 | 71 | 10 | 15 11.1 | 9 5.1 | 50 ≤37 | 50 18 | 79 | 14 11.1 | 9 5 | 5.0 1.0 | See also -------- * [Inline elements](https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements) * [`HTMLSpanElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLSpanElement) css max() max() ===== The `max()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](css_functions) lets you set the largest (most positive) value from a list of comma-separated expressions as the value of a CSS property value. The `max()` function can be used anywhere a [`<length>`](length), [`<frequency>`](frequency), [`<angle>`](angle), [`<time>`](time), [`<percentage>`](percentage), [`<number>`](number), or [`<integer>`](integer) is allowed. Try it ------ In the first above example, the width will be at least 400px, but will be wider if the viewport is more than 2000px wide (in which case 1vw would be 20px, so 20vw would be 400px). Think of the `max()` value as providing the *minimum* value a property can have. Syntax ------ The `max()` function takes one or more comma-separated expressions as its parameter, with the largest (most positive) expression value used as the value of the property to which it is assigned. The expressions can be math expressions (using arithmetic operators), literal values, or other expressions, such as [`attr()`](attr), that evaluate to a valid argument type (like [`<length>`](length)), or nested [`min()`](min) and `max()` functions. You can use different units for each value in your expression. You may also use parentheses to establish computation order when needed. ### Notes * 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 `min()` and other `max()` functions as expression values. The expressions are full math expressions, so you can use direct addition, subtraction, multiplication and division without using the calc() function itself. * The expression can be values combining the addition ( + ), subtraction ( - ), multiplication ( \* ) and division ( / ) operators, using standard operator precedence rules. Make sure to put a space on each side of the + and - operands. The operands in the expression may be any <length> syntax value. * You can (and often need to) combine `min()` and `max()` values, or use `max()` within a `clamp()` or `calc()` function. ### Formal syntax ``` <max()> = max( <calc-sum>[#](value_definition_syntax#hash_mark) ) <calc-sum> = <calc-product> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '+' [|](value_definition_syntax#single_bar) '-' []](value_definition_syntax#brackets) <calc-product> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-product> = <calc-value> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '*' [|](value_definition_syntax#single_bar) '/' []](value_definition_syntax#brackets) <calc-value> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-value> = [<number>](number) [|](value_definition_syntax#single_bar) [<dimension>](dimension) [|](value_definition_syntax#single_bar) [<percentage>](percentage) [|](value_definition_syntax#single_bar) <calc-constant> [|](value_definition_syntax#single_bar) ( <calc-sum> ) <calc-constant> = e [|](value_definition_syntax#single_bar) pi [|](value_definition_syntax#single_bar) infinity [|](value_definition_syntax#single_bar) -infinity [|](value_definition_syntax#single_bar) NaN ``` Examples -------- ### Setting a minimum size for a font Another use case for CSS functions is allow a font size to grow while ensuring it is at least a minimum size, enabling responsive font sizes while ensuring legibility. Let's look at some CSS: ``` h1 { font-size: 2rem; } h1.responsive { font-size: max(4vw, 2em, 2rem); } ``` The font-size will at minimum be 2rems, or twice the default size of font for the page. This ensure it is legible and ensures accessibility ``` <h1>This text is always legible, but doesn't change size</h1> <h1 class="responsive"> This text is always legible, and is responsive, to a point </h1> ``` Think of the `max()` function as finding the minimum value allowed for a property. Accessibility concerns ---------------------- When `max()` is used for controlling text size, make sure the text is always large enough to read. A suggestion is to use the [`min()`](min) function nested within a `max()` that has as its second value a [relative length unit](length#relative_length_units) that is always large enough to read. For example: ``` small { font-size: max(min(0.5vw, 0.5em), 1rem); } ``` This ensures a minimum size of *1rem*, with a text size that scales if the page is zoomed. * [MDN Understanding WCAG, Guideline 1.4 explanations](https://developer.mozilla.org/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) Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # calc-notation](https://w3c.github.io/csswg-drafts/css-values/#calc-notation) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `max` | 79 | 79 | 75 | No | 66 | 11.1 | 79 | 79 | 79 | 57 | 11.3 | 12.0 | See also -------- * [`calc()`](calc) * [`clamp()`](clamp) * [`min()`](min) * [CSS Values](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units) css mask-composite mask-composite ============== The `mask-composite` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property represents a compositing operation used on the current mask layer with the mask layers below it. ``` /\* Keyword values \*/ mask-composite: add; mask-composite: subtract; mask-composite: intersect; mask-composite: exclude; /\* Global values \*/ mask-composite: inherit; mask-composite: initial; mask-composite: revert; mask-composite: revert-layer; mask-composite: unset; ``` Syntax ------ One or more of the keyword values listed below, separated by commas. ### Values For the composition the current mask layer is referred to as *source*, while all layers below it are referred to as *destination*. `add` The source is placed over the destination. `subtract` The source is placed, where it falls outside of the destination. `intersect` The parts of source that overlap the destination, replace the destination. `exclude` The non-overlapping regions of source and destination are combined. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `add` | | Applies to | all elements; In SVG, it applies to container elements excluding the [`<defs>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs) element and all graphics elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` mask-composite = <compositing-operator>[#](value_definition_syntax#hash_mark) <compositing-operator> = add [|](value_definition_syntax#single_bar) subtract [|](value_definition_syntax#single_bar) intersect [|](value_definition_syntax#single_bar) exclude ``` Examples -------- ### Compositing mask layers with addition Specifications -------------- | Specification | | --- | | [CSS Masking Module Level 1 # the-mask-composite](https://drafts.fxtf.org/css-masking/#the-mask-composite) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `mask-composite` | No See also [`-webkit-mask-composite`](https://developer.mozilla.org/docs/Web/CSS/-webkit-mask-composite) for a similar non-standard property that uses different keywords. | 18-79 | 53 | No | No See also [`-webkit-mask-composite`](https://developer.mozilla.org/docs/Web/CSS/-webkit-mask-composite) for a similar non-standard property that uses different keywords. | 15.4 See also [`-webkit-mask-composite`](https://developer.mozilla.org/docs/Web/CSS/-webkit-mask-composite) for a similar non-standard property that uses different keywords. | No See also [`-webkit-mask-composite`](https://developer.mozilla.org/docs/Web/CSS/-webkit-mask-composite) for a similar non-standard property that uses different keywords. | No See also [`-webkit-mask-composite`](https://developer.mozilla.org/docs/Web/CSS/-webkit-mask-composite) for a similar non-standard property that uses different keywords. | 53 | No See also [`-webkit-mask-composite`](https://developer.mozilla.org/docs/Web/CSS/-webkit-mask-composite) for a similar non-standard property that uses different keywords. | 15.4 See also [`-webkit-mask-composite`](https://developer.mozilla.org/docs/Web/CSS/-webkit-mask-composite) for a similar non-standard property that uses different keywords. | No See also [`-webkit-mask-composite`](https://developer.mozilla.org/docs/Web/CSS/-webkit-mask-composite) for a similar non-standard property that uses different keywords. | See also -------- * [Clipping and Masking in CSS](https://css-tricks.com/clipping-masking-css/) css scroll-snap-stop scroll-snap-stop ================ The `scroll-snap-stop` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines whether or not the scroll container is allowed to "pass over" possible snap positions. Try it ------ Syntax ------ ``` /\* Keyword values \*/ scroll-snap-stop: normal; scroll-snap-stop: always; /\* Global values \*/ scroll-snap-stop: inherit; scroll-snap-stop: initial; scroll-snap-stop: revert; scroll-snap-stop: revert-layer; scroll-snap-stop: unset; ``` ### Values `normal` When the visual [viewport](https://developer.mozilla.org/en-US/docs/Glossary/Viewport) of this element's scroll container is scrolled, it may "pass over" possible snap positions. `always` The scroll container must not "pass over" a possible snap position; and must snap to the first of this elements' snap positions. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` scroll-snap-stop = normal [|](value_definition_syntax#single_bar) always ``` Examples -------- ### Setting different snap stops The example below demonstrates the contrast between the `always` and `normal` values of `scroll-snap-stop`. The difference in the two `scroll-snap-stop` values is more noticeable when the `scroll-snap-type` property is set to `mandatory`, which is what is used in this example. #### HTML ``` <p>scroll-snap-stop: always (X Mandatory)</p> <div class="x mandatory-scroll-snapping always-stop"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div> <p>scroll-snap-stop: always (X Mandatory) on odd child elements</p> <div class="x mandatory-scroll-snapping always-stop-odd"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div> <p>scroll-snap-stop: always (X Mandatory) on even child elements</p> <div class="x mandatory-scroll-snapping always-stop-even"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div> <p>scroll-snap-stop: normal (X Mandatory)</p> <div class="x mandatory-scroll-snapping normal-stop"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div> <p>scroll-snap-stop: always (Y Mandatory)</p> <div class="y mandatory-scroll-snapping always-stop"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div> <p>scroll-snap-stop: normal (Y Mandatory)</p> <div class="y mandatory-scroll-snapping normal-stop"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div> ``` #### CSS ``` /\* setting up mandatory scroll-snap on parent \*/ .x.mandatory-scroll-snapping { scroll-snap-type: x mandatory; } .y.mandatory-scroll-snapping { scroll-snap-type: y mandatory; } /\* defining scroll-snap alignment on children \*/ div > div { scroll-snap-align: center; } /\* defining scroll-snap stop on children \*/ .always-stop > div { scroll-snap-stop: always; } .always-stop-odd > div:nth-of-type(odd) { scroll-snap-stop: always; } .always-stop-even > div:nth-of-type(even) { scroll-snap-stop: always; } .normal-stop > div { scroll-snap-stop: normal; } ``` #### Result Scroll from left to right and from top to bottom in the X and Y boxes below, respectively. In the X and Y boxes where the `scroll-snap-stop` property is set to `always`, the scrolling is forced to stop at the snap point even when you scroll fast. However, in the boxes where the `scroll-snap-stop` property is set to `normal`, the snap points are skipped when you scroll fast. If required, you can be selective about the items that are `always` stopped at inside the scroll container. This is demonstrated in the example below by targeting odd and even items; you can choose a different strategy based on your requirement. In the example below, scrolling does not "pass over" odd and even items in the second and third boxes, respectively. Specifications -------------- | Specification | | --- | | [CSS Scroll Snap Module Level 1 # scroll-snap-stop](https://w3c.github.io/csswg-drafts/css-scroll-snap/#scroll-snap-stop) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scroll-snap-stop` | 75 | 79 | 103 | No | 62 | 15 | 75 | 75 | 103 | 54 | 15 | 11.0 | See also -------- * [CSS Scroll Snap](css_scroll_snap) * Other related CSS Scroll Snap properties: + <scroll-snap-align> + <scroll-snap-type> + <scroll-behavior> + <scroll-margin> + <scroll-padding> * [Well-controlled scrolling with CSS Scroll Snap](https://web.dev/css-scroll-snap/) on web.dev css :hover :hover ====== The `:hover` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) matches when the user interacts with an element with a pointing device, but does not necessarily activate it. It is generally triggered when the user hovers over an element with the cursor (mouse pointer). Try it ------ Styles defined by the `:hover` pseudo-class will be overridden by any subsequent link-related pseudo-class ([`:link`](:link), [`:visited`](:visited), or [`:active`](:active)) that has at least equal specificity. To style links appropriately, put the `:hover` rule after the `:link` and `:visited` rules but before the `:active` one, as defined by the *LVHA-order*: `:link` — `:visited` — `:hover` — `:active`. **Note:** The `:hover` pseudo-class is problematic on touchscreens. Depending on the browser, the `:hover` pseudo-class might never match, match only for a moment after touching an element, or continue to match even after the user has stopped touching and until the user touches another element. Web developers should make sure that content is accessible on devices with limited or non-existent hovering capabilities. Syntax ------ ``` :hover ``` Examples -------- ### Basic example #### HTML ``` <a href="#">Try hovering over this link.</a> ``` #### CSS ``` a { background-color: powderblue; transition: background-color 0.5s; } a:hover { background-color: gold; } ``` #### Result Specifications -------------- | Specification | | --- | | [HTML Standard # selector-hover](https://html.spec.whatwg.org/multipage/semantics-other.html#selector-hover) | | [Selectors Level 4 # the-hover-pseudo](https://w3c.github.io/csswg-drafts/selectors/#the-hover-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:hover` | 1 | 12 | 1 | 4 | 4 | 2 | 4.4 | 18 | 4 | 10.1 | 1 As of Safari for iOS 7.1.2, tapping a [clickable element](https://developer.mozilla.org/docs/Web/Events/click#Safari_Mobile) causes the element to enter the `:hover` state. The element will remain in the `:hover` state until a different element has entered the `:hover` state. | 1.0 | | `a_elements` | 1 | 12 | 1 | 4 | 4 | 2 | 37 | 18 | 4 | 10.1 | 1 | 1.0 | | `all_elements` | 1 | 12 In Edge, hovering over an element and then scrolling up or down without moving the pointer will leave the element in the `:hover` state until the pointer is moved. See [bug 5381673](https://developer.microsoft.com/microsoft-edge/platform/issues/5381673/). | 1 | 7 ["In Internet Explorer 8 to Internet Explorer 11, hovering over an element and then scrolling up or down without moving the pointer will leave the element in the `:hover` state until the pointer is moved. See [bug 926665](https://connect.microsoft.com/IE/feedbackdetail/view/926665).", "In Internet Explorer 9 (and possibly earlier), if a [`<table>`](https://developer.mozilla.org/docs/Web/HTML/Element/table) has a parent with a non-`auto` [`width`](https://developer.mozilla.org/docs/Web/CSS/width), [`overflow-x`](https://developer.mozilla.org/docs/Web/CSS/overflow-x)`: auto;`, the [`<table>`](https://developer.mozilla.org/docs/Web/HTML/Element/table) has enough content to horizontally overflow its parent, and there are [`:hover`](https://developer.mozilla.org/docs/Web/CSS/:hover) styles set on elements within the table, then hovering over said elements will cause the [`<table>`](https://developer.mozilla.org/docs/Web/HTML/Element/table)'s height to increase. See [a live demo that triggers the bug](https://output.jsbin.com/diwiqe). One workaround for the bug is to set `min-height: 0%;` (the `%` unit must be specified, since unitless and `px` don't work) on the `<table>`'s parent element."] | 7 | 2 | 37 | 18 | 4 | 10.1 | 1 | 1.0 | | `pseudo_elements` | 1 | 12 | 28 | 11 | 15 | 2 | ≤37 | 18 | 28 | 14 | 1 | 1.0 | See also -------- * [Chromium bug #370155: Don't make `:hover` sticky on tap on sites that set a mobile viewport](https://bugs.chromium.org/p/chromium/issues/detail?id=370155) * [Chromium bug #306581: Immediately show hover and active states on touch when page isn't scrollable.](https://bugs.chromium.org/p/chromium/issues/detail?id=306581)
programming_docs
css env() env() ===== The `env()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](css_functions) can be used to insert the value of a user-agent defined environment variable into your CSS, in a similar fashion to the [`var()`](var()) function and [custom properties](--*). The difference is that, as well as being user-agent defined rather than user-defined, environment variables are globally scoped to a document, whereas custom properties are scoped to the element(s) on which they are declared. In addition, unlike custom properties, which cannot be used outside of declarations, the `env()` function can be used in place of any part of a property value, or any part of a descriptor (e.g. in [Media query rules](@media)). As the spec evolves, it may also be usable in other places such as selectors. Originally provided by the iOS browser to allow developers to place their content in a safe area of the viewport, the `safe-area-inset-*` values defined in the specification can be used to help ensure content is visible even to viewers using non‑rectangular displays. For example, a common issue solved by `env()` is that of device notifications covering up some of the app user interface. By positioning fixed elements using `env()` you can ensure that they display in a safe area of the viewport. Another use case for `env()` variables is for desktop [Progressive web apps](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps) (PWAs) that use the Window Controls Overlay feature to take advantage of the full application window surface area. Using the `titlebar-area-*` values, they can position elements where the title bar would have been and ensure that content stays clear of the window control buttons. Syntax ------ ``` /\* Using the four safe area inset values with no fallback values \*/ env(safe-area-inset-top); env(safe-area-inset-right); env(safe-area-inset-bottom); env(safe-area-inset-left); /\* Using them with fallback values \*/ env(safe-area-inset-top, 20px); env(safe-area-inset-right, 1em); env(safe-area-inset-bottom, 0.5vh); env(safe-area-inset-left, 1.4rem); ``` ### Values `safe-area-inset-top`, `safe-area-inset-right`, `safe-area-inset-bottom`, `safe-area-inset-left` The `safe-area-inset-*` variables are four environment variables that define a rectangle by its top, right, bottom, and left insets from the edge of the viewport, which is safe to put content into without risking it being cut off by the shape of a non‑rectangular display. For rectangular viewports, like your average laptop monitor, their value is equal to zero. For non-rectangular displays — like a round watch face — the four values set by the user agent form a rectangle such that all content inside the rectangle is visible. `titlebar-area-x`, `titlebar-area-y`, `titlebar-area-width`, `titlebar-area-height` The `titlebar-area-*` variables are useful for PWA installed on Desktop devices. When a desktop PWA uses the `window-controls-overlay` [display\_override](https://developer.mozilla.org/en-US/docs/Web/Manifest/display_override) value, then it can use the `titlebar-area-*` variables to make sure content doesn't overlap with the window control buttons (i.e. minimize, maximize, and close). `keyboard-inset-top`, `keyboard-inset-right`, `keyboard-inset-bottom`, `keyboard-inset-left`, `keyboard-inset-width`, `keyboard-inset-height` The `keyboard-inset-*` variables provide information about the on-screen virtual keyboard's appearance. They define a rectangle by its top, right, bottom, and left insets from the edge of the viewport (the width and height insets are calculated from the other insets). To learn more, see the [VirtualKeyboard API](https://developer.mozilla.org/en-US/docs/Web/API/VirtualKeyboard_API). **Note:** Unlike other CSS properties, user agent-defined property names are case-sensitive. ### Formal syntax ``` <env()> = env( [<custom-ident>](custom-ident) [<integer [0,∞]>](integer)[\*](value_definition_syntax#asterisk) , [<declaration-value>](declaration-value)[?](value_definition_syntax#question_mark) ) ``` Usage ----- To tell the browser to use the whole available space on the screen, and so enabling us to use the `env()` variables, we need to add a new viewport meta value: ``` <meta name="viewport" content="viewport-fit=cover" /> ``` You can then use `env()` in your CSS: ``` body { padding: env(safe-area-inset-top, 20px) env(safe-area-inset-right, 20px) env( safe-area-inset-bottom, 20px ) env(safe-area-inset-left, 20px); } ``` Examples -------- ### Using env() to ensure buttons are not obscured by device UI In the following example `env()` is used to ensure that fixed app toolbar buttons are not obscured by device notifications appearing at the bottom of the screen. On the desktop `safe-area-inset-bottom` is `0`. However, in devices that display notifications at the bottom of the screen, such as iOS, it contains a value that leaves space for the notification to display. This can then be used in the value for [`padding-bottom`](padding-bottom) to create a gap that appears natural on that device. ``` <main>Main content of app here</main> <footer> <button>Go here</button> <button>Or here</button> </footer> ``` ``` body { display: flex; flex-direction: column; min-height: 100vh; font: 1em system-ui; } main { flex: 1; background-color: #eee; padding: 1em; } footer { flex: none; display: flex; gap: 1em; justify-content: space-evenly; background: black; padding: 1em 1em calc(1em + env(safe-area-inset-bottom)); /\* adds the safe-area-inset-bottom value to the initial 1em of padding. a larger black area will display for a device that has a positive value for this variable. \*/ position: sticky; bottom: 0; } button { padding: 1em; background: white; color: black; margin: 0; width: 100%; border: none; font: 1em system-ui; } ``` ### Using the fallback value The below example makes use of the optional second parameter of `env()`, which allows you to provide a fallback value in case the environment variable is not available. ``` <p> If the <code>env()</code> function is supported in your browser, this paragraph's text will have 50px of padding between it and the left border — but not the top, right and bottom. This is because the accompanying CSS is the equivalent of <code>padding: 0 0 0 50px</code>, because, unlike other CSS properties, user agent property names are case-sensitive. </p> ``` ``` p { width: 300px; border: 2px solid red; padding: env(safe-area-inset-top, 50px) env(safe-area-inset-right, 50px) env( safe-area-inset-bottom, 50px ) env(SAFE-AREA-INSET-LEFT, 50px); } ``` ### Example values ``` /\* zero for all rectangular user agents \*/ padding: env(safe-area-inset-bottom, 50px); /\* 50px because UA properties are case sensitive \*/ padding: env(safe-area-inset-bottom, 50px); /\* as if padding: '50px 20px' were set because x is not a valid environment variable \*/ padding: env(x, 50px 20px); /\* ignored because '50px, 20px' is not a valid padding value and x is not a valid environment variable \*/ padding: env(x, 50px, 20px); ``` The syntax of the fallback, like that of custom properties, allows commas. But, if the property value doesn't support commas, the value is not valid. **Note:** User agent properties are not reset by the <all> property. ### Using env() to ensure content is not obscured by window control buttons in desktop PWAs In the following example `env()` ensures that content displayed in a desktop Progressive Web App that uses the [Window Controls Overlay API](https://developer.mozilla.org/en-US/docs/Web/API/Window_Controls_Overlay_API) is not obscured by the operating system's window control buttons. The `titlebar-area-*` values define a rectangle where the title bar would normally have been displayed. On devices that do not support the Window Controls Overlay feature, such as mobile devices, the fallback values are used. Here is what a PWA installed on a desktop device normally looks like: With the Window Controls Overlay feature, the web content covers the whole app window surface area, with the window controls and PWA buttons displayed as overlays: ``` <header>Title of the app here</header> <main>Main content of app here</main> ``` ``` header { position: fixed; left: env(titlebar-area-x); top: env(titlebar-area-y); width: env(titlebar-area-width); height: env(titlebar-area-height); } main { margin-top: env(titlebar-area-height); } ``` **Note:** Using `position:fixed` makes sure the header does not scroll with the rest of the content, and instead stays aligned with the window control buttons, even on device/browsers that support elastic overscroll (also known as rubber banding). Specifications -------------- | Specification | | --- | | [CSS Environment Variables Module Level 1 # env-function](https://w3c.github.io/csswg-drafts/css-env/#env-function) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `env` | 69 | 79 | 65 | No | 56 | 11.1 11-11.1 | 69 | 69 | 65 | 48 | 11.3 11-11.3 | 10.0 | | `safe-area-inset-bottom` | 69 | 79 | 65 | No | 56 | 11 | 69 | 69 | 65 | 48 | 11 | 10.0 | | `safe-area-inset-left` | 69 | 79 | 65 | No | 56 | 11 | 69 | 69 | 65 | 48 | 11 | 10.0 | | `safe-area-inset-right` | 69 | 79 | 65 | No | 56 | 11 | 69 | 69 | 65 | 48 | 11 | 10.0 | | `safe-area-inset-top` | 69 | 79 | 65 | No | 56 | 11 | 69 | 69 | 65 | 48 | 11 | 10.0 | | `titlebar-area-height` | 93 92-93 Before version 93, Linux is unsupported. | 93 92-93 Before version 93, Linux is unsupported. | No | No | 78 | No | No | 93 92-93 Before version 93, Linux is unsupported. | No | 65 | No | 17.0 | | `titlebar-area-width` | 93 92-93 Before version 93, Linux is unsupported. | 93 92-93 Before version 93, Linux is unsupported. | No | No | 78 | No | No | 93 92-93 Before version 93, Linux is unsupported. | No | 65 | No | 17.0 | | `titlebar-area-x` | 93 92-93 Before version 93, Linux is unsupported. | 93 92-93 Before version 93, Linux is unsupported. | No | No | 78 | No | No | 93 92-93 Before version 93, Linux is unsupported. | No | 65 | No | 17.0 | | `titlebar-area-y` | 93 92-93 Before version 93, Linux is unsupported. | 93 92-93 Before version 93, Linux is unsupported. | No | No | 78 | No | No | 93 92-93 Before version 93, Linux is unsupported. | No | 65 | No | 17.0 | See also -------- * [`var(…)`](var()) * [CSS Custom Properties for Cascading Variables](css_variables) * [Custom Properties (--\*)](--*) * [Using CSS custom properties (variables)](using_css_custom_properties) * [Customize the window controls overlay of your PWA's title bar](https://web.dev/window-controls-overlay/) * [Display content in the title bar](https://docs.microsoft.com/microsoft-edge/progressive-web-apps-chromium/how-to/window-controls-overlay) * [Breaking Out of the Box](https://alistapart.com/article/breaking-out-of-the-box/) css overscroll-behavior-block overscroll-behavior-block ========================= The `overscroll-behavior-block` CSS property sets the browser's behavior when the block direction boundary of a scrolling area is reached. See [`overscroll-behavior`](overscroll-behavior) for a full explanation. ``` /\* Keyword values \*/ overscroll-behavior-block: auto; /\* default \*/ overscroll-behavior-block: contain; overscroll-behavior-block: none; /\* Global values \*/ overscroll-behavior-block: inherit; overscroll-behavior-block: initial; overscroll-behavior-block: revert; overscroll-behavior-block: revert-layer; overscroll-behavior-block: unset; ``` Syntax ------ The `overscroll-behavior-block` 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 is observed inside the element this value is set on (e.g. "bounce" effects or refreshes), but no scroll chaining occurs to neighboring scrolling areas, e.g. underlying elements will not scroll. `none` No scroll chaining occurs to neighboring scrolling areas, and default scroll overflow behavior is prevented. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | non-replaced block-level elements and non-replaced inline-block elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` overscroll-behavior-block = contain [|](value_definition_syntax#single_bar) none [|](value_definition_syntax#single_bar) auto ``` Examples -------- ### Preventing block overscrolling In this demo we have two block-level boxes, one inside the other. The outer box has a large [`height`](height) set on it so the page will scroll vertically. The inner box has a small [`width`](width) (and `height`) set on it so it sits comfortably inside the viewport, but its content is given a large `height` so it will also scroll vertically. 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 block direction, we've set `overscroll-behavior-block: contain` on the inner box. #### HTML ``` <main> <div> <div> <p> <code>overscroll-behavior-block</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 ``` main { height: 3000px; width: 500px; background-color: white; background-image: repeating-linear-gradient( to bottom, rgba(0, 0, 0, 0) 0px, rgba(0, 0, 0, 0) 19px, rgba(0, 0, 0, 0.5) 20px ); } main > div { height: 300px; width: 400px; overflow: auto; position: relative; top: 50px; left: 50px; overscroll-behavior-block: contain; } div > div { height: 1500px; width: 100%; background-color: yellow; background-image: repeating-linear-gradient( to bottom, rgba(0, 0, 0, 0) 0px, rgba(0, 0, 0, 0) 19px, rgba(0, 0, 0, 0.5) 20px ); } p { padding: 10px; background-color: rgba(255, 0, 0, 0.5); margin: 0; width: 340px; position: relative; top: 10px; left: 10px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Overscroll Behavior Module Level 1 # overscroll-behavior-longhands-logical](https://w3c.github.io/csswg-drafts/css-overscroll/#overscroll-behavior-longhands-logical) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `overscroll-behavior-block` | 77 | 79 | 73 | No | 64 | 16 | 77 | 77 | No | 55 | 16 | 12.0 | See also -------- * [Take control of your scroll: customizing pull-to-refresh and overflow effects](https://developer.chrome.com/blog/overscroll-behavior/#full-demo) css ::grammar-error ::grammar-error =============== **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `::grammar-error` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-element](pseudo-elements) represents a text segment which the [user agent](https://developer.mozilla.org/en-US/docs/Glossary/User_agent) has flagged as grammatically incorrect. Allowable properties -------------------- Only a small subset of CSS properties can be used in a rule with `::grammar-error` in its selector: * [`color`](color) * [`background-color`](background-color) * [`cursor`](cursor) * [`caret-color`](caret-color) * [`outline`](outline) and its longhands * [`text-decoration`](text-decoration) and its associated properties * [`text-emphasis-color`](text-emphasis-color) * [`text-shadow`](text-shadow) Syntax ------ ``` ::grammar-error ``` Examples -------- ### Simple document grammar check In this example, eventual supporting browsers should highlight any flagged grammatical errors with the styles shown. #### HTML ``` <p>My friends is coming to the party tonight.</p> ``` #### CSS ``` ::grammar-error { text-decoration: underline red; color: red; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Pseudo-Elements Module Level 4 # selectordef-grammar-error](https://w3c.github.io/csswg-drafts/css-pseudo/#selectordef-grammar-error) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `::grammar-error` | No | No | No | No | No | No See [bug 175784](https://webkit.org/b/175784). | No | No | No | No | No See [bug 175784](https://webkit.org/b/175784). | No | See also -------- * [`::spelling-error`](::spelling-error) css transform-box transform-box ============= The `transform-box` CSS property defines the layout box to which the [`transform`](transform), individual transform properties [`translate`](translate),[`scale`](scale), and [`rotate`](rotate), and [`transform-origin`](transform-origin) properties relate. ``` /\* Keyword values \*/ transform-box: content-box; transform-box: border-box; transform-box: fill-box; transform-box: stroke-box; transform-box: view-box; /\* Global values \*/ transform-box: inherit; transform-box: initial; transform-box: revert; transform-box: revert-layer; transform-box: unset; ``` Syntax ------ The `transform-box` property is specified as one of the keyword values listed below. ### Values `content-box` The content box is used as the reference box. The reference box of a [`<table>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table) is the border box of its table wrapper box, not its table box. `border-box` The border box is used as the reference box. The reference box of a [`<table>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table) is the border box of its table wrapper box, not its table box. `fill-box` The object bounding box is used as the reference box. `stroke-box` The stroke bounding box is used as the reference box. `view-box` The nearest [SVG](https://developer.mozilla.org/en-US/docs/Glossary/SVG) viewport is used as the reference box. If a `[viewBox](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox)` attribute is specified for the SVG viewport creating element, the reference box is positioned at the origin of the coordinate system established by the `viewBox` attribute, and the dimension of the reference box is set to the width and height values of the `viewBox` attribute. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `view-box` | | Applies to | transformable elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` transform-box = content-box [|](value_definition_syntax#single_bar) border-box [|](value_definition_syntax#single_bar) fill-box [|](value_definition_syntax#single_bar) stroke-box [|](value_definition_syntax#single_bar) view-box ``` Examples -------- ### SVG transform-origin scoping In this example we have an SVG: ``` <svg id="svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50"> <g> <circle id="center" fill="red" r="1" transform="translate(25 25)" /> <circle id="boxcenter" fill="blue" r=".5" transform="translate(15 15)" /> <rect id="box" x="10" y="10" width="10" height="10" rx="1" ry="1" stroke="black" fill="none" /> </g> </svg> ``` In the CSS we have an animation that uses a transform to rotate the rectangle infinitely. `transform-box: fill-box` is used to make the `transform-origin` the center of the bounding box, so the rectangle spins in place. Without it, the transform origin is the center of the SVG canvas, and so you get a very different effect. ``` svg { width: 80vh; border: 1px solid #d9d9d9; position: absolute; margin: auto; top: 0; right: 0; bottom: 0; left: 0; } #box { transform-origin: 50% 50%; /\* anything other than `0 0` to see the effect \*/ transform-box: fill-box; animation: rotateBox 3s linear infinite; } @keyframes rotateBox { to { transform: rotate(360deg); } } ``` Full credit for this example goes to [Pogany](https://codepen.io/giaco); see [this codepen](https://codepen.io/giaco/pen/OwowJQ) for a live version. Specifications -------------- | Specification | | --- | | [CSS Transforms Module Level 1 # transform-box](https://w3c.github.io/csswg-drafts/css-transforms/#transform-box) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `transform-box` | 64 | 79 | 55 | No | 51 | 11 | 64 | 64 | 55 | 47 | 11 | 9.0 | See also -------- * [Using CSS transforms](css_transforms/using_css_transforms) * [`transform`](transform), [`transform-origin`](transform-origin) * Individual transform properties: + [`translate`](translate) + [`scale`](scale) + [`rotate`](rotate)
programming_docs
css :host :host ===== The `:host` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) selects the shadow host of the [shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM) containing the CSS it is used inside — in other words, this allows you to select a custom element from inside its shadow DOM. **Note:** This has no effect when used outside a shadow DOM. ``` /\* Selects a shadow root host \*/ :host { font-weight: bold; } ``` Syntax ------ ``` :host ``` Examples -------- ### Styling the shadow host The following snippets are taken from our [host-selectors example](https://github.com/mdn/web-components-examples/tree/main/host-selectors) ([see it live also](https://mdn.github.io/web-components-examples/host-selectors/)). In this example we have a simple custom element — `<context-span>` — that you can wrap around text: ``` <h1> Host selectors <a href="#"><context-span>example</context-span></a> </h1> ``` Inside the element's constructor, we create `style` and `span` elements, fill the `span` with the content of the custom element, and fill the `style` element with some CSS rules: ``` const style = document.createElement("style"); const span = document.createElement("span"); span.textContent = this.textContent; const shadowRoot = this.attachShadow({ mode: "open" }); shadowRoot.appendChild(style); shadowRoot.appendChild(span); style.textContent = "span:hover { text-decoration: underline; }" + ":host-context(h1) { font-style: italic; }" + ':host-context(h1):after { content: " - no links in headers!" }' + ":host-context(article, aside) { color: gray; }" + ":host(.footer) { color : red; }" + ":host { background: rgba(0,0,0,0.1); padding: 2px 5px; }"; ``` The `:host { background: rgba(0,0,0,0.1); padding: 2px 5px; }` rule styles all instances of the `<context-span>` element (the shadow host in this instance) in the document. Specifications -------------- | Specification | | --- | | [CSS Scoping Module Level 1 # host-selector](https://w3c.github.io/csswg-drafts/css-scoping/#host-selector) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:host` | 54 | 79 | 63 | No | 41 | 10 | 54 | 54 | 63 | 41 | 10 | 6.0 | See also -------- * [Web components](https://developer.mozilla.org/en-US/docs/Web/Web_Components) * [`:host()`](:host_function) * [`:host-context()`](:host-context) css :only-child :only-child =========== The `:only-child` CSS [pseudo-class](pseudo-classes) represents an element without any siblings. This is the same as `:first-child:last-child` or `:nth-child(1):nth-last-child(1)`, but with a lower specificity. Try it ------ **Note:** As originally defined, the selected element had to have a parent. Beginning with Selectors Level 4, this is no longer required. Syntax ------ ``` :only-child ``` Examples -------- ### Basic example #### HTML ``` <div> <div>I am an only child.</div> </div> <div> <div>I am the 1st sibling.</div> <div>I am the 2nd sibling.</div> <div> I am the 3rd sibling, <div>but this is an only child.</div> </div> </div> ``` #### CSS ``` div:only-child { color: red; } div { display: inline-block; margin: 6px; outline: 1px solid; } ``` #### Result ### A list example #### HTML ``` <ol> <li> First <ul> <li>This list has just one element.</li> </ul> </li> <li> Second <ul> <li>This list has three elements.</li> <li>This list has three elements.</li> <li>This list has three elements.</li> </ul> </li> </ol> ``` #### CSS ``` li li { list-style-type: disc; } li:only-child { color: red; list-style-type: square; } ``` #### Result Specifications -------------- | Specification | | --- | | [Selectors Level 4 # only-child-pseudo](https://w3c.github.io/csswg-drafts/selectors/#only-child-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:only-child` | 2 | 12 | 1.5 | 9 | 9.5 | 3.1 | ≤37 | 18 | 4 | 10.1 | 2 | 1.0 | | `no_parent_required` | 57 | 79 | 52 | No | 44 | No | 57 | 57 | 52 | 43 | No | 7.0 | See also -------- * [`:only-of-type`](:only-of-type) * [`:first-child`](:first-child) * [`:last-child`](:last-child) * [`:nth-child`](:nth-child) css border-block-start-color border-block-start-color ======================== The `border-block-start-color` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the color of the logical block-start border of an element, which maps to a physical border color depending on the element's writing mode, directionality, and text orientation. It corresponds to the [`border-top-color`](border-top-color), [`border-right-color`](border-right-color), [`border-bottom-color`](border-bottom-color), or [`border-left-color`](border-left-color) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ Syntax ------ ``` border-block-start-color: blue; border-block-start-color: #4c5d21; /\* Global values \*/ border-block-start-color: inherit; border-block-start-color: initial; border-block-start-color: revert; border-block-start-color: revert-layer; border-block-start-color: unset; ``` Related properties are [`border-block-end-color`](border-block-end-color), [`border-inline-start-color`](border-inline-start-color), and [`border-inline-end-color`](border-inline-end-color), which define the other border colors of the element. ### Values `<'color'>` See [`border-color`](border-color) Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `currentcolor` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | computed color | | Animation type | a [color](color_value#interpolation) | Formal syntax ------------- ``` border-block-start-color = <'border-top-color'> ``` Examples -------- ### Border color with vertical text #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; border: 10px solid blue; border-block-start-color: red; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # border-color](https://w3c.github.io/csswg-drafts/css-logical/#border-color) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-block-start-color` | 69 | 79 | 41 | No | 56 | 12.1 | 69 | 69 | 41 | 48 | 12.2 | 10.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * This property maps to one of the physical border properties: [`border-top-color`](border-top-color), [`border-right-color`](border-right-color), [`border-bottom-color`](border-bottom-color), or [`border-left-color`](border-left-color). * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css transition-timing-function transition-timing-function ========================== The `transition-timing-function` CSS property sets how intermediate values are calculated for CSS properties being affected by a [transition effect](css_transitions/using_css_transitions). Try it ------ This, in essence, lets you establish an acceleration curve so that the speed of the transition can vary over its duration. This acceleration curve is defined using one [`<easing-function>`](easing-function) for each property to be transitioned. You may specify multiple easing functions; each one will be applied to the corresponding property as specified by the [`transition-property`](transition-property) property, which acts as a `transition-property` list. If there are fewer easing functions specified than in the `transition-property` list, the user agent must calculate which value is used by repeating the list of values until there is one for each transition property. If there are more easing functions, the list is truncated to the right size. In both cases, the CSS declaration stays valid. Syntax ------ ``` /\* Keyword values \*/ transition-timing-function: ease; transition-timing-function: ease-in; transition-timing-function: ease-out; transition-timing-function: ease-in-out; transition-timing-function: linear; transition-timing-function: step-start; transition-timing-function: step-end; /\* Function values \*/ transition-timing-function: steps(4, jump-end); transition-timing-function: cubic-bezier(0.1, 0.7, 1, 0.1); /\* Steps Function keywords \*/ transition-timing-function: steps(4, jump-start); transition-timing-function: steps(10, jump-end); transition-timing-function: steps(20, jump-none); transition-timing-function: steps(5, jump-both); transition-timing-function: steps(6, start); transition-timing-function: steps(8, end); /\* Multiple timing functions \*/ transition-timing-function: ease, step-start, cubic-bezier(0.1, 0.7, 1, 0.1); /\* Global values \*/ transition-timing-function: inherit; transition-timing-function: initial; transition-timing-function: revert; transition-timing-function: revert-layer; transition-timing-function: unset; ``` ### Values `<easing-function>` Each [`<easing-function>`](easing-function) represents the easing function to link to the corresponding property to transition, as defined in [`transition-property`](transition-property). The non-step keyword values (ease, linear, ease-in-out, etc.) each represent cubic Bézier curve with fixed four point values, with the cubic-bezier() function value allowing for a non-predefined value. The step timing functions divides the input time into a specified number of intervals that are equal in length. It is defined by a number of steps and a step position. `ease` Equal to `cubic-bezier(0.25, 0.1, 0.25, 1.0)`, the default value, increases in velocity towards the middle of the transition, slowing back down at the end. `linear` Equal to `cubic-bezier(0.0, 0.0, 1.0, 1.0)`, transitions at an even speed. `ease-in` Equal to `cubic-bezier(0.42, 0, 1.0, 1.0)`, starts off slowly, with the transition speed increasing until complete. `ease-out` Equal to `cubic-bezier(0, 0, 0.58, 1.0)`, starts transitioning quickly, slowing down the transition continues. • `ease-in-out` Equal to `cubic-bezier(0.42, 0, 0.58, 1.0)`, starts transitioning slowly, speeds up, and then slows down again. `cubic-bezier(p1, p2, p3, p4)` An author-defined cubic-Bezier curve, where the p1 and p3 values must be in the range of 0 to 1. `steps( n, <jumpterm>)` Displays the transition along *n stops along the transition, displaying each stop for* equal lengths of time. For example, if *n* is 5, there are 5 steps. Whether the transition holds temporarily at 0%, 20%, 40%, 60% and 80%, on the 20%, 40%, 60%, 80% and 100%, or makes 5 stops between the 0% and 100% along the transition, or makes 5 stops including the 0% and 100% marks (on the 0%, 25%, 50%, 75%, and 100%) depends on which of the following jump terms is used: `jump-start` Denotes a left-continuous function, so that the first jump happens when the transition begins; `jump-end` Denotes a right-continuous function, so that the last jump happens when the animation ends; `jump-none` There is no jump on either end. Instead, holding at both the 0% mark and the 100% mark, each for 1/n of the duration `jump-both` Includes pauses at both the 0% and 100% marks, effectively adding a step during the transition time. `start` Same as `jump-start.` `end` Same as `jump-end.` `step-start` Equal to `steps(1, jump-start)` `step-end` Equal to `steps(1, jump-end)` Accessibility concerns ---------------------- Some animations can be helpful such as to guide users to understand what actions are expected, to show relationships within the user interface, and to inform users as to what actions have occurred. Animations can help reduce cognitive load, prevent change blindness, and establish better recall in spatial relationships. However, some animations can be problematic for people with cognitive concerns such as Attention Deficit Hyperactivity Disorder (ADHD) and certain kinds of motion can be a trigger for Vestibular disorders, epilepsy, and migraine and Scotopic sensitivity. Consider providing a mechanism for pausing or disabling animation, as well as using the [Reduced Motion Media Query](@media/prefers-reduced-motion) to create a complimentary experience for users who have expressed a preference for no animated experiences. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `ease` | | Applies to | all elements, [`::before`](::before) and [`::after`](::after) <pseudo-elements> | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` transition-timing-function = <easing-function>[#](value_definition_syntax#hash_mark) <easing-function> = linear [|](value_definition_syntax#single_bar) <linear-easing-function> [|](value_definition_syntax#single_bar) <cubic-bezier-easing-function> [|](value_definition_syntax#single_bar) <step-easing-function> <linear-easing-function> = linear( <linear-stop-list> ) <cubic-bezier-easing-function> = ease [|](value_definition_syntax#single_bar) ease-in [|](value_definition_syntax#single_bar) ease-out [|](value_definition_syntax#single_bar) ease-in-out [|](value_definition_syntax#single_bar) cubic-bezier( [<number [0,1]>](number) , [<number>](number) , [<number [0,1]>](number) , [<number>](number) ) <step-easing-function> = step-start [|](value_definition_syntax#single_bar) step-end [|](value_definition_syntax#single_bar) steps( [<integer>](integer) [[](value_definition_syntax#brackets), <step-position> []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <linear-stop-list> = [[](value_definition_syntax#brackets) <linear-stop> []](value_definition_syntax#brackets)[#](value_definition_syntax#hash_mark) <step-position> = jump-start [|](value_definition_syntax#single_bar) jump-end [|](value_definition_syntax#single_bar) jump-none [|](value_definition_syntax#single_bar) jump-both [|](value_definition_syntax#single_bar) start [|](value_definition_syntax#single_bar) end <linear-stop> = [<number>](number) [&&](value_definition_syntax#double_ampersand) <linear-stop-length>[?](value_definition_syntax#question_mark) <linear-stop-length> = [<percentage>](percentage)[{1,2}](value_definition_syntax#curly_braces) ``` Examples -------- ### Cubic-Bezier examples ``` .ease { transition-timing-function: ease; } .easein { transition-timing-function: ease-in; } .easeout { transition-timing-function: ease-out; } .easeinout { transition-timing-function: ease-in-out; } .linear { transition-timing-function: linear; } .cb { transition-timing-function: cubic-bezier(0.2, -2, 0.8, 2); } ``` ### Step examples ``` .jump-start { transition-timing-function: steps(5, jump-start); } .jump-end { transition-timing-function: steps(5, jump-end); } .jump-none { transition-timing-function: steps(5, jump-none); } .jump-both { transition-timing-function: steps(5, jump-both); } .step-start { transition-timing-function: step-start; } .step-end { transition-timing-function: step-end; } ``` Specifications -------------- | Specification | | --- | | [CSS Transitions # transition-timing-function-property](https://w3c.github.io/csswg-drafts/css-transitions/#transition-timing-function-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `transition-timing-function` | 26 1 | 12 12 | 49 16 4 | 10 10 | 15 12.1 11.6-15 | 9 3.1 | ≤37 4.4 | 26 18 | 49 16 4 | 14 12.1 12-14 | 9 2 | 1.5 1.0 | | `jump` | 77 | 79 | 65 | No | 64 | 14 | 77 | 77 | 65 | 55 | 14 | 12.0 | See also -------- * [Using CSS transitions](css_transitions/using_css_transitions) * [`<easing-function>`](easing-function) * [`transition`](transition) * [`transition-property`](transition-property) * [`transition-duration`](transition-duration) * [`transition-delay`](transition-delay) * [`TransitionEvent`](https://developer.mozilla.org/en-US/docs/Web/API/TransitionEvent) css grid-area grid-area ========= The `grid-area` CSS [shorthand property](shorthand_properties) specifies a grid item's size and location within a [grid](https://developer.mozilla.org/en-US/docs/Glossary/Grid) by contributing a line, a span, or nothing (automatic) to its grid placement, thereby specifying the edges of its [grid area](https://developer.mozilla.org/en-US/docs/Glossary/Grid_Areas). Try it ------ If four `<grid-line>` values are specified, `grid-row-start` is set to the first value, `grid-column-start` is set to the second value, `grid-row-end` is set to the third value, and `grid-column-end` is set to the fourth value. When `grid-column-end` is omitted, if `grid-column-start` is a [`<custom-ident>`](custom-ident), `grid-column-end` is set to that `<custom-ident>`; otherwise, it is set to `auto`. When `grid-row-end` is omitted, if `grid-row-start` is a `<custom-ident>`, `grid-row-end` is set to that `<custom-ident>`; otherwise, it is set to `auto`. When `grid-column-start` is omitted, if `grid-row-start` is a `<custom-ident>`, all four longhands are set to that value. Otherwise, it is set to `auto`. The grid-area property can also be set to a [`<custom-ident>`](custom-ident) which acts as a name for the area, which can then be placed using [`grid-template-areas`](grid-template-areas). Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`grid-row-start`](grid-row-start) * [`grid-column-start`](grid-column-start) * [`grid-row-end`](grid-row-end) * [`grid-column-end`](grid-column-end) Syntax ------ ``` /\* Keyword values \*/ grid-area: auto; grid-area: auto / auto; grid-area: auto / auto / auto; grid-area: auto / auto / auto / auto; /\* <custom-ident> values \*/ grid-area: some-grid-area; grid-area: some-grid-area / another-grid-area; /\* <integer> && <custom-ident>? values \*/ grid-area: 4 some-grid-area; grid-area: 4 some-grid-area / 2 another-grid-area; /\* span && [ <integer> || <custom-ident> ] values \*/ grid-area: span 3; grid-area: span 3 / span some-grid-area; grid-area: 2 span / another-grid-area span; /\* Global values \*/ grid-area: inherit; grid-area: initial; grid-area: revert; grid-area: revert-layer; grid-area: unset; ``` ### Values `auto` Is a keyword indicating that the property contributes nothing to the grid item's placement, indicating auto-placement or a default span of `1`. `<custom-ident>` If there is a named line with the name '`<custom-ident>-start`'/'`<custom-ident>-end`', it contributes the first such line to the grid item's placement. **Note:** Named grid areas automatically generate implicit named lines of this form, so specifying `grid-area: foo;` will choose the start/end edge of that named grid area (unless another line named `foo-start`/`foo-end` was explicitly specified before it). Otherwise, this is treated as if the integer `1` had been specified along with the `<custom-ident>`. `<integer> && <custom-ident>?` Contributes the n-th grid line to the grid item's placement. If a negative integer is given, it instead counts in reverse, starting from the end edge of the explicit grid. If a name is given as a [`<custom-ident>`](custom-ident), only lines with that name are counted. If not enough lines with that name exist, all implicit grid lines are assumed to have that name for the purpose of finding this position. An [`<integer>`](integer) value of `0` is invalid. `span && [ <integer> || <custom-ident> ]` Contributes a grid span to the grid item's placement such that the corresponding edge of the grid item's grid area is *n* lines from the opposite edge. If a name is given as a [`<custom-ident>`](custom-ident), only lines with that name are counted. If not enough lines with that name exist, all implicit grid lines on the side of the explicit grid corresponding to the search direction are assumed to have that name for the purpose of counting this span. If the [`<integer>`](integer) is omitted, it defaults to `1`. Negative integers or 0 are invalid. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`grid-row-start`](grid-row-start): `auto` * [`grid-column-start`](grid-column-start): `auto` * [`grid-row-end`](grid-row-end): `auto` * [`grid-column-end`](grid-column-end): `auto` | | Applies to | grid items and absolutely-positioned boxes whose containing block is a grid container | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`grid-row-start`](grid-row-start): as specified * [`grid-column-start`](grid-column-start): as specified * [`grid-row-end`](grid-row-end): as specified * [`grid-column-end`](grid-column-end): as specified | | Animation type | discrete | Formal syntax ------------- ``` grid-area = <grid-line> [[](value_definition_syntax#brackets) / <grid-line> []](value_definition_syntax#brackets)[{0,3}](value_definition_syntax#curly_braces) <grid-line> = auto [|](value_definition_syntax#single_bar) [<custom-ident>](custom-ident) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) [<integer [-∞,-1]>](integer) [|](value_definition_syntax#single_bar) [<integer [1,∞]>](integer) []](value_definition_syntax#brackets) [&&](value_definition_syntax#double_ampersand) [<custom-ident>](custom-ident)[?](value_definition_syntax#question_mark) []](value_definition_syntax#brackets) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) span [&&](value_definition_syntax#double_ampersand) [[](value_definition_syntax#brackets) [<integer [1,∞]>](integer) [||](value_definition_syntax#double_bar) [<custom-ident>](custom-ident) []](value_definition_syntax#brackets) []](value_definition_syntax#brackets) ``` Examples -------- ### Setting grid areas #### HTML ``` <div id="grid"> <div id="item1"></div> <div id="item2"></div> <div id="item3"></div> </div> ``` #### CSS ``` #grid { display: grid; height: 100px; grid-template: repeat(4, 1fr) / 50px 100px; } #item1 { background-color: lime; grid-area: 2 / 2 / auto / span 3; } #item2 { background-color: yellow; } #item3 { background-color: blue; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Grid Layout Module Level 2 # propdef-grid-area](https://w3c.github.io/csswg-drafts/css-grid/#propdef-grid-area) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `grid-area` | 57 | 16 | 52 | No | 44 | 10.1 | 57 | 57 | 52 | 43 | 10.3 | 6.0 | See also -------- * Related CSS properties: [`grid-row`](grid-row), [`grid-row-start`](grid-row-start), [`grid-row-end`](grid-row-end), [`grid-column`](grid-column), [`grid-column-start`](grid-column-start), [`grid-column-end`](grid-column-end), [`grid-template-areas`](grid-template-areas) * Grid Layout Guide: *[Grid template areas](css_grid_layout/grid_template_areas)* * Video tutorial: *[Grid Template Areas](https://gridbyexample.com/video/grid-template-areas/)*
programming_docs
css overflow-inline overflow-inline =============== The `overflow-inline` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets what shows when content overflows the inline start and end edges of a box. This may be nothing, a scroll bar, or the overflow content. **Note:** The `overflow-inline` property maps to [`overflow-y`](overflow-y) or [`overflow-x`](overflow-x) depending on the writing mode of the document. Syntax ------ ``` /\* Keyword values \*/ overflow-inline: visible; overflow-inline: hidden; overflow-inline: scroll; overflow-inline: auto; /\* Global values \*/ overflow-inline: inherit; overflow-inline: initial; overflow-inline: revert; overflow-inline: revert-layer; overflow-inline: unset; ``` The `overflow-inline` property is specified as a single keyword chosen from the list of values below. ### Values `visible` Content is not clipped and may be rendered outside the padding box's inline start and end edges. `hidden` Content is clipped if necessary to fit the inline dimension in the padding box. No scrollbars are provided. `scroll` Content is clipped if necessary to fit in the padding box in the inline dimension. Browsers display scrollbars whether or not any content is actually clipped. (This prevents scrollbars from appearing or disappearing when the content changes.) Printers may still print overflowing content. `auto` Depends on the user agent. If content fits inside the padding box, it looks the same as `visible`, but still establishes a new block-formatting context. Desktop browsers provide scrollbars if content overflows. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | Block-containers, flex containers, and grid containers | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified, except with `visible`/`clip` computing to `auto`/`hidden` respectively if one of [`overflow-x`](overflow-x) or [`overflow-y`](overflow-y) is neither `visible` nor clip | | Animation type | discrete | Formal syntax ------------- ``` overflow-inline = <'overflow'> ``` Examples -------- ### Setting inline overflow behavior #### HTML ``` <ul> <li> <code>overflow-inline:hidden</code> — hides the text outside the box <div id="div1">ABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZ</div> </li> <li> <code>overflow-inline:scroll</code> — always adds a scrollbar <div id="div2">ABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZ</div> </li> <li> <code>overflow-inline:visible</code> — displays the text outside the box if needed <div id="div3">ABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZ</div> </li> <li> <code>overflow-inline:auto</code> — on most browsers, equivalent to <code>scroll</code> <div id="div4">ABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZ</div> </li> </ul> ``` #### CSS ``` #div1, #div2, #div3, #div4 { border: 1px solid black; width: 250px; margin-bottom: 12px; } #div1 { overflow-inline: hidden; } #div2 { overflow-inline: scroll; } #div3 { overflow-inline: visible; } #div4 { overflow-inline: auto; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Overflow Module Level 3 # logical](https://w3c.github.io/csswg-drafts/css-overflow/#logical) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `overflow-inline` | No | No | 69 | No | No | No | No | No | No | No | No | No | See also -------- * Related CSS properties: [`text-overflow`](text-overflow), [`white-space`](white-space), [`overflow`](overflow), [`overflow-block`](overflow-block), [`overflow-x`](overflow-x), [`overflow-y`](overflow-y), [`clip`](clip), [`display`](display) * [CSS Logical Properties](css_logical_properties) * [Writing Modes](css_writing_modes) css align-content align-content ============= The [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) `align-content` property sets the distribution of space between and around content items along a [flexbox](css_flexible_box_layout)'s cross-axis or a [grid](css_grid_layout)'s block axis. The interactive example below uses Grid Layout to demonstrate some of the values of this property. Try it ------ This property has no effect on single line flex containers (i.e. ones with `flex-wrap: nowrap`). Syntax ------ ``` /\* Basic positional alignment \*/ /\* align-content does not take left and right values \*/ align-content: center; /\* Pack items around the center \*/ align-content: start; /\* Pack items from the start \*/ align-content: end; /\* Pack items from the end \*/ align-content: flex-start; /\* Pack flex items from the start \*/ align-content: flex-end; /\* Pack flex items from the end \*/ /\* Normal alignment \*/ align-content: normal; /\* Baseline alignment \*/ align-content: baseline; align-content: first baseline; align-content: last baseline; /\* Distributed alignment \*/ align-content: space-between; /\* Distribute items evenly The first item is flush with the start, the last is flush with the end \*/ align-content: space-around; /\* Distribute items evenly Items have a half-size space on either end \*/ align-content: space-evenly; /\* Distribute items evenly Items have equal space around them \*/ align-content: stretch; /\* Distribute items evenly Stretch 'auto'-sized items to fit the container \*/ /\* Overflow alignment \*/ align-content: safe center; align-content: unsafe center; /\* Global values \*/ align-content: inherit; align-content: initial; align-content: revert; align-content: revert-layer; align-content: unset; ``` ### Values `start` The items are packed flush to each other against the start edge of the alignment container in the cross axis. `end` The items are packed flush to each other against the end edge of the alignment container in the cross axis. `flex-start` The items are packed flush to each other against the edge of the alignment container depending on the flex container's cross-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 against the edge of the alignment container depending on the flex container's cross-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 in the center of the alignment container along the cross axis. `normal` The items are packed in their default position as if no `align-content` value was set. `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`. `space-between` The items are evenly distributed within the alignment container along the cross axis. The spacing between each pair of adjacent items is the same. The first item is flush with the start edge of the alignment container in the cross axis, and the last item is flush with the end edge of the alignment container in the cross axis. `space-around` The items are evenly distributed within the alignment container along the cross 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 cross axis. The spacing between each pair of adjacent items, the start edge and the first item, and the end edge and the last item, are all exactly the same. `stretch` If the combined size of the items along the cross 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 [`max-height`](max-height)/[`max-width`](max-width) (or equivalent functionality), so that the combined size exactly fills the alignment container along the cross axis. `safe` Used alongside an alignment keyword. If the chosen keyword means that the item overflows the alignment container causing data loss, the item is instead aligned as if the alignment mode were `start`. `unsafe` Used alongside an alignment keyword. Regardless of the relative sizes of the item and alignment container and whether overflow which causes data loss might happen, the given alignment value is honored. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | multi-line flex containers | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` align-content = normal [|](value_definition_syntax#single_bar) <baseline-position> [|](value_definition_syntax#single_bar) <content-distribution> [|](value_definition_syntax#single_bar) <overflow-position>[?](value_definition_syntax#question_mark) <content-position> <baseline-position> = [[](value_definition_syntax#brackets) first [|](value_definition_syntax#single_bar) last []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) [&&](value_definition_syntax#double_ampersand) baseline <content-distribution> = space-between [|](value_definition_syntax#single_bar) space-around [|](value_definition_syntax#single_bar) space-evenly [|](value_definition_syntax#single_bar) stretch <overflow-position> = unsafe [|](value_definition_syntax#single_bar) safe <content-position> = center [|](value_definition_syntax#single_bar) start [|](value_definition_syntax#single_bar) end [|](value_definition_syntax#single_bar) flex-start [|](value_definition_syntax#single_bar) flex-end ``` Examples -------- ### CSS ``` #container { height: 200px; width: 240px; align-content: center; /\* Can be changed in the live sample \*/ background-color: #8c8c8c; } .flex { display: flex; flex-wrap: wrap; } .grid { display: grid; grid-template-columns: repeat(auto-fill, 50px); } div > div { box-sizing: border-box; border: 2px solid #8c8c8c; width: 50px; display: flex; align-items: center; justify-content: center; } #item1 { background-color: #8cffa0; min-height: 30px; } #item2 { background-color: #a0c8ff; min-height: 50px; } #item3 { background-color: #ffa08c; min-height: 40px; } #item4 { background-color: #ffff8c; min-height: 60px; } #item5 { background-color: #ff8cff; min-height: 70px; } #item6 { background-color: #8cffff; min-height: 50px; font-size: 30px; } select { font-size: 16px; } .row { margin-top: 10px; } ``` ### HTML ``` <div id="container" class="flex"> <div id="item1">1</div> <div id="item2">2</div> <div id="item3">3</div> <div id="item4">4</div> <div id="item5">5</div> <div id="item6">6</div> </div> <div class="row"> <label for="display">display: </label> <select id="display"> <option value="flex">flex</option> <option value="grid">grid</option> </select> </div> <div class="row"> <label for="values">align-content: </label> <select id="values"> <option value="normal">normal</option> <option value="stretch">stretch</option> <option value="flex-start">flex-start</option> <option value="flex-end">flex-end</option> <option value="center" selected>center</option> <option value="space-between">space-between</option> <option value="space-around">space-around</option> <option value="space-evenly">space-evenly</option> <option value="start">start</option> <option value="end">end</option> <option value="baseline">baseline</option> <option value="first baseline">first baseline</option> <option value="last baseline">last baseline</option> <option value="safe center">safe center</option> <option value="unsafe center">unsafe center</option> <option value="safe right">safe right</option> <option value="unsafe right">unsafe right</option> <option value="safe end">safe end</option> <option value="unsafe end">unsafe end</option> <option value="safe flex-end">safe flex-end</option> <option value="unsafe flex-end">unsafe flex-end</option> </select> </div> ``` ### Result Specifications -------------- | Specification | | --- | | [CSS Box Alignment Module Level 3 # align-justify-content](https://w3c.github.io/csswg-drafts/css-align/#align-justify-content) | | [CSS Flexible Box Layout Module Level 1 # align-content-property](https://w3c.github.io/csswg-drafts/css-flexbox/#align-content-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `align-content` | 29 21 | 12 12 | 49 28 | 11 | 16 15 | 9 7 | ≤37 4.4 | 29 25 | 49 28 | 16 14 | 9 7 | 2.0 1.5 | | `flex_context` | 21 | 12 | 28 | 11 | 15 | 9 | 4.4 | 25 | 28 | 14 | 9 | 1.5 | | `grid_context` | 57 | 16 | 52 | No | 44 | 10.1 | 57 | 52 | 52 | 43 | 10.3 | 6.2 | See also -------- * CSS Flexbox Guide: *[Basic Concepts of Flexbox](css_flexible_box_layout/basic_concepts_of_flexbox)* * CSS Flexbox Guide: *[Aligning items in a flex container](css_flexible_box_layout/aligning_items_in_a_flex_container)* * CSS Grid Guide: *[Box alignment in CSS Grid layouts](css_grid_layout/box_alignment_in_css_grid_layout)* * [CSS Box Alignment](css_box_alignment) css border-bottom-color border-bottom-color =================== The `border-bottom-color` CSS property sets the color of an element's bottom <border>. It can also be set with the shorthand CSS properties [`border-color`](border-color) or [`border-bottom`](border-bottom). Try it ------ Syntax ------ ``` /\* <color> values \*/ border-bottom-color: red; border-bottom-color: #ffbb00; border-bottom-color: rgb(255, 0, 0); border-bottom-color: hsl(100deg 50% 25% / 0.75); border-bottom-color: currentcolor; border-bottom-color: transparent; /\* Global values \*/ border-bottom-color: inherit; border-bottom-color: initial; border-bottom-color: revert; border-bottom-color: revert-layer; border-bottom-color: unset; ``` The `border-bottom-color` property is specified as a single value. ### Values [`<color>`](color_value) The color of the bottom border. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `currentcolor` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | computed color | | Animation type | a [color](color_value#interpolation) | Formal syntax ------------- ``` border-bottom-color = [<color>](color_value) ``` Examples -------- ### A simple div with a border #### HTML ``` <div class="mybox"> <p> This is a box with a border around it. Note which side of the box is <span class="redtext">red</span>. </p> </div> ``` #### CSS ``` .mybox { border: solid 0.3em gold; border-bottom-color: red; width: auto; } .redtext { color: red; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # border-color](https://w3c.github.io/csswg-drafts/css-backgrounds/#border-color) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-bottom-color` | 1 | 12 | 1 Firefox also supports the non-standard [`-moz-border-bottom-colors`](https://developer.mozilla.org/docs/Web/CSS/-moz-border-bottom-colors) CSS property that sets the bottom border to multiple colors. | 4 | 3.5 | 1 | 4.4 | 18 | 4 Firefox also supports the non-standard [`-moz-border-bottom-colors`](https://developer.mozilla.org/docs/Web/CSS/-moz-border-bottom-colors) CSS property that sets the bottom border to multiple colors. | 10.1 | 1 | 1.0 | See also -------- * The border-related CSS shorthand properties: [`border`](border), [`border-bottom`](border-bottom), and [`border-color`](border-color). * The color-related CSS properties for the other borders: [`border-right-color`](border-right-color), [`border-top-color`](border-top-color), and [`border-left-color`](border-left-color). * The other border-related CSS properties applying to the same border: [`border-bottom-style`](border-bottom-style) and [`border-bottom-width`](border-bottom-width). css :in-range :in-range ========= The `:in-range` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) represents an [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) element whose current value is within the range limits specified by the [`min`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-min) and [`max`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-max) attributes. Try it ------ This pseudo-class is useful for giving the user a visual indication that a field's current value is within the permitted limits. **Note:** This pseudo-class only applies to elements that have (and can take) a range limitation. In the absence of such a limitation, the element can neither be "in-range" nor "out-of-range." Syntax ------ ``` :in-range ``` Examples -------- ### HTML ``` <form action="" id="form1"> <ul> Values between 1 and 10 are valid. <li> <input id="value1" name="value1" type="number" placeholder="1 to 10" min="1" max="10" value="12" required /> <label for="value1">Your value is </label> </li> </ul> </form> ``` ### CSS ``` li { list-style: none; margin-bottom: 1em; } input { border: 1px solid black; } input:in-range { background-color: rgba(0, 255, 0, 0.25); } input:out-of-range { background-color: rgba(255, 0, 0, 0.25); border: 2px solid red; } input:in-range + label::after { content: "okay."; } input:out-of-range + label::after { content: "out of range!"; } ``` ### Result **Note:** An empty `<input>` does not count as out of range, and will not be selected using the `:out-of-range` pseudo-class selector. The [`:blank`](:blank) pseudo-class exists to select blank inputs, although at the time of writing this is experimental and not well-supported. You could also use the `required` attribute and the [`:invalid`](:invalid) pseudo-class to provide more general logic and styling for making inputs mandatory (`:invalid` will style blank *and* out-of-range inputs). Specifications -------------- | Specification | | --- | | [HTML Standard # selector-in-range](https://html.spec.whatwg.org/multipage/semantics-other.html#selector-in-range) | | [Selectors Level 4 # in-range-pseudo](https://w3c.github.io/csswg-drafts/selectors/#in-range-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:in-range` | 10 Before Chrome 52, `:in-range` matched disabled and read-only inputs (see [Chromium bug 602568](https://crbug.com/602568)). In Chrome 52, it was changed to only match enabled read-write inputs. | 13 | 29 Before Firefox 50, `:in-range` matched disabled and read-only inputs (see [bug 1264157](https://bugzil.la/1264157)). In Firefox 50, it was changed to only match enabled read-write inputs. | No | 11 Before Opera 39, `:in-range` matched disabled and read-only inputs (see [Chromium bug 602568](https://crbug.com/602568)). In Opera 39, it was changed to only match enabled read-write inputs. | 5.1 In Safari, `:in-range` matched disabled and read-only inputs (see [bug 156530](https://webkit.org/b/156530)). It was later changed to only match enabled read-write inputs. | 2.2 Before version 52, `:in-range` matched disabled and read-only inputs (see [Chromium bug 602568](https://crbug.com/602568)). In version 52, it was changed to only match enabled read-write inputs. | 18 Before Chrome 52, `:in-range` matched disabled and read-only inputs (see [Chromium bug 602568](https://crbug.com/602568)). In Chrome 52, it was changed to only match enabled read-write inputs. | 16 | 11 Before Opera 39, `:in-range` matched disabled and read-only inputs (see [Chromium bug 602568](https://crbug.com/602568)). In Opera 39, it was changed to only match enabled read-write inputs. | 5 In Safari, `:in-range` matched disabled and read-only inputs (see [bug 156530](https://webkit.org/b/156530)). It was later changed to only match enabled read-write inputs. | 1.0 Before version 6.0, `:in-range` matched disabled and read-only inputs (see [Chromium bug 602568](https://crbug.com/602568)). In version 6.0, it was changed to only match enabled read-write inputs. | See also -------- * [`:out-of-range`](:out-of-range) * [Form data validation](https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation)
programming_docs
css font-variant font-variant ============ The `font-variant` CSS [shorthand property](shorthand_properties) allows you to set all the font variants for a font. You can also set the CSS Level 2 (Revision 1) values of `font-variant`, (that is, `normal` or `small-caps`), by using the [`font`](font) shorthand. Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`font-variant-alternates`](font-variant-alternates) * [`font-variant-caps`](font-variant-caps) * [`font-variant-east-asian`](font-variant-east-asian) * [`font-variant-emoji`](font-variant-emoji) * [`font-variant-ligatures`](font-variant-ligatures) * [`font-variant-numeric`](font-variant-numeric) * [`font-variant-position`](font-variant-position) Syntax ------ ``` font-variant: small-caps; font-variant: common-ligatures small-caps; /\* Global values \*/ font-variant: inherit; font-variant: initial; font-variant: revert; font-variant: revert-layer; font-variant: unset; ``` ### Values `normal` Specifies a normal font face. Each longhand property has an initial value of `normal`. `none` Sets the value of the [`font-variant-ligatures`](font-variant-ligatures) as `none` and the values of the other longhand properties as `normal`, their initial value. `<common-lig-values>`, `<discretionary-lig-values>`, `<historical-lig-values>`, `<contextual-alt-values>` Specifies the keywords related to the [`font-variant-ligatures`](font-variant-ligatures) longhand property. The possible values are `common-ligatures`, `no-common-ligatures`, `discretionary-ligatures`, `no-discretionary-ligatures`, `historical-ligatures`, `no-historical-ligatures`, `contextual`, and `no-contextual`. `stylistic()`, `historical-forms`, `styleset()`, `character-variant()`, `swash()`, `ornaments()`, `annotation()` Specifies the keywords and functions related to the [`font-variant-ligatures`](font-variant-ligatures) longhand property. `small-caps`, `all-small-caps`, `petite-caps`, `all-petite-caps`, `unicase`, `titling-caps` Specifies the keywords and functions related to the [`font-variant-caps`](font-variant-caps) longhand property. `<numeric-figure-values>`, `<numeric-spacing-values>`, `<numeric-fraction-values>`, `ordinal`, `slashed-zero` Specifies the keywords related to the [`font-variant-numeric`](font-variant-numeric) longhand property. The possible values are `lining-nums`, `oldstyle-nums`, `proportional-nums`, `tabular-nums`, `diagonal-fractions`, `stacked-fractions`, `ordinal`, and `slashed-zero`. `<east-asian-variant-values>`, `<east-asian-width-values>`, `ruby` Specifies the keywords related to the [`font-variant-east-asian`](font-variant-east-asian) longhand property. The possible values are `jis78`, `jis83`, `jis90`, `jis04`, `simplified`, `traditional`, `full-width`, `proportional-width`, and `ruby`. `sub`, `super` Specifies the keywords and functions related to the [`font-variant-position`](font-variant-position) longhand property. `text`, `emoji`, `unicode` Specifies the keywords and functions related to the [`font-variant-emoji`](font-variant-emoji) longhand property. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` font-variant = normal [|](value_definition_syntax#single_bar) none [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) <common-lig-values> [||](value_definition_syntax#double_bar) <discretionary-lig-values> [||](value_definition_syntax#double_bar) <historical-lig-values> [||](value_definition_syntax#double_bar) <contextual-alt-values> []](value_definition_syntax#brackets) [||](value_definition_syntax#double_bar) [[](value_definition_syntax#brackets) small-caps [|](value_definition_syntax#single_bar) all-small-caps [|](value_definition_syntax#single_bar) petite-caps [|](value_definition_syntax#single_bar) all-petite-caps [|](value_definition_syntax#single_bar) unicase [|](value_definition_syntax#single_bar) titling-caps []](value_definition_syntax#brackets) [||](value_definition_syntax#double_bar) [[](value_definition_syntax#brackets) stylistic( <feature-value-name> ) [||](value_definition_syntax#double_bar) historical-forms [||](value_definition_syntax#double_bar) styleset( <feature-value-name>[#](value_definition_syntax#hash_mark) ) [||](value_definition_syntax#double_bar) character-variant( <feature-value-name>[#](value_definition_syntax#hash_mark) ) [||](value_definition_syntax#double_bar) swash( <feature-value-name> ) [||](value_definition_syntax#double_bar) ornaments( <feature-value-name> ) [||](value_definition_syntax#double_bar) annotation( <feature-value-name> ) []](value_definition_syntax#brackets) [||](value_definition_syntax#double_bar) [[](value_definition_syntax#brackets) <numeric-figure-values> [||](value_definition_syntax#double_bar) <numeric-spacing-values> [||](value_definition_syntax#double_bar) <numeric-fraction-values> [||](value_definition_syntax#double_bar) ordinal [||](value_definition_syntax#double_bar) slashed-zero []](value_definition_syntax#brackets) [||](value_definition_syntax#double_bar) [[](value_definition_syntax#brackets) <east-asian-variant-values> [||](value_definition_syntax#double_bar) <east-asian-width-values> [||](value_definition_syntax#double_bar) ruby []](value_definition_syntax#brackets) [||](value_definition_syntax#double_bar) [[](value_definition_syntax#brackets) sub [|](value_definition_syntax#single_bar) super []](value_definition_syntax#brackets) [||](value_definition_syntax#double_bar) [[](value_definition_syntax#brackets) text [|](value_definition_syntax#single_bar) emoji [|](value_definition_syntax#single_bar) unicode []](value_definition_syntax#brackets) []](value_definition_syntax#brackets) <common-lig-values> = common-ligatures [|](value_definition_syntax#single_bar) no-common-ligatures <discretionary-lig-values> = discretionary-ligatures [|](value_definition_syntax#single_bar) no-discretionary-ligatures <historical-lig-values> = historical-ligatures [|](value_definition_syntax#single_bar) no-historical-ligatures <contextual-alt-values> = contextual [|](value_definition_syntax#single_bar) no-contextual <feature-value-name> = [<ident>](ident) <numeric-figure-values> = lining-nums [|](value_definition_syntax#single_bar) oldstyle-nums <numeric-spacing-values> = proportional-nums [|](value_definition_syntax#single_bar) tabular-nums <numeric-fraction-values> = diagonal-fractions [|](value_definition_syntax#single_bar) stacked-fractions <east-asian-variant-values> = jis78 [|](value_definition_syntax#single_bar) jis83 [|](value_definition_syntax#single_bar) jis90 [|](value_definition_syntax#single_bar) jis04 [|](value_definition_syntax#single_bar) simplified [|](value_definition_syntax#single_bar) traditional <east-asian-width-values> = full-width [|](value_definition_syntax#single_bar) proportional-width ``` Examples -------- ### Setting the small-caps font variant #### HTML ``` <p class="normal">Firefox rocks!</p> <p class="small">Firefox rocks!</p> ``` #### CSS ``` p.normal { font-variant: normal; } p.small { font-variant: small-caps; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Fonts Module Level 4 # font-variant-prop](https://w3c.github.io/csswg-drafts/css-fonts/#font-variant-prop) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `font-variant` | 1 | 12 | 1 | 4 | 3.5 | 1 | 4.4 | 18 | 4 | 11 | 1 | 1.0 | | `css_fonts_shorthand` | 52 | 79 | 34 | No | 39 | 9.1 | 52 | 52 | 34 | 41 | 9.3 | 6.0 | | `font-variant-emoji` | No | No | 108 | No | No | No | No | No | 108 | No | No | No | | `greek_accented_characters` | No Some operating systems may correctly omit accents in all-uppercase Greek text. | No Some operating systems may correctly omit accents in all-uppercase Greek text. | No Some operating systems may correctly omit accents in all-uppercase Greek text. | No | No Some operating systems may correctly omit accents in all-uppercase Greek text. | No | No Some operating systems may correctly omit accents in all-uppercase Greek. | No Some operating systems may correctly omit accents in all-uppercase Greek text. | No Some operating systems may correctly omit accents in all-uppercase Greek text. | No Some operating systems may correctly omit accents in all-uppercase Greek text. | No | No Some operating systems may correctly omit accents in all-uppercase Greek text. | | `turkic_is` | 31 | 12 | 14 | 4 | 18 | 8 | 4.4.3 | 31 | 14 | 18 | 8 | 2.0 | | `uppercase_eszett` | No Some operating systems may capitalize `ß` as `SS`. | No Some operating systems may capitalize `ß` as `SS`. | No Some operating systems may capitalize `ß` as `SS`. | No | No Some operating systems may capitalize `ß` as `SS`. | No | No Some operating systems may capitalize `ß` as `SS`. | No Some operating systems may capitalize `ß` as `SS`. | No Some operating systems may capitalize `ß` as `SS`. | No Some operating systems may capitalize `ß` as `SS`. | No | No Some operating systems may capitalize `ß` as `SS`. | See also -------- * [`text-transform`](text-transform) * [`text-combine-upright`](text-combine-upright) * [`text-orientation`](text-orientation) css background-size background-size =============== The `background-size` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the size of the element's background image. The image can be left to its natural size, stretched, or constrained to fit the available space. Try it ------ Spaces not covered by a background image are filled with the [`background-color`](background-color) property, and the background color will be visible behind background images that have transparency/translucency. Syntax ------ ``` /\* Keyword values \*/ background-size: cover; background-size: contain; /\* One-value syntax \*/ /\* the width of the image (height becomes 'auto') \*/ background-size: 50%; background-size: 3.2em; background-size: 12px; background-size: auto; /\* Two-value syntax \*/ /\* first value: width of the image, second value: height \*/ background-size: 50% auto; background-size: 3em 25%; background-size: auto 6px; background-size: auto auto; /\* Multiple backgrounds \*/ background-size: auto, auto; /\* Not to be confused with `auto auto` \*/ background-size: 50%, 25%, 25%; background-size: 6px, auto, contain; /\* Global values \*/ background-size: inherit; background-size: initial; background-size: revert; background-size: revert-layer; background-size: unset; ``` The `background-size` property is specified in one of the following ways: * Using the keyword values `contain` or `cover`. * Using a width value only, in which case the height defaults to `auto`. * Using both a width and a height value, in which case the first sets the width and the second sets the height. Each value can be a [`<length>`](length), a [`<percentage>`](percentage), or `auto`. To specify the size of multiple background images, separate the value for each one with a comma. ### Values `contain` Scales the image as large as possible within its container without cropping or stretching the image. If the container is larger than the image, this will result in image tiling, unless the [`background-repeat`](background-repeat) property is set to `no-repeat`. `cover` Scales the image (while preserving its ratio) to the smallest possible size to fill the container (that is: both its height and width completely *cover* the container), leaving no empty space. If the proportions of the background differ from the element, the image is cropped either vertically or horizontally. `auto` Scales the background image in the corresponding direction such that its intrinsic proportions are maintained. [`<length>`](length) Stretches the image in the corresponding dimension to the specified length. Negative values are not allowed. [`<percentage>`](percentage) Stretches the image in the corresponding dimension to the specified percentage of the *background positioning area*. The background positioning area is determined by the value of [`background-origin`](background-origin) (by default, the padding box). However, if the background's [`background-attachment`](background-attachment) value is `fixed`, the positioning area is instead the entire [viewport](https://developer.mozilla.org/en-US/docs/Glossary/Viewport). Negative values are not allowed. ### Intrinsic dimensions and proportions The computation of values depends on the image's intrinsic dimensions (width and height) and intrinsic proportions (width-to-height ratio). These attributes are as follows: * A bitmap image (such as JPG) always has intrinsic dimensions and proportions. * A vector image (such as SVG) does not necessarily have intrinsic dimensions. If it has both horizontal and vertical intrinsic dimensions, it also has intrinsic proportions. If it has no dimensions or only one dimension, it may or may not have proportions. * CSS [`<gradient>`](gradient)s have no intrinsic dimensions or intrinsic proportions. * Background images created with the [`element()`](element()) function use the intrinsic dimensions and proportions of the generating element. **Note:** In Gecko, background images created using the [`element()`](element()) function are currently treated as images with the dimensions of the element, or of the background positioning area if the element is SVG, with the corresponding intrinsic proportion. This is non-standard behavior. Based on the intrinsic dimensions and proportions, the rendered size of the background image is computed as follows: * **If both components of `background-size` are specified and are not `auto`:** The background image is rendered at the specified size. * **If the `background-size` is `contain` or `cover`:** While preserving its intrinsic proportions, the image is rendered at the largest size contained within, or covering, the background positioning area. If the image has no intrinsic proportions, then it's rendered at the size of the background positioning area. * **If the `background-size` is `auto` or `auto auto`:** + If the image has both horizontal and vertical intrinsic dimensions, it's rendered at that size. + If the image has no intrinsic dimensions and has no intrinsic proportions, it's rendered at the size of the background positioning area. + If the image has no intrinsic dimensions but has intrinsic proportions, it's rendered as if `contain` had been specified instead. + If the image has only one intrinsic dimension and has intrinsic proportions, it's rendered at the size corresponding to that one dimension. The other dimension is computed using the specified dimension and the intrinsic proportions. + If the image has only one intrinsic dimension but has no intrinsic proportions, it's rendered using the specified dimension and the other dimension of the background positioning area. **Note:** SVG images have a [`preserveAspectRatio`](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio) attribute that defaults to the equivalent of `contain`; an explicit `background-size` causes `preserveAspectRatio` to be ignored. * **If the `background-size` has one `auto` component and one non-`auto` component:** + If the image has intrinsic proportions, it's stretched to the specified dimension. The unspecified dimension is computed using the specified dimension and the intrinsic proportions. + If the image has no intrinsic proportions, it's stretched to the specified dimension. The unspecified dimension is computed using the image's corresponding intrinsic dimension, if there is one. If there is no such intrinsic dimension, it becomes the corresponding dimension of the background positioning area. **Note:** Background sizing for vector images that lack intrinsic dimensions or proportions is not yet fully implemented in all browsers. Be careful about relying on the behavior described above, and test in multiple browsers to be sure the results are acceptable. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto auto` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | Percentages | relative to the background positioning area | | [Computed value](computed_value) | as specified, but with relative lengths converted into absolute lengths | | Animation type | repeatable list of simple list of length, percentage, or calc | Formal syntax ------------- ``` background-size = <bg-size>[#](value_definition_syntax#hash_mark) <bg-size> = [[](value_definition_syntax#brackets) [<length-percentage [0,∞]>](length-percentage) [|](value_definition_syntax#single_bar) auto []](value_definition_syntax#brackets)[{1,2}](value_definition_syntax#curly_braces) [|](value_definition_syntax#single_bar) cover [|](value_definition_syntax#single_bar) contain <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Tiling a large image Let's consider a large image, a 2982x2808 Firefox logo image. We want 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 ``` <div class="tiledBackground"></div> ``` #### 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 See [Resizing background images](css_backgrounds_and_borders/resizing_background_images) for more examples. Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # the-background-size](https://w3c.github.io/csswg-drafts/css-backgrounds/#the-background-size) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `background-size` | 3 1 WebKit-based browsers originally implemented an older draft of CSS3 `background-size` in which an omitted second value is treated as duplicating the first value; this draft does not include the `contain` or `cover` keywords. | 12 12 | 49 4 3.6-4 | 9 | 15 WebKit-based browsers originally implemented an older draft of CSS3 `background-size` in which an omitted second value is treated as duplicating the first value; this draft does not include the `contain` or `cover` keywords. 10 9.5-15 Opera 9.5's computation of the background positioning area is incorrect for fixed backgrounds. Opera 9.5 also interprets the two-value form as a horizontal scaling factor and, from appearances, a vertical clipping dimension. This has been fixed in Opera 10. | 5 3 WebKit-based browsers originally implemented an older draft of CSS3 `background-size` in which an omitted second value is treated as duplicating the first value; this draft does not include the `contain` or `cover` keywords. | ≤37 WebKit-based browsers originally implemented an older draft of CSS3 `background-size` in which an omitted second value is treated as duplicating the first value; this draft does not include the `contain` or `cover` keywords. 2.2 | 18 18 WebKit-based browsers originally implemented an older draft of CSS3 `background-size` in which an omitted second value is treated as duplicating the first value; this draft does not include the `contain` or `cover` keywords. | 49 4 | 14 WebKit-based browsers originally implemented an older draft of CSS3 `background-size` in which an omitted second value is treated as duplicating the first value; this draft does not include the `contain` or `cover` keywords. 10.1 10.1-14 Opera 9.5's computation of the background positioning area is incorrect for fixed backgrounds. Opera 9.5 also interprets the two-value form as a horizontal scaling factor and, from appearances, a vertical clipping dimension. This has been fixed in Opera 10. | 4.2 1 WebKit-based browsers originally implemented an older draft of CSS3 `background-size` in which an omitted second value is treated as duplicating the first value; this draft does not include the `contain` or `cover` keywords. | 1.0 1.0 WebKit-based browsers originally implemented an older draft of CSS3 `background-size` in which an omitted second value is treated as duplicating the first value; this draft does not include the `contain` or `cover` keywords. | | `contain_and_cover` | 3 | 12 | 3.6 | 9 | 10 | 5 | 37 | 18 | 4 | 14 | 4.2 | 1.0 | See also -------- * [Resizing background images](css_backgrounds_and_borders/resizing_background_images) * [Scaling of SVG backgrounds](scaling_of_svg_backgrounds) * [`object-fit`](object-fit)
programming_docs
css overflow overflow ======== The `overflow` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [shorthand property](shorthand_properties) sets the desired behavior for an element's overflow — i.e. when an element's content is too big to fit in its [block formatting context](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context) — in both directions. Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`overflow-x`](overflow-x) * [`overflow-y`](overflow-y) Syntax ------ ``` /\* Keyword values \*/ overflow: visible; overflow: hidden; overflow: clip; overflow: scroll; overflow: auto; overflow: hidden visible; /\* Global values \*/ overflow: inherit; overflow: initial; overflow: revert; overflow: revert-layer; overflow: unset; ``` The `overflow` property is specified as one or two keywords chosen from the list of values below. If two keywords are specified, the first applies to `overflow-x` and the second to `overflow-y`. Otherwise, both `overflow-x` and `overflow-y` are set to the same value. ### Values `visible` Content is not clipped and may be rendered outside the padding box. `hidden` Content is clipped if necessary to fit the padding box. No scrollbars are provided, and no support for allowing the user to scroll (such as by dragging or using a scroll wheel) is allowed. The content *can* be scrolled programmatically (for example, by setting the value of a property such as [`scrollLeft`](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollLeft) or the [`scrollTo()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTo) method), so the element is still a scroll container. `clip` Similar to `hidden`, the content is clipped to the element's padding box. The difference between `clip` and `hidden` is that the `clip` keyword also forbids all scrolling, including programmatic scrolling. The box is not a scroll container, and does not start a new formatting context. If you wish to start a new formatting context, you can use [`display: flow-root`](display#flow-root) to do so. `scroll` Content is clipped if necessary to fit the padding box. Browsers always display scrollbars whether or not any content is actually clipped, preventing scrollbars from appearing or disappearing as content changes. Printers may still print overflowing content. `auto` Depends on the [user agent](https://developer.mozilla.org/en-US/docs/Glossary/User_agent). If content fits inside the padding box, it looks the same as `visible`, but still establishes a new block formatting context. Desktop browsers provide scrollbars if content overflows. `overlay` Deprecated Behaves the same as `auto`, but with the scrollbars drawn on top of content instead of taking up space. #### Mozilla extensions `-moz-scrollbars-none` Deprecated Use `overflow: hidden` instead. `-moz-scrollbars-horizontal` Deprecated Use `[`overflow-x`](overflow-x): scroll` and `[`overflow-y`](overflow-y): hidden`, or `overflow: scroll hidden` instead. `-moz-scrollbars-vertical` Deprecated Use `[`overflow-x`](overflow-x): hidden` and `[`overflow-y`](overflow-y): scroll`, or `overflow: hidden scroll` instead. `-moz-hidden-unscrollable` Deprecated Use `overflow: clip` instead. As of Firefox 63, `-moz-scrollbars-none`, `-moz-scrollbars-horizontal`, and `-moz-scrollbars-vertical` are behind a feature preference setting. In about:config, set `layout.css.overflow.moz-scrollbars.enabled` to `true`. Description ----------- Overflow options include clipping, showing scrollbars, or displaying the content flowing out of its container into the surrounding area. Specifying a value other than `visible` (the default) or `clip` creates a new [block formatting context](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context). This is necessary for technical reasons — if a float intersected with the scrolling element it would forcibly rewrap the content after each scroll step, leading to a slow scrolling experience. In order for `overflow` to have an effect, the block-level container must have either a set height (`height` or `max-height`) or `white-space` set to `nowrap`. Setting one axis to `visible` (the default) while setting the other to a *different* value results in `visible` behaving as `auto`. The JavaScript [`Element.scrollTop`](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTop) property may be used to scroll an HTML element even when `overflow` is set to `hidden`. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `visible` | | Applies to | Block-containers, flex containers, and grid containers | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`overflow-x`](overflow-x): as specified, except with `visible`/`clip` computing to `auto`/`hidden` respectively if one of [`overflow-x`](overflow-x) or [`overflow-y`](overflow-y) is neither `visible` nor clip * [`overflow-y`](overflow-y): as specified, except with `visible`/`clip` computing to `auto`/`hidden` respectively if one of [`overflow-x`](overflow-x) or [`overflow-y`](overflow-y) is neither `visible` nor clip | | Animation type | discrete | Formal syntax ------------- ``` overflow = [[](value_definition_syntax#brackets) visible [|](value_definition_syntax#single_bar) hidden [|](value_definition_syntax#single_bar) clip [|](value_definition_syntax#single_bar) scroll [|](value_definition_syntax#single_bar) auto []](value_definition_syntax#brackets)[{1,2}](value_definition_syntax#curly_braces) ``` Examples -------- ### Setting different overflow values for text #### HTML ``` <div> <code>visible</code> <p class="visible"> Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium. </p> </div> <div> <code>hidden</code> <p class="hidden"> Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium. </p> </div> <div> <code>scroll</code> <p class="scroll"> Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium. </p> </div> <div> <code>auto</code> <p class="auto"> Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium. </p> </div> ``` #### CSS ``` body { display: flex; justify-content: space-around; } div { margin: 1em; font-size: 1.2em; } p { width: 8em; height: 5em; border: dotted; } p.visible { overflow: visible; } p.hidden { overflow: hidden; } p.scroll { overflow: scroll; } p.auto { overflow: auto; } ``` #### Result ### Accessibility Concerns A scrolling content area cannot be scrolled by a keyboard-only user, with the exception of users on Firefox (which makes the container keyboard focusable by default). As a developer, to allow non-Firefox keyboard-only users to scroll the container you will need to give it a [`tabindex`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex) using `tabindex="0"`. Unfortunately, when a screen reader encounters this tab-stop, they will have no context for what it is and their screen reader will likely announce the entirety of its contents. Giving it an appropriate [WAI-ARIA role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles) (`role="region"`, for example) and an accessible name (via [`aria-label`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label) or [`aria-labelledby`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-labelledby)) can mitigate this. * [Keyboard-Only Scrolling Areas](https://adrianroselli.com/2022/06/keyboard-only-scrolling-areas.html) Specifications -------------- | Specification | | --- | | [CSS Overflow Module Level 3 # propdef-overflow](https://w3c.github.io/csswg-drafts/css-overflow/#propdef-overflow) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `overflow` | 1 | 12 | 1 After Firefox 3.6, the `overflow` property is correctly applied to table group elements (`<thead>`, `<tbody>`, `<tfoot>`). | 4 From version 4 to 6, Internet Explorer enlarges an element with `overflow: visible` (default value) to fit the content inside it. `height` and `width` behave like `min-height` and `min-width`, respectively. | 7 | 1 | 37 | 18 | 4 | 14 | 1 | 1.0 | | `clip` | 90 | 90 | 81 1.5-81 | No | 76 | 16 | 90 | 90 | 81 4-81 | No | 16 | 15.0 | | `multiple_keywords` | 68 | 79 | 61 | No | 55 | preview | 68 | 68 | 61 | 48 | No | 10.0 | | `overlay` | 15 | 79 | No | No | 15 | No | 100 | 100 | No | No | No | 4.0 | See also -------- * Related CSS properties: [`text-overflow`](text-overflow), [`white-space`](white-space), [`overflow-x`](overflow-x), [`overflow-y`](overflow-y), [`overflow-inline`](overflow-inline), [`overflow-block`](overflow-block), [`clip`](clip), [`display`](display) * [CSS Overflow](css_overflow) and [Debug scrollable overflow](https://firefox-source-docs.mozilla.org/devtools-user/page_inspector/how_to/debug_scrollable_overflow/index.html) css <display-listitem> <display-listitem> ================== The `list-item` keyword causes the element to generate a `::marker` pseudo-element with the content specified by its [`list-style`](list-style) properties (for example a bullet point) together with a principal box of the specified type for its own contents. Syntax ------ A single value of `list-item` will cause the element to behave like a list item. This can be used together with [`list-style-type`](list-style-type) and [`list-style-position`](list-style-position). `list-item` can also be combined with any [`<display-outside>`](display-outside) keyword and the `flow` or `flow-root` [`<display-inside>`](display-inside) keywords. **Note:** In browsers that support the two-value syntax, if no inner value is specified it will default to `flow`. If no outer value is specified, the principal box will have an outer display type of `block`. Formal syntax ------------- ``` <display-listitem> = <display-outside>[?](value_definition_syntax#question_mark) [&&](value_definition_syntax#double_ampersand) [[](value_definition_syntax#brackets) flow [|](value_definition_syntax#single_bar) flow-root []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) [&&](value_definition_syntax#double_ampersand) list-item <display-outside> = block [|](value_definition_syntax#single_bar) inline [|](value_definition_syntax#single_bar) run-in ``` Examples -------- ### HTML ``` <div class="fake-list">I will display as a list item</div> ``` ### CSS ``` .fake-list { display: list-item; list-style-position: inside; } ``` ### Result Specifications -------------- | Specification | | --- | | [CSS Display Module Level 3 # typedef-display-listitem](https://w3c.github.io/csswg-drafts/css-display/#typedef-display-listitem) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `display-listitem` | 1 | 12 | 1 | 6 | 7 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | | `legend-support` | 71 | 79 | 64 | No | 58 | No | 71 | 71 | 64 | 50 | No | 10.0 | See also -------- * [`display`](display) + [`<display-outside>`](display-outside) + [`<display-inside>`](display-inside) + [`<display-internal>`](display-internal) + [`<display-box>`](display-box) + [`<display-legacy>`](display-legacy) css flex-direction flex-direction ============== The `flex-direction` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets how flex items are placed in the flex container defining the main axis and the direction (normal or reversed). Try it ------ Note that the values `row` and `row-reverse` are affected by the directionality of the flex container. If its [`dir`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#dir) attribute is `ltr`, `row` represents the horizontal axis oriented from the left to the right, and `row-reverse` from the right to the left; if the `dir` attribute is `rtl`, `row` represents the axis oriented from the right to the left, and `row-reverse` from the left to the right. Syntax ------ ``` /\* The direction text is laid out in a line \*/ flex-direction: row; /\* Like <row>, but reversed \*/ flex-direction: row-reverse; /\* The direction in which lines of text are stacked \*/ flex-direction: column; /\* Like <column>, but reversed \*/ flex-direction: column-reverse; /\* Global values \*/ flex-direction: inherit; flex-direction: initial; flex-direction: revert; flex-direction: revert-layer; flex-direction: unset; ``` ### Values The following values are accepted: `row` The flex container's main-axis is defined to be the same as the text direction. The **main-start** and **main-end** points are the same as the content direction. `row-reverse` Behaves the same as `row` but the **main-start** and **main-end** points are opposite to the content direction. `column` The flex container's main-axis is the same as the block-axis. The **main-start** and **main-end** points are the same as the **before** and **after** points of the writing-mode. `column-reverse` Behaves the same as `column` but the **main-start** and **main-end** are opposite to the content direction. Accessibility concerns ---------------------- Using the `flex-direction` property with values of `row-reverse` or `column-reverse` will create a disconnect between the visual presentation of content and DOM order. This will adversely affect users experiencing low vision navigating with the aid of assistive technology such as a screen reader. If the visual (CSS) order is important, then screen reader users will not have access to the correct reading order. * [Flexbox & the keyboard navigation disconnect — Tink](https://tink.uk/flexbox-the-keyboard-navigation-disconnect/) * [Source Order Matters | Adrian Roselli](https://adrianroselli.com/2015/09/source-order-matters.html) * [MDN Understanding WCAG, Guideline 1.3 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.3_%e2%80%94_create_content_that_can_be_presented_in_different_ways) * [Understanding Success Criterion 1.3.2 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/content-structure-separation-sequence.html) Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `row` | | Applies to | flex containers | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` flex-direction = row [|](value_definition_syntax#single_bar) row-reverse [|](value_definition_syntax#single_bar) column [|](value_definition_syntax#single_bar) column-reverse ``` Examples -------- ### Reversing flex container columns and rows #### HTML ``` <h4>This is a Column-Reverse</h4> <div id="col-rev" class="content"> <div class="box red">A</div> <div class="box lightblue">B</div> <div class="box yellow">C</div> </div> <h4>This is a Row-Reverse</h4> <div id="row-rev" class="content"> <div class="box red">A</div> <div class="box lightblue">B</div> <div class="box yellow">C</div> </div> ``` #### CSS ``` .content { width: 200px; height: 200px; border: 1px solid #c3c3c3; display: flex; } .box { width: 50px; height: 50px; } #col-rev { flex-direction: column-reverse; } #row-rev { flex-direction: row-reverse; } .red { background-color: red; } .lightblue { background-color: lightblue; } .yellow { background-color: yellow; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Flexible Box Layout Module Level 1 # flex-direction-property](https://w3c.github.io/csswg-drafts/css-flexbox/#flex-direction-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `flex-direction` | 29 21 | 12 12 | 81 49 20 ["Since Firefox 28, multi-line flexbox is supported.", "Before Firefox 81, overflow with `*-reverse` is unsupported. See [bug 1042151](https://bugzil.la/1042151)."] | 11 10 | 15 12.1 | 9 7 | ≤37 4.4 | 29 25 | 81 49 20 ["Since Firefox 28, multi-line flexbox is supported.", "Before Firefox 81, overflow with `*-reverse` is unsupported. See [bug 1042151](https://bugzil.la/1042151)."] | 14 12.1 | 9 7 | 2.0 1.5 | See also -------- * CSS Flexbox Guide: *[Basic Concepts of Flexbox](css_flexible_box_layout/basic_concepts_of_flexbox)* * CSS Flexbox Guide: *[Ordering flex items](css_flexible_box_layout/ordering_flex_items)* css -moz-image-rect -moz-image-rect =============== **Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future. **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `-moz-image-rect` value for [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [`background-image`](background-image) lets you use a portion of a larger image as a background. Syntax ------ ``` -moz-image-rect(url(), top, right, bottom, left); ``` ### Values [`url()`](url) The URI of the image from which to take the sub-image. `top` The top edge, specified as an [`<integer>`](integer) or [`<percentage>`](percentage), of the sub-image within the specified image. `right` The right edge, specified as an [`<integer>`](integer) or [`<percentage>`](percentage), of the sub-image within the specified image. `bottom` The bottom edge, specified as an [`<integer>`](integer) or [`<percentage>`](percentage), of the sub-image within the specified image. `left` The left edge, specified as an [`<integer>`](integer) or [`<percentage>`](percentage), of the sub-image within the specified image. Description ----------- This property allows you to, for example, use different parts of one larger image as backgrounds in different parts of your content. This works very similarly to the [`-moz-image-region`](-moz-image-region) property, which is used with the [`list-style-image`](list-style-image) property to use parts of an image as the bullets in lists. However, this can be used for any CSS background. The syntax for the rectangle is similar to the [`rect()`](shape#syntax) function generating a [`<shape>`](shape) CSS type. All four values are relative to the upper left corner of the image. Examples -------- This example loads an image and uses it in four segments to draw the Firefox logo in four [`<div>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div) blocks. Clicking on their container causes the four segments to rotate around by swapping the [`background-image`](background-image) property values among the four [`<div>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div) blocks. ### CSS The CSS defines one container style, then the styles for the four boxes that comprise the complete image. The container looks like this: ``` #container { width: 267px; height: 272px; top: 100px; left: 100px; position: absolute; font-size: 16px; text-shadow: white 0px 0px 6px; text-align: center; } ``` Then the four boxes defining the segments of the image are defined. Let's look at them one at a time. ``` #box1 { background-image: -moz-image-rect(url(firefox.png), 0%, 50%, 50%, 0%); width: 133px; height: 136px; position: absolute; } ``` This is the top-left corner of the image. It defines a rectangle containing the top-left quarter of the image in the file `firefox.jpg`. ``` #box2 { background-image: -moz-image-rect(url(firefox.png), 0%, 100%, 50%, 50%); width: 133px; height: 136px; position: absolute; } ``` This defines the top-right corner of the image. The other corners follow a similar pattern: ``` #box3 { background-image: -moz-image-rect(url(firefox.png), 50%, 50%, 100%, 0%); width: 133px; height: 136px; position: absolute; } #box4 { background-image: -moz-image-rect(url(firefox.png), 50%, 100%, 100%, 50%); width: 133px; height: 136px; position: absolute; } ``` ### HTML The HTML is quite simple: ``` <div id="container" onclick="rotate()"> <div id="box1" style="left:0px;top:0px;">Top left</div> <div id="box2" style="left:133px;top:0px;">Top right</div> <div id="box3" style="left:0px;top:136px;">Bottom left</div> <div id="box4" style="left:133px;top:136px;">Bottom right</div> </div> ``` This places the four segments of our image in a two-by-two box grid. These four segments are all contained within a larger [`<div>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div) block whose primary purpose is to receive click events and dispatch them to our JavaScript code. ### The JavaScript code This code handles the click event when the container receives a mouse click. ``` function rotate() { let prevStyle = window .getComputedStyle(document.getElementById("box4"), null) .getPropertyValue("background-image"); // Now that we've saved the last one, start rotating for (let i = 1; i <= 4; i++) { const curId = `box${i}`; // Shift the background images const curStyle = window .getComputedStyle(document.getElementById(curId), null) .getPropertyValue("background-image"); document.getElementById(curId).style.backgroundImage = prevStyle; prevStyle = curStyle; } } ``` This uses [`window.getComputedStyle()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle) to fetch the style of each element, shifting it to the following element. Notice that before it begins doing so it saves a copy of the last box's style since it will be overwritten by the third element's style. By copying the values of the [`background-image`](background-image) property from one element to the next with each mouse click, we achieve the desired effect. ### What it looks like Specifications -------------- Not part of any standard. Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `-moz-image-rect` | No | No | 4 | No | No | No See [WebKit bug 32177](https://webkit.org/b/32177). | No | No | 4 | No | No See [WebKit bug 32177](https://webkit.org/b/32177). | No | See also -------- * [Mozilla CSS extensions](https://developer.mozilla.org/en-US/docs/Web/CSS/Mozilla_Extensions) * [CSS Backgrounds and Borders module](css_backgrounds_and_borders)
programming_docs
css Custom properties (--*): CSS variables Custom properties (--\*): CSS variables ======================================= Property names that are prefixed with `--`, like `--example-name`, represent *custom properties* that contain a value that can be used in other declarations using the [`var()`](var()) function. Custom properties are scoped to the element(s) they are declared on, and participate in the cascade: the value of such a custom property is that from the declaration decided by the cascading algorithm. | | | | --- | --- | | [Initial value](initial_value) | see prose | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified with variables substituted | | Animation type | discrete | Syntax ------ ``` --somekeyword: left; --somecolor: #0000ff; --somecomplexvalue: 3px 6px rgb(20, 32, 54); ``` `<declaration-value>` This value matches any sequence of one or more tokens, so long as the sequence does not contain an disallowed token. It represents the entirety of what a valid declaration can have as its value. **Note:** Custom property names are case sensitive — `--my-color` will be treated as a separate custom property to `--My-color`. Example ------- ### HTML ``` <p id="firstParagraph"> This paragraph should have a blue background and yellow text. </p> <p id="secondParagraph"> This paragraph should have a yellow background and blue text. </p> <div id="container"> <p id="thirdParagraph"> This paragraph should have a green background and yellow text. </p> </div> ``` ### CSS ``` :root { --first-color: #16f; --second-color: #ff7; } #firstParagraph { background-color: var(--first-color); color: var(--second-color); } #secondParagraph { background-color: var(--second-color); color: var(--first-color); } #container { --first-color: #290; } #thirdParagraph { background-color: var(--first-color); color: var(--second-color); } ``` ### Result Specifications -------------- | Specification | | --- | | [CSS Custom Properties for Cascading Variables Module Level 1 # defining-variables](https://w3c.github.io/csswg-drafts/css-variables/#defining-variables) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `--*` | 49 | 15 | 31 | No | 36 | 9.1 | 49 | 49 | 31 | 36 | 9.3 | 5.0 | | `env` | 69 | 79 | 65 | No | 56 | 11.1 11-11.1 | 69 | 69 | 65 | 48 | 11.3 11-11.3 | 10.0 | | `var` | 49 | 15 | 31 | No | 36 | 9.1 | 50 | 49 | 31 | 36 | 9.3 | 5.0 | See also -------- * [Using CSS variables](using_css_custom_properties) * The [`var()`](var()) function css border-block-start-width border-block-start-width ======================== The `border-block-start-width` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the width of the logical block-start border of an element, which maps to a physical border width depending on the element's writing mode, directionality, and text orientation. It corresponds to the [`border-top-width`](border-top-width), [`border-right-width`](border-right-width), [`border-bottom-width`](border-bottom-width), or [`border-left-width`](border-left-width) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ Syntax ------ ``` /\* <'border-width'> values \*/ border-block-start-width: 5px; border-block-start-width: thick; /\* Global values \*/ border-block-start-width: inherit; border-block-start-width: initial; border-block-start-width: revert; border-block-start-width: revert-layer; border-block-start-width: unset; ``` Related properties are [`border-block-end-width`](border-block-end-width), [`border-inline-start-width`](border-inline-start-width), and [`border-inline-end-width`](border-inline-end-width), which define the other border widths of the element. | | | | --- | --- | | [Initial value](initial_value) | `medium` | | Applies to | all elements | | [Inherited](inheritance) | no | | Percentages | logical-width of containing block | | [Computed value](computed_value) | absolute length; `0` if the border style is `none` or `hidden` | | Animation type | a [length](length#interpolation) | ### Values `<'border-width'>` The width of the border. See [`border-width`](border-width). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `medium` | | Applies to | all elements | | [Inherited](inheritance) | no | | Percentages | logical-width of containing block | | [Computed value](computed_value) | absolute length; `0` if the border style is `none` or `hidden` | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` border-block-start-width = <'border-top-width'> ``` Examples -------- ### Border width with vertical text #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; border: 1px solid blue; border-block-start-width: 5px; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # border-width](https://w3c.github.io/csswg-drafts/css-logical/#border-width) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-block-start-width` | 69 | 79 | 41 | No | 56 | 12.1 | 69 | 69 | 41 | 48 | 12.2 | 10.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * This property maps to one of the physical border properties: [`border-top-width`](border-top-width), [`border-right-width`](border-right-width), [`border-bottom-width`](border-bottom-width), and [`border-left-width`](border-left-width) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css <blend-mode> <blend-mode> ============ The `<blend-mode>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) describes how colors should appear when elements overlap. It is used in the [`background-blend-mode`](background-blend-mode) and [`mix-blend-mode`](mix-blend-mode) properties. Syntax ------ The `<blend-mode>` data type is defined using a keyword value chosen from the list below. ### Values `normal` The final color is the top color, regardless of what the bottom color is. The effect is like two opaque pieces of paper overlapping. `multiply` The final color is the result of multiplying the top and bottom colors. A black layer leads to a black final layer, and a white layer leads to no change. The effect is like two images printed on transparent film overlapping. `screen` The final color is the result of inverting the colors, multiplying them, and inverting that value. A black layer leads to no change, and a white layer leads to a white final layer. The effect is like two images shone onto a projection screen. `overlay` The final color is the result of `multiply` if the bottom color is darker, or `screen` if the bottom color is lighter. This blend mode is equivalent to `hard-light` but with the layers swapped. `darken` The final color is composed of the darkest values of each color channel. `lighten` The final color is composed of the lightest values of each color channel. `color-dodge` The final color is the result of dividing the bottom color by the inverse of the top color. A black foreground leads to no change. A foreground with the inverse color of the backdrop leads to a fully lit color. This blend mode is similar to `screen`, but the foreground need only be as light as the inverse of the backdrop to create a fully lit color. `color-burn` The final color is the result of inverting the bottom color, dividing the value by the top color, and inverting that value. A white foreground leads to no change. A foreground with the inverse color of the backdrop leads to a black final image. This blend mode is similar to `multiply`, but the foreground need only be as dark as the inverse of the backdrop to make the final image black. `hard-light` The final color is the result of `multiply` if the top color is darker, or `screen` if the top color is lighter. This blend mode is equivalent to `overlay` but with the layers swapped. The effect is similar to shining a *harsh* spotlight on the backdrop. `soft-light` The final color is similar to `hard-light`, but softer. This blend mode behaves similar to `hard-light`. The effect is similar to shining a *diffused* spotlight on the backdrop\*.\* `difference` The final color is the result of subtracting the darker of the two colors from the lighter one. A black layer has no effect, while a white layer inverts the other layer's color. `exclusion` The final color is similar to `difference`, but with less contrast. As with `difference`, a black layer has no effect, while a white layer inverts the other layer's color. `hue` The final color has the *hue* of the top color, while using the *saturation* and *luminosity* of the bottom color. `saturation` The final color has the *saturation* of the top color, while using the *hue* and *luminosity* of the bottom color. A pure gray backdrop, having no saturation, will have no effect. `color` The final color has the *hue* and *saturation* of the top color, while using the *luminosity* of the bottom color. The effect preserves gray levels and can be used to colorize the foreground. `luminosity` The final color has the *luminosity* of the top color, while using the *hue* and *saturation* of the bottom color. This blend mode is equivalent to `color`, but with the layers swapped. Description ----------- For each pixel among the layers to which it is applied, a blend mode takes the colors of the foreground and the background, performs a calculation on them, and returns a new color value. Changes between blend modes are not interpolated. Any change occurs immediately. Formal syntax ------------- ``` <blend-mode> = normal [|](value_definition_syntax#single_bar) multiply [|](value_definition_syntax#single_bar) screen [|](value_definition_syntax#single_bar) overlay [|](value_definition_syntax#single_bar) darken [|](value_definition_syntax#single_bar) lighten [|](value_definition_syntax#single_bar) color-dodge [|](value_definition_syntax#single_bar) color-burn [|](value_definition_syntax#single_bar) hard-light [|](value_definition_syntax#single_bar) soft-light [|](value_definition_syntax#single_bar) difference [|](value_definition_syntax#single_bar) exclusion [|](value_definition_syntax#single_bar) hue [|](value_definition_syntax#single_bar) saturation [|](value_definition_syntax#single_bar) color [|](value_definition_syntax#single_bar) luminosity ``` Examples -------- ### Example using "normal" ``` #div { width: 300px; height: 300px; background: url("br.png"), url("tr.png"); background-blend-mode: normal; } ``` ### Example using "multiply" ``` #div { width: 300px; height: 300px; background: url("br.png"), url("tr.png"); background-blend-mode: multiply; } ``` ### Example using "screen" ``` #div { width: 300px; height: 300px; background: url("br.png"), url("tr.png"); background-blend-mode: screen; } ``` ### Example using "overlay" ``` #div { width: 300px; height: 300px; background: url("br.png"), url("tr.png"); background-blend-mode: overlay; } ``` ### Example using "darken" ``` #div { width: 300px; height: 300px; background: url("br.png"), url("tr.png"); background-blend-mode: darken; } ``` ### Example using "lighten" ``` #div { width: 300px; height: 300px; background: url("br.png"), url("tr.png"); background-blend-mode: lighten; } ``` ### Example using "color-dodge" ``` #div { width: 300px; height: 300px; background: url("br.png"), url("tr.png"); background-blend-mode: color-dodge; } ``` ### Example using "color-burn" ``` #div { width: 300px; height: 300px; background: url("br.png"), url("tr.png"); background-blend-mode: color-burn; } ``` ### Example using "hard-light" ``` #div { width: 300px; height: 300px; background: url("br.png"), url("tr.png"); background-blend-mode: hard-light; } ``` ### Example using "soft-light" ``` #div { width: 300px; height: 300px; background: url("br.png"), url("tr.png"); background-blend-mode: soft-light; } ``` ### Example using "difference" ``` #div { width: 300px; height: 300px; background: url("br.png"), url("tr.png"); background-blend-mode: difference; } ``` ### Example using "exclusion" ``` #div { width: 300px; height: 300px; background: url("br.png"), url("tr.png"); background-blend-mode: exclusion; } ``` ### Example using "hue" ``` #div { width: 300px; height: 300px; background: url("br.png"), url("tr.png"); background-blend-mode: hue; } ``` ### Example using "saturation" ``` #div { width: 300px; height: 300px; background: url("br.png"), url("tr.png"); background-blend-mode: saturation; } ``` ### Example using "color" ``` #div { width: 300px; height: 300px; background: url("br.png"), url("tr.png"); background-blend-mode: color; } ``` ### Example using "luminosity" ``` #div { width: 300px; height: 300px; background: url("br.png"), url("tr.png"); background-blend-mode: luminosity; } ``` ### Blend mode comparison In the following example, we have a `<div>` with two background images set on it — a Firefox logo on top of a linear gradient. Below it, we have a provided a `<select>` menu that allows you to change the `background-blend-mode` applied to the `<div>`, allowing you to compare the different blend mode effects. #### HTML ``` <div></div> <p>Choose a blend-mode:</p> <select> <option selected>normal</option> <option>multiply</option> <option>screen</option> <option>overlay</option> <option>darken</option> <option>lighten</option> <option>color-dodge</option> <option>color-burn</option> <option>hard-light</option> <option>soft-light</option> <option>difference</option> <option>exclusion</option> <option>hue</option> <option>saturation</option> <option>color</option> <option>luminosity</option> </select> ``` #### CSS ``` div { width: 300px; height: 300px; background: url(https://media.prod.mdn.mozit.cloud/attachments/2020/07/29/17350/3b4892b7e820122ac6dd7678891d4507/firefox.png) no-repeat center, linear-gradient(to bottom, blue, orange); } ``` #### JavaScript ``` const selectElem = document.querySelector('select'); const divElem = document.querySelector('div'); selectElem.addEventListener('change', () => { divElem.style.backgroundBlendMode = selectElem.value; }); ``` #### Result Specifications -------------- | Specification | | --- | | [Compositing and Blending Level 1 # ltblendmodegt](https://drafts.fxtf.org/compositing/#ltblendmodegt) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `blend-mode` | 35 | 79 | 30 | No | 22 | 8 | 59 | 59 | 54 | 22 | 8 | 7.0 | See also -------- * Properties that use this data type: [`background-blend-mode`](background-blend-mode), [`mix-blend-mode`](mix-blend-mode) Description to various blend modes on other website: * [Blend modes](https://en.wikipedia.org/wiki/Blend_modes) on Wikipedia * [Blending modes in Adobe Photoshop](https://helpx.adobe.com/photoshop/using/blending-modes.html) by Adobe css text-size-adjust text-size-adjust ================ **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `text-size-adjust` [CSS](https://developer.mozilla.org/en-US/docs/Web/API/CSS) property controls the text inflation algorithm used on some smartphones and tablets. Other browsers will ignore this property. ``` /\* Keyword values \*/ text-size-adjust: none; text-size-adjust: auto; /\* <percentage> value \*/ text-size-adjust: 80%; /\* Global values \*/ text-size-adjust: inherit; text-size-adjust: initial; text-size-adjust: revert; text-size-adjust: revert-layer; text-size-adjust: unset; ``` Because many websites have not been developed with small devices in mind, mobile browsers differ from desktop browsers in the way they render web pages. Instead of laying out pages at the width of the device screen, they lay them out using a [viewport](https://developer.mozilla.org/en-US/docs/Glossary/Viewport) that is much wider, usually 800 or 1000 pixels. To map the extra-wide layout back to the original device size, they either show only part of the whole render or scale the viewport down to fit. Since text that has been scaled down to fit a mobile screen may be very small, many mobile browsers apply a text inflation algorithm to enlarge the text to make it more readable. When an element containing text uses 100% of the screen's width, the algorithm increases its text size, but without modifying the layout. The `text-size-adjust` property allows web authors to disable or modify this behavior, as web pages designed with small screens in mind do not need it. Syntax ------ The `text-size-adjust` property is specified as `none`, `auto`, or a `<percentage>`. ### Values `none` Disables the browser's inflation algorithm. `auto` Enables the browser's inflation algorithm. This value is used to cancel a `none` value previously set with CSS. `<percentage>` Enables the browser's inflation algorithm, specifying a percentage value with which to increase the font size. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` for smartphone browsers supporting inflation, `none` in other cases (and then not modifiable). | | Applies to | all elements | | [Inherited](inheritance) | yes | | Percentages | yes, refer to the corresponding size of the text font | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` text-size-adjust = auto [|](value_definition_syntax#single_bar) none [|](value_definition_syntax#single_bar) [<percentage [0,∞]>](percentage) ``` Examples -------- ### Basic disabling usage As hinted at above, on a properly designed responsive site the `text-size-adjust` behavior is not needed, so developers can elect to turn it off by specifying a value of none: ``` p { -webkit-text-size-adjust: none; text-size-adjust: none; } ``` Specifications -------------- | Specification | | --- | | [CSS Mobile Text Size Adjustment Module Level 1 # adjustment-control](https://w3c.github.io/csswg-drafts/css-size-adjust/#adjustment-control) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `text-size-adjust` | 54 | 79 12-79 | No | No | 41 | No | 54 | 54 | 49 14 | 41 | 1 | 6.0 | | `percentages` | 54 | 12 | No | No | 41 | No | 54 | 54 | No | 41 | No | 6.0 | See also -------- * [Apple's documentation](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/AdjustingtheTextSize/AdjustingtheTextSize.html#//apple_ref/doc/uid/TP40006510-SW16) * [Google Chrome behavior description](https://tinyurl.com/TextAutosizer) * [Gecko's behavior description](https://dbaron.org/log/20111126-font-inflation), by L. David Baron * [Microsoft's documentation](https://msdn.microsoft.com/library/windows/apps/ff462082(v=vs.105).aspx#BKMK_AdjustingTextSizewithCustomCSS)
programming_docs
css <position> <position> ========== The `<position>` (or `<bg-position>`) [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) denotes a two-dimensional coordinate used to set a location relative to an element box. It is used in the [`background-position`](background-position) and [`offset-anchor`](offset-anchor) properties. **Note:** The final position described by the `<position>` value does not need to be inside the element's box. Syntax ------ The `<position>` data type is specified with one or two keywords, with optional offsets. The keyword values are `center`, `top`, `right`, `bottom`, and `left`. Each keyword represents either an edge of the element's box or the center line between two edges. Depending on the context, `center` represents either the center between the left and right edges, or the center between the top and bottom edges. If specified, an offset can be either a relative [`<percentage>`](percentage) value or an absolute [`<length>`](length) value. Positive values are offset towards the right or the bottom, whichever is appropriate. Negative values are offset in the opposite directions. If only a single offset value is specified, it defines the x-coordinate, with the value for the other axis defaulting to `center`. ``` /\* 1-value syntax \*/ keyword /\* Either the horizontal or vertical position; the other axis defaults to center \*/ value /\* The position on the x-axis; the y-axis defaults to 50% \*/ /\* 2-value syntax \*/ keyword keyword /\* A keyword for each direction (the order is irrelevant) \*/ keyword value /\* A keyword for horizontal position, value for vertical position \*/ value keyword /\* A value for horizontal position, keyword for vertical position \*/ value value /\* A value for each direction (horizontal then vertical) \*/ /\* 4-value syntax \*/ keyword value keyword value /\* Each value is an offset from the keyword that precedes it \*/ ``` **Note:** The [`background-position`](background-position) property also accepts a three-value syntax. This is not allowed in other properties that use `<position>`. Interpolation ------------- When animated, a point's abscissa and ordinate values are interpolated independently. However, because the speed of the interpolation is determined by a single [timing function](easing-function) for both coordinates, the point will move in a straight line. Formal syntax ------------- ``` <position> = [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) right []](value_definition_syntax#brackets) [||](value_definition_syntax#double_bar) [[](value_definition_syntax#brackets) top [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) bottom []](value_definition_syntax#brackets) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) <length-percentage> []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) top [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) bottom [|](value_definition_syntax#single_bar) <length-percentage> []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) right []](value_definition_syntax#brackets) <length-percentage> []](value_definition_syntax#brackets) [&&](value_definition_syntax#double_ampersand) [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) top [|](value_definition_syntax#single_bar) bottom []](value_definition_syntax#brackets) <length-percentage> []](value_definition_syntax#brackets) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Valid positions ``` center left center top right 8.5% bottom 12vmin right -6px 10% 20% 8rem 14px ``` ### Invalid positions ``` left right bottom top 10px 15px 20px 15px ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # position](https://w3c.github.io/csswg-drafts/css-values/#position) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `position_value` | 1 | 12 | 1 | 4 | 3.5 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | | `four_value_syntax` | 25 | 12 | 13 | 9 | 10.5 | 7 | 4.4 | 25 | 14 | 14 | 7 | 1.5 | | `keyword_value_syntax` | 1 | 12 | 1 | 4 | 3.5 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [CSS Values and Units](css_values_and_units) * [CSS Values and Units introduction](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units) * [`background-position`](background-position) * [`radial-gradient()`](gradient/radial-gradient) * [`conic-gradient()`](gradient/conic-gradient) css border-bottom-width border-bottom-width =================== The `border-bottom-width` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the width of the bottom border of an element. Try it ------ Syntax ------ ``` /\* Keyword values \*/ border-bottom-width: thin; border-bottom-width: medium; border-bottom-width: thick; /\* <length> values \*/ border-bottom-width: 10em; border-bottom-width: 3vmax; border-bottom-width: 6px; /\* Global keywords \*/ border-bottom-width: inherit; border-bottom-width: initial; border-bottom-width: revert; border-bottom-width: revert-layer; border-bottom-width: unset; ``` ### Values `<line-width>` Defines the width of the border, either as an explicit nonnegative [`<length>`](length) or a keyword. If it's a keyword, it must be one of the following values: * `thin` * `medium` * `thick` **Note:** Because the specification doesn't define the exact thickness denoted by each keyword, the precise result when using one of them is implementation-specific. Nevertheless, they always follow the pattern `thin ≤ medium ≤ thick`, and the values are constant within a single document. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `medium` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | the absolute length or `0` if [`border-bottom-style`](border-bottom-style) is `none` or `hidden` | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` border-bottom-width = <line-width> <line-width> = [<length [0,∞]>](length) [|](value_definition_syntax#single_bar) thin [|](value_definition_syntax#single_bar) medium [|](value_definition_syntax#single_bar) thick ``` Examples -------- ### Comparing bottom border widths #### HTML ``` <div>Element 1</div> <div>Element 2</div> ``` #### CSS ``` div { border: 1px solid red; margin: 1em 0; } div:nth-child(1) { border-bottom-width: thick; } div:nth-child(2) { border-bottom-width: 2em; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # the-border-width](https://w3c.github.io/csswg-drafts/css-backgrounds/#the-border-width) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-bottom-width` | 1 | 12 | 1 | 4 | 3.5 | 1 | 2.2 | 18 | 4 | 10.1 | 1 | 1.0 | See also -------- * The other border-width-related CSS properties: [`border-left-width`](border-left-width), [`border-right-width`](border-right-width), [`border-top-width`](border-top-width), and [`border-width`](border-width). * The other border-bottom-related CSS properties: [`border`](border), [`border-bottom`](border-bottom), [`border-bottom-style`](border-bottom-style), and [`border-bottom-color`](border-bottom-color). css font-variant-caps font-variant-caps ================= The `font-variant-caps` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property controls the use of alternate glyphs for capital letters. Try it ------ When a given font includes capital letter glyphs of multiple different sizes, this property selects the most appropriate ones. If petite capital glyphs are not available, they are rendered using small capital glyphs. If these are not present, the browser synthesizes them from the uppercase glyphs. Fonts sometimes include special glyphs for various caseless characters (such as punctuation marks) to better match the capitalized characters around them. However, small capital glyphs are never synthesized for caseless characters. ### Language-specific rules This property accounts for language-specific case mapping rules. For example: * In Turkic languages, such as Turkish (tr), Azerbaijani (az), Crimean Tatar (crh), Volga Tatar (tt), and Bashkir (ba), there are two kinds of `i` (one with the dot, one without) and two case pairings: `i`/`İ` and `ı`/`I`. * In German (de), the `ß` may become `ẞ` (U+1E9E) in uppercase. * In Greek (el), vowels lose their accent when the whole word is in uppercase (`ά`/`Α`), except for the disjunctive eta (`ή`/`Ή`). Also, diphthongs with an accent on the first vowel lose the accent and gain a diacritic on the second vowel (`άι`/`ΑΪ`). Syntax ------ ``` /\* Keyword values \*/ font-variant-caps: normal; font-variant-caps: small-caps; font-variant-caps: all-small-caps; font-variant-caps: petite-caps; font-variant-caps: all-petite-caps; font-variant-caps: unicase; font-variant-caps: titling-caps; /\* Global values \*/ font-variant-caps: inherit; font-variant-caps: initial; font-variant-caps: revert; font-variant-caps: revert-layer; font-variant-caps: unset; ``` The `font-variant-caps` property is specified using a single keyword value from the list below. In each case, if the font doesn't support the OpenType value, then it synthesizes the glyphs. ### Values `normal` Deactivates of the use of alternate glyphs. `small-caps` Enables display of small capitals (OpenType feature: `smcp`). Small-caps glyphs typically use the form of uppercase letters but are reduced to the size of lowercase letters. `all-small-caps` Enables display of small capitals for both upper and lowercase letters (OpenType features: `c2sc`, `smcp`). `petite-caps` Enables display of petite capitals (OpenType feature: `pcap`). `all-petite-caps` Enables display of petite capitals for both upper and lowercase letters (OpenType features: `c2pc`, `pcap`). `unicase` Enables display of mixture of small capitals for uppercase letters with normal lowercase letters (OpenType feature: `unic`). `titling-caps` Enables display of titling capitals (OpenType feature: `titl`). Uppercase letter glyphs are often designed for use with lowercase letters. When used in all uppercase titling sequences they can appear too strong. Titling capitals are designed specifically for this situation. Accessibility concerns ---------------------- Large sections of text set with a `font-variant` value of `all-small-caps` or `all-petite-caps` may be difficult for people with cognitive concerns such as Dyslexia to read. * [MDN Understanding WCAG, Guideline 1.4 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background) * [W3C Understanding WCAG 2.1](https://www.w3.org/TR/WCAG21/#visual-presentation) Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` font-variant-caps = normal [|](value_definition_syntax#single_bar) small-caps [|](value_definition_syntax#single_bar) all-small-caps [|](value_definition_syntax#single_bar) petite-caps [|](value_definition_syntax#single_bar) all-petite-caps [|](value_definition_syntax#single_bar) unicase [|](value_definition_syntax#single_bar) titling-caps ``` Examples -------- ### Setting the small-caps font variant #### HTML ``` <p class="small-caps">Firefox rocks, small caps!</p> <p class="normal">Firefox rocks, normal caps!</p> ``` #### CSS ``` .small-caps { font-variant-caps: small-caps; font-style: italic; } .normal { font-variant-caps: normal; font-style: italic; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Fonts Module Level 4 # font-variant-caps-prop](https://w3c.github.io/csswg-drafts/css-fonts/#font-variant-caps-prop) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `font-variant-caps` | 52 | 79 | 34 | No | 39 | 9.1 | 52 | 52 | 34 | 41 | 9.3 | 6.0 | See also -------- * [`font-variant`](font-variant) * [`font-variant-alternates`](font-variant-alternates) * [`font-variant-east-asian`](font-variant-east-asian) * [`font-variant-emoji`](font-variant-emoji) * [`font-variant-ligatures`](font-variant-ligatures) * [`font-variant-numeric`](font-variant-numeric) * [`font-variant-position`](font-variant-position) css border-left border-left =========== The `border-left` [shorthand](shorthand_properties) [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets all the properties of an element's left <border>. Try it ------ 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: ``` border-left-style: dotted; border-left: thick green; ``` It is actually the same as this one: ``` border-left-style: dotted; border-left: none thick green; ``` The value of [`border-left-style`](border-left-style) given before `border-left` is ignored. Since the default value of [`border-left-style`](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: * [`border-left-color`](border-left-color) * [`border-left-style`](border-left-style) * [`border-left-width`](border-left-width) Syntax ------ ``` 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 [`border-left-width`](border-left-width). `<br-style>` See [`border-left-style`](border-left-style). [`<color>`](color_value) See [`border-left-color`](border-left-color). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`border-left-width`](border-left-width): `medium` * [`border-left-style`](border-left-style): `none` * [`border-left-color`](border-left-color): `currentcolor` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`border-left-width`](border-left-width): the absolute length or `0` if [`border-left-style`](border-left-style) is `none` or `hidden` * [`border-left-style`](border-left-style): as specified * [`border-left-color`](border-left-color): computed color | | Animation type | as each of the properties of the shorthand:* [`border-left-color`](border-left-color): a [color](color_value#interpolation) * [`border-left-style`](border-left-style): discrete * [`border-left-width`](border-left-width): a [length](length#interpolation) | Formal syntax ------------- ``` border-left = <line-width> [||](value_definition_syntax#double_bar) <line-style> [||](value_definition_syntax#double_bar) [<color>](color_value) <line-width> = [<length [0,∞]>](length) [|](value_definition_syntax#single_bar) thin [|](value_definition_syntax#single_bar) medium [|](value_definition_syntax#single_bar) thick <line-style> = none [|](value_definition_syntax#single_bar) hidden [|](value_definition_syntax#single_bar) dotted [|](value_definition_syntax#single_bar) dashed [|](value_definition_syntax#single_bar) solid [|](value_definition_syntax#single_bar) double [|](value_definition_syntax#single_bar) groove [|](value_definition_syntax#single_bar) ridge [|](value_definition_syntax#single_bar) inset [|](value_definition_syntax#single_bar) outset ``` Examples -------- ### Applying a left border #### HTML ``` <div>This box has a border on the left side.</div> ``` #### CSS ``` div { border-left: 4px dashed blue; background-color: gold; height: 100px; width: 100px; font-weight: bold; text-align: center; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # border-shorthands](https://w3c.github.io/csswg-drafts/css-backgrounds/#border-shorthands) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-left` | 1 | 12 | 1 | 4 | 3.5 | 1 | 4.4 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [`border`](border) * [`border-block`](border-block) * [`outline`](outline) * [Backgrounds and borders](css_backgrounds_and_borders) * [Learn CSS: Backgrounds and borders](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Backgrounds_and_borders) css padding-top padding-top =========== The `padding-top` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the height of the [padding area](css_box_model/introduction_to_the_css_box_model#padding_area) on the top of an element. Try it ------ An element's padding area is the space between its content and its border. **Note:** The [`padding`](padding) property can be used to set paddings on all four sides of an element with a single declaration. Syntax ------ ``` /\* <length> values \*/ padding-top: 0.5em; padding-top: 0; padding-top: 2cm; /\* <percentage> value \*/ padding-top: 10%; /\* Global values \*/ padding-top: inherit; padding-top: initial; padding-top: revert; padding-top: revert-layer; padding-top: unset; ``` The `padding-top` property is specified as a single value chosen from the list below. Unlike margins, negative values are not allowed for padding. ### Values [`<length>`](length) The size of the padding as a fixed value. Must be nonnegative. [`<percentage>`](percentage) The size of the padding as a percentage, relative to the inline size (*width* in a horizontal language, defined by [`writing-mode`](writing-mode)) of the [containing block](containing_block). Must be nonnegative. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | all elements, except `table-row-group`, `table-header-group`, `table-footer-group`, `table-row`, `table-column-group` and `table-column`. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | Percentages | refer to the width of the containing block | | [Computed value](computed_value) | the percentage as specified or the absolute length | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` padding-top = [<length-percentage [0,∞]>](length-percentage) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Setting top padding using pixels and percentages ``` .content { padding-top: 5%; } .sidebox { padding-top: 10px; } ``` Specifications -------------- | Specification | | --- | | [CSS Box Model Module Level 3 # padding-physical](https://w3c.github.io/csswg-drafts/css-box/#padding-physical) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `padding-top` | 1 | 12 | 1 | 4 | 3.5 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [Introduction to the CSS basic box model](css_box_model/introduction_to_the_css_box_model) * [`padding-right`](padding-right), [`padding-bottom`](padding-bottom), [`padding-left`](padding-left) and the [`padding`](padding) shorthand * The mapped logical properties: [`padding-block-start`](padding-block-start), [`padding-block-end`](padding-block-end), [`padding-inline-start`](padding-inline-start), and [`padding-inline-end`](padding-inline-end) and the shorthands [`padding-block`](padding-block) and [`padding-inline`](padding-inline)
programming_docs
css min() min() ===== The `min()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](css_functions) lets you set the smallest (most negative) value from a list of comma-separated expressions as the value of a CSS property value. The `min()` function can be used anywhere a [`<length>`](length), [`<frequency>`](frequency), [`<angle>`](angle), [`<time>`](time), [`<percentage>`](percentage), [`<number>`](number), or [`<integer>`](integer) is allowed. Try it ------ In the first above example, the width will be at most 200px, but will be smaller if the viewport is less than 400px wide (in which case 1vw would be 4px, so 50vw would be 200px). In other words, the maximum width is 200px. Think of the `min()` value as providing the *maximum* value a property can have. Syntax ------ The `min()` function takes one or more comma-separated expressions as its parameter, with the smallest (most negative) expression value result used as the value. The expressions can be math expressions (using arithmetic operators), literal values, or other expressions, such as [`attr()`](attr), that evaluate to a valid argument type (like [`<length>`](length)). You can use different units for each value in your expression, if you wish. You may also use parentheses to establish computation order when needed. ### Notes * 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 `max()` and other `min()` functions as expression values. The expressions are full math expressions, so you can use direct addition, subtraction, multiplication and division without using the `calc()` function itself. * The expression can be values combining the addition ( + ), subtraction ( - ), multiplication ( \* ) and division ( / ) operators, using standard operator precedence rules. Make sure to put a space on each side of the + and - operands. The operands in the expression may be any `<length>` syntax value. * You can (and often need to) combine `min()` and `max()` values, or use `min()` within a `clamp()` or `calc()` function. * You can provide more than two arguments, if you have multiple constraints to apply. ### Formal syntax ``` <min()> = min( <calc-sum>[#](value_definition_syntax#hash_mark) ) <calc-sum> = <calc-product> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '+' [|](value_definition_syntax#single_bar) '-' []](value_definition_syntax#brackets) <calc-product> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-product> = <calc-value> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '*' [|](value_definition_syntax#single_bar) '/' []](value_definition_syntax#brackets) <calc-value> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-value> = [<number>](number) [|](value_definition_syntax#single_bar) [<dimension>](dimension) [|](value_definition_syntax#single_bar) [<percentage>](percentage) [|](value_definition_syntax#single_bar) <calc-constant> [|](value_definition_syntax#single_bar) ( <calc-sum> ) <calc-constant> = e [|](value_definition_syntax#single_bar) pi [|](value_definition_syntax#single_bar) infinity [|](value_definition_syntax#single_bar) -infinity [|](value_definition_syntax#single_bar) NaN ``` Accessibility concerns ---------------------- When using `min()` to set a maximum font size, ensure that the font can still be scaled at least 200% for readability (without assistive technology like a zoom function). * [MDN Understanding WCAG, Guideline 1.4 explanations](https://developer.mozilla.org/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) Examples -------- ### Setting a maximum size for a label and input Another use case for CSS functions is to set a maximum size on responsive form controls: enabling the width of labels and inputs to shrink as the width of the form shrinks. Let's look at some CSS: ``` input, label { padding: 2px; box-sizing: border-box; display: inline-block; width: min(40%, 400px); background-color: pink; } form { margin: 4px; border: 1px solid black; padding: 4px; } ``` Here, the form itself, along with the margin, border, and padding, will be 100% of its parent's width. We declare the input and label to be the lesser of 40% of the form width up to the padding or 400px wide, whichever is smaller. In other words, the widest that the label and input can be is 400px. The narrowest they will be is 40% of the form's width, which on a smartwatch's screen is very small. ``` <form> <label for="misc">Type something:</label> <input type="text" id="misc" name="misc" /> </form> ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # calc-notation](https://w3c.github.io/csswg-drafts/css-values/#calc-notation) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `min` | 79 | 79 | 75 | No | 66 | 11.1 | 79 | 79 | 79 | 57 | 11.3 | 12.0 | See also -------- * [`calc()`](calc) * [`clamp()`](clamp) * [`max()`](max) * [CSS Values](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units) css font-variant-numeric font-variant-numeric ==================== The `font-variant-numeric` CSS property controls the usage of alternate glyphs for numbers, fractions, and ordinal markers. Try it ------ Syntax ------ ``` font-variant-numeric: normal; font-variant-numeric: ordinal; font-variant-numeric: slashed-zero; font-variant-numeric: lining-nums; /\* <numeric-figure-values> \*/ font-variant-numeric: oldstyle-nums; /\* <numeric-figure-values> \*/ font-variant-numeric: proportional-nums; /\* <numeric-spacing-values> \*/ font-variant-numeric: tabular-nums; /\* <numeric-spacing-values> \*/ font-variant-numeric: diagonal-fractions; /\* <numeric-fraction-values> \*/ font-variant-numeric: stacked-fractions; /\* <numeric-fraction-values> \*/ font-variant-numeric: oldstyle-nums stacked-fractions; /\* Global values \*/ font-variant-numeric: inherit; font-variant-numeric: initial; font-variant-numeric: revert; font-variant-numeric: revert-layer; font-variant-numeric: unset; ``` This property can take one of two forms: * either the keyword value `normal` * or one or more of the other values listed below, space-separated, in any order. ### Values `normal` This keyword leads to the deactivation of the use of such alternate glyphs. `ordinal` This keyword forces the use of special glyphs for the ordinal markers, like 1st, 2nd, 3rd, 4th in English or a 1a in Italian. It corresponds to the OpenType values `ordn`. `slashed-zero` This keyword forces the use of a 0 with a slash; this is useful when a clear distinction between O and 0 is needed. It corresponds to the OpenType values `zero`. *<numeric-figure-values*> These values control the figures used for numbers. Two values are possible: * `lining-nums` activating the set of figures where numbers are all lying on the baseline. It corresponds to the OpenType values `lnum`. * `oldstyle-nums` activating the set of figures where some numbers, like 3, 4, 7, 9 have descenders. It corresponds to the OpenType values `onum`. *<numeric-spacing-values*> These values controls the sizing of figures used for numbers. Two values are possible: * `proportional-nums` activating the set of figures where numbers are not all of the same size. It corresponds to the OpenType values `pnum`. * `tabular-nums` activating the set of figures where numbers are all of the same size, allowing them to be easily aligned like in tables. It corresponds to the OpenType values `tnum`. *<numeric-fraction-values*> These values controls the glyphs used to display fractions. Two values are possible: * `diagonal-fractions` activating the set of figures where the numerator and denominator are made smaller and separated by a slash. It corresponds to the OpenType values `frac`. * `stacked-fractions` activating the set of figures where the numerator and denominator are made smaller, stacked and separated by a horizontal line. It corresponds to the OpenType values `afrc`. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` font-variant-numeric = normal [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) <numeric-figure-values> [||](value_definition_syntax#double_bar) <numeric-spacing-values> [||](value_definition_syntax#double_bar) <numeric-fraction-values> [||](value_definition_syntax#double_bar) ordinal [||](value_definition_syntax#double_bar) slashed-zero []](value_definition_syntax#brackets) <numeric-figure-values> = lining-nums [|](value_definition_syntax#single_bar) oldstyle-nums <numeric-spacing-values> = proportional-nums [|](value_definition_syntax#single_bar) tabular-nums <numeric-fraction-values> = diagonal-fractions [|](value_definition_syntax#single_bar) stacked-fractions ``` Examples -------- ### Setting ordinal numeric forms Specifications -------------- | Specification | | --- | | [CSS Fonts Module Level 4 # font-variant-numeric-prop](https://w3c.github.io/csswg-drafts/css-fonts/#font-variant-numeric-prop) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `font-variant-numeric` | 52 | 79 | 34 | No | 39 | 9.1 | 52 | 52 | 34 | 41 | 9.3 | 6.0 | See also -------- * [`font-variant`](font-variant) * [`font-variant-alternates`](font-variant-alternates) * [`font-variant-caps`](font-variant-caps) * [`font-variant-east-asian`](font-variant-east-asian) * [`font-variant-emoji`](font-variant-emoji) * [`font-variant-ligatures`](font-variant-ligatures) * [`font-variant-position`](font-variant-position) css scroll-timeline scroll-timeline =============== **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `scroll-timeline` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [shorthand property](shorthand_properties) defines a name that can be used to identify the source element of a scroll timeline, along with the scrollbar axis that should provide the timeline. The name can be referenced in an [`animation-timeline`](animation-timeline) declaration in order to indicate the element, and hence the scrollbar, that will be used to control the progress of the animation. Note that if the element does not display a scrollbar in the axis dimension, then no timeline will be created. The `scroll-timeline` property is equivalent to setting both [`scroll-timeline-name`](scroll-timeline-name) and [`scroll-timeline-axis`](scroll-timeline-axis) properties in a single declaration. Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`scroll-timeline-name`](scroll-timeline-name) * [`scroll-timeline-axis`](scroll-timeline-axis) Syntax ------ ``` /\* values for both scroll-timeline-name and scroll-timeline-axis \*/ scroll-timeline: custom_name_for_timeline block; scroll-timeline: custom_name_for_timeline inline; scroll-timeline: custom_name_for_timeline vertical; scroll-timeline: custom_name_for_timeline horizontal; /\* none keyword for scroll-timeline-name and value for scroll-timeline-axis \*/ scroll-timeline: none block; scroll-timeline: none inline; scroll-timeline: none vertical; scroll-timeline: none horizontal; /\* scroll-timeline-name or scroll-timeline-axis \*/ scroll-timeline: none; scroll-timeline: custom_name_for_timeline; scroll-timeline: block; scroll-timeline: inline; scroll-timeline: vertical; scroll-timeline: horizontal; ``` ### Values A `<scroll-timeline-name>` value followed by a `<scroll-timeline-axis>` value may be applied to the container element in any order. At least one value must be applied. Allowed values for `<scroll-timeline-name>` are: `none` The timeline has no name. `<custom-ident>` An arbitrary custom identifier that can be used to reference the scroll timeline in an [`animation-timeline`](animation-timeline). Possible values are described in [`<custom-ident>`](custom-ident). The `<scroll-timeline-axis>` indicates which scrollbar axis, in the element identified by `<scroll-timeline-name>`, provides the scroll timeline. Allowed values are: `block` (Default) Scrollbar in the block axis of the scroll container. The block axis is the direction perpendicular to the flow of text within a line. For horizontal writing modes like standard English this is the same as `vertical`, while for vertical writing modes it is the same as `horizontal`. `inline` Scrollbar in the inline axis of the scroll container. The inline axis is the direction parallel to the flow of text in a line. For horizontal writing modes this is the same as `horizontal`, while for vertical writing modes this is the same as `vertical`. `vertical` Scrollbar in the vertical axis of the scroll container. `horizontal` Scrollbar in the horizontal axis of the scroll container. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`scroll-timeline-name`](scroll-timeline-name): `none` * [`scroll-timeline-axis`](scroll-timeline-axis): `block` | | Applies to | scroll containers | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`scroll-timeline-name`](scroll-timeline-name): as specified * [`scroll-timeline-axis`](scroll-timeline-axis): as specified | | Animation type | as each of the properties of the shorthand:* [`scroll-timeline-name`](scroll-timeline-name): Not animatable * [`scroll-timeline-axis`](scroll-timeline-axis): Not animatable | Formal syntax ------------- ``` scroll-timeline = <'scroll-timeline-name'> [||](value_definition_syntax#double_bar) <'scroll-timeline-axis'> ``` Examples -------- In this example, a scroll timeline named `squareTimeline` is defined using the `scroll-timeline-name` property on the element with the id `container`. This is then applied to the animation on the `#square` element using `animation-timeline: squareTimeline`. ### HTML The HTML for the example is shown below. ``` <div id="container"> <div id="square"></div> <div id="stretcher"></div> </div> ``` ### CSS The CSS for the container sets it as the source of a scroll timeline named `squareTimeline` using the `scroll-timeline` property. It also sets the scrollbar to use for the timeline as "vertical" (though this was not actually needed as it would have been used by default). The height of the container is set to 300px and we also set the container to create a vertical scrollbar if it overflows (below we will use CSS on the "stretcher" element to ensure that it does overflow). ``` #container { height: 300px; overflow-y: scroll; scroll-timeline: squareTimeline vertical; position: relative; } ``` The CSS below defines a square that rotates in alternate directions according to the timeline provided by the `animation-timeline` property, which is set to the `squareTimeline` timeline named above. ``` #square { background-color: deeppink; width: 100px; height: 100px; margin-top: 100px; animation-name: rotateAnimation; animation-duration: 3s; animation-direction: alternate; animation-timeline: squareTimeline; position: absolute; bottom: 0; } @keyframes rotateAnimation { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } ``` The "stretcher" CSS simply sets the block height to 600px, which forces the container element to overflow and create scroll bars. Without this element there would be no scrollbar, and hence no scroll timeline to associate with the animation timeline. ``` #stretcher { height: 600px; } ``` ### Result Scroll the vertical bar to see the animation. Specifications -------------- | Specification | | --- | | [Scroll-linked Animations # scroll-timeline-shorthand](https://w3c.github.io/csswg-drafts/scroll-animations/#scroll-timeline-shorthand) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scroll-timeline` | No | No | 103 | No | No | No | No | No | No | No | No | No | See also -------- * [`animation-timeline`](animation-timeline) css text-decoration-thickness text-decoration-thickness ========================= The `text-decoration-thickness` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the stroke thickness of the decoration line that is used on text in an element, such as a line-through, underline, or overline. Try it ------ Syntax ------ ``` /\* Single keyword \*/ text-decoration-thickness: auto; text-decoration-thickness: from-font; /\* length \*/ text-decoration-thickness: 0.1em; text-decoration-thickness: 3px; /\* percentage \*/ text-decoration-thickness: 10%; /\* Global values \*/ text-decoration-thickness: inherit; text-decoration-thickness: initial; text-decoration-thickness: revert; text-decoration-thickness: revert-layer; text-decoration-thickness: unset; ``` ### Values `auto` The browser chooses an appropriate width for the text decoration line. `from-font` If the font file includes information about a preferred thickness, use that value. If the font file doesn't include this information, behave as if `auto` was set, with the browser choosing an appropriate thickness. `<length>` Specifies the thickness of the text decoration line as a [`<length>`](length), overriding the font file suggestion or the browser default. `<percentage>` Specifies the thickness of the text decoration line as a [`<percentage>`](percentage) of **1em** in the current font. A percentage inherits as a relative value, and so therefore scales with changes in the font. The browser must use a minimum of 1 device pixel. For a given application of this property, the thickness is constant across the whole box it is applied to, even if there are child elements with a different font size. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | Percentages | refer to the font size of the element itself | | [Computed value](computed_value) | as specified | | Animation type | by computed value type | Formal syntax ------------- ``` text-decoration-thickness = auto [|](value_definition_syntax#single_bar) from-font [|](value_definition_syntax#single_bar) [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Varying thickness #### HTML ``` <p class="thin">Here's some text with a 1px red underline.</p> <p class="thick">This one has a 5px red underline.</p> <p class="shorthand">This uses the equivalent shorthand.</p> ``` #### CSS ``` .thin { text-decoration-line: underline; text-decoration-style: solid; text-decoration-color: red; text-decoration-thickness: 1px; } .thick { text-decoration-line: underline; text-decoration-style: solid; text-decoration-color: red; text-decoration-thickness: 5px; } .shorthand { text-decoration: underline solid red 5px; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Text Decoration Module Level 4 # text-decoration-width-property](https://w3c.github.io/csswg-drafts/css-text-decor-4/#text-decoration-width-property) | **Note:** The property used to be called `text-decoration-width`, but was updated in 2019 to `text-decoration-thickness`. Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `text-decoration-thickness` | 89 87-89 The `text-decoration-thickness` property does not work unless either `text-underline-offset` is set to something other than `auto` or `text-decoration-color` is set to something other than `currentColor`. See [Chromium bug 1154537](https://crbug.com/1154537). | 89 87-89 The `text-decoration-thickness` property does not work unless either `text-underline-offset` is set to something other than `auto` or `text-decoration-color` is set to something other than `currentColor`. See [Chromium bug 1154537](https://crbug.com/1154537). | 70 | No | 75 73-75 The `text-decoration-thickness` property does not work unless either `text-underline-offset` is set to something other than `auto` or `text-decoration-color` is set to something other than `currentColor`. See [Chromium bug 1154537](https://crbug.com/1154537). | 12.1 | 89 87-89 The `text-decoration-thickness` property does not work unless either `text-underline-offset` is set to something other than `auto` or `text-decoration-color` is set to something other than `currentColor`. See [Chromium bug 1154537](https://crbug.com/1154537). | 89 87-89 The `text-decoration-thickness` property does not work unless either `text-underline-offset` is set to something other than `auto` or `text-decoration-color` is set to something other than `currentColor`. See [Chromium bug 1154537](https://crbug.com/1154537). | No | 63 | 12.2 | 15.0 | | `percentage` | No | No | 74 | No | No | No | No | No | No | No | No | No | See also -------- * [`text-decoration`](text-decoration) * [`text-underline-offset`](text-underline-offset)
programming_docs
css <dimension> <dimension> =========== The `<dimension>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) represents a [`<number>`](number) with a unit attached to it, for example `10px`. CSS uses dimensions to specify distances ([`<length>`](length)), durations ([`<time>`](time)), frequencies ([`<frequency>`](frequency)), resolutions ([`<resolution>`](resolution)), and other quantities. Syntax ------ The syntax of `<dimension>` is a [`<number>`](number) immediately followed by a unit which is an identifier. Unit identifiers are case insensitive. Examples -------- ### Valid dimensions ``` 12px 12 pixels 1rem 1 rem 1.2pt 1.2 points 2200ms 2200 milliseconds 5s 5 seconds 200hz 200 Hertz 200Hz 200 Hertz (values are case insensitive) ``` ### Invalid dimensions ``` 12 px The unit must come immediately after the number. 12"px" Units are identifiers and therefore unquoted. 3sec The seconds unit is abbreviated "s" not "sec". ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # dimensions](https://w3c.github.io/csswg-drafts/css-values/#dimensions) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `dimension` | 1 | 12 | 1 | 5 | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | See also -------- * [CSS data types](css_types) * [Learn to style HTML using CSS](https://developer.mozilla.org/en-US/docs/Learn/CSS) * CSS distances ([`<length>`](length)), durations ([`<time>`](time)), frequencies ([`<frequency>`](frequency)), and resolutions ([`<resolution>`](resolution)) css <display-legacy> <display-legacy> ================ CSS 2 used a single-keyword syntax for the `display` property, requiring separate keywords for block-level and inline-level variants of the same layout mode. This page details those values. Syntax ------ Valid `<display-legacy>` values: `inline-block` The element generates a block element box that will be flowed with surrounding content as if it were a single inline box (behaving much like a replaced element would). It is equivalent to `inline flow-root`. `inline-table` The `inline-table` value does not have a direct mapping in HTML. It behaves like an HTML [`<table>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table) element, but as an inline box, rather than a block-level box. Inside the table box is a block-level context. It is equivalent to `inline table`. `inline-flex` The element behaves like an inline element and lays out its content according to the flexbox model. It is equivalent to `inline flex`. `inline-grid` The element behaves like an inline element and lays out its content according to the grid model. It is equivalent to `inline grid`. Formal syntax ------------- ``` <display-legacy> = inline-block [|](value_definition_syntax#single_bar) inline-table [|](value_definition_syntax#single_bar) inline-flex [|](value_definition_syntax#single_bar) inline-grid ``` Examples -------- In the below example, we are creating an inline flex container with the legacy keyword inline-flex. ### HTML ``` <div class="container"> <div>Flex Item</div> <div>Flex Item</div> </div> Not a flex item ``` ### CSS ``` .container { display: inline-flex; } ``` ### Result In the new syntax the inline flex container would be created using two values, inline for the outer display type, and flex for the inner display type. ``` .container { display: inline flex; } ``` Specifications -------------- | Specification | | --- | | [CSS Display Module Level 3 # typedef-display-legacy](https://drafts.csswg.org/css-display/#typedef-display-legacy) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `display-legacy` | 57 | 16 12 | 52 | 10 Internet Explorer implements an older version of the specification. | 44 | 10.1 | 57 | 57 | 52 | 43 | 10.3 | 6.0 Samsung Internet added this earlier than the corresponding Chrome version would indicate. | | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `display-legacy` | 29 21 | 12 | 20 Firefox 28 added multi-line flexbox support. | 11 8 | 16 15 | 9 7 | ≤37 4.4 | 29 25 | 20 Firefox 28 added multi-line flexbox support. | 16 14 | 9 7 | 2.0 1.5 | | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `display-legacy` | 1 | 12 | 3 | 8 | 7 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `display-legacy` | 1 | 12 | 1 | 8 6 Until Internet Explorer 8, `inline-block` is only for natural inline elements. | 7 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | ### css.properties.display.inline-block BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. ### css.properties.display.inline-table BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. ### css.properties.display.inline-flex BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. ### css.properties.display.inline-grid BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. See also -------- * [`display`](display) + [`<display-outside>`](display-outside) + [`<display-inside>`](display-inside) + [`<display-listitem>`](display-listitem) + [`<display-internal>`](display-internal) + [`<display-box>`](display-box) css scroll-snap-type scroll-snap-type ================ The `scroll-snap-type` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets how strictly snap points are enforced on the scroll container in case there is one. Try it ------ Specifying any precise animations or physics used to enforce those snap points is not covered by this property but instead left up to the user agent. ``` /\* Keyword values \*/ scroll-snap-type: none; scroll-snap-type: x; scroll-snap-type: y; scroll-snap-type: block; scroll-snap-type: inline; scroll-snap-type: both; /\* Optional mandatory | proximity\*/ scroll-snap-type: x mandatory; scroll-snap-type: y proximity; scroll-snap-type: both mandatory; /\* … \*/ /\* Global values \*/ scroll-snap-type: inherit; scroll-snap-type: initial; scroll-snap-type: revert; scroll-snap-type: revert-layer; scroll-snap-type: unset; ``` Syntax ------ ### Values `none` When the visual [viewport](https://developer.mozilla.org/en-US/docs/Glossary/Viewport) of this scroll container is scrolled, it must ignore snap points. `x` The scroll container snaps to snap positions in its horizontal axis only. `y` The scroll container snaps to snap positions in its vertical axis only. `block` The scroll container snaps to snap positions in its block axis only. `inline` The scroll container snaps to snap positions in its inline axis only. `both` The scroll container snaps to snap positions in both of its axes independently (potentially snapping to different elements in each axis). `mandatory` The visual viewport of this scroll container will rest on a snap point if it isn't currently scrolled. That means it snaps on that point when the scroll action finished, if possible. If content is added, moved, deleted or resized the scroll offset will be adjusted to maintain the resting on that snap point. `proximity` The visual viewport of this scroll container may come to rest on a snap point if it isn't currently scrolled considering the user agent's scroll parameters. If content is added, moved, deleted or resized the scroll offset may be adjusted to maintain the resting on that snap point. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` scroll-snap-type = none [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) x [|](value_definition_syntax#single_bar) y [|](value_definition_syntax#single_bar) block [|](value_definition_syntax#single_bar) inline [|](value_definition_syntax#single_bar) both []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) mandatory [|](value_definition_syntax#single_bar) proximity []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ``` Examples -------- ### Snapping in different axes #### HTML ``` <div class="holster"> <div class="container x mandatory-scroll-snapping" dir="ltr"> <div>X Mand. LTR</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div> <div class="container x proximity-scroll-snapping" dir="ltr"> <div>X Prox. LTR</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div> <div class="container y mandatory-scroll-snapping" dir="ltr"> <div>Y Mand. LTR</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div> <div class="container y proximity-scroll-snapping" dir="ltr"> <div>Y Prox. LTR</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div> <div class="container x mandatory-scroll-snapping" dir="rtl"> <div>X Mand. RTL</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div> <div class="container x proximity-scroll-snapping" dir="rtl"> <div>X Prox. RTL</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div> <div class="container y mandatory-scroll-snapping" dir="rtl"> <div>Y Mand. RTL</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div> <div class="container y proximity-scroll-snapping" dir="rtl"> <div>Y Prox. RTL</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div> </div> ``` #### CSS ``` /\* setup \*/ html, body, .holster { height: 100%; } .holster { display: flex; align-items: center; justify-content: space-between; flex-flow: column nowrap; font-family: monospace; } .container { display: flex; overflow: auto; outline: 1px dashed lightgray; flex: none; } .container.x { width: 100%; height: 128px; flex-flow: row nowrap; } .container.y { width: 256px; height: 256px; flex-flow: column nowrap; } /\* scroll-snap \*/ .x.mandatory-scroll-snapping { scroll-snap-type: x mandatory; } .y.mandatory-scroll-snapping { scroll-snap-type: y mandatory; } .x.proximity-scroll-snapping { scroll-snap-type: x proximity; } .y.proximity-scroll-snapping { scroll-snap-type: y proximity; } .container > div { text-align: center; scroll-snap-align: center; flex: none; } .x.container > div { line-height: 128px; font-size: 64px; width: 100%; height: 128px; } .y.container > div { line-height: 256px; font-size: 128px; width: 256px; height: 100%; } /\* appearance fixes \*/ .y.container > div:first-child { line-height: 1.3; font-size: 64px; } /\* coloration \*/ .container > div:nth-child(even) { background-color: #87ea87; } .container > div:nth-child(odd) { background-color: #87ccea; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Scroll Snap Module Level 1 # scroll-snap-type](https://w3c.github.io/csswg-drafts/css-scroll-snap/#scroll-snap-type) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scroll-snap-type` | 69 | 79 12-79 Edge supports an earlier draft of CSS Scroll Snap without axis values. | 99 68-99 On macOS 12, scroll snapping does not complete reliably. See [bug 1749352](https://bugzil.la/1749352) 39-68 An earlier draft of CSS Scroll Snap without axis values. | 10 Internet Explorer supports an earlier draft of CSS Scroll Snap without axis values. | 56 | 11 9 Older Safari versions support an earlier draft of CSS Scroll Snap without axis values. | 69 | 69 | 68 39-68 An earlier draft of CSS Scroll Snap without axis values. | 48 | 11 9 Older Safari versions support an earlier draft of CSS Scroll Snap without axis values. | 10.0 | See also -------- * [CSS Scroll Snap](css_scroll_snap) * [Well-Controlled Scrolling with CSS Scroll Snap](https://web.dev/css-scroll-snap/) css inherit inherit ======= The `inherit` CSS keyword causes the element to take the [computed value](computed_value) of the property from its parent element. It can be applied to any CSS property, including the CSS shorthand property [`all`](all). For [inherited properties](inheritance#inherited_properties), this reinforces the default behavior, and is only needed to override another rule. **Note:** Inheritance is always from the parent element in the document tree, even when the parent element is not the containing block. Examples -------- ### Exclude selected elements from a rule ``` /\* Make second-level headers green \*/ h2 { color: green; } /\* Leave those in the sidebar alone so they use their parent's color \*/ #sidebar h2 { color: inherit; } ``` In this example, the `h2` elements inside the sidebar might be different colors. For example, consider one of them that would by the child of a `div` matched by the rule: ``` div#current { color: blue; } ``` Then, it would be blue. Specifications -------------- | Specification | | --- | | [CSS Cascading and Inheritance Level 4 # inherit](https://w3c.github.io/csswg-drafts/css-cascade/#inherit) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `inherit` | 1 | 12 | 1 | 8 | 4 | 1 | 4.4 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [Inheritance](inheritance) * Use the [`initial`](initial) keyword to set a property to its initial value. * Use the [`revert`](revert) keyword to reset a property to the value established by the user-agent stylesheet (or by user styles, if any exist). * Use the [`revert-layer`](revert-layer) keyword to reset a property to the value established in a previous cascade layer. * Use the [`unset`](unset) keyword to set a property to its inherited value if it inherits or to its initial value if not. * The [`all`](all) property lets you reset all properties to their initial, inherited, reverted, or unset state at once. css @counter-style @counter-style ============== The `@counter-style` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) <at-rule> lets you define counter styles that are not part of the predefined set of styles. A `@counter-style` rule defines how to convert a counter value into a string representation. ``` @counter-style thumbs { system: cyclic; symbols: "\1F44D"; suffix: " "; } ul { list-style: thumbs; } ``` The initial version of CSS defined a set of useful counter styles. However, although more styles were added to this set of predefined styles over the years, this system proved too restrictive to fulfill the needs of worldwide typography. The `@counter-style` at-rule addresses this shortcoming in an open-ended manner, by allowing authors to define their own counter styles when the pre-defined styles aren't fitting their needs. Syntax ------ ### Descriptors Each `@counter-style` is identified by a name and has a set of descriptors. [`system`](@counter-style/system) Specifies the algorithm to be used for converting the integer value of a counter to a string representation. [`negative`](@counter-style/negative) Lets the author specify symbols to be appended or prepended to the counter representation if the value is negative. [`prefix`](@counter-style/prefix) Specifies a symbol that should be prepended to the marker representation. Prefixes are added to the representation in the final stage, so in the final representation of the counter, it comes before the negative sign. [`suffix`](@counter-style/suffix) Specifies, similar to the prefix descriptor, a symbol that is appended to the marker representation. Suffixes come after the marker representation. [`range`](@counter-style/range) Defines the range of values over which the counter style is applicable. If a counter style is used to represent a counter value outside of its ranges, the counter style will drop back to its fallback style. [`pad`](@counter-style/pad) Is used when you need the marker representations to be of a minimum length. For example if you want the counters to start at 01 and go through 02, 03, 04, etc., then the pad descriptor is to be used. For representations larger than the specified pad value, the marker is constructed as normal. [`fallback`](@counter-style/fallback) Specifies a system to fall back into if either the specified system is unable to construct the representation of a counter value or if the counter value is outside the specified range. If the specified fallback also fails to represent the value, then the fallback style's fallback is used, if one is specified. If there are either no fallback systems described or if the chain of fallback systems are unable to represent a counter value, then it will ultimately fall back to the decimal style. [`symbols`](@counter-style/symbols) Specifies the symbols that are to be used for the marker representations. Symbols can contain strings, images, or custom identifiers. How the symbols are used to construct the marker representation is up to the algorithm specified in the system descriptor. For example, if the system specified is fixed, then each of the N symbols specified in the descriptor will be used to represent the first N counter symbols. Once the specified set of symbols have exhausted, the fallback style will be used for the rest of the list. The below `@counter-style` rule uses images instead of character symbols. Image values for symbols is currently an 'at risk' feature, and is not implemented in any browser. ``` @counter-style winners-list { system: fixed; symbols: url(gold-medal.svg) url(silver-medal.svg) url(bronze-medal.svg); suffix: " "; } ``` [`additive-symbols`](@counter-style/additive-symbols) While the symbols specified in the symbols descriptor is used for constructing marker representation by most algorithms, some systems such as 'additive' rely on *additive tuples* described in this descriptor. Each additive tuple consists of a counter symbol and a non-negative integer weight. The additive tuples must be specified in the descending order of their weights. [`speak-as`](@counter-style/speak-as) Describes how to read out the counter style in speech synthesizers, such as screen readers. For example, the value of the marker symbol can be read out as numbers or alphabets for ordered lists or as audio cues for unordered lists, based on the value of this descriptor. Formal syntax ------------- ``` @counter-style = @counter-style [<counter-style-name>](counter-style-name) { [<declaration-list>](declaration-list) } ``` Examples -------- ### Specifying symbols with counter-style ``` @counter-style circled-alpha { system: fixed; symbols: Ⓐ Ⓑ Ⓒ Ⓓ Ⓔ Ⓕ Ⓖ Ⓗ Ⓘ Ⓙ Ⓚ Ⓛ Ⓜ Ⓝ Ⓞ Ⓟ Ⓠ Ⓡ Ⓢ Ⓣ Ⓤ Ⓥ Ⓦ Ⓧ Ⓨ Ⓩ; suffix: " "; } ``` The above counter style rule can be applied to lists like this: ``` .items { list-style: circled-alpha; } ``` Which will produce lists like this: Ⓐ One Ⓑ Two Ⓒ Three Ⓓ Four Ⓔ Five … Ⓨ Twenty-five Ⓩ Twenty-six 27 Twenty-seven 28 Twenty-eight 29 Twenty-nine 30 Thirty See more examples on the [demo page](https://mdn.github.io/css-examples/counter-style-demo/). ### Ready-made counter styles Find a collection of over 100 `counter-style` code snippets in the [Ready-made Counter Styles](https://www.w3.org/TR/predefined-counter-styles/) document. This document provides counter styles that meet the needs of languages and cultures around the world. The [Counter styles converter](https://r12a.github.io/app-counters/) pulls from this list to test and create copy and paste code for counter styles. Specifications -------------- | Specification | | --- | | [CSS Counter Styles Level 3 # the-counter-style-rule](https://w3c.github.io/csswg-drafts/css-counter-styles/#the-counter-style-rule) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `@counter-style` | 91 | 91 | 33 | No | 77 | No See [bug 167645](https://webkit.org/b/167645). | 91 | 91 | 33 | 64 | No See [bug 167645](https://webkit.org/b/167645). | 16.0 | | `additive-symbols` | 91 | 91 | 33 | No | 77 | No | 91 | 91 | 33 | 64 | No | 16.0 | | `fallback` | 91 | 91 | 33 | No | 77 | No | 91 | 91 | 33 | 64 | No | 16.0 | | `negative` | 91 | 91 | 33 | No | 77 | No | 91 | 91 | 33 | 64 | No | 16.0 | | `pad` | 91 | 91 | 33 | No | 77 | No | 91 | 91 | 33 | 64 | No | 16.0 | | `prefix` | 91 | 91 | 33 | No | 77 | No | 91 | 91 | 33 | 64 | No | 16.0 | | `range` | 91 | 91 | 33 | No | 77 | No | 91 | 91 | 33 | 64 | No | 16.0 | | `speak-as` | No | No | 33 | No | No | No | No | No | 33 | No | No | No | | `suffix` | 91 | 91 | 33 | No | 77 | No | 91 | 91 | 33 | 64 | No | 16.0 | | `symbols` | 91 Does not support `<image>` as a value for the `symbols` descriptor. | 91 Does not support `<image>` as a value for the `symbols` descriptor. | 33 Does not support `<image>` as a value for the `symbols` descriptor. | No | 77 Does not support `<image>` as a value for the `symbols` descriptor. | No | 91 Does not support `<image>` as a value for the `symbols` descriptor. | 91 Does not support `<image>` as a value for the `symbols` descriptor. | 33 Does not support `<image>` as a value for the `symbols` descriptor. | 64 Does not support `<image>` as a value for the `symbols` descriptor. | No | 16.0 Does not support `<image>` as a value for the `symbols` descriptor. | | `system` | 91 | 91 | 33 | No | 77 | No | 91 | 91 | 33 | 64 | No | 16.0 | See also -------- * [`list-style`](list-style), [`list-style-image`](list-style-image), [`list-style-position`](list-style-position), [`list-style-type`](list-style-type) * [`symbols()`](@counter-style/symbols), the functional notation creating anonymous counter styles. * CSS [`counter()`](counter) and [`counters()`](counters) functions * [Counter style demo](https://mdn.github.io/css-examples/counter-style-demo/) ([code](https://github.com/mdn/css-examples/tree/main/counter-style-demo))
programming_docs
css ::spelling-error ::spelling-error ================ **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `::spelling-error` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-element](pseudo-elements) represents a text segment which the [user agent](https://developer.mozilla.org/en-US/docs/Glossary/User_agent) has flagged as incorrectly spelled. Allowable properties -------------------- Only a small subset of CSS properties can be used in a rule with `::spelling-error` in its selector: * [`color`](color) * [`background-color`](background-color) * [`cursor`](cursor) * [`caret-color`](caret-color) * [`outline`](outline) and its longhands * [`text-decoration`](text-decoration) and its associated properties * [`text-emphasis-color`](text-emphasis-color) * [`text-shadow`](text-shadow) Syntax ------ ``` ::spelling-error ``` Examples -------- ### Simple document spell check In this example, eventual supporting browsers should highlight any flagged spelling errors with the styles shown. #### HTML ``` <p contenteditable spellcheck="true"> My friends are coegdfgfddffbgning to the party tonight. </p> ``` #### CSS ``` ::spelling-error { text-decoration: wavy red; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Pseudo-Elements Module Level 4 # selectordef-spelling-error](https://w3c.github.io/csswg-drafts/css-pseudo/#selectordef-spelling-error) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `::spelling-error` | No | No | No | No | No | No See [bug 175784](https://webkit.org/b/175784). | No | No | No | No | No See [bug 175784](https://webkit.org/b/175784). | No | See also -------- * [`::grammar-error`](::grammar-error) css scroll-snap-align scroll-snap-align ================= The `scroll-snap-align` property specifies the box's snap position as an alignment of its snap area (as the alignment subject) within its snap container's snapport (as the alignment container). The two values specify the snapping alignment in the block axis and inline axis, respectively. If only one value is specified, the second value defaults to the same value. Try it ------ Syntax ------ ``` /\* Keyword values \*/ scroll-snap-align: none; scroll-snap-align: start end; /\* when two values set first is block, second inline \*/ scroll-snap-align: center; /\* Global values \*/ scroll-snap-align: inherit; scroll-snap-align: initial; scroll-snap-align: revert; scroll-snap-align: revert-layer; scroll-snap-align: unset; ``` ### Values `none` The box does not define a snap position in that axis. `start` The start alignment of this box's scroll snap area, within the scroll container's snapport is a snap position in this axis. `end` The end alignment of this box's scroll snap area, within the scroll container's snapport is a snap position in this axis. `center` The center alignment of this box's scroll snap area, within the scroll container's snapport is a snap position in this axis. Safari had the two value syntax in the wrong order, the first value being inline the second block. See [bug #191865](https://bugs.webkit.org/show_bug.cgi?id=191865). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` scroll-snap-align = [[](value_definition_syntax#brackets) none [|](value_definition_syntax#single_bar) start [|](value_definition_syntax#single_bar) end [|](value_definition_syntax#single_bar) center []](value_definition_syntax#brackets)[{1,2}](value_definition_syntax#curly_braces) ``` Specifications -------------- | Specification | | --- | | [CSS Scroll Snap Module Level 1 # scroll-snap-align](https://w3c.github.io/csswg-drafts/css-scroll-snap/#scroll-snap-align) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scroll-snap-align` | 69 | 79 | 68 | No | 56 | 11 | 69 | 69 | 68 | 48 | 11 | 10.0 | See also -------- * [CSS Scroll Snap](css_scroll_snap) * [Well-Controlled Scrolling with CSS Scroll Snap](https://web.dev/css-scroll-snap/) css :defined :defined ======== The `:defined` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) represents any element that has been defined. This includes any standard element built in to the browser, and custom elements that have been successfully defined (i.e. with the [`CustomElementRegistry.define()`](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define) method). ``` /\* Selects any defined element \*/ :defined { font-style: italic; } /\* Selects any instance of a specific custom element \*/ simple-custom:defined { display: block; } ``` Syntax ------ ``` :defined ``` Examples -------- ### Hiding elements until they are defined The following snippets are taken from our [defined-pseudo-class](https://github.com/mdn/web-components-examples/tree/main/defined-pseudo-class) demo ([see it live also](https://mdn.github.io/web-components-examples/defined-pseudo-class/)). In this demo we define a very simple trivial custom element: ``` customElements.define( "simple-custom", class extends HTMLElement { constructor() { super(); let divElem = document.createElement("div"); divElem.textContent = this.getAttribute("text"); let shadowRoot = this.attachShadow({ mode: "open" }).appendChild(divElem); } } ); ``` Then insert a copy of this element into the document, along with a standard `<p>`: ``` <simple-custom text="Custom element example text"></simple-custom> <p>Standard paragraph example text</p> ``` In the CSS we first include the following rules: ``` /\* Give the two elements distinctive backgrounds \*/ p { background: yellow; } simple-custom { background: cyan; } /\* Both the custom and the built-in element are given italic text \*/ :defined { font-style: italic; } ``` Then provide the following two rules to hide any instances of our custom element that are not defined, and display instances that are defined as block level elements: ``` simple-custom:not(:defined) { display: none; } simple-custom:defined { display: block; } ``` This is useful if you have a complex custom element that takes a while to load into the page — you might want to hide instances of the element until definition is complete, so that you don't end up with flashes of ugly unstyled elements on the page Specifications -------------- | Specification | | --- | | [HTML Standard # selector-defined](https://html.spec.whatwg.org/multipage/semantics-other.html#selector-defined) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:defined` | 54 | 79 | 63 | No | 41 | 10 | 54 | 54 | 63 | 41 | 10 | 6.0 | See also -------- * [Web components](https://developer.mozilla.org/en-US/docs/Web/Web_Components) css :-moz-only-whitespace :-moz-only-whitespace ===================== **Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future. **Note:** In [Selectors Level 4](https://drafts.csswg.org/selectors-4/#the-empty-pseudo), the [`:empty`](:empty) selector was changed to act like `:-moz-only-whitespace`, but no browser currently supports this yet. The `:-moz-only-whitespace` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) matches elements that only contain text nodes that only contain [whitespace](https://developer.mozilla.org/en-US/docs/Glossary/Whitespace). (This includes elements with empty text nodes and elements with no child nodes.) Syntax ------ ``` :-moz-only-whitespace ``` Examples -------- ### Simple :-moz-only-whitespace example #### HTML ``` <div> </div> ``` #### CSS ``` div { border: 4px solid red; } :-moz-only-whitespace { border-color: lime; } ``` #### Result Specifications -------------- Briefly defined as `:blank` in [Selectors Level 4](https://drafts.csswg.org/selectors-4/#changes-2018-02), but then the functionality was merged into [`:empty`](:empty) and [`:blank`](:blank) redefined to mean empty [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input). Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:-moz-only-whitespace` | No | No | 1 See [bug 1106296](https://bugzil.la/1106296). | No | No | No | No | No | 4 See [bug 1106296](https://bugzil.la/1106296). | No | No | No | See also -------- * [`:blank`](:blank) Experimental * [`:empty`](:empty) css column-width column-width ============ The `column-width` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the ideal column width in a multi-column layout. The container will have as many columns as can fit without any of them having a width less than the `column-width` value. If the width of the container is narrower than the specified value, the single column's width will be smaller than the declared column width. Try it ------ This property can help you create responsive designs that fit different screen sizes. Especially in the presence of the [`column-count`](column-count) property (which has precedence), you must specify all related length values to achieve an exact column width. In horizontal text these are [`width`](width), [`column-width`](column-width), [`column-gap`](column-gap), and [`column-rule-width`](column-rule-width). Syntax ------ ``` /\* Keyword value \*/ column-width: auto; /\* <length> values \*/ column-width: 60px; column-width: 15.5em; column-width: 3.3vw; /\* Global values \*/ column-width: inherit; column-width: initial; column-width: revert; column-width: revert-layer; column-width: unset; ``` The `column-width` property is specified as one of the values listed below. ### Values [`<length>`](length) Indicates the optimal column width. The actual column width may differ from the specified value: it may be wider when necessary to fill available space, and narrower when the available space is too small. The value must be strictly positive or the declaration is invalid. Percentage values are also invalid. `auto` The width of the column is determined by other CSS properties, such as [`column-count`](column-count). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | Block containers except table wrapper boxes | | [Inherited](inheritance) | no | | [Computed value](computed_value) | the absolute length, zero or larger | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` column-width = auto [|](value_definition_syntax#single_bar) [<length [0,∞]>](length) [|](value_definition_syntax#single_bar) min-content [|](value_definition_syntax#single_bar) max-content [|](value_definition_syntax#single_bar) fit-content( <length-percentage> ) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Setting column width in pixels #### HTML ``` <p class="content-box"> Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exercitation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. </p> ``` #### CSS ``` .content-box { column-width: 100px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Box Sizing Module Level 3 # column-sizing](https://w3c.github.io/csswg-drafts/css-sizing/#column-sizing) | | [CSS Multi-column Layout Module Level 1 # cw](https://w3c.github.io/csswg-drafts/css-multicol/#cw) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `column-width` | 50 1 | 12 12 | 50 1.5-74 Before version 37, multiple columns didn't work with `display: table-caption` elements. | 10 | 15 11.1 | 9 3 | 50 ≤37 | 50 18 | 50 4 Before version 37, multiple columns didn't work with `display: table-caption` elements. | 15 11.1 | 9 1 | 5.0 1.0 | | `intrinsic_sizes` | No See [bug 964183](https://crbug.com/964183). | No See [bug 964183](https://crbug.com/964183). | No | No | No See [bug 964183](https://crbug.com/964183). | No | No See [bug 964183](https://crbug.com/964183). | No See [bug 964183](https://crbug.com/964183). | No | No See [bug 964183](https://crbug.com/964183). | No | No See [bug 964183](https://crbug.com/964183). | See also -------- * [Multiple-column Layout](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Multiple-column_Layout) (Learn Layout) * [Basic Concepts of Multicol](css_columns/basic_concepts_of_multicol) css tab-size tab-size ======== The `tab-size` CSS property is used to customize the width of tab characters (U+0009). Try it ------ Syntax ------ ``` /\* <integer> values \*/ tab-size: 4; tab-size: 0; /\* <length> values \*/ tab-size: 10px; tab-size: 2em; /\* Global values \*/ tab-size: inherit; tab-size: initial; tab-size: revert; tab-size: revert-layer; tab-size: unset; ``` ### Values [`<integer>`](integer) A multiple of the advance width of the space character (U+0020) to be used as the width of tabs. Must be nonnegative. [`<length>`](length) The width of tabs. Must be nonnegative. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `8` | | Applies to | block containers | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | the specified integer or an absolute length | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` tab-size = [<number>](number) [|](value_definition_syntax#single_bar) [<length>](length) ``` Examples -------- ### Expanding by character count ``` pre { tab-size: 4; /\* Set tab size to 4 characters wide \*/ } ``` ### Collapse tabs ``` pre { tab-size: 0; /\* Remove indentation \*/ } ``` ### Comparing to the default size This example compares a default tab size with a custom tab size. Note that [`white-space`](white-space) is set to `pre` to prevent the tabs from collapsing. #### HTML ``` <p>no tab</p> <p>&#0009;default tab size of 8 characters wide</p> <p class="custom">&#0009;custom tab size of 3 characters wide</p> <p>&nbsp;&nbsp;&nbsp;3 spaces, equivalent to the custom tab size</p> ``` #### CSS ``` p { white-space: pre; } .custom { tab-size: 3; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Text Module Level 3 # tab-size-property](https://w3c.github.io/csswg-drafts/css-text/#tab-size-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `tab-size` | 21 This property is not yet animatable. | 79 This property is not yet animatable. | 91 4 Before Firefox 53, this property was not animatable. | No | 15 10.5-15 | 7 | 4.4 | 25 This property is not yet animatable. | 91 4 Before Firefox 53, this property was not animatable. | 14 11-14 | 7 | 1.5 This property is not yet animatable. | | `length` | 42 | 79 | 53 | No | 29 | preview | 56 | 42 | 53 | 29 | No | 4.0 | See also -------- * [`white-space`](white-space) css :user-valid (:-moz-ui-valid) :user-valid (:-moz-ui-valid) ============================ **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `:user-valid` CSS [pseudo-class](pseudo-classes) represents any validated form element whose value validates correctly based on its [validation constraints](https://developer.mozilla.org/en-US/docs/Learn/Forms#constraint_validation). However, unlike [`:valid`](:valid) it only matches once the user has interacted with it. **Note:** The pseudo-class behaves in the same way as the non-standard `:-moz-ui-valid` pseudo-class. 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 ------ ``` :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. ``` <form> <label for="email">Email *: </label> <input id="email" name="email" type="email" value="[email protected]" required /> <span></span> </form> ``` ``` input:user-valid { border: 2px solid green; } input:user-valid + span::before { content: "✓"; color: green; } ``` Specifications -------------- | Specification | | --- | | [Selectors Level 4 # user-valid-pseudo](https://w3c.github.io/csswg-drafts/selectors/#user-valid-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:user-valid` | No See [bug 1156069](https://crbug.com/1156069). | No See [bug 1156069](https://crbug.com/1156069). | 88 4 | No | No See [bug 1156069](https://crbug.com/1156069). | No See [bug 222267](https://webkit.org/b/222267). | No See [bug 1156069](https://crbug.com/1156069). | No See [bug 1156069](https://crbug.com/1156069). | 88 4 | No See [bug 1156069](https://crbug.com/1156069). | No See [bug 222267](https://webkit.org/b/222267). | No See [bug 1156069](https://crbug.com/1156069). | See also -------- * [`:valid`](:valid) * [`:invalid`](:invalid) * [`:required`](:required) * [`:optional`](:optional) * [`:user-invalid`](:user-invalid)
programming_docs
css log() log() ===== **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `log()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](css_functions) is an exponential function that returns the logarithm of a number. The [logarithm, or log](https://en.wikipedia.org/wiki/Logarithm), is the inverse of [`exponentiation`](exp); it is the number that a fixed base has to be raised to in order to yield the number passed as the first parameter. In CSS, when a single parameter is passed, the natural logarithm `e`, or approximately `2.7182818`, is used, though the base can be set to any value with an optional second parameter. Syntax ------ ``` /\* A <number> value \*/ width: calc(100px * log(7.389)); /\* 200px \*/ width: calc(100px * log(8, 2)); /\* 300px \*/ width: calc(100px * log(625, 5)); /\* 400px \*/ ``` ### Parameters The `log(value [, base]?)` function accepts two comma-separated values as its parameters. `value` A calculation which resolves to a [`<number>`](number) greater than or equal to 0. Representing the value to be logarithmed. `base` Optional. A calculation which resolves to a [`<number>`](number) greater than or equal to 0. Representing the base of the logarithm. If not defined, the default logarithmic base `e` is used. ### Return value The logarithm of `value`, when `base` is defined. The natural logarithm (base `e`) of `value`, when `base` is not defined. ### Formal syntax ``` <log()> = log( <calc-sum> , <calc-sum>[?](value_definition_syntax#question_mark) ) <calc-sum> = <calc-product> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '+' [|](value_definition_syntax#single_bar) '-' []](value_definition_syntax#brackets) <calc-product> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-product> = <calc-value> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '*' [|](value_definition_syntax#single_bar) '/' []](value_definition_syntax#brackets) <calc-value> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-value> = [<number>](number) [|](value_definition_syntax#single_bar) [<dimension>](dimension) [|](value_definition_syntax#single_bar) [<percentage>](percentage) [|](value_definition_syntax#single_bar) <calc-constant> [|](value_definition_syntax#single_bar) ( <calc-sum> ) <calc-constant> = e [|](value_definition_syntax#single_bar) pi [|](value_definition_syntax#single_bar) infinity [|](value_definition_syntax#single_bar) -infinity [|](value_definition_syntax#single_bar) NaN ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # exponent-funcs](https://w3c.github.io/csswg-drafts/css-values/#exponent-funcs) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `log` | No | No | No | No | No | 15.4 | No | No | No | No | 15.4 | No | See also -------- * [`pow()`](pow) * [`sqrt()`](sqrt) * [`hypot()`](hypot) * [`exp()`](exp) css left left ==== The `left` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property participates in specifying the horizontal position of a [positioned element](position). It has no effect on non-positioned elements. Try it ------ Syntax ------ ``` /\* <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 [`<length>`](length) A negative, null, or positive [`<length>`](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. [`<percentage>`](percentage) A [`<percentage>`](percentage) of the containing block's width. `auto` Specifies that: * for *absolutely positioned elements*, the position of the element is based on the [`right`](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 [`right`](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 [`<length>`](length), [`<percentage>`](percentage), or the `auto` keyword. Description ----------- The effect of `left` depends on how the element is positioned (i.e., the value of the [`position`](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 [`right`](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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | positioned elements | | [Inherited](inheritance) | no | | Percentages | refer to the width of the containing block | | [Computed value](computed_value) | if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, `auto` | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` left = auto [|](value_definition_syntax#single_bar) <length-percentage> <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Positioning elements #### 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 ``` #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 Specifications -------------- | Specification | | --- | | [CSS Positioned Layout Module Level 3 # insets](https://w3c.github.io/csswg-drafts/css-position/#insets) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `left` | 1 | 12 | 1 | 5.5 | 5 | 1 | 4.4 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [`inset`](inset), the shorthand for all related properties: [`top`](top), [`bottom`](bottom), [`left`](left), and [`right`](right) * The mapped logical properties: [`inset-block-start`](inset-block-start), [`inset-block-end`](inset-block-end), [`inset-inline-start`](inset-inline-start), and [`inset-inline-end`](inset-inline-end) and the shorthands [`inset-block`](inset-block) and [`inset-inline`](inset-inline) * [`position`](position) css <angle-percentage> <angle-percentage> ================== The `<angle-percentage>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) represents a value that can be either a [`<angle>`](angle) or a [`<percentage>`](percentage). Where an `<angle-percentage>` is specified as an allowable type, this means that the percentage resolves to an angle and therefore can be used in a [`calc()`](calc) expression. Syntax ------ Refer to the documentation for [`<angle>`](angle) and [`<percentage>`](percentage) for details of the individual syntaxes allowed by this type. Formal syntax ------------- ``` <angle-percentage> = [<angle>](angle) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # mixed-percentages](https://w3c.github.io/csswg-drafts/css-values/#mixed-percentages) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `angle-percentage` | 2 | 12 | 3.6 | 9 | 15 | 4 | 2 | 18 | 4 | 14 | 3.2 | 1.0 | See also -------- * [CSS data types](css_types) * [Using CSS gradients](css_images/using_css_gradients) * [`conic-gradient()`](gradient/conic-gradient) and [`repeating-conic-gradient()`](gradient/repeating-conic-gradient) css border-start-end-radius border-start-end-radius ======================= The `border-start-end-radius` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines a logical border radius on an element, which maps to a physical border radius depending on the element's [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). This is useful when building styles to work regardless of the [text orientation](text-orientation) and [writing mode](css_writing_modes). Try it ------ This property affects the corner between the block-start and the inline-end sides of the element. For instance, in a `horizontal-tb` writing mode with `ltr` direction, it corresponds to the [`border-top-right-radius`](border-top-right-radius) property. Syntax ------ ``` /\* <length> values \*/ /\* With one value the corner will be a circle \*/ border-start-end-radius: 10px; border-start-end-radius: 1em; /\* With two values the corner will be an ellipse \*/ border-start-end-radius: 1em 2em; /\* Global values \*/ border-start-end-radius: inherit; border-start-end-radius: initial; border-start-end-radius: revert; border-start-end-radius: revert-layer; border-start-end-radius: unset; ``` ### Values `<length-percentage>` Denotes the size of the circle radius or the semi-major and semi-minor axes of the ellipse. As absolute length it can be expressed in any unit allowed by the CSS [`<length>`](length) data type. Percentages for the horizontal axis refer to the width of the box, percentages for the vertical axis refer to the height of the box. Negative values are invalid. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | all elements; but User Agents are not required to apply to `table` and `inline-table` elements when [`border-collapse`](border-collapse) is `collapse`. The behavior on internal table elements is undefined for the moment.. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | Percentages | refer to the corresponding dimension of the border box | | [Computed value](computed_value) | two absolute [`<length>`](length)s or [`<percentage>`](percentage)s | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` border-start-end-radius = <'border-top-left-radius'> ``` Examples -------- ### Border radius with vertical text #### HTML ``` <div> <p class="exampleText">Example</p> </div> ``` #### CSS ``` div { background-color: rebeccapurple; width: 120px; height: 120px; border-start-end-radius: 10px; } .exampleText { writing-mode: vertical-rl; padding: 10px; background-color: #fff; border-start-end-radius: 10px; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # border-radius-properties](https://w3c.github.io/csswg-drafts/css-logical/#border-radius-properties) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-start-end-radius` | 89 | 89 | 66 | No | 75 | 15 | 89 | 89 | 66 | No | 15 | 15.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * The mapped physical property: [`border-bottom-left-radius`](border-bottom-left-radius) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css mask-clip mask-clip ========= The `mask-clip` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property determines the area which is affected by a mask. The painted content of an element must be restricted to this area. ``` /\* <geometry-box> values \*/ mask-clip: content-box; mask-clip: padding-box; mask-clip: border-box; mask-clip: margin-box; mask-clip: fill-box; mask-clip: stroke-box; mask-clip: view-box; /\* Keyword values \*/ mask-clip: no-clip; /\* Non-standard keyword values \*/ -webkit-mask-clip: border; -webkit-mask-clip: padding; -webkit-mask-clip: content; -webkit-mask-clip: text; /\* Multiple values \*/ mask-clip: padding-box, no-clip; mask-clip: view-box, fill-box, border-box; /\* Global values \*/ mask-clip: inherit; mask-clip: initial; mask-clip: revert; mask-clip: revert-layer; mask-clip: unset; ``` Syntax ------ One or more of the keyword values listed below, separated by commas. ### Values `content-box` The painted content is clipped to the content box. `padding-box` The painted content is clipped to the padding box. `border-box` The painted content is clipped to the border box. `margin-box` The painted content is clipped to the margin box. `fill-box` The painted content is clipped to the object bounding box. `stroke-box` The painted content is clipped to the stroke bounding box. `view-box` Uses the nearest SVG viewport as reference box. If a [`viewBox`](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox) attribute is specified for the element creating the SVG viewport, the reference box is positioned at the origin of the coordinate system established by the `viewBox` attribute and the dimension of the reference box is set to the width and height values of the `viewBox` attribute. `no-clip` The painted content is not clipped. `border` Non-standard This keyword behaves the same as `border-box`. `padding` Non-standard This keyword behaves the same as `padding-box`. `content` Non-standard This keyword behaves the same as `content-box`. `text` Non-standard This keyword clips the mask image to the text of the element. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `border-box` | | Applies to | all elements; In SVG, it applies to container elements excluding the [`<defs>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs) element and all graphics elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` mask-clip = [[](value_definition_syntax#brackets) <geometry-box> [|](value_definition_syntax#single_bar) no-clip []](value_definition_syntax#brackets)[#](value_definition_syntax#hash_mark) <geometry-box> = <shape-box> [|](value_definition_syntax#single_bar) fill-box [|](value_definition_syntax#single_bar) stroke-box [|](value_definition_syntax#single_bar) view-box <shape-box> = <box> [|](value_definition_syntax#single_bar) margin-box <box> = border-box [|](value_definition_syntax#single_bar) padding-box [|](value_definition_syntax#single_bar) content-box ``` Examples -------- ### Clipping a mask to the border box Change the `mask-clip` value to any of the allowed values detailed above. If viewing the example in a Chromium-based browser change the value of `-webkit-mask-clip`. Specifications -------------- | Specification | | --- | | [CSS Masking Module Level 1 # the-mask-clip](https://drafts.fxtf.org/css-masking/#the-mask-clip) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `mask-clip` | 1 | 79 | 53 | No | 15 | 15.4 4 | 2 | 18 | 53 | 14 | 15.4 3.2 | 1.0 | | `border` | 1 | 79 | No | No | 15 | 4 | 2 | 18 | No | 14 | 3.2 | 1.0 | | `content` | 1 | 79 | No | No | 15 | 4 | 2 | 18 | No | 14 | 3.2 | 1.0 | | `padding` | 1 | 79 | No | No | 15 | 4 | 2 | 18 | No | 14 | 3.2 | 1.0 | | `text` | 1 | 79 | No | No | 15 | 4 | 2 | 18 | No | 14 | 3.2 | 1.0 | See also -------- * [Clipping and Masking in CSS](https://css-tricks.com/clipping-masking-css/) css box-decoration-break box-decoration-break ==================== The `box-decoration-break` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property specifies how an element's [fragments](css_fragmentation) should be rendered when broken across multiple lines, columns, or pages. Try it ------ The specified value will impact the appearance of the following properties: * [`background`](background) * [`border`](border) * [`border-image`](border-image) * [`box-shadow`](box-shadow) * [`clip-path`](clip-path) * [`margin`](margin) * [`padding`](padding) Syntax ------ ``` /\* Keyword values \*/ box-decoration-break: slice; box-decoration-break: clone; /\* Global values \*/ box-decoration-break: inherit; box-decoration-break: initial; box-decoration-break: revert; box-decoration-break: revert-layer; box-decoration-break: unset; ``` The `box-decoration-break` property is specified as one of the keyword values listed below. ### Values `slice` The element is initially rendered as if its box were not fragmented, after which the rendering for this hypothetical box is sliced into pieces for each line/column/page. Note that the hypothetical box can be different for each fragment since it uses its own height if the break occurs in the inline direction, and its own width if the break occurs in the block direction. See the CSS specification for details. `clone` Each box fragment is rendered independently with the specified border, padding, and margin wrapping each fragment. The [`border-radius`](border-radius), [`border-image`](border-image), and [`box-shadow`](box-shadow) are applied to each fragment independently. The background is also drawn independently for each fragment, which means that a background image with [`background-repeat`](background-repeat)`: no-repeat` may nevertheless repeat multiple times. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `slice` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` box-decoration-break = slice [|](value_definition_syntax#single_bar) clone ``` Examples -------- ### Inline box fragments An inline element that contains line breaks styled with: ``` <style> .example { background: linear-gradient(to bottom right, yellow, green); box-shadow: 8px 8px 10px 0px deeppink, -5px -5px 5px 0px blue, 5px 5px 15px 0px yellow; padding: 0em 1em; border-radius: 16px; border-style: solid; margin-left: 10px; font: 24px sans-serif; line-height: 2; } </style> … <span class="example">The<br />quick<br />orange fox</span> ``` This results in: Adding `box-decoration-break: clone` to the above styles: ``` -webkit-box-decoration-break: clone; box-decoration-break: clone; ``` This one results in: You can [try the two inline examples above](https://media.prod.mdn.mozit.cloud/attachments/2014/07/12/8179/df096e9eb57177d8b7fdcd0c8f64ef18/box-decoration-break-inline.html) in your browser. Here's an example of an inline element using a large `border-radius` value. The second `"iM"` has a line-break between the `"i"` and the `"M"`. For comparison, the first `"iM"` is without line breaks. Note that if you stack the rendering of the two fragments horizontally next to each other it will result in the non-fragmented rendering. [Try the above example](https://media.prod.mdn.mozit.cloud/attachments/2014/07/12/8191/7a067e5731355081e856ea02b978ea2e/box-decoration-break-inline-extreme.html) in your browser. ### Block box fragments A block element with similar styles as above and no fragmentation results in: Fragmenting the above block into three columns results in: Note that stacking these pieces vertically will result in the non-fragmented rendering. Now, the same example but styled with `box-decoration-break: clone` results in: Note here that each fragment has an identical replicated border, box-shadow, and background. You can [try the block examples above](https://media.prod.mdn.mozit.cloud/attachments/2014/07/12/8187/6288bde9d276d78e203c9f8b9a26ff65/box-decoration-break-block.html) in your browser. Specifications -------------- | Specification | | --- | | [CSS Fragmentation Module Level 3 # break-decoration](https://w3c.github.io/csswg-drafts/css-break/#break-decoration) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `box-decoration-break` | 22 This property is only supported for inline elements. | 79 This property is only supported for inline elements. | 32 1-32 | No | 15 11.5-15 | 7 This property is only supported for inline elements. | ≤37 This property is only supported for inline elements. | 18 This property is only supported for inline elements. | 32 4-32 | 14 11.5-14 | 7 This property is only supported for inline elements. | 1.0 This property is only supported for inline elements. | See also -------- * [`break-after`](break-after), [`break-before`](break-before), [`break-inside`](break-inside)
programming_docs
css <transform-function> <transform-function> ==================== The `<transform-function>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) represents a transformation that affects an element's appearance. Transformation [functions](css_functions) can rotate, resize, distort, or move an element in 2D or 3D space. It is used in the [`transform`](transform) property. Syntax ------ The `<transform-function>` data type is specified using one of the transformation functions listed below. Each function applies a geometric operation in either 2D or 3D. ### Matrix transformation [`matrix()`](transform-function/matrix) Describes a homogeneous 2D transformation matrix. [`matrix3d()`](transform-function/matrix3d) Describes a 3D transformation as a 4×4 homogeneous matrix. ### Perspective [`perspective()`](transform-function/perspective) Sets the distance between the user and the z=0 plane. ### Rotation [`rotate()`](transform-function/rotate) Rotates an element around a fixed point on the 2D plane. [`rotate3d()`](transform-function/rotate3d) Rotates an element around a fixed axis in 3D space. [`rotateX()`](transform-function/rotatex) Rotates an element around the horizontal axis. [`rotateY()`](transform-function/rotatey) Rotates an element around the vertical axis. [`rotateZ()`](transform-function/rotatez) Rotates an element around the z-axis. ### Scaling (resizing) [`scale()`](transform-function/scale) Scales an element up or down on the 2D plane. [`scale3d()`](transform-function/scale3d) Scales an element up or down in 3D space. [`scaleX()`](transform-function/scalex) Scales an element up or down horizontally. [`scaleY()`](transform-function/scaley) Scales an element up or down vertically. [`scaleZ()`](transform-function/scalez) Scales an element up or down along the z-axis. ### Skewing (distortion) [`skew()`](transform-function/skew) Skews an element on the 2D plane. [`skewX()`](transform-function/skewx) Skews an element in the horizontal direction. [`skewY()`](transform-function/skewy) Skews an element in the vertical direction. ### Translation (moving) [`translate()`](transform-function/translate) Translates an element on the 2D plane. [`translate3d()`](transform-function/translate3d) Translates an element in 3D space. [`translateX()`](transform-function/translatex) Translates an element horizontally. [`translateY()`](transform-function/translatey) Translates an element vertically. [`translateZ()`](transform-function/translatez) Translates an element along the z-axis. Description ----------- Various coordinate models can be used to describe an HTML element's size and shape, as well as any transformations applied to it. The most common is the [Cartesian coordinate system](https://en.wikipedia.org/wiki/Cartesian_coordinate_system), although [homogeneous coordinates](https://en.wikipedia.org/wiki/Homogeneous_coordinates) are also sometimes used. ### Cartesian coordinates In the Cartesian coordinate system, a two-dimensional point is described using two values: an x coordinate (abscissa) and a y coordinate (ordinate). This is represented by the vector notation `(x, y)`. In CSS (and most computer graphics), the origin `(0, 0)` represents the *top-left* corner of any element. Positive coordinates are down and to the right of the origin, while negative ones are up and to the left. Thus, a point that's 2 units to the right and 5 units down would be `(2, 5)`, while a point 3 units to the left and 12 units up would be `(-3, -12)`. ### Transformation functions Transformation functions alter the appearance of an element by manipulating the values of its coordinates. A linear transformation function is described using a 2×2 matrix, like this: ( a c b d ) The function is applied to an element by using matrix multiplication. Thus, each coordinate changes based on the values in the matrix: ( a c b d ) ( x y ) = ( a x + c y b x + d y ) It is even possible to apply several transformations in a row: ( a 1 c 1 b 1 d 1 ) ( a 2 c 2 b 2 d 2 ) = ( a 1 a 2 + c 1 b 2 a 1 c 2 + c 1 d 2 b 1 a 2 + d 1 b 2 b 1 c 2 + d 1 d 2 ) With this notation, it is possible to describe, and therefore compose, most common transformations: rotations, scaling, or skewing. (In fact, all transformations that are linear functions can be described.) Composite transformations are effectively applied in order from right to left. However, one major transformation is not linear, and therefore must be special-cased when using this notation: translation. The translation vector `(tx, ty)` must be expressed separately, as two additional parameters. **Note:** Though trickier than Cartesian coordinates, [homogeneous coordinates](https://en.wikipedia.org/wiki/Homogeneous_coordinates) in [projective geometry](https://en.wikipedia.org/wiki/Projective_geometry) lead to 3×3 transformation matrices, and can express translations as linear functions. **Note:** Transform functions are used with the `transform` property but not with individual transform properties-[`translate`](translate), [`scale`](scale), and [`rotate`](rotate). Examples -------- ### Transform function comparison The following example provides a 3D cube created from DOM elements and transforms, and a select menu allowing you to choose different transform functions to transform the cube with, so you can compare the effects of the different types. Choose one, and the transform is applied to the cube; after 2 seconds, the cube reverts back to its starting state. The cube's starting state is slightly rotated using `transform3d()`, to allow you to see the effect of all the transforms. #### HTML ``` <main> <section id="example-element"> <div class="face front">1</div> <div class="face back">2</div> <div class="face right">3</div> <div class="face left">4</div> <div class="face top">5</div> <div class="face bottom">6</div> </section> <div class="select-form"> <label for="transfunction">Select a transform function</label> <select id="transfunction"> <option selected>Choose a function</option> <option>rotate(360deg)</option> <option>rotateX(360deg)</option> <option>rotateY(360deg)</option> <option>rotateZ(360deg)</option> <option>rotate3d(1, 1, 1, 90deg)</option> <option>scale(1.5)</option> <option>scaleX(1.5)</option> <option>scaleY(1.5)</option> <option>scaleZ(1.5)</option> <option>scale3d(1, 1.5, 1.5)</option> <option>skew(17deg, 13deg)</option> <option>skewX(17deg)</option> <option>skewY(17deg)</option> <option>translate(100px, 100px)</option> <option>translateX(100px)</option> <option>translateY(100px)</option> <option>translateZ(100px)</option> <option>translate3d(50px, 50px, 50px)</option> <option>perspective(200px)</option> <option>matrix(1, 2, -1, 1, 80, 80)</option> <option>matrix3d(1,0,0,0,0,1,3,0,0,0,1,0,50,100,0,1.1)</option> </select> </div> </main> ``` #### CSS ``` main { width: 400px; height: 200px; padding: 50px; background-image: linear-gradient(135deg, white, cyan, white); } #example-element { width: 100px; height: 100px; transform-style: preserve-3d; transition: transform 1.5s; transform: rotate3d(1, 1, 1, 30deg); } .face { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; position: absolute; backface-visibility: inherit; font-size: 60px; color: #fff; } .front { background: rgba(90, 90, 90, 0.7); transform: translateZ(50px); } .back { background: rgba(0, 210, 0, 0.7); transform: rotateY(180deg) translateZ(50px); } .right { background: rgba(210, 0, 0, 0.7); transform: rotateY(90deg) translateZ(50px); } .left { background: rgba(0, 0, 210, 0.7); transform: rotateY(-90deg) translateZ(50px); } .top { background: rgba(210, 210, 0, 0.7); transform: rotateX(90deg) translateZ(50px); } .bottom { background: rgba(210, 0, 210, 0.7); transform: rotateX(-90deg) translateZ(50px); } .select-form { margin-top: 50px; } ``` #### JavaScript ``` const selectElem = document.querySelector('select'); const example = document.querySelector('#example-element'); selectElem.addEventListener('change', () => { if (selectElem.value === 'Choose a function') { return; } else { example.style.transform = `rotate3d(1, 1, 1, 30deg) ${selectElem.value}`; setTimeout(() => { example.style.transform = 'rotate3d(1, 1, 1, 30deg)'; }, 2000) } }) ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Transforms Module Level 1 # transform-functions](https://w3c.github.io/csswg-drafts/css-transforms/#transform-functions) | | [CSS Transforms Module Level 2 # transform-functions](https://w3c.github.io/csswg-drafts/css-transforms-2/#transform-functions) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `transform-function` | 1 | 12 | 3.5 | 9 Internet Explorer 9 supports 2D but not 3D transforms. In version 9, mixing 2D and 3D transform functions invalidates the entire property. | 10.5 | 3.1 | 2 | 18 | 4 | 11 | 3.2 | 1.0 | | `matrix` | 1 | 12 | 3.5 Before Firefox 16, the translation values of `matrix()` could be [`<length>`](https://developer.mozilla.org/docs/Web/CSS/length)s, in addition to the standard [`<number>`](https://developer.mozilla.org/docs/Web/CSS/number). | 9 | 10.5 | 3.1 | 2 | 18 | 4 | 11 | 3.2 | 1.0 | | `matrix3d` | 12 | 12 | 10 Before Firefox 16, the translation values of `matrix3d()` could be [`<length>`](https://developer.mozilla.org/docs/Web/CSS/length)s, in addition to the standard [`<number>`](https://developer.mozilla.org/docs/Web/CSS/number). | 10 | 15 | 4 | 3 | 18 | 10 | 14 | 3.2 | 1.0 | | `perspective` | 12 | 12 | 10 | 10 | 15 | 4 | 3 | 18 | 10 | 14 | 3.2 | 1.0 | | `rotate` | 1 | 12 | 3.5 | 9 | 10.5 | 3.1 | 2 | 18 | 4 | 11 | 3.2 | 1.0 | | `rotate3d` | 12 | 12 | 10 | 10 | 15 | 4 | 3 | 18 | 10 | 14 | 3.2 | 1.0 | | `rotateX` | 12 | 12 | 10 | 10 | 15 | 4 | 3 | 18 | 10 | 14 | 3.2 | 1.0 | | `rotateY` | 12 | 12 | 10 | 10 | 15 | 4 | 3 | 18 | 10 | 14 | 3.2 | 1.0 | | `rotateZ` | 12 | 12 | 10 | 10 | 15 | 4 | 3 | 18 | 10 | 14 | 3.2 | 1.0 | | `scale` | 1 | 12 | 3.5 | 9 | 10.5 | 3.1 | 2 | 18 | 4 | 11 | 3.2 | 1.0 | | `scale3d` | 12 | 12 | 10 | 10 | 15 | 4 | 3 | 18 | 10 | 14 | 3.2 | 1.0 | | `scaleX` | 1 | 12 | 3.5 | 9 | 10.5 | 3.1 | 2 | 18 | 4 | 11 | 3.2 | 1.0 | | `scaleY` | 1 | 12 | 3.5 | 9 | 10.5 | 3.1 | 2 | 18 | 4 | 11 | 3.2 | 1.0 | | `scaleZ` | 12 | 12 | 10 | 10 | 15 | 4 | 3 | 18 | 10 | 14 | 3.2 | 1.0 | | `skew` | 1 | 12 | 3.5 Firefox 14 removed experimental support for `skew()`, but it was reintroduced in Firefox 15. | 9 | 10.5 | 3.1 | 2 | 18 | 4 | 11 | 3.2 | 1.0 | | `skewX` | 1 | 12 | 3.5 | 9 | 10.5 | 3.1 | 2 | 18 | 4 | 11 | 3.2 | 1.0 | | `skewY` | 1 | 12 | 3.5 | 9 | 10.5 | 3.1 | 2 | 18 | 4 | 11 | 3.2 | 1.0 | | `translate` | 1 | 12 | 3.5 | 9 | 10.5 | 3.1 | 2 | 18 | 4 | 11 | 3.2 | 1.0 | | `translate3d` | 12 | 12 | 10 | 10 | 15 | 4 | 3 | 18 | 10 | 14 | 3.2 | 1.0 | | `translateX` | 1 | 12 | 3.5 | 9 | 10.5 | 3.1 | 2 | 18 | 4 | 11 | 3.2 | 1.0 | | `translateY` | 1 | 12 | 3.5 | 9 | 10.5 | 3.1 | 2 | 18 | 4 | 11 | 3.2 | 1.0 | | `translateZ` | 12 | 12 | 10 | 10 | 15 | 4 | 3 | 18 | 10 | 14 | 3.2 | 1.0 | See also -------- * CSS [`transform`](transform) property * Individual transform properties: + [`translate`](translate) + [`scale`](scale) + [`rotate`](rotate) css abs() abs() ===== **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `abs()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](css_functions) returns the absolute value of the argument, as the same type as the input. Syntax ------ ``` /\* property: abs(expression) \*/ width: abs(20% - 100px); ``` ### Parameters The `abs(x)` function accepts only one value as its parameter. `x` A calculation which resolves to a number. ### Return value The absolute value of `x`. * if `x`'s numeric value is positive or `0⁺`, return `x`. * Otherwise, returns `-1 * x`. ### Formal syntax ``` <abs()> = abs( <calc-sum> ) <calc-sum> = <calc-product> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '+' [|](value_definition_syntax#single_bar) '-' []](value_definition_syntax#brackets) <calc-product> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-product> = <calc-value> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '*' [|](value_definition_syntax#single_bar) '/' []](value_definition_syntax#brackets) <calc-value> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-value> = [<number>](number) [|](value_definition_syntax#single_bar) [<dimension>](dimension) [|](value_definition_syntax#single_bar) [<percentage>](percentage) [|](value_definition_syntax#single_bar) <calc-constant> [|](value_definition_syntax#single_bar) ( <calc-sum> ) <calc-constant> = e [|](value_definition_syntax#single_bar) pi [|](value_definition_syntax#single_bar) infinity [|](value_definition_syntax#single_bar) -infinity [|](value_definition_syntax#single_bar) NaN ``` Examples -------- ### Positive variables The `abs()` function can be used to ensure that a value is always positive. In the following example a CSS custom property `--font-size` is used as the value of [`font-size`](font-size). Wrapping this custom property in `abs()` will convert a negative value to a positive one. ``` h1 { font-size: abs(var(--font-size)); } ``` ### Control gradient angle of direction You can also control the gradient direction using `abs()` function. In the following example, with an angle of -45deg the gradient would start red and transition to blue. By using `abs()` to make the value positive, the gradient will start blue and transition to red. ``` div { --deg: -45deg; background-image: linear-gradient(abs(var(--deg)), blue, red); } ``` ### Backwards compatible fallback In older browsers that lack the support for CSS `abs()` function, you can use the CSS [`max()`](max) function to achieve the same result, as shown below: ``` p { line-height: max(var(--lh), -1*var(--lh)); } ``` We use the [`max()`](max) function to return the largest (most positive) value from a list of two values: `var(--lh)` or `-1 * var(--lh)`. Irrespective of whether `--lh` is positive or negative, the calculated return value will always be positive, that is, an absolute number. Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # sign-funcs](https://w3c.github.io/csswg-drafts/css-values/#sign-funcs) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `abs` | No | No | No | No | No | 15.4 | No | No | No | No | 15.4 | No | See also -------- * [`sign()`](sign) css overflow-wrap overflow-wrap ============= The `overflow-wrap` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property applies to inline elements, setting whether the browser should insert line breaks within an otherwise unbreakable string to prevent text from overflowing its line box. Try it ------ **Note:** In contrast to [`word-break`](word-break), `overflow-wrap` will only create a break if an entire word cannot be placed on its own line without overflowing. The property was originally a nonstandard and unprefixed Microsoft extension called `word-wrap`, and was implemented by most browsers with the same name. It has since been renamed to `overflow-wrap`, with `word-wrap` being an alias. Syntax ------ ``` /\* Keyword values \*/ overflow-wrap: normal; overflow-wrap: break-word; overflow-wrap: anywhere; /\* Global values \*/ overflow-wrap: inherit; overflow-wrap: initial; overflow-wrap: revert; overflow-wrap: revert-layer; overflow-wrap: unset; ``` The `overflow-wrap` property is specified as a single keyword chosen from the list of values below. ### Values `normal` Lines may only break at normal word break points (such as a space between two words). `anywhere` To prevent overflow, an otherwise unbreakable string of characters — like a long word or URL — may be broken at any point if there are no otherwise-acceptable break points in the line. No hyphenation character is inserted at the break point. Soft wrap opportunities introduced by the word break are considered when calculating min-content intrinsic sizes. `break-word` The same as the `anywhere` value, with normally unbreakable words allowed to be broken at arbitrary points if there are no otherwise acceptable break points in the line, but soft wrap opportunities introduced by the word break are NOT considered when calculating min-content intrinsic sizes. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | non-replaced inline elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` overflow-wrap = normal [|](value_definition_syntax#single_bar) break-word [|](value_definition_syntax#single_bar) anywhere ``` Examples -------- ### Comparing overflow-wrap, word-break, and hyphens This example compares the results of `overflow-wrap`, `word-break`, and `hyphens` when breaking up a long word. #### HTML ``` <p> They say the fishing is excellent at Lake <em class="normal">Chargoggagoggmanchauggagoggchaubunagungamaugg</em>, though I've never been there myself. (<code>normal</code>) </p> <p> They say the fishing is excellent at Lake <em class="ow-anywhere">Chargoggagoggmanchauggagoggchaubunagungamaugg</em>, though I've never been there myself. (<code>overflow-wrap: anywhere</code>) </p> <p> They say the fishing is excellent at Lake <em class="ow-break-word">Chargoggagoggmanchauggagoggchaubunagungamaugg</em>, though I've never been there myself. (<code>overflow-wrap: break-word</code>) </p> <p> They say the fishing is excellent at Lake <em class="word-break">Chargoggagoggmanchauggagoggchaubunagungamaugg</em>, though I've never been there myself. (<code>word-break</code>) </p> <p> They say the fishing is excellent at Lake <em class="hyphens">Chargoggagoggmanchauggagoggchaubunagungamaugg</em>, though I've never been there myself. (<code>hyphens</code>, without <code>lang</code> attribute) </p> <p lang="en"> They say the fishing is excellent at Lake <em class="hyphens">Chargoggagoggmanchauggagoggchaubunagungamaugg</em>, though I've never been there myself. (<code>hyphens</code>, English rules) </p> <p class="hyphens" lang="de"> They say the fishing is excellent at Lake <em class="hyphens">Chargoggagoggmanchauggagoggchaubunagungamaugg</em>, though I've never been there myself. (<code>hyphens</code>, German rules) </p> ``` #### CSS ``` p { width: 13em; margin: 2px; background: gold; } .ow-anywhere { overflow-wrap: anywhere; } .ow-break-word { overflow-wrap: break-word; } .word-break { word-break: break-all; } .hyphens { hyphens: auto; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Text Module Level 3 # overflow-wrap-property](https://w3c.github.io/csswg-drafts/css-text/#overflow-wrap-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `overflow-wrap` | 23 1 | 18 12 | 49 3.5 | 5.5 | 12.1 10.5 | 7 1 | 4.4 1 | 25 18 | 49 4 | 12.1 11 | 7 1 | 1.5 1.0 | | `anywhere` | 80 | 80 | 65 | No | 67 | preview | 80 | 80 | 65 | No | No | 13.0 | | `break-word` | 1 | 12 | 3.5 | 5.5 | 10.5 | 1 | ≤37 | 18 | 4 | 11 | 1 | 1.0 | See also -------- * [`word-break`](word-break) * [`hyphens`](hyphens) * [`text-overflow`](text-overflow) * [Guide to wrapping and breaking text](css_text/wrapping_text)
programming_docs
css border-block-end-style border-block-end-style ====================== The `border-block-end-style` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the style of the logical block-end border of an element, which maps to a physical border style depending on the element's writing mode, directionality, and text orientation. It corresponds to the [`border-top-style`](border-top-style), [`border-right-style`](border-right-style), [`border-bottom-style`](border-bottom-style), or [`border-left-style`](border-left-style) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ Syntax ------ ``` /\* <'border-style'> values \*/ border-block-end-style: dashed; border-block-end-style: dotted; border-block-end-style: groove; /\* Global values \*/ border-block-end-style: inherit; border-block-end-style: initial; border-block-end-style: revert; border-block-end-style: revert-layer; border-block-end-style: unset; ``` Related properties are [`border-block-start-style`](border-block-start-style), [`border-inline-start-style`](border-inline-start-style), and [`border-inline-end-style`](border-inline-end-style), which define the other border styles of the element. ### Values `<'border-style'>` The line style of the border. See [`border-style`](border-style). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` border-block-end-style = <'border-top-style'> ``` Examples -------- ### Dashed border with vertical text #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; border: 5px solid blue; border-block-end-style: dashed; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # border-style](https://w3c.github.io/csswg-drafts/css-logical/#border-style) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-block-end-style` | 69 | 79 | 41 | No | 56 | 12.1 | 69 | 69 | 41 | 48 | 12.2 | 10.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * This property maps to one of the physical border properties: [`border-top-style`](border-top-style), [`border-right-style`](border-right-style), [`border-bottom-style`](border-bottom-style), and [`border-left-style`](border-left-style). * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css text-decoration-style text-decoration-style ===================== The `text-decoration-style` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the style of the lines specified by [`text-decoration-line`](text-decoration-line). The style applies to all lines that are set with `text-decoration-line`. Try it ------ 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 [`<del>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/del) or [`<s>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/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 [`text-decoration`](text-decoration) shorthand property instead. Syntax ------ ``` /\* 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 Draws no line. Use [`text-decoration-line`](text-decoration-line)`: none` instead. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `solid` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` text-decoration-style = solid [|](value_definition_syntax#single_bar) double [|](value_definition_syntax#single_bar) dotted [|](value_definition_syntax#single_bar) dashed [|](value_definition_syntax#single_bar) wavy ``` Examples -------- ### Setting a wavy underline The following creates a red wavy underline: #### CSS ``` .wavy { text-decoration-line: underline; text-decoration-style: wavy; text-decoration-color: red; } ``` #### HTML ``` <p class="wavy">This text has a wavy red line beneath it.</p> ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Text Decoration Module Level 3 # text-decoration-style-property](https://w3c.github.io/csswg-drafts/css-text-decor/#text-decoration-style-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `text-decoration-style` | 57 | 79 | 36 6-39 | No | 44 | 12.1 8 | 57 | 57 | 36 6-39 | 43 | 12.2 8 | 7.0 | | `wavy` | 57 | 79 | 6 | No | 44 | 8 | 57 | 57 | 6 | 43 | 8 | 7.0 | See also -------- * When setting multiple line-decoration properties at once, it may be more convenient to use the [`text-decoration`](text-decoration) shorthand property instead. * [`text-decoration-line`](text-decoration-line) * [`text-decoration-color`](text-decoration-color) * [`text-decoration-thickness`](text-decoration-thickness) * [`text-underline-offset`](text-underline-offset) css CSS Fragmentation CSS Fragmentation ================= **CSS Fragmentation** is a module of CSS that defines how content is displayed when it is broken (fragmented) across multiple [pages](https://developer.mozilla.org/en-US/docs/Web/CSS/Paged_Media), regions, or [columns](css_columns). Fragmentation occurs when an inline box wraps onto multiple lines. It also occurs when a block spans more than one column inside a column layout container, or spans a page break when printed. Each piece of the rendering for the element is called a *fragment*. Reference --------- ### Properties * [`box-decoration-break`](box-decoration-break) * [`break-after`](break-after) * [`break-before`](break-before) * [`break-inside`](break-inside) * [`orphans`](orphans) * [`widows`](widows) Specifications -------------- | Specification | | --- | | [CSS Fragmentation Module Level 3](https://drafts.csswg.org/css-break/) | css -webkit-line-clamp -webkit-line-clamp ================== The `-webkit-line-clamp` CSS property allows limiting of the contents of a [block](https://developer.mozilla.org/en-US/docs/Glossary/Block) to the specified number of lines. It only works in combination with the [`display`](display) property set to `-webkit-box` or `-webkit-inline-box` and the [`-webkit-box-orient`](box-orient) property set to `vertical`. In most cases you will also want to set [`overflow`](overflow) to `hidden`, otherwise the contents won't be clipped but an ellipsis will still be shown after the specified number of lines. When applied to anchor elements, the truncating can happen in the middle of the text, not necessarily at the end. **Note:** This property was originally implemented in WebKit and has some issues. It got standardized for legacy support. The [CSS Overflow Module Level 3](https://www.w3.org/TR/css-overflow-3/#propdef--webkit-line-clamp) specification also defines a `line-clamp` property, which is meant to replace this property and avoid its issues. Syntax ------ ``` /\* Keyword value \*/ -webkit-line-clamp: none; /\* <integer> values \*/ -webkit-line-clamp: 3; -webkit-line-clamp: 10; /\* Global values \*/ -webkit-line-clamp: inherit; -webkit-line-clamp: initial; -webkit-line-clamp: unset; ``` `none` This value specifies that the content won't be clamped. [`<integer>`](integer) This value specifies the number of lines after which the content will be clamped. It must be greater than 0. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | by computed value type | Formal syntax ------------- ``` -webkit-line-clamp = none [|](value_definition_syntax#single_bar) [<integer>](integer) ``` Examples -------- ### Truncating a paragraph #### HTML ``` <p> In this example the <code>-webkit-line-clamp</code> property is set to <code>3</code>, which means the text is clamped after three lines. An ellipsis will be shown at the point where the text is clamped. </p> ``` #### CSS ``` p { width: 300px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Overflow Module Level 3 # webkit-line-clamp](https://w3c.github.io/csswg-drafts/css-overflow/#webkit-line-clamp) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `-webkit-line-clamp` | 6 | 17 | 68 | No | 15 | 5 | ≤37 | 18 | 68 | 14 | 4.2 | 1.0 | See also -------- * [Line Clampin' (Truncating Multiple Line Text)](https://css-tricks.com/line-clampin/) * `line-clamp` css CSS Flexible Box Layout CSS Flexible Box Layout ======================= **CSS Flexible Box Layout** is a module of [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) that defines a CSS box model optimized for user interface design, and the layout of items in one dimension. In the flex layout model, the children of a flex container can be laid out in any direction, and can "flex" their sizes, either growing to fill unused space or shrinking to avoid overflowing the parent. Both horizontal and vertical alignment of the children can be easily manipulated. Basic example ------------- In the following example a container has been set to `display: flex`, which means that the three child items become flex items. The value of `justify-content` has been set to `space-between` in order to space the items out evenly on the main axis. An equal amount of space is placed between each item with the left and right items being flush with the edges of the flex container. You can also see that the items are stretching on the cross axis, due to the default value of `align-items` being `stretch`. The items stretch to the height of the flex container, making them each appear as tall as the tallest item. Reference --------- ### Properties * [`flex`](flex) * [`flex-basis`](flex-basis) * [`flex-direction`](flex-direction) * [`flex-flow`](flex-flow) * [`flex-grow`](flex-grow) * [`flex-shrink`](flex-shrink) * [`flex-wrap`](flex-wrap) * [`order`](order) ### Properties for alignment The properties `align-content`, `align-self`, `align-items` and `justify-content` initially appeared in the Flexbox specification, but are now defined in Box Alignment. The Flexbox spec now refers to the Box Alignment specification for up to date definitions. Also additional alignment properties are now defined in Box Alignment. * [`justify-content`](justify-content) * [`align-content`](align-content) * [`align-items`](align-items) * [`align-self`](align-self) * [`place-content`](place-content) * [`place-items`](place-items) * [`row-gap`](row-gap) * [`column-gap`](column-gap) * [`gap`](gap) Guides ------ [Basic concepts of flexbox](css_flexible_box_layout/basic_concepts_of_flexbox) An overview of the features of Flexbox [Relationship of flexbox to other layout methods](css_flexible_box_layout/relationship_of_flexbox_to_other_layout_methods) How Flexbox relates to other layout methods, and other CSS specifications [Aligning items in a flex container](css_flexible_box_layout/aligning_items_in_a_flex_container) How the Box Alignment properties work with Flexbox. [Ordering flex items](css_flexible_box_layout/ordering_flex_items) Explaining the different ways to change the order and direction of items, and covering the potential issues in doing so. [Controlling ratios of flex items along the main axis](css_flexible_box_layout/controlling_ratios_of_flex_items_along_the_main_ax) Explaining the flex-grow, flex-shrink and flex-basis properties. [Mastering wrapping of flex items](css_flexible_box_layout/mastering_wrapping_of_flex_items) How to create flex containers with multiple lines and control the display of the items in those lines. [Typical use cases of flexbox](css_flexible_box_layout/typical_use_cases_of_flexbox) Common design patterns that are typical Flexbox use cases. Specifications -------------- | Specification | | --- | | [CSS Flexible Box Layout Module Level 1](https://drafts.csswg.org/css-flexbox/) | See also -------- * Glossary terms: + [Flexbox](https://developer.mozilla.org/en-US/docs/Glossary/Flexbox) + [Flex Container](https://developer.mozilla.org/en-US/docs/Glossary/Flex_Container) + [Flex Item](https://developer.mozilla.org/en-US/docs/Glossary/Flex_Item) + [Main Axis](https://developer.mozilla.org/en-US/docs/Glossary/Main_Axis) + [Cross Axis](https://developer.mozilla.org/en-US/docs/Glossary/Cross_Axis) + [Flex](https://developer.mozilla.org/en-US/docs/Glossary/Flex) css <calc-sum> <calc-sum> ========== The `<calc-sum>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) represents an expression which performs a calculation in any [CSS math function](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](https://developer.mozilla.org/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 ``` <calc-sum> = <calc-product> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '+' [|](value_definition_syntax#single_bar) '-' []](value_definition_syntax#brackets) <calc-product> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-product> = <calc-value> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '*' [|](value_definition_syntax#single_bar) '/' []](value_definition_syntax#brackets) <calc-value> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-value> = [<number>](number) [|](value_definition_syntax#single_bar) [<dimension>](dimension) [|](value_definition_syntax#single_bar) [<percentage>](percentage) [|](value_definition_syntax#single_bar) <calc-constant> [|](value_definition_syntax#single_bar) ( <calc-sum> ) <calc-constant> = e [|](value_definition_syntax#single_bar) pi [|](value_definition_syntax#single_bar) infinity [|](value_definition_syntax#single_bar) -infinity [|](value_definition_syntax#single_bar) NaN <calc-sum> = <calc-product> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '+' [|](value_definition_syntax#single_bar) '-' []](value_definition_syntax#brackets) <calc-product> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) ``` Description ----------- The operands in the expression may be any [`<length>`](length) syntax value. You can use [`<length>`](length), [`<frequency>`](frequency), [`<angle>`](angle), [`<time>`](time), [`<percentage>`](percentage), [`<number>`](number), or [`<integer>`](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](css_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 [whitespace](https://developer.mozilla.org/en-US/docs/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 -------------- **No specification found**No specification data found for `css.types.calc-sum`. [Check for problems with this page](#on-github) or contribute a missing `spec_url` to [mdn/browser-compat-data](https://github.com/mdn/browser-compat-data). Also make sure the specification is included in [w3c/browser-specs](https://github.com/w3c/browser-specs). Browser compatibility --------------------- No compatibility data found for `css.types.calc-sum`. [Check for problems with this page](#on-github) or contribute missing data to [mdn/browser-compat-data](https://github.com/mdn/browser-compat-data). See also -------- * `<calc-product>` * `<calc-value>` * [`<calc-constant>`](calc-constant) css column-rule-width column-rule-width ================= The `column-rule-width` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the width of the line drawn between columns in a multi-column layout. Try it ------ Syntax ------ ``` /\* Keyword values \*/ column-rule-width: thin; column-rule-width: medium; column-rule-width: thick; /\* <length> values \*/ column-rule-width: 1px; column-rule-width: 2.5em; /\* Global values \*/ column-rule-width: inherit; column-rule-width: initial; column-rule-width: revert; column-rule-width: revert-layer; column-rule-width: unset; ``` The `column-rule-width` property is specified as a single `<'border-width'>` value. ### Values `<'border-width'>` Is a keyword defined by [`border-width`](border-width) describing the width of the rule. It may be either a [`<length>`](length) or one of the `thin`, `medium`, or `thick` keywords. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `medium` | | Applies to | multicol elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | the absolute length; `0` if the [`column-rule-style`](column-rule-style) is `none` or `hidden` | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` column-rule-width = <line-width> <line-width> = [<length [0,∞]>](length) [|](value_definition_syntax#single_bar) thin [|](value_definition_syntax#single_bar) medium [|](value_definition_syntax#single_bar) thick ``` Examples -------- ### Setting a thick column rule #### HTML ``` <p> This is a bunch of text split into three columns. The `column-rule-width` property is used to change the width of the line that is drawn between columns. Don't you think that's wonderful? </p> ``` #### CSS ``` p { column-count: 3; column-rule-style: solid; column-rule-width: thick; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Multi-column Layout Module Level 1 # crw](https://w3c.github.io/csswg-drafts/css-multicol/#crw) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `column-rule-width` | 50 1 | 12 12 | 52 3.5-74 | 10 | 15 11.1 | 9 3 | 50 ≤37 | 50 18 | 52 4 | 14 11.1 | 9 1 | 5.0 1.0 | See also -------- * [Multiple-column Layout](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Multiple-column_Layout) * [`column-rule-style`](column-rule-style) * [`column-rule-color`](column-rule-color) * [`column-rule`](column-rule)
programming_docs
css hyphens hyphens ======= The `hyphens` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property specifies how words should be hyphenated when text wraps across multiple lines. It can prevent hyphenation entirely, hyphenate at manually-specified points within the text, or let the browser automatically insert hyphens where appropriate. Try it ------ **Note:** In the above demo, the string "An extraordinarily long English word!" contains the hidden `&shy;` (soft hyphen) character: `An extra&shy;ordinarily long English word!`. This character is used to indicate a potential place to insert a hyphen when `hyphens: manual;` is specified. Hyphenation rules are language-specific. In HTML, the language is determined by the [`lang`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang) attribute, and browsers will hyphenate only if this attribute is present and the appropriate hyphenation dictionary is available. In XML, the [`xml:lang`](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/xml:lang) attribute must be used. **Note:** The rules defining how hyphenation is performed are not explicitly defined by the specification, so the exact hyphenation may vary from browser to browser. If supported, [`hyphenate-character`](hyphenate-character) may be used to specify an alternative hyphenation character to use at the end of the line being broken. Syntax ------ ``` /\* Keyword values \*/ hyphens: none; hyphens: manual; hyphens: auto; /\* Global values \*/ hyphens: inherit; hyphens: initial; hyphens: revert; hyphens: revert-layer; hyphens: unset; ``` The `hyphens` property is specified as a single keyword value chosen from the list below. ### Values `none` Words are not broken at line breaks, even if characters inside the words suggest line break points. Lines will only wrap at whitespace. `manual` Words are broken for line-wrapping only where characters inside the word suggest line break opportunities. See [Suggesting line break opportunities](#suggesting_line_break_opportunities) below for details. `auto` The browser is free to automatically break words at appropriate hyphenation points, following whatever rules it chooses. However, suggested line break opportunities (see [Suggesting line break opportunities](#suggesting_line_break_opportunities) below) will override automatic break point selection when present. **Note:** The `auto` setting's behavior depends on the language being properly tagged to select the appropriate hyphenation rules. You must specify a language using the `lang` HTML attribute to guarantee that automatic hyphenation is applied in that language. Suggesting line break opportunities ----------------------------------- There are two Unicode characters used to manually specify potential line break points within text: U+2010 (HYPHEN) The "hard" hyphen character indicates a visible line break opportunity. Even if the line is not actually broken at that point, the hyphen is still rendered. U+00AD (SHY) An invisible, "**s**oft" **hy**phen. This character is not rendered visibly; instead, it marks a place where the browser should break the word if hyphenation is necessary. In HTML, use `&shy;` to insert a soft hyphen. **Note:** When the HTML [`<wbr>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/wbr) element leads to a line break, no hyphen is added. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `manual` | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` hyphens = none [|](value_definition_syntax#single_bar) manual [|](value_definition_syntax#single_bar) auto ``` Examples -------- ### Specifying text hyphenation This example uses three classes, one for each possible configuration of the `hyphens` property. #### HTML ``` <dl> <dt><code>none</code>: no hyphen; overflow if needed</dt> <dd lang="en" class="none">An extreme&shy;ly long English word</dd> <dt> <code>manual</code>: hyphen only at &amp;hyphen; or &amp;shy; (if needed) </dt> <dd lang="en" class="manual">An extreme&shy;ly long English word</dd> <dt><code>auto</code>: hyphens where the algorithm decides (if needed)</dt> <dd lang="en" class="auto">An extreme&shy;ly long English word</dd> </dl> ``` #### CSS ``` dd { width: 55px; border: 1px solid black; } dd.none { hyphens: none; } dd.manual { hyphens: manual; } dd.auto { hyphens: auto; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Text Module Level 3 # hyphens-property](https://w3c.github.io/csswg-drafts/css-text/#hyphens-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `hyphens` | 55 `auto` value is only supported on macOS and Android and for languages the OS provides hyphenation for. 13 Only `-webkit-hyphens: none` is supported. | 79 `auto` value is only supported on macOS and Android and for languages the OS provides hyphenation for. 79 Only `-webkit-hyphens: none` is supported. 12-79 Only works if the specified language is the same as the language of the underlying OS. | 43 6 Automatic hyphenation only works for languages with hyphenation dictionaries that are integrated into Firefox. | 10 Only works if the specified language is the same as the language of the underlying OS. | 44 `auto` value is only supported on macOS and Android. | 5.1 | 55 4 | 55 18 | 43 6 Automatic hyphenation only works for languages with hyphenation dictionaries that are integrated into Firefox. | 43 | 4.2 | 6.0 1.0 | | `afrikaans` | No | No | 8 | No | No | No | No | No | 8 | No | No | No | | `bosnian` | No | No | 8 | No | No | No | No | No | 8 | No | No | No | | `bulgarian` | No | No | 8 | No | No | No | No | No | 8 | No | No | No | | `catalan` | No | No | 8 | No | No | 5.1 | No | No | 8 | No | 5 | No | | `croatian` | No | No | 8 | No | No | 9.1 | No | No | 8 | No | 9.3 | No | | `czech` | No | No | No | No | No | 9.1 | No | No | No | No | 9.3 | No | | `danish` | No | No | 8 | No | No | 5.1 | No | No | 8 | No | 5 | No | | `dutch` | No | No | 8 | No | No | 5.1 | No | No | 8 | No | 5 | No | | `english` | 55 | 12 | 6 For English, Firefox uses an en-US dictionary | 10 | 44 | 5.1 For English, Safari uses different en-GB and en-US dictionaries. | 55 | 55 | 6 For English, Firefox uses an en-US dictionary | 43 | 5 For English, Safari uses different en-GB and en-US dictionaries. | 6.0 | | `esperanto` | No | No | 8 | No | No | No | No | No | 8 | No | No | No | | `estonian` | No | No | 8 | No | No | No | No | No | 8 | No | No | No | | `finish` | No | No | 8 | No | No | 9.1 | No | No | 8 | No | 9.3 | No | | `french` | No | No | 8 | No | No | 5.1 | No | No | 8 | No | 5 | No | | `galician` | No | No | 9 | No | No | No | No | No | 9 | No | No | No | | `german_reformed_orthography` | No | No | 8 | No | No | 5.1 | No | No | 8 | No | 5 | No | | `german_swiss_orthography` | No | No | 8 | No | No | No | No | No | 8 | No | No | No | | `german_traditional_orthography` | No | No | 8 | No | No | No | No | No | 8 | No | No | No | | `hungarian` | No | No | 9 | No | No | 9.1 | No | No | 9 | No | 9.3 | No | | `icelandic` | No | No | 8 | No | No | No | No | No | 8 | No | No | No | | `interlingua` | No | No | 8 | No | No | No | No | No | 8 | No | No | No | | `italian` | No | No | 9 | No | No | 5.1 | No | No | 9 | No | 5 | No | | `kurmanji` | No | No | 8 | No | No | No | No | No | 8 | No | No | No | | `latin` | No | No | 8 | No | No | No | No | No | 8 | No | No | No | | `lithuanian` | No | No | 8 | No | No | No | No | No | 8 | No | No | No | | `mongolian` | No | No | 8 | No | No | No | No | No | 8 | No | No | No | | `norwegian_nn` | No | No | 8 | No | No | No | No | No | 8 | No | 5 | No | | `norwegian_no` | No | No | 8 | No | No | 5.1 | No | No | 8 | No | 5 | No | | `polish` | No | No | 31 | No | No | 9.1 | No | No | 31 | No | 9.3 | No | | `portuguese` | No | No | 8 | No | No | 9.1 | No | No | 8 | No | 9.3 | No | | `portuguese_brazilian` | No | No | 8 For Brazilian Portuguese, Firefox uses a Portuguese dictionary. | No | No | No | No | No | 8 For Brazilian Portuguese, Firefox uses a Portuguese dictionary. | No | No | No | | `russian` | No | No | 8 | No | No | 5.1 | No | No | 8 | No | 5 | No | | `slovenian` | No | No | 8 | No | No | No | No | No | 8 | No | No | No | | `spanish` | No | No | 8 | No | No | 5.1 | No | No | 8 | No | 5 | No | | `swedish` | No | No | 8 | No | No | 5.1 | No | No | 8 | No | 5 | No | | `turkish` | No | No | 9 | No | No | 5.1 | No | No | 9 | No | 5 | No | | `ukrainian` | No | No | 9 | No | No | 9.1 | No | No | 9 | No | 9.3 | No | | `upper_sorbian` | No | No | 8 | No | No | No | No | No | 8 | No | No | No | | `welsh` | No | No | 8 | No | No | No | No | No | 8 | No | No | No | See also -------- * [`content`](content) * [`overflow-wrap`](overflow-wrap) (formerly `word-wrap`) * [`word-break`](word-break) * [Guide to wrapping and breaking text](css_text/wrapping_text) css inset-inline-end inset-inline-end ================ The `inset-inline-end` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the logical inline end inset of an element, which maps to a physical offset depending on the element's writing mode, directionality, and text orientation. It corresponds to the [`top`](top), [`right`](right), [`bottom`](bottom), or [`left`](left) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ Syntax ------ ``` /\* <length> values \*/ inset-inline-end: 3px; inset-inline-end: 2.4em; /\* <percentage>s of the width or height of the containing block \*/ inset-inline-end: 10%; /\* Keyword value \*/ inset-inline-end: auto; /\* Global values \*/ inset-inline-end: inherit; inset-inline-end: initial; inset-inline-end: revert; inset-inline-end: revert-layer; inset-inline-end: unset; ``` The shorthand for [`inset-inline-start`](inset-inline-start) and `inset-inline-end` is [`inset-inline`](inset-inline). ### Values The `inset-inline-end` property takes the same values as the [`left`](left) property. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | positioned elements | | [Inherited](inheritance) | no | | Percentages | logical-width of containing block | | [Computed value](computed_value) | same as box offsets: [`top`](top), [`right`](right), [`bottom`](bottom), [`left`](left) properties except that directions are logical | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` inset-inline-end = auto [|](value_definition_syntax#single_bar) <length-percentage> <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Setting inline end offset #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-rl; position: relative; inset-inline-end: 20px; background-color: #c8c800; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # position-properties](https://w3c.github.io/csswg-drafts/css-logical/#position-properties) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `inset-inline-end` | 87 | 87 | 63 41-63 | No | 73 | 14.1 | 87 | 87 | 63 41-63 | 62 | 14.5 | 14.0 | See also -------- * The properties which defines other insets: [`inset-block-start`](inset-block-start), [`inset-block-end`](inset-block-end), and [`inset-inline-start`](inset-inline-start) * The mapped physical properties: [`top`](top), [`right`](right), [`bottom`](bottom), and [`left`](left) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css At-rules At-rules ======== **At-rules** are [CSS statements](syntax#css_statements) that instruct CSS how to behave. They begin with an at sign, '`@`' (`U+0040 COMMERCIAL AT`), followed by an identifier and includes everything up to the next semicolon, '`;`' (`U+003B SEMICOLON`), or the next [CSS block](syntax#css_declarations_blocks), whichever comes first. Syntax ------ ### Regular ``` /\* General structure \*/ @identifier (RULE); /\* Example: tells browser to use UTF-8 character set \*/ @charset "utf-8"; ``` There are several regular at-rules, designated by their identifiers, each with a different syntax: * [`@charset`](@charset) — Defines the character set used by the style sheet. * [`@import`](@import) — Tells the CSS engine to include an external style sheet. * [`@namespace`](@namespace) — Tells the CSS engine that all its content must be considered prefixed with an XML namespace. ### Nested ``` @identifier (RULE) { } ``` A subset of nested statements, which can be used as a statement of a style sheet as well as inside of conditional group rules. * [`@media`](@media) — A conditional group rule that will apply its content if the device meets the criteria of the condition defined using a *media query*. * [`@supports`](@supports) — A conditional group rule that will apply its content if the browser meets the criteria of the given condition. * [`@document`](@document) Deprecated — A conditional group rule that will apply its content if the document in which the style sheet is applied meets the criteria of the given condition. *(deferred to Level 4 of CSS Spec)* * [`@page`](@page) — Describes the aspect of layout changes that will be applied when printing the document. * [`@font-face`](@font-face) — Describes the aspect of an external font to be downloaded. * [`@keyframes`](@keyframes) — Describes the aspect of intermediate steps in a CSS animation sequence. * [`@counter-style`](@counter-style) — Defines specific counter styles that are not part of the predefined set of styles. *(at the Candidate Recommendation stage, but only implemented in Gecko as of writing)* * [`@font-feature-values`](@font-feature-values) (plus `@swash`, `@ornaments`, `@annotation`, `@stylistic`, `@styleset` and `@character-variant`) — Define common names in [`font-variant-alternates`](font-variant-alternates) for feature activated differently in OpenType. *(at the Candidate Recommendation stage, but only implemented in Gecko as of writing)* * [`@property`](@property) Experimental — Describes the aspect of custom properties and variables. *(currently at the Working Draft stage)* * [`@layer`](@layer) – Declares a cascade layer and defines the order of precedence in case of multiple cascade layers. Conditional group rules ----------------------- Much like the values of properties, each at-rule has a different syntax. Nevertheless, several of them can be grouped into a special category named **conditional group rules**. These statements share a common syntax and each of them can include *nested statements*—either *rulesets* or *nested at-rules*. Furthermore, they all convey a common semantic meaning—they all link some type of condition, which at any time evaluates to either **true** or **false**. If the condition evaluates to **true**, then all of the statements within the group will be applied. Conditional group rules are defined in [CSS Conditionals Level 3](https://drafts.csswg.org/css-conditional-3/) and are: * [`@media`](@media), * [`@supports`](@supports), * [`@document`](@document). *(deferred to Level 4 of CSS Spec)* Since each conditional group may also contain nested statements, there may be an unspecified amount of nesting. Index ----- * [`@charset`](@charset) * [`@counter-style`](@counter-style) * [`@document`](@document) Deprecated * [`@font-face`](@font-face) * [`@font-feature-values`](@font-feature-values) * [`@import`](@import) * [`@keyframes`](@keyframes) * [`@layer`](@layer) * [`@media`](@media) * [`@namespace`](@namespace) * [`@page`](@page) * [`@property`](@property) Experimental * [`@supports`](@supports) Specifications -------------- | Specification | | --- | | [CSS Conditional Rules Module Level 3](https://drafts.csswg.org/css-conditional-3/) | | [Compatibility Standard # css-at-rules](https://compat.spec.whatwg.org/#css-at-rules) | See also -------- * CSS key concepts: + [CSS syntax](syntax) + [Comments](comments) + [Specificity](specificity) + [Inheritance](inheritance) + [Box model](css_box_model/introduction_to_the_css_box_model) + [Layout modes](layout_mode) + [Visual formatting models](visual_formatting_model) + [Margin collapsing](css_box_model/mastering_margin_collapsing) + Values - [Initial values](initial_value) - [Computed values](computed_value) - [Used values](used_value) - [Actual values](actual_value) + [Value definition syntax](value_definition_syntax) + [Shorthand properties](shorthand_properties) + [Replaced elements](replaced_element) css <time-percentage> <time-percentage> ================= The `<time-percentage>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) represents a value that can be either a [`<time>`](time) or a [`<percentage>`](percentage). Syntax ------ Refer to the documentation for [`<time>`](time) and [`<percentage>`](percentage) for details of the individual syntaxes allowed by this type. Formal syntax ------------- ``` <time-percentage> = [<time>](time) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Use in calc() Where a `<time-percentage>` is specified as an allowable type, this means that the percentage resolves to a time and therefore can be used in a [`calc()`](calc) expression. ### Valid percentages ``` 50% +50% Optional plus sign -50% Negative percentages are not valid for all properties that accept percentages ``` ### Invalid percentages ``` 50 % Space not allowed between the number and the percentage sign ``` ### Valid times ``` 12s Positive integer -456ms Negative integer 4.3ms Non-integer 14mS The unit is case-insensitive, although capital letters are not recommended. +0s Zero with a leading + and a unit -0ms Zero with a leading - and a unit ``` ### Invalid times ``` 0 Although unitless zero is allowed for <length>s, it's invalid for <time>s. 12.0 This is a <number>, not a <time>, because it's missing a unit. 7 ms No space is allowed between the number and the unit. ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # mixed-percentages](https://w3c.github.io/csswg-drafts/css-values/#mixed-percentages) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `time-percentage` | 1 | 12 | 4 | 9 | 10.1 | 3.1 | 2 | 18 | 4 | 10.1 | 2 | 1.0 | See also -------- * [`<percentage>`](percentage) * [`<time>`](time) * [CSS Values and Units](css_values_and_units) css CSS Shapes CSS Shapes ========== **CSS Shapes** describe geometric shapes for use in CSS. For the [Level 1 specification](https://drafts.csswg.org/css-shapes/), CSS Shapes can be applied to floating elements. The specification defines a number of different ways to define a shape on a floated element, causing wrapping lines to wrap round the shape rather than following the rectangle of the element's box. Basic example ------------- The example below shows an image that has been floated left, and the `shape-outside` property applied with a value of `circle(50%)`. This creates a circle shape, and the content wrapping the float now wraps around that shape. This changes the length of the wrapping text's line boxes. Reference --------- ### Properties * [`shape-image-threshold`](shape-image-threshold) * [`shape-margin`](shape-margin) * [`shape-outside`](shape-outside) ### Data types * [`<basic-shape>`](basic-shape) Guides ------ * [Overview of shapes](css_shapes/overview_of_css_shapes) * [Shapes from box values](css_shapes/from_box_values) * [Basic shapes](css_shapes/basic_shapes) * [Shapes from images](css_shapes/shapes_from_images) Specifications -------------- | Specification | | --- | | [CSS Shapes Module Level 1](https://drafts.csswg.org/css-shapes/) | See also -------- * [CSS Shapes resources](https://codepen.io/KristopherVanSant/post/css-shapes-resources) * [CSS Shapes 101](https://alistapart.com/article/css-shapes-101/) * [Creating non-rectangular layouts with CSS Shapes](https://www.sarasoueidan.com/blog/css-shapes/) * [How to use CSS Shapes in your web design](https://webdesign.tutsplus.com/tutorials/how-to-use-css-shapes-in-your-web-design--cms-27498) * [How to get started with CSS Shapes](https://www.webdesignerdepot.com/2015/03/how-to-get-started-with-css-shapes/) * [What I learned in one weekend with CSS Shapes](https://medium.com/@MHarreither/what-i-learned-in-one-weekend-with-css-shapes-66ae9be69cc5) * [CSS vs. SVG: Shapes and arbitrarily-shaped UI components](https://blog.adobe.com/en/2015/09/01/css-vs-svg-shapes-and-arbitrarily-shaped-ui-components) * [Edit shape paths in CSS — Firefox Developer Tools](https://firefox-source-docs.mozilla.org/devtools-user/page_inspector/how_to/edit_css_shapes/index.html)
programming_docs
css CSS data types CSS data types ============== **CSS data types** define typical values (including keywords and units) accepted by CSS properties and functions. They are a special kind of [component value type](https://www.w3.org/TR/css3-values/#component-types). The most commonly-used types are defined in the [CSS Values and Units](css_values_and_units) specification. This specification also defines [functional notations](css_functions), which allow for more complex types or processing. Other types are defined in the specifications to which they apply. Below you will find a reference to the types that you are most likely to come across, however it is not a comprehensive reference for all types defined in every CSS specification. Syntax ------ ``` selector { property: <unit-data-type>; } ``` In formal CSS syntax, data types are denoted by a keyword placed between the inequality signs "`<`" and "`>`". Textual data types ------------------ These types include keywords and identifiers as well as strings, and URLs. Pre-defined keywords Keywords with a pre-defined meaning, for example the value of `collapse` for the [`border-collapse`](border-collapse) property. CSS-wide keyword: `initial` The value specified as the property's initial value. CSS-wide keyword: `inherit` The computed value of the property on the element's parent. CSS-wide keyword: `unset` Acts as `inherit` or `initial` depending on whether the property is inherited or not. [`<custom-ident>`](custom-ident) A user-defined identifier, for example the name assigned using the [`grid-area`](grid-area) property. [`<dashed-ident>`](dashed-ident) A `<custom-ident>` with the additional restriction that it must start with two dashes, for example with [CSS Custom Properties](using_css_custom_properties). [`<string>`](string) A quoted string, such as used for a value of the [`content`](content) property. [`url()`](url) A pointer to a resource, for example as the value of [`background-image`](background-image). Numeric data types ------------------ These data types are used to indicate quantities, indexes, and positions. The majority of these are defined in the Values and Units specification, however additional types are described in other specifications where they are specific to that specification alone — for example the `fr` unit in [CSS Grid Layout](https://www.w3.org/TR/css-grid-1/#fr-unit). [`<integer>`](integer) One or more decimal units 0 through 9. [`<number>`](number) Real numbers which may also have a fractional component, for example 1 or 1.34. [`<dimension>`](dimension) A number with a unit attached to it, for example 23px or 15em. [`<percentage>`](percentage) A number with a percentage sign attached to it, for example 10%. [`<ratio>`](ratio) A ratio, written with the syntax `<number> / <number>`. [`<flex>`](flex_value) A flexible length introduced for [CSS Grid Layout](css_grid_layout), written as a `<number>` with the `fr` unit attached and used for grid track sizing. Quantities ---------- These types are used to specify distance and other quantities. [`<length>`](length) Lengths are a `<dimension>` and refer to distances. [`<angle>`](angle) Angles are used in properties such as [`linear-gradient()`](gradient/linear-gradient) and are a `<dimension>` with one of `deg`, `grad`, `rad`, or `turn` units attached. [`<time>`](time) Duration units are a `<dimension>` with an `s` or `ms` unit. [`<frequency>`](frequency) Frequencies are a `<dimension>` with a `Hz` or `kHz` unit attached. [`<resolution>`](resolution) Is a `<dimension>` with a unit identifier of `dpi`, `dpcm`, `dppx`, or `x`. Combinations of types --------------------- Some CSS properties can take a dimension or a percentage value. In this case the percentage value will be resolved to a quantity that matches the allowable dimension. Properties which can accept a percentage in addition to a dimension will use one of the types listed below. [`<length-percentage>`](length-percentage) A type that can accept a length or a percentage as a value. [`<frequency-percentage>`](frequency-percentage) A type that can accept a frequency or a percentage as a value. [`<angle-percentage>`](angle-percentage) A type that can accept an angle or a percentage as a value. [`<time-percentage>`](time-percentage) A type that can accept a time or a percentage as a value. Color ----- [The CSS Color Specification](https://www.w3.org/TR/css-color-3/) defines the [`<color>`](color_value) data type, and other types which relate to color in CSS. [`<color>`](color_value) Specified as a keyword or a numerical color value. [`<alpha-value>`](alpha-value) Specifies the transparency of a color. May be a `<number>`, in which case 0 is fully transparent and 1 is fully opaque, or a `<percentage>`, in which case 0% is fully transparent and 100% fully opaque. Images ------ [The CSS Images Specification](https://www.w3.org/TR/css-images-3/) defines the data types which deal with images, including gradients. [`<image>`](image) A URL reference to an image or a color gradient. `<color-stop-list>` A list of two or more color stops with optional transition information using a color hint. `<linear-color-stop>` A `<color>` and a `<length-percentage>` to indicate the color stop for this part of the gradient. `<linear-color-hint>` A `<length-percentage>` to indicate how the color interpolates. `<ending-shape>` Used for radial gradients; can have a keyword value of `circle` or `ellipse`. `<size>` Determines the size of the radial gradient's ending shape. This accepts a value of a keyword or a `<length>` but not a percentage. 2D positioning -------------- The [`<position>`](position_value) data type is interpreted as defined for the [`<background-position>`](background-position) property. [`<position>`](position_value) Defines the position of an object area. Accepts a keyword value such as `top` or `left`, or a `<length-percentage>`. Calculation data types ---------------------- These data types are used in [CSS math function](css_functions#math_functions) calculations. [`<calc-sum>`](calc-sum) A calculation which is a sequence of calculation values interspersed with addition (`+`) and subtraction (`-`) operators. This data type requires both values to have units. `<calc-product>` A calculation which is a sequence of calculation values interspersed with multiplication (`*`) and division (`/`) operators. When multiplying, one value must be unitless. When dividing, the second value must be unitless. `<calc-value>` Defines accepted values for calculations, values such as [`<number>`](number), [`<dimension>`](dimension), [`<percentage>`](percentage), [`<calc-constant>`](calc-constant) or nested [`<calc-sum>`](calc-sum) calculations. [`<calc-constant>`](calc-constant) Defines a number of CSS keywords representing numeric constants such as `e` and `π`, that can be used in CSS math functions. Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4](https://drafts.csswg.org/css-values/) | See also -------- * [CSS Units and Values](css_values_and_units) * [Introduction to CSS: Values and Units](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units) * [CSS Functional Notation](css_functions) css mask-border-width mask-border-width ================= The `mask-border-width` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the width of an element's [mask border](mask-border). Syntax ------ ``` /\* Keyword value \*/ mask-border-width: auto; /\* <length> value \*/ mask-border-width: 1rem; /\* <percentage> value \*/ mask-border-width: 25%; /\* <number> value \*/ mask-border-width: 3; /\* top and bottom | left and right \*/ mask-border-width: 2em 3em; /\* top | left and right | bottom \*/ mask-border-width: 5% 15% 10%; /\* top | right | bottom | left \*/ mask-border-width: 5% 2em 10% auto; /\* Global values \*/ mask-border-width: inherit; mask-border-width: initial; mask-border-width: revert; mask-border-width: revert-layer; mask-border-width: unset; ``` The `mask-border-width` property may be specified using one, two, three, or four values chosen from the list of values below. * When **one** value is specified, it applies the same width to **all four sides**. * When **two** values are specified, the first width applies to the **top and bottom**, the second to the **left and right**. * When **three** values are specified, the first width applies to the **top**, the second to the **left and right**, the third to the **bottom**. * When **four** values are specified, the widths apply to the **top**, **right**, **bottom**, and **left** in that order (clockwise). ### Values `<length-percentage>` The width of the mask border, specified as a [`<length>`](length) or a [`<percentage>`](percentage). Percentages are relative to the *width* of the border area for horizontal offsets and the *height* of the border area for vertical offsets. Must not be negative. `<number>` The width of the mask border, specified as a multiple of the corresponding [`border-width`](border-width). Must not be negative. `auto` The width of the mask border is made equal to the intrinsic width or height (whichever is applicable) of the corresponding [`mask-border-slice`](mask-border-slice). If the image does not have the required intrinsic dimension, the corresponding `border-width` is used instead. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | all elements; In SVG, it applies to container elements excluding the [`<defs>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs) element and all graphics elements | | [Inherited](inheritance) | no | | Percentages | relative to width/height of the mask border image area | | [Computed value](computed_value) | as specified, but with relative lengths converted into absolute lengths | | Animation type | discrete | Formal syntax ------------- ``` mask-border-width = [[](value_definition_syntax#brackets) <length-percentage> [|](value_definition_syntax#single_bar) [<number>](number) [|](value_definition_syntax#single_bar) auto []](value_definition_syntax#brackets)[{1,4}](value_definition_syntax#curly_braces) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Basic usage This property doesn't appear to be supported anywhere yet. When it eventually starts to be supported, it will serve to define the width of the border mask — setting this to a different value to [`mask-border-slice`](mask-border-slice) will cause the slices to be scaled to fit the border mask. ``` mask-border-width: 30 fill; ``` Chromium-based browsers support an outdated version of this property — `mask-box-image-width` — with a prefix: ``` -webkit-mask-box-image-width: 20px; ``` **Note:** The [`mask-border`](mask-border) page features a working example (using the out-of-date prefixed border mask properties supported in Chromium), so you can get an idea of the effect. Specifications -------------- | Specification | | --- | | [CSS Masking Module Level 1 # the-mask-border-width](https://drafts.fxtf.org/css-masking/#the-mask-border-width) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `mask-border-width` | 1 | 79 | No See [bug 877294](https://bugzil.la/877294). | No | 15 | 3.1 | 4.4 | 18 | No See [bug 877294](https://bugzil.la/877294). | 14 | 3 | 1.0 | See also -------- * [`mask-border`](mask-border) * [`mask-border-mode`](mask-border-mode) * [`mask-border-outset`](mask-border-outset) * [`mask-border-repeat`](mask-border-repeat) * [`mask-border-source`](mask-border-source) css clear clear ===== The `clear` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets whether an element must be moved below (cleared) [floating](float) elements that precede it. The `clear` property applies to floating and non-floating elements. Try it ------ When applied to non-floating blocks, it moves the [border edge](css_box_model/introduction_to_the_css_box_model#border_area) of the element down until it is below the [margin edge](css_box_model/introduction_to_the_css_box_model#margin_area) of all relevant floats. The non-floated block's top margin collapses. Vertical margins between two floated elements on the other hand will not collapse. When applied to floating elements, the margin edge of the bottom element is moved below the margin edge of all relevant floats. This affects the position of later floats, since later floats cannot be positioned higher than earlier ones. The floats that are relevant to be cleared are the earlier floats within the same [block formatting context](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context). **Note:** If an element contains only floated elements, its height collapses to nothing. If you want it to always be able to resize, so that it contains floating elements inside it, set the value of the element's [`display`](display) property to [`flow-root`](display#flow-root). ``` #container { display: flow-root; } ``` Syntax ------ ``` /\* Keyword values \*/ clear: none; clear: left; clear: right; clear: both; clear: inline-start; clear: inline-end; /\* Global values \*/ clear: inherit; clear: initial; clear: revert; clear: revert-layer; clear: unset; ``` ### Values `none` Is a keyword indicating that the element is *not* moved down to clear past floating elements. `left` Is a keyword indicating that the element is moved down to clear past *left* floats. `right` Is a keyword indicating that the element is moved down to clear past *right* floats. `both` Is a keyword indicating that the element is moved down to clear past *both* left and right floats. `inline-start` Is a keyword indicating that the element is moved down to clear floats on *start side of its containing block*, that is the *left* floats on ltr scripts and the *right* floats on rtl scripts. `inline-end` Is a keyword indicating that the element is moved down to clear floats on *end side of its containing block*, that is the *right* floats on ltr scripts and the *left* floats on rtl scripts. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | block-level elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` clear = inline-start [|](value_definition_syntax#single_bar) inline-end [|](value_definition_syntax#single_bar) block-start [|](value_definition_syntax#single_bar) block-end [|](value_definition_syntax#single_bar) left [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) top [|](value_definition_syntax#single_bar) bottom [|](value_definition_syntax#single_bar) none ``` Examples -------- ### clear: left #### HTML ``` <div class="wrapper"> <p class="black"> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus sit amet diam. Duis mattis varius dui. Suspendisse eget dolor. </p> <p class="red">Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p> <p class="left">This paragraph clears left.</p> </div> ``` #### CSS ``` .wrapper { border: 1px solid black; padding: 10px; } .left { border: 1px solid black; clear: left; } .black { float: left; margin: 0; background-color: black; color: #fff; width: 20%; } .red { float: left; margin: 0; background-color: pink; width: 20%; } p { width: 50%; } ``` ### clear: right #### HTML ``` <div class="wrapper"> <p class="black"> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus sit amet diam. Duis mattis varius dui. Suspendisse eget dolor. </p> <p class="red">Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p> <p class="right">This paragraph clears right.</p> </div> ``` #### CSS ``` .wrapper { border: 1px solid black; padding: 10px; } .right { border: 1px solid black; clear: right; } .black { float: right; margin: 0; background-color: black; color: #fff; width: 20%; } .red { float: right; margin: 0; background-color: pink; width: 20%; } p { width: 50%; } ``` ### clear: both #### HTML ``` <div class="wrapper"> <p class="black"> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus sit amet diam. Duis mattis varius dui. Suspendisse eget dolor. Fusce pulvinar lacus ac dui. </p> <p class="red"> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus sit amet diam. Duis mattis varius dui. Suspendisse eget dolor. </p> <p class="both">This paragraph clears both.</p> </div> ``` #### CSS ``` .wrapper { border: 1px solid black; padding: 10px; } .both { border: 1px solid black; clear: both; } .black { float: left; margin: 0; background-color: black; color: #fff; width: 20%; } .red { float: right; margin: 0; background-color: pink; width: 20%; } p { width: 45%; } ``` Specifications -------------- | Specification | | --- | | [Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification # propdef-clear](https://w3c.github.io/csswg-drafts/css2/#propdef-clear) | | [CSS Logical Properties and Values Level 1 # float-clear](https://w3c.github.io/csswg-drafts/css-logical/#float-clear) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `clear` | 1 | 12 | 1 | 4 | 3.5 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `flow_relative_values` | 70 | 79 | 55 | No | 57 | preview | No | 70 | 55 | No | No | No | See also -------- * [CSS basic box model](css_box_model/introduction_to_the_css_box_model) css grid-column grid-column =========== The `grid-column` CSS [shorthand property](shorthand_properties) specifies a grid item's size and location within a [grid column](https://developer.mozilla.org/en-US/docs/Glossary/Grid_Column) by contributing a line, a span, or nothing (automatic) to its grid placement, thereby specifying the inline-start and inline-end edge of its [grid area](https://developer.mozilla.org/en-US/docs/Glossary/Grid_Areas). Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`grid-column-end`](grid-column-end) * [`grid-column-start`](grid-column-start) Syntax ------ ``` /\* Keyword values \*/ grid-column: auto; grid-column: auto / auto; /\* <custom-ident> values \*/ grid-column: somegridarea; grid-column: somegridarea / someothergridarea; /\* <integer> + <custom-ident> values \*/ grid-column: somegridarea 4; grid-column: 4 somegridarea / 6; /\* span + <integer> + <custom-ident> values \*/ grid-column: span 3; grid-column: span somegridarea; grid-column: 5 somegridarea span; grid-column: span 3 / 6; grid-column: span somegridarea / span someothergridarea; grid-column: 5 somegridarea span / 2 span; /\* Global values \*/ grid-column: inherit; grid-column: initial; grid-column: revert; grid-column: revert-layer; grid-column: unset; ``` This property is specified as one or two `<grid-line>` values. If two `<grid-line>` values are given, they are separated by `/`. The `grid-column-start` longhand is set to the value before the slash, and the `grid-column-end` longhand is set to the value after the slash. Each `<grid-line>` value can be specified as: * either the `auto` keyword * or a `<custom-ident>` value * or an `<integer>` value * or both `<custom-ident>` and `<integer>`, separated by a space * or the keyword `span` together with either a `<custom-ident>` or an `<integer>` or both. ### Values `auto` Is a keyword indicating that the property contributes nothing to the grid item's placement, indicating auto-placement, an automatic span, or a default span of `1`. `<custom-ident>` If there is a named line with the name `<custom-ident>-start`/`<custom-ident>-end`, it contributes the first such line to the grid item's placement. **Note:** Named grid areas automatically generate implicit named lines of this form, so specifying `grid-column: foo;` will choose the start/end edge of that named grid area (unless another line named `foo-start`/`foo-end` was explicitly specified before it). Otherwise, this is treated as if the integer `1` had been specified along with the `<custom-ident>`. `<integer> && <custom-ident>?` Contributes the nth grid line to the grid item's placement. If a negative integer is given, it instead counts in reverse, starting from the end edge of the explicit grid. If a name is given as a `<custom-ident>`, only lines with that name are counted. If not enough lines with that name exist, all implicit grid lines are assumed to have that name for the purpose of finding this position. An [`<integer>`](integer) value of `0` is invalid. `span && [ <integer> || <custom-ident> ]` Contributes a grid span to the grid item's placement such that the corresponding edge of the grid item's grid area is n lines from the opposite edge. If a name is given as a `<custom-ident>`, only lines with that name are counted. If not enough lines with that name exist, all implicit grid lines on the side of the explicit grid corresponding to the search direction are assumed to have that name for the purpose of counting this span. If the `<integer>` is omitted, it defaults to `1`. Negative integers or 0 are invalid. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`grid-column-start`](grid-column-start): `auto` * [`grid-column-end`](grid-column-end): `auto` | | Applies to | grid items and absolutely-positioned boxes whose containing block is a grid container | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`grid-column-start`](grid-column-start): as specified * [`grid-column-end`](grid-column-end): as specified | | Animation type | discrete | Formal syntax ------------- ``` grid-column = <grid-line> [[](value_definition_syntax#brackets) / <grid-line> []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) <grid-line> = auto [|](value_definition_syntax#single_bar) [<custom-ident>](custom-ident) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) [<integer [-∞,-1]>](integer) [|](value_definition_syntax#single_bar) [<integer [1,∞]>](integer) []](value_definition_syntax#brackets) [&&](value_definition_syntax#double_ampersand) [<custom-ident>](custom-ident)[?](value_definition_syntax#question_mark) []](value_definition_syntax#brackets) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) span [&&](value_definition_syntax#double_ampersand) [[](value_definition_syntax#brackets) [<integer [1,∞]>](integer) [||](value_definition_syntax#double_bar) [<custom-ident>](custom-ident) []](value_definition_syntax#brackets) []](value_definition_syntax#brackets) ``` Examples -------- ### Setting grid column size and location #### HTML ``` <div id="grid"> <div id="item1"></div> <div id="item2"></div> <div id="item3"></div> </div> ``` #### CSS ``` #grid { display: grid; height: 100px; grid-template-columns: repeat(6, 1fr); grid-template-rows: 100px; } #item1 { background-color: lime; } #item2 { background-color: yellow; grid-column: 2 / 4; } #item3 { background-color: blue; grid-column: span 2 / 7; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Grid Layout Module Level 2 # placement-shorthands](https://w3c.github.io/csswg-drafts/css-grid/#placement-shorthands) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `grid-column` | 57 | 16 | 52 | No | 44 | 10.1 | 57 | 57 | 52 | 43 | 10.3 | 6.0 | See also -------- * Related CSS properties: [`grid-row`](grid-row), [`grid-row-start`](grid-row-start), [`grid-row-end`](grid-row-end), [`grid-column-start`](grid-column-start), [`grid-column-end`](grid-column-end) * Grid Layout Guide: *[Line-based placement with CSS Grid](css_grid_layout/line-based_placement_with_css_grid)* * Video tutorial: *[Line-based placement](https://gridbyexample.com/video/series-line-based-placement/)*
programming_docs
css text-decoration-line text-decoration-line ==================== The `text-decoration-line` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the kind of decoration that is used on text in an element, such as an underline or overline. Try it ------ When setting multiple line-decoration properties at once, it may be more convenient to use the [`text-decoration`](text-decoration) shorthand property instead. Syntax ------ ``` /\* Single keyword \*/ text-decoration-line: none; text-decoration-line: underline; text-decoration-line: overline; text-decoration-line: line-through; text-decoration-line: blink; /\* Multiple keywords \*/ text-decoration-line: underline overline; /\* Two decoration lines \*/ text-decoration-line: overline underline line-through; /\* Multiple decoration lines \*/ /\* Global values \*/ text-decoration-line: inherit; text-decoration-line: initial; text-decoration-line: revert; text-decoration-line: revert-layer; text-decoration-line: unset; ``` The `text-decoration-line` property is specified as `none`, or **one or more** space-separated values from the list below. ### Values `none` Produces no text decoration. `underline` Each line of text has a decorative line beneath it. `overline` Each line of text has a decorative line above it. `line-through` Each line of text has a decorative line going through its middle. `blink` Deprecated The text blinks (alternates between visible and invisible). Conforming user agents may not blink the text. This value is **deprecated** in favor of [CSS animations](animation). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` text-decoration-line = none [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) underline [||](value_definition_syntax#double_bar) overline [||](value_definition_syntax#double_bar) line-through [||](value_definition_syntax#double_bar) blink []](value_definition_syntax#brackets) ``` Examples -------- ### Basic example ``` <p class="wavy">Here's some text with wavy red underline!</p> <p class="both">This text has lines both above and below it.</p> ``` ``` .wavy { text-decoration-line: underline; text-decoration-style: wavy; text-decoration-color: red; } .both { text-decoration-line: underline overline; } ``` Specifications -------------- | Specification | | --- | | [CSS Text Decoration Module Level 3 # text-decoration-line-property](https://w3c.github.io/csswg-drafts/css-text-decor/#text-decoration-line-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `text-decoration-line` | 57 | 79 | 36 6-39 | No | 44 | 12.1 8 | 57 | 57 | 36 6-39 | 43 | 12.2 8 | 7.0 | | `blink` | 57 The `blink` value does not have any effect. | 79 The `blink` value does not have any effect. | 26 The `blink` value does not have any effect. | No | 44 | 8 | 57 The `blink` value does not have any effect. | 57 The `blink` value does not have any effect. | 26 The `blink` value does not have any effect. | 43 | 8 | 7.0 The `blink` value does not have any effect. | See also -------- * When setting multiple line-decoration properties at once, it may be more convenient to use the [`text-decoration`](text-decoration) shorthand property instead, which also includes: + [`text-decoration-style`](text-decoration-style) + [`text-decoration-color`](text-decoration-color) + [`text-decoration-thickness`](text-decoration-thickness) * [`text-underline-offset`](text-underline-offset) css column-rule-color column-rule-color ================= The `column-rule-color` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the color of the line drawn between columns in a multi-column layout. Try it ------ Syntax ------ ``` /\* <color> values \*/ column-rule-color: red; column-rule-color: rgb(192 56 78); column-rule-color: transparent; column-rule-color: hsl(0 100% 50% / 0.6); /\* Global values \*/ column-rule-color: inherit; column-rule-color: initial; column-rule-color: revert; column-rule-color: revert-layer; column-rule-color: unset; ``` The `column-rule-color` property is specified as a single `<color>` value. ### Values [`<color>`](color_value) The color of the rule that separates columns. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `currentcolor` | | Applies to | multicol elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | computed color | | Animation type | a [color](color_value#interpolation) | Formal syntax ------------- ``` column-rule-color = [<color>](color_value) ``` Examples -------- ### Setting a blue column rule #### HTML ``` <p> This is a bunch of text split into three columns. The `column-rule-color` property is used to change the color of the line that is drawn between columns. Don't you think that's wonderful? </p> ``` #### CSS ``` p { column-count: 3; column-rule-style: solid; column-rule-color: blue; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Multi-column Layout Module Level 1 # crc](https://w3c.github.io/csswg-drafts/css-multicol/#crc) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `column-rule-color` | 50 1 | 12 12 | 52 3.5-74 | 10 | 15 11.1 | 9 3 | 50 ≤37 | 50 18 | 52 4 | 14 11.1 | 9 1 | 5.0 1.0 | See also -------- * The [`<color>`](color_value) data type * Other color-related properties: [`color`](color), [`background-color`](background-color), [`border-color`](border-color), [`outline-color`](outline-color), [`text-decoration-color`](text-decoration-color), [`text-emphasis-color`](text-emphasis-color), [`text-shadow`](text-shadow), and [`caret-color`](caret-color) * [Applying color to HTML elements using CSS](css_colors/applying_color) css ::part() ::part() ======== The `::part` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-element](pseudo-elements) represents any element within a [shadow tree](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM) that has a matching [`part`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#part) attribute. ``` custom-element::part(foo) { /\* Styles to apply to the `foo` part \*/ } ``` Syntax ------ ``` ::part( <ident>+ ) ``` Examples -------- ### HTML ``` <template id="tabbed-custom-element"> <style> \*, ::before, ::after { box-sizing: border-box; padding: 1rem; } :host { display: flex; } </style> <div part="tab active">Tab 1</div> <div part="tab">Tab 2</div> <div part="tab">Tab 3</div> </template> <tabbed-custom-element></tabbed-custom-element> ``` ### CSS ``` tabbed-custom-element::part(tab) { color: #0c0dcc; border-bottom: transparent solid 2px; } tabbed-custom-element::part(tab):hover { background-color: #0c0d19; border-color: #0c0d33; } tabbed-custom-element::part(tab):hover:active { background-color: #0c0d33; } tabbed-custom-element::part(tab):focus { box-shadow: 0 0 0 1px #0a84ff inset, 0 0 0 1px #0a84ff, 0 0 0 4px rgba(10, 132, 255, 0.3); } tabbed-custom-element::part(active) { color: #0060df; border-color: #0a84ff !important; } ``` ### JavaScript ``` let template = document.querySelector("#tabbed-custom-element"); globalThis.customElements.define( template.id, class extends HTMLElement { constructor() { super() .attachShadow({ mode: "open" }) .append(template.content); } } ); ``` ### Result Specifications -------------- | Specification | | --- | | [CSS Shadow Parts # part](https://w3c.github.io/csswg-drafts/css-shadow-parts/#part) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `::part` | 73 | 79 | 72 | No | 60 | 13.1 | 73 | 73 | 79 | 52 | 13.4 | 11.0 | See also -------- * The [`part`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#part) attribute - Used to define parts which can be selected by the `::part()` selector * The [`exportparts`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#exportparts) attribute - Used to transitively export shadow parts from a nested shadow tree into a containing light tree. * [Explainer: CSS Shadow ::part and ::theme](https://github.com/fergald/docs/blob/master/explainers/css-shadow-parts-1.md) css Privacy and the :visited selector Privacy and the :visited selector ================================= Before about 2010, the [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [`:visited`](:visited) selector allowed websites to uncover a user's browsing history and figure out what sites the user had visited. This was done through [`window.getComputedStyle`](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle) and other techniques. This process was quick to execute, and made it possible not only to determine where the user had been on the web, but could also be used to guess a lot of information about the user's identity. To mitigate this problem, browsers have limited the amount of information that can be obtained from visited links. Little white lies ----------------- To preserve users' privacy, Firefox and other browsers will lie to web applications under certain circumstances: * The `window.getComputedStyle` method, and similar functions such as [`element.querySelector`](https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelector), will always return values indicating that a user has never visited any of the links on a page. * If you use a sibling selector such as `:visited + span`, the adjacent element (`span` in this example) will be styled as if the link were unvisited. * In rare scenarios, if you're using nested link elements and the element being matched is different from the link whose presence in history is being tested, the element will be rendered as if the link were unvisited, as well. Limits to visited link styles ----------------------------- You can style visited links, but there are limits to which styles you can use. Only the following styles can be applied to visited links: * [`color`](color) * [`background-color`](background-color) * [`border-color`](border-color) (and its sub-properties) * [`column-rule-color`](column-rule-color) * [`outline-color`](outline-color) * [`text-decoration-color`](text-decoration-color) * [`text-emphasis-color`](text-emphasis-color) * The color parts of the `[fill](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill)` and `[stroke](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke)` attributes In addition, even for the above styles, you won't be able to change the transparency between unvisited and visited links, as you otherwise would be able to using the `alpha` parameter to [`rgb()`](color_value/rgb) or [`hsl()`](color_value/hsl), or the [`transparent`](color_value#transparent_keyword) keyword. Here is an example of how to use styles with the aforementioned restrictions: ``` :link { outline: 1px dotted blue; background-color: white; /\* The default value of background-color is `transparent`. You need to specify a different value, otherwise changes on :visited won't apply. \*/ } :visited { outline-color: orange; /\* Visited links have an orange outline \*/ background-color: green; /\* Visited links have a green background \*/ color: yellow; /\* Visited links have yellow colored text \*/ } ``` Impact on web developers ------------------------ Overall, these restrictions shouldn't affect web developers too significantly. They may, however, require the following changes to existing sites: * Using background images to style links based on whether they've been visited will no longer work, since only colors can be used to style visited links. * Colors that are otherwise transparent will fail to appear if styled in a `:visited` selector. See also -------- * [privacy-related changes coming to CSS :visited](https://hacks.mozilla.org/2010/03/privacy-related-changes-coming-to-css-vistited/) on Mozilla Hacks * [Plugging the CSS History Leak](https://blog.mozilla.org/security/2010/03/31/plugging-the-css-history-leak/) on the Mozilla Security Blog * [Preventing attacks on a user's history through CSS :visited selectors](https://dbaron.org/mozilla/visited-privacy) css text-decoration text-decoration =============== The `text-decoration` [shorthand](shorthand_properties) [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the appearance of decorative lines on text. It is a shorthand for [`text-decoration-line`](text-decoration-line), [`text-decoration-color`](text-decoration-color), [`text-decoration-style`](text-decoration-style), and the newer [`text-decoration-thickness`](text-decoration-thickness) property. Try it ------ Text decorations are drawn across descendant text elements. This means that if an element specifies a text decoration, then a child element can't remove the decoration. For example, in the markup `<p>This text has <em>some emphasized words</em> in it.</p>`, the style rule `p { text-decoration: underline; }` would cause the entire paragraph to be underlined. The style rule `em { text-decoration: none; }` would not cause any change; the entire paragraph would still be underlined. However, the rule `em { text-decoration: overline; }` would cause a second decoration to appear on "some emphasized words". Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`text-decoration-color`](text-decoration-color) * [`text-decoration-line`](text-decoration-line) * [`text-decoration-style`](text-decoration-style) * [`text-decoration-thickness`](text-decoration-thickness) Non-standard Syntax ------ ``` text-decoration: underline; text-decoration: overline red; text-decoration: none; /\* Global values \*/ text-decoration: inherit; text-decoration: initial; text-decoration: revert; text-decoration: revert-layer; text-decoration: unset; ``` The `text-decoration` property is specified as one or more space-separated values representing the various longhand text-decoration properties. ### Values [`text-decoration-line`](text-decoration-line) Sets the kind of decoration used, such as `underline` or `line-through`. [`text-decoration-color`](text-decoration-color) Sets the color of the decoration. [`text-decoration-style`](text-decoration-style) Sets the style of the line used for the decoration, such as `solid`, `wavy`, or `dashed`. [`text-decoration-thickness`](text-decoration-thickness) Sets the thickness of the line used for the decoration. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`text-decoration-color`](text-decoration-color): `currentcolor` * [`text-decoration-style`](text-decoration-style): `solid` * [`text-decoration-line`](text-decoration-line): `none` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`text-decoration-line`](text-decoration-line): as specified * [`text-decoration-style`](text-decoration-style): as specified * [`text-decoration-color`](text-decoration-color): computed color * [`text-decoration-thickness`](text-decoration-thickness): as specified | | Animation type | as each of the properties of the shorthand:* [`text-decoration-color`](text-decoration-color): a [color](color_value#interpolation) * [`text-decoration-style`](text-decoration-style): discrete * [`text-decoration-line`](text-decoration-line): discrete * [`text-decoration-thickness`](text-decoration-thickness): by computed value type | Formal syntax ------------- ``` text-decoration = <'text-decoration-line'> [||](value_definition_syntax#double_bar) <'text-decoration-style'> [||](value_definition_syntax#double_bar) <'text-decoration-color'> ``` Examples -------- ### Demonstration of text-decoration values ``` .under { text-decoration: underline red; } .over { text-decoration: wavy overline lime; } .line { text-decoration: line-through; } .plain { text-decoration: none; } .underover { text-decoration: dashed underline overline; } .thick { text-decoration: solid underline purple 4px; } .blink { text-decoration: blink; } ``` ``` <p class="under">This text has a line underneath it.</p> <p class="over">This text has a line over it.</p> <p class="line">This text has a line going through it.</p> <p> This <a class="plain" href="#">link will not be underlined</a>, as links generally are by default. Be careful when removing the text decoration on anchors since users often depend on the underline to denote hyperlinks. </p> <p class="underover">This text has lines above <em>and</em> below it.</p> <p class="thick"> This text has a really thick purple underline in supporting browsers. </p> <p class="blink"> This text might blink for you, depending on the browser you use. </p> ``` Specifications -------------- | Specification | | --- | | [CSS Text Decoration Module Level 3 # text-decoration-property](https://w3c.github.io/csswg-drafts/css-text-decor/#text-decoration-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `text-decoration` | 1 | 12 | 1 | 3 | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | | `blink` | No | No | 1-23 | No | 4-15 | preview | No | No | 4-23 | 10.1-14 | No | No | | `shorthand` | 57 | 79 | 6 | No | 44 | 8 | 57 | 57 | 6 | 43 | 8 | 7.0 | | `text-decoration-thickness` | 87 | 87 | 70 | No | 73 | No | 87 | 87 | No | 62 | No | 14.0 | See also -------- * The individual text-decoration properties are [`text-decoration-line`](text-decoration-line), [`text-decoration-color`](text-decoration-color), [`text-decoration-style`](text-decoration-style), and [`text-decoration-thickness`](text-decoration-thickness). * The [`text-decoration-skip-ink`](text-decoration-skip-ink), [`text-underline-offset`](text-underline-offset), and [`text-underline-position`](text-underline-position) properties also affect text-decoration, but are not included in the shorthand. * The [`list-style`](list-style) attribute controls the appearance of items in HTML [`<ol>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol) and [`<ul>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ul) lists. css transform-style transform-style =============== The `transform-style` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets whether children of an element are positioned in the 3D space or are flattened in the plane of the element. Try it ------ If flattened, the element's children will not exist on their own in the 3D-space. As this property is not inherited, it must be set for all non-leaf descendants of the element. Syntax ------ ``` /\* Keyword values \*/ transform-style: flat; transform-style: preserve-3d; /\* Global values \*/ transform-style: inherit; transform-style: initial; transform-style: revert; transform-style: revert-layer; transform-style: unset; ``` ### Values `flat` Indicates that the children of the element are lying in the plane of the element itself. `preserve-3d` Indicates that the children of the element should be positioned in the 3D-space. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `flat` | | Applies to | transformable elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | | Creates [stacking context](css_positioning/understanding_z_index/the_stacking_context) | yes | Formal syntax ------------- ``` transform-style = flat [|](value_definition_syntax#single_bar) preserve-3d ``` Examples -------- ### Transform style demonstration In this example we have a 3D cube created using transforms. The parent container of the cube faces has `transform-style: preserve-3d` set on it by default, so it is transformed in the 3D space and you can see it as intended. We also provide a checkbox allowing you to toggle between this, and `transform-style: flat`. In this alternative state, the cube faces are all flattened onto the plane of their parent, and you might not be able to see them at all, depending on the browser you are using. #### HTML ``` <section id="example-element"> <div class="face front">1</div> <div class="face back">2</div> <div class="face right">3</div> <div class="face left">4</div> <div class="face top">5</div> <div class="face bottom">6</div> </section> <div class="checkbox"> <label for="preserve"><code>preserve-3d</code></label> <input type="checkbox" id="preserve" checked /> </div> ``` #### CSS ``` #example-element { margin: 50px; width: 100px; height: 100px; transform-style: preserve-3d; transform: rotate3d(1, 1, 1, 30deg); } .face { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; position: absolute; backface-visibility: inherit; font-size: 60px; color: #fff; } .front { background: rgba(90, 90, 90, 0.7); transform: translateZ(50px); } .back { background: rgba(0, 210, 0, 0.7); transform: rotateY(180deg) translateZ(50px); } .right { background: rgba(210, 0, 0, 0.7); transform: rotateY(90deg) translateZ(50px); } .left { background: rgba(0, 0, 210, 0.7); transform: rotateY(-90deg) translateZ(50px); } .top { background: rgba(210, 210, 0, 0.7); transform: rotateX(90deg) translateZ(50px); } .bottom { background: rgba(210, 0, 210, 0.7); transform: rotateX(-90deg) translateZ(50px); } ``` #### JavaScript ``` const cube = document.getElementById('example-element'); const checkbox = document.getElementById('preserve'); checkbox.addEventListener('change', () => { cube.style.transformStyle = checkbox.checked ? 'preserve-3d' : 'flat'; }) ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Transforms Module Level 2 # transform-style-property](https://w3c.github.io/csswg-drafts/css-transforms-2/#transform-style-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `transform-style` | 36 12 | 12 12 | 49 16 10 | No | 23 15 | 9 4 | 4.4 3 | 36 18 | 49 16 10 | 24 14 | 9 2 | 3.0 1.0 | See also -------- * [Using CSS transforms](css_transforms/using_css_transforms)
programming_docs
css border-inline-start border-inline-start =================== The `border-inline-start` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property is a [shorthand property](shorthand_properties) for setting the individual logical inline-start border property values in a single place in the style sheet. Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`border-inline-start-color`](border-inline-start-color) * [`border-inline-start-style`](border-inline-start-style) * [`border-inline-start-width`](border-inline-start-width) Syntax ------ ``` border-inline-start: 1px; border-inline-start: 2px dotted; border-inline-start: medium dashed green; /\* Global values \*/ border-inline-start: inherit; border-inline-start: initial; border-inline-start: revert; border-inline-start: revert-layer; border-inline-start: unset; ``` The physical border to which `border-inline-start` maps depends on the element's writing mode, directionality, and text orientation. It corresponds to the [`border-top`](border-top), [`border-right`](border-right), [`border-bottom`](border-bottom), or [`border-left`](border-left) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Related properties are [`border-block-start`](border-block-start), [`border-block-end`](border-block-end), and [`border-inline-end`](border-inline-end), which define the other borders of the element. ### Values The `border-inline-start` is specified with one or more of the following, in any order: `<'border-width'>` The width of the border. See [`border-width`](border-width). `<'border-style'>` The line style of the border. See [`border-style`](border-style). `<'color'>` The color of the border. See [`color`](color). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`border-width`](border-width): as each of the properties of the shorthand: + [`border-top-width`](border-top-width): `medium` + [`border-right-width`](border-right-width): `medium` + [`border-bottom-width`](border-bottom-width): `medium` + [`border-left-width`](border-left-width): `medium` * [`border-style`](border-style): as each of the properties of the shorthand: + [`border-top-style`](border-top-style): `none` + [`border-right-style`](border-right-style): `none` + [`border-bottom-style`](border-bottom-style): `none` + [`border-left-style`](border-left-style): `none` * [`color`](color): `canvastext` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`border-width`](border-width): as each of the properties of the shorthand: + [`border-bottom-width`](border-bottom-width): the absolute length or `0` if [`border-bottom-style`](border-bottom-style) is `none` or `hidden` + [`border-left-width`](border-left-width): the absolute length or `0` if [`border-left-style`](border-left-style) is `none` or `hidden` + [`border-right-width`](border-right-width): the absolute length or `0` if [`border-right-style`](border-right-style) is `none` or `hidden` + [`border-top-width`](border-top-width): the absolute length or `0` if [`border-top-style`](border-top-style) is `none` or `hidden` * [`border-style`](border-style): as each of the properties of the shorthand: + [`border-bottom-style`](border-bottom-style): as specified + [`border-left-style`](border-left-style): as specified + [`border-right-style`](border-right-style): as specified + [`border-top-style`](border-top-style): as specified * [`border-inline-start-color`](border-inline-start-color): computed color | | Animation type | as each of the properties of the shorthand:* [`border-inline-start-color`](border-inline-start-color): a [color](color_value#interpolation) * [`border-inline-start-style`](border-inline-start-style): discrete * [`border-inline-start-width`](border-inline-start-width): a [length](length#interpolation) | Formal syntax ------------- ``` border-inline-start = <'border-top-width'> [||](value_definition_syntax#double_bar) <'border-top-style'> [||](value_definition_syntax#double_bar) [<color>](color_value) ``` Examples -------- ### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` ### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-rl; border-inline-start: 5px dashed blue; } ``` Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # border-shorthands](https://w3c.github.io/csswg-drafts/css-logical/#border-shorthands) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-inline-start` | 69 | 79 | 41 | No | 56 | 12.1 | 69 | 69 | 41 | 48 | 12.2 | 10.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * This property maps to one of the physical border properties: [`border-top`](border-top), [`border-right`](border-right), [`border-bottom`](border-bottom), or [`border-left`](border-left). * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css CSS Backgrounds and Borders CSS Backgrounds and Borders =========================== Styles in the **CSS Backgrounds and Borders** module allow filling backgrounds with color or an image (clipped or resized), or modifying them in other ways. These styles can also decorate borders with lines or images, and make them square or rounded. (Additionally, element boxes can be decorated with a shadow.) Reference --------- ### Properties * [`background`](background) * [`background-attachment`](background-attachment) * [`background-clip`](background-clip) * [`background-color`](background-color) * [`background-image`](background-image) * [`background-origin`](background-origin) * [`background-position`](background-position) * [`background-position-x`](background-position-x) * [`background-position-y`](background-position-y) * [`background-repeat`](background-repeat) * [`background-size`](background-size) * [`border`](border) * [`border-bottom`](border-bottom) * [`border-bottom-color`](border-bottom-color) * [`border-bottom-left-radius`](border-bottom-left-radius) * [`border-bottom-right-radius`](border-bottom-right-radius) * [`border-bottom-style`](border-bottom-style) * [`border-bottom-width`](border-bottom-width) * [`border-collapse`](border-collapse) * [`border-color`](border-color) * [`border-image`](border-image) * [`border-image-outset`](border-image-outset) * [`border-image-repeat`](border-image-repeat) * [`border-image-slice`](border-image-slice) * [`border-image-source`](border-image-source) * [`border-image-width`](border-image-width) * [`border-left`](border-left) * [`border-left-color`](border-left-color) * [`border-left-style`](border-left-style) * [`border-left-width`](border-left-width) * [`border-radius`](border-radius) * [`border-right`](border-right) * [`border-right-color`](border-right-color) * [`border-right-style`](border-right-style) * [`border-right-width`](border-right-width) * [`border-style`](border-style) * [`border-top`](border-top) * [`border-top-color`](border-top-color) * [`border-top-left-radius`](border-top-left-radius) * [`border-top-right-radius`](border-top-right-radius) * [`border-top-style`](border-top-style) * [`border-top-width`](border-top-width) * [`border-width`](border-width) * [`box-shadow`](box-shadow) Tools ----- [Using multiple backgrounds](css_backgrounds_and_borders/using_multiple_backgrounds) Explains how to set one or more backgrounds on an element. [Resizing background images](css_backgrounds_and_borders/resizing_background_images) Describes how to change the size and repeating behavior of background images. [Applying color to HTML elements using CSS](css_colors/applying_color) An overview of how CSS color can be used in HTML, including for borders. [Border-image generator](css_backgrounds_and_borders/border-image_generator) This interactive tool lets you visually create border images (the [`border-image`](border-image) property). [Border-radius generator](css_backgrounds_and_borders/border-radius_generator) This interactive tool lets you visually create rounded corners (the [`border-radius`](border-radius) property). [Box-shadow generator](css_backgrounds_and_borders/box-shadow_generator) This interactive tool lets you visually create shadows behind elements (the [`box-shadow`](box-shadow) property). Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3](https://drafts.csswg.org/css-backgrounds/) | css flex-grow flex-grow ========= The `flex-grow` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the flex grow factor of a flex item's [main size](https://www.w3.org/TR/css-flexbox/#main-size). Try it ------ Syntax ------ ``` /\* <number> values \*/ flex-grow: 3; flex-grow: 0.6; /\* Global values \*/ flex-grow: inherit; flex-grow: initial; flex-grow: revert; flex-grow: revert-layer; flex-grow: unset; ``` The `flex-grow` property is specified as a single `<number>`. ### Values `<number>` See [`<number>`](number). Negative values are invalid. Defaults to 0. Description ----------- This property specifies how much of the remaining space in the flex container should be assigned to the item (the flex grow factor). The [main size](https://www.w3.org/TR/css-flexbox/#main-size) is either width or height of the item which is dependent on the [`flex-direction`](flex-direction) value. The remaining space is the size of the flex container minus the size of all flex items' sizes together. If all sibling items have the same flex grow factor, then all items will receive the same share of remaining space, otherwise it is distributed according to the ratio defined by the different flex grow factors. `flex-grow` is used alongside the other flex properties [`flex-shrink`](flex-shrink) and [`flex-basis`](flex-basis), and normally defined using the [`flex`](flex) shorthand to ensure all values are set. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | flex items, including in-flow pseudo-elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | a [number](number#interpolation) | Formal syntax ------------- ``` flex-grow = [<number [0,∞]>](number) ``` Examples -------- ### Setting flex item grow factor #### HTML ``` <h4>This is a Flex-Grow</h4> <h5>A,B,C and F are flex-grow:1 . D and E are flex-grow:2 .</h5> <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 class="box" style="background-color:brown;">F</div> </div> ``` #### CSS ``` #content { display: flex; justify-content: space-around; flex-flow: row wrap; align-items: stretch; } .box { flex-grow: 1; border: 3px solid rgba(0, 0, 0, 0.2); } .box1 { flex-grow: 2; border: 3px solid rgba(0, 0, 0, 0.2); } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Flexible Box Layout Module Level 1 # flex-grow-property](https://w3c.github.io/csswg-drafts/css-flexbox/#flex-grow-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `flex-grow` | 29 22 | 12 12 | 20 Since Firefox 28, multi-line flexbox is supported. | 11 10 | 15 12.1 | 9 7 | ≤37 4.4 | 29 25 | 20 Since Firefox 28, multi-line flexbox is supported. | 14 12.1 | 9 7 | 2.0 1.5 | | `less_than_zero_animate` | 49 | 79 | 32 Before Firefox 32, Firefox wasn't able to animate values starting or stopping at `0`. | No | 36 | No | 49 | 49 | 32 Before Firefox 32, Firefox wasn't able to animate values starting or stopping at `0`. | 36 | No | 5.0 | See also -------- * CSS Flexbox Guide: *[Basic Concepts of Flexbox](css_flexible_box_layout/basic_concepts_of_flexbox)* * CSS Flexbox Guide: *[Controlling Ratios of flex items along the main axis](css_flexible_box_layout/controlling_ratios_of_flex_items_along_the_main_ax)* * [`flex-grow` is weird. Or is it?](https://css-tricks.com/flex-grow-is-weird/) article by Manuel Matuzovic on CSS-Tricks, which illustrates how flex-grow works css -webkit-text-fill-color -webkit-text-fill-color ======================= The `-webkit-text-fill-color` CSS property specifies the fill [color](color_value) of characters of text. If this property is not set, the value of the [`color`](color) property is used. Syntax ------ ``` /\* <color> values \*/ -webkit-text-fill-color: red; -webkit-text-fill-color: #000000; -webkit-text-fill-color: rgb(100, 200, 0); /\* Global values \*/ -webkit-text-fill-color: inherit; -webkit-text-fill-color: initial; -webkit-text-fill-color: unset; ``` ### Values `<color>` The foreground fill color of the element's text content. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `currentcolor` | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | computed color | | Animation type | a [color](color_value#interpolation) | Formal syntax ------------- ``` -webkit-text-fill-color = [<color>](color_value) ``` Examples -------- ### Changing the fill color #### CSS ``` p { margin: 0; font-size: 3em; -webkit-text-fill-color: green; } ``` #### HTML ``` <p>This text is green.</p> ``` #### Results Specifications -------------- | Specification | | --- | | [Compatibility Standard # the-webkit-text-fill-color](https://compat.spec.whatwg.org/#the-webkit-text-fill-color) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `-webkit-text-fill-color` | 1 | 12 | 49 | No | 15 | 3 | 37 | 18 | 49 | 15 | 2 | 1.0 | See also -------- * [Surfin' Safari blog post announcing this feature](https://webkit.org/blog/85/introducing-text-stroke/) * [CSS-Tricks article explaining this feature](https://css-tricks.com/adding-stroke-to-web-text/) * [`-webkit-text-stroke-color`](-webkit-text-stroke-color) * [`-webkit-text-stroke-width`](-webkit-text-stroke-width) * [`-webkit-text-stroke`](-webkit-text-stroke) css margin-bottom margin-bottom ============= The `margin-bottom` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the [margin area](css_box_model/introduction_to_the_css_box_model#margin_area) on the bottom of an element. A positive value places it farther from its neighbors, while a negative value places it closer. Try it ------ This property has no effect on *non-[replaced](replaced_element)* inline elements, such as [`<span>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span) or [`<code>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/code). Syntax ------ ``` /\* <length> values \*/ margin-bottom: 10px; /\* An absolute length \*/ margin-bottom: 1em; /\* relative to the text size \*/ margin-bottom: 5%; /\* relative to the nearest block container's width \*/ /\* Keyword values \*/ margin-bottom: auto; /\* Global values \*/ margin-bottom: inherit; margin-bottom: initial; margin-bottom: revert; margin-bottom: revert-layer; margin-bottom: unset; ``` The `margin-bottom` property is specified as the keyword `auto`, or a `<length>`, or a `<percentage>`. Its value can be positive, zero, or negative. ### Values [`<length>`](length) The size of the margin as a fixed value. [`<percentage>`](percentage) The size of the margin as a percentage, relative to the inline size (*width* in a horizontal language, defined by [`writing-mode`](writing-mode)) of the [containing block](containing_block). `auto` The browser selects a suitable value to use. See [`margin`](margin). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | all elements, except elements with table [`display`](display) types other than `table-caption`, `table` and `inline-table`. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | Percentages | refer to the width of the containing block | | [Computed value](computed_value) | the percentage as specified or the absolute length | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` margin-bottom = <length-percentage> [|](value_definition_syntax#single_bar) auto <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Setting positive and negative bottom margins #### HTML ``` <div class="container"> <div class="box0">Box 0</div> <div class="box1">Box 1</div> <div class="box2">Box one's negative margin pulls me up</div> </div> ``` #### CSS CSS for divs to set margin-bottom and height ``` .box0 { margin-bottom: 1em; height: 3em; } .box1 { margin-bottom: -1.5em; height: 4em; } .box2 { border: 1px dashed black; border-width: 1px 0; margin-bottom: 2em; } ``` Some definitions for container and divs so margins' effects can be seen more clearly ``` .container { background-color: orange; width: 320px; border: 1px solid black; } div { width: 320px; background-color: gold; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Box Model Module Level 3 # margin-physical](https://w3c.github.io/csswg-drafts/css-box/#margin-physical) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `margin-bottom` | 1 | 12 | 1 | 3 | 3.5 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `auto` | 1 | 12 The `auto` value is not supported in quirks mode. | 1 | 6 The `auto` value is not supported in quirks mode. | 3.5 | 1 | 37 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [`margin-top`](margin-top), [`margin-right`](margin-right), and [`margin-left`](margin-left) and the [`margin`](margin) shorthand * The mapped logical properties: [`margin-block-start`](margin-block-start), [`margin-block-end`](margin-block-end), [`margin-inline-start`](margin-inline-start), and [`margin-inline-end`](margin-inline-end) and the shorthands [`margin-block`](margin-block) and [`margin-inline`](margin-inline) css text-decoration-skip text-decoration-skip ==================== **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `text-decoration-skip` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets what parts of an element's content any text decoration affecting the element must skip over. It controls all text decoration lines drawn by the element and also any text decoration lines drawn by its ancestors. **Note:** Most other browsers are converging on supporting the simpler [`text-decoration-skip-ink`](text-decoration-skip-ink) property. ``` /\* Keyword values \*/ text-decoration-skip: none; text-decoration-skip: objects; text-decoration-skip: spaces; text-decoration-skip: edges; text-decoration-skip: box-decoration; /\* Multiple keywords \*/ text-decoration-skip: objects spaces; text-decoration-skip: leading-spaces trailing-spaces; text-decoration-skip: objects edges box-decoration; /\* Global values \*/ text-decoration-skip: inherit; text-decoration-skip: initial; text-decoration-skip: revert; text-decoration-skip: revert-layer; text-decoration-skip: unset; ``` Syntax ------ ### Values `none` Nothing is skipped. Thus, text decoration is drawn for all text content and across atomic inline-level boxes. `objects` The entire margin box of the element is skipped if it is an atomic inline such as an image or inline-block. `spaces` All spacing is skipped: all [Unicode white space characters](https://www.unicode.org/reports/tr44/#White_Space) and all word separators, plus any adjacent [`letter-spacing`](letter-spacing) or [`word-spacing`](word-spacing). `leading-spaces` The same as `spaces`, except that only leading spaces are skipped. `trailing-spaces` The same as `spaces`, except that only trailing spaces are skipped. `edges` The start and end of the text decoration is inset slightly (e.g., by half of the line thickness) from the content edge of the decorating box. Thus, adjacent elements receive separate underlines. (This is important in Chinese, where underlining is a form of punctuation.) `box-decoration` The text decoration is skipped over the box's margin, border, and padding areas. This only has an effect on decorations imposed by an ancestor; a *decorating box* never draws over its own box decoration. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `objects` | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` text-decoration-skip = none [|](value_definition_syntax#single_bar) auto ``` Examples -------- ### Skipping edges #### HTML ``` <p>Hey, grab a cup of <em>coffee!</em></p> ``` #### CSS ``` p { margin: 0; font-size: 3em; text-decoration: underline; text-decoration-skip: edges; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Text Decoration Module Level 4 # text-decoration-skipping](https://w3c.github.io/csswg-drafts/css-text-decor-4/#text-decoration-skipping) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `text-decoration-skip` | 57-64 Only supports the deprecated `ink` value. | No | No | No | 44-50 Only supports the deprecated `ink` value. | 12.1 Supports only `none`, `auto`, and `objects` values. 7 Supports only `none`, `auto`, and `objects` values. | 57-64 Only supports the deprecated `ink` value. | 57-64 Only supports the deprecated `ink` value. | No | 43-46 Only supports the deprecated `ink` value. | 12.2 Supports only `none`, `auto`, and `objects` values. 7 Supports only `none`, `auto`, and `objects` values. | 7.0-9.0 Only supports the deprecated `ink` value. | See also -------- * [`text-decoration-skip-ink`](text-decoration-skip-ink)
programming_docs
css overflow-x overflow-x ========== The `overflow-x` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets what shows when content overflows a block-level element's left and right edges. This may be nothing, a scroll bar, or the overflow content. Try it ------ Syntax ------ ``` /\* Keyword values \*/ overflow-x: visible; overflow-x: hidden; overflow-x: clip; overflow-x: scroll; overflow-x: auto; /\* Global values \*/ overflow-x: inherit; overflow-x: initial; overflow-x: revert; overflow-x: revert-layer; overflow-x: unset; ``` The `overflow-x` property is specified as a single keyword chosen from the list of values below. ### Values `visible` Content is not clipped and may be rendered outside the padding box's left and right edges. If [`overflow-y`](overflow-y) is `hidden`, `scroll` or `auto` and this property is `visible`, it will implicitly compute to `auto`. `hidden` Content is clipped if necessary to fit horizontally in the padding box. No scrollbars are provided. `clip` Like for `hidden`, the content is clipped to the element's padding box. The difference between `clip` and `hidden` is that the `clip` keyword also forbids all scrolling, including programmatic scrolling. The box is not a scroll container, and does not start a new formatting context. If you wish to start a new formatting context, you can use [`display: flow-root`](display#flow-root) to do so. `scroll` Content is clipped if necessary to fit horizontally in the padding box. Browsers display scrollbars whether or not any content is actually clipped. (This prevents scrollbars from appearing or disappearing when the content changes.) Printers may still print overflowing content. `auto` Depends on the user agent. If content fits inside the padding box, it looks the same as `visible`, but still establishes a new block-formatting context. Desktop browsers provide scrollbars if content overflows. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `visible` | | Applies to | Block-containers, flex containers, and grid containers | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified, except with `visible`/`clip` computing to `auto`/`hidden` respectively if one of [`overflow-x`](overflow-x) or [`overflow-y`](overflow-y) is neither `visible` nor clip | | Animation type | discrete | Formal syntax ------------- ``` overflow-x = visible [|](value_definition_syntax#single_bar) hidden [|](value_definition_syntax#single_bar) clip [|](value_definition_syntax#single_bar) scroll [|](value_definition_syntax#single_bar) auto ``` Examples -------- ### HTML ``` <ul> <li> <code>overflow-x:hidden</code> — hides the text outside the box <div id="div1">ABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZ</div> </li> <li> <code>overflow-x:scroll</code> — always adds a scrollbar <div id="div2">ABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZ</div> </li> <li> <code>overflow-x:visible</code> — displays the text outside the box if needed <div id="div3">ABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZ</div> </li> <li> <code>overflow-x:auto</code> — on most browsers, equivalent to <code>scroll</code> <div id="div4">ABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZ</div> </li> </ul> ``` ### CSS ``` #div1, #div2, #div3, #div4 { border: 1px solid black; width: 250px; margin-bottom: 12px; } #div1 { overflow-x: hidden; } #div2 { overflow-x: scroll; } #div3 { overflow-x: visible; } #div4 { overflow-x: auto; } ``` ### Result Specifications -------------- | Specification | | --- | | [CSS Overflow Module Level 3 # overflow-properties](https://w3c.github.io/csswg-drafts/css-overflow/#overflow-properties) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `overflow-x` | 1 | 12 | 3.5 | 8 5 | 9.5 | 3 | 4.4 | 18 | 4 | 14 | 1 | 1.0 | | `clip` | 90 | 90 | 81 3.5-81 | No | 76 | 16 | 90 | 90 | 81 4-81 | No | 16 | 15.0 | See also -------- * Related CSS properties: [`text-overflow`](text-overflow), [`white-space`](white-space), [`overflow`](overflow), [`overflow-y`](overflow-y), [`clip`](clip), [`display`](display) css :only-of-type :only-of-type ============= The `:only-of-type` CSS [pseudo-class](pseudo-classes) represents an element that has no siblings of the same type. Try it ------ **Note:** As originally defined, the selected element had to have a parent. Beginning with Selectors Level 4, this is no longer required. Syntax ------ ``` :only-of-type ``` Examples -------- ### Styling elements with no siblings of the same type #### HTML ``` <main> <div>I am `div` #1.</div> <p>I am the only `p` among my siblings.</p> <div>I am `div` #2.</div> <div> I am `div` #3. <i>I am the only `i` child.</i> <em>I am `em` #1.</em> <em>I am `em` #2.</em> </div> </main> ``` #### CSS ``` main :only-of-type { color: red; } ``` #### Result Specifications -------------- | Specification | | --- | | [Selectors Level 4 # only-of-type-pseudo](https://w3c.github.io/csswg-drafts/selectors/#only-of-type-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:only-of-type` | 1 | 12 Before Edge 16, Microsoft Edge treats all unknown elements (such as custom elements) as the same element type. | 3.5 | 9 Internet Explorer treats all unknown elements (such as custom elements) as the same element type. | 9.5 | 3.1 | 2 | 18 | 4 | 10.1 | 2 | 1.0 | See also -------- * [`:only-child`](:only-child) * [`:first-of-type`](:first-of-type) * [`:last-of-type`](:last-of-type) * [`:nth-of-type`](:nth-of-type) css background-position-x background-position-x ===================== The `background-position-x` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the initial horizontal position for each background image. The position is relative to the position layer set by [`background-origin`](background-origin). Try it ------ The value of this property is overridden by any declaration of the [`background`](background) or [`background-position`](background-position) shorthand properties applied to the element after it. Syntax ------ ``` /\* Keyword values \*/ background-position-x: left; background-position-x: center; background-position-x: right; /\* <percentage> values \*/ background-position-x: 25%; /\* <length> values \*/ background-position-x: 0px; background-position-x: 1cm; background-position-x: 8em; /\* Side-relative values \*/ background-position-x: right 3px; background-position-x: left 25%; /\* Multiple values \*/ background-position-x: 0px, center; /\* Global values \*/ background-position-x: inherit; background-position-x: initial; background-position-x: revert; background-position-x: revert-layer; background-position-x: unset; ``` The `background-position-x` property is specified as one or more values, separated by commas. ### Values `left` Aligns the left edge of the background image with the left edge of the background position layer. `center` Aligns the center of the background image with the center of the background position layer. `right` Aligns the right edge of the background image with the right edge of the background position layer. [`<length>`](length) The offset of the given background image's left vertical edge from the background position layer's left vertical edge. (Some browsers allow assigning the right edge for offset). [`<percentage>`](percentage) The offset of the given background image's horizontal position relative to the container. A value of 0% means that the left edge of the background image is aligned with the left edge of the container, and a value of 100% means that the *right* edge of the background image is aligned with the *right* edge of the container, thus a value of 50% horizontally centers the background image. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0%` | | Applies to | all elements | | [Inherited](inheritance) | no | | Percentages | refer to width of background positioning area minus height of background image | | [Computed value](computed_value) | A list, each item consisting of: an offset given as a combination of an absolute length and a percentage, plus an origin keyword | | Animation type | discrete | Formal syntax ------------- ``` background-position-x = [[](value_definition_syntax#brackets) center [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) x-start [|](value_definition_syntax#single_bar) x-end []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) <length-percentage>[?](value_definition_syntax#question_mark) ]! []](value_definition_syntax#brackets)[#](value_definition_syntax#hash_mark) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Basic example The following example shows a simple background image implementation, with background-position-x and background-position-y used to define the image's horizontal and vertical positions separately. #### HTML ``` <div></div> ``` #### CSS ``` div { width: 300px; height: 300px; background-color: skyblue; background-image: url(https://media.prod.mdn.mozit.cloud/attachments/2020/07/29/17350/3b4892b7e820122ac6dd7678891d4507/firefox.png); background-repeat: no-repeat; background-position-x: center; background-position-y: bottom 10px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 4 # background-position-longhands](https://w3c.github.io/csswg-drafts/css-backgrounds-4/#background-position-longhands) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `background-position-x` | 1 | 12 | 49 | 6 | 15 | 1 | ≤37 | 18 | 49 | 18 | 1 | 1.0 | | `two_value_syntax` | No | 12-79 | 49 | 9 | No | 15.4 | No | No | 49 | No | 15.4 | No | See also -------- * [`background-position`](background-position) * [`background-position-y`](background-position-y) * `background-position-inline` * `background-position-block` * [Using multiple backgrounds](css_backgrounds_and_borders/using_multiple_backgrounds) css <calc-constant> <calc-constant> =============== The `<calc-constant>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) represents well-defined constants such as `e` and `π`. Rather than require authors to manually type out several digits of these mathematical constants or calculate them, a few of them are provided directly by CSS for convenience. Syntax ------ The `<calc-constant>` type defines numeric constants that can be used in [CSS math functions](css_functions#math_functions). ### Values `e` The base of the natural logarithm, approximately equal to `2.7182818284590452354`. `pi` The ratio of a circle's circumference to its diameter, approximately equal to `3.1415926535897932`. `infinity` & `-infinity` Experimental An infinite value, used to indicate the largest/smallest possible value. `NaN` Experimental A value representing "Not a Number" canonical casing. ### Formal syntax ``` <calc-constant> = e [|](value_definition_syntax#single_bar) pi [|](value_definition_syntax#single_bar) infinity [|](value_definition_syntax#single_bar) -infinity [|](value_definition_syntax#single_bar) NaN ``` Description ----------- Mathematical constants can only be used inside [CSS math functions](css_functions#math_functions) for calculations. Math constants are not CSS keywords, but if they are used outside of a calculation, they're treated like any other keyword. For example: * `animation-name: pi;` refers to an animation named "pi", not the `pi` numeric constant. * `line-height: e;` is invalid, but `line-height: calc(e);` is valid. * `rotate(1rad * pi);` won't work because [`rotate()`](transform-function/rotate) is not a math function. Use `rotate(calc(1rad * pi));` In math functions, `<calc-constant>` values are evaluated as [`<number>`](number) values, therefore `e` and `pi` act as numeric constants. Both `infinity` and `NaN` are slightly different, they are considered as degenerate numeric constants. While not technically numbers, they act as [`<number>`](number) values. Thus to get an infinite [`<length>`](length), for example, requires an expression like `calc(infinity * 1px)`. The `infinity` and `NaN` values are included mostly to make serialization simpler and more obvious, but can be used to indicate a "largest possible value", since an infinite value gets clamped to the allowed range. It's rare for this to be reasonable, but when using infinity its much simpler than just putting an enormous number in a stylesheet. CSS constants are case-insensitive. Thus, `calc(Pi)`, `calc(E)` and `calc(InFiNiTy)` are all valid. There is only one exception: `NaN` is case-sensitive and must be written exactly as `NaN`. Both `nan` and `NAN` are invalid constants. Valid values: ``` e -e E pi -pi Pi infinity -infinity InFiNiTy NaN ``` Invalid values: ``` nan Nan NAN ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # calc-constants](https://w3c.github.io/csswg-drafts/css-values/#calc-constants) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `NaN` | No | No | 108 | No | No | No | No | No | 108 | No | No | No | | `calc-constant` | No | No | 108 | No | No | 15.4 | No | No | 108 | No | 15.4 | No | | `e` | No | No | 108 | No | No | 15.4 | No | No | 108 | No | 15.4 | No | | `infinity` | No | No | 108 | No | No | No | No | No | 108 | No | No | No | | `pi` | No | No | 108 | No | No | 15.4 | No | No | 108 | No | 15.4 | No | See also -------- * [`<calc-sum>`](calc-sum) * `<calc-product>` * `<calc-value>` css border-inline-end-style border-inline-end-style ======================= The `border-inline-end-style` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the style of the logical inline end border of an element, which maps to a physical border style depending on the element's writing mode, directionality, and text orientation. It corresponds to the [`border-top-style`](border-top-style), [`border-right-style`](border-right-style), [`border-bottom-style`](border-bottom-style), or [`border-left-style`](border-left-style) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ Syntax ------ ``` /\* <'border-style'> values \*/ border-inline-end-style: dashed; border-inline-end-style: dotted; border-inline-end-style: groove; /\* Global values \*/ border-inline-end-style: inherit; border-inline-end-style: initial; border-inline-end-style: revert; border-inline-end-style: revert-layer; border-inline-end-style: unset; ``` Related properties are [`border-block-start-style`](border-block-start-style), [`border-block-end-style`](border-block-end-style), and [`border-inline-start-style`](border-inline-start-style), which define the other border styles of the element. ### Values `<'border-style'>` The line style of the border. See [`border-style`](border-style). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` border-inline-end-style = <'border-top-style'> ``` Examples -------- ### Setting inline-end-style #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; border: 5px solid blue; border-inline-end-style: dashed; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # border-style](https://w3c.github.io/csswg-drafts/css-logical/#border-style) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-inline-end-style` | 69 | 79 | 41 3 | No | 56 | 12.1 | 69 | 69 | 41 4 | 48 | 12.2 | 10.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * This property maps to one of the physical border properties: [`border-top-style`](border-top-style), [`border-right-style`](border-right-style), [`border-bottom-style`](border-bottom-style), or [`border-left-style`](border-left-style). * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css Using CSS custom properties (variables) Using CSS custom properties (variables) ======================================= **Custom properties** (sometimes referred to as **CSS variables** or **cascading variables**) are entities defined by CSS authors that contain specific values to be reused throughout a document. They are set using custom property notation (e.g., `--main-color: black;`) and are accessed using the [`var()`](var()) function (e.g., `color: var(--main-color);`). Complex websites have very large amounts of CSS, often with a lot of repeated values. For example, the same color might be used in hundreds of different places, requiring global search and replace if that color needs to change. Custom properties allow a value to be stored in one place, then referenced in multiple other places. An additional benefit is semantic identifiers. For example, `--main-text-color` is easier to understand than `#00ff00`, especially if this same color is also used in other contexts. Custom properties are subject to the cascade and inherit their value from their parent. Basic usage ----------- Declaring a custom property is done using a custom property name that begins with a double hyphen (`--`), and a property value that can be any valid CSS value. Like any other property, this is written inside a ruleset, like so: ``` element { --main-bg-color: brown; } ``` Note that the selector given to the ruleset defines the scope that the custom property can be used in. A common best practice is to define custom properties on the [`:root`](:root) pseudo-class, so that it can be applied globally across your HTML document: ``` :root { --main-bg-color: brown; } ``` However, this doesn't always have to be the case: you maybe have a good reason for limiting the scope of your custom properties. **Note:** Custom property names are case sensitive — `--my-color` will be treated as a separate custom property to `--My-color`. As mentioned earlier, you use the custom property value by specifying your custom property name inside the [`var()`](var()) function, in place of a regular property value: ``` element { background-color: var(--main-bg-color); } ``` First steps with custom properties ---------------------------------- Let's start with this CSS that applies the same color to elements of different classes: ``` .one { color: white; background-color: brown; margin: 10px; width: 50px; height: 50px; display: inline-block; } .two { color: white; background-color: black; margin: 10px; width: 150px; height: 70px; display: inline-block; } .three { color: white; background-color: brown; margin: 10px; width: 75px; } .four { color: white; background-color: brown; margin: 10px; width: 100px; } .five { background-color: brown; } ``` We'll apply it to this HTML: ``` <div> <div class="one">1:</div> <div class="two">2: Text <span class="five">5 - more text</span></div> <input class="three" /> <textarea class="four">4: Lorem Ipsum</textarea> </div> ``` This produces the following result: Using the :root pseudo-class ---------------------------- Notice the repetitive CSS in the example above. The background color is set to `brown` in several places. For some CSS declarations, it is possible to declare this higher in the cascade and let CSS inheritance solve this problem naturally. For non-trivial projects, this is not always possible. By declaring a custom property on the [`:root`](:root) pseudo-class and using it where needed throughout the document, a CSS author can reduce the need for repetition: ``` :root { --main-bg-color: brown; } .one { color: white; background-color: var(--main-bg-color); margin: 10px; width: 50px; height: 50px; display: inline-block; } .two { color: white; background-color: black; margin: 10px; width: 150px; height: 70px; display: inline-block; } .three { color: white; background-color: var(--main-bg-color); margin: 10px; width: 75px; } .four { color: white; background-color: var(--main-bg-color); margin: 10px; width: 100px; } .five { background-color: var(--main-bg-color); } ``` This leads to the same result as the previous example, yet allows for one canonical declaration of the desired property value; very useful if you want to change the value across the entire page later. Inheritance of custom properties -------------------------------- Custom properties do inherit. This means that if no value is set for a custom property on a given element, the value of its parent is used. Take this HTML: ``` <div class="one"> <div class="two"> <div class="three"></div> <div class="four"></div> </div> </div> ``` … with the following CSS: ``` .two { --test: 10px; } .three { --test: 2em; } ``` In this case, the results of `var(--test)` are: * For the `class="two"` element: `10px` * For the `class="three"` element: `2em` * For the `class="four"` element: `10px` (inherited from its parent) * For the `class="one"` element: *invalid value*, which is the default value of any custom property Keep in mind that these are custom properties, not actual variables like you might find in other programming languages. The value is computed where it is needed, not stored for use in other rules. For instance, you cannot set a property for an element and expect to retrieve it in a sibling's descendant's rule. The property is only set for the matching selector and its descendants, like any normal CSS. Custom property fallback values ------------------------------- Using the [`var()`](var()) function, you can define multiple **fallback values** when the given variable is not yet defined; this can be useful when working with [Custom Elements](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements) and [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM). **Note:** Fallback values aren't used to fix the browser compatibility. If the browser doesn't support CSS custom properties, the fallback value won't help. It's just a backup for the browser which supports CSS custom properties to choose a different value if the given variable isn't defined or has an invalid value. The first argument to the function is the name of the [custom property](https://www.w3.org/TR/css-variables/#custom-property) to be substituted. The second argument to the function, if provided, is a fallback value, which is used as the substitution value when the referenced [custom property](https://www.w3.org/TR/css-variables/#custom-property) is invalid. The function only accepts two parameters, assigning everything following the first comma as the second parameter. If that second parameter is invalid, the fallback will fail. For example: ``` .two { /\* Red if --my-var is not defined \*/ color: var(--my-var, red); } .three { /\* pink if --my-var and --my-background are not defined \*/ background-color: var(--my-var, var(--my-background, pink)); } .three { /\* Invalid: "--my-background, pink" \*/ background-color: var(--my-var, --my-background, pink); } ``` Including a custom property as a fallback, as seen in the second example above, is the correct way to provide more than one fallback. The technique has been seen to cause performance issues as it takes more time to parse through the variables. **Note:** The syntax of the fallback, like that of [custom properties](https://www.w3.org/TR/css-variables/#custom-property), allows commas. For example, `var(--foo, red, blue)` defines a fallback of `red, blue` — anything between the first comma and the end of the function is considered a fallback value. Handling invalid custom properties ---------------------------------- Each CSS property can be assigned a defined set of values. If you try to assign a value to a property that is outside its set of valid values, it's considered *invalid*. When the browser encounters an invalid value for a normal property, it discards the value, and elements are assigned the values that they would have had if the declaration simply did not exist. However, when the values of custom properties are parsed, the browser doesn't yet know where they will be used, so it must consider nearly all values as *valid*. Unfortunately, these valid values can be used, via the `var()` functional notation, in a context where they might not make sense. Properties and custom variables can lead to invalid CSS statements, leading to the new concept of *valid at computed time.* When the browser encounters an invalid `var()` substitution, then the [initial](initial_value) or [inherited](inheritance) value of the property is used. The next two examples illustrate this. ### Invalid normal properties In this example we attempt to apply a value of `16px` to the [`color`](color) property. Because this is invalid, the CSS is discarded and the result is as if the rule did not exist, so the previous `color: blue` rule is applied instead, and the paragraph is blue. #### HTML ``` <p>This paragraph is initially black.</p> ``` #### CSS ``` p { color: blue; } p { color: 16px; } ``` #### Result ### Invalid custom properties This example is just like the last one, except we use a custom property. As expected, the browser substitutes the value of `--text-color` in place of `var(--text-color)`, but `16px` is not a valid property value for [`color`](color). After substitution, the property doesn't make sense. The browser handles this situation in two steps: 1. Check if the property [`color`](color) is inheritable. It is, but this `<p>` doesn't have any parent with the `color` property set. So we move on to the next step. 2. Set the value to its **default initial value**, which is black. #### HTML ``` <p>This paragraph is initially black.</p> ``` #### CSS ``` :root { --text-color: 16px; } p { color: blue; } p { color: var(--text-color); } ``` #### Result Values in JavaScript -------------------- To use the values of custom properties in JavaScript, it is just like standard properties. ``` // get variable from inline style element.style.getPropertyValue("--my-var"); // get variable from wherever getComputedStyle(element).getPropertyValue("--my-var"); // set variable on inline style element.style.setProperty("--my-var", jsVar + 4); ``` See also -------- * [Custom property syntax](--*) * [`var()`](var())
programming_docs
css align-items align-items =========== The [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) `align-items` property sets the [`align-self`](align-self) value on all direct children as a group. In Flexbox, it controls the alignment of items on the [Cross Axis](https://developer.mozilla.org/en-US/docs/Glossary/Cross_Axis). In Grid Layout, it controls the alignment of items on the Block Axis within their [grid area](https://developer.mozilla.org/en-US/docs/Glossary/Grid_Areas). The interactive example below demonstrates some of the values for `align-items` using grid layout. Try it ------ Syntax ------ ``` /\* Basic keywords \*/ align-items: normal; align-items: stretch; /\* Positional alignment \*/ /\* align-items does not take left and right values \*/ align-items: center; /\* Pack items around the center \*/ align-items: start; /\* Pack items from the start \*/ align-items: end; /\* Pack items from the end \*/ align-items: flex-start; /\* Pack flex items from the start \*/ align-items: flex-end; /\* Pack flex items from the end \*/ /\* Baseline alignment \*/ align-items: baseline; align-items: first baseline; align-items: last baseline; /\* Overflow alignment (for positional alignment only) \*/ align-items: safe center; align-items: unsafe center; /\* Global values \*/ align-items: inherit; align-items: initial; align-items: revert; align-items: revert-layer; align-items: unset; ``` ### Values `normal` The effect of this keyword is dependent of the layout mode we are in: * In absolutely-positioned layouts, the keyword behaves like `start` on *replaced* absolutely-positioned boxes, and as `stretch` on *all other* absolutely-positioned boxes. * In static position of absolutely-positioned layouts, the keyword behaves as `stretch`. * For flex items, the keyword behaves as `stretch`. * For grid items, 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`. * The property doesn't apply to block-level boxes, and to table cells. `flex-start` The cross-start margin edges of the flex items are flushed with the cross-start edge of the line. `flex-end` The cross-end margin edges of the flex items are flushed with the cross-end edge of the line. `center` The flex items' margin boxes are centered within the line on the cross-axis. If the cross-size of an item is larger than the flex container, it will overflow equally in both directions. `start` The items are packed flush to each other toward the start edge of the alignment container in the appropriate axis. `end` The items are packed flush to each other toward the end edge of the alignment container in the appropriate axis. `self-start` The items are packed flush to the edge of the alignment container of the start side of the item, in the appropriate axis. `self-end` The items are packed flush to the edge of the alignment container of the end side of the item, in the appropriate axis. `baseline`, `first baseline`, `last baseline` All flex items are aligned such that their [flex container baselines](https://drafts.csswg.org/css-flexbox-1/#flex-baselines) align. The item with the largest distance between its cross-start margin edge and its baseline is flushed with the cross-start edge of the line. `stretch` Flex items are stretched such that the cross-size of the item's margin box is the same as the line while respecting width and height constraints. `safe` Used alongside an alignment keyword. If the chosen keyword means that the item overflows the alignment container causing data loss, the item is instead aligned as if the alignment mode were `start`. `unsafe` Used alongside an alignment keyword. Regardless of the relative sizes of the item and alignment container and whether overflow which causes data loss might happen, the given alignment value is honored. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` align-items = normal [|](value_definition_syntax#single_bar) stretch [|](value_definition_syntax#single_bar) <baseline-position> [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) <overflow-position>[?](value_definition_syntax#question_mark) <self-position> []](value_definition_syntax#brackets) <baseline-position> = [[](value_definition_syntax#brackets) first [|](value_definition_syntax#single_bar) last []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) [&&](value_definition_syntax#double_ampersand) baseline <overflow-position> = unsafe [|](value_definition_syntax#single_bar) safe <self-position> = center [|](value_definition_syntax#single_bar) start [|](value_definition_syntax#single_bar) end [|](value_definition_syntax#single_bar) self-start [|](value_definition_syntax#single_bar) self-end [|](value_definition_syntax#single_bar) flex-start [|](value_definition_syntax#single_bar) flex-end ``` Examples -------- ### CSS ``` #container { height: 200px; width: 240px; align-items: center; /\* Can be changed in the live sample \*/ background-color: #8c8c8c; } .flex { display: flex; flex-wrap: wrap; } .grid { display: grid; grid-template-columns: repeat(auto-fill, 50px); } div > div { box-sizing: border-box; border: 2px solid #8c8c8c; width: 50px; display: flex; align-items: center; justify-content: center; } #item1 { background-color: #8cffa0; min-height: 30px; } #item2 { background-color: #a0c8ff; min-height: 50px; } #item3 { background-color: #ffa08c; min-height: 40px; } #item4 { background-color: #ffff8c; min-height: 60px; } #item5 { background-color: #ff8cff; min-height: 70px; } #item6 { background-color: #8cffff; min-height: 50px; font-size: 30px; } select { font-size: 16px; } .row { margin-top: 10px; } ``` ### HTML ``` <div id="container" class="flex"> <div id="item1">1</div> <div id="item2">2</div> <div id="item3">3</div> <div id="item4">4</div> <div id="item5">5</div> <div id="item6">6</div> </div> <div class="row"> <label for="display">display: </label> <select id="display"> <option value="flex">flex</option> <option value="grid">grid</option> </select> </div> <div class="row"> <label for="values">align-items: </label> <select id="values"> <option value="normal">normal</option> <option value="flex-start">flex-start</option> <option value="flex-end">flex-end</option> <option value="center" selected>center</option> <option value="baseline">baseline</option> <option value="stretch">stretch</option> <option value="start">start</option> <option value="end">end</option> <option value="self-start">self-start</option> <option value="self-end">self-end</option> <option value="first baseline">first baseline</option> <option value="last baseline">last baseline</option> <option value="safe center">safe center</option> <option value="unsafe center">unsafe center</option> <option value="safe right">safe right</option> <option value="unsafe right">unsafe right</option> <option value="safe end">safe end</option> <option value="unsafe end">unsafe end</option> <option value="safe self-end">safe self-end</option> <option value="unsafe self-end">unsafe self-end</option> <option value="safe flex-end">safe flex-end</option> <option value="unsafe flex-end">unsafe flex-end</option> </select> </div> ``` ### Result Specifications -------------- | Specification | | --- | | [CSS Box Alignment Module Level 3 # align-items-property](https://w3c.github.io/csswg-drafts/css-align/#align-items-property) | | [CSS Flexible Box Layout Module Level 1 # align-items-property](https://w3c.github.io/csswg-drafts/css-flexbox/#align-items-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `align-items` | 29 21 | 12 12 | 49 20 | 11 | 16 15 | 9 7 | 4.4 4.4 | 29 25 | 49 20 | 16 14 | 9 7 | 2.0 1.5 | | `flex_context` | 52 21-52 Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Chrome implements the new behavior beginning with Chrome 52. | 12 | 20 Multi-line flexbox has been supported since Firefox 28. | 11 In Internet Explorer 10 and 11, if column flex items have `align-items: center;` set on them and their content is too large, then they will overflow the bounds of their container. See [Flexbug #2](https://github.com/philipwalton/flexbugs#2-column-flex-items-set-to-align-itemscenter-overflow-their-container). | 39 15-39 Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Opera implements the new behavior beginning with Opera 39. | 7 | 52 4.4-52 Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Chrome implements the new behavior beginning with Chrome 52. | 52 25-52 Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Chrome implements the new behavior beginning with Chrome 52. | 20 Multi-line flexbox has been supported since Firefox 28. | 41 14-41 Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Opera implements the new behavior beginning with Opera 41. | 7 | 6.0 1.5-6.0 Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Samsung Internet implements the new behavior beginning with Samsung Internet 6.0. | | `grid_context` | 57 | 16 | 52 | No | 44 | 10.1 | 57 | 52 | 52 | 43 | 10.3 | 6.2 | See also -------- * CSS Flexbox Guide: *[Basic Concepts of Flexbox](css_flexible_box_layout/basic_concepts_of_flexbox)* * CSS Flexbox Guide: *[Aligning items in a flex container](css_flexible_box_layout/aligning_items_in_a_flex_container)* * CSS Grid Guide: *[Box alignment in CSS Grid layouts](css_grid_layout/box_alignment_in_css_grid_layout)* * [CSS Box Alignment](css_box_alignment) * The [`align-self`](align-self) property css flex-basis flex-basis ========== The `flex-basis` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the initial main size of a flex item. It sets the size of the content box unless otherwise set with [`box-sizing`](box-sizing). Try it ------ In this example, the [`flex-grow`](flex-grow) and [`flex-shrink`](flex-shrink) properties are both set to `1` on all three items, indicating that the flex item can grow and shrink from the initial `flex-basis`. The demo then changes the `flex-basis` on the first item. It will then grow and shrink from that flex-basis. This means that, for example, when the `flex-basis` of the first item is `200px`, it will start out at 200px but then shrink to fit the space available with the other items being at least `min-content` sized. The image below shows how the Firefox [Flexbox Inspector](https://firefox-source-docs.mozilla.org/devtools-user/page_inspector/how_to/examine_flexbox_layouts/index.html) helps you understand the size items become: **Note:** In case both `flex-basis` (other than `auto`) and `width` (or `height` in case of `flex-direction: column`) are set for an element, `flex-basis` has priority. Syntax ------ ``` /\* Specify <'width'> \*/ flex-basis: 10em; flex-basis: 3px; flex-basis: 50%; flex-basis: auto; /\* Intrinsic sizing keywords \*/ flex-basis: max-content; flex-basis: min-content; flex-basis: fit-content; /\* Automatically size based on the flex item's content \*/ flex-basis: content; /\* Global values \*/ flex-basis: inherit; flex-basis: initial; flex-basis: revert; flex-basis: revert-layer; flex-basis: unset; ``` The `flex-basis` property is specified as either the keyword `content` or a `<'width'>`. ### Values `<'width'>` An absolute [`<length>`](length), a [`<percentage>`](percentage) of the parent flex container's main size property, or the keyword `auto`. Negative values are invalid. Defaults to `auto`. `content` Indicates automatic sizing, based on the flex item's content. **Note:** This value was not present in the initial release of Flexible Box Layout, and thus some older implementations will not support it. The equivalent effect can be had by using `auto` together with a main size ([width](https://drafts.csswg.org/css2/#the-width-property) or [height](https://drafts.csswg.org/css2/#the-height-property)) of `auto`. * Originally, `flex-basis:auto` meant "look at my `width` or `height` property". * Then, `flex-basis:auto` was changed to mean automatic sizing, and "main-size" was introduced as the "look at my `width` or `height` property" keyword. It was implemented in [bug 1032922](https://bugzilla.mozilla.org/show_bug.cgi?id=1032922). * Then, that change was reverted in [bug 1093316](https://bugzilla.mozilla.org/show_bug.cgi?id=1093316), so `auto` once again means "look at my `width` or `height` property"; and a new `content` keyword is being introduced to trigger automatic sizing. ([bug 1105111](https://bugzilla.mozilla.org/show_bug.cgi?id=1105111) covers adding that keyword). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | flex items, including in-flow pseudo-elements | | [Inherited](inheritance) | no | | Percentages | refer to the flex container's inner main size | | [Computed value](computed_value) | as specified, but with relative lengths converted into absolute lengths | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` flex-basis = content [|](value_definition_syntax#single_bar) <'width'> ``` Examples -------- ### Setting flex item initial sizes #### HTML ``` <ul class="container"> <li class="flex flex1">1: flex-basis test</li> <li class="flex flex2">2: flex-basis test</li> <li class="flex flex3">3: flex-basis test</li> <li class="flex flex4">4: flex-basis test</li> <li class="flex flex5">5: flex-basis test</li> </ul> <ul class="container"> <li class="flex flex6">6: flex-basis test</li> </ul> ``` #### CSS ``` .container { font-family: arial, sans-serif; margin: 0; padding: 0; list-style-type: none; display: flex; flex-wrap: wrap; } .flex { background: #6ab6d8; padding: 10px; margin-bottom: 50px; border: 3px solid #2e86bb; color: white; font-size: 14px; text-align: center; position: relative; } .flex::after { position: absolute; z-index: 1; left: 0; top: 100%; margin-top: 10px; width: 100%; color: #333; font-size: 12px; } .flex1 { flex-basis: auto; } .flex1::after { content: "auto"; } .flex2 { flex-basis: max-content; } .flex2::after { content: "max-content"; } .flex3 { flex-basis: min-content; } .flex3::after { content: "min-content"; } .flex4 { flex-basis: fit-content; } .flex4::after { content: "fit-content"; } .flex5 { flex-basis: content; } .flex5::after { content: "content"; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Flexible Box Layout Module Level 1 # flex-basis-property](https://w3c.github.io/csswg-drafts/css-flexbox/#flex-basis-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `flex-basis` | 29 22 | 12 12 | 49 22 Since Firefox 28, multi-line flexbox is supported. | 11 When a non-`auto` `flex-basis` is specified, Internet Explorer 10 and 11 always uses a `content-box` box model to calculate the size of a flex item, even if [`box-sizing: border-box`](https://developer.mozilla.org/docs/Web/CSS/box-sizing) is applied to the element. See [Flexbug #7](https://github.com/philipwalton/flexbugs#7-flex-basis-doesnt-account-for-box-sizingborder-box) for more info. | 15 12.1 | 9 7 | ≤37 4.4 | 29 25 | 49 22 Since Firefox 28, multi-line flexbox is supported. | 14 12.1 | 9 7 | 2.0 1.5 | | `auto` | 22 | 12 | 22 | 11 | 12.1 | 9 7 | 4.4 | 25 | 22 | 12.1 | 9 7 | 1.5 | | `content` | 94 | 94 12-79 | 61 | No | 80 | preview | 94 | 94 | 61 | No | No | 17.0 | | `fit-content` | 94 | 94 | 94 22 | No | 80 | 16 | 94 | 94 | 94 22 | No | 16 | 17.0 | | `max-content` | 94 | 94 | 66 22 | No | 80 | 16 | 94 | 94 | 66 22 | No | 16 | 17.0 | | `min-content` | 94 | 94 | 66 22 | No | 80 | 16 | 94 | 94 | 66 22 | No | 16 | 17.0 | See also -------- * CSS Flexbox Guide: *[Basic Concepts of Flexbox](css_flexible_box_layout/basic_concepts_of_flexbox)* * CSS Flexbox Guide: *[Controlling Ratios of flex items along the main axis](css_flexible_box_layout/controlling_ratios_of_flex_items_along_the_main_ax)* * [`width`](width) css scroll-timeline-axis scroll-timeline-axis ==================== **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `scroll-timeline-axis` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property can be used to specify the scrollbar that will be used to provide the timeline for a scroll-timeline animation. A scroll-timeline animation is one in which the animation progress is determined by a scrollbar position rather than time, or some other dimension. The [`scroll-timeline-name`](scroll-timeline-axis) property defines a name that can be used to identify an element as the source of a scroll-timeline; the `scroll-timeline-axis` is used to indicate whether the horizontal or vertical scrollbar in that element provides the timeline. Note that if the element does not display a scrollbar in the axis dimension, then no timeline will be created. The `scroll-timeline-axis` (and `scroll-timeline-name`) property can also be set using the [`scroll-timeline`](scroll-timeline-name) shorthand property. Syntax ------ ``` scroll-timeline-axis: block; scroll-timeline-axis: inline; scroll-timeline-axis: vertical; scroll-timeline-axis: horizontal; ``` ### Values Allowed values for the scrollbar axis are: `block` (Default) Scrollbar in the block axis of the scroll container. The block axis is the direction perpendicular to the flow of text within a line. For horizontal writing modes, such as standard English, this is the same as `vertical`, while for vertical writing modes it is the same as `horizontal`. `inline` Scrollbar in the inline axis of the scroll container. The inline axis is the direction parallel to the flow of text in a line. For horizontal writing modes this is the same as the `horizontal` axis, while for vertical writing modes this is the same as `vertical`. `vertical` Scrollbar in the vertical axis of the scroll container. `horizontal` Scrollbar in the horizontal axis of the scroll container. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `block` | | Applies to | scroll containers | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | Not animatable | Formal syntax ------------- ``` scroll-timeline-axis = block [|](value_definition_syntax#single_bar) inline [|](value_definition_syntax#single_bar) vertical [|](value_definition_syntax#single_bar) horizontal ``` Examples -------- In this example, a scroll timeline named `squareTimeline` is defined using the `scroll-timeline-name` property on the element with the id `container`, and then this name is applied to the animation on the `#square` element using `animation-timeline: squareTimeline`. To demonstrate the effect of `scroll-timeline-axis`, the horizontal (non-default) scrollbar is used in this example to control the rotation of the square. ### HTML The HTML for the example is shown below. ``` <div id="container"> <div id="square"></div> <div id="stretcher"></div> </div> ``` ### CSS The CSS for the container sets it as the source of a scroll timeline named `squareTimeline` using the `scroll-timeline-name` property. We then set `scroll-timeline-axis: horizontal;` so that the *horizontal scrollbar* position will determine the animation timeline. The height and width of the container are set to 200px and we also set the container to create scrollbars if it overflows (below we will use CSS on the "stretcher" element to ensure that it does overflow). ``` #container { height: 200px; width: 200px; overflow: scroll; scroll-timeline-name: squareTimeline; scroll-timeline-axis: horizontal; } ``` The CSS below defines a square that rotates in alternate directions according to the timeline provided by the `animation-timeline` property, which is set to the `squareTimeline` timeline named above. The position is set as absolute, so the element rotates in place. ``` #square { background-color: deeppink; width: 100px; height: 100px; margin-top: 100px; animation-name: rotateAnimation; animation-duration: 3s; animation-direction: alternate; animation-timeline: squareTimeline; position: absolute; bottom: 50px; } @keyframes rotateAnimation { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } ``` The "stretcher" CSS simply sets the block height and width large enough to force the container element to overflow and create scroll bars. Without this element there would be no scrollbar, and hence no scroll timeline to associate with the animation timeline. ``` #stretcher { height: 300px; width: 1200px } ``` ### Result Scroll the horizontal bar at the bottom to see the animation. Specifications -------------- | Specification | | --- | | [Scroll-linked Animations # propdef-scroll-timeline-axis](https://w3c.github.io/csswg-drafts/scroll-animations/#propdef-scroll-timeline-axis) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scroll-timeline-axis` | No | No | 103 | No | No | No | No | No | No | No | No | No | See also -------- * [`scroll-timeline-name`](scroll-timeline-axis) * [`scroll-timeline`](scroll-timeline) * [`animation-timeline`](animation-timeline)
programming_docs
css @font-feature-values @font-feature-values ==================== The `@font-feature-values` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) <at-rule> lets you use a common name in the [`font-variant-alternates`](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](at-rule#conditional_group_rules). Syntax ------ ### Feature value blocks `@swash` Specifies a feature name that will work with the [`swash()`](font-variant-alternates#swash()) functional notation of [`font-variant-alternates`](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 [`annotation()`](font-variant-alternates#annotation()) functional notation of [`font-variant-alternates`](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 [`ornaments()`](font-variant-alternates#ornaments()) functional notation of [`font-variant-alternates`](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 [`stylistic()`](font-variant-alternates#stylistic()) functional notation of [`font-variant-alternates`](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 [`styleset()`](font-variant-alternates#styleset()) functional notation of [`font-variant-alternates`](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 [`character-variant()`](font-variant-alternates#character-variant()) functional notation of [`font-variant-alternates`](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 ------------- ``` @font-feature-values = @font-feature-values [<family-name>](family-name)[#](value_definition_syntax#hash_mark) { [<declaration-list>](declaration-list) } ``` Examples -------- ### Using @styleset in a @font-feature-values rule ``` /\* 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 -------------- | Specification | | --- | | [CSS Fonts Module Level 4 # font-feature-values](https://w3c.github.io/csswg-drafts/css-fonts/#font-feature-values) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `@font-feature-values` | No | No | 34 | No | No | 9.1 | No | No | 34 | No | 9.3 | No | | `annotation` | No | No | 34 | No | No | 9.1 | No | No | 34 | No | 9.3 | No | | `character-variant` | No | No | 34 | No | No | 9.1 | No | No | 34 | No | 9.3 | No | | `historical-forms` | No | No | 34 | No | No | 9.1 | No | No | 34 | No | 9.3 | No | | `ornaments` | No | No | 34 | No | No | 9.1 | No | No | 34 | No | 9.3 | No | | `styleset` | No | No | 34 | No | No | 9.1 | No | No | 34 | No | 9.3 | No | | `stylistic` | No | No | 34 | No | No | 9.1 | No | No | 34 | No | 9.3 | No | | `swash` | No | No | 34 | No | No | 9.1 | No | No | 34 | No | 9.3 | No | See also -------- * The [`font-variant-alternates`](font-variant-alternates) property that uses values that this at-rule defines. css :any-link :any-link ========= The `:any-link` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) selector represents an element that acts as the source anchor of a hyperlink, independent of whether it has been visited. In other words, it matches every [`<a>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a) or [`<area>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/area) element that has an `href` attribute. Thus, it matches all elements that match [`:link`](:link) or [`:visited`](:visited). Try it ------ Syntax ------ ``` :any-link ``` Examples -------- ### HTML ``` <a href="https://example.com">External link</a><br /> <a href="#">Internal target link</a><br /> <a>Placeholder link (won't get styled)</a> ``` ### CSS ``` a:any-link { border: 1px solid blue; color: orange; } /\* WebKit browsers \*/ a:-webkit-any-link { border: 1px solid blue; color: orange; } ``` ### Result Specifications -------------- | Specification | | --- | | [Selectors Level 4 # the-any-link-pseudo](https://w3c.github.io/csswg-drafts/selectors/#the-any-link-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:any-link` | 65 1 | 79 79 | 50 1-50 | No | 52 15 | 9 3 1.2-3 | 65 ≤37 | 65 18 | 50 4-50 | 47 14 | 9 1 | 9.0 1.0 | | `not_match_link` | 65 | 79 | 87 | No | 52 | No Safari currently matches `<link>` elements with link pseudo-classes. See [Bug: 220740](https://webkit.org/b/220740). | 65 | 65 | 87 | 47 | No Safari currently matches `<link>` elements with link pseudo-classes. See [Bug: 220740](https://webkit.org/b/220740). | 9.0 | See also -------- * [Creating hyperlinks](https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/Creating_hyperlinks) * Matches HTML elements: [`<a>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a) and [`<area>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/area) with an [`href`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-href) attribute * Related CSS selectors: + [`:visited`](:visited) + [`:link`](:link) css margin-left margin-left =========== The `margin-left` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the [margin area](css_box_model/introduction_to_the_css_box_model#margin_area) on the left side of an element. A positive value places it farther from its neighbors, while a negative value places it closer. Try it ------ The vertical margins of two adjacent boxes may fuse. This is called [*margin collapsing*](css_box_model/mastering_margin_collapsing). In the rare cases where width is overconstrained (i.e., when all of `width`, `margin-left`, `border`, `padding`, the content area, and `margin-right` are defined), `margin-left` is ignored, and will have the same calculated value as if the `auto` value was specified. Syntax ------ ``` /\* <length> values \*/ margin-left: 10px; /\* An absolute length \*/ margin-left: 1em; /\* relative to the text size \*/ margin-left: 5%; /\* relative to the nearest block container's width \*/ /\* Keyword values \*/ margin-left: auto; /\* Global values \*/ margin-left: inherit; margin-left: initial; margin-left: revert; margin-left: revert-layer; margin-left: unset; ``` The `margin-left` property is specified as the keyword `auto`, or a `<length>`, or a `<percentage>`. Its value can be positive, zero, or negative. ### Values [`<length>`](length) The size of the margin as a fixed value. [`<percentage>`](percentage) The size of the margin as a percentage, relative to the inline size (*width* in a horizontal language, defined by [`writing-mode`](writing-mode)) of the [containing block](containing_block). `auto` The left margin receives a share of the unused horizontal space, as determined mainly by the layout mode that is used. If the values of `margin-left` and `margin-right` are both `auto`, the calculated space is evenly distributed. This table summarizes the different cases: | Value of [`display`](display) | Value of [`float`](float) | Value of [`position`](position) | Computed value of `auto` | Comment | | --- | --- | --- | --- | --- | | `inline`, `inline-block`, `inline-table` | *any* | `static` or `relative` | `0` | Inline layout mode | | `block`, `inline`, `inline-block`, `block`, `table`, `inline-table`, `list-item`, `table-caption` | *any* | `static` or `relative` | `0`, except if both `margin-left` and `margin-right` are set to `auto`. In this case, it is set to the value centering the element inside its parent. | Block layout mode | | `block`, `inline`, `inline-block`, `block`, `table`, `inline-table`, `list-item`, `table-caption` | `left` or `right` | `static` or `relative` | `0` | Block layout mode (floating element) | | *any* `table-*`*, except* `table-caption` | *any* | *any* | `0` | Internal `table-*` elements don't have margins, use [`border-spacing`](border-spacing) instead | | *any, except `flex`,* `inline-flex`*, or* `table-*` | *any* | *`fixed`* or `absolute` | `0`, except if both `margin-left` and `margin-right` are set to `auto`. In this case, it is set to the value centering the border area inside the available `width`, if fixed. | Absolutely positioned layout mode | | `flex`, `inline-flex` | *any* | *any* | `0`, except if there is any positive horizontal free space. In this case, it is evenly distributed to all horizontal `auto` margins. | Flexbox layout mode | Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | all elements, except elements with table [`display`](display) types other than `table-caption`, `table` and `inline-table`. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | Percentages | refer to the width of the containing block | | [Computed value](computed_value) | the percentage as specified or the absolute length | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` margin-left = <length-percentage> [|](value_definition_syntax#single_bar) auto <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Setting left margin using pixels and percentages ``` .content { margin-left: 5%; } .sidebox { margin-left: 10px; } .logo { margin-left: -5px; } ``` Specifications -------------- | Specification | | --- | | [CSS Box Model Module Level 3 # margin-physical](https://w3c.github.io/csswg-drafts/css-box/#margin-physical) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `margin-left` | 1 | 12 | 1 | 3 | 3.5 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `auto` | 1 | 12 The `auto` value is not supported in quirks mode. | 1 | 6 The `auto` value is not supported in quirks mode. | 3.5 | 1 | 37 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [`margin-top`](margin-top), [`margin-right`](margin-right), and [`margin-bottom`](margin-bottom) and the [`margin`](margin) shorthand * The mapped logical properties: [`margin-block-start`](margin-block-start), [`margin-block-end`](margin-block-end), [`margin-inline-start`](margin-inline-start), and [`margin-inline-end`](margin-inline-end) and the shorthands [`margin-block`](margin-block) and [`margin-inline`](margin-inline) css ::marker ::marker ======== The `::marker` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-element](pseudo-elements) selects the marker box of a list item, which typically contains a bullet or number. It works on any element or pseudo-element set to [`display: list-item`](display), such as the [`<li>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/li) and [`<summary>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/summary) elements. Try it ------ Allowable properties -------------------- Only certain CSS properties can be used in a rule with `::marker` as a selector: * All [font properties](css_fonts) * The [`white-space`](white-space) property * [`color`](color) * [`text-combine-upright`](text-combine-upright), [`unicode-bidi`](unicode-bidi) and [`direction`](direction) properties * The [`content`](content) property * All [animation](css_animations#css_properties) and [transition](css_transitions#properties) properties **Note:** The specification states that additional CSS properties may be supported in future. Syntax ------ ``` ::marker ``` Examples -------- ### HTML ``` <ul> <li>Peaches</li> <li>Apples</li> <li>Plums</li> </ul> ``` ### CSS ``` ul li::marker { color: red; font-size: 1.5em; } ``` ### Result Specifications -------------- | Specification | | --- | | [CSS Pseudo-Elements Module Level 4 # marker-pseudo](https://w3c.github.io/csswg-drafts/css-pseudo/#marker-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `::marker` | 86 | 86 | 68 | No | 72 | 11.1 Safari support is limited to `color` and `font-size`. See [bug 204163](https://webkit.org/b/204163). | 86 | 86 | 68 | 61 | 11.3 Safari support is limited to `color` and `font-size`. See [bug 204163](https://webkit.org/b/204163). | 14.0 | | `animation_and_transition_support` | 86 | 86 | 80 | No | 72 | No | 86 | 86 | No | 61 | No | 14.0 | See also -------- * HTML elements that have marker boxes by default: [`<ol>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol), [`<li>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/li), [`<summary>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/summary) css border-right border-right ============ The `border-right` [shorthand](shorthand_properties) [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets all the properties of an element's right <border>. Try it ------ As with all shorthand properties, `border-right` 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: ``` border-right-style: dotted; border-right: thick green; ``` It is actually the same as this one: ``` border-right-style: dotted; border-right: none thick green; ``` The value of [`border-right-style`](border-right-style) given before `border-right` is ignored. Since the default value of [`border-right-style`](border-right-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: * [`border-right-color`](border-right-color) * [`border-right-style`](border-right-style) * [`border-right-width`](border-right-width) Syntax ------ ``` border-right: 1px; border-right: 2px dotted; border-right: medium dashed green; /\* Global values \*/ border-right: inherit; border-right: initial; border-right: revert; border-right: revert-layer; border-right: 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 [`border-right-width`](border-right-width). `<br-style>` See [`border-right-style`](border-right-style). [`<color>`](color_value) See [`border-right-color`](border-right-color). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`border-right-width`](border-right-width): `medium` * [`border-right-style`](border-right-style): `none` * [`border-right-color`](border-right-color): `currentcolor` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`border-right-width`](border-right-width): the absolute length or `0` if [`border-right-style`](border-right-style) is `none` or `hidden` * [`border-right-style`](border-right-style): as specified * [`border-right-color`](border-right-color): computed color | | Animation type | as each of the properties of the shorthand:* [`border-right-color`](border-right-color): a [color](color_value#interpolation) * [`border-right-style`](border-right-style): discrete * [`border-right-width`](border-right-width): a [length](length#interpolation) | Formal syntax ------------- ``` border-right = <line-width> [||](value_definition_syntax#double_bar) <line-style> [||](value_definition_syntax#double_bar) [<color>](color_value) <line-width> = [<length [0,∞]>](length) [|](value_definition_syntax#single_bar) thin [|](value_definition_syntax#single_bar) medium [|](value_definition_syntax#single_bar) thick <line-style> = none [|](value_definition_syntax#single_bar) hidden [|](value_definition_syntax#single_bar) dotted [|](value_definition_syntax#single_bar) dashed [|](value_definition_syntax#single_bar) solid [|](value_definition_syntax#single_bar) double [|](value_definition_syntax#single_bar) groove [|](value_definition_syntax#single_bar) ridge [|](value_definition_syntax#single_bar) inset [|](value_definition_syntax#single_bar) outset ``` Examples -------- ### Applying a right border #### HTML ``` <div>This box has a border on the right side.</div> ``` #### CSS ``` div { border-right: 4px dashed blue; background-color: gold; height: 100px; width: 100px; font-weight: bold; text-align: center; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # border-shorthands](https://w3c.github.io/csswg-drafts/css-backgrounds/#border-shorthands) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-right` | 1 | 12 | 1 | 5.5 | 9.2 | 1 | ≤37 | 18 | 14 | 14 | 1 | 1.0 | See also -------- * [`border`](border) * [`border-block`](border-block) * [`outline`](outline) css max-inline-size max-inline-size =============== The `max-inline-size` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the horizontal or vertical maximum size of an element's block, depending on its writing mode. It corresponds to either the [`max-width`](max-width) or the [`max-height`](max-height) property, depending on the value of [`writing-mode`](writing-mode). If the writing mode is vertically oriented, the value of `max-inline-size` relates to the maximal height of the element; otherwise, it relates to the maximal width of the element. A related property is [`max-block-size`](max-block-size), which defines the other dimension of the element. Try it ------ Syntax ------ ``` /\* <length> values \*/ max-inline-size: 300px; max-inline-size: 25em; /\* <percentage> values \*/ max-inline-size: 75%; /\* Keyword values \*/ max-inline-size: none; max-inline-size: max-content; max-inline-size: min-content; max-inline-size: fit-content(20em); /\* Global values \*/ max-inline-size: inherit; max-inline-size: initial; max-inline-size: revert; max-inline-size: revert-layer; max-inline-size: unset; ``` ### Values The `max-inline-size` property takes the same values as the [`max-width`](max-width) and [`max-height`](max-height) properties. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | same as [`width`](width) and [`height`](height) | | [Inherited](inheritance) | no | | Percentages | inline-size of containing block | | [Computed value](computed_value) | same as [`max-width`](max-width) and [`max-height`](max-height) | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` max-inline-size = <'max-width'> ``` Examples -------- ### Setting maximum inline size in pixels #### HTML ``` <p class="exampleText">Example text</p> ``` #### CSS ``` .exampleText { writing-mode: vertical-rl; background-color: yellow; block-size: 100%; max-inline-size: 200px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # propdef-max-inline-size](https://w3c.github.io/csswg-drafts/css-logical/#propdef-max-inline-size) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `max-inline-size` | 57 | 79 | 41 | No | 44 | 12.1 10.1 | 57 | 57 | 41 | 43 | 12.2 10.3 | 7.0 | | `fit-content` | 57 | 79 | 41 | No | 44 | 12.1 | 57 | 57 | 41 | 43 | 12.2 | 7.0 | | `fit-content_function` | No | No | 91 | No | No | No | No | No | No | No | No | No | | `max-content` | 57 | 79 | 66 41 | No | 44 | 12.1 | 57 | 57 | 66 41 | 43 | 12.2 | 7.0 | | `min-content` | 57 | 79 | 66 41 | No | 44 | 12.1 | 57 | 57 | 66 41 | 43 | 12.2 | 7.0 | See also -------- * The mapped physical properties: [`max-width`](max-width) and [`max-height`](max-height) * [`writing-mode`](writing-mode)
programming_docs
css -moz-outline-radius -moz-outline-radius =================== **Deprecated:** This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the [compatibility table](#browser_compatibility) at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time. **Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future. In Mozilla applications like Firefox, the `-moz-outline-radius` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [shorthand property](shorthand_properties) can be used to give an element's [`outline`](outline) rounded corners. ``` /\* One value \*/ -moz-outline-radius: 25px; /\* Two values \*/ -moz-outline-radius: 25px 1em; /\* Three values \*/ -moz-outline-radius: 25px 1em 12%; /\* Four values \*/ -moz-outline-radius: 25px 1em 12% 4mm; /\* Global values \*/ -moz-outline-radius: inherit; -moz-outline-radius: initial; -moz-outline-radius: unset; ``` Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`-moz-outline-radius-bottomleft`](-moz-outline-radius-bottomleft) * [`-moz-outline-radius-bottomright`](-moz-outline-radius-bottomright) * [`-moz-outline-radius-topleft`](-moz-outline-radius-topleft) * [`-moz-outline-radius-topright`](-moz-outline-radius-topright) Syntax ------ ### Values **Note:** Elliptical outlines and `<percentage>` values follow the syntax described in [`border-radius`](border-radius). One, two, three or four `<outline-radius>` values, represents one of: [`<length>`](length) See [`<length>`](length) for possible values. [`<percentage>`](percentage) A [`<percentage>`](percentage); see [`border-radius`](border-radius) for details. * If a single value is set, it applies to all 4 corners. * If two values are set, the first one applies to the top-left and bottom-right corners and the second one to the top-right and bottom-left corners. * If three values are set, the first one applies to the top-Left corner, the second one to the top-right and bottom-left corners and the third one to the bottom-right corner. * If four values are set, the first one applies to the top-left corner, the second one to the top-right corner, the third one to the bottom-right corner and the fourth one to the bottom-left corner. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`-moz-outline-radius-topleft`](-moz-outline-radius-topleft): `0` * [`-moz-outline-radius-topright`](-moz-outline-radius-topright): `0` * [`-moz-outline-radius-bottomright`](-moz-outline-radius-bottomright): `0` * [`-moz-outline-radius-bottomleft`](-moz-outline-radius-bottomleft): `0` | | Applies to | all elements | | [Inherited](inheritance) | no | | Percentages | as each of the properties of the shorthand:* [`-moz-outline-radius-topleft`](-moz-outline-radius-topleft): refer to the corresponding dimension of the border box * [`-moz-outline-radius-topright`](-moz-outline-radius-topright): refer to the corresponding dimension of the border box * [`-moz-outline-radius-bottomright`](-moz-outline-radius-bottomright): refer to the corresponding dimension of the border box * [`-moz-outline-radius-bottomleft`](-moz-outline-radius-bottomleft): refer to the corresponding dimension of the border box | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`-moz-outline-radius-topleft`](-moz-outline-radius-topleft): as specified * [`-moz-outline-radius-topright`](-moz-outline-radius-topright): as specified * [`-moz-outline-radius-bottomright`](-moz-outline-radius-bottomright): as specified * [`-moz-outline-radius-bottomleft`](-moz-outline-radius-bottomleft): as specified | | Animation type | as each of the properties of the shorthand:* [`-moz-outline-radius-topleft`](-moz-outline-radius-topleft): a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); * [`-moz-outline-radius-topright`](-moz-outline-radius-topright): a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); * [`-moz-outline-radius-bottomright`](-moz-outline-radius-bottomright): a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); * [`-moz-outline-radius-bottomleft`](-moz-outline-radius-bottomleft): a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` -moz-outline-radius = <outline-radius>{1,4} [ / <outline-radius>{1,4} ]? ``` Examples -------- ### Rounding an outline Note: This example will not display the desired effect if you are viewing this in a browser other than Firefox. #### HTML ``` <p>This element has a rounded outline!</p> ``` #### CSS ``` p { margin: 5px; border: 1px solid black; outline: dotted red; -moz-outline-radius: 12% 1em 25px; } ``` #### Result Notes ----- * `dotted` or `dashed` radiused corners were rendered as solid until Firefox 50, [bug 382721](https://bugzilla.mozilla.org/show_bug.cgi?id=382721) * Future versions of Gecko/Firefox may drop this property completely. See [bug 593717](https://bugzilla.mozilla.org/show_bug.cgi?id=593717). Specifications -------------- Not part of any standard. Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `-moz-outline-radius` | No | No | 1-88 From Firefox 88, [outline](https://developer.mozilla.org/docs/Web/CSS/outline) now follows the shape created by [border-radius](https://developer.mozilla.org/docs/Web/CSS/border-radius) automatically, so this property is no longer needed (see [bug 1694146](https://bugzil.la/1694146)). | No | No | No | No | No | 4-88 From Firefox 88, [outline](https://developer.mozilla.org/docs/Web/CSS/outline) now follows the shape created by [border-radius](https://developer.mozilla.org/docs/Web/CSS/border-radius) automatically, so this property is no longer needed (see [bug 1694146](https://bugzil.la/1694146)). | No | No | No | See also -------- * [Mozilla CSS extensions](https://developer.mozilla.org/en-US/docs/Web/CSS/Mozilla_Extensions) * Related CSS properties: + [`outline`](outline) css break-before break-before ============ The `break-before` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets how page, column, or region breaks should behave before a generated box. If there is no generated box, the property is ignored. ``` /\* Generic break values \*/ break-before: auto; break-before: avoid; break-before: always; break-before: all; /\* Page break values \*/ break-before: avoid-page; break-before: page; break-before: left; break-before: right; break-before: recto; break-before: verso; /\* Column break values \*/ break-before: avoid-column; break-before: column; /\* Region break values \*/ break-before: avoid-region; break-before: region; /\* Global values \*/ break-before: inherit; break-before: initial; break-before: revert; break-before: revert-layer; break-before: unset; ``` Each possible break point (in other words, each element boundary) is affected by three properties: the [`break-after`](break-after) value of the previous element, the `break-before` value of the next element, and the [`break-inside`](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. Syntax ------ The `break-before` property is specified as one of the keyword values from the list below. ### Values #### Generic break values `auto` Allows, but does not force, any break (page, column, or region) to be inserted right before the principal box. `avoid` Avoids any break (page, column, or region) from being inserted right before the principal box. `always` Experimental 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 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 before the principal box. `page` Forces a page break right before the principal box. `left` Forces one or two page breaks right before 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 before 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` Experimental Forces one or two page breaks right before 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` Experimental Forces one or two page breaks right before 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 before the principal box. `column` Forces a column break right before the principal box. #### Region break values `avoid-region` Experimental Avoids any region break right before the principal box. `region` Experimental Forces a region break right before the principal box. Page break aliases ------------------ For compatibility reasons, the legacy [`page-break-before`](page-break-before) property should be treated by browsers as an alias of `break-before`. This ensures that sites using `page-break-before` continue to work as designed. A subset of values should be aliased as follows: | page-break-before | break-before | | --- | --- | | `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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | block-level elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` break-before = auto [|](value_definition_syntax#single_bar) avoid [|](value_definition_syntax#single_bar) always [|](value_definition_syntax#single_bar) all [|](value_definition_syntax#single_bar) avoid-page [|](value_definition_syntax#single_bar) page [|](value_definition_syntax#single_bar) left [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) recto [|](value_definition_syntax#single_bar) verso [|](value_definition_syntax#single_bar) avoid-column [|](value_definition_syntax#single_bar) column [|](value_definition_syntax#single_bar) avoid-region [|](value_definition_syntax#single_bar) region ``` 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-before: column` on the `<h2>` elements to force a column break before each one, meaning that you end up with an `<h2>` neatly at the top of each column. #### 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 ``` 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; break-before: column; } p { line-height: 1.5; } article { column-width: 200px; gap: 20px; } ``` ### Result Specifications -------------- | Specification | | --- | | [CSS Fragmentation Module Level 3 # break-between](https://w3c.github.io/csswg-drafts/css-break/#break-between) | | [CSS Regions Module Level 1 # region-flow-break](https://w3c.github.io/csswg-drafts/css-regions/#region-flow-break) | | [CSS Multi-column Layout Module Level 1 # break-before-break-after-break-inside](https://w3c.github.io/csswg-drafts/css-multicol/#break-before-break-after-break-inside) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `break-before` | 50 | 12 | 65 | 10 | 37 11.1-12.1 | 10 | 50 | 50 | 65 | 37 11.1-12.1 | 10 | 5.0 | | `multicol_context` | 50 | 12 | 65 Only supported in print mode. See [bug 1675322](https://bugzil.la/1675322). | 10 | 37 11.1-12.1 | No | 50 | 50 | 65 Only supported in print mode. See [bug 1675322](https://bugzil.la/1675322). | 37 11.1-12.1 | No | 5.0 | | `paged_context` | 50 | 12 | 65 | 10 | 37 11.1-12.1 | 10 | 50 | 50 | 65 | 37 11.1-12.1 | 10 | 5.0 | See also -------- * [Multiple-column Layout](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Multiple-column_Layout) * [Breaking Boxes With CSS Fragmentation](https://www.smashingmagazine.com/2019/02/css-fragmentation/) css list-style list-style ========== The `list-style` CSS [shorthand property](shorthand_properties) allows you to set all the list style properties at once. Try it ------ **Note:** This property is applied to list items, i.e., elements with `[`display`](display): list-item;`. [By default](https://html.spec.whatwg.org/multipage/rendering.html#lists) this includes [`<li>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/li) elements. Because this property is inherited, it can be set on a parent element (normally [`<ol>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol) or [`<ul>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ul)) to make the same list styling apply to all the items inside. Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`list-style-image`](list-style-image) * [`list-style-position`](list-style-position) * [`list-style-type`](list-style-type) Syntax ------ ``` /\* type \*/ list-style: square; /\* image \*/ list-style: url("../img/shape.png"); /\* position \*/ list-style: inside; /\* type | position \*/ list-style: georgian inside; /\* type | image | position \*/ list-style: lower-roman url("../img/shape.png") outside; /\* Keyword value \*/ list-style: none; /\* Global values \*/ list-style: inherit; list-style: initial; list-style: revert; list-style: revert-layer; list-style: unset; ``` The `list-style` property is specified as one, two, or three keywords in any order. If [`list-style-type`](list-style-type) and [`list-style-image`](list-style-image) are both set, then `list-style-type` is used as a fallback if the image is unavailable. ### Values [`list-style-type`](list-style-type) See [`list-style-type`](list-style-type). [`list-style-image`](list-style-image) See [`list-style-image`](list-style-image). [`list-style-position`](list-style-position) See [`list-style-position`](list-style-position). `none` No list style is used. Accessibility concerns ---------------------- In a notable exception, Safari will not recognize an ordered or unordered list as a list in the accessibility tree if it has a `list-style` value of `none`. This [behavior is intentional](https://bugs.webkit.org/show_bug.cgi?id=170179#c1) and not considered a bug. The most straightforward way to address this is to add an explicit `role="list"` to the `<ol>` or `<ul>` element in the markup. This will restore the list semantics without affecting the design: ``` <ul role="list"> <li>An item</li> <li>Another item</li> </ul> ``` A CSS-only workaround is also available for those who do not have access to the markup: Adding [pseudo-content](content) before each list item can restore list semantics: ``` ul { list-style: none; } ul li::before { content: "+ "; } ``` The added pseudo-content is tested by Safari to determine if it should be accessible or ignored. Accessible pseudo-content restores list semantics, while ignored pseudo-content does not. Generally, text or images are determined to be things that should be accessible, which is why the `content: "+ ";` declaration in the previous example works. A declaration of `content: "";` (an empty string) is ignored, as are `content` values that contain only spaces, such as `content: " ";`, so these do not work. If the intent is to keep list item markers visually hidden, this can often be managed with a [zero-width space](https://en.wikipedia.org/wiki/Zero-width_space), `&#8203;`, which is `\200B` in CSS and `\u200B` in JavaScript: ``` ul { list-style: none; } ul li::before { content: "\200B"; } ``` Another visually hidden approach is to apply an [`<image>`](image) to the `list-style` property: ``` nav ol, nav ul { list-style: none; } /\* becomes \*/ nav ol, nav ul { list-style: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'/%3E"); } ``` These CSS workarounds should be used only when the HTML solution is not available, and only after testing to ensure that they don't result in unexpected behaviors that may negatively impact users' experiences. * [Bug #170179 | WebKit Bugzilla](https://bugs.webkit.org/show_bug.cgi?id=170179) * ['Fixing' Lists](https://www.scottohara.me/blog/2019/01/12/lists-and-safari.html) * [VoiceOver and list-style-type: none](https://gerardkcohen.me/writing/2017/voiceover-list-style-type.html) * [MDN Understanding WCAG, Guideline 1.3 explanations](#) * [Understanding Success Criterion 1.3.1: Info and Relationships | WCAG 2.1](https://www.w3.org/WAI/WCAG21/Understanding/info-and-relationships.html) Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`list-style-type`](list-style-type): `disc` * [`list-style-position`](list-style-position): `outside` * [`list-style-image`](list-style-image): `none` | | Applies to | list items | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`list-style-image`](list-style-image): * [`list-style-position`](list-style-position): as specified * [`list-style-type`](list-style-type): as specified | | Animation type | discrete | Formal syntax ------------- ``` list-style = <'list-style-position'> [||](value_definition_syntax#double_bar) <'list-style-image'> [||](value_definition_syntax#double_bar) <'list-style-type'> ``` Examples -------- ### Setting list style type and position #### HTML ``` List 1 <ul class="one"> <li>List Item1</li> <li>List Item2</li> <li>List Item3</li> </ul> List 2 <ul class="two"> <li>List Item A</li> <li>List Item B</li> <li>List Item C</li> </ul> ``` #### CSS ``` .one { list-style: circle; } .two { list-style: square inside; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Lists and Counters Module Level 3 # list-style-property](https://w3c.github.io/csswg-drafts/css-lists/#list-style-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `list-style` | 1 | 12 | 1 | 4 | 7 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `symbols` | No | No | 35 | No | No | No | No | No | 35 | No | No | No | See also -------- * [`list-style-type`](list-style-type), [`list-style-image`](list-style-image), [`list-style-position`](list-style-position)
programming_docs
css math-depth math-depth ========== **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `math-depth` property describes a notion of *depth* for each element of a mathematical formula, with respect to the top-level container of that formula. Concretely, this is used to determine the computed value of the <font-size> property when its specified value is `math`. Syntax ------ ``` /\* Keyword values \*/ math-depth: auto-add; /\* Relative values \*/ math-depth: add(2); math-depth: add(-2); /\* Absolute value \*/ math-depth: 4; /\* Global values \*/ math-depth: inherit; math-depth: initial; math-depth: revert; math-depth: revert-layer; math-depth: unset; ``` Values ------ `auto-add` Set to the inherited `math-depth` plus 1 when inherited <math-style> is `compact`. `add([`<integer>`](integer))` Set to the inherited `math-depth` plus the specified integer. [`<integer>`](integer) Set to the specified integer. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | Not animatable | Formal syntax ------------- ``` math-depth = auto-add [|](value_definition_syntax#single_bar) add( [<integer>](integer) ) [|](value_definition_syntax#single_bar) [<integer>](integer) ``` Examples -------- ### CSS ``` math { math-depth: auto-add; } ``` Specifications -------------- | Specification | | --- | | [MathML Core # the-math-script-level-property](https://w3c.github.io/mathml-core/#the-math-script-level-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `math-depth` | 87 | 87 | 83 Implementation lacks support for `font-size: math` to be complete. | No | 73 | No See [bug 202303](https://webkit.org/b/202303). | No | 87 | No | No | No See [bug 202303](https://webkit.org/b/202303). | No | See also -------- * [`font-size`](font-size) * [`math-style`](math-style) css border-image-repeat border-image-repeat =================== The `border-image-repeat` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines how the [edge regions](border-image-slice#edge-regions) and [middle region](border-image-slice#middle-region) of a source image are adjusted to fit the dimensions of an element's [border image](border-image). The middle region can be displayed by using the keyword "fill" in the border-image-slice property. Try it ------ Syntax ------ ``` /\* Keyword value \*/ border-image-repeat: stretch; border-image-repeat: repeat; border-image-repeat: round; border-image-repeat: space; /\* top and bottom | left and right \*/ border-image-repeat: round stretch; /\* Global values \*/ border-image-repeat: inherit; border-image-repeat: initial; border-image-repeat: revert; border-image-repeat: revert-layer; border-image-repeat: unset; ``` The `border-image-repeat` property may be specified using one or two values chosen from the list of values below. * When **one** value is specified, it applies the same behavior on **all four sides**. * When **two** values are specified, the first applies to the **top, middle, and bottom**, the second to the **left and right**. ### Values `stretch` The source image's edge regions are stretched to fill the gap between each border. `repeat` The source image's edge regions are tiled (repeated) to fill the gap between each border. Tiles may be clipped to achieve the proper fit. `round` The source image's edge regions are tiled (repeated) to fill the gap between each border. Tiles may be stretched to achieve the proper fit. `space` The source image's edge regions are tiled (repeated) to fill the gap between each border. Extra space will be distributed in between tiles to achieve the proper fit. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `stretch` | | Applies to | all elements, except internal table elements when [`border-collapse`](border-collapse) is `collapse`. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` border-image-repeat = [[](value_definition_syntax#brackets) stretch [|](value_definition_syntax#single_bar) repeat [|](value_definition_syntax#single_bar) round [|](value_definition_syntax#single_bar) space []](value_definition_syntax#brackets)[{1,2}](value_definition_syntax#curly_braces) ``` Examples -------- ### Repeating border images #### CSS ``` #bordered { width: 12rem; margin-bottom: 1rem; padding: 1rem; border: 40px solid; border-image: url("border.png") 27; border-image-repeat: stretch; /\* Can be changed in the live sample \*/ } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # the-border-image-repeat](https://w3c.github.io/csswg-drafts/css-backgrounds/#the-border-image-repeat) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-image-repeat` | 15 | 12 | 15 | 11 | 15 | 6 | 4.4 | 18 | 15 | 14 | 9.3 | 1.0 | | `round` | 30 | 12 | 15 | 11 | 17 | 9.1 | ≤37 | 30 | 15 | 18 | 9.3 | 2.0 | | `space` | 56 | 12 | 50 | 11 | 43 | 9.1 | 56 | 56 | 50 | 43 | 9.3 | 6.0 | See also -------- * [Backgrounds and borders](css_backgrounds_and_borders) * [Learn CSS: Backgrounds and borders](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Backgrounds_and_borders) css text-orientation text-orientation ================ The `text-orientation` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the orientation of the text characters in a line. It only affects text in vertical mode (when [`writing-mode`](writing-mode) is not `horizontal-tb`). It is useful for controlling the display of languages that use vertical script, and also for making vertical table headers. Try it ------ Syntax ------ ``` /\* Keyword values \*/ text-orientation: mixed; text-orientation: upright; text-orientation: sideways-right; text-orientation: sideways; text-orientation: use-glyph-orientation; /\* Global values \*/ text-orientation: inherit; text-orientation: initial; text-orientation: revert; text-orientation: revert-layer; text-orientation: unset; ``` The `text-orientation` property is specified as a single keyword from the list below. ### Values `mixed` Rotates the characters of horizontal scripts 90° clockwise. Lays out the characters of vertical scripts naturally. Default value. `upright` Lays out the characters of horizontal scripts naturally (upright), as well as the glyphs for vertical scripts. Note that this keyword causes all characters to be considered as left-to-right: the used value of [`direction`](direction) is forced to be `ltr`. `sideways` Causes characters to be laid out as they would be horizontally, but with the whole line rotated 90° clockwise. `sideways-right` An alias to `sideways` that is kept for compatibility purposes. `use-glyph-orientation` On SVG elements, this keyword leads to use the value of the deprecated SVG properties `glyph-orientation-vertical` and `glyph-orientation-horizontal`. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `mixed` | | Applies to | all elements, except table row groups, rows, column groups, and columns | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` text-orientation = mixed [|](value_definition_syntax#single_bar) upright [|](value_definition_syntax#single_bar) sideways ``` Examples -------- ### HTML ``` <p>Lorem ipsum dolet semper quisquam.</p> ``` ### CSS ``` p { writing-mode: vertical-rl; text-orientation: upright; } ``` ### Result Specifications -------------- | Specification | | --- | | [CSS Writing Modes Level 4 # text-orientation](https://w3c.github.io/csswg-drafts/css-writing-modes/#text-orientation) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `text-orientation` | 48 11 | 79 79 | 41 | No | 35 15 | 14 5.1 | 48 ≤37 | 48 18 | 41 | 35 14 | 14 5 | 5.0 1.0 | | `sideways` | No | No | 44 `sideways-right` has become an alias of `sideways`. | No | No | 7 | No | No | 44 `sideways-right` has become an alias of `sideways`. | No | 7 | No | See also -------- * The other vertical-script related CSS properties: [`writing-mode`](writing-mode), [`text-combine-upright`](text-combine-upright), and [`unicode-bidi`](unicode-bidi). * [CSS Logical properties](css_logical_properties) * [Styling vertical text (Chinese, Japanese, Korean and Mongolian)](https://www.w3.org/International/articles/vertical-text/) * Extensive browsers support test results: <https://w3c.github.io/i18n-tests/results/horizontal-in-vertical.html#text_orientation> css :checked :checked ======== The `:checked` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) selector represents any **radio** ([`<input type="radio">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio)), **checkbox** ([`<input type="checkbox">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox)), or **option** ([`<option>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option) in a [`<select>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select)) element that is checked or toggled to an `on` state. Try it ------ The user can engage this state by checking/selecting an element, or disengage it by unchecking/deselecting the element. **Note:** Because browsers often treat `<option>`s as [replaced elements](replaced_element), the extent to which they can be styled with the `:checked` pseudo-class varies from browser to browser. Syntax ------ ``` :checked ``` Examples -------- ### Basic example #### HTML ``` <div> <input type="radio" name="my-input" id="yes" value="yes" /> <label for="yes">Yes</label> <input type="radio" name="my-input" id="no" value="no" /> <label for="no">No</label> </div> <div> <input type="checkbox" name="my-checkbox" id="opt-in" /> <label for="opt-in">Check me!</label> </div> <select name="my-select" id="fruit"> <option value="opt1">Apples</option> <option value="opt2">Grapes</option> <option value="opt3">Pears</option> </select> ``` #### CSS ``` div, select { margin: 8px; } /\* Labels for checked inputs \*/ input:checked + label { color: red; } /\* Radio element, when checked \*/ input[type="radio"]:checked { box-shadow: 0 0 0 3px orange; } /\* Checkbox element, when checked \*/ input[type="checkbox"]:checked { box-shadow: 0 0 0 3px hotpink; } /\* Option elements, when selected \*/ option:checked { box-shadow: 0 0 0 3px lime; color: red; } ``` #### Result ### Toggling elements with a hidden checkbox This example utilizes the `:checked` pseudo-class to let the user toggle content based on the state of a checkbox, all without using [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript). #### HTML ``` <input type="checkbox" id="expand-toggle" /> <table> <thead> <tr> <th>Column #1</th> <th>Column #2</th> <th>Column #3</th> </tr> </thead> <tbody> <tr class="expandable"> <td>[more text]</td> <td>[more text]</td> <td>[more text]</td> </tr> <tr> <td>[cell text]</td> <td>[cell text]</td> <td>[cell text]</td> </tr> <tr> <td>[cell text]</td> <td>[cell text]</td> <td>[cell text]</td> </tr> <tr class="expandable"> <td>[more text]</td> <td>[more text]</td> <td>[more text]</td> </tr> <tr class="expandable"> <td>[more text]</td> <td>[more text]</td> <td>[more text]</td> </tr> </tbody> </table> <label for="expand-toggle" id="expand-btn">Toggle hidden rows</label> ``` #### CSS ``` /\* Hide the toggle checkbox \*/ #expand-toggle { display: none; } /\* Hide expandable content by default \*/ .expandable { visibility: collapse; background: #ddd; } /\* Style the button \*/ #expand-btn { display: inline-block; margin-top: 12px; padding: 5px 11px; background-color: #ff7; border: 1px solid; border-radius: 3px; } /\* Show hidden content when the checkbox is checked \*/ #expand-toggle:checked ~ \* .expandable { visibility: visible; } /\* Style the button when the checkbox is checked \*/ #expand-toggle:checked ~ #expand-btn { background-color: #ccc; } ``` #### Result Specifications -------------- | Specification | | --- | | [HTML Standard # selector-checked](https://html.spec.whatwg.org/multipage/semantics-other.html#selector-checked) | | [Selectors Level 4 # checked](https://w3c.github.io/csswg-drafts/selectors/#checked) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:checked` | 1 On macOS, styling `<option>` elements has no effect. | 12 On macOS, styling `<option>` elements has no effect. | 1 ["From Firefox 56, `<option>` elements cannot be styled.", "On macOS, styling `<option>` elements has no effect."] | 9 | 9 On macOS, styling `<option>` elements has no effect. | 3.1 Styling `<option>` elements has no effect. | 2 | 18 | 4 From Firefox 56, `<option>` elements cannot be styled. | 10.1 | 2 Styling `<option>` elements has no effect. | 1.0 | See also -------- * [Web forms — working with user data](https://developer.mozilla.org/en-US/docs/Learn/Forms) * [Styling web forms](https://developer.mozilla.org/en-US/docs/Learn/Forms/Styling_web_forms) * Related HTML elements: [`<input type="checkbox">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox), [`<input type="radio">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio), [`<select>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select), and [`<option>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option) * [Replaced elements](replaced_element) css border-block-end-width border-block-end-width ====================== The `border-block-end-width` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the width of the logical block-end border of an element, which maps to a physical border width depending on the element's writing mode, directionality, and text orientation. It corresponds to the [`border-top-width`](border-top-width), [`border-right-width`](border-right-width), [`border-bottom-width`](border-bottom-width), or [`border-left-width`](border-left-width) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ Syntax ------ ``` /\* <'border-width'> values \*/ border-block-end-width: 5px; border-block-end-width: thick; /\* Global values \*/ border-block-end-width: inherit; border-block-end-width: initial; border-block-end-width: revert; border-block-end-width: revert-layer; border-block-end-width: unset; ``` Related properties are [`border-block-start-width`](border-block-start-width), [`border-inline-start-width`](border-inline-start-width), and [`border-inline-end-width`](border-inline-end-width), which define the other border widths of the element. ### Values `<'border-width'>` The width of the border. See [`border-width`](border-width). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `medium` | | Applies to | all elements | | [Inherited](inheritance) | no | | Percentages | logical-width of containing block | | [Computed value](computed_value) | absolute length; `0` if the border style is `none` or `hidden` | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` border-block-end-width = <'border-top-width'> ``` Examples -------- ### Border width with vertical text #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; border: 1px solid blue; border-block-end-width: 5px; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # border-width](https://w3c.github.io/csswg-drafts/css-logical/#border-width) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-block-end-width` | 69 | 79 | 41 | No | 56 | 12.1 | 69 | 69 | 41 | 48 | 12.2 | 10.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * This property maps to one of the physical border properties: [`border-top-width`](border-top-width), [`border-right-width`](border-right-width), [`border-bottom-width`](border-bottom-width), and [`border-left-width`](border-left-width) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css Comments Comments ======== A CSS **comment** is used to add explanatory notes to the code or to prevent the browser from interpreting specific parts of the style sheet. By design, comments have no effect on the layout of a document. Syntax ------ Comments can be placed wherever white space is allowed within a style sheet. They can be used on a single line, or traverse multiple lines. ``` /\* Comment \*/ ``` Examples -------- ``` /\* A one-line comment \*/ /\* A comment which stretches over several lines \*/ /\* The comment below is used to disable specific styling \*/ /\* span { color: blue; font-size: 1.5em; } \*/ ``` Notes ----- The `/* */` comment syntax is used for both single and multiline comments. There is no other way to specify comments in external style sheets. However, when using the [`<style>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style) element, you may use `<!-- -->` to hide CSS from older browsers, although this is not recommended. As with most programming languages that use the `/* */` comment syntax, comments cannot be nested. In other words, the first instance of `*/` that follows an instance of `/*` closes the comment. Specifications -------------- * [CSS 2.1 Syntax and basic data types #comments](https://www.w3.org/TR/CSS21/syndata.html#comments) See also -------- * CSS key concepts: + [CSS syntax](syntax) + [At-rules](at-rule) + [Specificity](specificity) + [Inheritance](inheritance) + [Box model](css_box_model/introduction_to_the_css_box_model) + [Layout modes](layout_mode) + [Visual formatting models](visual_formatting_model) + [Margin collapsing](css_box_model/mastering_margin_collapsing) + Values - [Initial values](initial_value) - [Computed values](computed_value) - [Used values](used_value) - [Actual values](actual_value) + [Value definition syntax](value_definition_syntax) + [Shorthand properties](shorthand_properties) + [Replaced elements](replaced_element)
programming_docs
css accent-color accent-color ============ The `accent-color` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the [accent](https://developer.mozilla.org/en-US/docs/Glossary/Accent) color for user-interface controls generated by some elements. Try it ------ Browsers that support `accent-color` currently apply it to the following HTML elements: * [`<input type="checkbox">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox) * [`<input type="radio">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio) * [`<input type="range">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range) * [`<progress>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress) Syntax ------ ``` /\* Keyword values \*/ accent-color: auto; /\* <color> values \*/ accent-color: darkred; accent-color: #5729e9; accent-color: rgb(0, 200, 0); accent-color: hsl(228, 4%, 24%); /\* Global values \*/ accent-color: inherit; accent-color: initial; accent-color: revert; accent-color: revert-layer; accent-color: unset; ``` ### Values `auto` Represents a UA-chosen color, which should match the accent color of the platform, if any. [`<color>`](color_value) Specifies the color to be used as the accent color. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | `auto` is computed as specified and `<color>` values are computed as defined for the [`color`](color) property. | | Animation type | by computed value type | Formal syntax ------------- ``` accent-color = auto [|](value_definition_syntax#single_bar) [<color>](color_value) ``` Examples -------- ### Setting a custom accent color #### HTML ``` <input type="checkbox" checked /> <input type="checkbox" class="custom" checked /> ``` #### CSS ``` input { accent-color: auto; display: block; width: 30px; height: 30px; } input.custom { accent-color: rebeccapurple; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Basic User Interface Module Level 4 # widget-accent](https://w3c.github.io/csswg-drafts/css-ui/#widget-accent) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `accent-color` | 93 | 93 | 92 | No | 79 | 15.4 | 93 | 93 | 92 | 66 | 15.4 | 17.0 | See also -------- * The [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) element * [Applying color to HTML elements using CSS](css_colors/applying_color) * The [`<color>`](color_value) data type * Other color-related properties: [`color`](color), [`background-color`](background-color), [`border-color`](border-color), [`outline-color`](outline-color), [`text-decoration-color`](text-decoration-color), [`text-emphasis-color`](text-emphasis-color), [`text-shadow`](text-shadow), [`caret-color`](caret-color), and [`column-rule-color`](column-rule-color) css inset-inline-start inset-inline-start ================== The `inset-inline-start` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the logical inline start inset of an element, which maps to a physical offset depending on the element's writing mode, directionality, and text orientation. It corresponds to the [`top`](top), [`right`](right), [`bottom`](bottom), or [`left`](left) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ Syntax ------ ``` /\* <length> values \*/ inset-inline-start: 3px; inset-inline-start: 2.4em; /\* <percentage>s of the width or height of the containing block \*/ inset-inline-start: 10%; /\* Keyword value \*/ inset-inline-start: auto; /\* Global values \*/ inset-inline-start: inherit; inset-inline-start: initial; inset-inline-start: revert; inset-inline-start: revert-layer; inset-inline-start: unset; ``` The shorthand for `inset-inline-start` and [`inset-inline-end`](inset-inline-end) is [`inset-inline`](inset-inline). ### Values The `inset-inline-start` property takes the same values as the [`left`](left) property. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | positioned elements | | [Inherited](inheritance) | no | | Percentages | logical-width of containing block | | [Computed value](computed_value) | same as box offsets: [`top`](top), [`right`](right), [`bottom`](bottom), [`left`](left) properties except that directions are logical | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` inset-inline-start = auto [|](value_definition_syntax#single_bar) <length-percentage> <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Setting inline start offset #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; position: relative; inset-inline-start: 20px; background-color: #c8c800; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # position-properties](https://w3c.github.io/csswg-drafts/css-logical/#position-properties) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `inset-inline-start` | 87 | 87 | 63 41-63 | No | 73 | 14.1 | 87 | 87 | 63 41-63 | 62 | 14.5 | 14.0 | See also -------- * The properties which defines other insets: [`inset-block-start`](inset-block-start), [`inset-block-end`](inset-block-end), and [`inset-inline-end`](inset-inline-end) * The mapped physical properties: [`top`](top), [`right`](right), [`bottom`](bottom), and [`left`](left) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css padding-right padding-right ============= The `padding-right` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the width of the [padding area](css_box_model/introduction_to_the_css_box_model#padding_area) on the right of an element. Try it ------ An element's padding area is the space between its content and its border. **Note:** The [`padding`](padding) property can be used to set paddings on all four sides of an element with a single declaration. Syntax ------ ``` /\* <length> values \*/ padding-right: 0.5em; padding-right: 0; padding-right: 2cm; /\* <percentage> value \*/ padding-right: 10%; /\* Global values \*/ padding-right: inherit; padding-right: initial; padding-right: revert; padding-right: revert-layer; padding-right: unset; ``` The `padding-right` property is specified as a single value chosen from the list below. Unlike margins, negative values are not allowed for padding. ### Values [`<length>`](length) The size of the padding as a fixed value. Must be nonnegative. [`<percentage>`](percentage) The size of the padding as a percentage, relative to the inline size (*width* in a horizontal language, defined by [`writing-mode`](writing-mode)) of the [containing block](containing_block). Must be nonnegative. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | all elements, except `table-row-group`, `table-header-group`, `table-footer-group`, `table-row`, `table-column-group` and `table-column`. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | Percentages | refer to the width of the containing block | | [Computed value](computed_value) | the percentage as specified or the absolute length | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` padding-right = [<length-percentage [0,∞]>](length-percentage) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Setting right padding using pixels and percentages ``` .content { padding-right: 5%; } .sidebox { padding-right: 10px; } ``` Specifications -------------- | Specification | | --- | | [CSS Box Model Module Level 3 # padding-physical](https://w3c.github.io/csswg-drafts/css-box/#padding-physical) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `padding-right` | 1 | 12 | 1 | 4 | 3.5 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [Introduction to the CSS basic box model](css_box_model/introduction_to_the_css_box_model) * [`padding-top`](padding-top), [`padding-bottom`](padding-bottom), [`padding-left`](padding-left) and the [`padding`](padding) shorthand * The mapped logical properties: [`padding-block-start`](padding-block-start), [`padding-block-end`](padding-block-end), [`padding-inline-start`](padding-inline-start), and [`padding-inline-end`](padding-inline-end) and the shorthands [`padding-block`](padding-block) and [`padding-inline`](padding-inline) css <frequency-percentage> <frequency-percentage> ====================== The `<frequency-percentage>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) represents a value that can be either a [`<frequency>`](frequency) or a [`<percentage>`](percentage). Frequency values, e.g. the pitch of a speaking voice, are not currently used in any CSS properties. Syntax ------ The value of a `<frequency-percentage>` is either a [`<frequency>`](frequency) or a [`<percentage>`](percentage); see their individual reference pages for details about their syntaxes. Description ----------- ### Use in calc() Where a `<frequency-percentage>` is specified as an allowable type, this means that the percentage resolves to a frequency and therefore can be used in a [`calc()`](calc) expression. Formal syntax ------------- ``` <frequency-percentage> = [<frequency>](frequency) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Valid percentage values ``` 90% Positive percentage +90% Positive percentage with leading + -90% Negative percentage — not valid for all properties that use percentages ``` ### Invalid percentage values ``` 90 % No space is allowed between the number and the unit ``` ### Valid frequency values ``` 12Hz Positive integer 4.3Hz Non-integer 14KhZ The unit is case-insensitive, though non-SI capitalization is not recommended. +0Hz Zero, with a leading + and a unit -0kHz Zero, with a leading - and a unit ``` ### Invalid frequency values ``` 12.0 This is a <number>, not an <frequency>, because it is missing a unit. 7 Hz No space is allowed between the number and the unit. 0 Although unitless zero is an allowable <length>, it's an invalid <frequency>. ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # mixed-percentages](https://w3c.github.io/csswg-drafts/css-values/#mixed-percentages) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `frequency-percentage` | No | No | No See [bug 741643](https://bugzil.la/741643). | No | No | No | No | No | No See [bug 741643](https://bugzil.la/741643). | No | No | No | See also -------- * [CSS data types](css_types) * [CSS Values and Units](css_values_and_units) * Related CSS data types: + [`<frequency>`](frequency) + [`<percentage>`](percentage) css <percentage> <percentage> ============ The `<percentage>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) represents a percentage value. It is often used to define a size as relative to an element's parent object. Numerous properties can use percentages, such as [`width`](width), [`height`](height), [`margin`](margin), [`padding`](padding), and [`font-size`](font-size). **Note:** Only calculated values can be inherited. Thus, even if a percentage value is used on the parent property, a real value (such as a width in pixels for a [`<length>`](length) value) will be accessible on the inherited property, not the percentage value. Syntax ------ The `<percentage>` data type consists of a [`<number>`](number) followed by the percentage sign (`%`). Optionally, it may be preceded by a single `+` or `-` sign, although negative values are not valid for all properties. As with all CSS dimensions, there is no space between the symbol and the number. Interpolation ------------- When animated, values of the `<percentage>` data type are [interpolated](https://developer.mozilla.org/en-US/docs/Glossary/Interpolation) as real, floating-point numbers. The speed of the interpolation is determined by the [timing function](easing-function) associated with the animation. Examples -------- ### Width and margin-left ``` <div style="background-color:navy;"> <div style="width:50%; margin-left:20%; background-color:chartreuse;"> Width: 50%, Left margin: 20% </div> <div style="width:30%; margin-left:60%; background-color:pink;"> Width: 30%, Left margin: 60% </div> </div> ``` The above HTML will output: ### Font-size ``` <div style="font-size:18px;"> <p>Full-size text (18px)</p> <p><span style="font-size:50%;">50% (9px)</span></p> <p><span style="font-size:200%;">200% (36px)</span></p> </div> ``` The above HTML will output: Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # percentages](https://w3c.github.io/csswg-drafts/css-values/#percentages) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `percentage` | 1 | 12 | 1 | 3 | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | See also -------- * [`<length-percentage>`](length-percentage) * [CSS Values and Units](css_values_and_units) css counter-increment counter-increment ================= The `counter-increment` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property increases or decreases the value of a [CSS counter](css_counter_styles/using_css_counters) by a given value. Try it ------ **Note:** The counter's value can be reset to an arbitrary number using the [`counter-reset`](counter-reset) CSS property. Syntax ------ ``` /\* Increment "my-counter" by 1 \*/ counter-increment: my-counter; /\* Decrement "my-counter" by 1 \*/ counter-increment: my-counter -1; /\* Increment "counter1" by 1, and decrement "counter2" by 4 \*/ counter-increment: counter1 counter2 -4; /\* Do not increment/decrement anything: used to override less specific rules \*/ counter-increment: none; /\* Global values \*/ counter-increment: inherit; counter-increment: initial; counter-increment: revert; counter-increment: revert-layer; counter-increment: unset; ``` The `counter-increment` property is specified as either one of the following: * A `<custom-ident>` naming the counter, followed optionally by an `<integer>`. You may specify as many counters to increment as you want, with each name or name-number pair separated by a space. * The keyword value `none`. ### Values [`<custom-ident>`](custom-ident) The name of the counter to increment. [`<integer>`](integer) The value to add to the counter. Defaults to `1` if not specified. `none` No counter must be incremented. This is used as the default value, or to cancel an increment in more specific rules. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` counter-increment = [[](value_definition_syntax#brackets) [<counter-name>](counter-name) [<integer>](integer)[?](value_definition_syntax#question_mark) []](value_definition_syntax#brackets)[+](value_definition_syntax#plus) [|](value_definition_syntax#single_bar) none ``` Examples -------- ### Incrementing named counters ``` h1 { counter-increment: chapter section 2 page; /\* Increases the value of the chapter and page counters by 1, and the section counter by 2 \*/ } ``` Specifications -------------- | Specification | | --- | | [CSS Lists and Counters Module Level 3 # increment-set](https://w3c.github.io/csswg-drafts/css-lists/#increment-set) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `counter-increment` | 2 | 12 | 1 | 8 | 9.2 | 3 | 4.4 | 18 | 25 | 10.1 | 1 | 1.0 | See also -------- * [Using CSS Counters](css_counter_styles/using_css_counters) * [`counter-reset`](counter-reset) * [`counter-set`](counter-set) * [`@counter-style`](@counter-style) * The [`counter()`](counter) and [`counters()`](counters) functions css pointer-events pointer-events ============== The `pointer-events` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets under what circumstances (if any) a particular graphic element can become the [target](https://developer.mozilla.org/en-US/docs/Web/API/Event/target) of pointer events. Try it ------ Syntax ------ ``` /\* 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](https://developer.mozilla.org/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](https://developer.mozilla.org/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 `Tab` key. We would like to provide finer grained control (than just `auto` and `none`) in HTML for which parts of an element will cause it to "catch" pointer events, and when. To help us in deciding how `pointer-events` should be further extended for HTML, if you have any particular things that you would like to be able to do with this property, then please add them to the Use Cases section of [this wiki page](https://wiki.mozilla.org/SVG:Pointer-events) (don't worry about keeping it tidy). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` pointer-events = auto [|](value_definition_syntax#single_bar) bounding-box [|](value_definition_syntax#single_bar) visiblePainted [|](value_definition_syntax#single_bar) visibleFill [|](value_definition_syntax#single_bar) visibleStroke [|](value_definition_syntax#single_bar) visible [|](value_definition_syntax#single_bar) painted [|](value_definition_syntax#single_bar) fill [|](value_definition_syntax#single_bar) stroke [|](value_definition_syntax#single_bar) all [|](value_definition_syntax#single_bar) none ``` Examples -------- ### Disabling pointer events on all images This example disables pointer events (clicking, dragging, hovering, etc.) on all images. ``` img { pointer-events: none; } ``` ### Disabling pointer events on a single link This example disables pointer events on the link to `http://example.com`. #### HTML ``` <ul> <li><a href="https://developer.mozilla.org">MDN</a></li> <li><a href="http://example.com">example.com</a></li> </ul> ``` #### CSS ``` a[href="http://example.com"] { pointer-events: none; } ``` #### Result Specifications -------------- | Specification | | --- | | [Scalable Vector Graphics (SVG) 2 # PointerEventsProperty](https://svgwg.org/svg2-draft/interact.html#PointerEventsProperty) | Its extension to HTML elements, though present in early drafts of CSS Basic User Interface Module Level 3, has been pushed to its [level 4](https://wiki.csswg.org/spec/css4-ui#pointer-events). Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `pointer-events` | 1 | 12 | 1.5 | 11 | 9 | 4 | 2 | 18 | 4 | 14 | 3.2 | 1.0 | | `html_elements` | 2 | 12 | 3.6 | 11 | 15 | 4 | 37 | 18 | 4 | 14 | 3.2 | 1.0 | See also -------- * The SVG attribute `[pointer-events](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/pointer-events)` * The SVG attribute `[visibility](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/visibility)` * [WebKit Specs PointerEventsProperty](https://webkit.org/specs/PointerEventsProperty.html) extended for use in (X)HTML content * [`user-select`](user-select) - controls whether the user can select text
programming_docs
css :-moz-first-node :-moz-first-node ================ **Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future. The `:-moz-first-node` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) is a [Mozilla extension](https://developer.mozilla.org/en-US/docs/Web/CSS/Mozilla_Extensions) that represents any element that is the first child node of some other element. It differs from [`:first-child`](:first-child) because it does not match a first-child element with (non-whitespace) text before it. **Note:** Any whitespace at the start of an element is ignored for the determination of `:-moz-first-node`. Syntax ------ ``` :-moz-first-node ``` Examples -------- ### CSS ``` span:-moz-first-node { background-color: lime; } ``` ### HTML ``` <p> <span>This matches!</span> <span>This doesn't match.</span> </p> <p> Blahblah. <span>This doesn't match because it's preceded by text.</span> </p> ``` ### Result Specifications -------------- Not part of any standard. See also -------- * [`:-moz-last-node`](:-moz-last-node) * [`:first-child`](:first-child) css scroll-snap-coordinate scroll-snap-coordinate ====================== **Deprecated:** This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the [compatibility table](#browser_compatibility) at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time. **Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future. The `scroll-snap-coordinate` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the x and y coordinate positions within an element that will align with its nearest ancestor scroll container's [`scroll-snap-destination`](scroll-snap-destination) for each respective axis. ``` /\* Keyword value \*/ scroll-snap-coordinate: none; /\* <position> values \*/ scroll-snap-coordinate: 50px 50px; /\* Single coordinate \*/ scroll-snap-coordinate: 100px 100px, 100px bottom; /\* Multiple coordinates \*/ /\* Global values \*/ scroll-snap-coordinate: inherit; scroll-snap-coordinate: initial; scroll-snap-coordinate: unset; ``` If the element has been transformed, the snap coordinates are likewise transformed, thus aligning the snap points with the element as it is displayed. Syntax ------ ### Values `none` Specifies that the element does not contribute to a snap point. [`<position>`](position_value) Specifies the offset of the snap coordinates from the start edge of the element's border box. For each pairing, the first value gives the x coordinate of the snap coordinate, the second value its y coordinate. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements | | [Inherited](inheritance) | no | | Percentages | refer to the element’s border box | | [Computed value](computed_value) | as specified, but with relative lengths converted into absolute lengths | | Animation type | a [position](position_value#interpolation) | Formal syntax ------------- ``` scroll-snap-coordinate = none | <position># ``` Examples -------- ### Setting scroll snap coordinates #### HTML ``` <div id="container"> <div> <p>At coordinate (0, 0)</p> <div class="scrollContainer coordinate0"> <div>1</div> <div>2</div> <div>3</div> </div> </div> <div> <p>At coordinate (25, 0)</p> <div class="scrollContainer coordinate25"> <div>1</div> <div>2</div> <div>3</div> </div> </div> <div> <p>At coordinate (50, 0)</p> <div class="scrollContainer coordinate50"> <div>1</div> <div>2</div> <div>3</div> </div> </div> </div> ``` #### CSS ``` #container { display: flex; } #container > div:nth-child(-n + 2) { margin-right: 20px; } .scrollContainer { width: 100px; overflow: auto; white-space: nowrap; scroll-snap-type: mandatory; font-size: 0; } .scrollContainer > div { width: 100px; height: 100px; display: inline-block; line-height: 100px; text-align: center; font-size: 50px; } .coordinate0 > div { scroll-snap-coordinate: 0 0; } .coordinate25 > div { scroll-snap-coordinate: 25px 0; } .coordinate50 > div { scroll-snap-coordinate: 50px 0; } .scrollContainer > div:nth-child(even) { background-color: #87ea87; } .scrollContainer > div:nth-child(odd) { background-color: #87ccea; } ``` #### Result Specifications -------------- Not part of any standard. Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scroll-snap-coordinate` | No | No | 39-68 | No | No | No | No | No | 39-68 | No | No | No | See also -------- * [CSS Scroll Snap](css_scroll_snap) * [Well-Controlled Scrolling with CSS Scroll Snap](https://web.dev/css-scroll-snap/) css offset-distance offset-distance =============== The `offset-distance` CSS property specifies a position along an [`offset-path`](offset-path) for an element to be placed. Try it ------ Syntax ------ ``` /\* Default value \*/ offset-distance: 0; /\* the middle of the offset-path \*/ offset-distance: 50%; /\* a fixed length positioned along the path \*/ offset-distance: 40px; /\* Global values \*/ offset-distance: inherit; offset-distance: initial; offset-distance: revert; offset-distance: revert-layer; offset-distance: unset; ``` `[`<length-percentage>`](length-percentage)` A length that specifies how far the element is along the path (defined with [`offset-path`](offset-path)). 100% represents the total length of the path (when the `offset-path` is defined as a basic shape or `path()`). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | transformable elements | | [Inherited](inheritance) | no | | Percentages | refer to the total path length | | [Computed value](computed_value) | for [`<length>`](length) the absolute value, otherwise a percentage | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` offset-distance = <length-percentage> <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Using offset-distance in an animation The motion aspect in CSS Motion Path typically comes from animating the `offset-distance` property. If you want to animate an element along its full path, you would define its [`offset-path`](offset-path) and then set up an animation that takes the `offset-distance` from `0%` to `100%`. #### HTML ``` <div id="motion-demo"></div> ``` #### CSS ``` #motion-demo { offset-path: path("M20,20 C20,100 200,0 200,100"); animation: move 3000ms infinite alternate ease-in-out; width: 40px; height: 40px; background: cyan; } @keyframes move { 0% { offset-distance: 0%; } 100% { offset-distance: 100%; } } ``` #### Result Specifications -------------- | Specification | | --- | | [Motion Path Module Level 1 # offset-distance-property](https://drafts.fxtf.org/motion/#offset-distance-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `offset-distance` | 55 46 | 79 79 | 72 | No | 42 33 | preview | 55 46 | 55 46 | No | 42 33 | No | 6.0 5.0 | See also -------- * [`offset`](offset) * [`offset-anchor`](offset-anchor) * [`offset-path`](offset-path) * [`offset-position`](offset-position) * [`offset-rotate`](offset-rotate) css text-decoration-color text-decoration-color ===================== The `text-decoration-color` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the color of decorations added to text by [`text-decoration-line`](text-decoration-line). The color applies to decorations, such as underlines, overlines, strikethroughs, and wavy lines like those used to mark misspellings, in the scope of the property's value. Try it ------ CSS does not provide a direct mechanism for specifying a unique color for each line type. This effect can nevertheless be achieved by nesting elements, applying a different line type to each element (with the [`text-decoration-line`](text-decoration-line) property), and specifying the line color (with `text-decoration-color`) on a per-element basis. Syntax ------ ``` /\* <color> values \*/ text-decoration-color: currentcolor; text-decoration-color: red; text-decoration-color: #00ff00; text-decoration-color: rgba(255, 128, 128, 0.5); text-decoration-color: transparent; /\* Global values \*/ text-decoration-color: inherit; text-decoration-color: initial; text-decoration-color: revert; text-decoration-color: revert-layer; text-decoration-color: unset; ``` ### Values [`<color>`](color_value) The color of the line decoration. Accessibility concerns ---------------------- It is important to ensure that the contrast ratio between the color of the text, the background the text is placed over, and the text decoration line is high enough that people experiencing low vision conditions will be able to read the content of the page. Color contrast ratio is determined by comparing the luminosity of the text and background color values. Color alone should not be used to convey meaning. For example, change of text and text-decoration-color alone is not enough to indicate a link has focus. * [WebAIM: Color Contrast Checker](https://webaim.org/resources/contrastchecker/) * [MDN Understanding WCAG, Guideline 1.4 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background) * [Understanding Success Criterion 1.4.3 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html) Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `currentcolor` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | computed color | | Animation type | a [color](color_value#interpolation) | Formal syntax ------------- ``` text-decoration-color = [<color>](color_value) ``` Examples -------- ### Basic example ``` <p> This paragraph has <s>some erroneous text</s> inside it that I want to call attention to. </p> ``` ``` p { text-decoration-line: underline; text-decoration-color: cyan; } s { text-decoration-line: line-through; text-decoration-color: red; text-decoration-style: wavy; } ``` Specifications -------------- | Specification | | --- | | [CSS Text Decoration Module Level 3 # text-decoration-color-property](https://w3c.github.io/csswg-drafts/css-text-decor/#text-decoration-color-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `text-decoration-color` | 57 | 79 | 36 6-39 | No | 44 | 12.1 8 | 57 | 57 | 36 6-39 | 43 | 12.2 8 | 7.0 | See also -------- * When setting multiple line-decoration properties at once, it may be more convenient to use the [`text-decoration`](text-decoration) shorthand property instead. * The [`<color>`](color_value) data type * Other color-related properties: [`background-color`](background-color), [`border-color`](border-color), [`outline-color`](outline-color), [`text-decoration-color`](text-decoration-color), [`text-emphasis-color`](text-emphasis-color), [`text-shadow`](text-shadow), [`caret-color`](caret-color), and [`column-rule-color`](column-rule-color) * [Applying color to HTML elements using CSS](css_colors/applying_color) css border-block-end-color border-block-end-color ====================== The `border-block-end-color` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the color of the logical block-end border of an element, which maps to a physical border color depending on the element's writing mode, directionality, and text orientation. It corresponds to the [`border-top-color`](border-top-color), [`border-right-color`](border-right-color), [`border-bottom-color`](border-bottom-color), or [`border-left-color`](border-left-color) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ Syntax ------ ``` border-block-end-color: yellow; border-block-end-color: #f5f6f7; /\* Global values \*/ border-block-end-color: inherit; border-block-end-color: initial; border-block-end-color: revert; border-block-end-color: revert-layer; border-block-end-color: unset; ``` Related properties are [`border-block-start-color`](border-block-start-color), [`border-inline-start-color`](border-inline-start-color), and [`border-inline-end-color`](border-inline-end-color), which define the other border colors of the element. ### Values `<'color'>` The color of the border. See [`color`](color). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `currentcolor` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | computed color | | Animation type | a [color](color_value#interpolation) | Formal syntax ------------- ``` border-block-end-color = <'border-top-color'> ``` Examples -------- ### Border color with vertical text #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; border: 10px solid blue; border-block-end-color: red; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # border-color](https://w3c.github.io/csswg-drafts/css-logical/#border-color) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-block-end-color` | 69 | 79 | 41 | No | 56 | 12.1 | 69 | 69 | 41 | 48 | 12.2 | 10.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * This property maps to one of the physical border properties: [`border-top-color`](border-top-color), [`border-right-color`](border-right-color), [`border-bottom-color`](border-bottom-color), or [`border-left-color`](border-left-color). * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css perspective perspective =========== The `perspective` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property determines the distance between the z=0 plane and the user in order to give a 3D-positioned element some perspective. Try it ------ Syntax ------ ``` /\* Keyword value \*/ perspective: none; /\* <length> values \*/ perspective: 20px; perspective: 3.5em; /\* Global values \*/ perspective: inherit; perspective: initial; perspective: revert; perspective: revert-layer; perspective: unset; ``` ### Values `none` Indicates that no perspective transform is to be applied. `<length>` A [`<length>`](length) giving the distance from the user to the z=0 plane. It is used to apply a perspective transform to the children of the element. Negative values are syntax errors. If the value is smaller than `1px`, it is clamped to `1px`. Description ----------- Each 3D element with z>0 becomes larger; each 3D-element with z<0 becomes smaller. The strength of the effect is determined by the value of this property. Large values of `perspective` cause a small transformation; small values of `perspective` cause a large transformation. The parts of the 3D elements that are behind the user — i.e. their z-axis coordinates are greater than the value of the `perspective` CSS property — are not drawn. The *vanishing point* is by default placed at the center of the element, but its position can be changed using the [`perspective-origin`](perspective-origin) property. Using this property with a value other than `none` creates a new [stacking context](css_positioning/understanding_z_index/the_stacking_context). Also, in that case, the object will act as a containing block for `position: fixed` elements that it contains. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | transformable elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | the absolute length or `none` | | Animation type | a [length](length#interpolation) | | Creates [stacking context](css_positioning/understanding_z_index/the_stacking_context) | yes | Formal syntax ------------- ``` perspective = none [|](value_definition_syntax#single_bar) [<length [0,∞]>](length) ``` Examples -------- ### Setting perspective An example showing how a cube varies if the `perspective` is set at different positions is given in [Using CSS transforms > Setting perspective](css_transforms/using_css_transforms#setting_perspective). Specifications -------------- | Specification | | --- | | [CSS Transforms Module Level 2 # perspective-property](https://w3c.github.io/csswg-drafts/css-transforms-2/#perspective-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `perspective` | 36 12 | 12 12 | 49 16 10 | 10 | 23 15 | 9 4 | 4.4 3 | 36 18 | 49 16 10 | 24 14 | 9 2 | 3.0 1.0 | See also -------- * [Using CSS Transforms](css_transforms/using_css_transforms) css :out-of-range :out-of-range ============= The `:out-of-range` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) represents an [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) element whose current value is outside the range limits specified by the [`min`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-min) and [`max`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-max) attributes. Try it ------ This pseudo-class is useful for giving the user a visual indication that a field's current value is outside the permitted limits. **Note:** This pseudo-class only applies to elements that have (and can take) a range limitation. In the absence of such a limitation, the element can neither be "in-range" nor "out-of-range." Syntax ------ ``` :out-of-range ``` Examples -------- ### HTML ``` <form action="" id="form1"> <p>Values between 1 and 10 are valid.</p> <ul> <li> <input id="value1" name="value1" type="number" placeholder="1 to 10" min="1" max="10" value="12" /> <label for="value1">Your value is </label> </li> </ul> </form> ``` ### CSS ``` li { list-style: none; margin-bottom: 1em; } input { border: 1px solid black; } input:in-range { background-color: rgba(0, 255, 0, 0.25); } input:out-of-range { background-color: rgba(255, 0, 0, 0.25); border: 2px solid red; } input:in-range + label::after { content: "okay."; } input:out-of-range + label::after { content: "out of range!"; } ``` ### Result Specifications -------------- | Specification | | --- | | [HTML Standard # selector-out-of-range](https://html.spec.whatwg.org/multipage/semantics-other.html#selector-out-of-range) | | [Selectors Level 4 # out-of-range-pseudo](https://w3c.github.io/csswg-drafts/selectors/#out-of-range-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:out-of-range` | 10 | 13 | 29 | No | 11 | 5.1 | 2.2 | 18 | 16 | 11 | 5 | 1.0 | See also -------- * [`:in-range`](:in-range) * [Form data validation](https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation)
programming_docs
css border-block-start-style border-block-start-style ======================== The `border-block-start-style` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the style of the logical block start border of an element, which maps to a physical border style depending on the element's writing mode, directionality, and text orientation. It corresponds to the [`border-top-style`](border-top-style), [`border-right-style`](border-right-style), [`border-bottom-style`](border-bottom-style), or [`border-left-style`](border-left-style) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ Syntax ------ ``` /\* <'border-style'> values \*/ border-block-start-style: dashed; border-block-start-style: dotted; border-block-start-style: groove; /\* Global values \*/ border-block-start-style: inherit; border-block-start-style: initial; border-block-start-style: revert; border-block-start-style: revert-layer; border-block-start-style: unset; ``` Related properties are [`border-block-end-style`](border-block-end-style), [`border-inline-start-style`](border-inline-start-style), and [`border-inline-end-style`](border-inline-end-style), which define the other border styles of the element. ### Values `<'border-style'>` The line style of the border. See [`border-style`](border-style). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` border-block-start-style = <'border-top-style'> ``` Examples -------- ### Dashed border with vertical text #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; border: 5px solid blue; border-block-start-style: dashed; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # border-style](https://w3c.github.io/csswg-drafts/css-logical/#border-style) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-block-start-style` | 69 | 79 | 41 | No | 56 | 12.1 | 69 | 69 | 41 | 48 | 12.2 | 10.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * This property maps to one of the physical border properties: [`border-top-style`](border-top-style), [`border-right-style`](border-right-style), [`border-bottom-style`](border-bottom-style), or [`border-left-style`](border-left-style). * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css flex-wrap flex-wrap ========= The `flex-wrap` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets whether flex items are forced onto one line or can wrap onto multiple lines. If wrapping is allowed, it sets the direction that lines are stacked. Try it ------ See [Using CSS flexible boxes](css_flexible_box_layout/basic_concepts_of_flexbox) for more properties and information. Syntax ------ ``` flex-wrap: nowrap; /\* Default value \*/ flex-wrap: wrap; flex-wrap: wrap-reverse; /\* Global values \*/ flex-wrap: inherit; flex-wrap: initial; flex-wrap: revert; flex-wrap: revert-layer; flex-wrap: unset; ``` The `flex-wrap` property is specified as a single keyword chosen from the list of values below. ### Values The following values are accepted: `nowrap` The flex items are laid out in a single line which may cause the flex container to overflow. The **cross-start** is either equivalent to **start** or **before** depending on the [`flex-direction`](flex-direction) value. This is the default value. `wrap` The flex items break into multiple lines. The **cross-start** is either equivalent to **start** or **before** depending `flex-direction` value and the **cross-end** is the opposite of the specified **cross-start**. `wrap-reverse` Behaves the same as `wrap` but **cross-start** and **cross-end** are permuted. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `nowrap` | | Applies to | flex containers | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` flex-wrap = nowrap [|](value_definition_syntax#single_bar) wrap [|](value_definition_syntax#single_bar) wrap-reverse ``` Examples -------- ### Setting flex container wrap values #### HTML ``` <h4>This is an example for flex-wrap:wrap</h4> <div class="content"> <div class="red">1</div> <div class="green">2</div> <div class="blue">3</div> </div> <h4>This is an example for flex-wrap:nowrap</h4> <div class="content1"> <div class="red">1</div> <div class="green">2</div> <div class="blue">3</div> </div> <h4>This is an example for flex-wrap:wrap-reverse</h4> <div class="content2"> <div class="red">1</div> <div class="green">2</div> <div class="blue">3</div> </div> ``` #### CSS ``` /\* Common Styles \*/ .content, .content1, .content2 { color: #fff; font: 100 24px/100px sans-serif; height: 150px; width: 897px; text-align: center; } .content div, .content1 div, .content2 div { height: 50%; width: 300px; } .red { background: orangered; } .green { background: yellowgreen; } .blue { background: steelblue; } /\* Flexbox Styles \*/ .content { display: flex; flex-wrap: wrap; } .content1 { display: flex; flex-wrap: nowrap; } .content2 { display: flex; flex-wrap: wrap-reverse; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Flexible Box Layout Module Level 1 # flex-wrap-property](https://w3c.github.io/csswg-drafts/css-flexbox/#flex-wrap-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `flex-wrap` | 29 21 | 12 | 28 | 11 Partial support due to large number of bugs present. See [Flexbugs](https://github.com/philipwalton/flexbugs). | 17 | 9 7 | ≤37 4.4 | 29 25 | 52 | 18 | 9 7 | 2.0 1.5 | See also -------- * CSS Flexbox Guide: *[Basic Concepts of Flexbox](css_flexible_box_layout/basic_concepts_of_flexbox)* * CSS Flexbox Guide: *[Mastering wrapping of flex items](css_flexible_box_layout/mastering_wrapping_of_flex_items)* css :is() :is() ===== The `:is()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) function takes a selector list as its argument, and selects any element that can be selected by one of the selectors in that list. This is useful for writing large selectors in a more compact form. **Note:** Originally named `:matches()` (and `:any()`), this selector was renamed to `:is()` in [CSSWG issue #3258](https://github.com/w3c/csswg-drafts/issues/3258). Try it ------ Pseudo-elements are not valid in the selector list for `:is()`. ### Difference between :is() and :where() The difference between the two is that `:is()` counts towards the specificity of the overall selector (it takes the specificity of its most specific argument), whereas [`:where()`](:where) has a specificity value of 0. This is demonstrated by the [example on the `:where()` reference page](:where#examples). ### Forgiving Selector Parsing The specification defines `:is()` and `:where()` as accepting a [forgiving selector list](https://drafts.csswg.org/selectors-4/#typedef-forgiving-selector-list). In CSS when using a selector list, if any of the selectors are invalid then the whole list is deemed invalid. When using `:is()` or `:where()` instead of the whole list of selectors being deemed invalid if one fails to parse, the incorrect or unsupported selector will be ignored and the others used. ``` :is(:valid, :unsupported) { /\* … \*/ } ``` Will still parse correctly and match `:valid` even in browsers which don't support `:unsupported`, whereas: ``` :valid, :unsupported { /\* … \*/ } ``` Will be ignored in browsers which don't support `:unsupported` even if they support `:valid`. Examples -------- ### Simplifying list selectors The `:is()` pseudo-class can greatly simplify your CSS selectors. For example, take the following CSS: ``` /\* 3-deep (or more) unordered lists use a square \*/ ol ol ul, ol ul ul, ol menu ul, ol dir ul, ol ol menu, ol ul menu, ol menu menu, ol dir menu, ol ol dir, ol ul dir, ol menu dir, ol dir dir, ul ol ul, ul ul ul, ul menu ul, ul dir ul, ul ol menu, ul ul menu, ul menu menu, ul dir menu, ul ol dir, ul ul dir, ul menu dir, ul dir dir, menu ol ul, menu ul ul, menu menu ul, menu dir ul, menu ol menu, menu ul menu, menu menu menu, menu dir menu, menu ol dir, menu ul dir, menu menu dir, menu dir dir, dir ol ul, dir ul ul, dir menu ul, dir dir ul, dir ol menu, dir ul menu, dir menu menu, dir dir menu, dir ol dir, dir ul dir, dir menu dir, dir dir dir { list-style-type: square; } ``` You can replace it with: ``` /\* 3-deep (or more) unordered lists use a square \*/ :is(ol, ul, menu, dir) :is(ol, ul, menu, dir) :is(ul, menu, dir) { list-style-type: square; } ``` ### Simplifying section selectors The `:is()` pseudo-class is particularly useful when dealing with HTML [sections and headings](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements). Since [`<section>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/section), [`<article>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/article), [`<aside>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/aside), and [`<nav>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/nav) are commonly nested together, without `:is()`, styling them to match one another can be tricky. For example, without `:is()`, styling all the [`<h1>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements) elements at different depths could be very complicated: ``` /\* Level 0 \*/ h1 { font-size: 30px; } /\* Level 1 \*/ section h1, article h1, aside h1, nav h1 { font-size: 25px; } /\* Level 2 \*/ section section h1, section article h1, section aside h1, section nav h1, article section h1, article article h1, article aside h1, article nav h1, aside section h1, aside article h1, aside aside h1, aside nav h1, nav section h1, nav article h1, nav aside h1, nav nav h1 { font-size: 20px; } /\* Level 3 \*/ /\* don't even think about it! \*/ ``` Using `:is()`, though, it's much easier: ``` /\* Level 0 \*/ h1 { font-size: 30px; } /\* Level 1 \*/ :is(section, article, aside, nav) h1 { font-size: 25px; } /\* Level 2 \*/ :is(section, article, aside, nav) :is(section, article, aside, nav) h1 { font-size: 20px; } /\* Level 3 \*/ :is(section, article, aside, nav) :is(section, article, aside, nav) :is(section, article, aside, nav) h1 { font-size: 15px; } ``` ### :is() does not select pseudo-elements The `:is()` pseudo-class does not match pseudo-elements. So rather than this: ``` some-element:is(::before, ::after) { display: block; } ``` instead do: ``` some-element::before, some-element::after { display: block; } ``` Syntax ------ ``` :is( <forgiving-selector-list> ) ``` Specifications -------------- | Specification | | --- | | [Selectors Level 4 # matches-pseudo](https://w3c.github.io/csswg-drafts/selectors/#matches-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:is` | 88 12 Doesn't support combinators. | 88 79 Doesn't support combinators. | 78 4 ["Doesn't support combinators.", "See [bug 906353](https://bugzil.la/906353)."] | No | 74 15 Doesn't support combinators. | 14 9 5 Doesn't support combinators. | 88 ≤37 Doesn't support combinators. | 88 18 Doesn't support combinators. | 79 4 ["Doesn't support combinators.", "See [bug 906353](https://bugzil.la/906353)."] | 63 14 Doesn't support combinators. | 14 9 5 Doesn't support combinators. | 15.0 9.0-10.0 1.0 | | `forgiving_selector_list` | 88 | 88 | 82 | No | 74 | 14 | 88 | 88 | 82 | 63 | 14 | 15.0 | See also -------- * [`:where()`](:where) - Like `:is()`, but with 0 <specificity>. * [Selector list](selector_list) * [Web components](https://developer.mozilla.org/en-US/docs/Web/Web_Components) css :disabled :disabled ========= The `:disabled` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](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. Try it ------ Syntax ------ ``` :disabled ``` Examples -------- This example shows a basic shipping form. It uses the [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript) [`change`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event) event to let the user enable/disable the billing fields. ### 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 ``` input[type="text"]:disabled { background: #ccc; } ``` ### JavaScript ``` // 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 Specifications -------------- | Specification | | --- | | [HTML Standard # selector-disabled](https://html.spec.whatwg.org/multipage/semantics-other.html#selector-disabled) | | [Selectors Level 4 # enableddisabled](https://w3c.github.io/csswg-drafts/selectors/#enableddisabled) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:disabled` | 1 | 12 Edge does not recognize `:disabled` on the [`<fieldset>`](https://developer.mozilla.org/docs/Web/HTML/Element/fieldset) element. | 1 | 9 Internet Explorer does not recognize `:disabled` on the [`<fieldset>`](https://developer.mozilla.org/docs/Web/HTML/Element/fieldset) element. | 9 | 3.1 | 2 | 18 | 4 | 10.1 | 2 | 1.0 | See also -------- * [`:enabled`](:enabled) css :focus-visible :focus-visible ============== The `:focus-visible` pseudo-class applies while an element matches the [`:focus`](:focus) pseudo-class and the UA ([User Agent](https://developer.mozilla.org/en-US/docs/Glossary/User_agent)) determines via heuristics that the focus should be made evident on the element. (Many browsers show a "focus ring" by default in this case.) Try it ------ This selector is useful to provide a different focus indicator based on the user's input modality (mouse vs. keyboard). Syntax ------ ``` :focus-visible ``` Examples -------- ### Basic example In this example, the `:focus-visible` selector uses the UA's behavior to determine when to match. Compare what happens when you click on the different controls with a mouse, versus when you tab through them using a keyboard. Note the difference in behavior from elements styled with `:focus`. ``` <input value="Default styles" /><br /> <button>Default styles</button><br /> <input class="focus-only" value=":focus only" /><br /> <button class="focus-only">:focus only</button><br /> <input class="focus-visible-only" value=":focus-visible only" /><br /> <button class="focus-visible-only">:focus-visible only</button> ``` ``` input, button { margin: 10px; } .focus-only:focus { outline: 2px solid black; } .focus-visible-only:focus-visible { outline: 4px dashed darkorange; } ``` ### Providing a :focus fallback If your code has to work in old browser versions that do not support `:focus-visible`, check supports of `:focus-visible` with [`@supports`](@supports) and repeat the same focus styling in it, but inside a `:focus` rule. Note that even if you do not specify anything at all for `:focus`, old browsers will simply display the native outline, which can be enough. ``` <button class="button with-fallback" type="button"> Button with fallback </button> <button class="button without-fallback" type="button"> Button without fallback </button> ``` ``` .button { margin: 10px; border: 2px solid darkgray; border-radius: 4px; } .button:focus-visible { /\* Draw the focus when :focus-visible is supported \*/ outline: 3px solid deepskyblue; outline-offset: 3px; } @supports not selector(:focus-visible) { .button.with-fallback:focus { /\* Fallback for browsers without :focus-visible support \*/ outline: 3px solid deepskyblue; outline-offset: 3px; } } ``` Accessibility concerns ---------------------- ### Low vision Make sure the visual focus indicator can be seen by people with low vision. This will also benefit anyone use a screen in a brightly lit space (like outside in the sun). [WCAG 2.1 SC 1.4.11 Non-Text Contrast](https://www.w3.org/WAI/WCAG21/Understanding/non-text-contrast.html) requires that the visual focus indicator be at least 3 to 1. * Accessible Visual Focus Indicators: [Give Your Site Some Focus! Tips for Designing Useful and Usable Focus Indicators](https://www.deque.com/blog/give-site-focus-tips-designing-usable-focus-indicators/) ### Cognition It may not be obvious as to why the focus indicator is appearing and disappearing if a person is using mixed forms of input. For users with cognitive concerns, or who are less technologically literate, this lack of consistent behavior for interactive elements may be confusing. Specifications -------------- | Specification | | --- | | [Selectors Level 4 # the-focus-visible-pseudo](https://w3c.github.io/csswg-drafts/selectors/#the-focus-visible-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:focus-visible` | 86 | 86 | 85 4 | No | 72 | 15.4 | 86 | 86 | 85 4 | 61 | 15.4 | 14.0 | See also -------- * [`:focus`](:focus) * [`:focus-within`](:focus-within) * [A polyfill for `:focus-visible`](https://github.com/WICG/focus-visible)
programming_docs
css <display-inside> <display-inside> ================ These keywords specify the element's inner [`display`](display) type, which defines the type of formatting context that lays out its contents (assuming it is a non-replaced element). These keywords are used as values of the `display` property, and can be used for legacy purposes as a single keyword, or as defined in the Level 3 specification alongside a value from the [`<display-outside>`](display-outside) keywords. Syntax ------ Valid `<display-inside>` values: `flow` Experimental The element lays out its contents using flow layout (block-and-inline layout). If its outer display type is `inline` or `run-in`, and it is participating in a block or inline formatting context, then it generates an inline box. Otherwise it generates a block container box. Depending on the value of other properties (such as [`position`](position), [`float`](float), or [`overflow`](overflow)) and whether it is itself participating in a block or inline formatting context, it either establishes a new [block formatting context](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context) (BFC) for its contents or integrates its contents into its parent formatting context. `flow-root` The element generates a block element box that establishes a new [block formatting context](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context), defining where the formatting root lies. `table` These elements behave like HTML [`<table>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table) elements. It defines a block-level box. `flex` The element behaves like a block element and lays out its content according to the [flexbox model](css_flexible_box_layout). `grid` The element behaves like a block element and lays out its content according to the [grid model](css_grid_layout/basic_concepts_of_grid_layout). `ruby` Experimental The element behaves like an inline element and lays out its content according to the ruby formatting model. It behaves like the corresponding HTML [`<ruby>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ruby) elements. **Note:** Browsers that support the two value syntax, on finding the inner value only, such as when `display: flex` or `display: grid` is specified, will set their outer value to `block`. This will result in expected behavior; for example if you specify an element to be `display: grid`, you would expect that the box created on the grid container would be a block level box. Formal syntax ------------- ``` <display-inside> = flow [|](value_definition_syntax#single_bar) flow-root [|](value_definition_syntax#single_bar) table [|](value_definition_syntax#single_bar) flex [|](value_definition_syntax#single_bar) grid [|](value_definition_syntax#single_bar) ruby ``` Examples -------- In this example the parent box has been given `display: flow-root` and so establishes a new BFC and contains the floated item. ### HTML ``` <div class="box"> <div class="float">I am a floated box!</div> <p>I am content inside the container.</p> </div> ``` ### CSS ``` .box { background-color: rgb(224, 206, 247); border: 5px solid rebeccapurple; display: flow-root; } .float { float: left; width: 200px; height: 150px; background-color: white; border: 1px solid black; padding: 10px; } ``` ### Result Specifications -------------- | Specification | | --- | | [CSS Display Module Level 3 # typedef-display-inside](https://drafts.csswg.org/css-display/#typedef-display-inside) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `display-inside` | No | 12-79 | 38 | 7 | No | No | No | No | 38 | No | No | No | | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `display-inside` | 29 21 | 12 | 20 Firefox 28 added multi-line flexbox support. | 11 IE incorrectly positions inline block content inside flex containers. See the [discussion on Microsoft Answers](https://answers.microsoft.com/en-us/ie/forum/ie11-iewindows_10/inline-block-content-in-a-flex-container-not/deea64e2-933b-4bd2-a98c-62be16d04b57). 8 IE incorrectly positions inline block content inside flex containers. See the [discussion on Microsoft Answers](https://answers.microsoft.com/en-us/ie/forum/ie11-iewindows_10/inline-block-content-in-a-flex-container-not/deea64e2-933b-4bd2-a98c-62be16d04b57). | 16 15 12.1-15 | 9 7 | ≤37 4.4 | 29 25 | 20 Firefox 28 added multi-line flexbox support. | 16 14 12.1-14 | 9 7 | 2.0 1.5 | | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `display-inside` | 57 | 16 12 | 52 | 10 Internet Explorer implements an older version of the specification. | 44 | 10.1 | 57 | 57 | 52 | 43 | 10.3 | 6.0 Samsung Internet added this earlier than the corresponding Chrome version would indicate. | | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `display-inside` | 1 | 12 | 1 | 8 | 7 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `display-inside` | 58 | 79 | 53 | No | 45 | 13 | 58 | 58 | 53 | 43 | 13 | 7.0 | | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `display-inside` | No | No | 70 | No | No | 15 | No | No | No | No | 15 | No | ### css.properties.display.multi-keyword\_values BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. ### css.properties.display.flow-root BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. ### css.properties.display.table\_values BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. ### css.properties.display.grid BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. ### css.properties.display.flex BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. ### css.properties.display.ruby\_values BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. See also -------- * [`display`](display) + [`<display-outside>`](display-outside) + [`<display-listitem>`](display-listitem) + [`<display-internal>`](display-internal) + [`<display-box>`](display-box) + [`<display-legacy>`](display-legacy) * [Basic Concepts of Flexbox](css_flexible_box_layout/basic_concepts_of_flexbox) * [Basic Concepts of Grid Layout](css_grid_layout/basic_concepts_of_grid_layout) css scroll-padding-block scroll-padding-block ==================== The `scroll-padding-block` [shorthand property](shorthand_properties) sets the scroll padding of an element in the block dimension. Try it ------ The scroll-padding properties define offsets for 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. Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`scroll-padding-block-end`](scroll-padding-block-end) * [`scroll-padding-block-start`](scroll-padding-block-start) Syntax ------ ``` /\* Keyword values \*/ scroll-padding-block: auto; /\* <length> values \*/ scroll-padding-block: 10px; scroll-padding-block: 1em 0.5em; scroll-padding-block: 10%; /\* Global values \*/ scroll-padding-block: inherit; scroll-padding-block: initial; scroll-padding-block: revert; scroll-padding-block: revert-layer; scroll-padding-block: unset; ``` ### Values `<length-percentage>` An inwards offset from the corresponding 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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`scroll-padding-block-start`](scroll-padding-block-start): `auto` * [`scroll-padding-block-end`](scroll-padding-block-end): `auto` | | Applies to | scroll containers | | [Inherited](inheritance) | no | | Percentages | relative to the scroll container's scrollport | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`scroll-padding-block-start`](scroll-padding-block-start): as specified * [`scroll-padding-block-end`](scroll-padding-block-end): as specified | | Animation type | by computed value type | Formal syntax ------------- ``` scroll-padding-block = [[](value_definition_syntax#brackets) auto [|](value_definition_syntax#single_bar) [<length-percentage [0,∞]>](length-percentage) []](value_definition_syntax#brackets)[{1,2}](value_definition_syntax#curly_braces) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Specifications -------------- | Specification | | --- | | [CSS Scroll Snap Module Level 1 # propdef-scroll-padding-block](https://w3c.github.io/csswg-drafts/css-scroll-snap/#propdef-scroll-padding-block) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scroll-padding-block` | 69 | 79 | 68 | No | 56 | 15 | 69 | 69 | 68 | 48 | 15 | 10.0 | See also -------- * [CSS Scroll Snap](css_scroll_snap) * [Well-Controlled Scrolling with CSS Scroll Snap](https://web.dev/css-scroll-snap/) css <named-color> <named-color> ============= The `<named-color>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) is the name of a color, such as `red`, `blue`, `black`, or `lightseagreen`. Syntactically, a `<named-color>` is an [`<ident>`](ident). A `<named-color>` value can be used anywhere a [`<color>`](color_value) can be used. Syntax ------ ``` color: red; color: orange; color: tan; color: rebeccapurple; color: transparent; ``` ### Value #### CSS Level 1 values [CSS Level 1](https://www.w3.org/TR/CSS1/) only included 16 basic colors, called the *VGA colors* as they were taken from the set of displayable colors on [VGA](https://en.wikipedia.org/wiki/VGA) graphics cards. | Keyword | RGB hex value | Sample | | --- | --- | --- | | `black` | `#000000` | | | `silver` | `#c0c0c0` | | | `gray` | `#808080` | | | `white` | `#ffffff` | | | `maroon` | `#800000` | | | `red` | `#ff0000` | | | `purple` | `#800080` | | | `fuchsia` | `#ff00ff` | | | `green` | `#008000` | | | `lime` | `#00ff00` | | | `olive` | `#808000` | | | `yellow` | `#ffff00` | | | `navy` | `#000080` | | | `blue` | `#0000ff` | | | `teal` | `#008080` | | | `aqua` | `#00ffff` | | ### CSS Level 2 values The following value is defined in [CSS Level 2](https://www.w3.org/TR/CSS2/). | Keyword | RGB hex value | Sample | | --- | --- | --- | | `orange` | `#ffa500` | | ### CSS Level 3 values Although various colors not in the specification (mostly adapted from the X11 colors list) were supported by early browsers, it wasn't until SVG 1.0 and [CSS Colors Level 3](https://drafts.csswg.org/css-color-3/) that they were formally defined. They are called the *extended color keywords*, the *X11 colors*, or the *SVG colors*. | Keyword | RGB hex value | Sample | | --- | --- | --- | | `aliceblue` | `#f0f8ff` | | | `antiquewhite` | `#faebd7` | | | `aquamarine` | `#7fffd4` | | | `azure` | `#f0ffff` | | | `beige` | `#f5f5dc` | | | `bisque` | `#ffe4c4` | | | `blanchedalmond` | `#ffebcd` | | | `blueviolet` | `#8a2be2` | | | `brown` | `#a52a2a` | | | `burlywood` | `#deb887` | | | `cadetblue` | `#5f9ea0` | | | `chartreuse` | `#7fff00` | | | `chocolate` | `#d2691e` | | | `coral` | `#ff7f50` | | | `cornflowerblue` | `#6495ed` | | | `cornsilk` | `#fff8dc` | | | `crimson` | `#dc143c` | | | `cyan`(synonym of `aqua`) | `#00ffff` | | | `darkblue` | `#00008b` | | | `darkcyan` | `#008b8b` | | | `darkgoldenrod` | `#b8860b` | | | `darkgray` | `#a9a9a9` | | | `darkgreen` | `#006400` | | | `darkgrey` | `#a9a9a9` | | | `darkkhaki` | `#bdb76b` | | | `darkmagenta` | `#8b008b` | | | `darkolivegreen` | `#556b2f` | | | `darkorange` | `#ff8c00` | | | `darkorchid` | `#9932cc` | | | `darkred` | `#8b0000` | | | `darksalmon` | `#e9967a` | | | `darkseagreen` | `#8fbc8f` | | | `darkslateblue` | `#483d8b` | | | `darkslategray` | `#2f4f4f` | | | `darkslategrey` | `#2f4f4f` | | | `darkturquoise` | `#00ced1` | | | `darkviolet` | `#9400d3` | | | `deeppink` | `#ff1493` | | | `deepskyblue` | `#00bfff` | | | `dimgray` | `#696969` | | | `dimgrey` | `#696969` | | | `dodgerblue` | `#1e90ff` | | | `firebrick` | `#b22222` | | | `floralwhite` | `#fffaf0` | | | `forestgreen` | `#228b22` | | | `gainsboro` | `#dcdcdc` | | | `ghostwhite` | `#f8f8ff` | | | `gold` | `#ffd700` | | | `goldenrod` | `#daa520` | | | `greenyellow` | `#adff2f` | | | `grey` | `#808080` | | | `honeydew` | `#f0fff0` | | | `hotpink` | `#ff69b4` | | | `indianred` | `#cd5c5c` | | | `indigo` | `#4b0082` | | | `ivory` | `#fffff0` | | | `khaki` | `#f0e68c` | | | `lavender` | `#e6e6fa` | | | `lavenderblush` | `#fff0f5` | | | `lawngreen` | `#7cfc00` | | | `lemonchiffon` | `#fffacd` | | | `lightblue` | `#add8e6` | | | `lightcoral` | `#f08080` | | | `lightcyan` | `#e0ffff` | | | `lightgoldenrodyellow` | `#fafad2` | | | `lightgray` | `#d3d3d3` | | | `lightgreen` | `#90ee90` | | | `lightgrey` | `#d3d3d3` | | | `lightpink` | `#ffb6c1` | | | `lightsalmon` | `#ffa07a` | | | `lightseagreen` | `#20b2aa` | | | `lightskyblue` | `#87cefa` | | | `lightslategray` | `#778899` | | | `lightslategrey` | `#778899` | | | `lightsteelblue` | `#b0c4de` | | | `lightyellow` | `#ffffe0` | | | `limegreen` | `#32cd32` | | | `linen` | `#faf0e6` | | | `magenta`(synonym of `fuchsia`) | `#ff00ff` | | | `mediumaquamarine` | `#66cdaa` | | | `mediumblue` | `#0000cd` | | | `mediumorchid` | `#ba55d3` | | | `mediumpurple` | `#9370db` | | | `mediumseagreen` | `#3cb371` | | | `mediumslateblue` | `#7b68ee` | | | `mediumspringgreen` | `#00fa9a` | | | `mediumturquoise` | `#48d1cc` | | | `mediumvioletred` | `#c71585` | | | `midnightblue` | `#191970` | | | `mintcream` | `#f5fffa` | | | `mistyrose` | `#ffe4e1` | | | `moccasin` | `#ffe4b5` | | | `navajowhite` | `#ffdead` | | | `oldlace` | `#fdf5e6` | | | `olivedrab` | `#6b8e23` | | | `orangered` | `#ff4500` | | | `orchid` | `#da70d6` | | | `palegoldenrod` | `#eee8aa` | | | `palegreen` | `#98fb98` | | | `paleturquoise` | `#afeeee` | | | `palevioletred` | `#db7093` | | | `papayawhip` | `#ffefd5` | | | `peachpuff` | `#ffdab9` | | | `peru` | `#cd853f` | | | `pink` | `#ffc0cb` | | | `plum` | `#dda0dd` | | | `powderblue` | `#b0e0e6` | | | `rosybrown` | `#bc8f8f` | | | `royalblue` | `#4169e1` | | | `saddlebrown` | `#8b4513` | | | `salmon` | `#fa8072` | | | `sandybrown` | `#f4a460` | | | `seagreen` | `#2e8b57` | | | `seashell` | `#fff5ee` | | | `sienna` | `#a0522d` | | | `skyblue` | `#87ceeb` | | | `slateblue` | `#6a5acd` | | | `slategray` | `#708090` | | | `slategrey` | `#708090` | | | `snow` | `#fffafa` | | | `springgreen` | `#00ff7f` | | | `steelblue` | `#4682b4` | | | `tan` | `#d2b48c` | | | `thistle` | `#d8bfd8` | | | `tomato` | `#ff6347` | | | `transparent` | See [transparent](#transparent). | | | `turquoise` | `#40e0d0` | | | `violet` | `#ee82ee` | | | `wheat` | `#f5deb3` | | | `whitesmoke` | `#f5f5f5` | | | `yellowgreen` | `#9acd32` | | #### transparent The `transparent` keyword represents a fully transparent color. This makes the background behind the colored item completely visible. Technically, `transparent` is a shortcut for `rgba(0,0,0,0)`. To prevent unexpected behavior, such as in a [`<gradient>`](gradient), the current CSS spec states that `transparent` should be calculated in the [alpha-premultiplied color space](https://www.w3.org/TR/css-color-4/#interpolation-alpha). However, be aware that older browsers may treat it as black with an alpha value of `0`. The `transparent` keyword wasn't a true color in CSS Level 2 (Revision 1). It was a special keyword that could be used instead of a regular `<color>` value on two CSS properties: [`background`](background) and [`border`](border). It was essentially added to allow developers to override an inherited solid color. With the advent of alpha channels in CSS Colors Level 3, `transparent` was redefined as a true color. It can now be used wherever a `<color>` value can be used. ### CSS Level 4 values [CSS Colors Level 4](https://drafts.csswg.org/css-color-4/) added the `rebeccapurple` keyword [to honor web pioneer Eric Meyer](https://codepen.io/trezy/post/honoring-a-great-man). | Keyword | RGB hex value | Sample | | --- | --- | --- | | [`rebeccapurple`](https://en.wikipedia.org/wiki/Eric_A._Meyer#Personal_life) | `#663399` | | Description ----------- All names specify a color in the [sRGB color space](https://en.wikipedia.org/wiki/SRGB). Although the names more or less describe their respective colors, they are essentially artificial, without a strict rationale behind the terms used. The color keywords all represent plain, solid colors without transparency. Several keywords are aliases for each other: * `aqua` / `cyan` * `fuchsia` / `magenta` * `darkgray` / `darkgrey` * `darkslategray` / `darkslategrey` * `dimgray` / `dimgrey` * `lightgray` / `lightgrey` * `lightslategray` / `lightslategrey` * `gray` / `grey` * `slategray` / `slategrey` Though many keywords have been adapted from [X11](https://en.wikipedia.org/wiki/X_Window_System), their RGB values may differ from the corresponding color on X11 systems since manufacturers sometimes tailor X11 colors to their specific hardware. Examples -------- ### Using named colors #### HTML ``` <div id="container"> <div id="one"></div> <div id="two"></div> <div id="three"></div> </div> ``` #### CSS ``` #container { display: flex; justify-content: space-around; background-color: darkslateblue; padding: 20px; } #container > div { height: 100px; width: 100px; margin: 3px; border: 2px solid black; } #one { background-color: red; } #two { background-color: lavender; } #three { background-color: transparent; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Color Module Level 4 # named-colors](https://w3c.github.io/csswg-drafts/css-color/#named-colors) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `named-color` | 1 | 12 | 1 | 3 Internet Explorer 8 and later support gray color keywords spelled with an *e* (`grey`, `darkgrey`, `darkslategrey`, `dimgrey`, `lightgrey`, and `lightslategrey`). Internet Explorer 3 to Internet Explorer 7 only support the keywords spelled with *a* (`gray`, `darkgray`, `darkslategray`, `dimgray`, `lightgray`, and `lightslategray`). | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | | `rebeccapurple` | 38 | 12 | 33 | 11 | 25 | 9 | 38 | 38 | 33 | 25 | 8 | 3.0 | See also -------- * [`<color>`](color_value): the data type of whose definition `<named-color>` is a constituent part.
programming_docs
css CSS Box Model CSS Box Model ============= **CSS Box Model** is a module of CSS that defines the rectangular boxes—including their padding and margin—that are generated for elements and laid out according to the [visual formatting model](visual_formatting_model). Box model overview ------------------ A box in CSS consists of a content area, which is where any text, images, or other HTML elements are displayed. This is optionally surrounded by padding, a border, and a margin, on one or more sides. The box model describes how these elements work together to create a box as displayed by CSS. To learn more about it read [Introduction to the CSS Box Model](css_box_model/introduction_to_the_css_box_model). ### Box-edge keywords The Box Model specification defines a set of keywords that refer to the edges of each part of the box, these are used as keyword values in CSS including as a value for the [`box-sizing`](box-sizing) property, to control how the box model calculates its size. `content-box` The edge of the content area of the box. `padding-box` The edge of the padding of the box, if there is no padding on a side then this is the same as `content-box`. `border-box` The edge of the border of the box, if there is no border on a side then this is the same as `padding-box`. `margin-box` The edge of the margin of the box, if there is no margin on a side then this is the same as `border-box`. `stroke-box` In SVG refers to the stroke bounding box, in CSS treated as `content-box`. `view-box` In SVG refers to the nearest SVG viewport element's origin box, which is a rectangle with the width and height of the initial SVG user coordinate system established by the `[viewBox](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox)` attribute for that element. In CSS treated as `border-box`. Reference --------- **Note:** This specification defines the physical padding and margin properties. Flow-relative properties, which relate to text direction, are defined in [Logical Properties and Values](css_logical_properties). ### Properties for controlling the margin of a box Margins surround the border edge of a box, and provide spacing between boxes. * [`margin`](margin) * [`margin-bottom`](margin-bottom) * [`margin-left`](margin-left) * [`margin-right`](margin-right) * [`margin-top`](margin-top) * [`margin-trim`](margin-trim) Experimental ### Properties for controlling the padding for a box Padding is inserted between the content edge and border edge of a box. * [`padding`](padding) * [`padding-bottom`](padding-bottom) * [`padding-left`](padding-left) * [`padding-right`](padding-right) * [`padding-top`](padding-top) ### Other properties There are other properties that relate to the box model, that are defined elsewhere. [Borders](css_backgrounds_and_borders) The border properties specify the thickness of the border, drawing style and color. [Overflow](overflow) Controls what happens when there is too much content to fit into a box. Guides ------ [Introduction to the CSS box model](css_box_model/introduction_to_the_css_box_model) Explains one of the fundamental concept of CSS: the box model. This model defines how CSS lays out elements, including their content, padding, border, and margin areas. [Mastering margin collapsing](css_box_model/mastering_margin_collapsing) Sometimes, two adjacent margins are collapsed into one. This article describes the rules that govern when and why this happens, and how to control it. [Visual formatting model](visual_formatting_model) Explains the visual formatting model. Specifications -------------- | Specification | | --- | | [CSS Box Model Module Level 3](https://drafts.csswg.org/css-box/) | css list-style-image list-style-image ================ The `list-style-image` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets an image to be used as the list item marker. It is often more convenient to use the shorthand [`list-style`](list-style). Try it ------ **Note:** This property is applied to list items, i.e. elements with `[`display`](display): list-item;` [by default](https://html.spec.whatwg.org/multipage/rendering.html#lists) this includes [`<li>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/li) elements. Because this property is inherited, it can be set on the parent element (normally [`<ol>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol) or [`<ul>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ul)) to let it apply to all list items. Syntax ------ ``` /\* Keyword values \*/ list-style-image: none; /\* <url> values \*/ list-style-image: url("starsolid.gif"); /\* valid image values \*/ list-style-image: linear-gradient(to left bottom, red, blue); /\* Global values \*/ list-style-image: inherit; list-style-image: initial; list-style-image: revert; list-style-image: revert-layer; list-style-image: unset; ``` ### Values [`<image>`](image) A valid image to use as the marker. `none` Specifies that no image is used as the marker. If this value is set, the marker defined in [`list-style-type`](list-style-type) will be used instead. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | list items | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | | | Animation type | discrete | Formal syntax ------------- ``` list-style-image = <image> [|](value_definition_syntax#single_bar) none <image> = <url> [|](value_definition_syntax#single_bar) [<gradient>](gradient) <url> = url( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) [|](value_definition_syntax#single_bar) src( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) ``` Examples -------- ### Using a url value #### HTML ``` <ul> <li>Item 1</li> <li>Item 2</li> </ul> ``` #### CSS ``` ul { list-style-image: url("starsolid.gif"); } ``` #### Result ### Using a gradient #### HTML ``` <ul> <li>Item 1</li> <li>Item 2</li> </ul> ``` #### CSS ``` ul { font-size: 200%; list-style-image: linear-gradient(to left bottom, red, blue); } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Lists and Counters Module Level 3 # image-markers](https://w3c.github.io/csswg-drafts/css-lists/#image-markers) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `list-style-image` | 1 | 12 | 1 Before Firefox 86, this property did not accept an `<image>` type, and required the URL of an image. | 4 | 7 | 1 | 4.4 | 18 | 4 Before Firefox 86, this property did not accept an `<image>` type, and required the URL of an image. | 10.1 | 1 | 1.0 | See also -------- * [`list-style`](list-style), [`list-style-type`](list-style-type), [`list-style-position`](list-style-position) * [`url()`](url) function css background background ========== The `background` [shorthand](shorthand_properties) [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets all background style properties at once, such as color, image, origin and size, or repeat method. Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`background-attachment`](background-attachment) * [`background-clip`](background-clip) * [`background-color`](background-color) * [`background-image`](background-image) * [`background-origin`](background-origin) * [`background-position`](background-position) * [`background-repeat`](background-repeat) * [`background-size`](background-size) Syntax ------ ``` /\* Using a <background-color> \*/ background: green; /\* Using a <bg-image> and <repeat-style> \*/ background: url("test.jpg") repeat-y; /\* Using a <box> and <background-color> \*/ background: border-box red; /\* A single image, centered and scaled \*/ background: no-repeat center/80% url("../img/image.png"); /\* Global values \*/ background: inherit; background: initial; background: revert; background: revert-layer; background: unset; ``` The `background` property is specified as one or more background layers, separated by commas. The syntax of each layer is as follows: * Each layer may include zero or one occurrences of any of the following values: + `<attachment>` + `<bg-image>` + `<position>` + `<bg-size>` + `<repeat-style>` * The `<bg-size>` value may only be included immediately after `<position>`, separated with the '/' character, like this: "`center/80%`". * The `<box>` value may be included zero, one, or two times. If included once, it sets both [`background-origin`](background-origin) and [`background-clip`](background-clip). If it is included twice, the first occurrence sets [`background-origin`](background-origin), and the second sets [`background-clip`](background-clip). * The `<background-color>` value may only be included in the last layer specified. ### Values `<attachment>` See [`background-attachment`](background-attachment). `<box>` See [`background-clip`](background-clip) and [`background-origin`](background-origin). `<background-color>` See [`background-color`](background-color). `<bg-image>` See [`background-image`](background-image). `<position>` See [`background-position`](background-position). `<repeat-style>` See [`background-repeat`](background-repeat). `<bg-size>` See [`background-size`](background-size). Accessibility concerns ---------------------- Browsers do not provide any special information on background images to assistive technology. This is important primarily for screen readers, as a screen reader will not announce its presence and therefore convey nothing to its users. If the image contains information critical to understanding the page's overall purpose, it is better to describe it semantically in the document. * [MDN Understanding WCAG, Guideline 1.1 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.1_%e2%80%94_providing_text_alternatives_for_non-text_content) * [Understanding Success Criterion 1.1.1 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/2016/NOTE-UNDERSTANDING-WCAG20-20161007/text-equiv-all.html) Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`background-image`](background-image): `none` * [`background-position`](background-position): `0% 0%` * [`background-size`](background-size): `auto auto` * [`background-repeat`](background-repeat): `repeat` * [`background-origin`](background-origin): `padding-box` * [`background-clip`](background-clip): `border-box` * [`background-attachment`](background-attachment): `scroll` * [`background-color`](background-color): `transparent` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | Percentages | as each of the properties of the shorthand:* [`background-position`](background-position): refer to the size of the background positioning area minus size of background image; size refers to the width for horizontal offsets and to the height for vertical offsets * [`background-size`](background-size): relative to the background positioning area | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`background-image`](background-image): as specified, but with [`url()`](url) values made absolute * [`background-position`](background-position): as each of the properties of the shorthand: + [`background-position-x`](background-position-x): A list, each item consisting of: an offset given as a combination of an absolute length and a percentage, plus an origin keyword + [`background-position-y`](background-position-y): A list, each item consisting of: an offset given as a combination of an absolute length and a percentage, plus an origin keyword * [`background-size`](background-size): as specified, but with relative lengths converted into absolute lengths * [`background-repeat`](background-repeat): a list, each item consisting of two keywords, one per dimension * [`background-origin`](background-origin): as specified * [`background-clip`](background-clip): as specified * [`background-attachment`](background-attachment): as specified * [`background-color`](background-color): computed color | | Animation type | as each of the properties of the shorthand:* [`background-color`](background-color): a [color](color_value#interpolation) * [`background-image`](background-image): discrete * [`background-clip`](background-clip): discrete * [`background-position`](background-position): repeatable list of simple list of length, percentage, or calc * [`background-size`](background-size): repeatable list of simple list of length, percentage, or calc * [`background-repeat`](background-repeat): discrete * [`background-attachment`](background-attachment): discrete | Formal syntax ------------- ``` background = [[](value_definition_syntax#brackets) <bg-layer>[#](value_definition_syntax#hash_mark) , []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) <final-bg-layer> <bg-layer> = <bg-image> [||](value_definition_syntax#double_bar) <bg-position> [[](value_definition_syntax#brackets) / <bg-size> []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) [||](value_definition_syntax#double_bar) <repeat-style> [||](value_definition_syntax#double_bar) <attachment> [||](value_definition_syntax#double_bar) <box> [||](value_definition_syntax#double_bar) <box> <final-bg-layer> = <'background-color'> [||](value_definition_syntax#double_bar) <bg-image> [||](value_definition_syntax#double_bar) <bg-position> [[](value_definition_syntax#brackets) / <bg-size> []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) [||](value_definition_syntax#double_bar) <repeat-style> [||](value_definition_syntax#double_bar) <attachment> [||](value_definition_syntax#double_bar) <box> [||](value_definition_syntax#double_bar) <box> <bg-image> = <image> [|](value_definition_syntax#single_bar) none <bg-position> = [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) top [|](value_definition_syntax#single_bar) bottom [|](value_definition_syntax#single_bar) <length-percentage> []](value_definition_syntax#brackets) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) <length-percentage> []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) top [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) bottom [|](value_definition_syntax#single_bar) <length-percentage> []](value_definition_syntax#brackets) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) center [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) right []](value_definition_syntax#brackets) <length-percentage>[?](value_definition_syntax#question_mark) []](value_definition_syntax#brackets) [&&](value_definition_syntax#double_ampersand) [[](value_definition_syntax#brackets) center [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) top [|](value_definition_syntax#single_bar) bottom []](value_definition_syntax#brackets) <length-percentage>[?](value_definition_syntax#question_mark) []](value_definition_syntax#brackets) <bg-size> = [[](value_definition_syntax#brackets) [<length-percentage [0,∞]>](length-percentage) [|](value_definition_syntax#single_bar) auto []](value_definition_syntax#brackets)[{1,2}](value_definition_syntax#curly_braces) [|](value_definition_syntax#single_bar) cover [|](value_definition_syntax#single_bar) contain <repeat-style> = repeat-x [|](value_definition_syntax#single_bar) repeat-y [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) repeat [|](value_definition_syntax#single_bar) space [|](value_definition_syntax#single_bar) round [|](value_definition_syntax#single_bar) no-repeat []](value_definition_syntax#brackets)[{1,2}](value_definition_syntax#curly_braces) <attachment> = scroll [|](value_definition_syntax#single_bar) fixed [|](value_definition_syntax#single_bar) local <box> = border-box [|](value_definition_syntax#single_bar) padding-box [|](value_definition_syntax#single_bar) content-box <image> = <url> [|](value_definition_syntax#single_bar) [<gradient>](gradient) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) <url> = url( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) [|](value_definition_syntax#single_bar) src( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) ``` Examples -------- ### Setting backgrounds with color keywords and images #### HTML ``` <p class="topbanner"> Starry sky<br /> Twinkle twinkle<br /> Starry sky </p> <p class="warning">Here is a paragraph</p> <p></p> ``` #### CSS ``` .warning { background: pink; } .topbanner { background: url("starsolid.gif") #99f repeat-y fixed; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # the-background](https://w3c.github.io/csswg-drafts/css-backgrounds/#the-background) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `SVG_image_as_background` | 1 | 12 | 4 | 9 | 9.5 | 3.1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | | `background` | 1 | 12 | 1 | 4 | 3.5 | 1 | 2 | 18 | 4 | 10.1 | 1 | 1.0 | | `background-clip` | 21 | 12 | 22 | 9 | 15 | 5.1 | 3 | 25 | 22 | 14 | 4 | 1.5 | | `background-origin` | 21 | 12 | 22 | 9 | 15 | 5.1 | 3 | 25 | 22 | 14 | 4 | 1.5 | | `background-size` | 21 | 12 | 9 | 9 | 21 | 5.1 | 3 | 25 | 18 | 14 | 4 | 1.5 | | `multiple_backgrounds` | 1 | 12 | 3.6 | 9 | 10.5 | 1.3 | 2 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [`box-decoration-break`](box-decoration-break) * [Using gradients](css_images/using_css_gradients) * [Using multiple backgrounds](css_backgrounds_and_borders/using_multiple_backgrounds) css border-bottom-style border-bottom-style =================== The `border-bottom-style` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the line style of an element's bottom [`border`](border). Try it ------ **Note:** The specification doesn't define how borders of different styles connect in the corners. Syntax ------ ``` /\* Keyword values \*/ border-bottom-style: none; border-bottom-style: hidden; border-bottom-style: dotted; border-bottom-style: dashed; border-bottom-style: solid; border-bottom-style: double; border-bottom-style: groove; border-bottom-style: ridge; border-bottom-style: inset; border-bottom-style: outset; /\* Global values \*/ border-bottom-style: inherit; border-bottom-style: initial; border-bottom-style: revert; border-bottom-style: revert-layer; border-bottom-style: unset; ``` The `border-bottom-style` property is specified as a single keyword chosen from those available for the [`border-style`](border-style) property. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` border-bottom-style = <line-style> <line-style> = none [|](value_definition_syntax#single_bar) hidden [|](value_definition_syntax#single_bar) dotted [|](value_definition_syntax#single_bar) dashed [|](value_definition_syntax#single_bar) solid [|](value_definition_syntax#single_bar) double [|](value_definition_syntax#single_bar) groove [|](value_definition_syntax#single_bar) ridge [|](value_definition_syntax#single_bar) inset [|](value_definition_syntax#single_bar) outset ``` Examples -------- ### Demonstrating all border styles #### 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 ``` /\* Define look of the table \*/ table { border-width: 3px; background-color: #52e385; } tr, td { padding: 3px; } /\* border-bottom-style example classes \*/ .b1 {border-bottom-style: none;} .b2 {border-bottom-style: hidden;} .b3 {border-bottom-style: dotted;} .b4 {border-bottom-style: dashed;} .b5 {border-bottom-style: solid;} .b6 {border-bottom-style: double;} .b7 {border-bottom-style: groove;} .b8 {border-bottom-style: ridge;} .b9 {border-bottom-style: inset;} .b10 {border-bottom-style: outset;} ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # border-style](https://w3c.github.io/csswg-drafts/css-backgrounds/#border-style) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-bottom-style` | 1 | 12 | 1 Before Firefox 50, border styles of rounded corners (with [`border-radius`](https://developer.mozilla.org/docs/Web/CSS/border-radius)) were always rendered as if `border-bottom-style` was `solid`. This has been fixed in Firefox 50. | 5.5 | 9.2 | 1 | ≤37 | 18 | 4 Before Firefox 50, border styles of rounded corners (with [`border-radius`](https://developer.mozilla.org/docs/Web/CSS/border-radius)) were always rendered as if `border-bottom-style` was `solid`. This has been fixed in Firefox 50. | 14 | 1 | 1.0 | See also -------- * The other style-related border properties: [`border-left-style`](border-left-style), [`border-right-style`](border-right-style), [`border-top-style`](border-top-style), and [`border-style`](border-style). * The other bottom-border-related properties: [`border-bottom`](border-bottom), [`border-bottom-color`](border-bottom-color), and [`border-bottom-width`](border-bottom-width).
programming_docs
css margin-block-start margin-block-start ================== The `margin-block-start` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the logical block start margin of an element, which maps to a physical margin depending on the element's writing mode, directionality, and text orientation. Try it ------ Syntax ------ ``` /\* <length> values \*/ margin-block-start: 10px; /\* An absolute length \*/ margin-block-start: 1em; /\* relative to the text size \*/ margin-block-start: 5%; /\* relative to the nearest block container's width \*/ /\* Keyword values \*/ margin-block-start: auto; /\* Global values \*/ margin-block-start: inherit; margin-block-start: initial; margin-block-start: revert; margin-block-start: revert-layer; margin-block-start: unset; ``` It corresponds to the [`margin-top`](margin-top), [`margin-right`](margin-right), [`margin-bottom`](margin-bottom), or [`margin-left`](margin-left) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). It relates to [`margin-block-end`](margin-block-end), [`margin-inline-start`](margin-inline-start), and [`margin-inline-end`](margin-inline-end), which define the other margins of the element. ### Values The `margin-block-start` property takes the same values as the [`margin-left`](margin-left) property. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | same as [`margin`](margin) | | [Inherited](inheritance) | no | | Percentages | depends on layout model | | [Computed value](computed_value) | if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, `auto` | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` margin-block-start = <'margin-top'> ``` Examples -------- ### Setting block start margin #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; margin-block-start: 20px; background-color: #c8c800; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # margin-properties](https://w3c.github.io/csswg-drafts/css-logical/#margin-properties) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `margin-block-start` | 87 | 87 | 41 | No | 73 | 12.1 | 87 | 87 | 41 | 62 | 12.2 | 14.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * The mapped physical properties: [`margin-top`](margin-top), [`margin-right`](margin-right), [`margin-bottom`](margin-bottom), and [`margin-left`](margin-left) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css clip clip ==== **Deprecated:** This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the [compatibility table](#browser_compatibility) at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time. **Warning:** Where possible, authors are encouraged to use the newer [`clip-path`](clip-path) property instead. The `clip` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines a visible portion of an element. The `clip` property applies only to absolutely positioned elements — that is, elements with [`position:absolute`](position) or [`position:fixed`](position). Syntax ------ ``` /\* Keyword value \*/ clip: auto; /\* <shape> values \*/ clip: rect(1px, 10em, 3rem, 2ch); /\* Global values \*/ clip: inherit; clip: initial; clip: revert; clip: revert-layer; clip: unset; ``` ### Values [`<shape>`](shape) A rectangular [`<shape>`](shape) of the form `rect(<top>, <right>, <bottom>, <left>)`. The `<top>` and `<bottom>` values are offsets from the *inside top border edge* of the box, while `<right>` and `<left>` are offsets from the *inside left border edge* of the box — that is, the extent of the padding box. The `<top>`, `<right>`, `<bottom>`, and `<left>` values may be either a [`<length>`](length) or `auto`. If any side's value is `auto`, the element is clipped to that side's *inside border edge*. `auto` The element does not clip (default). This is different from `rect(auto, auto, auto, auto)`, which clips to the element's inside border edges. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | absolutely positioned elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | `auto` if specified as `auto`, otherwise a rectangle with four values, each of which is `auto` if specified as `auto` or the computed length otherwise | | Animation type | a [rectangle](shape#interpolation) | Formal syntax ------------- ``` clip = <rect()> [|](value_definition_syntax#single_bar) auto <rect()> = rect( [[](value_definition_syntax#brackets) <length-percentage> [|](value_definition_syntax#single_bar) auto []](value_definition_syntax#brackets)[{4}](value_definition_syntax#curly_braces) [[](value_definition_syntax#brackets) round <'border-radius'> []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Clipping an image #### HTML ``` <p class="dotted-border"> <img src="macarons.png" title="Original graphic" /> <img id="top-left" src="macarons.png" title="Graphic clipped to upper left" /> <img id="middle" src="macarons.png" title="Graphic clipped towards middle" /> <img id="bottom-right" src="macarons.png" title="Graphic clipped to bottom right" /> </p> ``` #### CSS ``` .dotted-border { border: dotted; position: relative; width: 390px; height: 400px; } #top-left, #middle, #bottom-right { position: absolute; top: 0; } #top-left { left: 400px; clip: rect(0, 130px, 90px, 0); } #middle { left: 270px; clip: rect(100px, 260px, 190px, 130px); } #bottom-right { left: 140px; clip: rect(200px, 390px, 290px, 260px); } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Masking Module Level 1 # clip-property](https://drafts.fxtf.org/css-masking/#clip-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `clip` | 1 | 12 | 1 | 4 Before Internet Explorer 7, Internet Explorer incorrectly interprets `clip: auto` as `clip: rect(auto, auto, auto, auto)`. | 7 | 1 Safari incorrectly interprets `clip: auto` as `clip: rect(auto, auto, auto, auto)`. | 37 | 18 | 4 | 14 | 1 Safari incorrectly interprets `clip: auto` as `clip: rect(auto, auto, auto, auto)`. | 1.0 | See also -------- * This property is deprecated. Use [`clip-path`](clip-path) instead. * Related CSS properties: + [`text-overflow`](text-overflow) + [`white-space`](white-space) + [`overflow-x`](overflow-x) + [`overflow-y`](overflow-y) + [`overflow`](overflow) + [`display`](display) + [`position`](position) css :focus-within :focus-within ============= The `:focus-within` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) matches an element if the element or any of its descendants are focused. In other words, it represents an element that is itself matched by the [`:focus`](:focus) pseudo-class or has a descendant that is matched by `:focus`. (This includes descendants in [shadow trees](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM).) Try it ------ This selector is useful, to take a common example, for highlighting an entire [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form) container when the user focuses on one of its [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) fields. Syntax ------ ``` :focus-within ``` Examples -------- In this example, the form will receive special coloring styles when either text input receives focus. ### HTML ``` <p>Try typing into this form.</p> <form> <label for="given\_name">Given Name:</label> <input id="given\_name" type="text" /> <br /> <label for="family\_name">Family Name:</label> <input id="family\_name" type="text" /> </form> ``` ### CSS ``` form { border: 1px solid; color: gray; padding: 4px; } form:focus-within { background: #ff8; color: black; } input { margin: 4px; } ``` ### Result Specifications -------------- | Specification | | --- | | [Selectors Level 4 # the-focus-within-pseudo](https://w3c.github.io/csswg-drafts/selectors/#the-focus-within-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:focus-within` | 60 | 79 | 52 | No | 47 | 10.1 | 60 | 60 | 52 | 44 | 10.3 | 8.0 | See also -------- * [`:focus`](:focus) * [`:focus-visible`](:focus-visible) * [Grab your user's attention with the focus-within selector](https://dev.to/vtrpldn/grab-your-user-s-attention-with-the-focus-within-css-selector-4d4) css CSS Scroll Snap CSS Scroll Snap =============== **CSS Scroll Snap** is a module of CSS that introduces scroll snap positions, which enforce the scroll positions that a [scroll container](https://developer.mozilla.org/en-US/docs/Glossary/Scroll_container)'s [scrollport](https://developer.mozilla.org/en-US/docs/Glossary/Scrollport) may end at after a scrolling operation has completed. Reference --------- ### Properties on containers * [`scroll-snap-type`](scroll-snap-type) * [`scroll-padding`](scroll-padding) * [`scroll-padding-top`](scroll-padding-top) * [`scroll-padding-right`](scroll-padding-right) * [`scroll-padding-bottom`](scroll-padding-bottom) * [`scroll-padding-left`](scroll-padding-left) * [`scroll-padding-inline`](scroll-padding-inline) * [`scroll-padding-inline-start`](scroll-padding-inline-start) * [`scroll-padding-inline-end`](scroll-padding-inline-end) * [`scroll-padding-block`](scroll-padding-block) * [`scroll-padding-block-start`](scroll-padding-block-start) * [`scroll-padding-block-end`](scroll-padding-block-end) ### Properties on children * [`scroll-snap-align`](scroll-snap-align) * [`scroll-margin`](scroll-margin) * [`scroll-margin-top`](scroll-margin-top) * [`scroll-margin-right`](scroll-margin-right) * [`scroll-margin-bottom`](scroll-margin-bottom) * [`scroll-margin-left`](scroll-margin-left) * [`scroll-margin-inline`](scroll-margin-inline) * [`scroll-margin-inline-start`](scroll-margin-inline-start) * [`scroll-margin-inline-end`](scroll-margin-inline-end) * [`scroll-margin-block`](scroll-margin-block) * [`scroll-margin-block-start`](scroll-margin-block-start) * [`scroll-margin-block-end`](scroll-margin-block-end) * [`scroll-snap-stop`](scroll-snap-stop) Guides ------ * [Basic concepts of CSS Scroll Snap](css_scroll_snap/basic_concepts) Specifications -------------- | Specification | | --- | | [CSS Scroll Snap Module Level 1](https://drafts.csswg.org/css-scroll-snap/) | Browser compatibility --------------------- css text-shadow text-shadow =========== The `text-shadow` CSS property adds shadows to text. It accepts a comma-separated list of shadows to be applied to the text and any of its [`decorations`](text-decoration). Each shadow is described by some combination of X and Y offsets from the element, blur radius, and color. Try it ------ Syntax ------ ``` /\* offset-x | offset-y | blur-radius | color \*/ text-shadow: 1px 1px 2px black; /\* color | offset-x | offset-y | blur-radius \*/ text-shadow: #fc0 1px 0 10px; /\* offset-x | offset-y | color \*/ text-shadow: 5px 5px #558abb; /\* color | offset-x | offset-y \*/ text-shadow: white 2px 5px; /\* offset-x | offset-y /\* Use defaults for color and blur-radius \*/ text-shadow: 5px 10px; /\* Global values \*/ text-shadow: inherit; text-shadow: initial; text-shadow: revert; text-shadow: revert-layer; text-shadow: unset; ``` This property is specified as a comma-separated list of shadows. Each shadow is specified as two or three `<length>` values, followed optionally by a `<color>` value. The first two `<length>` values are the `<offset-x>` and `<offset-y>` values. The third, optional, `<length>` value is the `<blur-radius>`. The `<color>` value is the shadow's color. When more than one shadow is given, shadows are applied front-to-back, with the first-specified shadow on top. This property applies to both [`::first-line`](::first-line) and [`::first-letter`](::first-letter) <pseudo-elements>. ### Values [`<color>`](color_value) Optional. The color of the shadow. It can be specified either before or after the offset values. If unspecified, the color's value is left up to the user agent, so when consistency across browsers is desired you should define it explicitly. `<offset-x> <offset-y>` Required. These [`<length>`](length) values specify the shadow's distance from the text. `<offset-x>` specifies the horizontal distance; a negative value places the shadow to the left of the text. `<offset-y>` specifies the vertical distance; a negative value places the shadow above the text. If both values are `0`, the shadow is placed directly behind the text, although it may be partly visible due to the effect of `<blur-radius>`. `<blur-radius>` Optional. This is a [`<length>`](length) value. The higher the value, the bigger the blur; the shadow becomes wider and lighter. If not specified, it defaults to `0`. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | a color plus three absolute lengths | | Animation type | a [shadow list](box-shadow#interpolation) | Formal syntax ------------- ``` text-shadow = none [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) [<color>](color_value)[?](value_definition_syntax#question_mark) [&&](value_definition_syntax#double_ampersand) [<length>](length)[{2,3}](value_definition_syntax#curly_braces) []](value_definition_syntax#brackets)[#](value_definition_syntax#hash_mark) ``` Examples -------- ### Simple shadow ``` .red-text-shadow { text-shadow: red 0 -2px; } ``` ``` <p class="red-text-shadow"> Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore. </p> ``` ### Multiple shadows ``` .white-text-with-blue-shadow { text-shadow: 1px 1px 2px black, 0 0 1em blue, 0 0 0.2em blue; color: white; font: 1.5em Georgia, serif; } ``` ``` <p class="white-text-with-blue-shadow"> Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore. </p> ``` Specifications -------------- | Specification | | --- | | [CSS Text Decoration Module Level 3 # text-shadow-property](https://w3c.github.io/csswg-drafts/css-text-decor/#text-shadow-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `text-shadow` | 2 | 12 | 3.5 ["Firefox versions before 57 have a bug whereby [`transition`](https://developer.mozilla.org/docs/Web/CSS/transition)s will not work when transitioning from a `text-shadow` with a color specified to a `text-shadow` without a color specified ([bug 726550](https://bugzil.la/726550)).", "From Firefox 4, the blur radius is capped at 300 for performance reasons.", "Firefox theoretically supports infinite text-shadows (don't try it).", "If the `<color>` value is unspecified, then Firefox uses the value of the element's [`color`](https://developer.mozilla.org/docs/Web/CSS/color) property."] | 10 | 9.5 ["Opera supports a maximum of 6-9 text-shadows for performance reasons. The blur radius is limited to 100px.", "Opera 9.5 to 10.1 adheres to the old, reverse painting order (in CSS2, the first specified shadow is on the bottom)."] | 1.1 ["In Safari, any shadows that do not explicitly specify a color are transparent.", "Safari 1.1 to 3.2 only supports one text-shadow (displays the first shadow of a comma-separated list and ignores the rest). Safari 4.0 (WebKit 528) and later support multiple text-shadows."] | 37 | 18 | 4 ["Firefox versions before 57 have a bug whereby [`transition`](https://developer.mozilla.org/docs/Web/CSS/transition)s will not work when transitioning from a `text-shadow` with a color specified to a `text-shadow` without a color specified ([bug 726550](https://bugzil.la/726550)).", "From Firefox 4, the blur radius is capped at 300 for performance reasons.", "Firefox theoretically supports infinite text-shadows (don't try it).", "If the `<color>` value is unspecified, then Firefox uses the value of the element's [`color`](https://developer.mozilla.org/docs/Web/CSS/color) property."] | 14 | 1 ["In Safari, any shadows that do not explicitly specify a color are transparent.", "Safari iOS 1 and 2 only support one text-shadow (displays the first shadow of a comma-separated list and ignores the rest). Safari iOS 3 (WebKit 528) and later support multiple text-shadows."] | 1.0 | See also -------- * The [`<color>`](color_value) data type (for specifying the shadow color) * [`box-shadow`](box-shadow) * [`drop-shadow()`](filter-function/drop-shadow) * [Applying color to HTML elements using CSS](css_colors/applying_color) css <display-internal> <display-internal> ================== Some layout models such as `table` and `ruby` have a complex internal structure, with several different roles that their children and descendants can fill. This page defines those "internal" display values, which only have meaning within that particular layout mode. Syntax ------ Valid `<display-internal>` values: `table-row-group` These elements behave like [`<tbody>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tbody) HTML elements. `table-header-group` These elements behave like [`<thead>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/thead) HTML elements. `table-footer-group` These elements behave like [`<tfoot>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tfoot) HTML elements. `table-row` These elements behave like [`<tr>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tr) HTML elements. `table-cell` These elements behave like [`<td>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td) HTML elements. `table-column-group` These elements behave like [`<colgroup>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/colgroup) HTML elements. `table-column` These elements behave like [`<col>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/col) HTML elements. `table-caption` These elements behave like [`<caption>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption) HTML elements. `ruby-base` Experimental These elements behave like [`<rb>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/rb) HTML elements. `ruby-text` Experimental These elements behave like [`<rt>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/rt) HTML elements. `ruby-base-container` Experimental These elements are generated as anonymous boxes. `ruby-text-container` Experimental These elements behave like [`<rtc>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/rtc) HTML elements. Formal syntax ------------- ``` <display-internal> = table-row-group [|](value_definition_syntax#single_bar) table-header-group [|](value_definition_syntax#single_bar) table-footer-group [|](value_definition_syntax#single_bar) table-row [|](value_definition_syntax#single_bar) table-cell [|](value_definition_syntax#single_bar) table-column-group [|](value_definition_syntax#single_bar) table-column [|](value_definition_syntax#single_bar) table-caption [|](value_definition_syntax#single_bar) ruby-base [|](value_definition_syntax#single_bar) ruby-text [|](value_definition_syntax#single_bar) ruby-base-container [|](value_definition_syntax#single_bar) ruby-text-container ``` Examples -------- ### CSS tables example The following example demonstrates laying out a simple form using CSS table layout. #### HTML ``` <main> <div> <label for="name">Name</label> <input type="text" id="name" name="name" /> </div> <div> <label for="age">Age</label> <input type="text" id="age" name="age" /> </div> </main> ``` #### CSS ``` main { display: table; } div { display: table-row; } label, input { display: table-cell; margin: 5px; } ``` #### Result Specifications -------------- **No specification found**No specification data found for `css.properties.display.table_values,css.properties.display.ruby_values`. [Check for problems with this page](#on-github) or contribute a missing `spec_url` to [mdn/browser-compat-data](https://github.com/mdn/browser-compat-data). Also make sure the specification is included in [w3c/browser-specs](https://github.com/w3c/browser-specs). Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `display-internal` | No | 12-79 | 38 | 7 | No | No | No | No | 38 | No | No | No | | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `display-internal` | 1 | 12 | 1 | 8 | 7 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | ### css.properties.display.table\_values BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. ### css.properties.display.ruby\_values BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data. See also -------- * [`display`](display) + [`<display-outside>`](display-outside) + [`<display-inside>`](display-inside) + [`<display-listitem>`](display-listitem) + [`<display-box>`](display-box) + [`<display-legacy>`](display-legacy)
programming_docs
css :where() :where() ======== The `:where()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) function takes a selector list as its argument, and selects any element that can be selected by one of the selectors in that list. Try it ------ The difference between `:where()` and [`:is()`](:is) is that `:where()` always has 0 <specificity>, whereas `:is()` takes on the specificity of the most specific selector in its arguments. ### Forgiving Selector Parsing The specification defines `:is()` and `:where()` as accepting a [forgiving selector list](https://drafts.csswg.org/selectors-4/#typedef-forgiving-selector-list). In CSS when using a selector list, if any of the selectors are invalid then the whole list is deemed invalid. When using `:is()` or `:where()` instead of the whole list of selectors being deemed invalid if one fails to parse, the incorrect or unsupported selector will be ignored and the others used. ``` :where(:valid, :unsupported) { /\* … \*/ } ``` Will still parse correctly and match `:valid` even in browsers which don't support `:unsupported`, whereas: ``` :valid, :unsupported { /\* … \*/ } ``` Will be ignored in browsers which don't support `:unsupported` even if they support `:valid`. Examples -------- ### Comparing :where() and :is() This example shows how `:where()` works, and also illustrates the difference between `:where()` and `:is()`. Take the following HTML: ``` <article> <h2>:is()-styled links</h2> <section class="is-styling"> <p> Here is my main content. This <a href="https://mozilla.org">contains a link</a>. </p> </section> <aside class="is-styling"> <p> Here is my aside content. This <a href="https://developer.mozilla.org">also contains a link</a>. </p> </aside> <footer class="is-styling"> <p> This is my footer, also containing <a href="https://github.com/mdn">a link</a>. </p> </footer> </article> <article> <h2>:where()-styled links</h2> <section class="where-styling"> <p> Here is my main content. This <a href="https://mozilla.org">contains a link</a>. </p> </section> <aside class="where-styling"> <p> Here is my aside content. This <a href="https://developer.mozilla.org">also contains a link</a>. </p> </aside> <footer class="where-styling"> <p> This is my footer, also containing <a href="https://github.com/mdn">a link</a>. </p> </footer> </article> ``` In this somewhat-contrived example, we have two articles that each contain a section, an aside, and a footer. They differ by the classes used to mark the child elements. To make selecting the links inside them simpler, but still distinct, we *could* use `:is()` or `:where()`, in the following manner: ``` html { font-family: sans-serif; font-size: 150%; } :is(section.is-styling, aside.is-styling, footer.is-styling) a { color: red; } :where(section.where-styling, aside.where-styling, footer.where-styling) a { color: orange; } ``` However, what if we later want to override the color of links in the footers using a simple selector? ``` footer a { color: blue; } ``` This won't work for the red links, because the selectors inside `:is()` count towards the specificity of the overall selector, and class selectors have a higher specificity than element selectors. However, selectors inside `:where()` have specificity 0, so the orange footer link will be overridden by our simple selector. **Note:** You can also find this example on GitHub; see [is-where](https://mdn.github.io/css-examples/is-where/). Syntax ------ ``` :where( <complex-selector-list> ) ``` Specifications -------------- | Specification | | --- | | [Selectors Level 4 # zero-matches](https://w3c.github.io/csswg-drafts/selectors/#zero-matches) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:where` | 88 | 88 | 78 | No | 74 | 14 | 88 | 88 | 79 | 63 | 14 | 15.0 | | `forgiving_selector_list` | 88 | 88 | 82 | No | 74 | 14 | 88 | 88 | 82 | 63 | 14 | 15.0 | See also -------- * [`:is()`](:is) * [Selector list](selector_list) * [Web components](https://developer.mozilla.org/en-US/docs/Web/Web_Components) css mask-border-slice mask-border-slice ================= The `mask-border-slice` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property divides the image set by [`mask-border-source`](mask-border-source) into regions. These regions are used to form the components of an element's [mask border](mask-border). Syntax ------ ``` /\* All sides \*/ mask-border-slice: 30%; /\* top and bottom | left and right \*/ mask-border-slice: 10% 30%; /\* top | left and right | bottom \*/ mask-border-slice: 30 30% 45; /\* top | right | bottom | left \*/ mask-border-slice: 7 12 14 5; /\* Using the `fill` keyword \*/ mask-border-slice: 10% fill 7 12; /\* Global values \*/ mask-border-slice: inherit; mask-border-slice: initial; mask-border-slice: revert; mask-border-slice: revert-layer; mask-border-slice: unset; ``` The `mask-border-slice` property may be specified using one to four `<number-percentage>` values to represent the position of each image slice. Negative values are invalid; values greater than their corresponding dimension are clamped to `100%`. * When **one** position is specified, it creates all four slices at the same distance from their respective sides. * When **two** positions are specified, the first value creates slices measured from the **top and bottom**, the second creates slices measured from the **left and right**. * When **three** positions are specified, the first value creates a slice measured from the **top**, the second creates slices measured from the **left and right**, the third creates a slice measured from the **bottom**. * When **four** positions are specified, they create slices measured from the **top**, **right**, **bottom**, and **left** in that order (clockwise). The optional `fill` value, if used, can be placed anywhere in the declaration. ### Values [`<number>`](number) Represents an edge offset in *pixels* for raster images and *coordinates* for vector images. For vector images, the number is relative to the element's size, not the size of the source image, so percentages are generally preferable in these cases. [`<percentage>`](percentage) Represents an edge offset as a percentage of the source image's size: the width of the image for horizontal offsets, the height for vertical offsets. `fill` Preserves the middle image region. Its width and height are sized to match the top and left image regions, respectively. Description ----------- The slicing process creates nine regions in total: four corners, four edges, and a middle region. Four slice lines, set a given distance from their respective sides, control the size of the regions. The above diagram illustrates the location of each region. * Zones 1-4 are corner regions. Each one is used a single time to form the corners of the final border image. * Zones 5-8 are edge regions. These are [repeated, scaled, or otherwise modified](mask-border-repeat) in the final border image to match the dimensions of the element. * Zone 9 is the middle region. It is discarded by default, but is used like a background image if the keyword `fill` is set. The [`mask-border-repeat`](mask-border-repeat), [`mask-border-width`](mask-border-width), and [`mask-border-outset`](mask-border-outset) properties determine how these regions are used to form the final mask border. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | all elements; In SVG, it applies to container elements excluding the [`<defs>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs) element and all graphics elements | | [Inherited](inheritance) | no | | Percentages | refer to size of the mask border image | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` mask-border-slice = [[](value_definition_syntax#brackets) [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) []](value_definition_syntax#brackets)[{1,4}](value_definition_syntax#curly_braces) fill[?](value_definition_syntax#question_mark) ``` Examples -------- ### Basic usage This property doesn't appear to be supported anywhere yet. When it eventually starts to be supported, it will serve to define the size of the slices taken from the source image, and used to create the border mask. ``` mask-border-slice: 30 fill; ``` Chromium-based browsers support an outdated version of this property — `mask-box-image-slice` — with a prefix: ``` -webkit-mask-box-image-slice: 30 fill; ``` **Note:** The [`mask-border`](mask-border) page features a working example (using the out-of-date prefixed border mask properties supported in Chromium), so you can get an idea of the effect. **Note:** The fill keyword needs to be included if you want the element's content to be visible. Specifications -------------- | Specification | | --- | | [CSS Masking Module Level 1 # the-mask-border-slice](https://drafts.fxtf.org/css-masking/#the-mask-border-slice) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `mask-border-slice` | 1 | 79 | No See [bug 877294](https://bugzil.la/877294). | No | 15 | 3.1 | 4.4 | 18 | No See [bug 877294](https://bugzil.la/877294). | 14 | 3 | 1.0 | See also -------- * [`mask-border`](mask-border) * [`mask-border-mode`](mask-border-mode) * [`mask-border-outset`](mask-border-outset) * [`mask-border-repeat`](mask-border-repeat) * [`mask-border-source`](mask-border-source) * [`mask-border-width`](mask-border-width) * [Illustrated description of the 1-to-4-value syntax](shorthand_properties#tricky_edge_cases) css -moz-image-region -moz-image-region ================= **Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future. For certain XUL elements and pseudo-elements that use an image from the [`list-style-image`](list-style-image) property, this property specifies a region of the image that is used in place of the whole image. This allows elements to use different pieces of the same image to improve performance. ``` /\* Keyword value \*/ -moz-image-region: auto; /\* <shape> value \*/ -moz-image-region: rect(0, 8px, 4px, 4px); /\* Global values \*/ -moz-image-region: inherit; -moz-image-region: initial; -moz-image-region: unset; ``` The syntax is similar to the [`clip`](clip) property. All four values are relative to the upper left corner of the image. **Note:** For a system that works on any background, see [`-moz-image-rect()`](-moz-image-rect). Syntax ------ ### Values `auto` Automatically defines the region of the image to use. [`<shape>`](shape) A shape defining the part of the image to use. The `rect()` function defines a rectangle to use as shape. Its parameters define the top, right, bottom, and left offsets of the edges of the image, in this order. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | XUL [`<image>`](image) elements and [`:-moz-tree-image`](:-moz-tree-image), [`:-moz-tree-twisty`](:-moz-tree-twisty), and [`:-moz-tree-checkbox`](:-moz-tree-checkbox) pseudo-elements. **Note:** `-moz-image-region` only works with [`<image>`](image) elements where the icon is specified using [`list-style-image`](list-style-image). It will not work with XUL `<image src="url" />`. | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` -moz-image-region = <shape> | auto ``` Examples -------- ### Clipping an image ``` #example-button { /\* display only the 4x4 area from the top left of this image \*/ list-style-image: url("chrome://example/skin/example.png"); -moz-image-region: rect(0px, 4px, 4px, 0px); } #example-button:hover { /\* use the 4x4 area to the right of the first for the hovered button \*/ -moz-image-region: rect(0px, 8px, 4px, 4px); } ``` Specifications -------------- Not part of any standard. Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `-moz-image-region` | No | No | 1 | No | No | No | No | No | 4 | No | No | No | See also -------- * [`-moz-image-rect()`](-moz-image-rect) css border-inline-end-width border-inline-end-width ======================= The `border-inline-end-width` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the width of the logical inline-end border of an element, which maps to a physical border width depending on the element's writing mode, directionality, and text orientation. It corresponds to the [`border-top-width`](border-top-width), [`border-right-width`](border-right-width), [`border-bottom-width`](border-bottom-width), or [`border-left-width`](border-left-width) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ Syntax ------ ``` /\* <'border-width'> values \*/ border-inline-end-width: 2px; border-inline-end-width: thick; /\* Global values \*/ border-inline-end-width: inherit; border-inline-end-width: initial; border-inline-end-width: revert; border-inline-end-width: revert-layer; border-inline-end-width: unset; ``` Related properties are [`border-block-start-width`](border-block-start-width), [`border-block-end-width`](border-block-end-width), and [`border-inline-start-width`](border-inline-start-width), which define the other border widths of the element. ### Values `<'border-width'>` The width of the border. See [`border-width`](border-width). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `medium` | | Applies to | all elements | | [Inherited](inheritance) | no | | Percentages | logical-width of containing block | | [Computed value](computed_value) | absolute length; `0` if the border style is `none` or `hidden` | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` border-inline-end-width = <'border-top-width'> ``` Examples -------- ### Applying a border with vertical text #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; border: 1px solid blue; border-inline-end-width: 5px; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # border-width](https://w3c.github.io/csswg-drafts/css-logical/#border-width) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-inline-end-width` | 69 | 79 | 41 3 | No | 56 | 12.1 | 69 | 69 | 41 4 | 48 | 12.2 | 10.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * This property maps to one of the physical border properties: [`border-top-width`](border-top-width), [`border-right-width`](border-right-width), [`border-bottom-width`](border-bottom-width), and [`border-left-width`](border-left-width) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css text-underline-position text-underline-position ======================= The `text-underline-position` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property specifies the position of the underline which is set using the [`text-decoration`](text-decoration) property's `underline` value. Try it ------ Syntax ------ ``` /\* 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 [user agent](https://developer.mozilla.org/en-US/docs/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 `under`. `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 `under`. `auto-pos` Non-standard Experimental A synonym of `auto`, which should be used instead. `above` Non-standard Forces the line to be above the text. When used with East-Asian text, using the `auto` keyword will lead to a similar effect. `below` Non-standard Forces the line to be below the text. When used with alphabetic text, using the `auto` keyword will lead to a similar effect. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` text-underline-position = auto [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) under [||](value_definition_syntax#double_bar) [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) right []](value_definition_syntax#brackets) []](value_definition_syntax#brackets) ``` Examples -------- ### A simple example Let's take a couple of simple example paragraphs: ``` <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: ``` 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`](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: ### Setting text-underline-position globally Because the `text-underline-position` property inherits and is not reset by the [`text-decoration`](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. ``` :root { text-underline-position: under; } ``` Specifications -------------- | Specification | | --- | | [CSS Text Decoration Module Level 3 # text-underline-position-property](https://w3c.github.io/csswg-drafts/css-text-decor/#text-underline-position-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `text-underline-position` | 33 | 12 | 74 | 6 | 20 | 12.1 9 | 4.4.3 | 33 | No | 20 | No | 2.0 | | `above_below` | No | 12-79 | 74 | 6 | No | No | No | No | No | No | No | No | | `auto-pos` | No | 12-79 | No | 6 | No | No | No | No | No | No | No | No | | `from-font` | 87 | 87 | 74 | No | No | preview | 87 | 87 | No | No | No | 14.0 | | `left_right` | 71 | 79 | 74 | No | 58 | No | 71 | 71 | No | 50 | No | 10.0 | | `under` | 33 | 79 | 74 | No | 20 | 12.1 | 4.4.3 | 33 | No | 20 | No | 2.0 | See also -------- * The [`text-decoration`](text-decoration) property is a shorthand for setting most text-decoration properties, including [`text-decoration-line`](text-decoration-line), [`text-decoration-color`](text-decoration-color), and [`text-decoration-style`](text-decoration-style). However, it does not set `text-underline-position`.
programming_docs
css Adjacent sibling combinator Adjacent sibling combinator =========================== The **adjacent sibling combinator** (`+`) separates two selectors and matches the second element only if it *immediately* follows the first element, and both are children of the same parent [`element`](https://developer.mozilla.org/en-US/docs/Web/API/Element). ``` /\* Paragraphs that come immediately after any image \*/ img + p { font-weight: bold; } ``` Syntax ------ ``` former\_element + target\_element { style properties } ``` Examples -------- ### CSS ``` li:first-of-type + li { color: red; } ``` ### HTML ``` <ul> <li>One</li> <li>Two!</li> <li>Three</li> </ul> ``` ### Result Specifications -------------- | Specification | | --- | | [Selectors Level 4 # adjacent-sibling-combinators](https://w3c.github.io/csswg-drafts/selectors/#adjacent-sibling-combinators) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `Adjacent_sibling_combinator` | 1 | 12 | 1 | 7 ["Before Internet Explorer 10, the combinator only works in standards mode.", "Internet Explorer 7 doesn't update the style correctly when an element is dynamically placed before an element that matched the selector.", "In Internet Explorer 8, if an element is inserted dynamically by clicking on a link the first-child style isn't applied until the link loses focus."] | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | See also -------- * [General sibling combinator](general_sibling_combinator) css -webkit-text-stroke-width -webkit-text-stroke-width ========================= The `-webkit-text-stroke-width` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property specifies the width of the stroke for text. Syntax ------ ``` /\* Keyword values \*/ -webkit-text-stroke-width: thin; -webkit-text-stroke-width: medium; -webkit-text-stroke-width: thick; /\* <length> values \*/ -webkit-text-stroke-width: 2px; -webkit-text-stroke-width: 0.1em; -webkit-text-stroke-width: 1mm; -webkit-text-stroke-width: 5pt; /\* Global values \*/ -webkit-text-stroke-width: inherit; -webkit-text-stroke-width: initial; -webkit-text-stroke-width: unset; ``` ### Values `<line-width>` The width of the stroke. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | absolute [`<length>`](length) | | Animation type | discrete | Formal syntax ------------- ``` -webkit-text-stroke-width = <line-width> <line-width> = [<length [0,∞]>](length) [|](value_definition_syntax#single_bar) thin [|](value_definition_syntax#single_bar) medium [|](value_definition_syntax#single_bar) thick ``` Examples -------- ### Varying stroke widths #### CSS ``` p { margin: 0; font-size: 4em; -webkit-text-stroke-color: red; } #thin { -webkit-text-stroke-width: thin; } #medium { -webkit-text-stroke-width: 3px; } #thick { -webkit-text-stroke-width: 1.5mm; } ``` #### HTML ``` <p id="thin">Thin stroke</p> <p id="medium">Medium stroke</p> <p id="thick">Thick stroke</p> ``` #### Results Specifications -------------- | Specification | | --- | | [Compatibility Standard # the-webkit-text-stroke-width](https://compat.spec.whatwg.org/#the-webkit-text-stroke-width) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `-webkit-text-stroke-width` | 1 | 15 | 49 | No | 15 | 3 | 38 | 18 | 49 | 15 | 2 | 1.0 | See also -------- * [Surfin' Safari blog post announcing this feature](https://webkit.org/blog/85/introducing-text-stroke/) * [CSS-Tricks article explaining this feature](https://css-tricks.com/adding-stroke-to-web-text/) * [`-webkit-text-stroke-color`](-webkit-text-stroke-color) * [`-webkit-text-stroke`](-webkit-text-stroke) * [`-webkit-text-fill-color`](-webkit-text-fill-color) css justify-content justify-content =============== The [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) `justify-content` property defines how the browser distributes space between and around content items along the [main-axis](https://developer.mozilla.org/en-US/docs/Glossary/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. Try it ------ The alignment is done after the lengths and auto margins are applied, meaning that, if in a [Flexbox layout](css_flexible_box_layout) there is at least one flexible element, with [`flex-grow`](flex-grow) different from `0`, it will have no effect as there won't be any available space. Syntax ------ ``` /\* 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 Items have a half-size space on either end \*/ justify-content: space-evenly; /\* Distribute items evenly Items have equal space around them \*/ 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 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`. `normal` The items are packed in their default position as if no `justify-content` value was set. This value behaves as `stretch` in grid and flex containers. `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`. `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 [`max-height`](max-height)/[`max-width`](max-width) (or equivalent functionality), so that the combined size exactly fills the alignment container along the main axis. **Note:** `stretch` is not supported by flexible boxes (flexbox). `safe` Used alongside an alignment keyword. If the chosen keyword means that the item overflows the alignment container causing data loss, the item is instead aligned as if the alignment mode were `start`. `unsafe` Used alongside an alignment keyword. Regardless of the relative sizes of the item and alignment container, and regardless of whether overflow which causes data loss might happen, the given alignment value is honored. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | flex containers | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` justify-content = normal [|](value_definition_syntax#single_bar) <content-distribution> [|](value_definition_syntax#single_bar) <overflow-position>[?](value_definition_syntax#question_mark) [[](value_definition_syntax#brackets) <content-position> [|](value_definition_syntax#single_bar) left [|](value_definition_syntax#single_bar) right []](value_definition_syntax#brackets) <content-distribution> = space-between [|](value_definition_syntax#single_bar) space-around [|](value_definition_syntax#single_bar) space-evenly [|](value_definition_syntax#single_bar) stretch <overflow-position> = unsafe [|](value_definition_syntax#single_bar) safe <content-position> = center [|](value_definition_syntax#single_bar) start [|](value_definition_syntax#single_bar) end [|](value_definition_syntax#single_bar) flex-start [|](value_definition_syntax#single_bar) flex-end ``` Examples -------- ### Setting flex item distribution #### 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); } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Box Alignment Module Level 3 # align-justify-content](https://w3c.github.io/csswg-drafts/css-align/#align-justify-content) | | [CSS Flexible Box Layout Module Level 1 # justify-content-property](https://w3c.github.io/csswg-drafts/css-flexbox/#justify-content-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `justify-content` | 29 21 | 12 12 | 49 20 | 11 | 12.1 | 9 7 | 4.4 4.4 | 29 25 | 49 20 | 12.1 | 9 7 | 2.0 1.5 | | `flex_context` | 52 21-52 Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Chrome implements the new behavior beginning with Chrome 52. | 12 | 20 Before Firefox 27, Firefox supported only single-line flexbox. | 11 | 12.1 | 7 | 52 4.4-52 Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Chrome implements the new behavior beginning with Chrome 52. | 52 25-52 Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Chrome implements the new behavior beginning with Chrome 52. | 20 Before Firefox 27, Firefox supported only single-line flexbox. | 12.1 | 7 | 6.0 1.5-6.0 Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Samsung Internet implements the new behavior beginning with Samsung Internet 6.0. | | `grid_context` | 57 | 16 | 52 | No | 44 | 10.1 | 57 | 52 | 52 | 43 | 10.3 | 6.2 | See also -------- * CSS Flexbox Guide: *[Basic Concepts of Flexbox](css_flexible_box_layout/basic_concepts_of_flexbox)* * CSS Flexbox Guide: *[Aligning items in a flex container](css_flexible_box_layout/aligning_items_in_a_flex_container)* * CSS Grid Guide: *[Box alignment in CSS Grid layouts](css_grid_layout/box_alignment_in_css_grid_layout)* * [CSS Box Alignment](css_box_alignment) css :first-of-type :first-of-type ============== The `:first-of-type` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) represents the first element of its type among a group of sibling elements. Try it ------ Syntax ------ ``` :first-of-type ``` Examples -------- ### Styling the first paragraph #### HTML ``` <h2>Heading</h2> <p>Paragraph 1</p> <p>Paragraph 2</p> ``` #### CSS ``` p:first-of-type { color: red; font-style: italic; } ``` #### Result ### Nested elements This example shows how nested elements can also be targeted. Note that the [universal selector](universal_selectors) (`*`) is implied when no type selector is written. #### HTML ``` <article> <div>This `div` is first!</div> <div>This <span>nested `span` is first</span>!</div> <div> This <em>nested `em` is first</em>, but this <em>nested `em` is last</em>! </div> <div>This <span>nested `span` gets styled</span>!</div> <p>This `p` qualifies!</p> <div>This is the final `div`.</div> </article> ``` #### CSS ``` article :first-of-type { background-color: pink; } ``` #### Result Specifications -------------- | Specification | | --- | | [Selectors Level 4 # first-of-type-pseudo](https://w3c.github.io/csswg-drafts/selectors/#first-of-type-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:first-of-type` | 1 | 12 Before Edge 16, Microsoft Edge treats all unknown elements (such as custom elements) as the same element type. | 3.5 | 9 Internet Explorer treats all unknown elements (such as custom elements) as the same element type. | 9.5 | 3.1 | 2 | 18 | 4 | 10.1 | 2 | 1.0 | See also -------- * [`:first-child`](:first-child), [`:last-of-type`](:last-of-type), [`:nth-of-type`](:nth-of-type) css atan2() atan2() ======= The `atan2()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](css_functions) is a trigonometric function that returns the inverse tangent of two values between `-infinity` and `infinity`. The function accepts two arguments and returns the number of radians representing an [`<angle>`](angle) between `-180deg` and `180deg`. Syntax ------ ``` /\* Single <number> values \*/ transform: rotate(atan2(3, 2)); /\* Single <dimension> values \*/ transform: rotate(atan2(1rem, -0.5rem)); /\* Single <percentage> values \*/ transform: rotate(atan2(20%, -30%)); /\* Other values \*/ transform: rotate(atan2(pi, 45)); transform: rotate(atan2(e, 30)); ``` ### Parameters The `atan2(y, x)` function accepts two comma-separated values as its parameters. The values can be [`<number>`](number), [`<dimension>`](dimension), or [`<percentage>`](percentage) types, but both must be the same type. `y` The y coordinate of the point. A calculation which resolves to a [`<number>`](number), a [`<dimension>`](dimension), or a [`<percentage>`](percentage). `x` The x coordinate of the point. A calculation which resolves to a [`<number>`](number), a [`<dimension>`](dimension), or a [`<percentage>`](percentage). ### Return value Given two points `x` and `y`, the function `atan2(y, x)` calculates and returns the [`<angle>`](angle) between the positive `x` axis and the ray from the origin to the point `(x, y)`. ### Formal syntax ``` <atan2()> = atan2( <calc-sum> , <calc-sum> ) <calc-sum> = <calc-product> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '+' [|](value_definition_syntax#single_bar) '-' []](value_definition_syntax#brackets) <calc-product> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-product> = <calc-value> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '*' [|](value_definition_syntax#single_bar) '/' []](value_definition_syntax#brackets) <calc-value> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-value> = [<number>](number) [|](value_definition_syntax#single_bar) [<dimension>](dimension) [|](value_definition_syntax#single_bar) [<percentage>](percentage) [|](value_definition_syntax#single_bar) <calc-constant> [|](value_definition_syntax#single_bar) ( <calc-sum> ) <calc-constant> = e [|](value_definition_syntax#single_bar) pi [|](value_definition_syntax#single_bar) infinity [|](value_definition_syntax#single_bar) -infinity [|](value_definition_syntax#single_bar) NaN ``` Examples -------- ### Rotate elements The `atan2()` function can be used to [`rotate`](transform-function/rotate) elements as it return an [`<angle>`](angle). #### 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 ``` div.box { width: 100px; height: 100px; background: linear-gradient(orange, red); } div.box-1 { transform: rotate(atan2(3, 2)); } div.box-2 { transform: rotate(atan2(3%, -2%)); } div.box-3 { transform: rotate(atan2(-1, 0.5)); } div.box-4 { transform: rotate(atan2(1, 0.5)); } div.box-5 { transform: rotate(atan2(1rem, -0.5rem)); } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # trig-funcs](https://w3c.github.io/csswg-drafts/css-values/#trig-funcs) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `atan2` | No | No | 108 | No | No | 15.4 | No | No | 108 | No | 15.4 | No | See also -------- * [`sin()`](sin) * [`cos()`](cos) * [`tan()`](tan) * [`asin()`](asin) * [`acos()`](acos) * [`atan()`](atan)
programming_docs
css border-inline-end-color border-inline-end-color ======================= The `border-inline-end-color` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the color of the logical inline-end border of an element, which maps to a physical border color depending on the element's writing mode, directionality, and text orientation. It corresponds to the [`border-top-color`](border-top-color), [`border-right-color`](border-right-color), [`border-bottom-color`](border-bottom-color), or [`border-left-color`](border-left-color) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ Syntax ------ ``` border-inline-end-color: rebeccapurple; border-inline-end-color: #663399; /\* Global values \*/ border-inline-end-color: inherit; border-inline-end-color: initial; border-inline-end-color: revert; border-inline-end-color: revert-layer; border-inline-end-color: unset; ``` Related properties are [`border-block-start-color`](border-block-start-color), [`border-block-end-color`](border-block-end-color), and [`border-inline-start-color`](border-inline-start-color), which define the other border colors of the element. ### Values `<'color'>` The color of the border. See [`color`](color). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `currentcolor` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | computed color | | Animation type | a [color](color_value#interpolation) | Formal syntax ------------- ``` border-inline-end-color = <'border-top-color'> ``` Examples -------- ### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` ### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; border: 10px solid blue; border-inline-end-color: red; } ``` Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # border-color](https://w3c.github.io/csswg-drafts/css-logical/#border-color) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-inline-end-color` | 69 | 79 | 41 3 | No | 56 | 12.1 | 69 | 69 | 41 4 | 48 | 12.2 | 10.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * This property maps to one of the physical border properties: [`border-top-color`](border-top-color), [`border-right-color`](border-right-color), [`border-bottom-color`](border-bottom-color), or [`border-left-color`](border-left-color). * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css grid-row-end grid-row-end ============ The `grid-row-end` CSS property specifies a grid item's end position within the grid row by contributing a line, a span, or nothing (automatic) to its grid placement, thereby specifying the inline-end edge of its [grid area](https://developer.mozilla.org/en-US/docs/Glossary/Grid_Areas). Try it ------ Syntax ------ ``` /\* Keyword value \*/ grid-row-end: auto; /\* <custom-ident> values \*/ grid-row-end: somegridarea; /\* <integer> + <custom-ident> values \*/ grid-row-end: 2; grid-row-end: somegridarea 4; /\* span + <integer> + <custom-ident> values \*/ grid-row-end: span 3; grid-row-end: span somegridarea; grid-row-end: 5 somegridarea span; /\* Global values \*/ grid-row-end: inherit; grid-row-end: initial; grid-row-end: revert; grid-row-end: revert-layer; grid-row-end: unset; ``` ### Values `auto` Is a keyword indicating that the property contributes nothing to the grid item's placement, indicating auto-placement, an automatic span, or a default span of `1`. `<custom-ident>` If there is a named line with the name '<custom-ident>-end', it contributes the first such line to the grid item's placement. **Note:** Named grid areas automatically generate implicit named lines of this form, so specifying `grid-row-end: foo;` will choose the end edge of that named grid area (unless another line named `foo-end` was explicitly specified before it). Otherwise, this is treated as if the integer `1` had been specified along with the `<custom-ident>`. The `<custom-ident>` cannot take the `span` value. `<integer> && <custom-ident>?` Contributes the nth grid line to the grid item's placement. If a negative integer is given, it instead counts in reverse, starting from the end edge of the explicit grid. If a name is given as a <custom-ident>, only lines with that name are counted. If not enough lines with that name exist, all implicit grid lines are assumed to have that name for the purpose of finding this position. An [`<integer>`](integer) value of `0` is invalid. `span && [ <integer> || <custom-ident> ]` Contributes a grid span to the grid item's placement such that the row end edge of the grid item's grid area is n lines from the start edge. If a name is given as a <custom-ident>, only lines with that name are counted. If not enough lines with that name exist, all implicit grid lines on the side of the explicit grid corresponding to the search direction are assumed to have that name for the purpose of counting this span. If the <integer> is omitted, it defaults to `1`. Negative integers or 0 are invalid. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | grid items and absolutely-positioned boxes whose containing block is a grid container | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` grid-row-end = <grid-line> <grid-line> = auto [|](value_definition_syntax#single_bar) [<custom-ident>](custom-ident) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) [<integer [-∞,-1]>](integer) [|](value_definition_syntax#single_bar) [<integer [1,∞]>](integer) []](value_definition_syntax#brackets) [&&](value_definition_syntax#double_ampersand) [<custom-ident>](custom-ident)[?](value_definition_syntax#question_mark) []](value_definition_syntax#brackets) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) span [&&](value_definition_syntax#double_ampersand) [[](value_definition_syntax#brackets) [<integer [1,∞]>](integer) [||](value_definition_syntax#double_bar) [<custom-ident>](custom-ident) []](value_definition_syntax#brackets) []](value_definition_syntax#brackets) ``` Examples -------- ### Setting row end for a grid item #### HTML ``` <div class="wrapper"> <div class="box1">One</div> <div class="box2">Two</div> <div class="box3">Three</div> <div class="box4">Four</div> <div class="box5">Five</div> </div> ``` #### CSS ``` .wrapper { display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 100px; } .box1 { grid-column-start: 1; grid-column-end: 4; grid-row-start: 1; grid-row-end: 3; } .box2 { grid-column-start: 1; grid-row-start: 3; grid-row-end: 5; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Grid Layout Module Level 2 # line-placement](https://w3c.github.io/csswg-drafts/css-grid/#line-placement) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `grid-row-end` | 57 | 16 | 52 | No | 44 | 10.1 | 57 | 57 | 52 | 43 | 10.3 | 6.0 | See also -------- * Related CSS properties: [`grid-row-start`](grid-row-start), [`grid-row`](grid-row), [`grid-column-start`](grid-column-start), [`grid-column-end`](grid-column-end), [`grid-column`](grid-column) * Grid Layout Guide: *[Line-based placement with CSS Grid](css_grid_layout/line-based_placement_with_css_grid)* * Video tutorial: *[Line-based placement](https://gridbyexample.com/video/series-line-based-placement/)* css justify-items justify-items ============= The [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) `justify-items` property defines the default [`justify-self`](justify-self) for all items of the box, giving them all a default way of justifying each box along the appropriate axis. Try it ------ The effect of this property is dependent of the layout mode we are in: * In block-level layouts, it aligns the items inside their containing block on the inline axis. * For absolutely-positioned elements, it aligns the items inside their 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* ([more](css_box_alignment/box_alignment_in_block_abspos_tables) about alignment in block, absolute positioned and table layout) * In flexbox layouts, this property is *ignored* ([more](css_box_alignment/box_alignment_in_flexbox) about alignment in Flexbox) * In grid layouts, it aligns the items inside their grid areas on the inline axis ([more](css_box_alignment/box_alignment_in_grid_layout) about alignment in grid layouts) Syntax ------ ``` /\* Basic keywords \*/ justify-items: normal; justify-items: stretch; /\* Positional alignment \*/ justify-items: center; /\* Pack items around the center \*/ justify-items: start; /\* Pack items from the start \*/ justify-items: end; /\* Pack items from the end \*/ justify-items: flex-start; /\* Equivalent to 'start'. Note that justify-items is ignored in Flexbox layouts. \*/ justify-items: flex-end; /\* Equivalent to 'end'. Note that justify-items is ignored in Flexbox layouts. \*/ justify-items: self-start; justify-items: self-end; justify-items: left; /\* Pack items from the left \*/ justify-items: right; /\* Pack items from the right \*/ /\* Baseline alignment \*/ justify-items: baseline; justify-items: first baseline; justify-items: last baseline; /\* Overflow alignment (for positional alignment only) \*/ justify-items: safe center; justify-items: unsafe center; /\* Legacy alignment \*/ justify-items: legacy right; justify-items: legacy left; justify-items: legacy center; /\* Global values \*/ justify-items: inherit; justify-items: initial; justify-items: revert; justify-items: revert-layer; justify-items: unset; ``` This property can take one of four different forms: * Basic keywords: one of the keyword values `normal` 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`. * Legacy alignment: the `legacy` keyword, followed by one of `left` or `right`. ### Values `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 behaved 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 [`max-height`](max-height)/[`max-width`](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. `legacy` Makes the value inherited by the box descendants. Note that if a descendant has a `justify-self: auto` value, the `legacy` keyword is not considered by the descend, only the `left`, `right`, or `center` value associated to it. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `legacy` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` justify-items = normal [|](value_definition_syntax#single_bar) stretch [|](value_definition_syntax#single_bar) <baseline-position> [|](value_definition_syntax#single_bar) <overflow-position>[?](value_definition_syntax#question_mark) [[](value_definition_syntax#brackets) <self-position> [|](value_definition_syntax#single_bar) left [|](value_definition_syntax#single_bar) right []](value_definition_syntax#brackets) [|](value_definition_syntax#single_bar) legacy [|](value_definition_syntax#single_bar) legacy [&&](value_definition_syntax#double_ampersand) [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) center []](value_definition_syntax#brackets) <baseline-position> = [[](value_definition_syntax#brackets) first [|](value_definition_syntax#single_bar) last []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) [&&](value_definition_syntax#double_ampersand) baseline <overflow-position> = unsafe [|](value_definition_syntax#single_bar) safe <self-position> = center [|](value_definition_syntax#single_bar) start [|](value_definition_syntax#single_bar) end [|](value_definition_syntax#single_bar) self-start [|](value_definition_syntax#single_bar) self-end [|](value_definition_syntax#single_bar) flex-start [|](value_definition_syntax#single_bar) flex-end ``` 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. If you hover or tab onto the grid container however, it is given a `justify-items` value of `center`, which causes the grid items to span only as wide as their content width, and align in the center of their cells. #### HTML ``` <article class="container" tabindex="0"> <span>First child</span> <span>Second child</span> <span>Third child</span> <span>Fourth child</span> </article> ``` #### 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; } article:hover, article:focus { justify-items: center; } article span { background-color: black; color: white; margin: 1px; text-align: center; } article, span { padding: 10px; border-radius: 7px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Box Alignment Module Level 3 # justify-items-property](https://w3c.github.io/csswg-drafts/css-align/#justify-items-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `justify-items` | 52 | 12 | 20 | 11 | 12.1 | 9 | 52 | 52 | 20 | 12.1 | 9 | 6.0 | | `flex_context` | 52 | 12 | 20 | 11 | 12.1 | 9 | 52 | 52 | 20 | 12.1 | 9 | 6.0 | | `grid_context` | 57 | 16 | 45 | No | 44 | 10.1 | 57 | 57 | 45 | 43 | 10.3 | 6.0 | See also -------- * CSS Grid Guide: *[Box alignment in CSS Grid layouts](css_grid_layout/box_alignment_in_css_grid_layout)* * [CSS Box Alignment](css_box_alignment) * The [`place-items`](place-items) shorthand property * The [`justify-self`](justify-self) property * The [`align-items`](align-items) property css revert-layer revert-layer ============ **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `revert-layer` CSS keyword rolls back the value of a property in a [`cascade layer`](@layer) to the value of the property in a CSS rule matching the element in a previous cascade layer. The value of the property with this keyword is recalculated as if no rules were specified on the target element in the current cascade layer. If there is no other cascade layer to revert to for the matching CSS rule, the property value rolls back to the [`computed value`](computed_value) derived from the current layer. Furthermore, if there is no matching CSS rule in the current layer, the property value for the element rolls back to the style defined in a previous [style origin](https://developer.mozilla.org/en-US/docs/Glossary/Style_origin). This keyword can be applied to any CSS property, including the CSS shorthand property [`all`](all). Revert-layer vs revert ---------------------- The `revert-layer` keyword lets you rollback styles to the ones specified in previous cascade layers. All cascade layers exist in the [author origin](https://developer.mozilla.org/en-US/docs/Glossary/Style_origin). The [`revert`](revert) keyword, in comparison, lets you remove styles applied in the author origin and roll back to styles in user origin or user-agent origin. The `revert-layer` keyword is ideally meant for applying on properties inside a layer. However, if the `revert-layer` keyword is set on a property outside a layer, the value of the property will roll back to the default value established by the user agent's stylesheet (or by user styles, if any exist). So in this scenario, the `revert-layer` keyword behaves like the [`revert`](revert) keyword. Examples -------- ### Default cascade layer behavior In the example below, two cascade layers are defined in the CSS, `base` and `special`. By default, rules in the `special` layer will override competing rules in the `base` layer because `special` is listed after `base` in the `@layer` declaration statement. #### HTML ``` <p>This example contains a list.</p> <ul> <li class="item feature">Item one</li> <li class="item">Item two</li> <li class="item">Item three</li> </ul> ``` #### CSS ``` @layer base, special; @layer special { .item { color: red; } } @layer base { .item { color: blue; } .feature { color: green; } } ``` #### Result All the `<li>` elements match the `item` rule in the `special` layer and are red. This is the default cascade layer behavior, where rules in the `special` layer take precedence over rules in the `base` layer. ### Revert to style in previous cascade layer Let's examine how the `revert-layer` keyword changes the default cascade layer behavior. For this example, the `special` layer contains an additional `feature` rule targeting the first `<li>` element. The `color` property in this rule is set to `revert-layer`. #### HTML ``` <p>This example contains a list.</p> <ul> <li class="item feature">Item one</li> <li class="item">Item two</li> <li class="item">Item three</li> </ul> ``` #### CSS ``` @layer base, special; @layer special { .item { color: red; } .feature { color: revert-layer; } } @layer base { .item { color: blue; } .feature { color: green; } } ``` #### Result With `color` set to `revert-layer`, the `color` property value rolls back to the value in the matching `feature` rule in the previous layer `base`, and so 'Item one' is now green. ### Revert to style in previous origin This example shows the `revert-layer` keyword behavior when there is no cascade layer to revert to *and* there is no matching CSS rule in the current layer to inherit the property value. #### HTML ``` <p>This example contains a list.</p> <ul> <li class="item feature">Item one</li> <li class="item">Item two</li> <li class="item">Item three</li> </ul> ``` #### CSS ``` @layer base { .item { color: revert-layer; } } ``` #### Result The style for all `<li>` elements rolls back to the defaults in the user-agent origin. Specifications -------------- | Specification | | --- | | [CSS Cascading and Inheritance Level 5 # revert-layer](https://w3c.github.io/csswg-drafts/css-cascade-5/#revert-layer) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `revert-layer` | No | No | 97 | No | No | No | No | No | 97 | No | No | No | See also -------- * Use the [`initial`](initial) keyword to set a property to its initial value. * Use the [`inherit`](inherit) keyword to make an element's property the same as its parent. * Use the [`revert`](revert) keyword to reset a property to the value established by the user-agent stylesheet (or by user styles, if any exist). * Use the [`unset`](unset) keyword to set a property to its inherited value if it inherits or to its initial value if not. * The [`all`](all) property lets you reset all properties to their initial, inherited, reverted, or unset state at once.
programming_docs
css @page @page ===== The `@page` at-rule is a CSS at-rule used to modify different aspects of a printed page property. It targets and modifies the page's dimensions, page orientation, and margins. The `@page` at-rule can be used to target all pages in a print-out, or even specific ones using its various pseudo-classes. Syntax ------ ``` /\* Targets all the pages \*/ @page { size: 8.5in 9in; margin-top: 4in; } /\* Targets all even-numbered pages \*/ @page :left { margin-top: 4in; } /\* Targets all odd-numbered pages \*/ @page :right { size: 11in; margin-top: 4in; } ``` ### Descriptors [`size`](@page/size) Specifies the target size and orientation of the page box's containing block. In the general case, where one page box is rendered onto one page sheet, it also indicates the size of the destination page sheet. Description ----------- **Note:** This documentation lists out features yet to be implemented across UAs, but they are stated in the official documentation. At the time of this writing, the only CSS property shown to have visible on both the at-rule and its pseudo-classes is the `margin` property. You can't change all CSS properties with `@page`. You can only change the margin of the document. Attempts to change any other CSS properties will be ignored. The `@page` at-rule can be accessed via the CSS object model interface [`CSSPageRule`](https://developer.mozilla.org/en-US/docs/Web/API/CSSPageRule). **Note:** The W3C is discussing how to handle viewport-related [`<length>`](length) units, `vh`, `vw`, `vmin`, and `vmax`. Meanwhile do not use them within a `@page` at-rule. Formal syntax ------------- ``` @page = @page <page-selector-list>[?](value_definition_syntax#question_mark) { [<declaration-list>](declaration-list) } <page-selector-list> = <page-selector>[#](value_definition_syntax#hash_mark) <page-selector> = [[](value_definition_syntax#brackets) [<ident-token>](ident-token)[?](value_definition_syntax#question_mark) <pseudo-page>[\*](value_definition_syntax#asterisk) ]! <pseudo-page> = ':' [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) first [|](value_definition_syntax#single_bar) blank []](value_definition_syntax#brackets) ``` Where the `<page-body>` includes: * page-properties * page-margin properties and `<pseudo-selector>` represents these pseudo-classes: * [`:blank`](:blank) * [`:first`](:first) * [`:left`](:left) * [`:right`](:right) **Note:** The `@page` at-rule can only contain **page-properties** and **margin at-rules**, and the **margin at-rules** can only contain **page-margin properties** ### page-properties | Feature | CSS properties | | --- | --- | | bidi properties | direction | | background properties | background-color | | | background-image | | | background-repeat | | | background-attachment | | | background-position | | | background | | border properties | border-top-width | | | border-right-width | | | border-bottom-width | | | border-left-width | | | border-width | | | border-top-color | | | border-right-color | | | border-bottom-color | | | border-left-color | | | border-color | | | border-top-style | | | border-right-style | | | border-bottom-style | | | border-left-style | | | border-short-style | | | border-top | | | border-right | | | border-bottom | | | border-left | | | border | | counter properties | counter-reset | | | counter-increment | | color | color | | font properties | font-family | | | font-size | | | font-style | | | font-variant | | | font-weight | | | font | | height properties | height | | | min-height | | | max-height | | line height | line-height | | margin properties | margin-top | | | margin-right | | | margin-bottom | | | margin-left | | | margin | | outline properties | outline-width | | | outline-style | | | outline-color | | | outline | | padding properties | padding-top | | | padding-right | | | padding-bottom | | | padding-left | | | padding | | quotes | quotes | | text properties | letter-spacing | | | text-align | | | text-decoration | | | text-indent | | | text-transform | | | white-space | | | word-spacing | | visibility | visibility | | width properties | width | | | min-width | | | max-width | ### margin at-rules The margin at-rules are used inside of the `@page` at-rule. They each target a different section of the document printed page and make changes based on the properties or content set in the block of code: ``` @page { @top-left { <page-margin-properties> } } ``` `@top-left` targets the top-left of the document and applies the changes based on the page-margin-properties set. Other margin-at rules include: ``` @top-left-corner { <page-margin-properties> } @top-left { <page-margin-properties> } @top-center { <page-margin-properties> } @top-right { <page-margin-properties> } @top-right-corner { <page-margin-properties> } @bottom-left-corner { <page-margin-properties> } @bottom-left { <page-margin-properties> } @bottom-center { <page-margin-properties> } @bottom-right { <page-margin-properties> } @bottom-right-corner { <page-margin-properties> } @left-top { <page-margin-properties> } @left-middle { <page-margin-properties> } @left-bottom { <page-margin-properties> } @right-top { <page-margin-properties> } @right-middle { <page-margin-properties> } @right-bottom { <page-margin-properties> } ``` #### page-margin properties The page-margin properties are the set of CSS properties can be set in any individual margin at-rule. They include: | Feature | CSS properties | | --- | --- | | bidi properties | direction | | background properties | background-color | | | background-image | | | background-repeat | | | background-attachment | | | background-position | | | background | | border properties | border-top-width | | | border-right-width | | | border-bottom-width | | | border-left-width | | | border-width | | | border-top-color | | | border-right-color | | | border-bottom-color | | | border-left-color | | | border-color | | | border-top-style | | | border-right-style | | | border-bottom-style | | | border-left-style | | | border-short-style | | | border-top | | | border-right | | | border-bottom | | | border-left | | | border | | counter properties | counter-reset | | | counter-increment | | content | content | | color | color | | font properties | font-family | | | font-size | | | font-style | | | font-variant | | | font-weight | | | font | | height properties | height | | | min-height | | | max-height | | line height | line-height | | margin properties | margin-top | | | margin-right | | | margin-bottom | | | margin-left | | | margin | | outline properties | outline-width | | | outline-style | | | outline-color | | | outline | | padding properties | padding-top | | | padding-right | | | padding-bottom | | | padding-left | | | padding | | quotes | quotes | | text properties | letter-spacing | | | text-align | | | text-decoration | | | text-indent | | | text-transform | | | white-space | | | word-spacing | | vertical alignment | vertical-align | | visibility | visibility | | width properties | width | | | min-width | | | max-width | | z-index | z-index | Examples -------- The example below prints out 5 different sections in `landscape` size, and adds a 20% margin to each of them in the print-out. HTML: ``` <article> <section> <h2>Header</h2> <p> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consequatur facilis vitae voluptatibus odio consequuntur optio placeat? Id, nam sequi aut in dolorem dolores, laudantium, quasi totam ipsam aliquam quibusdam velit. </p> </section> <section> <h2>Header</h2> <p> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consequatur facilis vitae voluptatibus odio consequuntur optio placeat? Id, nam sequi aut in dolorem dolores, laudantium, quasi totam ipsam aliquam quibusdam velit. </p> </section> <section> <h2>Header</h2> <p> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consequatur facilis vitae voluptatibus odio consequuntur optio placeat? Id, nam sequi aut in dolorem dolores, laudantium, quasi totam ipsam aliquam quibusdam velit. </p> </section> <section> <h2>Header</h2> <p> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consequatur facilis vitae voluptatibus odio consequuntur optio placeat? Id, nam sequi aut in dolorem dolores, laudantium, quasi totam ipsam aliquam quibusdam velit. </p> </section> <section> <h2>Header</h2> <p> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consequatur facilis vitae voluptatibus odio consequuntur optio placeat? Id, nam sequi aut in dolorem dolores, laudantium, quasi totam ipsam aliquam quibusdam velit. </p> </section> </article> <button>Print Webpage</button> ``` CSS: ``` @page { size: landscape; margin: 20%; } body { font-family: "Helvetica"; background-color: rgb(110 110 119); } article { width: 100%; } section { display: grid; background-color: white; border-radius: 0.6rem; margin-block-end: 1.5rem; justify-items: center; padding: 1rem; width: 50%; page-break-after: always; break-after: page; print-color-adjust: exact; -webkit-print-color-adjust: exact; } section { page-break-after: always; break-after: page; } ``` JavaScript: ``` const button = document.querySelector("button"); button.addEventListener("click", () => { window.print(); }); ``` Print out the page below to see the output of this example: ### @page pseudo-class examples Please refer to the various <pseudo-classes> of `@page` for examples. * [`:blank`](:blank) * [`:first`](:first) * [`:left`](:left) * [`:right`](:right) Specifications -------------- | Specification | | --- | | [CSS Paged Media Module Level 3 # at-page-rule](https://w3c.github.io/csswg-drafts/css-page/#at-page-rule) | | [CSS Logical Properties and Values Level 1 # page](https://w3c.github.io/csswg-drafts/css-logical/#page) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `@page` | 2 | 12 | 19 | 8 | 6 | No | 37 | 18 | 19 | 14 | No | 1.0 | | `page-orientation` | 85 | 85 | No | No | 71 | No | 85 | 85 | No | 60 | No | 14.0 | | `size` | 15 | 79 | No | No | 15 | No | 37 | 18 | No | 14 | No | 1.5 | See also -------- * See the [[META] CSS Paged Media Module Level 3](https://bugzilla.mozilla.org/show_bug.cgi?id=286443) ticket in Bugzilla for tracking progress on the subject (page-based counters, etc.) css mask-border-mode mask-border-mode ================ The `mask-border-mode` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property specifies the blending mode used in a [mask border](mask-border). Syntax ------ ``` /\* Keyword values \*/ mask-border-mode: luminance; mask-border-mode: alpha; /\* Global values \*/ mask-border-mode: inherit; mask-border-mode: initial; mask-border-mode: revert; mask-border-mode: revert-layer; mask-border-mode: unset; ``` ### Values `luminance` The luminance values of the mask border image are used as the mask values. `alpha` The alpha values of the mask border image are used as the mask values. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `alpha` | | Applies to | all elements; In SVG, it applies to container elements excluding the [`<defs>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs) element and all graphics elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` mask-border-mode = luminance [|](value_definition_syntax#single_bar) alpha ``` Examples -------- ### Basic usage This property doesn't yet seem to have support anywhere. When browsers support it, it will specify the type of blending mode used for the mask border — luminance or alpha: ``` mask-border-mode: luminance; mask-border-mode: alpha; ``` Specifications -------------- **No specification found**No specification data found for `css.properties.mask-border-mode`. [Check for problems with this page](#on-github) or contribute a missing `spec_url` to [mdn/browser-compat-data](https://github.com/mdn/browser-compat-data). Also make sure the specification is included in [w3c/browser-specs](https://github.com/w3c/browser-specs). Browser compatibility --------------------- No compatibility data found for `css.properties.mask-border-mode`. [Check for problems with this page](#on-github) or contribute missing data to [mdn/browser-compat-data](https://github.com/mdn/browser-compat-data). See also -------- * [`mask-border`](mask-border) * [`mask-border-outset`](mask-border-outset) * [`mask-border-repeat`](mask-border-repeat) * [`mask-border-source`](mask-border-source) * [`mask-border-width`](mask-border-width) css shape-margin shape-margin ============ The `shape-margin` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets a margin for a CSS shape created using [`shape-outside`](shape-outside). Try it ------ The margin lets you adjust the distance between the edges of the shape (the **float element**) and the surrounding content. Syntax ------ ``` /\* <length> values \*/ shape-margin: 10px; shape-margin: 20mm; /\* <percentage> value \*/ shape-margin: 60%; /\* Global values \*/ shape-margin: inherit; shape-margin: initial; shape-margin: revert; shape-margin: revert-layer; shape-margin: unset; ``` ### Values `<length-percentage>` Sets the margin of the shape to a [`<length>`](length) value or to a [`<percentage>`](percentage) of the width of the element's containing block. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | floats | | [Inherited](inheritance) | no | | Percentages | refer to the width of the containing block | | [Computed value](computed_value) | as specified, but with relative lengths converted into absolute lengths | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` shape-margin = <length-percentage> <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Adding a margin to a polygon #### HTML ``` <section> <div class="shape"></div> We are not quite sure of any one thing in biology; our knowledge of geology is relatively very slight, and the economic laws of society are uncertain to every one except some individual who attempts to set them forth; but before the world was fashioned the square on the hypotenuse was equal to the sum of the squares on the other two sides of a right triangle, and it will be so after this world is dead; and the inhabitant of Mars, if one exists, probably knows its truth as we know it. </section> ``` #### CSS ``` section { max-width: 400px; } .shape { float: left; width: 150px; height: 150px; background-color: maroon; clip-path: polygon(0 0, 150px 150px, 0 150px); shape-outside: polygon(0 0, 150px 150px, 0 150px); shape-margin: 20px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Shapes Module Level 1 # shape-margin-property](https://w3c.github.io/csswg-drafts/css-shapes/#shape-margin-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `shape-margin` | 37 | 79 | 62 | No | 24 | 10.1 10.1 | 37 | 37 | 62 | 24 | 10.3 | 3.0 | See also -------- * [CSS Shapes](css_shapes) * [Overview of CSS Shapes](css_shapes/overview_of_css_shapes) * [`shape-outside`](shape-outside) * [`shape-image-threshold`](shape-image-threshold) * [`<basic-shape>`](basic-shape) css -webkit-text-stroke-color -webkit-text-stroke-color ========================= The `-webkit-text-stroke-color` CSS property specifies the stroke [color](color_value) of characters of text. If this property is not set, the value of the [`color`](color) property is used. ``` /\* <color> values \*/ -webkit-text-stroke-color: red; -webkit-text-stroke-color: #e08ab4; -webkit-text-stroke-color: rgb(200, 100, 0); /\* Global values \*/ -webkit-text-stroke-color: inherit; -webkit-text-stroke-color: initial; -webkit-text-stroke-color: unset; ``` Syntax ------ ### Values `<color>` The color of the stroke. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `currentcolor` | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | computed color | | Animation type | a [color](color_value#interpolation) | Formal syntax ------------- ``` -webkit-text-stroke-color = [<color>](color_value) ``` Examples -------- ### Varying the stroke color #### HTML ``` <p>Text with stroke</p> <input type="color" value="#ff0000" /> ``` #### CSS ``` p { margin: 0; font-size: 4em; -webkit-text-stroke-width: 3px; -webkit-text-stroke-color: #ff0000; /\* Can be changed in the live sample \*/ } ``` #### Results Specifications -------------- | Specification | | --- | | [Compatibility Standard # the-webkit-text-stroke-color](https://compat.spec.whatwg.org/#the-webkit-text-stroke-color) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `-webkit-text-stroke-color` | 1 | 15 | 49 | No | 15 | 3 | 37 | 18 | 49 | 15 | 2 | 1.0 | See also -------- * [Surfin' Safari blog post announcing this feature](https://webkit.org/blog/85/introducing-text-stroke/) * [CSS-Tricks article explaining this feature](https://css-tricks.com/adding-stroke-to-web-text/) * [`-webkit-text-fill-color`](-webkit-text-fill-color) * [`-webkit-text-stroke-width`](-webkit-text-stroke-width) * [`-webkit-text-stroke`](-webkit-text-stroke) css acos() acos() ====== The `acos()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](css_functions) is a trigonometric function that returns the inverse cosine of a number between `-1` and `1`. The function contains a single calculation that returns the number of radians representing an [`<angle>`](angle) between `0deg` and `180deg`. Syntax ------ ``` /\* Single <number> values \*/ transform: rotate(acos(-0.2)); transform: rotate(acos(2 * 0.125)); /\* Other values \*/ transform: rotate(acos(pi / 5)); transform: rotate(acos(e / 3)); ``` ### Parameter The `acos(number)` function accepts only one value as its parameter. `number` A calculation which resolves to a [`<number>`](number) between `-1` and `1`. ### Return value The inverse cosine of an `number` will always return an [`<angle>`](angle) between `0deg` and `180deg`. * If `number` is less than `-1` or greater than `1`, the result is `NaN`. * If `number` is exactly `1`, the result is `0`. ### Formal syntax ``` <acos()> = acos( <calc-sum> ) <calc-sum> = <calc-product> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '+' [|](value_definition_syntax#single_bar) '-' []](value_definition_syntax#brackets) <calc-product> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-product> = <calc-value> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '*' [|](value_definition_syntax#single_bar) '/' []](value_definition_syntax#brackets) <calc-value> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-value> = [<number>](number) [|](value_definition_syntax#single_bar) [<dimension>](dimension) [|](value_definition_syntax#single_bar) [<percentage>](percentage) [|](value_definition_syntax#single_bar) <calc-constant> [|](value_definition_syntax#single_bar) ( <calc-sum> ) <calc-constant> = e [|](value_definition_syntax#single_bar) pi [|](value_definition_syntax#single_bar) infinity [|](value_definition_syntax#single_bar) -infinity [|](value_definition_syntax#single_bar) NaN ``` Examples -------- ### Rotate elements The `acos()` function can be used to [`rotate`](transform-function/rotate) elements as it return an [`<angle>`](angle). #### 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 ``` div.box { width: 100px; height: 100px; background: linear-gradient(orange, red); } div.box-1 { transform: rotate(acos(1)); } div.box-2 { transform: rotate(acos(0.5)); } div.box-3 { transform: rotate(acos(0)); } div.box-4 { transform: rotate(acos(-0.5)); } div.box-5 { transform: rotate(acos(-1)); } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # trig-funcs](https://w3c.github.io/csswg-drafts/css-values/#trig-funcs) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `acos` | No | No | 108 | No | No | 15.4 | No | No | 108 | No | 15.4 | No | See also -------- * [`sin()`](sin) * [`cos()`](cos) * [`tan()`](tan) * [`asin()`](asin) * [`atan()`](atan) * [`atan2()`](atan2)
programming_docs
css :nth-child() :nth-child() ============ The `:nth-child()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) matches elements based on their position among a group of siblings. Try it ------ Note that, in the `element:nth-child()` syntax, the child count includes children of any element type; but it is considered a match only if the element *at that child position* is of the specified element type. Syntax ------ `:nth-child()` takes a single argument that describes a pattern for matching element indices in a list of siblings. Element indices are 1-based. ``` :nth-child( <nth> [ of <complex-selector-list> ]? ) ``` ### Keyword values `odd` Represents elements whose numeric position in a series of siblings is odd: 1, 3, 5, etc. `even` Represents elements whose numeric position in a series of siblings is even: 2, 4, 6, etc. ### Functional notation `<An+B>` Represents elements whose numeric position in a series of siblings matches the pattern `An+B`, for every positive integer or zero value of `n`, where: * `A` is an integer step size, * `B` is an integer offset, * `n` is all nonnegative integers, starting from 0. It can be read as the `An+B`-th element of a list. The `A` and `B` must both have [`<integer>`](integer) values. Examples -------- ### Example selectors `tr:nth-child(odd)` or `tr:nth-child(2n+1)` Represents the odd rows of an HTML table: 1, 3, 5, etc. `tr:nth-child(even)` or `tr:nth-child(2n)` Represents the even rows of an HTML table: 2, 4, 6, etc. `:nth-child(7)` Represents the seventh element. `:nth-child(5n)` Represents elements **5** [=5×1], **10** [=5×2], **15** [=5×3], **etc.** The first one to be returned as a result of the formula is **0** [=5x0], resulting in a no-match, since the elements are indexed from 1, whereas `n` starts from 0. This may seem weird at first, but it makes more sense when the `B` part of the formula is `>0`, like in the next example. `:nth-child(n+7)` Represents the seventh and all following elements: **7** [=0+7], **8** [=1+7], **9** [=2+7], **etc.** `:nth-child(3n+4)` Represents elements **4** [=(3×0)+4], **7** [=(3×1)+4], **10** [=(3×2)+4], **13** [=(3×3)+4], **etc.** `:nth-child(-n+3)` Represents the first three elements. [=-0+3, -1+3, -2+3] `p:nth-child(n)` Represents every `<p>` element in a group of siblings. This selects the same elements as a simple `p` selector (although with a higher specificity). `p:nth-child(1)` or `p:nth-child(0n+1)` Represents every `<p>` that is the first element in a group of siblings. This is the same as the [`:first-child`](:first-child) selector (and has the same specificity). `p:nth-child(n+8):nth-child(-n+15)` Represents the eighth through the fifteenth `<p>` elements of a group of siblings. ### Detailed example #### HTML ``` <h3> <code>span:nth-child(2n+1)</code>, WITHOUT an <code>&lt;em&gt;</code> among the child elements. </h3> <p>Children 1, 3, 5, and 7 are selected.</p> <div class="first"> <span>Span 1!</span> <span>Span 2</span> <span>Span 3!</span> <span>Span 4</span> <span>Span 5!</span> <span>Span 6</span> <span>Span 7!</span> </div> <br /> <h3> <code>span:nth-child(2n+1)</code>, WITH an <code>&lt;em&gt;</code> among the child elements. </h3> <p> Children 1, 5, and 7 are selected.<br /> 3 is used in the counting because it is a child, but it isn't selected because it isn't a <code>&lt;span&gt;</code>. </p> <div class="second"> <span>Span!</span> <span>Span</span> <em>This is an `em`.</em> <span>Span</span> <span>Span!</span> <span>Span</span> <span>Span!</span> <span>Span</span> </div> <br /> <h3> <code>span:nth-of-type(2n+1)</code>, WITH an <code>&lt;em&gt;</code> among the child elements. </h3> <p> Children 1, 4, 6, and 8 are selected.<br /> 3 isn't used in the counting or selected because it is an <code>&lt;em&gt;</code>, not a <code>&lt;span&gt;</code>, and <code>nth-of-type</code> only selects children of that type. The <code>&lt;em&gt;</code> is completely skipped over and ignored. </p> <div class="third"> <span>Span!</span> <span>Span</span> <em>This is an `em`.</em> <span>Span!</span> <span>Span</span> <span>Span!</span> <span>Span</span> <span>Span!</span> </div> ``` #### CSS ``` html { font-family: sans-serif; } span, div em { padding: 5px; border: 1px solid green; display: inline-block; margin-bottom: 3px; } .first span:nth-child(2n + 1), .second span:nth-child(2n + 1), .third span:nth-of-type(2n + 1) { background-color: lime; } ``` #### Result Specifications -------------- | Specification | | --- | | [Selectors Level 4 # nth-child-pseudo](https://w3c.github.io/csswg-drafts/selectors/#nth-child-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:nth-child` | 1 | 12 | 3.5 | 9 | 9.5 Before Opera 15, Opera does not handle dynamically inserted elements for `:nth-child()`. | 3.1 | ≤37 | 18 | 4 | 10.1 Before Opera 15, Opera does not handle dynamically inserted elements for `:nth-child()`. | 2 | 1.0 | | `no_parent_required` | 57 | 79 | 52 | No | 44 | No | 57 | 57 | 52 | 43 | No | 7.0 | | `of_syntax` | No See [bug 304163](https://crbug.com/304163). | No See [bug 304163](https://crbug.com/304163). | No See [bug 854148](https://bugzil.la/854148). | No | No See [bug 304163](https://crbug.com/304163). | 9 | No See [bug 304163](https://crbug.com/304163). | No See [bug 304163](https://crbug.com/304163). | No See [bug 854148](https://bugzil.la/854148). | No See [bug 304163](https://crbug.com/304163). | 9 | No See [bug 304163](https://crbug.com/304163). | See also -------- * [`:nth-of-type`](:nth-of-type), [`:nth-last-child`](:nth-last-child) css letter-spacing letter-spacing ============== The `letter-spacing` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the horizontal spacing behavior between text characters. This value is added to the natural spacing between characters while rendering the text. Positive values of `letter-spacing` causes characters to spread farther apart, while negative values of `letter-spacing` bring characters closer together. Try it ------ Syntax ------ ``` /\* Keyword value \*/ letter-spacing: normal; /\* <length> values \*/ letter-spacing: 0.3em; letter-spacing: 3px; letter-spacing: 0.3px; /\* Global values \*/ letter-spacing: inherit; letter-spacing: initial; letter-spacing: revert; letter-spacing: revert-layer; letter-spacing: unset; ``` ### Values `normal` The normal letter spacing for the current font. Unlike a value of `0`, this keyword allows the [user agent](https://developer.mozilla.org/en-US/docs/Glossary/User_agent) to alter the space between characters in order to justify text. [`<length>`](length) Specifies extra inter-character space *in addition to* the default space between characters. Values may be negative, but there may be implementation-specific limits. User agents may not further increase or decrease the inter-character space in order to justify text. Accessibility concerns ---------------------- A large positive or negative `letter-spacing` value will make the word(s) the styling is applied to unreadable. For text styled with a very large positive value, the letters will be so far apart that the word(s) will appear like a series of individual, unconnected letters. For text styled with a very large negative value, the letters will overlap each other to the point where the word(s) may be unrecognizable. Legible letter-spacing must be determined on a case-by-case basis, as different font families have different character widths. There is no one value that can ensure all font families automatically maintain their legibility. * [MDN Understanding WCAG, Guideline 1.4 explanations](https://developer.mozilla.org/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.8 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-visual-presentation.html) Internationalization concerns ----------------------------- Some written languages should not have any letter spacing applied. For instance, languages that use the Arabic script expect connected letters to remain visually connected, as in the following example. Applying letter spacing will lead the text to look broken. > شسيبتنمك > > Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | an optimum value consisting of either an absolute length or the keyword `normal` | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` letter-spacing = normal [|](value_definition_syntax#single_bar) [<length>](length) ``` Examples -------- ### Setting letter spacing #### HTML ``` <p class="normal">letter spacing</p> <p class="em-wide">letter spacing</p> <p class="em-wider">letter spacing</p> <p class="em-tight">letter spacing</p> <p class="px-wide">letter spacing</p> ``` #### CSS ``` .normal { letter-spacing: normal; } .em-wide { letter-spacing: 0.4em; } .em-wider { letter-spacing: 1em; } .em-tight { letter-spacing: -0.05em; } .px-wide { letter-spacing: 6px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Text Module Level 3 # letter-spacing-property](https://w3c.github.io/csswg-drafts/css-text/#letter-spacing-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `letter-spacing` | 1 | 12 | 1 | 4 | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | | `svg` | 1 | 12 | 72 | 9 | 7 | 5.1 | ≤37 | 18 | No | 10.1 | 5 | 1.0 | See also -------- * [`font-kerning`](font-kerning) * [`word-spacing`](word-spacing) css :read-write :read-write =========== The `:read-write` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) represents an element (such as `input` or `textarea`) that is editable by the user. Try it ------ Syntax ------ ``` :read-write ``` Examples -------- ### Confirming form information in read-only/read-write controls One use of `readonly` form controls is to allow the user to check and verify information that they may have entered in an earlier form (for example, shipping details), while still being able to submit the information along with the rest of the form. We do just this in the example below. The `:read-only` pseudo-class is used to remove all the styling that makes the inputs look like clickable fields, making them look more like read-only paragraphs. The `:read-write` pseudo-class on the other hand is used to provide some nicer styling to the editable `<textarea>`. ``` input:-moz-read-only, textarea:-moz-read-only, input:read-only, textarea:read-only { border: 0; box-shadow: none; background-color: white; } textarea:-moz-read-write, textarea:read-write { box-shadow: inset 1px 1px 3px #ccc; border-radius: 5px; } ``` You can find the full source code at [readonly-confirmation.html](https://github.com/mdn/learning-area/blob/main/html/forms/pseudo-classes/readonly-confirmation.html); this renders like so: ### Styling read-write non-form controls This selector doesn't just select [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input)/[`<textarea>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea) elements — it will select *any* element that can be edited by the user, such as a [`<p>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p) element with [`contenteditable`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#contenteditable) set on it. ``` <p contenteditable>This paragraph is editable; it is read-write.</p> <p>This paragraph is not editable; it is read-only.</p> ``` ``` p { font-size: 150%; padding: 5px; border-radius: 5px; } p:read-only { background-color: red; color: white; } p:read-write { background-color: lime; } ``` Specifications -------------- | Specification | | --- | | [HTML Standard # selector-read-write](https://html.spec.whatwg.org/multipage/semantics-other.html#selector-read-write) | | [Selectors Level 4 # rw-pseudos](https://w3c.github.io/csswg-drafts/selectors/#rw-pseudos) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:read-write` | 1 | 13 | 78 1.5 | No | 9 | 4 | ≤37 | 18 | 4 | 10.1 | 3.2 | 1.0 | See also -------- * [`:read-only`](:read-only) * HTML [`contenteditable`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#contenteditable) attribute css CSS Colors CSS Colors ========== **CSS Color** is a CSS module that deals with colors, color types, color blending, opacity, and how you can apply these colors and effects to HTML content. Not all CSS properties that take a [`<color>`](color_value) as a value are part of this module, but they do depend upon it. Reference --------- ### Properties * [`color`](color) * [`print-color-adjust`](print-color-adjust) * [`opacity`](opacity) ### Data types * [`<color>`](color_value) Guides ------ [Applying color to HTML elements using CSS](css_colors/applying_color) A guide to using CSS to apply color to a variety of types of content. All color-related CSS properties are touched upon. Tools ----- [Color picker tool](css_colors/color_picker_tool) This tool makes it easy to create, adjust, and experiment with custom colors. Specifications -------------- | Specification | | --- | | [CSS Color Module Level 4](https://drafts.csswg.org/css-color/) | See also -------- * Color-related properties that are part of other specifications: [`background-color`](background-color), [`border-color`](border-color), [`outline-color`](outline-color), [`text-decoration-color`](text-decoration-color), [`text-emphasis-color`](text-emphasis-color), [`text-shadow`](text-shadow), [`caret-color`](caret-color), and [`column-rule-color`](column-rule-color) * In CSS, gradients aren't colors but [images](css_images). css font-variant-ligatures font-variant-ligatures ====================== The `font-variant-ligatures` CSS property controls which [ligatures](https://developer.mozilla.org/en-US/docs/Glossary/Ligature) and contextual forms are used in textual content of the elements it applies to. This leads to more harmonized forms in the resulting text. Try it ------ Syntax ------ ``` /\* 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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` font-variant-ligatures = normal [|](value_definition_syntax#single_bar) none [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) <common-lig-values> [||](value_definition_syntax#double_bar) <discretionary-lig-values> [||](value_definition_syntax#double_bar) <historical-lig-values> [||](value_definition_syntax#double_bar) <contextual-alt-values> []](value_definition_syntax#brackets) <common-lig-values> = common-ligatures [|](value_definition_syntax#single_bar) no-common-ligatures <discretionary-lig-values> = discretionary-ligatures [|](value_definition_syntax#single_bar) no-discretionary-ligatures <historical-lig-values> = historical-ligatures [|](value_definition_syntax#single_bar) no-historical-ligatures <contextual-alt-values> = contextual [|](value_definition_syntax#single_bar) no-contextual ``` Examples -------- ### Setting font ligatures and contextual forms #### 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 ``` 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 Specifications -------------- | Specification | | --- | | [CSS Fonts Module Level 4 # font-variant-ligatures-prop](https://w3c.github.io/csswg-drafts/css-fonts/#font-variant-ligatures-prop) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `font-variant-ligatures` | 34 31 | 79 79 | 34 | No | 21 19 | 9.1 7 | 37 4.4 | 34 | 34 | 21 19 | 9.3 7 | 2.0 | See also -------- * [`font-variant`](font-variant) * [`font-variant-alternates`](font-variant-ligatures) * [`font-variant-caps`](font-variant-caps) * [`font-variant-emoji`](font-variant-emoji) * [`font-variant-east-asian`](font-variant-east-asian) * [`font-variant-numeric`](font-variant-numeric) * [`font-variant-position`](font-variant-position)
programming_docs
css list-style-type list-style-type =============== The `list-style-type` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the marker (such as a disc, character, or custom counter style) of a list item element. Try it ------ The [color](color_value) of the marker will be the same as the computed color of the element it applies to. Only a few elements ([`<li>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/li) and [`<summary>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/summary)) have a default value of `display: list-item`. However, the `list-style-type` property may be applied to any element whose [`display`](display) value is set to `list-item`. Moreover, because this property is inherited, it can be set on a parent element (commonly [`<ol>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol) or [`<ul>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ul)) to make it apply to all list items. Syntax ------ ``` /\* 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 [`<custom-ident>`](custom-ident) An identifier matching the value of a [`@counter-style`](@counter-style) or one of the predefined styles: [`symbols()`](@counter-style/symbols) Defines an anonymous style of the list. [`<string>`](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 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 [`<details>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details) is opened. `disclosure-closed` Symbol indicating that a disclosure widget, like [`<details>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details) is closed. ### Non-standard extensions A few more predefined types are provided by Mozilla (Firefox), Blink (Chrome and Opera) and WebKit (Safari) to support list types in other languages. See the compatibility table to check which browsers support which extension. * `-moz-ethiopic-halehame` * `-moz-ethiopic-halehame-am` * `ethiopic-halehame-ti-er`, `-moz-ethiopic-halehame-ti-er` * `ethiopic-halehame-ti-et`, `-moz-ethiopic-halehame-ti-et` * `hangul`, `-moz-hangul` * `hangul-consonant`, `-moz-hangul-consonant` * `urdu`, `-moz-urdu` 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`. To learn more about this and potential workarounds, see [`list-style`](list-style#accessibility_concerns). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `disc` | | Applies to | list items | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` list-style-type = <counter-style> [|](value_definition_syntax#single_bar) [<string>](string) [|](value_definition_syntax#single_bar) none <counter-style> = [<counter-style-name>](counter-style-name) [|](value_definition_syntax#single_bar) <symbols()> <symbols()> = symbols( <symbols-type>[?](value_definition_syntax#question_mark) [[](value_definition_syntax#brackets) [<string>](string) [|](value_definition_syntax#single_bar) <image> []](value_definition_syntax#brackets)[+](value_definition_syntax#plus) ) <symbols-type> = cyclic [|](value_definition_syntax#single_bar) numeric [|](value_definition_syntax#single_bar) alphabetic [|](value_definition_syntax#single_bar) symbolic [|](value_definition_syntax#single_bar) fixed <image> = <url> [|](value_definition_syntax#single_bar) [<gradient>](gradient) <url> = url( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) [|](value_definition_syntax#single_bar) src( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) ``` Examples -------- ### Setting list item markers #### 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 ``` ol.normal { list-style-type: upper-alpha; } /\* or use the shortcut "list-style": \*/ ol.shortcut { list-style: upper-alpha; } ``` #### Result ### All list style types #### 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 ``` ol { font-size: 1.2rem; } .container { column-count: 3; } label { display: block; } input { margin: 0.4rem; } ``` #### JavaScript ``` const container = document.querySelector(".container"); container.addEventListener("change", (event) => { const list = document.querySelector("ol"); list.setAttribute("style", `list-style-type: ${event.target.value}`); }); ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Lists and Counters Module Level 3 # text-markers](https://w3c.github.io/csswg-drafts/css-lists/#text-markers) | | [CSS Counter Styles Level 3 # extending-css2](https://w3c.github.io/csswg-drafts/css-counter-styles/#extending-css2) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `list-style-type` | 1 | 12 | 1 | 4 | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | | `afar` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `amharic` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `amharic-abegede` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `arabic-indic` | 6 | 79 | 33 1 | No | 15 | 5 | 4.4 | 18 | 33 4 | 14 | 4.2 | 1.0 | | `armenian` | 1 | 12 | 1 | 8 | 6 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `asterisks` | 13-45 | No | No | No | 15-32 | 5.1 | 4.4-45 | 18-45 | No | 14-32 | 5 | 1.0-5.0 | | `bengali` | 6 | 79 | 33 1 | No | 15 | 5 | 4.4 | 18 | 33 4 | 14 | 4.2 | 1.0 | | `binary` | 13-45 | No | No | No | 15-32 | 5 | 4.4-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `cambodian` | 6 | 79 | 33 | No | 15 | 5 | 4.4 | 18 | 33 | 14 | 4.2 | 1.0 | | `circle` | 1 | 12 | 1 | 4 | 3.5 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `cjk-decimal` | No | No | 28 | No | No | preview | No | No | 28 | No | No | No | | `cjk-earthly-branch` | 6 | 79 | 33 1 | No | 15 | 5 | 4.4 | 18 | 33 4 | 14 | 4.2 | 1.0 | | `cjk-heavenly-stem` | 6 | 79 | 33 1 | No | 15 | 5 | 4.4 | 18 | 33 4 | 14 | 4.2 | 1.0 | | `cjk-ideographic` | 1 | 79 | 1 | No | 15 7 Until version 15, only decimal numbers display. | 5 | 4.4 | 18 | 4 | 14 10.1 Until version 15, only decimal numbers display. | 4.2 | 1.0 | | `decimal` | 1 | 12 | 1 | 4 | 3.5 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `decimal-leading-zero` | 1 | 12 | 1 | 8 | 8 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `devanagari` | 6 | 79 | 33 1 | No | 15 | 5 | 4.4 | 18 | 33 4 | 14 | 4.2 | 1.0 | | `disc` | 1 | 12 | 1 | 4 | 3.5 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `disclosure-closed` | No | No | 33 | No | No | 15 | No | No | 33 | No | 15 | No | | `disclosure-open` | No | No | 33 | No | No | 15 | No | No | 33 | No | 15 | No | | `ethiopic` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `ethiopic-abegede` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `ethiopic-abegede-am-et` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `ethiopic-abegede-gez` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `ethiopic-abegede-ti-er` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `ethiopic-abegede-ti-et` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `ethiopic-halehame` | 45 | 79 | 1 | No | 32 | No | 45 | 45 | 4 | 32 | No | 5.0 | | `ethiopic-halehame-aa-er` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `ethiopic-halehame-aa-et` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `ethiopic-halehame-am` | 45 | 79 | 1 | No | 32 | 5 | 45 | 45 | 4 | 32 | 4.2 | 5.0 | | `ethiopic-halehame-am-et` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `ethiopic-halehame-gez` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `ethiopic-halehame-om-et` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `ethiopic-halehame-sid-et` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `ethiopic-halehame-so-et` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `ethiopic-halehame-ti-er` | 6 | 79 | 1 | No | 15 | 5 | 3 | 18 | 4 | 14 | 4.2 | 1.0 | | `ethiopic-halehame-ti-et` | 6 | 79 | 1 | No | 15 | 5 | 3 | 18 | 4 | 14 | 4.2 | 1.0 | | `ethiopic-halehame-tig` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `ethiopic-numeric` | No | No | 33 Before Firefox 38, Firefox added a dot as suffix of the number for `ethiopic-numeric` (for example, ፫. instead of ፫). The specification later defined the absence of a suffix, which Firefox 38 followed. 1 | No | No | 15 | No | No | 33 Before Firefox 38, Firefox added a dot as suffix of the number for `ethiopic-numeric` (for example, ፫. instead of ፫). The specification later defined the absence of a suffix, which Firefox 38 followed. 4 | No | 15 | No | | `footnotes` | 13-45 | No | No | No | 15-32 | 5.1 | 4.4-45 | 18-45 | No | 14-32 | 5 | 1.0-5.0 | | `georgian` | 1 | 12 | 1 | 8 | 6 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `gujarati` | 6 | 79 | 33 1 | No | 15 | 5 | 4.4 | 18 | 33 4 | 14 | 4.2 | 1.0 | | `gurmukhi` | 6 | 79 | 33 1 | No | 15 | 5 | 4.4 | 18 | 33 4 | 14 | 4.2 | 1.0 | | `hangul` | 6 | 79 | 1 | No | 15 | 5 | 4.4 | 18 | 4 | 14 | 4.2 | 1.0 | | `hangul-consonant` | 6 | 79 | 1 | No | 15 | 5 | 4.4 | 18 | 4 | 14 | 4.2 | 1.0 | | `hebrew` | 1 | 79 | 1 | No | 15 | 1 | 4.4 | 18 | 4 | 14 | 1 | 1.0 | | `hiragana` | 1 | 79 | 1 | No | 15 | 1 | 4.4 | 18 | 4 | 14 | 1 | 1.0 | | `hiragana-iroha` | 1 | 79 | 1 | No | 15 | 1 | 4.4 | 18 | 4 | 14 | 1 | 1.0 | | `japanese-formal` | No | No | 28 1 | No | No | 15 | No | No | 28 4 | No | 15 | No | | `japanese-informal` | No | No | 28 1 | No | No | 15 | No | No | 28 4 | No | 15 | No | | `kannada` | 6 | 79 | 33 1 | No | 15 | 5 | 4.4 | 18 | 33 4 | 14 | 4.2 | 1.0 | | `katakana` | 1 | 79 | 1 | No | 15 | 1 | 4.4 | 18 | 4 | 14 | 1 | 1.0 | | `katakana-iroha` | 1 | 79 | 1 | No | 15 | 1 | 4.4 | 18 | 4 | 14 | 1 | 1.0 | | `khmer` | 6 | 79 | 33 1 | No | 15 | 5 | 4.4 | 18 | 33 4 | 14 | 4.2 | 1.0 | | `korean-hangul-formal` | 45 | 79 | 28 | No | 32 | 15 | 45 | 45 | 28 | 32 | 15 | 5.0 | | `korean-hanja-formal` | 45 | 79 | 28 | No | 32 | 15 | 45 | 45 | 28 | 32 | 15 | 5.0 | | `korean-hanja-informal` | 45 | 79 | 28 | No | 32 | 15 | 45 | 45 | 28 | 32 | 15 | 5.0 | | `lao` | 6 | 79 | 33 1 | No | 15 | 5 | 4.4 | 18 | 33 4 | 14 | 4.2 | 1.0 | | `lower-alpha` | 1 | 12 | 1 | 8 | 6 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `lower-armenian` | 13 | 79 | 33 | No | 15 | 5.1 | 4.4 | 18 | 33 | 14 | 5 | 1.0 | | `lower-greek` | 1 | 12 | 1 | 8 | 6 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `lower-hexadecimal` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `lower-latin` | 1 | 12 | 1 | 8 | 6 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 5.0 | | `lower-norwegian` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `lower-roman` | 1 | 12 | 1 | 8 | 6 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `malayalam` | 6 | 79 | 33 1 | No | 15 | 5 | 4.4 | 18 | 33 4 | 14 | 4.2 | 1.0 | | `mongolian` | 6 | 79 | 33 | No | 15 | 5 | 4.4 | 18 | 33 | 14 | 4.2 | 1.0 | | `myanmar` | 6 | 79 | 33 1 | No | 15 | 5 | 4.4 | 18 | 33 4 | 14 | 4.2 | 1.0 | | `octal` | 6-45 | No | No | No | 15-32 | 5 | 4.4-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `oriya` | 6 | 79 | 33 1 | No | 15 | 5 | 4.4 | 18 | 33 4 | 14 | 4.2 | 1.0 | | `oromo` | 6-45 | No | No | No | 15-32 | 5 | 4.4-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `persian` | 6 | 79 | 33 1 | No | 15 | 5 | 4.4 | 18 | 33 4 | 14 | 4.2 | 1.0 | | `sidama` | 6-45 | No | No | No | 15-32 | 5 | 4.4-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `simp-chinese-formal` | 45 | 79 | 28 1 | No | 32 | 15 | 45 | 45 | 28 4 | 32 | 15 | 5.0 | | `simp-chinese-informal` | 45 | 79 | 28 1 | No | 32 | 15 | 45 | 45 | 28 4 | 32 | 15 | 5.0 | | `somali` | 6-45 | No | No | No | 15-32 | 5 | 4.4-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `square` | 1 | 12 | 1 | 4 | 3.5 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `string` | 79 | 79 | 39 | No | 66 | 14.1 | 79 | 79 | 39 | No | 14.5 | 12.0 | | `symbols` | No | No | 35 | No | No | No | No | No | 35 | No | No | No | | `tamil` | No | No | 33 1 | No | No | preview | No | No | 33 4 | No | No | No | | `telugu` | 6 | 79 | 33 1 | No | 15 | 5 | 4.4 | 18 | 33 4 | 14 | 4.2 | 1.0 | | `thai` | 6 | 79 | 33 1 | No | 15 | 5 | 4.4 | 18 | 33 4 | 14 | 4.2 | 1.0 | | `tibetan` | 6 | 79 | 33 | No | 15 | 5 | 4.4 | 18 | No | 14 | 4.2 | 1.0 | | `tigre` | 6-45 | No | No | No | 15-32 | 5 | 4.4-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `tigrinya-er` | 6-45 | No | No | No | 15-32 | 5 | 4.4-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `tigrinya-er-abegede` | 6-45 | No | No | No | 15-32 | 5 | 4.4-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `tigrinya-et` | 6-45 | No | No | No | 15-32 | 5 | 4.4-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `tigrinya-et-abegede` | 6-45 | No | No | No | 15-32 | 5 | 4.4-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `trad-chinese-formal` | 45 | 79 | 28 1 | No | 32 | 15 | 45 | 45 | 28 4 | 32 | 15 | 5.0 | | `trad-chinese-informal` | 45 | 79 | 28 1 | No | 32 | 15 | 45 | 45 | 28 4 | 32 | 15 | 5.0 | | `upper-alpha` | 1 | 12 | 1 | 8 | 6 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `upper-armenian` | 13 | 79 | 33 | No | 15 | 5.1 | 4.4 | 18 | 33 | 14 | 5 | 1.0 | | `upper-greek` | 1 | 12 | 1 | 8 | 6 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `upper-hexadecimal` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `upper-latin` | 1 | 12 | 1 | 8 | 6 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `upper-norwegian` | 6-45 | No | No | No | 15-32 | 5 | 3-45 | 18-45 | No | 14-32 | 4.2 | 1.0-5.0 | | `upper-roman` | 1 | 12 | 1 | 8 | 6 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `urdu` | 6 | 79 | 33 | No | 15 | 5 | 4.4 | 18 | 33 | 14 | 4.2 | 1.0 | See also -------- * [`list-style`](list-style), [`list-style-image`](list-style-image), [`list-style-position`](list-style-position)
programming_docs
css :nth-last-col() :nth-last-col() =============== **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `:nth-last-col()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) is designed for tables and grids. It accepts the An+B notation such as used with the [`:nth-child`](:nth-child) selector, using this to target every nth column before it, therefore counting back from the end of the set of columns. The values odd and even are also valid. ``` /\* Selects every odd column in a table \*/ :nth-last-col(odd) { background-color: pink; } ``` Syntax ------ The `nth-last-col()` pseudo-class is specified with a single argument, which represents the pattern for matching elements. It uses `:nth-last-col(An+B)` syntax. See [`:nth-child`](:nth-child) for a more detailed explanation of its syntax. ``` :nth-last-col(An+B) ``` Examples -------- ### Basic example #### HTML ``` <table> <tr> <td>one</td> <td>two</td> <td>three</td> <td>four</td> </tr> <tr> <td>one</td> <td>two</td> <td>three</td> <td>four</td> </tr> </table> ``` #### CSS ``` td { border: 1px solid #ccc; padding: 0.2em; } /\* Odd columns starting with the final column of the table \*/ :nth-last-col(2n + 1) { background-color: pink; } ``` #### Result Specifications -------------- **No specification found**No specification data found for `css.selectors.nth-last-col`. [Check for problems with this page](#on-github) or contribute a missing `spec_url` to [mdn/browser-compat-data](https://github.com/mdn/browser-compat-data). Also make sure the specification is included in [w3c/browser-specs](https://github.com/w3c/browser-specs). Browser compatibility --------------------- No compatibility data found for `css.selectors.nth-last-col`. [Check for problems with this page](#on-github) or contribute missing data to [mdn/browser-compat-data](https://github.com/mdn/browser-compat-data). See also -------- * [`:nth-child`](:nth-child), [`:nth-last-of-type`](:nth-last-of-type) css <flex> <flex> ====== The `<flex>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) denotes a flexible length within a grid container. It is used in [`grid-template-columns`](grid-template-columns), [`grid-template-rows`](grid-template-rows) and other related properties. Syntax ------ The `<flex>` data type is specified as a [`<number>`](number) followed by the unit `fr`. The `fr` unit represents a fraction of the leftover space in the grid container. As with all CSS dimensions, there is no space between the unit and the number. Examples -------- ### Examples of correct values for the fr data type ``` 1fr /* Using an integer value */ 2.5fr /* Using a float value */ ``` ### Example of use in a tracklisting for CSS Grid layout ``` .grid { display: grid; grid-template-columns: 1fr 1fr 2.5fr 1.5fr; } ``` Specifications -------------- | Specification | | --- | | [CSS Grid Layout Module Level 2 # fr-unit](https://w3c.github.io/csswg-drafts/css-grid/#fr-unit) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `flex_value` | 29 | 12 | 40 | 10 | 28 | 10.1 | 57 | 29 | 40 | 28 | 10.3 | 2.0 | See also -------- * [CSS Grid Layout](css_grid_layout) css border-top-right-radius border-top-right-radius ======================= The `border-top-right-radius` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property rounds the top-right corner of an element by specifying the radius (or the radius of the semi-major and semi-minor axes) of the ellipse defining the curvature of the corner. Try it ------ The rounding can be a circle or an ellipse, or if one of the value is `0` no rounding is done and the corner is square. A background, being an image or a color, is clipped at the border, even a rounded one; the exact location of the clipping is defined by the value of the [`background-clip`](background-clip) property. **Note:** If the value of this property is not set in a [`border-radius`](border-radius) shorthand property that is applied to the element after the `border-top-right-radius` CSS property, the value of this property is then reset to its initial value by the [shorthand property](shorthand_properties). Syntax ------ ``` /\* the corner is a circle \*/ /\* border-top-right-radius: radius \*/ border-top-right-radius: 3px; /\* the corner is an ellipse \*/ /\* border-top-right-radius: horizontal vertical \*/ border-top-right-radius: 0.5em 1em; border-top-right-radius: inherit; /\* Global values \*/ border-top-right-radius: inherit; border-top-right-radius: initial; border-top-right-radius: revert; border-top-right-radius: revert-layer; border-top-right-radius: unset; ``` With one value: * the value is a [`<length>`](length) or a [`<percentage>`](percentage) denoting the radius of the circle to use for the border in that corner. With two values: * the first value is a [`<length>`](length) or a [`<percentage>`](percentage) denoting the horizontal semi-major axis of the ellipse to use for the border in that corner. * the second value is a [`<length>`](length) or a [`<percentage>`](percentage) denoting the vertical semi-major axis of the ellipse to use for the border in that corner. ### Values `<length-percentage>` Denotes the size of the circle radius or the semi-major and semi-minor axes of the ellipse. As absolute length it can be expressed in any unit allowed by the CSS [`<length>`](length) data type. Percentages for the horizontal axis refer to the width of the box, percentages for the vertical axis refer to the height of the box. Negative values are invalid. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | all elements; but User Agents are not required to apply to `table` and `inline-table` elements when [`border-collapse`](border-collapse) is `collapse`. The behavior on internal table elements is undefined for the moment.. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | Percentages | refer to the corresponding dimension of the border box | | [Computed value](computed_value) | two absolute [`<length>`](length)s or [`<percentage>`](percentage)s | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` border-top-right-radius = [<length-percentage [0,∞]>](length-percentage)[{1,2}](value_definition_syntax#curly_braces) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Arc of a circle A single `<length>` value produces an arc of a circle. ``` div { border-top-right-radius: 40px; background-color: lightgreen; border: solid 1px black; width: 100px; height: 100px; } ``` ### Arc of an ellipse Two different `<length>` values produce an arc of an ellipse. ``` div { border-top-right-radius: 40px 20px; background-color: lightgreen; border: solid 1px black; width: 100px; height: 100px; } ``` ### Square element with percentage radius A square element with a single `<percentage>` value produces an arc of a circle. ``` div { border-top-right-radius: 40%; background-color: lightgreen; border: solid 1px black; width: 100px; height: 100px; } ``` ### Non-square element with percentage radius A non-square element with a single `<percentage>` value produces an arc of an ellipse. ``` div { border-top-right-radius: 40%; background-color: lightgreen; border: solid 1px black; width: 200px; height: 100px; } ``` Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # the-border-radius](https://w3c.github.io/csswg-drafts/css-backgrounds/#the-border-radius) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-top-right-radius` | 4 1 | 12 12 | 49 4 Before Firefox 50, border styles of rounded corners were always rendered as if `border-style` was solid. This has been fixed in Firefox 50. 1-12 | 9 | 15 10.5 | 5 3 | ≤37 ≤37 | 18 18 | 49 4 Before Firefox 50, border styles of rounded corners were always rendered as if `border-style` was solid. This has been fixed in Firefox 50. 4-14 | 14 11 | 4.2 1 | 1.0 1.0 | | `elliptical_corners` | 1 | 12 | 3.5 | 9 | 10.5 | 3 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | | `percentages` | 4 | 12 | 4 1-4 Before Firefox 4, the [`<percentage>`](https://developer.mozilla.org/docs/Web/CSS/percentage) was relative to the width of the box even when specifying the radius for a height. This implied that `-moz-border-radius-bottomright` was always drawing an arc of circle, and never an ellipse, when followed by a single value. | 9 | 10.5 | 5 | ≤37 | 18 | 4 | 14 | 4.2 | 1.0 | See also -------- * [`border-radius`](border-radius) shorthand property * [`border-bottom-right-radius`](border-bottom-right-radius), [`border-bottom-left-radius`](border-bottom-left-radius), and [`border-top-left-radius`](border-top-left-radius) css padding-inline-end padding-inline-end ================== The `padding-inline-end` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the logical inline end padding of an element, which maps to a physical padding depending on the element's writing mode, directionality, and text orientation. Try it ------ Syntax ------ ``` /\* <length> values \*/ padding-inline-end: 10px; /\* An absolute length \*/ padding-inline-end: 1em; /\* A length relative to the text size \*/ /\* <percentage> value \*/ padding-inline-end: 5%; /\* A padding relative to the block container's width \*/ /\* Global values \*/ padding-inline-end: inherit; padding-inline-end: initial; padding-inline-end: revert; padding-inline-end: revert-layer; padding-inline-end: unset; ``` ### Values [`<length>`](length) The size of the padding as a fixed value. Must be nonnegative. [`<percentage>`](percentage) The size of the padding as a percentage, relative to the [inline-size](css_flow_layout/block_and_inline_layout_in_normal_flow) (*width* in a horizontal language) of the [containing block](containing_block). Must be nonnegative. Description ----------- The `padding-inline-end` property is defined in the specification as taking the same values as the [`padding-top`](padding-top) property. However, the physical property it maps to depends on the values set for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Therefore, it could map to [`padding-bottom`](padding-bottom), [`padding-right`](padding-right), or [`padding-left`](padding-left) It relates to [`padding-block-start`](padding-block-start), [`padding-block-end`](padding-block-end), and [`padding-inline-start`](padding-inline-start), which define the other paddings of the element. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | all elements, except `table-row-group`, `table-header-group`, `table-footer-group`, `table-row`, `table-column-group` and `table-column` | | [Inherited](inheritance) | no | | Percentages | logical-width of containing block | | [Computed value](computed_value) | as [`<length>`](length) | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` padding-inline-end = <'padding-top'> ``` Examples -------- ### Setting inline end padding for vertical text #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; padding-inline-end: 20px; background-color: #c8c800; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # padding-properties](https://w3c.github.io/csswg-drafts/css-logical/#padding-properties) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `padding-inline-end` | 87 2 | 87 79 | 41 3 | No | 73 15 | 12.1 3 | 87 2 | 87 18 | 41 4 | 62 14 | 12.2 3 | 14.0 1.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * The mapped physical properties: [`padding-top`](padding-top), [`padding-right`](padding-right), [`padding-bottom`](padding-bottom), and [`padding-left`](padding-left) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css scroll-margin-inline scroll-margin-inline ==================== The `scroll-margin-inline` [shorthand property](shorthand_properties) sets the scroll margins of an element in the inline dimension. Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`scroll-margin-inline-end`](scroll-margin-inline-end) * [`scroll-margin-inline-start`](scroll-margin-inline-start) Syntax ------ ``` /\* <length> values \*/ scroll-margin-inline: 10px; scroll-margin-inline: 1em 0.5em; /\* Global values \*/ scroll-margin-inline: inherit; scroll-margin-inline: initial; scroll-margin-inline: revert; scroll-margin-inline: revert-layer; scroll-margin-inline: unset; ``` ### Values `<length>` An outset from the corresponding edge of the scroll container. Description ----------- 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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`scroll-margin-inline-start`](scroll-margin-inline-start): `0` * [`scroll-margin-inline-end`](scroll-margin-inline-end): `0` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`scroll-margin-inline-start`](scroll-margin-inline-start): as specified * [`scroll-margin-inline-end`](scroll-margin-inline-end): as specified | | Animation type | by computed value type | Formal syntax ------------- ``` scroll-margin-inline = [<length>](length)[{1,2}](value_definition_syntax#curly_braces) ``` 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 right of each block. #### HTML The HTML that represents the blocks is very simple: ``` <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: ``` .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: ``` .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: end; } .scroller > div:nth-child(2n) { background-color: #fff; color: #663399; } ``` The most relevant part here is `scroll-snap-align: end`, which specifies that the right-hand edges (the "ends" 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: ``` .scroller > div:nth-child(2) { scroll-margin-inline: 1rem; } .scroller > div:nth-child(3) { scroll-margin-inline: 2rem; } ``` This means that when scrolling past the middle child elements, the scrolling will snap to `1rem` outside the inline end edge of the second `<div>`, and `2rems` outside the inline end edge of the third `<div>`. **Note:** Here we are setting `scroll-margin` on the start *and* end of the inline axis (x in our case), but only the end 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: 0 1rem`, or `scroll-margin-inline-end: 1rem`. #### Result Try it for yourself: Specifications -------------- | Specification | | --- | | [CSS Scroll Snap Module Level 1 # propdef-scroll-margin-inline](https://w3c.github.io/csswg-drafts/css-scroll-snap/#propdef-scroll-margin-inline) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scroll-margin-inline` | 69 | 79 | 68 | No | 56 | 14.1 | 69 | 69 | 68 | 48 | 14.5 | 10.0 | See also -------- * [CSS Scroll Snap](css_scroll_snap) * [Well-Controlled Scrolling with CSS Scroll Snap](https://web.dev/css-scroll-snap/) css :right :right ====== The `:right` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes), used with the [`@page`](@page) <at-rule>, represents all right-hand pages of a printed document. ``` /\* Selects any right-hand pages when printing \*/ @page :right { margin: 2in 3in; } ``` Whether a given page is "left" or "right" is determined by the major writing direction of the document. For example, if the first page has a major writing direction of left-to-right then it will be a `:right` page; if it has a major writing direction of right-to-left then it will be a [`:left`](:left) page. **Note:** This pseudo-class can be used to change only the [`margin`](margin), [`padding`](padding), [`border`](border), and [`background`](background) properties of the *page box*. All other properties will be ignored, and only the page box, not the document content on the page, will be affected. Syntax ------ ``` :right ``` Examples -------- ### Setting margins for right-hand pages ``` @page :right { margin: 2in 3in; } ``` Specifications -------------- | Specification | | --- | | [CSS Paged Media Module Level 3 # left-right-first](https://w3c.github.io/csswg-drafts/css-page/#left-right-first) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:right` | 6 | 12 | No | 8 | 9.2 | 5 | ≤37 | 18 | No | 10.1 | 4.2 | 1.0 | See also -------- * [`@page`](@page) * Other page-related pseudo-classes: [`:first`](:first), [`:left`](:left)
programming_docs
css flex-flow flex-flow ========= The `flex-flow` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [shorthand property](shorthand_properties) specifies the direction of a flex container, as well as its wrapping behavior. Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`flex-direction`](flex-direction) * [`flex-wrap`](flex-wrap) Syntax ------ ``` /\* flex-flow: <'flex-direction'> \*/ flex-flow: row; flex-flow: row-reverse; flex-flow: column; flex-flow: column-reverse; /\* flex-flow: <'flex-wrap'> \*/ flex-flow: nowrap; flex-flow: wrap; flex-flow: wrap-reverse; /\* flex-flow: <'flex-direction'> and <'flex-wrap'> \*/ flex-flow: row nowrap; flex-flow: column wrap; flex-flow: column-reverse wrap-reverse; /\* Global values \*/ flex-flow: inherit; flex-flow: initial; flex-flow: revert; flex-flow: revert-layer; flex-flow: unset; ``` ### Values See [`flex-direction`](flex-direction) and [`flex-wrap`](flex-wrap) for details on the values. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`flex-direction`](flex-direction): `row` * [`flex-wrap`](flex-wrap): `nowrap` | | Applies to | flex containers | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`flex-direction`](flex-direction): as specified * [`flex-wrap`](flex-wrap): as specified | | Animation type | discrete | Formal syntax ------------- ``` flex-flow = <'flex-direction'> [||](value_definition_syntax#double_bar) <'flex-wrap'> ``` Examples -------- ### Setting column-reverse and wrap ``` element { /\* Main-axis is the block direction with reversed main-start and main-end. Flex items are laid out in multiple lines \*/ flex-flow: column-reverse wrap; } ``` Specifications -------------- | Specification | | --- | | [CSS Flexible Box Layout Module Level 1 # flex-flow-property](https://w3c.github.io/csswg-drafts/css-flexbox/#flex-flow-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `flex-flow` | 29 21 | 12 | 49 28 | 11 | 15 12.1 | 9 7 | ≤37 4.4 | 29 25 | 49 28 | 14 12.1 | 9 7 | 2.0 1.5 | See also -------- * CSS Flexbox Guide: *[Basic Concepts of Flexbox](css_flexible_box_layout/basic_concepts_of_flexbox)* * CSS Flexbox Guide: *[Ordering flex items](css_flexible_box_layout/ordering_flex_items)* css Animatable CSS properties Animatable CSS properties ========================= A CSS property is *animatable* if its value can be made to change over a given amount of time. **Certain CSS properties can be animated** using [CSS Animations](css_animations) or [CSS Transitions](css_transitions). CSS properties that define animation parameters such as <animation-direction> and <animation-name> are not animatable because animating them would create complex recursive behavior. **Note:** To check whether or not a CSS property can be animated, see the "Formal definition" section on the property's page on MDN Web Docs. For example, check out the "Animation type" field in the "Formal definition" section for [padding-bottom](padding-bottom#formal_definition) and [animation-direction](animation-direction#formal_definition). The following CSS properties are animatable: * [`-moz-outline-radius`](-moz-outline-radius) * [`-moz-outline-radius-bottomleft`](-moz-outline-radius-bottomleft) * [`-moz-outline-radius-bottomright`](-moz-outline-radius-bottomright) * [`-moz-outline-radius-topleft`](-moz-outline-radius-topleft) * [`-moz-outline-radius-topright`](-moz-outline-radius-topright) * [`-ms-grid-columns`](grid-template-columns) * [`-ms-grid-rows`](grid-template-rows) * [`-webkit-line-clamp`](-webkit-line-clamp) * [`-webkit-text-fill-color`](-webkit-text-fill-color) * [`-webkit-text-stroke`](-webkit-text-stroke) * [`-webkit-text-stroke-color`](-webkit-text-stroke-color) * [`accent-color`](accent-color) * [`all`](all) * [`backdrop-filter`](backdrop-filter) * [`background`](background) * [`background-color`](background-color) * [`background-position`](background-position) * [`background-size`](background-size) * [`block-size`](block-size) * [`border`](border) * [`border-block-end`](border-block-end) * [`border-block-end-color`](border-block-end-color) * [`border-block-end-width`](border-block-end-width) * [`border-block-start`](border-block-start) * [`border-block-start-color`](border-block-start-color) * [`border-block-start-width`](border-block-start-width) * [`border-bottom`](border-bottom) * [`border-bottom-color`](border-bottom-color) * [`border-bottom-left-radius`](border-bottom-left-radius) * [`border-bottom-right-radius`](border-bottom-right-radius) * [`border-bottom-width`](border-bottom-width) * [`border-color`](border-color) * [`border-end-end-radius`](border-end-end-radius) * [`border-end-start-radius`](border-end-start-radius) * [`border-image-outset`](border-image-outset) * [`border-image-slice`](border-image-slice) * [`border-image-width`](border-image-width) * [`border-inline-end`](border-inline-end) * [`border-inline-end-color`](border-inline-end-color) * [`border-inline-end-width`](border-inline-end-width) * [`border-inline-start`](border-inline-start) * [`border-inline-start-color`](border-inline-start-color) * [`border-inline-start-width`](border-inline-start-width) * [`border-left`](border-left) * [`border-left-color`](border-left-color) * [`border-left-width`](border-left-width) * [`border-radius`](border-radius) * [`border-right`](border-right) * [`border-right-color`](border-right-color) * [`border-right-width`](border-right-width) * [`border-start-end-radius`](border-start-end-radius) * [`border-start-start-radius`](border-start-start-radius) * [`border-top`](border-top) * [`border-top-color`](border-top-color) * [`border-top-left-radius`](border-top-left-radius) * [`border-top-right-radius`](border-top-right-radius) * [`border-top-width`](border-top-width) * [`border-width`](border-width) * [`bottom`](bottom) * [`box-shadow`](box-shadow) * `caret` * [`caret-color`](caret-color) * `caret-shape` * [`clip`](clip) * [`clip-path`](clip-path) * [`color`](color) * [`column-count`](column-count) * [`column-gap`](column-gap) * [`column-rule`](column-rule) * [`column-rule-color`](column-rule-color) * [`column-rule-width`](column-rule-width) * [`column-width`](column-width) * [`columns`](columns) * [`contain-intrinsic-block-size`](contain-intrinsic-block-size) * [`contain-intrinsic-height`](contain-intrinsic-height) * [`contain-intrinsic-inline-size`](contain-intrinsic-inline-size) * [`contain-intrinsic-size`](contain-intrinsic-size) * [`contain-intrinsic-width`](contain-intrinsic-width) * [`filter`](filter) * [`flex`](flex) * [`flex-basis`](flex-basis) * [`flex-grow`](flex-grow) * [`flex-shrink`](flex-shrink) * [`font`](font) * [`font-size`](font-size) * [`font-size-adjust`](font-size-adjust) * [`font-stretch`](font-stretch) * [`font-variation-settings`](font-variation-settings) * [`font-weight`](font-weight) * [`gap`](gap) * [`grid-column-gap`](column-gap) * [`grid-gap`](gap) * [`grid-row-gap`](row-gap) * [`grid-template-columns`](grid-template-columns) * [`grid-template-rows`](grid-template-rows) * [`height`](height) * [`inline-size`](inline-size) * `input-security` * [`inset`](inset) * [`inset-block`](inset-block) * [`inset-block-end`](inset-block-end) * [`inset-block-start`](inset-block-start) * [`inset-inline`](inset-inline) * [`inset-inline-end`](inset-inline-end) * [`inset-inline-start`](inset-inline-start) * [`left`](left) * [`letter-spacing`](letter-spacing) * `line-clamp` * [`line-height`](line-height) * [`margin`](margin) * [`margin-block`](margin-block) * [`margin-block-end`](margin-block-end) * [`margin-block-start`](margin-block-start) * [`margin-bottom`](margin-bottom) * [`margin-inline`](margin-inline) * [`margin-inline-end`](margin-inline-end) * [`margin-inline-start`](margin-inline-start) * [`margin-left`](margin-left) * [`margin-right`](margin-right) * [`margin-top`](margin-top) * [`mask`](mask) * [`mask-border`](mask-border) * [`mask-position`](mask-position) * [`mask-size`](mask-size) * [`max-block-size`](max-block-size) * [`max-height`](max-height) * [`max-inline-size`](max-inline-size) * `max-lines` * [`max-width`](max-width) * [`min-block-size`](min-block-size) * [`min-height`](min-height) * [`min-inline-size`](min-inline-size) * [`min-width`](min-width) * [`object-position`](object-position) * [`offset`](offset) * [`offset-anchor`](offset-anchor) * [`offset-distance`](offset-distance) * [`offset-path`](offset-path) * [`offset-position`](offset-position) * [`offset-rotate`](offset-rotate) * [`opacity`](opacity) * [`order`](order) * [`outline`](outline) * [`outline-color`](outline-color) * [`outline-offset`](outline-offset) * [`outline-width`](outline-width) * [`padding`](padding) * [`padding-block`](padding-block) * [`padding-block-end`](padding-block-end) * [`padding-block-start`](padding-block-start) * [`padding-bottom`](padding-bottom) * [`padding-inline`](padding-inline) * [`padding-inline-end`](padding-inline-end) * [`padding-inline-start`](padding-inline-start) * [`padding-left`](padding-left) * [`padding-right`](padding-right) * [`padding-top`](padding-top) * [`perspective`](perspective) * [`perspective-origin`](perspective-origin) * [`right`](right) * [`rotate`](rotate) * [`row-gap`](row-gap) * [`scale`](scale) * [`scroll-margin`](scroll-margin) * [`scroll-margin-block`](scroll-margin-block) * [`scroll-margin-block-end`](scroll-margin-block-end) * [`scroll-margin-block-start`](scroll-margin-block-start) * [`scroll-margin-bottom`](scroll-margin-bottom) * [`scroll-margin-inline`](scroll-margin-inline) * [`scroll-margin-inline-end`](scroll-margin-inline-end) * [`scroll-margin-inline-start`](scroll-margin-inline-start) * [`scroll-margin-left`](scroll-margin-left) * [`scroll-margin-right`](scroll-margin-right) * [`scroll-margin-top`](scroll-margin-top) * [`scroll-padding`](scroll-padding) * [`scroll-padding-block`](scroll-padding-block) * [`scroll-padding-block-end`](scroll-padding-block-end) * [`scroll-padding-block-start`](scroll-padding-block-start) * [`scroll-padding-bottom`](scroll-padding-bottom) * [`scroll-padding-inline`](scroll-padding-inline) * [`scroll-padding-inline-end`](scroll-padding-inline-end) * [`scroll-padding-inline-start`](scroll-padding-inline-start) * [`scroll-padding-left`](scroll-padding-left) * [`scroll-padding-right`](scroll-padding-right) * [`scroll-padding-top`](scroll-padding-top) * [`scroll-snap-coordinate`](scroll-snap-coordinate) * [`scroll-snap-destination`](scroll-snap-destination) * [`scroll-timeline`](scroll-timeline) * [`scrollbar-color`](scrollbar-color) * [`shape-image-threshold`](shape-image-threshold) * [`shape-margin`](shape-margin) * [`shape-outside`](shape-outside) * [`tab-size`](tab-size) * [`text-decoration`](text-decoration) * [`text-decoration-color`](text-decoration-color) * [`text-decoration-thickness`](text-decoration-thickness) * [`text-emphasis`](text-emphasis) * [`text-emphasis-color`](text-emphasis-color) * [`text-indent`](text-indent) * [`text-shadow`](text-shadow) * [`text-underline-offset`](text-underline-offset) * [`top`](top) * [`transform`](transform) * [`transform-origin`](transform-origin) * [`translate`](translate) * [`vertical-align`](vertical-align) * [`visibility`](visibility) * [`width`](width) * [`word-spacing`](word-spacing) * [`z-index`](z-index) * [`zoom`](zoom) css font-synthesis font-synthesis ============== The `font-synthesis` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property controls which missing typefaces, bold, italic, or small-caps, may be synthesized by the browser. Try it ------ Syntax ------ ``` font-synthesis: none; font-synthesis: weight; font-synthesis: style; font-synthesis: small-caps; font-synthesis: weight style small-caps; /\* Global values \*/ font-synthesis: inherit; font-synthesis: initial; font-synthesis: revert; font-synthesis: revert-layer; font-synthesis: unset; ``` ### Values `none` Indicates that no bold, italic, nor small-caps typeface may be synthesized. `weight` Indicates that a bold typeface may be synthesized if needed. `style` Indicates that an italic typeface may be synthesized if needed. `small-caps` Indicates that a small-caps typeface may be synthesized if needed. Description ----------- Most standard Western fonts include italic and bold variants, and some fonts include a small-caps variant. However, many fonts do not. Fonts used for Chinese, Japanese, Korean and other logographic scripts tend not to include these variants, and synthesizing them may impede the legibility of the text. In these cases, it may be desirable to switch off the browser's default font-synthesis. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `weight style` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` font-synthesis = none [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) weight [||](value_definition_syntax#double_bar) style [||](value_definition_syntax#double_bar) small-caps []](value_definition_syntax#brackets) ``` Examples -------- ### Disabling font synthesis #### HTML ``` <em class="syn">Synthesize me! 站直。</em> <br /> <em class="no-syn">Don't synthesize me! 站直。</em> ``` #### CSS ``` em { font-weight: bold; } .syn { font-synthesis: style weight small-caps; } .no-syn { font-synthesis: none; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Fonts Module Level 4 # font-synthesis](https://w3c.github.io/csswg-drafts/css-fonts/#font-synthesis) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `font-synthesis` | 97 | 97 | 34 | No | 83 | 9 | 97 | 97 | 34 | No | 9 | 18.0 | | `small-caps` | 97 | 97 | 93 | No | 83 | 10.1 | 97 | 97 | 93 | No | 10.3 | 18.0 | See also -------- * [`font-style`](font-style) * [`font-weight`](font-weight) css @font-palette-values @font-palette-values ==================== The `@font-palette-values` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) <at-rule> allows you to customize the default values of <font-palette> created by the font-maker. Syntax ------ ``` @font-palette-values --identifier { font-family: Bixa; } .my-class { font-palette: --identifier; } ``` The [<dashed-ident>](dashed-ident) is a user defined identifier, that while it looks like a [CSS custom property](using_css_custom_properties) behaves in a different way and is not wrapped in a [CSS var() function](var()). ### Descriptors [font-family](@font-palette-values/font-family) Specifies the name of the font family that this palette can be applied to. [base-palette](@font-palette-values/base-palette) Specifies the name or index of the base-palette, created by the font-maker, to use. [override-colors](@font-palette-values/override-colors) Specifies the colors in the base palette to override. Formal definition ----------------- Value not found in DB!Formal syntax ------------- ``` @font-palette-values = @font-palette-values [<dashed-ident>](dashed-ident) { [<declaration-list>](declaration-list) } ``` Examples -------- ### Overriding colors in an existing palette This example shows how you can change some or all of the colors in a color font. #### HTML ``` <p>default colors</p> <p class="alternate">alternate colors</p> ``` #### CSS ``` @import url(https://fonts.googleapis.com/css2?family=Bungee+Spice); p { font-family: "Bungee Spice"; font-size: 2rem; } @font-palette-values --Alternate { font-family: "Bungee Spice"; override-colors: 0 #00ffbb, 1 #007744; } .alternate { font-palette: --Alternate; } ``` #### Result When overriding colors of the normal or base-palette at index 0 you do not need to declare which base-palette to use. This should only be done when overriding a different base-palette. If you are overriding all the colors then there is also no need to specify the base-palette to use. Specifications -------------- | Specification | | --- | | [CSS Fonts Module Level 4 # at-ruledef-font-palette-values](https://w3c.github.io/csswg-drafts/css-fonts/#at-ruledef-font-palette-values) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `@font-palette-values` | 101 | 101 | 107 | No | 87 | 15.4 | 101 | 101 | 107 | 70 | 15.4 | 19.0 | | `base-palette` | 101 | 101 | 107 | No | 87 | 15.4 | 101 | 101 | 107 | 70 | 15.4 | 19.0 | | `font-family` | 101 | 101 | 107 | No | 87 | 15.4 | 101 | 101 | 107 | 70 | 15.4 | 19.0 | | `override-colors` | 101 | 101 | 107 | No | 87 | 15.4 | 101 | 101 | 107 | 70 | 15.4 | 19.0 | See also -------- * [`font-palette`](font-palette) property * [`font-family`](@font-palette-values/font-family) descriptor * [`base-palette`](@font-palette-values/base-palette) descriptor * [`override-colors`](@font-palette-values/override-colors) descriptor css Resolved value Resolved value ============== The **resolved value** of a [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property is the value returned by [`getComputedStyle()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle). For most properties, it is the [computed value](computed_value), but for a few legacy properties (including [`width`](width) and [`height`](height)), it is instead the [used value](used_value). See the specification link below for more per-property details. Specifications -------------- | Specification | | --- | | [CSS Object Model (CSSOM) # resolved-values](https://drafts.csswg.org/cssom/#resolved-values) | See also -------- * [`window.getComputedStyle`](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle) * CSS key concepts: + [CSS syntax](syntax) + [At-rules](at-rule) + [Comments](comments) + [Specificity](specificity) + [Inheritance](inheritance) + [Box model](css_box_model/introduction_to_the_css_box_model) + [Layout modes](layout_mode) + [Visual formatting models](visual_formatting_model) + [Margin collapsing](css_box_model/mastering_margin_collapsing) + Values - [Initial values](initial_value) - [Computed values](computed_value) - [Used values](used_value) - [Actual values](actual_value) + [Value definition syntax](value_definition_syntax) + [Shorthand properties](shorthand_properties) + [Replaced elements](replaced_element) css column-rule-style column-rule-style ================= The `column-rule-style` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the style of the line drawn between columns in a multi-column layout. Try it ------ Syntax ------ ``` /\* <'border-style'> values \*/ column-rule-style: none; column-rule-style: hidden; column-rule-style: dotted; column-rule-style: dashed; column-rule-style: solid; column-rule-style: double; column-rule-style: groove; column-rule-style: ridge; column-rule-style: inset; column-rule-style: outset; /\* Global values \*/ column-rule-style: inherit; column-rule-style: initial; column-rule-style: revert; column-rule-style: revert-layer; column-rule-style: unset; ``` The `column-rule-style` property is specified as a single `<'border-style'>` value. ### Values `<'border-style'>` Is a keyword defined by [`border-style`](border-style) describing the style of the rule. The styling must be interpreted as in the collapsing border model. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | multicol elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` column-rule-style = <line-style> <line-style> = none [|](value_definition_syntax#single_bar) hidden [|](value_definition_syntax#single_bar) dotted [|](value_definition_syntax#single_bar) dashed [|](value_definition_syntax#single_bar) solid [|](value_definition_syntax#single_bar) double [|](value_definition_syntax#single_bar) groove [|](value_definition_syntax#single_bar) ridge [|](value_definition_syntax#single_bar) inset [|](value_definition_syntax#single_bar) outset ``` Examples -------- ### Setting a dashed column rule #### HTML ``` <p> This is a bunch of text split into three columns. The `column-rule-style` property is used to change the style of the line that is drawn between columns. Don't you think that's wonderful? </p> ``` #### CSS ``` p { column-count: 3; column-rule-style: dashed; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Multi-column Layout Module Level 1 # crs](https://w3c.github.io/csswg-drafts/css-multicol/#crs) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `column-rule-style` | 50 1 | 12 12 | 52 3.5-74 | 10 | 15 11.1 | 9 3 | 50 ≤37 | 50 18 | 52 4 | 14 11.1 | 9 1 | 5.0 1.0 | See also -------- * [Multiple-column Layout](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Multiple-column_Layout) * [`column-rule`](column-rule) * [`column-rule-width`](column-rule-width) * [`column-rule-color`](column-rule-color)
programming_docs
css border-spacing border-spacing ============== The `border-spacing` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the distance between the borders of adjacent cells in a [`<table>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table). This property applies only when [`border-collapse`](border-collapse) is `separate`. Try it ------ The `border-spacing` value is also used along the outside edge of the table, where the distance between the table's border and the cells in the first/last column or row is the sum of the relevant (horizontal or vertical) `border-spacing` and the relevant (top, right, bottom, or left) [`padding`](padding) on the table. **Note:** The `border-spacing` property is equivalent to the deprecated `cellspacing` attribute of the `<table>` element, except that `border-spacing` has an optional second value that can be used to set different horizontal and vertical spacing. Syntax ------ ``` /\* <length> \*/ border-spacing: 2px; /\* horizontal <length> | vertical <length> \*/ border-spacing: 1cm 2em; /\* Global values \*/ border-spacing: inherit; border-spacing: initial; border-spacing: revert; border-spacing: revert-layer; border-spacing: unset; ``` The `border-spacing` property may be specified as either one or two values. * When **one** `<length>` value is specified, it defines both the horizontal and vertical spacings between cells. * When **two** `<length>` values are specified, the first value defines the horizontal spacing between cells (i.e., the space between cells in adjacent *columns*), and the second value defines the vertical spacing between cells (i.e., the space between cells in adjacent *rows*). ### Values [`<length>`](length) The size of the spacing as a fixed value. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | `table` and `inline-table` elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | two absolute lengths | | Animation type | discrete | Formal syntax ------------- ``` border-spacing = [<length>](length)[{1,2}](value_definition_syntax#curly_braces) ``` Examples -------- ### Spacing and padding table cells This example applies a spacing of `.5em` vertically and `1em` horizontally between a table's cells. Note how, along its outside edges, the table's `padding` values are added to its `border-spacing` values. #### HTML ``` <table> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>4</td> <td>5</td> <td>6</td> </tr> <tr> <td>7</td> <td>8</td> <td>9</td> </tr> </table> ``` #### CSS ``` table { border-spacing: 1em 0.5em; padding: 0 2em 1em 0; border: 1px solid orange; } td { width: 1.5em; height: 1.5em; background: #d2d2d2; text-align: center; vertical-align: middle; } ``` #### Result Specifications -------------- | Specification | | --- | | [Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification # separated-borders](https://w3c.github.io/csswg-drafts/css2/#separated-borders) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-spacing` | 1 | 12 | 1 | 8 | 4 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [`border-collapse`](border-collapse), [`border-style`](border-style) * The `border-spacing` property alters the appearance of the [`<table>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table) HTML element. css <system-color> <system-color> ============== The `<system-color>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) usually reflects the default color choices used for the different parts of a web page. However, user agents can provide an accessibility feature called *forced colors mode*, in which colors are restricted into a user- and user agent-defined palette, overriding the author's choice of colors in certain properties. In forced colors mode, `<system-color>` exposes the chosen colors, so that the rest of the page can integrate with them. An example of forced colors mode is [high contrast mode on Windows](https://blogs.windows.com/msedgedev/2020/09/17/styling-for-windows-high-contrast-with-new-standards-for-forced-colors/). In forced colors mode, authors should use colors from the `<system-color>` type for all properties that are *not* in the set of properties whose colors are overridden. This ensures that the page consistently uses the same color palette across all properties. Authors can detect forced colors mode using the [`forced-colors`](@media/forced-colors) media feature. A `<system-color>` value can be used anywhere a [`<color>`](color_value) can be used. Syntax ------ Note that these keywords are *case insensitive*, but are listed here with mixed case for readability. `AccentColor` Background of accented user interface controls `AccentColorText` Text of accented user interface controls `ActiveText` Text of active links `ButtonBorder` Base border color of controls `ButtonFace` Background color of controls `ButtonText` Text color of controls `Canvas` Background of application content or documents `CanvasText` Text color in application content or documents `Field` Background of input fields `FieldText` Text in input fields `GrayText` Text color for disabled items (e.g. a disabled control) `Highlight` Background of selected items `HighlightText` Text color of selected items `LinkText` Text of non-active, non-visited links `Mark` Background of text that has been specially marked (such as by the HTML `mark` element) `MarkText` Text that has been specially marked (such as by the HTML `mark` element) `VisitedText` Text of visited links ### Deprecated system color keywords The following keywords were defined in earlier versions of the CSS Color Module. They are now deprecated for use on public web pages. `ActiveBorder` Deprecated Active window border. `ActiveCaption` Deprecated Active window caption. Should be used with `CaptionText` as foreground color. `AppWorkspace` Deprecated Background color of multiple document interface. `Background` Deprecated Desktop background. `ButtonHighlight` Deprecated The color of the border facing the light source for 3-D elements that appear 3-D due to that layer of surrounding border. `ButtonShadow` Deprecated The color of the border away from the light source for 3-D elements that appear 3-D due to that layer of surrounding border. `CaptionText` Deprecated Text in caption, size box, and scrollbar arrow box. Should be used with the `ActiveCaption` background color. `InactiveBorder` Deprecated Inactive window border. `InactiveCaption` Deprecated Inactive window caption. Should be used with the `InactiveCaptionText` foreground color. `InactiveCaptionText` Deprecated Color of text in an inactive caption. Should be used with the `InactiveCaption` background color. `InfoBackground` Deprecated Background color for tooltip controls. Should be used with the `InfoText` foreground color. `InfoText` Deprecated Text color for tooltip controls. Should be used with the `InfoBackground` background color. `Menu` Deprecated Menu background. Should be used with the `MenuText` or `-moz-MenuBarText` foreground color. `MenuText` Deprecated Text in menus. Should be used with the `Menu` background color. `Scrollbar` Deprecated Background color of scroll bars. `ThreeDDarkShadow` Deprecated The color of the darker (generally outer) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border. `ThreeDFace` Deprecated The face background color for 3-D elements that appear 3-D due to two concentric layers of surrounding border. Should be used with the `ButtonText` foreground color. `ThreeDHighlight` Deprecated The color of the lighter (generally outer) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border. `ThreeDLightShadow` Deprecated The color of the darker (generally inner) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border. `ThreeDShadow` Deprecated The color of the lighter (generally inner) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border. `Window` Deprecated Window background. Should be used with the `WindowText` foreground color. `WindowFrame` Deprecated Window frame. `WindowText` Deprecated Text in windows. Should be used with the `Window` background color. ### Firefox non-standard system color extensions Firefox also supports some non-standard extensions to the system color keyword set. `-moz-ButtonDefault` Non-standard The border color that goes around buttons that represent the default action for a dialog box. `-moz-ButtonHoverFace` Non-standard The background color of a button that the mouse pointer is over (which would be `ThreeDFace` or `ButtonFace` when the mouse pointer is not over it). Should be used with the `-moz-ButtonHoverText` foreground color. `-moz-ButtonHoverText` Non-standard The text color of a button that the mouse pointer is over (which would be ButtonText when the mouse pointer is not over it). Should be used with the `-moz-ButtonHoverFace background` color. `-moz-CellHighlight` Non-standard Background color for selected item in a tree widget. Should be used with the `-moz-CellHighlightText` foreground color. See also `-moz-html-CellHighlight`. `-moz-CellHighlightText` Non-standard Text color for a selected item in a tree. Should be used with the `-moz-CellHighlight background` color. See also `-moz-html-CellHighlightText`. `-moz-Combobox` Non-standard Background color for combo-boxes. Should be used with the `-moz-ComboboxText` foreground color. In versions prior to 1.9.2, use `-moz-Field` instead. `-moz-ComboboxText` Non-standard Text color for combo-boxes. Should be used with the `-moz-Combobox` background color. In versions prior to 1.9.2, use `-moz-FieldText` instead. `-moz-Dialog` Non-standard Background color for dialog boxes. Should be used with the `-moz-DialogText` foreground color. `-moz-DialogText` Non-standard Text color for dialog boxes. Should be used with the `-moz-Dialog` background color. `-moz-dragtargetzone` Non-standard , `-moz-EvenTreeRow` Non-standard Background color for even-numbered rows in a tree. Should be used with the `-moz-FieldText` foreground color. In Gecko versions prior to 1.9, use `-moz-Field`. See also `-moz-OddTreeRow`. `-moz-html-CellHighlight` Non-standard Background color for highlighted item in HTML [`<select>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select)s. Should be used with the `-moz-html-CellHighlightText` foreground color. Prior to Gecko 1.9, use `-moz-CellHighlight`. `-moz-html-CellHighlightText` Non-standard Text color for highlighted items in HTML [`<select>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select)s. Should be used with the `-moz-html-CellHighlight` background color. Prior to Gecko 1.9, use `-moz-CellHighlightText`. `-moz-mac-accentdarkestshadow` Non-standard , `-moz-mac-accentdarkshadow` Non-standard , `-moz-mac-accentface` Non-standard , `-moz-mac-accentlightesthighlight` Non-standard , `-moz-mac-accentlightshadow` Non-standard , `-moz-mac-accentregularhighlight` Non-standard , `-moz-mac-accentregularshadow` Non-standard Accent colors. `-moz-mac-chrome-active` Non-standard , `-moz-mac-chrome-inactive` Non-standard Colors for inactive and active browser chrome. `-moz-mac-focusring` Non-standard , `-moz-mac-menuselect` Non-standard , `-moz-mac-menushadow` Non-standard , `-moz-mac-menutextselect` Non-standard , `-moz-MenuHover` Non-standard Background color for hovered menu items. Often similar to `Highlight`. Should be used with the `-moz-MenuHoverText` or `-moz-MenuBarHoverText` foreground color. `-moz-MenuHoverText` Non-standard Text color for hovered menu items. Often similar to `HighlightText`. Should be used with the `-moz-MenuHover` background color. `-moz-MenuBarText` Non-standard Text color in menu bars. Often similar to `MenuText`. Should be used on top of `Menu` background. `-moz-MenuBarHoverText` Non-standard Color for hovered text in menu bars. Often similar to `-moz-MenuHoverText`. Should be used on top of `-moz-MenuHover` background. `-moz-nativehyperlinktext` Non-standard Default platform hyperlink color. `-moz-OddTreeRow` Non-standard Background color for odd-numbered rows in a tree. Should be used with the `-moz-FieldText` foreground color. In Gecko versions prior to 1.9, use `-moz-Field`. See also `-moz-EvenTreeRow`. `-moz-win-communicationstext` Non-standard Should be used for text in objects with `[`appearance`](appearance): -moz-win-communications-toolbox;`. `-moz-win-mediatext` Non-standard Should be used for text in objects with `[`appearance`](appearance): -moz-win-media-toolbox`. `-moz-win-accentcolor` Non-standard Used to access the Windows 10 custom accent color that you can set on the start menu, taskbar, title bars, etc. `-moz-win-accentcolortext` Non-standard Used to access the color of text placed over the Windows 10 custom accent color in the start menu, taskbar, title bars, etc. Examples -------- ### Using system colors In this example we have a button that normally gets its contrast using the [`box-shadow`](box-shadow) property. In forced colors mode, `box-shadow` is forced to `none`, so the example uses the `forced-colors` media feature to ensure there is a border of the appropriate color (`ButtonBorder` in this case). #### HTML ``` <button class="button">Press me!</button> ``` #### CSS ``` .button { border: 0; padding: 10px; box-shadow: -2px -2px 5px gray, 2px 2px 5px gray; } @media (forced-colors: active) { .button { /\* Use a border instead, since box-shadow is forced to 'none' in forced-colors mode \*/ border: 2px ButtonBorder solid; } } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Color Module Level 4 # css-system-colors](https://w3c.github.io/csswg-drafts/css-color/#css-system-colors) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `system-color` | 1 | 12 | 1 | 3 | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 | See also -------- * [`<color>`](color_value): the data type these keywords belong to. css mask-border-outset mask-border-outset ================== The `mask-border-outset` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property specifies the distance by which an element's [mask border](mask-border) is set out from its border box. Syntax ------ ``` /\* <length> value \*/ mask-border-outset: 1rem; /\* <number> value \*/ mask-border-outset: 1.5; /\* top and bottom | left and right \*/ mask-border-outset: 1 1.2; /\* top | left and right | bottom \*/ mask-border-outset: 30px 2 45px; /\* top | right | bottom | left \*/ mask-border-outset: 7px 12px 14px 5px; /\* Global values \*/ mask-border-outset: inherit; mask-border-outset: initial; mask-border-outset: revert; mask-border-outset: revert-layer; mask-border-outset: unset; ``` The `mask-border-outset` property may be specified as one, two, three, or four values. Each value is a [`<length>`](length) or [`<number>`](number). Negative values are invalid. * When **one** value is specified, it applies the same outset to **all four sides**. * When **two** values are specified, the first outset applies to the **top and bottom**, the second to the **left and right**. * When **three** values are specified, the first outset applies to the **top**, the second to the **left and right**, the third to the **bottom**. * When **four** values are specified, the outsets apply to the **top**, **right**, **bottom**, and **left** in that order (clockwise). ### Values [`<length>`](length) The size of the mask border outset as a dimension. [`<number>`](number) The size of the mask border outset as a multiple of the corresponding [`border-width`](border-width). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | all elements; In SVG, it applies to container elements excluding the [`<defs>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs) element and all graphics elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified, but with relative lengths converted into absolute lengths | | Animation type | discrete | Formal syntax ------------- ``` mask-border-outset = [[](value_definition_syntax#brackets) [<length>](length) [|](value_definition_syntax#single_bar) [<number>](number) []](value_definition_syntax#brackets)[{1,4}](value_definition_syntax#curly_braces) ``` Examples -------- ### Basic usage This property doesn't appear to be supported anywhere yet. When it eventually starts to be supported, it will serve to move the mask away from the inner edge of the element's border box — you can use it to make the mask start from part way across the border, rather than the inside of it. ``` mask-border-outset: 1rem; ``` Chromium-based browsers support an outdated version of this property — `mask-box-image-outset` — with a prefix: ``` -webkit-mask-box-image-outset: 1rem; ``` **Note:** The [`mask-border`](mask-border) page features a working example (using the out-of-date prefixed border mask properties supported in Chromium), so you can get an idea of the effect. Specifications -------------- | Specification | | --- | | [CSS Masking Module Level 1 # the-mask-border-outset](https://drafts.fxtf.org/css-masking/#the-mask-border-outset) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `mask-border-outset` | 1 | 79 | No See [bug 877294](https://bugzil.la/877294). | No | 15 | 3.1 | 4.4 | 18 | No See [bug 877294](https://bugzil.la/877294). | 14 | 3 | 1.0 | See also -------- * [`mask-border`](mask-border) * [`mask-border-mode`](mask-border-mode) * [`mask-border-repeat`](mask-border-repeat) * [`mask-border-source`](mask-border-source) * [`mask-border-width`](mask-border-width) css animation-iteration-count animation-iteration-count ========================= The `animation-iteration-count` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the number of times an animation sequence should be played before stopping. Try it ------ It is often convenient to use the shorthand property [`animation`](animation) to set all animation properties at once. Syntax ------ ``` /\* Keyword value \*/ animation-iteration-count: infinite; /\* <number> values \*/ animation-iteration-count: 3; animation-iteration-count: 2.4; /\* Multiple values \*/ animation-iteration-count: 2, 0, infinite; /\* Global values \*/ animation-iteration-count: inherit; animation-iteration-count: initial; animation-iteration-count: revert; animation-iteration-count: revert-layer; animation-iteration-count: unset; ``` The `animation-iteration-count` property is specified as one or more comma-separated values. ### Values `infinite` The animation will repeat forever. `[`<number>`](number)` The number of times the animation will repeat; this is `1` by default. You may specify non-integer values to play part of an animation cycle: for example, `0.5` will play half of the animation cycle. Negative values are invalid. **Note:** When you specify multiple comma-separated values on an `animation-*` property, they are applied to the animations in the order in which the [`animation-name`](animation-name)s appear. For situations where the number of animations and `animation-*` property values do not match, see [Setting multiple animation property values](css_animations/using_css_animations#setting_multiple_animation_property_values). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `1` | | Applies to | all elements, [`::before`](::before) and [`::after`](::after) <pseudo-elements> | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | Not animatable | Formal syntax ------------- ``` animation-iteration-count = <single-animation-iteration-count>[#](value_definition_syntax#hash_mark) <single-animation-iteration-count> = infinite [|](value_definition_syntax#single_bar) [<number [0,∞]>](number) ``` Examples -------- ### Setting iteration count This animation will run 10 times. #### HTML ``` <div class="box"></div> ``` #### CSS ``` .box { background-color: rebeccapurple; border-radius: 10px; width: 100px; height: 100px; } .box:hover { animation-name: rotate; animation-duration: 0.7s; animation-iteration-count: 10; } @keyframes rotate { 0% { transform: rotate(0); } 100% { transform: rotate(360deg); } } ``` #### Result Hover over the rectangle to start the animation. See [CSS animations](css_animations/using_css_animations) for examples. Specifications -------------- | Specification | | --- | | [CSS Animations Level 1 # animation-iteration-count](https://w3c.github.io/csswg-drafts/css-animations/#animation-iteration-count) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `animation-iteration-count` | 43 3 | 12 12 | 49 16 5 | 10 | 30 15 12.1-15 12-15 | 9 4 | 43 ≤37 | 43 18 | 49 16 5 | 30 14 12.1-14 12-14 | 9 3.2 | 4.0 1.0 | See also -------- * [Using CSS animations](css_animations/using_css_animations) * JavaScript [`AnimationEvent`](https://developer.mozilla.org/en-US/docs/Web/API/AnimationEvent) API * Other related animation properties: [`animation`](animation), [`animation-composition`](animation-composition), [`animation-delay`](animation-delay), [`animation-direction`](animation-direction), [`animation-duration`](animation-duration), [`animation-fill-mode`](animation-fill-mode), [`animation-name`](animation-name), [`animation-play-state`](animation-play-state), [`animation-timeline`](animation-timeline), [`animation-timing-function`](animation-timing-function)
programming_docs
css :required :required ========= The `:required` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) represents any [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input), [`<select>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select), or [`<textarea>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea) element that has the [`required`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-required) attribute set on it. Try it ------ This pseudo-class is useful for highlighting fields that must have valid data before a form can be submitted. **Note:** The [`:optional`](:optional) pseudo-class selects *optional* form fields. Syntax ------ ``` :required ``` Examples -------- ### The required field has a red border #### HTML ``` <form> <div class="field"> <label for="url\_input">Enter a URL:</label> <input type="url" id="url\_input" /> </div> <div class="field"> <label for="email\_input">Enter an email address:</label> <input type="email" id="email\_input" required /> </div> </form> ``` #### CSS ``` label { display: block; margin: 1px; padding: 1px; } .field { margin: 1px; padding: 1px; } input:required { border-color: #800000; border-width: 3px; } input:required:invalid { border-color: #c00000; } ``` #### Result Accessibility concerns ---------------------- Mandatory [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input)s should have the [`required`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-required) attribute applied to them. This will ensure that people navigating with the aid of assistive technology such as a screen reader will be able to understand which inputs need valid content to ensure a successful submission. If the form also contains [optional](:optional) inputs, required inputs should be indicated visually using a treatment that does not rely solely on color to convey meaning. Typically, descriptive text and/or an icon are used. * [MDN Understanding WCAG, Guideline 3.3 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Understandable#guideline_3.3_%e2%80%94_input_assistance_help_users_avoid_and_correct_mistakes) * [Understanding Success Criterion 3.3.2 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/minimize-error-cues.html) Specifications -------------- | Specification | | --- | | [HTML Standard # selector-required](https://html.spec.whatwg.org/multipage/semantics-other.html#selector-required) | | [Selectors Level 4 # opt-pseudos](https://w3c.github.io/csswg-drafts/selectors/#opt-pseudos) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:required` | 10 | 12 | 4 | 10 | 10 | 5 | 4.4.3 | 18 | 4 | 10.1 | 5 | 1.0 | See also -------- * Other validation-related pseudo-classes: [`:optional`](:optional), [`:invalid`](:invalid), [`:valid`](:valid) * [Form data validation](https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation) css background-attachment background-attachment ===================== The `background-attachment` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets whether a background image's position is fixed within the [viewport](https://developer.mozilla.org/en-US/docs/Glossary/Viewport), or scrolls with its containing block. Try it ------ Syntax ------ ``` /\* 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 [`background-clip: text`](background-clip#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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | `scroll` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` background-attachment = <attachment>[#](value_definition_syntax#hash_mark) <attachment> = scroll [|](value_definition_syntax#single_bar) fixed [|](value_definition_syntax#single_bar) local ``` Examples -------- ### Simple example #### 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 ``` p { background-image: url("starsolid.gif"); background-attachment: fixed; } ``` #### Result ### 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 ``` <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 ``` p { background-image: url("starsolid.gif"), url("startransparent.gif"); background-attachment: fixed, scroll; background-repeat: no-repeat, repeat-y; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # the-background-attachment](https://w3c.github.io/csswg-drafts/css-backgrounds/#the-background-attachment) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `background-attachment` | 1 | 12 | 1 | 4 | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 3.2 | 1.0 | | `fixed` | 1 | 12 | 2 | 9 | 10.5 | 14 `local` is recognized but has no effect due to [a bug](https://webkit.org/b/219324). 3.1-14 | 37 | 18 | 4 | 14 | 5 `fixed` is recognized but has no effect. See [bug 219324](https://webkit.org/b/219324). | 1.0 | | `local` | 1 | 12 | 25 | 9 | 10.5 | 13 `local` is recognized but has no effect due to [a bug](https://webkit.org/b/219324). 5-13 | 37 | 18 | 25 | 14 | 13 `local` is recognized but has no effect due to [a bug](https://webkit.org/b/219324). 4.2-13 If `-webkit-overflow-scrolling: touch` is set, then `local` has no effect. | 1.0 | | `multiple_backgrounds` | 1 | 12 | 3.6 | 9 | 10.5 | 1.3 | ≤37 | 18 | 4 | 11 | 3.2 | 1.0 | See also -------- * [Using multiple backgrounds](css_backgrounds_and_borders/using_multiple_backgrounds) css <frequency> <frequency> =========== The `<frequency>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) represents a frequency dimension, such as the pitch of a speaking voice. It is not currently used in any CSS properties. Syntax ------ The `<frequency>` data type consists of a [`<number>`](number) followed by one of the units listed below. As with all CSS dimensions, there is no space between the unit literal and the number. ### Units `Hz` Represents a frequency in hertz. Examples: `0Hz`, `1500Hz`, `10000Hz`. `kHz` Represents a frequency in kilohertz. Examples: `0kHz`, `1.5kHz`, `10kHz`. **Note:** Although the number `0` is always the same regardless of unit, the unit may not be omitted. In other words, `0` is invalid and does not represent `0Hz` or `0kHz`. Though the units are case-insensitive, it is good practice to use a capital "H" for `Hz` and `kHz`, as specified in the [SI](https://en.wikipedia.org/wiki/International_System_of_Units). Examples -------- Valid frequency values: ``` 12Hz Positive integer 4.3Hz Non-integer 14KhZ The unit is case-insensitive, though non-SI capitalization is not recommended. +0Hz Zero, with a leading + and a unit -0kHz Zero, with a leading - and a unit ``` Invalid frequency values: ``` 12.0 This is a <number>, not an <frequency>, because it is missing a unit. 7 Hz No space is allowed between the number and the unit. 0 Although unitless zero is an allowable <length>, it's an invalid <frequency>. ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # frequency](https://w3c.github.io/csswg-drafts/css-values/#frequency) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `frequency` | No | No | No See [bug 741643](https://bugzil.la/741643). | No | No | No | No | No | No See [bug 741643](https://bugzil.la/741643). | No | No | No | | `hz` | No | No | No | No | No | No | No | No | No | No | No | No | | `khz` | No | No | No | No | No | No | No | No | No | No | No | No | See also -------- * [`<frequency-percentage>`](frequency-percentage) * [CSS Values and Units](css_values_and_units) css border-image border-image ============ The `border-image` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property draws an image around a given element. It replaces the element's regular <border>. Try it ------ **Note:** You should specify a separate [`border-style`](border-style) in case the border image fails to load. Although the specification doesn't strictly require it, some browsers don't render the border image if [`border-style`](border-style) is `none` or [`border-width`](border-width) is `0`. Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`border-image-outset`](border-image-outset) * [`border-image-repeat`](border-image-repeat) * [`border-image-slice`](border-image-slice) * [`border-image-source`](border-image-source) * [`border-image-width`](border-image-width) Syntax ------ ``` /\* source | slice \*/ border-image: linear-gradient(red, blue) 27; /\* source | slice | repeat \*/ border-image: url("/images/border.png") 27 space; /\* source | slice | width \*/ border-image: linear-gradient(red, blue) 27 / 35px; /\* source | slice | width | outset | repeat \*/ border-image: url("/images/border.png") 27 23 / 50px 30px / 1rem round space; /\* Global values \*/ border-image: inherit; border-image: initial; border-image: revert; border-image: revert-layer; border-image: unset; ``` The `border-image` property may be specified with anywhere from one to five of the values listed below. **Note:** If the [computed value](computed_value) of [`border-image-source`](border-image-source) is `none`, or if the image cannot be displayed, the [`border-style`](border-style) will be displayed instead. ### Values `<'border-image-source'>` The source image. See [`border-image-source`](border-image-source). `<'border-image-slice'>` The dimensions for slicing the source image into regions. Up to four values may be specified. See [`border-image-slice`](border-image-slice). `<'border-image-width'>` The width of the border image. Up to four values may be specified. See [`border-image-width`](border-image-width). `<'border-image-outset'>` The distance of the border image from the element's outside edge. Up to four values may be specified. See [`border-image-outset`](border-image-outset). `<'border-image-repeat'>` Defines how the edge regions of the source image are adjusted to fit the dimensions of the border image. Up to two values may be specified. See [`border-image-repeat`](border-image-repeat). Accessibility concerns ---------------------- Assistive technology cannot parse border images. If the image contains information critical to understanding the page's overall purpose, it is better to describe it semantically in the document. * [MDN Understanding WCAG, Guideline 1.1 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.1_%e2%80%94_providing_text_alternatives_for_non-text_content) * [Understanding Success Criterion 1.1.1 | Understanding WCAG 2.0](https://www.w3.org/TR/2016/NOTE-UNDERSTANDING-WCAG20-20161007/text-equiv-all.html) Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`border-image-source`](border-image-source): `none` * [`border-image-slice`](border-image-slice): `100%` * [`border-image-width`](border-image-width): `1` * [`border-image-outset`](border-image-outset): `0` * [`border-image-repeat`](border-image-repeat): `stretch` | | Applies to | all elements, except internal table elements when [`border-collapse`](border-collapse) is `collapse`. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | Percentages | as each of the properties of the shorthand:* [`border-image-slice`](border-image-slice): refer to the size of the border image * [`border-image-width`](border-image-width): refer to the width or height of the border image area | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`border-image-outset`](border-image-outset): as specified, but with relative lengths converted into absolute lengths * [`border-image-repeat`](border-image-repeat): as specified * [`border-image-slice`](border-image-slice): one to four percentage(s) (as specified) or absolute length(s), plus the keyword `fill` if specified * [`border-image-source`](border-image-source): `none` or the image with its URI made absolute * [`border-image-width`](border-image-width): as specified, but with relative lengths converted into absolute lengths | | Animation type | discrete | Formal syntax ------------- ``` border-image = <'border-image-source'> [||](value_definition_syntax#double_bar) <'border-image-slice'> [[](value_definition_syntax#brackets) / <'border-image-width'> [|](value_definition_syntax#single_bar) / <'border-image-width'>[?](value_definition_syntax#question_mark) / <'border-image-outset'> []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) [||](value_definition_syntax#double_bar) <'border-image-repeat'> ``` Examples -------- ### Bitmap In this example, we will apply a diamond pattern to an element's borders. The source for the border image is a ".png" file of 81 by 81 pixels, with three diamonds going vertically and horizontally: #### HTML ``` <div id="bitmap"> This element is surrounded by a bitmap-based border image! </div> ``` #### CSS To match the size of a single diamond, we will use a value of 81 divided by 3, or `27`, for slicing the image into corner and edge regions. To center the border image on the edge of the element's background, we will make the outset values equal to half of the width values. Finally, a repeat value of `round` will make the border slices fit evenly, i.e., without clipping or gaps. ``` #bitmap { width: 200px; background-color: #ffa; border: 36px solid orange; margin: 30px; padding: 10px; border-image: url("border.png") /\* source \*/ 27 / /\* slice \*/ 36px 28px 18px 8px / /\* width \*/ 18px 14px 9px 4px /\* outset \*/ round; /\* repeat \*/ } ``` #### Result ### Gradient #### HTML ``` <div id="gradient"> This element is surrounded by a gradient-based border image! </div> ``` #### CSS ``` #gradient { width: 200px; border: 30px solid; border-image: repeating-linear-gradient(45deg, #f33, #3bf, #f33 30px) 60; padding: 20px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # the-border-image](https://w3c.github.io/csswg-drafts/css-backgrounds/#the-border-image) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-image` | 16 7 | 12 12 | 15 ["Small SVGs are incorrectly stretched, because percentages in [`border-image-slice`](https://developer.mozilla.org/docs/Web/CSS/border-image-slice) are computed to integers instead of floats ([bug 1284797](https://bugzil.la/1284797)).", "Until Firefox 47, SVGs without viewport were not sliced correctly ([bug 619500](https://bugzil.la/619500)).", "From Firefox 48 until Firefox 49, SVGs without viewport are displayed the same as SVGs with viewport, but if the slices are not exactly 50%, they are incorrectly stretched ([bug 1264809](https://bugzil.la/1264809)).", "Until Firefox 57, an issue persisted for SVGs without viewport when [e10s](https://wiki.mozilla.org/Electrolysis) was disabled ([bug 1290782](https://bugzil.la/1290782))."] 3.5 Before Firefox 15, an earlier version of the specification was implemented, prefixed. | 11 | 11 10.5-15 | 6 3 | 4.4 2 | 18 18 | 15 ["Small SVGs are incorrectly stretched, because percentages in [`border-image-slice`](https://developer.mozilla.org/docs/Web/CSS/border-image-slice) are computed to integers instead of floats ([bug 1284797](https://bugzil.la/1284797)).", "Until Firefox 47, SVGs without viewport were not sliced correctly ([bug 619500](https://bugzil.la/619500)).", "From Firefox 48 until Firefox 49, SVGs without viewport are displayed the same as SVGs with viewport, but if the slices are not exactly 50%, they are incorrectly stretched ([bug 1264809](https://bugzil.la/1264809)).", "Until Firefox 57, an issue persisted for SVGs without viewport when [e10s](https://wiki.mozilla.org/Electrolysis) was disabled ([bug 1290782](https://bugzil.la/1290782))."] 4 Before Firefox 15, an earlier version of the specification was implemented, prefixed. | 11 11-14 | 6 3.2 | 1.0 1.0 | | `fill` | 16 | 12 | 15 | 11 | 15 | 6 | ≤37 | 18 | 15 | 14 | 6 | 1.0 | | `gradient` | 7 | 12 | 29 | 11 | 15 | 4 | ≤37 | 18 | 29 | 14 | 3.2 | 1.0 | | `optional_border_image_slice` | 16 | 12 | 15 | 11 | 15 | 6 | ≤37 | 18 | 15 | 14 | 6 | 1.0 | See also -------- * [`border`](border) * [`outline`](outline) * [`box-shadow`](box-shadow) * [`background-image`](background-image) * [`url()`](url) function * Gradient functions: [`conic-gradient()`](gradient/conic-gradient), [`repeating-conic-gradient()`](gradient/repeating-conic-gradient), [`linear-gradient()`](gradient/linear-gradient), [`repeating-linear-gradient()`](gradient/repeating-linear-gradient), [`radial-gradient()`](gradient/radial-gradient), [`repeating-radial-gradient()`](gradient/repeating-radial-gradient)
programming_docs
css image-orientation image-orientation ================= The `image-orientation` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property specifies a layout-independent correction to the orientation of an image. Try it ------ Syntax ------ ``` /\* keyword values \*/ image-orientation: none; image-orientation: from-image; /\* Use EXIF data from the image \*/ /\* Global values \*/ image-orientation: inherit; image-orientation: initial; image-orientation: revert; image-orientation: revert-layer; image-orientation: unset; ``` ### Values `none` Does not apply any additional image rotation; the image is oriented as encoded or as other CSS property values dictate. `from-image` Default initial value. The [EXIF](https://en.wikipedia.org/wiki/EXIF) information contained in the image is used to rotate the image appropriately. Description ----------- This property is intended *only* to be used for the purpose of correcting the orientation of images which were shot with the camera rotated. It should *not* be used for arbitrary rotations. For any purpose other than correcting an image's orientation due to how it was shot or scanned, use a [`transform`](transform) property with the `rotate` keyword to specify rotation. This includes any user-directed changes to the orientation of the image, or changes required for printing in portrait versus landscape orientation. If used in conjunction with other CSS properties, such as a [`<transform-function>`](transform-function), any `image-orientation` rotation is applied before any other transformations. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `from-image` | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | an [`<angle>`](angle), rounded to the next quarter turn from `0deg` and normalized, that is moduloing the value by `1turn` | | Animation type | discrete | Formal syntax ------------- ``` image-orientation = from-image [|](value_definition_syntax#single_bar) none [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) [<angle>](angle) [||](value_definition_syntax#double_bar) flip []](value_definition_syntax#brackets) ``` Examples -------- ### Orienting image from image data The following image has been rotated through 180 degrees, and the `image-orientation` property is used to correct its orientation based on the EXIF data in the image. By changing the `image-orientation` to `none` you can see the effect of the property. #### CSS ``` #image { image-orientation: from-image; /\* Can be changed in the live sample \*/ } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Images Module Level 3 # the-image-orientation](https://w3c.github.io/csswg-drafts/css-images/#the-image-orientation) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `image-orientation` | 81 | 81 | 26 | No | 67 | 13.1 | 81 | 81 | 26 | No | 13.4 | 13.0 | | `flip_and_angle` | No | No | 26-63 | No | No | No | No | No | 26-63 | No | No | No | See also -------- * Other image-related CSS properties: [`object-fit`](object-fit), [`object-position`](object-position), [`image-orientation`](image-orientation), [`image-rendering`](image-rendering), [`image-resolution`](image-resolution). * [`transform`](transform) and [`rotate`](rotate) css aspect-ratio aspect-ratio ============ The `aspect-ratio` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets a **preferred aspect ratio** for the box, which will be used in the calculation of auto sizes and some other layout functions. Try it ------ Syntax ------ ``` aspect-ratio: 1 / 1; aspect-ratio: 1; /\* Global values \*/ aspect-ratio: inherit; aspect-ratio: initial; aspect-ratio: revert; aspect-ratio: revert-layer; aspect-ratio: unset; ``` ### Values `auto` [Replaced elements](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. [`<ratio>`](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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | all elements except inline boxes and internal ruby or table boxes | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` aspect-ratio = auto [||](value_definition_syntax#double_bar) <ratio> <ratio> = [<number [0,∞]>](number) [[](value_definition_syntax#brackets) / [<number [0,∞]>](number) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ``` Examples -------- ### Examples of values for aspect-ratio ``` aspect-ratio: 1 / 1; aspect-ratio: 16 / 9; aspect-ratio: 0.5; ``` Specifications -------------- | Specification | | --- | | [CSS Box Sizing Module Level 4 # aspect-ratio](https://w3c.github.io/csswg-drafts/css-sizing-4/#aspect-ratio) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `aspect-ratio` | 88 | 88 | 89 | No | 74 | 15 | 88 | 88 | 89 | 63 | 15 | 15.0 | See also -------- * [Image aspect-ratio: preventing jank](https://developer.mozilla.org/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/) css :nth-last-child() :nth-last-child() ================= The `:nth-last-child()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) matches elements based on their position among a group of siblings, counting from the end. Try it ------ Syntax ------ The `nth-last-child` pseudo-class is specified with a single argument, which represents the pattern for matching elements, counting from the end. ``` :nth-last-child( <nth> [ of <complex-selector-list> ]? ) ``` ### Keyword values `odd` Represents elements whose numeric position in a series of siblings is odd: 1, 3, 5, etc., counting from the end. `even` Represents elements whose numeric position in a series of siblings is even: 2, 4, 6, etc., counting from the end. ### Functional notation `<An+B>` Represents elements whose numeric position in a series of siblings matches the pattern `An+B`, for every positive integer or zero value of `n`, where: * `A` is an integer step size, * `B` is an integer offset, * `n` is all nonnegative integers, starting from 0. It can be read as the `An+B`-th element of a list. The index of the first element, counting from the end, is `1`. The `A` and `B` must both have [`<integer>`](integer) values. Examples -------- ### Example selectors `tr:nth-last-child(odd)` or `tr:nth-last-child(2n+1)` Represents the odd rows of an HTML table: 1, 3, 5, etc., counting from the end. `tr:nth-last-child(even)` or `tr:nth-last-child(2n)` Represents the even rows of an HTML table: 2, 4, 6, etc., counting from the end. `:nth-last-child(7)` Represents the seventh element, counting from the end. `:nth-last-child(5n)` Represents elements 5, 10, 15, etc., counting from the end. `:nth-last-child(3n+4)` Represents elements 4, 7, 10, 13, etc., counting from the end. `:nth-last-child(-n+3)` Represents the last three elements among a group of siblings. `p:nth-last-child(n)` or `p:nth-last-child(n+1)` Represents every `<p>` element among a group of siblings. This is the same as a simple `p` selector. (Since `n` starts at zero, while the last element begins at one, `n` and `n+1` will both select the same elements.) `p:nth-last-child(1)` or `p:nth-last-child(0n+1)` Represents every `<p>` that is the first element among a group of siblings, counting from the end. This is the same as the [`:last-child`](:last-child) selector. ### Table example #### HTML ``` <table> <tbody> <tr> <td>First line</td> </tr> <tr> <td>Second line</td> </tr> <tr> <td>Third line</td> </tr> <tr> <td>Fourth line</td> </tr> <tr> <td>Fifth line</td> </tr> </tbody> </table> ``` #### CSS ``` table { border: 1px solid blue; } /\* Selects the last three elements \*/ tr:nth-last-child(-n + 3) { background-color: pink; } /\* Selects every element starting from the second to last item \*/ tr:nth-last-child(n + 2) { color: blue; } /\* Select only the last second element \*/ tr:nth-last-child(2) { font-weight: 600; } ``` #### Result ### Quantity query A *quantity query* styles elements depending on how many of them there are. In this example, list items turn red when there are at least three of them in a given list. This is accomplished by combining the capabilities of the `nth-last-child` pseudo-class and the [general sibling combinator](general_sibling_combinator). #### HTML ``` <h4>A list of four items (styled):</h4> <ol> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> </ol> <h4>A list of two items (unstyled):</h4> <ol> <li>One</li> <li>Two</li> </ol> ``` #### CSS ``` /\* If there are at least three list items, style them all \*/ li:nth-last-child(n + 3), li:nth-last-child(3) ~ li { color: red; } ``` #### Result Specifications -------------- | Specification | | --- | | [Selectors Level 4 # nth-last-child-pseudo](https://w3c.github.io/csswg-drafts/selectors/#nth-last-child-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:nth-last-child` | 4 | 12 | 3.5 | 9 | 9 | 3.1 | ≤37 | 18 | 4 | 10.1 | 2 | 1.0 | | `no_parent_required` | 57 | 79 | 52 | No | 44 | No | 57 | 57 | 52 | 43 | No | 7.0 | | `of_syntax` | No See [bug 304163](https://crbug.com/304163). | No See [bug 304163](https://crbug.com/304163). | No See [bug 854148](https://bugzil.la/854148). | No | No See [bug 304163](https://crbug.com/304163). | 9 | No See [bug 304163](https://crbug.com/304163). | No See [bug 304163](https://crbug.com/304163). | No See [bug 854148](https://bugzil.la/854148). | No See [bug 304163](https://crbug.com/304163). | 9 | No See [bug 304163](https://crbug.com/304163). | See also -------- * [`:nth-child`](:nth-child), [`:nth-last-of-type`](:nth-last-of-type) * [Quantity Queries for CSS](https://alistapart.com/article/quantity-queries-for-css/) css opacity opacity ======= The `opacity` CSS property sets the opacity of an element. Opacity is the degree to which content behind an element is hidden, and is the opposite of transparency. Try it ------ Syntax ------ ``` opacity: 0.9; opacity: 90%; /\* Global values \*/ opacity: inherit; opacity: initial; opacity: revert; opacity: revert-layer; opacity: unset; ``` ### Values `<alpha-value>` A [`<number>`](number) in the range `0.0` to `1.0`, inclusive, or a [`<percentage>`](percentage) in the range `0%` to `100%`, inclusive, representing the opacity of the channel (that is, the value of its alpha channel). Any value outside the interval, though valid, is clamped to the nearest limit in the range. | Value | Meaning | | --- | --- | | `0` | The element is fully transparent (that is, invisible). | | Any [`<number>`](number) strictly between `0` and `1` | The element is translucent (that is, content behind the element can be seen). | | `1` (default value) | The element is fully opaque (visually solid). | Description ----------- `opacity` applies to the element as a whole, including its contents, even though the value is not inherited by child elements. Thus, the element and its children all have the same opacity relative to the element's background, even if they have different opacities relative to one another. Using `opacity` with a value other than `1` places the element in a new [stacking context](css_positioning/understanding_z_index/the_stacking_context). To change the opacity of a background only, use the [`background`](background) property with a [`color value`](color_value) that allows for an alpha channel. For example: ``` background: rgba(0, 0, 0, 0.4); ``` Accessibility concerns ---------------------- If text opacity is adjusted, it is important to ensure that the contrast ratio between the color of the text and the background the text is placed over is high enough that people experiencing low vision conditions will be able to read the content of the page. Color contrast ratio is determined by comparing the luminosity of the opacity-adjusted text and background color values. In order to meet current [Web Content Accessibility Guidelines (WCAG)](https://www.w3.org/WAI/standards-guidelines/wcag/), a ratio of 4.5:1 is required for text content and 3:1 for larger text such as headings. Large text is defined as 18.66px and [bold](font-weight) or larger, or 24px or larger. * [WebAIM: Color Contrast Checker](https://webaim.org/resources/contrastchecker/) * [MDN Understanding WCAG, Guideline 1.4 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background) * [Understanding Success Criterion 1.4.3 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html) Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `1` | | Applies to | all elements | | [Inherited](inheritance) | no | | Percentages | map to the range `[0,1]` | | [Computed value](computed_value) | The same as the specified value after clipping the [`<number>`](number) to the range [0.0, 1.0]. | | Animation type | by computed value type | Formal syntax ------------- ``` opacity = <alpha-value> <alpha-value> = [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Setting opacity The following example demonstrates how the `opacity` property changes the opacity of the entire element and content, thus making the text very hard to read. #### HTML ``` <div class="light">You can barely see this.</div> <div class="medium">This is easier to see.</div> <div class="heavy">This is very easy to see.</div> ``` #### CSS ``` div { background-color: yellow; font-weight: bold; font-size: 130%; } .light { opacity: 0.2; /\* Barely see the text over the background \*/ } .medium { opacity: 0.5; /\* See the text more clearly over the background \*/ } .heavy { opacity: 0.9; /\* See the text very clearly over the background \*/ } ``` #### Result ### Setting opacity on hover In the following example opacity is changed on hover, so the striped background image on the parent element shows through the image. #### HTML ``` <div class="wrapper"> <img src="//interactive-examples.mdn.mozilla.net/media/dino.svg" alt="MDN Dino" width="128" height="146" class="opacity" /> </div> ``` #### CSS ``` img.opacity { opacity: 1; } img.opacity:hover { opacity: 0.5; } .wrapper { width: 200px; height: 160px; background-color: #f03cc3; background-image: linear-gradient( 90deg, transparent 50%, rgba(255, 255, 255, 0.5) 50% ); background-size: 20px 20px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Color Module Level 4 # transparency](https://w3c.github.io/csswg-drafts/css-color/#transparency) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `opacity` | 1 | 12 | 1 1-3.5 | 9 | 9 | 2 1.1-2 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `percentages` | 78 | 79 | 70 | No | No | preview | 78 | 78 | No | No | No | 12.0 | css overflow-anchor overflow-anchor =============== The `overflow-anchor` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property provides a way to opt out of the browser's scroll anchoring behavior, which adjusts scroll position to minimize content shifts. Scroll anchoring behavior is enabled by default in any browser that supports it. Therefore, changing the value of this property is typically only required if you are experiencing problems with scroll anchoring in a document or part of a document and need to turn the behavior off. Try it ------ Syntax ------ ``` /\* Keyword values \*/ overflow-anchor: auto; overflow-anchor: none; /\* Global values \*/ overflow-anchor: inherit; overflow-anchor: initial; overflow-anchor: revert; overflow-anchor: revert-layer; overflow-anchor: unset; ``` ### Values `auto` The element becomes a potential anchor when adjusting scroll position. `none` The element won't be selected as a potential anchor. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` overflow-anchor = auto [|](value_definition_syntax#single_bar) none ``` Examples -------- ### Prevent scroll anchoring To prevent scroll anchoring in a document, use the `overflow-anchor` property. ``` \* { overflow-anchor: none; } ``` Specifications -------------- | Specification | | --- | | [CSS Scroll Anchoring Module Level 1 # exclusion-api](https://w3c.github.io/csswg-drafts/css-scroll-anchoring/#exclusion-api) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `overflow-anchor` | 56 | 79 | 66 | No | 43 | No | 56 | 56 | No | 43 | No | 6.0 | See also -------- * [Guide to scroll anchoring](overflow-anchor/guide_to_scroll_anchoring) css background-image background-image ================ The `background-image` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets one or more background images on an element. Try it ------ The background images are drawn on stacking context layers on top of each other. The first layer specified is drawn as if it is closest to the user. The [borders](border) of the element are then drawn on top of them, and the [`background-color`](background-color) is drawn beneath them. How the images are drawn relative to the box and its borders is defined by the [`background-clip`](background-clip) and [`background-origin`](background-origin) CSS properties. If a specified image cannot be drawn (for example, when the file denoted by the specified URI cannot be loaded), browsers handle it as they would a `none` value. **Note:** Even if the images are opaque and the color won't be displayed in normal circumstances, web developers should always specify a [`background-color`](background-color). If the images cannot be loaded—for instance, when the network is down—the background color will be used as a fallback. Syntax ------ Each background image is specified either as the keyword `none` or as an [`<image>`](image) value. To specify multiple background images, supply multiple values, separated by a comma: ``` background-image: linear-gradient( to bottom, rgba(255, 255, 0, 0.5), rgba(0, 0, 255, 0.5) ), url("catfront.png"); /\* Global values \*/ background-image: inherit; background-image: initial; background-image: revert; background-image: revert-layer; background-image: unset; ``` ### Values `none` Is a keyword denoting the absence of images. `<image>` Is an [`<image>`](image) denoting the image to display. There can be several of them, separated by commas, as [multiple backgrounds](css_backgrounds_and_borders/using_multiple_backgrounds) are supported. Accessibility concerns ---------------------- Browsers do not provide any special information on background images to assistive technology. This is important primarily for screen readers, as a screen reader will not announce its presence and therefore convey nothing to its users. If the image contains information critical to understanding the page's overall purpose, it is better to describe it semantically in the document. * [MDN Understanding WCAG, Guideline 1.1 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.1_%e2%80%94_providing_text_alternatives_for_non-text_content) * [Understanding Success Criterion 1.1.1 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/2016/NOTE-UNDERSTANDING-WCAG20-20161007/text-equiv-all.html) Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified, but with [`url()`](url) values made absolute | | Animation type | discrete | Formal syntax ------------- ``` background-image = <bg-image>[#](value_definition_syntax#hash_mark) <bg-image> = <image> [|](value_definition_syntax#single_bar) none <image> = <url> [|](value_definition_syntax#single_bar) [<gradient>](gradient) <url> = url( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) [|](value_definition_syntax#single_bar) src( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) ``` Examples -------- ### Layering background images Note that the star image is partially transparent and is layered over the cat image. #### HTML ``` <div> <p class="catsandstars">This paragraph is full of cats<br />and stars.</p> <p>This paragraph is not.</p> <p class="catsandstars">Here are more cats for you.<br />Look at them!</p> <p>And no more.</p> </div> ``` #### CSS ``` p { font-size: 1.5em; color: #fe7f88; background-image: none; background-color: transparent; } div { background-image: url("mdn\_logo\_only\_color.png"); } .catsandstars { background-image: url("startransparent.gif"), url("catfront.png"); background-color: transparent; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # background-image](https://w3c.github.io/csswg-drafts/css-backgrounds/#background-image) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `background-image` | 1 | 12 | 1 If the `browser.display.use_document_colors` user preference in `about:config` is set to `false`, background images will not be displayed. | 4 | 3.5 | 1 | ≤37 | 18 | 4 If the `browser.display.use_document_colors` user preference in `about:config` is set to `false`, background images will not be displayed. | 14 | 1 | 1.0 | | `element` | No | No | 4 | No | No | No | No | No | 4 | No | No | No | | `gradients` | 1 Some versions support only experimental gradients prefixed with `-webkit`. | 12 | 3.6 Some versions support only experimental gradients prefixed with `-moz`. | 10 | 11 Some versions support only experimental gradients prefixed with `-o`. | 4 Some versions support only experimental gradients prefixed with `-webkit`. | ≤37 Some versions support only experimental gradients prefixed with `-webkit`. | 18 Some versions support only experimental gradients prefixed with `-webkit`. | 4 Some versions support only experimental gradients prefixed with `-moz`. | 14 Some versions support only experimental gradients prefixed with `-webkit`. | 3.2 Some versions support only experimental gradients prefixed with `-webkit`. | 1.0 Some versions support only experimental gradients prefixed with `-webkit`. | | `image-rect` | No | No | 4 | No | No | No | No | No | 4 | No | No | No | | `image-set` | 21 | 79 | No See [bug 1107646](https://bugzil.la/1107646). | No | 15 | 6 Support for `url` images only and `x` is the only supported resolution unit. See [bug 160934](https://webkit.org/b/160934). preview | 4.4 | 25 | No See [bug 1107646](https://bugzil.la/1107646). | 14 | 6 Support for `url` images only and `x` is the only supported resolution unit. See [bug 160934](https://webkit.org/b/160934). | 1.5 | | `multiple_backgrounds` | 1 | 12 | 3.6 | 9 | 10.5 | 1.3 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | | `svg_images` | 8 | 12 | 4 | 9 | 9.5 | 5 Support of SVG in CSS background is incomplete. | ≤37 | 18 | 4 | 14 | 5 Support of SVG in CSS background is incomplete. | 1.0 | See also -------- * [Implementing image sprites in CSS](css_images/implementing_image_sprites_in_css) * [`<img>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img) * Image-related data types: [`<image>`](image), [`<gradient>`](gradient) * Image-related functions: + [`cross-fade()`](cross-fade) + [`element()`](element()) + [`image()`](image/image) + [`image-set()`](image/image-set) + [`linear-gradient()`](gradient/linear-gradient) + [`radial-gradient()`](gradient/radial-gradient) + [`conic-gradient()`](gradient/conic-gradient) + [`repeating-linear-gradient()`](gradient/repeating-linear-gradient) + [`repeating-radial-gradient()`](gradient/repeating-radial-gradient) + [`repeating-conic-gradient()`](gradient/repeating-conic-gradient) + [`paint()`](image/paint) + [`url()`](url)
programming_docs
css Initial value Initial value ============= The **initial value** of a [CSS](https://developer.mozilla.org/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](inheritance#inherited_properties), the initial value is used on the *root element only*, as long as no [specified value](specified_value) is supplied. * For [non-inherited properties](inheritance#non-inherited_properties), the initial value is used on *all elements*, as long as no [specified value](specified_value) is supplied. You can explicitly specify the initial value by using the [`initial`](initial) keyword. **Note:** The initial value should not be confused with the value specified by the browser's style sheet. Specifications -------------- | Specification | | --- | | [Cascading Style Sheets Level 2 Revision 2 (CSS 2.2) Specification # specified-value](https://www.w3.org/TR/CSS22/cascade.html#specified-value) | See also -------- * [`initial`](initial) * CSS key concepts: + [CSS syntax](syntax) + [At-rules](at-rule) + [Comments](comments) + [Specificity](specificity) + [Inheritance](inheritance) + [Box model](css_box_model/introduction_to_the_css_box_model) + [Layout modes](layout_mode) + [Visual formatting models](visual_formatting_model) + [Margin collapsing](css_box_model/mastering_margin_collapsing) + Values - [Computed values](computed_value) - [Used values](used_value) - [Actual values](actual_value) + [Value definition syntax](value_definition_syntax) + [Shorthand properties](shorthand_properties) + [Replaced elements](replaced_element) css CSS Animations CSS Animations ============== **CSS Animations** is a module of CSS that lets you animate the values of CSS properties over time, using keyframes. The behavior of these keyframe animations can be controlled by specifying their timing function, duration, their number of repetitions, and other attributes. Reference --------- ### Properties * [`animation`](animation) * [`animation-composition`](animation-composition) * [`animation-delay`](animation-delay) * [`animation-direction`](animation-direction) * [`animation-duration`](animation-duration) * [`animation-fill-mode`](animation-fill-mode) * [`animation-iteration-count`](animation-iteration-count) * [`animation-name`](animation-name) * [`animation-play-state`](animation-play-state) * [`animation-timeline`](animation-timeline) * [`animation-timing-function`](animation-timing-function) * [`scroll-timeline-name`](scroll-timeline-name) * [`scroll-timeline-axis`](scroll-timeline-axis) ### At-rules * [`@keyframes`](@keyframes) Guides ------ [Using CSS animations](css_animations/using_css_animations) Step-by-step tutorial about how to create animations using CSS. This article describes each relevant CSS property and at-rule and explains how they interact with each other. [CSS animations tips and tricks](css_animations/tips) Tips and tricks to help you get the most out of CSS animations. Currently offers a technique for replaying an animation which has already run through to completion, which the API doesn't support inherently. Specifications -------------- | Specification | | --- | | [CSS Animations Level 1 # animation](https://w3c.github.io/csswg-drafts/css-animations/#animation) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `CSS_Animations` | 43 3 | 12 12 | 49 16 5 | 10 | 30 15 12.1-15 12-15 | 9 4 | 43 2 The [`animation-fill-mode`](https://developer.mozilla.org/docs/Web/CSS/animation-fill-mode) property is not supported in Android browsers below 2.3. | 43 18 | 49 16 5 | 30 14 12.1-14 12-14 | 9 3.2 | 4.0 1.0 | See also -------- * Related to CSS Animations, [CSS Transitions](css_transitions) can trigger animations based on user actions. css overscroll-behavior overscroll-behavior =================== The `overscroll-behavior` CSS property sets what a browser does when reaching the boundary of a scrolling area. It's a shorthand for [`overscroll-behavior-x`](overscroll-behavior-x) and [`overscroll-behavior-y`](overscroll-behavior-y). Try it ------ 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 on top of a page of scrolling content, once the dialog box's scroll boundary is reached, the underlying page will then start to scroll — this is called **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 only applies to [scroll containers](https://developer.mozilla.org/en-US/docs/Glossary/Scroll_container). In particular, since an [`<iframe>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe) is not a scroll container, this property cannot be used to stop scroll chaining for iframes. Syntax ------ ``` /\* 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 is observed inside the element this value is set on (e.g. "bounce" effects or refreshes), but no scroll chaining occurs to neighboring scrolling areas, e.g. underlying elements will not scroll. `none` No scroll chaining occurs to neighboring scrolling areas, and default scroll overflow behavior is prevented. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | non-replaced block-level elements and non-replaced inline-block elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`overscroll-behavior-x`](overscroll-behavior-x): as specified * [`overscroll-behavior-y`](overscroll-behavior-y): as specified | | Animation type | discrete | Formal syntax ------------- ``` overscroll-behavior = [[](value_definition_syntax#brackets) contain [|](value_definition_syntax#single_bar) none [|](value_definition_syntax#single_bar) auto []](value_definition_syntax#brackets)[{1,2}](value_definition_syntax#curly_braces) ``` 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: ``` .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 [`<html>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html) element: ``` html { margin: 0; overscroll-behavior: none; } ``` Specifications -------------- | Specification | | --- | | [CSS Overscroll Behavior Module Level 1 # overscroll-behavior-properties](https://w3c.github.io/csswg-drafts/css-overscroll/#overscroll-behavior-properties) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `overscroll-behavior` | 63 | 18 Currently the `none` value incorrectly behaves as `contain` (allowing for the elastic bounce effect). | 59 | No | 50 | 16 | 63 | 63 | 59 | 46 | 16 | 8.0 | See also -------- * [Take control of your scroll: customizing pull-to-refresh and overflow effects](https://developer.chrome.com/blog/overscroll-behavior/#demo) css ::target-text ::target-text ============= **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `::target-text` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-element](pseudo-elements) represents the text that has been scrolled to if the browser supports [text fragments](https://developer.mozilla.org/en-US/docs/Web/Text_fragments). It allows authors to choose how to highlight that section of text. ``` ::target-text { background-color: pink; } ``` Syntax ------ ``` ::target-text ``` Examples -------- ### Highlighting text fragments ``` ::target-text { background-color: rebeccapurple; color: white; } ``` To see this CSS in action follow the link to [scroll-to-text demo](https://mdn.github.io/css-examples/target-text/index.html#:~:text=From%20the%20foregoing%20remarks%20we%20may%20gather%20an%20idea%20of%20the%20importance). Specifications -------------- | Specification | | --- | | [CSS Pseudo-Elements Module Level 4 # selectordef-target-text](https://w3c.github.io/csswg-drafts/css-pseudo/#selectordef-target-text) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `::target-text` | 89 | 89 | No | No | 75 | No | 89 | 89 | No | 63 | No | 15.0 | See also -------- * [Text fragments](https://developer.mozilla.org/en-US/docs/Web/Text_fragments) css mask-origin mask-origin =========== The `mask-origin` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the origin of a mask. ``` /\* Keyword values \*/ mask-origin: content-box; mask-origin: padding-box; mask-origin: border-box; mask-origin: margin-box; mask-origin: fill-box; mask-origin: stroke-box; mask-origin: view-box; /\* Multiple values \*/ mask-origin: padding-box, content-box; mask-origin: view-box, fill-box, border-box; /\* Non-standard keyword values \*/ -webkit-mask-origin: content; -webkit-mask-origin: padding; -webkit-mask-origin: border; /\* Global values \*/ mask-origin: inherit; mask-origin: initial; mask-origin: revert; mask-origin: revert-layer; mask-origin: unset; ``` For elements rendered as a single box, this property specifies the mask positioning area. In other words, this property specifies the origin position of an image specified by the [`mask-image`](mask-image) CSS property. For elements rendered as multiple boxes, such as inline boxes on several lines or boxes on several pages, it specifies which boxes [`box-decoration-break`](box-decoration-break) operates upon to determine the mask positioning area. Syntax ------ One or more of the keyword values listed below, separated by commas. ### Values `content-box` The position is relative to the content box. `padding-box` The position is relative to the padding box. For single boxes `0 0` is the upper left corner of the padding edge, `100% 100%` is the lower right corner. `border-box` The position is relative to the border box. `margin-box` The position is relative to the margin box. `fill-box` Experimental The position is relative to the object bounding box. `stroke-box` Experimental The position is relative to the stroke bounding box. `view-box` Experimental Uses the nearest SVG viewport as reference box. If a `[viewBox](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox)` attribute is specified for the element creating the SVG viewport, the reference box is positioned at the origin of the coordinate system established by the `viewBox` attribute and the dimension of the reference box is set to the width and height values of the `viewBox` attribute. `content` Non-standard Same as `content-box`. `padding` Non-standard Same as `padding-box`. `border` Non-standard Same as `border-box`. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `border-box` | | Applies to | all elements; In SVG, it applies to container elements excluding the [`<defs>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs) element and all graphics elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` mask-origin = <geometry-box>[#](value_definition_syntax#hash_mark) <geometry-box> = <shape-box> [|](value_definition_syntax#single_bar) fill-box [|](value_definition_syntax#single_bar) stroke-box [|](value_definition_syntax#single_bar) view-box <shape-box> = <box> [|](value_definition_syntax#single_bar) margin-box <box> = border-box [|](value_definition_syntax#single_bar) padding-box [|](value_definition_syntax#single_bar) content-box ``` Examples -------- ### Setting mask origin to border-box Try some of the other possible values by updating the CSS in the box below. Specifications -------------- | Specification | | --- | | [CSS Masking Module Level 1 # the-mask-origin](https://drafts.fxtf.org/css-masking/#the-mask-origin) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `mask-origin` | 1 The `margin-box` value is unsupported. | 79 The `margin-box` value is unsupported. | 53 | No | 15 The `margin-box` value is unsupported. | 15.4 4 The `margin-box` value is unsupported. | 2 The `margin-box` value is unsupported. | 18 The `margin-box` value is unsupported. | 53 | 14 The `margin-box` value is unsupported. | 15.4 3.2 The `margin-box` value is unsupported. | 1.0 The `margin-box` value is unsupported. | | `fill-box` | No | No | No | No | No | No See [bug 137293](https://webkit.org/b/137293). | No | No | No | No | No See [bug 137293](https://webkit.org/b/137293). | No | | `non_standard_values` | 1 | 79 | No | No | 15 | 4 preview | 2 | 18 | No | 14 | 3.2 | 1.0 | | `stroke-box` | No | No | No | No | No | No See [bug 137293](https://webkit.org/b/137293). | No | No | No | No | No See [bug 137293](https://webkit.org/b/137293). | No | | `view-box` | No | No | No | No | No | No See [bug 137293](https://webkit.org/b/137293). | No | No | No | No | No See [bug 137293](https://webkit.org/b/137293). | No | See also -------- * [Clipping and Masking in CSS](https://css-tricks.com/clipping-masking-css/) css animation-direction animation-direction =================== The `animation-direction` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets whether an animation should play forward, backward, or alternate back and forth between playing the sequence forward and backward. Try it ------ It is often convenient to use the shorthand property [`animation`](animation) to set all animation properties at once. Syntax ------ ``` /\* Single animation \*/ animation-direction: normal; animation-direction: reverse; animation-direction: alternate; animation-direction: alternate-reverse; /\* Multiple animations \*/ animation-direction: normal, reverse; animation-direction: alternate, reverse, normal; /\* Global values \*/ animation-direction: inherit; animation-direction: initial; animation-direction: revert; animation-direction: revert-layer; animation-direction: unset; ``` ### Values `normal` The animation plays *forwards* each cycle. In other words, each time the animation cycles, the animation will reset to the beginning state and start over again. This is the default value. `reverse` The animation plays *backwards* each cycle. In other words, each time the animation cycles, the animation will reset to the end state and start over again. Animation steps are performed backwards, and timing functions are also reversed. For example, an `ease-in` timing function becomes `ease-out`. `alternate` The animation reverses direction each cycle, with the first iteration being played *forwards*. The count to determine if a cycle is even or odd starts at one. `alternate-reverse` The animation reverses direction each cycle, with the first iteration being played *backwards*. The count to determine if a cycle is even or odd starts at one. **Note:** When you specify multiple comma-separated values on an `animation-*` property, they are applied to the animations in the order in which the [`animation-name`](animation-name)s appear. For situations where the number of animations and `animation-*` property values do not match, see [Setting multiple animation property values](css_animations/using_css_animations#setting_multiple_animation_property_values). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | all elements, [`::before`](::before) and [`::after`](::after) <pseudo-elements> | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | Not animatable | Formal syntax ------------- ``` animation-direction = <single-animation-direction>[#](value_definition_syntax#hash_mark) <single-animation-direction> = normal [|](value_definition_syntax#single_bar) reverse [|](value_definition_syntax#single_bar) alternate [|](value_definition_syntax#single_bar) alternate-reverse ``` Examples -------- ### Reversing the animation direction #### HTML ``` <div class="box"></div> ``` #### CSS ``` .box { background-color: rebeccapurple; border-radius: 10px; width: 100px; height: 100px; } .box:hover { animation-name: rotate; animation-duration: 0.7s; animation-direction: reverse; } @keyframes rotate { 0% { transform: rotate(0); } 100% { transform: rotate(360deg); } } ``` #### Result See [CSS animations](css_animations/using_css_animations) for examples. Specifications -------------- | Specification | | --- | | [CSS Animations Level 1 # animation-direction](https://w3c.github.io/csswg-drafts/css-animations/#animation-direction) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `animation-direction` | 43 3 | 12 12 | 49 16 5 | 10 | 30 15 12.1-15 12-15 | 9 4 | 43 ≤37 | 43 18 | 49 16 5 | 30 14 12.1-14 12-14 | 9 3.2 | 4.0 1.0 | | `alternate-reverse` | 19 | 12 | 16 | 10 | 12.1 | 6 | 4.4 | 25 | 16 | 12.1 | 6 | 1.5 | | `reverse` | 19 | 12 | 16 | 10 | 12.1 | 6 | 4.4 | 25 | 16 | 12.1 | 6 | 1.5 | See also -------- * [Using CSS animations](css_animations/using_css_animations) * JavaScript [`AnimationEvent`](https://developer.mozilla.org/en-US/docs/Web/API/AnimationEvent) API * Other related animation properties: [`animation`](animation), [`animation-composition`](animation-composition), [`animation-delay`](animation-delay), [`animation-duration`](animation-duration), [`animation-fill-mode`](animation-fill-mode), [`animation-iteration-count`](animation-iteration-count), [`animation-name`](animation-name), [`animation-play-state`](animation-play-state), [`animation-timeline`](animation-timeline), [`animation-timing-function`](animation-timing-function)
programming_docs
css CSS Grid Layout CSS Grid Layout =============== **CSS Grid Layout** excels at dividing a page into major regions or defining the relationship in terms of size, position, and layer, between parts of a control built from HTML primitives. Like tables, grid layout enables an author to align elements into columns and rows. However, many more layouts are either possible or easier with CSS grid than they were with tables. For example, a grid container's child elements could position themselves so they actually overlap and layer, similar to CSS positioned elements. Basic example ------------- The example below shows a three-column track grid with new rows created at a minimum of 100 pixels and a maximum of auto. Items have been placed onto the grid using line-based placement. ### HTML ``` <div class="wrapper"> <div class="one">One</div> <div class="two">Two</div> <div class="three">Three</div> <div class="four">Four</div> <div class="five">Five</div> <div class="six">Six</div> </div> ``` ### CSS ``` .wrapper { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; grid-auto-rows: minmax(100px, auto); } .one { grid-column: 1 / 3; grid-row: 1; } .two { grid-column: 2 / 4; grid-row: 1 / 3; } .three { grid-column: 1; grid-row: 2 / 5; } .four { grid-column: 3; grid-row: 3; } .five { grid-column: 2; grid-row: 4; } .six { grid-column: 3; grid-row: 4; } ``` Reference --------- ### Properties * [`display`](display) * [`grid-template-columns`](grid-template-columns) * [`grid-template-rows`](grid-template-rows) * [`grid-template-areas`](grid-template-areas) * [`grid-template`](grid-template) * [`grid-auto-columns`](grid-auto-columns) * [`grid-auto-rows`](grid-auto-rows) * [`grid-auto-flow`](grid-auto-flow) * [`grid`](grid) * [`grid-row-start`](grid-row-start) * [`grid-column-start`](grid-column-start) * [`grid-row-end`](grid-row-end) * [`grid-column-end`](grid-column-end) * [`grid-row`](grid-row) * [`grid-column`](grid-column) * [`grid-area`](grid-area) * [`row-gap`](row-gap) * [`column-gap`](column-gap) * [`gap`](gap) * [`masonry-auto-flow`](masonry-auto-flow) Experimental * [`align-tracks`](align-tracks) Experimental * [`justify-tracks`](justify-tracks) Experimental ### Functions * [`repeat()`](repeat) * [`minmax()`](minmax) * [`fit-content()`](fit-content_function) ### Data types * [`<flex>`](flex_value) Guides ------ * [Basic concepts of grid layout](css_grid_layout/basic_concepts_of_grid_layout) * [Relationship of grid layout to other layout methods](css_grid_layout/relationship_of_grid_layout) * [Grid template areas](css_grid_layout/grid_template_areas) * [Grid layout using line-based placement](css_grid_layout/line-based_placement_with_css_grid) * [Grid layout using named grid lines](css_grid_layout/layout_using_named_grid_lines) * [Auto-placement in grid layout](css_grid_layout/auto-placement_in_css_grid_layout) * [Box alignment in grid layout](css_grid_layout/box_alignment_in_css_grid_layout) * [Grids, logical values, and writing modes](css_grid_layout/css_grid_logical_values_and_writing_modes) * [Grid layout and accessibility](css_grid_layout/css_grid_layout_and_accessibility) * [Realizing common layouts using grids](css_grid_layout/realizing_common_layouts_using_css_grid_layout) * [Subgrid](css_grid_layout/subgrid) * [Masonry layout](css_grid_layout/masonry_layout) Experimental Specifications -------------- | Specification | | --- | | [CSS Grid Layout Module Level 2](https://drafts.csswg.org/css-grid/) | See also -------- * Glossary terms: + [Grid](https://developer.mozilla.org/en-US/docs/Glossary/Grid) + [Grid lines](https://developer.mozilla.org/en-US/docs/Glossary/Grid_Lines) + [Grid tracks](https://developer.mozilla.org/en-US/docs/Glossary/Grid_Tracks) + [Grid cell](https://developer.mozilla.org/en-US/docs/Glossary/Grid_Cell) + [Grid area](https://developer.mozilla.org/en-US/docs/Glossary/Grid_Areas) + [Gutters](https://developer.mozilla.org/en-US/docs/Glossary/Gutters) + [Grid axis](https://developer.mozilla.org/en-US/docs/Glossary/Grid_Axis) + [Grid row](https://developer.mozilla.org/en-US/docs/Glossary/Grid_Row) + [Grid column](https://developer.mozilla.org/en-US/docs/Glossary/Grid_Column) * [Grid by Example](https://gridbyexample.com/) - A collection of usage examples and video tutorials * [CSS Grid Reference - Codrops](https://tympanus.net/codrops/css_reference/grid/) * [CSS Grid Inspector - Firefox DevTools](https://firefox-source-docs.mozilla.org/devtools-user/page_inspector/how_to/examine_grid_layouts/index.html) * [CSS Grid Playground](https://mozilladevelopers.github.io/playground/css-grid/) * [CSS Grid Garden](https://cssgridgarden.com) - A game for learning CSS grid css mask-image mask-image ========== The `mask-image` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the image that is used as mask layer for an element. By default this means the alpha channel of the mask image will be multiplied with the alpha channel of the element. This can be controlled with the [`mask-mode`](mask-mode) property. ``` /\* Keyword value \*/ mask-image: none; /\* <mask-source> value \*/ mask-image: url(masks.svg#mask1); /\* <image> values \*/ mask-image: linear-gradient(rgba(0, 0, 0, 1), transparent); mask-image: image(url(mask.png), skyblue); /\* Multiple values \*/ mask-image: image(url(mask.png), skyblue), linear-gradient(rgba(0, 0, 0, 1), transparent); /\* Global values \*/ mask-image: inherit; mask-image: initial; mask-image: revert; mask-image: revert-layer; mask-image: unset; ``` Syntax ------ ### Values `none` This keyword is interpreted as an opaque white image layer. `<mask-source>` A [`url()`](url) reference to a [`<mask>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/mask) or to a CSS image. [`<image>`](image) An image value used as mask image layer. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements; In SVG, it applies to container elements excluding the [`<defs>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs) element and all graphics elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified, but with [`url()`](url) values made absolute | | Animation type | discrete | Formal syntax ------------- ``` mask-image = <mask-reference>[#](value_definition_syntax#hash_mark) <mask-reference> = none [|](value_definition_syntax#single_bar) <image> [|](value_definition_syntax#single_bar) <mask-source> <image> = <url> [|](value_definition_syntax#single_bar) [<gradient>](gradient) <mask-source> = <url> <url> = url( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) [|](value_definition_syntax#single_bar) src( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) ``` Examples -------- ### Setting a mask image with a URL Specifications -------------- | Specification | | --- | | [CSS Masking Module Level 1 # the-mask-image](https://drafts.fxtf.org/css-masking/#the-mask-image) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `mask-image` | 1 From version 8, Chrome added support for gradient values. Initially, Chrome supported only `-webkit-` prefixed values for gradients (such as `-webkit-linear-gradient()`). Later, support for unprefixed values was added. | 79 16-79 | 53 | No | 15 | 15.4 4 Initially, Safari supported only `-webkit-` prefixed values for gradients (such as `-webkit-linear-gradient()`). Later, support for unprefixed values was added. | 2 Initially, Android supported only `-webkit-` prefixed values for gradients (such as `-webkit-linear-gradient()`). Later, support for unprefixed values was added. | 18 From version 8, Chrome added support for gradient values. Initially, Chrome supported only `-webkit-` prefixed values for gradients (such as `-webkit-linear-gradient()`). Later, support for unprefixed values was added. | 53 | 14 | 15.4 3.2 Initially, Safari supported only `-webkit-` prefixed values for gradients (such as `-webkit-linear-gradient()`). Later, support for unprefixed values was added. | 1.0 | | `multiple_mask_images` | 1 | 18 | 53 | No | 15 | 4 | ≤37 | 18 | 53 | 14 | 3.2 | 1.0 | | `svg_masks` | 8 | 18 | 53 | No | 15 | 4 | ≤37 | 18 | 53 | 14 | 3.2 | 1.0 | See also -------- * [Clipping and Masking in CSS](https://css-tricks.com/clipping-masking-css/) * [Apply effects to images with CSS's mask-image property](https://web.dev/css-masking/) css overflow-block overflow-block ============== The `overflow-block` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets what shows when content overflows the block start and block end edges of a box. This may be nothing, a scroll bar, or the overflow content. **Note:** The `overflow-block` property maps to [`overflow-y`](overflow-y) or [`overflow-x`](overflow-x) depending on the writing mode of the document. Syntax ------ ``` /\* Keyword values \*/ overflow-block: visible; overflow-block: hidden; overflow-block: scroll; overflow-block: auto; /\* Global values \*/ overflow-block: inherit; overflow-block: initial; overflow-block: revert; overflow-block: revert-layer; overflow-block: unset; ``` The `overflow-block` property is specified as a single keyword chosen from the list of values below. ### Values `visible` Content is not clipped and may be rendered outside the padding box's block start and block end edges. `hidden` Content is clipped if necessary to fit the block dimension in the padding box. No scrollbars are provided. `scroll` Content is clipped if necessary to fit in the block dimension in the padding box. Browsers display scrollbars whether or not any content is actually clipped. (This prevents scrollbars from appearing or disappearing when the content changes.) Printers may still print overflowing content. `auto` Depends on the user agent. If content fits inside the padding box, it looks the same as `visible`, but still establishes a new block-formatting context. Desktop browsers provide scrollbars if content overflows. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | Block-containers, flex containers, and grid containers | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified, except with `visible`/`clip` computing to `auto`/`hidden` respectively if one of [`overflow-x`](overflow-x) or [`overflow-y`](overflow-y) is neither `visible` nor clip | | Animation type | discrete | Formal syntax ------------- ``` overflow-block = <'overflow'> ``` Examples -------- ### HTML ``` <ul> <li> <code>overflow-block:hidden</code> — hides the text outside the box <div id="div1"> 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> </li> <li> <code>overflow-block:scroll</code> — always adds a scrollbar <div id="div2"> 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> </li> <li> <code>overflow-block:visible</code> — displays the text outside the box if needed <div id="div3"> 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> </li> <li> <code>overflow-block:auto</code> — on most browser, equivalent to <code>scroll</code> <div id="div4"> 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> </li> </ul> ``` ### CSS ``` #div1, #div2, #div3, #div4 { border: 1px solid black; width: 250px; height: 100px; } #div1 { overflow-block: hidden; margin-bottom: 120px; } #div2 { overflow-block: scroll; margin-bottom: 120px; } #div3 { overflow-block: visible; margin-bottom: 120px; } #div4 { overflow-block: auto; margin-bottom: 120px; } ``` ### Result Specifications -------------- | Specification | | --- | | [CSS Overflow Module Level 3 # logical](https://w3c.github.io/csswg-drafts/css-overflow/#logical) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `overflow-block` | No | No | 69 | No | No | No | No | No | No | No | No | No | See also -------- * Related CSS properties: [`text-overflow`](text-overflow), [`white-space`](white-space), [`overflow`](overflow), [`overflow-inline`](overflow-inline), [`overflow-x`](overflow-x), [`overflow-y`](overflow-y), [`clip`](clip), [`display`](display) * [CSS Logical Properties](css_logical_properties) * [Writing Modes](css_writing_modes) css backface-visibility backface-visibility =================== The `backface-visibility` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets whether the back face of an element is visible when turned towards the user. Try it ------ An element's back face is a mirror image of its front face. Though invisible in 2D, the back face can become visible when a transformation causes the element to be rotated in 3D space. (This property has no effect on 2D transforms, which have no perspective.) Syntax ------ ``` /\* Keyword values \*/ backface-visibility: visible; backface-visibility: hidden; /\* Global values \*/ backface-visibility: inherit; backface-visibility: initial; backface-visibility: revert; backface-visibility: revert-layer; backface-visibility: unset; ``` The `backface-visibility` property is specified as one of the keywords listed below. ### Values `visible` The back face is visible when turned towards the user. `hidden` The back face is hidden, effectively making the element invisible when turned away from the user. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `visible` | | Applies to | transformable elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` backface-visibility = visible [|](value_definition_syntax#single_bar) hidden ``` Examples -------- ### Cube with transparent and opaque faces This example shows a cube with transparent faces, and one with opaque faces. #### HTML ``` <table> <tr> <th><code>backface-visibility: visible;</code></th> <th><code>backface-visibility: hidden;</code></th> </tr> <tr> <td> <div class="container"> <div class="cube showbf"> <div class="face front">1</div> <div class="face back">2</div> <div class="face right">3</div> <div class="face left">4</div> <div class="face top">5</div> <div class="face bottom">6</div> </div> </div> <p> Since all faces are partially transparent, the back faces (2, 4, 5) are visible through the front faces (1, 3, 6). </p> </td> <td> <div class="container"> <div class="cube hidebf"> <div class="face front">1</div> <div class="face back">2</div> <div class="face right">3</div> <div class="face left">4</div> <div class="face top">5</div> <div class="face bottom">6</div> </div> </div> <p>The three back faces (2, 4, 5) are hidden.</p> </td> </tr> </table> ``` #### CSS ``` /\* Classes that will show or hide the three back faces of the "cube" \*/ .showbf div { backface-visibility: visible; } .hidebf div { backface-visibility: hidden; } /\* Define the container div, the cube div, and a generic face \*/ .container { width: 150px; height: 150px; margin: 75px 0 0 75px; border: none; } .cube { width: 100%; height: 100%; perspective: 550px; perspective-origin: 150% 150%; transform-style: preserve-3d; } .face { display: block; position: absolute; width: 100px; height: 100px; border: none; line-height: 100px; font-family: sans-serif; font-size: 60px; color: white; text-align: center; } /\* Define each face based on direction \*/ .front { background: rgba(0, 0, 0, 0.3); transform: translateZ(50px); } .back { background: rgba(0, 255, 0, 1); color: black; transform: rotateY(180deg) translateZ(50px); } .right { background: rgba(196, 0, 0, 0.7); transform: rotateY(90deg) translateZ(50px); } .left { background: rgba(0, 0, 196, 0.7); transform: rotateY(-90deg) translateZ(50px); } .top { background: rgba(196, 196, 0, 0.7); transform: rotateX(90deg) translateZ(50px); } .bottom { background: rgba(196, 0, 196, 0.7); transform: rotateX(-90deg) translateZ(50px); } /\* Make the table a little nicer \*/ th, p, td { background-color: #eeeeee; margin: 0px; padding: 6px; font-family: sans-serif; text-align: left; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Transforms Module Level 2 # backface-visibility-property](https://w3c.github.io/csswg-drafts/css-transforms-2/#backface-visibility-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `backface-visibility` | 36 12 | 12 12 | 49 16 10 | 10 | 23 15 | 15.4 5.1 | 37 3 | 36 18 | 49 16 10 | 24 14 | 15.4 5 | 3.0 1.0 | See also -------- * [Using CSS transforms](css_transforms/using_css_transforms) css shape-image-threshold shape-image-threshold ===================== The `shape-image-threshold` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the alpha channel threshold used to extract the shape using an image as the value for [`shape-outside`](shape-outside). Try it ------ Any pixels whose alpha component's value is greater than the threshold are considered to be part of the shape for the purposes of determining its boundaries. For example, a value of `0.5` means that the shape will enclose all the pixels that are more than 50% opaque. Syntax ------ ``` /\* <number> value \*/ shape-image-threshold: 0.7; /\* Global values \*/ shape-image-threshold: inherit; shape-image-threshold: initial; shape-image-threshold: revert; shape-image-threshold: revert-layer; shape-image-threshold: unset; ``` ### Values [`<alpha-value>`](alpha-value) Sets the threshold used for extracting a shape from an image. The shape is defined by the pixels whose alpha value is greater than the threshold. Values outside the range 0.0 (fully transparent) to 1.0 (fully opaque) are clamped to this range. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0.0` | | Applies to | floats | | [Inherited](inheritance) | no | | [Computed value](computed_value) | The same as the specified value after clipping the [`<number>`](number) to the range [0.0, 1.0]. | | Animation type | a [number](number#interpolation) | Formal syntax ------------- ``` shape-image-threshold = <alpha-value> <alpha-value> = [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Aligning text to a gradient This example creates a [`<div>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div) block with a gradient background image. The gradient is established as a CSS shape using `shape-outside`, so that pixels within the gradient which are at least 20% opaque (that is, those pixels with an alpha component greater than 0.2) are considered part of the shape. #### HTML ``` <div id="gradient-shape"></div> <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vel at commodi voluptates enim, distinctio officia. Saepe optio accusamus doloribus sint facilis itaque ab nulla, dolor molestiae assumenda cum sit placeat adipisci, libero quae nihil porro debitis laboriosam inventore animi impedit nostrum nesciunt quisquam expedita! Dolores consectetur iure atque a mollitia dicta repudiandae illum exercitationem aliquam repellendus ipsum porro modi, id nemo eligendi, architecto ratione quibusdam iusto nisi soluta? Totam inventore ea eum sed velit et eligendi suscipit accusamus iusto dolore, at provident eius alias maxime pariatur non deleniti ipsum sequi rem eveniet laboriosam magni expedita? </p> ``` #### CSS ``` #gradient-shape { width: 150px; height: 150px; float: left; background-image: linear-gradient(30deg, black, transparent 80%, transparent); shape-outside: linear-gradient(30deg, black, transparent 80%, transparent); shape-image-threshold: 0.2; } ``` The shape is established here using [`background-image`](background-image) with a linear gradient rather than an image file. The same gradient is also used as the image from which the shape is derived for establishing the float area, using the [`shape-outside`](shape-outside) property. The 20% opacity threshold for treating gradient pixels as part of the shape is then established using `shape-image-threshold` with a value of `0.2`. #### Result Specifications -------------- | Specification | | --- | | [CSS Shapes Module Level 1 # shape-image-threshold-property](https://w3c.github.io/csswg-drafts/css-shapes/#shape-image-threshold-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `shape-image-threshold` | 37 | 79 | 62 | No | 24 | 10.1 | 37 | 37 | 62 | 24 | 10.3 | 3.0 | | `percentages` | 78 | 79 | 70 | No | No | No | 78 | 78 | No | No | No | 12.0 | See also -------- * [CSS Shapes](css_shapes) * [Overview of CSS Shapes](css_shapes/overview_of_css_shapes) * [`<basic-shape>`](basic-shape) * [`shape-outside`](shape-outside) * [`shape-margin`](shape-margin)
programming_docs
css clamp() clamp() ======= The `clamp()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](css_functions) clamps a middle value within a range of values between a defined minimum bound and a maximum bound. The function takes three parameters: a minimum value, a preferred value, and a maximum allowed value. Try it ------ Note that using `clamp()` for font sizes, as in these examples, allows you to set a font-size that grows with the size of the viewport, but doesn't go below a minimum font-size or above a maximum font-size. It has the same effect as the code in [Fluid Typography](https://css-tricks.com/snippets/css/fluid-typography/) but in one line, and without the use of media queries. Syntax ------ ``` /\* Static values \*/ width: clamp(200px, 40%, 400px); width: clamp(20rem, 30vw, 70rem); width: clamp(10vw, 20em, 100vw); /\* Calculated values \*/ width: clamp(min(10vw, 20rem), 300px, max(90vw, 55rem)); width: clamp(100px, calc(30% / 2rem + 10px), 900px); ``` ### Parameters The `clamp(min, val, max)` function accepts three comma-separated expressions as its parameters. `min` The minimum value is the smallest (most negative) value. This is the lower bound in the range of allowed values. If the preferred value is less than this value, the minimum value will be used. `val` The preferred value is the expression whose value will be used as long as the result is between the minimum and maximum values. `max` The maximum value is the largest (most positive) expression value to which the value of the property will be assigned if the preferred value is greater than this upper bound. The expressions can be math functions (see [`calc()`](calc) for more information), literal values, other expressions that evaluate to a valid argument type (like [`<length>`](length)), or nested [`min()`](min) and [`max()`](max) functions. For math expressions, you can use addition, subtraction, multiplication, and division without using the `calc()` function itself. You may also use parentheses to establish computation order when needed. You can use different units for each value in your expressions and different units in any math function making up any of the arguments. Keep the following aspects in mind while working with the function: * 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 `max()` and `min()` functions as expression values, in which case the inner ones are treated as simple parentheses. The expressions are full math expressions, so you can use direct addition, subtraction, multiplication and division without using the calc() function itself. * The expression can be values combining the addition ( `+` ), subtraction ( `-` ), multiplication ( `*` ) and division ( `/` ) operators, using standard operator precedence rules. Make sure to put a space on each side of the `+` and `-` operands. The operands in the expression may be any [`<length>`](length) syntax value. You can use different units for each value in your expression. You may also use parentheses to establish computation order when needed. * Oftentimes you will want to use [`min()`](min) and [`max()`](max) within a `clamp()` function. ### Return value `clamp(MIN, VAL, MAX)` is resolved as `[`max`](max)(MIN, [`min`](min)(VAL, MAX))`. Based on the provided parameters, the function returns [`<length>`](length), [`<frequency>`](frequency), [`<angle>`](angle), [`<time>`](time), [`<percentage>`](percentage), [`<number>`](number), or [`<integer>`](integer). ### Formal syntax ``` <clamp()> = clamp( <calc-sum>[#](value_definition_syntax#hash_mark)[{3}](value_definition_syntax#curly_braces) ) <calc-sum> = <calc-product> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '+' [|](value_definition_syntax#single_bar) '-' []](value_definition_syntax#brackets) <calc-product> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-product> = <calc-value> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '*' [|](value_definition_syntax#single_bar) '/' []](value_definition_syntax#brackets) <calc-value> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-value> = [<number>](number) [|](value_definition_syntax#single_bar) [<dimension>](dimension) [|](value_definition_syntax#single_bar) [<percentage>](percentage) [|](value_definition_syntax#single_bar) <calc-constant> [|](value_definition_syntax#single_bar) ( <calc-sum> ) <calc-constant> = e [|](value_definition_syntax#single_bar) pi [|](value_definition_syntax#single_bar) infinity [|](value_definition_syntax#single_bar) -infinity [|](value_definition_syntax#single_bar) NaN ``` Examples -------- ### min, max, and clamp comparison In this example we have a simple responsive example that makes use of [`min()`](min), [`max()`](max), and [`clamp()`](clamp) for some of the sizes. The [`<body>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body) element's [`width`](width) is set as `min(1000px, calc(70% + 100px))`. This means that the width will be set at `1000px`, unless the result of `calc(70% + 100px)` is less than `1000px`, in which case it will be set to that value instead. `min()` allows you set a maximum value. The [`<p>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p) element's [`font-size`](font-size) is set as `max(1.2rem, 1.2vw)`. This means that the `font-size` will be set at `1.2rem`, unless the computed value of `1.2vw` is greater than that of `1.2rem`, in which case it will be set to that value instead. `max()` allows you set a minimum value, which in cases like this is useful for accessibility purposes. The [`<h1>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements) element's `font-size` is set as `clamp(1.8rem, 2.5vw, 2.8rem)`. This means that the `font-size` will be set at `1.8rem`, until the computed value of `2.5vw` becomes greater than that of `1.8rem`. At this point, `font-size` will be set at `2.5vw`, until `2.5vw`'s computed value becomes greater than that of `2.8rem`. At this point, the `font-size` will be set at `2.8rem`. `clamp()` allows you to set a minimum and maximum value. You find this [example live on GitHub](https://mdn.github.io/css-examples/min-max-clamp/), if you want to play around with it. #### HTML ``` <h1>Simple responsive test</h1> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. In orci orci, eleifend id risus nec, mattis rutrum velit. Suspendisse fringilla egestas erat eu convallis. Phasellus eu velit ut magna dapibus elementum cursus at ligula. Ut tempus varius nibh, nec auctor sapien iaculis sit amet. Fusce iaculis, libero quis elementum viverra, nulla ante accumsan lectus, sit amet convallis lacus ipsum vel est. Curabitur et urna non est consectetur pulvinar vel id risus. Ut vestibulum, sem in semper aliquet, felis arcu euismod sapien, ac imperdiet massa nisl quis sem. Vestibulum ac elementum felis, in tempor velit. Pellentesque purus ex, mattis at ornare quis, porta condimentum mi. Donec vestibulum ligula vel nulla blandit, quis euismod nulla vestibulum. Suspendisse potenti. Nunc neque mauris, tempor sed facilisis at, ultrices eget nulla. Pellentesque convallis ante nec augue porttitor, id tempus ante luctus. </p> <p> Integer rutrum sollicitudin tellus, quis cursus nulla scelerisque nec. Nunc eu facilisis lorem. Maecenas faucibus sapien eleifend, semper tellus at, pharetra quam. Cras feugiat vulputate tortor at rhoncus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam non felis quis sem lobortis sodales vel id libero. Phasellus sit amet placerat lorem. </p> ``` #### CSS ``` html { font-family: sans-serif; } body { margin: 0 auto; width: min(1000px, calc(70% + 100px)); } h1 { letter-spacing: 2px; font-size: clamp(1.8rem, 2.5vw, 2.8rem); } p { line-height: 1.5; font-size: max(1.2rem, 1.2vw); } ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # calc-notation](https://w3c.github.io/csswg-drafts/css-values/#calc-notation) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `clamp` | 79 | 79 | 75 | No | 66 | 13.1 | 79 | 79 | 79 | 57 | 13.4 | 12.0 | See also -------- * [`calc()`](calc) * [`max()`](max) * [`min()`](min) * [CSS Values](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units) css font-language-override font-language-override ====================== The `font-language-override` CSS property controls the use of language-specific glyphs in a typeface. ``` /\* Keyword value \*/ font-language-override: normal; /\* <string> values \*/ font-language-override: "ENG"; /\* Use English glyphs \*/ font-language-override: "TRK"; /\* Use Turkish glyphs \*/ /\* Global values \*/ font-language-override: inherit; font-language-override: initial; font-language-override: revert; font-language-override: revert-layer; font-language-override: unset; ``` By default, HTML's `lang` attribute tells browsers to display glyphs designed specifically for that language. For example, a lot of fonts have a special character for the digraph `fi` that merge the dot on the "i" with the "f." However, if the language is set to Turkish the typeface will likely know not to use the merged glyph; Turkish has two versions of the "i," one with a dot (`i`) and one without (`ı`), and using the ligature would incorrectly transform a dotted "i" into a dotless "i." The `font-language-override` property lets you override the typeface behavior for a specific language. This is useful, for example, when the typeface you're using lacks proper support for the language. For instance, if a typeface doesn't have proper rules for the Azeri language, you can force the font to use Turkish glyphs, which follow similar rules. Syntax ------ The `font-language-override` property is specified as the keyword `normal` or a `<string>`. ### Values `normal` Tells the browser to use font glyphs that are appropriate for the language specified by the `lang` attribute. This is the default value. [`<string>`](string) Tells the browser to use font glyphs that are appropriate for the language specified by the string. The string must match a language tag found in the [OpenType language system](https://docs.microsoft.com/typography/opentype/spec/languagetags). For example, "ENG" is English, and "KOR" is Korean. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` font-language-override = normal [|](value_definition_syntax#single_bar) [<string>](string) ``` Examples -------- ### Using Danish glyphs #### HTML ``` <p class="para1">Default language setting.</p> <p class="para2"> This is a string with the <code>font-language-override</code> set to Danish. </p> ``` #### CSS ``` p.para1 { font-language-override: normal; } p.para2 { font-language-override: "DAN"; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Fonts Module Level 4 # font-language-override-prop](https://w3c.github.io/csswg-drafts/css-fonts/#font-language-override-prop) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `font-language-override` | No | No | 34 4 | No | No | No | No | No | 34 4 | No | No | No | See also -------- * [`font-variant`](font-variant), [`font-variant-position`](font-variant-position), [`font-variant-east-asian`](font-variant-east-asian), [`font-variant-caps`](font-variant-caps), [`font-variant-ligatures`](font-variant-ligatures), [`font-variant-numeric`](font-variant-numeric), [`font-variant-alternates`](font-variant-alternates), [`font-synthesis`](font-synthesis), [`font-kerning`](font-kerning). css direction direction ========= The `direction` CSS property sets the direction of text, table columns, and horizontal overflow. Use `rtl` for languages written from right to left (like Hebrew or Arabic), and `ltr` for those written from left to right (like English and most other languages). Try it ------ Note that text direction is usually defined within a document (e.g., with [HTML's `dir` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir)) rather than through direct use of the `direction` property. The property sets the base text direction of block-level elements and the direction of embeddings created by the [`unicode-bidi`](unicode-bidi) property. It also sets the default alignment of text, block-level elements, and the direction that cells flow within a table row. Unlike the `dir` attribute in HTML, the `direction` property is not inherited from table columns into table cells, since CSS inheritance follows the document tree, and table cells are inside of rows but not inside of columns. The `direction` and [`unicode-bidi`](unicode-bidi) properties are the two only properties which are not affected by the [`all`](all) shorthand property. Syntax ------ ``` /\* Keyword values \*/ direction: ltr; direction: rtl; /\* Global values \*/ direction: inherit; direction: initial; direction: revert; direction: revert-layer; direction: unset; ``` ### Values `ltr` Text and other elements go from left to right. This is the default value. `rtl` Text and other elements go from right to left. For the `direction` property to have any effect on inline-level elements, the [`unicode-bidi`](unicode-bidi) property's value must be `embed` or `override`. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `ltr` | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` direction = ltr [|](value_definition_syntax#single_bar) rtl ``` Examples -------- ### Setting right-to-left direction In the example below are two strings of text, both which are displaying using `direction: rtl`. While the Arabic text is displayed correctly with this setting, the English text now has a full stop in an unusual location. ``` blockquote { direction: rtl; width: 300px; } ``` ``` <blockquote> <p>This paragraph is in English but incorrectly goes right to left.</p> <p></p> </blockquote> <blockquote> <p>هذه الفقرة باللغة العربية ، لذا يجب الانتقال من اليمين إلى اليسار.</p> <p></p> </blockquote> ``` Specifications -------------- | Specification | | --- | | [CSS Writing Modes Level 4 # direction](https://w3c.github.io/csswg-drafts/css-writing-modes/#direction) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `direction` | 2 | 12 | 1 | 5.5 | 9.2 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | See also -------- * [`unicode-bidi`](unicode-bidi) * [`writing-mode`](writing-mode) * The HTML [`dir`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#dir) global attribute css caption-side caption-side ============ The `caption-side` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property puts the content of a table's [`<caption>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption) on the specified side. The values are relative to the [`writing-mode`](writing-mode) of the table. Try it ------ Syntax ------ ``` /\* Directional values \*/ caption-side: top; caption-side: bottom; /\* Logical values \*/ caption-side: block-start; caption-side: block-end; caption-side: inline-start; caption-side: inline-end; /\* Global values \*/ caption-side: inherit; caption-side: initial; caption-side: revert; caption-side: revert-layer; caption-side: unset; ``` The `caption-side` property is specified as one of the keyword values listed below. ### Values `top` The caption box should be positioned above the table. `bottom` The caption box should be positioned below the table. `block-start` The caption box should be positioned at the block start edge of the table. `block-end` The caption box should be positioned at the block end edge of the table. `inline-start` The caption box should be positioned at the inline start edge of the table. `inline-end` The caption box should be positioned at the inline end edge of the table. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `top` | | Applies to | table-caption elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` caption-side = top [|](value_definition_syntax#single_bar) bottom ``` Examples -------- ### Setting captions above and below #### HTML ``` <table class="top"> <caption> Caption ABOVE the table </caption> <tr> <td>Some data</td> <td>Some more data</td> </tr> </table> <br /> <table class="bottom"> <caption> Caption BELOW the table </caption> <tr> <td>Some data</td> <td>Some more data</td> </tr> </table> ``` #### CSS ``` .top caption { caption-side: top; } .bottom caption { caption-side: bottom; } table { border: 1px solid red; } td { border: 1px solid blue; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # caption-side](https://w3c.github.io/csswg-drafts/css-logical/#caption-side) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `caption-side` | 1 | 12 | 1 | 8 | 4 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | | `non_standard_values` | No | No | 1-87 | No | No | preview | No | No | 4-87 | No | No | No | | `writing-mode_relative_values` | No | No | 42 | No | No | No | No | No | 42 | No | No | No | css CSS Multi-column Layout CSS Multi-column Layout ======================= **CSS Multi-column Layout** is a module of CSS that adds support for multi-column layouts. Support is included for establishing the number of columns in a layout, as well as how content should flow from column to column, gap sizes between columns, and column dividing lines (known as column rules) along with their appearance. Basic example ------------- In the following example, the [`column-count`](column-count) property has been applied to the `<div>` element with the class `container`. As the value of `column-count` is `3`, the content is arranged into three columns of the same size. Relationship to fragmentation ----------------------------- Multiple-column layout is closely related to [Paged Media](css_pages), in that each column box becomes a fragment, much like a printed page becomes a fragment of an overall document. Therefore, the properties now defined in the [CSS Fragmentation](css_fragmentation) specification are required to control how content breaks between columns. Reference --------- ### Properties for multi-column layout * [`column-count`](column-count) * [`column-fill`](column-fill) * [`column-gap`](column-gap) * [`column-rule`](column-rule) * [`column-rule-color`](column-rule-color) * [`column-rule-style`](column-rule-style) * [`column-rule-width`](column-rule-width) * [`column-span`](column-span) * [`column-width`](column-width) * [`columns`](columns) ### Properties related to CSS fragmentation * [`break-after`](break-after) * [`break-before`](break-before) * [`break-inside`](break-inside) * [`orphans`](orphans) * [`widows`](widows) Guides ------ [Basic concepts of multi-column layout](css_columns/basic_concepts_of_multicol) An overview of the Multiple-column Layout specification [Styling columns](css_columns/styling_columns) How to use column rules and manage the spacing between columns. [Spanning and balancing](css_columns/spanning_columns) How to make elements span across all columns and controlling the way columns are filled. [Handling overflow in multi-column layout](css_columns/handling_overflow_in_multicol) What happens when an item overflows the column it is in and what happens when there is too much columned content to fit a container. [Handling content breaks in multi-column layout](css_columns/handling_content_breaks_in_multicol) Introduction to the Fragmentation specification and how to control where column content breaks. Specifications -------------- | Specification | | --- | | [CSS Multi-column Layout Module Level 1](https://drafts.csswg.org/css-multicol/) | See also -------- Other CSS layout technologies include: * [CSS Flexible Box Layout](css_flexible_box_layout) (CSS flexbox) * [CSS Grid Layout](css_grid_layout)
programming_docs
css empty-cells empty-cells =========== The `empty-cells` CSS property sets whether borders and backgrounds appear around [`<table>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table) cells that have no visible content. Try it ------ This property has an effect only when the [`border-collapse`](border-collapse) property is `separate`. Syntax ------ ``` /\* Keyword values \*/ empty-cells: show; empty-cells: hide; /\* Global values \*/ empty-cells: inherit; empty-cells: initial; empty-cells: revert; empty-cells: revert-layer; empty-cells: unset; ``` The `empty-cells` property is specified as one of the keyword values listed below. ### Values `show` Borders and backgrounds are drawn like in normal cells. `hide` No borders or backgrounds are drawn. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `show` | | Applies to | table-cell elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` empty-cells = show [|](value_definition_syntax#single_bar) hide ``` Example ------- ### Showing and hiding empty table cells #### HTML ``` <table class="table\_1"> <tr> <td>Moe</td> <td>Larry</td> </tr> <tr> <td>Curly</td> <td></td> </tr> </table> <br /> <table class="table\_2"> <tr> <td>Moe</td> <td>Larry</td> </tr> <tr> <td>Curly</td> <td></td> </tr> </table> ``` #### CSS ``` .table\_1 { empty-cells: show; } .table\_2 { empty-cells: hide; } td, th { border: 1px solid gray; padding: 0.5rem; } ``` #### Result Specifications -------------- | Specification | | --- | | [Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification # empty-cells](https://w3c.github.io/csswg-drafts/css2/#empty-cells) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `empty-cells` | 1 | 12 | 1 | 8 | 4 | 1.2 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | See also -------- * [`border-collapse`](border-collapse) * [Styling tables](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Styling_tables) css :blank :blank ====== **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. **Note:** The `:blank` selector is considered at risk, as the CSSWG keeps changing it. See [CSSWG issue #1967](https://github.com/w3c/csswg-drafts/issues/1967). The `:blank` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) selects empty user input elements (e.g. [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) or [`<textarea>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea)). Syntax ------ ``` :blank ``` Examples -------- ### Simple :blank example In eventual supporting browsers, the `:blank` pseudo-class will enable developers to highlight in some way input controls that are not required, but still have no content filled in, perhaps as a reminder to users. #### HTML ``` <textarea></textarea> ``` #### CSS ``` textarea:blank { border: 3px solid red; } ``` #### Result Specifications -------------- | Specification | | --- | | [Selectors Level 4 # blank-pseudo](https://w3c.github.io/csswg-drafts/selectors/#blank-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:blank` | No | No | No See [bug 1197736](https://bugzil.la/1197736). | No | No | No | No | No | No See [bug 1197736](https://bugzil.la/1197736). | No | No | No | See also -------- * [`:empty`](:empty) css :left :left ===== The `:left` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes), used with the [`@page`](@page) <at-rule>, represents all left-hand pages of a printed document. ``` /\* Selects any left-hand pages when printing \*/ @page :left { margin: 2in 3in; } ``` Whether a given page is "left" or "right" is determined by the major writing direction of the document. For example, if the first page has a major writing direction of left-to-right then it will be a [`:right`](:right) page; if it has a major writing direction of right-to-left then it will be a `:left` page. **Note:** This pseudo-class can be used to change only the [`margin`](margin), [`padding`](padding), [`border`](border), and [`background`](background) properties of the *page box*. All other properties will be ignored, and only the page box, not the document content on the page, will be affected. Syntax ------ ``` :left ``` Examples -------- ### Setting a margin for left-hand pages ``` @page :left { margin: 2in 3in; } ``` Specifications -------------- | Specification | | --- | | [CSS Paged Media Module Level 3 # left-right-first](https://w3c.github.io/csswg-drafts/css-page/#left-right-first) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:left` | 6 | 12 | No | 8 | 9.2 | 5 | ≤37 | 18 | No | 10.1 | 4.2 | 1.0 | See also -------- * [`@page`](@page) * Other page-related pseudo-classes: [`:first`](:first), [`:right`](:right) css writing-mode writing-mode ============ The `writing-mode` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets whether lines of text are laid out horizontally or vertically, as well as the direction in which blocks progress. When set for an entire document, it should be set on the root element (`html` element for HTML documents). Try it ------ This property specifies the *block flow direction*, which is the direction in which block-level containers are stacked, and the direction in which inline-level content flows within a block container. Thus, it also determines the ordering of block-level content. Syntax ------ ``` /\* Keyword values \*/ writing-mode: horizontal-tb; writing-mode: vertical-rl; writing-mode: vertical-lr; /\* Global values \*/ writing-mode: inherit; writing-mode: initial; writing-mode: revert; writing-mode: revert-layer; writing-mode: unset; ``` The `writing-mode` property is specified as one of the values listed below. The flow direction in horizontal scripts is also affected by the [directionality of that script](https://www.w3.org/International/questions/qa-scripts.en), either left-to-right (`ltr`, like English and most other languages) or right-to-left (`rtl`, like Hebrew or Arabic). ### Values `horizontal-tb` For `ltr` scripts, content flows horizontally from left to right. For `rtl` scripts, content flows horizontally from right to left. The next horizontal line is positioned below the previous line. `vertical-rl` For `ltr` scripts, content flows vertically from top to bottom, and the next vertical line is positioned to the left of the previous line. For `rtl` scripts, content flows vertically from bottom to top, and the next vertical line is positioned to the right of the previous line. `vertical-lr` For `ltr` scripts, content flows vertically from top to bottom, and the next vertical line is positioned to the right of the previous line. For `rtl` scripts, content flows vertically from bottom to top, and the next vertical line is positioned to the left of the previous line. `sideways-rl` Experimental For `ltr` scripts, content flows vertically from bottom to top. For `rtl` scripts, content flows vertically from top to bottom. All the glyphs, even those in vertical scripts, are set sideways toward the right. `sideways-lr` Experimental For `ltr` scripts, content flows vertically from top to bottom. For `rtl` scripts, content flows vertically from bottom to top. All the glyphs, even those in vertical scripts, are set sideways toward the left. `lr` Deprecated Deprecated except for SVG1 documents. For CSS, use `horizontal-tb` instead. `lr-tb` Deprecated Deprecated except for SVG1 documents. For CSS, use `horizontal-tb` instead. `rl` Deprecated Deprecated except for SVG1 documents. For CSS, use `horizontal-tb` instead. `tb` Deprecated Deprecated except for SVG1 documents. For CSS, use `vertical-lr` instead. `tb-lr` Deprecated Deprecated except for SVG1 documents. For CSS, use `vertical-lr` instead. `tb-rl` Deprecated Deprecated except for SVG1 documents. For CSS, use `vertical-rl` instead. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `horizontal-tb` | | Applies to | all elements except table row groups, table column groups, table rows, and table columns | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` writing-mode = horizontal-tb [|](value_definition_syntax#single_bar) vertical-rl [|](value_definition_syntax#single_bar) vertical-lr [|](value_definition_syntax#single_bar) sideways-rl [|](value_definition_syntax#single_bar) sideways-lr ``` Examples -------- ### Using multiple writing modes This example demonstrates all of the writing modes, showing each with text in various languages. #### HTML The HTML is a [`<table>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table) with each writing mode in a row with a column showing text in various scripts using that writing mode. ``` <table> <tr> <th>Value</th> <th>Vertical script</th> <th>Horizontal (LTR) script</th> <th>Horizontal (RTL) script</th> <th>Mixed script</th> </tr> <tr> <td>horizontal-tb</td> <td class="example Text1"><span>我家没有电脑。</span></td> <td class="example Text1"><span>Example text</span></td> <td class="example Text1"><span>מלל ארוך לדוגמא</span></td> <td class="example Text1"><span>1994年に至っては</span></td> </tr> <tr> <td>vertical-lr</td> <td class="example Text2"><span>我家没有电脑。</span></td> <td class="example Text2"><span>Example text</span></td> <td class="example Text2"><span>מלל ארוך לדוגמא</span></td> <td class="example Text2"><span>1994年に至っては</span></td> </tr> <tr> <td>vertical-rl</td> <td class="example Text3"><span>我家没有电脑。</span></td> <td class="example Text3"><span>Example text</span></td> <td class="example Text3"><span>מלל ארוך לדוגמא</span></td> <td class="example Text3"><span>1994年に至っては</span></td> </tr> <tr> <td>sideways-lr</td> <td class="example Text4"><span>我家没有电脑。</span></td> <td class="example Text4"><span>Example text</span></td> <td class="example Text4"><span>מלל ארוך לדוגמא</span></td> <td class="example Text4"><span>1994年に至っては</span></td> </tr> <tr> <td>sideways-rl</td> <td class="example Text5"><span>我家没有电脑。</span></td> <td class="example Text5"><span>Example text</span></td> <td class="example Text5"><span>מלל ארוך לדוגמא</span></td> <td class="example Text5"><span>1994年に至っては</span></td> </tr> </table> ``` #### CSS The CSS that adjusts the directionality of the content looks like this: ``` .example.Text1 span, .example.Text1 { writing-mode: horizontal-tb; } .example.Text2 span, .example.Text2 { writing-mode: vertical-lr; } .example.Text3 span, .example.Text3 { writing-mode: vertical-rl; } .example.Text4 span, .example.Text4 { writing-mode: sideways-lr; } .example.Text5 span, .example.Text5 { writing-mode: sideways-rl; } ``` #### Result This image shows what the output should look like, in case your browser's support for `writing-mode` is incomplete: Specifications -------------- | Specification | | --- | | [CSS Writing Modes Level 4 # block-flow](https://w3c.github.io/csswg-drafts/css-writing-modes/#block-flow) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `writing-mode` | 48 8 | 12 12 | 41 Firefox 42 added support for bidirectional and RTL scripts in vertical modes. | 9 Internet Explorer's implementation differs from the specification. 9 Internet Explorer's implementation differs from the specification. | 35 15 | 10.1 5.1 | 48 3 | 48 18 | 41 Firefox 42 added support for bidirectional and RTL scripts in vertical modes. | 35 14 | 10.3 5 | 5.0 1.0 | | `horizontal_vertical_values` | 48 | 79 | 43 | No | 35 | 9 | 48 | 48 | 43 | 35 | 9 | 5.0 | | `sideways_values` | No | No | 43 | No | No | No | No | No | 43 | No | No | No | | `svg_values` | 48 | 12 | 43 | 9 | 35 | 10.1 | 48 | 48 | 43 | 35 | 10.3 | 5.0 | See also -------- * SVG [`writing-mode`](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/writing-mode) attribute * [`direction`](direction) * [`unicode-bidi`](unicode-bidi) * [`text-orientation`](text-orientation) * [`text-combine-upright`](text-combine-upright) * [CSS Logical properties](css_logical_properties) * [Styling vertical text (Chinese, Japanese, Korean and Mongolian)](https://www.w3.org/International/articles/vertical-text/) * Extensive browsers support test results: <https://w3c.github.io/i18n-tests/results/writing-mode-vertical> css Introducing the CSS Cascade Introducing the CSS Cascade =========================== The **cascade** is an algorithm that defines how user agents combine property values originating from different sources. The cascade defines the origin and layer that takes precedence when declarations in more than one [origin](#origin_types) or [cascade layer](@layer) set a value for a property on an element. The cascade lies at the core of CSS, as emphasized by the name: ***Cascading*** Style Sheets. When a [selector](css_selectors) matches an element, the property value from the origin with the highest precedence gets applied, even if the selector from a lower precedence origin or layer has greater <specificity>. This article explains what the cascade is and the order in which [CSS](https://developer.mozilla.org/en-US/docs/Glossary/CSS) [declarations](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleDeclaration) cascade, covering cascade layers and origin type. Understanding origin precedence is key to understanding the cascade. Origin types ------------ The CSS cascade algorithm's job is to select CSS declarations in order to determine the correct values for CSS properties. CSS declarations come from different origin types: **[User-agent stylesheets](#user-agent_stylesheets)**, **[Author stylesheets](#author_stylesheets)**, and **[User stylesheets](#user_stylesheets)**. Though style sheets come from these different origins and can be within different [layers](@layer) in each of these origins, they overlap in scope; to make this work, the cascade algorithm defines how they interact. Before addressing the interactions, let's define some terms: ### User-agent stylesheets User-agent, or browsers, have basic style sheets that give default styles to any document. These style sheets are named **user-agent stylesheets**. Most browsers use actual stylesheets for this purpose, while others simulate them in code. The end result is the same. Some browsers let users modify the user-agent stylesheet, but this is rare and not something that can be controlled. Although some constraints on user-agent stylesheets are set by the HTML specification, browsers have a lot of latitude: that means some differences exist between browsers. To simplify the development process, Web developers may use a CSS reset stylesheet, such as [normalize.css](https://github.com/necolas/normalize.css), which sets common properties values to a known state for all browsers before beginning to make alterations to suit their specific needs. Unless the user-agent stylesheet includes an [`!important`](specificity#the_!important_exception) next to a property, making it "important", styles declared by author styles, including a reset style sheet, take precedence over the user-agent styles, regardless of the specificity of the associated selector. ### Author stylesheets **Author stylesheets** are the most common type of style sheet; these are the styles written by web developers. These styles can reset user-agent styles, as noted above, and define the styles for the design of a given web page or application. The author, or web developer, defines the styles for the document using one or more linked or imported stylesheets, [`<style>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style) blocks, and inline styles defined with the [`style`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#style) attribute. These author styles define the look and feel of the website — its theme. ### User stylesheets In most browsers, the user (or reader) of the web site can choose to override styles using a custom **user stylesheet** designed to tailor the experience to the user's wishes. Depending on the user agent, [user styles can be configured](https://www.thoughtco.com/user-style-sheet-3469931) directly or added via browser extensions. ### Cascade layers The cascade order is based on origin type. The cascade within each origin type is based on the declaration order of [cascade layers](@layer) within that type. For all origins - user-agent, author, or user - styles can be declared within or outside of named or anonymous layers. When declared using [`layer`, `layer()`](@import) or [`@layer`](@layer), styles are placed into the specified named layer, or into an anonymous layer if no name is provided. Styles declared outside of a layer are treated as being part of an anonymous last declared layer. Let's take a look at cascading origin type before diving into cascade layers within each origin type. Cascading order --------------- The cascading algorithm determines how to find the value to apply for each property for each document element. The following steps apply to the cascading algorithm: 1. **Relevance**: It first filters all the rules from the different sources to keep only the rules that apply to a given element. That means rules whose selector matches the given element and which are part of an appropriate `media` at-rule. 2. **Origin and importance**: Then it sorts these rules according to their importance, that is, whether or not they are followed by `!important`, and by their origin. Ignoring layers for the moment, the cascade order is as follows: | Order (low to high) | Origin | Importance | | --- | --- | --- | | 1 | user-agent (browser) | normal | | 2 | user | normal | | 3 | author (developer) | normal | | 4 | CSS @keyframe animations | | | 5 | author (developer) | `!important` | | 6 | user | `!important` | | 7 | user-agent (browser) | `!important` | | 8 | CSS transitions | | 3. **Specificity:** In case of equality with an origin, the <specificity> of a rule is considered to choose one value or another. The specificity of the selectors are compared, and the declaration with the highest specificity wins. 4. **Order of appearance**: In the origin with precedence, if there are competing values for a property that are in style block matching selectors of equal specificity, the last declaration in the style order is applied. The cascade is in ascending order, meaning animations have precedence of normal values, whether those are declared in user, author, or user-agent styles, important values take precedence over animations, and transitions have precedence over important values. **Note:** **Transitions and animations** Property values set by animation [`@keyframes`](@keyframes) are more important than all normal styles (those with no [`!important`](specificity#the_!important_exception) set). Property values being set in a [`transition`](transition) take precedence over all other values set, even those marked with `!important`. The cascade algorithm is applied *before* the specificity algorithm, meaning if `:root p { color: red;}` is declared in the user stylesheet (line 2) and a less specific `p {color: blue;}` is in the author stylesheet (line 3), the paragraphs will be blue. Basic example ------------- Before taking a deeper look at how cascade layers impact the cascade, let's look at an example involving multiple sources of CSS across the various origins, and work through the steps of the cascade algorithm: Here we have a user agent style sheet, two author style sheets, a user stylesheet, and inline styles within the HTML: **User-agent CSS:** ``` li { margin-left: 10px; } ``` **Author CSS 1:** ``` li { margin-left: 0; } /\* This is a reset \*/ ``` **Author CSS 2:** ``` @media screen { li { margin-left: 3px; } } @media print { li { margin-left: 1px; } } @layer namedLayer { li { margin-left: 5px; } } ``` **User CSS:** ``` .specific { margin-left: 1em; } ``` **HTML:** ``` <ul> <li class="specific">1<sup>st</sup></li> <li>2<sup>nd</sup></li> </ul> ``` In this case, declarations inside `li` and `.specific` rules should apply. Once again, there are four steps in the cascade algorithm, in order: 1. Relevance 2. Origin and importance 3. Specificity 4. Order of appearance The `1px` is for print media. Due to lack of *relevance* based on its media type, it is removed from consideration. No declaration is marked as `!important`, so the precedence order is author style sheets over user style sheets over user-agent stylesheet. Based on *origin and importance*, the `1em` from the user stylesheet and the `10px` from the user-agent stylesheet are removed from consideration. Note that even though the user style on `.specific` of `1em` has a higher specificity, it's a normal declaration in a user style sheet. As such, it has a lower precedence than any author styles, and gets removed by the origin and importance step of the algorithm before specificity even comes into play. There are three declarations in author stylesheets: ``` li { margin-left: 0; } /\* from author css 1 \*/ ``` ``` @media screen { li { margin-left: 3px; } } ``` ``` @layer namedLayer { li { margin-left: 5px; } } ``` The last one, the `5px` is part of a cascade layer. Normal declarations in layers have lower precedence than normal styles not in a layer within the same origin type. This is also removed by step 2 of the algorithm, *origin and importance*. This leaves the `0` and the `3px`, which both have the same selector, hence the same *specificity*. We then look at *order of appearance*. The second one, the last of the two unlayered author styles, wins. ``` margin-left: 3px; ``` **Note:** The declaration defined in the user CSS, while it may have greater specificity, is not chosen as the cascade algorithm's *origin and importance* is applied before the *specificity* algorithm. The declaration defined in a cascade layer, though it may come later in the code, will not have precedence either as normal styles in cascade layers have less precedence than normal unlayered styles. *Order of appearance* only matters when both origin, importance, and specificity are equal. Author styles: inline styles, layers, and precedence ---------------------------------------------------- The [table in Cascading order](#cascading_order) provided a precedence order overview. The table summarized the user-agent, user, and author origin type styles in two lines each with "origin type - normal" and "origin type - !important". The precedence within each origin type is more nuanced. Styles can be contained within layers within their origin type, and, with author styles, there is also the issue of where inline styles land in the cascade order. The order in which layers are declared is important in determining precedence. Normal styles in a layer take precedence over styles declared in prior layers; with normal styles declared outside of any layer taking precedence over normal layered styles regardless of specificity. In this example, the author used CSS's [`@import`](@import) rule to import five external style sheets within a [`<style>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style) information element. ``` <style> @import unlayeredStyles.css; @import AStyles.css layer(A); @import moreUnlayeredStyles.css; @import BStyles.css layer(B); @import CStyles.css layer(C); p { color: red; padding: 1em !important; } </style> ``` and then in the body of the document we have inline styles: ``` <p style="line-height: 1.6em; text-decoration: overline !important;">Hello</p> ``` In the CSS code block above, three cascade layers named "A", "B", and "C", were created, in that order. Three stylesheets were imported directly into layers and two were imported without creating or being assigned to a layer. The "All unlayered styles" in the list below (normal author style precedence - order 4) includes styles from these two stylesheets and the additional unlayered CSS style blocks. In addition, there are two inline styles, a normal `line-height` declaration and an important `text-decoration` declaration: | Order (low to high) | Author style | Importance | | --- | --- | --- | | 1 | A - first layer | normal | | 2 | B - second layer | normal | | 3 | C - last layer | normal | | 4 | All unlayered styles | normal | | 5 | inline `style` | normal | | 6 | animations | | | 7 | All unlayered styles | `!important` | | 8 | C - last layer | `!important` | | 9 | B - second layer | `!important` | | 10 | A - first layer | `!important` | | 11 | inline `style` | `!important` | | 12 | transitions | | In all origin types, the non important styles contained in layers have the lowest precedence. In our example, the normal styles associated with the first declared layer (A) have lower precedence than normal styles in the second declared layer (B), which have lower precedence than normal styles in the third declared layer (C). These layered styles have lower precedence than all normal unlayered styles, which includes normal styles from `unlayeredStyles.css`, `moreUnlayeredStyles.css`, and the `color` of `p` in the `<style>` itself. If any of the layered styles in A, B, or C, have selectors with higher specificity matching an element, similar to `:root body p { color: black;}`, it doesn't matter. Those declarations are removed from consideration because of *origin*; normal layered styles have less precedence than normal unlayered styles. If, however, the more specific selector `:root body p { color: black;}` was found in `unlayeredStyles.css`, as both *origin and importance* have the same precedence, *specificity* would mean the more specific, black declaration would win. The layer order of precedence is inverted for styles declared as `!important`. Important styles declared in a layer take precedence over important styles declared outside of a layer. Important styles in the first declared layer (A) take precedence over important declarations found in layer B, which takes precedence over C, which have precedence over important declarations in the unlayered styles. ### Inline styles Only relevant to author styles are inline styles, declared with the `style` attribute. Normal inline styles take precedence over any other normal author styles, no matter the specificity of the selector. If `line-height: 2;` were declared in a `:root body p` selector block in any of the five imported stylesheets, the line height would still be `1.6`. Normal inline styles take precedence over any other normal author styles unless the property is being altered by a CSS animation. All important inline styles take precedence over all author styles, important and not, inline and not, layered and not. Important styles also take precedence over animated properties, but not transitioning properties. Three things can override an important inline style: 1) an important user style, 2) an important user agent style, or 3) a property value being transitioned. ### Importance and layers The origin type precedence order is inverted for important styles. Important styles declared outside of any cascade layer have lower precedence than those declared as part of a layer. Important values that come in early layers have precedence over important styles declared in subsequent cascade layers. Take for example the following CSS: ``` p { color: red; } @layer B { :root p { color: blue; } } ``` Even though the red is declared first and has a less specific selector, because unlayered CSS takes precedence over layered CSS, the paragraph will be red. Had we included an inline style on the paragraph setting it to a different color, such as `<p style="color: black">`, the paragraph would be black. When we add `!important` to this bit of CSS, the precedence order is reversed with the stylesheet: ``` p { color: red !important; } @layer B { :root p { color: blue !important; } } ``` Now the paragraph will be blue. The `!important` in the earliest declared layer takes precedence of subsequent layers and unlayered important declarations. If the inline style contained !important, such as `<p style="color: black !important">`, again the paragraph would be black. Inline importance does take precedence over all other author declared `!important` declarations, no matter the specificity. **Note:** `!important` reverses the precedence of cascade layers. For this reason, rather than using `!important` to override external styles, import frameworks, third party styles, widget stylesheets, etc., into layers, demoting their precedence. `!important` should only be used sparingly, if ever, to guard required styles against later overrides, in the first declared layer. Styles that are transitioning take precedence over all important styles, no matter who or how they are declared. Complete cascade order ---------------------- Now that we have a better understanding of origin type and cascade layer precedence, we realize the table in [Cascading order](#cascading_order) could have more accurately been represented by the following table: | Precedence Order(low to high) | Style Origin | Importance | | --- | --- | --- | | 1 | user-agent - first declared layer | normal | | user-agent - last declared layer | | user-agent - unlayered styles | | 2 | user - first declared layer | normal | | user - last declared layer | | user - unlayered styles | | 3 | author - first declared layer | normal | | author - last declared layer | | author - unlayered styles | | inline `style` | | 4 | animations | | | 5 | author - unlayered styles | `!important` | | author - last declared layer | | author - first declared layer | | inline `style` | | 6 | user - unlayered styles | `!important` | | user - last declared layer | | user - first declared layer | | 7 | user-agent - unlayered styles | `!important` | | user-agent - last declared layer | | user-agent - first declared layer | | 8 | transitions | | Which CSS entities participate in the cascade --------------------------------------------- Only CSS property/value pair declarations participate in the cascade. This means that [at-rules](at-rule) containing entities other than declarations, such as a [`@font-face`](@font-face) rule containing *descriptors*, don't participate in the cascade. For the most part, the properties and descriptors defined in at-rules don't participate in the cascade. Only at-rules as a whole participate in the cascade. For example, within a `@font-face` rule, font names are identified by [`font-family`](@font-face/font-family) descriptors. If several `@font-face` rules with the same descriptor are defined, only the most appropriate `@font-face`, as a whole, is considered. If more than one are identically appropriate, the entire `@font-face` declarations are compared using steps 1, 2, and 4 of the algorithm (there is no specificity when it comes to at-rules). While the declarations contained in most at-rules — such as those in [`@media`](@media), [`@document`](@document), or [`@supports`](@supports) — participate in the cascade, the at-rule may make an entire selector not relevant, as we saw with the print style in the [basic example](#basic-example). Declarations in [`@keyframes`](@keyframes) don't participate in the cascade. As with `@font-face`, only the `@keyframes` as a whole is selected via the cascade algorithm. The [precedence order of animation is described below](#css-animations-and-the-cascade). When it comes to [`@import`](@import), the `@import` doesn't participate itself in the cascade, but all of the imported styles do participate. If the `@import` defines a [named or anonymous layer](@layer), the contents of the imported stylesheet are placed into the specified layer. All other CSS imported with `@import` is treated as the last declared layer. This was discussed above. Finally, [`@charset`](@charset) obeys specific algorithms and isn't affected by the cascade algorithm. CSS animations and the cascade ------------------------------ [CSS animations](css_animations), using [`@keyframes`](@keyframes) at-rules, define animations between states. Keyframes don't cascade, meaning that at any given time CSS takes values from only one single [`@keyframes`](@keyframes), and never mixes multiple ones together. If the several keyframe animations are defined with the same animation name, the last defined `@keyframes` in the origin and layer with the greatest precedence. Only one `@keyframes` definition is used, even if the `@keyframes` animate different property. `@keyframes` with the same name are never combined. ``` p { animation: infinite 5s alternate repeatedName; } @keyframes repeatedName { from { font-size: 1rem; } to { font-size: 3rem; } } @layer A { @keyframes repeatedName { from { background-color: yellow; } to { background-color: orange; } } } @layer B { @keyframes repeatedName { from { color: white; } to { color: black; } } } ``` In this example, there are three separate animation declaration named `repeatedName`. When `animation: infinite 5s alternate repeatedName` is applied to the paragraph, only one animation is applied: the keyframe animation defined in the unlayered CSS takes precedence over the layered keyframe animation declarations based on origin and cascade layer precedence order. In this example, only the element's font size will be animated. **Note:** There are no important animations, as property declarations in a [`@keyframes`](@keyframes) block that contain `!important` as part of the value are ignored. Resetting styles ---------------- After your content has finished altering styles, it may find itself in a situation where it needs to restore them to a known state. This may happen in cases of animations, theme changes, and so forth. The CSS property [`all`](all) lets you quickly set (almost) everything in CSS back to a known state. `all` lets you opt to immediately restore all properties to any of their initial (default) state, the state inherited from the previous level of the cascade, a specific origin (the user-agent stylesheet, the author stylesheet, or the user stylesheet), or even to clear the values of the properties entirely. Specifications -------------- | Specification | | --- | | [CSS Cascading and Inheritance Level 4](https://drafts.csswg.org/css-cascade/) | See also -------- * [A very simple introduction to the CSS cascade](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Cascade_and_inheritance) * CSS key concepts: + [CSS syntax](syntax) + [At-rules](at-rule) + [Comments](comments) + [Specificity](specificity) + [Inheritance](inheritance) + [Box model](css_box_model/introduction_to_the_css_box_model) + [Layout modes](layout_mode) + [Visual formatting models](visual_formatting_model) + [Margin collapsing](css_box_model/mastering_margin_collapsing) + Values - [Initial values](initial_value) - [Computed values](computed_value) - [Used values](used_value) - [Actual values](actual_value) + [Value definition syntax](value_definition_syntax) + [Shorthand properties](shorthand_properties) + [Replaced elements](replaced_element)
programming_docs
css object-fit object-fit ========== The `object-fit` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets how the content of a [replaced element](replaced_element), such as an [`<img>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img) or [`<video>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video), should be resized to fit its container. You can alter the alignment of the replaced element's content object within the element's box using the [`object-position`](object-position) property. Try it ------ Syntax ------ ``` object-fit: contain; object-fit: cover; object-fit: fill; object-fit: none; object-fit: scale-down; /\* Global values \*/ object-fit: inherit; object-fit: initial; object-fit: revert; object-fit: revert-layer; object-fit: unset; ``` The `object-fit` property is specified as a single keyword chosen from the list of values below. ### Values `contain` The replaced content is scaled to maintain its aspect ratio while fitting within the element's content box. The entire object is made to fill the box, while preserving its aspect ratio, so the object will be ["letterboxed"](https://en.wikipedia.org/wiki/Letterboxing_(filming)) if its aspect ratio does not match the aspect ratio of the box. `cover` The replaced content is sized to maintain its aspect ratio while filling the element's entire content box. If the object's aspect ratio does not match the aspect ratio of its box, then the object will be clipped to fit. `fill` The replaced content is sized to fill the element's content box. The entire object will completely fill the box. If the object's aspect ratio does not match the aspect ratio of its box, then the object will be stretched to fit. `none` The replaced content is not resized. `scale-down` The content is sized as if `none` or `contain` were specified, whichever would result in a smaller concrete object size. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `fill` | | Applies to | replaced elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` object-fit = fill [|](value_definition_syntax#single_bar) contain [|](value_definition_syntax#single_bar) cover [|](value_definition_syntax#single_bar) none [|](value_definition_syntax#single_bar) scale-down ``` Examples -------- ### Setting object-fit for an image #### HTML ``` <section> <h2>object-fit: fill</h2> <img class="fill" src="mdn\_logo\_only\_color.png" alt="MDN Logo" /> <img class="fill narrow" src="mdn\_logo\_only\_color.png" alt="MDN Logo" /> <h2>object-fit: contain</h2> <img class="contain" src="mdn\_logo\_only\_color.png" alt="MDN Logo" /> <img class="contain narrow" src="mdn\_logo\_only\_color.png" alt="MDN Logo" /> <h2>object-fit: cover</h2> <img class="cover" src="mdn\_logo\_only\_color.png" alt="MDN Logo" /> <img class="cover narrow" src="mdn\_logo\_only\_color.png" alt="MDN Logo" /> <h2>object-fit: none</h2> <img class="none" src="mdn\_logo\_only\_color.png" alt="MDN Logo" /> <img class="none narrow" src="mdn\_logo\_only\_color.png" alt="MDN Logo" /> <h2>object-fit: scale-down</h2> <img class="scale-down" src="mdn\_logo\_only\_color.png" alt="MDN Logo" /> <img class="scale-down narrow" src="mdn\_logo\_only\_color.png" alt="MDN Logo" /> </section> ``` #### CSS ``` h2 { font-family: Courier New, monospace; font-size: 1em; margin: 1em 0 0.3em; } img { width: 150px; height: 100px; border: 1px solid #000; margin: 10px 0; } .narrow { width: 100px; height: 150px; } .fill { object-fit: fill; } .contain { object-fit: contain; } .cover { object-fit: cover; } .none { object-fit: none; } .scale-down { object-fit: scale-down; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Images Module Level 3 # the-object-fit](https://w3c.github.io/csswg-drafts/css-images/#the-object-fit) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `object-fit` | 32 | 79 16-79 Only supported for `<img>` elements. | 36 | No | 19 11.6-15 | 10 | 4.4.3 | 32 | 36 | 19 12-14 | 10 | 2.0 | See also -------- * Other image-related CSS properties: [`object-position`](object-position), [`image-orientation`](image-orientation), [`image-rendering`](image-rendering), [`image-resolution`](image-resolution). * [`background-size`](background-size) css ruby-position ruby-position ============= The `ruby-position` CSS property defines the position of a ruby element relatives to its base element. It can be positioned over the element (`over`), under it (`under`), or between the characters on their right side (`inter-character`). Try it ------ Syntax ------ ``` /\* Keyword values \*/ ruby-position: over; ruby-position: under; ruby-position: inter-character; ruby-position: alternate; /\* Global values \*/ ruby-position: inherit; ruby-position: initial; ruby-position: revert; ruby-position: revert-layer; ruby-position: unset; ``` ### Values `over` Is a keyword indicating that the ruby has to be placed over the main text for horizontal scripts and right to it for vertical scripts. `under` Is a keyword indicating that the ruby has to be placed under the main text for horizontal scripts and left to it for vertical scripts. `inter-character` Experimental Is a keyword indicating that the ruby has to be placed between the different characters. `alternate` Experimental Is a keyword indicating that the ruby alternates between over and under, when there are multiple levels of annotation. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `alternate` | | Applies to | ruby annotations containers | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` ruby-position = [[](value_definition_syntax#brackets) alternate [||](value_definition_syntax#double_bar) [[](value_definition_syntax#brackets) over [|](value_definition_syntax#single_bar) under []](value_definition_syntax#brackets) []](value_definition_syntax#brackets) [|](value_definition_syntax#single_bar) inter-character ``` Examples -------- ### Ruby positioned over the text #### HTML ``` <ruby> <rb>超電磁砲</rb> <rp>(</rp><rt>レールガン</rt><rp>)</rp> </ruby> ``` #### CSS ``` ruby { ruby-position: over; } ``` #### Result ### Ruby positioned under the text #### HTML ``` <ruby> <rb>超電磁砲</rb> <rp>(</rp><rt>レールガン</rt><rp>)</rp> </ruby> ``` #### CSS ``` ruby { ruby-position: under; } ``` #### Result ### Ruby alternate #### HTML ``` <ruby> <rb>A</rb><rb>B</rb><rb>C</rb> <rtc>Above</rtc> <rtc>Below</rtc> </ruby> ``` #### CSS ``` ruby { ruby-position: alternate; /\* this is also the initial value \*/ } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Ruby Annotation Layout Module Level 1 # rubypos](https://w3c.github.io/csswg-drafts/css-ruby/#rubypos) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `ruby-position` | 84 1 Implemented as a non-standard, prefixed, version of `ruby-position`, `-webkit-ruby-position`: it has two properties: `before` and `after` (both equivalent, for ltr and rtl scripts to the standard `over` value used with `ruby-align: start`). | 84 79 Implemented as a non-standard, prefixed, version of `ruby-position`, `-webkit-ruby-position`: it has two properties: `before` and `after` (both equivalent, for ltr and rtl scripts to the standard `over` value used with `ruby-align: start`). 12-79 | 38 | No Internet Explorer 9 and later support an old draft values: `inline` (equivalent of having `display: inline` on the ruby), and `above` (synonym of the modern `over`). | 70 15 Implemented as a non-standard, prefixed, version of `ruby-position`, `-webkit-ruby-position`: it has two properties: `before` and `after` (both equivalent, for ltr and rtl scripts to the standard `over` value used with `ruby-align: start`). | 7 Implemented as a non-standard, prefixed, version of `ruby-position`, `-webkit-ruby-position`: it has two properties: `before` and `after` (both equivalent, for ltr and rtl scripts to the standard `over` value used with `ruby-align: start`). | 84 4.4 Implemented as a non-standard, prefixed, version of `ruby-position`, `-webkit-ruby-position`: it has two properties: `before` and `after` (both equivalent, for ltr and rtl scripts to the standard `over` value used with `ruby-align: start`). | 84 18 Implemented as a non-standard, prefixed, version of `ruby-position`, `-webkit-ruby-position`: it has two properties: `before` and `after` (both equivalent, for ltr and rtl scripts to the standard `over` value used with `ruby-align: start`). | 38 | 60 14 Implemented as a non-standard, prefixed, version of `ruby-position`, `-webkit-ruby-position`: it has two properties: `before` and `after` (both equivalent, for ltr and rtl scripts to the standard `over` value used with `ruby-align: start`). | 7 Implemented as a non-standard, prefixed, version of `ruby-position`, `-webkit-ruby-position`: it has two properties: `before` and `after` (both equivalent, for ltr and rtl scripts to the standard `over` value used with `ruby-align: start`). | 14.0 | | `alternate` | No See [bug 1191394](https://crbug.com/1191394). | No See [bug 1191394](https://crbug.com/1191394). | 88 | No | No See [bug 1191394](https://crbug.com/1191394). | No | No See [bug 1191394](https://crbug.com/1191394). | No See [bug 1191394](https://crbug.com/1191394). | 88 | No See [bug 1191394](https://crbug.com/1191394). | No | No See [bug 1191394](https://crbug.com/1191394). | | `inter-character` | No See [bug 1258284](https://crbug.com/1258284). | No See [bug 1258284](https://crbug.com/1258284). | No See [bug 1055672](https://bugzil.la/1055672). | No | No See [bug 1258284](https://crbug.com/1258284). | No | No See [bug 1258284](https://crbug.com/1258284). | No See [bug 1258284](https://crbug.com/1258284). | No See [bug 1055672](https://bugzil.la/1055672). | No See [bug 1258284](https://crbug.com/1258284). | No | No See [bug 1258284](https://crbug.com/1258284). | See also -------- * HTML Ruby elements: [`<ruby>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ruby), [`<rt>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/rt), [`<rp>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/rp), and [`<rtc>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/rtc). * CSS Ruby properties: [`ruby-align`](ruby-align), `ruby-merge`. css -webkit-tap-highlight-color -webkit-tap-highlight-color =========================== **Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future. `-webkit-tap-highlight-color` is a non-standard CSS property that sets the color of the highlight that appears over a link while it's being tapped. The highlighting indicates to the user that their tap is being successfully recognized, and indicates which element they're tapping on. ``` -webkit-tap-highlight-color: red; -webkit-tap-highlight-color: transparent; /\* for removing the highlight \*/ ``` Syntax ------ ### Values A [`<color>`](color_value). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `black` | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` -webkit-tap-highlight-color = <color> ``` Specifications -------------- Not part of any standard. Apple has [a description in the Safari Web Content Guide](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/AdjustingtheTextSize/AdjustingtheTextSize.html#//apple_ref/doc/uid/TP40006510-SW5). Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `-webkit-tap-highlight-color` | 16 | 12 | No | No | 15 | No | ≤37 | 18 | No | 14 | 4 | 1.0 | See also -------- * [WebKit CSS extensions](https://developer.mozilla.org/en-US/docs/Web/CSS/WebKit_Extensions) * Related CSS pseudo-classes: + [`:hover`](:hover) + [`:active`](:active) + [`:visited`](:visited) css @keyframes @keyframes ========== The `@keyframes` 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](css_transitions). Syntax ------ ``` @keyframes slidein { from { transform: translateX(0%); } to { transform: translateX(100%); } } ``` ### Values [`<custom-ident>`](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%`. [`<percentage>`](percentage) A percentage of the time through the animation sequence at which the specified keyframe should occur. Description ----------- To use keyframes, create a `@keyframes` rule with a name that is then used by the [`animation-name`](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 [`CSSKeyframesRule`](https://developer.mozilla.org/en-US/docs/Web/API/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: ``` @keyframes identifier { 0% { top: 0; left: 0; } 30% { top: 50px; } 68%, 72% { left: 50px; } 100% { top: 100px; left: 100%; } } ``` Here, the [`top`](top) property animates using the `0%`, `30%`, and `100%` keyframes, and [`left`](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: ``` @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. ``` @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 ------------- ``` @keyframes = @keyframes <keyframes-name> { [<rule-list>](rule-list) } <keyframes-name> = [<custom-ident>](custom-ident) [|](value_definition_syntax#single_bar) [<string>](string) ``` Examples -------- ### CSS animation examples See [Using CSS animations](css_animations/using_css_animations) for examples. Specifications -------------- | Specification | | --- | | [CSS Animations Level 1 # keyframes](https://w3c.github.io/csswg-drafts/css-animations/#keyframes) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `@keyframes` | 43 1 | 12 | 49 16 5 | 10 | 30 15 12.1-15 12-15 | 9 4 | 43 4.4 | 43 18 | 49 16 5 | 30 14 12.1-14 12-14 | 9 4 | 4.0 1.0 | | `ignore_important_declarations` | 45 | 79 | 19 | No | 32 | 10.1 | 45 | 45 | 19 | 32 | 10.3 | 5.0 | See also -------- * [Using CSS animations](css_animations/using_css_animations) * [`AnimationEvent`](https://developer.mozilla.org/en-US/docs/Web/API/AnimationEvent) css Value definition syntax Value definition syntax ======================= **CSS value definition syntax**, a formal grammar, is used for defining the set of valid values for a CSS property or function. In addition to this syntax, the set of valid values can be further restricted by semantic constraints (for example, for a number to be strictly positive). The definition syntax describes which values are allowed and the interactions between them. A component can be a *keyword*, some characters considered as a *literal*, or a value of a given CSS data type or of another CSS property. Component value types --------------------- ### Keywords #### Generic keywords A keyword with a predefined meaning appears literally, without quotation marks. For example: `auto`, `smaller` or `ease-in`. #### The specific case of `inherit`, `initial` and `unset` All CSS properties accept the keywords `inherit`, `initial` and `unset`, that are defined throughout CSS. They are not shown in the value definition, and are implicitly defined. ### Literals In CSS, a few characters can appear on their own, like the slash ('`/`') or the comma ('`,`'), and are used in a property definition to separate its parts. The comma is often used to separate values in enumerations, or parameters in mathematical-like functions; the slash often separates parts of the value that are semantically different, but have a common syntax. Typically, the slash is used in shorthand properties; to separate components that are of the same type, but belong to different properties. Both symbols appear literally in a value definition. ### Data types #### Basic data types Some kind of data are used throughout CSS, and are defined once for all values in the specification. Called *basic data types*, they are represented with their name surrounded by the symbol '`<`' and '`>`': [`<angle>`](angle), [`<string>`](string), … #### Non-terminal data types Less common data types, called *non-terminal data types*, are also surrounded by '`<`' and '`>`'. Non-terminal data types are of two kinds: * data types *sharing the same name of a property*, put between quotes. In this case, the data type shares the same set of values as the property. They are often used in the definition of shorthand properties. * data type *not sharing the same name of a property*. These data types are very close to the basic data types. They only differ from the basic data types in the physical location of their definition. In this case, the definition is usually physically very close to the definition of the property using them. Component value combinators --------------------------- ### Brackets *Brackets* enclose several entities, combinators, and multipliers, then transform them as a single component. They are used to **group components to bypass the precedence rules**. ``` bold [ thin && <length> ] ``` This example matches the following values: * `bold thin 2vh` * `bold 0 thin` * `bold thin 3.5em` But not: * `thin bold 3em`, as `bold` is juxtaposed with the component defined by the brackets, it must appear before it. ### Juxtaposition Placing several keywords, literals or data types, next to one another, only separated by one or several spaces, is called *juxtaposition*. All juxtaposed components are **mandatory and should appear in the exact order**. ``` bold <length>, thin ``` This example matches the following values: * `bold 1em, thin` * `bold 0, thin` * `bold 2.5cm, thin` * `bold 3vh, thin` But not: * `thin 1em, bold`, as the entities must be in the expressed order * `bold 1em thin`, as the entities are mandatory; the comma, a literal, must be present * `bold 0.5ms, thin`, as the `ms` values are not [`<length>`](length) ### Double ampersand Separating two or more components, by a *double ampersand*, `&&`, means that all these entities are **mandatory but may appear in any order**. ``` bold && <length> ``` This example matches the following values: * `bold 1em` * `bold 0` * `2.5cm bold` * `3vh bold` But not: * `bold`, as both components must appear in the value. * `bold 1em bold`, as both components must appear only one time. **Note:** juxtaposition has precedence over the double ampersand, meaning that `bold thin && <length>` is equivalent to `[ bold thin ] && <length>`. It describes `bold thin <length>` or `<length> bold thin` but not `bold <length> thin`. ### Double bar Separating two or more components by a *double bar*, `||`, means that all entities are options: **at least one of them must be present, and they may appear in any order**. Typically this is used to define the different values of a [shorthand property](shorthand_properties). ``` <'border-width'> || <'border-style'> || <'border-color'> ``` This example matches the following values: * `1em solid blue` * `blue 1em` * `solid 1px yellow` But not: * `blue yellow`, as a component must appear at most one single time. * `bold`, as it isn't a keyword allowed as value of any of the entity. **Note:** the double ampersand has precedence over the double bar, meaning that `bold || thin && <length>` is equivalent to `bold || [ thin && <length> ]`. It describes `bold`, `thin <length>`, `bold thin <length>`, or `thin <length> bold` but not `<length> bold thin` as bold, if not omitted, must be placed before or after the whole `thin && <length>` component. ### Single bar Separating two or more entities by a *single bar*, `|`, means that all entities are exclusive options: **exactly one of these options must be present**. This is typically used to separate a list of possible keywords. ``` <percentage> | <length> | left | center | right | top | bottom ``` This example matches the following values: * `3%` * `0` * `3.5em` * `left` * `center` * `right` * `top` * `bottom` But not: * `center 3%`, as only one of the components must be present. * `3em 4.5em`, as a component must be present at most one time. **Note:** the double bar has precedence over the single bar, meaning that `bold | thin || <length>` is equivalent to `bold | [ thin || <length> ]`. It describes `bold`, `thin`, `<length>`, `<length> thin`, or `thin <length>` but not `bold <length>` as only one entity from each side of the `|` combinator can be present. Component value multipliers --------------------------- A multiplier is a sign that indicates how many times a preceding entity can be repeated. Without a multiplier, an entity must appear exactly one time. Note that multipliers cannot be added and have all precedence over combinators. ### Asterisk (`*`) The *asterisk multiplier* indicates that the entity may appear **zero, one or several times**. ``` bold smaller* ``` This example matches the following values: * `bold` * `bold smaller` * `bold smaller smaller` * `bold smaller smaller smaller`, and so on. But not: * `smaller`, as `bold` is juxtaposed, and must appear before any `smaller` keyword. ### Plus (`+`) The *plus multiplier* indicates that the entity may appear **one or several times**. ``` bold smaller+ ``` This example matches the following values: * `bold smaller` * `bold smaller smaller` * `bold smaller smaller smaller`, and so on. But not: * `bold`, as `smaller` must appear at least one time. * `smaller`, as `bold` is juxtaposed and must appear before any `smaller` keyword. ### Question mark (`?`) The *question mark multiplier* indicates that the entity is optional, and **must appear zero or one time**. ``` bold smaller? ``` This example matches the following values: * `bold` * `bold smaller` But not: * `bold smaller smaller`, as `smaller` must appear at most one time. * `smaller`, as `bold` is juxtaposed and must appear before any `smaller` keyword. ### Curly braces (`{ }`) The *curly braces multiplier*, enclosing two integers separated by a comma, A and B, indicates that the entity **must appear at least A times and at most B times**. ``` bold smaller{1,3} ``` This example matches the following values: * `bold smaller` * `bold smaller smaller` * `bold smaller smaller smaller` But not: * `bold`, as `smaller` must appear at least one time. * `bold smaller smaller smaller smaller`, as `smaller` must appear at most three times. * `smaller`, as `bold` is juxtaposed and must appear before any `smaller` keyword ### Hash mark (`#`) The *hash mark multiplier* indicates that the entity may be repeated one or more times (for example, the plus multiplier), but each occurrence is separated by a comma (','). ``` bold smaller# ``` This example matches the following values: * `bold smaller` * `bold smaller, smaller` * `bold smaller, smaller, smaller`, and so on. But not: * `bold`, as `smaller` must appear at least one time. * `bold smaller smaller smaller`, as the different occurrence of `smaller` must be separated by commas. * `smaller`, as `bold` is juxtaposed and must appear before any `smaller` keyword. The hash mark may optionally be followed by curly braces to indicate precisely how many times the repetition occurs. ``` bold smaller#{1,3} ``` This example matches the following values: * `bold smaller` * `bold smaller, smaller` * `bold smaller, smaller, smaller` But not: * `bold smaller, smaller, smaller, smaller`, as `smaller` must appear at most three times. ``` bold smaller#{2} ``` This example matches the following value: * `bold smaller, smaller` But not: * `bold smaller`, as `smaller` must appear exactly two times. ### Exclamation point (`!`) The *exclamation point multiplier* after a group indicates that the group is required, and must produce at least one value; even if the grammar of the items within the group would otherwise allow the entire contents to be omitted, at least one component value must not be omitted. ``` [ bold? smaller? ]! ``` This example matches the following values: * `bold` * `smaller` * `bold smaller` But not: * neither `bold` nor `smaller`, as one of them must appear. * `smaller bold`, as `bold` is juxtaposed and must appear before the `smaller` keyword. * `bold smaller bold`, as `bold` and `smaller` may only appear once. Summary ------- | Sign | Name | Description | Example | | --- | --- | --- | --- | | Combinators | | --- | | | Juxtaposition | Components are mandatory and should appear in that order | `solid <length>` | | `&&` | Double ampersand | Components are mandatory but may appear in any order | `<length> && <string>` | | `||` | Double bar | At least one of the components must be present, and they may appear in any order. | `<'border-image-outset'> || <'border-image-slice'>` | | `|` | Single bar | Exactly one of the components must be present | `smaller | small | normal | big | bigger` | | `[ ]` | Brackets | Group components to bypass precedence rules | `bold [ thin && <length> ]` | | Multipliers | | | No multiplier | Exactly 1 times | `solid` | | `*` | Asterisk | 0 or more times | `bold smaller*` | | `+` | Plus sign | 1 or more times | `bold smaller+` | | `?` | Question mark | 0 or 1 time (that is *optional)* | `bold smaller?` | | `{A,B}` | Curly braces | At least `A` times, at most `B` times | `bold smaller{1,3}` | | `#` | Hash mark | 1 or more times, but each occurrence separated by a comma ('`,`') | `bold smaller#` | | `!` | Exclamation point | Group must produce at least 1 value | `[ bold? smaller? ]!` | Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # value-defs](https://drafts.csswg.org/css-values/#value-defs) | See also -------- * CSS key concepts: + [CSS syntax](syntax) + [Comments](comments) + [Specificity](specificity) + [Inheritance](inheritance) + [Box model](css_box_model/introduction_to_the_css_box_model) + [Layout modes](layout_mode) + [Visual formatting models](visual_formatting_model) + [Margin collapsing](css_box_model/mastering_margin_collapsing) + Values - [Initial values](initial_value) - [Computed values](computed_value) - [Used values](used_value) - [Actual values](actual_value) + [Value definition syntax](value_definition_syntax) + [Shorthand properties](shorthand_properties) + [Replaced elements](replaced_element)
programming_docs
css justify-tracks justify-tracks ============== **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `justify-tracks` CSS property sets the alignment in the masonry axis for grid containers that have [masonry](css_grid_layout/masonry_layout) in their inline axis. Syntax ------ ``` /\* Keyword values \*/ justify-tracks: start; justify-tracks: space-between; justify-tracks: center; justify-tracks: start, center, end; /\* Global values \*/ justify-tracks: inherit; justify-tracks: initial; justify-tracks: revert; justify-tracks: revert-layer; justify-tracks: unset; ``` The property can take a single value, in which case all tracks are aligned in the same way. If a list of values is used then the first value applies to the first track in the grid axis, the second to the next, and so on. If there are fewer values than tracks, the last value is used for all remaining tracks. If there are more values than tracks, any additional values are ignored. ### Values `start` The items are packed flush to each other toward the start edge of the alignment container in the masonry axis. `end` The items are packed flush to each other toward the end edge of the alignment container in the masonry axis. `center` The items are packed flush to each other toward the center of the alignment container along the masonry axis. `normal` Acts as `start`. `space-between` The items are evenly distributed within the alignment container along the masonry 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 masonry 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 masonry 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` The items stretch along the masonry axis to fill the content box. Items with definite size do not stretch. `left` The items are packed flush to each other toward the left edge of the alignment container. `right` The items are packed flush to each other toward the right edge of the alignment container. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | Grid containers with masonry layout in their inline axis | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` justify-tracks = [[](value_definition_syntax#brackets) normal [|](value_definition_syntax#single_bar) <content-distribution> [|](value_definition_syntax#single_bar) <overflow-position>[?](value_definition_syntax#question_mark) [[](value_definition_syntax#brackets) <content-position> [|](value_definition_syntax#single_bar) left [|](value_definition_syntax#single_bar) right []](value_definition_syntax#brackets) []](value_definition_syntax#brackets)[#](value_definition_syntax#hash_mark) <content-distribution> = space-between [|](value_definition_syntax#single_bar) space-around [|](value_definition_syntax#single_bar) space-evenly [|](value_definition_syntax#single_bar) stretch <overflow-position> = unsafe [|](value_definition_syntax#single_bar) safe <content-position> = center [|](value_definition_syntax#single_bar) start [|](value_definition_syntax#single_bar) end [|](value_definition_syntax#single_bar) flex-start [|](value_definition_syntax#single_bar) flex-end ``` Examples -------- ### Masonry layout with multiple values for justify-tracks Specifications -------------- | Specification | | --- | | [CSS Grid Layout Module Level 3 # tracks-alignment](https://w3c.github.io/csswg-drafts/css-grid-3/#tracks-alignment) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `justify-tracks` | No | No | 77 | No | No | No | No | No | No | No | No | No | See also -------- * Related CSS properties: [`align-tracks`](align-tracks), [`masonry-auto-flow`](masonry-auto-flow) css color color ===== The `color` CSS property sets the foreground [color value](color_value) of an element's text and [text decorations](text-decoration), and sets the [`currentcolor`](color_value#currentcolor_keyword) value. `currentcolor` may be used as an indirect value on *other* properties and is the default for other color properties, such as [`border-color`](border-color). Try it ------ For an overview of using color in HTML, see [Applying color to HTML elements using CSS](css_colors/applying_color). Syntax ------ ``` /\* Keyword values \*/ color: currentcolor; /\* <named-color> values \*/ color: red; color: orange; color: tan; color: rebeccapurple; /\* <hex-color> values \*/ color: #090; color: #009900; color: #090a; color: #009900aa; /\* <rgb()> values \*/ color: rgb(34, 12, 64, 0.6); color: rgba(34, 12, 64, 0.6); color: rgb(34 12 64 / 0.6); color: rgba(34 12 64 / 0.3); color: rgb(34 12 64 / 60%); color: rgba(34.6 12 64 / 30%); /\* <hsl()> values \*/ color: hsl(30, 100%, 50%, 0.6); color: hsla(30, 100%, 50%, 0.6); color: hsl(30 100% 50% / 0.6); color: hsla(30 100% 50% / 0.6); color: hsl(30 100% 50% / 60%); color: hsla(30.2 100% 50% / 60%); /\* <hwb()> values \*/ color: hwb(90 10% 10%); color: hwb(90 10% 10% / 0.5); color: hwb(90deg 10% 10%); color: hwb(1.5708rad 60% 0%); color: hwb(0.25turn 0% 40% / 50%); /\* Global values \*/ color: inherit; color: initial; color: revert; color: revert-layer; color: unset; ``` The `color` property is specified as a single [`<color>`](color_value) value. Note that the value must be a uniform [`color`](color). It can't be a [`<gradient>`](gradient), which is actually a type of [`<image>`](image). ### Values [`<color>`](color_value) Sets the color of the textual and decorative parts of the element. Accessibility concerns ---------------------- It is important to ensure that the contrast ratio between the color of the text and the background the text is placed over is high enough that people experiencing low vision conditions will be able to read the content of the page. Color contrast ratio is determined by comparing the luminosity of the text and background color values. In order to meet current [Web Content Accessibility Guidelines (WCAG)](https://www.w3.org/WAI/standards-guidelines/wcag/), a ratio of 4.5:1 is required for text content and 3:1 for larger text such as headings. Large text is defined as 18.66px and [bold](font-weight) or larger, or 24px or larger. * [WebAIM: Color Contrast Checker](https://webaim.org/resources/contrastchecker/) * [MDN Understanding WCAG, Guideline 1.4 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background) * [Understanding Success Criterion 1.4.3 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html) Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `canvastext` | | Applies to | all elements and text. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | computed color | | Animation type | by computed value type | Formal syntax ------------- ``` color = [<color>](color_value) ``` Examples -------- ### Making text red The following are all ways to make a paragraph's text red: ``` p { color: red; } p { color: #f00; } p { color: #ff0000; } p { color: rgb(255,0,0); } p { color: rgb(100%, 0%, 0%); } p { color: hsl(0, 100%, 50%); } /\* 50% translucent \*/ p { color: #ff000080; } p { color: rgba(255, 0, 0, 0.5); } p { color: hsla(0, 100%, 50%, 0.5); } ``` Specifications -------------- | Specification | | --- | | [CSS Color Module Level 4 # the-color-property](https://w3c.github.io/csswg-drafts/css-color/#the-color-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `color` | 1 | 12 | 1 | 3 | 3.5 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | See also -------- * The [`<color>`](color_value) data type * Other color-related properties: [`background-color`](background-color), [`border-color`](border-color), [`outline-color`](outline-color), [`text-decoration-color`](text-decoration-color), [`text-emphasis-color`](text-emphasis-color), [`text-shadow`](text-shadow), [`caret-color`](caret-color), [`column-rule-color`](column-rule-color), and [`print-color-adjust`](print-color-adjust) * [Applying color to HTML elements using CSS](css_colors/applying_color) css box-shadow box-shadow ========== The `box-shadow` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property adds shadow effects around an element's frame. You can set multiple effects separated by commas. A box shadow is described by X and Y offsets relative to the element, blur and spread radius, and color. Try it ------ The `box-shadow` property enables you to cast a drop shadow from the frame of almost any element. If a [`border-radius`](border-radius) is specified on the element with a box shadow, the box shadow takes on the same rounded corners. The z-ordering of multiple box shadows is the same as multiple [text shadows](text-shadow) (the first specified shadow is on top). [Box-shadow generator](css_backgrounds_and_borders/box-shadow_generator) is an interactive tool allowing you to generate a `box-shadow`. Syntax ------ ``` /\* Keyword values \*/ box-shadow: none; /\* offset-x | offset-y | color \*/ box-shadow: 60px -16px teal; /\* offset-x | offset-y | blur-radius | color \*/ box-shadow: 10px 5px 5px black; /\* offset-x | offset-y | blur-radius | spread-radius | color \*/ box-shadow: 2px 2px 2px 1px rgba(0, 0, 0, 0.2); /\* inset | offset-x | offset-y | color \*/ box-shadow: inset 5em 1em gold; /\* Any number of shadows, separated by commas \*/ box-shadow: 3px 3px red, -1em 0 0.4em olive; /\* Global values \*/ box-shadow: inherit; box-shadow: initial; box-shadow: revert; box-shadow: revert-layer; box-shadow: unset; ``` Specify a single box-shadow using: * Two, three, or four [`<length>`](length) values. + If only two values are given, they are interpreted as `<offset-x>` and `<offset-y>` values. + If a third value is given, it is interpreted as a `<blur-radius>`. + If a fourth value is given, it is interpreted as a `<spread-radius>`. * Optionally, the `inset` keyword. * Optionally, a [`<color>`](#color) value. To specify multiple shadows, provide a comma-separated list of shadows. ### Values `inset` If not specified (default), the shadow is assumed to be a drop shadow (as if the box were raised above the content). The presence of the `inset` keyword changes the shadow to one inside the frame (as if the content was debossed inside the box). Inset shadows are drawn inside the border (even transparent ones), above the background, but below content. `<offset-x>` The [`<length>`](length) value specifies the horizontal distance. Negative values place the shadow to the left of the element. `<offset-y>` The [`<length>`](length) values specifies the vertical distance. Negative values place the shadow above the element. If both `<offset-x>` and `<offset-y>` are set to `0`, the shadow is placed behind the element (and may generate a blur effect if `<blur-radius>` and/or `<spread-radius>` is set). `<blur-radius>` This is a third [`<length>`](length) value. The larger this value, the bigger the blur, so the shadow becomes bigger and lighter. Negative values are not allowed. If not specified, it will be `0` (the shadow's edge is sharp). The specification does not include an exact algorithm for how the blur radius should be calculated, however, it does elaborate as follows: > …for a long, straight shadow edge, this should create a color transition the length of the blur distance that is perpendicular to and centered on the shadow's edge, and that ranges from the full shadow color at the radius endpoint inside the shadow to fully transparent at the endpoint outside it. > > `<spread-radius>` This is a fourth [`<length>`](length) value. Positive values will cause the shadow to expand and grow bigger, negative values will cause the shadow to shrink. If not specified, it will be `0` (the shadow will be the same size as the element). `<color>` See [`<color>`](color_value) values for possible keywords and notations. If not specified, it defaults to [`currentcolor`](color_value#currentcolor_keyword). ### Interpolation When animating shadows, such as when multiple shadow values on a box transition to new values on hover, the values are interpolated. [Interpolation](https://developer.mozilla.org/en-US/docs/Glossary/Interpolation) determines intermediate values of properties, such as the blur radius, spread radius, and color, as shadows transition. For each shadow in a list of shadows, the color, x, y, blur, and spread transition; the color as [`<color>`](color_value), and the other values as [`<length>`](length)s. In interpolating multiple shadows between two comma-separated lists of multiple box shadows, the shadows are paired, in order, with interpolation occurring between paired shadows. If the lists of shadows have different lengths, then the shorter list is padded at the end with shadows whose color is `transparent`, and X, Y, and blur are `0`, with the inset, or lack of inset, being set to match. If, in any pair of shadows, one has `inset` set and the other is does not, the entire shadow list is uninterpolated; the shadows will change to the new values without an animating effect. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | any length made absolute; any specified color computed; otherwise as specified | | Animation type | a [shadow list](box-shadow#Interpolation) | Formal syntax ------------- ``` box-shadow = none [|](value_definition_syntax#single_bar) <shadow>[#](value_definition_syntax#hash_mark) <shadow> = [<color>](color_value)[?](value_definition_syntax#question_mark) [&&](value_definition_syntax#double_ampersand) [[](value_definition_syntax#brackets) [<length>](length)[{2}](value_definition_syntax#curly_braces) [<length [0,∞]>](length)[?](value_definition_syntax#question_mark) [<length>](length)[?](value_definition_syntax#question_mark) []](value_definition_syntax#brackets) [&&](value_definition_syntax#double_ampersand) inset[?](value_definition_syntax#question_mark) ``` Examples -------- ### Setting three shadows In this example, we include three shadows: an inset shadow, a regular drop shadow, and a 2px shadow that creates a border effect (we could have used an [`outline`](outline) instead for that third shadow). #### HTML ``` <blockquote> <q> You may shoot me with your words,<br /> You may cut me with your eyes,<br /> You may kill me with your hatefulness,<br /> But still, like air, I'll rise. </q> <p>&mdash; Maya Angelou</p> </blockquote> ``` #### CSS ``` blockquote { padding: 20px; box-shadow: inset 0 -3em 3em rgba(0, 0, 0, 0.1), 0 0 0 2px rgb(255, 255, 255), 0.3em 0.3em 1em rgba(0, 0, 0, 0.3); } ``` #### Result ### Setting zero for offset and blur When the `x-offset`, `y-offset`, and `blur` are all zero, the box shadow will be a solid-colored outline of equal-size on all sides. The shadows are drawn back to front, so the first shadow sits on top of subsequent shadows. When the `border-radius` is set to 0, as is the default, the corners of the shadow will be, well, corners. Had we put in a `border-radius` of any other value, the corners would have been rounded. We added a margin the size of the widest box-shadow to ensure the shadow doesn't overlap adjacent elements or go beyond the border of the containing box. A box-shadow does not impact [box model](css_box_model) dimensions. #### HTML ``` <div><p>Hello World</p></div> ``` #### CSS ``` p { box-shadow: 0 0 0 2em #f4aab9, 0 0 0 4em #66ccff; margin: 4em; padding: 1em; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # box-shadow](https://w3c.github.io/csswg-drafts/css-backgrounds/#box-shadow) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `box-shadow` | 10 Shadows affect layout in this browser. For example, if you cast an outer shadow to a box with a `width` of `100%`, then you'll see a scrollbar. 1 | 12 | 49 4 Shadows affect layout in this browser. For example, if you cast an outer shadow to a box with a `width` of `100%`, then you'll see a scrollbar. 3.5-13 | 9 ["To use `box-shadow` in Internet Explorer 9 or later, you must set [`border-collapse`](https://developer.mozilla.org/docs/Web/CSS/border-collapse) to `separate`.", "Since version 5.5, Internet Explorer supports Microsoft's [DropShadow](https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/ms532985(v=vs.85)) and [Shadow Filter](https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/ms533086(v=vs.85)). You can use this proprietary extension to cast a drop shadow (though the syntax and the effect are different from CSS3)"] | 10.5 Shadows affect layout in this browser. For example, if you cast an outer shadow to a box with a `width` of `100%`, then you'll see a scrollbar. | 5.1 Shadows affect layout in this browser. For example, if you cast an outer shadow to a box with a `width` of `100%`, then you'll see a scrollbar. 3 | ≤37 Shadows affect layout in this browser. For example, if you cast an outer shadow to a box with a `width` of `100%`, then you'll see a scrollbar. ≤37 | 18 Shadows affect layout in this browser. For example, if you cast an outer shadow to a box with a `width` of `100%`, then you'll see a scrollbar. 18 | 49 4 Shadows affect layout in this browser. For example, if you cast an outer shadow to a box with a `width` of `100%`, then you'll see a scrollbar. 4-14 | 14 Shadows affect layout in this browser. For example, if you cast an outer shadow to a box with a `width` of `100%`, then you'll see a scrollbar. 14 | 5 Shadows affect layout in this browser. For example, if you cast an outer shadow to a box with a `width` of `100%`, then you'll see a scrollbar. 1 | 1.0 Shadows affect layout in this browser. For example, if you cast an outer shadow to a box with a `width` of `100%`, then you'll see a scrollbar. 1.0 | | `inset` | 10 1 | 12 | 4 3.5-13 | 9 ["To use `box-shadow` in Internet Explorer 9 or later, you must set [`border-collapse`](https://developer.mozilla.org/docs/Web/CSS/border-collapse) to `separate`.", "`inset` must be the last keyword in the declaration."] | 10.5 | 5.1 5 | ≤37 ≤37 | 18 18 | 4 4-14 | 14 14 | 5 4.2 | 1.0 1.0 | | `multiple_shadows` | 10 1 | 12 | 4 3.5-13 | 9 To use `box-shadow` in Internet Explorer 9 or later, you must set [`border-collapse`](https://developer.mozilla.org/docs/Web/CSS/border-collapse) to `separate`. | 10.5 | 5.1 3 | ≤37 ≤37 | 18 18 | 4 4-14 | 14 14 | 5 1 | 1.0 1.0 | | `spread_radius` | 10 1 | 12 | 4 3.5-13 | 9 To use `box-shadow` in Internet Explorer 9 or later, you must set [`border-collapse`](https://developer.mozilla.org/docs/Web/CSS/border-collapse) to `separate`. | 10.5 | 5.1 5 | ≤37 ≤37 | 18 18 | 4 4-14 | 14 14 | 5 4.2 | 1.0 1.0 | See also -------- * The [`<color>`](color_value) data type (for specifying the shadow color) * [`text-shadow`](text-shadow) * [`drop-shadow()`](filter-function/drop-shadow) * [Applying color to HTML elements using CSS](css_colors/applying_color)
programming_docs
css CSS Overflow CSS Overflow ============ The **CSS Overflow** module contains the features of CSS relating to scrollable overflow handling in visual media. In CSS overflow happens when the content of a box extends past one or more of the box's edges. Ink overflow and scrollable overflow ------------------------------------ There are two types of overflow that you might encounter in CSS. The first is described as **ink overflow**. This is the overflow of painting effects which do not affect layout or otherwise extend the scrollable overflow region, such as box shadows, border images, text decoration, overhanging glyphs, outlines, etc. The overflow that we sometimes need to manage in CSS is described as **scrollable overflow**. This is the content appearing outside of the box for which scrolling mechanisms need to be provided. The overflow properties are how we can control what happens when content overflows a box. Basic example ------------- The following interactive example shows how changing the value of the `overflow` property, changes how the overflow of a fixed height box is dealt with. Try it ------ Reference --------- ### CSS properties * [`overflow`](overflow) * [`overflow-block`](overflow-block) * [`overflow-inline`](overflow-inline) * [`overflow-x`](overflow-x) * [`overflow-y`](overflow-y) * [`text-overflow`](text-overflow) * `block-overflow` Experimental * `line-clamp` Experimental * `max-lines` Experimental * `continue` Experimental ### Non-standard properties * [`-webkit-line-clamp`](-webkit-line-clamp) Non-standard Specifications -------------- | Specification | | --- | | [CSS Overflow Module Level 3 # propdef-overflow](https://drafts.csswg.org/css-overflow/#propdef-overflow) | See also -------- * Properties for controlling the look of scrollbars [`scrollbar-width`](scrollbar-width) and [`scrollbar-color`](scrollbar-color) * How to [Debug scrollable overflow](https://firefox-source-docs.mozilla.org/devtools-user/page_inspector/how_to/debug_scrollable_overflow/index.html). css :active :active ======= The `:active` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) represents an element (such as a button) that is being activated by the user. When using a mouse, "activation" typically starts when the user presses down the primary mouse button. Try it ------ The `:active` pseudo-class is commonly used on [`<a>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a) and [`<button>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button) elements. Other common targets of this pseudo-class include elements that are *contained in* an activated element, and form elements that are being activated through their associated [`<label>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label). Styles defined by the `:active` pseudo-class will be overridden by any subsequent link-related pseudo-class ([`:link`](:link), [`:hover`](:hover), or [`:visited`](:visited)) that has at least equal specificity. To style links appropriately, put the `:active` rule after all other link-related rules, as defined by the *LVHA-order*: `:link` — `:visited` — `:hover` — `:active`. **Note:** On systems with multi-button mice, CSS specifies that the `:active` pseudo-class must only apply to the primary button; on right-handed mice, this is typically the leftmost button. Syntax ------ ``` :active ``` Examples -------- ### Active links #### HTML ``` <p> This paragraph contains a link: <a href="#">This link will turn red while you click on it.</a> The paragraph will get a gray background while you click on it or the link. </p> ``` #### CSS ``` /\* Unvisited links \*/ a:link { color: blue; } /\* Visited links \*/ a:visited { color: purple; } /\* Hovered links \*/ a:hover { background: yellow; } /\* Active links \*/ a:active { color: red; } /\* Active paragraphs \*/ p:active { background: #eee; } ``` #### Result ### Active form elements #### HTML ``` <form> <label for="my-button">My button: </label> <button id="my-button" type="button">Try Clicking Me or My Label!</button> </form> ``` #### CSS ``` form :active { color: red; } form button { background: white; } ``` #### Result Specifications -------------- | Specification | | --- | | [HTML Standard # selector-active](https://html.spec.whatwg.org/multipage/semantics-other.html#selector-active) | | [Selectors Level 4 # the-active-pseudo](https://w3c.github.io/csswg-drafts/selectors/#the-active-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:active` | 1 | 12 | 1 | 4 | 5 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `non_a_elements` | 1 | 12 | 1 | 8 | 7 | 1 | 4.4 | 18 | 4 | 14 | 1 By default, Safari on iOS does not use the [`:active`](https://developer.mozilla.org/docs/Web/CSS/:active) state unless there is a [`touchstart`](https://developer.mozilla.org/docs/Web/Reference/Events/touchstart) event handler on the relevant element or on the [`<body>`](https://developer.mozilla.org/docs/Web/HTML/Element/body) element. | 1.0 | See also -------- * Link-related pseudo-classes: [`:link`](:link), [`:visited`](:visited), and [`:hover`](:hover) css row-gap row-gap ======= The `row-gap` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the size of the gap ([gutter](https://developer.mozilla.org/en-US/docs/Glossary/Gutters)) between an element's rows. Try it ------ Syntax ------ ``` /\* <length> values \*/ row-gap: 20px; row-gap: 1em; row-gap: 3vmin; row-gap: 0.5cm; /\* <percentage> value \*/ row-gap: 10%; /\* Global values \*/ row-gap: inherit; row-gap: initial; row-gap: revert; row-gap: revert-layer; row-gap: unset; ``` Note that `grid-row-gap` is an alias for this property. ### Values `<length-percentage>` Is the width of the gutter separating the rows. [`<percentage>`](percentage) values are relative to the dimension of the element. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | multi-column elements, flex containers, grid containers | | [Inherited](inheritance) | no | | Percentages | refer to corresponding dimension of the content area | | [Computed value](computed_value) | as specified, with <length>s made absolute, and normal computing to zero except on multi-column elements | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` row-gap = normal [|](value_definition_syntax#single_bar) [<length-percentage [0,∞]>](length-percentage) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Flex layout #### HTML ``` <div id="flexbox"> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> </div> ``` #### CSS ``` #flexbox { display: flex; flex-wrap: wrap; width: 300px; row-gap: 20px; } #flexbox > div { border: 1px solid green; background-color: lime; flex: 1 1 auto; width: 100px; height: 50px; } ``` #### Result ### Grid layout #### HTML ``` <div id="grid"> <div></div> <div></div> <div></div> </div> ``` #### CSS ``` #grid { display: grid; height: 200px; grid-template-columns: 200px; grid-template-rows: repeat(3, 1fr); row-gap: 20px; } #grid > div { border: 1px solid green; background-color: lime; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Box Alignment Module Level 3 # column-row-gap](https://w3c.github.io/csswg-drafts/css-align/#column-row-gap) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `row-gap` | 47 | 16 | 52 | No | 34 | 10.1 | 47 | 47 | 52 | 34 | 10.3 | 5.0 | | `flex_context` | 84 | 84 | 63 | No | 70 | 14.1 | 84 | 84 | 63 | 60 | 14.5 | 14.0 | | `grid_context` | 66 57 | 16 16 | 61 52 | No | 53 44 | 12 10.1 | 66 57 | 66 57 | 61 52 | 47 43 | 12 10.3 | 9.0 6.0 | See also -------- * Related CSS properties: [`column-gap`](column-gap), [`gap`](gap) * Grid Layout Guide: *[Basic concepts of grid layout - Gutters](css_grid_layout/basic_concepts_of_grid_layout#gutters)* css sin() sin() ===== The `sin()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](css_functions) is a trigonometric function that returns the sine of a number, which is a value between `-1` and `1`. The function contains a single calculation that must resolve to either a [`<number>`](number) or an [`<angle>`](angle) by interpreting the result of the argument as radians. That is, `sin(45deg)`, `sin(0.125turn)`, and `sin(3.14159 / 4)` all represent the same value, approximately `0.707`. Syntax ------ ``` /\* Single <angle> values \*/ width: calc(100px * sin(45deg)); width: calc(100px * sin(0.25turn)); width: calc(100px * sin(1.0471967rad)); /\* Single <number> values \*/ width: calc(100px * sin(63.673)); width: calc(100px * sin(2 * 0.125)); /\* Other values \*/ width: calc(100px * sin(pi / 2)); width: calc(100px * sin(e / 4)); ``` ### Parameter The `sin(angle)` function accepts only one value as its parameter. `angle` A calculation which resolves to a [`<number>`](number) or an [`<angle>`](angle). When specifying unitless numbers they are interpreted as a number of radians, representing an [`<angle>`](angle) ### Return value The sine of an `angle` will always return a number between `−1` and `1`. * If `angle` is `infinity`, `-infinity`, or `NaN`, the result is `NaN`. * If `angle` is `0⁻`, the result is `0⁻`. ### Formal syntax ``` <sin()> = sin( <calc-sum> ) <calc-sum> = <calc-product> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '+' [|](value_definition_syntax#single_bar) '-' []](value_definition_syntax#brackets) <calc-product> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-product> = <calc-value> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '*' [|](value_definition_syntax#single_bar) '/' []](value_definition_syntax#brackets) <calc-value> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-value> = [<number>](number) [|](value_definition_syntax#single_bar) [<dimension>](dimension) [|](value_definition_syntax#single_bar) [<percentage>](percentage) [|](value_definition_syntax#single_bar) <calc-constant> [|](value_definition_syntax#single_bar) ( <calc-sum> ) <calc-constant> = e [|](value_definition_syntax#single_bar) pi [|](value_definition_syntax#single_bar) infinity [|](value_definition_syntax#single_bar) -infinity [|](value_definition_syntax#single_bar) NaN ``` Examples -------- ### Boxes Size For example, when creating a 100x100 box based on external parameters, in this case `sin(90deg)`. Thus `sin(90deg)` will return `1` making the box `100px` width and `100px` height. ``` div { background-color: red; width: calc(sin(90deg) * 100px); height: calc(sin(90deg) * 100px); } ``` ### Controlling Animation Duration Another use-case is to control the [`animation-duration`](animation-duration). Reducing duration based on the sine value. In this case, the animation duration will be `1s`. ``` div { animation-name: myAnimation; animation-duration: calc(sin(0.25turn) * 1s); } ``` Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # trig-funcs](https://w3c.github.io/csswg-drafts/css-values/#trig-funcs) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `sin` | No | No | 108 | No | No | 15.4 | No | No | 108 | No | 15.4 | No | See also -------- * [`cos()`](cos) * [`tan()`](tan) * [`asin()`](asin) * [`acos()`](acos) * [`atan()`](atan) * [`atan2()`](atan2) css <filter-function> <filter-function> ================= The `<filter-function>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) represents a graphical effect that can change the appearance of an input image. It is used in the [`filter`](filter) and [`backdrop-filter`](backdrop-filter) properties. Syntax ------ The `<filter-function>` data type is specified using one of the filter functions listed below. Each function requires an argument which, if invalid, results in no filter being applied. [`blur()`](filter-function/blur) Blurs the image. [`brightness()`](filter-function/brightness) Makes the image brighter or darker. [`contrast()`](filter-function/contrast) Increases or decreases the image's contrast. [`drop-shadow()`](filter-function/drop-shadow) Applies a drop shadow behind the image. [`grayscale()`](filter-function/grayscale) Converts the image to grayscale. [`hue-rotate()`](filter-function/hue-rotate) Changes the overall hue of the image. [`invert()`](filter-function/invert) Inverts the colors of the image. [`opacity()`](filter-function/opacity) Makes the image transparent. [`saturate()`](filter-function/saturate) Super-saturates or desaturates the input image. [`sepia()`](filter-function/sepia) Converts the image to sepia. Formal syntax ------------- ``` <filter-function> = <blur()> [|](value_definition_syntax#single_bar) <brightness()> [|](value_definition_syntax#single_bar) <contrast()> [|](value_definition_syntax#single_bar) <drop-shadow()> [|](value_definition_syntax#single_bar) <grayscale()> [|](value_definition_syntax#single_bar) <hue-rotate()> [|](value_definition_syntax#single_bar) <invert()> [|](value_definition_syntax#single_bar) <opacity()> [|](value_definition_syntax#single_bar) <sepia()> [|](value_definition_syntax#single_bar) <saturate()> <blur()> = blur( [<length>](length)[?](value_definition_syntax#question_mark) ) <brightness()> = brightness( [[](value_definition_syntax#brackets) [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <contrast()> = contrast( [[](value_definition_syntax#brackets) [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <drop-shadow()> = drop-shadow( [[](value_definition_syntax#brackets) [<color>](color_value)[?](value_definition_syntax#question_mark) [&&](value_definition_syntax#double_ampersand) [<length>](length)[{2,3}](value_definition_syntax#curly_braces) []](value_definition_syntax#brackets) ) <grayscale()> = grayscale( [[](value_definition_syntax#brackets) [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <hue-rotate()> = hue-rotate( [[](value_definition_syntax#brackets) [<angle>](angle) [|](value_definition_syntax#single_bar) [<zero>](zero) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <invert()> = invert( [[](value_definition_syntax#brackets) [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <opacity()> = opacity( [[](value_definition_syntax#brackets) [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <sepia()> = sepia( [[](value_definition_syntax#brackets) [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <saturate()> = saturate( [[](value_definition_syntax#brackets) [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) ``` Examples -------- ### Filter function comparison This example provides a simple graphic, along with a select menu to allow you to choose between the different types of filter function, and a slider to allow you to vary the values used inside the filter function. Updating the controls updates the filter effect in real time, allowing you to investigate the effects of different filters. #### HTML ``` <div></div> <ul> <li> <label for="filter-select">Choose a filter function:</label> <select id="filter-select"> <option selected>blur</option> <option>brightness</option> <option>contrast</option> <option>drop-shadow</option> <option>grayscale</option> <option>hue-rotate</option> <option>invert</option> <option>opacity</option> <option>saturate</option> <option>sepia</option> </select> </li> <li><input type="range" /><output></output></li> <li> <p>Current value: <code></code></p> </li> </ul> ``` #### CSS ``` div { width: 300px; height: 300px; background: url(https://media.prod.mdn.mozit.cloud/attachments/2020/07/29/17350/3b4892b7e820122ac6dd7678891d4507/firefox.png) no-repeat center; } li { display: flex; align-items: center; justify-content: center; margin-bottom: 20px; } input { width: 60%; } output { width: 5%; text-align: center; } select { width: 40%; margin-left: 2px; } ``` #### JavaScript ``` const selectElem = document.querySelector('select'); const divElem = document.querySelector('div'); const slider = document.querySelector('input'); const output = document.querySelector('output'); const curValue = document.querySelector('p code'); selectElem.addEventListener('change', () => { setSlider(selectElem.value); setDiv(selectElem.value); }); slider.addEventListener('input', () => { setDiv(selectElem.value); }); function setSlider(filter) { if (filter === 'blur') { slider.value = 0; slider.min = 0; slider.max = 30; slider.step = 1; slider.setAttribute('data-unit', 'px'); } else if (filter === 'brightness' || filter === 'contrast' || filter === 'saturate') { slider.value = 1; slider.min = 0; slider.max = 4; slider.step = 0.05; slider.setAttribute('data-unit', ''); } else if (filter === 'drop-shadow') { slider.value = 0; slider.min = -20; slider.max = 40; slider.step = 1; slider.setAttribute('data-unit', 'px'); } else if (filter === 'opacity') { slider.value = 1; slider.min = 0; slider.max = 1; slider.step = 0.01; slider.setAttribute('data-unit', ''); } else if (filter === 'grayscale' || filter === 'invert' || filter === 'sepia') { slider.value = 0; slider.min = 0; slider.max = 1; slider.step = 0.01; slider.setAttribute('data-unit', ''); } else if (filter === 'hue-rotate') { slider.value = 0; slider.min = 0; slider.max = 360; slider.step = 1; slider.setAttribute('data-unit', 'deg'); } } function setDiv(filter) { const unit = slider.getAttribute('data-unit'); const offset = `${Math.round(slider.value)}${unit}`; const radius = `${Math.round(Math.abs(slider.value / 2))}${unit}`; divElem.style.filter = filter === 'drop-shadow' ? `${selectElem.value}(${offset}${offset}${radius})` : `${selectElem.value}(${slider.value}${unit})`; updateOutput(); updateCurValue(); } function updateOutput() { output.textContent = slider.value; } function updateCurValue() { curValue.textContent = `filter: ${divElem.style.filter}`; } setSlider(selectElem.value); setDiv(selectElem.value); ``` #### Result Specifications -------------- | Specification | | --- | | [Filter Effects Module Level 1 # typedef-filter-function](https://drafts.fxtf.org/filter-effects/#typedef-filter-function) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `filter-function` | 18 | 12 | 35 | No | 15 | 6 | 4.4 | 53 | 35 | 14 | 6 | 6.0 | | `blur` | 18 | 12 | 35 | No | 15 | 6 | 4.4 | 53 | 35 | 14 | 6 | 6.0 | | `brightness` | 18 | 12 | 35 | No | 15 | 6 | 4.4 | 53 | 35 | 14 | 6 | 6.0 | | `contrast` | 18 | 12 | 35 | No | 15 | 6 | 4.4 | 53 | 35 | 14 | 6 | 6.0 | | `drop-shadow` | 18 | 12 | 35 | No | 15 | 6 | 4.4 | 53 | 35 | 14 | 6 | 6.0 | | `grayscale` | 18 | 12 | 35 | No | 15 | 6 | 4.4 | 53 | 35 | 14 | 6 | 6.0 | | `hue-rotate` | 18 | 12 | 35 | No | 15 | 6 | 4.4 | 53 | 35 | 14 | 6 | 6.0 | | `invert` | 18 | 12 | 35 | No | 15 | 6 | 4.4 | 53 | 35 | 14 | 6 | 6.0 | | `opacity` | 18 | 12 | 35 | No | 15 | 6 | 4.4 | 53 | 35 | 14 | 6 | 6.0 | | `saturate` | 18 | 12 | 35 | No | 15 | 6 | 4.4 | 53 | 35 | 14 | 6 | 6.0 | | `sepia` | 18 | 12 | 35 | No | 15 | 6 | 4.4 | 53 | 35 | 14 | 6 | 6.0 | See also -------- * Properties that use this data type: [`filter`](filter) and [`backdrop-filter`](backdrop-filter)
programming_docs
css background-repeat background-repeat ================= The `background-repeat` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets how background images are repeated. A background image can be repeated along the horizontal and vertical axes, or not repeated at all. Try it ------ By default, the repeated images are clipped to the size of the element, but they can be scaled to fit (using `round`) or evenly distributed from end to end (using `space`). Syntax ------ ``` /\* Keyword values \*/ background-repeat: repeat-x; background-repeat: repeat-y; background-repeat: repeat; background-repeat: space; background-repeat: round; background-repeat: no-repeat; /\* Two-value syntax: horizontal | vertical \*/ background-repeat: repeat space; background-repeat: repeat repeat; background-repeat: round space; background-repeat: no-repeat round; /\* Global values \*/ background-repeat: inherit; background-repeat: initial; background-repeat: revert; background-repeat: revert-layer; background-repeat: unset; ``` ### Values `<repeat-style>` The one-value syntax is a shorthand for the full two-value syntax: | | | | --- | --- | | **Single value** | **Two-value equivalent** | | `repeat-x` | `repeat no-repeat` | | `repeat-y` | `no-repeat repeat` | | `repeat` | `repeat repeat` | | `space` | `space space` | | `round` | `round round` | | `no-repeat` | `no-repeat no-repeat` | In the two-value syntax, the first value represents the horizontal repetition behavior and the second value represents the vertical behavior. Here is an explanation of how each option works for either direction: | | | | --- | --- | | `repeat` | The image is repeated as much as needed to cover the whole background image painting area. The last image will be clipped if it doesn't fit. | | `space` | The image is repeated as much as possible without clipping. The first and last images are pinned to either side of the element, and whitespace is distributed evenly between the images. The [`background-position`](background-position) property is ignored unless only one image can be displayed without clipping. The only case where clipping happens using `space` is when there isn't enough room to display one image. | | `round` | As the allowed space increases in size, the repeated images will stretch (leaving no gaps) until there is room (space left >= half of the image width) for another one to be added. When the next image is added, all of the current ones compress to allow room. Example: An image with an original width of 260px, repeated three times, might stretch until each repetition is 300px wide, and then another image will be added. They will then compress to 225px. | | `no-repeat` | The image is not repeated (and hence the background image painting area will not necessarily be entirely covered). The position of the non-repeated background image is defined by the [`background-position`](background-position) CSS property. | Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `repeat` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | a list, each item consisting of two keywords, one per dimension | | Animation type | discrete | Formal syntax ------------- ``` background-repeat = <repeat-style>[#](value_definition_syntax#hash_mark) <repeat-style> = repeat-x [|](value_definition_syntax#single_bar) repeat-y [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) repeat [|](value_definition_syntax#single_bar) space [|](value_definition_syntax#single_bar) round [|](value_definition_syntax#single_bar) no-repeat []](value_definition_syntax#brackets)[{1,2}](value_definition_syntax#curly_braces) ``` Examples -------- ### Setting background-repeat #### HTML ``` <ol> <li> no-repeat <div class="one"></div> </li> <li> repeat <div class="two"></div> </li> <li> repeat-x <div class="three"></div> </li> <li> repeat-y <div class="four"></div> </li> <li> space <div class="five"></div> </li> <li> round <div class="six"></div> </li> <li> repeat-x, repeat-y (multiple images) <div class="seven"></div> </li> </ol> ``` #### CSS ``` /\* Shared for all DIVS in example \*/ ol, li { margin: 0; padding: 0; } li { margin-bottom: 12px; } div { background-image: url(starsolid.gif); width: 160px; height: 70px; } /\* Background repeats \*/ .one { background-repeat: no-repeat; } .two { background-repeat: repeat; } .three { background-repeat: repeat-x; } .four { background-repeat: repeat-y; } .five { background-repeat: space; } .six { background-repeat: round; } /\* Multiple images \*/ .seven { background-image: url(starsolid.gif), url(favicon32.png); background-repeat: repeat-x, repeat-y; height: 144px; } ``` #### Result In this example, each list item is matched with a different value of `background-repeat`. Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # the-background-repeat](https://w3c.github.io/csswg-drafts/css-backgrounds/#the-background-repeat) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `2-value` | 3 | 12 | 13 | 9 | 10.5 | 5 | ≤37 | 18 | 14 | 11 | 4 | 1.0 | | `background-repeat` | 1 | 12 | 1 | 4 | 3.5 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `multiple_backgrounds` | 1 | 12 | 3.6 | 9 | 10.5 | 1.3 | 4.4 | 18 | 4 | 11 | 1 | 1.0 | | `round_space` | 30 | 12 | 49 | 9 | 17 10.5-15 | 8 | 4.4 | 30 | 49 | 18 | 8 | 2.0 | See also -------- * [Using multiple backgrounds](css_backgrounds_and_borders/using_multiple_backgrounds) css cursor cursor ====== The `cursor` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the mouse cursor, if any, to show when the mouse pointer is over an element. The cursor setting should inform users of the mouse operations that can be performed at the current location, including: text selection, activating help or context menus, copying content, resizing tables, and so on. You can specify either the *type* of cursor using a keyword, or load a specific icon to use (with optional fallback images and mandatory keyword as a final fallback). Try it ------ Syntax ------ ``` /\* Keyword value \*/ cursor: auto; cursor: pointer; /\* … \*/ cursor: zoom-out; /\* URL with mandatory keyword fallback \*/ cursor: url(hand.cur), pointer; /\* URL and coordinates, with mandatory keyword fallback \*/ cursor: url(cursor\_1.png) 4 12, auto; cursor: url(cursor\_2.png) 2 2, pointer; /\* URLs and fallback URLs (some with coordinates), with mandatory keyword fallback \*/ cursor: url(cursor\_1.svg) 4 5, url(cursor\_2.svg), /\* … ,\*/ url(cursor\_n.cur) 5 5, progress; /\* Global values \*/ cursor: inherit; cursor: initial; cursor: revert; cursor: revert-layer; cursor: unset; ``` The `cursor` property is specified as zero or more `<url>` values, separated by commas, followed by a single mandatory keyword value. Each `<url>` should point to an image file. The browser will try to load the first image specified, falling back to the next if it can't, and falling back to the keyword value if no images could be loaded (or if none were specified). Each `<url>` may be optionally followed by a pair of space-separated numbers, which set the `<x>` and `<y>` coordinates of the cursor's hotspot relative to the top-left corner of the image. ### Values `<url>` Optional A `url()` or a comma separated list `url(), url(), …`, pointing to an image file. More than one [`url()`](url) may be provided as fallbacks, in case some cursor image types are not supported. A non-URL fallback (one or more of the keyword values) *must* be at the end of the fallback list. `<x>`, `<y>` Optional Optional x- and y-coordinates indicating the cursor hotspot; the precise position within the cursor that is being pointed to. The numbers are in units of image pixels. They are relative to the top left corner of the image, which corresponds to "`0 0`", and are clamped within the boundaries of the cursor image. If these values are not specified, they may be read from the file itself, and will otherwise default to the top-left corner of the image. `keyword` A keyword value *must* be specified, indicating either the type of cursor to use, or the fallback cursor to use if all specified icons fail to load. The available keywords are listed in the table below. Other than `none`, which means no cursor, there is an image showing how the cursors used to be rendered. You can hover your mouse over the table rows to see the effect of the different cursor keyword values on your browser today. | Category | Keyword | Example | Description | | --- | --- | --- | --- | | General | `auto` | | The UA will determine the cursor to display based on the current context. E.g., equivalent to `text` when hovering text. | | `default` | | The platform-dependent default cursor. Typically an arrow. | | `none` | | No cursor is rendered. | | Links & status | `context-menu` | | A context menu is available. | | `help` | | Help information is available. | | `pointer` | | The cursor is a pointer that indicates a link. Typically an image of a pointing hand. | | `progress` | | The program is busy in the background, but the user can still interact with the interface (in contrast to `wait`). | | `wait` | | The program is busy, and the user can't interact with the interface (in contrast to `progress`). Sometimes an image of an hourglass or a watch. | | Selection | `cell` | | The table cell or set of cells can be selected. | | `crosshair` | | Cross cursor, often used to indicate selection in a bitmap. | | `text` | | The text can be selected. Typically the shape of an I-beam. | | `vertical-text` | | The vertical text can be selected. Typically the shape of a sideways I-beam. | | Drag & drop | `alias` | | An alias or shortcut is to be created. | | `copy` | | Something is to be copied. | | `move` | | Something is to be moved. | | `no-drop` | | An item may not be dropped at the current location.[bug 275173](https://bugzilla.mozilla.org/show_bug.cgi?id=275173): On Windows and macOS, `no-drop` is the same as `not-allowed`. | | `not-allowed` | | The requested action will not be carried out. | | `grab` | | Something can be grabbed (dragged to be moved). | | `grabbing` | | Something is being grabbed (dragged to be moved). | | Resizing & scrolling | `all-scroll` | | Something can be scrolled in any direction (panned).[bug 275174](https://bugzilla.mozilla.org/show_bug.cgi?id=275174): On Windows, `all-scroll` is the same as `move`. | | `col-resize` | | The item/column can be resized horizontally. Often rendered as arrows pointing left and right with a vertical bar separating them. | | `row-resize` | | The item/row can be resized vertically. Often rendered as arrows pointing up and down with a horizontal bar separating them. | | `n-resize` | | Some edge is to be moved. For example, the `se-resize` cursor is used when the movement starts from the *south-east* corner of the box.In some environments, an equivalent bidirectional resize cursor is shown. For example, `n-resize` and `s-resize` are the same as `ns-resize`. | | `e-resize` | | | `s-resize` | | | `w-resize` | | | `ne-resize` | | | `nw-resize` | | | `se-resize` | | | `sw-resize` | | | `ew-resize` | | Bidirectional resize cursor. | | `ns-resize` | | | `nesw-resize` | | | `nwse-resize` | | | Zooming | `zoom-in` | | Something can be zoomed (magnified) in or out. | | `zoom-out` | | Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified, but with [`url()`](url) values made absolute | | Animation type | discrete | Formal syntax ------------- ``` cursor = [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) <url> [|](value_definition_syntax#single_bar) [<url-set>](url-set) []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) [<x>](x) [<y>](y) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) []](value_definition_syntax#brackets)[#](value_definition_syntax#hash_mark)[?](value_definition_syntax#question_mark) [[](value_definition_syntax#brackets) auto [|](value_definition_syntax#single_bar) default [|](value_definition_syntax#single_bar) none [|](value_definition_syntax#single_bar) context-menu [|](value_definition_syntax#single_bar) help [|](value_definition_syntax#single_bar) pointer [|](value_definition_syntax#single_bar) progress [|](value_definition_syntax#single_bar) wait [|](value_definition_syntax#single_bar) cell [|](value_definition_syntax#single_bar) crosshair [|](value_definition_syntax#single_bar) text [|](value_definition_syntax#single_bar) vertical-text [|](value_definition_syntax#single_bar) alias [|](value_definition_syntax#single_bar) copy [|](value_definition_syntax#single_bar) move [|](value_definition_syntax#single_bar) no-drop [|](value_definition_syntax#single_bar) not-allowed [|](value_definition_syntax#single_bar) grab [|](value_definition_syntax#single_bar) grabbing [|](value_definition_syntax#single_bar) e-resize [|](value_definition_syntax#single_bar) n-resize [|](value_definition_syntax#single_bar) ne-resize [|](value_definition_syntax#single_bar) nw-resize [|](value_definition_syntax#single_bar) s-resize [|](value_definition_syntax#single_bar) se-resize [|](value_definition_syntax#single_bar) sw-resize [|](value_definition_syntax#single_bar) w-resize [|](value_definition_syntax#single_bar) ew-resize [|](value_definition_syntax#single_bar) ns-resize [|](value_definition_syntax#single_bar) nesw-resize [|](value_definition_syntax#single_bar) nwse-resize [|](value_definition_syntax#single_bar) col-resize [|](value_definition_syntax#single_bar) row-resize [|](value_definition_syntax#single_bar) all-scroll [|](value_definition_syntax#single_bar) zoom-in [|](value_definition_syntax#single_bar) zoom-out []](value_definition_syntax#brackets) <url> = url( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) [|](value_definition_syntax#single_bar) src( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) ``` Usage notes ----------- ### Icon size limits While the specification does not limit the `cursor` image size, [user agents](https://developer.mozilla.org/en-US/docs/Glossary/User_agent) commonly restrict them to avoid potential misuse. For example, on Firefox and Chromium cursor images are restricted to 128x128 pixels by default, but it is recommended to limit the cursor image size to 32x32 pixels. Cursor changes using images that are larger than the user-agent maximum supported size will generally just be ignored. ### Supported image file formats User agents are required by the specification to support PNG files, SVG v1.1 files in secure static mode that contain a natural size, and any other non-animated image file formats that they support for images in other properties. Desktop browsers also broadly support the `.cur` file format. The specification further indicates that user agents *should* also support SVG v1.1 files in secure animated mode that contain a natural size, along with any other animated images file formats they support for images in other properties. User agents *may* support both static and animated SVG images that do not contain a natural size. ### Other notes Cursor changes that intersect toolbar areas are commonly blocked to avoid spoofing. Examples -------- ### Setting cursor types ``` .foo { cursor: crosshair; } .bar { cursor: zoom-in; } /\* A fallback keyword value is required when using a URL \*/ .baz { cursor: url("hyper.cur"), auto; } ``` Specifications -------------- | Specification | | --- | | [CSS Basic User Interface Module Level 4 # cursor](https://w3c.github.io/csswg-drafts/css-ui/#cursor) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `cursor` | 1 | 12 | 1 Starting in Firefox 67, the maximum size allowed for custom cursors is 32x32 pixels due to cursors being misused by certain malicious sites. | 4 In Internet Explorer 11, when `cursor` is applied to an element and this element is underneath an open [`<select>`](https://developer.mozilla.org/docs/Web/HTML/Element/select) menu and the user hovers over a [`<select>`](https://developer.mozilla.org/docs/Web/HTML/Element/select) menu item that's on top of said element, the cursor for said element will be displayed rather than the [`<select>`](https://developer.mozilla.org/docs/Web/HTML/Element/select)'s normal cursor. See [bug 817822](https://developer.microsoft.com/microsoft-edge/platform/issues/817822/). | 7 | 1.2 | No | 18 | 95 | 14 | 1 | 1.0 | | `alias` | 1 | 12 | 1.5 | 10 | 10.6 | 3 | No | 18 | 95 | 14 | 1 | 1.0 | | `all-scroll` | 1 | 12 | 1.5 | 6 | 10.6 | 3 | No | 18 | 95 | 14 | 1 | 1.0 | | `auto` | 1 | 12 | 1 | 4 | 7 | 1.2 | No | 18 | 95 | 14 | 1 | 1.0 | | `bidirectional_resize` | 1 | 12 | 1.5 | 10 | 10.6 | 3 | No | 18 | 95 | 14 | 1 | 1.0 | | `cell` | 1 | 12 | 1.5 | 10 | 10.6 | 3 | No | 18 | 95 | 14 | 1 | 1.0 | | `col-resize` | 1 | 12 | 1.5 | 6 | 10.6 | 3 | No | 18 | 95 | 14 | 1 | 1.0 | | `context-menu` | 1 This cursor is only supported on macOS and Linux. | 12 | 1.5 This cursor is only supported on macOS and Linux. | 10 | 10.6 | 3 | No | 18 This cursor is only supported on macOS and Linux. | 95 | 14 This cursor is only supported on macOS and Linux. | 1 | 1.0 This cursor is only supported on macOS and Linux. | | `copy` | 1 | 12 | 1.5 | 10 | 10.6 | 3 | No | 18 | 95 | 14 | 1 | 1.0 | | `crosshair` | 1 | 12 | 1 | 4 | 7 | 1.2 | No | 18 | 95 | 14 | 1 | 1.0 | | `default` | 1 | 12 | 1 | 4 | 7 | 1.2 | No | 18 | 95 | 14 | 1 | 1.0 | | `grab` | 68 Chrome also continues to support the prefixed versions. 1 Chrome 22 added Windows support. | 14 | 27 1.5 | No | 55 Opera also continues to support the prefixed versions. 15 Opera 22 added Windows support. | 11 4 | No | 68 Chrome also continues to support the prefixed versions. 18 Chrome 22 added Windows support. | 95 | 48 Opera also continues to support the prefixed versions. 14 Opera 22 added Windows support. | 1 | 10.0 1.0 | | `help` | 1 | 12 | 1 | 4 | 7 | 1.2 | No | 18 | 95 | 14 | 1 | 1.0 | | `inherit` | 1 | 12 | 1 | 8 | 9 | 1.2 | No | 18 | 95 | 14 | 1 | 1.0 | | `move` | 1 | 12 | 1 | 4 | 7 | 1.2 | No | 18 | 95 | 14 | 1 | 1.0 | | `no-drop` | 1 | 12 | 1.5 | 6 | 10.6 | 3 | No | 18 | 95 | 14 | 1 | 1.0 | | `none` | 5 | 12 | 3 | 9 | 15 | 5 | No | 18 | 95 | 14 | 4.2 | 1.0 | | `not-allowed` | 1 | 12 | 1.5 | 6 | 10.6 | 3 | No | 18 | 95 | 14 | 1 | 1.0 | | `pointer` | 1 | 12 | 1 | 6 | 7 | 1.2 | No | 18 | 95 | 14 | 1 | 1.0 | | `progress` | 1 | 12 | 1 | 6 | 7 | 1.2 | No | 18 | 95 | 14 | 1 | 1.0 | | `row-resize` | 1 | 12 | 1.5 | 6 | 10.6 | 3 | No | 18 | 95 | 14 | 1 | 1.0 | | `text` | 1 | 12 | 1 | 4 | 7 | 1.2 | No | 18 | 95 | 14 | 1 | 1.0 | | `unidirectional_resize` | 1 | 12 | 1 | 4 | 7 | 1.2 | No | 18 | 95 | 14 | 1 | 1.0 | | `url` | 1 | 12 | 1.5 Firefox 4 added macOS support. | 6 | 15 | 3 | No | 18 | 95 | 14 | 1 | 1.0 | | `url_positioning_syntax` | 1 | 79 | 1.5 Firefox 4 added macOS support. | No | 15 | 3 | No | 18 | 95 | 14 | 1 | 1.0 | | `vertical-text` | 1 | 12 | 1.5 | No | 10.6 | 3 | No | 18 | 95 | 14 | 1 | 1.0 | | `wait` | 1 | 12 | 1 | 4 | 7 | 1.2 | No | 18 | 95 | 14 | 1 | 1.0 | | `zoom` | 37 1 | 12 | 24 1 | No | 24 15-23 | 9 3 | No | 37 18 | 95 | 24 14-24 | 1 | 3.0 1.0 | See also -------- * [`pointer-events`](pointer-events) * [`url()`](url) function
programming_docs
css font-size-adjust font-size-adjust ================ The `font-size-adjust` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the size of lower-case letters relative to the current font size (which defines the size of upper-case letters). ``` /\* Use the specified font size \*/ font-size-adjust: none; /\* Use a font size that makes lowercase letters half the specified font size \*/ font-size-adjust: 0.5; /\* Two values - added in the Level 5 spec \*/ font-size-adjust: ex-height 0.5; /\* Global values \*/ font-size-adjust: inherit; font-size-adjust: initial; font-size-adjust: revert; font-size-adjust: revert-layer; font-size-adjust: unset; ``` The property is useful since the legibility of fonts, especially at small sizes, is determined more by the size of lowercase letters than by the size of capital letters. Legibility can become an issue when the first-choice [`font-family`](font-family) is unavailable and its replacement has a significantly different aspect ratio (the ratio of the size of lowercase letters to the size of the font). To use this property in a way that is compatible with browsers that do not support `font-size-adjust`, it is specified as a number that the [`font-size`](font-size) property is multiplied by. This means the value specified for the property should generally be the aspect ratio of the first choice font. For example, consider this style sheet: ``` font-size: 14px; font-size-adjust: 0.5; ``` It is really specifying that the lowercase letters of the font should be `7px` high (0.5 × 14px). This will still produce reasonable results in browsers that do not support `font-size-adjust`, where a `14px` font will be used. Syntax ------ ### Values `none` Choose the size of the font based only on the [`font-size`](font-size) property. ex-height | cap-height | ch-width | ic-width | ic-height Specifies the font metric to normalize on. Defaults to `ex-height`. One of: `ex-height` Normalize the aspect value of the fonts, using the x-height divided by the font size. `cap-height` Normalize the cap-height of the fonts, using the cap-height by the font size. `ch-width` Normalize the horizontal narrow pitch of the fonts, using the advance width of "0" (ZERO, U+0030) divided by the font size. `ic-width` Normalize the horizontal wide pitch of the font, using the advance width of "水" (CJK water ideograph, U+6C34) divided by the font size. `ic-height` Normalize the vertical wide pitch of the font, using the advance height of "水" (CJK water ideograph, U+6C34) divided by the font size. [`<number>`](number) Choose the size of the font so that its lowercase letters (as determined by the x-height of the font) are the specified number times the [`font-size`](font-size). The number specified should generally be the aspect ratio (ratio of x-height to font size) of the first choice [`font-family`](font-family). This means that the first-choice font, when available, will appear the same size in browsers, whether or not they support `font-size-adjust`. `0` yields text of zero height (hidden text). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | a [number](number#interpolation) | Formal syntax ------------- ``` font-size-adjust = none [|](value_definition_syntax#single_bar) [<number [0,∞]>](number) ``` Examples -------- ### Adjusting lower-case letter sizes #### HTML ``` <p class="times"> This text uses the Times font (10px), which is hard to read in small sizes. </p> <p class="verdana"> This text uses the Verdana font (10px), which has relatively large lowercase letters. </p> <p class="adjtimes"> This is the 10px Times, but now adjusted to the same aspect ratio as the Verdana. </p> ``` #### CSS ``` .times { font-family: Times, serif; font-size: 10px; } .verdana { font-family: Verdana, sans-serif; font-size: 10px; } .adjtimes { font-family: Times, serif; font-size-adjust: ex-height 0.58; font-size: 10px; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Fonts Module Level 5 # font-size-adjust-prop](https://w3c.github.io/csswg-drafts/css-fonts-5/#font-size-adjust-prop) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `font-size-adjust` | No | No | 3 Before Firefox 40, `font-size-adjust: 0` was incorrectly interpreted as `font-size-adjust: none` ([bug 1144885](https://bugzil.la/1144885)). 1-3 Only supported on Windows. | No | No | preview | No | No | 4 Before Firefox 40, `font-size-adjust: 0` was incorrectly interpreted as `font-size-adjust: none` ([bug 1144885](https://bugzil.la/1144885)). | No | No | No | | `two-values` | No | No | 92 | No | No | No | No | No | 92 | No | No | No | See also -------- * [`font-size`](font-size) * [`font-weight`](font-weight) * [Fundamental text and font styling](https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text/Fundamentals) * [`size-adjust`](@font-face/size-adjust) descriptor css min-inline-size min-inline-size =============== The `min-inline-size` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the horizontal or vertical minimal size of an element's block, depending on its writing mode. It corresponds to either the [`min-width`](min-width) or the [`min-height`](min-height) property, depending on the value of [`writing-mode`](writing-mode). Try it ------ Syntax ------ ``` /\* <length> values \*/ min-inline-size: 100px; min-inline-size: 5em; /\* <percentage> values \*/ min-inline-size: 10%; /\* Keyword values \*/ min-inline-size: max-content; min-inline-size: min-content; min-inline-size: fit-content(20em); /\* Global values \*/ min-inline-size: inherit; min-inline-size: initial; min-inline-size: revert; min-inline-size: revert-layer; min-inline-size: unset; ``` If the writing mode is vertically oriented, the value of `min-inline-size` relates to the minimum height of the element; otherwise, it relates to the minimum width of the element. A related property is [`min-block-size`](min-block-size), which defines the other dimension of the element. ### Values The `min-inline-size` property takes the same values as the [`min-width`](min-width) and [`min-height`](min-height) properties. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | same as [`width`](width) and [`height`](height) | | [Inherited](inheritance) | no | | Percentages | inline-size of containing block | | [Computed value](computed_value) | same as [`min-width`](min-width) and [`min-height`](min-height) | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` min-inline-size = <'min-width'> ``` Examples -------- ### Setting minimum inline size for vertical text #### HTML ``` <p class="exampleText">Example text</p> ``` #### CSS ``` .exampleText { writing-mode: vertical-rl; background-color: yellow; block-size: 5%; min-inline-size: 200px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # propdef-min-inline-size](https://w3c.github.io/csswg-drafts/css-logical/#propdef-min-inline-size) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `min-inline-size` | 57 | 79 | 41 | No | 44 | 12.1 | 57 | 57 | 41 | 43 | 12.2 | 7.0 | | `fit-content` | 57 | 79 | 41 | No | 44 | 12.1 | 57 | 57 | 41 | 43 | 12.2 | 7.0 | | `fit-content_function` | No | No | 91 | No | No | No | No | No | No | No | No | No | | `max-content` | 57 | 79 | 66 41 | No | 44 | 12.1 | 57 | 57 | 66 41 | 43 | 12.2 | 7.0 | | `min-content` | 57 | 79 | 66 41 | No | 44 | 12.1 | 57 | 57 | 66 41 | 43 | 12.2 | 7.0 | See also -------- * The mapped physical properties: [`min-width`](min-width) and [`min-height`](min-height) * [`writing-mode`](writing-mode) css offset-anchor offset-anchor ============= The `offset-anchor` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property specifies the point inside the box of an element traveling along an [`offset-path`](offset-path) that is actually moving along the path. Try it ------ Syntax ------ ``` /\* Keyword values \*/ offset-anchor: top; offset-anchor: bottom; offset-anchor: left; offset-anchor: right; offset-anchor: center; offset-anchor: auto; /\* <percentage> values \*/ offset-anchor: 25% 75%; /\* <length> values \*/ offset-anchor: 0 0; offset-anchor: 1cm 2cm; offset-anchor: 10ch 8em; /\* Edge offsets values \*/ offset-anchor: bottom 10px right 20px; offset-anchor: right 3em bottom 10px; /\* Global values \*/ offset-anchor: inherit; offset-anchor: initial; offset-anchor: revert; offset-anchor: unset; ``` ### Values `auto` `offset-anchor` is given the same value as the element's [`transform-origin`](transform-origin), unless [`offset-path`](offset-path) is `none`, in which case it takes its value from [`offset-position`](offset-position). `<position>` A [`<position>`](position_value) defines an x/y coordinate, to place an item relative to the edges of an element's box. It can be defined using one to four values. For more specifics, see the [`<position>`](position_value) and [`background-position`](background-position) reference pages. Note that the 3-value position syntax does not work for any usage of `<position>`, except for in `background(-position)`. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | transformable elements | | [Inherited](inheritance) | no | | Percentages | relativeToWidthAndHeight | | [Computed value](computed_value) | for [`<length>`](length) the absolute value, otherwise a percentage | | Animation type | a [position](position_value#interpolation) | Formal syntax ------------- ``` offset-anchor = auto [|](value_definition_syntax#single_bar) <position> <position> = [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) right []](value_definition_syntax#brackets) [||](value_definition_syntax#double_bar) [[](value_definition_syntax#brackets) top [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) bottom []](value_definition_syntax#brackets) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) <length-percentage> []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) top [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) bottom [|](value_definition_syntax#single_bar) <length-percentage> []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) right []](value_definition_syntax#brackets) <length-percentage> []](value_definition_syntax#brackets) [&&](value_definition_syntax#double_ampersand) [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) top [|](value_definition_syntax#single_bar) bottom []](value_definition_syntax#brackets) <length-percentage> []](value_definition_syntax#brackets) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Setting various offset-anchor values In the following example, we have three [`<div>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div) elements nested in [`<section>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/section) elements. Each `<div>` is given the same [`offset-path`](offset-path) (a horizontal line 200 pixels long) and animated to move along it. The three are then given different [`background-color`](background-color) and `offset-anchor` values. Each `<section>` has been styled with a linear gradient to give it a horizontal line running through its center, to give you a visual display of where the `<div>`'s offset paths are running. This allows you to see what effect the different `offset-anchor` values have — the first one, `auto`, causes the `<div>`'s center point to move along the path. The other two cause the `<div>`'s top-right and bottom-left points to move along the path, respectively. #### HTML ``` <section> <div class="offset-anchor1"></div> </section> <section> <div class="offset-anchor2"></div> </section> <section> <div class="offset-anchor3"></div> </section> ``` #### CSS ``` div { offset-path: path("M 0,20 L 200,20"); animation: move 3000ms infinite alternate ease-in-out; width: 40px; height: 40px; } section { background-image: linear-gradient( to bottom, transparent, transparent 49%, #000 50%, #000 51%, transparent 52% ); border: 1px solid #ccc; margin-bottom: 10px; } .offset-anchor1 { offset-anchor: auto; background: cyan; } .offset-anchor2 { offset-anchor: right top; background: purple; } .offset-anchor3 { offset-anchor: left bottom; background: magenta; } @keyframes move { 0% { offset-distance: 0%; } 100% { offset-distance: 100%; } } ``` #### Result Specifications -------------- | Specification | | --- | | [Motion Path Module Level 1 # offset-anchor-property](https://drafts.fxtf.org/motion/#offset-anchor-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `offset-anchor` | No | No | 72 | No | No | preview | No | No | 79 | No | No | No | See also -------- * [`offset`](offset) * [`offset-distance`](offset-distance) * [`offset-rotate`](offset-rotate) * [SVG `<path>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths) css filter filter ====== The `filter` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property applies graphical effects like blur or color shift to an element. Filters are commonly used to adjust the rendering of images, backgrounds, and borders. Included in the CSS standard are several functions that achieve predefined effects. You can also reference an SVG filter with a URL to an [SVG filter element](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/filter). Try it ------ Syntax ------ ``` /\* URL to SVG filter \*/ filter: url("filters.svg#filter-id"); /\* <filter-function> values \*/ filter: blur(5px); filter: brightness(0.4); filter: contrast(200%); filter: drop-shadow(16px 16px 20px blue); filter: grayscale(50%); filter: hue-rotate(90deg); filter: invert(75%); filter: opacity(25%); filter: saturate(30%); filter: sepia(60%); /\* Multiple filters \*/ filter: contrast(175%) brightness(3%); /\* Use no filter \*/ filter: none; /\* Global values \*/ filter: inherit; filter: initial; filter: revert; filter: revert-layer; filter: unset; ``` With a function, use the following: ``` filter: <filter-function> [<filter-function>]* | none ``` For a reference to an SVG [`<filter>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/filter) element, use the following: ``` filter: url(file.svg#filter-element-id) ``` ### Interpolation When animated, if both the beginning and end filters have a function list of the same length without [`url()`](url), each of their filter functions is [interpolated](https://developer.mozilla.org/en-US/docs/Glossary/Interpolation) according to its specific rules. If they have different lengths, the missing equivalent filter functions from the longer list are added to the end of the shorter list using their initial values, then all filter functions are interpolated according to their specific rules. If one filter is `none`, it is replaced with the filter functions list of the other one using the filter function default values, then all filter functions are interpolated according to their specific rules. Otherwise, discrete interpolation is used. Functions --------- The `filter` property is specified as `none` or one or more of the functions listed below. If the parameter for any function is invalid, the function returns `none`. Except where noted, the functions that take a value expressed with a percent sign (as in `34%`) also accept the value expressed as decimal (as in `0.34`). When a `filter` property has two or more functions, its results are different from the same functions applied separately using multiple `filter` properties. ### SVG filter #### url() Takes an URI pointing to an [SVG filter](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/filter), which may be embedded in an external XML file. ``` filter: url(resources.svg#c1) ``` ### Filter functions #### blur() The [`blur()`](filter-function/blur) function applies a Gaussian blur to the input image. The value of `radius` defines the value of the standard deviation to the Gaussian function, or how many pixels on the screen blend into each other, so a larger value will create more blur. The initial value for interpolation is `0`. The parameter is specified as a CSS length, but does not accept percentage values. ``` filter: blur(5px) ``` ``` <svg style="position: absolute; top: -99999px" xmlns="http://www.w3.org/2000/svg"> <filter id="svgBlur" x="-5%" y="-5%" width="110%" height="110%"> <feGaussianBlur in="SourceGraphic" stdDeviation="5"/> </filter> </svg> ``` #### brightness() The [`brightness()`](filter-function/brightness) function applies a linear multiplier to the input image, making it appear more or less bright. A value of `0%` will create an image that is completely black. A value of `100%` leaves the input unchanged. Other values are linear multipliers on the effect. Values of an amount over `100%` are allowed, providing brighter results. The initial value for interpolation is `1`. ``` filter: brightness(2) ``` ``` <svg style="position: absolute; top: -99999px" xmlns="http://www.w3.org/2000/svg"> <filter id="brightness"> <feComponentTransfer> <feFuncR type="linear" slope="[amount]"/> <feFuncG type="linear" slope="[amount]"/> <feFuncB type="linear" slope="[amount]"/> </feComponentTransfer> </filter> </svg> ``` #### contrast() The [`contrast()`](filter-function/contrast) function adjusts the contrast of the input image. A value of `0%` will create an image that is completely gray. A value of `100%` leaves the input unchanged. Values of an amount over `100%` are allowed, providing results with more contrast. The initial value for interpolation is `1`. ``` filter: contrast(200%) ``` ``` <svg style="position: absolute; top: -99999px" xmlns="http://www.w3.org/2000/svg"> <filter id="contrast"> <feComponentTransfer> <feFuncR type="linear" slope="[amount]" intercept="-(0.5 \* [amount]) + 0.5"/> <feFuncG type="linear" slope="[amount]" intercept="-(0.5 \* [amount]) + 0.5"/> <feFuncB type="linear" slope="[amount]" intercept="-(0.5 \* [amount]) + 0.5"/> </feComponentTransfer> </filter> </svg> ``` #### drop-shadow() The [`drop-shadow()`](filter-function/drop-shadow) function applies a drop shadow effect to the input image. A drop shadow is effectively a blurred, offset version of the input image's alpha mask drawn in a particular color, composited below the image. The function accepts a parameter of type `<shadow>` (defined in [CSS Backgrounds and Borders Module Level 3](https://www.w3.org/TR/css-backgrounds-3/#typedef-shadow)), with the exception that the `inset` keyword and `spread` parameter are not allowed. This function is similar to the more established [`box-shadow`](box-shadow) property; the difference is that with filters, some browsers provide hardware acceleration for better performance. The parameters of the `<shadow>` parameter are as follows: `offset-x` (required) The horizontal offset for the shadow, specified as a [`<length>`](length) value. Negative values place the shadow to the left of the element. `offset-y` (required) The vertical offset for the shadow, specified as a [`<length>`](length) value. Negative values place the shadow above the element. `<blur-radius>` (optional) This is a third [`<length>`](length) value. The larger this value, the bigger the blur, so the shadow becomes bigger and lighter. Negative values are not allowed. If not specified, it will be `0` (the shadow's edge is sharp). `<color>` (optional) See [`<color>`](color_value) values for possible keywords and notations. If not specified, the color used depends on the browser - it is usually the value of the [`<color>`](color_value) property, but note that Safari currently paints a transparent shadow in this case. ``` filter: drop-shadow(16px 16px 10px black) ``` ``` <svg style="position: absolute; top: -999999px" xmlns="http://www.w3.org/2000/svg"> <filter id="drop-shadow"> <feGaussianBlur in="SourceAlpha" stdDeviation="[radius]"/> <feOffset dx="[offset-x]" dy="[offset-y]" result="offsetblur"/> <feFlood flood-color="[color]"/> <feComposite in2="offsetblur" operator="in"/> <feMerge> <feMergeNode/> <feMergeNode in="SourceGraphic"/> </feMerge> </filter> </svg> ``` #### grayscale() The [`grayscale()`](filter-function/grayscale) function converts the input image to grayscale. The value of `amount` defines the proportion of the conversion. A value of `100%` is completely grayscale. A value of `0%` leaves the input unchanged. Values between `0%` and `100%` are linear multipliers on the effect. The initial value for interpolation is `0`. ``` filter: grayscale(100%) ``` #### hue-rotate() The [`hue-rotate()`](filter-function/hue-rotate) function applies a hue rotation on the input image. The value of `angle` defines the number of degrees around the color circle the input samples will be adjusted. A value of `0deg` leaves the input unchanged. The initial value for interpolation is `0`. Though there is no maximum value; the effect of values above `360deg` wraps around. ``` filter: hue-rotate(90deg) ``` ``` <svg style="position: absolute; top: -999999px" xmlns="http://www.w3.org/2000/svg"> <filter id="svgHueRotate"> <feColorMatrix type="hueRotate" values="90" /> </filter> </svg> ``` #### invert() The [`invert()`](filter-function/invert) function inverts the samples in the input image. The value of `amount` defines the proportion of the conversion. A value of `100%` is completely inverted. A value of `0%` leaves the input unchanged. Values between `0%` and `100%` are linear multipliers on the effect. The initial value for interpolation is `0`. ``` filter: invert(100%) ``` #### opacity() The [`opacity()`](filter-function/opacity) function applies transparency to the samples in the input image. The value of `amount` defines the proportion of the conversion. A value of `0%` is completely transparent. A value of `100%` leaves the input unchanged. Values between `0%` and `100%` are linear multipliers on the effect. This is equivalent to multiplying the input image samples by amount. The initial value for interpolation is `1`. This function is similar to the more established [`opacity`](opacity) property; the difference is that with filters, some browsers provide hardware acceleration for better performance. ``` filter: opacity(50%) ``` #### saturate() The [`saturate()`](filter-function/saturate) function saturates the input image. The value of `amount` defines the proportion of the conversion. A value of `0%` is completely un-saturated. A value of `100%` leaves the input unchanged. Other values are linear multipliers on the effect. Values of amount over `100%` are allowed, providing super-saturated results. The initial value for interpolation is `1`. ``` filter: saturate(200%) ``` #### sepia() The [`sepia()`](filter-function/sepia) function converts the input image to sepia. The value of `amount` defines the proportion of the conversion. A value of `100%` is completely sepia. A value of `0%` leaves the input unchanged. Values between `0%` and `100%` are linear multipliers on the effect. The initial value for interpolation is `0`. ``` filter: sepia(100%) ``` Combining functions ------------------- You may combine any number of functions to manipulate the rendering. The following example enhances the contrast and brightness of the image: ``` filter: contrast(175%) brightness(103%) ``` Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements; In SVG, it applies to container elements excluding the [`<defs>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs) element and all graphics elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | a [filter function list](filter#Interpolation) | Formal syntax ------------- ``` filter = none [|](value_definition_syntax#single_bar) <filter-value-list> <filter-value-list> = [[](value_definition_syntax#brackets) <filter-function> [|](value_definition_syntax#single_bar) <url> []](value_definition_syntax#brackets)[+](value_definition_syntax#plus) <filter-function> = <blur()> [|](value_definition_syntax#single_bar) <brightness()> [|](value_definition_syntax#single_bar) <contrast()> [|](value_definition_syntax#single_bar) <drop-shadow()> [|](value_definition_syntax#single_bar) <grayscale()> [|](value_definition_syntax#single_bar) <hue-rotate()> [|](value_definition_syntax#single_bar) <invert()> [|](value_definition_syntax#single_bar) <opacity()> [|](value_definition_syntax#single_bar) <sepia()> [|](value_definition_syntax#single_bar) <saturate()> <url> = url( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) [|](value_definition_syntax#single_bar) src( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) <blur()> = blur( [<length>](length)[?](value_definition_syntax#question_mark) ) <brightness()> = brightness( [[](value_definition_syntax#brackets) [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <contrast()> = contrast( [[](value_definition_syntax#brackets) [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <drop-shadow()> = drop-shadow( [[](value_definition_syntax#brackets) [<color>](color_value)[?](value_definition_syntax#question_mark) [&&](value_definition_syntax#double_ampersand) [<length>](length)[{2,3}](value_definition_syntax#curly_braces) []](value_definition_syntax#brackets) ) <grayscale()> = grayscale( [[](value_definition_syntax#brackets) [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <hue-rotate()> = hue-rotate( [[](value_definition_syntax#brackets) [<angle>](angle) [|](value_definition_syntax#single_bar) [<zero>](zero) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <invert()> = invert( [[](value_definition_syntax#brackets) [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <opacity()> = opacity( [[](value_definition_syntax#brackets) [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <sepia()> = sepia( [[](value_definition_syntax#brackets) [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <saturate()> = saturate( [[](value_definition_syntax#brackets) [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) ``` Examples -------- ### Applying filter functions Examples of using the predefined functions are shown below. See each function for a specific example. ``` .mydiv { filter: grayscale(50%); } /\* Gray all images by 50% and blur by 10px \*/ img { filter: grayscale(0.5) blur(10px); } ``` ### Applying SVG filters Examples of using the URL function with an SVG resource are as follows: ``` .target { filter: url(#c1); } .mydiv { filter: url(commonfilters.xml#large-blur); } ``` Specifications -------------- | Specification | | --- | | [Filter Effects Module Level 1 # FilterProperty](https://drafts.fxtf.org/filter-effects/#FilterProperty) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `filter` | 53 18 In Chrome 18 to 19, the `saturate()` function only takes integers instead of decimal or percentage values. From Chrome 20, this bug is fixed. | 12 12 | 49 35 | No Internet Explorer 4 to 9 implemented a non-standard `filter` property. The syntax was completely different from this one and is not documented here. | 40 15 | 9.1 6 | 53 4.4 | 53 | 49 35 | 41 14 | 9.3 6 | 6.0 | | `svg` | No | No | 35 | No | No | No | No | No | 35 | No | No | No | See also -------- * [Applying SVG effects to HTML content](https://developer.mozilla.org/en-US/docs/Web/SVG/Applying_SVG_effects_to_HTML_content) * The [`mask`](mask) property * [SVG](https://developer.mozilla.org/en-US/docs/Web/SVG)
programming_docs
css translate translate ========= The `translate` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property allows you to specify translation transforms individually and independently of the [`transform`](transform) property. This maps better to typical user interface usage, and saves having to remember the exact order of transform functions to specify in the `transform` value. Try it ------ Syntax ------ ``` /\* Keyword values \*/ translate: none; /\* Single values \*/ translate: 100px; translate: 50%; /\* Two values \*/ translate: 100px 200px; translate: 50% 105px; /\* Three values \*/ translate: 50% 105px 5rem; /\* Global values \*/ translate: inherit; translate: initial; translate: revert; translate: revert-layer; translate: unset; ``` ### Values Single [`<length-percentage>`](length-percentage) value A [`<length>`](length) or [`<percentage>`](percentage) that specifies a translation along the X-axis. Equivalent to a `translate()` (2D translation) function with a single value specified. Two [`<length-percentage>`](length-percentage) values Two [`<length>`](length) or [`<percentage>`](percentage) that specify the X and Y axis translation values (respectively) of a 2D translation. Equivalent to a `translate()` (2D translation) function with two values specified. Three values Two [`<length-percentage>`](length-percentage) and single [`<length>`](length) values that specify the X, Y, and Z axis translation values (respectively) of a 3D translation. Equivalent to a `translate3d()` (3D translation) function. `none` Specifies that no translation should be applied. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | transformable elements | | [Inherited](inheritance) | no | | Percentages | refer to the size of bounding box | | [Computed value](computed_value) | as specified, but with relative lengths converted into absolute lengths | | Animation type | a transform | | Creates [stacking context](css_positioning/understanding_z_index/the_stacking_context) | yes | Formal syntax ------------- ``` translate = none [|](value_definition_syntax#single_bar) <length-percentage> [[](value_definition_syntax#brackets) <length-percentage> [<length>](length)[?](value_definition_syntax#question_mark) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Translating an element on hover This example shows how to use the `translate` property to move an element in three axes. The first box is moved along the X axis and the second box is moved along the X and Y axes. The third box is moved along the X, Y and Z axes and has the appearance of moving toward the viewer because of the addition of [`perspective`](perspective) to the parent element. #### HTML ``` <div class="wrapper"> <div id="box1">translate X</div> <div id="box2">translate X,Y</div> <div id="box3">translate X,Y,Z</div> </div> ``` #### CSS ``` .wrapper { perspective: 100px; display: inline-flex; gap: 1em; } .wrapper > div { width: 7em; line-height: 7em; text-align: center; transition: 0.5s ease-in-out; border: 3px dotted; } #box1:hover { translate: 20px; } #box2:hover { translate: 20px 20px; } #box3:hover { translate: 5px 5px 30px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Transforms Module Level 2 # individual-transforms](https://w3c.github.io/csswg-drafts/css-transforms-2/#individual-transforms) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `translate` | 104 | 104 | 72 | No | 90 | 14.1 | 104 | 104 | 79 | 71 | 14.5 | No | See also -------- * [`scale`](scale) * [`rotate`](rotate) * [`transform`](transform) Note: skew is not an independent transform value css border-start-start-radius border-start-start-radius ========================= The `border-start-start-radius` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines a logical border radius on an element, which maps to a physical border radius that depends on the element's [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). This is useful when building styles to work regardless of the [text orientation](text-orientation) and [writing mode](css_writing_modes). Try it ------ This property affects the corner between the block-start and the inline-start sides of the element. For instance, in a `horizontal-tb` writing mode with `ltr` direction, it corresponds to the [`border-top-left-radius`](border-top-left-radius) property. Syntax ------ ``` /\* <length> values \*/ /\* With one value the corner will be a circle \*/ border-start-start-radius: 10px; border-start-start-radius: 1em; /\* With two values the corner will be an ellipse \*/ border-start-start-radius: 1em 2em; /\* Global values \*/ border-start-start-radius: inherit; border-start-start-radius: initial; border-start-start-radius: revert; border-start-start-radius: revert-layer; border-start-start-radius: unset; ``` ### Values `<length-percentage>` Denotes the size of the circle radius or the semi-major and semi-minor axes of the ellipse. As absolute length it can be expressed in any unit allowed by the CSS [`<length>`](length) data type. Percentages for the horizontal axis refer to the width of the box, percentages for the vertical axis refer to the height of the box. Negative values are invalid. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | all elements; but User Agents are not required to apply to `table` and `inline-table` elements when [`border-collapse`](border-collapse) is `collapse`. The behavior on internal table elements is undefined for the moment.. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | Percentages | refer to the corresponding dimension of the border box | | [Computed value](computed_value) | two absolute [`<length>`](length)s or [`<percentage>`](percentage)s | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` border-start-start-radius = <'border-top-left-radius'> ``` Examples -------- ### Border radius with vertical text #### HTML ``` <div> <p class="exampleText">Example</p> </div> ``` #### CSS ``` div { background-color: rebeccapurple; width: 120px; height: 120px; border-start-start-radius: 10px; } .exampleText { writing-mode: vertical-rl; padding: 10px; background-color: #fff; border-start-start-radius: 10px; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # border-radius-properties](https://w3c.github.io/csswg-drafts/css-logical/#border-radius-properties) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-start-start-radius` | 89 | 89 | 66 | No | 75 | 15 | 89 | 89 | 66 | No | 15 | 15.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * The mapped physical property: [`border-top-left-radius`](border-top-left-radius) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css padding-inline padding-inline ============== The `padding-inline` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [shorthand property](shorthand_properties) defines the logical inline start and end padding of an element, which maps to physical padding properties depending on the element's writing mode, directionality, and text orientation. Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`padding-inline-end`](padding-inline-end) * [`padding-inline-start`](padding-inline-start) Syntax ------ ``` /\* <length> values \*/ padding-inline: 10px 20px; /\* An absolute length \*/ padding-inline: 1em 2em; /\* relative to the text size \*/ padding-inline: 10px; /\* sets both start and end values \*/ /\* <percentage> values \*/ padding-inline: 5% 2%; /\* relative to the nearest block container's width \*/ /\* Global values \*/ padding-inline: inherit; padding-inline: initial; padding-inline: revert; padding-inline: unset; ``` The `padding-inline` property may be specified with one or two values. If one value is given, it is used as the value for both [`padding-inline-start`](padding-inline-start) and [`padding-inline-end`](padding-inline-end). If two values are given, the first is used for [`padding-inline-start`](padding-inline-start) and the second for [`padding-inline-end`](padding-inline-end). ### Values [`<length>`](length) The size of the padding as a fixed value. Must be nonnegative. [`<percentage>`](percentage) The size of the padding as a percentage, relative to the inline size (*width* in a horizontal language, defined by [`writing-mode`](writing-mode)) of the [containing block](containing_block). Must be nonnegative. Description ----------- Values for this property correspond to the [`padding-top`](padding-top) and [`padding-bottom`](padding-bottom), or [`padding-right`](padding-right), and [`padding-left`](padding-left) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`padding-inline-start`](padding-inline-start): `0` * [`padding-inline-end`](padding-inline-end): `0` | | Applies to | all elements, except `table-row-group`, `table-header-group`, `table-footer-group`, `table-row`, `table-column-group` and `table-column` | | [Inherited](inheritance) | no | | Percentages | logical-width of containing block | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`padding-inline-start`](padding-inline-start): as [`<length>`](length) * [`padding-inline-end`](padding-inline-end): as [`<length>`](length) | | Animation type | a [length](length#interpolation) | Formal syntax ------------- ``` padding-inline = <'padding-top'>[{1,2}](value_definition_syntax#curly_braces) ``` Examples -------- ### Setting inline padding for vertical text #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-rl; padding-inline: 20px 40px; background-color: #c8c800; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # propdef-padding-inline](https://w3c.github.io/csswg-drafts/css-logical/#propdef-padding-inline) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `padding-inline` | 87 | 87 | 66 | No | 73 | 14.1 | 87 | 87 | 66 | 62 | 14.5 | 14.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * The mapped physical properties: [`padding-top`](padding-top), [`padding-right`](padding-right), [`padding-bottom`](padding-bottom), and [`padding-left`](padding-left) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css image-resolution image-resolution ================ **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `image-resolution` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property specifies the intrinsic resolution of all raster images used in or on the element. It affects content images such as replaced elements and generated content, and decorative images such as `background-image` images. The image resolution is defined as the number of image pixels per unit length, e.g., pixels per inch. By default, CSS assumes a resolution of one image pixel per CSS px unit; however, the `image-resolution` property allows a different resolution to be specified. Syntax ------ ``` image-resolution: from-image; image-resolution: 300dpi; image-resolution: from-image 300dpi; image-resolution: 300dpi snap; /\* Global values \*/ image-resolution: inherit; image-resolution: initial; image-resolution: revert; image-resolution: revert-layer; image-resolution: unset; ``` ### Values `[`<resolution>`](resolution)` Specifies the intrinsic resolution explicitly. `from-image` Uses the intrinsic resolution as specified by the image format. If the image does not specify its own resolution, the explicitly specified resolution is used (if given), else it defaults to `1dppx` (1 image pixel per CSS px unit). `snap` If the `snap` keyword is provided, the computed resolution is the specified resolution rounded to the nearest value that would map one image pixel to an integer number of device pixels. If the resolution is taken from the image, then the used intrinsic resolution is the image's native resolution similarly adjusted. **Note:** As vector formats such as SVG do not have an intrinsic resolution, this property has no effect on vector images. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `1dppx` | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified, except with <resolution> possibly altered by computed for 'snap' value | | Animation type | discrete | Formal syntax ------------- ``` image-resolution = [[](value_definition_syntax#brackets) from-image [||](value_definition_syntax#double_bar) [<resolution>](resolution) []](value_definition_syntax#brackets) [&&](value_definition_syntax#double_ampersand) snap[?](value_definition_syntax#question_mark) ``` Examples -------- ### Setting a high dpi for print When printing the document, use a higher resolution. ``` @media print { .myimage { image-resolution: 300dpi; } } ``` ### Use image resolution with fallback Uses the resolution from the image. If the image does not have a resolution, use 300dpi rather than the default 1dppx. ``` .myimage { image-resolution: from-image 300dpi; } ``` Specifications -------------- | Specification | | --- | | [CSS Image Values and Replaced Content Module Level 4 # the-image-resolution](https://drafts.csswg.org/css-images-4/#the-image-resolution) | Browser compatibility --------------------- See also -------- * Other image-related CSS properties: [`object-fit`](object-fit), [`object-position`](object-position), [`image-orientation`](image-orientation), [`image-rendering`](image-rendering). * [Chromium bug: 1086473](https://bugs.chromium.org/p/chromium/issues/detail?id=1086473). css border-image-slice border-image-slice ================== The `border-image-slice` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property divides the image specified by [`border-image-source`](border-image-source) into regions. These regions form the components of an element's [border image](border-image). Try it ------ The slicing process creates nine regions in total: four corners, four edges, and a middle region. Four slice lines, set a given distance from their respective sides, control the size of the regions. The above diagram illustrates the location of each region. * Zones 1-4 are corner regions. Each one is used a single time to form the corners of the final border image. * Zones 5-8 are edge regions. These are [repeated, scaled, or otherwise modified](border-image-repeat) in the final border image to match the dimensions of the element. * Zone 9 is the middle region. It is discarded by default, but is used like a background image if the keyword `fill` is set. The [`border-image-repeat`](border-image-repeat), [`border-image-width`](border-image-width), and [`border-image-outset`](border-image-outset) properties determine how these regions are used to form the final border image. Syntax ------ ``` /\* All sides \*/ border-image-slice: 30%; /\* top and bottom | left and right \*/ border-image-slice: 10% 30%; /\* top | left and right | bottom \*/ border-image-slice: 30 30% 45; /\* top | right | bottom | left \*/ border-image-slice: 7 12 14 5; /\* Using the `fill` keyword \*/ border-image-slice: 10% fill 7 12; /\* Global values \*/ border-image-slice: inherit; border-image-slice: initial; border-image-slice: revert; border-image-slice: revert-layer; border-image-slice: unset; ``` The `border-image-slice` property may be specified using one to four `<number-percentage>` values to represent the position of each image slice. Negative values are invalid; values greater than their corresponding dimension are clamped to `100%`. * When **one** position is specified, it creates all four slices at the same distance from their respective sides. * When **two** positions are specified, the first value creates slices measured from the **top and bottom**, the second creates slices measured from the **left and right**. * When **three** positions are specified, the first value creates a slice measured from the **top**, the second creates slices measured from the **left and right**, the third creates a slice measured from the **bottom**. * When **four** positions are specified, they create slices measured from the **top**, **right**, **bottom**, and **left** in that order (clockwise). The optional `fill` value, if used, can be placed anywhere in the declaration. ### Values [`<number>`](number) Represents an edge offset in *pixels* for raster images and *coordinates* for vector images. For vector images, the number is relative to the element's size, not the size of the source image, so percentages are generally preferable in these cases. [`<percentage>`](percentage) Represents an edge offset as a percentage of the source image's size: the width of the image for horizontal offsets, the height for vertical offsets. `fill` Preserves the middle image region and displays it like a background image, but stacked above the actual [`background`](background). Its width and height are sized to match the top and left image regions, respectively. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `100%` | | Applies to | all elements, except internal table elements when [`border-collapse`](border-collapse) is `collapse`. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | Percentages | refer to the size of the border image | | [Computed value](computed_value) | one to four percentage(s) (as specified) or absolute length(s), plus the keyword `fill` if specified | | Animation type | by computed value type | Formal syntax ------------- ``` border-image-slice = [[](value_definition_syntax#brackets) [<number [0,∞]>](number) [|](value_definition_syntax#single_bar) [<percentage [0,∞]>](percentage) []](value_definition_syntax#brackets)[{1,4}](value_definition_syntax#curly_braces) [&&](value_definition_syntax#double_ampersand) fill[?](value_definition_syntax#question_mark) ``` Examples -------- ### Adjustable border width and slice The following example shows a simple `<div>` with a border image set on it. The source image for the borders is as follows: The diamonds are 30px across, therefore setting 30 pixels as the value for both [`border-width`](border-width) and `border-image-slice` will get you complete and fairly crisp diamonds in your border: ``` border-width: 30px; border-image-slice: 30; ``` These are the default values we have used in this example. However, we have also provided two sliders to allow you to dynamically change the values of the above two properties, allowing you to appreciate the effect they have: `border-image-slice` Changes the size of the image slice sampled for use in each border and border corner (and the content area, if the `fill` keyword is used) — varying this away from 30 causes the border to look somewhat irregular, but can have some interesting effects. `border-width`: Changes the width of the border. The sampled image size is scaled to fit inside the border, which means that if the width is bigger than the slice, the image can start to look somewhat pixelated (unless of course you use an SVG image). #### HTML ``` <div class="wrapper"> <div></div> </div> <ul> <li> <label for="width">slide to adjust <code>border-width</code></label> <input type="range" min="10" max="45" id="width" /> <output id="width-output">30px</output> </li> <li> <label for="slice">slide to adjust <code>border-image-slice</code></label> <input type="range" min="10" max="45" id="slice" /> <output id="slice-output">30</output> </li> </ul> ``` #### CSS ``` .wrapper { width: 400px; height: 300px; } div > div { width: 300px; height: 200px; border-width: 30px; border-style: solid; border-image: url(https://interactive-examples.mdn.mozilla.net/media/examples/border-diamonds.png); border-image-slice: 30; border-image-repeat: round; } li { display: flex; place-content: center; } ``` #### JavaScript ``` const widthSlider = document.getElementById("width"); const sliceSlider = document.getElementById("slice"); const widthOutput = document.getElementById("width-output"); const sliceOutput = document.getElementById("slice-output"); const divElem = document.querySelector("div > div"); widthSlider.addEventListener("input", () => { const newValue = `${widthSlider.value}px`; divElem.style.borderWidth = newValue; widthOutput.textContent = newValue; }); sliceSlider.addEventListener("input", () => { const newValue = sliceSlider.value; divElem.style.borderImageSlice = newValue; sliceOutput.textContent = newValue; }); ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # the-border-image-slice](https://w3c.github.io/csswg-drafts/css-backgrounds/#the-border-image-slice) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-image-slice` | 15 | 12 | 15 ["Small SVGs are incorrectly stretched, because percentages in [`border-image-slice`](https://developer.mozilla.org/docs/Web/CSS/border-image-slice) are computed to integers instead of floats ([bug 1284797](https://bugzil.la/1284797)).", "Until Firefox 47, SVGs without viewport were not sliced correctly ([bug 619500](https://bugzil.la/619500)).", "From Firefox 48 until Firefox 49, SVGs without viewport are displayed the same as SVGs with viewport, but if the slices are not exactly 50%, they are incorrectly stretched ([bug 1264809](https://bugzil.la/1264809)).", "Until Firefox 57, an issue persisted for SVGs without viewport when [e10s](https://wiki.mozilla.org/Electrolysis) was disabled ([bug 1290782](https://bugzil.la/1290782))."] | 11 | 15 | 6 | 4.4 4 | 18 | 15 ["Small SVGs are incorrectly stretched, because percentages in [`border-image-slice`](https://developer.mozilla.org/docs/Web/CSS/border-image-slice) are computed to integers instead of floats ([bug 1284797](https://bugzil.la/1284797)).", "Until Firefox 47, SVGs without viewport were not sliced correctly ([bug 619500](https://bugzil.la/619500)).", "From Firefox 48 until Firefox 49, SVGs without viewport are displayed the same as SVGs with viewport, but if the slices are not exactly 50%, they are incorrectly stretched ([bug 1264809](https://bugzil.la/1264809)).", "Until Firefox 57, an issue persisted for SVGs without viewport when [e10s](https://wiki.mozilla.org/Electrolysis) was disabled ([bug 1290782](https://bugzil.la/1290782))."] | 14 | 6 | 1.0 | See also -------- * [Illustrated description of the 1-to-4-value syntax](shorthand_properties#tricky_edge_cases)
programming_docs
css width width ===== The `width` CSS property sets an element's width. By default, it sets the width of the [content area](css_box_model/introduction_to_the_css_box_model#content_area), but if [`box-sizing`](box-sizing) is set to `border-box`, it sets the width of the [border area](css_box_model/introduction_to_the_css_box_model#border_area). Try it ------ The [`min-width`](min-width) and [`max-width`](max-width) properties override `width`. Syntax ------ ``` /\* <length> values \*/ width: 300px; width: 25em; /\* <percentage> value \*/ width: 75%; /\* Keyword values \*/ width: max-content; width: min-content; width: fit-content(20em); width: auto; /\* Global values \*/ width: inherit; width: initial; width: revert; width: revert-layer; width: unset; ``` ### Values [`<length>`](length) Defines the width as an absolute value. [`<percentage>`](percentage) Defines the width as a percentage of the containing block's width. `auto` The browser will calculate and select a width for the specified element. `max-content` The intrinsic preferred width. `min-content` The intrinsic minimum width. `fit-content([`<length-percentage>`](length-percentage))` Uses the fit-content formula with the available space replaced by the specified argument, i.e. `min(max-content, max(min-content, <length-percentage>))`. Accessibility concerns ---------------------- Ensure that elements set with a `width` 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](https://developer.mozilla.org/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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | all elements but non-replaced inline elements, table rows, and row groups | | [Inherited](inheritance) | no | | Percentages | refer to the width of the containing block | | [Computed value](computed_value) | a percentage or `auto` or the absolute length | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` width = auto [|](value_definition_syntax#single_bar) [<length-percentage [0,∞]>](length-percentage) [|](value_definition_syntax#single_bar) min-content [|](value_definition_syntax#single_bar) max-content [|](value_definition_syntax#single_bar) fit-content( [<length-percentage [0,∞]>](length-percentage) ) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Default width ``` p.goldie { background: gold; } ``` ``` <p class="goldie">The Mozilla community produces a lot of great software.</p> ``` ### Example using pixels and ems ``` .px\_length { width: 200px; background-color: red; color: white; border: 1px solid black; } .em\_length { width: 20em; background-color: white; color: red; border: 1px solid black; } ``` ``` <div class="px\_length">Width measured in px</div> <div class="em\_length">Width measured in em</div> ``` ### Example with percentage ``` .percent { width: 20%; background-color: silver; border: 1px solid red; } ``` ``` <div class="percent">Width in percentage</div> ``` ### Example using "max-content" ``` p.maxgreen { background: lightgreen; width: intrinsic; /\* Safari/WebKit uses a non-standard name \*/ width: -moz-max-content; /\* Firefox/Gecko \*/ width: -webkit-max-content; /\* Chrome \*/ width: max-content; } ``` ``` <p class="maxgreen">The Mozilla community produces a lot of great software.</p> ``` ### Example using "min-content" ``` p.minblue { background: lightblue; width: -moz-min-content; /\* Firefox \*/ width: -webkit-min-content; /\* Chrome \*/ width: min-content; } ``` ``` <p class="minblue">The Mozilla community produces a lot of great software.</p> ``` Specifications -------------- | Specification | | --- | | [CSS Box Sizing Module Level 4 # width-height-keywords](https://w3c.github.io/csswg-drafts/css-sizing-4/#width-height-keywords) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `width` | 1 | 12 | 1 | 4 | 3.5 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `animatable` | 26 | 12 | 16 | 11 | 15 | 7 | 4.4 | 26 | 16 | 14 | 7 | 1.5 | | `fill` | 46 | 79 | No | No | 33 | 12 | 46 | 46 | No | 33 | 12 | 5.0 | | `fit-content` | 46 22 1-48 | 79 79 | 94 3 | No | 33 15 15-35 | 11 7 2 | 46 4.4 4.4-48 | 46 25 18-48 | 94 4 | 33 14 14-35 | 11 7 1 | 5.0 1.5 1.0-5.0 | | `fit-content_function` | No | No | 91 | No | No | No | No | No | No | No | No | No | | `max-content` | 46 22 | 79 79 | 66 3 | No | 44 | 11 2 | 46 | 46 | 66 4 | 43 | 11 1 | 5.0 | | `min-content` | 46 1-48 | 79 | 66 3 | No | 33 15-35 | 11 2 | 46 4.4-48 | 46 18-48 | 66 4 | 33 14-35 | 11 1 | 5.0 1.0-5.0 | | `stretch` | 22 | 79 | 3 | No | 15 | 7 | 4.4 | 25 | 4 | 14 | 7 | 5.0 | See also -------- * [The box model](css_box_model/introduction_to_the_css_box_model) * [`height`](height) * [`box-sizing`](box-sizing) * [`min-width`](min-width), [`max-width`](max-width) * The mapped logical properties: [`block-size`](block-size), [`inline-size`](inline-size) css min-height min-height ========== The `min-height` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the minimum height of an element. It prevents the [used value](used_value) of the [`height`](height) property from becoming smaller than the value specified for `min-height`. Try it ------ The element's height is set to the value of `min-height` whenever `min-height` is larger than [`max-height`](max-height) or [`height`](height). Syntax ------ ``` /\* <length> value \*/ min-height: 3.5em; /\* <percentage> value \*/ min-height: 10%; /\* Keyword values \*/ min-height: max-content; min-height: min-content; min-height: fit-content(20em); /\* Global values \*/ min-height: inherit; min-height: initial; min-height: revert; min-height: revert-layer; min-height: unset; ``` ### Values [`<length>`](length) Defines the `min-height` as an absolute value. [`<percentage>`](percentage) Defines the `min-height` as a percentage of the containing block's height. `auto` The browser will calculate and select a `min-height` for the specified element. `max-content` The intrinsic preferred `min-height`. `min-content` The intrinsic minimum `min-height`. `fit-content([`<length-percentage>`](length-percentage))` Uses the `fit-content` formula with the available space replaced by the specified argument, i.e. `min(max-content, max(min-content, argument))`. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | all elements but non-replaced inline elements, table columns, and column groups | | [Inherited](inheritance) | no | | Percentages | The percentage is calculated with respect to the height of the generated box's containing block. If the height of the containing block is not specified explicitly (i.e., it depends on content height), and this element is not absolutely positioned, the percentage value is treated as `0`. | | [Computed value](computed_value) | the percentage as specified or the absolute length | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` min-height = auto [|](value_definition_syntax#single_bar) [<length-percentage [0,∞]>](length-percentage) [|](value_definition_syntax#single_bar) min-content [|](value_definition_syntax#single_bar) max-content [|](value_definition_syntax#single_bar) fit-content( [<length-percentage [0,∞]>](length-percentage) ) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Setting min-height ``` table { min-height: 75%; } form { min-height: 0; } ``` Specifications -------------- | Specification | | --- | | [CSS Box Sizing Module Level 3 # width-height-keywords](https://w3c.github.io/csswg-drafts/css-sizing/#width-height-keywords) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `min-height` | 1 | 12 | 3 CSS 2.1 leaves the behavior of `min-height` with [`table`](https://developer.mozilla.org/docs/Web/HTML/Element/table) undefined. Firefox supports applying `min-height` to `table` elements. | 7 In Internet Explorer 10 and 11, a `min-height` declaration on a column-direction flex container doesn't apply to the container's flex items. See [Flexbug #3](https://github.com/philipwalton/flexbugs#3-min-height-on-a-column-flex-container-wont-apply-to-its-flex-items) for more info. | 4 CSS 2.1 leaves the behavior of `min-height` with [`table`](https://developer.mozilla.org/docs/Web/HTML/Element/table) undefined. Opera supports applying `min-height` to `table` elements. | 1.3 | 4.4 | 18 | 4 CSS 2.1 leaves the behavior of `min-height` with [`table`](https://developer.mozilla.org/docs/Web/HTML/Element/table) undefined. Firefox supports applying `min-height` to `table` elements. | 14 | 1 | 1.0 | | `auto` | 21 | 79 | 16-22 Firefox 18 and later used `auto` as the initial value for `min-height`. | No | 12.1 | 7 | 37 | 25 | 16-22 Firefox 18 and later used `auto` as the initial value for `min-height`. | 14 | 7 | 1.5 | | `fit-content` | 46 25 | 79 79 | 3 Firefox implements the definitions given in CSS3 Basic Box. This defines `available` and not `fit-available`. Also, the definition of `fit-content` is simpler than in CSS3 Sizing. | No | 44 | 11 7 2 | 46 ≤37 | 46 | 4 Firefox implements the definitions given in CSS3 Basic Box. This defines `available` and not `fit-available`. Also, the definition of `fit-content` is simpler than in CSS3 Sizing. | 43 | 11 7 1 | 5.0 | | `fit-content_function` | No | No | 91 | No | No | No | No | No | No | No | No | No | | `max-content` | 46 | 79 | 66 3 | No | 44 | 11 9 | 46 | 46 | 66 4 | 43 | 11 9 | 5.0 | | `min-content` | 46 | 79 | 66 3 | No | 44 | 11 9 | 46 | 46 | 66 4 | 43 | 11 9 | 5.0 | | `stretch` | 28 | 79 | No | No | 15 | 9 | 4.4 | 28 | No | 15 | 9 | 1.5 | See also -------- * [The box model](css_box_model/introduction_to_the_css_box_model), [`box-sizing`](box-sizing) * [`height`](height), [`max-height`](max-height) css scale scale ===== The `scale` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property allows you to specify scale transforms individually and independently of the [`transform`](transform) property. This maps better to typical user interface usage, and saves having to remember the exact order of transform functions to specify in the `transform` value. Try it ------ Syntax ------ ``` /\* Keyword values \*/ scale: none; /\* Single values \*/ /\* values of more than 1 or 100% make the element grow \*/ scale: 2; /\* values of less than 1 or 100% make the element shrink \*/ scale: 50%; /\* Two values \*/ scale: 2 0.5; /\* Three values \*/ scale: 200% 50% 200%; /\* Global values \*/ scale: inherit; scale: initial; scale: revert; scale: revert-layer; scale: unset; ``` ### Values Single value A [`<number>`](number) or [`<percentage>`](percentage) specifying a scale factor to make the affected element scale by the same factor along both the X and Y axes. Equivalent to a `scale()` (2D scaling) function with a single value specified. Two values Two [`<number>`](number) or [`<percentage>`](percentage) values that specify the X and Y axis scaling values (respectively) of a 2D scale. Equivalent to a `scale()` (2D scaling) function with two values specified. Three values Three [`<number>`](number) or [`<percentage>`](percentage) values that specify the X, Y, and Z axis scaling values (respectively) of a 3D scale. Equivalent to a `scale3d()` (3D scaling) function. `none` Specifies that no scaling should be applied. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | transformable elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | a transform | | Creates [stacking context](css_positioning/understanding_z_index/the_stacking_context) | yes | Formal syntax ------------- ``` scale = none [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) []](value_definition_syntax#brackets)[{1,3}](value_definition_syntax#curly_braces) ``` Examples -------- ### Scaling an element on hover The following example shows how to scale an element on hover. Two boxes are shown, one with a single `scale` value which scales the element along both axes. The second box has two `scale` values which scales the element along the X and Y axes independently. #### HTML ``` <div class="box" id="box1">single value</div> <div class="box" id="box2">two values</div> ``` #### CSS ``` .box { float: left; margin: 1em; width: 7em; line-height: 7em; text-align: center; transition: 0.5s ease-in-out; border: 3px dotted; } #box1:hover { scale: 1.25; } #box2:hover { scale: 1.25 0.75; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Transforms Module Level 2 # individual-transforms](https://w3c.github.io/csswg-drafts/css-transforms-2/#individual-transforms) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scale` | 104 | 104 | 72 | No | 90 | 14.1 | 104 | 104 | 79 | 71 | 14.5 | No | See also -------- * [`translate`](translate) * [`rotate`](rotate) * [`transform`](transform) Note: skew is not an independent transform value css word-break word-break ========== The `word-break` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets whether line breaks appear wherever the text would otherwise overflow its content box. Try it ------ Syntax ------ ``` /\* Keyword values \*/ word-break: normal; word-break: break-all; word-break: keep-all; word-break: break-word; /\* deprecated \*/ /\* Global values \*/ word-break: inherit; word-break: initial; word-break: revert; word-break: revert-layer; word-break: unset; ``` The `word-break` property is specified as a single keyword chosen from the list of values below. ### Values `normal` Use the default line break rule. `break-all` To prevent overflow, word breaks should be inserted between any two characters (excluding Chinese/Japanese/Korean text). `keep-all` Word breaks should not be used for Chinese/Japanese/Korean (CJK) text. Non-CJK text behavior is the same as for `normal`. `break-word` Deprecated Has the same effect as `word-break: normal` and `overflow-wrap: anywhere`, regardless of the actual value of the [`overflow-wrap`](overflow-wrap) property. **Note:** In contrast to `word-break: break-word` and `overflow-wrap: break-word` (see [`overflow-wrap`](overflow-wrap)), `word-break: break-all` will create a break at the exact place where text would otherwise overflow its container (even if putting an entire word on its own line would negate the need for a break). **Note:** While `word-break: break-word` is deprecated, it has the same effect, when specified, as `word-break: normal` and `overflow-wrap: anywhere` — regardless of the actual value of the [`overflow-wrap`](overflow-wrap) property. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | all elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` word-break = normal [|](value_definition_syntax#single_bar) keep-all [|](value_definition_syntax#single_bar) break-all [|](value_definition_syntax#single_bar) break-word ``` Examples -------- ### HTML ``` <p>1. <code>word-break: normal</code></p> <p class="normal narrow"> This is a long and Honorificabilitudinitatibus califragilisticexpialidocious Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu グレートブリテンおよび北アイルランド連合王国という言葉は本当に長い言葉 </p> <p>2. <code>word-break: break-all</code></p> <p class="breakAll narrow"> This is a long and Honorificabilitudinitatibus califragilisticexpialidocious Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu グレートブリテンおよび北アイルランド連合王国という言葉は本当に長い言葉 </p> <p>3. <code>word-break: keep-all</code></p> <p class="keepAll narrow"> This is a long and Honorificabilitudinitatibus califragilisticexpialidocious Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu グレートブリテンおよび北アイルランド連合王国という言葉は本当に長い言葉 </p> <p>4. <code>word-break: break-word</code></p> <p class="breakWord narrow"> This is a long and Honorificabilitudinitatibus califragilisticexpialidocious Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu グレートブリテンおよび北アイルランド連合王国という言葉は本当に長い言葉 </p> ``` ### CSS ``` .narrow { padding: 10px; border: 1px solid; width: 500px; margin: 0 auto; font-size: 20px; line-height: 1.5; letter-spacing: 1px; } .normal { word-break: normal; } .breakAll { word-break: break-all; } .keepAll { word-break: keep-all; } .breakWord { word-break: break-word; } ``` Specifications -------------- | Specification | | --- | | [CSS Text Module Level 3 # word-break-property](https://w3c.github.io/csswg-drafts/css-text/#word-break-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `word-break` | 1 | 12 | 15 | 8 Don't use `-ms-word-break`, which is a synonym for `word-break`. 5.5 No version of Internet Explorer supports the `initial` value. | 15 | 3 | ≤37 | 18 | 15 | 14 | 2 | 1.0 | | `break-word` | 1 | 79 | 67 | No | 15 | 3 | ≤37 | 18 | 67 | 14 | 2 | 1.0 | | `keep-all` | 44 | 12 | 15 | 5.5 | 31 | 9 | 44 | 44 | 15 | 32 | 9 | 4.0 | See also -------- * [`overflow-wrap`](overflow-wrap) * [`hyphens`](hyphens) * [`line-break`](line-break) * [Guide to wrapping and breaking text](css_text/wrapping_text) css font-stretch font-stretch ============ The `font-stretch` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property selects a normal, condensed, or expanded face from a font. Try it ------ Syntax ------ ``` /\* Keyword values \*/ font-stretch: ultra-condensed; font-stretch: extra-condensed; font-stretch: condensed; font-stretch: semi-condensed; font-stretch: normal; font-stretch: semi-expanded; font-stretch: expanded; font-stretch: extra-expanded; font-stretch: ultra-expanded; /\* Percentage values \*/ font-stretch: 50%; font-stretch: 100%; font-stretch: 200%; /\* Global values \*/ font-stretch: inherit; font-stretch: initial; font-stretch: revert; font-stretch: revert-layer; font-stretch: unset; ``` This property may be specified as a single keyword value or a single [`<percentage>`](percentage) value. ### Values `normal` Specifies a normal font face. `semi-condensed`, `condensed`, `extra-condensed`, `ultra-condensed` Specifies a more condensed font face than normal, with `ultra-condensed` as the most condensed. `semi-expanded`, `expanded`, `extra-expanded`, `ultra-expanded` Specifies a more expanded font face than normal, with `ultra-expanded` as the most expanded. `<percentage>` A [`<percentage>`](percentage) value between 50% and 200% (inclusive). Negative values are not allowed for this property. ### Keyword to numeric mapping The table below shows the mapping between keyword values and numeric percentages: | Keyword | Percentage | | --- | --- | | `ultra-condensed` | 50% | | `extra-condensed` | 62.5% | | `condensed` | 75% | | `semi-condensed` | 87.5% | | `normal` | 100% | | `semi-expanded` | 112.5% | | `expanded` | 125% | | `extra-expanded` | 150% | | `ultra-expanded` | 200% | Description ----------- Some font families offer additional faces in which the characters are narrower than the normal face (*condensed* faces) or wider than the normal face (*expanded* faces). You can use `font-stretch` to select a condensed or expanded face from such fonts. If the font you are using does not offer condensed or expanded faces, this property has no effect. ### Font face selection The face selected for a given value of `font-stretch` depends on the faces supported by the font in question. If the font does not provide a face that exactly matches the given value, then values less than 100% map to a narrower face, and values greater than or equal to 100% map to a wider face. The table below demonstrates the effect of supplying various different percentage values of `font-stretch` on two different fonts: * [Anek Malayalam](https://fonts.google.com/specimen/Anek+Malayalam) is a variable google font that supports widths from 75% to 125%. Values below and above this range select the closest matching font. * [Inconsolata](https://fonts.google.com/specimen/Inconsolata) is a variable font that offers a continuous range of widths from 50% to 200%. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | a [font stretch](font-stretch#Interpolation) | Formal syntax ------------- ``` font-stretch = normal [|](value_definition_syntax#single_bar) [<percentage [0,∞]>](percentage) [|](value_definition_syntax#single_bar) ultra-condensed [|](value_definition_syntax#single_bar) extra-condensed [|](value_definition_syntax#single_bar) condensed [|](value_definition_syntax#single_bar) semi-condensed [|](value_definition_syntax#single_bar) semi-expanded [|](value_definition_syntax#single_bar) expanded [|](value_definition_syntax#single_bar) extra-expanded [|](value_definition_syntax#single_bar) ultra-expanded ``` Examples -------- ### Setting font stretch percentages Specifications -------------- | Specification | | --- | | [CSS Fonts Module Level 4 # font-stretch-prop](https://w3c.github.io/csswg-drafts/css-fonts/#font-stretch-prop) | **Note:** The `font-stretch` property was initially defined in CSS 2, but dropped in CSS 2.1 due to the lack of browser implementation. It was brought back in CSS 3. Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `font-stretch` | 60 A `font-stretch` definition must be added to the `@font-face` before this property will function. | 12 | 9 | 9 | 47 A `font-stretch` definition must be added to the `@font-face` before this property will function. | 11 | 60 A `font-stretch` definition must be added to the `@font-face` before this property will function. | 60 A `font-stretch` definition must be added to the `@font-face` before this property will function. | 9 | 44 A `font-stretch` definition must be added to the `@font-face` before this property will function. | 11 | 8.0 A `font-stretch` definition must be added to the `@font-face` before this property will function. | | `percentage` | 62 | 18 | 61 | No | 49 | 11.1 | 62 | 62 | 61 | 46 | 11.3 | 8.0 | See also -------- * [`font-style`](font-style) * [`font-weight`](font-weight) * [Fundamental text and font styling](https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text/Fundamentals)
programming_docs
css tan() tan() ===== The `tan()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](css_functions) is a trigonometric function that returns the tangent of a number, which is a value between `−infinity` and `infinity`. The function contains a single calculation that must resolve to either a [`<number>`](number) or an [`<angle>`](angle) by interpreting the result of the argument as radians. Syntax ------ ``` /\* Single <angle> values \*/ width: calc(100px * tan(45deg)); width: calc(100px * tan(0.125turn)); width: calc(100px * tan(0.785398163rad)); /\* Single <number> values \*/ width: calc(100px * tan(0.5773502)); width: calc(100px * tan(1.732 – 1)); /\* Other values \*/ width: calc(100px * tan(pi / 3)); width: calc(100px * tan(e)); ``` ### Parameter The `tan(angle)` function accepts only one value as its parameter. `angle` A calculation which resolves to a [`<number>`](number) or an [`<angle>`](angle). When specifying unitless numbers they are interpreted as a number of radians, representing an [`<angle>`](angle). ### Return value The tangent of an `angle` will always return a number between `−∞` and `+∞`. * If `angle` is `infinity`, `-infinity`, or `NaN`, the result is `NaN`. * If `angle` is `0⁻`, the result is `0⁻`. * If `angle` is one of the asymptote values (such as `90deg`, `270deg`, etc), the result must be `∞` for `90deg` and all values a multiple of `360deg` from that (such as `-270deg` or `450deg`), and `−∞` for `-90deg` and all values a multiple of `360deg` from that (such as `-450deg` or `270deg`). ### Formal syntax ``` <tan()> = tan( <calc-sum> ) <calc-sum> = <calc-product> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '+' [|](value_definition_syntax#single_bar) '-' []](value_definition_syntax#brackets) <calc-product> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-product> = <calc-value> [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) '*' [|](value_definition_syntax#single_bar) '/' []](value_definition_syntax#brackets) <calc-value> []](value_definition_syntax#brackets)[\*](value_definition_syntax#asterisk) <calc-value> = [<number>](number) [|](value_definition_syntax#single_bar) [<dimension>](dimension) [|](value_definition_syntax#single_bar) [<percentage>](percentage) [|](value_definition_syntax#single_bar) <calc-constant> [|](value_definition_syntax#single_bar) ( <calc-sum> ) <calc-constant> = e [|](value_definition_syntax#single_bar) pi [|](value_definition_syntax#single_bar) infinity [|](value_definition_syntax#single_bar) -infinity [|](value_definition_syntax#single_bar) NaN ``` Examples -------- ### Draw parallelograms The `tan()` function can be used draw a parallelogram. #### HTML ``` <div class="parallelogram"></div> ``` #### CSS ``` .parallelogram { --w: 400; --h: 200; position: relative; width: calc(1px * var(--w)); height: calc(1px * var(--h)); } .parallelogram::before { --angle: calc(sin(var(--h) / var(--w))); content: ""; position: absolute; width: calc(100% - 100% * var(--h) / var(--w) * tan(var(--angle))); height: 100%; transform-origin: 0 100%; transform: skew(calc(0 - var(--angle))); background-color: red; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Values and Units Module Level 4 # trig-funcs](https://w3c.github.io/csswg-drafts/css-values/#trig-funcs) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `tan` | No | No | 108 | No | No | 15.4 | No | No | 108 | No | 15.4 | No | See also -------- * [`sin()`](sin) * [`cos()`](cos) * [`asin()`](asin) * [`acos()`](acos) * [`atan()`](atan) * [`atan2()`](atan2) css border-radius border-radius ============= The `border-radius` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property rounds the corners of an element's outer border edge. You can set a single radius to make circular corners, or two radii to make elliptical corners. Try it ------ The radius applies to the whole [`background`](background), even if the element has no border; the exact position of the clipping is defined by the [`background-clip`](background-clip) property. The `border-radius` property does not apply to table elements when [`border-collapse`](border-collapse) is `collapse`. **Note:** As with any shorthand property, individual sub-properties cannot inherit, such as in `border-radius:0 0 inherit inherit`, which would partially override existing definitions. Instead, the individual longhand properties have to be used. Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`border-top-left-radius`](border-top-left-radius) * [`border-top-right-radius`](border-top-right-radius) * [`border-bottom-right-radius`](border-bottom-right-radius) * [`border-bottom-left-radius`](border-bottom-left-radius) Syntax ------ ``` /\* The syntax of the first radius allows one to four values \*/ /\* Radius is set for all 4 sides \*/ border-radius: 10px; /\* top-left-and-bottom-right | top-right-and-bottom-left \*/ border-radius: 10px 5%; /\* top-left | top-right-and-bottom-left | bottom-right \*/ border-radius: 2px 4px 2px; /\* top-left | top-right | bottom-right | bottom-left \*/ border-radius: 1px 0 3px 4px; /\* The syntax of the second radius allows one to four values \*/ /\* (first radius values) / radius \*/ border-radius: 10px / 20px; /\* (first radius values) / top-left-and-bottom-right | top-right-and-bottom-left \*/ border-radius: 10px 5% / 20px 30px; /\* (first radius values) / top-left | top-right-and-bottom-left | bottom-right \*/ border-radius: 10px 5px 2em / 20px 25px 30%; /\* (first radius values) / top-left | top-right | bottom-right | bottom-left \*/ border-radius: 10px 5% / 20px 25em 30px 35em; /\* Global values \*/ border-radius: inherit; border-radius: initial; border-radius: revert; border-radius: revert-layer; border-radius: unset; ``` The `border-radius` property is specified as: * one, two, three, or four [`<length>`](length) or [`<percentage>`](percentage) values. This is used to set a single radius for the corners. * followed optionally by "/" and one, two, three, or four `<length>` or `<percentage>` values. This is used to set an additional radius, so you can have elliptical corners. ### Values | | | | | --- | --- | --- | | *radius* | | Is a [`<length>`](length) or a [`<percentage>`](percentage) denoting a radius to use for the border in each corner of the border. It is used only in the one-value syntax. | | *top-left-and-bottom-right* | | Is a [`<length>`](length) or a [`<percentage>`](percentage) denoting a radius to use for the border in the top-left and bottom-right corners of the element's box. It is used only in the two-value syntax. | | *top-right-and-bottom-left* | | Is a [`<length>`](length) or a [`<percentage>`](percentage) denoting a radius to use for the border in the top-right and bottom-left corners of the element's box. It is used only in the two- and three-value syntaxes. | | *top-left* | | Is a [`<length>`](length) or a [`<percentage>`](percentage) denoting a radius to use for the border in the top-left corner of the element's box. It is used only in the three- and four-value syntaxes. | | *top-right* | | Is a [`<length>`](length) or a [`<percentage>`](percentage) denoting a radius to use for the border in the top-right corner of the element's box. It is used only in the four-value syntax. | | *bottom-right* | | Is a [`<length>`](length) or a [`<percentage>`](percentage) denoting a radius to use for the border in the bottom-right corner of the element's box. It is used only in the three- and four-value syntaxes. | | *bottom-left* | | Is a [`<length>`](length) or a [`<percentage>`](percentage) denoting a radius to use for the border in the bottom-left corner of the element's box. It is used only in the four-value syntax. | [`<length>`](length) Denotes the size of the circle radius, or the semi-major and semi-minor axes of the ellipse, using length values. Negative values are invalid. [`<percentage>`](percentage) Denotes the size of the circle radius, or the semi-major and semi-minor axes of the ellipse, using percentage values. Percentages for the horizontal axis refer to the width of the box; percentages for the vertical axis refer to the height of the box. Negative values are invalid. For example: ``` border-radius: 1em/5em; /\* It is equivalent to: \*/ border-top-left-radius: 1em 5em; border-top-right-radius: 1em 5em; border-bottom-right-radius: 1em 5em; border-bottom-left-radius: 1em 5em; ``` ``` border-radius: 4px 3px 6px / 2px 4px; /\* It is equivalent to: \*/ border-top-left-radius: 4px 2px; border-top-right-radius: 3px 4px; border-bottom-right-radius: 6px 2px; border-bottom-left-radius: 3px 4px; ``` Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`border-top-left-radius`](border-top-left-radius): `0` * [`border-top-right-radius`](border-top-right-radius): `0` * [`border-bottom-right-radius`](border-bottom-right-radius): `0` * [`border-bottom-left-radius`](border-bottom-left-radius): `0` | | Applies to | all elements; but User Agents are not required to apply to `table` and `inline-table` elements when [`border-collapse`](border-collapse) is `collapse`. The behavior on internal table elements is undefined for the moment.. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | Percentages | refer to the corresponding dimension of the border box | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`border-bottom-left-radius`](border-bottom-left-radius): two absolute [`<length>`](length)s or [`<percentage>`](percentage)s * [`border-bottom-right-radius`](border-bottom-right-radius): two absolute [`<length>`](length)s or [`<percentage>`](percentage)s * [`border-top-left-radius`](border-top-left-radius): two absolute [`<length>`](length)s or [`<percentage>`](percentage)s * [`border-top-right-radius`](border-top-right-radius): two absolute [`<length>`](length)s or [`<percentage>`](percentage)s | | Animation type | as each of the properties of the shorthand:* [`border-top-left-radius`](border-top-left-radius): a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); * [`border-top-right-radius`](border-top-right-radius): a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); * [`border-bottom-right-radius`](border-bottom-right-radius): a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); * [`border-bottom-left-radius`](border-bottom-left-radius): a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` border-radius = [<length-percentage [0,∞]>](length-percentage)[{1,4}](value_definition_syntax#curly_braces) [[](value_definition_syntax#brackets) / [<length-percentage [0,∞]>](length-percentage)[{1,4}](value_definition_syntax#curly_braces) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Live Samples * Sample 1 : <https://jsfiddle.net/Tripad/qnGKj/2/> * Sample 2 : <https://jsfiddle.net/Tripad/qnGKj/3/> * Sample 3 : <https://jsfiddle.net/Tripad/qnGKj/4/> * Sample 4 : <https://jsfiddle.net/Tripad/qnGKj/5/> * Sample 5 : <https://jsfiddle.net/Tripad/qnGKj/6/> Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # border-radius](https://w3c.github.io/csswg-drafts/css-backgrounds/#border-radius) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `4_values_for_4_corners` | 4 | 12 | 4 | 9 | 10.5 | 5 | ≤37 | 18 | 4 | 11 | 4.2 | 1.0 | | `border-radius` | 4 Chrome ignores `border-radius` on `<select>` elements unless `-webkit-appearance` is overridden to an appropriate value. 1 | 12 12 | 4 ["Before Firefox 50, border styles of rounded corners (with `border-radius`) were always rendered as if `border-style` was `solid`. This has been fixed in Firefox 50.", "To conform to the CSS3 standard, Firefox 4 changes the handling of [`<percentage>`](https://developer.mozilla.org/docs/Web/CSS/percentage) values to match the specification. You can specify an ellipse as a border on an arbitrary sized element with `border-radius: 50%;`. Firefox 4 also makes rounded corners clip content and images if [`overflow`](https://developer.mozilla.org/docs/Web/CSS/overflow)`: visible` is not set."] 1-12 | 9 | 10.5 Before Opera 11.60, replaced elements with `border-radius` do not have rounded corners. | 5 Safari ignores `border-radius` on `<select>` elements unless `-webkit-appearance` is overridden to an appropriate value. 3 | ≤37 2 | 18 | 4 Before Firefox 50, border styles of rounded corners (with `border-radius`) were always rendered as if `border-style` was `solid`. This has been fixed in Firefox 50. 4-14 | 11 | 4.2 Safari ignores `border-radius` on `<select>` elements unless `-webkit-appearance` is overridden to an appropriate value. 1 | 1.0 | | `elliptical_borders` | 1 Before Chrome 4, the slash `/` notation is unsupported. If two values are specified, then an elliptical border is drawn on all four corners. `-webkit-border-radius: 40px 10px;` is equivalent to `border-radius: 40px / 10px;`. | 12 | 4 | 9 | 10.5 | 3 Before Safari 5, the slash `/` notation is unsupported. If two values are specified, then an elliptical border is drawn on all four corners. `-webkit-border-radius: 40px 10px;` is equivalent to `border-radius: 40px / 10px;`. | ≤37 | 18 | 4 | 11 | 4.2 | 1.0 | | `percentages` | 8 | 12 | 4 Before Firefox 4, `<percentage>` values are implemented in a non-standard way. Both horizontal and vertical radii were relative to the width of the border box. | 9 | 11.5 Before Opera 11.5, the implementation of `<percentage>` values was buggy. | 5.1 | ≤37 | 18 | 4 | 11.5 | 5 | 1.0 | See also -------- * Border-radius-related CSS properties: [`border-top-left-radius`](border-top-left-radius), [`border-top-right-radius`](border-top-right-radius), [`border-bottom-right-radius`](border-bottom-right-radius), [`border-bottom-left-radius`](border-bottom-left-radius), [`border-start-start-radius`](border-start-start-radius), [`border-start-end-radius`](border-start-end-radius), [`border-end-start-radius`](border-end-start-radius), [`border-end-end-radius`](border-end-end-radius) css place-items place-items =========== The [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) `place-items` [shorthand property](shorthand_properties) allows you to align items along both the block and inline directions at once (i.e. the [`align-items`](align-items) and [`justify-items`](justify-items) properties) in a relevant layout system such as [Grid](css_grid_layout) or [Flexbox](css_flexible_box_layout). If the second value is not set, the first value is also used for it. Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`align-items`](align-items) * [`justify-items`](justify-items) Syntax ------ ``` /\* Keyword values \*/ place-items: center; place-items: normal start; /\* Positional alignment \*/ place-items: center normal; place-items: start legacy; place-items: end normal; place-items: self-start legacy; place-items: self-end normal; place-items: flex-start legacy; place-items: flex-end normal; place-items: left legacy; place-items: right normal; /\* Baseline alignment \*/ place-items: baseline normal; place-items: first baseline legacy; place-items: last baseline normal; place-items: stretch legacy; /\* Global values \*/ place-items: inherit; place-items: initial; place-items: revert; place-items: revert-layer; place-items: unset; ``` ### Values One of the following forms: * A single [`align-items`](align-items) value, which is used to set alignment in both block and inline directions. * An [`align-items`](align-items) value, which sets alignment in the block direction, followed by a [`justify-items`](justify-items) value, which sets alignment in the inline direction. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`align-items`](align-items): `normal` * [`justify-items`](justify-items): `legacy` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`align-items`](align-items): as specified * [`justify-items`](justify-items): as specified | | Animation type | discrete | Formal syntax ------------- ``` place-items = <'align-items'> <'justify-items'>[?](value_definition_syntax#question_mark) ``` Examples -------- ### Placing items in a flex container In flexbox [`justify-self`](justify-self) or [`justify-items`](justify-items) do not apply, as on the main axis items are treated as a group. Therefore, the second value will be ignored. #### CSS ``` #container { height: 200px; width: 240px; place-items: stretch; /\* You can change this value by selecting another option in the list \*/ background-color: #8c8c8c; display: flex; } ``` #### Result ### Placing items in a grid container The following grid container has items which are smaller than the grid areas they are placed in, therefore `place-items` will move them in the block and inline dimensions. #### CSS ``` #gridcontainer { height: 200px; width: 240px; place-items: stretch; /\* You can change this value by selecting another option in the list \*/ background-color: #8c8c8c; display: grid; grid-template-columns: repeat(3, 1fr); } #gridcontainer > div { width: 50px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Box Alignment Module Level 3 # place-items-property](https://w3c.github.io/csswg-drafts/css-align/#place-items-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `place-items` | 59 | 79 | 45 | No | 46 | 11 | 59 | 59 | 45 | 43 | 11 | 7.0 | | `flex_context` | 59 | 79 | 45 | No | 46 | 11 | 59 | 59 | 45 | 43 | 11 | 7.0 | | `grid_context` | 59 | 79 | 45 | No | 46 | 11 | 59 | 59 | 45 | 43 | 11 | 7.0 | See also -------- * CSS Flexbox Guide: *[Basic Concepts of Flexbox](css_flexible_box_layout/basic_concepts_of_flexbox)* * CSS Flexbox Guide: *[Aligning items in a flex container](css_flexible_box_layout/aligning_items_in_a_flex_container)* * CSS Grid Guide: *[Box alignment in CSS Grid layouts](css_grid_layout/box_alignment_in_css_grid_layout)* * [CSS Box Alignment](css_box_alignment) * The [`align-items`](align-items) property * The [`align-self`](align-self) property * The [`justify-items`](justify-items) property * The [`justify-self`](justify-self) property css border-end-end-radius border-end-end-radius ===================== The `border-end-end-radius` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines a logical border radius on an element, which maps to a physical border radius that depends on the element's [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). This is useful when building styles to work regardless of the [text orientation](text-orientation) and [writing mode](css_writing_modes). Try it ------ This property affects the corner between the block-end and the inline-end sides of the element. For instance, in a `horizontal-tb` writing mode with `ltr` direction, it corresponds to the [`border-bottom-right-radius`](border-bottom-right-radius) property. Syntax ------ ``` /\* <length> values \*/ /\* With one value the corner will be a circle \*/ border-end-end-radius: 10px; border-end-end-radius: 1em; /\* With two values the corner will be an ellipse \*/ border-end-end-radius: 1em 2em; /\* Global values \*/ border-end-end-radius: inherit; border-end-end-radius: initial; border-end-end-radius: revert; border-end-end-radius: revert-layer; border-end-end-radius: unset; ``` ### Values `<length-percentage>` Denotes the size of the circle radius or the semi-major and semi-minor axes of the ellipse. As absolute length it can be expressed in any unit allowed by the CSS [`<length>`](length) data type. Percentages for the horizontal axis refer to the width of the box, percentages for the vertical axis refer to the height of the box. Negative values are invalid. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | all elements; but User Agents are not required to apply to `table` and `inline-table` elements when [`border-collapse`](border-collapse) is `collapse`. The behavior on internal table elements is undefined for the moment.. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | Percentages | refer to the corresponding dimension of the border box | | [Computed value](computed_value) | two absolute [`<length>`](length)s or [`<percentage>`](percentage)s | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` border-end-end-radius = <'border-top-left-radius'> ``` Examples -------- ### Border radius with vertical text #### HTML ``` <div> <p class="exampleText">Example</p> </div> ``` #### CSS Content ``` div { background-color: rebeccapurple; width: 120px; height: 120px; border-end-end-radius: 10px; } .exampleText { writing-mode: vertical-rl; padding: 10px; background-color: #fff; border-end-end-radius: 10px; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # border-radius-properties](https://w3c.github.io/csswg-drafts/css-logical/#border-radius-properties) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-end-end-radius` | 89 | 89 | 66 | No | 75 | 15 | 89 | 89 | 66 | No | 15 | 15.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * The mapped physical property: [`border-bottom-right-radius`](border-bottom-right-radius) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation)
programming_docs
css table-layout table-layout ============ The `table-layout` CSS property sets the algorithm used to lay out [`<table>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table) cells, rows, and columns. Try it ------ Syntax ------ ``` /\* Keyword values \*/ table-layout: auto; table-layout: fixed; /\* Global values \*/ table-layout: inherit; table-layout: initial; table-layout: revert; table-layout: revert-layer; table-layout: unset; ``` ### Values `auto` By default, most browsers use an automatic table layout algorithm. The widths of the table and its cells are adjusted to fit the content. `fixed` Table and column widths are set by the widths of `table` and `col` elements or by the width of the first row of cells. Cells in subsequent rows do not affect column widths. Under the "fixed" layout method, the entire table can be rendered once the first table row has been downloaded and analyzed. This can speed up rendering time over the "automatic" layout method, but subsequent cell content might not fit in the column widths provided. Cells use the [`overflow`](overflow) property to determine whether to clip any overflowing content, but only if the table has a known width; otherwise, they won't overflow the cells. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `auto` | | Applies to | `table` and `inline-table` elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` table-layout = auto [|](value_definition_syntax#single_bar) fixed ``` Examples -------- ### Fixed-width tables with text-overflow This example uses a fixed table layout, combined with the [`width`](width) property, to restrict the table's width. The [`text-overflow`](text-overflow) property is used to apply an ellipsis to words that are too long to fit. If the table layout were `auto`, the table would grow to accommodate its contents, despite the specified `width`. #### HTML ``` <table> <tr> <td>Ed</td> <td>Wood</td> </tr> <tr> <td>Albert</td> <td>Schweitzer</td> </tr> <tr> <td>Jane</td> <td>Fonda</td> </tr> <tr> <td>William</td> <td>Shakespeare</td> </tr> </table> ``` #### CSS ``` table { table-layout: fixed; width: 120px; border: 1px solid red; } td { border: 1px solid blue; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } ``` #### Result Specifications -------------- | Specification | | --- | | [Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification # width-layout](https://w3c.github.io/csswg-drafts/css2/#width-layout) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `table-layout` | 14 | 12 | 1 | 5 | 7 | 1 | 1.5 | 18 | 4 | 10.1 | 3 | 1.0 | See also -------- * [`<table>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table) css <shape> <shape> ======= **Deprecated:** This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the [compatibility table](#browser_compatibility) at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time. The `<shape>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) defines the specific form (shape) of a region. The region represents the part of an element to which the [`clip`](clip) property applies. **Note:** `<shape>` and `rect()` work in conjunction with [`clip`](clip), which has been deprecated in favor of [`clip-path`](clip-path). When possible, use `clip-path` and the [`<basic-shape>`](basic-shape) data type instead. Syntax ------ The `<shape>` data type is specified using the `rect()` function, which produces a region in the form of a rectangle. `rect()` ``` rect(top, right, bottom, left) ``` ### Values *top* Is a [`<length>`](length) representing the offset for the top of the rectangle relative to the top border of the element's box. *right* Is a [`<length>`](length) representing the offset for the right of the rectangle relative to the left border of the element's box. *bottom* Is a [`<length>`](length) representing the offset for the bottom of the rectangle relative to the top border of the element's box. *left* Is a [`<length>`](length) representing the offset for the left of the rectangle relative to the left border of the element's box. Interpolation ------------- When animated, values of the `<shape>` data type are interpolated over their `top`, `right`, `bottom`, and `left` components, each treated as a real, floating-point number. The speed of the interpolation is determined by the [timing function](easing-function) associated with the animation. Example ------- ### Example demonstrating correct use of the rect() function ``` img.clip04 { clip: rect(10px, 20px, 20px, 10px); } ``` Specifications -------------- | Specification | | --- | | [Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification # value-def-shape](https://w3c.github.io/csswg-drafts/css2/#value-def-shape) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `shape` | 1 | 12 | 1 | 5.5 | 9.5 | 1.3 | 37 | 18 | 4 | 14 | 1 | 1.0 | | `rect` | 1 | 12 | 1 | 5.5 For Internet Explorer versions 5.5 through 7, the `rect()` function uses spaces (instead of commas) to separate parameters. For Internet Explorer 8 and later versions, only the standard comma-separated syntax is supported. | 9.5 | 1.3 | 37 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * Related CSS property: [`clip`](clip) * The [`-moz-image-rect()`](-moz-image-rect) function has similar coordinate values to `rect()`. css font-palette font-palette ============ The `font-palette` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property allows specifying one of the many palettes contained in a font that a user agent should use for the font. Users can also override the values in a palette or create a new palette by using the <@font-palette-values> at-rule. Syntax ------ ``` /\* Using a font-defined palette \*/ font-palette: normal; /\* Using a user-defined palette \*/ font-palette: --one; ``` ### Values `normal` Specifies the default color palette or the default glyph colorization (set by the font maker) to be used for the font. With this setting, the palette in the font at index 0 is rendered. `light` Specifies the first palette in the font that matches 'light' to be used for the font. Some fonts contain metadata that identify a palette as applicable for a light (close to white) background. If a font does not have this metadata, the `light` value behaves as `normal`. `dark` Specifies the first palette in the font that matches 'dark' to be used for the font. Some fonts contain metadata that identify a palette as applicable for a dark (close to black) background. If a font does not have this metadata, the value behaves as `normal`. `<palette-identifier>` Allows you to specify your own values for the font palette by using the <@font-palette-values> at-rule. This value is specified using the [<dashed-ident>](dashed-ident) format. Formal definition ----------------- Value not found in DB!Formal syntax ------------- ``` font-palette = normal [|](value_definition_syntax#single_bar) light [|](value_definition_syntax#single_bar) dark [|](value_definition_syntax#single_bar) [<palette-identifier>](palette-identifier) ``` Examples -------- ### Specifying a dark palette This example allows you to use the first palette marked as *dark* (works best on a near black background) by the font-maker. ``` @media (prefers-color-scheme: dark) { .banner { font-palette: dark; } } ``` Specifications -------------- | Specification | | --- | | [CSS Fonts Module Level 4 # font-palette-prop](https://w3c.github.io/csswg-drafts/css-fonts/#font-palette-prop) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `font-palette` | 101 | 101 | 107 | No | 87 | 15.4 | 101 | 101 | 107 | 70 | 15.4 | 19.0 | See also -------- * [`@font-palette-values`](@font-palette-values) * [`base-palette`](@font-palette-values/base-palette) descriptor * [`font-family`](@font-palette-values/font-family) descriptor * [`override-colors`](@font-palette-values/override-colors) descriptor css :optional :optional ========= The `:optional` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) represents any [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input), [`<select>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select), or [`<textarea>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea) element that does not have the [`required`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-required) attribute set on it. Try it ------ This pseudo-class is useful for styling fields that are not required to submit a form. **Note:** The [`:required`](:required) pseudo-class selects *required* form fields. Syntax ------ ``` :optional ``` Examples -------- ### The optional field has a purple border #### HTML ``` <form> <div class="field"> <label for="url\_input">Enter a URL:</label> <input type="url" id="url\_input" /> </div> <div class="field"> <label for="email\_input">Enter an email address:</label> <input type="email" id="email\_input" required /> </div> </form> ``` #### CSS ``` label { display: block; margin: 1px; padding: 1px; } .field { margin: 1px; padding: 1px; } input:optional { border-color: rebeccapurple; border-width: 3px; } ``` #### Result Accessibility concerns ---------------------- If a [form](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form) contains optional [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input)s, required inputs should be indicated using the [`required`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-required) attribute. This will ensure that people navigating with the aid of assistive technology such as a screen reader will be able to understand which inputs need valid content to ensure a successful form submission. Required inputs should also be indicated visually, using a treatment that does not rely solely on color to convey meaning. Typically, descriptive text and/or an icon are used. * [MDN Understanding WCAG, Guideline 3.3 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Understandable#guideline_3.3_%e2%80%94_input_assistance_help_users_avoid_and_correct_mistakes) * [Understanding Success Criterion 3.3.2 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/minimize-error-cues.html) Specifications -------------- | Specification | | --- | | [HTML Standard # selector-optional](https://html.spec.whatwg.org/multipage/semantics-other.html#selector-optional) | | [Selectors Level 4 # opt-pseudos](https://w3c.github.io/csswg-drafts/selectors/#opt-pseudos) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:optional` | 10 | 12 | 4 | 10 | 10 | 5 | 37 | 18 | 4 | 10.1 | 5 | 1.0 | See also -------- * Other validation-related pseudo-classes: [`:required`](:required), [`:invalid`](:invalid), [`:valid`](:valid) * [Form data validation](https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation) css border-block-color border-block-color ================== The `border-block-color` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the color of the logical block borders of an element, which maps to a physical border color depending on the element's writing mode, directionality, and text orientation. It corresponds to the [`border-top-color`](border-top-color) and [`border-bottom-color`](border-bottom-color), or [`border-right-color`](border-right-color) and [`border-left-color`](border-left-color) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ The border color in the other dimension can be set with [`border-inline-color`](border-inline-color) which sets [`border-inline-start-color`](border-inline-start-color), and [`border-inline-end-color`](border-inline-end-color). Syntax ------ ``` border-block-color: yellow; border-block-color: #f5f6f7; /\* Global values \*/ border-block-color: inherit; border-block-color: initial; border-block-color: revert; border-block-color: revert-layer; border-block-color: unset; ``` ### Values `<'color'>` The color of the border. See [`color`](color). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `currentcolor` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | computed color | | Animation type | discrete | Formal syntax ------------- ``` border-block-color = <'border-top-color'>[{1,2}](value_definition_syntax#curly_braces) ``` Examples -------- ### Border with vertical text #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; border: 10px solid blue; border-block-color: red; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # propdef-border-block-color](https://w3c.github.io/csswg-drafts/css-logical/#propdef-border-block-color) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-block-color` | 87 | 87 | 66 | No | 73 | 14.1 | 87 | 87 | 66 | 62 | 14.5 | 14.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * This property maps to the physical border properties: [`border-top-color`](border-top-color), [`border-right-color`](border-right-color), [`border-bottom-color`](border-bottom-color), or [`border-left-color`](border-left-color). * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation)+ bug 1297097 css ::slotted() ::slotted() =========== The `::slotted()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-element](pseudo-elements) represents any element that has been placed into a slot inside an HTML template (see [Using templates and slots](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_templates_and_slots) for more information). This only works when used inside CSS placed within a [shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM). Note also that this selector won't select a text node placed into a slot; it only targets actual elements. ``` /\* Selects any element placed inside a slot \*/ ::slotted(\*) { font-weight: bold; } /\* Selects any <span> placed inside a slot \*/ ::slotted(span) { font-weight: bold; } ``` Syntax ------ ``` ::slotted( <compound-selector> ) ``` Examples -------- ### Highlighting slotted elements The following snippets are taken from our [slotted-pseudo-element](https://github.com/mdn/web-components-examples/tree/main/slotted-pseudo-element) demo ([see it live also](https://mdn.github.io/web-components-examples/slotted-pseudo-element/)). In this demo we use a simple template with three slots: ``` <template id="person-template"> <div> <h2>Personal ID Card</h2> <slot name="person-name">NAME MISSING</slot> <ul> <li><slot name="person-age">AGE MISSING</slot></li> <li><slot name="person-occupation">OCCUPATION MISSING</slot></li> </ul> </div> </template> ``` A custom element — `<person-details>` — is defined like so: ``` customElements.define('person-details', class extends HTMLElement { constructor() { super(); let template = document.getElementById('person-template'); let templateContent = template.content; const shadowRoot = this.attachShadow({mode: 'open'}); let style = document.createElement('style'); style.textContent = 'div { padding: 10px; border: 1px solid gray; width: 200px; margin: 10px; }' + 'h2 { margin: 0 0 10px; }' + 'ul { margin: 0; }' + 'p { margin: 10px 0; }' + '::slotted(\*) { color: gray; font-family: sans-serif; } '; shadowRoot.appendChild(style); shadowRoot.appendChild(templateContent.cloneNode(true)); } }) ``` You'll see that when filling the `style` element with content, we select all slotted elements (`::slotted(*)`) and give them a different font and color. This allows them to stand out better next to the slots that haven't been successfully filled. The element looks like this when inserted into the page: ``` <person-details> <p slot="person-name">Dr. Shazaam</p> <span slot="person-age">Immortal</span> <span slot="person-occupation">Superhero</span> </person-details> ``` Specifications -------------- | Specification | | --- | | [CSS Scoping Module Level 1 # slotted-pseudo](https://w3c.github.io/csswg-drafts/css-scoping/#slotted-pseudo) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `::slotted` | 50 | 79 | 63 | No | 37 | 10 | 50 | 50 | 63 | 37 | 10 | 5.0 | See also -------- * [Web components](https://developer.mozilla.org/en-US/docs/Web/Web_Components) css :-moz-last-node :-moz-last-node =============== **Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future. The `:-moz-last-node` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-class](pseudo-classes) is a [Mozilla extension](https://developer.mozilla.org/en-US/docs/Web/CSS/Mozilla_Extensions) that represents any element that is the last child node of some other element. It differs from [`:last-child`](:last-child) because it does not match a last-child element with (non-whitespace) text after it. **Note:** Any whitespace at the end of an element is ignored for the determination of `:-moz-last-node`. Syntax ------ ``` :-moz-last-node ``` Examples -------- ### CSS ``` span:-moz-last-node { background-color: lime; } ``` ### HTML ``` <p> <span>This does not match.</span> <span>This matches!</span> </p> <p> <span>This doesn't match because it's followed by text.</span> Blahblah. </p> ``` ### Result Specifications -------------- Not part of any standard. See also -------- * [`:-moz-first-node`](:-moz-first-node) * [`:last-child`](:last-child)
programming_docs
css border-collapse border-collapse =============== The `border-collapse` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets whether cells inside a [`<table>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table) have shared or separate borders. Try it ------ When cells are collapsed, the [`border-style`](border-style) value of `inset` behaves like `groove`, and `outset` behaves like `ridge`. When cells are separated, the distance between cells is defined by the [`border-spacing`](border-spacing) property. Syntax ------ ``` /\* Keyword values \*/ border-collapse: collapse; border-collapse: separate; /\* Global values \*/ border-collapse: inherit; border-collapse: initial; border-collapse: revert; border-collapse: revert-layer; border-collapse: unset; ``` The `border-collapse` property is specified as a single keyword, which may be chosen from the list below. ### Values `collapse` Adjacent cells have shared borders (the collapsed-border table rendering model). `separate` Adjacent cells have distinct borders (the separated-border table rendering model). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `separate` | | Applies to | `table` and `inline-table` elements | | [Inherited](inheritance) | yes | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` border-collapse = separate [|](value_definition_syntax#single_bar) collapse ``` Examples -------- ### A colorful table of browser engines #### HTML ``` <table class="separate"> <caption> <code>border-collapse: separate</code> </caption> <tbody> <tr> <th>Browser</th> <th>Layout Engine</th> </tr> <tr> <td class="fx">Firefox</td> <td class="gk">Gecko</td> </tr> <tr> <td class="ed">Edge</td> <td class="tr">EdgeHTML</td> </tr> <tr> <td class="sa">Safari</td> <td class="wk">Webkit</td> </tr> <tr> <td class="ch">Chrome</td> <td class="bk">Blink</td> </tr> <tr> <td class="op">Opera</td> <td class="bk">Blink</td> </tr> </tbody> </table> <table class="collapse"> <caption> <code>border-collapse: collapse</code> </caption> <tbody> <tr> <th>Browser</th> <th>Layout Engine</th> </tr> <tr> <td class="fx">Firefox</td> <td class="gk">Gecko</td> </tr> <tr> <td class="ed">Edge</td> <td class="tr">EdgeHTML</td> </tr> <tr> <td class="sa">Safari</td> <td class="wk">Webkit</td> </tr> <tr> <td class="ch">Chrome</td> <td class="bk">Blink</td> </tr> <tr> <td class="op">Opera</td> <td class="bk">Blink</td> </tr> </tbody> </table> ``` #### CSS ``` .collapse { border-collapse: collapse; } .separate { border-collapse: separate; } table { display: inline-table; margin: 1em; border: dashed 5px; } table th, table td { border: solid 3px; } .fx { border-color: orange blue; } .gk { border-color: black red; } .ed { border-color: blue gold; } .tr { border-color: aqua; } .sa { border-color: silver blue; } .wk { border-color: gold blue; } .ch { border-color: red yellow green blue; } .bk { border-color: navy blue teal aqua; } .op { border-color: red; } ``` #### Result Specifications -------------- | Specification | | --- | | [Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification # propdef-border-collapse](https://w3c.github.io/csswg-drafts/css2/#propdef-border-collapse) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-collapse` | 1 | 12 | 1 | 5 | 4 | 1.2 | 2.2 | 18 | 4 | 10.1 | 3 | 1.0 | See also -------- * [`border-spacing`](border-spacing), [`border-style`](border-style) * The `border-collapse` property alters the appearance of the [`<table>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table) HTML element. css Column combinator Column combinator ================= **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The **column combinator** (`||`) is placed between two CSS selectors. It matches only those elements matched by the second selector that belong to the column elements matched by the first. ``` /\* Table cells that belong to the "selected" column \*/ col.selected||td { background: gray; } ``` Syntax ------ ``` column-selector||cell-selector { /\* style properties \*/ } ``` Examples -------- ### HTML ``` <table border="1"> <colgroup> <col span="2" /> <col class="selected" /> </colgroup> <tbody> <tr> <td>A</td> <td>B</td> <td>C</td> </tr> <tr> <td colspan="2">D</td> <td>E</td> </tr> <tr> <td>F</td> <td colspan="2">G</td> </tr> </tbody> </table> ``` ### CSS ``` col.selected||td { background: gray; color: white; font-weight: bold; } ``` ### Result Specifications -------------- | Specification | | --- | | [Selectors Level 4 # the-column-combinator](https://w3c.github.io/csswg-drafts/selectors/#the-column-combinator) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `Column_combinator` | No | No | No See [bug 1605558](https://bugzil.la/1605558). | No | No | No | No | No | No See [bug 1605558](https://bugzil.la/1605558). | No | No | No | See also -------- * [`<col>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/col) * [`<colgroup>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/colgroup) * [`grid`](grid) * [`:nth-col`](:nth-col) * [`:nth-last-col`](:nth-last-col) css <basic-shape> <basic-shape> ============= The `<basic-shape>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) represents a shape used in the [`clip-path`](clip-path), [`shape-outside`](shape-outside), and [`offset-path`](offset-path) properties. Try it ------ Syntax ------ The `<basic-shape>` data type is defined with one of the basic shape functions listed below. When creating a shape, the reference box is defined by each property that uses `<basic-shape>` values. The coordinate system for the shape has its origin at the top-left corner of the reference box, with the x-axis running to the right and the y-axis running downwards. All the lengths expressed in percentages are resolved from the used dimensions of the reference box. The default reference box is the `margin-box`, as demonstrated in the below image which shows a circle created using `shape-outside: circle(50%)`. The shape is being defined with reference to the margin box. ### Shape functions The following shapes are supported. All `<basic-shape>` values use functional notation and are defined here using the [value definition syntax](value_definition_syntax). `[`inset()`](basic-shape/inset)` Defines an inset rectangle. ``` inset( <shape-arg>{1,4} [round <border-radius>]? ) ``` When all of the first four arguments are supplied they represent the top, right, bottom and left offsets from the reference box inward that define the positions of the edges of the inset rectangle. These arguments follow the syntax of the margin shorthand, that let you set all four insets with one, two or four values. The optional [`<border-radius>`](border-radius) argument(s) define rounded corners for the inset rectangle using the border-radius shorthand syntax. A pair of insets in either dimension that add up to more than the used dimension (such as left and right insets of 75% apiece) define a shape enclosing no area. For this specification, this results in an empty float area. `[`circle()`](basic-shape/circle)` Defines a circle using a radius and a position. ``` circle( [<shape-radius>]? [at <position>]? ) ``` The `<shape-radius>` argument represents *r*, the radius of the circle. Negative values are invalid. A percentage value here is resolved from the used width and height of the reference box as `sqrt(width^2+height^2)/sqrt(2)`. The [`<position>`](position_value) argument defines the center of the circle. This defaults to center if omitted. `[`ellipse()`](basic-shape/ellipse)` Defines an ellipse using two radii and a position. ``` ellipse( [<shape-radius>{2}]? [at <position>]? ) ``` The `<shape-radius>` arguments represent rx and ry, the x-axis and y-axis radii of the ellipse, in that order. Negative values for either radius are invalid. Percentage values here are resolved against the used width (for the rx value) and the used height (for the ry value) of the reference box. The position argument defines the center of the ellipse. This defaults to center if omitted. `[`polygon()`](basic-shape/polygon)` Defines a polygon using an SVG `[fill-rule](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule)` and a set of vertices. ``` polygon( [<fill-rule>,]? [<shape-arg> <shape-arg>]# ) ``` `<fill-rule>` represents the `[fill-rule](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule)` used to determine the interior of the polygon. Possible values are `nonzero` and `evenodd`. Default value when omitted is `nonzero`. Each pair argument in the list represents *xi* and *yi* - the x and y axis coordinates of the vertex of the polygon at position i. `[`path()`](path)` Defines a shape using an SVG `[fill-rule](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule)` and an SVG [path definition](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d). ``` path( [<fill-rule>,]? <string>) ``` The optional `<fill-rule>` represents the `[fill-rule](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule)` used to determine the interior of the path. Possible values are `nonzero` and `evenodd`. Default value when omitted is `nonzero`. The required <string> is an [SVG Path](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d) string encompassed in quotes The arguments not defined above are defined as follows: ``` <shape-arg> = <length> | <percentage> <shape-radius> = <length> | <percentage> | closest-side | farthest-side ``` Defines a radius for a circle or ellipse. If omitted it defaults to `closest-side`. `closest-side` uses the length from the center of the shape to the closest side of the reference box. For circles, this is the closest side in any dimension. For ellipses, this is the closest side in the radius dimension. `farthest-side` uses the length from the center of the shape to the farthest side of the reference box. For circles, this is the farthest side in any dimension. For ellipses, this is the farthest side in the radius dimension. Description ----------- ### Computed values of basic shapes The values in a `<basic-shape>` function are computed as specified, with these exceptions: * Omitted values are included and compute to their defaults. * A [`<position>`](position_value) value in `circle()` or `ellipse()` is computed as a pair of offsets (horizontal then vertical) from the top left origin, each given as a combination of an absolute length and a percentage. * A [`<border-radius>`](border-radius) value in `inset()` is computed as an expanded list of all eight [`<length>`](length) or percentage values. ### Interpolation of basic shapes When animating between one `<basic-shape>` and another, the rules below are applied. The values in the shape functions [interpolate](https://developer.mozilla.org/en-US/docs/Glossary/Interpolation) as a simple list. The list values interpolate as [`<length>`](length), [`<percentage>`](percentage), or [`calc()`](calc) where possible. If list values are not one of those types but are identical, those values do interpolate. * Both shapes must use the same reference box. * If both shapes are the same type, that type is `ellipse()` or `circle()`, and none of the radii use the `closest-side` or `farthest-side` keywords, interpolate between each value in the shape functions. * If both shapes are of type `inset()`, interpolate between each value in the shape functions. * If both shapes are of type `polygon()`, both polygons have the same number of vertices, and use the same `<fill-rule>`, interpolate between each value in the shape functions. * If both shapes are of type `path()`, both paths strings have the same number and types of path data commands in the same order, interpolate each path data command as real numbers. * In all other cases no interpolation occurs. Examples -------- ### Animated polygon In this example, we use the <@keyframes> at-rule to animate a clip path between two polygons. Note that both polygons have the same number of vertices, which is necessary for this type of animation to work. #### HTML ``` <div></div> ``` #### CSS ``` div { width: 300px; height: 300px; background: repeating-linear-gradient(red, orange 50px); clip-path: polygon( 50% 0%, 60% 40%, 100% 50%, 60% 60%, 50% 100%, 40% 60%, 0% 50%, 40% 40% ); animation: 4s poly infinite alternate ease-in-out; margin: 10px auto; } @keyframes poly { from { clip-path: polygon( 50% 0%, 60% 40%, 100% 50%, 60% 60%, 50% 100%, 40% 60%, 0% 50%, 40% 40% ); } to { clip-path: polygon( 50% 30%, 100% 0%, 70% 50%, 100% 100%, 50% 70%, 0% 100%, 30% 50%, 0% 0% ); } } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Shapes Module Level 1 # basic-shape-functions](https://w3c.github.io/csswg-drafts/css-shapes/#basic-shape-functions) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `basic-shape` | 37 | 79 | 54 | No | 24 | 10.1 | 37 | 37 | 54 | 24 | 10.3 | 3.0 | | `animation` | 37 | 79 | 54 | No | 24 | 10.1 | 37 | 37 | 54 | 24 | 10.3 | 3.0 | | `circle` | 37 | 79 | 54 | No | 24 | 10.1 | 37 | 37 | 54 | 24 | 10.3 | 3.0 | | `ellipse` | 37 | 79 | 54 | No | 24 | 10.1 | 37 | 37 | 54 | 24 | 10.3 | 3.0 | | `inset` | 37 | 79 | 54 | No | 24 | 10.1 | 37 | 37 | 54 | 24 | 10.3 | 3.0 | | `path` | 46 Only supported on the `offset-path` property. | 79 Only supported on the `offset-path` property. | 97 Only supported on the `d` SVG presentation attribute and the `clip-path` and `offset-path` CSS properties. Not supported on the `shape-outside` CSS property. 71 Only supported on the `clip-path` and `offset-path` properties. 63 Only supported on the `offset-path` property. | No | 33 Only supported on the `offset-path` property. | No | 46 Only supported on the `offset-path` property. | 46 Only supported on the `offset-path` property. | 97 Only supported on the `d` SVG presentation attribute and the `clip-path` and `offset-path` CSS properties. Not supported on the `shape-outside` CSS property. 79 Only supported on the `clip-path` and `offset-path` properties. 63 Only supported on the `offset-path` property. | 33 Only supported on the `offset-path` property. | No | 5.0 Only supported on the `offset-path` property. | | `polygon` | 37 | 79 | 54 | No | 24 | 10.1 | 37 | 37 | 54 | 24 | 10.3 | 3.0 | See also -------- * Properties that use this data type: [`clip-path`](clip-path), [`shape-outside`](shape-outside) * [Edit Shape Paths in CSS — Firefox Developer Tools](https://firefox-source-docs.mozilla.org/devtools-user/page_inspector/how_to/edit_css_shapes/index.html) * [Overview of CSS Shapes](css_shapes/overview_of_css_shapes) css transform-origin transform-origin ================ The `transform-origin` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets the origin for an element's transformations. Try it ------ The transform origin is the point around which a transformation is applied. For example, the transform origin of the [`rotate()`](transform-function/rotate) function is the center of rotation. In effect, this property wraps a pair of translations around the element's other transformations. The first translation moves the transform origin to the true origin at ( 0 , 0 ) . Then the other transformations are applied, and because the transform origin is at ( 0 , 0 ) , those transformations act about the transform origin. Finally, the opposite translation is applied, moving the transform origin back to its original location. Consequently, this definition ``` transform-origin: -100% 50%; transform: rotate(45deg); ``` results in the same transformation as ``` transform-origin: 0 0; transform: translate(-100%, 50%) rotate(45deg) translate(100%, -50%); ``` Reading from right to left, `translate(100%, -50%)` is the translation to bring the transform origin to the true origin, `rotate(45deg)` is the original transformation, and `translate(-100%, 50%)` is the translation to restore the transform origin to its original location. By default, the origin of a transform is `center`. Syntax ------ ``` /\* One-value syntax \*/ transform-origin: 2px; transform-origin: bottom; /\* x-offset | y-offset \*/ transform-origin: 3cm 2px; /\* x-offset-keyword | y-offset \*/ transform-origin: left 2px; /\* x-offset-keyword | y-offset-keyword \*/ transform-origin: right top; /\* y-offset-keyword | x-offset-keyword \*/ transform-origin: top right; /\* x-offset | y-offset | z-offset \*/ transform-origin: 2px 30% 10px; /\* x-offset-keyword | y-offset | z-offset \*/ transform-origin: left 5px -3px; /\* x-offset-keyword | y-offset-keyword | z-offset \*/ transform-origin: right bottom 2cm; /\* y-offset-keyword | x-offset-keyword | z-offset \*/ transform-origin: bottom right 2cm; /\* Global values \*/ transform-origin: inherit; transform-origin: initial; transform-origin: revert; transform-origin: revert-layer; transform-origin: unset; ``` The `transform-origin` property may be specified using one, two, or three values, where each value represents an offset. Offsets that are not explicitly defined are reset to their corresponding [initial values](initial_value). If a single [`<length>`](length) or [`<percentage>`](percentage) value is defined, it represents the horizontal offset. If two or more values are defined and either no value is a keyword, or the only used keyword is `center`, then the first value represents the horizontal offset and the second represents the vertical offset. * One-value syntax: + The value must be a [`<length>`](length), a [`<percentage>`](percentage), or one of the keywords `left`, `center`, `right`, `top`, and `bottom`. * Two-value syntax: + One value must be a [`<length>`](length), a [`<percentage>`](percentage), or one of the keywords `left`, `center`, and `right`. + The other value must be a [`<length>`](length), a [`<percentage>`](percentage), or one of the keywords `top`, `center`, and `bottom`. * Three-value syntax: + The first two values are the same as for the two-value syntax. + The third value must be a [`<length>`](length). It always represents the Z offset. ### Values *x-offset* Is a [`<length>`](length) or a [`<percentage>`](percentage) describing how far from the left edge of the box the origin of the transform is set. *offset-keyword* Is one of the `left`, `right`, `top`, `bottom`, or `center` keyword describing the corresponding offset. *y-offset* Is a [`<length>`](length) or a [`<percentage>`](percentage) describing how far from the top edge of the box the origin of the transform is set. *x-offset-keyword* Is one of the `left`, `right`, or `center` keyword describing how far from the left edge of the box the origin of the transform is set. *y-offset-keyword* Is one of the `top`, `bottom`, or `center` keyword describing how far from the top edge of the box the origin of the transform is set. *z-offset* Is a [`<length>`](length) (and never a [`<percentage>`](percentage) which would make the statement invalid) describing how far from the user eye the z=0 origin is set. The keywords are convenience shorthands and match the following [`<percentage>`](percentage) values: | Keyword | Value | | --- | --- | | `left` | `0%` | | `center` | `50%` | | `right` | `100%` | | `top` | `0%` | | `bottom` | `100%` | Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `50% 50% 0` | | Applies to | transformable elements | | [Inherited](inheritance) | no | | Percentages | refer to the size of bounding box | | [Computed value](computed_value) | for [`<length>`](length) the absolute value, otherwise a percentage | | Animation type | simple list of length, percentage, or calc | **Note:** The initial value of `transform-origin` is `0 0` for all SVG elements except for root `<svg>` elements and `<svg>` elements that are a direct child of a [foreignObject](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/foreignObject), and whose `transform-origin` is `50% 50%`, like other CSS elements. See the [SVG transform-origin](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/transform-origin) attribute for more information. Formal syntax ------------- ``` transform-origin = [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) top [|](value_definition_syntax#single_bar) bottom [|](value_definition_syntax#single_bar) <length-percentage> []](value_definition_syntax#brackets) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) left [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) right [|](value_definition_syntax#single_bar) <length-percentage> []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) top [|](value_definition_syntax#single_bar) center [|](value_definition_syntax#single_bar) bottom [|](value_definition_syntax#single_bar) <length-percentage> []](value_definition_syntax#brackets) [<length>](length)[?](value_definition_syntax#question_mark) [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) center [|](value_definition_syntax#single_bar) left [|](value_definition_syntax#single_bar) right []](value_definition_syntax#brackets) [&&](value_definition_syntax#double_ampersand) [[](value_definition_syntax#brackets) center [|](value_definition_syntax#single_bar) top [|](value_definition_syntax#single_bar) bottom []](value_definition_syntax#brackets) []](value_definition_syntax#brackets) [<length>](length)[?](value_definition_syntax#question_mark) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### A demonstration of various transform values This example shows the effect of choosing different `transform-origin` values for a variety of transformation functions. Specifications -------------- | Specification | | --- | | [CSS Transforms Module Level 1 # transform-origin-property](https://w3c.github.io/csswg-drafts/css-transforms/#transform-origin-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `transform-origin` | 36 1 | 12 12 | 49 16 3.5 | 10 9 | 23 15 12.1-15 10.5-15 | 9 2 | ≤37 4.4 | 36 18 | 49 16 4 | 24 15 12.1-15 11-14 | 9 1 | 3.0 1.0 | | `support_in_svg` | 19 | 17 | 43 Keywords and percentages refer to the canvas instead of the object itself. See [bug 1209061](https://bugzil.la/1209061). | No | 15 | 6 Only supported for transformations applied using the CSS `transform` property (e.g. `.className { transform: rotate(45deg); transform-origin: center; }`). It has no effect on transformations applied using the `transform` SVG attribute (e.g. `<rect style="transform-origin: center;" transform="rotate(45)" />`). | 4.4 | 25 | 43 Keywords and percentages refer to the canvas instead of the object itself. See [bug 1209061](https://bugzil.la/1209061). | 14 | 6 Only supported for transformations applied using the CSS `transform` property (e.g. `.className { transform: rotate(45deg); transform-origin: center; }`). It has no effect on transformations applied using the `transform` SVG attribute (e.g. `<rect style="transform-origin: center;" transform="rotate(45)" />`). | 1.5 | | `three_value_syntax` | 12 | 12 | 10 | 9 | 15 | 5 | ≤37 | 18 | 10 | 14 | 3.2 | 1.0 | See also -------- * [Using CSS transforms](css_transforms/using_css_transforms) * <https://css-tricks.com/almanac/properties/t/transform-origin/>
programming_docs
css ::cue-region ::cue-region ============ **Experimental:** **This is an [experimental technology](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Experimental_deprecated_obsolete#experimental)** Check the [Browser compatibility table](#browser_compatibility) carefully before using this in production. The `::cue-region` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [pseudo-element](pseudo-elements) matches [WebVTT](https://developer.mozilla.org/en-US/docs/Web/API/WebVTT_API) cues within a selected element. This can be used to [style captions and other cues](https://developer.mozilla.org/en-US/docs/Web/API/WebVTT_API#styling_webvtt_cues) in media with VTT tracks. ``` ::cue-region { color: yellow; font-weight: bold; } ``` The properties are applied to the entire set of cues as if they were a single unit. The only exception is that `background` and its longhand properties apply to each cue individually, to avoid creating boxes and obscuring unexpectedly large areas of the media. Syntax ------ ``` ::cue-region | ::cue-region( <selector> ) ``` Permitted properties -------------------- Rules whose selectors include this element may only use the following CSS properties: * [`background`](background) * [`background-attachment`](background-attachment) * [`background-clip`](background-clip) * [`background-color`](background-color) * [`background-image`](background-image) * [`background-origin`](background-origin) * [`background-position`](background-position) * [`background-repeat`](background-repeat) * [`background-size`](background-size) * [`color`](color) * [`font`](font) * [`font-family`](font-family) * [`font-size`](font-size) * [`font-stretch`](font-stretch) * [`font-style`](font-style) * [`font-variant`](font-variant) * [`font-weight`](font-weight) * [`line-height`](line-height) * [`opacity`](opacity) * [`outline`](outline) * [`outline-color`](outline-color) * [`outline-style`](outline-style) * [`outline-width`](outline-width) * [`ruby-position`](ruby-position) * [`text-combine-upright`](text-combine-upright) * [`text-decoration`](text-decoration) * [`text-decoration-color`](text-decoration-color) * [`text-decoration-line`](text-decoration-line) * [`text-decoration-style`](text-decoration-style) * [`text-decoration-thickness`](text-decoration-thickness) * [`text-shadow`](text-shadow) * [`visibility`](visibility) * [`white-space`](white-space) Specifications -------------- **No specification found**No specification data found for `css.selectors.cue-region`. [Check for problems with this page](#on-github) or contribute a missing `spec_url` to [mdn/browser-compat-data](https://github.com/mdn/browser-compat-data). Also make sure the specification is included in [w3c/browser-specs](https://github.com/w3c/browser-specs). Browser compatibility --------------------- No compatibility data found for `css.selectors.cue-region`. [Check for problems with this page](#on-github) or contribute missing data to [mdn/browser-compat-data](https://github.com/mdn/browser-compat-data). See also -------- * Other [WebVTT](https://developer.mozilla.org/en-US/docs/Web/API/WebVTT_API) selectors: + [`::cue`](::cue) + [`:past`](:past) + [`:future`](:future) css min-content min-content =========== The `min-content` sizing keyword represents the intrinsic minimum width of the content. For text content this means that the content will take all soft-wrapping opportunities, becoming as small as the longest word. Syntax ------ ``` /\* Used as a length \*/ width: min-content; inline-size: min-content; height: min-content; block-size: min-content; /\* used in grid tracks \*/ grid-template-columns: 200px 1fr min-content; /\* Global values \*/ min-content: inherit; min-content: initial; min-content: revert; min-content: revert-layer; min-content: unset; ``` Examples -------- ### Using min-content for box sizing #### HTML ``` <div class="item">Item</div> <div class="item">Item with more text in it.</div> ``` #### CSS ``` .item { width: min-content; background-color: #8ca0ff; padding: 5px; margin-bottom: 1em; } ``` #### Result ### Sizing grid columns with min-content #### HTML ``` <div id="container"> <div>Item</div> <div>Item with more text in it.</div> <div>Flexible item</div> </div> ``` #### CSS ``` #container { display: grid; grid-template-columns: min-content min-content 1fr; grid-gap: 5px; box-sizing: border-box; height: 200px; width: 100%; background-color: #8cffa0; padding: 10px; } #container > div { background-color: #8ca0ff; padding: 5px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Box Sizing Module Level 3 # valdef-width-min-content](https://w3c.github.io/csswg-drafts/css-sizing-3/#valdef-width-min-content) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `min-content` | 46 1-48 | 79 | 66 3 | No | 33 15-35 | 11 2 | 46 4.4-48 | 46 18-48 | 66 4 | 33 14-35 | 11 1 | 5.0 1.0-5.0 | css transition-delay transition-delay ================ The `transition-delay` CSS property specifies the duration to wait before starting a property's [transition effect](css_transitions/using_css_transitions) when its value changes. Try it ------ 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 [`transition-property`](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 ------ ``` /\* <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 [`<time>`](time) Denotes the amount of time to wait between a property's value changing and the start of the transition effect. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0s` | | Applies to | all elements, [`::before`](::before) and [`::after`](::after) <pseudo-elements> | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` transition-delay = [<time>](time)[#](value_definition_syntax#hash_mark) ``` Examples -------- ### Example showing different delays #### 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 ``` .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 ``` 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 Specifications -------------- | Specification | | --- | | [CSS Transitions # transition-delay-property](https://w3c.github.io/csswg-drafts/css-transitions/#transition-delay-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `transition-delay` | 26 1 | 12 12 | 49 16 4 | 10 10 | 15 12.1 11.6-15 | 9 4 | 4.4 2 | 26 18 | 49 16 4 | 14 12.1 12-14 | 9 2 | 1.5 1.0 | See also -------- * [Using CSS transitions](css_transitions/using_css_transitions) * [`TransitionEvent`](https://developer.mozilla.org/en-US/docs/Web/API/TransitionEvent) API css contain-intrinsic-inline-size contain-intrinsic-inline-size ============================= The `contain-intrinsic-inline-size` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [logical property](css_logical_properties) defines the inline-size of an element that a browser can use for layout when the element is subject to [size containment](css_containment#size_containment). Inline-size is the size of the element in the dimension parallel to the flow of text within a line. In a horizontal [writing mode](writing-mode) like standard English, inline size is the horizontal dimension (width); for a vertical writing mode, inline size is the vertical dimension. Syntax ------ ``` /\* Keyword values \*/ contain-intrinsic-inline-size: none; /\* <length> values \*/ contain-intrinsic-inline-size: 1000px; contain-intrinsic-inline-size: 10rem; /\* auto <length> \*/ contain-intrinsic-inline-size: auto 300px; /\* Global values \*/ contain-intrinsic-inline-size: inherit; contain-intrinsic-inline-size: initial; contain-intrinsic-inline-size: revert; contain-intrinsic-inline-size: revert-layer; contain-intrinsic-inline-size: unset; ``` ### Values The following values can be specified for the intrinsic inline size of an element: `none` The element has no intrinsic inline-size. `<length>` The element has the specified inline-size ([`<length>`](length)). `auto <length>` When the element is in size containment and skipping its contents (for example, when it is offscreen and `content-visibility: auto` is set) the inline size is remembered from the actual size of the element when it was last able to render its child elements. If the element has never rendered its child elements and hence has no remembered value for the normally rendered element size, or if it is not skipping its contents, the inline size is the specified `<length>`. Description ----------- The property is commonly applied alongside elements that can trigger size containment, such as [`contain: size`](contain) and [`content-visibility`](content-visibility). 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-inline-size` property allows authors to specify an appropriate value to be used as the inline-size for layout. The `auto <length>` value allows the inline-size of the element to be stored if the element is ever "normally rendered" (with its child elements), and then used instead of the specified value when the element is skipping its contents. This allows offscreen elements with [`content-visibility: auto`](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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | elements for which size containment can apply | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified, with <length>s values computed | | Animation type | by computed value type | Formal syntax ------------- ``` contain-intrinsic-inline-size = none [|](value_definition_syntax#single_bar) [<length>](length) [|](value_definition_syntax#single_bar) auto [<length>](length) ``` Examples -------- ### Setting the intrinsic inline size The HTML below defines an element "contained\_element" that will be subject to size constraint, and which contains a child element. ``` <div id="contained\_element"> <div class="child\_element"></div> </div> ``` The CSS below sets the [`content-visibility`](content-visibility) of `contained_element` to `auto`, so if the element is hidden it will be size constrained. The intrinsic block size and inline size that are used when it is size constrained are set at the same time using `contain-intrinsic-block-size` and `contain-intrinsic-inline-size`, respectively. ``` #contained\_element { border: 2px solid green; inline-size: 151px; content-visibility: auto; contain-intrinsic-inline-size: 152px; contain-intrinsic-block-size: 52px; } .child\_element { border: 1px solid red; background: blue; block-size: 50px; inline-size: 150px; } ``` Specifications -------------- | Specification | | --- | | [CSS Box Sizing Module Level 4 # propdef-contain-intrinsic-inline-size](https://w3c.github.io/csswg-drafts/css-sizing-4/#propdef-contain-intrinsic-inline-size) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `contain-intrinsic-inline-size` | 95 | 95 | 107 | No | 81 | No | 95 | 95 | 107 | 67 | No | 17.0 | See also -------- * [content-visibility: the new CSS property that boosts your rendering performance](https://web.dev/content-visibility/) (web.dev) * [`contain-intrinsic-block-size`](contain-intrinsic-block-size) * [`contain-intrinsic-size`](contain-intrinsic-size) * [`contain-intrinsic-width`](contain-intrinsic-width) * [`contain-intrinsic-height`](contain-intrinsic-height) css text-indent text-indent =========== The `text-indent` CSS property sets the length of empty space (indentation) that is put before lines of text in a block. Try it ------ Horizontal spacing is with respect to the left (or right, for right-to-left layout) edge of the containing block-level element's content box. Syntax ------ ``` /\* <length> values \*/ text-indent: 3mm; text-indent: 40px; /\* <percentage> value relative to the containing block width \*/ text-indent: 15%; /\* Keyword values \*/ text-indent: 5em each-line; text-indent: 5em hanging; text-indent: 5em hanging each-line; /\* Global values \*/ text-indent: inherit; text-indent: initial; text-indent: revert; text-indent: revert-layer; text-indent: unset; ``` ### Values [`<length>`](length) Indentation is specified as an absolute [`<length>`](length). Negative values are allowed. See [`<length>`](length) values for possible units. [`<percentage>`](percentage) Indentation is a [`<percentage>`](percentage) of the containing block's width. `each-line` Indentation affects the first line of the block container as well as each line after a *forced line break*, but does not affect lines after a *soft wrap break*. `hanging` Inverts which lines are indented. All lines *except* the first line will be indented. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `0` | | Applies to | block containers | | [Inherited](inheritance) | yes | | Percentages | refer to the width of the containing block | | [Computed value](computed_value) | the percentage as specified or the absolute length, plus any keywords as specified | | Animation type | a [length](length#interpolation), [percentage](percentage#interpolation) or calc(); | Formal syntax ------------- ``` text-indent = [[](value_definition_syntax#brackets) <length-percentage> []](value_definition_syntax#brackets) [&&](value_definition_syntax#double_ampersand) hanging[?](value_definition_syntax#question_mark) [&&](value_definition_syntax#double_ampersand) each-line[?](value_definition_syntax#question_mark) <length-percentage> = [<length>](length) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Examples -------- ### Simple indent #### HTML ``` <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. </p> <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. </p> ``` #### CSS ``` p { text-indent: 5em; background: powderblue; } ``` #### Result ### Skipping indentation on the first paragraph A common typographic practice when paragraph indentation is present is to skip the indentation for the first paragraph. As the *The Chicago Manual of Style* puts it, "the first line of text following a subhead may begin flush left or be indented by the usual paragraph indention." Treating first paragraphs differently from subsequent paragraphs can be done using the [adjacent sibling combinator](adjacent_sibling_combinator), as in the following example: #### HTML ``` <h2>Lorem ipsum</h2> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse eu venenatis quam. Vivamus euismod eleifend metus vitae pharetra. In vel tempor metus. Donec dapibus feugiat euismod. Vivamus interdum tellus dolor. Vivamus blandit eros et imperdiet auctor. Mauris sapien nunc, condimentum a efficitur non, elementum ac sapien. Cras consequat turpis non augue ullamcorper, sit amet porttitor dui interdum. </p> <p> Sed laoreet luctus erat at rutrum. Proin velit metus, luctus in sapien in, tincidunt mattis ex. Praesent venenatis orci at sagittis eleifend. Nulla facilisi. In feugiat vehicula magna iaculis vehicula. Nulla suscipit tempor odio a semper. Donec vitae dapibus ipsum. Donec libero purus, convallis eu efficitur id, pulvinar elementum diam. Maecenas mollis blandit placerat. Ut gravida pellentesque nunc, in eleifend ante convallis sit amet. </p> <h2>Donec ullamcorper elit nisl</h2> <p> Donec ullamcorper elit nisl, sagittis bibendum massa gravida in. Fusce tempor in ante gravida iaculis. Integer posuere tempor metus. Vestibulum lacinia, nunc et dictum viverra, urna massa aliquam tellus, id mollis sem velit vestibulum nulla. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec vulputate leo ut iaculis ultrices. Cras egestas rhoncus lorem. Nunc blandit tempus lectus, rutrum hendrerit orci eleifend id. Ut at quam velit. </p> <p> Aenean rutrum tempor ligula, at luctus ligula auctor vestibulum. Sed sollicitudin velit in leo fringilla sollicitudin. Proin eu gravida arcu. Nam iaculis malesuada massa, eget aliquet turpis sagittis sed. Sed mollis tellus ac dui ullamcorper, nec lobortis diam pellentesque. Quisque dapibus accumsan libero, sed euismod ipsum ullamcorper sed. </p> ``` #### CSS ``` p { text-align: justify; margin: 1em 0 0 0; } p + p { text-indent: 2em; margin: 0; } ``` #### Result ### Percentage indent #### HTML ``` <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. </p> <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. </p> ``` #### CSS ``` p { text-indent: 30%; background: plum; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Text Module Level 3 # text-indent-property](https://w3c.github.io/csswg-drafts/css-text/#text-indent-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `text-indent` | 1 | 12 | 1 | 3 | 3.5 | 1 | ≤37 | 18 | 4 | 14 | 1 | 1.0 | | `each-line` | No | No | No | No | No | No | No | No | No | No | No | No | | `hanging` | No | No | No | No | No | No | No | No | No | No | No | No | See also -------- * [Learn to style HTML using CSS](https://developer.mozilla.org/en-US/docs/Learn/CSS) * Related CSS properties: + [`text-justify`](text-justify) + [`text-orientation`](text-orientation) + [`text-overflow`](text-overflow) + [`text-rendering`](text-rendering) + [`text-transform`](text-transform) + [`hanging-punctuation`](hanging-punctuation) * [CSS Text Decoration](css_text_decoration) CSS module * [CSS Text module](css_text)
programming_docs
css border-block-width border-block-width ================== The `border-block-width` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the width of the logical block borders of an element, which maps to a physical border width depending on the element's writing mode, directionality, and text orientation. It corresponds to the [`border-top-width`](border-top-width) and [`border-bottom-width`](border-bottom-width), or [`border-left-width`](border-left-width), and [`border-right-width`](border-right-width) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ The border width in the other dimension can be set with [`border-inline-width`](border-inline-width), which sets [`border-inline-start-width`](border-inline-start-width), and [`border-inline-end-width`](border-inline-end-width). Syntax ------ ``` /\* <'border-width'> values \*/ border-block-width: 5px; border-block-width: thick; /\* Global values \*/ border-block-width: inherit; border-block-width: initial; border-block-width: revert; border-block-width: revert-layer; border-block-width: unset; ``` ### Values `<'border-width'>` The width of the border. See [`border-width`](border-width). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `medium` | | Applies to | all elements | | [Inherited](inheritance) | no | | Percentages | logical-width of containing block | | [Computed value](computed_value) | absolute length; `0` if the border style is `none` or `hidden` | | Animation type | discrete | Formal syntax ------------- ``` border-block-width = <'border-top-width'>[{1,2}](value_definition_syntax#curly_braces) ``` Examples -------- ### Border width with vertical text #### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; border: 1px solid blue; border-block-width: 5px; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # propdef-border-block-width](https://w3c.github.io/csswg-drafts/css-logical/#propdef-border-block-width) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-block-width` | 87 | 87 | 66 | No | 73 | 14.1 | 87 | 87 | 66 | 62 | 14.5 | 14.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * This property maps to one of the physical border properties: [`border-top-width`](border-top-width), [`border-right-width`](border-right-width), [`border-bottom-width`](border-bottom-width), and [`border-left-width`](border-left-width) * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css scroll-margin-block scroll-margin-block =================== The `scroll-margin-block` [shorthand property](shorthand_properties) sets the scroll margins of an element in the block dimension. Try it ------ Constituent properties ---------------------- This property is a shorthand for the following CSS properties: * [`scroll-margin-block-end`](scroll-margin-block-end) * [`scroll-margin-block-start`](scroll-margin-block-start) Syntax ------ ``` /\* <length> values \*/ scroll-margin-block: 10px; scroll-margin-block: 1em 0.5em; /\* Global values \*/ scroll-margin-block: inherit; scroll-margin-block: initial; scroll-margin-block: revert; scroll-margin-block: revert-layer; scroll-margin-block: unset; ``` ### Values `<length>` An outset from the corresponding edge of the scroll container. Description ----------- 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 ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`scroll-margin-block-start`](scroll-margin-block-start): `0` * [`scroll-margin-block-end`](scroll-margin-block-end): `0` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`scroll-margin-block-start`](scroll-margin-block-start): as specified * [`scroll-margin-block-end`](scroll-margin-block-end): as specified | | Animation type | by computed value type | Formal syntax ------------- ``` scroll-margin-block = [<length>](length)[{1,2}](value_definition_syntax#curly_braces) ``` Specifications -------------- | Specification | | --- | | [CSS Scroll Snap Module Level 1 # propdef-scroll-margin-block](https://w3c.github.io/csswg-drafts/css-scroll-snap/#propdef-scroll-margin-block) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `scroll-margin-block` | 69 | 79 | 68 | No | 56 | 14.1 | 69 | 69 | 68 | 48 | 14.5 | 10.0 | See also -------- * [CSS Scroll Snap](css_scroll_snap) * [Well-Controlled Scrolling with CSS Scroll Snap](https://web.dev/css-scroll-snap/) css :-moz-submit-invalid :-moz-submit-invalid ==================== **Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future. The `:-moz-submit-invalid` CSS [pseudo-class](pseudo-classes) is a [Mozilla extension](https://developer.mozilla.org/en-US/docs/Web/CSS/Mozilla_Extensions) that represents any submit [`<button>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button) on forms whose contents aren't valid based on their [validation constraints](https://developer.mozilla.org/en-US/docs/Learn/Forms#constraint_validation). By default, no style is applied. You can use this pseudo-class to customize the appearance of the submit button when there are invalid form fields. Syntax ------ ``` :-moz-submit-invalid ``` Specifications -------------- Not part of any standard. Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `:-moz-submit-invalid` | No | No | 88 From Firefox 88 the feature has been placed behind a flag. See [bug 1694129](https://bugzil.la/1694129). 4-88 | No | No | No | No | No | 4-88 From version 88, the feature has been withdrawn. See [bug 1694129](https://bugzil.la/1694129). | No | No | No | See also -------- * [`:valid`](:valid) * [`:invalid`](:invalid) * [`:required`](:required) * [`:optional`](:optional) css content content ======= The `content` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property replaces an element with a generated value. Objects inserted using the `content` property are **anonymous [replaced elements](replaced_element)**. Try it ------ Syntax ------ ``` /\* Keywords that cannot be combined with other values \*/ content: normal; content: none; /\* <image> values \*/ content: url("http://www.example.com/test.png"); content: linear-gradient(#e66465, #9198e5); content: image-set("image1x.png" 1x, "image2x.png" 2x); /\* alt text for generated content, added in the Level 3 specification \*/ content: url("http://www.example.com/test.png") / "This is the alt text"; /\* <string> value \*/ content: "prefix"; /\* list of content values \*/ content: "prefix" url("http://www.example.com/test.png"); content: "prefix" url("http://www.example.com/test.png") "suffix" / "This is some alt 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(value string); /\* Language- and position-dependent keywords \*/ content: open-quote; content: close-quote; content: no-open-quote; content: no-close-quote; /\* Except for normal and none, several values can be used simultaneously \*/ content: open-quote counter(chapter_counter); /\* Global values \*/ content: inherit; content: initial; content: revert; content: revert-layer; content: unset; ``` ### Values `none` When applied to a pseudo-element, the pseudo-element is not generated. If applied to an element, the value has no effect. `normal` Computes to `none` for the `::before` and `::after` pseudo-elements. [`<string>`](string) Specifies the "alt text" for the element. This value can be any number of text characters. Non-Latin characters must be encoded using their Unicode escape sequences: for example, `\000A9` represents the copyright symbol. `<content-list>` A list of anonymous inline boxes that will replace the content of the selected element (in the specified order). This list can include strings, images, counters, and so on. [`<image>`](image) An [`<image>`](image), denoted by the [`url()`](url) or [`<gradient>`](gradient) data type, or part of the webpage, defined by the [`element()`](element()) function, denoting the content to display. [`counter()`](counter) The value of a [CSS counter](css_counter_styles/using_css_counters), generally a number produced by computations defined by [`<counter-reset>`](counter-reset) and [`<counter-increment>`](counter-increment) properties. It can be displayed using either the [`counter()`](counter) or [`counters()`](counters) function. The [`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 [`<list-style-type>`](list-style-type) (`decimal` by default). The [`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 [`<list-style-type>`](list-style-type) (`decimal` by default). `attr(x)` The value of the element's attribute `x` as a string. If there is no attribute `x`, an empty string is returned. The case-sensitivity of attribute names depends on the document language. `open-quote` | `close-quote` These values are replaced by the appropriate string from the [`quotes`](quotes) property. `no-open-quote` | `no-close-quote` Introduces no content, but increments (decrements) the level of nesting for quotes. `<content-list> / "Alternative text"` Alternative text may be specified for an image (or list of content items) by appending a forward slash and then the text. 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, neither the content or alternative text will be used. Accessibility concerns ---------------------- CSS-generated content is not included in the [DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction). Because of this, it will not be represented in the [accessibility tree](https://developer.mozilla.org/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. * [Accessibility support for CSS generated content – Tink](https://tink.uk/accessibility-support-for-css-generated-content/) * [Explanation of WCAG, Guideline 1.3 – MDN](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.3_%e2%80%94_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) Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | All elements, tree-abiding pseudo-elements, and page margin boxes | | [Inherited](inheritance) | no | | [Computed value](computed_value) | On elements, always computes to `normal`. On [`::before`](::before) and [`::after`](::after), if `normal` is specified, computes to `none`. Otherwise, for URI values, the absolute URI; for `attr()` values, the resulting string; for other keywords, as specified. | | Animation type | discrete | Formal syntax ------------- ``` content = normal [|](value_definition_syntax#single_bar) none [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) <content-replacement> [|](value_definition_syntax#single_bar) <content-list> []](value_definition_syntax#brackets) [[](value_definition_syntax#brackets) / [[](value_definition_syntax#brackets) [<string>](string) [|](value_definition_syntax#single_bar) <counter> []](value_definition_syntax#brackets)[+](value_definition_syntax#plus) []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) [|](value_definition_syntax#single_bar) element( ) <content-replacement> = <image> <content-list> = [[](value_definition_syntax#brackets) [<string>](string) [|](value_definition_syntax#single_bar) contents [|](value_definition_syntax#single_bar) <image> [|](value_definition_syntax#single_bar) <counter> [|](value_definition_syntax#single_bar) <quote> [|](value_definition_syntax#single_bar) <target> [|](value_definition_syntax#single_bar) <leader()> []](value_definition_syntax#brackets)[+](value_definition_syntax#plus) <counter> = <counter()> [|](value_definition_syntax#single_bar) <counters()> <image> = <url> [|](value_definition_syntax#single_bar) [<gradient>](gradient) <quote> = open-quote [|](value_definition_syntax#single_bar) close-quote [|](value_definition_syntax#single_bar) no-open-quote [|](value_definition_syntax#single_bar) no-close-quote <target> = <target-counter()> [|](value_definition_syntax#single_bar) <target-counters()> [|](value_definition_syntax#single_bar) <target-text()> <leader()> = leader( <leader-type> ) <counter()> = counter( [<counter-name>](counter-name) , <counter-style>[?](value_definition_syntax#question_mark) ) <counters()> = counters( [<counter-name>](counter-name) , [<string>](string) , <counter-style>[?](value_definition_syntax#question_mark) ) <url> = url( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) [|](value_definition_syntax#single_bar) src( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) <target-counter()> = target-counter( [[](value_definition_syntax#brackets) [<string>](string) [|](value_definition_syntax#single_bar) <url> []](value_definition_syntax#brackets) , [<custom-ident>](custom-ident) , <counter-style>[?](value_definition_syntax#question_mark) ) <target-counters()> = target-counters( [[](value_definition_syntax#brackets) [<string>](string) [|](value_definition_syntax#single_bar) <url> []](value_definition_syntax#brackets) , [<custom-ident>](custom-ident) , [<string>](string) , <counter-style>[?](value_definition_syntax#question_mark) ) <target-text()> = target-text( [[](value_definition_syntax#brackets) [<string>](string) [|](value_definition_syntax#single_bar) <url> []](value_definition_syntax#brackets) , [[](value_definition_syntax#brackets) content [|](value_definition_syntax#single_bar) before [|](value_definition_syntax#single_bar) after [|](value_definition_syntax#single_bar) first-letter []](value_definition_syntax#brackets)[?](value_definition_syntax#question_mark) ) <leader-type> = dotted [|](value_definition_syntax#single_bar) solid [|](value_definition_syntax#single_bar) space [|](value_definition_syntax#single_bar) [<string>](string) <counter-style> = [<counter-style-name>](counter-style-name) [|](value_definition_syntax#single_bar) <symbols()> <symbols()> = symbols( <symbols-type>[?](value_definition_syntax#question_mark) [[](value_definition_syntax#brackets) [<string>](string) [|](value_definition_syntax#single_bar) <image> []](value_definition_syntax#brackets)[+](value_definition_syntax#plus) ) <symbols-type> = cyclic [|](value_definition_syntax#single_bar) numeric [|](value_definition_syntax#single_bar) alphabetic [|](value_definition_syntax#single_bar) symbolic [|](value_definition_syntax#single_bar) fixed ``` Examples -------- ### Headings and quotes This example inserts quotation marks around quotes, and adds the word "Chapter" before headings. #### HTML ``` <h1>5</h1> <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> <h1>6</h1> <p> According to the Mozilla Manifesto, <q cite="http://www.mozilla.org/en-US/about/manifesto/"> Individuals must have the ability to shape the Internet and their own experiences on the Internet. </q> Therefore, we can infer that contributing to the open web can protect our own individual experiences on it. </p> ``` #### CSS ``` q { color: blue; } q::before { content: open-quote; } q::after { content: close-quote; } h1::before { content: "Chapter "; /\* The trailing space creates separation between the added content and the rest of the content \*/ } ``` #### Result ### Image combined with alternative text This example inserts an image before the link and provides alternative text that a screen reader can output as speech. Some browsers may also display the alternative text. #### 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 only be used on browsers that *display* the alternative text. ``` a::before { content: url("https://mozorg.cdn.mozilla.net/media/img/favicon.ico") / " MOZILLA: "; font: x-small Arial, sans-serif; color: gray; } ``` #### Result The browser should display the icon before the link below. If using a screen reader, it should speak the word "MOZILLA" when it reaches the image. Note that on a browser that does not support the alternative text syntax, the whole line is invalid. In this case neither the image or alternative text will be used! You could partially address this issue by including CSS that adds the image before the line with them both. ### Targeting classes This example inserts additional text after special items in a list. #### 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 ``` .new-entry::after { content: " New!"; /\* The leading space creates separation between the added content and the rest of the content \*/ color: red; } ``` #### Result ### Images and element attributes This example inserts an image before each link, and adds its `id` attribute after. #### HTML ``` <ul> <li><a id="moz" href="https://www.mozilla.org/"> Mozilla Home Page</a></li> <li> <a id="mdn" href="https://developer.mozilla.org/"> Mozilla Developer Network</a > </li> </ul> ``` #### CSS ``` a { text-decoration: none; border-bottom: 3px dotted navy; } a::after { content: " (" attr(id) ")"; } #moz::before { content: url("https://mozorg.cdn.mozilla.net/media/img/favicon.ico"); } #mdn::before { content: url("mdn-favicon16.png"); } li { margin: 1em; } ``` #### Result ### Element replacement This example replaces an element's content with an image. You can replace the contents of an element with either a [`url()`](url) or an [`<image>`](image) value. Content added with `::before` or `::after` will not be generated as the contents of the element have been replaced. #### HTML ``` <div id="replaced">Mozilla</div> ``` #### CSS ``` #replaced { content: url("mdn.svg"); } /\* will not show if element replacement is supported \*/ #replaced::after { content: " (" attr(id) ")"; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Generated Content Module Level 3 # content-property](https://w3c.github.io/csswg-drafts/css-content/#content-property) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `content` | 1 | 12 | 1 | 8 | 4 | 1 | 4.4 | 18 | 4 | 10.1 | 1 | 1.0 | | `alt_text` | 77 | 79 | No | No | 64 | No | 77 | 77 | No | 55 | No | 12.0 | | `element_replacement` | 28 | 79 | 63 | No | 7 | 9 | 4.4 | 28 | 63 | 10.1 | 9 | 1.5 | | `none_applies_to_elements` | No | No | 91 | No | No | No | No | No | No | No | No | No | | `url` | 1 | 12 | 1 | 8 | 7 | 1 | 37 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [Replaced elements](replaced_element) * [`::after`](::after) * [`::before`](::before) * [`::marker`](::marker) * [`contain`](contain) * [`quotes`](quotes) * [`url()`](url) function
programming_docs
css border-inline-start-style border-inline-start-style ========================= The `border-inline-start-style` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property defines the style of the logical inline start border of an element, which maps to a physical border style depending on the element's writing mode, directionality, and text orientation. It corresponds to the [`border-top-style`](border-top-style), [`border-right-style`](border-right-style), [`border-bottom-style`](border-bottom-style), or [`border-left-style`](border-left-style) property depending on the values defined for [`writing-mode`](writing-mode), [`direction`](direction), and [`text-orientation`](text-orientation). Try it ------ Syntax ------ ``` /\* <'border-style'> values \*/ border-inline-start-style: dashed; border-inline-start-style: dotted; border-inline-start-style: groove; /\* Global values \*/ border-inline-start-style: inherit; border-inline-start-style: initial; border-inline-start-style: revert; border-inline-start-style: revert-layer; border-inline-start-style: unset; ``` Related properties are [`border-block-start-style`](border-block-start-style), [`border-block-end-style`](border-block-end-style), and [`border-inline-end-style`](border-inline-end-style), which define the other border styles of the element. | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | ### Values `<'border-style'>` The line style of the border. See [`border-style`](border-style). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` border-inline-start-style = <'border-top-style'> ``` Examples -------- ### HTML ``` <div> <p class="exampleText">Example text</p> </div> ``` ### CSS ``` div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; border: 5px solid blue; border-inline-start-style: dashed; } ``` Specifications -------------- | Specification | | --- | | [CSS Logical Properties and Values Level 1 # border-style](https://w3c.github.io/csswg-drafts/css-logical/#border-style) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-inline-start-style` | 69 | 79 | 41 3 | No | 56 | 12.1 | 69 | 69 | 41 4 | 48 | 12.2 | 10.0 | See also -------- * [CSS Logical Properties and Values](css_logical_properties) * This property maps to one of the physical border properties: [`border-top-style`](border-top-style), [`border-right-style`](border-right-style), [`border-bottom-style`](border-bottom-style), or [`border-left-style`](border-left-style). * [`writing-mode`](writing-mode), [`direction`](direction), [`text-orientation`](text-orientation) css animation-name animation-name ============== The `animation-name` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property specifies the names of one or more [`@keyframes`](@keyframes) at-rules that describe the animation to apply to an element. Multiple `@keyframe` at-rules are specified as a comma-separated list of names. If the specified name does not match any `@keyframe` at-rule, no properties are animated. Try it ------ It is often convenient to use the shorthand property [`animation`](animation) to set all animation properties at once. Syntax ------ ``` /\* Single animation \*/ animation-name: none; animation-name: test_05; animation-name: -specific; animation-name: sliding-vertically; /\* Multiple animations \*/ animation-name: test1, animation4; animation-name: none, -moz-specific, sliding; /\* Global values \*/ animation-name: inherit; animation-name: initial; animation-name: revert; animation-name: revert-layer; animation-name: unset; ``` ### Values `none` A special keyword denoting no keyframes. It can be used to deactivate an animation without changing the ordering of the other identifiers, or to deactivate animations coming from the cascade. [`<custom-ident>`](custom-ident) A name identifying the animation. This identifier is composed of a combination of case-sensitive letters `a` to `z`, numbers `0` to `9`, underscores (`_`), and/or dashes (`-`). The first non-dash character must be a letter. Also, two dashes are forbidden at the beginning of the identifier. Furthermore, the identifier can't be `none`, `unset`, `initial`, or `inherit`. **Note:** When you specify multiple comma-separated values on an `animation-*` property, they are applied to the animations in the order in which the [`animation-name`](animation-name)s appear. For situations where the number of animations and `animation-*` property values do not match, see [Setting multiple animation property values](css_animations/using_css_animations#setting_multiple_animation_property_values). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements, [`::before`](::before) and [`::after`](::after) <pseudo-elements> | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | Not animatable | Formal syntax ------------- ``` animation-name = [[](value_definition_syntax#brackets) none [|](value_definition_syntax#single_bar) <keyframes-name> []](value_definition_syntax#brackets)[#](value_definition_syntax#hash_mark) <keyframes-name> = [<custom-ident>](custom-ident) [|](value_definition_syntax#single_bar) [<string>](string) ``` Examples -------- ### Naming an animation This animation has an `animation-name` of `rotate`. #### HTML ``` <div class="box"></div> ``` #### CSS ``` .box { background-color: rebeccapurple; border-radius: 10px; width: 100px; height: 100px; } .box:hover { animation-name: rotate; animation-duration: 0.7s; } @keyframes rotate { 0% { transform: rotate(0); } 100% { transform: rotate(360deg); } } ``` #### Result Hover over the rectangle to start the animation. See [CSS animations](css_animations/using_css_animations) for examples. Specifications -------------- | Specification | | --- | | [CSS Animations Level 1 # animation-name](https://w3c.github.io/csswg-drafts/css-animations/#animation-name) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `animation-name` | 43 3 | 12 12 | 49 16 5 | 10 | 30 15 12.1-15 12-15 | 9 4 | 43 ≤37 | 43 18 | 49 16 5 | 30 14 12.1-14 12-14 | 9 3.2 | 4.0 1.0 | See also -------- * [Using CSS animations](css_animations/using_css_animations) * JavaScript [`AnimationEvent`](https://developer.mozilla.org/en-US/docs/Web/API/AnimationEvent) API * Other related animation properties: [`animation`](animation), [`animation-composition`](animation-composition), [`animation-delay`](animation-delay), [`animation-direction`](animation-direction), [`animation-duration`](animation-duration), [`animation-fill-mode`](animation-fill-mode), [`animation-iteration-count`](animation-iteration-count), [`animation-play-state`](animation-play-state), [`animation-timeline`](animation-timeline), [`animation-timing-function`](animation-timing-function) css <alpha-value> <alpha-value> ============= The `<alpha-value>` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [data type](css_types) represents a value that can be either a [`<number>`](number) or a [`<percentage>`](percentage), specifying the **[alpha channel](https://developer.mozilla.org/en-US/docs/Glossary/Alpha)** or **transparency** of a color. Syntax ------ The value of an `<alpha-value>` is given as either a [`<number>`](number) or a [`<percentage>`](percentage). If given as a number, the useful range is 0 (fully transparent) to 1.0 (fully opaque), with decimal values in between; that is, 0.5 indicates that half of the foreground color is used and half of the background color is used. Values outside the range of 0 to 1 are permitted, but are [clamped](https://en.wikipedia.org/wiki/Clamping_(graphics)) to lie within the range 0 to 1. If the alpha value is given as a percentage, 0% corresponds to fully transparent while 100% indicates fully opaque. Formal syntax ------------- ``` <alpha-value> = [<number>](number) [|](value_definition_syntax#single_bar) [<percentage>](percentage) ``` Interpolation ------------- When animated, values of the `<alpha-value>` CSS data type are [interpolated](https://developer.mozilla.org/en-US/docs/Glossary/Interpolation) as real, floating-point numbers. The speed of the interpolation is determined by the [timing function](easing-function) associated with the animation. Examples -------- ### Setting text color opacity Here an alpha value is used to set partially transparent text: ``` /\* <rgba()> \*/ color: rgba(34, 12, 64, 0.6); color: rgba(34 12 64 / 60%); ``` ### Setting shape image threshold Here an alpha value is used to determine which parts of an image are considered part of a shape: ``` /\* shape-image-threshold \*/ shape-image-threshold: 70%; shape-image-threshold: 0.7; ``` Specifications -------------- | Specification | | --- | | [CSS Color Module Level 4 # type-def-alpha-value](https://drafts.csswg.org/css-color/#type-def-alpha-value) | See also -------- * [Fundamental text and font styling](https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text/Fundamentals) * [CSS data types](css_types) * [CSS Color](css_colors) * [`<color>`](color_value) css background-blend-mode background-blend-mode ===================== The `background-blend-mode` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets how an element's background images should blend with each other and with the element's background color. Try it ------ Blending modes should be defined in the same order as the [`background-image`](background-image) property. If the blending modes' and background images' list lengths are not equal, it will be repeated and/or truncated until lengths match. Syntax ------ ``` /\* One value \*/ background-blend-mode: normal; /\* Two values, one per background \*/ background-blend-mode: darken, luminosity; /\* Global values \*/ background-blend-mode: inherit; background-blend-mode: initial; background-blend-mode: revert; background-blend-mode: revert-layer; background-blend-mode: unset; ``` ### Values [`<blend-mode>`](blend-mode) The blending mode to be applied. There can be several values, separated by commas. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `normal` | | Applies to | All elements. In SVG, it applies to container elements, graphics elements, and graphics referencing elements.. It also applies to [`::first-letter`](::first-letter) and [`::first-line`](::first-line). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as specified | | Animation type | discrete | Formal syntax ------------- ``` background-blend-mode = [<mix-blend-mode>](mix-blend-mode)[#](value_definition_syntax#hash_mark) ``` Examples -------- ### Basic example ``` .item { width: 300px; height: 300px; background: url("image1.png"), url("image2.png"); background-blend-mode: screen; } ``` ### Try out different blend modes Specifications -------------- | Specification | | --- | | [Compositing and Blending Level 1 # background-blend-mode](https://drafts.fxtf.org/compositing/#background-blend-mode) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `background-blend-mode` | 35 | 79 | 30 | No | 22 | 8 | 37 | 35 | 30 | 22 | 8 | 3.0 | See also -------- * [`<blend-mode>`](blend-mode) * [`mix-blend-mode`](mix-blend-mode) css max-content max-content =========== The `max-content` sizing keyword represents the intrinsic maximum width or height of the content. For text content this means that the content will not wrap at all even if it causes overflows. Syntax ------ ``` /\* Used as a length \*/ width: max-content; inline-size: max-content; height: max-content; block-size: max-content; /\* used in grid tracks \*/ grid-template-columns: 200px 1fr max-content; /\* Global values \*/ max-content: inherit; max-content: initial; max-content: revert; max-content: revert-layer; max-content: unset; ``` Examples -------- ### Using max-content for box sizing #### HTML ``` <div id="container"> <div class="item">Item</div> <div class="item"> Item with more text in it which will overflow the fixed width box. </div> </div> ``` #### CSS ``` #container { background-color: #8cffa0; padding: 10px; width: 200px; } .item { width: max-content; background-color: #8ca0ff; padding: 5px; margin-bottom: 1em; } ``` #### Result ### Sizing grid columns with max-content #### HTML ``` <div id="container"> <div>Item</div> <div>Item with more text in it.</div> <div>Flexible item</div> </div> ``` #### CSS ``` #container { display: grid; grid-template-columns: max-content max-content 1fr; grid-gap: 5px; box-sizing: border-box; height: 200px; width: 100%; background-color: #8cffa0; padding: 10px; } #container > div { background-color: #8ca0ff; padding: 5px; } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Box Sizing Module Level 3 # valdef-width-max-content](https://w3c.github.io/csswg-drafts/css-sizing-3/#valdef-width-max-content) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `max-content` | 46 22 | 79 79 | 66 3 | No | 44 | 11 2 | 46 | 46 | 66 4 | 43 | 11 1 | 5.0 | See also -------- * Related sizing keywords: [`min-content`](min-content), [`fit-content`](fit-content) css clip-path clip-path ========= The `clip-path` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property creates a clipping region that sets what part of an element should be shown. Parts that are inside the region are shown, while those outside are hidden. Try it ------ Syntax ------ ``` /\* Keyword values \*/ clip-path: none; /\* <clip-source> values \*/ clip-path: url(resources.svg#c1); /\* <geometry-box> values \*/ clip-path: margin-box; clip-path: border-box; clip-path: padding-box; clip-path: content-box; clip-path: fill-box; clip-path: stroke-box; clip-path: view-box; /\* <basic-shape> values \*/ clip-path: inset(100px 50px); clip-path: circle(50px at 0 100px); clip-path: ellipse(50px 60px at 0 10% 20%); clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); clip-path: path( "M0.5,1 C0.5,1,0,0.7,0,0.3 A0.25,0.25,1,1,1,0.5,0.3 A0.25,0.25,1,1,1,1,0.3 C1,0.7,0.5,1,0.5,1 Z" ); /\* Box and shape values combined \*/ clip-path: padding-box circle(50px at 0 100px); /\* Global values \*/ clip-path: inherit; clip-path: initial; clip-path: revert; clip-path: revert-layer; clip-path: unset; ``` The `clip-path` property is specified as one or a combination of the values listed below. ### Values `<clip-source>` A [`url()`](url) referencing an [SVG](https://developer.mozilla.org/en-US/docs/Web/SVG) [`<clipPath>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/clipPath) element. [`<basic-shape>`](basic-shape) A shape whose size and position is defined by the `<geometry-box>` value. If no geometry box is specified, the `border-box` will be used as the reference box. One of: [`inset()`](basic-shape/inset) Defines an inset rectangle. [`circle()`](basic-shape/circle) Defines a circle using a radius and a position. [`ellipse()`](basic-shape/ellipse) Defines an ellipse using two radii and a position. [`polygon()`](basic-shape/polygon) Defines a polygon using an SVG filling rule and a set of vertices. [`path()`](path) Defines a shape using an optional SVG filling rule and an SVG path definition. `<geometry-box>` If specified in combination with a `<basic-shape>`, this value defines the reference box for the basic shape. If specified by itself, it causes the edges of the specified box, including any corner shaping (such as a [`border-radius`](border-radius)), to be the clipping path. The geometry box can be one of the following values: `margin-box` Uses the [margin box](css_shapes/from_box_values#margin-box) as the reference box. `border-box` Uses the [border box](css_shapes/from_box_values#border-box) as the reference box. `padding-box` Uses the [padding box](css_shapes/from_box_values#padding-box) as the reference box. `content-box` Uses the [content box](css_shapes/from_box_values#content-box) as the reference box. `fill-box` Uses the object bounding box as the reference box. `stroke-box` Uses the stroke bounding box as the reference box. `view-box` Uses the nearest SVG viewport as the reference box. If a `[viewBox](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox)` attribute is specified for the element creating the SVG viewport, the reference box is positioned at the origin of the coordinate system established by the `viewBox` attribute and the dimension of the size of the reference box is set to the width and height values of the `viewBox` attribute. `none` No clipping path is created. **Note:** A computed value other than `none` results in the creation of a new [stacking context](css_positioning/understanding_z_index/the_stacking_context) the same way that CSS [`opacity`](opacity) does for values other than `1`. Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | `none` | | Applies to | all elements; In SVG, it applies to container elements excluding the [`<defs>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs) element and all graphics elements | | [Inherited](inheritance) | no | | Percentages | refer to reference box when specified, otherwise border-box | | [Computed value](computed_value) | as specified, but with [`url()`](url) values made absolute | | Animation type | yes, as specified for [`<basic-shape>`](basic-shape), otherwise no | Formal syntax ------------- ``` clip-path = <clip-source> [|](value_definition_syntax#single_bar) [[](value_definition_syntax#brackets) [<basic-shape>](basic-shape) [||](value_definition_syntax#double_bar) <geometry-box> []](value_definition_syntax#brackets) [|](value_definition_syntax#single_bar) none <clip-source> = <url> <geometry-box> = <shape-box> [|](value_definition_syntax#single_bar) fill-box [|](value_definition_syntax#single_bar) stroke-box [|](value_definition_syntax#single_bar) view-box <url> = url( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) [|](value_definition_syntax#single_bar) src( [<string>](string) [<url-modifier>](url-modifier)[\*](value_definition_syntax#asterisk) ) <shape-box> = <box> [|](value_definition_syntax#single_bar) margin-box <box> = border-box [|](value_definition_syntax#single_bar) padding-box [|](value_definition_syntax#single_bar) content-box ``` Examples -------- ### Comparison of HTML and SVG ``` html, body { height: 100%; box-sizing: border-box; background: #eee; } .grid { width: 100%; height: 100%; display: flex; font: 1em monospace; } .row { display: flex; flex: 1 auto; flex-direction: row; flex-wrap: wrap; } .col { flex: 1 auto; } .cell { margin: 0.5em; padding: 0.5em; background-color: #fff; overflow: hidden; text-align: center; flex: 1; } .note { background: #fff3d4; padding: 1em; margin: 0.5em 0.5em 0; font: 0.8em sans-serif; text-align: left; white-space: nowrap; } .note + .row .cell { margin-top: 0; } .container { display: inline-block; border: 1px dotted grey; position: relative; } .container::before { content: "margin"; position: absolute; top: 2px; left: 2px; font: italic 0.6em sans-serif; } .view-box { box-shadow: 1rem 1rem 0 #efefef inset, -1rem -1rem 0 #efefef inset; } .container.view-box::after { content: "view-box"; position: absolute; left: 1.1rem; top: 1.1rem; font: italic 0.6em sans-serif; } .cell span { display: block; margin-bottom: 0.5em; } p { font-family: sans-serif; background: #000; color: pink; margin: 2em; padding: 3em 1em; border: 1em solid pink; width: 6em; } .none { clip-path: none; } .svg { clip-path: url(#myPath); } .svg2 { clip-path: path( "M15,45 A30,30,0,0,1,75,45 A30,30,0,0,1,135,45 Q135,90,75,130 Q15,90,15,45 Z" ); } .shape1 { clip-path: circle(25%); } .shape2 { clip-path: circle(25% at 25% 25%); } .shape3 { clip-path: fill-box circle(25% at 25% 25%); } .shape4 { clip-path: stroke-box circle(25% at 25% 25%); } .shape5 { clip-path: view-box circle(25% at 25% 25%); } .shape6 { clip-path: margin-box circle(25% at 25% 25%); } .shape7 { clip-path: border-box circle(25% at 25% 25%); } .shape8 { clip-path: padding-box circle(25% at 25% 25%); } .shape9 { clip-path: content-box circle(25% at 25% 25%); } .defs { width: 0; height: 0; margin: 0; } pre { margin-bottom: 0; } svg { margin: 1em; font-family: sans-serif; width: 192px; height: 192px; } svg rect { stroke: pink; stroke-width: 16px; } svg text { fill: pink; text-anchor: middle; } svg text.em { font-style: italic; } ``` ### Complete example #### HTML ``` <img id="clipped" src="mdn.svg" alt="MDN logo" /> <svg height="0" width="0"> <defs> <clipPath id="cross"> <rect y="110" x="137" width="90" height="90" /> <rect x="0" y="110" width="90" height="90" /> <rect x="137" y="0" width="90" height="90" /> <rect x="0" y="0" width="90" height="90" /> </clipPath> </defs> </svg> <select id="clipPath"> <option value="none">none</option> <option value="circle(100px at 110px 100px)">circle</option> <option value="url(#cross)" selected>cross</option> <option value="inset(20px round 20px)">inset</option> <option value="path('M 0 200 L 0,110 A 110,90 0,0,1 240,100 L 200 340 z')"> path </option> </select> ``` #### CSS ``` #clipped { margin-bottom: 20px; clip-path: url(#cross); } ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Masking Module Level 1 # the-clip-path](https://drafts.fxtf.org/css-masking/#the-clip-path) | | [CSS Shapes Module Level 1 # supported-basic-shapes](https://w3c.github.io/csswg-drafts/css-shapes/#supported-basic-shapes) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `clip-path` | 55 23 | 79 12 Only supports clip paths defined by `url()`. | 3.5 | 10 Only supports clip paths defined by `url()`. | 42 15 | 9.1 7 | 55 4.4 | 55 25 | 4 | 42 14 | 9.3 7 | 6.0 1.5 | | `animations` | 55 | 79 | 49 | No | 42 | No | 55 | 55 | 49 | 42 | No | 6.0 | | `basic_shape` | 23 | 79 | 54 | No | 15 | 7 | 4.4 | 25 | 54 | 14 | 7 | 1.5 | | `fill_and_stroke_box` | No | No | 51 This value was supported before Firefox 51, but as an alias to `border-box`. | No | No | preview | No | No | 51 This value was supported before Firefox 51, but as an alias to `border-box`. | No | No | No | | `html` | 23 | 79 | 3.5 | No | 15 | 7 | 4.4 | 25 | 4 | 14 | 7 | 1.5 | | `path` | 88 | 88 | 71 | No | No | 13.1 10 | 88 | 88 | 79 | No | 13 10 | 15.0 | | `svg` | 23 | 12 | 52 | 10 | 15 | 7 | 4.4 | 25 | 52 | 14 | 7 | 1.5 | See also -------- * [Shapes in clipping and masking – and how to use them](https://hacks.mozilla.org/2017/06/css-shapes-clipping-and-masking/) * CSS properties: [`mask`](mask), [`filter`](filter) * [Applying SVG effects to HTML content](https://developer.mozilla.org/en-US/docs/Web/SVG/Applying_SVG_effects_to_HTML_content) * SVG attributes: + `[clip-path](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/clip-path)` + `[clip-rule](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/clip-rule)`
programming_docs
css border-bottom border-bottom ============= The `border-bottom` [shorthand](shorthand_properties) [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) property sets an element's bottom <border>. It sets the values of [`border-bottom-width`](border-bottom-width), [`border-bottom-style`](border-bottom-style) and [`border-bottom-color`](border-bottom-color). Try it ------ As with all shorthand properties, `border-bottom` 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: ``` border-bottom-style: dotted; border-bottom: thick green; ``` It is actually the same as this one: ``` border-bottom-style: dotted; border-bottom: none thick green; ``` The value of [`border-bottom-style`](border-bottom-style) given before `border-bottom` is ignored. Since the default value of [`border-bottom-style`](border-bottom-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: * [`border-bottom-color`](border-bottom-color) * [`border-bottom-style`](border-bottom-style) * [`border-bottom-width`](border-bottom-width) Syntax ------ ``` border-bottom: 1px; border-bottom: 2px dotted; border-bottom: medium dashed blue; /\* Global values \*/ border-bottom: inherit; border-bottom: initial; border-bottom: revert; border-bottom: revert-layer; border-bottom: 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 [`border-bottom-width`](border-bottom-width). `<br-style>` See [`border-bottom-style`](border-bottom-style). [`<color>`](color_value) See [`border-bottom-color`](border-bottom-color). Formal definition ----------------- | | | | --- | --- | | [Initial value](initial_value) | as each of the properties of the shorthand:* [`border-bottom-width`](border-bottom-width): `medium` * [`border-bottom-style`](border-bottom-style): `none` * [`border-bottom-color`](border-bottom-color): `currentcolor` | | Applies to | all elements. It also applies to [`::first-letter`](::first-letter). | | [Inherited](inheritance) | no | | [Computed value](computed_value) | as each of the properties of the shorthand:* [`border-bottom-width`](border-bottom-width): the absolute length or `0` if [`border-bottom-style`](border-bottom-style) is `none` or `hidden` * [`border-bottom-style`](border-bottom-style): as specified * [`border-bottom-color`](border-bottom-color): computed color | | Animation type | as each of the properties of the shorthand:* [`border-bottom-color`](border-bottom-color): a [color](color_value#interpolation) * [`border-bottom-style`](border-bottom-style): discrete * [`border-bottom-width`](border-bottom-width): a [length](length#interpolation) | Formal syntax ------------- ``` border-bottom = <line-width> [||](value_definition_syntax#double_bar) <line-style> [||](value_definition_syntax#double_bar) [<color>](color_value) <line-width> = [<length [0,∞]>](length) [|](value_definition_syntax#single_bar) thin [|](value_definition_syntax#single_bar) medium [|](value_definition_syntax#single_bar) thick <line-style> = none [|](value_definition_syntax#single_bar) hidden [|](value_definition_syntax#single_bar) dotted [|](value_definition_syntax#single_bar) dashed [|](value_definition_syntax#single_bar) solid [|](value_definition_syntax#single_bar) double [|](value_definition_syntax#single_bar) groove [|](value_definition_syntax#single_bar) ridge [|](value_definition_syntax#single_bar) inset [|](value_definition_syntax#single_bar) outset ``` Examples -------- ### Applying a bottom border #### HTML ``` <div>This box has a border on the bottom side.</div> ``` #### CSS ``` div { border-bottom: 4px dashed blue; background-color: gold; height: 100px; width: 100px; font-weight: bold; text-align: center; } ``` #### Results Specifications -------------- | Specification | | --- | | [CSS Backgrounds and Borders Module Level 3 # border-shorthands](https://w3c.github.io/csswg-drafts/css-backgrounds/#border-shorthands) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `border-bottom` | 1 | 12 | 1 | 4 | 3.5 | 1 | 4.4 | 18 | 4 | 14 | 1 | 1.0 | See also -------- * [`border`](border) * [`border-block`](border-block) * [`outline`](outline) css path() path() ====== The `path()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](css_functions) accepts an SVG path string, and is used in [CSS Shapes](css_shapes) and CSS Motion Path to enable a shape to be drawn. Try it ------ Syntax ------ When used in [`offset-path`](offset-path) or `[d](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d)`: ``` path(<string>) ``` When used in [`clip-path`](clip-path): ``` path([<'fill-rule'>,]?<string>) ``` ### Parameters `<'fill-rule'>` The filling rule for the interior of the path. Possible values are `nonzero` or `evenodd`. The default value is `nonzero`. See [fill-rule](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule) for more details. `<string>` The string is a [data string](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d) for defining an [SVG path](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/path). Examples -------- ### Examples of correct values for path() ``` path("M 10 80 C 40 10, 65 10, 95 80 S 150 150, 180 80"); path(evenodd,"M 10 80 C 40 10, 65 10, 95 80 S 150 150, 180 80"); ``` ### Use as the value of offset-path The `path()` function is used to create a path for the item to travel round. Changing any of the values will cause the path to not neatly run round the circle. ### Modify the value of the SVG path d attribute The `path()` can be used to modify the value of the SVG [`d` attribute](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d), which can also be set to `none` in your CSS. The "V" symbol will flip vertically when you hover over it, if `d` is supported as a CSS property. #### CSS ``` html, body, svg { height: 100%; } /\* This path is displayed on hover\*/ #svg\_css\_ex1:hover path { d: path("M20,80 L50,20 L80,80"); } ``` #### HTML ``` <svg id="svg\_css\_ex1" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"> <path fill="none" stroke="red" d="M20,20 L50,80 L80,20" /> </svg> ``` #### Result Specifications -------------- | Specification | | --- | | [CSS Shapes Module Level 1 # funcdef-basic-shape-path](https://w3c.github.io/csswg-drafts/css-shapes/#funcdef-basic-shape-path) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `path` | 46 Only supported on the `offset-path` property. | 79 Only supported on the `offset-path` property. | 97 Only supported on the `d` SVG presentation attribute and the `clip-path` and `offset-path` CSS properties. Not supported on the `shape-outside` CSS property. 71 Only supported on the `clip-path` and `offset-path` properties. 63 Only supported on the `offset-path` property. | No | 33 Only supported on the `offset-path` property. | No | 46 Only supported on the `offset-path` property. | 46 Only supported on the `offset-path` property. | 97 Only supported on the `d` SVG presentation attribute and the `clip-path` and `offset-path` CSS properties. Not supported on the `shape-outside` CSS property. 79 Only supported on the `clip-path` and `offset-path` properties. 63 Only supported on the `offset-path` property. | 33 Only supported on the `offset-path` property. | No | 5.0 Only supported on the `offset-path` property. | See also -------- * [`<shape-outside>`](shape-outside) * [CSS Shapes](css_shapes) * [Overview of CSS Shapes](css_shapes/overview_of_css_shapes) * [SVG Path Syntax Illustrated Guide](https://css-tricks.com/svg-path-syntax-illustrated-guide/) css repeating-conic-gradient() repeating-conic-gradient() ========================== The `repeating-conic-gradient()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](../css_functions) creates an image consisting of a repeating gradient (rather than a [`single gradient`](conic-gradient)) with color transitions rotated around a center point (rather than [`radiating from the center`](repeating-radial-gradient)). Try it ------ Syntax ------ ``` /\* Starburst: a blue on blue starburst: the gradient is a starburst of lighter and darker blue, centered in the upper left quadrant, offset by 3degrees so there is no up/down straight line \*/ background: repeating-conic-gradient( from 3deg at 25% 25%, hsl(200, 100%, 50%) 0deg 15deg, hsl(200, 100%, 60%) 10deg 30deg ); ``` ### Values [`<angle>`](../angle) Preceded by the `from` keyterm, and taking an angle as its value, defines the gradient rotation in clockwise direction. `<position>` Using the same length, order and keyterm values as the [background-position](../background-position) property, the position defines center of the gradient. If omitted, the default value is `center`, meaning the gradient will be centered, . `<angular-color-stop>` A color-stop's [`<color>`](../color_value) value, followed by one or two optional stop positions, (an [`<angle>`](../angle) along the gradient's circumference axis). The last color stop minus the first color-stop angle defines the size of the repeating gradient. `<color-hint>` An [interpolation](https://developer.mozilla.org/en-US/docs/Glossary/Interpolation) hint defining how the gradient progresses between adjacent color stops. The length defines at which point between two color stops the gradient color should reach the midpoint of the color transition. If omitted, the midpoint of the color transition is the midpoint between two color stops. **Note:** Rendering of [color stops in CSS gradients](#gradient_with_multiple_color_stops) follows the same rules as color stops in [SVG gradients](https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Gradients). Description ----------- Example repeating conic gradients include starbursts. The result of the `repeating-conic-gradient()` function is an object of the [`<gradient>`](../gradient) data type, which is a special kind of [`<image>`](../image). If neither the first nor the last color stops include a color stop angle greater than 0deg or less than 360 degrees respectively, the conic-gradient will not repeat. As with any gradient, a repeating-conic gradient has [no intrinsic dimensions](../image#description); i.e., it has no natural or preferred size, nor a preferred ratio. Its concrete size will match the size of the element it applies to, or the size the `<image>` is set to if it's set to something other than the element's size. Because `<gradient>`s belong to the `<image>` data type, they can only be used where `<image>`s can be used. For this reason, `repeating-conic-gradient()` won't work on [`background-color`](../background-color) and other properties that use the [`<color>`](../color_value) data type. **Note:** To create a conic gradient that does not repeat, make the gradient a full 360 degree rotation, or use the [`conic-gradient()`](conic-gradient) function instead. ### Understanding repeating conic gradients The repeating-conic-gradient syntax is similar to the [`conic-gradient()`](conic-gradient) and [`repeating-radial-gradient()`](repeating-radial-gradient) syntax. Like the non-repeating conic-gradient, the color-stops are placed around a gradient arc. Like the repeating radial gradient, the size of the repeating section is the first color stop subtracted from the angle of the last color stop. The above gradients are defined as being one third blue, one third red, and one third yellow. ``` repeating-conic-gradient(from 0deg, red 0deg 30deg, yellow 30deg 60deg, blue 60deg 90deg); repeating-radial-gradient(red 0 8%, yellow 8% 16%, blue 16% 24%); conic-gradient(red 120deg, yellow 120deg 240deg, blue 240deg); radial-gradient(red 33%, yellow 33% 66%, blue 66%); ``` For a repeating gradient to repeat we define the first and last color stops. Like in non-repeating gradients, the first and last color stops are assumed to be 0 and either 100% or 360deg if not explicitly declared. When defaulting to these values, the repeating arc is 360 degrees, and therefore doesn't repeat. Like the non-repeating conic gradient, the color-stops are placed around a gradient arc — the circumference of a circle, rather than on the gradient line emerging from the center of the gradient. The colors transition as if spun around the center of a circle, starting at the top if no `from <angle>` is declared, and going clockwise for the size of the angle that is the different between the largest and smallest color angle, then repeating. A repeating conic gradient is specified by indicating a rotation angle, the center of the gradient, and then specifying a list of color-stops. Like non-repeating conic gradients, the color-stops of a repeating conic gradient are specified with an [`<angle>`](../angle). Units include `deg` for degrees, `grad` for gradients, `rad` for radians, and `turn` for turns. There are 360 degrees, 400 gradians, 2π radians, and 1 turn in a circle. Browsers supporting repeating conic gradients also accept percent values, with 100% equaling 360 degrees, but this is not in the specification. Radial and conic gradient syntax provides for positioning the center of the gradient anywhere within, or even outside, the image. The values for the position are similar to the syntax for 2-value [`background-position`](../background-position). The gradient arc is part of the circumference of the gradient. 0 degrees is north, or 12:00pm. The colors of the gradient are determined by the angled color stops, their starting points, ending points, and, in between, and optional angled color-stop points. The transitions between colors can be altered with color hints between adjacent colors' color stops. #### Customizing gradients By adding more angled color-stop points on the gradient arc, you can create a highly customized transition between multiple colors. A color-stop's position can be explicitly defined by using an [`<angle>`](../angle). If you don't specify the location of a color stop, it is placed halfway between the one that precedes it and the one that follows it. Like the non-repeating gradient counterpart, If you don't specify an angle for the first or last color stop, the values are will be 0deg and 360deg. If you don't declare an angle for either, you'll get a non-repeating conic gradient. If you declare a non 0 or 360degree for the first or last respectively, the gradient will repeat based on that value. For example, if you don't declare an angle for the first color, and declare 10% on the last color stop, the arc will repeat 10 times. Rather, the starting point is the first color stop declared, and the last color stop is the last color stop angle declared. The following two gradients are equivalent: ``` repeating-conic-gradient(red, orange, yellow, green, blue 50%); repeating-conic-gradient(from -45deg, red 45deg, orange, yellow, green, blue 225deg) ``` By default, colors transition smoothly from the color at one color stop to the color at the subsequent color stop, with the midpoint between the colors being the half way point between the color transition. You can move this color transition midpoint to any point between two color stops by adding a color hint, indicating where the middle of the color transition should be. If two or more color stops are at the same location, the transition will be a hard line between the first and last colors declared at that location. While you can mix and match different angle units, don't. It makes CSS hard to read. ### Formal syntax Error: could not find syntax for this itemAccessibility concerns ---------------------- Browsers do not provide any special information on background images to assistive technology. This is important primarily for screen readers, as a screen reader will not announce its presence and therefore convey nothing to its users. While it is possible to create pie charts, checkerboards, and other effects with conic gradients, CSS images provide no native way to assign alternative text, and therefore the image represented by the conic gradient will not be accessible to screen reader users. If the image contains information critical to understanding the page's overall purpose, it is better to describe it semantically in the document. * [MDN Understanding WCAG, Guideline 1.1 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.1_%e2%80%94_providing_text_alternatives_for_non-text_content) * [Understanding Success Criterion 1.1.1 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/2016/NOTE-UNDERSTANDING-WCAG20-20161007/text-equiv-all.html) Examples -------- ### Black and white starburst ``` div { background-image: repeating-conic-gradient(#fff 0 9deg, #000 9deg 18deg); } ``` ### Off-centered gradient This gradient repeats 18 times, but since we only see the right half, we only see 9 repeats. ``` div { background: repeating-conic-gradient( from 3deg at 25% 25%, green, blue 2deg 5deg, green, yellow 15deg 18deg, green 20deg ); } ``` ### More repeating-conic-gradient examples Please see [Using CSS gradients](../css_images/using_css_gradients) for more examples. Specifications -------------- | Specification | | --- | | [CSS Image Values and Replaced Content Module Level 4 # repeating-gradients](https://w3c.github.io/csswg-drafts/css-images-4/#repeating-gradients) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `repeating-conic-gradient` | 69 | 79 | 83 | No | 56 | 12.1 | 69 | 69 | 83 | 48 | 12.2 | 10.0 | See also -------- * [Using CSS gradients](../css_images/using_css_gradients) * Other gradient functions: [`conic-gradient()`](conic-gradient), [`linear-gradient()`](linear-gradient), [`repeating-linear-gradient()`](repeating-linear-gradient), [`radial-gradient()`](radial-gradient), [`repeating-radial-gradient()`](repeating-radial-gradient) * [`<image>`](../image) * [`image()`](../image/image) * [`element()`](../element()) * [`image-set()`](../image/image-set) * [`cross-fade()`](../cross-fade) css repeating-radial-gradient() repeating-radial-gradient() =========================== The `repeating-radial-gradient()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](../css_functions) creates an image consisting of repeating gradients that radiate from an origin. It is similar to [`radial-gradient()`](radial-gradient) and takes the same arguments, but it repeats the color stops infinitely in all directions so as to cover its entire container, similar to [`repeating-linear-gradient()`](repeating-linear-gradient). The function's result is an object of the [`<gradient>`](../gradient) data type, which is a special kind of [`<image>`](../image). Try it ------ With each repetition, the positions of the color stops are shifted by a multiple of the dimensions of the basic radial gradient (the distance between the last color stop and the first). Thus, the position of each ending color stop coincides with a starting color stop; if the color values are different, this will result in a sharp visual transition, which can be mitigated by repeating the first color as the last color. As with any gradient, a repeating radial gradient has [no intrinsic dimensions](../image#description); i.e., it has no natural or preferred size, nor a preferred ratio. Its concrete size will match the size of the element it applies to. Because `<gradient>`s belong to the `<image>` data type, they can only be used where `<image>`s can be used. For this reason, `repeating-radial-gradient()` won't work on [`background-color`](../background-color) and other properties that use the [`<color>`](../color_value) data type. Syntax ------ ``` /\* A gradient at the center of its container, starting red, changing to blue, and finishing green, with the colors repeating every 30px \*/ repeating-radial-gradient(circle at center, red 0, blue, green 30px); /\* An elliptical gradient near the top left of its container, starting red, changing to green and back again, repeating five times between the center and the bottom right corner, and only once between the center and the top left corner \*/ repeating-radial-gradient(farthest-corner at 20% 20%, red 0, green, red 20%); ``` ### Values [`<position>`](../position_value) The position of the gradient, interpreted in the same way as [`background-position`](../background-position) or [`transform-origin`](../transform-origin). If unspecified, it defaults to `center`. `<shape>` The gradient's shape. The value can be `circle` (meaning that the gradient's shape is a circle with constant radius) or `ellipse` (meaning that the shape is an axis-aligned ellipse). If unspecified, it defaults to `ellipse`. `<extent-keyword>` A keyword describing how big the ending shape must be. The possible values are: | Keyword | Description | | --- | --- | | `closest-side` | The gradient's ending shape meets the side of the box closest to its center (for circles) or meets both the vertical and horizontal sides closest to the center (for ellipses). | | `closest-corner` | The gradient's ending shape is sized so that it exactly meets the closest corner of the box from its center. | | `farthest-side` | Similar to `closest-side`, except the ending shape is sized to meet the side of the box farthest from its center (or vertical and horizontal sides). | | `farthest-corner` | The gradient's ending shape is sized so that it exactly meets the farthest corner of the box from its center. | **Note:** Early implementations of this function included other keywords (`cover` and `contain`) as synonyms of the standard `farthest-corner` and `closest-side`, respectively. Use the standard keywords only, as some implementations have already dropped those older variants. `<color-stop>` A color-stop's [`<color>`](../color_value) value, followed by an optional stop position (either a [`<percentage>`](../percentage) or a [`<length>`](../length) along the gradient's axis). A percentage of `0%`, or a length of `0`, represents the center of the gradient; the value `100%` represents the intersection of the ending shape with the virtual gradient ray. Percentage values in between are linearly positioned on the virtual gradient ray. ### Formal syntax Error: could not find syntax for this itemExamples -------- ### Black and white gradient ``` .radial-gradient { background: repeating-radial-gradient( black, black 5px, white 5px, white 10px ); } ``` ### Farthest-corner ``` .radial-gradient { background: repeating-radial-gradient( ellipse farthest-corner at 20% 20%, red, black 5%, blue 5%, green 10% ); background: repeating-radial-gradient( ellipse farthest-corner at 20% 20%, red 0 5%, green 5% 10% ); } ``` The elliptical gradient will be centered 20% from the top left, and will repeat 10 times between the center and the farthest corner (the bottom right corner). Browsers supporting multi position color stops will display a red and green striped ellipse. Browsers not supporting the syntax yet will see a gradient that goes from red to black and then from blue to green. **Note:** Please see [Using CSS gradients](../css_images/using_css_gradients) for more examples. Specifications -------------- | Specification | | --- | | [CSS Images Module Level 3 # repeating-gradients](https://w3c.github.io/csswg-drafts/css-images/#repeating-gradients) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `repeating-radial-gradient` | 26 10 | 12 | 49 16 Before Firefox 36, gradients weren't applied on the pre-multiplied color space, leading to shades of grey unexpectedly appearing when used with transparency. 3.6 Since Firefox 42, the prefixed version of gradients can be disabled by setting `layout.css.prefixes.gradients` to `false`. | 10 | 15 12.1 12-15 | 7 5.1 Safari 4 was supporting an experimental `[-webkit-gradient(radial,…)](https://developer.apple.com/library/archive/documentation/InternetWeb/Conceptual/SafariVisualEffectsProgGuide/Gradients/Gradient.html)` function. This old outdated syntax is still supported for compatibility purposes. | ≤37 4.4 | 26 18 | 49 16 Before Firefox 36, gradients weren't applied on the pre-multiplied color space, leading to shades of grey unexpectedly appearing when used with transparency. 10 Since Firefox 42, the prefixed version of gradients can be disabled by setting `layout.css.prefixes.gradients` to `false`. | 14 12.1 12-14 | 7 5 Safari 4 was supporting an experimental `[-webkit-gradient(radial,…)](https://developer.apple.com/library/archive/documentation/InternetWeb/Conceptual/SafariVisualEffectsProgGuide/Gradients/Gradient.html)` function. This old outdated syntax is still supported for compatibility purposes. | 1.5 1.0 | | `at` | 26 | 12 | 49 16 Before Firefox 36, gradients weren't applied on the pre-multiplied color space, leading to shades of grey unexpectedly appearing when used with transparency. 10 Since Firefox 42, the prefixed version of gradients can be disabled by setting `layout.css.prefixes.gradients` to `false`. | 10 | 15 12-15 | No | 4.4 | 26 | 49 16 Before Firefox 36, gradients weren't applied on the pre-multiplied color space, leading to shades of grey unexpectedly appearing when used with transparency. 10 Since Firefox 42, the prefixed version of gradients can be disabled by setting `layout.css.prefixes.gradients` to `false`. | 14 12-14 | No | 1.5 | | `doubleposition` | 71 | 79 | 64 | No | 58 | 12.1 | 71 | 71 | 64 | 50 | 12.2 | 10.0 | | `interpolation_hints` | 40 | 79 | 36 | No | 27 | 7 | 40 | 40 | 46 | 27 | 7 | 4.0 | See also -------- * [Using CSS gradients](../css_images/using_css_gradients) * Other gradient functions: [`radial-gradient()`](radial-gradient), [`linear-gradient()`](linear-gradient), [`repeating-linear-gradient()`](repeating-linear-gradient), [`conic-gradient()`](conic-gradient), [`repeating-conic-gradient()`](repeating-conic-gradient) * [`<image>`](../image) * [`image()`](../image/image) * [`element()`](../element()) * [`image-set()`](../image/image-set) * [`cross-fade()`](../cross-fade)
programming_docs
css repeating-linear-gradient() repeating-linear-gradient() =========================== The `repeating-linear-gradient()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](../css_functions) creates an image consisting of repeating linear gradients. It is similar to [`linear-gradient()`](linear-gradient) and takes the same arguments, but it repeats the color stops infinitely in all directions so as to cover its entire container. The function's result is an object of the [`<gradient>`](../gradient) data type, which is a special kind of [`<image>`](../image). Try it ------ The length of the gradient that repeats is the distance between the first and last color stop. If the first color does not have a color-stop-length, the color-stop-length defaults to 0. With each repetition, the positions of the color stops are shifted by a multiple of the length of the basic linear gradient. Thus, the position of each ending color stop coincides with a starting color stop; if the color values are different, this will result in a sharp visual transition. This can be altered with repeating the first color again as the last color. As with any gradient, a repeating linear gradient has [no intrinsic dimensions](../image#description); i.e., it has no natural or preferred size, nor a preferred ratio. Its concrete size will match the size of the element it applies to. Because `<gradient>`s belong to the `<image>` data type, they can only be used where `<image>`s can be used. For this reason, `repeating-linear-gradient()` won't work on [`background-color`](../background-color) and other properties that use the [`<color>`](../color_value) data type. Syntax ------ ``` /\* A repeating gradient tilted 45 degrees, starting blue and finishing red, repeating 3 times \*/ repeating-linear-gradient(45deg, blue, red 33.3%); /\* A repeating gradient going from the bottom right to the top left, starting blue and finishing red, repeating every 20px \*/ repeating-linear-gradient(to left top, blue, red 20px); /\* A gradient going from the bottom to top, starting blue, turning green after 40%, and finishing red. This gradient doesn't repeat because the last color stop defaults to 100% \*/ repeating-linear-gradient(0deg, blue, green 40%, red); /\* A gradient repeating five times, going from the left to right, starting red, turning green, and back to red \*/ repeating-linear-gradient(to right, red 0%, green 10%, red 20%); ``` ### Values `<side-or-corner>` The position of the gradient line's starting point. If specified, it consists of the word `to` and up to two keywords: one indicates the horizontal side (`left` or `right`), and the other the vertical side (`top` or `bottom`). The order of the side keywords does not matter. If unspecified, it defaults to `to bottom`. The values `to top`, `to bottom`, `to left`, and `to right` are equivalent to the angles `0deg`, `180deg`, `270deg`, and `90deg` respectively. The other values are translated into an angle. [`<angle>`](../angle) The gradient line's angle of direction. A value of `0deg` is equivalent to `to top`; increasing values rotate clockwise from there. `<linear-color-stop>` A color-stop's [`<color>`](../color_value) value, followed by one or two optional stop positions, (each being either a [`<percentage>`](../percentage) or a [`<length>`](../length) along the gradient's axis). A percentage of `0%`, or a length of `0`, represents the start of the gradient; the value `100%` is 100% of the image size, meaning the gradient will not repeat. `<color-hint>` Th color-hint is an interpolation hint defining how the gradient progresses between adjacent color stops. The length defines at which point between two color stops the gradient color should reach the midpoint of the color transition. If omitted, the midpoint of the color transition is the midpoint between two color stops. **Note:** Rendering of [color stops in CSS gradients](#gradient_with_multiple_color_stops) follows the same rules as color stops in [SVG gradients](https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Gradients). ### Formal syntax Error: could not find syntax for this itemExamples -------- ### Zebra stripes ``` body { background-image: repeating-linear-gradient( -45deg, transparent, transparent 20px, black 20px, black 40px ); /\* with multiple color stop lengths \*/ background-image: repeating-linear-gradient( -45deg, transparent 0 20px, black 20px 40px ); } ``` ### Ten repeating horizontal bars ``` body { background-image: repeating-linear-gradient( to bottom, rgb(26, 198, 204), rgb(26, 198, 204) 7%, rgb(100, 100, 100) 10% ); } ``` Because the last color stop is 10% and the gradient is vertical, each gradient in the repeated gradient is 10% of the height, fitting 10 horizontal bars. **Note:** Please see [Using CSS gradients](../css_images/using_css_gradients) for more examples. Specifications -------------- | Specification | | --- | | [CSS Images Module Level 3 # repeating-gradients](https://w3c.github.io/csswg-drafts/css-images/#repeating-gradients) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `repeating-linear-gradient` | 26 10 | 12 | 49 16 Before Firefox 36, gradients weren't applied on the pre-multiplied color space, leading to shades of grey unexpectedly appearing when used with transparency. 3.6 ["Since Firefox 42, the prefixed version of gradients can be disabled by setting `layout.css.prefixes.gradients` to `false`.", "Considers `<angle>` to start to the right, instead of the top. I.e. it considered an angle of `0deg` as a direction indicator pointing to the right."] | 10 Internet Explorer 5.5 through 9.0 supported gradients via a proprietary filter: `[-ms-filter: progid:DXImageTransform.Microsoft.Gradient()](https://developer.mozilla.org/docs/Web/CSS/-ms-filter#Gradient)`. | 15 Considers `<angle>` to start to the right, instead of the top. I.e. it considered an angle of `0deg` as a direction indicator pointing to the right. 12.1 11-15 Considers `<angle>` to start to the right, instead of the top. I.e. it considered an angle of `0deg` as a direction indicator pointing to the right. | 7 5.1 ["Safari 4 was supporting an experimental `[-webkit-gradient(linear,…)](https://developer.apple.com/library/archive/documentation/InternetWeb/Conceptual/SafariVisualEffectsProgGuide/Gradients/Gradient.html)` function. It is more limited than the later standard version: you cannot specify both a position and an angle like in `repeating-linear-gradient()`. This old outdated syntax is still supported for compatibility purposes.", "Considers `<angle>` to start to the right, instead of the top. I.e. it considered an angle of `0deg` as a direction indicator pointing to the right."] | ≤37 ≤37 | 26 18 | 49 16 Before Firefox 36, gradients weren't applied on the pre-multiplied color space, leading to shades of grey unexpectedly appearing when used with transparency. 4 ["Since Firefox 42, the prefixed version of gradients can be disabled by setting `layout.css.prefixes.gradients` to `false`.", "Considers `<angle>` to start to the right, instead of the top. I.e. it considered an angle of `0deg` as a direction indicator pointing to the right."] | 14 Considers `<angle>` to start to the right, instead of the top. I.e. it considered an angle of `0deg` as a direction indicator pointing to the right. 12.1 11-14 Considers `<angle>` to start to the right, instead of the top. I.e. it considered an angle of `0deg` as a direction indicator pointing to the right. | 7 5 ["Safari 4 was supporting an experimental `[-webkit-gradient(linear,…)](https://developer.apple.com/library/archive/documentation/InternetWeb/Conceptual/SafariVisualEffectsProgGuide/Gradients/Gradient.html)` function. It is more limited than the later standard version: you cannot specify both a position and an angle like in `repeating-linear-gradient()`. This old outdated syntax is still supported for compatibility purposes.", "Considers `<angle>` to start to the right, instead of the top. I.e. it considered an angle of `0deg` as a direction indicator pointing to the right."] | 1.5 1.0 | | `doubleposition` | 71 | 79 | 64 | No | 58 | 12.1 | 71 | 71 | 64 | 50 | 12.2 | 10.0 | | `interpolation_hints` | 40 | 79 | 36 | No | 27 | 7 | 40 | 40 | 36 | 27 | 7 | 4.0 | | `to` | 26 | 12 | 10 | 10 | 12.1 | 7 | 4.4 | 26 | 10 | 14 | 7 | 1.5 | | `unitless_0_angle` | 26 | 12 | 55 46 Accepted only in `-webkit-repeating-linear-gradient()` and `-moz-repeating-linear-gradient()`, not `repeating-linear-gradient()`. | No | 16 | 7 | 4.4 | 26 | 55 46 Accepted only in `-webkit-repeating-linear-gradient()` and `-moz-repeating-linear-gradient()`, not `repeating-linear-gradient()`. | 14 | 7 | 1.5 | See also -------- * [Using CSS gradients](../css_images/using_css_gradients) * Other gradient functions: [`linear-gradient()`](linear-gradient), [`radial-gradient()`](radial-gradient), [`repeating-radial-gradient()`](repeating-radial-gradient), [`conic-gradient()`](conic-gradient), [`repeating-conic-gradient()`](repeating-conic-gradient) * [`<image>`](../image) * [`image()`](../image/image) * [`element()`](../element()) * [`image-set()`](../image/image-set) * [`cross-fade()`](../cross-fade) css radial-gradient() radial-gradient() ================= The `radial-gradient()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](../css_functions) creates an image consisting of a progressive transition between two or more colors that radiate from an origin. Its shape may be a circle or an ellipse. The function's result is an object of the [`<gradient>`](../gradient) data type, which is a special kind of [`<image>`](../image). Try it ------ Syntax ------ ``` /\* A gradient at the center of its container, starting red, changing to blue, and finishing green \*/ radial-gradient(circle at center, red 0, blue, green 100%) ``` A radial gradient is specified by indicating the center of the gradient (where the 0% ellipse will be) and the size and shape of the *ending shape* (the 100% ellipse). ### Values [`<position>`](../position_value) The position of the gradient, interpreted in the same way as [`background-position`](../background-position) or [`transform-origin`](../transform-origin). If unspecified, it defaults to `center`. `<ending-shape>` The gradient's ending-shape. The value can be `circle` (meaning that the gradient's shape is a circle with a constant radius) or `ellipse` (meaning that the shape is an axis-aligned ellipse). If unspecified, it defaults to `ellipse`. `<size>` Determines the size of the gradient's ending shape. If omitted it defaults to farthest-corner. It can be given explicitly or by keyword. For the purpose of the keyword definitions, consider the gradient box edges as extending infinitely in both directions, rather than being finite line segments. Both circle and ellipse gradients accept the following keywords for their `<size>`: | Keyword | Description | | --- | --- | | `closest-side` | The gradient's ending shape meets the side of the box closest to its center (for circles) or meets both the vertical and horizontal sides closest to the center (for ellipses). | | `closest-corner` | The gradient's ending shape is sized so that it exactly meets the closest corner of the box from its center. | | `farthest-side` | Similar to `closest-side`, except the ending shape is sized to meet the side of the box farthest from its center (or vertical and horizontal sides). | | `farthest-corner` | The default value, the gradient's ending shape is sized so that it exactly meets the farthest corner of the box from its center. | If `<ending-shape>` is specified as `circle`, the size may be given explicitly as a [`<length>`](../length), which provides an explicit circle radius. Negative values are invalid. If `<ending-shape>` is specified as `ellipse` or is omitted, the size may be given as a [`<length-percentage>`](../length-percentage) with two values to provide an explicit ellipse size. The first value represents the horizontal radius, the second the vertical radius. Percentages values are relative to the corresponding dimension of the gradient box. Negative values are invalid. `<linear-color-stop>` A color-stop's [`<color>`](../color_value) value, followed by an one or two optional stop positions (either a [`<percentage>`](../percentage) or a [`<length>`](../length) along the gradient's axis). A percentage of `0%`, or a length of `0`, represents the center of the gradient; the value `100%` represents the intersection of the ending shape with the virtual gradient ray. Percentage values in between are linearly positioned on the gradient ray. Including two stop positions is equivalent to declaring two color stops with the same color at the two positions. `<color-hint>` The color-hint is an interpolation hint defining how the gradient progresses between adjacent color stops. The length defines at which point between two color stops the gradient color should reach the midpoint of the color transition. If omitted, the midpoint of the color transition is the midpoint between two color stops. Description ----------- As with any gradient, a radial gradient has [no intrinsic dimensions](../image#description); i.e., it has no natural or preferred size, nor a preferred ratio. Its concrete size will match the size of the element it applies to. To create a radial gradient that repeats so as to fill its container, use the [`repeating-radial-gradient()`](repeating-radial-gradient) function instead. Because `<gradient>`s belong to the `<image>` data type, they can only be used where `<image>`s can be used. For this reason, `radial-gradient()` won't work on [`background-color`](../background-color) and other properties that use the [`<color>`](../color_value) data type. ### Composition of a radial gradient A radial gradient is defined by a *center point*, an *ending shape*, and two or more *color-stop points*. To create a smooth gradient, the `radial-gradient()` function draws a series of concentric shapes radiating out from the center to the *ending shape* (and potentially beyond). The ending shape may be either a circle or an ellipse. Color-stop points are positioned on a *virtual gradient ray* that extends horizontally from the center towards the right. Percentage-based color-stop positions are relative to the intersection between the ending shape and this gradient ray, which represents `100%`. Each shape is a single color determined by the color on the gradient ray it intersects. Formal syntax ------------- ``` <radial-gradient()> = radial-gradient( [[](../value_definition_syntax#brackets) [<ending-shape>](../ending-shape) [||](../value_definition_syntax#double_bar) <size> []](../value_definition_syntax#brackets)[?](../value_definition_syntax#question_mark) [[](../value_definition_syntax#brackets) at <position> []](../value_definition_syntax#brackets)[?](../value_definition_syntax#question_mark) , <color-stop-list> ) <size> = <extent-keyword> [|](../value_definition_syntax#single_bar) [<length [0,∞]>](../length) [|](../value_definition_syntax#single_bar) [<length-percentage [0,∞]>](../length-percentage)[{2}](../value_definition_syntax#curly_braces) <position> = [[](../value_definition_syntax#brackets) left [|](../value_definition_syntax#single_bar) center [|](../value_definition_syntax#single_bar) right []](../value_definition_syntax#brackets) [||](../value_definition_syntax#double_bar) [[](../value_definition_syntax#brackets) top [|](../value_definition_syntax#single_bar) center [|](../value_definition_syntax#single_bar) bottom []](../value_definition_syntax#brackets) [|](../value_definition_syntax#single_bar) [[](../value_definition_syntax#brackets) left [|](../value_definition_syntax#single_bar) center [|](../value_definition_syntax#single_bar) right [|](../value_definition_syntax#single_bar) <length-percentage> []](../value_definition_syntax#brackets) [[](../value_definition_syntax#brackets) top [|](../value_definition_syntax#single_bar) center [|](../value_definition_syntax#single_bar) bottom [|](../value_definition_syntax#single_bar) <length-percentage> []](../value_definition_syntax#brackets)[?](../value_definition_syntax#question_mark) [|](../value_definition_syntax#single_bar) [[](../value_definition_syntax#brackets) [[](../value_definition_syntax#brackets) left [|](../value_definition_syntax#single_bar) right []](../value_definition_syntax#brackets) <length-percentage> []](../value_definition_syntax#brackets) [&&](../value_definition_syntax#double_ampersand) [[](../value_definition_syntax#brackets) [[](../value_definition_syntax#brackets) top [|](../value_definition_syntax#single_bar) bottom []](../value_definition_syntax#brackets) <length-percentage> []](../value_definition_syntax#brackets) <color-stop-list> = <linear-color-stop> , [[](../value_definition_syntax#brackets) <linear-color-hint>[?](../value_definition_syntax#question_mark) , <linear-color-stop> []](../value_definition_syntax#brackets)[#](../value_definition_syntax#hash_mark) <extent-keyword> = closest-corner [|](../value_definition_syntax#single_bar) closest-side [|](../value_definition_syntax#single_bar) farthest-corner [|](../value_definition_syntax#single_bar) farthest-side <length-percentage> = [<length>](../length) [|](../value_definition_syntax#single_bar) [<percentage>](../percentage) <linear-color-stop> = [<color>](../color_value) [&&](../value_definition_syntax#double_ampersand) <length-percentage>[?](../value_definition_syntax#question_mark) <linear-color-hint> = <length-percentage> ``` Examples -------- ### Simple gradient ``` .radial-gradient { background-image: radial-gradient(cyan 0%, transparent 20%, salmon 40%); } ``` ### Non-centered gradient ``` .radial-gradient { background-image: radial-gradient( farthest-corner at 40px 40px, #f35 0%, #43e 100% ); } ``` ### More radial-gradient examples Please see [Using CSS gradients](../css_images/using_css_gradients) for more examples. Specifications -------------- | Specification | | --- | | [CSS Images Module Level 3 # radial-gradients](https://w3c.github.io/csswg-drafts/css-images/#radial-gradients) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `radial-gradient` | 26 13 | 12 | 49 16 Before Firefox 36, gradients weren't applied on the pre-multiplied color space, leading to shades of grey unexpectedly appearing when used with transparency. 3.6 Since Firefox 42, the prefixed version of gradients can be disabled by setting `layout.css.prefixes.gradients` to `false`. | 10 Internet Explorer 5.5 through 9.0 supported gradients via a proprietary filter: `[-ms-filter: progid:DXImageTransform.Microsoft.Gradient()](https://developer.mozilla.org/docs/Web/CSS/-ms-filter#Gradient)`. | 15 12.1 11.6-15 | 7 5.1 Safari 4 was supporting an experimental `[-webkit-gradient(radial,…)](https://developer.apple.com/library/archive/documentation/InternetWeb/Conceptual/SafariVisualEffectsProgGuide/Gradients/Gradient.html)` function. This old outdated syntax is still supported for compatibility purposes. | ≤37 ≤37 | 26 18 | 49 16 Before Firefox 36, gradients weren't applied on the pre-multiplied color space, leading to shades of grey unexpectedly appearing when used with transparency. 4 Since Firefox 42, the prefixed version of gradients can be disabled by setting `layout.css.prefixes.gradients` to `false`. | 14 12.1 12-14 | 7 5 Safari 4 was supporting an experimental `[-webkit-gradient(radial,…)](https://developer.apple.com/library/archive/documentation/InternetWeb/Conceptual/SafariVisualEffectsProgGuide/Gradients/Gradient.html)` function. This old outdated syntax is still supported for compatibility purposes. | 1.5 1.0 | | `at` | 26 | 12 | 49 16 Before Firefox 36, gradients weren't applied on the pre-multiplied color space, leading to shades of grey unexpectedly appearing when used with transparency. 10 Since Firefox 42, the prefixed version of gradients can be disabled by setting `layout.css.prefixes.gradients` to `false`. | 10 | 15 11.6-15 | No | 4.4 | 26 | 16 10 | 14 12-14 | No | 1.5 | | `doubleposition` | 71 | 79 | 64 | No | 58 | 12.1 | 71 | 71 | 64 | 50 | 12.2 | 10.0 | | `interpolation_hints` | 40 | 79 | 36 | No | 27 | 7 | 40 | 40 | 36 | 27 | 7 | 4.0 | See also -------- * [Using CSS gradients](../css_images/using_css_gradients) * Other gradient functions: [`repeating-radial-gradient()`](repeating-radial-gradient), [`linear-gradient()`](linear-gradient), [`repeating-linear-gradient()`](repeating-linear-gradient), [`conic-gradient()`](conic-gradient), [`repeating-conic-gradient()`](repeating-conic-gradient) * [`<image>`](../image) * [`image()`](../image/image) * [`element()`](../element()) * [`image-set()`](../image/image-set) * [`cross-fade()`](../cross-fade)
programming_docs
css linear-gradient() linear-gradient() ================= The `linear-gradient()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](../css_functions) creates an image consisting of a progressive transition between two or more colors along a straight line. Its result is an object of the [`<gradient>`](../gradient) data type, which is a special kind of [`<image>`](../image). Try it ------ Syntax ------ ``` /\* A gradient tilted 45 degrees, starting blue and finishing red \*/ linear-gradient(45deg, blue, red); /\* A gradient going from the bottom right to the top left corner, starting blue and finishing red \*/ linear-gradient(to left top, blue, red); /\* Color stop: A gradient going from the bottom to top, starting blue, turning green at 40% of its length, and finishing red \*/ linear-gradient(0deg, blue, green 40%, red); /\* Color hint: A gradient going from the left to right, starting red, getting to the midpoint color 10% of the way across the length of the gradient, taking the rest of the 90% of the length to change to blue \*/ linear-gradient(.25turn, red, 10%, blue); /\* Multi-position color stop: A gradient tilted 45 degrees, with a red bottom-left half and a blue top-right half, with a hard line where the gradient changes from red to blue \*/ linear-gradient(45deg, red 0 50%, blue 50% 100%); ``` ### Values `<side-or-corner>` The position of the gradient line's starting point. If specified, it consists of the word `to` and up to two keywords: one indicates the horizontal side (`left` or `right`), and the other the vertical side (`top` or `bottom`). The order of the side keywords does not matter. If unspecified, it defaults to `to bottom`. The values `to top`, `to bottom`, `to left`, and `to right` are equivalent to the angles `0deg`, `180deg`, `270deg`, and `90deg`, respectively. The other values are translated into an angle. [`<angle>`](../angle) The gradient line's angle of direction. A value of `0deg` is equivalent to `to top`; increasing values rotate clockwise from there. `<linear-color-stop>` A color-stop's [`<color>`](../color_value) value, followed by one or two optional stop positions, (each being either a [`<percentage>`](../percentage) or a [`<length>`](../length) along the gradient's axis). `<color-hint>` An interpolation hint defining how the gradient progresses between adjacent color stops. The length defines at which point between two color stops the gradient color should reach the midpoint of the color transition. If omitted, the midpoint of the color transition is the midpoint between two color stops. **Note:** Rendering of [color stops in CSS gradients](#composition_of_a_linear_gradient) follows the same rules as color stops in [SVG gradients](https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Gradients). Note also that the first example above does not exactly render as depicted in Mozilla Firefox (particularly version 80.0b3). You'll have to set the html height property to 100% or 100vh to render as depicted. Description ----------- As with any gradient, a linear gradient has [no intrinsic dimensions](../image#description); i.e., it has no natural or preferred size, nor a preferred ratio. Its concrete size will match the size of the element it applies to. To create a linear gradient that repeats so as to fill its container, use the [`repeating-linear-gradient()`](repeating-linear-gradient) function instead. Because `<gradient>`s belong to the `<image>` data type, they can only be used where `<image>`s can be used. For this reason, `linear-gradient()` won't work on [`background-color`](../background-color) and other properties that use the [`<color>`](../color_value) data type. ### Composition of a linear gradient A linear gradient is defined by an axis—the *gradient line*—and two or more *color-stop points*. Each point on the axis is a distinct color; to create a smooth gradient, the `linear-gradient()` function draws a series of colored lines perpendicular to the gradient line, each one matching the color of the point where it intersects the gradient line. The gradient line is defined by the center of the box containing the gradient image and by an angle. The colors of the gradient are determined by two or more points: the starting point, the ending point, and, in between, optional color-stop points. The *starting point* is the location on the gradient line where the first color begins. The *ending point* is the point where the last color ends. Each of these two points is defined by the intersection of the gradient line with a perpendicular line passing from the box corner which is in the same quadrant. The ending point can be understood as the symmetrical point of the starting point. These somewhat complex definitions lead to an interesting effect sometimes called *magic corners*: the corners nearest to the starting and ending points have the same color as their respective starting or ending points. #### Customizing Gradients By adding more color-stop points on the gradient line, you can create a highly customized transition between multiple colors. A color-stop's position can be explicitly defined by using a [`<length>`](../length) or a [`<percentage>`](../percentage). If you don't specify the location of a color, it is placed halfway between the one that precedes it and the one that follows it. The following two gradients are equivalent. ``` linear-gradient(red, orange, yellow, green, blue); linear-gradient(red 0%, orange 25%, yellow 50%, green 75%, blue 100%); ``` By default, colors transition smoothly from the color at one color stop to the color at the subsequent color stop, with the midpoint between the colors being the half way point between the color transition. You can move this midpoint to any position between two color stops by adding an unlabelled % color hint between the two colors to indicate where the middle of the color transition should be. The following example is solid red from the start to the 10% mark and solid blue from 90% to the end. Between 10% and 90% the color transitions from red to blue, however the midpoint of the transition is at the 30% mark rather than 50% as would have happened without the 30% color hint. ``` linear-gradient(red 10%, 30%, blue 90%); ``` If two or more color stops are at the same location, the transition will be a hard line between the first and last colors declared at that location. Color stops should be listed in ascending order. Subsequent color stops of lower value will override the value of the previous color stop creating a hard transition. The following changes from red to yellow at the 40% mark, and then transitions from yellow to blue over 25% of the gradient ``` linear-gradient(red 40%, yellow 30%, blue 65%); ``` Multi-position color stop are allowed. A color can be declared as two adjacent color stops by including both positions in the CSS declaration. The following three gradients are equivalent: ``` linear-gradient(red 0%, orange 10%, orange 30%, yellow 50%, yellow 70%, green 90%, green 100%); linear-gradient(red, orange 10% 30%, yellow 50% 70%, green 90%); linear-gradient(red 0%, orange 10% 30%, yellow 50% 70%, green 90% 100%); ``` By default, if there is no color with a 0% stop, the first color declared will be at that point. Similarly, the last color will continue to the 100% mark, or be at the 100% mark if no length has been declared on that last stop. Formal syntax ------------- ``` <linear-gradient()> = linear-gradient( [[](../value_definition_syntax#brackets) [<angle>](../angle) [|](../value_definition_syntax#single_bar) to <side-or-corner> []](../value_definition_syntax#brackets)[?](../value_definition_syntax#question_mark) , <color-stop-list> ) <side-or-corner> = [[](../value_definition_syntax#brackets) left [|](../value_definition_syntax#single_bar) right []](../value_definition_syntax#brackets) [||](../value_definition_syntax#double_bar) [[](../value_definition_syntax#brackets) top [|](../value_definition_syntax#single_bar) bottom []](../value_definition_syntax#brackets) <color-stop-list> = <linear-color-stop> , [[](../value_definition_syntax#brackets) <linear-color-hint>[?](../value_definition_syntax#question_mark) , <linear-color-stop> []](../value_definition_syntax#brackets)[#](../value_definition_syntax#hash_mark) <linear-color-stop> = [<color>](../color_value) [&&](../value_definition_syntax#double_ampersand) <length-percentage>[?](../value_definition_syntax#question_mark) <linear-color-hint> = <length-percentage> <length-percentage> = [<length>](../length) [|](../value_definition_syntax#single_bar) [<percentage>](../percentage) ``` Examples -------- ### Gradient at a 45-degree angle ``` body { background: linear-gradient(45deg, red, blue); } ``` ### Gradient that starts at 60% of the gradient line ``` body { background: linear-gradient(135deg, orange 60%, cyan); } ``` ### Gradient with multi-position color stops This example uses multi-position color stops, with adjacent colors having the same color stop value, creating a striped effect. ``` body { background: linear-gradient( to right, red 20%, orange 20% 40%, yellow 40% 60%, green 60% 80%, blue 80% ); } ``` ### More linear-gradient examples Please see [Using CSS gradients](../css_images/using_css_gradients) for more examples. Specifications -------------- | Specification | | --- | | [CSS Images Module Level 3 # linear-gradients](https://w3c.github.io/csswg-drafts/css-images/#linear-gradients) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `linear-gradient` | 26 10 | 12 | 49 16 Before Firefox 36, gradients weren't applied on the pre-multiplied color space, leading to shades of grey unexpectedly appearing when used with transparency. 3.6 ["Since Firefox 42, the prefixed version of gradients can be disabled by setting `layout.css.prefixes.gradients` to `false`.", "Considers `<angle>` to start to the right, instead of the top. I.e. it considered an angle of `0deg` as a direction indicator pointing to the right."] | 10 Internet Explorer 5.5 through 9.0 supported gradients via a proprietary filter: `[-ms-filter: progid:DXImageTransform.Microsoft.Gradient()](https://developer.mozilla.org/docs/Web/CSS/-ms-filter#Gradient)`. | 15 Considers `<angle>` to start to the right, instead of the top. I.e. it considered an angle of `0deg` as a direction indicator pointing to the right. 12.1 11-15 Considers `<angle>` to start to the right, instead of the top. I.e. it considered an angle of `0deg` as a direction indicator pointing to the right. | 7 5.1 ["Safari 4 was supporting an experimental `[-webkit-gradient(linear,…)](https://developer.apple.com/library/archive/documentation/InternetWeb/Conceptual/SafariVisualEffectsProgGuide/Gradients/Gradient.html)` function. It is more limited than the later standard version: you cannot specify both a position and an angle like in `linear-gradient()`. This old outdated syntax is still supported for compatibility purposes.", "Considers `<angle>` to start to the right, instead of the top. I.e. it considered an angle of `0deg` as a direction indicator pointing to the right."] | ≤37 ≤37 | 26 18 | 49 16 Before Firefox 36, gradients weren't applied on the pre-multiplied color space, leading to shades of grey unexpectedly appearing when used with transparency. 4 ["Since Firefox 42, the prefixed version of gradients can be disabled by setting `layout.css.prefixes.gradients` to `false`.", "Considers `<angle>` to start to the right, instead of the top. I.e. it considered an angle of `0deg` as a direction indicator pointing to the right."] | 14 Considers `<angle>` to start to the right, instead of the top. I.e. it considered an angle of `0deg` as a direction indicator pointing to the right. 12.1 11-14 Considers `<angle>` to start to the right, instead of the top. I.e. it considered an angle of `0deg` as a direction indicator pointing to the right. | 7 5 ["Safari 4 was supporting an experimental `[-webkit-gradient(linear,…)](https://developer.apple.com/library/archive/documentation/InternetWeb/Conceptual/SafariVisualEffectsProgGuide/Gradients/Gradient.html)` function. It is more limited than the later standard version: you cannot specify both a position and an angle like in `linear-gradient()`. This old outdated syntax is still supported for compatibility purposes.", "Considers `<angle>` to start to the right, instead of the top. I.e. it considered an angle of `0deg` as a direction indicator pointing to the right."] | 1.5 1.0 | | `doubleposition` | 71 | 79 | 64 | No | 58 | 12.1 | 71 | 71 | 64 | 50 | 12.2 | 10.0 | | `interpolation_hints` | 40 | 79 | 36 | No | 27 | 7 | 40 | 40 | 36 | 27 | 7 | 4.0 | | `to` | 26 | 12 | 10 | 10 | 12.1 | 7 | 4.4 | 26 | 10 | 14 | 7 | 1.5 | | `unitless_0_angle` | 26 | 12 | 55 46 Accepted only in `-webkit-linear-gradient()` and `-moz-linear-gradient()`, not `linear-gradient()`. | No | 16 | 7 | 4.4 | 26 | 55 46 Accepted only in `-webkit-linear-gradient()` and `-moz-linear-gradient()`, not `linear-gradient()`. | 14 | 7 | 1.5 | See also -------- * [Using CSS gradients](../css_images/using_css_gradients) * Other gradient functions: [`repeating-linear-gradient()`](repeating-linear-gradient), [`radial-gradient()`](radial-gradient), [`repeating-radial-gradient()`](repeating-radial-gradient), [`conic-gradient()`](conic-gradient), [`repeating-conic-gradient()`](repeating-conic-gradient) * [`<image>`](../image) * [`element()`](../element()) * [`image()`](../image/image) * [`image-set()`](../image/image-set) * [`cross-fade()`](../cross-fade) css conic-gradient() conic-gradient() ================ The `conic-gradient()` [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) [function](../css_functions) creates an image consisting of a gradient with color transitions rotated around a center point (rather than radiating from the center). Example conic gradients include pie charts and [color wheels](https://developer.mozilla.org/en-US/docs/Glossary/Color_wheel). The result of the `conic-gradient()` function is an object of the [`<gradient>`](../gradient) data type, which is a special kind of [`<image>`](../image). Try it ------ Syntax ------ ``` /\* A conic gradient rotated 45 degrees, starting blue and finishing red \*/ conic-gradient(from 45deg, blue, red); /\* A bluish purple box: the gradient goes from blue to red, but only the bottom right quadrant is visible, as the center of the conic gradient is at the top left corner \*/ conic-gradient(from 90deg at 0 0, blue, red); /\* Color wheel \*/ background: conic-gradient( hsl(360, 100%, 50%), hsl(315, 100%, 50%), hsl(270, 100%, 50%), hsl(225, 100%, 50%), hsl(180, 100%, 50%), hsl(135, 100%, 50%), hsl(90, 100%, 50%), hsl(45, 100%, 50%), hsl(0, 100%, 50%) ); ``` ### Values [`<angle>`](../angle) Preceded by the `from` keyterm, and taking an angle as its value, defines the gradient rotation in clockwise direction. `<position>` Using the same length, order and keyterm values as the [background-position](../background-position) property, the position defines center of the gradient. If omitted, the default value is `center`, meaning the gradient will be centered, . `<angular-color-stop>` A color-stop's [`<color>`](../color_value) value, followed by one or two optional stop positions, (an [`<angle>`](../angle) along the gradient's circumference axis). `<color-hint>` An [interpolation](https://developer.mozilla.org/en-US/docs/Glossary/Interpolation) hint defining how the gradient progresses between adjacent color stops. The length defines at which point between two color stops the gradient color should reach the midpoint of the color transition. If omitted, the midpoint of the color transition is the midpoint between two color stops. **Note:** Rendering of [color stops in CSS gradients](#gradient_with_multiple_color_stops) follows the same rules as color stops in [SVG gradients](https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Gradients). Description ----------- As with any gradient, a conic gradient has [no intrinsic dimensions](../image#description); i.e., it has no natural or preferred size, nor a preferred ratio. Its concrete size will match the size of the element it applies to, or the size of the `<image>` if it is set to something other than the element size. To create a conic gradient that repeats so as to fill a 360 degree rotation, use the [`repeating-conic-gradient()`](repeating-conic-gradient) function instead. Because `<gradient>`s belong to the `<image>` data type, they can only be used where `<image>`s can be used. For this reason, `conic-gradient()` won't work on [`background-color`](../background-color) and other properties that use the [`<color>`](../color_value) data type. **Note:** Why is it called a "conic" gradient? If the color stops are much lighter on one side than the other, it can look like a cone from above. ### Composition of a conic gradient The conic-gradient syntax is similar to the radial-gradient syntax, but the color-stops are placed around a gradient arc, the circumference of a circle, rather than on the gradient line emerging from the center of the gradient. With conic gradients, the colors transition as if spun around the center of a circle, starting at the top and going clockwise. In a radial gradient, the colors transition from the center of an ellipse, outward, in all directions. A conic gradient is specified by indicating a rotation angle, the center of the gradient, and then specifying a list of color-stops. Unlike linear and radial gradients, whose color-stops are placed by specifying a [length](../length), the color-stops of a conic gradient are specified with an [angle](../angle). Units include `deg` for degrees, `grad` for gradients, `rad` for radians, and `turn` for turns. There are 360 degrees, 400 gradians, 2π radians, and 1 turn in a circle. Browsers supporting conic gradients also accept percent values, with 100% equaling 360 degrees, but this is not in the specification. Similar to radial gradients, the conic gradient syntax provides for positioning the center of the gradient anywhere within, or even outside, the image. The values for the position are similar to the syntax for 2-value background-position. The gradient arc is the circumference of the gradient. The *starting point* of the gradient or arc is north, or 12:00pm. The gradient is then rotated by the *from* angle. The colors of the gradient are determined by the angled color stops, their starting points, ending points, and, in between, and optional angled color-stop points. The transitions between colors can be altered with color hints between adjacent colors' color stops. #### Customizing gradients By adding more angled color-stop points on the gradient arc, you can create a highly customized transition between multiple colors. A color-stop's position can be explicitly defined by using an [`<angle>`](../angle). If you don't specify the location of a color stop, it is placed halfway between the one that precedes it and the one that follows it. If you don't specify an angle for the first or last color stop, their values are 0deg and 360deg respectively. The following two gradients are equivalent ``` conic-gradient(red, orange, yellow, green, blue); conic-gradient(red 0deg, orange 90deg, yellow 180deg, green 270deg, blue 360deg); ``` By default, colors transition smoothly from the color at one color stop to the color at the subsequent color stop, with the midpoint between the colors being the half way point between the color transition. You can move this color transition midpoint to any point between two color stops by adding a color hint, indicating where the middle of the color transition should be. The following is solid red from the start to the 10% mark, transitions from red to blue over 80% of the turn, with the final 10% being solid blue. The midpoint of the red to blue gradient change, however, is at the 20% mark rather than the 50% mark as would have happened without the 80grad, or 20%, color hint. ``` conic-gradient(red 40grad, 80grad, blue 360grad); ``` If two or more color stops are at the same location, the transition will be a hard line between the first and last colors declared at that location. To use conic gradients to create pie charts — which is NOT the correct way to create pie charts as background images are not accessible — use hard color stops, where the color stop angles for two adjacent color stops are the same. The easiest way to do this is to use multiple position colors stops. The following two declarations are equivalent: ``` conic-gradient(#fff 0.09turn, #bbb 0.09turn, #bbb 0.27turn, #666 0.27turn, #666 0.54turn, #000 0.54turn); conic-gradient(#fff 0turn 0.09turn, #bbb 0.09turn 0.27turn, #666 0.27turn 0.54turn, #000 0.54turn 1turn); ``` Color stops should be listed in ascending order. Subsequent color stops of lower value will override the value of the previous color stop creating a hard transition. The following changes from red to yellow at the 30% mark, and then transitions from yellow to blue over 35% of the gradient ``` conic-gradient(red .8rad, yellow .6rad, blue 1.3rad); ``` There are other effects you can create with conic gradients. Oddly, a checkerboard is one of them. By creating quadrants with an upper left and lower right white quadrant and lower left and upper right black quadrants, then repeating the gradient 16 times (four times across and four times down) you can make a checkerboard. ``` conic-gradient(#fff 90deg, #000 0.25turn 0.5turn, #fff 1rad 1.5rad, #000 300grad); background-size: 25% 25%; ``` And, yes, you can mix and match different angle units, but don't. The above is hard to read. Formal syntax ------------- ``` <conic-gradient()> = conic-gradient( [[](../value_definition_syntax#brackets) [[](../value_definition_syntax#brackets) from [<angle>](../angle) []](../value_definition_syntax#brackets)[?](../value_definition_syntax#question_mark) [[](../value_definition_syntax#brackets) at <position> []](../value_definition_syntax#brackets)[?](../value_definition_syntax#question_mark) []](../value_definition_syntax#brackets) [||](../value_definition_syntax#double_bar) <color-interpolation-method> , <angular-color-stop-list> ) <position> = [[](../value_definition_syntax#brackets) left [|](../value_definition_syntax#single_bar) center [|](../value_definition_syntax#single_bar) right []](../value_definition_syntax#brackets) [||](../value_definition_syntax#double_bar) [[](../value_definition_syntax#brackets) top [|](../value_definition_syntax#single_bar) center [|](../value_definition_syntax#single_bar) bottom []](../value_definition_syntax#brackets) [|](../value_definition_syntax#single_bar) [[](../value_definition_syntax#brackets) left [|](../value_definition_syntax#single_bar) center [|](../value_definition_syntax#single_bar) right [|](../value_definition_syntax#single_bar) <length-percentage> []](../value_definition_syntax#brackets) [[](../value_definition_syntax#brackets) top [|](../value_definition_syntax#single_bar) center [|](../value_definition_syntax#single_bar) bottom [|](../value_definition_syntax#single_bar) <length-percentage> []](../value_definition_syntax#brackets)[?](../value_definition_syntax#question_mark) [|](../value_definition_syntax#single_bar) [[](../value_definition_syntax#brackets) [[](../value_definition_syntax#brackets) left [|](../value_definition_syntax#single_bar) right []](../value_definition_syntax#brackets) <length-percentage> []](../value_definition_syntax#brackets) [&&](../value_definition_syntax#double_ampersand) [[](../value_definition_syntax#brackets) [[](../value_definition_syntax#brackets) top [|](../value_definition_syntax#single_bar) bottom []](../value_definition_syntax#brackets) <length-percentage> []](../value_definition_syntax#brackets) <color-interpolation-method> = in [[](../value_definition_syntax#brackets) <rectangular-color-space> [|](../value_definition_syntax#single_bar) <polar-color-space> <hue-interpolation-method>[?](../value_definition_syntax#question_mark) []](../value_definition_syntax#brackets) <angular-color-stop-list> = <angular-color-stop> , [[](../value_definition_syntax#brackets) <angular-color-hint>[?](../value_definition_syntax#question_mark) , <angular-color-stop> []](../value_definition_syntax#brackets)[#](../value_definition_syntax#hash_mark) <length-percentage> = [<length>](../length) [|](../value_definition_syntax#single_bar) [<percentage>](../percentage) <rectangular-color-space> = srgb [|](../value_definition_syntax#single_bar) srgb-linear [|](../value_definition_syntax#single_bar) lab [|](../value_definition_syntax#single_bar) oklab [|](../value_definition_syntax#single_bar) xyz [|](../value_definition_syntax#single_bar) xyz-d50 [|](../value_definition_syntax#single_bar) xyz-d65 <polar-color-space> = hsl [|](../value_definition_syntax#single_bar) hwb [|](../value_definition_syntax#single_bar) lch [|](../value_definition_syntax#single_bar) oklch <hue-interpolation-method> = [[](../value_definition_syntax#brackets) shorter [|](../value_definition_syntax#single_bar) longer [|](../value_definition_syntax#single_bar) increasing [|](../value_definition_syntax#single_bar) decreasing []](../value_definition_syntax#brackets) hue <angular-color-stop> = [<color>](../color_value) [&&](../value_definition_syntax#double_ampersand) <color-stop-angle>[?](../value_definition_syntax#question_mark) <angular-color-hint> = <angle-percentage> <color-stop-angle> = <angle-percentage>[{1,2}](../value_definition_syntax#curly_braces) <angle-percentage> = [<angle>](../angle) [|](../value_definition_syntax#single_bar) [<percentage>](../percentage) ``` Accessibility concerns ---------------------- Browsers do not provide any special information on background images to assistive technology. This is important primarily for screen readers, as a screen reader will not announce its presence and therefore convey nothing to its users. While it is possible to create pie charts, checkerboards, and other effects with conic gradients, CSS images provide no native way to assign alternative text, and therefore the image represented by the conic gradient will not be accessible to screen reader users. If the image contains information critical to understanding the page's overall purpose, it is better to describe it semantically in the document. * [MDN Understanding WCAG, Guideline 1.1 explanations](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.1_%e2%80%94_providing_text_alternatives_for_non-text_content) * [Understanding Success Criterion 1.1.1 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/2016/NOTE-UNDERSTANDING-WCAG20-20161007/text-equiv-all.html) Examples -------- ### Gradient at 40-degrees ``` div { background-image: conic-gradient(from 40deg, #fff, #000); } ``` ### Off-centered gradient ``` div { background: conic-gradient(from 0deg at 0% 25%, blue, green, yellow 180deg); } ``` ### Gradient pie-chart This example uses multi-position color stops, with adjacent colors having the same color stop value, creating a striped effect. ``` div { background: conic-gradient(red 36deg, orange 36deg 170deg, yellow 170deg); border-radius: 50%; } ``` ### Checkerboard ``` div { background: conic-gradient( #fff 0.25turn, #000 0.25turn 0.5turn, #fff 0.5turn 0.75turn, #000 0.75turn ) top left / 25% 25% repeat; border: 1px solid; } ``` ### More conic-gradient examples Please see [Using CSS gradients](../css_images/using_css_gradients) for more examples. Specifications -------------- | Specification | | --- | | [CSS Image Values and Replaced Content Module Level 4 # conic-gradients](https://w3c.github.io/csswg-drafts/css-images-4/#conic-gradients) | Browser compatibility --------------------- | | Desktop | Mobile | | --- | --- | --- | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | | `conic-gradient` | 69 | 79 | 83 | No | 56 | 12.1 | 69 | 69 | 83 | 48 | 12.2 | 10.0 | | `doubleposition` | 72 | 79 | 83 | No | 60 | 12.1 | 72 | 72 | 83 | 51 | 12.2 | 11.0 | See also -------- * [Using CSS gradients](../css_images/using_css_gradients) * Other gradient functions: [`repeating-conic-gradient()`](repeating-conic-gradient), [`linear-gradient()`](linear-gradient), [`repeating-linear-gradient()`](repeating-linear-gradient), [`radial-gradient()`](radial-gradient), [`repeating-radial-gradient()`](repeating-radial-gradient) * [`<image>`](../image) * [`image()`](../image/image) * [`element()`](../element()) * [`image-set()`](../image/image-set) * [`cross-fade()`](../cross-fade)
programming_docs
css Logical properties for margins, borders, and padding Logical properties for margins, borders, and padding ==================================================== The [Logical Properties and Values specification](https://drafts.csswg.org/css-logical/) defines flow-relative mappings for the various margin, border, and padding properties and their shorthands. In this guide, we take a look at these. If you have looked at the main page for [CSS Logical Properties and Values](../css_logical_properties) you will see there are a huge number of properties listed. This is mostly because there are four longhand values each for margin, border, and padding side, plus all the shorthand values. Mappings for margins, borders, and padding ------------------------------------------ The specification details mappings for each logical value to a physical counterpart. In the table below I have given these mapped values assuming that the [`writing-mode`](../writing-mode) in use is `horizontal-tb` — with a left to right direction. The inline direction therefore runs horizontally — left to right — and [`margin-inline-start`](../margin-inline-start) would be equivalent to [`margin-left`](../margin-left). If you were using a `horizontal-tb` writing mode with a right-to-left text direction then [`margin-inline-start`](../margin-inline-start) would be the same as [`margin-right`](../margin-right), and in a vertical writing mode it would be the same as using [`margin-top`](../margin-top). | Logical property | Physical Property | | --- | --- | | [`border-block-end`](../border-block-end) | [`border-bottom`](../border-bottom) | | [`border-block-end-color`](../border-block-end-color) | [`border-bottom-color`](../border-bottom-color) | | [`border-block-end-style`](../border-block-end-style) | [`border-bottom-style`](../border-bottom-style) | | [`border-block-end-width`](../border-block-end-width) | [`border-bottom-width`](../border-bottom-width) | | [`border-block-start`](../border-block-start) | [`border-top`](../border-top) | | [`border-block-start-color`](../border-block-start-color) | [`border-top-color`](../border-top-color) | | [`border-block-start-style`](../border-block-start-style) | [`border-top-style`](../border-top-style) | | [`border-block-start-width`](../border-block-start-width) | [`border-top-width`](../border-top-width) | | [`border-inline-end`](../border-inline-end) | [`border-right`](../border-right) | | [`border-inline-end-color`](../border-inline-end-color) | [`border-right-color`](../border-right-color) | | [`border-inline-end-style`](../border-inline-end-style) | [`border-right-style`](../border-right-style) | | [`border-inline-end-width`](../border-inline-end-width) | [`border-right-width`](../border-right-width) | | [`border-inline-start`](../border-inline-start) | [`border-left`](../border-left) | | [`border-inline-start-color`](../border-inline-start-color) | [`border-left-color`](../border-left-color) | | [`border-inline-start-style`](../border-inline-start-style) | [`border-left-style`](../border-left-style) | | [`border-inline-start-width`](../border-inline-start-width) | [`border-left-width`](../border-left-width) | | [`border-start-start-radius`](../border-start-start-radius) | [`border-top-left-radius`](../border-top-left-radius) | | [`border-end-start-radius`](../border-end-start-radius) | [`border-bottom-left-radius`](../border-bottom-left-radius) | | [`border-start-end-radius`](../border-start-end-radius) | [`border-top-right-radius`](../border-top-right-radius) | | [`border-end-end-radius`](../border-end-end-radius) | [`border-bottom-right-radius`](../border-bottom-right-radius) | | [`margin-block-end`](../margin-block-end) | [`margin-bottom`](../margin-bottom) | | [`margin-block-start`](../margin-block-start) | [`margin-top`](../margin-top) | | [`margin-inline-end`](../margin-inline-end) | [`margin-right`](../margin-right) | | [`margin-inline-start`](../margin-inline-start) | [`margin-left`](../margin-left) | | [`padding-block-end`](../padding-block-end) | [`padding-bottom`](../padding-bottom) | | [`padding-block-start`](../padding-block-start) | [`padding-top`](../padding-top) | | [`padding-inline-end`](../padding-inline-end) | [`padding-right`](../padding-right) | | [`padding-inline-start`](../padding-inline-start) | [`padding-left`](../padding-left) | There are also some additional shorthands, made possible because we can target both block or both inline edges of the box simultaneously. These shorthands have no physical equivalent. | Property | Purpose | | --- | --- | | [`border-block`](../border-block) | Sets [`border-color`](../border-color), [`border-style`](../border-style), and [`border-width`](../border-width) for both block borders. | | [`border-block-color`](../border-block-color) | Sets `border-color` for both block borders. | | [`border-block-style`](../border-block-style) | Sets `border-style` for both block borders. | | [`border-block-width`](../border-block-width) | Sets `border-width` for both block borders. | | [`border-inline`](../border-inline) | Sets `border-color`, `-style`, and `-width` for both inline borders. | | [`border-inline-color`](../border-inline-color) | Sets `border-color` for both inline borders. | | [`border-inline-style`](../border-inline-style) | Sets `border-style` for both inline borders. | | [`border-inline-width`](../border-inline-width) | Sets `border-width` for both inline borders. | | [`margin-block`](../margin-block) | Sets all the block [`margin`](../margin)s. | | [`margin-inline`](../margin-inline) | Sets all the inline `margin`s. | | [`padding-block`](../padding-block) | Sets the block [`padding`](../padding). | | [`padding-inline`](../padding-inline) | Sets the inline `padding`. | Margin examples --------------- The mapped margin properties of [`margin-inline-start`](../margin-inline-start), [`margin-inline-end`](../margin-inline-end), [`margin-block-start`](../margin-block-start), and [`margin-inline-end`](../margin-inline-end) can be used instead of their physical counterparts. In the example below I have created two boxes and added different sized margins to each edge. I have added an extra container with a border to make the margin more obvious to see. One box uses physical properties and the other logical properties. Try changing the [`direction`](../direction) property to `rtl` to cause the boxes to display in a right-to-left direction, the margins on the first box will stay in the same place, while the margins on the inline dimension of the second box will switch. You can also try changing the `writing-mode` from `horizontal-tb` to `vertical-rl`. Again, notice how the margins stay in the same place for the first box, but switch around to follow the text direction in the second. ### Margin shorthands As we can now target both sides of a box — either both inline sides or both block sides — there are new shorthands available, [`margin-inline`](../margin-inline) and [`margin-block`](../margin-block), which accept two values. The first value will apply to the start of that dimension, the second to the end. If you only use one value it is applied to both. In a horizontal writing mode this CSS would apply a 5px margin to the top of the box and a 10px margin to the bottom. ``` .box { margin-block: 5px 10px; } ``` Padding examples ---------------- The mapped padding properties of [`padding-inline-start`](../padding-inline-start), [`padding-inline-end`](../padding-inline-end), [`padding-block-start`](../padding-block-start), and [`padding-inline-end`](../padding-inline-end) can be used instead of their physical counterparts. In the example below I have two boxes, one of which is using physical padding properties and the other logical padding properties. With a `writing-mode` of `horizontal-tb`, both boxes should appear the same. Try changing the `direction` property to `rtl` to cause the boxes to display in a right-to-left direction. The padding on the first box will stay in the same place, whereas the padding on the inline dimension of the second box will switch. You can also try changing the `writing-mode` from `horizontal-tb` to `vertical-rl`. Again, notice how the padding stays in the same place for the first box, but switches around to follow the text direction in the second. ### Padding shorthands As with margin, there are two-value shorthands for padding — [`padding-inline`](../padding-inline) and [`padding-block`](../padding-block) — which allow you to set the padding of the two inline, and two block dimensions, respectively. In a horizontal `writing-mode` this CSS would apply `5px` of padding to the top of the box and 10px of padding to the bottom: ``` .box { padding-block: 5px 10px; } ``` Border examples --------------- The border properties are the main reason that Logical Properties and Values seems to have so many properties, as we have the longhands for the color, width, and style of the border on each side of a box, along with the shorthand to set all three at once for each side. As with margin and padding we have a mapped version of each physical property. The demo below uses some longhands and three shorthand values. As with the other demos try changing the `direction` property to `rtl` to cause the boxes to display in a right-to-left direction, or changing the `writing-mode` from `horizontal-tb` to `vertical-rl`. ### New border shorthands There are two-value shorthands to set the width, style and, color of the block or inline dimension, and two-value shorthands to set all three values in the block or inline dimension. The below code, in a horizontal writing mode, would give you a 2px green solid border on the top and bottom of the box, and a 4px dotted purple border on the left and right. ``` .box { border-block: 2px solid green; border-inline-width: 4px; border-inline-style: dotted; border-inline-color: rebeccapurple; } ``` ### Flow relative border-radius properties The specification has fairly recently added flow-relative values for the [`border-radius`](../border-radius) longhands. These have not yet been implemented by any browser. The below example, in a horizontal `writing-mode`, would set the top-right border radius to 1em, the bottom-right to 0, the bottom-left to 20px and the top-left to 40px. ``` .box { border-end-start-radius: 1em; border-end-end-radius: 0; border-start-end-radius: 20px; border-start-start-radius: 40px; } ``` Indicating logical values for the 4-value shorthand syntax ---------------------------------------------------------- The specification makes a suggestion for the four-value shorthands such as the `margin` property, however the final decision on how this should be indicated is as yet unresolved, and is discussed in [this issue](https://github.com/w3c/csswg-drafts/issues/1282). Using any four-value shorthand such as margin, padding, or border will currently use the physical versions, so if following the flow of the document is important, use the longhand properties for the time being. css Basic concepts of Logical Properties and Values Basic concepts of Logical Properties and Values =============================================== The Logical Properties and Values Specification introduces flow-relative mappings for many of the properties and values in CSS. This article introduces the specification, and explains flow relative properties and values. Why do we need logical properties? ---------------------------------- CSS traditionally has sized things according to the physical dimensions of the screen. Therefore we describe boxes as having a [`width`](../width) and [`height`](../height), position items from the `top` and `left`, float things left, assign borders, margin, and padding to the `top`, `right`, `bottom`, `left`, etc. The [Logical Properties and Values specification](https://drafts.csswg.org/css-logical/) defines mappings for these physical values to their logical, or flow relative, counterparts — e.g. `start` and `end` as opposed to `left` and `right`/`top` and `bottom`. An example of why these mappings might be needed is as follows. I have a Layout using CSS Grid, the grid container has a width applied and I am using the [`align-self`](../align-self) and [`justify-self`](../justify-self) properties to align the items. These properties are flow relative — `justify-self: start` aligns the item to the start on the inline dimension, `align-self: start` does the same on the block dimension. If I now change the writing mode of this component to `vertical-rl` using the [`writing-mode`](../writing-mode) property, the alignment continues to work in the same way. The inline dimension is now running vertically and the block dimension horizontally. The grid doesn't look the same, however, as the width assigned to the container is a horizontal measure, a measure tied to the physical and not the logical or flow relative running of the text. If instead of the `width` property we use the logical property [`inline-size`](../inline-size), the component now works the same way no matter which writing mode it is displayed using. You can try this out in the live example below. Change `writing-mode` from `vertical-rl` to `horizontal-tb` on `.grid` to see how the different properties change the layout. When working with a site in a writing mode other than a horizontal, top to bottom one, or when using writing modes for creative reasons, being able to relate to the flow of the content makes a lot of sense. Block and inline dimensions --------------------------- A key concept of working with flow relative properties and values is the two dimensions of block and inline. As we saw above, newer CSS layout methods such as Flexbox and Grid Layout use the concepts of `block` and `inline` rather than `right` and `left`/`top` and `bottom` when aligning items. The `inline` dimension is the dimension along which a line of text runs in the writing mode in use. Therefore, in an English document with the text running horizontally left to right, or an Arabic document with the text running horizontally right to left, the inline dimension is *horizontal*. Switch to a vertical writing mode (e.g. a Japanese document) and the inline dimension is now *vertical*, as lines in that writing mode run vertically. The block dimension is the other dimension, and the direction in which blocks — such as paragraphs — display one after the other. In English and Arabic, these run vertically, whereas in any vertical writing mode these run horizontally. The below diagram shows the inline and block directions in a horizontal writing mode: This diagram shows block and inline in a vertical writing mode: See also -------- * [Box Alignment in Grid Layout](../css_grid_layout/box_alignment_in_css_grid_layout) * [Box Alignment in Flex Layout](../css_box_alignment/box_alignment_in_flexbox) * [Understanding Logical Properties and Values](https://www.smashingmagazine.com/2018/03/understanding-logical-properties-values/) * [Writing Modes](../css_flow_layout/flow_layout_and_writing_modes) css Logical properties for floating and positioning Logical properties for floating and positioning =============================================== The [Logical Properties and Values specification](https://drafts.csswg.org/css-logical/) contains logical mappings for the physical values of [`float`](../float) and [`clear`](../clear), and also for the positioning properties used with [positioned layout](../css_positioning). This guide takes a look at how to use these. Mapped properties and values ---------------------------- The table below details the properties and values discussed in this guide along with their physical mappings. They assume a horizontal [`writing-mode`](../writing-mode), with a left-to-right direction. | Logical property or value | Physical property or value | | --- | --- | | [`float`](../float): inline-start | [`float`](../float): left | | [`float`](../float): inline-end | [`float`](../float): right | | [`clear`](../clear): inline-start | [`clear`](../clear): left | | [`clear`](../clear): inline-end | [`clear`](../clear): right | | [`inset-inline-start`](../inset-inline-start) | [`left`](../left) | | [`inset-inline-end`](../inset-inline-end) | [`right`](../right) | | [`inset-block-start`](../inset-block-start) | [`top`](../top) | | [`inset-block-end`](../inset-block-end) | [`bottom`](../bottom) | | [`text-align`](../text-align): start | [`text-align`](../text-align): left | | [`text-align`](../text-align): end | [`text-align`](../text-align): right | In addition to these mapped properties there are some additional shorthand properties made possible by being able to address block and inline dimensions. These have no mapping to physical properties, aside from the [`inset`](../inset) property. | Logical property | Purpose | | --- | --- | | [`inset-inline`](../inset-inline) | Sets both of the above inset values for the inline dimension simultaneously. | | [`inset-block`](../inset-block) | Sets both of the above inset values for the block dimension simultaneously. | | [`inset`](../inset) | Sets all four inset values simultaneously with physical mapping of multi-value. | Float and clear example ----------------------- The physical values used with the [`float`](../float) and [`clear`](../clear) properties are `left`, `right` and `both`. The Logical Properties specification defines the values `inline-start` and `inline-end` as mappings for `left` and `right`. In the example below I have two boxes — the first has the box floated with `float: left`, the second with `float: inline-start`. If you change the `writing-mode` to `vertical-rl` or the `direction` to `rtl` you will see that the left-floated box always sticks to the left, whereas the `inline-start`-floated item follows the `direction` and `writing-mode`. Example: Inset properties for positioned layout ----------------------------------------------- Positioning generally allows us to position an element in a manner relative to its containing block — we essentially inset the item relative to where it would fall based on normal flow. To do this we have historically used the physical properties [`top`](../top), [`right`](../right), [`bottom`](../bottom) and [`left`](../left). These properties take a length or a percentage as a value, and relate to the user's screen dimensions. New properties have been created in the Logical Properties specification for when you want the positioning to relate to the flow of text in your writing mode. These are as follows: [`inset-block-start`](../inset-block-start), [`inset-block-end`](../inset-block-end), [`inset-inline-start`](../inset-inline-start) and [`inset-inline-end`](../inset-inline-end). In the below example I have used the `inset-block-start` and `inset-inline-end` properties to position the blue box using absolute positioning inside the area with the grey dotted border, which has `position: relative`. Change the `writing-mode` property to `vertical-rl`, or add `direction: rtl`, and see how the flow relative box stays with the text direction. New two- and four-value shorthands ---------------------------------- As with other properties in the specification we have some new shorthand properties, which give the ability to set two or four values at once. * [`inset`](../inset) — sets all four sides together with physical mapping. * [`inset-inline`](../inset-inline) — sets both logical inline insets. * [`inset-block`](../inset-block) — sets both logical block insets. Example: Logical values for text-align -------------------------------------- The [`text-align`](../text-align) property has logical values that relate to text direction — rather than using `left` and `right` we can use `start` and `end`. In the below example I have set `text-align: right` in the first block and `text-align: end` in the second. If you change the value of `direction` to `rtl` you will see that the alignment stays to the right for the first block, but goes to the logical end on the left in the second. This works more consistently when using box alignment that uses start and end rather than physical directions for alignment.
programming_docs