repo_id
stringlengths
22
103
file_path
stringlengths
41
147
content
stringlengths
181
193k
__index_level_0__
int64
0
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_backdrop/index.md
--- title: "::backdrop" slug: Web/CSS/::backdrop page-type: css-pseudo-element browser-compat: css.selectors.backdrop --- {{CSSRef}} The **`::backdrop`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) is a box the size of the {{Glossary("viewport")}}, which is rendered immediately beneath any element being presented in the {{glossary("top layer")}}. {{EmbedInteractiveExample("pages/tabbed/pseudo-element-backdrop.html", "tabbed-shorter")}} ## Syntax ```css ::backdrop { /* ... */ } ``` ## Description Backdrops appear in the following instances: - Elements which have been placed in fullscreen mode using the [Fullscreen API](/en-US/docs/Web/API/Fullscreen_API) {{domxref("Element.requestFullscreen()")}} method. - {{HTMLElement("dialog")}} elements that have been shown in the top layer via a {{domxref("HTMLDialogElement.showModal()")}} call. - {{domxref("Popover API", "Popover", "", "nocode")}} elements that have been shown in the top layer via a {{domxref("HTMLElement.showPopover()")}} call. When multiple elements have been placed into the top layer, each one has its own `::backdrop` pseudo-element. ```css /* Backdrop is only displayed when dialog is opened with dialog.showModal() */ dialog::backdrop { background: rgb(255 0 0 / 25%); } ``` Elements are placed in a last-in/first out (LIFO) stack in the top layer. The `::backdrop` pseudo-element makes it possible to obscure, style, or completely hide everything located below a top layer element. `::backdrop` neither inherits from nor is inherited by any other elements. No restrictions are made on what properties apply to this pseudo-element. ## Examples ### Styling the backdrop for fullscreen video In this example, the backdrop style used when a video is shifted to fullscreen mode is configured to be a grey-blue color rather than the black it defaults to in most browsers. ```css video::backdrop { background-color: #448; } ``` The resulting screen looks like this: ![An almost full-screen video player with purple above and below the player as the video player doesn't completely fill the screen.](bbb-backdrop.png) [See this example in action](https://mdn.github.io/css-examples/backdrop/index.html), after changing the color of the background cause the video to go fullscreen to see the change to the backdrop color. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref(":fullscreen")}} pseudo-class - {{HTMLElement("dialog")}} HTML element - [Fullscreen API](/en-US/docs/Web/API/Fullscreen_API) - [`popover`](/en-US/docs/Web/HTML/Global_attributes/popover) HTML global attribute - [Popover API](/en-US/docs/Web/API/Popover_API)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/scroll-padding-inline-end/index.md
--- title: scroll-padding-inline-end slug: Web/CSS/scroll-padding-inline-end page-type: css-property browser-compat: css.properties.scroll-padding-inline-end --- {{CSSRef}} 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. {{EmbedInteractiveExample("pages/css/scroll-padding-inline-end.html")}} ## Syntax ```css /* 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 {{cssinfo}} ## Formal syntax {{csssyntax}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS scroll snap](/en-US/docs/Web/CSS/CSS_scroll_snap) - [Well-controlled scrolling with CSS scroll snap](https://web.dev/articles/css-scroll-snap)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/background-blend-mode/index.md
--- title: background-blend-mode slug: Web/CSS/background-blend-mode page-type: css-property browser-compat: css.properties.background-blend-mode --- {{CSSRef}} The **`background-blend-mode`** [CSS](/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. {{EmbedInteractiveExample("pages/css/background-blend-mode.html")}} Blending modes should be defined in the same order as the {{cssxref("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 ```css /* 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 - {{cssxref("&lt;blend-mode&gt;")}} - : The blending mode to be applied. There can be several values, separated by commas. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Basic example ```css .item { width: 300px; height: 300px; background: url("image1.png"), url("image2.png"); background-blend-mode: screen; } ``` ### Try out different blend modes ```html hidden <div id="div"></div> <select id="select"> <option>normal</option> <option>multiply</option> <option selected>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 hidden #div { width: 300px; height: 300px; background: url("br.png"), url("tr.png"); background-blend-mode: screen; } ``` ```js hidden document.getElementById("select").onchange = (event) => { document.getElementById("div").style.backgroundBlendMode = document.getElementById("select").selectedOptions[0].innerHTML; }; console.log(document.getElementById("div")); ``` {{ EmbedLiveSample('Examples', "330", "350") }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("&lt;blend-mode&gt;")}} - {{cssxref("mix-blend-mode")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_-webkit-meter-even-less-good-value/index.md
--- title: "::-webkit-meter-even-less-good-value" slug: Web/CSS/::-webkit-meter-even-less-good-value page-type: css-pseudo-element status: - non-standard browser-compat: css.selectors.-webkit-meter-even-less-good-value --- {{CSSRef}}{{Non-standard_header}} The **`::-webkit-meter-even-less-good-value`** styles the {{htmlelement("meter")}} element when the value and the optimum attributes fall outside the low-high range, but in opposite zones. To illustrate, it applies when _value_ < _low_ < _high_ < _optimum_ or _value_ > _high_ > _low_ > _optimum_. Red is the default color. ## Syntax ```css ::-webkit-meter-even-less-good-value { /* ... */ } ``` ## Specifications Not part of any standard. ## Examples ### HTML ```html Normal: <meter min="0" max="10" low="3" high="7" optimum="8" value="2"> Score 2/10 </meter> <br /> Styled: <meter id="styled" min="0" max="10" low="3" high="7" optimum="8" value="2"> Score 2/10 </meter> ``` ### CSS ```css body { font-family: monospace; } .safari meter { /* Reset the default appearance for Safari only */ /* .safari class is added via JavaScript */ -webkit-appearance: none; } #styled::-webkit-meter-even-less-good-value { background: linear-gradient(to bottom, #f77, #900 45%, #900 55%, #f77); height: 100%; box-sizing: border-box; } ``` ### JavaScript ```js // Safari requires <meter> elements to have an `appearance` of `none` for custom styling // using `::-webkit-meter-*` selectors, but `appearance: none` breaks rendering on Chrome. // Therefore, we must check if the browser is Safari-based. const is_safari = navigator.userAgent.includes("AppleWebKit/") && !navigator.userAgent.includes("Chrome/"); if (is_safari) { document.body.classList.add("safari"); } ``` ### Result {{ EmbedLiveSample('Examples', '100%', 50) }} ## Browser compatibility {{Compat}} ## See also The pseudo-elements used by WebKit/Blink to style other parts of a {{htmlelement("meter")}} element are as follows: - {{cssxref("::-webkit-meter-inner-element")}} - {{cssxref("::-webkit-meter-bar")}} - {{cssxref("::-webkit-meter-optimum-value")}} - {{cssxref("::-webkit-meter-suboptimum-value")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/-webkit-mask-repeat-y/index.md
--- title: "-webkit-mask-repeat-y" slug: Web/CSS/-webkit-mask-repeat-y page-type: css-property status: - non-standard browser-compat: css.properties.-webkit-mask-repeat-y --- {{CSSRef}}{{Non-standard_header}} The `-webkit-mask-repeat-y` property sets whether and how a mask image is repeated (tiled) vertically. ## Syntax ```css /* Keyword values */ -webkit-mask-repeat-y: repeat; -webkit-mask-repeat-y: no-repeat; -webkit-mask-repeat-y: space; -webkit-mask-repeat-y: round; /* Multiple values */ -webkit-mask-repeat-y: repeat, no-repeat, space; /* Global values */ -webkit-mask-repeat-y: inherit; -webkit-mask-repeat-y: initial; -webkit-mask-repeat-y: revert; -webkit-mask-repeat-y: revert-layer; -webkit-mask-repeat-y: unset; ``` ### Values - repeat - : The mask image is repeated vertically. - no-repeat - : The mask image is not repeated vertically; only one copy of the mask image is drawn in vertical direction. The vertical remainder of the masked element's content is not displayed. - repeat - : The mask image is repeated vertically. - space - : The image is repeated as much as possible without clipping. The first and last images are pinned to the top and bottom edge of the element, and whitespace is distributed evenly between the images. The {{cssxref("mask-position")}} property is ignored unless only one image can be displayed without clipping. The only case where clipping happens using space is when there isn't enough room to display one image. - round - : As the allowed vertical 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 height of 260px, repeated three times, might stretch until each repetition is 300px high, and then another image will be added. They will then compress to a height of 225px. ## Formal definition {{CSSInfo}} ## Formal syntax ```plain -webkit-mask-repeat-y = repeat | no-repeat | space | round ``` ## Examples ### Using a repeating or non-repeating mask image ```css .exampleone { -webkit-mask-image: url("mask.png"); -webkit-mask-repeat-y: repeat; } .exampletwo { -webkit-mask-image: url("mask.png"); -webkit-mask-repeat-y: no-repeat; } ``` ### Using multiple mask images You can specify a different `<repeat-style>` for each mask image, separated by commas: ```css .examplethree { -webkit-mask-image: url("mask1.png"), url("mask2.png"); -webkit-mask-repeat-y: repeat, space; } ``` Each image is matched with the corresponding repeat style, from first specified to last. ## Specifications Not part of any standard. ## Browser compatibility {{Compat}} ## See also {{cssxref("mask-repeat", "-webkit-mask-repeat")}}, {{cssxref("-webkit-mask-repeat-x")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/padding-right/index.md
--- title: padding-right slug: Web/CSS/padding-right page-type: css-property browser-compat: css.properties.padding-right --- {{CSSRef}} The **`padding-right`** [CSS](/en-US/docs/Web/CSS) property sets the width of the [padding area](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model#padding_area) on the right of an element. {{EmbedInteractiveExample("pages/css/padding-right.html")}} An element's padding area is the space between its content and its border. > **Note:** The {{cssxref("padding")}} property can be used to set paddings on all four sides of an element with a single declaration. ## Syntax ```css /* <length> values */ padding-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 - {{cssxref("&lt;length&gt;")}} - : The size of the padding as a fixed value. Must be nonnegative. - {{cssxref("&lt;percentage&gt;")}} - : The size of the padding as a percentage, relative to the inline size (_width_ in a horizontal language, defined by {{cssxref("writing-mode")}}) of the [containing block](/en-US/docs/Web/CSS/Containing_block). Must be nonnegative. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting right padding using pixels and percentages ```css .content { padding-right: 5%; } .sidebox { padding-right: 10px; } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Introduction to the CSS basic box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model) - {{cssxref("padding-top")}}, {{cssxref("padding-bottom")}}, {{cssxref("padding-left")}} and the {{cssxref("padding")}} shorthand - The mapped logical properties: {{cssxref("padding-block-start")}}, {{cssxref("padding-block-end")}}, {{cssxref("padding-inline-start")}}, and {{cssxref("padding-inline-end")}} and the shorthands {{cssxref("padding-block")}} and {{cssxref("padding-inline")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/offset-distance/index.md
--- title: offset-distance slug: Web/CSS/offset-distance page-type: css-property browser-compat: css.properties.offset-distance --- {{CSSRef}} The **`offset-distance`** CSS property specifies a position along an {{CSSxRef("offset-path")}} for an element to be placed. {{EmbedInteractiveExample("pages/css/offset-distance.html")}} ## Syntax ```css /* 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; ``` - `{{cssxref('&lt;length-percentage&gt;')}}` - : A length that specifies how far the element is along the path (defined with {{cssxref('offset-path')}}). 100% represents the total length of the path (when the `offset-path` is defined as a basic shape or `path()`). ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## 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 {{cssxref('offset-path')}} and then set up an animation that takes the `offset-distance` from `0%` to `100%`. #### HTML ```html <div id="motion-demo"></div> ``` #### CSS ```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 {{EmbedLiveSample('Using_offset-distance_in_an_animation', '100%', 150)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("offset")}} - {{cssxref("offset-anchor")}} - {{cssxref("offset-path")}} - {{cssxref("offset-position")}} - {{cssxref("offset-rotate")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_scoping/index.md
--- title: CSS scoping slug: Web/CSS/CSS_scoping page-type: css-module spec-urls: https://drafts.csswg.org/css-scoping/ --- {{CSSRef}} The **CSS scoping** module defines the CSS scoping and encapsulation mechanisms, focusing on the [Shadow DOM](/en-US/docs/Web/API/Web_components/Using_shadow_DOM) [scoping](https://css.oddbird.net/scope/) mechanism. CSS styles are either global in scope or scoped to a {{Glossary("shadow tree")}}. Globally scoped styles apply to all the elements in the node tree that match the selector, including custom elements in that tree, but not to the shadow trees composing each custom element. Selectors and their associated style definitions don't bleed between scopes. Within the CSS of a shadow tree, selectors don't select elements outside the tree, either in the global scope or in other shadow trees. Each custom element has its own shadow tree, which contains all the components that make up the custom element (but not the custom element, or "host", itself). Sometimes it's useful to be able to style a host from inside the shadow tree context. The CSS scoping module makes this possible by defining selectors that: - Enable a shadow tree to style its host. - Enable external CSS to style elements within a shadow DOM (but only if the associated custom element is set up to accept external styles). ## Reference ### Selectors - {{CSSXref(":host")}} - {{CSSXref(":host_function", ":host()")}} - {{CSSXref(":host-context", ":host-context()")}} - {{CSSXref("::slotted")}} ## Guides - [Web components](/en-US/docs/Web/API/Web_components) - : An introduction to the different technologies used to create reusable web components β€” custom elements whose functionality is encapsulated away from the rest of your code. - [Using shadow DOM](/en-US/docs/Web/API/Web_components/Using_shadow_DOM) - : Shadow DOM fundamentals, including attaching a shadow DOM to an element, adding to the shadow DOM tree, and styling. - [Using templates and slots](/en-US/docs/Web/API/Web_components/Using_templates_and_slots) - : Defining reusable HTML structure using {{htmlelement("template")}} and {{htmlelement("slot")}} elements, and using that structure inside web components. - [Using custom elements](/en-US/docs/Web/API/Web_components/Using_custom_elements) - : Introduction to the Custom Elements API, the JavaScript API used to create custom elements that encapsulate functionality. ## Related concepts - CSS {{CSSXref(":defined")}} pseudo-class - CSS {{CSSXref("::part")}} pseudo-element - HTML {{HTMLElement("template")}} element - HTML {{HTMLElement("slot")}} element - HTML [`slot`](/en-US/docs/Web/HTML/Global_attributes/slot) attribute - {{Glossary("Shadow tree")}} glossary term - {{Glossary("DOM")}} glossary term - [Compound selector](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#compound_selector) term - [Selector list](/en-US/docs/Web/CSS/Selector_list) term - [Web components](/en-US/docs/Web/API/Web_components) interfaces, properties, and methods - {{DOMxRef("CustomElementRegistry")}} interface - {{DOMxRef("Element")}} API - {{DOMxRef("Element.slot")}} property - {{DOMxRef("Element.assignedSlot")}} property - {{DOMxRef("Element.attachShadow()")}} method - {{DOMxRef("HTMLSlotElement")}} interface - {{DOMxRef("HTMLTemplateElement")}} interface - {{DOMxRef("ShadowRoot")}} interface > **Note:** Despite the name, the {{CSSXref(":scope")}} pseudo-class, which represents elements that are a reference point (or scope) for selectors to match against, is defined in the [Selectors](/en-US/docs/Web/CSS/CSS_selectors) module. It is otherwise unrelated to the CSS scoping module, which is focused on scoping as it pertains to the Shadow DOM scoping mechanism. ## Specifications {{Specifications}} ## See also - [CSS selectors](/en-US/docs/Web/CSS/CSS_selectors) module - [CSS pseudo elements](/en-US/docs/Web/CSS/CSS_pseudo-elements) module - [CSS namespaces](/en-US/docs/Web/CSS/CSS_namespaces) module - [CSS shadow-parts](/en-US/docs/Web/CSS/CSS_shadow_parts) module - [Template, slot, and shadow](https://web.dev/learn/html/template/) on web.dev (2023) - [Custom element best practices](https://web.dev/articles/custom-elements-best-practices) on web.dev (2019)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/outline/index.md
--- title: outline slug: Web/CSS/outline page-type: css-shorthand-property browser-compat: css.properties.outline --- {{CSSRef}} The **`outline`** [CSS](/en-US/docs/Web/CSS) [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) sets most of the outline properties in a single declaration. {{EmbedInteractiveExample("pages/css/outline.html")}} ## Constituent properties This property is a shorthand for the following CSS properties: - {{cssxref("outline-color")}} - {{cssxref("outline-style")}} - {{cssxref("outline-width")}} ## Syntax ```css /* 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](/en-US/docs/Web/CSS/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 {{cssxref("outline-color")}}. - `<'outline-style'>` - : Sets the style of the outline. Defaults to `none` if absent. See {{cssxref("outline-style")}}. - `<'outline-width'>` - : Sets the thickness of the outline. Defaults to `medium` if absent. See {{cssxref("outline-width")}}. ## Description Outline is a line outside of the element's [border](/en-US/docs/Web/CSS/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 {{cssxref("outline-offset")}} property, and corner angles using the {{cssxref("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 {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Using outline to set a focus style #### HTML ```html <a href="#">This link has a special focus style.</a> ``` #### CSS ```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 {{EmbedLiveSample("Using_outline_to_set_a_focus_style", "100%", 85)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("outline-color")}} - {{cssxref("outline-style")}} - {{cssxref("outline-width")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/scroll-padding-block/index.md
--- title: scroll-padding-block slug: Web/CSS/scroll-padding-block page-type: css-shorthand-property browser-compat: css.properties.scroll-padding-block --- {{CSSRef}} The `scroll-padding-block` [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) sets the scroll padding of an element in the block dimension. {{EmbedInteractiveExample("pages/css/scroll-padding-block.html")}} 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`](/en-US/docs/Web/CSS/scroll-padding-block-end) - [`scroll-padding-block-start`](/en-US/docs/Web/CSS/scroll-padding-block-start) ## Syntax ```css /* 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 {{cssinfo}} ## Formal syntax {{csssyntax}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS scroll snap](/en-US/docs/Web/CSS/CSS_scroll_snap) - [Well-controlled scrolling with CSS scroll snap](https://web.dev/articles/css-scroll-snap)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/animation-timeline/index.md
--- title: animation-timeline slug: Web/CSS/animation-timeline page-type: css-property status: - experimental browser-compat: css.properties.animation-timeline --- {{CSSRef}}{{SeeCompatTable}} The **`animation-timeline`** [CSS](/en-US/docs/Web/CSS) property specifies the timeline that is used to control the progress of a CSS animation. The following types of timelines can be set via `animation-timeline`: - The default document timeline, which is progressed through by the passing of time since the document was first loaded in the browser. This is the timeline traditionally associated with CSS animations and is selected with a value of `auto`, or by not specifying an `animation-timeline` value at all. - A _scroll progress timeline_, which is progressed through by scrolling a scrollable element (_scroller_) between top and bottom (or left and right). The position in the scroll range is converted into a percentage of progress β€” 0% at the start and 100% at the end. The element that provides the scroll progress timeline can be specified in two ways: - A _named scroll progress timeline_ is one where the scroller providing the scroll progress timeline is explicitly named using the {{cssxref("scroll-timeline-name")}} property (or the {{cssxref("scroll-timeline")}} shorthand property). The name is then linked to the element to animate by specifying it as the value of that element's `animation-timeline` property. - An _anonymous scroll progress timeline_ is one where the element to animate is given a {{cssxref("animation-timeline/scroll", "scroll()")}} function as an `animation-timeline` value, which selects the scroller providing the scroll progress timeline and the scroll axis to be used based on the arguments you pass to it. - A _view progress timeline_, which is progressed through based on the change in visibility of an element (known as the _subject_) inside a scroller. The visibility of the subject inside the scroller is tracked β€” by default, the timeline is at 0% when the subject is first visible at one edge of the scroller, and 100% when it reaches the opposite edge. Unlike with scroll progress timelines, you can't specify the scroller β€” the subject's visibility is always tracked within its nearest ancestor scroller. The subject that provides the view progress timeline can be specified in two ways: - A _named view progress timeline_ is one where the subject is explicitly named using the {{cssxref("view-timeline-name")}} property (or the {{cssxref("view-timeline")}} shorthand property). The name is then linked to the element to animate by specifying it as the value of that element's `animation-timeline` property. This is a key point β€” with named view progress timelines, the element to animate does not have to be the same as the subject. - An _anonymous view progress timeline_ is one where the subject is given a {{cssxref("animation-timeline/view", "view()")}} function as an `animation-timeline` value, causing it to be animated based on its position inside its nearest parent scroller. > **Note:** {{cssxref("animation-timeline")}} is included in the {{cssxref("animation")}} shorthand as a reset-only value. This means that including `animation` resets a previously-declared `animation-timeline` value to `auto`, but a specific value cannot be set via `animation`. When creating [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations), you need to declare `animation-timeline` after declaring any `animation` shorthand for it to take effect. <!-- {{EmbedInteractiveExample("pages/css/animation-name.html")}} --> ## Syntax ```css /* Keyword */ animation-timeline: none; animation-timeline: auto; /* Single animation named timeline */ animation-timeline: --timeline_name; /* Single animation anonymous scroll progress timeline */ animation-timeline: scroll(); animation-timeline: scroll(scroller axis); /* Single animation anonymous view progress timeline */ animation-timeline: view(); animation-timeline: view(axis inset); /* Multiple animations */ animation-timeline: --progressBarTimeline, --carouselTimeline; animation-timeline: none, --slidingTimeline; /* 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](/en-US/docs/Web/API/DocumentTimeline). - `scroll()` {{Experimental_Inline}} - : An anonymous scroll progress timeline is provided by some ancestor scroller of the current element. The function parameters allow you to select the scroller, and the scrolling axis the timeline will be measured along. See {{cssxref("animation-timeline/scroll", "scroll()")}} for more information. - `view()` {{Experimental_Inline}} - : An anonymous view progress timeline is provided by the subject that `animation-timeline: view();` is set on. The function parameters allow you to select the scrollbar axis along which timeline progress will be tracked and an inset that adjusts the position of the box in which the subject is deemed to be visible. See {{cssxref("animation-timeline/view", "view()")}} for more information. - `<dashed-ident>` - : A {{cssxref('dashed-ident')}} identifying a named timeline previously declared with the {{cssxref('scroll-timeline-name')}} or {{cssxref('view-timeline-name')}} property (or the {{cssxref('scroll-timeline')}} or {{cssxref('view-timeline')}} shorthand property). > **Note:** If two or more timelines share the same name, the last declared within the cascade will be used. Also, if no timeline is found that matches the given name, the animation is not associated with a timeline. > **Note:** The [`<dashed-ident>`](/en-US/docs/Web/CSS/dashed-ident) values must start with `--`. This helps avoid name clashes with standard CSS keywords. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting a named scroll progress timeline A scroll progress timeline named `--squareTimeline` is defined using the `scroll-timeline-name` property on an element with an `id` of `container`. This is then set as the timeline for the animation on the `#square` element using `animation-timeline: --squareTimeline`. #### HTML The HTML for the example is shown below. ```html <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 progress timeline named `--squareTimeline` using the `scroll-timeline-name` property (we could explicitly set which scrollbar axis to use with {{cssxref("scroll-timeline-axis")}}, but there is only a block direction 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). ```css #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. ```css #square { background-color: deeppink; width: 100px; height: 100px; margin-top: 100px; animation-name: rotateAnimation; animation-duration: 1ms; /* Firefox requires this to apply the animation */ animation-direction: alternate; animation-timeline: --squareTimeline; position: absolute; bottom: 0; } @keyframes rotateAnimation { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } ``` The "stretcher" CSS 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 progress timeline to associate with the animation timeline. ```css #stretcher { height: 600px; } ``` #### Result Scroll to see the square element being animated. {{EmbedLiveSample("Setting a named scroll progress timeline", "100%", "320px")}} ### Setting an anonymous scroll progress timeline In this example, the `#square` element is animated using an anonymous scroll progress timeline, which is applied to the element to be animated using the `scroll()` function. 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. ```html <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:** `block` and `nearest` are actually the default parameter values, so we could have used just `scroll()`. ```css #square { background-color: deeppink; width: 100px; height: 100px; margin-top: 100px; position: absolute; bottom: 0; animation-name: rotateAnimation; animation-duration: 1ms; /* Firefox requires this to apply the animation */ 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 scroll progress timeline. ```css #container { height: 300px; overflow-y: scroll; position: relative; } #stretcher { height: 600px; } ``` #### Result Scroll to see the square element being animated. {{EmbedLiveSample("Setting an anonymous scroll progress timeline", "100%", "320px")}} ### Setting a named view progress timeline A view progress timeline named `--subjectReveal` is defined using the `view-timeline-name` property on a subject element with a `class` of `animation`. This is then set as the timeline for the same element using `animation-timeline: --subjectReveal;`. The result is that the subject element animates as it moves upwards through the document as it is scrolled. #### HTML The HTML for the example is shown below. ```html <div class="content"> <h1>Content</h1> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Risus quis varius quam quisque id. Et ligula ullamcorper malesuada proin libero nunc consequat interdum varius. Elit ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at augue. </p> <p> Dolor sed viverra ipsum nunc aliquet. Sed sed risus pretium quam vulputate dignissim. Tortor aliquam nulla facilisi cras. A erat nam at lectus urna duis convallis convallis. Nibh ipsum consequat nisl vel pretium lectus. Sagittis aliquam malesuada bibendum arcu vitae elementum. Malesuada bibendum arcu vitae elementum curabitur vitae nunc sed velit. </p> <div class="subject animation"></div> <p> Adipiscing enim eu turpis egestas pretium aenean pharetra magna ac. Arcu cursus vitae congue mauris rhoncus aenean vel. Sit amet cursus sit amet dictum. Augue neque gravida in fermentum et. Gravida rutrum quisque non tellus orci ac auctor augue mauris. Risus quis varius quam quisque id diam vel quam elementum. Nibh praesent tristique magna sit amet purus gravida quis. Duis ultricies lacus sed turpis tincidunt id aliquet. In egestas erat imperdiet sed euismod nisi. Eget egestas purus viverra accumsan in nisl nisi scelerisque. Netus et malesuada fames ac. </p> </div> ``` #### CSS The `subject` element and its containing `content` element are styled minimally, and the text content is given some basic font settings: ```css .subject { width: 300px; height: 200px; margin: 0 auto; background-color: deeppink; } .content { width: 75%; max-width: 800px; margin: 0 auto; } p, h1 { font-family: Arial, Helvetica, sans-serif; } h1 { font-size: 3rem; } p { font-size: 1.5rem; line-height: 1.5; } ``` The `<div>` with the class of `subject` is also given a class of `animation` β€” this is where the {{cssxref("view-timeline-name")}} is set to define a named view progress timeline. It is also given an `animation-timeline` name with the same value to declare that this will be the element animated as the view progress timeline is progressed. Lastly, an animation is specified on the element that animates its opacity and scale, causing it to fade in and size up as it moves up the scroller. ```css .animation { view-timeline-name: --subjectReveal; animation-timeline: --subjectReveal; animation-name: appear; animation-fill-mode: both; animation-duration: 1ms; /* Firefox requires this to apply the animation */ } @keyframes appear { from { opacity: 0; transform: scaleX(0); } to { opacity: 1; transform: scaleX(1); } } ``` #### Result Scroll to see the subject element being animated. {{EmbedLiveSample("Setting a named view progress timeline", "100%", "480px")}} ### Setting an anonymous view progress timeline An anonymous view progress timeline is set on an element with class `subject` using `animation-timeline: view()`. The result is that the `subject` element animates as it moves upwards through the document as it is scrolled. #### HTML The HTML for the example is shown below. ```html <div class="content"> <h1>Content</h1> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Risus quis varius quam quisque id. Et ligula ullamcorper malesuada proin libero nunc consequat interdum varius. Elit ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at augue. </p> <p> Dolor sed viverra ipsum nunc aliquet. Sed sed risus pretium quam vulputate dignissim. Tortor aliquam nulla facilisi cras. A erat nam at lectus urna duis convallis convallis. Nibh ipsum consequat nisl vel pretium lectus. Sagittis aliquam malesuada bibendum arcu vitae elementum. Malesuada bibendum arcu vitae elementum curabitur vitae nunc sed velit. </p> <div class="subject animation"></div> <p> Adipiscing enim eu turpis egestas pretium aenean pharetra magna ac. Arcu cursus vitae congue mauris rhoncus aenean vel. Sit amet cursus sit amet dictum. Augue neque gravida in fermentum et. Gravida rutrum quisque non tellus orci ac auctor augue mauris. Risus quis varius quam quisque id diam vel quam elementum. Nibh praesent tristique magna sit amet purus gravida quis. Duis ultricies lacus sed turpis tincidunt id aliquet. In egestas erat imperdiet sed euismod nisi. Eget egestas purus viverra accumsan in nisl nisi scelerisque. Netus et malesuada fames ac. </p> </div> ``` #### CSS The `subject` element and its containing `content` element are styled minimally, and the text content is given some basic font settings: ```css .subject { width: 300px; height: 200px; margin: 0 auto; background-color: deeppink; } .content { width: 75%; max-width: 800px; margin: 0 auto; } p, h1 { font-family: Arial, Helvetica, sans-serif; } h1 { font-size: 3rem; } p { font-size: 1.5rem; line-height: 1.5; } ``` The `<div>` with the class of `subject` is also given a class of `animation` β€” this is where `animation-timeline: view()` is set to declare that it will be animated as it progresses through the view progress timeline provided by its scrolling ancestor (in this case the document's root element). Last, an animation is specified on the element that animates its opacity and scale, causing it to fade in and size up as it moves up the scroller. ```css .animation { animation-timeline: view(); animation-name: appear; animation-fill-mode: both; animation-duration: 1ms; /* Firefox requires this to apply the animation */ } @keyframes appear { from { opacity: 0; transform: scaleX(0); } to { opacity: 1; transform: scaleX(1); } } ``` #### Result Scroll to see the subject element being animated. {{EmbedLiveSample("Setting an anonymous view progress timeline", "100%", "480px")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("animation")}}, {{cssxref("animation-composition")}}, {{cssxref("animation-delay")}}, {{cssxref("animation-direction")}}, {{cssxref("animation-duration")}}, {{cssxref("animation-fill-mode")}}, {{cssxref("animation-iteration-count")}}, {{cssxref("animation-name")}}, {{cssxref("animation-play-state")}}, {{cssxref("animation-timing-function")}} - {{cssxref("scroll-timeline-name")}}, {{cssxref("scroll-timeline-axis")}}, {{cssxref("scroll-timeline")}} - {{cssxref("timeline-scope")}} - {{cssxref("view-timeline-name")}}, {{cssxref("view-timeline-axis")}}, {{cssxref("view-timeline")}}, {{cssxref("view-timeline-inset")}} - The JavaScript equivalent: The `timeline` property available in {{domxref("Element.animate()")}} calls - [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations) - [Using CSS animations](/en-US/docs/Web/CSS/CSS_animations/Using_CSS_animations)
0
data/mdn-content/files/en-us/web/css/animation-timeline
data/mdn-content/files/en-us/web/css/animation-timeline/view/index.md
--- title: view() slug: Web/CSS/animation-timeline/view page-type: css-function status: - experimental browser-compat: css.properties.animation-timeline.view --- {{CSSRef}}{{SeeCompatTable}} The **`view()`** [CSS function](/en-US/docs/Web/CSS/CSS_Functions) can be used with {{cssxref("animation-timeline")}} to indicate a subject element that will provide an anonymous view progress timeline to animate. The view progress timeline is progressed through by a change in visibility of the subject element inside the nearest ancestor scroller. The visibility of the subject inside the scroller is tracked β€” by default, the timeline is at 0% when the subject is first visible at one edge of the scroller, and 100% when it reaches the opposite edge. The function parameters can specify the scrollbar axis along which timeline progress will be tracked and an inset that adjusts the position of the box in which the subject is deemed to be visible. > **Note:** If the indicated axis does not contain a scrollbar, then the animation timeline will be inactive (have zero progress). > **Note:** Each use of `view()` corresponds to its own unique instance of {{domxref("ViewTimeline")}} in the [Web Animations API](/en-US/docs/Web/API/Web_Animations_API). ## Syntax ```css /* Function with no parameters set */ animation-timeline: view(); /* Values for selecting the axis */ animation-timeline: view(block); /* Default */ animation-timeline: view(inline); animation-timeline: view(y); animation-timeline: view(x); /* Values for the inset */ animation-timeline: view(auto); /* Default */ animation-timeline: view(20%); animation-timeline: view(200px); animation-timeline: view(20% 40%); animation-timeline: view(20% 200px); animation-timeline: view(100px 200px); animation-timeline: view(auto 200px); /* Examples that specify axis and inset */ animation-timeline: view(block auto); /* Default */ animation-timeline: view(inline 20%); animation-timeline: view(x 200px auto); ``` ### Parameters - axis - : The scrollbar axis value can be any one of the following: - `block` - : The scrollbar on the block axis of the scroll container, which is the axis in the direction perpendicular to the flow of text within a line. For horizontal writing modes, such as standard English, this is the same as `y`, while for vertical writing modes, it is the same as `x`. This is the default value. - `inline` - : The scrollbar on the inline axis of the scroll container, which is the axis in the direction parallel to the flow of text in a line. For horizontal writing modes, this is the same as `x`, while for vertical writing modes, this is the same as `y`. - `y` - : The scrollbar on the vertical axis of the scroll container. - `x` - : The scrollbar on the horizontal axis of the scroll container. - inset - : The inset value can be one or two values, which can be either `auto` or a {{cssxref("length-percentage")}}. It specifies an inset (positive) or outset (negative) adjustment of the [scrollport](/en-US/docs/Glossary/Scroll_container#scrollport). The inset is used to determine whether the element is in view which determines the length of the animation timeline. In other words, the animation lasts as long as the element is in the inset-adjusted view. - start - : Inward offset from beginning of the scrollport. - end - : Inward offset from end of the scrollport. > **Note:** The scroller and inset values can be specified in any order. ### Formal syntax {{CSSSyntax}} ## Examples ### Setting an anonymous view progress timeline An anonymous view progress timeline is set on an element with class `subject` using `animation-timeline: view()`. The result is that the `subject` element animates as it moves upwards through the document as it is scrolled. #### HTML The HTML for the example is shown below. ```html <div class="content"> <h1>Content</h1> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Risus quis varius quam quisque id. Et ligula ullamcorper malesuada proin libero nunc consequat interdum varius. Elit ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at augue. </p> <p> Dolor sed viverra ipsum nunc aliquet. Sed sed risus pretium quam vulputate dignissim. Tortor aliquam nulla facilisi cras. A erat nam at lectus urna duis convallis convallis. Nibh ipsum consequat nisl vel pretium lectus. Sagittis aliquam malesuada bibendum arcu vitae elementum. Malesuada bibendum arcu vitae elementum curabitur vitae nunc sed velit. </p> <div class="subject-container"> <div class="subject animation"></div> </div> <p> Adipiscing enim eu turpis egestas pretium aenean pharetra magna ac. Arcu cursus vitae congue mauris rhoncus aenean vel. Sit amet cursus sit amet dictum. Augue neque gravida in fermentum et. Gravida rutrum quisque non tellus orci ac auctor augue mauris. Risus quis varius quam quisque id diam vel quam elementum. Nibh praesent tristique magna sit amet purus gravida quis. Duis ultricies lacus sed turpis tincidunt id aliquet. In egestas erat imperdiet sed euismod nisi. Eget egestas purus viverra accumsan in nisl nisi scelerisque. Netus et malesuada fames ac. </p> </div> <div class="overlay top">inset start 50%</div> <div class="overlay bottom">inset end 10%</div> ``` #### CSS The `subject` element and `content` elements are minimally styled and the text content is given some basic font settings: ```css .subject { width: 300px; height: 200px; background-color: deeppink; } .content { width: 75%; max-width: 800px; margin: 0 auto; } p { font-size: 1.5rem; line-height: 1.8; } ``` To aid the understanding of the result, extra elements `subject-container`, `top`, and `bottom` have been used. The `subject-container` shows the bounds of the animation. And semi-transparent `top` and `bottom` overlays mark inset offsetted scrollport. ```css .subject-container { border: 2px dashed black; width: 300px; margin: 0 auto; } .overlay { position: fixed; width: 100%; background-color: #f5deb3aa; display: flex; font-size: 1.2rem; font-weight: bold; color: red; justify-content: flex-end; } .top { top: 0; height: 244px; align-items: end; } .bottom { top: 432px; height: 48px; } ``` In the following code, the `<div>` with the class of `subject` is also given a class of `animation`. The `grow` animation causes the `subject` element to grow or shrink. The `animation-timeline: view(block 55% 10%)` is set to declare that it will be animated as it progresses through the view progress timeline provided by its scrolling ancestor (in this case the document's root element). While scrolling down, note how the inset value of `50% 10%` causes the animation to start at 10% from the bottom and finish at 50% from the top. As animation moves forward along the timeline the `subject` grows. Conversely, when scrolling up the animation proceeds in the reverse direction, starting at 50% from the top, moving backward through the animation, and ending at 10% from the bottom. So, as the animation happens backwards the `subject` shrinks. An important point to remember is that the animation lasts as long as the `subject` element is in the view which has been set and to be offset using `50% 10%` inset values. ```css .animation { animation-timeline: view(block 50% 10%); animation-name: grow; animation-fill-mode: both; animation-duration: 1ms; /* Firefox requires this to apply the animation */ animation-timing-function: linear; } @keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } } ``` #### Result Scroll to see the subject element being animated. {{EmbedLiveSample("Setting an anonymous view progress timeline", "100%", "480px")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations) - [Using CSS animations](/en-US/docs/Web/CSS/CSS_animations/Using_CSS_animations) - [`animation-timeline`](/en-US/docs/Web/CSS/animation-timeline)
0
data/mdn-content/files/en-us/web/css/animation-timeline
data/mdn-content/files/en-us/web/css/animation-timeline/scroll/index.md
--- title: scroll() slug: Web/CSS/animation-timeline/scroll page-type: css-function status: - experimental browser-compat: css.properties.animation-timeline.scroll --- {{CSSRef}}{{SeeCompatTable}} The **`scroll()`** [CSS function](/en-US/docs/Web/CSS/CSS_Functions) can be used with {{cssxref("animation-timeline")}} to indicate a scrollable element (_scroller_) and scrollbar axis that will provide an anonymous scroll progress timeline for animating the current element. The scroll progress timeline is progressed through by scrolling the scroller between top and bottom (or left and right). The position in the scroll range is converted into a percentage of progress β€” 0% at the start and 100% at the end. > **Note:** If the indicated axis does not contain a scrollbar, then the animation timeline will be inactive (have zero progress). > **Note:** Each use of `scroll()` corresponds to its own unique instance of {{domxref("ScrollTimeline")}} in the [Web Animations API](/en-US/docs/Web/API/Web_Animations_API). ## Syntax ```css /* Function with no parameters set */ animation-timeline: scroll(); /* Values for selecting the scroller element */ animation-timeline: scroll(nearest); /* Default */ animation-timeline: scroll(root); animation-timeline: scroll(self); /* Values for selecting the axis */ animation-timeline: scroll(block); /* Default */ animation-timeline: scroll(inline); animation-timeline: scroll(y); animation-timeline: scroll(x); /* Examples that specify scroller and axis */ animation-timeline: scroll(block nearest); /* Default */ animation-timeline: scroll(inline root); animation-timeline: scroll(x self); ``` ### Parameters - scroller - : The value for indicating the scroller element that will provide the scroll progress timeline can be any one of the following: - `nearest` - : The nearest ancestor of the current element that has scrollbars on either axis. This is the default value. - `root` - : The root element of the document. - `self` - : The current element itself. - axis - : The scrollbar axis value can be any one of the following: - `block` - : The scrollbar on the block axis of the scroll container, which is the axis in the direction perpendicular to the flow of text within a line. For horizontal writing modes, such as standard English, this is the same as `y`, while for vertical writing modes, it is the same as `x`. This is the default value. - `inline` - : The scrollbar on the inline axis of the scroll container, which is the axis in the direction parallel to the flow of text in a line. For horizontal writing modes, this is the same as `x`, while for vertical writing modes, this is the same as `y`. - `y` - : The scrollbar on the vertical axis of the scroll container. - `x` - : The scrollbar on the horizontal axis of the scroll container. > **Note:** The scroller and axis values can be specified in any order. ### Formal syntax {{CSSSyntax}} ## Examples ### Setting an anonymous scroll progress timeline In this example, the `#square` element is animated using an anonymous scroll progress timeline, which is applied to the element to be animated using the `scroll()` function. 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. ```html <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:** `block` and `nearest` are actually the default parameter values, so we could have used just `scroll()`. ```css #square { background-color: deeppink; width: 100px; height: 100px; margin-top: 100px; position: absolute; bottom: 0; animation-name: rotateAnimation; animation-duration: 1ms; /* Firefox requires this to apply the animation */ 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 scroll progress timeline. ```css #container { height: 300px; overflow-y: scroll; position: relative; } #stretcher { height: 600px; } ``` #### Result Scroll to see the square element being animated. {{EmbedLiveSample("Setting an anonymous scroll progress timeline", "100%", "320px")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations) - [Using CSS animations](/en-US/docs/Web/CSS/CSS_animations/Using_CSS_animations) - [`animation-timeline`](/en-US/docs/Web/CSS/animation-timeline)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-right-color/index.md
--- title: border-right-color slug: Web/CSS/border-right-color page-type: css-property browser-compat: css.properties.border-right-color --- {{CSSRef}} The **`border-right-color`** CSS property sets the color of an element's right [border](/en-US/docs/Web/CSS/border). It can also be set with the shorthand CSS properties {{cssxref("border-color")}} or {{cssxref("border-right")}}. {{EmbedInteractiveExample("pages/css/border-right-color.html")}} ## Syntax ```css /* <color> values */ border-right-color: red; border-right-color: #ffbb00; border-right-color: rgb(255 0 0); border-right-color: hsl(100deg 50% 25% / 75%); border-right-color: currentcolor; border-right-color: transparent; /* Global values */ border-right-color: inherit; border-right-color: initial; border-right-color: revert; border-right-color: revert-layer; border-right-color: unset; ``` The `border-right-color` property is specified as a single value. ### Values - {{cssxref("&lt;color&gt;")}} - : The color of the right border. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### A simple div with a border #### HTML ```html <div class="mybox"> <p> This is a box with a border around it. Note which side of the box is <span class="redtext">red</span>. </p> </div> ``` #### CSS ```css .mybox { border: solid 0.3em gold; border-right-color: red; width: auto; } .redtext { color: red; } ``` #### Result {{EmbedLiveSample('A_simple_div_with_a_border')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - The border-related CSS shorthand properties: {{cssxref("border")}}, {{cssxref("border-right")}}, and {{cssxref("border-color")}}. - The color-related CSS properties for the other borders: {{cssxref("border-left-color")}}, {{cssxref("border-bottom-color")}}, and {{cssxref("border-top-color")}}. - The other border-related CSS properties applying to the same border: {{cssxref("border-right-style")}} and {{cssxref("border-right-width")}}. - The default [`currentcolor`](/en-US/docs/Web/CSS/color_value#currentcolor_keyword) color value.
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/cos/index.md
--- title: cos() slug: Web/CSS/cos page-type: css-function browser-compat: css.types.cos --- {{CSSRef}} The **`cos()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) is a trigonometric function that returns the cosine of a number, which is a value between `-1` and `1`. The function contains a single calculation that must resolve to either a {{cssxref("&lt;number&gt;")}} or an {{cssxref("&lt;angle&gt;")}} by interpreting the result of the argument as radians. That is, `cos(45deg)`, `cos(0.125turn)`, and `cos(3.14159 / 4)` all represent the same value, approximately `0.707`. ## Syntax ```css /* Single <angle> values */ width: calc(100px * cos(45deg)); width: calc(100px * cos(0.125turn)); width: calc(100px * cos(0.785398163rad)); /* Single <number> values */ width: calc(100px * cos(63.673)); width: calc(100px * cos(2 * 0.125)); /* Other values */ width: calc(100px * cos(pi)); width: calc(100px * cos(e / 2)); ``` ### Parameter The `cos(angle)` function accepts only one value as its parameter. - `angle` - : A calculation which resolves to a {{cssxref("&lt;number&gt;")}} or an {{cssxref("&lt;angle&gt;")}}. When specifying unitless numbers they are interpreted as a number of radians, representing an {{cssxref("&lt;angle&gt;")}}. ### Return value The cosine of an `angle` will always return a number between `βˆ’1` and `1`. - If `angle` is `infinity`, `-infinity`, or `NaN`, the result is `NaN`. ### Formal syntax {{CSSSyntax}} ## Examples ### Keep the size of a rotated box The `cos()` function can be used to keep the size of a rotated box. When the element is rotated using {{cssxref("transform-function/rotate", "rotate()")}}, it goes beyond its initial size. To fix this, we will use `cos()` to update the element size. For example, if you rotate a `100px`/`100px` square `45deg`, the diamond it creates will be wider and taller than the original square. To shrink the diamond into the box allotted for the original square, you would have to scale down the diamond using this formula: `width = height = 100px * cos(45deg) = 100px * 0.707 = 70.7px`. You need to also adjust the {{cssxref("transform-origin")}} and add {{cssxref("transform-function/translate", "translate()")}} to correct the position: #### HTML ```html <div class="original-square"></div> <div class="rotated-diamond"></div> <div class="rotated-scaled-diamond"></div> ``` #### CSS ```css hidden body { height: 100vh; display: flex; justify-content: center; align-items: center; gap: 50px; } ``` ```css div.original-square { width: 100px; height: 100px; background-color: blue; } div.rotated-diamond { width: 100px; height: 100px; background-color: red; transform: rotate(45deg); } div.rotated-scaled-diamond { width: calc(100px * cos(45deg)); height: calc(100px * cos(45deg)); margin: calc(100px / 4 * cos(45deg)); transform: rotate(45deg); transform-origin: center; background-color: green; } ``` #### Result {{EmbedLiveSample('Keep the size of a rotated box', '100%', '200px')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("sin")}} - {{CSSxRef("tan")}} - {{CSSxRef("asin")}} - {{CSSxRef("acos")}} - {{CSSxRef("atan")}} - {{CSSxRef("atan2")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_-moz-scrolled-page-sequence/index.md
--- title: "::-moz-scrolled-page-sequence" slug: Web/CSS/::-moz-scrolled-page-sequence page-type: css-pseudo-element status: - non-standard browser-compat: css.selectors.-moz-scrolled-page-sequence --- {{CSSRef}}{{non-standard_header}} The **`::-moz-scrolled-page-sequence`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) is a [Mozilla extension](/en-US/docs/Web/CSS/Mozilla_Extensions) that represents the background of a print preview. ## Syntax ```css ::-moz-scrolled-page-sequence { /* ... */ } ``` ## Specifications Not part of any standard. ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("::-moz-page")}} - {{CSSxRef("::-moz-page-sequence")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/view-timeline-name/index.md
--- title: view-timeline-name slug: Web/CSS/view-timeline-name page-type: css-property status: - experimental browser-compat: css.properties.view-timeline-name --- {{CSSRef}}{{SeeCompatTable}} The **`view-timeline-name`** [CSS](/en-US/docs/Web/CSS) property is used to define the name of a _named view progress timeline_, which is progressed through based on the change in visibility of an element (known as the _subject_) inside a scrollable element (_scroller_). `view-timeline` is set on the subject. The visibility of the subject inside the scroller is tracked β€” by default, the timeline is at 0% when the subject is first visible at one edge of the scroller and 100% when it reaches the opposite edge. The name is then referenced in an [`animation-timeline`](/en-US/docs/Web/CSS/animation-timeline) declaration to indicate the element that will be animated as the timeline progresses. This can be the subject element, but it doesn't have to be β€” you can animate a different element as the subject moves through the scrolling area. > **Note:** If the element does not overflow its container in the axis dimension or if the overflow is hidden or clipped, no timeline will be created. The {{cssxref("view-timeline-axis")}} and `view-timeline-name` properties can also be set using the [`view-timeline`](/en-US/docs/Web/CSS/scroll-timeline) shorthand property. ## Syntax ```css view-timeline-name: none; view-timeline-name: --custom_name_for_timeline; ``` ### Values Allowed values for `view-timeline-name` are: - `none` - : The timeline has no name. - `<dashed-ident>` - : An arbitrary custom identifier defining a name for a view progress timeline, which can then be referenced in an [`animation-timeline`](/en-US/docs/Web/CSS/animation-timeline) property. > **Note:** [`<dashed-ident>`](/en-US/docs/Web/CSS/dashed-ident) values must start with `--`, which helps avoid name clashes with standard CSS keywords. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Creating a named view progress timeline A view progress timeline named `--subjectReveal` is defined using the `view-timeline-name` property on a subject element with a `class` of `animation`. This is then set as the timeline for the same element using `animation-timeline: --subjectReveal;`. The result is that the subject element animates as it moves upwards through the document as it is scrolled. #### HTML The HTML for the example is shown below. ```html <div class="content"> <h1>Content</h1> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Risus quis varius quam quisque id. Et ligula ullamcorper malesuada proin libero nunc consequat interdum varius. Elit ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at augue. </p> <p> Dolor sed viverra ipsum nunc aliquet. Sed sed risus pretium quam vulputate dignissim. Tortor aliquam nulla facilisi cras. A erat nam at lectus urna duis convallis convallis. Nibh ipsum consequat nisl vel pretium lectus. Sagittis aliquam malesuada bibendum arcu vitae elementum. Malesuada bibendum arcu vitae elementum curabitur vitae nunc sed velit. </p> <div class="subject animation"></div> <p> Adipiscing enim eu turpis egestas pretium aenean pharetra magna ac. Arcu cursus vitae congue mauris rhoncus aenean vel. Sit amet cursus sit amet dictum. Augue neque gravida in fermentum et. Gravida rutrum quisque non tellus orci ac auctor augue mauris. Risus quis varius quam quisque id diam vel quam elementum. Nibh praesent tristique magna sit amet purus gravida quis. Duis ultricies lacus sed turpis tincidunt id aliquet. In egestas erat imperdiet sed euismod nisi. Eget egestas purus viverra accumsan in nisl nisi scelerisque. Netus et malesuada fames ac. </p> </div> ``` #### CSS The `subject` element and its containing `content` element are styled minimally, and the text content is given some basic font settings: ```css .subject { width: 300px; height: 200px; margin: 0 auto; background-color: deeppink; } .content { width: 75%; max-width: 800px; margin: 0 auto; } p, h1 { font-family: Arial, Helvetica, sans-serif; } h1 { font-size: 3rem; } p { font-size: 1.5rem; line-height: 1.5; } ``` The `<div>` with the class of `subject` is also given a class of `animation` β€” this is where `view-timeline-name` is set to define a named view progress timeline. It is also given an `animation-timeline` name with the same value to declare that this will be the element animated as the view progress timeline is progressed. Last, an animation is specified on the element that animates its opacity and scale, causing it to fade in and size up as it moves up the scroller. ```css .animation { view-timeline-name: --subjectReveal; animation-timeline: --subjectReveal; animation-name: appear; animation-fill-mode: both; animation-duration: 1ms; /* Firefox requires this to apply the animation */ } @keyframes appear { from { opacity: 0; transform: scaleX(0); } to { opacity: 1; transform: scaleX(1); } } ``` #### Result Scroll to see the subject element being animated. {{EmbedLiveSample("Creating a named view progress timeline", "100%", "480px")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`animation-timeline`](/en-US/docs/Web/CSS/animation-timeline) - {{cssxref("timeline-scope")}} - [`view-timeline`](/en-US/docs/Web/CSS/view-timeline), [`view-timeline-axis`](/en-US/docs/Web/CSS/view-timeline-axis) - [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_-moz-handler-blocked/index.md
--- title: ":-moz-handler-blocked" slug: Web/CSS/:-moz-handler-blocked page-type: css-pseudo-class status: - non-standard --- {{CSSRef}} {{Non-standard_header}} The **`:-moz-handler-blocked`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) is a [Mozilla extension](/en-US/docs/Web/CSS/Mozilla_Extensions) that matches elements that can't be displayed because their handlers have been blocked. > **Note:** This selector is mainly intended to be used by theme developers. ## Syntax ```css :-moz-handler-blocked { /* ... */ } ``` ## Specifications Not part of any standard. ## See also - {{ cssxref(":-moz-handler-crashed") }} - {{ cssxref(":-moz-handler-disabled") }}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_ruby_layout/index.md
--- title: CSS ruby layout slug: Web/CSS/CSS_ruby_layout page-type: css-module spec-urls: https://drafts.csswg.org/css-ruby/ --- {{CSSRef}} The **CSS ruby layout** module provides the rendering model and formatting controls related to the display of ruby annotation. Ruby annotation is a form of interlinear annotation, consisting of short runs of text alongside the base text. They are typically used in East Asian documents to indicate pronunciation or to provide a short annotation. ## Reference ### Properties - {{cssxref("ruby-align")}} - {{cssxref("ruby-position")}} ## Specifications {{Specifications}} ## See also - {{HTMLElement('ruby')}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/inset-inline-start/index.md
--- title: inset-inline-start slug: Web/CSS/inset-inline-start page-type: css-property browser-compat: css.properties.inset-inline-start --- {{CSSRef}} The **`inset-inline-start`** [CSS](/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 {{cssxref("top")}}, {{cssxref("right")}}, {{cssxref("bottom")}}, or {{cssxref("left")}} property depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. {{EmbedInteractiveExample("pages/css/inset-inline-start.html")}} ## Syntax ```css /* <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 {{cssxref("inset-inline-end")}} is {{cssxref("inset-inline")}}. ### Values The `inset-inline-start` property takes the same values as the {{cssxref("left")}} property. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting inline start offset #### HTML ```html <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ```css div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; position: relative; inset-inline-start: 20px; background-color: #c8c800; } ``` #### Result {{EmbedLiveSample("Setting_inline_start_offset", 140, 140)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - The properties which defines other insets: {{cssxref("inset-block-start")}}, {{cssxref("inset-block-end")}}, and {{cssxref("inset-inline-end")}} - The mapped physical properties: {{cssxref("top")}}, {{cssxref("right")}}, {{cssxref("bottom")}}, and {{cssxref("left")}} - {{cssxref("writing-mode")}}, {{cssxref("direction")}}, {{cssxref("text-orientation")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_active/index.md
--- title: ":active" slug: Web/CSS/:active page-type: css-pseudo-class browser-compat: css.selectors.active --- {{CSSRef}} The **`:active`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/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. {{EmbedInteractiveExample("pages/tabbed/pseudo-class-active.html", "tabbed-shorter")}} The `:active` pseudo-class is commonly used on {{HTMLElement("a")}} and {{HTMLElement("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 {{HTMLElement("label")}}. Styles defined by the `:active` pseudo-class will be overridden by any subsequent link-related pseudo-class ({{cssxref(":link")}}, {{cssxref(":hover")}}, or {{cssxref(":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 ```css :active { /* ... */ } ``` ## Examples ### Active links #### HTML ```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 ```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 {{EmbedLiveSample('Active_links')}} ### Active form elements #### HTML ```html <form> <label for="my-button">My button: </label> <button id="my-button" type="button">Try Clicking Me or My Label!</button> </form> ``` #### CSS ```css form :active { color: red; } form button { background: white; } ``` #### Result {{EmbedLiveSample('Active_form_elements')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Link-related pseudo-classes: {{cssxref(":link")}}, {{cssxref(":visited")}}, and {{cssxref(":hover")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-width/index.md
--- title: border-width slug: Web/CSS/border-width page-type: css-shorthand-property browser-compat: css.properties.border-width --- {{CSSRef}} The **`border-width`** [shorthand](/en-US/docs/Web/CSS/Shorthand_properties) [CSS](/en-US/docs/Web/CSS) property sets the width of an element's border. {{EmbedInteractiveExample("pages/css/border-width.html")}} ## Constituent properties This property is a shorthand for the following CSS properties: - [`border-bottom-width`](/en-US/docs/Web/CSS/border-bottom-width) - [`border-left-width`](/en-US/docs/Web/CSS/border-left-width) - [`border-right-width`](/en-US/docs/Web/CSS/border-right-width) - [`border-top-width`](/en-US/docs/Web/CSS/border-top-width) ## Syntax ```css /* Keyword values */ border-width: thin; border-width: medium; border-width: thick; /* <length> values */ border-width: 4px; border-width: 1.2rem; /* top and bottom | left and right */ border-width: 2px 1.5em; /* top | left and right | bottom */ border-width: 1px 2em 1.5cm; /* top | right | bottom | left */ border-width: 1px 2em 0 4rem; /* Global values */ border-width: inherit; border-width: initial; border-width: revert; border-width: revert-layer; border-width: unset; ``` The `border-width` property may be specified using one, two, three, or four values. - 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 - `<line-width>` - : Defines the width of the border, either as an explicit nonnegative {{cssxref("&lt;length&gt;")}} 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 {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### A mix of values and lengths #### HTML ```html <p id="one-value">one value: 6px wide border on all 4 sides</p> <p id="two-values"> two different values: 2px wide top and bottom border, 10px wide right and left border </p> <p id="three-values"> three different values: 0.3em top, 9px bottom, and zero width right and left </p> <p id="four-values"> four different values: "thin" top, "medium" right, "thick" bottom, and 1em left </p> ``` #### CSS ```css #one-value { border: ridge #ccc; border-width: 6px; } #two-values { border: solid red; border-width: 2px 10px; } #three-values { border: dotted orange; border-width: 0.3em 0 9px; } #four-values { border: solid lightgreen; border-width: thin medium thick 1em; } p { width: auto; margin: 0.25em; padding: 0.25em; } ``` #### Result {{ EmbedLiveSample('A_mix_of_values_and_lengths', 320, 320) }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - The border-related shorthand properties: {{Cssxref("border")}}, {{Cssxref("border-style")}}, {{Cssxref("border-color")}} - The border-width-related properties: {{Cssxref("border-bottom-width")}}, {{Cssxref("border-left-width")}}, {{Cssxref("border-right-width")}}, {{Cssxref("border-top-width")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/-webkit-box-reflect/index.md
--- title: "-webkit-box-reflect" slug: Web/CSS/-webkit-box-reflect page-type: css-property status: - non-standard browser-compat: css.properties.-webkit-box-reflect --- {{CSSRef}}{{Non-standard_Header}} The **`-webkit-box-reflect`** [CSS](/en-US/docs/Web/CSS) property lets you reflect the content of an element in one specific direction. ## Syntax ```css /* Direction values */ -webkit-box-reflect: above; -webkit-box-reflect: below; -webkit-box-reflect: left; -webkit-box-reflect: right; /* Offset value */ -webkit-box-reflect: below 10px; /* Mask value */ -webkit-box-reflect: below 0 linear-gradient(transparent, white); /* Global values */ -webkit-box-reflect: inherit; -webkit-box-reflect: initial; -webkit-box-reflect: revert; -webkit-box-reflect: revert-layer; -webkit-box-reflect: unset; ``` ### Values - `above`_,_ `below`_,_ `right`_,_ `left` - : Are keywords indicating in which direction the reflection is to happen. - {{CSSxRef("&lt;length&gt;")}} - : Indicates the size of the reflection. - {{CSSxRef("&lt;image&gt;")}} - : Describes the mask to be applied to the reflection. ## Formal definition {{CSSInfo}} ## Formal syntax ```plain -webkit-box-reflect = [ above | below | right | left ]? <length>? <image>? ``` ## Specifications Not part of any standard. The standard way to do reflection in CSS is to use the CSS {{CSSxRef("element", "element()")}} function. ## Browser compatibility {{Compat}} ## See also - The Apple [documentation](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html). - The Webkit [specification](https://webkit.org/blog/182/css-reflections/). - Lea Verou's article on reflection using [CSS features on the standard track](https://lea.verou.me/2011/06/css-reflections-for-firefox-with-moz-element-and-svg-masks/).
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/outline-color/index.md
--- title: outline-color slug: Web/CSS/outline-color page-type: css-property browser-compat: css.properties.outline-color --- {{CSSRef}} The **`outline-color`** CSS property sets the color of an element's outline. {{EmbedInteractiveExample("pages/css/outline-color.html")}} ## Syntax ```css /* <color> values */ outline-color: #f92525; outline-color: rgb(30 222 121); outline-color: blue; /* Keyword value */ outline-color: auto; /* Global values */ outline-color: inherit; outline-color: initial; outline-color: revert; outline-color: revert-layer; outline-color: unset; ``` The `outline-color` property is specified as any one of the values listed below. ### Values - {{cssxref("&lt;color&gt;")}} - : The color of the outline, specified as a `<color>`. - `auto` {{Experimental_Inline}} - : Computes to [`currentcolor`](/en-US/docs/Web/CSS/color_value#currentcolor_keyword) unless [`outline-style`](/en-US/docs/Web/CSS/outline-style) is set to `auto` then it computes to the [accent color](/en-US/docs/Web/CSS/accent-color). ## Description An outline is a line that is drawn around an element, outside the {{cssxref("border")}}. Unlike the element's border, the outline is drawn outside the element's frame, and may overlap other content. The border, on the other hand, will actually alter the page's layout to ensure that it fits without overlapping anything else (unless you explicitly set it to overlap). It is often more convenient to use the shorthand property {{cssxref("outline")}} when defining the appearance of an outline. ## Accessibility concerns Custom [focus styles](/en-US/docs/Web/CSS/:focus) commonly involve making adjustments to the {{cssxref("outline")}} property. If the color of the outline is adjusted, it is important to ensure that the contrast ratio between it and the background the outline is placed over is high enough that people experiencing low vision conditions will be able to perceive it. 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](/en-US/docs/Web/CSS/font-weight) or larger, or 24px or larger. - [WebAIM: Color Contrast Checker](https://webaim.org/resources/contrastchecker/) - [MDN Understanding WCAG, Guideline 1.4 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background) - [Understanding Success Criterion 1.4.3 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html) ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting a solid blue outline #### HTML ```html <p>My outline is blue, as you can see.</p> ``` #### CSS ```css p { outline: 2px solid; /* Set the outline width and style */ outline-color: #0000ff; /* Make the outline blue */ margin: 5px; } ``` #### Result {{ EmbedLiveSample('Setting_a_solid_blue_outline') }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("outline")}} - {{cssxref("outline-color")}} - {{cssxref("outline-style")}} - {{cssxref("outline-width")}} - The {{cssxref("&lt;color&gt;")}} data type - Other color-related properties: {{cssxref("color")}}, {{cssxref("background-color")}}, {{cssxref("border-color")}}, {{cssxref("text-decoration-color")}}, {{cssxref("text-emphasis-color")}}, {{cssxref("text-shadow")}}, {{cssxref("caret-color")}}, and {{cssxref("column-rule-color")}} - [Applying color to HTML elements using CSS](/en-US/docs/Web/CSS/CSS_colors/Applying_color)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-end-end-radius/index.md
--- title: border-end-end-radius slug: Web/CSS/border-end-end-radius page-type: css-property browser-compat: css.properties.border-end-end-radius --- {{CSSRef}} The **`border-end-end-radius`** [CSS](/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 {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. This is useful when building styles to work regardless of the [text orientation](/en-US/docs/Web/CSS/text-orientation) and [writing mode](/en-US/docs/Web/CSS/CSS_writing_modes). {{EmbedInteractiveExample("pages/css/border-end-end-radius.html")}} 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 {{CSSxRef("border-bottom-right-radius")}} property. ## Syntax ```css /* <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 {{cssxref("&lt;length&gt;")}} 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 {{CSSInfo}} ## Formal syntax {{CSSSyntax}} ## Examples ### Border radius with vertical text #### HTML ```html <div> <p class="exampleText">Example</p> </div> ``` #### CSS ```css 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; } ``` #### Result {{EmbedLiveSample("Border_radius_with_vertical_text", 140, 140)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS Logical Properties and Values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values) - The mapped physical property: {{CSSxRef("border-bottom-right-radius")}} - {{CSSxRef("writing-mode")}}, {{CSSxRef("direction")}}, {{CSSxRef("text-orientation")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/table-layout/index.md
--- title: table-layout slug: Web/CSS/table-layout page-type: css-property browser-compat: css.properties.table-layout --- {{CSSRef}} The **`table-layout`** CSS property sets the algorithm used to lay out {{htmlelement("table")}} cells, rows, and columns. {{EmbedInteractiveExample("pages/css/table-layout.html")}} ## Syntax ```css /* 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` - : The automatic table layout algorithm is used. The widths of the table and its cells are adjusted to fit the content. Most browsers use this algorithm by default. - `fixed` - : The fixed table layout algorithm is used. When using this keyword, the table's width _needs to be specified explicitly_ using the [`width`](/en-US/docs/Web/CSS/width) property. If the value of the `width` property is set to `auto`or is not specified, the browser uses the automatic table layout algorithm, in which case the `fixed` value has no effect.\ The fixed table layout algorithm is faster than the automatic layout algorithm because the horizontal layout of the table depends only on the table's width, the width of the columns, and borders or cell spacing. The horizontal layout doesn't depend on the contents of the cells because it depends only on explicitly set widths. In the fixed table layout algorithm, the width of each column is determined as follows: - A column element with explicit width sets the width for that column. - Otherwise, a cell in the first row with explicit width determines the width for that column. - Otherwise, the column gets the width from the shared remaining horizontal space. With this algorithm 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 {{Cssxref("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 {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Fixed-width tables with text-overflow This example uses a fixed table layout, combined with the {{cssxref("width")}} property, to restrict the table's width. The {{cssxref("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 ```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 ```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 {{EmbedLiveSample('Fixed-width_tables_with_text-overflow')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`<table>`](/en-US/docs/Web/HTML/Element/table)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/text-orientation/index.md
--- title: text-orientation slug: Web/CSS/text-orientation page-type: css-property browser-compat: css.properties.text-orientation --- {{CSSRef}} The **`text-orientation`** [CSS](/en-US/docs/Web/CSS) property sets the orientation of the text characters in a line. It only affects text in vertical mode (when {{cssxref("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. {{EmbedInteractiveExample("pages/css/text-orientation.html")}} ## Syntax ```css /* 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 {{cssxref("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 {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### HTML ```html <p>Lorem ipsum dolet semper quisquam.</p> ``` ### CSS ```css p { writing-mode: vertical-rl; text-orientation: upright; } ``` ### Result {{EmbedLiveSample('Examples')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - The other vertical-script related CSS properties: {{cssxref("writing-mode")}}, {{cssxref("text-combine-upright")}}, and {{cssxref("unicode-bidi")}}. - [CSS Logical properties](/en-US/docs/Web/CSS/CSS_logical_properties_and_values) - [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>
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/column-gap/index.md
--- title: column-gap slug: Web/CSS/column-gap page-type: css-property browser-compat: css.properties.column-gap --- {{CSSRef}} The **`column-gap`** [CSS](/en-US/docs/Web/CSS) property sets the size of the gap ({{glossary("Gutters","gutter")}}) between an element's columns. Initially a part of [Multi-column Layout](/en-US/docs/Web/CSS/CSS_multicol_layout), the definition of `column-gap` has been broadened to include multiple layout methods. Now specified in [Box Alignment](/en-US/docs/Web/CSS/CSS_box_alignment), it may be used in Multi-column, Flexible Box, and Grid layouts. Early versions of the specification called this property `grid-column-gap`, and to maintain compatibility with legacy websites, browsers will still accept `grid-column-gap` as an alias for `column-gap`. {{EmbedInteractiveExample("pages/css/column-gap.html")}} ## Syntax ```css /* 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. - {{CSSxRef("&lt;length&gt;")}} - : The size of the gap between columns, defined as a {{CSSxRef("&lt;length&gt;")}}. The {{CSSxRef("&lt;length&gt;")}} property's value must be non-negative. - {{CSSxRef("&lt;percentage&gt;")}} - : The size of the gap between columns, defined as a {{CSSxRef("&lt;percentage&gt;")}}. The {{CSSxRef("&lt;percentage&gt;")}} property's value must be non-negative. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Flex layout In this example, a flex container contains six flex items of two different widths (`200px` and `300px`), creating flex items that are not laid out as a grid. The `column-gap` property is used to add horizontal space between the adjacent flex items. #### HTML ```html <div class="flexbox"> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> </div> ``` #### CSS To create a flex container, we set its {{cssxref("display")}} property value to `flex`. We then use the {{cssxref("flex-flow")}} shorthand property to set the {{cssxref("flex-direction")}} to row (the default) and {{cssxref("flex-wrap")}} to `wrap`, allowing the flex items to flow onto new lines if needed. By default, flex items stretch to be as tall as their container. By setting a {{cssxref("height")}}, even the empty flex items will be `100px` tall. To better demonstrate the `column-gap` property, the flex items in this example have two different width values. The width of the flex items is set within the `<div>` flex items. We use the {{cssxref("flex-basis")}} component of the {{cssxref("flex")}} shorthand property to make all the flex items `200px` wide. We then target every third flex item by using the {{cssxref(":nth-of-type", ":nth-of-type(3n)")}} selector, widening them to `300px`. The `column-gap` value is set as `20px` on the flex container to create a `20px` gap between the adjacent flex items in each row. ```css .flexbox { display: flex; flex-flow: row wrap; height: 100px; column-gap: 20px; } .flexbox > div { border: 1px solid green; background-color: lime; flex: 200px; } div:nth-of-type(3n) { flex: 300px; } ``` #### Result {{EmbedLiveSample("Flex_layout", "auto", "220px")}} > **Note:** While there is horizontal space between adjacent flex items in each flex row, there is no space between the rows. To set vertical space between flex rows, you can specify a non-zero value for the {{cssxref("row-gap")}} property. The {{cssxref("gap")}} shorthand property is also available to set both the `row-gap` and `column-gap` in one declaration, in that order. ### Grid layout #### HTML ```html <div id="grid"> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> </div> ``` #### CSS ```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 {{EmbedLiveSample("Grid_layout", "auto", "220px")}} ### Multi-column layout #### HTML ```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 ```css .content-box { column-count: 3; column-gap: 40px; } ``` #### Result {{EmbedLiveSample("Multi-column_layout", "auto", "120px")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Related CSS properties: {{CSSxRef("row-gap")}}, {{CSSxRef("gap")}} - Grid Layout Guide: _[Basic concepts of grid layout - Gutters](/en-US/docs/Web/CSS/CSS_grid_layout/Basic_concepts_of_grid_layout#gutters)_ - Multi-column Layout Guide: _[Styling Columns](/en-US/docs/Web/CSS/CSS_multicol_layout/Styling_columns)_
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_transitions/index.md
--- title: CSS transitions slug: Web/CSS/CSS_transitions page-type: css-module spec-urls: https://drafts.csswg.org/css-transitions/ --- {{CSSRef}} The **CSS transitions** module lets you create gradual transitions between the values of specific CSS properties. The behavior of these transitions can be controlled by specifying their easing function, duration, and other attributes. ## Reference ### Properties - {{cssxref("transition")}} - {{cssxref("transition-delay")}} - {{cssxref("transition-duration")}} - {{cssxref("transition-property")}} - {{cssxref("transition-timing-function")}} ### At rules - {{cssxref("@starting-style")}} ## Guides - [Using CSS transitions](/en-US/docs/Web/CSS/CSS_transitions/Using_CSS_transitions) - : Step-by-step tutorial about how to create transitions using CSS. This article describes each relevant CSS property and explains how they interact with each other. ## Specifications {{Specifications}} ## See also - Related to CSS transitions, [CSS animations](/en-US/docs/Web/CSS/CSS_animations) provide finer control over animated properties.
0
data/mdn-content/files/en-us/web/css/css_transitions
data/mdn-content/files/en-us/web/css/css_transitions/using_css_transitions/index.md
--- title: Using CSS transitions slug: Web/CSS/CSS_transitions/Using_CSS_transitions page-type: guide spec-urls: https://drafts.csswg.org/css-transitions/ --- {{CSSRef}} **CSS transitions** provide a way to control animation speed when changing CSS properties. Instead of having property changes take effect immediately, you can cause the changes in a property to take place over a period of time. For example, if you change the color of an element from white to black, usually the change is instantaneous. With CSS transitions enabled, changes occur at time intervals that follow an acceleration curve, all of which can be customized. Animations that involve transitioning between two states are often called _implicit transitions_ as the states in between the start and final states are implicitly defined by the browser. ![A CSS transition tells the browser to draw the intermediate states between the initial and final states, showing the user a smooth transitions.](transitionsprinciple.png) CSS transitions let you decide which properties to animate (by [_listing them explicitly_](/en-US/docs/Web/CSS/transition-property)), when the animation will start (by setting a [_delay_](/en-US/docs/Web/CSS/transition-delay)), how long the transition will last (by setting a [_duration_](/en-US/docs/Web/CSS/transition-duration)), and how the transition will run (by defining an [_easing function_](/en-US/docs/Web/CSS/transition-timing-function), e.g., linearly or quick at the beginning, slow at the end). ## Which CSS properties can be transitioned? The Web author can define which property has to be animated and in which way. This allows the creation of complex transitions. However, some properties are [not animatable](/en-US/docs/Web/CSS/CSS_animated_properties) as it doesn't make sense to animate them. > **Note:** The `auto` value is often a very complex case. The specification recommends not animating from and to `auto`. Some user agents, like those based on Gecko, implement this requirement and others, like those based on WebKit, are less strict. Using animations with `auto` may lead to unpredictable results, depending on the browser and its version, and should be avoided. ## Defining transitions CSS Transitions are controlled using the shorthand {{cssxref("transition")}} property. This is the best way to configure transitions, as it makes it easier to avoid out of sync parameters, which can be very frustrating to have to spend lots of time debugging in CSS. You can control the individual components of the transition with the following sub-properties: - {{cssxref("transition-property")}} - : Specifies the name or names of the CSS properties to which transitions should be applied. Only properties listed here are animated during transitions; changes to all other properties occur instantaneously as usual. - {{cssxref("transition-duration")}} - : Specifies the duration over which transitions should occur. You can specify a single duration that applies to all properties during the transition, or multiple values to allow each property to transition over a different period of time. - {{cssxref("transition-timing-function")}} - : Specifies a function to define how intermediate values for properties are computed. _Easing functions_ determine how intermediate values of the transition are calculated. Most [easing functions](/en-US/docs/Web/CSS/easing-function) can be specified by providing the graph of the corresponding function, as defined by four points defining a cubic bezier. You can also choose easing from [Easing functions cheat sheet](https://easings.net/). - {{cssxref("transition-delay")}} - : Defines how long to wait between the time a property is changed and the transition actually begins. The `transition` shorthand CSS syntax is written as follows: ```css div { transition: <property> <duration> <timing-function> <delay>; } ``` ## Examples ### Basic example This example performs a four-second font size transition with a two-second delay between the time the user mouses over the element and the beginning of the animation effect: ```css #delay { font-size: 14px; transition-property: font-size; transition-duration: 4s; transition-delay: 2s; } #delay:hover { font-size: 36px; } ``` ### Multiple animated properties example ```html hidden <body> <p> The box below combines transitions for: width, height, background-color, rotate. Hover over the box to see these properties animated. </p> <div class="box">Sample</div> </body> ``` #### CSS ```css .box { border-style: solid; border-width: 1px; display: block; width: 100px; height: 100px; background-color: #0000ff; transition: width 2s, height 2s, background-color 2s, rotate 2s; } .box:hover { background-color: #ffcccc; width: 200px; height: 200px; rotate: 180deg; } ``` {{EmbedLiveSample('Multiple_animated_properties_example', 600, 300)}} ### When property value lists are of different lengths If any property's list of values is shorter than the others, its values are repeated to make them match. For example: ```css div { transition-property: opacity, left, top, height; transition-duration: 3s, 5s; } ``` This is treated as if it were: ```css div { transition-property: opacity, left, top, height; transition-duration: 3s, 5s, 3s, 5s; } ``` Similarly, if any property's value list is longer than that for {{cssxref("transition-property")}}, it's truncated, so if you have the following CSS: ```css div { transition-property: opacity, left; transition-duration: 3s, 5s, 2s, 1s; } ``` This gets interpreted as: ```css div { transition-property: opacity, left; transition-duration: 3s, 5s; } ``` ### Using transitions when highlighting menus A common use of CSS is to highlight items in a menu as the user hovers the mouse cursor over them. It's easy to use transitions to make the effect even more attractive. First, we set up the menu using HTML: ```html <nav> <a href="#">Home</a> <a href="#">About</a> <a href="#">Contact Us</a> <a href="#">Links</a> </nav> ``` Then we build the CSS to implement the look and feel of our menu: ```css nav { display: flex; gap: 0.5rem; } a { flex: 1; background-color: #333; color: #fff; border: 1px solid; padding: 0.5rem; text-align: center; text-decoration: none; transition: all 0.5s ease-out; } a:hover, a:focus { background-color: #fff; color: #333; } ``` This CSS establishes the look of the menu, with the background and text colors both changing when the element is in its {{cssxref(":hover")}} and {{cssxref(":focus")}} states: {{EmbedLiveSample("Using transitions when highlighting menus")}} ### Transitioning display and content-visibility This example demonstrates how [`display`](/en-US/docs/Web/CSS/display) and [`content-visibility`](/en-US/docs/Web/CSS/content-visibility) can be transitioned. This behavior is useful for creating entry/exit animations where you want to for example remove a container from the DOM with `display: none`, but have it fade out with [`opacity`](/en-US/docs/Web/CSS/opacity) rather than disappearing immediately. Supporting browsers transition `display` and `content-visibility` with a variation on the [discrete animation type](/en-US/docs/Web/CSS/CSS_animated_properties#discrete). This generally means that properties will flip between two values 50% through animating between the two. There is an exception, however, which is when animating to/from `display: none` or `content-visibility: hidden`. In this case, the browser will flip between the two values so that the transitioned content is shown for the entire animation duration. So for example: - When animating `display` from `none` to `block` (or another visible `display` value), the value will flip to `block` at `0%` of the animation duration so it is visible throughout. - When animating `display` from `block` (or another visible `display` value) to `none`, the value will flip to `none` at `100%` of the animation duration so it is visible throughout. When transitioning these properties [`transition-behavior: allow-discrete`](/en-US/docs/Web/CSS/transition-behavior) needs to be set on the transitions. This effectively enables `display`/`content-visibility` transitions. When transitioning `display`, [`@starting-style`](/en-US/docs/Web/CSS/@starting-style) is needed to provide a set of starting values for properties set on an element that you want to transition from when the element receives its first style update. This is needed to avoid unexpected behavior. By default, CSS transitions are not triggered on elements' first style updates when they first appear in the DOM, which includes when `display` changes from `none` to another state. `content-visibility` animations do not need starting values specified in a `@starting-style` block. This is because `content-visibility` doesn't hide an element from the DOM like `display` does: it just skips rendering the element's content. #### HTML The HTML contains two {{htmlelement("p")}} elements with a {{htmlelement("div")}} in between that we will animate from `display` `none` to `block`. ```html <p> Click anywhere on the screen or press any key to toggle the <code>&lt;div&gt;</code> between hidden and showing. </p> <div> This is a <code>&lt;div&gt;</code> element that transitions between <code>display: none; opacity: 0</code> and <code>display: block; opacity: 1</code>. Neat, huh? </div> <p> This is another paragraph to show that <code>display: none; </code> is being applied and removed on the above <code>&lt;div&gt; </code>. If only its <code>opacity</code> was being changed, it would always take up the space in the DOM. </p> ``` #### CSS ```css html { height: 100vh; } div { font-size: 1.6rem; padding: 20px; border: 3px solid red; border-radius: 20px; width: 480px; display: none; opacity: 0; transition: opacity 1s, display 1s allow-discrete; /* Equivalent to transition: all 1s allow-discrete; */ } .showing { opacity: 1; display: block; } @starting-style { .showing { opacity: 0; } } ``` Note the `@starting-style` block used to specify the starting style for the transition, and the inclusion of the `display` property in the transitions list, with `allow-discrete` set on it. #### JavaScript Finally, we include a bit of JavaScript to set up event listeners to trigger the transition (via the `showing` class). ```js const divElem = document.querySelector("div"); const htmlElem = document.querySelector(":root"); htmlElem.addEventListener("click", showHide); document.addEventListener("keydown", showHide); function showHide() { divElem.classList.toggle("showing"); } ``` #### Result The code renders as follows: {{ EmbedLiveSample("Transitioning display and content-visibility", "100%", "350") }} ## JavaScript examples > **Note:** Care should be taken when using a transition immediately after: > > - adding the element to the DOM using `.appendChild()` > - removing an element's `display: none;` property. > > This is treated as if the initial state had never occurred and the element was always in its final state. The easy way to overcome this limitation is to apply a `setTimeout()` of a handful of milliseconds before changing the CSS property you intend to transition to. ### Using transitions to make JavaScript functionality smooth Transitions are a great tool to make things look much smoother without having to do anything to your JavaScript functionality. Take the following example. ```html <p>Click anywhere to move the ball</p> <div id="foo" class="ball"></div> ``` Using JavaScript you can make the effect of moving the ball to a certain position happen: ```js const f = document.getElementById("foo"); document.addEventListener( "click", (ev) => { f.style.transform = `translateY(${ev.clientY - 25}px)`; f.style.transform += `translateX(${ev.clientX - 25}px)`; }, false, ); ``` With CSS you can make it smooth without any extra effort. Add a transition to the element and any change will happen smoothly: ```css .ball { border-radius: 25px; width: 50px; height: 50px; background: #c00; position: absolute; top: 0; left: 0; transition: transform 1s; } ``` {{EmbedGHLiveSample("css-examples/transitions/js-transitions.html", '100%', 500)}} ### Detecting the start and completion of a transition You can use the {{domxref("Element/transitionend_event", "transitionend")}} event to detect that an animation has finished running. This is a {{domxref("TransitionEvent")}} object, which has two added properties beyond a typical {{domxref("Event")}} object: - `propertyName` - : A string indicating the name of the CSS property whose transition completed. - `elapsedTime` - : A float indicating the number of seconds the transition had been running at the time the event fired. This value isn't affected by the value of {{cssxref("transition-delay")}}. As usual, you can use the {{domxref("EventTarget.addEventListener", "addEventListener()")}} method to monitor for this event: ```js el.addEventListener("transitionend", updateTransition, true); ``` You detect the beginning of a transition using {{domxref("Element/transitionrun_event", "transitionrun")}} (fires before any delay) and {{domxref("Element/transitionstart_event", "transitionstart")}} (fires after any delay), in the same kind of fashion: ```js el.addEventListener("transitionrun", signalStart, true); el.addEventListener("transitionstart", signalStart, true); ``` > **Note:** The `transitionend` event doesn't fire if the transition is aborted before the transition is completed because either the element is made {{cssxref("display")}}`: none` or the animating property's value is changed. ## Specifications {{Specifications}} ## See also - The {{domxref("TransitionEvent")}} interface and the {{domxref("Element/transitionend_event", "transitionend")}} event - [Using CSS animations](/en-US/docs/Web/CSS/CSS_animations/Using_CSS_animations)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_counter_styles/index.md
--- title: CSS counter styles slug: Web/CSS/CSS_counter_styles page-type: css-module spec-urls: https://drafts.csswg.org/css-counter-styles/ --- {{CSSRef}} The **CSS counter styles** module lets you define your own counter styles to manage the appearance of [markers](/en-US/docs/Web/CSS/::marker) in lists and counters in [generated content](/en-US/docs/Web/CSS/CSS_generated_content). It also enables you to extend native browser list styles with your own customizations. While we think of counters as numbers, they are actually strings with components that can be incremented. The counter styles module defines the `@counter-style` rule with ten descriptors, which enable developers to precisely define how counters are converted into strings. This module enables defining which characters to use for the counter bullets, the prefix to put before the counter and postfix that comes after, along with how to handle negative values. The descriptors can also set a range to limit the values a counter style can handle, while also providing fallback styles for when the counter value falls outside the defined range or otherwise can't render the counter value. The module also enables defining how the counter is read out loud by speech synthesizers. ## Reference ### Properties No properties are defined in this module ### Functions - {{cssxref("symbols", "symbols()")}} ### Data types - [`<counter-style-name>`](/en-US/docs/Web/CSS/@counter-style#counter-style-name) - [`<symbol>`](/en-US/docs/Web/CSS/@counter-style/symbols#values) - [`<symbols-type>`](/en-US/docs/Web/CSS/symbols#syntax) ### At-rules and descriptors - {{cssxref("@counter-style")}} - {{cssxref("@counter-style/system","system")}} - {{cssxref("@counter-style/symbols", "symbols")}} - {{cssxref("@counter-style/additive-symbols", "additive-symbols")}} - {{cssxref("@counter-style/negative", "negative")}} - {{cssxref("@counter-style/prefix", "prefix")}} - {{cssxref("@counter-style/suffix", "suffix")}} - {{cssxref("@counter-style/range", "range")}} - {{cssxref("@counter-style/pad", "pad")}} - {{cssxref("@counter-style/speak-as", "speak-as")}} - {{cssxref("@counter-style/fallback", "fallback")}} ### Interfaces and APIs - [CSS counter styles](/en-US/docs/Web/API/CSS_Counter_Styles) API - {{domxref("CSSCounterStyleRule")}} interface ## Guides - [Using CSS counters](/en-US/docs/Web/CSS/CSS_counter_styles/Using_CSS_counters) - : Describes how to use counters to number any HTML element or to perform complex counting. ## Related concepts [CSS lists and counters](/en-US/docs/Web/CSS/CSS_lists) module: - {{cssxref("counter-increment")}} property - {{cssxref("counter-reset")}} property - {{cssxref("counter-set")}} property - {{cssxref("list-style-type")}} property - {{cssxref("list-style")}} shorthand property - {{cssxref("counter", "counter()")}} function - {{cssxref("counters", "counters()")}} function [CSS pseudo-elements](/en-US/docs/Web/CSS/CSS_pseudo-elements) module: - {{cssxref("::after")}} pseudo-element - {{cssxref("::before")}} pseudo-element - {{cssxref("::marker")}} pseudo-element [CSS generated content](/en-US/docs/Web/CSS/CSS_generated_content) - {{cssxref("content")}} property ## Specifications {{Specifications}} ## See also - [CSS counter styles](/en-US/docs/Web/API/CSS_Counter_Styles) API - [CSS lists and counters](/en-US/docs/Web/CSS/CSS_lists) module - [CSS pseudo-elements](/en-US/docs/Web/CSS/CSS_pseudo-elements) module - [CSS generated content](/en-US/docs/Web/CSS/CSS_generated_content) module - [Ready-made counter styles](https://w3c.github.io/predefined-counter-styles/#builtins) via W3C (2023)
0
data/mdn-content/files/en-us/web/css/css_counter_styles
data/mdn-content/files/en-us/web/css/css_counter_styles/using_css_counters/index.md
--- title: Using CSS counters slug: Web/CSS/CSS_counter_styles/Using_CSS_counters page-type: guide spec-urls: https://drafts.csswg.org/css-lists/#auto-numbering --- {{CSSRef}} **CSS counters** let you adjust the appearance of content based on its location in a document. For example, you can use counters to automatically number the headings in a webpage, or to change the numbering on ordered lists. Counters are, in essence, variables maintained by CSS whose values may be incremented or decremented by CSS rules that track how many times they're used. You can define your own named counters, and you can also manipulate the `list-item` counter that is created by default for all ordered lists. ## Using counters To use a counter it must first be initialized to a value with the {{cssxref("counter-reset")}} property. The counter's value can then be increased or decreased using {{cssxref("counter-increment")}} property. The current value of a counter is displayed using the {{cssxref("counter", "counter()")}} or {{cssxref("counters", "counters()")}} function, typically within a [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) {{CSSxRef("content")}} property. Counters can only be set, reset, or incremented in elements that generate boxes. For example, if an element is set to `display: none` then any counter operation on that element will be ignored. The properties of counters can be scoped to specific elements using style containment which is described in more detail in the {{cssxref("contain")}} property. ### Manipulating a counter's value To use a CSS counter, it must first be initialized to a value with the {{cssxref("counter-reset")}} property. The property can also be used to change the counter value to any specific number. Below we initialize a counter named `section` to the default value (0). ```css counter-reset: section; ``` You can also initialize multiple counters, optionally specifying an initial value for each. Below we initialize the `section` and `topic` counters to the default value, and the `page` counter to 3. ```css counter-reset: section page 3 topic; ``` Once initialized, a counter's value can be increased or decreased using {{cssxref("counter-increment")}}. For example, the following declaration would increment the `section` counter by one on every `h3` tag. ```css h3::before { counter-increment: section; /* Increment the value of section counter by 1 */ } ``` You can specify the value to increment or decrement the counter after the counter name, using a positive or negative number. The counter's name must not be `none`, `inherit`, or `initial`; otherwise the declaration is ignored. ### Displaying a counter The value of a counter can be displayed using either the {{cssxref("counter", "counter()")}} or {{cssxref("counters", "counters()")}} function in a {{cssxref("content")}} property. For example, the following declaration uses `counter()` to prefix each `h3` heading with the text `Section <number>:`, where `<number>` is the value of the count in decimal (the default display style): ```css h3::before { counter-increment: section; /* Increment the value of section counter by 1 */ content: "Section " counter(section) ": "; /* Display counter value in default style (decimal) */ } ``` The {{cssxref("counter", "counter()")}} function is used when the numbering of nesting levels does not include the context of parent levels. For example, here each nested level restarts from one: ```plain 1 One 1 Nested one 2 Nested two 2 Two 1 Nested one 2 Nested two 3 Nested three 3 Three ``` The {{cssxref("counters", "counters()")}} function is used when the count for nested levels must include the count from parent levels. For example, you might use this to lay out sections as shown: ```plain 1 One 1.1 Nested one 1.2 Nested two 2 Two 2.1 Nested one 2.2 Nested two 2.3 Nested three 3 Three ``` The {{cssxref("counter", "counter()")}} function has two forms: `counter(<counter-name>)` and `counter(<counter-name>, <counter-style>)`. The generated text is the value of the innermost counter of the given name in scope at the pseudo-element. The {{cssxref("counters", "counters()")}} function also has two forms: `counters(<counter-name>, <separator>)` and `counters(<counter-name>, <separator>, <counter-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 (`<separator>`). The counter is rendered in the specified `<counter-style>` for both methods (`decimal` by default). You can use any of the {{cssxref("list-style-type")}} values or your own [custom styles](/en-US/docs/Web/CSS/CSS_counter_styles). Examples showing the use of `counter()` and `counters()` are given below in the [basic example](#basic_example) and [Example of a nested counter](#example_of_a_nested_counter), respectively. ### Reversed counters A reversed counter is one that is intended to count down (decrement) rather than up (increment). Reversed counters are created using the `reversed()` function notation when naming the counter in {{cssxref("counter-reset")}}. Reversed counters have a default initial value equal to the number of elements (unlike normal counters, which have a default value of 0). This makes it easy to implement a counter that counts from the number of elements down to one. For example, to create a reversed counter named `section` with a default initial value, you would use the following syntax: ```css counter-reset: reversed(section); ``` You can of course specify any initial value that you like. The counter value is decreased by specifying a negative value for {{cssxref("counter-increment")}}. > **Note:** You can also use {{cssxref("counter-increment")}} to decrement a non-reversed counter. > The main benefit of using a reversed counter is the default initial value, and that the `list-item` counter automatically decrements reversed counters. ### List item counters Ordered lists, as created using {{HTMLElement("ol")}} elements, implicitly have a counter named `list-item`. Like other counters, this has a default initial value of 0 for upward counters and "number of items" for reversed counters. Unlike author-created counters, `list-item` _automatically_ increments or decrements by one for each list element, depending on whether or not the counter is reversed. The `list-item` counter can be used to manipulate the default behavior of ordered lists using CSS. For example, you can change the default initial value, or use {{cssxref("counter-increment")}} to change the way in which the list items increment or decrement. ## Examples ### Basic example This example adds "Section \[the value of the counter]:" to the beginning of each heading. #### CSS ```css body { counter-reset: section; /* Set a counter named 'section', and its initial value is 0. */ } h3::before { counter-increment: section; /* Increment the value of section counter by 1 */ content: "Section " counter(section) ": "; /* Display the word 'Section ', the value of section counter, and a colon before the content of each h3 */ } ``` #### HTML ```html <h3>Introduction</h3> <h3>Body</h3> <h3>Conclusion</h3> ``` #### Result {{EmbedLiveSample("Basic_example", "100%", 150)}} ### Basic example: reversed counter This example is the same as the one above but uses a reversed counter. If your browser supports the `reversed()` function notation, the result will look like this: ![reversed counter](reversed_headings_basic.png) #### CSS ```css body { counter-reset: reversed( section ); /* Set a counter named 'section', and its initial value is 0. */ } h3::before { counter-increment: section -1; /* Decrement the value of section counter by 1 */ content: "Section " counter(section) ": "; /* Display the word 'Section ', the value of section counter, and a colon before the content of each h3 */ } ``` #### HTML ```html <h3>Introduction</h3> <h3>Body</h3> <h3>Conclusion</h3> ``` #### Result {{EmbedLiveSample("Basic example: reversed counter", "100%", 150)}} ### A more sophisticated example A counter need not necessarily be shown every time it is incremented. This example counts all links with the counter showing only when a link has no text, as a convenient replacement. #### CSS ```css :root { counter-reset: link; } a[href] { counter-increment: link; } a[href]:empty::after { content: "[" counter(link) "]"; } ``` #### HTML ```html <p>See <a href="https://www.mozilla.org/"></a></p> <p>Do not forget to <a href="contact-me.html">leave a message</a>!</p> <p>See also <a href="https://developer.mozilla.org/"></a></p> ``` #### Result {{EmbedLiveSample("A_more_sophisticated_example", "100%", 150)}} ### Example of a nested counter A CSS counter can be especially useful for making outlined lists, because a new instance of the counter is automatically created in child elements. Using the {{cssxref("counters", "counters()")}} function, separating text can be inserted between different levels of nested counters. #### CSS ```css ol { counter-reset: section; /* Creates a new instance of the section counter with each ol element */ list-style-type: none; } li::before { counter-increment: section; /* Increments only this instance of the section counter */ content: counters(section, ".") " "; /* Combines the values of all instances of the section counter, separated by a period */ } ``` #### HTML ```html-nolint <ol> <li>item</li> <!-- 1 --> <li>item <!-- 2 --> <ol> <li>item</li> <!-- 2.1 --> <li>item</li> <!-- 2.2 --> <li>item <!-- 2.3 --> <ol> <li>item</li> <!-- 2.3.1 --> <li>item</li> <!-- 2.3.2 --> </ol> <ol> <li>item</li> <!-- 2.3.1 --> <li>item</li> <!-- 2.3.2 --> <li>item</li> <!-- 2.3.3 --> </ol> </li> <li>item</li> <!-- 2.4 --> </ol> </li> <li>item</li> <!-- 3 --> <li>item</li> <!-- 4 --> </ol> <ol> <li>item</li> <!-- 1 --> <li>item</li> <!-- 2 --> </ol> ``` #### Result {{EmbedLiveSample("Example_of_a_nested_counter", "100%", 350)}} ## Specifications {{Specifications}} ## See also - {{cssxref("contain")}} - {{cssxref("counter-reset")}} - {{cssxref("counter-set")}} - {{cssxref("counter-increment")}} - {{cssxref("@counter-style")}} - [CSS counter styles](/en-US/docs/Web/CSS/CSS_counter_styles) module - [CSS lists and counters](/en-US/docs/Web/CSS/CSS_lists) module
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/pow/index.md
--- title: pow() slug: Web/CSS/pow page-type: css-function browser-compat: css.types.pow --- {{CSSRef}} The **`pow()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) is an exponential function that returns the value of a base raised to the power of a number. The {{CSSxRef("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 ```css /* 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 {{CSSxRef("&lt;number&gt;")}}, representing the base. - `number` - : A calculation that resolves to a {{CSSxRef("&lt;number&gt;")}}, representing the exponent. ### Return value Returns a {{CSSxRef("&lt;number&gt;")}} representing base<sup>number</sup>, that is, `base` raised to the power of `number`. ## Formal syntax {{CSSSyntax}} ## 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 ```html <h1>Heading 1</h1> <h2>Heading 2</h2> <h3>Heading 3</h3> <h4>Heading 4</h4> <h5>Heading 5</h5> <h6>Heading 6</h6> ``` #### CSS ```css h1 { font-size: calc(1rem * 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 {{EmbedLiveSample('Scale headings by fixed ratio', '100%', '300px')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("sqrt")}} - {{CSSxRef("hypot")}} - {{CSSxRef("exp")}} - {{CSSxRef("log")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/grid-template/index.md
--- title: grid-template slug: Web/CSS/grid-template page-type: css-shorthand-property browser-compat: css.properties.grid-template --- {{CSSRef}} The **`grid-template`** CSS property is a [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) for defining {{glossary("grid column", "grid columns")}}, {{glossary("grid_row", "grid rows")}}, and {{glossary("grid areas", "grid areas")}}. {{EmbedInteractiveExample("pages/css/grid-template.html")}} ## Constituent properties This property is a shorthand for the following CSS properties: - [`grid-template-areas`](/en-US/docs/Web/CSS/grid-template-areas) - [`grid-template-columns`](/en-US/docs/Web/CSS/grid-template-columns) - [`grid-template-rows`](/en-US/docs/Web/CSS/grid-template-rows) ## Syntax ```css /* Keyword value */ grid-template: none; /* grid-template-rows / grid-template-columns values */ grid-template: 100px 1fr / 50px 1fr; grid-template: auto 1fr / auto 1fr auto; grid-template: [linename] 100px / [columnname1] 30% [columnname2] 70%; grid-template: fit-content(100px) / fit-content(40%); /* grid-template-areas grid-template-rows / grid-template-column values */ grid-template: "a a a" "b b b"; grid-template: "a a a" 20% "b b b" auto; grid-template: [header-top] "a a a" [header-bottom] [main-top] "b b b" 1fr [main-bottom] / auto 1fr auto; /* Global values */ grid-template: inherit; grid-template: initial; grid-template: revert; grid-template: revert-layer; grid-template: unset; ``` ### Values - `none` - : Is a keyword that sets all three longhand properties to `none`, meaning there is no explicit grid. There are no named grid areas. Rows and columns will be implicitly generated; their size will be determined by the {{cssxref("grid-auto-rows")}} and {{cssxref("grid-auto-columns")}} properties. - `<'grid-template-rows'> / <'grid-template-columns'>` - : Sets {{cssxref("grid-template-rows")}} and {{cssxref("grid-template-columns")}} to the specified values, and sets {{cssxref("grid-template-areas")}} to `none`. - `[ <line-names>? <string> <track-size>? <line-names>? ]+ [ / <explicit-track-list> ]?` - : Sets {{cssxref("grid-template-areas")}} to the strings listed, {{cssxref("grid-template-rows")}} to the track sizes following each string (filling in `auto` for any missing sizes), and splicing in the named lines defined before/after each size, and {{cssxref("grid-template-columns")}} to the track listing specified after the slash (or `none`, if not specified). > **Note:** The {{cssxref("repeat", "repeat()")}} function isn't allowed in these track listings, as the tracks are intended to visually line up one-to-one with the rows/columns in the "ASCII art". > **Note:** The {{cssxref("grid")}} shorthand accepts the same syntax, but also resets the implicit grid properties to their initial values. Use `grid` (as opposed to `grid-template`) to prevent these values from cascading in separately. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Defining a grid template #### CSS ```css #page { display: grid; width: 100%; height: 200px; grid-template: [header-left] "head head" 30px [header-right] [main-left] "nav main" 1fr [main-right] [footer-left] "nav foot" 30px [footer-right] / 120px 1fr; } header { background-color: lime; grid-area: head; } nav { background-color: lightblue; grid-area: nav; } main { background-color: yellow; grid-area: main; } footer { background-color: red; grid-area: foot; } ``` #### HTML ```html <div id="page"> <header>Header</header> <nav>Navigation</nav> <main>Main area</main> <footer>Footer</footer> </div> ``` #### Result {{EmbedLiveSample("Defining_a_grid_template", "100%", "200px")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Related CSS properties: {{cssxref("grid-template-rows")}}, {{cssxref("grid-template-columns")}}, {{cssxref("grid-template-areas")}} - Grid Layout Guide: _[Line-based placement with CSS Grid](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_layout_using_line-based_placement)_ - Grid Layout Guide: _[Grid template areas - Grid definition shorthands](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_template_areas#grid_definition_shorthands)_ - Video tutorial: _[Grid Template shorthand](https://gridbyexample.com/video/grid-template-shorthand/)_
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_before/index.md
--- title: "::before" slug: Web/CSS/::before page-type: css-pseudo-element browser-compat: css.selectors.before --- {{CSSRef}} In CSS, **`::before`** creates a [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) that is the first child of the selected element. It is often used to add cosmetic content to an element with the {{cssxref("content")}} property. It is inline by default. {{EmbedInteractiveExample("pages/tabbed/pseudo-element-before.html", "tabbed-standard")}} > **Note:** The pseudo-elements generated by `::before` and `::after` are boxes generated as if they were immediate children of the element on which they are applied, or the "originating element," and thus can not apply to _[replaced elements](/en-US/docs/Web/CSS/Replaced_element)_, such as {{htmlelement("img")}}, whose content is outside the scope of the CSS formatting model. ## Syntax ```css-nolint ::before { content: /* value */; /* properties */ } ``` If the [`content`](/en-US/docs/Web/CSS/content) property is not specified, has an invalid value, or has `normal` or `none` as a value, then the `::before` pseudo-element is not rendered. It behaves as if `display: none` is set. > **Note:** [Selectors Level 3](https://drafts.csswg.org/selectors-3/#gen-content) introduced the double-colon notation `::before` to distinguish [pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes) from [pseudo-elements](/en-US/docs/Web/CSS/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 `{{Cssxref("::after")}}` to insert quotation characters. #### HTML ```html <q>Some quotes</q>, he said, <q>are better than none.</q> ``` #### CSS ```css q::before { content: "Β«"; color: blue; } q::after { content: "Β»"; color: red; } ``` #### Result {{EmbedLiveSample('Adding_quotation_marks', '500', '50')}} ### Decorative example We can style text or images in the {{cssxref("content")}} property almost any way we want. #### HTML ```html <span class="ribbon">Notice where the orange box is.</span> ``` #### CSS ```css .ribbon { background-color: #5bc8f7; } .ribbon::before { content: "Look at this orange box."; background-color: #ffba10; border-color: black; border-style: dotted; } ``` #### Result {{EmbedLiveSample('Decorative_example', 450, 60)}} ### 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 ```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 ```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 ```js 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 {{EmbedLiveSample('To-do_list', 400, 300)}} ### 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 ```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 ```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 {{EmbedLiveSample('Special_characters', 400, 200)}} ## Accessibility concerns Using a `::before` pseudo-element to add content is discouraged, as it is not reliably accessible to screen readers. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{Cssxref("::after")}} - {{Cssxref("content")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/background-clip/index.md
--- title: background-clip slug: Web/CSS/background-clip page-type: css-property browser-compat: css.properties.background-clip --- {{CSSRef}} The **`background-clip`** [CSS](/en-US/docs/Web/CSS) property sets whether an element's background extends underneath its border box, padding box, or content box. {{EmbedInteractiveExample("pages/css/background-clip.html")}} If the element has no {{cssxref("background-image")}} or {{cssxref("background-color")}}, this property will only have a visual effect when the border has transparent regions or partially opaque regions (due to {{cssxref("border-style")}} or {{cssxref("border-image")}}); otherwise, the border masks the difference. > **Note:** Because the [root element](/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](/en-US/docs/Web/HTML/Element/html) is an HTML element: if the computed value of {{cssxref("background-image")}} on the root element is `none` and its {{cssxref("background-color")}} is `transparent`, user agents must instead propagate the computed values of the `background` properties from that element's first HTML {{HTMLElement("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 ```css /* 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 {{cssxref("background-color")}} to prevent this from happening, and test without the image. Consider using feature queries with {{cssxref("@supports")}} to test for support of `background-clip: text` and provide an accessible alternative where it is not supported. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### HTML ```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 ```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: rgb(0 0 0 / 20%); } ``` #### Result {{EmbedLiveSample('Examples', 600, 580)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - The {{cssxref("clip-path")}} property creates a clipping region that defines what part of an _entire element_ should be displayed. - Background properties: {{cssxref("background")}}, {{cssxref("background-color")}}, {{cssxref("background-image")}}, {{cssxref("background-origin")}} - [Introduction to the CSS box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_nth-of-type/index.md
--- title: ":nth-of-type()" slug: Web/CSS/:nth-of-type page-type: css-pseudo-class browser-compat: css.selectors.nth-of-type --- {{CSSRef}} The **`:nth-of-type()`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) matches elements based on their position among siblings of the same type (tag name). {{EmbedInteractiveExample("pages/tabbed/pseudo-class-nth-of-type.html", "tabbed-shorter")}} ## Syntax The `nth-of-type` pseudo-class is specified with a single argument, which represents the pattern for matching elements. See {{Cssxref(":nth-child")}} for a more detailed explanation of its syntax. ```css-nolint :nth-of-type(<an-plus-b> | even | odd) { /* ... */ } ``` ## Examples ### Basic example #### HTML ```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 ```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 {{EmbedLiveSample('Basic_example', 250, 250)}} > **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 {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{Cssxref(":nth-child")}}, {{Cssxref(":nth-last-of-type")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/animation-range-start/index.md
--- title: animation-range-start slug: Web/CSS/animation-range-start page-type: css-property status: - experimental browser-compat: css.properties.animation-range-start --- {{CSSRef}}{{SeeCompatTable}} The **`animation-range-start`** [CSS](/en-US/docs/Web/CSS) property is used to set the start of an animation's attachment range along its timeline, i.e. where along the timeline an animation will start. The `animation-range-start` and {{cssxref("animation-range-end")}} properties can also be set using the [`animation-range`](/en-US/docs/Web/CSS/animation-range) shorthand property. > **Note:** {{cssxref("animation-range-start")}} is included in the {{cssxref("animation")}} shorthand as a reset-only value. This means that including `animation` resets a previously-declared `animation-range-start` value to `normal`, but a specific value cannot be set via `animation`. When creating [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations), you need to declare `animation-range-start` after declaring any `animation` shorthand for it to take effect. ## Syntax ```css /* Keyword or length percentage value */ animation-range-start: normal; animation-range-start: 20%; animation-range-start: 100px; /* Named timeline range value */ animation-range-start: cover; animation-range-start: contain; animation-range-start: cover 20%; animation-range-start: contain 100px; ``` ### Values Allowed values for `animation-range-start` are `normal`, a {{cssxref("length-percentage")}}, a `<timeline-range-name>`, or a `<timeline-range-name>` with a `<length-percentage>` following it. See [`animation-range`](/en-US/docs/Web/CSS/animation-range) for a detailed description of the available values. Also check out the [View Timeline Ranges Visualizer](https://scroll-driven-animations.style/tools/view-timeline/ranges/), which shows exactly what the different values mean in an easy visual format. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Creating a named view progress timeline with range start A view progress timeline named `--subjectReveal` is defined using the `view-timeline` property on a subject element with a `class` of `animation`. This is then set as the timeline for the same element using `animation-timeline: --subjectReveal;`. The result is that the subject element animates as it moves upwards through the document as it is scrolled. An `animation-range-start` declaration is also set to make the animation begin later than expected. #### HTML The HTML for the example is shown below. ```html <div class="content"> <h1>Content</h1> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Risus quis varius quam quisque id. Et ligula ullamcorper malesuada proin libero nunc consequat interdum varius. Elit ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at augue. </p> <p> Dolor sed viverra ipsum nunc aliquet. Sed sed risus pretium quam vulputate dignissim. Tortor aliquam nulla facilisi cras. A erat nam at lectus urna duis convallis convallis. Nibh ipsum consequat nisl vel pretium lectus. Sagittis aliquam malesuada bibendum arcu vitae elementum. Malesuada bibendum arcu vitae elementum curabitur vitae nunc sed velit. </p> <div class="subject animation"></div> <p> Adipiscing enim eu turpis egestas pretium aenean pharetra magna ac. Arcu cursus vitae congue mauris rhoncus aenean vel. Sit amet cursus sit amet dictum. Augue neque gravida in fermentum et. Gravida rutrum quisque non tellus orci ac auctor augue mauris. Risus quis varius quam quisque id diam vel quam elementum. Nibh praesent tristique magna sit amet purus gravida quis. Duis ultricies lacus sed turpis tincidunt id aliquet. In egestas erat imperdiet sed euismod nisi. Eget egestas purus viverra accumsan in nisl nisi scelerisque. Netus et malesuada fames ac. </p> </div> ``` #### CSS The `subject` element and its containing `content` element are styled minimally, and the text content is given some basic font settings: ```css .subject { width: 300px; height: 200px; margin: 0 auto; background-color: deeppink; } .content { width: 75%; max-width: 800px; margin: 0 auto; } p, h1 { font-family: Arial, Helvetica, sans-serif; } h1 { font-size: 3rem; } p { font-size: 1.5rem; line-height: 1.5; } ``` The `<div>` with the class of `subject` is also given a class of `animation` β€” this is where `view-timeline` is set to define a named view progress timeline. It is also given an `animation-timeline` name with the same value to declare that this will be the element animated as the view progress timeline is progressed. We also give it an `animation-range-start` declaration to make the animation begin later than expected. Last, an animation is specified on the element that animates its opacity and scale, causing it to fade in and size up as it moves up the scroller. ```css .animation { view-timeline: --subjectReveal block; animation-timeline: --subjectReveal; animation-name: appear; animation-range-start: entry 25%; animation-fill-mode: both; animation-duration: 1ms; /* Firefox requires this to apply the animation */ } @keyframes appear { from { opacity: 0; transform: scaleX(0); } to { opacity: 1, transform: scaleX(1); } } ``` #### Result Scroll to see the subject element being animated. {{EmbedLiveSample("Creating a named view progress timeline with range start", "100%", "480px")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`animation-timeline`](/en-US/docs/Web/CSS/animation-timeline) - [`animation-range`](/en-US/docs/Web/CSS/animation-range), [`animation-range-end`](/en-US/docs/Web/CSS/animation-range-end) - [`scroll-timeline`](/en-US/docs/Web/CSS/scroll-timeline), [`scroll-timeline-axis`](/en-US/docs/Web/CSS/scroll-timeline-axis), [`scroll-timeline-name`](/en-US/docs/Web/CSS/scroll-timeline-name) - {{cssxref("timeline-scope")}} - [`view-timeline-inset`](/en-US/docs/Web/CSS/view-timeline-inset) - The JavaScript equivalent: The `rangeStart` property available in {{domxref("Element.animate()")}} calls - [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/color/index.md
--- title: color slug: Web/CSS/color page-type: css-property browser-compat: css.properties.color --- {{CSSRef}} The **`color`** CSS property sets the foreground [color value](/en-US/docs/Web/CSS/color_value) of an element's text and [text decorations](/en-US/docs/Web/CSS/text-decoration), and sets the [`currentcolor`](/en-US/docs/Web/CSS/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 {{cssxref("border-color")}}. {{EmbedInteractiveExample("pages/css/color.html")}} For an overview of using color in HTML, see [Applying color to HTML elements using CSS](/en-US/docs/Web/CSS/CSS_colors/Applying_color). ## Syntax ```css /* 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 and legacy <rgba()> 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.6); color: rgb(34.6 12 64 / 60%); color: rgba(34.6 12 64 / 60%); /* <hsl()> values and legacy <hsla()> 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.2 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 {{cssxref("&lt;color&gt;")}} value. Note that the value must be a uniform {{cssxref("color")}}. It can't be a {{cssxref("&lt;gradient&gt;")}}, which is actually a type of {{cssxref("&lt;image&gt;")}}. ### Values - {{cssxref("&lt;color&gt;")}} - : Sets the color of the textual and decorative parts of the element. - [`currentcolor`](/en-US/docs/Web/CSS/color_value#currentcolor_keyword) - : Sets the color to the element's `color` property value. However, if set as the value of `color`, `currentcolor` is treated as `inherit`. ## 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](/en-US/docs/Web/CSS/font-weight) or larger, or 24px or larger. - [WebAIM: Color Contrast Checker](https://webaim.org/resources/contrastchecker/) - [MDN Understanding WCAG, Guideline 1.4 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background) - [Understanding Success Criterion 1.4.3 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html) ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Making text red The following are all ways to make a paragraph's text red: ```css 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: rgb(255 0 0 / 50%); } p { color: hsl(0 100% 50% / 50%); } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - The {{cssxref("&lt;color&gt;")}} data type - Other color-related properties: {{cssxref("background-color")}}, {{cssxref("border-color")}}, {{cssxref("outline-color")}}, {{cssxref("text-decoration-color")}}, {{cssxref("text-emphasis-color")}}, {{cssxref("text-shadow")}}, {{cssxref("caret-color")}}, {{cssxref("column-rule-color")}}, and {{cssxref("print-color-adjust")}} - [Applying color to HTML elements using CSS](/en-US/docs/Web/CSS/CSS_colors/Applying_color)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/align-content/index.md
--- title: align-content slug: Web/CSS/align-content page-type: css-property browser-compat: css.properties.align-content --- {{CSSRef}} The [CSS](/en-US/docs/Web/CSS) **`align-content`** property sets the distribution of space between and around content items along a [flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout)'s cross-axis or a [grid](/en-US/docs/Web/CSS/CSS_grid_layout)'s block axis. The interactive example below uses Grid Layout to demonstrate some of the values of this property. {{EmbedInteractiveExample("pages/css/align-content.html")}} This property has no effect on single line flex containers (i.e. ones with `flex-wrap: nowrap`). ## Syntax ```css /* 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 baseline is the line upon which most letters "sit" and below which descenders extend.](410px-typography_line_terms.svg.png) 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 {{cssxref("max-height")}}/{{cssxref("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 {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### CSS ```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 ```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> ``` ```js hidden const values = document.getElementById("values"); const display = document.getElementById("display"); const container = document.getElementById("container"); values.addEventListener("change", (evt) => { container.style.alignContent = evt.target.value; }); display.addEventListener("change", (evt) => { container.className = evt.target.value; }); ``` ### Result {{EmbedLiveSample("Examples", 260, 290)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - CSS Flexbox Guide: _[Basic Concepts of Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox)_ - CSS Flexbox Guide: _[Aligning items in a flex container](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Aligning_items_in_a_flex_container)_ - CSS Grid Guide: _[Box alignment in CSS Grid layouts](/en-US/docs/Web/CSS/CSS_grid_layout/Box_alignment_in_grid_layout)_ - [CSS Box Alignment](/en-US/docs/Web/CSS/CSS_box_alignment)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_placeholder/index.md
--- title: "::placeholder" slug: Web/CSS/::placeholder page-type: css-pseudo-element browser-compat: css.selectors.placeholder --- {{CSSRef}} The **`::placeholder`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) represents the [placeholder text](/en-US/docs/Web/HTML/Element/input#placeholder) in an {{HTMLElement("input")}} or {{HTMLElement("textarea")}} element. {{EmbedInteractiveExample("pages/tabbed/pseudo-element-placeholder.html", "tabbed-shorter")}} Only the subset of CSS properties that apply to the {{cssxref("::first-line")}} pseudo-element can be used in a rule using `::placeholder` in its selector. > **Note:** In most browsers, the appearance of placeholder text is a translucent or light gray color by default. ## Syntax ```css ::placeholder { /* ... */ } ``` ## Accessibility concerns ### Color contrast #### Contrast Ratio Placeholder text typically has a lighter color treatment to indicate that it is a suggestion for what kind of input will be valid, and is not actual input of any kind. It is important to ensure that the contrast ratio between the color of the placeholder text and the background of the input is high enough that people experiencing low vision conditions will be able to read it while also making sure there is enough of a difference between the placeholder text and input text color that users do not mistake the placeholder for inputted data. Color contrast ratio is determined by comparing the luminosity of the placeholder text and the input 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 or larger, or 24px or larger. - [WebAIM: Color Contrast Checker](https://webaim.org/resources/contrastchecker/) - [MDN Understanding WCAG, Guideline 1.4 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background) - [Understanding Success Criterion 1.4.3 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html) #### Usability Placeholder text with sufficient color contrast may be interpreted as entered input. Placeholder text will also disappear when a person enters content into an {{htmlelement("input")}} element. Both of these circumstances can interfere with successful form completion, especially for people with cognitive concerns. An alternate approach to providing placeholder information is to include it outside of the input in close visual proximity, then use [`aria-describedby`](/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-describedby) to programmatically associate the {{HTMLElement("input")}} with its hint. With this implementation, the hint content is available even if information is entered into the input field, and the input appears free of preexisting input when the page is loaded. Most screen reading technology will use `aria-describedby` to read the hint after the input's label text is announced, and the person using the screen reader can mute it if they find the extra information unnecessary. ```html <label for="user-email">Your email address</label> <span id="user-email-hint" class="input-hint">Example: [email protected]</span> <input id="user-email" aria-describedby="user-email-hint" name="email" type="email" /> ``` - [Placeholders in Form Fields Are Harmful β€” Nielsen Norman Group](https://www.nngroup.com/articles/form-design-placeholders/) ### Windows High Contrast Mode Placeholder text will appear with the same styling as user-entered text content when rendered in [Windows High Contrast Mode](https://www.smashingmagazine.com/2022/06/guide-windows-high-contrast-mode/)). This will make it difficult for some people to determine which content has been entered, and which content is placeholder text. ### Labels Placeholders are not a replacement for the {{htmlelement("label")}} element. Without a label that has been programmatically associated with an input using a combination of the [`for`](/en-US/docs/Web/HTML/Element/label#for) and [`id`](/en-US/docs/Web/HTML/Global_attributes#id) attributes, assistive technology such as screen readers cannot parse {{htmlelement("input")}} elements. - [Placeholders in Form Fields Are Harmful β€” Nielsen Norman Group](https://www.nngroup.com/articles/form-design-placeholders/) ## Examples ### Change placeholder appearance This example shows some of the adjustments that you can make to the styles of placeholder text. #### HTML ```html <input placeholder="Type here" /> ``` #### CSS ```css input::placeholder { color: red; font-size: 1.2em; font-style: italic; } ``` #### Result {{EmbedLiveSample("Change_placeholder_appearance", 200, 60)}} ### Opaque text Some browsers (such as Firefox) set the default {{cssxref("opacity")}} of placeholders to something less than 100%. If you want fully opaque placeholder text, set `opacity` to `1`. #### HTML ```html <input placeholder="Default opacity" /> <input placeholder="Full opacity" class="force-opaque" /> ``` #### CSS ```css ::placeholder { color: green; } .force-opaque::placeholder { opacity: 1; } ``` #### Result {{EmbedLiveSample("Opaque_text", 200, 60)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - The {{cssxref(":placeholder-shown")}} pseudo-class styles an element that _has_ an active placeholder. - Related HTML elements: {{HTMLElement("input")}}, {{HTMLElement("textarea")}} - [HTML forms](/en-US/docs/Learn/Forms)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/text-decoration-line/index.md
--- title: text-decoration-line slug: Web/CSS/text-decoration-line page-type: css-property browser-compat: css.properties.text-decoration-line --- {{CSSRef}} The **`text-decoration-line`** [CSS](/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. {{EmbedInteractiveExample("pages/css/text-decoration-line.html")}} When setting multiple line-decoration properties at once, it may be more convenient to use the {{cssxref("text-decoration")}} shorthand property instead. ## Syntax ```css /* 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_inline}} - : 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](/en-US/docs/Web/CSS/animation). ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Basic example ```html <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> ``` ```css .wavy { text-decoration-line: underline; text-decoration-style: wavy; text-decoration-color: red; } .both { text-decoration-line: underline overline; } ``` {{EmbedLiveSample('Examples')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - When setting multiple line-decoration properties at once, it may be more convenient to use the {{cssxref("text-decoration")}} shorthand property instead, which also includes: - {{cssxref("text-decoration-style")}} - {{cssxref("text-decoration-color")}} - {{cssxref("text-decoration-thickness")}} - {{cssxref("text-underline-offset")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/time-percentage/index.md
--- title: <time-percentage> slug: Web/CSS/time-percentage page-type: css-type browser-compat: css.types.time-percentage --- {{CSSRef}} The **`<time-percentage>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) represents a value that can be either a {{Cssxref("time")}} or a {{Cssxref("percentage")}}. ## Syntax Refer to the documentation for {{Cssxref("time")}} and {{Cssxref("percentage")}} for details of the individual syntaxes allowed by this type. ## Formal syntax {{csssyntax}} ## 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 {{Cssxref("calc", "calc()")}} expression. ### Valid percentages ```plain example-good 50% +50% Optional plus sign -50% Negative percentages are not valid for all properties that accept percentages ``` ### Invalid percentages ```plain example-bad 50 % Space not allowed between the number and the percentage sign ``` ### Valid times ```plain example-good 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 ```plain example-bad 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 {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("&lt;percentage&gt;")}} - {{cssxref("&lt;time&gt;")}} - [CSS Values and Units](/en-US/docs/Web/CSS/CSS_Values_and_Units)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/-moz-image-rect/index.md
--- title: "-moz-image-rect" slug: Web/CSS/-moz-image-rect page-type: css-function status: - deprecated - non-standard browser-compat: css.types.-moz-image-rect --- {{CSSRef}}{{Non-standard_Header}}{{Deprecated_Header}} The **`-moz-image-rect`** value for [CSS](/en-US/docs/Web/CSS) {{CSSxRef("background-image")}} lets you use a portion of a larger image as a background. ## Syntax ```css -moz-image-rect({{CSSxRef("url", "url()")}}, top, right, bottom, left); ``` ### Values - {{CSSxRef("url", "url()")}} - : The URI of the image from which to take the sub-image. - `top` - : The top edge, specified as an {{CSSxRef("&lt;integer&gt;")}} or {{CSSxRef("&lt;percentage&gt;")}}, of the sub-image within the specified image. - `right` - : The right edge, specified as an {{CSSxRef("&lt;integer&gt;")}} or {{CSSxRef("&lt;percentage&gt;")}}, of the sub-image within the specified image. - `bottom` - : The bottom edge, specified as an {{CSSxRef("&lt;integer&gt;")}} or {{CSSxRef("&lt;percentage&gt;")}}, of the sub-image within the specified image. - `left` - : The left edge, specified as an {{CSSxRef("&lt;integer&gt;")}} or {{CSSxRef("&lt;percentage&gt;")}}, 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 {{CSSxRef("-moz-image-region")}} property, which is used with the {{CSSxRef("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()`](/en-US/docs/Web/CSS/shape#syntax) function generating a {{CSSxRef("&lt;shape&gt;")}} 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 {{HTMLElement("div")}} blocks. Clicking on their container causes the four segments to rotate around by swapping the {{CSSxRef("background-image")}} property values among the four {{HTMLElement("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: ```css #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. ```css #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`. ```css #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: ```css #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: ```html <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 {{HTMLElement("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. ```js 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 {{DOMxRef("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 {{CSSxRef("background-image")}} property from one element to the next with each mouse click, we achieve the desired effect. ### What it looks like {{EmbedLiveSample("Examples","400","400")}} ## Specifications Not part of any standard. ## Browser compatibility {{Compat}} ## See also - [Mozilla CSS extensions](/en-US/docs/Web/CSS/Mozilla_Extensions) - [CSS Backgrounds and Borders module](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_only-child/index.md
--- title: ":only-child" slug: Web/CSS/:only-child page-type: css-pseudo-class browser-compat: css.selectors.only-child --- {{CSSRef}} The **`:only-child`** CSS [pseudo-class](/en-US/docs/Web/CSS/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. {{EmbedInteractiveExample("pages/tabbed/pseudo-class-only-child.html", "tabbed-shorter")}} ## Syntax ```css :only-child { /* ... */ } ``` ## Examples ### Basic example #### HTML ```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 ```css div:only-child { color: red; } div { display: inline-block; margin: 6px; outline: 1px solid; } ``` #### Result {{EmbedLiveSample('Basic_example','100%',180)}} ### A list example #### HTML ```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 ```css li li { list-style-type: disc; } li:only-child { color: red; list-style-type: square; } ``` #### Result {{EmbedLiveSample('A_list_example', '100%', 210)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{Cssxref(":only-of-type")}} - {{Cssxref(":first-child")}} - {{Cssxref(":last-child")}} - {{Cssxref(":nth-child")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_-moz-range-thumb/index.md
--- title: "::-moz-range-thumb" slug: Web/CSS/::-moz-range-thumb page-type: css-pseudo-element status: - non-standard browser-compat: css.selectors.-moz-range-thumb --- {{CSSRef}}{{Non-standard_header}} The **`::-moz-range-thumb`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) is a [Mozilla extension](/en-US/docs/Web/CSS/Mozilla_Extensions) that represents the _thumb_ (i.e., virtual knob) of an {{HTMLElement("input")}} of `type="range"`. The user can move the thumb along the input's track to alter its numerical value. > **Note:** Using `::-moz-range-thumb` with anything but an `<input type="range">` doesn't match anything and has no effect. ## Syntax ```css ::-moz-range-thumb { /* ... */ } ``` ## Examples ### HTML ```html <input type="range" min="0" max="100" step="5" value="50" /> ``` ### CSS ```css input[type="range"]::-moz-range-thumb { background-color: green; } ``` ### Result {{EmbedLiveSample("Examples", 300, 50)}} A progress bar using this style might look something like this: ![The thumb of the 'input type=right' styled in green](screen_shot_2015-12-04_at_13.30.08.png) ## Specifications Not part of any standard. ## Browser compatibility {{Compat}} ## See also - The pseudo-elements used by Gecko to style other parts of a range input: - {{cssxref("::-moz-range-track")}} represents the groove in which the thumb slides. - {{cssxref("::-moz-range-progress")}} represents the lower portion of the track. - Similar pseudo-elements used by other browsers: - {{cssxref("::-webkit-slider-thumb")}}, pseudo-element supported by WebKit and Blink (Safari, Chrome, and Opera) - [CSS-Tricks: Styling Cross-Browser Compatible Range Inputs with CSS](https://css-tricks.com/styling-cross-browser-compatible-range-inputs-css/) - [QuirksMode: Styling and scripting sliders](https://www.quirksmode.org/blog/archives/2015/11/styling_and_scr.html)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/scroll-timeline-name/index.md
--- title: scroll-timeline-name slug: Web/CSS/scroll-timeline-name page-type: css-property status: - experimental browser-compat: css.properties.scroll-timeline-name --- {{CSSRef}}{{SeeCompatTable}} The **`scroll-timeline-name`** [CSS](/en-US/docs/Web/CSS) property is used to define the name of a _named scroll progress timeline_, which is progressed through by scrolling a scrollable element (_scroller_) between top and bottom (or left and right). `scroll-timeline-name` is set on the scroller that will provide the timeline. The name is then referenced in an [`animation-timeline`](/en-US/docs/Web/CSS/animation-timeline) declaration to indicate the container's element that is used to drive the progress of the animation through the scrolling action. > **Note:** If the element does not overflow its container in the axis dimension or if the overflow is hidden or clipped, no timeline will be created. The {{cssxref("scroll-timeline-axis")}} and `scroll-timeline-name` properties can also be set using the [`scroll-timeline`](/en-US/docs/Web/CSS/scroll-timeline) shorthand property. ## Syntax ```css scroll-timeline-name: none; scroll-timeline-name: --custom_name_for_timeline; ``` ### Values Allowed values for `scroll-timeline-name` are: - `none` - : The timeline has no name. - `<dashed-ident>` - : An arbitrary custom identifier defining a name for a scroll progress timeline, which can then be referenced in an [`animation-timeline`](/en-US/docs/Web/CSS/animation-timeline) property. > **Note:** [`<dashed-ident>`](/en-US/docs/Web/CSS/dashed-ident) values must start with `--`, which helps avoid name clashes with standard CSS keywords. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Creating a named scroll progress timeline animation 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. ```html <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. No [scrollbar axis](/en-US/docs/Web/CSS/scroll-timeline-axis) is defined here because the vertical axis will be used by default. The height of the container is set to `300px`, and the container is also set to create a vertical scrollbar if it overflows (the CSS `height` rule on the `stretcher` element below does make the content overflow its container). ```css #container { height: 300px; overflow-y: scroll; scroll-timeline-name: --squareTimeline; position: relative; } ``` The CSS below defines a square that rotates according to the timeline provided by the `animation-timeline` property, which is set to the `--squareTimeline` timeline named above. ```css #square { background-color: deeppink; width: 100px; height: 100px; margin-top: 100px; animation-name: rotateAnimation; animation-duration: 1ms; /* Firefox requires this to apply the animation */ animation-timeline: --squareTimeline; position: absolute; bottom: 0; } #stretcher { height: 600px; background: #dedede; } @keyframes rotateAnimation { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } ``` The `stretcher` CSS rule sets the block height to `600px`, which creates content that overflows the container element, thereby creating scroll bars. Without this element, the content would not overflow the container, there would be no scrollbar, and hence no scroll timeline to associate with the animation timeline. #### Result Scroll the vertical bar to see the square animate as you scroll. {{EmbedLiveSample("Creating_a_named_scroll_progress_timeline_animation", "100%", "320px")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`animation-timeline`](/en-US/docs/Web/CSS/animation-timeline) - [`scroll-timeline`](/en-US/docs/Web/CSS/scroll-timeline), [`scroll-timeline-axis`](/en-US/docs/Web/CSS/scroll-timeline-axis) - {{cssxref("timeline-scope")}} - [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/text-emphasis-position/index.md
--- title: text-emphasis-position slug: Web/CSS/text-emphasis-position page-type: css-property browser-compat: css.properties.text-emphasis-position --- {{CSSRef}} The **`text-emphasis-position`** [CSS](/en-US/docs/Web/CSS) property sets where emphasis marks are drawn. Like ruby text, if there isn't enough room for emphasis marks, the line height is increased. {{EmbedInteractiveExample("pages/css/text-emphasis-position.html")}} ## Syntax ```css /* Initial value */ text-emphasis-position: over right; /* Keywords value */ text-emphasis-position: over left; text-emphasis-position: under right; text-emphasis-position: under left; text-emphasis-position: left over; text-emphasis-position: right under; text-emphasis-position: left under; /* Global values */ text-emphasis-position: inherit; text-emphasis-position: initial; text-emphasis-position: revert; text-emphasis-position: revert-layer; text-emphasis-position: unset; ``` ### Values - `over` - : Draws marks over the text in horizontal writing mode. - `under` - : Draws marks under the text in horizontal writing mode. - `right` - : Draws marks to the right of the text in vertical writing mode. - `left` - : Draws marks to the left of the text in vertical writing mode. ## Description The preferred position of emphasis marks depends on the language. In Japanese for example, the preferred position is `over right`. In Chinese, on the other hand, the preferred position is `under right`. The informative table below summarizes the preferred emphasis mark positions for Chinese, Mongolian and Japanese: <table> <caption> Preferred emphasis mark and ruby position </caption> <thead> <tr> <th rowspan="2" scope="col">Language</th> <th colspan="2" scope="col">Preferred position</th> <th colspan="2" rowspan="2" scope="col">Illustration</th> </tr> <tr> <th>Horizontal</th> <th>Vertical</th> </tr> </thead> <tbody> <tr> <td>Japanese</td> <td rowspan="3">over</td> <td rowspan="3">right</td> <td rowspan="3"> <img alt="Emphasis marks appear over each emphasized character in horizontal Japanese text." src="text-emphasis-ja.png" title="Emphasis (shown in blue for clarity) applied above a fragment of Japanese text" /> </td> <td rowspan="4"> <img alt="Emphasis marks appear on the right of each emphasized character in vertical Japanese text." src="text-emphasis-v.gif" title="Emphasis applied on the right of a fragment of Japanese text" /> </td> </tr> <tr> <td>Korean</td> </tr> <tr> <td>Mongolian</td> </tr> <tr> <td>Chinese</td> <td>under</td> <td>right</td> <td> <img alt="Emphasis marks appear below each emphasized character in horizontal Simplified Chinese text." src="text-emphasis-zh.gif" title="Emphasis (shown in blue for clarity) applied below a fragment of Chinese text" /> </td> </tr> </tbody> </table> > **Note:** The `text-emphasis-position` cannot be set, and therefore are not reset either, using the {{cssxref("text-emphasis")}} shorthand property. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Preferring ruby over emphasis marks Some editors prefer to hide emphasis marks when they conflict with ruby. In HTML, this can be done with the following style rule: ```css ruby { text-emphasis: none; } ``` ### Preferring emphasis marks over ruby Some other editors prefer to hide ruby when they conflict with emphasis marks. In HTML, this can be done with the following pattern: ```css em { text-emphasis: dot; /* Set text-emphasis for <em> elements */ } em rt { display: none; /* Hide ruby inside <em> elements */ } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - The longhand properties {{cssxref("text-emphasis-style")}}, {{cssxref("text-emphasis-color")}}, and the corresponding shorthand property {{cssxref("text-emphasis")}}.
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/overflow-x/index.md
--- title: overflow-x slug: Web/CSS/overflow-x page-type: css-property browser-compat: css.properties.overflow-x --- {{CSSRef}} The **`overflow-x`** [CSS](/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. This property may also be set by using the [`overflow`](/en-US/docs/Web/CSS/overflow) shorthand property. {{EmbedInteractiveExample("pages/css/overflow-x.html")}} ## Syntax ```css /* 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 {{CSSXref("overflow_value", "&lt;overflow&gt;")}} keyword value. If {{cssxref("overflow-y")}} is `hidden`, `scroll`, or `auto`, and the `overflow-x` property is `visible` (default), the value will be implicitly computed as `auto`. ### Values - `visible` - : Overflow content is not clipped and may be visible outside the element's padding box on left and right edges. The element box is not a {{glossary("scroll container")}}. - `hidden` - : Overflow content is clipped if necessary to fit horizontally in the elements' padding box. No scroll bars are provided. - `clip` - : Overflow content is clipped at the element's _overflow clip edge_ that is defined using the [`overflow-clip-margin`](/en-US/docs/Web/CSS/overflow-clip-margin) property. As a result, content overflows the element's padding box by the {{cssxref("&lt;length&gt;")}} value of `overflow-clip-margin` or by `0px` if not set. The difference between `clip` and `hidden` is that the `clip` keyword also forbids all scrolling, including programmatic scrolling. No new formatting context is created. To establish a formatting context, use `overflow: clip` along with {{cssxref("display", "display: flow-root", "#flow-root")}}. The element box is not a scroll container. - `scroll` - : Overflow content is clipped if necessary to fit horizontally inside the element's padding box. Browsers display scroll bars in the horizontal direction whether or not any content is actually clipped. (This prevents scroll bars from appearing or disappearing when the content changes.) Printers may still print overflowing content. - `auto` - : Overflow content is clipped at the element's padding box, and overflow content can be scrolled into view. Unlike `scroll`, user agents display scroll bars _only if_ the content is overflowing and hide scroll bars by default. If content fits inside the element's padding box, it looks the same as with `visible`, but still establishes a new block-formatting context. Desktop browsers provide scroll bars if content overflows. > **Note:** The keyword value `overlay` is a legacy value alias for `auto`. With `overlay`, the scroll bars are drawn on top of the content instead of taking up space. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### HTML ```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 ```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 {{EmbedLiveSample("Examples", "100%", "270")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{Cssxref("clip")}}, {{Cssxref("display")}}, {{cssxref("text-overflow")}}, {{cssxref("white-space")}} - [CSS overflow](/en-US/docs/Web/CSS/CSS_overflow) module - [CSS building blocks: Overflowing content](/en-US/docs/Learn/CSS/Building_blocks/Overflowing_content)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_-webkit-meter-optimum-value/index.md
--- title: "::-webkit-meter-optimum-value" slug: Web/CSS/::-webkit-meter-optimum-value page-type: css-pseudo-element status: - non-standard browser-compat: css.selectors.-webkit-meter-optimum-value --- {{CSSRef}}{{Non-standard_header}} The **`::-webkit-meter-optimum-value`** CSS [pseudo-element](/en-US/docs/Glossary/Pseudo-element) styles the {{htmlelement("meter")}} element when its value is inside the low-high range, or when the value is equivalent to the optimum value. Green is the default color. ## Syntax ```css ::-webkit-meter-optimum-value { /* ... */ } ``` ## Specifications Not part of any standard. ## Examples This example will only work in browsers based on WebKit or Blink. ### HTML ```html Normal: <meter min="0" max="10" low="3" high="7" optimum="6" value="6"> Score 6/10 </meter> <br /> Styled: <meter id="styled" min="0" max="10" low="3" high="7" optimum="6" value="6"> Score 6/10 </meter> ``` ### CSS ```css body { font-family: monospace; } .safari meter { /* Reset the default appearance for Safari only */ /* .safari class is added via JavaScript */ -webkit-appearance: none; } #styled::-webkit-meter-optimum-value { background: linear-gradient(to bottom, #7f7, #090 45%, #090 55%, #7f7); height: 100%; box-sizing: border-box; } ``` ### JavaScript ```js // Safari requires <meter> elements to have an `appearance` of `none` for custom styling // using `::-webkit-meter-*` selectors, but `appearance: none` breaks rendering on Chrome. // Therefore, we must check if the browser is Safari-based. const is_safari = navigator.userAgent.includes("AppleWebKit/") && !navigator.userAgent.includes("Chrome/"); if (is_safari) { document.body.classList.add("safari"); } ``` ### Result {{ EmbedLiveSample('Examples', '100%', 50) }} ## Browser compatibility {{Compat}} ## See also The pseudo-elements used by WebKit/Blink to style other parts of a {{htmlelement("meter")}} element are as follows: - {{cssxref("::-webkit-meter-inner-element")}} - {{cssxref("::-webkit-meter-bar")}} - {{cssxref("::-webkit-meter-even-less-good-value")}} - {{cssxref("::-webkit-meter-suboptimum-value")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_empty/index.md
--- title: ":empty" slug: Web/CSS/:empty page-type: css-pseudo-class browser-compat: css.selectors.empty --- {{CSSRef}} The **`:empty`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents any element that has no children. Children can be either element nodes or text (including whitespace). Comments, processing instructions, and CSS {{cssxref("content")}} do not affect whether an element is considered empty. {{EmbedInteractiveExample("pages/tabbed/pseudo-class-empty.html", "tabbed-shorter")}} > **Note:** In [Selectors Level 4](https://drafts.csswg.org/selectors-4/#the-empty-pseudo), the `:empty` pseudo-class was changed to act like {{CSSxRef(":-moz-only-whitespace")}}, but no browser currently supports this yet. ## Syntax ```css :empty { /* ... */ } ``` ## Examples ### HTML ```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 ```css hidden body { display: flex; justify-content: space-around; } ``` ```css .box { background: pink; height: 80px; width: 80px; } .box:empty { background: lime; } ``` ### Result {{EmbedLiveSample("Examples", 300, 80)}} ## 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](/en-US/docs/Web/HTML/Element/a), [buttons](/en-US/docs/Web/HTML/Element/button), etc.). Accessible names expose the interactive control to the [accessibility tree](/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](/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 {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef(":-moz-only-whitespace")}} {{Non-standard_Inline}} – The {{glossary("Vendor_Prefix", "prefixed")}} implementation of the changes in [Selectors Level 4](https://drafts.csswg.org/selectors-4/#the-empty-pseudo) - {{CSSxRef(":blank")}} {{Experimental_Inline}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_invalid/index.md
--- title: ":invalid" slug: Web/CSS/:invalid page-type: css-pseudo-class browser-compat: css.selectors.invalid --- {{CSSRef}} The **`:invalid`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents any {{HTMLElement("form")}}, {{HTMLElement("fieldset")}}, {{HTMLElement("input")}} or other {{HTMLElement("form")}} element whose contents fail to [validate](/en-US/docs/Web/HTML/Constraint_validation). {{EmbedInteractiveExample("pages/tabbed/pseudo-class-invalid.html", "tabbed-shorter")}} This pseudo-class is useful for highlighting field errors for the user. ## Syntax ```css :invalid { /* ... */ } ``` ## Examples ### Coloring elements to show validation #### HTML ```html <form> <div class="field"> <label for="url_input">Enter a URL:</label> <input type="url" id="url_input" /> </div> <div class="field"> <label for="email_input">Enter an email address:</label> <input type="email" id="email_input" required /> </div> </form> ``` #### CSS ```css label { display: block; margin: 1px; padding: 1px; } .field { margin: 1px; padding: 1px; } input: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 {{EmbedLiveSample('Coloring elements to show validation', 600, 200)}} ### Showing sections in stages In this example we use `:invalid` along with `~`, the [subsequent-sibling combinator](/en-US/docs/Web/CSS/Subsequent-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 ```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 ```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 {{EmbedLiveSample('Showing sections in stages', 600, 300)}} ## 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](/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 {{Cssxref("box-shadow")}} property) to the {{cssxref(":user-invalid")}} pseudo-class, which applies in a subset of cases for `:invalid`. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Other validation-related pseudo-classes: {{ cssxref(":required") }}, {{ cssxref(":optional") }}, {{ cssxref(":valid") }} - Related Mozilla pseudo-classes: {{cssxref(":user-invalid")}}, {{cssxref(":-moz-submit-invalid")}} - [Form data validation](/en-US/docs/Learn/Forms/Form_validation) - Accessing the [validity state](/en-US/docs/Web/API/ValidityState) from JavaScript
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_paused/index.md
--- title: ":paused" slug: Web/CSS/:paused page-type: css-pseudo-class browser-compat: css.selectors.paused --- {{CSSRef}} The **`:paused`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) selector represents an element that is playable, such as {{htmlelement("audio")}} or {{htmlelement("video")}}, when that element is "paused" (i.e. not "playing"). A resource is paused if the user explicitly paused it, or if it is in a non-activated or other non-playing state, like "loaded, hasn't been activated yet". This is different from `:buffering` or `:stalled`, which are states that occur while the resource is considered "playing". ## Syntax ```css :paused { /* ... */ } ``` ## Examples ### CSS ```css :paused { border: 5px solid orange; } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref(":buffering")}} - {{cssxref(":muted")}} - {{cssxref(":playing")}} - {{cssxref(":seeking")}} - {{cssxref(":stalled")}} - {{cssxref(":volume-locked")}} - [CSS selectors](/en-US/docs/Web/CSS/CSS_selectors)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-left-width/index.md
--- title: border-left-width slug: Web/CSS/border-left-width page-type: css-property browser-compat: css.properties.border-left-width --- {{CSSRef}} The **`border-left-width`** [CSS](/en-US/docs/Web/CSS) property sets the width of the left border of an element. {{EmbedInteractiveExample("pages/css/border-left-width.html")}} ## Syntax ```css /* 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 {{cssxref("&lt;length&gt;")}} 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 {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Comparing border widths #### HTML ```html <div>Element 1</div> <div>Element 2</div> ``` #### CSS ```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 {{EmbedLiveSample('Comparing_border_widths', '100%')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - The other border-width-related CSS properties: {{Cssxref("border-top-width")}}, {{Cssxref("border-right-width")}}, {{Cssxref("border-bottom-width")}}, and {{Cssxref("border-width")}}. - The other border-left-related CSS properties: {{Cssxref("border")}}, {{Cssxref("border-left")}}, {{Cssxref("border-left-style")}}, and {{Cssxref("border-left-color")}}.
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/box-ordinal-group/index.md
--- title: box-ordinal-group slug: Web/CSS/box-ordinal-group page-type: css-property status: - deprecated - non-standard browser-compat: css.properties.box-ordinal-group --- {{CSSRef}}{{Non-standard_Header}}{{Deprecated_Header}} > **Warning:** This is a property of the original CSS Flexible Box Layout Module draft. It has been replaced in the specification. See [flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox) for information about the current standard. The **`box-ordinal-group`** [CSS](/en-US/docs/Web/CSS) property assigns the flexbox's child elements to an ordinal group. Ordinal groups may be used in conjunction with the {{CSSxRef("box-direction")}} property to control the order in which the direct children of a box appear. When the computed `box-direction` is normal, a box will display its elements starting from the lowest numbered ordinal group and ensure that those elements appear to the left (for horizontal boxes) or at the top (for vertical boxes) of the container. Elements with the same ordinal group are flowed in the order they appear in the source document tree. In the reverse direction, the ordinal groups are examined in the same order, except the elements appear reversed. ## Syntax ```css /* <integer> values */ box-ordinal-group: 1; box-ordinal-group: 5; /* Global values */ box-ordinal-group: inherit; box-ordinal-group: initial; box-ordinal-group: unset; ``` The `box-ordinal-group` property is specified as any positive {{CSSxRef("&lt;integer&gt;")}}. ## Formal definition {{CSSInfo}} ## Formal syntax ```plain box-ordinal-group = <integer> ``` ## Examples ### Basic usage example In an older version of the spec, `box-ordinal-group` was included to allow you to change the display order of flex children inside a flex container: ```css article:nth-child(1) { -webkit-box-ordinal-group: 2; -moz-box-ordinal-group: 2; box-ordinal-group: 2; } article:nth-child(2) { -webkit-box-ordinal-group: 1; -moz-box-ordinal-group: 1; box-ordinal-group: 1; } ``` The modern flexbox equivalent is {{cssxref("order")}}. ## Specifications Not part of any standard. ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("flex")}} - {{CSSxRef("flex-basis")}} - {{CSSxRef("flex-grow")}} - {{CSSxRef("flex-shrink")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/view-transition-name/index.md
--- title: view-transition-name slug: Web/CSS/view-transition-name page-type: css-property status: - experimental browser-compat: css.properties.view-transition-name --- {{CSSRef}}{{SeeCompatTable}} The **`view-transition-name`** [CSS](/en-US/docs/Web/CSS) property provides the selected element with a distinct identifying name (a {{cssxref("custom-ident")}}) and causes it to participate in a separate [view transition](/en-US/docs/Web/API/View_Transitions_API) from the root view transition β€” or no view transition if the `none` value is specified. ## Syntax ```css /* <custom-ident> value examples */ view-transition-name: header; view-transition-name: figure-caption; /* Keyword value */ view-transition-name: none; ``` ### Values - {{cssxref("custom-ident")}} - : A distinct identifying name that causes the selected element to participate in a separate [view transition](/en-US/docs/Web/API/View_Transitions_API) from the root view transition. The identifier must be unique. If two rendered elements have the same `view-transition-name` at the same time, {{domxref("ViewTransition.ready")}} will reject and the transition will be skipped. - `none` - : The selected element will not participate in a view transition. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ```css figcaption { view-transition-name: figure-caption; } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [View Transitions API](/en-US/docs/Web/API/View_Transitions_API) - [Smooth and simple transitions with the View Transitions API](https://developer.chrome.com/docs/web-platform/view-transitions/)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/margin-inline/index.md
--- title: margin-inline slug: Web/CSS/margin-inline page-type: css-shorthand-property browser-compat: css.properties.margin-inline --- {{CSSRef}} The **`margin-inline`** [CSS](/en-US/docs/Web/CSS) [shorthand property](/en-US/docs/Web/CSS/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. {{EmbedInteractiveExample("pages/css/margin-inline.html")}} ## Constituent properties This property is a shorthand for the following CSS properties: - {{cssxref("margin-inline-start")}} - {{cssxref("margin-inline-end")}} ## Syntax ```css /* <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 {{CSSxRef("margin-top")}} and {{CSSxRef("margin-bottom")}}, or the {{CSSxRef("margin-right")}} and {{CSSxRef("margin-left")}} properties, depending on the values defined for {{CSSxRef("writing-mode")}}, {{CSSxRef("direction")}}, and {{CSSxRef("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 {{CSSxRef("margin", "", "#values")}} property. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting inline start and end margins #### CSS ```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 ```html <div> <p>Example text</p> </div> <div class="verticalExample"> <p>Example text</p> </div> ``` #### Result {{EmbedLiveSample("Setting_inline_start_and_end_margins", 140, 240)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS Logical Properties and Values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values) - The mapped physical properties: {{CSSxRef("margin-top")}}, {{CSSxRef("margin-right")}}, {{CSSxRef("margin-bottom")}}, and {{CSSxRef("margin-left")}} - {{CSSxRef("writing-mode")}}, {{CSSxRef("direction")}}, {{CSSxRef("text-orientation")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_-webkit-slider-runnable-track/index.md
--- title: "::-webkit-slider-runnable-track" slug: Web/CSS/::-webkit-slider-runnable-track page-type: css-pseudo-element status: - experimental browser-compat: css.selectors.-webkit-slider-runnable-track --- {{CSSRef}}{{SeeCompatTable}} The **`::-webkit-slider-runnable-track`** CSS [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) represents the "track" (the groove in which the indicator slides) of an {{HTMLElement("input/range", '&lt;input type="range"&gt;')}}. ## Syntax ```css ::-webkit-slider-runnable-track { /* ... */ } ``` ## Specifications Not part of any standard. ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("::-webkit-slider-thumb")}} - Similar pseudo-elements used by other browsers: - {{CSSxRef("::-moz-range-track")}} - [CSS-Tricks: Styling Cross-Browser Compatible Range Inputs with CSS](https://css-tricks.com/styling-cross-browser-compatible-range-inputs-css/) - [QuirksMode: Styling and scripting sliders](https://www.quirksmode.org/blog/archives/2015/11/styling_and_scr.html)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/attr/index.md
--- title: attr() slug: Web/CSS/attr page-type: css-function browser-compat: css.types.attr --- {{CSSRef}} > **Note:** The `attr()` function can be used with any CSS property, but support for properties other than {{CSSxRef("content")}} is experimental, and support for the type-or-unit parameter is sparse. The **`attr()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) is used to retrieve the value of an attribute of the selected element and use it in the stylesheet. It can also be used on [pseudo-elements](/en-US/docs/Web/CSS/Pseudo-elements), in which case the value of the attribute on the pseudo-element's originating element is returned. {{EmbedInteractiveExample("pages/tabbed/function-attr.html", "tabbed-shorter")}} ## Syntax ```css /* Simple usage */ attr(data-count); attr(title); /* With type */ attr(src url); attr(data-count number); attr(data-width px); /* With fallback */ attr(data-count number, 0); attr(src url, ""); attr(data-width px, inherit); attr(data-something, "default"); ``` ### Values - `attribute-name` - : The name of an attribute on the HTML element referenced in the CSS. - `<type-or-unit>` {{Experimental_Inline}} - : A keyword representing either the type of the attribute's value, or its unit, as in HTML some attributes have implicit units. If the use of `<type-or-unit>` as a value for the given attribute is invalid, the `attr()` expression will be invalid too. If omitted, it defaults to `string`. The list of valid values are: - `string` - : The attribute value is treated as a CSS {{CSSxRef("&lt;string&gt;")}}. It is NOT reparsed, and in particular the characters are used as-is instead of CSS escapes being turned into different characters. Default value: an empty string. - `color` {{Experimental_Inline}} - : The attribute value is parsed as a hash (3- or 6-value hash) or a keyword. It must be a valid CSS {{CSSxRef("&lt;string&gt;")}} value. Leading and trailing spaces are stripped. Default value: `currentcolor`. - `url` {{Experimental_Inline}} - : The attribute value is parsed as a string that is used inside a CSS `url()` function. Relative URL are resolved relatively to the original document, not relatively to the style sheet. Leading and trailing spaces are stripped. Default value: the URL `about:invalid` that points to a non-existent document with a generic error condition. - `integer` {{Experimental_Inline}} - : The attribute value is parsed as a CSS {{CSSxRef("&lt;integer&gt;")}}. If it is not valid, that is not an integer or out of the range accepted by the CSS property, the default value is used. Leading and trailing spaces are stripped. Default value: `0`, or, if `0` is not a valid value for the property, the property's minimum value. - `number` {{Experimental_Inline}} - : The attribute value is parsed as a CSS {{CSSxRef("&lt;number&gt;")}}. If it is not valid, that is not a number or out of the range accepted by the CSS property, the default value is used. Leading and trailing spaces are stripped. Default value: `0`, or, if `0` is not a valid value for the property, the property's minimum value. - `length` {{Experimental_Inline}} - : The attribute value is parsed as a CSS {{CSSxRef("&lt;length&gt;")}} dimension, that is including the unit (e.g. `12.5em`). If it is not valid, that is not a length or out of the range accepted by the CSS property, the default value is used. If the given unit is a relative length, `attr()` computes it to an absolute length. Leading and trailing spaces are stripped. Default value: `0`, or, if `0` is not a valid value for the property, the property's minimum value. - `em`, `ex`, `px`, `rem`, `vw`, `vh`, `vmin`, `vmax`, `mm`, `cm`, `in`, `pt`, or `pc` {{Experimental_Inline}} - : The attribute value is parsed as a CSS {{CSSxRef("&lt;number&gt;")}}, that is without the unit (e.g. `12.5`), and interpreted as a {{CSSxRef("&lt;length&gt;")}} with the specified unit. If it is not valid, that is not a number or out of the range accepted by the CSS property, the default value is used. If the given unit is a relative length, `attr()` computes it to an absolute length. Leading and trailing spaces are stripped. Default value: `0`, or, if `0` is not a valid value for the property, the property's minimum value. - `angle` {{Experimental_Inline}} - : The attribute value is parsed as a CSS {{CSSxRef("&lt;angle&gt;")}} dimension, that is including the unit (e.g. `30.5deg`). If it is not valid, that is not an angle or out of the range accepted by the CSS property, the default value is used. Leading and trailing spaces are stripped. Default value: `0deg`, or, if `0deg` is not a valid value for the property, the property's minimum value. - `deg`, `grad`, `rad` {{Experimental_Inline}} - : The attribute value is parsed as a CSS {{CSSxRef("&lt;number&gt;")}}, that is without the unit (e.g. `12.5`), and interpreted as an {{CSSxRef("&lt;angle&gt;")}} with the specified unit. If it is not valid, that is not a number or out of the range accepted by the CSS property, the default value is used. Leading and trailing spaces are stripped. Default value: `0deg`, or, if `0deg` is not a valid value for the property, the property's minimum value. - `time` {{Experimental_Inline}} - : The attribute value is parsed as a CSS {{CSSxRef("&lt;time&gt;")}} dimension, that is including the unit (e.g. `30.5ms`). If it is not valid, that is not a time or out of the range accepted by the CSS property, the default value is used. Leading and trailing spaces are stripped. Default value: `0s`, or, if `0s` is not a valid value for the property, the property's minimum value. - `s`, `ms` {{Experimental_Inline}} - : The attribute value is parsed as a CSS {{CSSxRef("&lt;number&gt;")}}, that is without the unit (e.g. `12.5`), and interpreted as an {{CSSxRef("&lt;time&gt;")}} with the specified unit. If it is not valid, that is not a number or out of the range accepted by the CSS property, the default value is used. Leading and trailing spaces are stripped. Default value: `0s`, or, if `0s` is not a valid value for the property, the property's minimum value. - `frequency` {{Experimental_Inline}} - : The attribute value is parsed as a CSS {{CSSxRef("&lt;frequency&gt;")}} dimension, that is including the unit (e.g. `30.5kHz`). If it is not valid, that is not a frequency or out of the range accepted by the CSS property, the default value is used. Default value: `0Hz`, or, if `0Hz` is not a valid value for the property, the property's minimum value. - `Hz`, `kHz` {{Experimental_Inline}} - : The attribute value is parsed as a CSS {{CSSxRef("&lt;number&gt;")}}, that is without the unit (e.g. `12.5`), and interpreted as a {{CSSxRef("&lt;frequency&gt;")}} with the specified unit. If it is not valid, that is not a number or out of the range accepted by the CSS property, the default value is used. Leading and trailing spaces are stripped. Default value: `0Hz`, or, if `0Hz` is not a valid value for the property, the property's minimum value. - `%` {{Experimental_Inline}} - : The attribute value is parsed as a CSS {{CSSxRef("&lt;number&gt;")}}, that is without the unit (e.g. `12.5`), and interpreted as a {{CSSxRef("&lt;percentage&gt;")}}. If it is not valid, that is not a number or out of the range accepted by the CSS property, the default value is used. If the given value is used as a length, `attr()` computes it to an absolute length. Leading and trailing spaces are stripped. Default value: `0%`, or, if `0%` is not a valid value for the property, the property's minimum value. - `<fallback>` {{Experimental_Inline}} - : The value to be used if the associated attribute is missing or contains an invalid value. If not set, CSS will use the default value defined for each `<type-or-unit>`. ### Formal syntax {{CSSSyntax}} ## Examples ### content property In this example, we prepend the value of the `data-foo` [`data-*`](/en-US/docs/Web/HTML/Global_attributes/data-*) [global attribute](/en-US/docs/Web/HTML/Global_attributes) to the contents of the {{HTMLElement("p")}} element. #### HTML ```html <p data-foo="hello">world</p> ``` #### CSS ```css [data-foo]::before { content: attr(data-foo) " "; } ``` #### Result {{EmbedLiveSample("content_property", "100%", 50)}} ### color value {{SeeCompatTable}} In this example, we set the CSS value of {{CSSXRef("background-color")}} to the value of the `data-background` [`data-*`](/en-US/docs/Web/HTML/Global_attributes/data-*) [global attribute](/en-US/docs/Web/HTML/Global_attributes) assigned to the {{HTMLElement("div")}} element. #### HTML ```html <div class="background" data-background="lime"> background expected to be red if your browser does not support advanced usage of attr() </div> ``` #### CSS ```css hidden .background { height: 100vh; } ``` ```css .background { background-color: red; } .background[data-background] { background-color: attr(data-background color, red); } ``` #### Result {{EmbedLiveSample("color_value", "100%", 50)}} ### using fallback {{SeeCompatTable}} In this example, we append the value of `data-browser` [`data-*`](/en-US/docs/Web/HTML/Global_attributes/data-*) [global attribute](/en-US/docs/Web/HTML/Global_attributes) to the {{HTMLElement("p")}} element. If the `data-browser` attribute is missing from the {{HTMLElement("p")}} element, we append the _fallback_ value of "**Unknown**". #### HTML ```html <p data-browser="Firefox">My favorite browser is:</p> <p>Your favorite browser is:</p> ``` #### CSS ```css p::after { content: " " attr(data-browser, "Unknown"); color: tomato; } ``` #### Result {{EmbedLiveSample("using_fallback", "100%", 90)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Attribute selectors](/en-US/docs/Web/CSS/Attribute_selectors) - [HTML `data-*` attributes](/en-US/docs/Web/HTML/Global_attributes/data-*) - [SVG `data-*` attributes](/en-US/docs/Web/SVG/Attribute/data-*)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/universal_selectors/index.md
--- title: Universal selectors slug: Web/CSS/Universal_selectors page-type: css-selector browser-compat: css.selectors.universal --- {{CSSRef}} The CSS **universal selector** (`*`) matches elements of any type. ```css /* Selects all elements */ * { color: green; } ``` The universal selector is a special [type selector](/en-US/docs/Web/CSS/Type_selectors) and can therefore be namespaced when using {{CSSXref("@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 ```css * { style properties } ``` The asterisk is optional with simple selectors. For instance, `*.warning` and `.warning` are equivalent. ## Examples ### CSS ```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 ```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 {{EmbedLiveSample('Examples')}} ### Namespaces In this example the selector will only match elements in the example namespace. ```css @namespace example url(http://www.example.com); example|* { color: blue; } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS selectors](/en-US/docs/Web/CSS/CSS_selectors) module - [Learn CSS: Selectors](/en-US/docs/Learn/CSS/Building_blocks/Selectors)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_color_adjustment/index.md
--- title: CSS color adjustment slug: Web/CSS/CSS_color_adjustment page-type: css-module spec-urls: https://drafts.csswg.org/css-color-adjust-1/ --- {{CSSRef}} The **CSS color adjustment** module provides a model and controls automatic color adjustment by the user agent to handle user preferences, such as "Dark Mode", contrast adjustment, and other color scheme preferences. Together with the {{CSSxRef("@media")}} features {{cssxref("@media/prefers-color-scheme", "prefers-color-scheme")}}, {{cssxref("@media/prefers-contrast", "prefers-contrast")}} and {{cssxref("@media/forced-colors", "forced-colors")}}, this module defines how and when colors are automatically adjusted by the browser. ## Reference ### Properties - {{cssxref("color-scheme")}} - {{cssxref("forced-color-adjust")}} - {{cssxref("print-color-adjust")}} ## Related concepts - {{cssxref("&lt;color&gt;")}} CSS data type - Related {{CSSxRef("@media")}} features: - {{cssxref("@media/prefers-color-scheme", "prefers-color-scheme")}} - {{cssxref("@media/prefers-contrast", "prefers-contrast")}} - {{cssxref("@media/forced-colors", "forced-colors")}} - Properties affected by forced colors mode - {{cssxref("accent-color")}} - {{cssxref("background-color")}} - {{cssxref("background-image")}} - {{cssxref("border-color")}} - {{cssxref("box-shadow")}} - {{cssxref("caret-color")}} - {{cssxref("color")}} - {{cssxref("color-scheme")}} - {{cssxref("column-rule-color")}} - [`fill`](/en-US/docs/Web/SVG/Attribute/fill) - [`flood-color`](/en-US/docs/Web/SVG/Attribute/flood-color) - [`lighting-color`](/en-US/docs/Web/SVG/Attribute/lighting-color) - {{cssxref("outline-color")}} - {{cssxref("scrollbar-color")}} - [`stop-color`](/en-US/docs/Web/SVG/Attribute/stop-color) - [`stroke`](/en-US/docs/Web/SVG/Attribute/stroke) - {{cssxref("text-decoration-color")}} - {{cssxref("text-emphasis-color")}} - {{cssxref("text-shadow")}} - {{cssxref("-webkit-tap-highlight-color")}} ## Specifications {{Specifications}} ## See also - [CSS colors](/en-US/docs/Web/CSS/CSS_colors) module
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_current/index.md
--- title: ":current" slug: Web/CSS/:current page-type: css-pseudo-class browser-compat: css.selectors.current spec-urls: https://drafts.csswg.org/selectors/#the-current-pseudo --- {{CSSRef}} The **`:current`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/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](/en-US/docs/Web/API/WebVTT_API). ```css :current(p, span) { background-color: yellow; } ``` ## Syntax ```css-nolint :current { /* ... */ } :current(<compound-selector-list>) { /* ... */ } ``` ## Examples ### CSS ```css :current(p, span) { background-color: yellow; } ``` ### HTML ```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 ```plain 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 {{Specifications}} ## Browser compatibility There is no browser implementing this feature. ## See also - [Web Video Text Tracks Format (WebVTT)](/en-US/docs/Web/API/WebVTT_API) - {{cssxref(":past")}} - {{cssxref(":future")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/-webkit-mask-box-image/index.md
--- title: "-webkit-mask-box-image" slug: Web/CSS/-webkit-mask-box-image page-type: css-property status: - non-standard browser-compat: css.properties.-webkit-mask-box-image --- {{CSSRef}} {{ Non-standard_header() }} The non-standard prefixed **`-webkit-mask-box-image`** [shorthand](/en-US/docs/Web/CSS/Shorthand_properties) property sets the mask image for an element's border box. > **Note:** This property is not standard and is not on any standards track. Consider using the {{CSSXref("mask-border")}} property instead. ## Constituent properties This property is a shorthand for the following CSS properties: - [`-webkit-mask-box-image-source`](/en-US/docs/Web/CSS/mask-border-source) - [`-webkit-mask-box-image-outset`](/en-US/docs/Web/CSS/mask-border-outset) - [`-webkit-mask-box-image-repeat`](/en-US/docs/Web/CSS/mask-border-repeat) The values includes the `<image>` to be used as the mask border, and optionally four border outset values and up to two border repeat styles. ## Syntax ```css /* default */ -webkit-mask-box-image: none; /* image */ -webkit-mask-box-image: url(image.png); /* image edge-offset */ -webkit-mask-box-image: url(image.png) 10 20 20 10; -webkit-mask-box-image: url(image.png) 10px 20px 20px 10px; /* image repeat-style */ -webkit-mask-box-image: url(image.png) space repeat; /* image edge-offset repeat-style */ -webkit-mask-box-image: url(image.png) 10px 20px 20px 10px space repeat; /* Global values */ -webkit-mask-box-image: inherit; -webkit-mask-box-image: initial; -webkit-mask-box-image: revert; -webkit-mask-box-image: revert-layer; -webkit-mask-box-image: unset; ``` ### Values - {{cssxref("&lt;image&gt;")}} - : The location of the image resource to be used as a mask image, {{cssxref("&lt;gradient&gt;")}}, or other {{cssxref("&lt;image&gt;")}} value. - `none` - : Used to specify that a border box is to have no mask image. - {{cssxref("length")}} - : The size of the mask image's offset. See {{cssxref("&lt;length&gt;")}} for possible units. - `{{cssxref("percentage")}}` - : The mask image's offset has a percentage value relative to the border box's corresponding dimension (width or height). - {{cssxref("number")}} - : The size of the mask image's offset in pixels. - `repeat` - : The mask image is repeated as many times as is necessary to span the border box. May include a partial image if the mask image does not divide evenly into the border box. - `stretch` - : The mask image is stretched to contain the border box exactly. - `round` - : The mask image is stretched somewhat and repeated such that there is no partial mask image at the end of the border box. - `space` - : The mask image is repeated as many times as possible without stretching. There is no partial mask image at the end of the border box. The outset values, or edge offsets, define the distances from the top, right, bottom, and left edges of the image, in that order. The values can be set as {{cssxref("length")}}, {{cssxref("number")}}, or {{cssxref("percentage")}}, with numbers interpreted as pixel lengths. Border repeat styles, when included, are interpreted in the order of `<repeat-x> <repeat-y>`. If only one value is declared, the value is the same for both axes. While similar to `{{cssxref("background-repeat")}}`, the `cover` and `contain` values are not supported. ## Formal definition - [Initial value](/en-US/docs/Web/CSS/initial_value): `none` - Applies to: all elements - [Inherited](/en-US/docs/Web/CSS/Inheritance): no - [Computed value](/en-US/docs/Web/CSS/computed_value): as specified ## Formal syntax ```plain -webkit-mask-box-image: <mask-image-source> [<mask-image-offset>{4} <mask-border-repeat>{1,2} ] Where: <mask-image-source> = {{cssxref("url", "&lt;uri&gt;")}} | <gradient> | none <mask-image-offset> = <length> | <percentage> | <number> <repeat-style> = repeat | stretch | round | space ``` ## Examples ### Setting an image ```css .exampleone { -webkit-mask-box-image: url("mask.png"); } ``` ### Offsetting and filling an image ```css .exampletwo { -webkit-mask-box-image: url("logo.png") 100 100 0 0 round round; } ``` ## Specifications Not part of any standard. ## Browser compatibility {{Compat}} ## See also - CSS {{ cssxref("mask-border") }} property - CSS {{ cssxref("border-image") }} property - [Safari CSS reference: `-webkit-mask-box-image`](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html#//apple_ref/doc/uid/TP30001266-SW14)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-image-width/index.md
--- title: border-image-width slug: Web/CSS/border-image-width page-type: css-property browser-compat: css.properties.border-image-width --- {{CSSRef}} The **`border-image-width`** [CSS](/en-US/docs/Web/CSS) property sets the width of an element's [border image](/en-US/docs/Web/CSS/border-image). {{EmbedInteractiveExample("pages/css/border-image-width.html")}} If this property's value is greater than the element's {{cssxref("border-width")}}, the border image will extend beyond the padding (and/or content) edge. ## Syntax ```css /* 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 {{cssxref("&lt;length&gt;")}} or a {{cssxref("&lt;percentage&gt;")}}. 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 {{cssxref("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 {{cssxref("border-image-slice")}}. If the image does not have the required intrinsic dimension, the corresponding `border-width` is used instead. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Tiling a border image This example creates a border image using the following ".png" file, which is 90 by 90 pixels: ![Square image containing eight circles. The circles in each corner are light purple. The four side circles are blue. The area in the middle, where a ninth circle could fit, is blank.](border.png) Thus, each circle in the source image is 30 by 30 pixels. #### HTML ```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 ```css p { border: 20px solid; border-image: url("border.png") 30 round; border-image-width: 16px; padding: 40px; } ``` #### Result {{EmbedLiveSample('Tiling_a_border_image', 200, 240)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Backgrounds and borders](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders) - [Learn CSS: Backgrounds and borders](/en-US/docs/Learn/CSS/Building_blocks/Backgrounds_and_borders) - [Border images in CSS: A key focus area for Interop 2023](/en-US/blog/border-images-interop-2023/) on MDN blog (2023)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_cascade/index.md
--- title: CSS cascade and inheritance slug: Web/CSS/CSS_cascade page-type: css-module spec-urls: - https://drafts.csswg.org/css-cascade/ - https://drafts.csswg.org/css-cascade-5/ --- {{CSSRef}} The **CSS cascade and inheritance** module defines the rules for assigning values to properties by way of cascading and inheritance. This module specifies the rules for finding the specified value for all properties on all elements. One of the fundamental design principles of CSS is cascading of rules. It allows several style sheets to influence the presentation of a document. CSS property-value declarations define how a document is rendered. Multiple declarations may set different values for the same element and property combination, but only one value can be applied to any CSS property. The CSS cascade module defines how these conflicts are resolved. The opposite also occurs. Sometimes there are no declarations defining the value of a property. The CSS cascade module defines how these missing values should be set via inheritance or from the property's initial value. > **Note:** The rules for finding the specified values in the page context and its margin boxes are described in the [CSS page module](/en-US/docs/Web/CSS/CSS_paged_media). ## Reference ### Properties - {{cssxref("all")}} ### At-rules - {{cssxref("@import")}} - {{cssxref("@layer")}} ### Keywords - {{cssxref("initial")}} - {{cssxref("inherit")}} - {{cssxref("revert")}} - {{cssxref("revert-layer")}} {{Experimental_Inline}} - {{cssxref("unset")}} - {{cssxref("important", "!important")}} flag ### Interfaces - {{DOMXRef("CSSLayerBlockRule")}} - {{DOMXRef("CSSGroupingRule")}} - {{DOMXRef("CSSLayerStatementRule")}} - {{DOMXRef("CSSRule")}} ### Key concepts and definitions - {{cssxref("Specificity")}} - [Cascade origin and importance](/en-US/docs/Web/CSS/Cascade) - [Values](/en-US/docs/Web/CSS/Value_definition_syntax) - [actual value](/en-US/docs/Web/CSS/actual_value) - [computed value](/en-US/docs/Web/CSS/computed_value) - [initial value](/en-US/docs/Web/CSS/initial_value) - [resolved value](/en-US/docs/Web/CSS/resolved_value) - [specified value](/en-US/docs/Web/CSS/specified_value) - [used value](/en-US/docs/Web/CSS/used_value) - [Origin types](/en-US/docs/Web/CSS/Cascade#origin_types) - [user-agent origin](/en-US/docs/Web/CSS/Cascade#user-agent_stylesheets) - [author origin](/en-US/docs/Web/CSS/Cascade#author_stylesheets) - [user origin](/en-US/docs/Web/CSS/Cascade#user_stylesheets) - [Declaring layers](/en-US/docs/Web/CSS/@import#importing_css_rules_into_a_cascade_layer) - [named layer](/en-US/docs/Learn/CSS/Building_blocks/Cascade_layers#the_layer_statement_at-rule_for_named_layers) - [anonymous layer](/en-US/docs/Learn/CSS/Building_blocks/Cascade_layers#the-layer-block-at-rule-for-named-and-anonymous-layers) - Glossary: {{glossary("style origin")}} ## Guides - [Introducing the CSS Cascade](/en-US/docs/Web/CSS/Cascade) - : Guide to the cascade algorithm that defines how user agents combine property values originating from different sources. - [Learn: Cascade, specificity, and inheritance](/en-US/docs/Learn/CSS/Building_blocks/Cascade_and_inheritance) - : The most fundamental concepts of CSS β€” the cascade, specificity, and inheritance β€” which control how CSS is applied to HTML and how conflicts are resolved. - [Learn: Cascade layers](/en-US/docs/Learn/CSS/Building_blocks/Cascade_layers) - : Introduction to [cascade layers](/en-US/docs/Web/CSS/@layer), a more advanced feature that builds on the fundamental concepts of the [CSS cascade](/en-US/docs/Web/CSS/Cascade) and [CSS specificity](/en-US/docs/Web/CSS/Specificity). - [CSS inheritance](/en-US/docs/Web/CSS/Inheritance) - : A guide to CSS inheritance. ## Related concepts - [Element-attached styles](/en-US/docs/Web/HTML/Global_attributes/style) - [Inline styles and the cascade](/en-US/docs/Web/CSS/Cascade#inline_styles) - [Conditional rules for @imports](/en-US/docs/Web/CSS/@import#importing_css_rules_conditional_on_media_queries) ## Specifications {{Specifications}} ## See also - [CSS selectors module](/en-US/docs/Web/CSS/CSS_selectors) - [CSS pseudo-elements module](/en-US/docs/Web/CSS/CSS_pseudo-elements) - [CSS paged media module](/en-US/docs/Web/CSS/CSS_paged_media) - [CSS conditional rules module](/en-US/docs/Web/CSS/CSS_conditional_rules) - [CSS nesting module](/en-US/docs/Web/CSS/CSS_nesting) - [Shorthand properties](/en-US/docs/Web/CSS/Shorthand_properties)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/privacy_and_the__colon_visited_selector/index.md
--- title: Privacy and the :visited selector slug: Web/CSS/Privacy_and_the_:visited_selector page-type: guide --- {{CSSRef}} Before about 2010, the [CSS](/en-US/docs/Web/CSS) {{ cssxref(":visited") }} selector allowed websites to uncover a user's browsing history and figure out what sites the user had visited. This was done through {{domxref("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 {{ domxref("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: - {{ cssxref("color") }} - {{ cssxref("background-color") }} - {{ cssxref("border-color") }} (and its sub-properties) - {{ cssxref("column-rule-color") }} - {{ cssxref("outline-color") }} - {{ cssxref("text-decoration-color") }} - {{ cssxref("text-emphasis-color") }} - The color parts of the {{SVGAttr("fill")}} and {{SVGAttr("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()`](/en-US/docs/Web/CSS/color_value/rgb) or [`hsl()`](/en-US/docs/Web/CSS/color_value/hsl), or the [`transparent`](/en-US/docs/Web/CSS/named-color#transparent) keyword. Here is an example of how to use styles with the aforementioned restrictions: ```css :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)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-inline/index.md
--- title: border-inline slug: Web/CSS/border-inline page-type: css-shorthand-property browser-compat: css.properties.border-inline --- {{CSSRef}} The **`border-inline`** [CSS](/en-US/docs/Web/CSS) property is a [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) for setting the individual logical inline border property values in a single place in the style sheet. {{EmbedInteractiveExample("pages/css/border-inline.html")}} The physical borders to which `border-inline` maps depends on the element's writing mode, directionality, and text orientation. It corresponds to the {{cssxref("border-top")}} and {{cssxref("border-bottom")}} or {{cssxref("border-right")}}, and {{cssxref("border-left")}} properties, depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. The borders in the other dimension can be set with {{cssxref("border-block")}}, which sets {{cssxref("border-block-start")}}, and {{cssxref("border-block-end")}}. ## Constituent properties This property is a shorthand for the following CSS properties: - [`border-inline-color`](/en-US/docs/Web/CSS/border-inline-color) - [`border-inline-style`](/en-US/docs/Web/CSS/border-inline-style) - [`border-inline-width`](/en-US/docs/Web/CSS/border-inline-width) ## Syntax ```css border-inline: 1px; border-inline: 2px dotted; border-inline: medium dashed blue; /* Global values */ border-inline: inherit; border-inline: initial; border-inline: revert; border-inline: revert-layer; border-inline: unset; ``` ### Values The `border-inline` is specified with one or more of the following, in any order: - `<'border-width'>` - : The width of the border. See {{cssxref("border-width")}}. - `<'border-style'>` - : The line style of the border. See {{cssxref("border-style")}}. - {{CSSXref("&lt;color&gt;")}} - : The color of the border. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Border with vertical text #### HTML ```html <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ```css div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-rl; border-inline: 5px dashed blue; } ``` #### Results {{EmbedLiveSample("Border_with_vertical_text", 140, 140)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS Logical Properties and Values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values) - This property maps to one of the physical border properties: {{cssxref("border-top")}}, {{cssxref("border-right")}}, {{cssxref("border-bottom")}}, or {{cssxref("border-left")}}. - {{cssxref("writing-mode")}}, {{cssxref("direction")}}, {{cssxref("text-orientation")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/background-position/index.md
--- title: background-position slug: Web/CSS/background-position page-type: css-property browser-compat: css.properties.background-position --- {{CSSRef}} The **`background-position`** [CSS](/en-US/docs/Web/CSS) property sets the initial position for each background image. The position is relative to the position layer set by {{cssxref("background-origin")}}. {{EmbedInteractiveExample("pages/css/background-position.html")}} ## Syntax ```css /* 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 {{cssxref("&lt;position&gt;")}}. 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`, or `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 {{cssxref("&lt;length&gt;")}} or {{cssxref("&lt;percentage&gt;")}}. 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`, or `right`. If `left` or `right` is given, then this defines X and the other given value defines Y. If `top` or `bottom` is given, then this defines Y and the other value defines X. - A {{cssxref("&lt;length&gt;")}} or {{cssxref("&lt;percentage&gt;")}}. 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 {{cssxref("&lt;length&gt;")}} or {{cssxref("&lt;percentage&gt;")}} 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 {{cssxref("&lt;length&gt;")}} or {{cssxref("&lt;percentage&gt;")}} 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 {{cssxref("&lt;length&gt;")}} or {{cssxref("&lt;percentage&gt;")}} values is not valid. **4-value syntax:** The first and third values are keyword values defining X and Y. The second and fourth values are offsets for the preceding X and Y keyword values: - The first and third values are equal to one of the keyword values `top`, `left`, `bottom`, or `right`. If `left` or `right` is given for the first value, then this defines X and the other value defines Y. If `top` or `bottom` is given for the first value, then this defines Y and the other keyword value defines X. - The second and fourth values are {{cssxref("&lt;length&gt;")}} or {{cssxref("&lt;percentage&gt;")}} 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. ```plain (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: ```plain 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: ```plain -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 {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Positioning background images Each of these three examples uses the {{cssxref("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 ```html <div class="exampleone">Example One</div> <div class="exampletwo">Example Two</div> <div class="examplethree">Example Three</div> ``` #### CSS ```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 {{EmbedLiveSample('Positioning_background_images', 420, 200)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("background-position-x")}} - {{cssxref("background-position-y")}} - [Using multiple backgrounds](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders/Using_multiple_backgrounds) - {{cssxref("transform-origin")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/white-space/index.md
--- title: white-space slug: Web/CSS/white-space page-type: css-property browser-compat: css.properties.white-space --- {{CSSRef}} The **`white-space`** CSS property sets how {{Glossary("whitespace", "white space")}} inside an element is handled. {{EmbedInteractiveExample("pages/css/white-space.html")}} The property specifies two things: - Whether and how white space is [collapsed](#collapsing_of_white_space). - Whether and how lines wrap. > **Note:** To make words break _within themselves_, use {{CSSxRef("overflow-wrap")}}, {{CSSxRef("word-break")}}, or {{CSSxRef("hyphens")}} instead. ## Syntax ```css /* Single keyword values */ white-space: normal; white-space: nowrap; white-space: pre; white-space: pre-wrap; white-space: pre-line; white-space: break-spaces; /* white-space-collapse and text-wrap shorthand values */ white-space: collapse balance; white-space: preserve nowrap; /* Global values */ white-space: inherit; white-space: initial; white-space: revert; white-space: revert-layer; white-space: unset; ``` ### Values `white-space` property values can be specified as a single keyword chosen from the list of values below, or two values representing shorthand for the {{CSSxRef("white-space-collapse")}} and {{cssxref("text-wrap")}} properties. - `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 {{HTMLElement("br")}} elements. - `pre-wrap` - : Sequences of white space are preserved. Lines are broken at newline characters, at {{HTMLElement("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 {{HTMLElement("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, thus affecting the box's intrinsic sizes (`min-content` size and `max-content` size). The following table summarizes the behavior of the various `white-space` keyword values: <table class="standard-table"> <thead> <tr> <th></th> <th>New lines</th> <th>Spaces and tabs</th> <th>Text wrapping</th> <th>End-of-line spaces</th> <th>End-of-line other space separators</th> </tr> </thead> <tbody> <tr> <th><code>normal</code></th> <td>Collapse</td> <td>Collapse</td> <td>Wrap</td> <td>Remove</td> <td>Hang</td> </tr> <tr> <th><code>nowrap</code></th> <td>Collapse</td> <td>Collapse</td> <td>No wrap</td> <td>Remove</td> <td>Hang</td> </tr> <tr> <th><code>pre</code></th> <td>Preserve</td> <td>Preserve</td> <td>No wrap</td> <td>Preserve</td> <td>No wrap</td> </tr> <tr> <th><code>pre-wrap</code></th> <td>Preserve</td> <td>Preserve</td> <td>Wrap</td> <td>Hang</td> <td>Hang</td> </tr> <tr> <th><code>pre-line</code></th> <td>Preserve</td> <td>Collapse</td> <td>Wrap</td> <td>Remove</td> <td>Hang</td> </tr> <tr> <th><code>break-spaces</code></th> <td>Preserve</td> <td>Preserve</td> <td>Wrap</td> <td>Wrap</td> <td>Wrap</td> </tr> </tbody> </table> > **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 {{cssxref("white-space-collapse")}} property page explains the [browser algorithm for collapsing white space](/en-US/docs/Web/CSS/white-space-collapse#collapsing_of_white_space). ## Formal definition {{CSSInfo}} ## Formal syntax {{CSSSyntax}} ## Examples ### Basic example ```css code { white-space: pre; } ``` ### Line breaks inside \<pre> elements ```css pre { white-space: pre-wrap; } ``` ### In action ```html hidden <div id="css-code" class="box"> p { white-space: <select> <option>normal</option> <option>nowrap</option> <option>pre</option> <option>pre-wrap</option> <option>pre-line</option> <option>break-spaces</option> <option>preserve nowrap</option> </select> } </div> <div id="results" class="box"> <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> </div> ``` ```css hidden .box { width: 300px; padding: 16px; } #css-code { background-color: rgb(220 220 220); font-size: 16px; font-family: monospace; } #css-code select { font-family: inherit; } #results { background-color: rgb(230 230 230); overflow-x: scroll; white-space: normal; font-size: 14px; } ``` ```js hidden const select = document.querySelector("#css-code select"); const results = document.querySelector("#results p"); select.addEventListener("change", (e) => { results.setAttribute("style", `white-space: ${e.target.value}`); }); ``` {{EmbedLiveSample("In_action", "100%", 350)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Properties that define how words break _within themselves_: {{CSSxRef("overflow-wrap")}}, {{CSSxRef("word-break")}}, {{CSSxRef("hyphens")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_masking/index.md
--- title: CSS masking slug: Web/CSS/CSS_masking page-type: css-module spec-urls: https://drafts.fxtf.org/css-masking/ --- {{CSSRef}} The **CSS masking** module that defines masking and clipping for partially or fully hiding portions of visual elements. ## Reference ### Properties - {{cssxref("clip")}} {{deprecated_inline}} - {{cssxref("clip-path")}} - {{cssxref("clip-rule")}} - {{cssxref("mask")}} - {{cssxref("mask-border")}} - {{cssxref("mask-border-mode")}} - {{cssxref("mask-border-outset")}} - {{cssxref("mask-border-repeat")}} - {{cssxref("mask-border-slice")}} - {{cssxref("mask-border-source")}} - {{cssxref("mask-border-width")}} - {{cssxref("mask-clip")}} - {{cssxref("mask-composite")}} - {{cssxref("mask-image")}} - {{cssxref("mask-mode")}} - {{cssxref("mask-origin")}} - {{cssxref("mask-position")}} - {{cssxref("mask-repeat")}} - {{cssxref("mask-size")}} - {{cssxref("mask-type")}} ## Specifications {{Specifications}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_-moz-page/index.md
--- title: "::-moz-page" slug: Web/CSS/::-moz-page page-type: css-pseudo-element status: - non-standard browser-compat: css.selectors.-moz-page --- {{CSSRef}}{{Non-standard_header}} The **`::-moz-page`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) is a [Mozilla extension](/en-US/docs/Web/CSS/Mozilla_Extensions) that represents an individual page when printed or in a print preview. ## Syntax ```css ::-moz-page { /* ... */ } ``` ## Specifications Not part of any standard. ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("::-moz-page-sequence")}} - {{CSSxRef("::-moz-scrolled-page-sequence")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/text-emphasis/index.md
--- title: text-emphasis slug: Web/CSS/text-emphasis page-type: css-shorthand-property browser-compat: css.properties.text-emphasis --- {{CSSRef}} The **`text-emphasis`** [CSS](/en-US/docs/Web/CSS) property applies emphasis marks to text (except spaces and control characters). It is a [shorthand](/en-US/docs/Web/CSS/Shorthand_properties) for {{cssxref("text-emphasis-style")}} and {{cssxref("text-emphasis-color")}}. {{EmbedInteractiveExample("pages/css/text-emphasis.html")}} The `text-emphasis` property is quite different from {{cssxref("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 {{cssxref("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 {{cssxref("text-emphasis-position")}}. ## Constituent properties This property is a shorthand for the following CSS properties: - [`text-emphasis-color`](/en-US/docs/Web/CSS/text-emphasis-color) - [`text-emphasis-style`](/en-US/docs/Web/CSS/text-emphasis-style) ## Syntax ```css /* 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 {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### A heading with emphasis shape and color This example draws a heading with triangles used to emphasize each character. #### CSS ```css h2 { text-emphasis: triangle #d55; } ``` #### HTML ```html <h2>This is important!</h2> ``` #### Result {{EmbedLiveSample("A_heading_with_emphasis_shape_and_color", 500, 90)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - The longhand properties {{cssxref('text-emphasis-style')}}, {{cssxref('text-emphasis-color')}}. - The {{cssxref('text-emphasis-position')}} property allowing to define the position of the emphasis marks.
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/type_selectors/index.md
--- title: Type selectors slug: Web/CSS/Type_selectors page-type: css-selector browser-compat: css.selectors.type --- {{CSSRef}} The CSS **type selector** matches elements by node name. In other words, it selects all elements of the given type within a document. ```css /* All <a> elements. */ a { color: red; } ``` Type selectors can be namespaced when using {{CSSXref("@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|h1` - matches `<h1>` elements in namespace _ns_ - `*|h1` - matches all `<h1>` elements - `|h1` - matches all `<h1>` elements without any declared namespace ## Syntax ```css element { style properties } ``` ## Examples ### CSS ```css span { background-color: skyblue; } ``` ### HTML ```html <span>Here's a span with some text.</span> <p>Here's a p with some text.</p> <span>Here's a span with more text.</span> ``` ### Result {{EmbedLiveSample('Examples', '100%', 150)}} ### Namespaces In this example the selector will only match `<h1>` elements in the example namespace. ```css @namespace example url(http://www.example.com); example|h1 { color: blue; } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS Selectors](/en-US/docs/Web/CSS/CSS_selectors) - [Learn CSS: Selectors](/en-US/docs/Learn/CSS/Building_blocks/Selectors)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/flex-grow/index.md
--- title: flex-grow slug: Web/CSS/flex-grow page-type: css-property browser-compat: css.properties.flex-grow --- {{CSSRef}} The **`flex-grow`** [CSS](/en-US/docs/Web/CSS) property sets the flex grow factor, which specifies how much of the flex container's remaining space should be assigned to the flex item's [main size](https://www.w3.org/TR/css-flexbox/#main-size). When the flex-container's main size is larger than the combined main sizes of the flex items, the extra space is distributed among the flex items, with each item growth being their growth factor value as a proportion of the sum total of all the container's items' flex grow factors. {{EmbedInteractiveExample("pages/css/flex-grow.html")}} ## Syntax ```css /* <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 {{cssxref("&lt;number&gt;")}}. 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 {{cssxref("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 {{cssxref("flex-shrink")}} and {{cssxref("flex-basis")}}, and normally defined using the {{cssxref("flex")}} shorthand to ensure all values are set. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting flex item grow factor In this example, there is a total of 8 growth factors distributed among the 6 flex items, meaning each growth factor is 12.5% of the remaining space. #### HTML ```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="small" style="background-color:red;">A</div> <div class="small" style="background-color:lightblue;">B</div> <div class="small" style="background-color:yellow;">C</div> <div class="double" style="background-color:brown;">D</div> <div class="double" style="background-color:lightgreen;">E</div> <div class="small" style="background-color:brown;">F</div> </div> ``` #### CSS ```css #content { display: flex; justify-content: space-around; flex-flow: row wrap; align-items: stretch; } .small { flex-grow: 1; border: 3px solid rgb(0 0 0 / 20%); } .double { flex-grow: 2; border: 3px solid rgb(0 0 0 / 20%); } ``` #### Result {{EmbedLiveSample('Setting flex item grow factor')}} When the six flex items are distributed along the container's main axis, if the sum of the main content of those flex items is less than the size of the container's main axis, the extra space is distributed among the size flex items, with A, B, C, and F, each getting 12.5% of the remaining space and D and E each getting 25% of the extra space. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - CSS Flexbox Guide: _[Basic Concepts of Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox)_ - CSS Flexbox Guide: _[Controlling Ratios of flex items along the main axis](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Controlling_ratios_of_flex_items_along_the_main_axis)_ - [`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
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/mask-border/index.md
--- title: mask-border slug: Web/CSS/mask-border page-type: css-shorthand-property browser-compat: css.properties.mask-border --- {{CSSRef}} The **`mask-border`** [CSS](/en-US/docs/Web/CSS) [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) lets you create a mask along the edge of an element's border. ## Constituent properties This property is a shorthand for the following CSS properties: - [`mask-border-mode`](/en-US/docs/Web/CSS/mask-border-mode) - [`mask-border-outset`](/en-US/docs/Web/CSS/mask-border-outset) - [`mask-border-repeat`](/en-US/docs/Web/CSS/mask-border-repeat) - [`mask-border-slice`](/en-US/docs/Web/CSS/mask-border-slice) - [`mask-border-source`](/en-US/docs/Web/CSS/mask-border-source) - [`mask-border-width`](/en-US/docs/Web/CSS/mask-border-width) ## Syntax ```css /* source | slice */ mask-border: url("border-mask.png") 25; /* source | slice | repeat */ mask-border: url("border-mask.png") 25 space; /* source | slice | width */ mask-border: url("border-mask.png") 25 / 35px; /* source | slice | width | outset | repeat | mode */ mask-border: url("border-mask.png") 25 / 35px / 12px space alpha; /* Global values */ mask-border: inherit; mask-border: initial; mask-border: revert; mask-border: revert-layer; mask-border: unset; ``` ### Values - `<'mask-border-source'>` - : The source image. See {{cssxref("mask-border-source")}}. - `<'mask-border-slice'>` - : The dimensions for slicing the source image into regions. Up to four values may be specified. See {{cssxref("mask-border-slice")}}. - `<'mask-border-width'>` - : The width of the border mask. Up to four values may be specified. See {{cssxref("mask-border-width")}}. - `<'mask-border-outset'>` - : The distance of the border mask from the element's outside edge. Up to four values may be specified. See {{cssxref("mask-border-outset")}}. - `<'mask-border-repeat'>` - : Defines how the edge regions of the source image are adjusted to fit the dimensions of the border mask. Up to two values may be specified. See {{cssxref("mask-border-repeat")}}. - `<'mask-border-mode'>` - : Defines whether the source image is treated as a luminance mask or alpha mask. See {{cssxref("mask-border-mode")}}. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting a bitmap-based mask border In this example, we will mask an element's border with a diamond pattern. The source for the mask is a ".png" file of 90 by 90 pixels, with three diamonds going vertically and horizontally: ![The image used for the mask examples on this page. The mask is a transparent square with three rows of three diamonds each. The diamonds are a very light, almost white, shade of grey. The middle part between the diamonds is also solid grey. The parts between the outside of the diamonds and the edge of the image are transparent.](mask-border-diamonds.png) To match the size of a single diamond, we will use a value of 90 divided by 3, or `30`, for slicing the image into corner and edge regions. A repeat value of `round` will make the mask slices fit evenly, i.e., without clipping or gaps. {{EmbedGHLiveSample("css-examples/masking/mask-border.html", '100%', 800)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("mask-border-mode")}} - {{cssxref("mask-border-outset")}} - {{cssxref("mask-border-repeat")}} - {{cssxref("mask-border-source")}} - {{cssxref("mask-border-width")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_last-child/index.md
--- title: ":last-child" slug: Web/CSS/:last-child page-type: css-pseudo-class browser-compat: css.selectors.last-child --- {{CSSRef}} The **`:last-child`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents the last element among a group of sibling elements. {{EmbedInteractiveExample("pages/tabbed/pseudo-class-last-child.html", "tabbed-shorter")}} ## Syntax ```css :last-child { /* ... */ } ``` ## Examples ### Basic example #### HTML ```html <div> <p>This text isn't selected.</p> <p>This text is selected!</p> </div> <div> <p>This text isn't selected.</p> <h2>This text isn't selected: it's not a `p`.</h2> </div> ``` #### CSS ```css p:last-child { color: lime; background-color: black; padding: 5px; } ``` #### Result {{EmbedLiveSample('Basic_example', 500, 200)}} ### Styling a list #### HTML ```html <ul> <li>Item 1</li> <li>Item 2</li> <li> Item 3 <ul> <li>Item 3.1</li> <li>Item 3.2</li> <li>Item 3.3</li> </ul> </li> </ul> ``` #### CSS ```css ul li { color: blue; } ul li:last-child { border: 1px solid red; color: red; } ``` #### Result {{EmbedLiveSample('Styling_a_list')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef(":-moz-last-node")}} {{Non-standard_Inline}} - {{CSSxRef(":last-of-type")}} - {{CSSxRef(":first-child")}} - {{CSSxRef(":nth-child")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/white-space-collapse/index.md
--- title: white-space-collapse slug: Web/CSS/white-space-collapse page-type: css-property browser-compat: css.properties.white-space-collapse --- {{CSSRef}} The **`white-space-collapse`** CSS property controls how {{Glossary("whitespace", "white space")}} inside an element is collapsed. > **Note:** The `white-space-collapse` and {{CSSxRef("text-wrap")}} properties can be declared together using the {{CSSxRef("white-space")}} shorthand property. ## Syntax ```css /* Keyword values */ white-space-collapse: collapse; white-space-collapse: preserve; white-space-collapse: preserve-breaks; white-space-collapse: preserve-spaces; white-space-collapse: break-spaces; /* Global values */ white-space-collapse: inherit; white-space-collapse: initial; white-space-collapse: revert; white-space-collapse: revert-layer; white-space-collapse: unset; ``` The `white-space-collapse` property is specified as a single keyword chosen from the list of values below. ### Values - `collapse` - : White space sequences are [collapsed](#collapsing_of_white_space). - `preserve` - : White space sequences and segment break characters are preserved. - `preserve-breaks` - : White space sequences are collapsed, while segment break characters are preserved. - `preserve-spaces` - : White space sequences are preserved, while tabs and segment break characters are converted to spaces. - `break-spaces` - : The behavior is identical to `preserve`, 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. - Preserved spaces take up space and do not hang, thus affecting the box's intrinsic sizes (`min-content` size and `max-content` size). > **Note:** _Segment break characters_ are characters such as line feeds that cause text to break onto new lines. ## Collapsing of white space User agents handle white space collapsing as follows: - Tabs are generally converted to spaces. - If segment breaks are to be collapsed: - Sequences of segment breaks are collapsed down to a single segment break. - They are converted to spaces in the case of languages that separate words with spaces (like English), or removed altogether in the case of languages that do not separate words with spaces (like Chinese). - If spaces are to be collapsed: - Spaces or tabs before or after segment breaks are removed. - Sequences of spaces are converted, or "collapsed", to a single space. - When spaces are preserved, sequences of spaces are treated as non-breaking except that they will soft-wrap at the end of each sequence β€” i.e. the next line will always start with the next non-space character. In the case of the `break-spaces` value however, a soft wrap could potentially occur after each space, so the next line may start with one or more spaces. ## Formal definition {{CSSInfo}} ## Formal syntax {{CSSSyntax}} ## Examples ### HTML <!-- prettier-ignore-start --> ```html <h2 class="collapse">Default behavior; all whitespace is collapsed in the heading .</h2> <h2 class="preserve">In this case all whitespace is preserved in the heading .</h2> <h2 class="preserve-breaks">In this case only the line break is preserved in the heading .</h2> ``` <!-- prettier-ignore-end --> ### CSS ```css .collapse { white-space-collapse: collapse; } .preserve { white-space-collapse: preserve; } .preserve-breaks { white-space-collapse: preserve-breaks; } h2 { font-size: 1.6rem; font-family: monospace; } ``` ### Result {{EmbedLiveSample("Examples", "100%", 350)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Shorthand for `white-space-collapse` and {{CSSxRef("text-wrap")}}: The {{CSSxRef("white-space")}} property. - [CSS text module](/en-US/docs/Web/CSS/CSS_text)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/float/index.md
--- title: float slug: Web/CSS/float page-type: css-property browser-compat: css.properties.float --- {{CSSRef}} 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](/en-US/docs/Web/CSS/position#absolute_positioning)). {{EmbedInteractiveExample("pages/css/float.html")}} 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 {{cssxref("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:** When accessing a CSS property in JavaScript through the {{domxref("HTMLElement.style")}} object, single-word property names are used as is. Although `float` is a reserved keyword in JavaScript, the CSS `float` property is accessed as `float` in modern browsers. In older browsers, you must use `cssFloat` to access the `float` property. (This is similar to how the "class" attribute is accessed as "className" and the "for" attribute of a `<label>` element is accessed as "htmlFor".) ## Syntax ```css /* 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 {{cssinfo}} ## Formal syntax {{csssyntax}} ## 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 ```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 ```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 {{EmbedLiveSample('How_floated_elements_are_positioned','400','190')}} ### 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 {{cssxref("clear")}} for examples. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Block formatting context](/en-US/docs/Web/CSS/CSS_display/Block_formatting_context) - Use {{cssxref("clear")}} to force an item to move below a floated element.
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/specified_value/index.md
--- title: Specified value slug: Web/CSS/specified_value page-type: guide spec-urls: https://www.w3.org/TR/CSS22/cascade.html#specified-value --- {{CSSRef}} The **specified value** of a [CSS](/en-US/docs/Web/CSS) property is the value it receives from the document's style sheet. The specified value for a given property is determined according to the following rules: 1. If the document's style sheet explicitly specifies a value for the property, the given value will be used. 2. If the document's style sheet doesn't specify a value but it is an inherited property, the value will be taken from the parent element. 3. If none of the above pertain, the element's [initial value](/en-US/docs/Web/CSS/initial_value) will be used. ## Examples ### HTML ```html <p>My specified color is given explicitly in the CSS.</p> <div> The specified values of all my properties default to their initial values, because none of them are given in the CSS. </div> <div class="fun"> <p> The specified value of my font family is not given explicitly in the CSS, so it is inherited from my parent. However, the border is not an inheriting property. </p> </div> ``` ### CSS ```css .fun { border: 1px dotted pink; font-family: fantasy; } p { color: green; } ``` ### Result {{EmbedLiveSample("Examples", 500, 220)}} ## Specifications {{Specifications}} ## See also - CSS key concepts: - [CSS syntax](/en-US/docs/Web/CSS/Syntax) - [At-rules](/en-US/docs/Web/CSS/At-rule) - [Comments](/en-US/docs/Web/CSS/Comments) - [Specificity](/en-US/docs/Web/CSS/Specificity) - [Inheritance](/en-US/docs/Web/CSS/Inheritance) - [Box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model) - [Layout modes](/en-US/docs/Web/CSS/Layout_mode) - [Visual formatting models](/en-US/docs/Web/CSS/Visual_formatting_model) - [Margin collapsing](/en-US/docs/Web/CSS/CSS_box_model/Mastering_margin_collapsing) - Values - [Initial values](/en-US/docs/Web/CSS/initial_value) - [Computed values](/en-US/docs/Web/CSS/computed_value) - [Used values](/en-US/docs/Web/CSS/used_value) - [Actual values](/en-US/docs/Web/CSS/actual_value) - [Value definition syntax](/en-US/docs/Web/CSS/Value_definition_syntax) - [Shorthand properties](/en-US/docs/Web/CSS/Shorthand_properties) - [Replaced elements](/en-US/docs/Web/CSS/Replaced_element)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/overscroll-behavior-block/index.md
--- title: overscroll-behavior-block slug: Web/CSS/overscroll-behavior-block page-type: css-property browser-compat: css.properties.overscroll-behavior-block --- {{CSSRef}} The **`overscroll-behavior-block`** CSS property sets the browser's behavior when the block direction boundary of a scrolling area is reached. See {{cssxref("overscroll-behavior")}} for a full explanation. ## Syntax ```css /* 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; ``` 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 (e.g., "bounce" effects) is observed inside the element where this value is set. However, no {{Glossary("Scroll_chaining", "scroll chaining")}} occurs on neighboring scrolling areas; the underlying elements will not scroll. The `contain` value disables native browser navigation, including the vertical pull-to-refresh gesture and horizontal swipe navigation. - `none` - : No scroll chaining occurs to neighboring scrolling areas, and default scroll overflow behavior is prevented. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Preventing block overscrolling In this demo we have two block-level boxes, one inside the other. The outer box has a large {{cssxref("height")}} set on it so the page will scroll vertically. The inner box has a small {{cssxref("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 ```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 ```css main { height: 3000px; width: 500px; background-color: white; background-image: repeating-linear-gradient( to bottom, rgb(0 0 0 / 0%) 0px, rgb(0 0 0 / 0%) 19px, rgb(0 0 0 / 50%) 20px ); } main > div { height: 300px; width: 400px; overflow: auto; position: relative; top: 50px; left: 50px; overscroll-behavior-block: contain; } div > div { height: 1500px; width: 100%; background-color: yellow; background-image: repeating-linear-gradient( to bottom, rgb(0 0 0 / 0%) 0px, rgb(0 0 0 / 0%) 19px, rgb(0 0 0 / 50%) 20px ); } p { padding: 10px; background-color: rgb(255 0 0 / 50%); margin: 0; width: 340px; position: relative; top: 10px; left: 10px; } ``` #### Result {{EmbedLiveSample('Preventing_block_overscrolling','100%', 500)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Take control of your scroll: customizing pull-to-refresh and overflow effects](https://developer.chrome.com/blog/overscroll-behavior/#full-demo)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_-moz-page-sequence/index.md
--- title: "::-moz-page-sequence" slug: Web/CSS/::-moz-page-sequence page-type: css-pseudo-element status: - non-standard browser-compat: css.selectors.-moz-page-sequence --- {{CSSRef}}{{Non-standard_Header}} The **`::-moz-page-sequence`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) is a [Mozilla extension](/en-US/docs/Web/CSS/Mozilla_Extensions) that represents the background of a print preview. ## Syntax ```css ::-moz-page-sequence { /* ... */ } ``` ## Specifications Not part of any standard. ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("::-moz-page")}} - {{CSSxRef("::-moz-scrolled-page-sequence")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/column-fill/index.md
--- title: column-fill slug: Web/CSS/column-fill page-type: css-property browser-compat: css.properties.column-fill --- {{CSSRef}} The **`column-fill`** [CSS](/en-US/docs/Web/CSS) property controls how an element's contents are balanced when broken into columns. {{EmbedInteractiveExample("pages/css/column-fill.html")}} ## Syntax ```css /* 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](/en-US/docs/Web/CSS/CSS_paged_media), only the last fragment is balanced. Therefore in paged media, only the last page would be balanced. - `balance-all` {{Experimental_Inline}} - : Content is equally divided between columns. In fragmented contexts, such as [paged media](/en-US/docs/Web/CSS/CSS_paged_media), all fragments are balanced. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Balancing column content #### HTML ```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 ```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 {{EmbedLiveSample('Balancing_column_content', 'auto', 320)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} > **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](/en-US/docs/Learn/CSS/CSS_layout/Multiple-column_Layout) - {{CSSXref("column-count")}} - {{CSSXref("column-width")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_-webkit-meter-suboptimum-value/index.md
--- title: "::-webkit-meter-suboptimum-value" slug: Web/CSS/::-webkit-meter-suboptimum-value page-type: css-pseudo-element status: - non-standard browser-compat: css.selectors.-webkit-meter-suboptimum-value --- {{CSSRef}}{{Non-standard_header}} The **`::-webkit-meter-suboptimum-value`** [pseudo-element](/en-US/docs/Glossary/Pseudo-element) styles the {{htmlelement("meter")}} element when the value attribute falls outside of the low-high range and is not equivalent to the optimum value. Yellow is the default color. ## Syntax ```css ::-webkit-meter-suboptimum-value { /* ... */ } ``` ## Examples This example will only work in browsers based on WebKit or Blink. ### HTML ```html Normal: <meter min="0" max="10" low="3" high="7" optimum="6" value="2"> Score 2/10 </meter> <br /> Styled: <meter id="styled" min="0" max="10" low="3" high="7" optimum="6" value="2"> Score 2/10 </meter> ``` ### CSS ```css body { font-family: monospace; } .safari meter { /* Reset the default appearance for Safari only */ /* .safari class is added via JavaScript */ -webkit-appearance: none; } #styled::-webkit-meter-suboptimum-value { background: linear-gradient(to bottom, #ff7, #990 45%, #990 55%, #ff7); height: 100%; box-sizing: border-box; } ``` ### JavaScript ```js // Safari requires <meter> elements to have an `appearance` of `none` for custom styling // using `::-webkit-meter-*` selectors, but `appearance: none` breaks rendering on Chrome. // Therefore, we must check if the browser is Safari-based. const is_safari = navigator.userAgent.includes("AppleWebKit/") && !navigator.userAgent.includes("Chrome/"); if (is_safari) { document.body.classList.add("safari"); } ``` ### Result {{ EmbedLiveSample('Examples', '100%', 50) }} ## Specifications Not part of any standard. ## Browser compatibility {{Compat}} ## See also The pseudo-elements used by WebKit/Blink to style other parts of a {{htmlelement("meter")}} element are as follows: - {{cssxref("::-webkit-meter-inner-element")}} - {{cssxref("::-webkit-meter-bar")}} - {{cssxref("::-webkit-meter-even-less-good-value")}} - {{cssxref("::-webkit-meter-optimum-value")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/-webkit-mask-attachment/index.md
--- title: "-webkit-mask-attachment" slug: Web/CSS/-webkit-mask-attachment page-type: css-property status: - non-standard browser-compat: css.properties.-webkit-mask-attachment --- {{CSSRef}}{{Non-standard_Header}} If a {{CSSxRef("mask-image")}} is specified, `-webkit-mask-attachment` determines whether the mask image's position is fixed within the viewport, or scrolls along with its containing block. ## Syntax ```css /* Keyword values */ -webkit-mask-attachment: scroll; -webkit-mask-attachment: fixed; -webkit-mask-attachment: local; /* Multiple values */ -webkit-mask-attachment: scroll, local; -webkit-mask-attachment: fixed, local, scroll; /* Global values */ -webkit-mask-attachment: inherit; -webkit-mask-attachment: initial; -webkit-mask-attachment: revert; -webkit-mask-attachment: revert-layer; -webkit-mask-attachment: unset; ``` ### Values - scroll - : If `scroll` is specified, the mask image scrolls within the viewport along with the block that contains the mask image. - fixed - : If `fixed` is specified, the mask image does not scroll with its containing element, instead remaining stationary within the viewport. ## Formal definition {{CSSInfo}} ## Formal syntax ```plain -webkit-mask-attachment = <attachment># ``` ## Examples ### Fixing a mask image to the viewport ```css body { -webkit-mask-image: url("images/mask.png"); -webkit-mask-attachment: fixed; } ``` ## Specifications Not part of any standard. ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("mask")}} - {{CSSxRef("mask-clip")}} - {{CSSxRef("-webkit-mask-box-image")}} - {{CSSxRef("mask-origin")}} - {{CSSxRef("mask-image")}} - {{CSSxRef("-webkit-mask-composite")}} - {{CSSxRef("mask-repeat")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/view-timeline-axis/index.md
--- title: view-timeline-axis slug: Web/CSS/view-timeline-axis page-type: css-property status: - experimental browser-compat: css.properties.view-timeline-axis --- {{CSSRef}}{{SeeCompatTable}} The **`view-timeline-axis`** [CSS](/en-US/docs/Web/CSS) property is used to specify the scrollbar direction that will be used to provide the timeline for a _named view progress timeline_ animation, which is progressed through based on the change in visibility of an element (known as the _subject_) inside a scrollable element (_scroller_). `view-timeline-axis` is set on the subject. See [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations) for more details. > **Note:** If the scroller element does not overflow its container in the axis dimension or if the overflow is hidden or clipped, no scroll progress timeline will be created. The `view-timeline-axis` and {{cssxref("view-timeline-name")}} properties can also be set using the [`view-timeline`](/en-US/docs/Web/CSS/view-timeline) shorthand property. ## Syntax ```css /* Logical property values */ view-timeline-axis: block; view-timeline-axis: inline; /* Non-logical property values */ view-timeline-axis: y; view-timeline-axis: x; ``` ### Values Allowed values for `view-timeline-axis` are: - `block` - : The scrollbar on the block axis of the scroller element, which is the axis in the direction perpendicular to the flow of text within a line. For horizontal writing modes, such as standard English, this is the same as `y`, while for vertical writing modes, it is the same as `x`. This is the default value. - `inline` - : The scrollbar on the inline axis of the scroller element, which is the axis in the direction parallel to the flow of text in a line. For horizontal writing modes, this is the same as `x`, while for vertical writing modes, this is the same as `y`. - `y` - : The scrollbar on the vertical axis of the scroller element. - `x` - : The scrollbar on the horizontal axis of the scroller element. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Defining the axis of the view progress timeline In this example, a view progress timeline named `--subjectReveal` is defined using the `view-timeline-name` property on a subject element with a class of "animation". This timeline is then applied to the animation on the same element, using `animation-timeline: --subjectReveal;`. To demonstrate the effect of `view-timeline-axis`, a horizontal (non-default) scrollbar is used in this example to drive the animation. #### HTML The HTML for the example is shown below. ```html <div class="content"> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p> <p> Risus quis varius quam quisque id. Et ligula ullamcorper malesuada proin libero nunc consequat interdum varius. Elit ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at augue. </p> <p> Dolor sed viverra ipsum nunc aliquet. Sed sed risus pretium quam vulputate dignissim. Tortor aliquam nulla facilisi cras. </p> <p> A erat nam at lectus urna duis convallis convallis. Nibh ipsum consequat nisl vel pretium lectus. </p> <p> Sagittis aliquam malesuada bibendum arcu vitae elementum. Malesuada bibendum arcu vitae elementum curabitur vitae nunc sed velit. </p> <div class="subject animation"></div> <p> Adipiscing enim eu turpis egestas pretium aenean pharetra magna ac. Arcu cursus vitae congue mauris rhoncus aenean vel. Sit amet cursus sit amet dictum. Augue neque gravida in fermentum et. Gravida rutrum quisque non tellus orci ac auctor augue mauris. </p> </div> ``` #### CSS In the CSS, we set the `subject` element as the source of a view progress timeline named `--subjectReveal` using the `view-timeline-name` property. The scroll axis is set using `view-timeline-axis: x;` (Chromium) and `view-timeline-axis: horizontal;` (Firefox) β€” this causes the _horizontal scrollbar_ position of the scrolling ancestor element to determine the animation timeline. The `content` ancestor element is made to overflow horizontally by laying out its contents using `display: flex;` and `flex-flow: column wrap;`. Also worth noting is that the subject element has an `animation-duration` applied to it so that the example will work in Firefox. ```css .subject { width: 300px; height: 200px; margin: 0 auto; background-color: deeppink; } .content { width: 50%; height: 400px; margin-top: 30px; display: flex; flex-flow: column wrap; gap: 10px; } p { font-family: Arial, Helvetica, sans-serif; } p { font-size: 1.3rem; line-height: 1.4; } .animation { view-timeline-name: --subjectReveal; /* Chromium supports the new x/y syntax */ view-timeline-axis: x; /* Firefox still supports the old horizontal/vertical syntax */ view-timeline-axis: horizontal; animation-name: appear; animation-fill-mode: both; animation-timeline: --subjectReveal; animation-duration: 1ms; /* Firefox requires this to apply the animation */ } @keyframes appear { from { opacity: 0; transform: scaleX(0); } to { opacity: 1, transform: scaleX(1); } } ``` #### Result Scroll the horizontal bar at the bottom to see the subject element animate as you scroll. {{EmbedLiveSample("Defining_the_axis_of_the_view_progress_timeline", "100%", "450px")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`animation-timeline`](/en-US/docs/Web/CSS/animation-timeline) - {{cssxref("timeline-scope")}} - [`view-timeline`](/en-US/docs/Web/CSS/view-timeline), [`view-timeline-name`](/en-US/docs/Web/CSS/view-timeline-name) - [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/transform-function/index.md
--- title: <transform-function> slug: Web/CSS/transform-function page-type: css-type browser-compat: css.types.transform-function --- {{CSSRef}} The **`<transform-function>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) represents a transformation that affects an element's appearance. Transformation [functions](/en-US/docs/Web/CSS/CSS_Functions) can rotate, resize, distort, or move an element in 2D or 3D space. It is used in the {{cssxref("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()`](/en-US/docs/Web/CSS/transform-function/matrix) - : Describes a homogeneous 2D transformation matrix. - [`matrix3d()`](/en-US/docs/Web/CSS/transform-function/matrix3d) - : Describes a 3D transformation as a 4Γ—4 homogeneous matrix. ### Perspective - [`perspective()`](/en-US/docs/Web/CSS/transform-function/perspective) - : Sets the distance between the user and the z=0 plane. ### Rotation - [`rotate()`](/en-US/docs/Web/CSS/transform-function/rotate) - : Rotates an element around a fixed point on the 2D plane. - [`rotate3d()`](/en-US/docs/Web/CSS/transform-function/rotate3d) - : Rotates an element around a fixed axis in 3D space. - [`rotateX()`](/en-US/docs/Web/CSS/transform-function/rotateX) - : Rotates an element around the horizontal axis. - [`rotateY()`](/en-US/docs/Web/CSS/transform-function/rotateY) - : Rotates an element around the vertical axis. - [`rotateZ()`](/en-US/docs/Web/CSS/transform-function/rotateZ) - : Rotates an element around the z-axis. ### Scaling (resizing) - [`scale()`](/en-US/docs/Web/CSS/transform-function/scale) - : Scales an element up or down on the 2D plane. - [`scale3d()`](/en-US/docs/Web/CSS/transform-function/scale3d) - : Scales an element up or down in 3D space. - [`scaleX()`](/en-US/docs/Web/CSS/transform-function/scaleX) - : Scales an element up or down horizontally. - [`scaleY()`](/en-US/docs/Web/CSS/transform-function/scaleY) - : Scales an element up or down vertically. - [`scaleZ()`](/en-US/docs/Web/CSS/transform-function/scaleZ) - : Scales an element up or down along the z-axis. ### Skewing (distortion) - [`skew()`](/en-US/docs/Web/CSS/transform-function/skew) - : Skews an element on the 2D plane. - [`skewX()`](/en-US/docs/Web/CSS/transform-function/skewX) - : Skews an element in the horizontal direction. - [`skewY()`](/en-US/docs/Web/CSS/transform-function/skewY) - : Skews an element in the vertical direction. ### Translation (moving) - [`translate()`](/en-US/docs/Web/CSS/transform-function/translate) - : Translates an element on the 2D plane. - [`translate3d()`](/en-US/docs/Web/CSS/transform-function/translate3d) - : Translates an element in 3D space. - [`translateX()`](/en-US/docs/Web/CSS/transform-function/translateX) - : Translates an element horizontally. - [`translateY()`](/en-US/docs/Web/CSS/transform-function/translateY) - : Translates an element vertically. - [`translateZ()`](/en-US/docs/Web/CSS/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)`. ![A cartesian plane showing the negative Y and positive X axis starting from origin with three points P1, P2 and P3 with corresponding X and Y values](coord_in_r2.png) 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: <math><mrow><mo>(</mo><mtable><mtr><mtd><mi>a</mi></mtd><mtd><mi>c</mi></mtd></mtr> <mtr><mtd><mi>b</mi></mtd><mtd><mi>d</mi></mtd></mtr></mtable><mo>)</mo></mrow></math> The function is applied to an element by using matrix multiplication. Thus, each coordinate changes based on the values in the matrix: <math><mrow><mo>(</mo><mtable><mtr><mtd><mi>a</mi></mtd><mtd><mi>c</mi></mtd></mtr> <mtr><mtd><mi>b</mi></mtd><mtd><mi>d</mi></mtd></mtr> </mtable><mo>)</mo></mrow><mrow><mo>(</mo><mtable><mtr><mtd><mi>x</mi></mtd></mtr><mtr><mtd><mi>y</mi></mtd></mtr> </mtable><mo>)</mo></mrow><mo>=</mo> <mrow><mo>(</mo><mtable><mtr><mtd><mi>a</mi><mi>x</mi><mo>+</mo><mi>c</mi><mi>y</mi></mtd> </mtr><mtr><mtd><mi>b</mi><mi>x</mi><mo>+</mo><mi>d</mi><mi>y</mi></mtd></mtr></mtable><mo>)</mo></mrow></math> It is even possible to apply several transformations in a row: <math><mrow><mo>(</mo><mtable><mtr><mtd><msub><mi>a</mi><mn>1</mn></msub></mtd> <mtd><msub><mi>c</mi><mn>1</mn></msub></mtd> </mtr><mtr><mtd><msub><mi>b</mi><mn>1</mn></msub></mtd> <mtd><msub><mi>d</mi><mn>1</mn></msub></mtd> </mtr></mtable><mo>)</mo></mrow><mrow><mo>(</mo><mtable><mtr><mtd><msub><mi>a</mi><mn>2</mn></msub></mtd> <mtd><msub><mi>c</mi><mn>2</mn></msub></mtd> </mtr><mtr><mtd><msub><mi>b</mi><mn>2</mn></msub></mtd> <mtd><msub><mi>d</mi><mn>2</mn></msub></mtd> </mtr></mtable><mo>)</mo></mrow><mo>=</mo> <mrow><mo>(</mo><mtable><mtr><mtd><msub><mi>a</mi><mn>1</mn></msub> <msub><mi>a</mi><mn>2</mn></msub> <mo>+</mo> <msub><mi>c</mi><mn>1</mn></msub> <msub><mi>b</mi><mn>2</mn></msub> </mtd><mtd><msub><mi>a</mi><mn>1</mn></msub> <msub><mi>c</mi><mn>2</mn></msub> <mo>+</mo> <msub><mi>c</mi><mn>1</mn></msub> <msub><mi>d</mi><mn>2</mn></msub> </mtd></mtr><mtr><mtd><msub><mi>b</mi><mn>1</mn></msub> <msub><mi>a</mi><mn>2</mn></msub> <mo>+</mo> <msub><mi>d</mi><mn>1</mn></msub> <msub><mi>b</mi><mn>2</mn></msub> </mtd><mtd><msub><mi>b</mi><mn>1</mn></msub> <msub><mi>c</mi><mn>2</mn></msub> <mo>+</mo> <msub><mi>d</mi><mn>1</mn></msub> <msub><mi>d</mi><mn>2</mn></msub></mtd></mtr></mtable><mo>)</mo></mrow></math> 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-{{cssxref("translate")}}, {{cssxref("scale")}}, and {{cssxref("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 ```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 ```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: rgb(90 90 90 / 70%); transform: translateZ(50px); } .back { background: rgb(0 210 0 / 70%); transform: rotateY(180deg) translateZ(50px); } .right { background: rgb(210 0 0 / 70%); transform: rotateY(90deg) translateZ(50px); } .left { background: rgb(0 0 210 / 70%); transform: rotateY(-90deg) translateZ(50px); } .top { background: rgb(210 210 0 / 70%); transform: rotateX(90deg) translateZ(50px); } .bottom { background: rgb(210 0 210 / 70%); transform: rotateX(-90deg) translateZ(50px); } .select-form { margin-top: 50px; } ``` #### JavaScript ```js 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 {{EmbedLiveSample('Transform_function_comparison', '100%', 300)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - CSS {{cssxref("transform")}} property - Individual transform properties: - {{cssxref("translate")}} - {{cssxref("scale")}} - {{cssxref("rotate")}}
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/rotate/index.md
--- title: rotate() slug: Web/CSS/transform-function/rotate page-type: css-function browser-compat: css.types.transform-function.rotate --- {{CSSRef}} The **`rotate()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) defines a transformation that rotates an element around a fixed point on the 2D plane, without deforming it. Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-rotate.html")}} The fixed point that the element rotates around β€” mentioned above β€” is also known as the **transform origin**. This defaults to the center of the element, but you can set your own custom transform origin using the {{ cssxref("transform-origin") }} property. ## Syntax The amount of rotation created by `rotate()` is specified by an {{cssxref("&lt;angle&gt;")}}. If positive, the movement will be clockwise; if negative, it will be counter-clockwise. A rotation by 180Β° is called _point reflection_. ```css rotate(a) ``` ### Values - _a_ - : Is an {{ cssxref("&lt;angle&gt;") }} representing the angle of the rotation. The direction of rotation depends on the writing direction. In a left-to-right context, a positive angle denotes a clockwise rotation, a negative angle a counter-clockwise one. In a right-to-left context, a positive angle denotes a counter-clockwise rotation, a negative angle a clockwise one. <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd ><mo>-</mo> <mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd></mtr ><mtr ><mtd ><mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo></mtd ></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd ><mo>-</mo> <mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd ><mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd ><mo>-</mo> <mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd ><mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd ><mo>-</mo> <mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd ><mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> <tr> <td><code>[cos(a) sin(a) -sin(a) cos(a) 0 0]</code></td> </tr> </tbody> </table> ## Examples ### Basic example #### HTML ```html <div>Normal</div> <div class="rotated">Rotated</div> ``` #### CSS ```css div { width: 80px; height: 80px; background-color: skyblue; } .rotated { transform: rotate(45deg); /* Equal to rotateZ(45deg) */ background-color: pink; } ``` #### Result {{EmbedLiveSample("Basic_example", "auto", 180)}} ### Combining rotation with another transformation If you want to apply multiple transformations to an element, be careful about the order in which you specify your transformations. For example, if you rotate before translating, the translation will be along the new axis of rotation! #### HTML ```html <div>Normal</div> <div class="rotate">Rotated</div> <div class="rotate-translate">Rotated + Translated</div> <div class="translate-rotate">Translated + Rotated</div> ``` #### CSS ```css div { position: absolute; left: 40px; top: 40px; width: 100px; height: 100px; background-color: lightgray; } .rotate { background-color: transparent; outline: 2px dashed; transform: rotate(45deg); } .rotate-translate { background-color: pink; transform: rotate(45deg) translateX(180px); } .translate-rotate { background-color: gold; transform: translateX(180px) rotate(45deg); } ``` #### Result {{EmbedLiveSample("Combining_rotation_with_another_transformation", "auto", 320)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("transform")}} property - {{cssxref("rotate")}} property - {{cssxref("&lt;transform-function&gt;")}} - [`rotate3d()`](/en-US/docs/Web/CSS/transform-function/rotate3d)
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/rotate3d/index.md
--- title: rotate3d() slug: Web/CSS/transform-function/rotate3d page-type: css-function browser-compat: css.types.transform-function.rotate3d --- {{CSSRef}} The **`rotate3d()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) defines a transformation that rotates an element around a fixed axis in 3D space, without deforming it. Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/rotate3d.html")}} In 3D space, rotations have three degrees of freedom, which together describe a single axis of rotation. The axis of rotation is defined by an \[x, y, z] vector and pass by the origin (as defined by the {{ cssxref("transform-origin") }} property). If, as specified, the vector is not _normalized_ (i.e., if the sum of the square of its three coordinates is not 1), the {{glossary("user agent")}} will normalize it internally. A non-normalizable vector, such as the null vector, \[0, 0, 0], will cause the rotation to be ignored, but without invalidating the whole CSS property. > **Note:** Unlike rotations in the 2D plane, the composition of 3D rotations is usually > not commutative. In other words, the order in which the rotations are applied impacts the result. ## Syntax The amount of rotation created by `rotate3d()` is specified by three {{cssxref("&lt;number&gt;")}}s and one {{cssxref("&lt;angle&gt;")}}. The `<number>`s represent the x-, y-, and z-coordinates of the vector denoting the axis of rotation. The `<angle>` represents the angle of rotation; if positive, the movement will be clockwise; if negative, it will be counter-clockwise. ```css rotate3d(x, y, z, a) ``` ### Values - `x` - : Is a {{cssxref("&lt;number&gt;")}} describing the x-coordinate of the vector denoting the axis of rotation which can be a positive or negative number. - `y` - : Is a {{cssxref("&lt;number&gt;")}} describing the y-coordinate of the vector denoting the axis of rotation which can be a positive or negative number. - `z` - : Is a {{cssxref("&lt;number&gt;")}} describing the z-coordinate of the vector denoting the axis of rotation which can be a positive or negative number. - `a` - : Is an {{ cssxref("&lt;angle&gt;") }} representing the angle of the rotation. A positive angle denotes a clockwise rotation, a negative angle a counter-clockwise one. <table class="standard-table"> <tbody> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <td rowspan="2"> This transformation applies to the 3D space and can't be represented on the plane. </td> </tr> <tr> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> </tr> <tr> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <td> <math><semantics><mrow><mo>(</mo><mtable displaystyle="false" rowspacing="0.5ex"><mtr><mtd><mn>1</mn><mo>+</mo><mo stretchy="false">(</mo><mn>1</mn><mo>βˆ’</mo><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo><mo stretchy="false">(</mo><msup><mi>x</mi><mn>2</mn></msup><mo>βˆ’</mo><mn>1</mn><mo stretchy="false">)</mo></mtd><mtd><mi>z</mi><mo>β‹…</mo><mo lspace="0em" rspace="0em">sin</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo>+</mo><mi>x</mi><mi>y</mi><mo stretchy="false">(</mo><mn>1</mn><mo>βˆ’</mo><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo></mtd><mtd><mo>βˆ’</mo><mi>y</mi><mo>β‹…</mo><mo lspace="0em" rspace="0em">sin</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo>+</mo><mi>x</mi><mi>z</mi><mo stretchy="false">(</mo><mn>1</mn><mo>βˆ’</mo><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo></mtd></mtr><mtr><mtd><mo>βˆ’</mo><mi>z</mi><mo>β‹…</mo><mo lspace="0em" rspace="0em">sin</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo>+</mo><mi>x</mi><mi>y</mi><mo stretchy="false">(</mo><mn>1</mn><mo>βˆ’</mo><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo></mtd><mtd><mn>1</mn><mo>+</mo><mo stretchy="false">(</mo><mn>1</mn><mo>βˆ’</mo><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo><mo stretchy="false">(</mo><msup><mi>y</mi><mn>2</mn></msup><mo>βˆ’</mo><mn>1</mn><mo stretchy="false">)</mo></mtd><mtd><mi>x</mi><mo>β‹…</mo><mo lspace="0em" rspace="0em">sin</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo>+</mo><mi>y</mi><mi>z</mi><mo stretchy="false">(</mo><mn>1</mn><mo>βˆ’</mo><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo></mtd></mtr><mtr><mtd><mi>y</mi><mo>β‹…</mo><mo lspace="0em" rspace="0em">sin</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo>+</mo><mi>x</mi><mi>z</mi><mo stretchy="false">(</mo><mn>1</mn><mo>βˆ’</mo><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo></mtd><mtd><mo>βˆ’</mo><mi>x</mi><mo>β‹…</mo><mo lspace="0em" rspace="0em">sin</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo>+</mo><mi>y</mi><mi>z</mi><mo stretchy="false">(</mo><mn>1</mn><mo>βˆ’</mo><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo></mtd><mtd><mn>1</mn><mo>+</mo><mo stretchy="false">(</mo><mn>1</mn><mo>βˆ’</mo><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo><mo stretchy="false">(</mo><msup><mi>z</mi><mn>2</mn></msup><mo>βˆ’</mo><mn>1</mn><mo stretchy="false">)</mo></mtd></mtr></mtable><mo>)</mo></mrow><annotation encoding="TeX">\begin{pmatrix}1 + (1 - \cos(a))(x^2 - 1) &amp; z\cdot \sin(a) + xy(1 - \cos(a)) &amp; -y\cdot \sin(a) + xz(1 - \cos(a))\\-z\cdot \sin(a) + xy(1 - \cos(a)) &amp; 1 + (1 - \cos(a))(y^2 - 1) &amp; x\cdot \sin(a) + yz(1 - \cos(a))\\y\cdot \sin(a) + xz(1 - \cos(a)) &amp; -x\cdot \sin(a) + yz(1 - \cos(a)) &amp; 1 + (1 - \cos(a))(z^2 - 1)\end{pmatrix}</annotation></semantics></math> </td> </tr> <tr> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> <td> <math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mo>(</mo><mtable displaystyle="false" rowspacing="0.5ex"><mtr><mtd><mn>1</mn><mo>+</mo><mo stretchy="false">(</mo><mn>1</mn><mo>βˆ’</mo><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo><mo stretchy="false">(</mo><msup><mi>x</mi><mn>2</mn></msup><mo>βˆ’</mo><mn>1</mn><mo stretchy="false">)</mo></mtd><mtd><mi>z</mi><mo>β‹…</mo><mo lspace="0em" rspace="0em">sin</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo>+</mo><mi>x</mi><mi>y</mi><mo stretchy="false">(</mo><mn>1</mn><mo>βˆ’</mo><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo></mtd><mtd><mo>βˆ’</mo><mi>y</mi><mo>β‹…</mo><mo lspace="0em" rspace="0em">sin</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo>+</mo><mi>x</mi><mi>z</mi><mo stretchy="false">(</mo><mn>1</mn><mo>βˆ’</mo><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo></mtd><mtd><mn>0</mn></mtd></mtr><mtr><mtd><mo>βˆ’</mo><mi>z</mi><mo>β‹…</mo><mo lspace="0em" rspace="0em">sin</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo>+</mo><mi>x</mi><mi>y</mi><mo stretchy="false">(</mo><mn>1</mn><mo>βˆ’</mo><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo></mtd><mtd><mn>1</mn><mo>+</mo><mo stretchy="false">(</mo><mn>1</mn><mo>βˆ’</mo><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo><mo stretchy="false">(</mo><msup><mi>y</mi><mn>2</mn></msup><mo>βˆ’</mo><mn>1</mn><mo stretchy="false">)</mo></mtd><mtd><mi>x</mi><mo>β‹…</mo><mo lspace="0em" rspace="0em">sin</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo>+</mo><mi>y</mi><mi>z</mi><mo stretchy="false">(</mo><mn>1</mn><mo>βˆ’</mo><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo></mtd><mtd><mn>0</mn></mtd></mtr><mtr><mtd><mi>y</mi><mo>β‹…</mo><mo lspace="0em" rspace="0em">sin</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo>+</mo><mi>x</mi><mi>z</mi><mo stretchy="false">(</mo><mn>1</mn><mo>βˆ’</mo><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo></mtd><mtd><mo>βˆ’</mo><mi>x</mi><mo>β‹…</mo><mo lspace="0em" rspace="0em">sin</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo>+</mo><mi>y</mi><mi>z</mi><mo stretchy="false">(</mo><mn>1</mn><mo>βˆ’</mo><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo></mtd><mtd><mn>1</mn><mo>+</mo><mo stretchy="false">(</mo><mn>1</mn><mo>βˆ’</mo><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo><mo stretchy="false">(</mo><msup><mi>z</mi><mn>2</mn></msup><mo>βˆ’</mo><mn>1</mn><mo stretchy="false">)</mo></mtd><mtd><mn>0</mn></mtd></mtr><mtr><mtd><mn>0</mn></mtd><mtd><mn>0</mn></mtd><mtd><mn>0</mn></mtd><mtd><mn>1</mn></mtd></mtr></mtable><mo>)</mo></mrow><annotation encoding="TeX">\begin{pmatrix}1 + (1 - \cos(a))(x^2 - 1) &amp; z\cdot \sin(a) + xy(1 - \cos(a)) &amp; -y\cdot \sin(a) + xz(1 - \cos(a)) &amp; 0\\-z\cdot \sin(a) + xy(1 - \cos(a)) &amp; 1 + (1 - \cos(a))(y^2 - 1) &amp; x\cdot \sin(a) + yz(1 - \cos(a)) &amp; 0\\y\cdot \sin(a) + xz(1 - \cos(a)) &amp; -x\cdot \sin(a) + yz(1 - \cos(a)) &amp; 1 + (1 - \cos(a))(z^2 - 1) &amp; 0\\0 &amp; 0 &amp; 0 &amp; 1\end{pmatrix}</annotation></semantics></math> </td> </tr> </tbody> </table> ## Examples ### Rotating on the y-axis #### HTML ```html <div>Normal</div> <div class="rotated">Rotated</div> ``` #### CSS ```css body { perspective: 800px; } div { width: 80px; height: 80px; background-color: skyblue; } .rotated { transform: rotate3d(0, 1, 0, 60deg); background-color: pink; } ``` #### Result {{EmbedLiveSample("Rotating_on_the_y-axis", "auto", 180)}} ### Rotating on a custom axis #### HTML ```html <div>Normal</div> <div class="rotated">Rotated</div> ``` #### CSS ```css body { perspective: 800px; } div { width: 80px; height: 80px; background-color: skyblue; } .rotated { transform: rotate3d(1, 2, -1, 192deg); background-color: pink; } ``` #### Result {{EmbedLiveSample("Rotating_on_a_custom_axis", "auto", 180)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("transform")}} property - {{cssxref("rotate")}} property - {{cssxref("&lt;transform-function&gt;")}}
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/rotatey/index.md
--- title: rotateY() slug: Web/CSS/transform-function/rotateY page-type: css-function browser-compat: css.types.transform-function.rotateY --- {{CSSRef}} The **`rotateY()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) defines a transformation that rotates an element around the y-axis (vertical) without deforming it. Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-rotateY.html")}} The axis of rotation passes through an origin, defined by the {{ cssxref("transform-origin") }} CSS property. > **Note:** `rotateY(a)` is equivalent to > `rotate3d(0, 1, 0, a)`. > **Note:** Unlike rotations in the 2D plane, the composition of 3D rotations is usually > not commutative. In other words, the order in which the rotations are applied impacts the result. ## Syntax The amount of rotation created by `rotateY()` is specified by an {{cssxref("&lt;angle&gt;")}}. If positive, the movement will be clockwise; if negative, it will be counter-clockwise. ```css rotateY(a) ``` ### Values - `a` - : Is an {{ cssxref("&lt;angle&gt;") }} representing the angle of the rotation. A positive angle denotes a clockwise rotation, a negative angle a counter-clockwise one. <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td colspan="2"> This transformation applies to the 3D space and can't be represented on the plane. </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd ><mtd ><mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd ><mo>-</mo> <mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo></mtd ></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd ><mtd ><mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd ><mo>-</mo> <mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> </tbody> </table> ## Examples ### HTML ```html <div>Normal</div> <div class="rotated">Rotated</div> ``` ### CSS ```css div { width: 80px; height: 80px; background-color: skyblue; } .rotated { transform: rotateY(60deg); background-color: pink; } ``` ### Result {{EmbedLiveSample("Examples", "auto", 180)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("transform")}} property - {{cssxref("rotate")}} property - {{cssxref("&lt;transform-function&gt;")}}
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/rotatez/index.md
--- title: rotateZ() slug: Web/CSS/transform-function/rotateZ page-type: css-function browser-compat: css.types.transform-function.rotateZ --- {{CSSRef}} The **`rotateZ()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) defines a transformation that rotates an element around the z-axis without deforming it. Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-rotateZ.html")}} The axis of rotation passes through an origin, defined by the {{ cssxref("transform-origin") }} CSS property. > **Note:** `rotateZ(a)` is equivalent to > `rotate(a)` or > `rotate3d(0, 0, 1, a)`. > **Note:** Unlike rotations in the 2D plane, the composition of 3D rotations is usually > not commutative. In other words, the order in which the rotations are applied impacts the result. ## Syntax The amount of rotation created by `rotateZ()` is specified by an {{cssxref("&lt;angle&gt;")}}. If positive, the movement will be clockwise; if negative, it will be counter-clockwise. ```css rotateZ(a) ``` ### Values - `a` - : Is an {{ cssxref("&lt;angle&gt;") }} representing the angle of the rotation. A positive angle denotes a clockwise rotation, a negative angle a counter-clockwise one. <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td colspan="2"> This transformation applies to the 3D space and can't be represented on the plane. </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd ><mo>-</mo> <mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd ><mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd ><mo>-</mo> <mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd ><mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> </tbody> </table> ## Examples ### HTML ```html <div>Normal</div> <div class="rotated">Rotated</div> ``` ### CSS ```css div { width: 80px; height: 80px; background-color: skyblue; } .rotated { transform: rotateZ(45deg); background-color: pink; } ``` ### Result {{EmbedLiveSample("Examples", "auto", 180)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("transform")}} property - {{cssxref("rotate")}} property - {{cssxref("&lt;transform-function&gt;")}}
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/scalex/index.md
--- title: scaleX() slug: Web/CSS/transform-function/scaleX page-type: css-function browser-compat: css.types.transform-function.scaleX --- {{CSSRef}} The **`scaleX()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) defines a transformation that resizes an element along the x-axis (horizontally). Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-scaleX.html")}} It modifies the abscissa (horizontal, x-coordinate) of each element point by a constant factor, except when the scale factor is 1, in which case the function is the identity transform. The scaling is not isotropic, and the angles of the element are generally not conserved, except for multiples of 90 degrees. `scaleX(-1)` defines an [axial symmetry](https://en.wikipedia.org/wiki/Axial_symmetry), with a vertical axis passing through the origin (as specified by the {{cssxref("transform-origin")}} property). > **Note:** `scaleX(sx)` is equivalent to > `scale(sx, 1)` or > `scale3d(sx, 1, 1)`. ## Syntax ```css scaleX(s) ``` ### Values - `s` - : Is a {{cssxref("&lt;number&gt;")}} representing the scaling factor to apply on the abscissa (horizontal, x-coordinate) of each point of the element. <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mi>s</mi> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mi>s</mi> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mi>s</mi> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mi>s</mi> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> <tr> <td><code>[s 0 0 1 0 0]</code></td> </tr> </tbody> </table> ## Examples ### HTML ```html <div>Normal</div> <div class="scaled">Scaled</div> ``` ### CSS ```css div { width: 80px; height: 80px; background-color: skyblue; } .scaled { transform: scaleX(0.6); background-color: pink; } ``` ### Result {{EmbedLiveSample("Examples","200","200")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`scaleY()`](/en-US/docs/Web/CSS/transform-function/scaleY) - [`scaleZ()`](/en-US/docs/Web/CSS/transform-function/scaleZ) - {{cssxref("transform")}} - {{cssxref("scale")}} - {{cssxref("&lt;transform-function&gt;")}} - {{cssxref("transform-origin")}} - Other individual transform properties: - {{cssxref("translate")}} - {{cssxref("rotate")}} - Note: there is no `skew` property
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/translate3d/index.md
--- title: translate3d() slug: Web/CSS/transform-function/translate3d page-type: css-function browser-compat: css.types.transform-function.translate3d --- {{CSSRef}} The **`translate3d()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) repositions an element in 3D space. Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-translate3d.html")}} This transformation is characterized by a three-dimensional vector [tx, ty, tz]. Its coordinates define how much the element moves in each direction. ## Syntax ```css translate3d(tx, ty, tz) ``` ### Values - `tx` - : Is a {{cssxref("&lt;length&gt;")}} or {{cssxref("&lt;percentage&gt;")}} representing the abscissa (horizontal, x-component) of the translating vector [tx, ty, tz]. - `ty` - : Is a {{cssxref("&lt;length&gt;")}} or {{cssxref("&lt;percentage&gt;")}} representing the ordinate (vertical, y-component)of the translating vector [tx, ty, tz]. - `tz` - : Is a {{cssxref("&lt;length&gt;")}} representing the z-component of the translating vector. It can't be a {{cssxref("&lt;percentage&gt;")}} value; in that case the property containing the transform is considered invalid [tx, ty, tz]. <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td colspan="2"> <p> This transformation applies to the 3D space and can't be represented on the plane. </p> </td> <td> A translation is not a linear transformation in ℝ^3 and can't be represented using a Cartesian-coordinate matrix. </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mi>tx</mi> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mi>ty</mi> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn> </mtd><mtd><mi>tz</mi> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> </tbody> </table> ## Examples ### Using a single axis translation #### HTML ```html <div>Static</div> <div class="moved">Moved</div> <div>Static</div> ``` #### CSS ```css div { width: 60px; height: 60px; background-color: skyblue; } .moved { /* Equivalent to perspective(500px) translateX(10px) */ transform: perspective(500px) translate3d(10px, 0, 0px); background-color: pink; } ``` #### Result {{EmbedLiveSample("Using_a_single_axis_translation", 250, 250)}} ### Combining z-axis and x-axis translation #### HTML ```html <div>Static</div> <div class="moved">Moved</div> <div>Static</div> ``` #### CSS ```css div { width: 60px; height: 60px; background-color: skyblue; } .moved { transform: perspective(500px) translate3d(10px, 0, 100px); background-color: pink; } ``` #### Result {{EmbedLiveSample("Combining_z-axis_and_x-axis_translation", 250, 250)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("transform")}} - {{cssxref("&lt;transform-function&gt;")}} - {{cssxref("translate")}}
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/matrix/index.md
--- title: matrix() slug: Web/CSS/transform-function/matrix page-type: css-function browser-compat: css.types.transform-function.matrix --- {{CSSRef}} The **`matrix()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) defines a homogeneous 2D transformation matrix. Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-matrix.html")}} > **Note:** `matrix(a, b, c, d, tx, ty)` is a shorthand for > `matrix3d(a, b, 0, 0, c, d, 0, 0, 0, 0, 1, 0, tx, ty, 0, 1)`. ## Syntax The `matrix()` function is specified with six values. The constant values are implied and not passed as parameters; the other parameters are described in the column-major order. ```css matrix(a, b, c, d, tx, ty) ``` ### Values - _a_ _b_ _c_ _d_ - : Are {{cssxref("&lt;number&gt;")}}s describing the linear transformation. - _tx_ _ty_ - : Are {{cssxref("&lt;number&gt;")}}s describing the translation to apply. <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mi>a</mi> </mtd><mtd><mi>c</mi> </mtd></mtr ><mtr ><mtd><mi>b</mi> </mtd><mtd><mi>d</mi></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mi>a</mi> </mtd><mtd><mi>c</mi> </mtd ><mtd><mi>tx</mi> </mtd></mtr ><mtr ><mtd><mi>b</mi> </mtd><mtd><mi>d</mi> </mtd ><mtd><mi>ty</mi> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mi>a</mi> </mtd><mtd><mi>c</mi> </mtd ><mtd><mi>tx</mi> </mtd></mtr ><mtr ><mtd><mi>b</mi> </mtd><mtd><mi>d</mi> </mtd ><mtd><mi>ty</mi> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mi>a</mi> </mtd><mtd><mi>c</mi> </mtd ><mtd><mn>0</mn> </mtd><mtd><mi>tx</mi> </mtd></mtr ><mtr ><mtd><mi>b</mi> </mtd><mtd><mi>d</mi> </mtd ><mtd><mn>0</mn> </mtd><mtd><mi>ty</mi> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> <tr> <td><code>[a b c d tx ty]</code></td> </tr> </tbody> </table> The values represent the following functions: `matrix(scaleX(), skewY(), skewX(), scaleY(), translateX(), translateY())` ## Examples ### HTML ```html <div>Normal</div> <div class="changed">Changed</div> ``` ### CSS ```css div { width: 80px; height: 80px; background-color: skyblue; } .changed { transform: matrix(1, 2, -1, 1, 80, 80); background-color: pink; } ``` ### Result {{EmbedLiveSample("Examples", 350, 350)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("transform")}} - Individual transform properties: - {{cssxref("translate")}} - {{cssxref("scale")}} - {{cssxref("rotate")}} - {{cssxref("&lt;transform-function&gt;")}} - [`matrix3d()`](/en-US/docs/Web/CSS/transform-function/matrix3d) - [Understanding the CSS Transforms Matrix](https://dev.opera.com/articles/understanding-the-css-transforms-matrix/)
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/scale/index.md
--- title: scale() slug: Web/CSS/transform-function/scale page-type: css-function browser-compat: css.types.transform-function.scale --- {{CSSRef}} The **`scale()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) defines a transformation that resizes an element on the 2D plane. Because the amount of scaling is defined by a vector [sx, sy], it can resize the horizontal and vertical dimensions at different scales. Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-scale.html")}} This scaling transformation is characterized by a two-dimensional vector. Its coordinates define how much scaling is done in each direction. If both coordinates are equal, the scaling is uniform (_isotropic_) and the aspect ratio of the element is preserved (this is a [homothetic transformation](https://en.wikipedia.org/wiki/Homothetic_transformation)). When a coordinate value is outside the \[-1, 1] range, the element grows along that dimension; when inside, it shrinks. A negative value results in a [point reflection](https://en.wikipedia.org/wiki/Point_reflection) in that dimension. The value `1` has no effect. > **Note:** The `scale()` function only scales in 2D. To scale in 3D, use > [`scale3d()`](/en-US/docs/Web/CSS/transform-function/scale3d) instead. ## Syntax The `scale()` function is specified with either one or two values, which represent the amount of scaling to be applied in each direction. ```css scale(sx) scale(sx, sy) ``` ### Values - `sx` - : A {{cssxref("&lt;number&gt;")}} or {{cssxref("&lt;percentage&gt;")}} representing the abscissa (horizontal, x-component) of the scaling vector. - `sy` - : A {{cssxref("&lt;number&gt;")}} or {{cssxref("&lt;percentage&gt;")}} representing the ordinate (vertical, y-component) of the scaling vector. If not defined, its default value is `sx`, resulting in a uniform scaling that preserves the element's aspect ratio. <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mi>sx</mi> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mi>sy</mi></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mi>sx</mi> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mi>sy</mi> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mi>sx</mi> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mi>sy</mi> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mi>sx</mi> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mi>sy</mi> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> <tr> <td><code>[sx 0 0 sy 0 0]</code></td> </tr> </tbody> </table> ## Accessibility concerns Scaling/zooming animations are problematic for accessibility, as they are a common trigger for certain types of migraine. If you need to include such animations on your website, you should provide a control to allow users to turn off animations, preferably site-wide. Also, consider making use of the {{cssxref("@media/prefers-reduced-motion", "prefers-reduced-motion")}} media feature β€” use it to write a [media query](/en-US/docs/Web/CSS/CSS_media_queries) that will turn off animations if the user has reduced animation specified in their system preferences. Find out more: - [MDN Understanding WCAG, Guideline 2.3 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Operable#guideline_2.3_%e2%80%94_seizures_and_physical_reactions_do_not_design_content_in_a_way_that_is_known_to_cause_seizures_or_physical_reactions) - [Understanding Success Criterion 2.3.3 | W3C Understanding WCAG 2.1](https://www.w3.org/WAI/WCAG21/Understanding/animation-from-interactions) ## Examples ### Scaling the X and Y dimensions together #### HTML ```html <div>Normal</div> <div class="scaled">Scaled</div> ``` #### CSS ```css div { width: 80px; height: 80px; background-color: skyblue; } .scaled { transform: scale(0.7); /* Equal to scaleX(0.7) scaleY(0.7) */ background-color: pink; } ``` #### Result {{EmbedLiveSample("Scaling_the_X_and_Y_dimensions_together", "200", "200")}} ### Scaling X and Y dimensions separately, and translating the origin #### HTML ```html <div>Normal</div> <div class="scaled">Scaled</div> ``` #### CSS ```css div { width: 80px; height: 80px; background-color: skyblue; } .scaled { transform: scale(2, 0.5); /* Equal to scaleX(2) scaleY(0.5) */ transform-origin: left; background-color: pink; } ``` #### Result {{EmbedLiveSample("Scaling_X_and_Y_dimensions_separately_and_translating_the_origin", "200", "200")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("transform")}} - {{cssxref("scale")}} - {{cssxref("&lt;transform-function&gt;")}} - {{cssxref("transform-function/scale3d", "scale3d()")}} - Other individual transform properties {{cssxref("translate")}} and {{cssxref("rotate")}}
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/rotatex/index.md
--- title: rotateX() slug: Web/CSS/transform-function/rotateX page-type: css-function browser-compat: css.types.transform-function.rotateX --- {{CSSRef}} The **`rotateX()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) defines a transformation that rotates an element around the x-axis (horizontal) without deforming it. Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-rotateX.html")}} The axis of rotation passes through an origin, defined by the {{ cssxref("transform-origin") }} CSS property. > **Note:** `rotateX(a)` is equivalent to > `rotate3d(1, 0, 0, a)`. > **Note:** Unlike rotations in the 2D plane, the composition of 3D rotations is usually > not commutative. In other words, the order in which the rotations are applied impacts the result. ## Syntax The amount of rotation created by `rotateX()` is specified by an {{cssxref("&lt;angle&gt;")}}. If positive, the movement will be clockwise; if negative, it will be counter-clockwise. ```css rotateX(a) ``` ### Values - `a` - : Is an {{ cssxref("&lt;angle&gt;") }} representing the angle of the rotation. A positive angle denotes a clockwise rotation, a negative angle a counter-clockwise one. <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td colspan="2"> This transformation applies to the 3D space and can't be represented on the plane. </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd ><mo>-</mo> <mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd ><mtd ><mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo></mtd ></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd ><mo>-</mo> <mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd ><mtd ><mo>sin</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd ><mo>cos</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> </tbody> </table> ## Examples ### HTML ```html <div>Normal</div> <div class="rotated">Rotated</div> ``` ### CSS ```css div { width: 80px; height: 80px; background-color: skyblue; } .rotated { transform: rotateX(45deg); background-color: pink; } ``` ### Result {{EmbedLiveSample("Examples", "auto", 180)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("transform")}} property - {{cssxref("rotate")}} property - {{cssxref("&lt;transform-function&gt;")}}
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/skewy/index.md
--- title: skewY() slug: Web/CSS/transform-function/skewY page-type: css-function browser-compat: css.types.transform-function.skewY --- {{CSSRef}} The **`skewY()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) defines a transformation that skews an element in the vertical direction on the 2D plane. Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-skewY.html")}} This transformation is a shear mapping ([transvection](https://en.wikipedia.org/wiki/Shear_mapping)) that distorts each point within an element by a certain angle in the vertical direction. The ordinate (vertical, y-coordinate) of each point is modified by a value proportionate to the specified angle and the distance to the origin; thus, the farther from the origin a point is, the greater will be the value added it. ## Syntax ```css skewY(a) ``` ### Values - `a` - : Is an {{cssxref("&lt;angle&gt;")}} representing the angle to use to distort the element along the ordinate (vertical, y-coordinate). <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd ><mo>tan</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd ><mo>tan</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd ><mo>tan</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd ><mo>tan</mo> <mo>(</mo> <mi>a</mi> <mo>)</mo> </mtd ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> <tr> <td><code>[1 tan(a) 0 1 0 0]</code></td> </tr> </tbody> </table> ## Examples ### HTML ```html <div>Normal</div> <div class="skewed">Skewed</div> ``` ### CSS ```css div { width: 80px; height: 80px; background-color: skyblue; } .skewed { transform: skewY(40deg); background-color: pink; } ``` ### Result {{EmbedLiveSample("Examples", 200, 200)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("transform")}} - {{cssxref("&lt;transform-function&gt;")}} - Individual transform properties: - {{cssxref("translate")}} - {{cssxref("scale")}} - {{cssxref("rotate")}} - Note: there is no `skew` property
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/perspective/index.md
--- title: perspective() slug: Web/CSS/transform-function/perspective page-type: css-function browser-compat: css.types.transform-function.perspective --- {{CSSRef}} The **`perspective()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) defines a transformation that sets the distance between the user and the z=0 plane, the perspective from which the viewer would be if the 2-dimensional interface were 3-dimensional. Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-perspective.html")}} The `perspective()` transform function is part of the {{cssxref('transform')}} value applied on the element being transformed. This differs from the {{cssxref('perspective')}} and {{cssxref('perspective-origin')}} properties which are attached to the parent of a child transformed in 3-dimensional space. ## Syntax The perspective distance used by `perspective()` is specified by a {{cssxref("&lt;length&gt;")}} value, which represents the distance between the user and the z=0 plane, or by `none`. The z=0 plane is the plane where everything appears in a 2-dimensional view, or the screen. Negative values are syntax errors. Values smaller than `1px` (including zero) are clamped to `1px`. Values other than `none` cause elements with positive z positions to appear larger, and elements with negative z positions to appear smaller. Elements with z positions equal to or larger than the perspective value disappear as though they are behind the user. Large values of perspective represent a small transformation; small values of `perspective()` represent a large transformation; `perspective(none)` represents perspective from infinite distance and no transformation. ```css perspective(d) ``` ### Values - _d_ - : Is a {{cssxref("&lt;length&gt;")}} representing the distance from the user to the z=0 plane. If it is 0 or a negative value, no perspective transform is applied. <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td colspan="2"> <p> This transformation applies to the 3D space and can't be represented on the plane. </p> </td> <td> This transformation is not a linear transformation in ℝ^3, and can't be represented using a Cartesian-coordinate matrix. </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd ><mo>βˆ’</mo> <mn>1</mn> <mo>/</mo> <mi>d</mi> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> </tbody> </table> ## Examples ### HTML ```html <p>Without perspective:</p> <div class="no-perspective-box"> <div class="face front">A</div> <div class="face top">B</div> <div class="face left">C</div> </div> <p>With perspective (9cm):</p> <div class="perspective-box-far"> <div class="face front">A</div> <div class="face top">B</div> <div class="face left">C</div> </div> <p>With perspective (4cm):</p> <div class="perspective-box-closer"> <div class="face front">A</div> <div class="face top">B</div> <div class="face left">C</div> </div> ``` ### CSS ```css .face { position: absolute; width: 100px; height: 100px; line-height: 100px; font-size: 100px; text-align: center; } p + div { width: 100px; height: 100px; transform-style: preserve-3d; margin-left: 100px; } .no-perspective-box { transform: rotateX(-15deg) rotateY(30deg); } .perspective-box-far { transform: perspective(9cm) rotateX(-15deg) rotateY(30deg); } .perspective-box-closer { transform: perspective(4cm) rotateX(-15deg) rotateY(30deg); } .top { background-color: skyblue; transform: rotateX(90deg) translate3d(0, 0, 50px); } .left { background-color: pink; transform: rotateY(-90deg) translate3d(0, 0, 50px); } .front { background-color: limegreen; transform: translate3d(0, 0, 50px); } ``` ### Result {{ EmbedLiveSample('Examples', '250', '350') }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("transform")}} - {{cssxref("&lt;transform-function&gt;")}} - Individual transform properties: - {{cssxref("translate")}} - {{cssxref("scale")}} - {{cssxref("rotate")}}
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/translate/index.md
--- title: translate() slug: Web/CSS/transform-function/translate page-type: css-function browser-compat: css.types.transform-function.translate --- {{CSSRef}} The **`translate()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) repositions an element in the horizontal and/or vertical directions. Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-translate.html")}} This transformation is characterized by a two-dimensional vector [tx, ty]. Its coordinates define how much the element moves in each direction. ## Syntax ```css /* Single <length-percentage> values */ transform: translate(200px); transform: translate(50%); /* Double <length-percentage> values */ transform: translate(100px, 200px); transform: translate(100px, 50%); transform: translate(30%, 200px); transform: translate(30%, 50%); ``` ### Values - Single `<length-percentage>` values - : This value is a {{cssxref("&lt;length&gt;")}} or {{cssxref("&lt;percentage&gt;")}} representing the abscissa (horizontal, x-component) of the translating vector [tx, 0]. The ordinate (vertical, y-component) of the translating vector will be set to `0`. For example, `translate(2px)` is equivalent to `translate(2px, 0)`. A percentage value refers to the width of the reference box defined by the {{cssxref("transform-box")}} property. - Double `<length-percentage>` values - : This value describes two {{cssxref("&lt;length&gt;")}} or {{cssxref("&lt;percentage&gt;")}} values representing both the abscissa (horizontal, x-component) and the ordinate (vertical, y-component) of the translating vector [tx, ty]. A percentage as first value refers to the width, as second part to the height of the reference box defined by the {{cssxref("transform-box")}} property. <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td rowspan="2"> <p> A translation is not a linear transformation in ℝ^2 and can't be represented using a Cartesian-coordinate matrix. </p> </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mi>tx</mi> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd ><mtd><mi>ty</mi> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mi>tx</mi> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd ><mtd><mi>ty</mi> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mi>tx</mi> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mi>ty</mi> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> <tr> <td><code>[1 0 0 1 tx ty]</code></td> </tr> </tbody> </table> ### Formal syntax ```css translate({{cssxref("&lt;length-percentage&gt;")}}, {{cssxref("&lt;length-percentage&gt;")}}?) ``` ## Examples ### Using a single-axis translation #### HTML ```html <div>Static</div> <div class="moved">Moved</div> <div>Static</div> ``` #### CSS ```css div { width: 60px; height: 60px; background-color: skyblue; } .moved { /* Equal to: translateX(10px) or translate(10px, 0) */ transform: translate(10px); background-color: pink; } ``` #### Result {{EmbedLiveSample("Using_a_single-axis_translation", 250, 250)}} ### Combining y-axis and x-axis translation #### HTML ```html <div>Static</div> <div class="moved">Moved</div> <div>Static</div> ``` #### CSS ```css div { width: 60px; height: 60px; background-color: skyblue; } .moved { transform: translate(10px, 10px); background-color: pink; } ``` #### Result {{EmbedLiveSample("Combining_y-axis_and_x-axis_translation", 250, 250)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("transform")}} - {{cssxref("&lt;transform-function&gt;")}} - {{cssxref("translate")}}
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/matrix3d/index.md
--- title: matrix3d() slug: Web/CSS/transform-function/matrix3d page-type: css-function browser-compat: css.types.transform-function.matrix3d --- {{CSSRef}} The **`matrix3d()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) defines a 3D transformation as a 4x4 homogeneous matrix. Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-matrix3d.html")}} ## Syntax The `matrix3d()` function is specified with 16 values. They are described in the column-major order. ```css matrix3d(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4) ``` ### Values - _a1_ _b1_ _c1_ _d1_ _a2_ _b2_ _c2_ _d2_ _a3_ _b3_ _c3_ _d3_ - : Are {{cssxref("&lt;number&gt;")}}s describing the linear transformation. - _a4_ _b4_ _c4 d4_ - : Are {{cssxref("&lt;number&gt;")}}s describing the translation to apply. <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td colspan="2"> This transformation applies to the 3D space and can't be represented on the plane. </td> <td> A generic 3D <a href="https://en.wikipedia.org/wiki/Affine_transformation" >affine transformation</a > can't be represented using a Cartesian-coordinate matrix, as translations are not linear transformations. </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mi>a1</mi> </mtd><mtd><mi>a2</mi> </mtd ><mtd><mi>a3</mi> </mtd><mtd><mi>a4</mi> </mtd></mtr ><mtr ><mtd><mi>b1</mi> </mtd><mtd><mi>b2</mi> </mtd ><mtd><mi>b3</mi> </mtd><mtd><mi>b4</mi> </mtd></mtr ><mtr ><mtd><mi>c1</mi> </mtd><mtd><mi>c2</mi> </mtd ><mtd><mi>c3</mi> </mtd><mtd><mi>c4</mi> </mtd></mtr ><mtr ><mtd><mi>d1</mi> </mtd><mtd><mi>d2</mi> </mtd ><mtd><mi>d3</mi> </mtd><mtd><mi>d4</mi></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> </tbody> </table> ## Examples ### Cube squashing example The following example shows a 3D cube created from DOM elements and transforms, which can be hovered/focused to apply a `matrix3d()` transform to it. #### HTML ```html <section id="example-element" tabindex="0"> <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> ``` #### CSS ```css #example-element { width: 100px; height: 100px; transform-style: preserve-3d; transition: transform 1.5s; transform: rotate3d(1, 1, 1, 30deg); margin: 50px auto; } #example-element:hover, #example-element:focus { transform: rotate3d(1, 1, 1, 30deg) matrix3d( 1, 0, 0, 0, 0, 1, 6, 0, 0, 0, 1, 0, 50, 100, 0, 1.1 ); } .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: rgb(90 90 90 / 70%); transform: translateZ(50px); } .back { background: rgb(0 210 0 / 70%); transform: rotateY(180deg) translateZ(50px); } .right { background: rgb(210 0 0 / 70%); transform: rotateY(90deg) translateZ(50px); } .left { background: rgb(0 0 210 / 70%); transform: rotateY(-90deg) translateZ(50px); } .top { background: rgb(210 210 0 / 70%); transform: rotateX(90deg) translateZ(50px); } .bottom { background: rgb(210 0 210 / 70%); transform: rotateX(-90deg) translateZ(50px); } ``` #### Result {{EmbedLiveSample('Cube_squashing_example', '100%', '300px')}} ### Matrix translation and scale example Another `transform3d()` example, which implements an animated combined translate and scale. #### HTML ```html <div class="foo"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quos quaerat sit soluta, quisquam exercitationem delectus qui unde in facere necessitatibus aut quia porro dolorem nesciunt enim, at consequuntur aliquam esse? </div> ``` #### CSS ```css-nolint html { width: 100%; } body { height: 100vh; /* Centering content */ display: flex; flex-flow: row wrap; justify-content: center; align-content: center; } .foo { width: 50%; padding: 1em; color: white; background: #ff8c66; border: 2px dashed black; text-align: center; font-family: system-ui, sans-serif; font-size: 14px; /* Setting up animation for better demonstration */ animation: MotionScale 2s alternate linear infinite; } @keyframes MotionScale { from { /* Identity matrix is used as basis here. The matrix below describes the following transformations: Translates every X point by -50px Translates every Y point by -100px Translates every Z point by 0 Scales down by 10% */ transform: matrix3d( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -50, -100, 0, 1.1 ); } 50% { transform: matrix3d( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0.9 ); } to { transform: matrix3d( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 50, 100, 0, 1.1 ) } } ``` #### Result {{EmbedLiveSample('Matrix_translation_and_scale_example', '100%', '400px')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("transform")}} - Individual transform properties: - {{cssxref("translate")}} - {{cssxref("scale")}} - {{cssxref("rotate")}} - {{cssxref("&lt;transform-function&gt;")}} - [Understanding the CSS Transforms Matrix](https://dev.opera.com/articles/understanding-the-css-transforms-matrix/) (2012)
0
data/mdn-content/files/en-us/web/css/transform-function
data/mdn-content/files/en-us/web/css/transform-function/skew/index.md
--- title: skew() slug: Web/CSS/transform-function/skew page-type: css-function browser-compat: css.types.transform-function.skew --- {{CSSRef}} The **`skew()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) defines a transformation that skews an element on the 2D plane. Its result is a {{cssxref("&lt;transform-function&gt;")}} data type. {{EmbedInteractiveExample("pages/css/function-skew.html")}} This transformation is a shear mapping ([transvection](https://en.wikipedia.org/wiki/Shear_mapping)) that distorts each point within an element by a certain angle in the horizontal and vertical directions. The effect is as if you grabbed each corner of the element and pulled them along a certain angle. The coordinates of each point are modified by a value proportionate to the specified angle and the distance to the origin. Thus, the farther from the origin a point is, the greater the value added to it. ## Syntax The `skew()` function is specified with either one or two values, which represent the amount of skewing to be applied in each direction. If you only specify one value it is used for the x-axis and there will be no skewing on the y-axis. ```css skew(ax) skew(ax, ay) ``` ### Values - `ax` - : Is an {{cssxref("&lt;angle&gt;")}} representing the angle to use to distort the element along the x-axis. - `ay` - : Is an {{cssxref("&lt;angle&gt;")}} representing the angle to use to distort the element along the y-axis. If not defined, its default value is `0`, resulting in a purely horizontal skewing. <table class="standard-table"> <thead> <tr> <th scope="col"><a href="/en-US/docs/Web/CSS/transform-function#cartesian_coordinates">Cartesian coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^2</a></th> <th scope="col"><a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">Homogeneous coordinates</a> on <a href="https://en.wikipedia.org/wiki/Real_projective_plane">ℝℙ^2</a></th> <th scope="col">Cartesian coordinates on <a href="https://en.wikipedia.org/wiki/Real_coordinate_space">ℝ^3</a></th> <th scope="col">Homogeneous coordinates on <a href="https://en.wikipedia.org/wiki/Real_projective_space">ℝℙ^3</a></th> </tr> </thead> <tbody> <tr> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd ><mtd ><mo>tan</mo> <mo>(</mo> <mi>ax</mi> <mo>)</mo> </mtd></mtr ><mtr ><mtd ><mo>tan</mo> <mo>(</mo> <mi>ay</mi> <mo>)</mo> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd ><mtd ><mo>tan</mo> <mo>(</mo> <mi>ax</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd ><mo>tan</mo> <mo>(</mo> <mi>ay</mi> <mo>)</mo> </mtd ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ><mtr></mtr></mtable><mo>)</mo></mrow ></math> </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd ><mtd ><mo>tan</mo> <mo>(</mo> <mi>ax</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd ><mo>tan</mo> <mo>(</mo> <mi>ay</mi> <mo>)</mo> </mtd ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> <td rowspan="2"> <math ><mrow><mo>(</mo ><mtable ><mtr ><mtd><mn>1</mn> </mtd ><mtd ><mo>tan</mo> <mo>(</mo> <mi>ax</mi> <mo>)</mo> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd ><mo>tan</mo> <mo>(</mo> <mi>ay</mi> <mo>)</mo> </mtd ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>1</mn> </mtd><mtd><mn>0</mn> </mtd></mtr ><mtr ><mtd><mn>0</mn> </mtd><mtd><mn>0</mn> </mtd ><mtd><mn>0</mn> </mtd><mtd><mn>1</mn></mtd></mtr ></mtable ><mo>)</mo></mrow ></math > </td> </tr> <tr> <td><code>[1 tan(ay) tan(ax) 1 0 0]</code></td> </tr> </tbody> </table> ## Examples ### Skewing on the x-axis only #### HTML ```html <div>Normal</div> <div class="skewed">Skewed</div> ``` #### CSS ```css body { margin: 20px; } div { width: 80px; height: 80px; background-color: skyblue; } .skewed { transform: skew(10deg); /* Equal to skewX(10deg) */ background-color: pink; } ``` #### Result {{EmbedLiveSample("Skewing_on_the_x-axis_only", 200, 200)}} ### Skewing on both axes #### HTML ```html <div>Normal</div> <div class="skewed">Skewed</div> ``` #### CSS ```css body { margin: 20px; } div { width: 80px; height: 80px; background-color: skyblue; } .skewed { transform: skew(10deg, 10deg); background-color: pink; } ``` #### Result {{EmbedLiveSample("Skewing_on_both_axes", 200, 200)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("transform")}} - {{cssxref("&lt;transform-function&gt;")}} - [skewX()](/en-US/docs/Web/CSS/transform-function/skewX) - [skewY()](/en-US/docs/Web/CSS/transform-function/skewY) - Individual transform properties: - {{cssxref("translate")}} - {{cssxref("scale")}} - {{cssxref("rotate")}} - Note: there is no `skew` property
0