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/@namespace/index.md
--- title: "@namespace" slug: Web/CSS/@namespace page-type: css-at-rule browser-compat: css.at-rules.namespace --- {{CSSRef}} **`@namespace`** is an [at-rule](/en-US/docs/Web/CSS/At-rule) that defines XML [namespaces](/en-US/docs/Glossary/Namespace) to be used in a [CSS](/en-US/docs/Glossary/CSS) [style sheet](/en-US/docs/Web/API/StyleSheet). {{EmbedInteractiveExample("pages/tabbed/at-rule-namespace.html", "tabbed-shorter")}} ## Syntax ```css /* Default namespace */ @namespace url(XML-namespace-URL); @namespace "XML-namespace-URL"; /* Prefixed namespace */ @namespace prefix url(XML-namespace-URL); @namespace prefix "XML-namespace-URL"; ``` ## Description The defined namespaces can be used to restrict the [universal](/en-US/docs/Web/CSS/Universal_selectors), [type](/en-US/docs/Web/CSS/Type_selectors), and [attribute](/en-US/docs/Web/CSS/Attribute_selectors) [selectors](/en-US/docs/Learn/CSS/Building_blocks/Selectors) to only select elements within that namespace. The `@namespace` rule is generally only useful when dealing with documents containing multiple namespaces—such as HTML with inline SVG or MathML, or XML that mixes multiple vocabularies. Any `@namespace` rules must follow all {{cssxref("@charset")}} and {{cssxref("@import")}} rules, and precede all other at-rules and [style declarations](/en-US/docs/Web/API/CSSStyleDeclaration) in a style sheet. `@namespace` can be used to define the **default namespace** for the style sheet. When a default namespace is defined, all universal and type selectors (but not attribute selectors, see note below) apply only to elements in that namespace. The `@namespace` rule can also be used to define a **namespace prefix**. When a universal, type, or attribute selector is prefixed with a namespace prefix, then that selector only matches if the namespace _and_ name of the element or attribute matches. In HTML, known [foreign elements](https://html.spec.whatwg.org/multipage/syntax.html#foreign-elements) will automatically be assigned namespaces. This means that HTML elements will act as though they are in the XHTML namespace (`http://www.w3.org/1999/xhtml`), even if there is no `xmlns` attribute anywhere in the document, and the [`<svg>`](/en-US/docs/Web/SVG/Element/svg) and [`<math>`](/en-US/docs/Web/MathML/Element/math) elements will be assigned their proper namespaces (`http://www.w3.org/2000/svg` and `http://www.w3.org/1998/Math/MathML`, respectively). > **Note:** In XML, unless a prefix is defined directly on an attribute (_e.g._, `xlink:href`), that attribute has no namespace. In other words, attributes do not inherit the namespace of the element they're on. To match this behavior, the default namespace in CSS does not apply to attribute selectors. ## Formal syntax {{csssyntax}} ## Examples ### Specifying default and prefixed namespaces ```css @namespace url(http://www.w3.org/1999/xhtml); @namespace svg url(http://www.w3.org/2000/svg); /* This matches all XHTML <a> elements, as XHTML is the default unprefixed namespace */ a { } /* This matches all SVG <a> elements */ svg|a { } /* This matches both XHTML and SVG <a> elements */ *|a { } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Namespaces crash course](/en-US/docs/Web/SVG/Namespaces_Crash_Course)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/scroll-margin-inline-start/index.md
--- title: scroll-margin-inline-start slug: Web/CSS/scroll-margin-inline-start page-type: css-property browser-compat: css.properties.scroll-margin-inline-start --- {{CSSRef}} The `scroll-margin-inline-start` property defines the margin of the scroll snap area at the start of the inline dimension that is used for snapping this box to the snapport. The scroll snap area is determined by taking the transformed border box, finding its rectangular bounding box (axis-aligned in the scroll container's coordinate space), then adding the specified outsets. {{EmbedInteractiveExample("pages/css/scroll-margin-inline-start.html")}} ## Syntax ```css /* <length> values */ scroll-margin-inline-start: 10px; scroll-margin-inline-start: 1em; /* Global values */ scroll-margin-inline-start: inherit; scroll-margin-inline-start: initial; scroll-margin-inline-start: revert; scroll-margin-inline-start: revert-layer; scroll-margin-inline-start: unset; ``` ### Values - {{CSSXref("&lt;length&gt;")}} - : An outset from the inline start edge of the scroll container. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Simple demonstration This example implements something very similar to the interactive example above, except that here we'll explain to you how it's implemented. The aim here is to create four horizontally-scrolling blocks, the second and third of which snap into place, near but not quite at the left of each block. #### HTML The HTML that represents the blocks is very simple: ```html <div class="scroller"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> </div> ``` #### CSS Let's walk through the CSS. The outer container is styled like this: ```css .scroller { text-align: left; width: 250px; height: 250px; overflow-x: scroll; display: flex; box-sizing: border-box; border: 1px solid #000; scroll-snap-type: x mandatory; } ``` The main parts relevant to the scroll snapping are `overflow-x: scroll`, which makes sure the contents will scroll and not be hidden, and `scroll-snap-type: x mandatory`, which dictates that scroll snapping must occur along the horizontal axis, and the scrolling will always come to rest on a snap point. The child elements are styled as follows: ```css .scroller > div { flex: 0 0 250px; width: 250px; background-color: #663399; color: #fff; font-size: 30px; display: flex; align-items: center; justify-content: center; scroll-snap-align: start; } .scroller > div:nth-child(2n) { background-color: #fff; color: #663399; } ``` The most relevant part here is `scroll-snap-align: start`, which specifies that the left-hand edges (the "starts" along the x axis, in our case) are the designated snap points. Last of all we specify the scroll margin-values, a different one for the second and third child elements: ```css .scroller > div:nth-child(2) { scroll-margin-inline-start: 1rem; } .scroller > div:nth-child(3) { scroll-margin-inline-start: 2rem; } ``` This means that when scrolling past the middle child elements, the scrolling will snap to `1rem` outside the inline start edge of the second `<div>`, and `2rems` outside the inline start edge of the third `<div>`. #### Result Try it for yourself: {{EmbedLiveSample('Simple_demonstration', '100%', 300)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS scroll snap](/en-US/docs/Web/CSS/CSS_scroll_snap) - [Well-controlled scrolling with CSS scroll snap](https://web.dev/articles/css-scroll-snap)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/cursor/index.md
--- title: cursor slug: Web/CSS/cursor page-type: css-property browser-compat: css.properties.cursor --- {{CSSRef}} The **`cursor`** [CSS](/en-US/docs/Web/CSS) property sets the mouse cursor, if any, to show when the mouse pointer is over an element. The cursor setting should inform users of the mouse operations that can be performed at the current location, including: text selection, activating help or context menus, copying content, resizing tables, and so on. You can specify either the _type_ of cursor using a keyword, or load a specific icon to use (with optional fallback images and mandatory keyword as a final fallback). {{EmbedInteractiveExample("pages/css/cursor.html")}} ## Syntax ```css /* Keyword value */ cursor: auto; cursor: pointer; /* … */ cursor: zoom-out; /* URL with mandatory keyword fallback */ cursor: url(hand.cur), pointer; /* URL and coordinates, with mandatory keyword fallback */ cursor: url(cursor_1.png) 4 12, auto; cursor: url(cursor_2.png) 2 2, pointer; /* URLs and fallback URLs (some with coordinates), with mandatory keyword fallback */ cursor: url(cursor_1.svg) 4 5, url(cursor_2.svg), /* …, */ url(cursor_n.cur) 5 5, progress; /* Global values */ cursor: inherit; cursor: initial; cursor: revert; cursor: revert-layer; cursor: unset; ``` The `cursor` property is specified as zero or more `<url>` values, separated by commas, followed by a single mandatory keyword value. Each `<url>` should point to an image file. The browser will try to load the first image specified, falling back to the next if it can't, and falling back to the keyword value if no images could be loaded (or if none were specified). Each `<url>` may be optionally followed by a pair of space-separated numbers, which set the `<x>` and `<y>` coordinates of the cursor's hotspot relative to the top-left corner of the image. ### Values - `<url>` {{optional_inline}} - : A `url()` or a comma separated list `url(), url(), …`, pointing to an image file. More than one {{cssxref("url", "url()")}} may be provided as fallbacks, in case some cursor image types are not supported. A non-URL fallback (one or more of the keyword values) _must_ be at the end of the fallback list. - `<x>`, `<y>` {{optional_inline}} - : Optional x- and y-coordinates indicating the cursor hotspot; the precise position within the cursor that is being pointed to. The numbers are in units of image pixels. They are relative to the top left corner of the image, which corresponds to "`0 0`", and are clamped within the boundaries of the cursor image. If these values are not specified, they may be read from the file itself, and will otherwise default to the top-left corner of the image. - `keyword` - : A keyword value _must_ be specified, indicating either the type of cursor to use, or the fallback cursor to use if all specified icons fail to load. The available keywords are listed in the table below. Other than `none`, which means no cursor, there is an image showing how the cursors used to be rendered. You can hover your mouse over the table rows to see the effect of the different cursor keyword values on your browser today. <table class="standard-table"> <thead> <tr> <th scope="col">Category</th> <th scope="col">Keyword</th> <th scope="col">Example</th> <th scope="col">Description</th> </tr> </thead> <tbody> <tr style="cursor: auto"> <th rowspan="3" scope="row">General</th> <td><code>auto</code></td> <td></td> <td> The UA will determine the cursor to display based on the current context. E.g., equivalent to <code>text</code> when hovering text. </td> </tr> <tr style="cursor: default"> <td><code>default</code></td> <td><img src="default.gif" alt="wide arrow pointing up and to the left" /></td> <td>The platform-dependent default cursor. Typically an arrow.</td> </tr> <tr style="cursor: none"> <td><code>none</code></td> <td></td> <td>No cursor is rendered.</td> </tr> <tr style="cursor: context-menu"> <th rowspan="5" scope="row" style="cursor: auto">Links &#x26; status</th> <td><code>context-menu</code></td> <td><img alt="wide arrow pointing up and to the left slightly obscuring a menu icon" src="context-menu.png" /></td> <td>A context menu is available.</td> </tr> <tr style="cursor: help"> <td><code>help</code></td> <td><img src="help.gif" alt="wide arrow pointing up and to the left next to a question mark" /></td> <td>Help information is available.</td> </tr> <tr style="cursor: pointer"> <td><code>pointer</code></td> <td><img src="pointer.gif" alt="right hand with an index finger pointing up" /></td> <td> The cursor is a pointer that indicates a link. Typically an image of a pointing hand. </td> </tr> <tr style="cursor: progress"> <td><code>progress</code></td> <td><img src="progress.gif" alt="wide arrow and hour glass" /></td> <td> The program is busy in the background, but the user can still interact with the interface (in contrast to <code>wait</code>). </td> </tr> <tr style="cursor: wait"> <td><code>wait</code></td> <td><img src="wait.gif" alt="hour glass" /></td> <td> The program is busy, and the user can't interact with the interface (in contrast to <code>progress</code>). Sometimes an image of an hourglass or a watch. </td> </tr> <tr style="cursor: cell"> <th rowspan="4" scope="row" style="cursor: auto">Selection</th> <td><code>cell</code></td> <td><img src="cell.gif" alt="wide plus symbol" /></td> <td>The table cell or set of cells can be selected.</td> </tr> <tr style="cursor: crosshair"> <td><code>crosshair</code></td> <td><img src="crosshair.gif" alt="plus symbol composed of two thin lines." /></td> <td>Cross cursor, often used to indicate selection in a bitmap.</td> </tr> <tr style="cursor: text"> <td><code>text</code></td> <td><img class="default" src="text.gif" alt="vertical i-beam" /></td> <td>The text can be selected. Typically the shape of an I-beam.</td> </tr> <tr style="cursor: vertical-text"> <td><code>vertical-text</code></td> <td><img alt="horizontal i-beam" src="vertical-text.gif" /></td> <td> The vertical text can be selected. Typically the shape of a sideways I-beam. </td> </tr> <tr style="cursor: alias"> <th rowspan="7" scope="row" style="cursor: auto">Drag &#x26; drop</th> <td><code>alias</code></td> <td><img src="alias.gif" alt="wide arrow pointing up and to the left partially obscuring a smaller folder icon with a curved arrow pointing up and to the right"/></td> <td>An alias or shortcut is to be created.</td> </tr> <tr style="cursor: copy"> <td><code>copy</code></td> <td><img class="default" src="copy.gif" alt="wide arrow pointing up and to the left partially obscuring a smaller folder icon with a plus sign" /></td> <td>Something is to be copied.</td> </tr> <tr style="cursor: move"> <td><code>move</code></td> <td><img src="move.gif" alt="plus sign made of two thin lines. The four points are small arrows facing out" /></td> <td>Something is to be moved.</td> </tr> <tr style="cursor: no-drop"> <td><code>no-drop</code></td> <td> <img src="no-drop.gif" alt="pointer icon and a not allowed icon" /> </td> <td> An item may not be dropped at the current location.<br />[Firefox bug 275173](https://bugzil.la/275173): On Windows and macOS, <code>no-drop</code> is the same as <code>not-allowed</code>. </td> </tr> <tr style="cursor: not-allowed"> <td><code>not-allowed</code></td> <td><img alt="Not allowed icon, which is a circle with a line through it" src="not-allowed.gif" /></td> <td>The requested action will not be carried out.</td> </tr> <tr style="cursor: grab"> <td><code>grab</code></td> <td><img class="default" src="grab.gif" alt="fully opened hand icon" /></td> <td>Something can be grabbed (dragged to be moved).</td> </tr> <tr style="cursor: grabbing"> <td><code>grabbing</code></td> <td><img class="default" src="grabbing.gif" alt="closed hand icon, of the back of the hand"/></td> <td>Something is being grabbed (dragged to be moved).</td> </tr> <tr style="cursor: all-scroll"> <th rowspan="15" scope="row" style="cursor: auto"> Resizing &#x26; scrolling </th> <td><code>all-scroll</code></td> <td><img alt="icon of a medium size dot with four triangles around it." src="all-scroll.gif" /></td> <td> Something can be scrolled in any direction (panned).<br />[Firefox bug 275174](https://bugzil.la/275174): On Windows, <code>all-scroll</code> is the same as <code>move</code>. </td> </tr> <tr style="cursor: col-resize"> <td><code>col-resize</code></td> <td><img alt="col-resize.gif" src="col-resize.gif" alt="two narrow parallel vertical lines with a small arrow pointing left and another pointing right" /></td> <td> The item/column can be resized horizontally. Often rendered as arrows pointing left and right with a vertical bar separating them. </td> </tr> <tr style="cursor: row-resize"> <td><code>row-resize</code></td> <td><img src="row-resize.gif" alt="two narrow parallel horizontal lines with a small arrow pointing up and another pointing down" /></td> <td> The item/row can be resized vertically. Often rendered as arrows pointing up and down with a horizontal bar separating them. </td> </tr> <tr style="cursor: n-resize"> <td><code>n-resize</code></td> <td> <img alt="thin long arrow pointing towards the top" src="n-resize.gif" style="border-style: solid; border-width: 0px" /> </td> <td rowspan="8" style="cursor: auto"> Some edge is to be moved. For example, the <code>se-resize</code> cursor is used when the movement starts from the <em>south-east</em> corner of the box.<br /> In some environments, an equivalent bidirectional resize cursor is shown. For example, <code>n-resize</code> and <code>s-resize</code> are the same as <code>ns-resize</code>. </td> </tr> <tr style="cursor: e-resize"> <td><code>e-resize</code></td> <td> <img alt="thin long arrow pointing towards the right" src="e-resize.gif" /> </td> </tr> <tr style="cursor: s-resize"> <td><code>s-resize</code></td> <td> <img alt="thin long arrow pointing down" src="s-resize.gif" /> </td> </tr> <tr style="cursor: w-resize"> <td><code>w-resize</code></td> <td> <img alt="thin long arrow pointing towards the left" src="w-resize.gif" /> </td> </tr> <tr style="cursor: ne-resize"> <td><code>ne-resize</code></td> <td> <img alt="thin long arrow pointing top-right" src="ne-resize.gif" /> </td> </tr> <tr style="cursor: nw-resize"> <td><code>nw-resize</code></td> <td> <img alt="thin long arrow pointing top-left" src="nw-resize.gif" /> </td> </tr> <tr style="cursor: se-resize"> <td><code>se-resize</code></td> <td> <img alt="thin long arrow pointing bottom-right" src="se-resize.gif" /> </td> </tr> <tr style="cursor: sw-resize"> <td><code>sw-resize</code></td> <td> <img alt="thin long arrow pointing bottom-left" src="sw-resize.gif" /> </td> </tr> <tr style="cursor: ew-resize"> <td><code>ew-resize</code></td> <td><img alt="thin long arrow pointing left and right" class="default" src="3-resize.gif" /></td> <td rowspan="4" style="cursor: auto">Bidirectional resize cursor.</td> </tr> <tr style="cursor: ns-resize"> <td><code>ns-resize</code></td> <td><img alt="thin long arrow pointing up and down" class="default" src="6-resize.gif" /></td> </tr> <tr style="cursor: nesw-resize"> <td><code>nesw-resize</code></td> <td><img alt="thin long arrow pointing both to the top-right and bottom-left" class="default" src="1-resize.gif" /></td> </tr> <tr style="cursor: nwse-resize"> <td><code>nwse-resize</code></td> <td><img alt="thin long arrow pointing both to the top-left and bottom-right" class="default" src="4-resize.gif" /></td> </tr> <tr style="cursor: zoom-in"> <th rowspan="2" scope="row" style="cursor: auto">Zooming</th> <td><code>zoom-in</code></td> <td><img alt="magnifying glass with a plus sign" class="default" src="zoom-in.gif" /></td> <td rowspan="2" style="cursor: auto"> <p>Something can be zoomed (magnified) in or out.</p> </td> </tr> <tr style="cursor: zoom-out"> <td><code>zoom-out</code></td> <td><img alt="magnifying glass with a minus sign" class="default" src="zoom-out.gif" /></td> </tr> </tbody> </table> ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Usage notes ### Icon size limits While the specification does not limit the `cursor` image size, {{Glossary("user agent", "user agents")}} commonly restrict them to avoid potential misuse. For example, on Firefox and Chromium cursor images are restricted to 128x128 pixels by default, but it is recommended to limit the cursor image size to 32x32 pixels. Cursor changes using images that are larger than the user-agent maximum supported size will generally just be ignored. ### Supported image file formats User agents are required by the specification to support PNG files, SVG v1.1 files in secure static mode that contain a natural size, and any other non-animated image file formats that they support for images in other properties. Desktop browsers also broadly support the `.cur` file format. The specification further indicates that user agents _should_ also support SVG v1.1 files in secure animated mode that contain a natural size, along with any other animated images file formats they support for images in other properties. User agents _may_ support both static and animated SVG images that do not contain a natural size. ### iPadOS iPadOS supports pointer devices like trackpads and mouses. By default, the iPad cursor is displayed as a circle, and the only supported value that will change an appearance of the pointer is `text`. ### Other notes Cursor changes that intersect toolbar areas are commonly blocked to avoid spoofing. ## Examples ### Setting cursor types ```css .foo { cursor: crosshair; } .bar { cursor: zoom-in; } /* A fallback keyword value is required when using a URL */ .baz { cursor: url("hyper.cur"), auto; } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("pointer-events")}} - {{cssxref("url", "url()")}} function
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_first/index.md
--- title: ":first" slug: Web/CSS/:first page-type: css-pseudo-class browser-compat: css.selectors.first --- {{CSSRef}} The **`:first`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes), used with the {{cssxref("@page")}} [at-rule](/en-US/docs/Web/CSS/At-rule), represents the first page of a printed document. (See {{cssxref(":first-child")}} for general first element of a node.) ```css /* Selects the first page when printing */ @page :first { margin-left: 50%; margin-top: 50%; } ``` > **Note:** You can't change all CSS properties with this pseudo-class. You can only change the margins, {{cssxref("orphans")}}, {{cssxref("widows")}}, and page breaks of the document. Furthermore, you may only use [absolute-length](/en-US/docs/Web/CSS/length#absolute_length_units) units when defining the margins. All other properties will be ignored. ## Syntax ```css :first { /* ... */ } ``` ## Examples ### HTML ```html <p>First Page.</p> <p>Second Page.</p> <button>Print!</button> ``` ### CSS ```css @page :first { margin-left: 50%; margin-top: 50%; } p { page-break-after: always; } ``` ### JavaScript ```js document.querySelector("button").addEventListener("click", () => { window.print(); }); ``` ### Result Press the "Print!" button to print the example. The words on the first page should be somewhere around the center, while other pages will have their contents at the default position. {{ EmbedLiveSample('Examples', '80%', '150px') }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{Cssxref("@page")}} - Other page-related pseudo-classes: {{Cssxref(":left")}}, {{Cssxref(":right")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/scroll-padding-bottom/index.md
--- title: scroll-padding-bottom slug: Web/CSS/scroll-padding-bottom page-type: css-property browser-compat: css.properties.scroll-padding-bottom --- {{CSSRef}} The `scroll-padding-bottom` property defines offsets for the bottom of the _optimal viewing region_ of the scrollport: the region used as the target region for placing things in view of the user. This allows the author to exclude regions of the scrollport that are obscured by other content (such as fixed-positioned toolbars or sidebars) or to put more breathing room between a targeted element and the edges of the scrollport. {{EmbedInteractiveExample("pages/css/scroll-padding-bottom.html")}} ## Syntax ```css /* Keyword values */ scroll-padding-bottom: auto; /* <length> values */ scroll-padding-bottom: 10px; scroll-padding-bottom: 1em; scroll-padding-bottom: 10%; /* Global values */ scroll-padding-bottom: inherit; scroll-padding-bottom: initial; scroll-padding-bottom: revert; scroll-padding-bottom: revert-layer; scroll-padding-bottom: unset; ``` ### Values - `<length-percentage>` - : An inwards offset from the bottom edge of the scrollport, as a valid length or a percentage. - `auto` - : The offset is determined by the user agent. This will generally be 0px, but a user agent is able to detect and do something else if a non-zero value is more appropriate. ## Formal definition {{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/overflow-inline/index.md
--- title: overflow-inline slug: Web/CSS/overflow-inline page-type: css-property browser-compat: css.properties.overflow-inline --- {{CSSRef}} The **`overflow-inline`** [CSS](/en-US/docs/Web/CSS) property sets what shows when content overflows the inline start and end edges of a box. This may be nothing, a scroll bar, or the overflow content. > **Note:** The `overflow-inline` property maps to {{Cssxref("overflow-y")}} or {{Cssxref("overflow-x")}} depending on the writing mode of the document. ## Syntax ```css /* Keyword values */ overflow-inline: visible; overflow-inline: hidden; overflow-inline: clip; overflow-inline: scroll; overflow-inline: auto; /* Global values */ overflow-inline: inherit; overflow-inline: initial; overflow-inline: revert; overflow-inline: revert-layer; overflow-inline: unset; ``` The `overflow-inline` property is specified as a single {{CSSXref("overflow_value", "&lt;overflow&gt;")}} keyword value. ### Values - `visible` - : Content is not clipped and may be rendered outside the padding box's inline start and end edges. - `hidden` - : Content is clipped if necessary to fit the inline dimension in the padding box. No scrollbars are provided. - `clip` - : Overflow content is clipped at the element's overflow clip edge that is defined using the {{CSSXref("overflow-clip-margin")}} property. - `scroll` - : Content is clipped if necessary to fit in the padding box in the inline dimension. Browsers display scrollbars whether or not any content is actually clipped. (This prevents scrollbars from appearing or disappearing when the content changes.) Printers may still print overflowing content. - `auto` - : Depends on the user agent. If content fits inside the padding box, it looks the same as `visible`, but still establishes a new block-formatting context. Desktop browsers provide scrollbars if content overflows. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting inline overflow behavior #### HTML ```html <ul> <li> <code>overflow-inline: hidden</code> (hides the text outside the box) <div id="div1">ABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZ</div> </li> <li> <code>overflow-inline: scroll</code> (always adds a scrollbar) <div id="div2">ABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZ</div> </li> <li> <code>overflow-inline: visible</code> (displays the text outside the box if needed) <div id="div3">ABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZ</div> </li> <li> <code>overflow-inline: auto</code> (equivalent to <code>scroll</code> in most browsers) <div id="div4">ABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZ</div> </li> <li> <code>overflow-inline: clip</code> (hides the text outside the box beyond the overflow clip edge) <code>clip</code> <div id="div5">ABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZ</div> </li> </ul> ``` #### CSS ```css div { border: 1px solid black; width: 250px; margin-bottom: 12px; } #div1 { overflow-inline: hidden; } #div2 { overflow-inline: scroll; } #div3 { overflow-inline: visible; } #div4 { overflow-inline: auto; } #div5 { overflow-inline: clip; overflow-clip-margin: 2em; } ``` #### Result {{EmbedLiveSample("Setting_inline_overflow_behavior", "100%", "270")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("clip")}}, {{cssxref("display")}}, {{cssxref("overflow")}}, {{cssxref("overflow-block")}}, {{cssxref("overflow-clip-margin")}}, {{cssxref("overflow-x")}}, {{cssxref("overflow-y")}}, {{cssxref("text-overflow")}}, {{cssxref("white-space")}} - [CSS overflow](/en-US/docs/Web/CSS/CSS_overflow) module - [CSS logical properties](/en-US/docs/Web/CSS/CSS_logical_properties_and_values) - [CSS writing modes](/en-US/docs/Web/CSS/CSS_writing_modes) - [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/scaling_of_svg_backgrounds/index.md
--- title: Scaling of SVG backgrounds slug: Web/CSS/Scaling_of_SVG_backgrounds page-type: guide --- {{CSSRef}} Given the flexibility of SVG images, there's a lot to keep in mind when using them as background images with the {{ cssxref("background-image") }} property, and even more to keep in mind when also scaling them using the {{ cssxref("background-size") }} property. This article describes how scaling of SVG images is handled when using these properties. ## The algorithm, in summary The algorithm can for the most part be summarized by these four rules. There are some edge cases that aren't covered by these rules, but this covers the majority of cases. 1. If {{ cssxref("background-size") }} specifies a fixed dimension (that is, percentages and relative units are fixed by their context), that dimension wins. 2. If the image has an intrinsic ratio (that is, its width:height ratio is constant, such as 16:9, 4:3, 2.39:1, 1:1, and so forth), the rendered size preserves that ratio. 3. If the image specifies a size, and the size isn't modified by constrain or cover, that specified size wins. 4. If none of the above cases are met, the image is rendered at the same size as the background area. It's worth noting that the sizing algorithm only cares about the image's dimensions and proportions, or lack thereof. An SVG image with fixed dimensions will be treated just like a raster image of the same size. > **Note:** If you are trying to stretch your SVG to a different aspect ratio with CSS—for example in order to stretch it over the page background—make sure your SVG includes `preserveAspectRatio="none"`. Find out more about {{svgattr("preserveAspectRatio")}}. ## Source image examples Before diving in to look at the results of using different kinds of source images and seeing how they look when used with {{ cssxref("background-size") }}, it would be helpful to look at a few example source images that have different dimensions and sizing settings. In each case, we show what the source image looks like rendered in a 150x150 box, and provide a link to the SVG source. ### Dimensionless and proportionless This image is both dimensionless and proportionless. It doesn't care what size it is, nor does it care about remaining at a particular aspect ratio. This would make a good gradient desktop background that would work regardless of your screen size and its aspect ratio. ![no-dimensions-or-ratio.png](no-dimensions-or-ratio.png) [SVG source](https://mdn.dev/archives/media/attachments/2012/07/09/3469/6587a382ffb2c944462a6b110b079496/no-dimensions-or-ratio.svg) ### One specified dimension and proportionless This image specifies a width of 100 pixels but no height or intrinsic ratio. This is, basically, a thin strip of wallpaper that could be stretched across the entire height of a block. ![100px-wide-no-height-or-ratio.png](100px-wide-no-height-or-ratio.png) [SVG source](https://mdn.dev/archives/media/attachments/2012/07/09/3468/af73bea307a10ffe2559df42fad199e3/100px-wide-no-height-or-ratio.svg) ### One specified dimension with intrinsic ratio This image specifies a 100 pixel height but no width. It also specifies an intrinsic aspect ratio of 3:4. This ensures that its width:height ratio is always 3:4, unless it's deliberately scaled to a disproportionate size (that is, by explicitly specifying both width and height that aren't of that ratio). This is very much like specifying a specific width and height, since once you have one dimension and a ratio, the other dimension is implied, but it's still a useful example. ![100px-height-3x4-ratio.png](100px-height-3x4-ratio.png) [SVG source](https://mdn.dev/archives/media/attachments/2012/07/09/3467/fd0c534c506be06d52f0a954a59863a6/100px-height-3x4-ratio.svg) ### No width or height with intrinsic ratio This image doesn't specify either a width or a height; instead, it specifies an intrinsic ratio of 1:1. Think of this like a program icon. It's always square, and is usable at any size, such as 32x32, 128x128, or 512x512, for example. ![no-dimensions-1x1-ratio.png](no-dimensions-1x1-ratio.png) [SVG source](https://mdn.dev/archives/media/attachments/2012/07/09/3466/a3398e03c058d99fb2b7837167cdbc26/no-dimensions-1x1-ratio.svg) ## Scaling examples Now let's see some examples of what happens as we apply different scaling to these images. In each of the examples below, the enclosing rectangles are 300 pixels wide and 200 pixels tall. In addition, the backgrounds have {{ cssxref("background-repeat") }} set to no-repeat for clarity. > **Note:** The screenshots below show the **expected** rendering. Not all browsers currently render these correctly. ### Specifying fixed lengths for both dimensions If you use {{ cssxref("background-size") }} to specify fixed lengths for both dimensions, those lengths are always used, per rule 1 above. In other words, the image will always get stretched to the dimensions you specify, regardless of whether or not the source image has specified its dimensions and/or aspect ratio. #### Source: No dimensions or intrinsic ratio Given this CSS: ```css background: url(no-dimensions-or-ratio.svg); background-size: 125px 175px; ``` The rendered output would look like this: ![fixed-no-dimensions-or-ratio.png](fixed-no-dimensions-or-ratio.png) #### Source: One specified dimension, no intrinsic ratio Given this CSS: ```css background: url(100px-wide-no-height-or-ratio.svg); background-size: 250px 150px; ``` The rendered output would look like this: ![fixed-100px-wide-no-height-or-ratio.png](fixed-100px-wide-no-height-or-ratio.png) #### Source: One specified dimension with intrinsic ratio Given this CSS: ```css background: url(100px-height-3x4-ratio.svg); background-size: 275px 125px; ``` The rendered output would look like this: ![fixed-100px-height-3x4-ratio.png](fixed-100px-height-3x4-ratio.png) #### Source: No specified width or height with intrinsic ratio Given this CSS: ```css background: url(no-dimensions-1x1-ratio.svg); background-size: 250px 100px; ``` The rendered output would look like this: ![fixed-no-dimensions-1x1-ratio.png](fixed-no-dimensions-1x1-ratio.png) ### Using contain or cover Specifying `cover` for {{ cssxref("background-size") }} makes the picture as small as possible while still covering the entire background area. `contain`, on the other hand, makes the image as large as possible while not being clipped by the background area. For an image with an intrinsic ratio, exactly one size matches the `cover`/fit criteria alone. But if there is no intrinsic ratio specified, `cover`/fit isn't sufficient, so the large/small constraints choose the resulting size. #### Source: No dimensions or intrinsic ratio If an image doesn't specify either dimensions or an intrinsic ratio, neither rule 2 nor rule 3 apply, so rule 4 takes over: the background image is rendered covering the entire background area. This satisfies the largest-or-smallest constraint. ```css background: url(no-dimensions-or-ratio.svg); background-size: contain; ``` The rendered output looks like this: ![no-dimensions-or-ratio-contain.png](no-dimensions-or-ratio-contain.png) #### Source: One specified dimension, no intrinsic ratio Similarly, if the image has one dimension specified but no intrinsic ratio, rule 4 applies, and the image is scaled to cover the entire background area. ```css background: url(100px-wide-no-height-or-ratio.svg); background-size: contain; ``` The rendered output looks like this: ![100px-wide-no-height-or-ratio-contain.png](100px-wide-no-height-or-ratio-contain.png) #### Source: One specified dimension with intrinsic ratio Things change when you specify an intrinsic ratio. In this case, rule 1 isn't relevant, so rule 2 is applied: we try to preserve any intrinsic ratio (while respecting `contain` or `cover`). For example, preserving a 3:4 intrinsic aspect ratio for a 300x200 box with `contain` means drawing a 150x200 background. ##### contain case ```css background: url(100px-height-3x4-ratio.svg); background-size: contain; ``` The rendered output looks like this: ![100px-height-3x4-ratio-contain.png](100px-height-3x4-ratio-contain.png) Notice how the entire image is rendered, fitting as best as possible into the box without clipping any of it away. ##### cover case ```css background: url(100px-height-3x4-ratio.svg); background-size: cover; ``` The rendered output looks like this: ![100px-height-3x4-ratio-cover.png](100px-height-3x4-ratio-cover.png) Here, the 3:4 ratio is preserved while still stretching the image to fill the entire box. That causes the bottom of the image to be clipped away. #### Source: No dimensions with intrinsic ratio When using an image with no intrinsic dimensions but an intrinsic ratio, things work similarly. ##### contain case ```css background: url(no-dimensions-1x1-ratio.svg); background-size: contain; ``` The rendered output looks like this: ![no-dimensions-1x1-ratio-contain.png](no-dimensions-1x1-ratio-contain.png) Notice that the image is sized to fit the smallest dimension while preserving the 1:1 aspect ratio. ##### cover case ```css background: url(no-dimensions-1x1-ratio.svg); background-size: cover; ``` The rendered output looks like this: ![no-dimensions-1x1-ratio-cover.png](no-dimensions-1x1-ratio-cover.png) Here, the image is sized so that it fills the largest dimension. The 1:1 aspect ratio has been preserved, although with this source image, that can be difficult to see. ### Automatic sizing using "auto" for both dimensions If {{ cssxref("background-size") }} is set to `auto` or `auto auto`, rule 2 says that rendering must preserve any intrinsic ratio that's provided. #### Source: No dimensions or intrinsic ratio When no intrinsic ratio or dimensions are specified by the source image, rule 4 takes effect, and the image is rendered to fill the background area. ```css background: url(no-dimensions-or-ratio.svg); background-size: auto auto; ``` The rendered output looks like this: ![auto-no-dimensions-or-ratio.png](auto-no-dimensions-or-ratio.png) #### Source: One dimension and no intrinsic ratio If no intrinsic ratio is specified, but at least one dimension is specified, rule 3 takes effect, and we render the image obeying those dimensions. ```css background: url(100px-wide-no-height-or-ratio.svg); background-size: auto auto; ``` The rendered output looks like this: ![auto-100px-wide-no-height-or-ratio.png](auto-100px-wide-no-height-or-ratio.png) Note here that the width, which is specified in the source SVG at 100 pixels, is obeyed, while the height fills the background area since it's not specified (either explicitly or by an intrinsic ratio). #### Source: One dimension and an intrinsic ratio If we have an intrinsic ratio with a fixed dimension, that fixes both dimensions in place. Knowing one dimension and a ratio is, as has been mentioned already, the same as specifying both dimensions explicitly. ```css background: url(100px-height-3x4-ratio.svg); background-size: auto auto; ``` The rendered output looks like this: ![auto-100px-height-3x4-ratio.png](auto-100px-height-3x4-ratio.png) Since this image has an explicit 100 pixel height, the 3:4 ratio explicitly sets its width at 75 pixels, so that's how it's rendered in the `auto` case. #### Source: No fixed dimensions with intrinsic ratio When an intrinsic ratio is specified, but no dimensions, rule 4 is applied — except that rule 2 also applies. The image is therefore rendered just like for the `contain` case. ```css background: url(no-dimensions-1x1-ratio.svg); background-size: auto auto; ``` The rendered output looks like this: ![auto-no-dimensions-1x1-ratio.png](auto-no-dimensions-1x1-ratio.png) ### Using "auto" and one specific length Given rule 1, specified dimensions are always used, so we need to use our rules only to determine the second dimension. #### Source: No dimensions or intrinsic ratio If the image has no dimensions or intrinsic ratio, rule 4 applies, and we use the background area's dimension to determine the value for the `auto` dimension. ```css background: url(no-dimensions-or-ratio.svg); background-size: auto 150px; ``` ![1auto-no-dimensions-or-ratio.png](1auto-no-dimensions-or-ratio.png) Here, the width is determined using the background area's width per rule 4, while the height is the 140px specified in the CSS. #### Source: One specified dimension with no intrinsic ratio If the image has one specified dimension but no intrinsic ratio, that specified dimension is used per rule 3 if that dimension is set to `auto` in the CSS. ```css background: url(100px-wide-no-height-or-ratio.svg); background-size: 200px auto; ``` ![100px-wide-no-height-or-ratio-length-auto.png](100px-wide-no-height-or-ratio-length-auto.png) Here, the 200px specified in the CSS overrides the 100px width specified in the SVG, per rule 1. Since there's no intrinsic ratio or height provided, `auto` selects the height of the background area as the height for the rendered image. ```css background: url(100px-wide-no-height-or-ratio.svg); background-size: auto 125px; ``` ![100px-wide-no-height-or-ratio-auto-length.png](100px-wide-no-height-or-ratio-auto-length.png) In this case, the width is specified as auto in the CSS, so the 100px width specified in the SVG is selected, per rule 3. The height is set at 125px in the CSS, so that is selected per rule 1. #### Source: One specified dimension with intrinsic ratio When a dimension is specified, rule 1 applies that dimension from the SVG to the rendered background unless specifically overridden by the CSS. When an intrinsic ratio is also specified, that's used to determine the other dimension. ```css background: url(100px-height-3x4-ratio.svg); background-size: 150px auto; ``` ![1auto-100px-height-3x4-ratio.png](1auto-100px-height-3x4-ratio.png) In this case, we use the width of the image specified in the CSS set at 150px, so rule 1 is applied. The intrinsic 3:4 aspect ratio then determines the height for the `auto` case. #### Source: No specified dimensions with intrinsic ratio If no dimensions are specified in the SVG, the specified dimension in the CSS is applied, then the intrinsic ratio is used to select the other dimension, per rule 2. ```css background: url(no-dimensions-1x1-ratio.svg); background-size: 150px auto; ``` ![1auto-no-dimensions-1x1-ratio.png](1auto-no-dimensions-1x1-ratio.png) The width is set by the CSS to 150px. The `auto` value for the height is computed using that width and the 1:1 aspect ratio to be 150px as well, resulting in the image above. ## See also - {{cssxref("background-size")}} - Blog post: [Properly resizing vector image backgrounds](https://whereswalden.com/2011/10/21/properly-resizing-vector-image-backgrounds/)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_first-line/index.md
--- title: "::first-line" slug: Web/CSS/::first-line page-type: css-pseudo-element browser-compat: css.selectors.first-line --- {{CSSRef}} The **`::first-line`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) applies styles to the first line of a [block container](/en-US/docs/Web/CSS/Visual_formatting_model#block_containers). {{EmbedInteractiveExample("pages/tabbed/pseudo-element-first-line.html", "tabbed-shorter")}} The effects of `::first-line` are limited by the length and content of the first line of text in the element. The length of the first line depends on many factors, including the width of the element, the width of the document, and the font size of the text. `::first-line` has no effect when the first child of the element, which would be the first part of the first line, is an inline block-level element, such as an inline table. > **Note:** [Selectors Level 3](https://drafts.csswg.org/selectors-3/#first-line) introduced the double-colon notation (`::`) to distinguish [pseudo-elements](/en-US/docs/Web/CSS/Pseudo-elements) from the single-colon (`:`) [pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes). Browsers accept both `::first-line` and `:first-line`, which was introduced in CSS2. For the purposes of CSS {{CSSXref("background")}}, the `::first-line` pseudo-element is like an inline-level element meaning that in a left-justified first line, the background may not extend all the way to the right margin. ## Allowable properties Only a small subset of CSS properties can be used with the `::first-line` pseudo-element: - All font-related properties: {{Cssxref("font")}}, {{cssxref("font-kerning")}}, {{Cssxref("font-style")}}, {{Cssxref("font-variant")}}, {{cssxref("font-variant-numeric")}}, {{cssxref("font-variant-position")}}, {{cssxref("font-variant-east-asian")}}, {{cssxref("font-variant-caps")}}, {{cssxref("font-variant-alternates")}}, {{cssxref("font-variant-ligatures")}}, {{cssxref("font-synthesis")}}, {{cssxref("font-feature-settings")}}, {{cssxref("font-language-override")}}, {{Cssxref("font-weight")}}, {{Cssxref("font-size")}}, {{cssxref("font-size-adjust")}}, {{cssxref("font-stretch")}}, and {{Cssxref("font-family")}} - All background-related properties: {{Cssxref("background-color")}}, {{cssxref("background-clip")}}, {{Cssxref("background-image")}}, {{cssxref("background-origin")}}, {{Cssxref("background-position")}}, {{Cssxref("background-repeat")}}, {{cssxref("background-size")}}, {{Cssxref("background-attachment")}}, and {{cssxref("background-blend-mode")}} - The {{cssxref("color")}} property - {{cssxref("word-spacing")}}, {{cssxref("letter-spacing")}}, {{cssxref("text-decoration")}}, {{cssxref("text-transform")}}, and {{cssxref("line-height")}} - {{cssxref("text-shadow")}}, {{cssxref("text-decoration")}}, {{cssxref("text-decoration-color")}}, {{cssxref("text-decoration-line")}}, {{cssxref("text-decoration-style")}}, and {{cssxref("vertical-align")}}. ## Syntax ```css ::first-line { /* ... */ } ``` ## Examples ### HTML ```html <p> Styles will only be applied to the first line of this paragraph. After that, all text will be styled like normal. See what I mean? </p> <span> The first line of this text will not receive special styling because it is not a block-level element. </span> ``` ### CSS ```css ::first-line { color: blue; text-transform: uppercase; /* WARNING: DO NOT USE THESE */ /* Many properties are invalid in ::first-line pseudo-elements */ margin-left: 20px; text-indent: 20px; } ``` ### Result {{EmbedLiveSample('Examples', 350, 160)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("::first-letter")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_local-link/index.md
--- title: ":local-link" slug: Web/CSS/:local-link page-type: css-pseudo-class spec-urls: https://drafts.csswg.org/selectors/#local-link-pseudo --- {{CSSRef}} The **`:local-link`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents a link to the same document. Therefore an element that is the source anchor of a hyperlink whose target's absolute URL matches the element's own document URL. ```css /* Selects any <a> that links to the current document */ a:local-link { color: green; } ``` ## Syntax ```css :local-link { /* ... */ } ``` ## Examples ### HTML ```html <a href="#target">This is a link on the current page.</a><br /> <a href="https://example.com">This is an external link</a><br /> ``` ### CSS ```css a:local-link { color: green; } ``` ### Result {{EmbedLiveSample("Examples")}} ## Specifications {{Specifications}} ## Browser compatibility This feature is a proposal integrated into the specification. Currently, no browser supports it. ## See also - Link-related pseudo-classes: {{ cssxref(":link") }}, {{ cssxref(":visited") }}, {{ cssxref(":hover") }}, {{ cssxref(":active") }}, {{ cssxref(":any-link") }}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/grid-row-start/index.md
--- title: grid-row-start slug: Web/CSS/grid-row-start page-type: css-property browser-compat: css.properties.grid-row-start --- {{CSSRef}} The **`grid-row-start`** CSS property specifies a grid item's start position within the grid row by contributing a line, a span, or nothing (automatic) to its grid placement, thereby specifying the inline-start edge of its {{glossary("grid areas", "grid area")}}. {{EmbedInteractiveExample("pages/css/grid-row-start.html")}} ## Syntax ```css /* Keyword value */ grid-row-start: auto; /* <custom-ident> values */ grid-row-start: somegridarea; /* <integer> + <custom-ident> values */ grid-row-start: 2; grid-row-start: somegridarea 4; /* span + <integer> + <custom-ident> values */ grid-row-start: span 3; grid-row-start: span somegridarea; grid-row-start: 5 somegridarea span; /* Global values */ grid-row-start: inherit; grid-row-start: initial; grid-row-start: revert; grid-row-start: revert-layer; grid-row-start: unset; ``` This property is specified as a single `<grid-line>` value. A `<grid-line>` value can be specified as: - either the `auto` keyword - or a `<custom-ident>` value - or an `<integer>` value - or both `<custom-ident>` and `<integer>`, separated by a space - or the keyword `span` together with either a `<custom-ident>` or an `<integer>` or both. ### Values - `auto` - : Is a keyword indicating that the property contributes nothing to the grid item's placement, indicating auto-placement, an automatic span, or a default span of `1`. - `<custom-ident>` - : If there is a named line with the name '\<custom-ident>-start', it contributes the first such line to the grid item's placement. > **Note:** Named grid areas automatically generate implicit named lines of this form, so specifying `grid-row-start: foo;` will choose the start edge of that named grid area (unless another line named `foo-start` was explicitly specified before it). Otherwise, this is treated as if the integer `1` had been specified along with the `<custom-ident>`. - `<integer> && <custom-ident>?` - : Contributes the nth grid line to the grid item's placement. If a negative integer is given, it instead counts in reverse, starting from the end edge of the explicit grid. If a name is given as a \<custom-ident>, only lines with that name are counted. If not enough lines with that name exist, all implicit grid lines are assumed to have that name for the purpose of finding this position. An {{cssxref("integer")}} value of `0` is invalid. - `span && [ <integer> || <custom-ident> ]` - : Contributes a grid span to the grid item's placement; such that the row start edge of the grid item's grid area is n lines from the end edge. If a name is given as a \<custom-ident>, only lines with that name are counted. If not enough lines with that name exist, all implicit grid lines on the side of the explicit grid, corresponding to the search direction, are assumed to have that name for the purpose of counting this span. If the \<integer> is omitted, it defaults to `1`. Negative integers or 0 are invalid. The `<custom-ident>` cannot take the `span` value. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting row start for a grid item #### HTML ```html <div class="wrapper"> <div class="box1">One</div> <div class="box2">Two</div> <div class="box3">Three</div> <div class="box4">Four</div> <div class="box5">Five</div> </div> ``` #### CSS ```css .wrapper { display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 100px; } .box1 { grid-column-start: 1; grid-column-end: 4; grid-row-start: 1; grid-row-end: 3; } .box2 { grid-column-start: 1; grid-row-start: 3; grid-row-end: 5; } ``` ```css hidden * { box-sizing: border-box; } .wrapper { border: 2px solid #f76707; border-radius: 5px; background-color: #fff4e6; } .wrapper > div { border: 2px solid #ffa94d; border-radius: 5px; background-color: #ffd8a8; padding: 1em; color: #d9480f; } .nested { border: 2px solid #ffec99; border-radius: 5px; background-color: #fff9db; padding: 1em; } ``` #### Result {{ EmbedLiveSample('Setting_row_start_for_a_grid_item', '230', '420') }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Related CSS properties: {{cssxref("grid-row-end")}}, {{cssxref("grid-row")}}, {{cssxref("grid-column-start")}}, {{cssxref("grid-column-end")}}, {{cssxref("grid-column")}} - Grid Layout Guide: _[Line-based placement with CSS Grid](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_layout_using_line-based_placement)_ - Video tutorial: _[Line-based placement](https://gridbyexample.com/video/series-line-based-placement/)_
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/animation-name/index.md
--- title: animation-name slug: Web/CSS/animation-name page-type: css-property browser-compat: css.properties.animation-name --- {{CSSRef}} The **`animation-name`** [CSS](/en-US/docs/Web/CSS) property specifies the names of one or more {{cssxref("@keyframes")}} at-rules that describe the animation to apply to an element. Multiple `@keyframe` at-rules are specified as a comma-separated list of names. If the specified name does not match any `@keyframe` at-rule, no properties are animated. {{EmbedInteractiveExample("pages/css/animation-name.html")}} It is often convenient to use the shorthand property {{cssxref("animation")}} to set all animation properties at once. ## Syntax ```css /* Single animation */ animation-name: none; animation-name: test_05; animation-name: -specific; animation-name: sliding-vertically; /* Multiple animations */ animation-name: test1, animation4; animation-name: none, -moz-specific, sliding; /* Global values */ animation-name: inherit; animation-name: initial; animation-name: revert; animation-name: revert-layer; animation-name: unset; ``` ### Values - `none` - : A special keyword denoting no keyframes. It can be used to deactivate an animation without changing the ordering of the other identifiers, or to deactivate animations coming from the cascade. - {{cssxref("&lt;custom-ident&gt;")}} - : A name identifying the animation. This identifier is composed of a combination of case-sensitive letters `a` to `z`, numbers `0` to `9`, underscores (`_`), and/or dashes (`-`). The first non-dash character must be a letter. Also, two dashes are forbidden at the beginning of the identifier. Furthermore, the identifier can't be `none`, `unset`, `initial`, or `inherit`. > **Note:** When you specify multiple comma-separated values on an `animation-*` property, they are applied to the animations in the order in which the {{cssxref("animation-name")}}s appear. For situations where the number of animations and `animation-*` property values do not match, see [Setting multiple animation property values](/en-US/docs/Web/CSS/CSS_animations/Using_CSS_animations#setting_multiple_animation_property_values). ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Naming an animation This animation has an `animation-name` of `rotate`. #### HTML ```html <div class="box"></div> ``` #### CSS ```css .box { background-color: rebeccapurple; border-radius: 10px; width: 100px; height: 100px; } .box:hover { animation-name: rotate; animation-duration: 0.7s; } @keyframes rotate { 0% { transform: rotate(0); } 100% { transform: rotate(360deg); } } ``` #### Result Hover over the rectangle to start the animation. {{EmbedLiveSample("Naming an animation","100%","250")}} See [CSS animations](/en-US/docs/Web/CSS/CSS_animations/Using_CSS_animations) for examples. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Using CSS animations](/en-US/docs/Web/CSS/CSS_animations/Using_CSS_animations) - JavaScript {{domxref("AnimationEvent")}} API - Other related animation properties: {{cssxref("animation")}}, {{cssxref("animation-composition")}}, {{cssxref("animation-delay")}}, {{cssxref("animation-direction")}}, {{cssxref("animation-duration")}}, {{cssxref("animation-fill-mode")}}, {{cssxref("animation-iteration-count")}}, {{cssxref("animation-play-state")}}, {{cssxref("animation-timeline")}}, {{cssxref("animation-timing-function")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/contain-intrinsic-size/index.md
--- title: contain-intrinsic-size slug: Web/CSS/contain-intrinsic-size page-type: css-shorthand-property browser-compat: css.properties.contain-intrinsic-size --- {{CSSRef}} The **`contain-intrinsic-size`** [CSS](/en-US/docs/Web/CSS) [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) sets the size of an element that a browser will use for layout when the element is subject to [size containment](/en-US/docs/Web/CSS/CSS_containment#size_containment). ## Constituent properties This property is a shorthand for the following CSS properties: - [`contain-intrinsic-width`](/en-US/docs/Web/CSS/contain-intrinsic-width) - [`contain-intrinsic-height`](/en-US/docs/Web/CSS/contain-intrinsic-height) ## Syntax ```css /* Keyword values */ contain-intrinsic-width: none; /* <length> values */ contain-intrinsic-size: 1000px; contain-intrinsic-size: 10rem; /* width | height */ contain-intrinsic-size: 1000px 1.5em; /* auto <length> */ contain-intrinsic-size: auto 300px; contain-intrinsic-size: auto none; /* auto width | auto height */ contain-intrinsic-size: auto 300px auto 4rem; /* Global values */ contain-intrinsic-size: inherit; contain-intrinsic-size: initial; contain-intrinsic-size: revert; contain-intrinsic-size: revert-layer; contain-intrinsic-size: unset; ``` ### Values The following values may be specified for the `contain-intrinsic-size` property: - `none` - : The element has no intrinsic size in the given dimension(s). - `<length>` - : The element has the specified {{cssxref("&lt;length&gt;")}} in the given dimension(s). - `auto [<length> | none]` - : A remembered value of the "normally rendered" element size if one exists and the element is skipping its contents (for example, when it is offscreen); otherwise the specified `<length>`. The `none` keyword may be used in place of `<length>` where `0px` fixed lengths behave differently than `none` (such as in multi column, or grid layouts). If one value is provided as a keyword, a length or an `auto [<length> | none]` pair, it applies to both width and height. Two length values may be specified, which apply to the width and height in that order. If two `auto [<length> | none]` pairs are specified, the first pair applies to the width, and the second to the height. ## Description The property is commonly applied alongside elements that can trigger size containment, such as [`contain: size`](/en-US/docs/Web/CSS/contain) and [`content-visibility`](/en-US/docs/Web/CSS/content-visibility). Size containment allows a user agent to lay out an element as though it had a fixed size, preventing unnecessary reflows by avoiding the re-rendering of child elements to determine the actual size (thereby improving user experience). By default, size containment treats elements as though they had no contents, and may collapse the layout in the same way as if the contents had no width or height. The `contain-intrinsic-size` property allows authors to specify an appropriate value to be used as the size for layout. The `auto <length>` value allows the size of the element to be stored if the element is ever "normally rendered" (with its child elements), and then used instead of the specified length when the element is skipping its contents. This allows offscreen elements with [`content-visibility: auto`](/en-US/docs/Web/CSS/content-visibility) to benefit from size containment without developers having to be as precise in their estimates of element size. The remembered value is not used if the child elements are being rendered (if size containment is enabled, the `<length>` will be used). In grid and multi column layouts, an explicit size is treated differently than implicit content-based height. Elements might lay out substantially differently than it would have were it simply filled with content up to that height. The `auto none` value allows the element to fallback to `contain-intrinsic-size: none` if no remembered value exists, which will allow the element to be laid out as though it had no contents. This is almost always preferred to setting 0px as the intrinsic size in grid and multi column layouts, where contained elements may overflow their parents and can result in unexpected page layout. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Using auto value pairs for intrinsic size This example demonstrates `contain-intrinsic-size: auto <length>` and `contain-intrinsic-size: auto none`, using a layout where there are many elements displayed vertically that have both accurate and incorrect intrinsic size estimations. Using `content-visibility: auto` skips rendering elements when they are offscreen, so this property is a good candidate to combine with `contain-intrinsic-size` to improve rendering performance and minimize [reflows](/en-US/docs/Glossary/Reflow). The `contain-intrinsic-size: auto 500px` value pair tells the browser to use 500px as a kind of 'placeholder' size (width and height) for the element when it is offscreen and the page is being laid out. When the user scrolls to the element and it needs to be displayed, the browser will calculate the actual size of the element and its contents. If there is a difference between the placeholder and calculated size this might force a new layout, with accompanying changes to the sidebar position. Once the browser has actual size information for the element, it will remember this size when the element scrolls offscreen again, and use the remembered size for layout calculations instead of the placeholder value. The benefit is that the browser does not need to repeatedly render the element contents to calculate its size and is especially useful when the contents are complex or depend on network resources or JavaScript. #### HTML ```html <div id="container"> <div id="auto-length-note"> <p> Your browser does not support <code>contain-intrinsic-size: auto &lt;length&gt;</code>. </p> </div> <div class="auto-length"> <p>Item one</p> </div> <div class="auto-length"> <p>Item two</p> </div> <div class="auto-length large-intrinsic-size"> <p class="small">Item three</p> </div> <div class="auto-length large-intrinsic-size"> <p class="small">Item four</p> </div> <div id="auto-none-note"> <p> Your browser does not support <code>contain-intrinsic-size: auto none</code>. </p> </div> <div class="auto-length none"> <p>Item five</p> </div> <div class="auto-length none"> <p>Item six</p> </div> </div> ``` #### CSS ```css hidden div, p { padding: 1rem; margin-bottom: 1rem; font-size: 2rem; font-family: sans-serif; } code { background-color: lightgray; padding: 0.25rem; border-radius: 0.25rem; } #container { width: 90%; height: 80%; } .auto-length, .auto-length.none { display: none; } #auto-length-note, #auto-none-note { display: block; padding: 0; } #auto-length-note p, #auto-none-note p { padding: 0.5rem; width: 100%; height: max-content; font-size: 1rem; line-height: 1.5rem; background-color: tomato; } @supports (contain-intrinsic-size: auto none) { .auto-length.none { display: block; } #auto-none-note { display: none; } } @supports (contain-intrinsic-size: auto 500px) { .auto-length { display: block; } #auto-length-note { display: none; } } ``` ```css p { height: 500px; width: 500px; border: 4px dotted; background: lightblue; } .auto-length { content-visibility: auto; contain-intrinsic-size: auto 500px; background-color: linen; outline: 4px dotted blue; } .large-intrinsic-size { /* Setting an inaccurate intrinsic size for the element */ contain-intrinsic-size: auto 5000px; background-color: lightgray; outline: 4px dotted red; } .small { /* This element is a lot smaller than expected */ height: 100px; width: 100px; } .none { background-color: papayawhip; contain-intrinsic-size: auto none; outline: 4px dotted red; } ``` #### Result - The first two boxes have an intrinsic size that matches their actual size, so as they flow into view, the layout is recalculated but we see no change in the scrollbar or the scroll position. - The third and fourth boxes have a huge intrinsic size, so the initial layout that the browser calculated is far too big, and we've made these boxes smaller so that it's obvious when you've reached a point that forces a drastic layout change. When the third and fourth boxes scroll into view, the size is recalculated, making the box and its parent less tall. The effect is that the scroller jumps down the page (we've effectively scrolled further through the box than we'd estimated) and the scroller is longer, because the entire page is less tall than we'd estimated. - The last boxes have `auto none`, so they have zero estimated size. When they scroll into view the size of the element and its parent are recalculated to be much larger, so the scroller decreases in size and moves up the bar. After scrolling all the way to the bottom you can subsequently scroll up and down smoothly, because using `content-visibility: auto` saves the actual rendered size of the element for next time it is displayed. {{EmbedLiveSample('Using_auto_value_pairs_for_intrinsic_size', 800, 400)}} ### Setting the intrinsic size This example provides selection lists that can be used to modify `contain-intrinsic-size`, `content-visibility` and `contain` on an element in order to observe the effect of the different settings. #### CSS ```css #contained_element { border: 2px solid green; width: 120px; } .child_element { border: 1px solid red; background: blue; height: 50px; width: 150px; } ``` #### JavaScript The code below adds styles to, and removes styles from, the containing element based on the selected options. ```js const containedElement = document.querySelector("#contained_element"); const intrinsicSizeSelector = document.querySelector( "#contain_intrinsic_size_selector", ); const containSelector = document.querySelector("#contain_selector"); const contentVisibilitySelector = document.querySelector( "#content_visibility_selector", ); containedElement.style["contain-intrinsic-size"] = intrinsicSizeSelector.options[intrinsicSizeSelector.selectedIndex].text; containedElement.style["contain"] = containSelector.options[containSelector.selectedIndex].text; containedElement.style["content-visibility"] = contentVisibilitySelector.options[ contentVisibilitySelector.selectedIndex ].text; intrinsicSizeSelector.addEventListener("change", () => { containedElement.style["contain-intrinsic-size"] = intrinsicSizeSelector.options[intrinsicSizeSelector.selectedIndex].text; }); containSelector.addEventListener("change", () => { containedElement.style["contain"] = containSelector.options[containSelector.selectedIndex].text; }); contentVisibilitySelector.addEventListener("change", () => { containedElement.style["content-visibility"] = contentVisibilitySelector.options[ contentVisibilitySelector.selectedIndex ].text; }); ``` #### HTML The HTML defines two buttons, a container element that is subject to containment via the `content-visibility` property. ```html <p> <label for="contain_intrinsic_size_selector">contain-intrinsic-size:</label> <select id="contain_intrinsic_size_selector"> <option>none</option> <option>40px 130px</option> <option>auto 40px auto 130px</option></select >;<br /> <label for="contain_selector">contain:</label> <select id="contain_selector"> <option>none</option> <option>size</option> <option>strict</option></select >;<br /> <label for="content_visibility_selector">content-visibility:</label> <select id="content_visibility_selector"> <option>visible</option> <option>auto</option> <option>hidden</option></select >; </p> <div id="contained_element"> <div class="child_element"></div> </div> ``` #### Result Use the selectors to apply the given styles to the containing `div` element. Note that when `content-visibility` is `visible` or `auto`, changing `contain-intrinsic-size` makes no difference. However if the content is hidden, having a `contain-intrinsic-size` of `none` collapses the parent element as though its child element had no size. {{EmbedLiveSample('Setting the intrinsic size', '100%', 170)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [content-visibility: the new CSS property that boosts your rendering performance](https://web.dev/articles/content-visibility) (web.dev) - {{CSSxRef("contain-intrinsic-block-size")}} - {{CSSxRef("contain-intrinsic-inline-size")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_shadow_parts/index.md
--- title: CSS shadow parts slug: Web/CSS/CSS_shadow_parts page-type: css-module spec-urls: https://drafts.csswg.org/css-shadow-parts/ --- {{CSSRef}} The **CSS shadow parts** module defines the {{CSSXref("::part", "::part()")}} pseudo-element that can be set on a [shadow host](/en-US/docs/Glossary/Shadow_tree). Using this pseudo-element, you can enable shadow hosts to expose the selected element in the shadow tree to the outside page for styling purposes. By default, elements in a shadow tree can be styled only within their respective shadow roots. The CSS shadow parts module enables including a [`part`](/en-US/docs/Web/HTML/Global_attributes#part) attribute on {{HTMLElement("template")}} descendants that make up the custom element, exposing the shadow tree node to external styling via the `::part()` pseudo-element. ## Reference ### Selectors - {{CSSXref("::part", "::part()")}} ### HTML attributes - [`part`](/en-US/docs/Web/HTML/Global_attributes#part) - [`exportparts`](/en-US/docs/Web/HTML/Global_attributes#exportparts) ### Definitions - {{glossary("Shadow tree")}} ## Guides - [CSS pseudo-elements](/en-US/docs/Web/CSS/Pseudo-elements) - : Alphabetical list of pseudo-elements defined by all the CSS specifications and WebVTT - [Web components](/en-US/docs/Web/API/Web_components) - : Overview of the different APIs that enable creating reusable custom elements or web components. ## Related concepts - HTML {{HTMLElement("template")}} element - HTML {{HTMLElement("slot")}} element - {{domxref("Element.part")}} property - {{domxref("Element.shadowRoot")}} property - {{domxref("Element.attachShadow()")}} method - {{domxref("ShadowRoot")}} interface - [CSS scoping](/en-US/docs/Web/CSS/CSS_scoping) module - {{CSSXref(":host")}} - {{CSSXref(":host_function", ":host()")}} - {{CSSXref(":host-context", ":host-context()")}} - {{CSSXref("::slotted")}} ## Specifications {{Specifications}} ## See also - [CSS pseudo elements](/en-US/docs/Web/CSS/CSS_pseudo-elements) module - [CSS selectors](/en-US/docs/Web/CSS/CSS_selectors) module - [Using shadow DOM](/en-US/docs/Web/API/Web_components/Using_shadow_DOM) - [Templates: Styling outside of the current scope](https://web.dev/learn/html/template/#styling_outside_of_the_current_scope) on web.dev (2023)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/pseudo-classes/index.md
--- title: Pseudo-classes slug: Web/CSS/Pseudo-classes page-type: landing-page spec-urls: - https://html.spec.whatwg.org/multipage/#pseudo-classes - https://drafts.csswg.org/selectors/ - https://drafts.csswg.org/css-ui/ --- {{CSSRef}} A [CSS](/en-US/docs/Web/CSS) **_pseudo-class_** is a keyword added to a selector that specifies a special state of the selected element(s). For example, the pseudo-class {{CSSxRef(":hover")}} can be used to select a button when a user's pointer hovers over the button and this selected button can then be styled. ```css /* Any button over which the user's pointer is hovering */ button:hover { color: blue; } ``` A pseudo-class consists of a colon (`:`) followed by the pseudo-class name (e.g., `:hover`). A functional pseudo-class also contains a pair of parentheses to define the arguments (e.g., `:dir()`). The element that a pseudo-class is attached to is defined as an _anchor element_ (e.g., `button` in case `button:hover`). Pseudo-classes let you apply a style to an element not only in relation to the content of the document tree, but also in relation to external factors like the history of the navigator ({{CSSxRef(":visited")}}, for example), the status of its content (like {{CSSxRef(":checked")}} on certain form elements), or the position of the mouse (like {{CSSxRef(":hover")}}, which lets you know if the mouse is over an element or not). > **Note:** In contrast to pseudo-classes, [pseudo-elements](/en-US/docs/Web/CSS/Pseudo-elements) can be used to style a _specific part_ of an element. ## Element display state pseudo-classes These pseudo-classes enable the selection of elements based on their display states. - {{CSSxRef(":fullscreen")}} - : Matches an element that is currently in fullscreen mode. - {{CSSxRef(":modal")}} - : Matches an element that is in a state in which it excludes all interaction with elements outside it until the interaction has been dismissed. - {{CSSxRef(":picture-in-picture")}} - : Matches an element that is currently in picture-in-picture mode. ## Input pseudo-classes These pseudo-classes relate to form elements, and enable selecting elements based on HTML attributes and the state that the field is in before and after interaction. - {{CSSxRef(":autofill")}} - : Matches when an {{htmlelement("input")}} has been autofilled by the browser. - {{CSSxRef(":enabled")}} - : Represents a user interface element that is in an enabled state. - {{CSSxRef(":disabled")}} - : Represents a user interface element that is in a disabled state. - {{CSSxRef(":read-only")}} - : Represents any element that cannot be changed by the user. - {{CSSxRef(":read-write")}} - : Represents any element that is user-editable. - {{CSSxRef(":placeholder-shown")}} - : Matches an input element that is displaying placeholder text. For example, it will match the `placeholder` attribute in the {{htmlelement("input")}} and {{htmlelement("textarea")}} elements. - {{CSSxRef(":default")}} - : Matches one or more UI elements that are the default among a set of elements. - {{CSSxRef(":checked")}} - : Matches when elements such as checkboxes and radio buttons are toggled on. - {{CSSxRef(":indeterminate")}} - : Matches UI elements when they are in an indeterminate state. - {{CSSxRef(":blank")}} - : Matches a user-input element which is empty, containing an empty string or other null input. - {{CSSxRef(":valid")}} - : Matches an element with valid contents. For example, an input element with the type 'email' that contains a validly formed email address or an empty value if the control is not required. - {{CSSxRef(":invalid")}} - : Matches an element with invalid contents. For example, an input element with type 'email' with a name entered. - {{CSSxRef(":in-range")}} - : Applies to elements with range limitations. For example, a slider control when the selected value is in the allowed range. - {{CSSxRef(":out-of-range")}} - : Applies to elements with range limitations. For example, a slider control when the selected value is outside the allowed range. - {{CSSxRef(":required")}} - : Matches when a form element is required. - {{CSSxRef(":optional")}} - : Matches when a form element is optional. - {{CSSxRef(":user-valid")}} - : Represents an element with correct input, but only when the user has interacted with it. - {{CSSxRef(":user-invalid")}} - : Represents an element with incorrect input, but only when the user has interacted with it. ## Linguistic pseudo-classes These pseudo-classes reflect the document language and enable the selection of elements based on language or script direction. - {{CSSxRef(":dir", ":dir()")}} - : The directionality pseudo-class selects an element based on its directionality as determined by the document language. - {{CSSxRef(":lang", ":lang()")}} - : Select an element based on its content language. ## Location pseudo-classes These pseudo-classes relate to links, and to targeted elements within the current document. - {{CSSxRef(":any-link")}} - : Matches an element if the element would match either {{CSSxRef(":link")}} or {{CSSxRef(":visited")}}. - {{CSSxRef(":link")}} - : Matches links that have not yet been visited. - {{CSSxRef(":visited")}} - : Matches links that have been visited. - {{CSSxRef(":local-link")}} - : Matches links whose absolute URL is the same as the target URL. For example, anchor links to the same page. - {{CSSxRef(":target")}} - : Matches the element which is the target of the document URL. - {{CSSxRef(":target-within")}} - : Matches elements which are the target of the document URL, but also elements which have a descendant which is the target of the document URL. - {{CSSxRef(":scope")}} - : Represents elements that are a reference point for selectors to match against. ## Resource state pseudo-classes These pseudo-classes apply to media that is capable of being in a state where it would be described as playing, such as a video. - {{CSSxRef(":playing")}} - : Represents a media element that is capable of playing when that element is playing. - {{CSSxRef(":paused")}} - : Represents a media element that is capable of playing when that element is paused. ## Time-dimensional pseudo-classes These pseudo-classes apply when viewing something which has timing, such as a [WebVTT](/en-US/docs/Web/API/WebVTT_API) caption track. - {{CSSxRef(":current")}} - : Represents the element or ancestor of the element that is being displayed. - {{CSSxRef(":past")}} - : Represents an element that occurs entirely before the {{CSSxRef(":current")}} element. - {{CSSxRef(":future")}} - : Represents an element that occurs entirely after the {{CSSxRef(":current")}} element. ## Tree-structural pseudo-classes These pseudo-classes relate to the location of an element within the document tree. - {{CSSxRef(":root")}} - : Represents an element that is the root of the document. In HTML this is usually the `<html>` element. - {{CSSxRef(":empty")}} - : Represents an element with no children other than white-space characters. - {{CSSxRef(":nth-child")}} - : Uses `An+B` notation to select elements from a list of sibling elements. - {{CSSxRef(":nth-last-child")}} - : Uses `An+B` notation to select elements from a list of sibling elements, counting backwards from the end of the list. - {{CSSxRef(":first-child")}} - : Matches an element that is the first of its siblings. - {{CSSxRef(":last-child")}} - : Matches an element that is the last of its siblings. - {{CSSxRef(":only-child")}} - : Matches an element that has no siblings. For example, a list item with no other list items in that list. - {{CSSxRef(":nth-of-type")}} - : Uses `An+B` notation to select elements from a list of sibling elements that match a certain type from a list of sibling elements. - {{CSSxRef(":nth-last-of-type")}} - : Uses `An+B` notation to select elements from a list of sibling elements that match a certain type from a list of sibling elements counting backwards from the end of the list. - {{CSSxRef(":first-of-type")}} - : Matches an element that is the first of its siblings, and also matches a certain type selector. - {{CSSxRef(":last-of-type")}} - : Matches an element that is the last of its siblings, and also matches a certain type selector. - {{CSSxRef(":only-of-type")}} - : Matches an element that has no siblings of the chosen type selector. ## User action pseudo-classes These pseudo-classes require some interaction by the user in order for them to apply, such as holding a mouse pointer over an element. - {{CSSxRef(":hover")}} - : Matches when a user designates an item with a pointing device, such as holding the mouse pointer over the item. - {{CSSxRef(":active")}} - : Matches when an item is being activated by the user. For example, when the item is clicked on. - {{CSSxRef(":focus")}} - : Matches when an element has focus. - {{CSSxRef(":focus-visible")}} - : Matches when an element has focus and the user agent identifies that the element should be visibly focused. - {{CSSxRef(":focus-within")}} - : Matches an element to which {{CSSxRef(":focus")}} applies, plus any element that has a descendant to which {{CSSxRef(":focus")}} applies. ## Functional pseudo-classes These pseudo-classes accept a [selector list](/en-US/docs/Web/CSS/Selector_list#selector_list) or [forgiving selector list](/en-US/docs/Web/CSS/Selector_list#forgiving_selector_list) as a parameter. - [`:is()`](/en-US/docs/Web/CSS/:is) - : The matches-any pseudo-class matches any element that matches any of the selectors in the list provided. The list is forgiving. - [`:not()`](/en-US/docs/Web/CSS/:not) - : The negation, or matches-none, pseudo-class represents any element that is not represented by its argument. - [`:where()`](/en-US/docs/Web/CSS/:where) - : The specificity-adjustment pseudo-class matches any element that matches any of the selectors in the list provided without adding any specificity weight. The list is forgiving. - [`:has()`](/en-US/docs/Web/CSS/:has) - : The relational pseudo-class represents an element if any of the relative selectors match when anchored against the attached element. ## Syntax ```css selector:pseudo-class { property: value; } ``` Like regular classes, you can chain together as many pseudo-classes as you want in a selector. ## Alphabetical index Pseudo-classes defined by a set of CSS specifications include the following: A - {{CSSxRef(":active")}} - {{CSSxRef(":any-link")}} - {{CSSxRef(":autofill")}} B - {{CSSxRef(":blank")}} {{Experimental_Inline}} C - {{CSSxRef(":checked")}} - {{CSSxRef(":current")}} {{Experimental_Inline}} D - {{CSSxRef(":default")}} - {{CSSxRef(":defined")}} - {{CSSxRef(":dir", ":dir()")}} {{Experimental_Inline}} - {{CSSxRef(":disabled")}} E - {{CSSxRef(":empty")}} - {{CSSxRef(":enabled")}} F - {{CSSxRef(":first")}} - {{CSSxRef(":first-child")}} - {{CSSxRef(":first-of-type")}} - {{CSSxRef(":focus")}} - {{CSSxRef(":focus-visible")}} - {{CSSxRef(":focus-within")}} - {{CSSxRef(":fullscreen")}} - {{CSSxRef(":future")}} {{Experimental_Inline}} H - {{CSSxRef(":has", ":has()")}} {{Experimental_Inline}} - {{CSSxRef(":host")}} - {{CSSxRef(":host", ":host()")}} - {{CSSxRef(":host-context", ":host-context()")}} {{Experimental_Inline}} - {{CSSxRef(":hover")}} I - {{CSSxRef(":indeterminate")}} - {{CSSxRef(":in-range")}} - {{CSSxRef(":invalid")}} - {{CSSxRef(":is", ":is()")}} L - {{CSSxRef(":lang", ":lang()")}} - {{CSSxRef(":last-child")}} - {{CSSxRef(":last-of-type")}} - {{CSSxRef(":left")}} - {{CSSxRef(":link")}} - {{CSSxRef(":local-link")}} {{Experimental_Inline}} M - {{CSSxRef(":modal")}} N - {{CSSxRef(":not", ":not()")}} - {{CSSxRef(":nth-child", ":nth-child()")}} - {{CSSxRef(":nth-last-child", ":nth-last-child()")}} - {{CSSxRef(":nth-last-of-type", ":nth-last-of-type()")}} - {{CSSxRef(":nth-of-type", ":nth-of-type()")}} O - {{CSSxRef(":only-child")}} - {{CSSxRef(":only-of-type")}} - {{CSSxRef(":optional")}} - {{CSSxRef(":out-of-range")}} P - {{CSSxRef(":past")}} {{Experimental_Inline}} - {{CSSxRef(":paused")}} - {{CSSxRef(":picture-in-picture")}} - {{CSSxRef(":placeholder-shown")}} - {{CSSxRef(":playing")}} R - {{CSSxRef(":read-only")}} - {{CSSxRef(":read-write")}} - {{CSSxRef(":required")}} - {{CSSxRef(":right")}} - {{CSSxRef(":root")}} S - {{CSSxRef(":scope")}} - {{CSSxRef(":state", ":state()")}} {{Experimental_Inline}} T - {{CSSxRef(":target")}} - {{CSSxRef(":target-within")}} {{Experimental_Inline}} U - {{CSSxRef(":user-invalid")}} {{Experimental_Inline}} V - {{CSSxRef(":valid")}} - {{CSSxRef(":visited")}} W - {{CSSxRef(":where", ":where()")}} ## Specifications {{Specifications}} ## See also - [Pseudo-elements](/en-US/docs/Web/CSS/Pseudo-elements)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_text/index.md
--- title: CSS text slug: Web/CSS/CSS_text page-type: css-module spec-urls: - https://drafts.csswg.org/css-logical/ - https://drafts.csswg.org/css-text/ - https://drafts.csswg.org/css-text-4/ --- {{CSSRef}} The **CSS text** module defines how to perform text manipulation, like line breaking, justification and alignment, white space handling, and text transformation. ## Reference ### Properties - {{cssxref("hanging-punctuation")}} - {{cssxref("hyphenate-limit-chars")}} - {{cssxref("hyphens")}} - {{cssxref("letter-spacing")}} - {{cssxref("line-break")}} - {{cssxref("overflow-wrap")}} - {{cssxref("tab-size")}} - {{cssxref("text-align")}} - {{cssxref("text-align-last")}} - {{cssxref("text-indent")}} - {{cssxref("text-justify")}} - {{cssxref("text-size-adjust")}} - {{cssxref("text-transform")}} - {{cssxref("text-wrap")}} {{experimental_inline}} - {{cssxref("white-space")}} - {{cssxref("white-space-collapse")}} {{experimental_inline}} - {{cssxref("word-break")}} - {{cssxref("word-spacing")}} ## Specifications {{Specifications}}
0
data/mdn-content/files/en-us/web/css/css_text
data/mdn-content/files/en-us/web/css/css_text/wrapping_breaking_text/index.md
--- title: Wrapping and breaking text slug: Web/CSS/CSS_text/Wrapping_breaking_text page-type: guide --- {{CSSRef}} This guide explains the various ways in which overflowing text can be managed in CSS. ## What is overflowing text? In CSS, if you have an unbreakable string such as a very long word, by default it will overflow any container that is too small for it in the inline direction. We can see this happening in the example below: the long word is extending past the boundary of the box it is contained in. {{EmbedGHLiveSample("css-examples/css-text/inline-overflow.html", '100%', 420)}} CSS will display overflow in this way, because doing something else could cause data loss. In CSS data loss means that some of your content vanishes. So the initial value of {{cssxref("overflow")}} is `visible`, and we can see the overflowing text. It is generally better to be able to see overflow, even if it is messy. If things were to disappear or be cropped as would happen if `overflow` was set to `hidden` you might not spot it when previewing your site. Messy overflow is at least easy to spot, and in the worst case, your visitor will be able to see and read the content even if it looks a bit strange. In this next example, you can see what happens if `overflow` is set to `hidden`. {{EmbedGHLiveSample("css-examples/css-text/inline-overflow-hidden.html", '100%', 420)}} ## Finding the min-content size To find the minimum size of the box that will contain its contents with no overflows, set the {{cssxref("width")}} or {{cssxref("inline-size")}} property of the box to {{cssxref("min-content")}}. {{EmbedGHLiveSample("css-examples/css-text/min-content.html", '100%', 420)}} Using `min-content` is therefore one possibility for overflowing boxes. If it is possible to allow the box to grow to be the minimum size required for the content, but no bigger, using this keyword will give you that size. ## Breaking long words If the box needs to be a fixed size, or you are keen to ensure that long words can't overflow, then the {{cssxref("overflow-wrap")}} property can help. This property will break a word once it is too long to fit on a line by itself. {{EmbedGHLiveSample("css-examples/css-text/overflow-wrap.html", '100%', 660)}} > **Note:** The `overflow-wrap` property acts in the same way as the non-standard property `word-wrap`. The `word-wrap` property is now treated by browsers as an alias of the standard property. An alternative property to try is {{cssxref("word-break")}}. This property will break the word at the point it overflows. It will cause a break-even if placing the word onto a new line would allow it to display without breaking. In this next example, you can compare the difference between the two properties on the same string of text. {{EmbedGHLiveSample("css-examples/css-text/word-break.html", '100%', 700)}} This might be useful if you want to prevent a large gap from appearing if there is just enough space for the string. Or, where there is another element that you would not want the break to happen immediately after. In the example below there is a checkbox and label. Let's say, you want the label to break should it be too long for the box. However, you don't want it to break directly after the checkbox. {{EmbedGHLiveSample("css-examples/css-text/word-break-checkbox.html", '100%', 660)}} ## Adding hyphens To add hyphens when words are broken, use the CSS {{cssxref("hyphens")}} property. Using a value of `auto`, the browser is free to automatically break words at appropriate hyphenation points, following whatever rules it chooses. To have some control over the process, use a value of `manual`, then insert a hard or soft break character into the string. A hard break (`‐`) will always break, even if it is not necessary to do so. A soft break (`&shy;`) only breaks if breaking is needed. {{EmbedGHLiveSample("css-examples/css-text/hyphens.html", '100%', 600)}} You can also use the {{cssxref("hyphenate-character")}} property to use the string of your choice instead of the default hyphenation character at the end of the line (before the hyphenation line break) for the language. The `auto` value selects the correct value to mark a mid-word line break according to the typographic conventions of the current content language. CSS provides additional hyphenation control: the {{cssxref("hyphenate-limit-chars")}} property can be used to set the minimum word length that allows for hyphenation as well as the minimum number of characters before and after the hyphen. ## The `<wbr>` element If you know where you want a long string to break, then it is also possible to insert the HTML {{HTMLElement("wbr")}} element. This can be useful in cases such as displaying a long URL on a page. You can then add the property in order to break the string in sensible places that will make it easier to read. In the below example the text breaks in the location of the {{HTMLElement("wbr")}}. {{EmbedGHLiveSample("css-examples/css-text/wbr.html", '100%', 460)}} ## See also - The HTML {{HTMLElement("wbr")}} element - The CSS {{cssxref("word-break")}} property - The CSS {{cssxref("overflow-wrap")}} property - The CSS {{cssxref("white-space")}} property - The CSS {{cssxref("text-wrap")}} property - The CSS {{cssxref("hyphens")}} property - The CSS {{cssxref("hyphenate-character")}} property - The CSS {{cssxref("hyphenate-limit-chars")}} property - [Overflow and Data Loss in CSS](https://www.smashingmagazine.com/2019/09/overflow-data-loss-css/)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_marker/index.md
--- title: "::marker" slug: Web/CSS/::marker page-type: css-pseudo-element browser-compat: css.selectors.marker --- {{CSSRef}} The **`::marker`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) selects the marker box of a list item, which typically contains a bullet or number. It works on any element or pseudo-element set to [`display: list-item`](/en-US/docs/Web/CSS/display), such as the {{HTMLElement("li")}} and {{HTMLElement("summary")}} elements. {{EmbedInteractiveExample("pages/tabbed/pseudo-element-marker.html", "tabbed-shorter")}} ## Allowable properties The `::marker` pseudo-element supports a limited number of CSS properties, including: - All [font properties](/en-US/docs/Web/CSS/CSS_fonts) - The {{CSSxRef("white-space")}} property - {{CSSxRef("color")}} - {{CSSxRef("text-combine-upright")}}, {{CSSxRef("unicode-bidi")}}, and {{CSSxRef("direction")}} properties - The {{CSSxRef("content")}} property - All [animation](/en-US/docs/Web/CSS/CSS_animations#properties) and [transition](/en-US/docs/Web/CSS/CSS_transitions#properties) properties > **Note:** The specification states that additional CSS properties may be supported in the future. ## Syntax ```css ::marker { /* ... */ } ``` ## Examples ### HTML ```html <ul> <li>Peaches</li> <li>Apples</li> <li>Plums</li> </ul> ``` ### CSS ```css ul li::marker { color: red; font-size: 1.5em; } ``` ### Result {{EmbedLiveSample('Examples')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - HTML elements that have marker boxes by default: {{HTMLElement("ol")}}, {{HTMLElement("li")}}, {{HTMLElement("summary")}} - [CSS generated content](/en-US/docs/Web/CSS/CSS_generated_content) module - [CSS lists and counters](/en-US/docs/Web/CSS/CSS_lists) module - [CSS counter styles](/en-US/docs/Web/CSS/CSS_counter_styles) module
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/display-outside/index.md
--- title: <display-outside> slug: Web/CSS/display-outside page-type: css-type browser-compat: css.properties.display.display-outside --- {{CSSRef}} The `<display-outside>` keywords specify the element's outer {{CSSxRef("display")}} type, which is essentially its role in flow layout. These keywords are used as values of the `display` property, and can be used for legacy purposes as a single keyword, or as defined in the Level 3 specification alongside a value from the {{CSSxRef("&lt;display-inside&gt;")}} keywords. ## Syntax Valid `<display-outside>` values: - `block` - : The element generates a block element box, generating line breaks both before and after the element when in the normal flow. - `inline` - : The element generates one or more inline element boxes that do not generate line breaks before or after themselves. In normal flow, the next element will be on the same line if there is space. > **Note:** When browsers encounter a display property with only an **outer** `display` value (e.g., `display: block` or `display: inline`), the inner value defaults to `flow` (e.g., `display: block flow` and `display: inline flow`). > This is backwards-compatible with single-keyword syntax. ## Formal syntax {{csssyntax}} ## Examples In the following example, span elements (normally displayed as inline elements) are set to `display: block` and so break onto new lines and expand to fill their container in the inline dimension. ### HTML ```html <span>span 1</span> <span>span 2</span> ``` ### CSS ```css span { display: block; border: 1px solid rebeccapurple; } ``` ### Result {{EmbedLiveSample("Examples", 300, 60)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("display")}} - {{CSSxRef("&lt;display-inside&gt;")}} - {{CSSxRef("&lt;display-listitem&gt;")}} - {{CSSxRef("&lt;display-internal&gt;")}} - {{CSSxRef("&lt;display-box&gt;")}} - {{CSSxRef("&lt;display-legacy&gt;")}} - [Block and Inline layout in Normal Flow](/en-US/docs/Web/CSS/CSS_flow_layout/Block_and_inline_layout_in_normal_flow) - [Formatting Contexts explained](/en-US/docs/Web/CSS/CSS_flow_layout/Introduction_to_formatting_contexts)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/overflow-anchor/index.md
--- title: overflow-anchor slug: Web/CSS/overflow-anchor page-type: css-property browser-compat: css.properties.overflow-anchor --- {{CSSRef}} The **`overflow-anchor`** [CSS](/en-US/docs/Web/CSS) property provides a way to opt out of the browser's scroll anchoring behavior, which adjusts scroll position to minimize content shifts. Scroll anchoring behavior is enabled by default in any browser that supports it. Therefore, changing the value of this property is typically only required if you are experiencing problems with scroll anchoring in a document or part of a document and need to turn the behavior off. {{EmbedInteractiveExample("pages/css/overflow-anchor.html")}} ## Syntax ```css /* Keyword values */ overflow-anchor: auto; overflow-anchor: none; /* Global values */ overflow-anchor: inherit; overflow-anchor: initial; overflow-anchor: revert; overflow-anchor: revert-layer; overflow-anchor: unset; ``` ### Values - `auto` - : The element becomes a potential anchor when adjusting scroll position. - `none` - : The element won't be selected as a potential anchor. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Prevent scroll anchoring To prevent scroll anchoring in a document, use the `overflow-anchor` property. ```css * { overflow-anchor: none; } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Guide to scroll anchoring](/en-US/docs/Web/CSS/overflow-anchor/Guide_to_scroll_anchoring)
0
data/mdn-content/files/en-us/web/css/overflow-anchor
data/mdn-content/files/en-us/web/css/overflow-anchor/guide_to_scroll_anchoring/index.md
--- title: Guide to scroll anchoring slug: Web/CSS/overflow-anchor/Guide_to_scroll_anchoring page-type: guide browser-compat: css.properties.overflow-anchor --- {{CSSRef}} As a user of the web, you are probably familiar with the problem that scroll anchoring solves. You browse to a long page on a slow connection and begin to scroll to read the content; while you are busy reading, the part of the page you are looking at suddenly jumps. This has happened because large images or some other elements have just loaded further up in the content. Scroll anchoring is a browser feature that aims to solve this problem of content jumping, which happens if content loads in after the user has already scrolled to a new part of the document. ## How does it work? Scroll anchoring adjusts the scroll position to compensate for the changes outside of the viewport. This means that the point in the document the user is looking at remains in the viewport, which may mean their scroll position actually changes in terms of how _far_ they have moved through the document. ## How do I turn on scroll anchoring? You don't! The feature is enabled by default in supporting browsers. In most cases anchored scrolling is exactly what you want — content jumping is a poor experience for anyone. ## What if I need to debug it? If your page is not behaving well with scroll anchoring enabled, it is probably because some `scroll` event listener is not handling well the extra scrolling to compensate for the anchor node movement. You can check whether disabling scroll anchoring fixes the issue in Firefox by changing `layout.css.scroll-anchoring.enabled` to `false` in `about:config`. If it does, you can check what node is Firefox using as the anchor using the `layout.css.scroll-anchoring.highlight` switch. That will show a purple overlay on top of the anchor node. If one node doesn't seem appropriate to be an anchor, you can exclude it using {{cssxref("overflow-anchor")}}, as described below. ## What if I need to disable it? The specification provides a new property, {{cssxref("overflow-anchor")}}, which can be used to disable scroll anchoring on all or part of the document. It's essentially a way to opt out of the new behavior. The only possible values are `auto` or `none`: - `auto` is the initial value; as long as the user has a supported browser the scroll anchoring behavior will happen, and they should see fewer content jumps. - `none` means that you have explicitly opted the document, or part of the document, out of scroll anchoring. To opt out the entire document, you can set it on the {{htmlelement("body")}} element: ```css body { overflow-anchor: none; } ``` To opt out a certain part of the document use `overflow-anchor: none` on its container element: ```css .container { overflow-anchor: none; } ``` > **Note:** The specification details that once scroll anchoring has been opted out of, you cannot opt back into it from a child element. For example, if you opt out for the entire document, you will not be able to set `overflow-anchor: auto` elsewhere in the document to turn it back on for a subsection. ### Suppression triggers The specification also details some _suppression triggers_, which will disable scroll anchoring in places where it might be problematic. If any of the triggers happen on the anchor node, or an ancestor of it, anchoring is suppressed. These suppression triggers are changes to the computed value of any of the following properties: - {{cssxref("top")}}, {{cssxref("left")}}, {{cssxref("right")}}, or {{cssxref("bottom")}} - {{cssxref("margin")}} or {{cssxref("padding")}} - Any {{cssxref("width")}} or {{cssxref("height")}}-related properties - {{cssxref("transform")}} and the individual transform properties {{cssxref("translate")}}, {{cssxref("scale")}}, and {{cssxref("rotate")}} Additionally, {{cssxref("position")}} changes anywhere inside the scrolling box also disable scroll anchoring. > **Note:** In [Firefox bug 1584285](https://bugzil.la/1584285) the `layout.css.scroll-anchoring.suppressions.enabled` flag was added to Firefox Nightly in order to allow the disabling of these triggers. ## Further reading - [Explainer document on the WICG site](https://github.com/WICG/ScrollAnchoring/blob/master/explainer.md) - [Scroll anchoring for web developers on the Chromium blog](https://blog.chromium.org/2017/04/scroll-anchoring-for-web-developers.html) - [Implement a pin-to-bottom scrolling element using scroll anchoring](https://blog.eqrion.net/pin-to-bottom/) ## Browser compatibility {{Compat}} ### Compatibility notes If you need to test whether scroll anchoring is available in a browser, use [Feature Queries](/en-US/docs/Web/CSS/@supports) to test support for the `overflow-anchor` property.
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/mask-border-repeat/index.md
--- title: mask-border-repeat slug: Web/CSS/mask-border-repeat page-type: css-property browser-compat: css.properties.mask-border-repeat --- {{CSSRef}} The **`mask-border-repeat`** [CSS](/en-US/docs/Web/CSS) property sets how the [edge regions](/en-US/docs/Web/CSS/border-image-slice#edge-regions) of a source image are adjusted to fit the dimensions of an element's [mask border](/en-US/docs/Web/CSS/mask-border). ## Syntax ```css /* Keyword value */ mask-border-repeat: stretch; mask-border-repeat: repeat; mask-border-repeat: round; mask-border-repeat: space; /* top and bottom | left and right */ mask-border-repeat: round stretch; /* Global values */ mask-border-repeat: inherit; mask-border-repeat: initial; mask-border-repeat: revert; mask-border-repeat: revert-layer; mask-border-repeat: unset; ``` The `mask-border-repeat` property may be specified using one or two values chosen from the list of values below. - When **one** value is specified, it applies the same behavior on **all four sides**. - When **two** values are specified, the first applies to the **top and bottom**, the second to the **left and right**. ### Values - `stretch` - : The source image's edge regions are stretched to fill the gap between each border. - `repeat` - : The source image's edge regions are tiled (repeated) to fill the gap between each border. Tiles may be clipped to achieve the proper fit. - `round` - : The source image's edge regions are tiled (repeated) to fill the gap between each border. Tiles may be stretched to achieve the proper fit. - `space` - : The source image's edge regions are tiled (repeated) to fill the gap between each border. Extra space will be distributed in between tiles to achieve the proper fit. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Basic usage This property doesn't appear to be supported anywhere yet. When it eventually starts to be supported, it will serve to define how the border mask slice will repeat around the border — i.e. will it just repeat, or be scaled slightly so a whole number of slices fits, or be stretched so one slice fits? ```css mask-border-repeat: round; ``` Chromium-based browsers support an outdated version of this property — `mask-box-image-repeat` — with a prefix: ```css -webkit-mask-box-image-repeat: round; ``` > **Note:** The [`mask-border`](/en-US/docs/Web/CSS/mask-border) page features a working example (using the out-of-date prefixed border mask properties supported in Chromium), so you can get an idea of the effect. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("mask-border")}} - {{cssxref("mask-border-mode")}} - {{cssxref("mask-border-outset")}} - {{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/css_cascading_variables/index.md
--- title: CSS custom properties for cascading variables slug: Web/CSS/CSS_cascading_variables page-type: css-module spec-urls: https://drafts.csswg.org/css-variables/ --- {{CSSRef}} The **CSS custom properties for cascading variables** module adds support for cascading variables in CSS properties and lets you create custom properties to define these variables along with the mechanisms to use custom properties as the values for other CSS properties. When working with CSS, you often end up reusing common project-specific values such as widths that work well with your layout, or a set of colors for your color scheme. One way of managing repetition in stylesheets is to define a value once and use it many times in other places. Custom properties let you create and define custom variables that can be reused, simplifying complex or repetitive rules and making them easier to read and maintain. For example, `--dark-grey-text` and `--dark-background` are easier to understand than hexadecimal colors such as `#323831`, and the context of how you use them is more obvious, too. ## Custom properties in action To see how custom properties can be used, move the input slider left to right. ```html hidden <div class="container"> <div id="color-1">--hue</div> <div id="color-2">--hue + 10</div> <div id="color-3">--hue + 20</div> <div id="color-4">--hue + 30</div> <div id="color-5">--hue + 40</div> <div id="color-6">--hue + 50</div> <div id="color-7">--hue + 60</div> <div id="color-8">--hue + 70</div> </div> <input type="range" min="0" max="360" value="0" step="0.1" id="hue" /> ``` ```js hidden const hue = document.querySelector("#hue"); const updateHue = () => { document.documentElement.style.setProperty("--hue", hue.value); }; hue.addEventListener("input", updateHue); ``` ```css hidden .container { display: grid; font-family: sans-serif; color: white; gap: 0.5rem; grid-template-columns: repeat(4, 1fr); margin-bottom: 1rem; } .container div { border-radius: 0.5rem; padding: 1rem; } input { width: 100%; margin: 0; } :root { --hue: 0; } #color-1 { background-color: hsl(var(--hue) 50% 50%); } #color-2 { background-color: hsl(calc(var(--hue) + 10) 50% 50%); } #color-3 { background-color: hsl(calc(var(--hue) + 20) 50% 50%); } #color-4 { background-color: hsl(calc(var(--hue) + 30) 50% 50%); } #color-5 { background-color: hsl(calc(var(--hue) + 40) 50% 50%); } #color-6 { background-color: hsl(calc(var(--hue) + 50) 50% 50%); } #color-7 { background-color: hsl(calc(var(--hue) + 60) 50% 50%); } #color-8 { background-color: hsl(calc(var(--hue) + 70) 50% 50%); } ``` {{EmbedLiveSample("Custom properties in action",600,160)}} In these color swatches, the {{cssxref("background-color")}} is set using the {{cssxref("color_value/hsl", "hsl()")}} {{cssxref("&lt;color&gt;")}} function as `hsl(var(--hue) 50% 50%)`. Each color swatch increments the {{cssxref("hue")}} value by 10 degrees like `calc(var(--hue) + 10)`, `calc(var(--hue) + 20)` etc. As the slider's value changes from 0 up to 360, the value of the `--hue` [custom property](/en-US/docs/Web/CSS/--*) is updated using {{cssxref("calc")}}, and the background color of each box inside the grid is updated, also. ## Reference ### Properties - {{cssxref("--*")}} ### Functions - {{cssxref("var")}} ## Guides - [Using CSS custom properties (variables)](/en-US/docs/Web/CSS/Using_CSS_custom_properties) - : Explains how to use custom properties in CSS and JavaScript, with hints on handling undefined and invalid values, fallbacks, and inheritance. - [Invalid custom properties](/en-US/docs/Web/CSS/CSS_syntax/Error_handling#invalid_custom_properties) - : Explains how browsers handle property values when a custom property's value is an invalid data type for that property. ## Related concepts - [CSS Properties and Values API](/en-US/docs/Web/CSS/CSS_properties_and_values_API) module - [`@property`](/en-US/docs/Web/CSS/@property) at-rule - [`CSS.registerProperty()`](/en-US/docs/Web/API/CSS/registerProperty_static) method ## Specifications {{Specifications}} ## See also - [CSS cascade and inheritance](/en-US/docs/Web/CSS/CSS_cascade) module - [CSS `env()`](/en-US/docs/Web/CSS/env) function - [CSS `calc()`](/en-US/docs/Web/CSS/calc) function - [`getPropertyValue()`](/en-US/docs/Web/API/CSSStyleDeclaration/getPropertyValue) method
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_required/index.md
--- title: ":required" slug: Web/CSS/:required page-type: css-pseudo-class browser-compat: css.selectors.required --- {{CSSRef}} The **`:required`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents any {{HTMLElement("input")}}, {{HTMLElement("select")}}, or {{HTMLElement("textarea")}} element that has the [`required`](/en-US/docs/Web/HTML/Element/input#required) attribute set on it. {{EmbedInteractiveExample("pages/tabbed/pseudo-class-required.html", "tabbed-standard")}} This pseudo-class is useful for highlighting fields that must have valid data before a form can be submitted. > **Note:** The {{cssxref(":optional")}} pseudo-class selects _optional_ form fields. ## Syntax ```css :required { /* ... */ } ``` ## Examples ### The required field has a red border #### HTML ```html <form> <div class="field"> <label for="url_input">Enter a URL:</label> <input type="url" id="url_input" /> </div> <div class="field"> <label for="email_input">Enter an email address:</label> <input type="email" id="email_input" required /> </div> </form> ``` #### CSS ```css label { display: block; margin: 1px; padding: 1px; } .field { margin: 1px; padding: 1px; } input:required { border-color: #800000; border-width: 3px; } input:required:invalid { border-color: #c00000; } ``` #### Result {{EmbedLiveSample('Examples', 600, 120)}} ## Accessibility concerns Mandatory {{htmlelement("input")}}s should have the [`required`](/en-US/docs/Web/HTML/Element/input#required) attribute applied to them. This will ensure that people navigating with the aid of assistive technology such as a screen reader will be able to understand which inputs need valid content to ensure a successful submission. If the form also contains [optional](/en-US/docs/Web/CSS/:optional) inputs, required inputs should be indicated visually using a treatment that does not rely solely on color to convey meaning. Typically, descriptive text and/or an icon are used. - [MDN Understanding WCAG, Guideline 3.3 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Understandable#guideline_3.3_%e2%80%94_input_assistance_help_users_avoid_and_correct_mistakes) - [Understanding Success Criterion 3.3.2 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/minimize-error-cues.html) ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Other validation-related pseudo-classes: {{ cssxref(":optional") }}, {{ cssxref(":invalid") }}, {{ cssxref(":valid") }} - [Form data validation](/en-US/docs/Learn/Forms/Form_validation)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/scale/index.md
--- title: scale slug: Web/CSS/scale page-type: css-property browser-compat: css.properties.scale --- {{CSSRef}} The **`scale`** [CSS](/en-US/docs/Web/CSS) property allows you to specify scale transforms individually and independently of the {{CSSxRef("transform")}} property. This maps better to typical user interface usage, and saves having to remember the exact order of transform functions to specify in the `transform` value. {{EmbedInteractiveExample("pages/css/scale.html")}} ## Syntax ```css /* Keyword values */ scale: none; /* Single values */ /* values of more than 1 or 100% make the element grow */ scale: 2; /* values of less than 1 or 100% make the element shrink */ scale: 50%; /* Two values */ scale: 2 0.5; /* Three values */ scale: 200% 50% 200%; /* Global values */ scale: inherit; scale: initial; scale: revert; scale: revert-layer; scale: unset; ``` ### Values - Single value - : A {{cssxref("&lt;number&gt;")}} or {{cssxref("&lt;percentage&gt;")}} specifying a scale factor to make the affected element scale by the same factor along both the X and Y axes. Equivalent to a `scale()` (2D scaling) function with a single value specified. - Two values - : Two {{cssxref("&lt;number&gt;")}} or {{cssxref("&lt;percentage&gt;")}} values that specify the X and Y axis scaling values (respectively) of a 2D scale. Equivalent to a `scale()` (2D scaling) function with two values specified. - Three values - : Three {{cssxref("&lt;number&gt;")}} or {{cssxref("&lt;percentage&gt;")}} values that specify the X, Y, and Z axis scaling values (respectively) of a 3D scale. Equivalent to a `scale3d()` (3D scaling) function. - `none` - : Specifies that no scaling should be applied. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Scaling an element on hover The following example shows how to scale an element on hover. Two boxes are shown, one with a single `scale` value which scales the element along both axes. The second box has two `scale` values which scales the element along the X and Y axes independently. #### HTML ```html <div class="box" id="box1">single value</div> <div class="box" id="box2">two values</div> ``` #### CSS ```css .box { float: left; margin: 1em; width: 7em; line-height: 7em; text-align: center; transition: 0.5s ease-in-out; border: 3px dotted; } #box1:hover { scale: 1.25; } #box2:hover { scale: 1.25 0.75; } ``` #### Result {{EmbedLiveSample("Scaling_an_element_on_hover", "100%", 150)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref('translate')}} - {{cssxref('rotate')}} - {{cssxref('transform')}} Note: skew is not an independent transform value
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/absolute-size/index.md
--- title: <absolute-size> slug: Web/CSS/absolute-size page-type: css-type spec-urls: https://drafts.csswg.org/css-fonts/#valdef-font-size-absolute-size --- {{CSSRef}} The **`<absolute-size>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) describes the absolute size keywords. This data type is used in the {{cssxref("font")}} shorthand and {{cssxref("font-size")}} properties. The font size keywords are mapped to the deprecated HTML `size` attribute. See the [HTML size attribute](#html_size_attribute) section below). ## Syntax ```plain <absolute-size> = xx-small | x-small | small | medium | large | x-large | xx-large | xxx-large ``` ### Values The `<absolute-size>` data type is defined using a keyword value chosen from the list below. - `xx-small` - : An absolute size 60% the size of `medium`. Mapped to the deprecated `size="1"`. - `x-small` - : An absolute size 75% the size of `medium`. - `small` - : An absolute size 89% the size of `medium`. Mapped to the deprecated `size="2"`. - `medium` - : A user's preferred font size. This value is used as the reference middle value. Mapped to `size="3"`. - `large` - : An absolute size 20% larger than `medium`. Mapped to the deprecated `size="4"`. - `x-large` - : An absolute size 50% larger than `medium`. Mapped to the deprecated `size="5"`. - `xx-large` - : An absolute size twice the size of `medium`. Mapped to the deprecated `size="6"`. - `xxx-large` - : An absolute size three times the size of `medium`. Mapped to the deprecated `size="7"`. ## Description Each `<absolute-size>` keyword value is sized relative to the `medium` size and the individual device's characteristics, such as device resolution. User agents maintain a table of font sizes for each font, with the `<absolute-size>` keywords being the index. In CSS1 (1996), the scaling factor between adjacent keyword value indexes was 1.5, which was too large. In CSS2 (1998), the scaling factor between adjacent keyword value indexes was 1.2, which created issues for the small values. As a single fixed ratio between adjacent absolute-size keywords was found to be problematic, there is no longer a fixed ratio recommendation. The only recommendation to preserve readability is that the smallest font size should not be less than `9px`. For each `<absolute-size>` keyword value, the following table lists the scaling factor, mapping to [`<h1>` to `<h6>`](/en-US/docs/Web/HTML/Element/Heading_Elements) headings, and mapping to the deprecated [HTML `size` attribute](#html_size_attribute). | `<absolute-size>` | xx-small | x-small | small | medium | large | x-large | xx-large | xxx-large | | --------------------- | -------- | ------- | ----- | ------ | ----- | ------- | -------- | --------- | | scaling factor | 3/5 | 3/4 | 8/9 | 1 | 6/5 | 3/2 | 2/1 | 3/1 | | HTML headings | h6 | | h5 | h4 | h3 | h2 | h1 | | | HTML `size` attribute | 1 | | 2 | 3 | 4 | 5 | 6 | 7 | ### HTML size attribute The `size` attribute to set a font's size in HTML is deprecated. The attribute value was either an integer between `1` and `7` or a relative value. Relative values were an integer preceded by `+` or `-` to increase or decrease the font size, respectively. A value of `+1` meant increasing the `size` by one and `-2` meant decreasing the size by two, with the computed value clamped at a minimum of `1` and a maximum computed value of `7`. ## Examples ### Comparing the keyword values ```html <ul> <li class="xx-small">font-size: xx-small;</li> <li class="x-small">font-size: x-small;</li> <li class="small">font-size: small;</li> <li class="medium">font-size: medium;</li> <li class="large">font-size: large;</li> <li class="x-large">font-size: x-large;</li> <li class="xx-large">font-size: xx-large;</li> <li class="xxx-large">font-size: xxx-large;</li> </ul> ``` ```css li { margin-bottom: 0.3em; } .xx-small { font-size: xx-small; } .x-small { font-size: x-small; } .small { font-size: small; } .medium { font-size: medium; } .large { font-size: large; } .x-large { font-size: x-large; } .xx-large { font-size: xx-large; } .xxx-large { font-size: xxx-large; } ``` #### Result {{EmbedLiveSample('Comparing the keyword values', '100%', 400)}} ## Specifications {{Specifications}} ## See also - CSS {{cssxref("relative-size")}} data type - CSS {{cssxref("font")}} and {{cssxref("font-size")}} properties - [CSS fonts](/en-US/docs/Web/CSS/CSS_fonts) module
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_types/index.md
--- title: CSS data types slug: Web/CSS/CSS_Types page-type: guide spec-urls: https://drafts.csswg.org/css-values/ --- {{CSSRef}} **CSS data types** define typical values (including keywords and units) accepted by CSS properties and functions. They are a special kind of [component value type](https://www.w3.org/TR/css3-values/#component-types). The most commonly-used types are defined in the [CSS Values and Units](/en-US/docs/Web/CSS/CSS_Values_and_Units) specification. This specification also defines [functional notations](/en-US/docs/Web/CSS/CSS_Functions), which allow for more complex types or processing. Other types are defined in the specifications to which they apply. Below you will find a reference to the types that you are most likely to come across, however it is not a comprehensive reference for all types defined in every CSS specification. ## Syntax ```css selector { property: <unit-data-type>; } ``` In formal CSS syntax, data types are denoted by a keyword placed between the inequality signs "`<`" and "`>`". ## Textual data types These types include keywords and identifiers as well as strings, and URLs. - Pre-defined keywords - : Keywords with a pre-defined meaning, for example, the value of `collapse` for the {{cssxref("border-collapse")}} property. - CSS-wide keywords - : All properties, including custom properties, accept the CSS-wide keywords: - {{CSSXref("initial")}} - : The value specified as the property's initial value. - {{CSSXref("inherit")}} - : The computed value of the property on the element's parent. - {{CSSXref("revert")}} - : Rolls back the cascade to the value of the earlier origin. - {{CSSXref("unset")}} - : Acts as `inherit` or `initial` depending on whether the property is inherited or not. - {{cssxref("&lt;custom-ident&gt;")}} - : A user-defined identifier, for example the name assigned using the {{cssxref("grid-area")}} property. - {{cssxref("&lt;dashed-ident&gt;")}} - : A `<custom-ident>` with the additional restriction that it must start with two dashes, for example, with [CSS Custom Properties](/en-US/docs/Web/CSS/Using_CSS_custom_properties). - {{cssxref("&lt;string&gt;")}} - : A quoted string, such as used for a value of the {{cssxref("content")}} property. - {{cssxref("&lt;url&gt;", "url()")}} - : A pointer to a resource, for example as the value of {{cssxref("background-image")}}. ## Numeric data types These data types are used to indicate quantities, indexes, and positions. The majority of these are defined in the Values and Units specification, however additional types are described in other specifications where they are specific to that specification alone — for example the `fr` unit in [CSS Grid Layout](https://www.w3.org/TR/css-grid-1/#fr-unit). - {{cssxref("&lt;integer&gt;")}} - : One or more decimal units 0 through 9. - {{cssxref("&lt;number&gt;")}} - : Real numbers which may also have a fractional component, for example 1 or 1.34. - {{cssxref("&lt;dimension&gt;")}} - : A number with a unit attached to it, for example 23px or 15em. - {{cssxref("&lt;percentage&gt;")}} - : A number with a percentage sign attached to it, for example 10%. - {{cssxref("&lt;ratio&gt;")}} - : A ratio, written with the syntax `<number> / <number>`. - {{cssxref("&lt;flex&gt;")}} - : A flexible length introduced for [CSS Grid Layout](/en-US/docs/Web/CSS/CSS_grid_layout), written as a `<number>` with the `fr` unit attached and used for grid track sizing. ## Quantities These types are used to specify distance and other quantities. - {{cssxref("&lt;length&gt;")}} - : Lengths are a `<dimension>` and refer to distances. - {{cssxref("&lt;angle&gt;")}} - : Angles are used in properties such as {{cssxref("gradient/linear-gradient", "linear-gradient()")}} and are a `<dimension>` with one of `deg`, `grad`, `rad`, or `turn` units attached. - {{cssxref("&lt;time&gt;")}} - : Duration units are a `<dimension>` with an `s` or `ms` unit. - {{cssxref("&lt;frequency&gt;")}} - : Frequencies are a `<dimension>` with a `Hz` or `kHz` unit attached. - {{cssxref("&lt;resolution&gt;")}} - : Is a `<dimension>` with a unit identifier of `dpi`, `dpcm`, `dppx`, or `x`. ## Combinations of types Some CSS properties can take a dimension or a percentage value. In this case the percentage value will be resolved to a quantity that matches the allowable dimension. Properties which can accept a percentage in addition to a dimension will use one of the types listed below. - {{cssxref("&lt;length-percentage&gt;")}} - : A type that can accept a length or a percentage as a value. - {{cssxref("&lt;frequency-percentage&gt;")}} - : A type that can accept a frequency or a percentage as a value. - {{cssxref("&lt;angle-percentage&gt;")}} - : A type that can accept an angle or a percentage as a value. - {{cssxref("&lt;time-percentage&gt;")}} - : A type that can accept a time or a percentage as a value. ## Color [The CSS Color Specification](https://www.w3.org/TR/css-color-4/) defines the {{cssxref("&lt;color&gt;")}} data type, and other types which relate to color in CSS. - {{cssxref("&lt;color&gt;")}} - : Specified as a keyword or a numerical color value. - {{cssxref("&lt;alpha-value&gt;")}} - : Specifies the transparency of a color. May be a `<number>`, in which case 0 is fully transparent and 1 is fully opaque, or a `<percentage>`, in which case 0% is fully transparent and 100% fully opaque. - {{cssxref("&lt;hue&gt;")}} - : Specifies the `<angle>`, with a unit identifier of `deg`, `grad`, `rad`, or `turn`, or unitless `<number>` interpreted as `deg`, of the {{glossary("color wheel")}} specific to the `<absolute-color-functions>` of which it is a component. ## Images [The CSS Images Specification](https://www.w3.org/TR/css-images-3/) defines the data types which deal with images, including gradients. - {{cssxref("&lt;image&gt;")}} - : A URL reference to an image or a color gradient. - {{cssxref("&lt;color-stop-list&gt;")}} - : A list of two or more color stops with optional transition information using a color hint. - {{cssxref("&lt;linear-color-stop&gt;")}} - : A `<color>` and a `<length-percentage>` to indicate the color stop for this part of the gradient. - {{cssxref("&lt;linear-color-hint&gt;")}} - : A `<length-percentage>` to indicate how the color interpolates. - {{cssxref("&lt;ending-shape&gt;")}} - : Used for radial gradients; can have a keyword value of `circle` or `ellipse`. - {{cssxref("&lt;size&gt;")}} - : Determines the size of the radial gradient's ending shape. This accepts a value of a keyword or a `<length>` but not a percentage. ## 2D positioning The {{cssxref("&lt;position&gt;")}} data type is interpreted as defined for the {{cssxref("&lt;background-position&gt;")}} property. - {{cssxref("&lt;position&gt;")}} - : Defines the position of an object area. Accepts a keyword value such as `top` or `left`, or a `<length-percentage>`. ## Calculation data types These data types are used in [CSS math function](/en-US/docs/Web/CSS/CSS_Functions#math_functions) calculations. - {{cssxref("&lt;calc-sum&gt;")}} - : A calculation which is a sequence of calculation values interspersed with addition (`+`) and subtraction (`-`) operators. This data type requires both values to have units. - {{cssxref("&lt;calc-product&gt;")}} - : A calculation which is a sequence of calculation values interspersed with multiplication (`*`) and division (`/`) operators. When multiplying, one value must be unitless. When dividing, the second value must be unitless. - {{cssxref("&lt;calc-value&gt;")}} - : Defines accepted values for calculations, values such as {{cssxref("&lt;number&gt;")}}, {{cssxref("&lt;dimension&gt;")}}, {{cssxref("&lt;percentage&gt;")}}, {{cssxref("&lt;calc-constant&gt;")}} or nested {{cssxref("&lt;calc-sum&gt;")}} calculations. - {{cssxref("&lt;calc-constant&gt;")}} - : Defines a number of CSS keywords representing numeric constants such as `e` and `π`, that can be used in CSS math functions. ## Specifications {{Specifications}} ## See also - [CSS Units and Values](/en-US/docs/Web/CSS/CSS_Values_and_Units) - [Introduction to CSS: Values and Units](/en-US/docs/Learn/CSS/Building_blocks/Values_and_units) - [CSS Functional Notation](/en-US/docs/Web/CSS/CSS_Functions)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/animation-fill-mode/index.md
--- title: animation-fill-mode slug: Web/CSS/animation-fill-mode page-type: css-property browser-compat: css.properties.animation-fill-mode --- {{CSSRef}} The **`animation-fill-mode`** [CSS](/en-US/docs/Web/CSS) property sets how a CSS animation applies styles to its target before and after its execution. {{EmbedInteractiveExample("pages/css/animation-fill-mode.html")}} It is often convenient to use the shorthand property {{cssxref("animation")}} to set all animation properties at once. ## Syntax ```css /* Single animation */ animation-fill-mode: none; animation-fill-mode: forwards; animation-fill-mode: backwards; animation-fill-mode: both; /* Multiple animations */ animation-fill-mode: none, backwards; animation-fill-mode: both, forwards, none; /* Global values */ animation-fill-mode: inherit; animation-fill-mode: initial; animation-fill-mode: revert; animation-fill-mode: revert-layer; animation-fill-mode: unset; ``` ### Values - `none` - : The animation will not apply any styles to the target when it's not executing. The element will instead be displayed using any other CSS rules applied to it. This is the default value. - `forwards` - : The target will retain the computed values set by the last [keyframe](/en-US/docs/Web/CSS/@keyframes) encountered during execution. The last keyframe depends on the value of {{cssxref("animation-direction")}} and {{cssxref("animation-iteration-count")}}: | `animation-direction` | `animation-iteration-count` | last keyframe encountered | | --------------------- | --------------------------- | ------------------------- | | `normal` | even or odd | `100%` or `to` | | `reverse` | even or odd | `0%` or `from` | | `alternate` | even | `0%` or `from` | | `alternate` | odd | `100%` or `to` | | `alternate-reverse` | even | `100%` or `to` | | `alternate-reverse` | odd | `0%` or `from` | - `backwards` - : The animation will apply the values defined in the first relevant [keyframe](/en-US/docs/Web/CSS/@keyframes) as soon as it is applied to the target, and retain this during the {{cssxref("animation-delay")}} period. The first relevant keyframe depends on the value of {{cssxref("animation-direction")}}: | `animation-direction` | first relevant keyframe | | -------------------------------- | ----------------------- | | `normal` or `alternate` | `0%` or `from` | | `reverse` or `alternate-reverse` | `100%` or `to` | - `both` - : The animation will follow the rules for both forwards and backwards, thus extending the animation properties in both directions. > **Note:** When you specify multiple comma-separated values on an `animation-*` property, they are applied to the animations in the order in which the {{cssxref("animation-name")}}s appear. For situations where the number of animations and `animation-*` property values do not match, see [Setting multiple animation property values](/en-US/docs/Web/CSS/CSS_animations/Using_CSS_animations#setting_multiple_animation_property_values). > **Note:** `animation-fill-mode` has the same effect when creating [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations) as it does for regular time-based animations. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting fill mode You can see the effect of `animation-fill-mode` in the following example. It demonstrates how you can make the animation remain in its final state rather than reverting to the original state (which is the default). #### HTML ```html <p>Move your mouse over the gray box!</p> <div class="demo"> <div class="growsandstays">This grows and stays big.</div> <div class="grows">This just grows.</div> </div> ``` #### CSS ```css .demo { border-top: 100px solid #ccc; height: 300px; } @keyframes grow { 0% { font-size: 0; } 100% { font-size: 40px; } } .demo:hover .grows { animation-name: grow; animation-duration: 3s; } .demo:hover .growsandstays { animation-name: grow; animation-duration: 3s; animation-fill-mode: forwards; } ``` #### Result {{EmbedLiveSample('Setting fill mode',700,300)}} See [CSS animations](/en-US/docs/Web/CSS/CSS_animations/Using_CSS_animations) for more examples. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Using CSS animations](/en-US/docs/Web/CSS/CSS_animations/Using_CSS_animations) - JavaScript {{domxref("AnimationEvent")}} API - Other related animation properties: {{cssxref("animation")}}, {{cssxref("animation-composition")}}, {{cssxref("animation-delay")}}, {{cssxref("animation-direction")}}, {{cssxref("animation-duration")}}, {{cssxref("animation-iteration-count")}}, {{cssxref("animation-name")}}, {{cssxref("animation-play-state")}}, {{cssxref("animation-timeline")}}, {{cssxref("animation-timing-function")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/scroll-margin-block-end/index.md
--- title: scroll-margin-block-end slug: Web/CSS/scroll-margin-block-end page-type: css-property browser-compat: css.properties.scroll-margin-block-end --- {{CSSRef}} The `scroll-margin-block-end` property defines the margin of the scroll snap area at the end of the block dimension that is used for snapping this box to the snapport. The scroll snap area is determined by taking the transformed border box, finding its rectangular bounding box (axis-aligned in the scroll container's coordinate space), then adding the specified outsets. {{EmbedInteractiveExample("pages/css/scroll-margin-block-end.html")}} ## Syntax ```css /* <length> values */ scroll-margin-block-end: 10px; scroll-margin-block-end: 1em; /* Global values */ scroll-margin-block-end: inherit; scroll-margin-block-end: initial; scroll-margin-block-end: revert; scroll-margin-block-end: revert-layer; scroll-margin-block-end: unset; ``` ### Values - {{CSSXref("&lt;length&gt;")}} - : An outset from the block end edge of the scroll container. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS scroll snap](/en-US/docs/Web/CSS/CSS_scroll_snap) - [Well-controlled scrolling with CSS scroll snap](https://web.dev/articles/css-scroll-snap)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/resolution/index.md
--- title: <resolution> slug: Web/CSS/resolution page-type: css-type browser-compat: css.types.resolution --- {{CSSRef}} The **`<resolution>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types), used for describing [resolutions](/en-US/docs/Web/CSS/@media/resolution) in [media queries](/en-US/docs/Web/CSS/CSS_media_queries), denotes the pixel density of an output device, i.e., its resolution. On screens, the units are related to _CSS_ inches, centimeters, or pixels, not physical values. ## Syntax The `<resolution>` data type consists of a strictly positive {{cssxref("&lt;number&gt;")}} followed by one of the units listed below. As with all CSS dimensions, there is no space between the unit literal and the number. ### Units - `dpi` - : Represents the number of [dots per inch](https://en.wikipedia.org/wiki/Dots_per_inch). Screens typically contains 72 or 96 dots per inch, but the dpi for printed documents is usually much greater. As 1 inch is 2.54 cm, `1dpi ≈ 0.39dpcm`. - `dpcm` - : Represents the number of [dots per centimeter](https://en.wikipedia.org/wiki/Dots_per_inch). As 1 inch is 2.54 cm, `1dpcm ≈ 2.54dpi`. - `dppx` - : Represents the number of dots per [`px`](/en-US/docs/Web/CSS/length#px) unit. Due to the 1:96 fixed ratio of CSS `in` to CSS `px`, `1dppx` is equivalent to `96dpi`, which corresponds to the default resolution of images displayed in CSS as defined by {{cssxref("image-resolution")}}. - `x` - : Alias for `dppx`. > **Note:** Although the number `0` is always the same regardless of unit, the unit may not be omitted. In other words, `0` is invalid and does not represent `0dpi`, `0dpcm`, or `0dppx`. ## Examples ### Use in a media query ```css @media print and (min-resolution: 300dpi) { /* … */ } @media (resolution: 120dpcm) { /* … */ } @media (min-resolution: 2dppx) { /* … */ } @media (resolution: 1x) { /* … */ } ``` ### Valid resolutions ```plain example-good 96dpi 50.82dpcm 3dppx ``` ### Invalid resolutions ```plain example-bad 72 dpi Spaces are not allowed between the number and the unit. ten dpi The number must use digits only. 0 The unit is required. ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [resolution](/en-US/docs/Web/CSS/@media/resolution) media feature - The {{cssxref("image-resolution")}} property - [Using @media queries](/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/flex-flow/index.md
--- title: flex-flow slug: Web/CSS/flex-flow page-type: css-shorthand-property browser-compat: css.properties.flex-flow --- {{CSSRef}} The **`flex-flow`** [CSS](/en-US/docs/Web/CSS) [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) specifies the direction of a flex container, as well as its wrapping behavior. {{EmbedInteractiveExample("pages/css/flex-flow.html")}} ## Constituent properties This property is a shorthand for the following CSS properties: - [`flex-direction`](/en-US/docs/Web/CSS/flex-direction) - [`flex-wrap`](/en-US/docs/Web/CSS/flex-wrap) ## Syntax ```css /* flex-flow: <'flex-direction'> */ flex-flow: row; flex-flow: row-reverse; flex-flow: column; flex-flow: column-reverse; /* flex-flow: <'flex-wrap'> */ flex-flow: nowrap; flex-flow: wrap; flex-flow: wrap-reverse; /* flex-flow: <'flex-direction'> and <'flex-wrap'> */ flex-flow: row nowrap; flex-flow: column wrap; flex-flow: column-reverse wrap-reverse; /* Global values */ flex-flow: inherit; flex-flow: initial; flex-flow: revert; flex-flow: revert-layer; flex-flow: unset; ``` ### Values See {{cssxref("flex-direction")}} and {{cssxref("flex-wrap")}} for details on the values. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting column-reverse and wrap ```css element { /* Main-axis is the block direction with reversed main-start and main-end. Flex items are laid out in multiple lines */ flex-flow: column-reverse wrap; } ``` ## Specifications {{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: _[Ordering flex items](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Ordering_flex_items)_
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/-webkit-mask-position-x/index.md
--- title: "-webkit-mask-position-x" slug: Web/CSS/-webkit-mask-position-x page-type: css-property status: - non-standard browser-compat: css.properties.-webkit-mask-position-x --- {{CSSRef}}{{Non-standard_header}} The `-webkit-mask-position-x` CSS property sets the initial horizontal position of a mask image. ## Syntax ```css /* Keyword values */ -webkit-mask-position-x: left; -webkit-mask-position-x: center; -webkit-mask-position-x: right; /* <percentage> values */ -webkit-mask-position-x: 100%; -webkit-mask-position-x: -50%; /* <length> values */ -webkit-mask-position-x: 50px; -webkit-mask-position-x: -1cm; /* Multiple values */ -webkit-mask-position-x: 50px, 25%, -3em; /* Global values */ -webkit-mask-position-x: inherit; -webkit-mask-position-x: initial; -webkit-mask-position-x: revert; -webkit-mask-position-x: revert-layer; -webkit-mask-position-x: unset; ``` ### Values - `<length-percentage>` - : A length indicating the position of the left edge of the image relative to the box's left padding edge. Percentages are calculated against the horizontal dimension of the box padding area. That means, a value of `0%` means the left edge of the image is aligned with the box's left padding edge and a value of `100%` means the right edge of the image is aligned with the box's right padding edge. - `left` - : Equivalent to `0%`. - `center` - : Equivalent to `50%`. - `right` - : Equivalent to `100%`. ## Formal definition {{CSSInfo}} ## Formal syntax ```plain -webkit-mask-position-x = [ <length-percentage> | left | center | right ]# ``` ## Examples ### Horizontally positioning a mask image ```css .exampleOne { -webkit-mask-image: url(mask.png); -webkit-mask-position-x: right; } .exampleTwo { -webkit-mask-image: url(mask.png); -webkit-mask-position-x: 25%; } ``` ## Specifications Not part of any standard. ## Browser compatibility {{Compat}} ## See also {{cssxref("mask-position", "-webkit-mask-position")}}, {{cssxref("-webkit-mask-position-y")}}, {{cssxref("mask-origin", "-webkit-mask-origin")}}, {{cssxref("-webkit-mask-attachment")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/margin-inline-end/index.md
--- title: margin-inline-end slug: Web/CSS/margin-inline-end page-type: css-property browser-compat: css.properties.margin-inline-end --- {{CSSRef}} The **`margin-inline-end`** [CSS](/en-US/docs/Web/CSS) property defines the logical inline end margin of an element, which maps to a physical margin depending on the element's writing mode, directionality, and text orientation. In other words, it corresponds to the {{cssxref("margin-top")}}, {{cssxref("margin-right")}}, {{cssxref("margin-bottom")}} or {{cssxref("margin-left")}} property depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. {{EmbedInteractiveExample("pages/css/margin-inline-end.html")}} ## Syntax ```css /* <length> values */ margin-inline-end: 10px; /* An absolute length */ margin-inline-end: 1em; /* relative to the text size */ margin-inline-end: 5%; /* relative to the nearest block container's width */ /* Keyword values */ margin-inline-end: auto; /* Global values */ margin-inline-end: inherit; margin-inline-end: initial; margin-inline-end: revert; margin-inline-end: revert-layer; margin-inline-end: unset; ``` It relates to {{cssxref("margin-block-start")}}, {{cssxref("margin-block-end")}}, and {{cssxref("margin-inline-start")}}, which define the other margins of the element. ### Values The `margin-inline-end` property takes the same values as the {{cssxref("margin-left")}} property. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting inline end margin #### HTML ```html <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ```css div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; margin-inline-end: 20px; background-color: #c8c800; } ``` #### Result {{EmbedLiveSample("Setting_inline_end_margin", 140, 140)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS Logical Properties and Values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values) - {{cssxref("margin-inline-start")}} - 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/perspective-origin/index.md
--- title: perspective-origin slug: Web/CSS/perspective-origin page-type: css-property browser-compat: css.properties.perspective-origin --- {{CSSRef}} The **`perspective-origin`** [CSS](/en-US/docs/Web/CSS) property determines the position at which the viewer is looking. It is used as the _vanishing point_ by the {{cssxref("perspective")}} property. {{EmbedInteractiveExample("pages/css/perspective-origin.html")}} The **`perspective-origin`** and {{cssxref('perspective')}} properties are attached to the parent of a child transformed in 3-dimensional space, unlike the [`perspective()`](/en-US/docs/Web/CSS/transform-function/perspective) transform function which is placed on the element being transformed. ## Syntax ```css /* One-value syntax */ perspective-origin: x-position; /* Two-value syntax */ perspective-origin: x-position y-position; /* When both x-position and y-position are keywords, the following is also valid */ perspective-origin: y-position x-position; /* Global values */ perspective-origin: inherit; perspective-origin: initial; perspective-origin: revert; perspective-origin: revert-layer; perspective-origin: unset; ``` ### Values - _x-position_ - : Indicates the position of the abscissa of the _vanishing point_. It can have one of the following values: - {{cssxref("&lt;length-percentage&gt;")}} indicating the position as an absolute length value or relative to the width of the element. The value may be negative. - `left`, a keyword being a shortcut for the `0` length value. - `center`, a keyword being a shortcut for the `50%` percentage value. - `right`, a keyword being a shortcut for the `100%` percentage value. - _y-position_ - : Indicates the position of the ordinate of the _vanishing point_. It can have one of the following values: - {{cssxref("&lt;length-percentage&gt;")}} indicating the position as an absolute length value or relative to the height of the element. The value may be negative. - `top`, a keyword being a shortcut for the `0` length value. - `center`, a keyword being a shortcut for the `50%` percentage value. - `bottom`, a keyword being a shortcut for the `100%` percentage value. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Changing the perspective origin An example showing how to change `perspective-origin` is given in [Using CSS transforms > Changing the perspective origin](/en-US/docs/Web/CSS/CSS_transforms/Using_CSS_transforms#changing_the_perspective_origin). ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Using CSS Transforms](/en-US/docs/Web/CSS/CSS_transforms/Using_CSS_transforms) - {{cssxref('transform-style')}} - {{cssxref('transform-function')}} - {{cssxref('perspective')}} - [`transform: perspective()`](/en-US/docs/Web/CSS/transform-function/perspective) function
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_-moz-handler-crashed/index.md
--- title: ":-moz-handler-crashed" slug: Web/CSS/:-moz-handler-crashed page-type: css-pseudo-class status: - non-standard --- {{CSSRef}} {{Non-standard_header}} The **`:-moz-handler-crashed`** [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 the plugin responsible for drawing them has crashed. > **Note:** This selector is mainly intended to be used by theme developers. ## Syntax ```css :-moz-handler-crashed { /* ... */ } ``` ## Specifications Not part of any standard. ## See also - {{ cssxref(":-moz-handler-blocked") }} - {{ cssxref(":-moz-handler-disabled") }}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-block-style/index.md
--- title: border-block-style slug: Web/CSS/border-block-style page-type: css-property browser-compat: css.properties.border-block-style --- {{CSSRef}} The **`border-block-style`** [CSS](/en-US/docs/Web/CSS) property defines the style of the logical block borders of an element, which maps to a physical border style depending on the element's writing mode, directionality, and text orientation. It corresponds to the {{cssxref("border-top-style")}} and {{cssxref("border-bottom-style")}}, or {{cssxref("border-left-style")}} and {{cssxref("border-right-style")}} properties depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. {{EmbedInteractiveExample("pages/css/border-block-style.html")}} The border style in the other dimension can be set with {{cssxref("border-inline-style")}}, which sets {{cssxref("border-inline-start-style")}}, and {{cssxref("border-inline-end-style")}}. ## Syntax ```css /* <'border-style'> values */ border-block-style: dashed; border-block-style: dotted; border-block-style: groove; /* Global values */ border-block-style: inherit; border-block-style: initial; border-block-style: revert; border-block-style: revert-layer; border-block-style: unset; ``` ### Values - `<'border-style'>` - : The line style of the border. See {{ cssxref("border-style") }}. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Dashed 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-lr; border: 5px solid blue; border-block-style: dashed; } ``` #### Results {{EmbedLiveSample("Dashed_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-style")}}, {{cssxref("border-right-style")}}, {{cssxref("border-bottom-style")}}, or {{cssxref("border-left-style")}}. - {{cssxref("writing-mode")}}, {{cssxref("direction")}}, {{cssxref("text-orientation")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_box_model/index.md
--- title: CSS box model slug: Web/CSS/CSS_box_model page-type: css-module spec-urls: https://drafts.csswg.org/css-box/ --- {{CSSRef}} The **CSS box model** module defines the rectangular boxes, including their padding and margin, that are generated for elements and laid out according to the [visual formatting model](/en-US/docs/Web/CSS/Visual_formatting_model). ## Box model overview A box in CSS consists of a content area, which is where any text, images, or other HTML elements are displayed. This is optionally surrounded by padding, a border, and a margin, on one or more sides. The box model describes how these elements work together to create a box as displayed by CSS. To learn more about it read [Introduction to the CSS box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model). ### Box-edge keywords The Box Model specification defines a set of keywords that refer to the edges of each part of the box, these are used as keyword values in CSS including as a value for the {{cssxref("box-sizing")}} property, to control how the box model calculates its size. - `content-box` - : The edge of the content area of the box. - `padding-box` - : The edge of the padding of the box, if there is no padding on a side then this is the same as `content-box`. - `border-box` - : The edge of the border of the box, if there is no border on a side then this is the same as `padding-box`. - `margin-box` - : The edge of the margin of the box, if there is no margin on a side then this is the same as `border-box`. - `stroke-box` - : In SVG refers to the stroke bounding box, in CSS treated as `content-box`. - `view-box` - : In SVG refers to the nearest SVG viewport element's origin box, which is a rectangle with the width and height of the initial SVG user coordinate system established by the {{svgattr("viewBox")}} attribute for that element. In CSS treated as `border-box`. ## Reference > **Note:** This specification defines the physical padding and margin properties. Flow-relative properties, which relate to text direction, are defined in [Logical Properties and Values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values). ### Properties for controlling the margin of a box Margins surround the border edge of a box, and provide spacing between boxes. - {{CSSxRef("margin")}} - {{CSSxRef("margin-bottom")}} - {{CSSxRef("margin-left")}} - {{CSSxRef("margin-right")}} - {{CSSxRef("margin-top")}} - {{CSSxRef("margin-trim")}} {{Experimental_Inline}} ### Properties for controlling the padding for a box Padding is inserted between the content edge and border edge of a box. - {{CSSxRef("padding")}} - {{CSSxRef("padding-bottom")}} - {{CSSxRef("padding-left")}} - {{CSSxRef("padding-right")}} - {{CSSxRef("padding-top")}} ### Other properties There are other properties that relate to the box model, that are defined elsewhere. - [Borders](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders) - : The border properties specify the thickness of the border, drawing style and color. - [Overflow](/en-US/docs/Web/CSS/overflow) - : Controls what happens when there is too much content to fit into a box. ## Guides - [Introduction to the CSS box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model) - : Explains one of the fundamental concept of CSS: the box model. This model defines how CSS lays out elements, including their content, padding, border, and margin areas. - [Mastering margin collapsing](/en-US/docs/Web/CSS/CSS_box_model/Mastering_margin_collapsing) - : Sometimes, two adjacent margins are collapsed into one. This article describes the rules that govern when and why this happens, and how to control it. - [Visual formatting model](/en-US/docs/Web/CSS/Visual_formatting_model) - : Explains the visual formatting model. ## Specifications {{Specifications}}
0
data/mdn-content/files/en-us/web/css/css_box_model
data/mdn-content/files/en-us/web/css/css_box_model/mastering_margin_collapsing/index.md
--- title: Mastering margin collapsing slug: Web/CSS/CSS_box_model/Mastering_margin_collapsing page-type: guide --- {{CSSRef}} The [top](/en-US/docs/Web/CSS/margin-top) and [bottom](/en-US/docs/Web/CSS/margin-bottom) margins of blocks are sometimes combined (collapsed) into a single margin whose size is the largest of the individual margins (or just one of them, if they are equal), a behavior known as **margin collapsing**. Note that the margins of [floating](/en-US/docs/Web/CSS/float) and [absolutely positioned](/en-US/docs/Web/CSS/position#types_of_positioning) elements never collapse. Margin collapsing occurs in three basic cases: - Adjacent siblings - : The margins of adjacent siblings are collapsed (except when the latter sibling needs to be [cleared](/en-US/docs/Web/CSS/clear) past floats). - No content separating parent and descendants - : If there is no border, padding, inline part, [block formatting context](/en-US/docs/Web/CSS/CSS_display/Block_formatting_context) created, or _[clearance](/en-US/docs/Web/CSS/clear)_ to separate the {{cssxref("margin-top")}} of a block from the {{cssxref("margin-top")}} of one or more of its descendant blocks; or no border, padding, inline content, {{cssxref("height")}}, or {{cssxref("min-height")}} to separate the {{cssxref("margin-bottom")}} of a block from the {{cssxref("margin-bottom")}} of one or more of its descendant blocks, then those margins collapse. The collapsed margin ends up outside the parent. - Empty blocks - : If there is no border, padding, inline content, {{cssxref("height")}}, or {{cssxref("min-height")}} to separate a block's {{cssxref("margin-top")}} from its {{cssxref("margin-bottom")}}, then its top and bottom margins collapse. Some things to note: - More complex margin collapsing (of more than two margins) occurs when the above cases are combined. - These rules apply even to margins that are zero, so the margin of a descendant ends up outside its parent (according to the rules above) whether or not the parent's margin is zero. - When negative margins are involved, the size of the collapsed margin is the sum of the largest positive margin and the smallest (most negative) negative margin. - When all margins are negative, the size of the collapsed margin is the smallest (most negative) margin. This applies to both adjacent elements and nested elements. - Collapsing margins is only relevant in the vertical direction. - Margins don't collapse in a container with `display` set to `flex` or `grid`. ## Examples ### HTML ```html <p>The bottom margin of this paragraph is collapsed …</p> <p> … with the top margin of this paragraph, yielding a margin of <code>1.2rem</code> in between. </p> <div> This parent element contains two paragraphs! <p> This paragraph has a <code>.4rem</code> margin between it and the text above. </p> <p> My bottom margin collapses with my parent, yielding a bottom margin of <code>2rem</code>. </p> </div> <p>I am <code>2rem</code> below the element above.</p> ``` ### CSS ```css div { margin: 2rem 0; background: lavender; } p { margin: 0.4rem 0 1.2rem 0; background: yellow; } ``` ### Result {{EmbedLiveSample('Examples', 'auto', 350)}} ## 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) - 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/css_box_model
data/mdn-content/files/en-us/web/css/css_box_model/introduction_to_the_css_box_model/index.md
--- title: Introduction to the CSS basic box model slug: Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model page-type: guide --- {{CSSRef}} When laying out a document, the browser's rendering engine represents each element as a rectangular box according to the standard **CSS basic box model**. CSS determines the size, position, and properties (color, background, border size, etc.) of these boxes. Every box is composed of four parts (or _areas_), defined by their respective edges: the _content edge_, _padding edge_, _border edge_, and _margin edge_. ![CSS Box model](boxmodel.png) ## Content area The **content area**, bounded by the content edge, contains the "real" content of the element, such as text, an image, or a video player. Its dimensions are the _content width_ (or _content-box width_) and the _content height_ (or _content-box height_). It often has a background color or background image. If the {{cssxref("box-sizing")}} property is set to `content-box` (default) and if the element is a block element, the content area's size can be explicitly defined with the {{cssxref("width")}}, {{cssxref("min-width")}}, {{cssxref("max-width")}}, {{ cssxref("height") }}, {{cssxref("min-height")}}, and {{cssxref("max-height")}} properties. ## Padding area The **padding area**, bounded by the padding edge, extends the content area to include the element's padding. Its dimensions are the _padding-box width_ and the _padding-box height_. The thickness of the padding is determined by the {{cssxref("padding-top")}}, {{cssxref("padding-right")}}, {{cssxref("padding-bottom")}}, {{cssxref("padding-left")}}, and shorthand {{cssxref("padding")}} properties. ## Border area The **border area**, bounded by the border edge, extends the padding area to include the element's borders. Its dimensions are the _border-box width_ and the _border-box height_. The thickness of the borders are determined by the {{cssxref("border-width")}} and shorthand {{cssxref("border")}} properties. If the {{cssxref("box-sizing")}} property is set to `border-box`, the border area's size can be explicitly defined with the {{cssxref("width")}}, {{cssxref("min-width")}}, {{cssxref("max-width")}}, {{ cssxref("height") }}, {{cssxref("min-height")}}, and {{cssxref("max-height")}} properties. When there is a background ({{cssxref("background-color")}} or {{cssxref("background-image")}}) set on a box, it extends to the outer edge of the border (i.e. extends underneath the border in z-ordering). This default behavior can be altered with the {{cssxref("background-clip")}} CSS property. ## Margin area The **margin area**, bounded by the margin edge, extends the border area to include an empty area used to separate the element from its neighbors. Its dimensions are the _margin box width_ and the _margin box height_. The size of the margin area is determined by the {{cssxref("margin-top")}}, {{cssxref("margin-right")}}, {{cssxref("margin-bottom")}}, {{cssxref("margin-left")}}, and shorthand {{cssxref("margin")}} properties. When [margin collapsing](/en-US/docs/Web/CSS/CSS_box_model/Mastering_margin_collapsing) occurs, the margin area is not clearly defined since margins are shared between boxes. Finally, note that for non-replaced inline elements, the amount of space taken up (the contribution to the height of the line) is determined by the {{cssxref('line-height')}} property, even though the borders and padding are still displayed around the content. ## See also - [Layout and the containing block](/en-US/docs/Web/CSS/Containing_block) - [Introducing the CSS Cascade](/en-US/docs/Web/CSS/Cascade) - [Cascade, specificity, and inheritance](/en-US/docs/Learn/CSS/Building_blocks/Cascade_and_inheritance) - CSS key concepts: - [CSS syntax](/en-US/docs/Web/CSS/Syntax) - [At-rules](/en-US/docs/Web/CSS/At-rule) - [Comments](/en-US/docs/Web/CSS/Comments) - [Specificity](/en-US/docs/Web/CSS/Specificity) - [Inheritance](/en-US/docs/Web/CSS/Inheritance) - [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/@scope/index.md
--- title: "@scope" slug: Web/CSS/@scope page-type: css-at-rule browser-compat: css.at-rules.scope --- {{CSSRef}} The **`@scope`** [CSS](/en-US/docs/Web/CSS) [at-rule](/en-US/docs/Web/CSS/At-rule) enables you to select elements in specific DOM subtrees, targeting elements precisely without writing overly-specific selectors that are hard to override, and without coupling your selectors too tightly to the DOM structure. In JavaScript, `@scope` can be accessed via the CSS object model interface {{DOMxRef("CSSScopeRule")}}. ## Syntax The `@scope` at-rule contains one or more rulesets (termed **scoped style rules**) and defines a scope in which to apply them to selected elements. `@scope` can be used in two ways: 1. As a standalone block inside your CSS, in which case it includes a prelude section that includes **scope root** and optional **scope limit** selectors — these define the upper and lower bounds of the scope. ```css @scope (scope root) to (scope limit) { rulesets } ``` 2. As inline styles included inside a {{htmlelement("style")}} element in your HTML, in which case the prelude is omitted, and the enclosed ruleset is automatically scoped to the `<style>` element's enclosing parent element. ```html <parent-element> <style> @scope { rulesets } </style> </parent-element> ``` ## Description A complex web document might include components such as headers, footers, news articles, maps, media players, ads, and others. As complexity increases, effectively managing the styling for these components becomes more of a concern, and effective scoping of styles helps us manage this complexity. Let's consider the following DOM tree: ```plain-nolint body └─ article.feature ├─ section.article-hero │ ├─ h2 │ └─ img │ ├─ section.article-body │ ├─ h3 │ ├─ p │ ├─ img │ ├─ p │ └─ figure │ ├─ img │ └─ figcaption │ └─ footer ├─ p └─ img ``` If you wanted to select the {{htmlelement("img")}} element inside the {{htmlelement("section")}} with a class of `article-body`, you could do the following: - Write a selector like `.feature > .article-body > img`. However, that has high specificity so is hard to override, and is also tightly coupled to the DOM structure. If your markup structure changes in the future, you might need to rewrite your CSS. - Write something less specific like `.article-body img`. However, that will select all images inside the `section`. This is where `@scope` is useful. It allows you to define a precise scope inside which your selectors are allowed to target elements. For example, you could solve the above problem using a standalone `@scope` block like the following: ```css @scope (.article-body) to (figure) { img { border: 5px solid black; background-color: goldenrod; } } ``` The `.article-body` scope root selector defines the upper bound of the DOM tree scope in which the ruleset will be applied, and the `figure` scope limit selector defines the lower bound. As a result, only {{htmlelement("img")}} elements inside a `<section>` with a class of `article-body`, but not inside {{htmlelement("figure")}} elements, will be selected. > **Note:** This kind of scoping — with an upper and lower bound — is commonly referred to as a **donut scope**. If you want to select all images inside a `<section>` with a class of `article-body`, you can omit the scope limit: ```css @scope (.article-body) { img { border: 5px solid black; background-color: goldenrod; } } ``` Or you could include your `@scope` block inline inside a `<style>` element, which in turn is inside the `<section>` with a class of `article-body`: ```html <section class="article-body"> <style> @scope { img { border: 5px solid black; background-color: goldenrod; } } </style> <!-- ... --> </section> ``` > **Note:** It is important to understand that, while `@scope` allows you to isolate the application of selectors to specific DOM subtrees, it does not completely isolate the applied styles to within those subtrees. This is most noticeable with inheritance — properties that are inherited by children (for example {{cssxref("color")}} or {{cssxref("font-family")}}) will still be inherited, beyond any set scope limit. ### The `:scope` pseudo-class In the context of a `@scope` block, the {{cssxref(":scope")}} pseudo-class represents the scope root — it provides an easy way to apply styles to the scope root itself, from inside the scope: ```css @scope (.feature) { :scope { background: rebeccapurple; color: antiquewhite; font-family: sans-serif; } } ``` In fact, `:scope` is implicitly prepended to all scoped style rules. If you want, you can explicitly prepend `:scope` or prepend the [nesting](/en-US/docs/Web/CSS/CSS_nesting) selector (`&`) to get the same effect if you find these representations easier to understand. The three rules in the following block are all equivalent in what they select: ```css @scope (.feature) { img { ... } :scope img { ... } & img { ... } } ``` ### Notes on scoped selector usage - A scope limit can use `:scope` to specify a specific relationship requirement between the scope limit and root. For example: ```css /* figure is only a limit when it is a direct child of the :scope */ @scope (.article-body) to (:scope > figure) { ... } ``` - A scope limit can reference elements outside the scope root using `:scope`. For example: ```css /* figure is only a limit when the :scope is inside .feature */ @scope (.article-body) to (.feature :scope figure) { ... } ``` - Scoped style rules can't escape the subtree. Selections like `:scope + p` are invalid because that selection would be outside the subtree. - It is perfectly valid to define the scope root and limit as a selector list, in which case multiple scopes will be defined. In the following example the styles are applied to any `<img>` inside a `<section>` with a class of `article-hero` or `article-body`, but not if it is nested inside a `<figure>`: ```css @scope (.article-hero, .article-body) to (figure) { img { border: 5px solid black; background-color: goldenrod; } } ``` ### Specificity in `@scope` Including a ruleset inside a `@scope` block does not affect the specificity of its selector, regardless of the selectors used inside the scope root and limit. For example: ```css @scope (.article-body) { /* img has a specificity of 0-0-1, as expected */ img { ... } } ``` However, if you decide to explicitly prepend the `:scope` pseudo-class to your scoped selectors, you'll need to factor it in when calculating their specificity. `:scope`, like all regular pseudo-classes, has a specificity of 0-1-0. For example: ```css @scope (.article-body) { /* :scope img has a specificity of 0-1-0 + 0-0-1 = 0-1-1 */ :scope img { ... } } ``` When using the `&` selector inside a `@scope` block, `&` represents the scope root selector; it is internally calculated as that selector wrapped inside an {{cssxref(":is", ":is()")}} pseudo-class function. So for example, in: ```css @scope (figure, #primary) { & img { ... } } ``` `& img` is equivalent to `:is(figure, #primary) img`. Since `:is()` takes the specificity of its most specific argument (`#primary`, in this case), the specificity of the scoped `& img` selector is therefore 1-0-0 + 0-0-1 = 1-0-1. ### The difference between `:scope` and `&` inside `@scope` `:scope` represents the matched scope root, whereas `&` represents the selector used to match the scope root. Because of this, it is possible to chain `&` multiple times. However, you can only use `:scope` once — you can't match a scope root inside a scope root. ```css @scope (.feature) { /* Selects a .feature inside the matched root .feature */ & & { ... } /* Doesn't work */ :root :root { ... } } ``` ### How `@scope` conflicts are resolved `@scope` adds a new criterion to the [CSS cascade](/en-US/docs/Web/CSS/CSS_cascade): **scoping proximity**. This states that when two scopes have conflicting styles, the style that has the smallest number of hops up the DOM tree hierarchy to the scope root is applied. Let's look at an example to see what this means. Take the following HTML snippet, where different-themed cards are nested inside one another: ```html <div class="light-theme"> <p>Light theme text</p> <div class="dark-theme"> <p>Dark theme text</p> <div class="light-theme"> <p>Light theme text</p> </div> </div> </div> ``` If you wrote the theme CSS like so, you'd run into trouble: ```css .light-theme { background: #ccc; } .dark-theme { background: #333; } .light-theme p { color: black; } .dark-theme p { color: white; } ``` The innermost paragraph is supposed to be colored black because it is inside a light theme card. However, it's targeted by both `.light-theme p` and `.dark-theme p`. Because the `.dark-theme p` rule appears later in the source order, it is applied, and the paragraph ends up being wrongly colored white. To fix this, you can use `@scope` as follows: ```css @scope (.light-theme) { :scope { background: #ccc; } p { color: black; } } @scope (.dark-theme) { :scope { background: #333; } p { color: white; } } ``` Now the innermost paragraph is correctly colored black. This is because it is only one DOM tree hierarchy level away from the `.light-theme` scope root, but two levels away from the `.dark-theme` scope root. Therefore, the light style wins. > **Note:** Scoping proximity overrules source order but is itself overridden by other, higher-priority criteria such as [importance](/en-US/docs/Web/CSS/important), [layers](/en-US/docs/Learn/CSS/Building_blocks/Cascade_layers), and [specificity](/en-US/docs/Web/CSS/Specificity). ## Formal syntax {{csssyntax}} ## Examples ### Basic style inside scope roots In this example, we use two separate `@scope` blocks to match links inside elements with a `.light-scheme` and `.dark-scheme` class respectively. Note how `:scope` is used to select and provide styling to the scope roots themselves. In this example, the scope roots are the {{htmlelement("div")}} elements that have the classes applied to them. #### HTML ```html <div class="light-scheme"> <p> MDN contains lots of information about <a href="/en-US/docs/Web/HTML">HTML</a>, <a href="/en-US/docs/Web/CSS">CSS</a>, and <a href="/en-US/docs/Web/JavaScript">JavaScript</a>. </p> </div> <div class="dark-scheme"> <p> MDN contains lots of information about <a href="/en-US/docs/Web/HTML">HTML</a>, <a href="/en-US/docs/Web/CSS">CSS</a>, and <a href="/en-US/docs/Web/JavaScript">JavaScript</a>. </p> </div> ``` #### CSS ```css hidden div { padding: 10px; } ``` ```css @scope (.light-scheme) { :scope { background-color: plum; } a { color: darkmagenta; } } @scope (.dark-scheme) { :scope { background-color: darkmagenta; color: antiquewhite; } a { color: plum; } } ``` #### Result The above code renders like this: {{ EmbedLiveSample("Basic style inside scope roots", "100%", "150") }} ### Scope roots and scope limits In this example, we have an HTML snippet that matches the DOM structure we talked about earlier in the [Description](#description) section. This structure represents a typical article summary. The key features to note are the {{htmlelement("img")}} elements, which are nested at various levels in the structure. The aim of this example is to show how to use a scope root and limit to style `<img>` elements starting at the top of the hierarchy, but only down as far as (and not including) the `<img>` inside the {{htmlelement("figure")}} element — in effect creating a donut scope. #### HTML ```html <article class="feature"> <section class="article-hero"> <h2>Article heading</h2> <img alt="image" /> </section> <section class="article-body"> <h3>Article subheading</h3> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam euismod consectetur leo, nec eleifend quam volutpat vitae. Duis quis felis at augue imperdiet aliquam. Morbi at felis et massa mattis lacinia. Cras pharetra velit nisi, ac efficitur magna luctus nec. </p> <img alt="image" /> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> <figure> <img alt="image" /> <figcaption>My infographic</figcaption> </figure> </section> <footer> <p>Written by Chris Mills.</p> <img alt="image" /> </footer> </article> ``` #### CSS ```css hidden * { box-sizing: border-box; } article { margin-bottom: 20px; padding: 10px; border: 2px solid gray; } .article-hero, .article-body, article footer { padding: 20px; margin: 10px; border: 2px solid lightgray; } img { height: 100px; width: 100%; display: block; background-color: lightgray; color: black; padding: 10px; } ``` In our CSS, we have two `@scope` blocks: - The first `@scope` block defines its scope root as elements with a class of `.feature` (in this case, the outer `<div>` only), demonstrating how `@scope` can be used to theme a specific HTML subset. - The second `@scope` block also defines its scope root as elements with a class of `.feature`, but in addition defines a scope limit of `figure`. This ensures that contained rulesets will only be applied to matching elements within the scope root (`<div class="figure"> ... </div>` in this case) that **are not** nested inside descendant `<figure>` elements. This `@scope` block contains a single ruleset that styles `<img>` elements with a thick black border and a golden background color. ```css /* Scoped CSS */ @scope (.feature) { :scope { background: rebeccapurple; color: antiquewhite; font-family: sans-serif; } figure { background-color: white; border: 2px solid black; color: black; padding: 10px; } } /* Donut scope */ @scope (.feature) to (figure) { img { border: 5px solid black; background-color: goldenrod; } } ``` #### Result In the rendered code, note how all of the `<img>` elements are styled with the thick border and golden background, except for the one inside the `<figure>` element (labeled "My infographic"). {{ EmbedLiveSample("Scope roots and scope limits", "100%", "400") }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef(":scope")}} - {{DOMxRef("CSSScopeRule")}} - [Limit the reach of your selectors with the CSS `@scope` at-rule](https://developer.chrome.com/docs/css-ui/at-scope) on developer.chrome.com (2023)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/place-content/index.md
--- title: place-content slug: Web/CSS/place-content page-type: css-shorthand-property browser-compat: css.properties.place-content --- {{CSSRef}} The **`place-content`** [CSS](/en-US/docs/Web/CSS) [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) allows you to align content along both the block and inline directions at once (i.e. the {{CSSxRef("align-content")}} and {{CSSxRef("justify-content")}} properties) in a relevant layout system such as [Grid](/en-US/docs/Web/CSS/CSS_grid_layout) or [Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout). {{EmbedInteractiveExample("pages/css/place-content.html")}} ## Constituent properties This property is a shorthand for the following CSS properties: - [`align-content`](/en-US/docs/Web/CSS/align-content) - [`justify-content`](/en-US/docs/Web/CSS/justify-content) ## Syntax ```css /* Positional alignment */ /* align-content does not take left and right values */ place-content: center start; place-content: start center; place-content: end left; place-content: flex-start center; place-content: flex-end center; /* Baseline alignment */ /* justify-content does not take baseline values */ place-content: baseline center; place-content: first baseline space-evenly; place-content: last baseline right; /* Distributed alignment */ place-content: space-between space-evenly; place-content: space-around space-evenly; place-content: space-evenly stretch; place-content: stretch space-evenly; /* Global values */ place-content: inherit; place-content: initial; place-content: revert; place-content: revert-layer; place-content: unset; ``` The first value is the {{CSSxRef("align-content")}} property value, the second the {{CSSxRef("justify-content")}} one. > **Note:** If the second value is not present, the first value is used for both, provided it is a valid value for both. If it is invalid for one or the other, the whole value will be invalid. ### Values - `start` - : The items are packed flush to each other toward the start edge of the alignment container in the appropriate axis. - `end` - : The items are packed flush to each other toward the end edge of the alignment container in the appropriate axis. - `flex-start` - : The items are packed flush to each other toward the edge of the alignment container depending on the flex container's main-start or cross-start side. This only applies to flex layout items. For items that are not children of a flex container, this value is treated like `start`. - `flex-end` - : The items are packed flush to each other toward the edge of the alignment container depending on the flex container's main-end or cross-end side. This only applies to flex layout items. For items that are not children of a flex container, this value is treated like `end`. - `center` - : The items are packed flush to each other toward the center of the alignment container. - `left` - : The items are packed flush to each other toward the left edge of the alignment container. If the property's axis is not parallel with the inline axis, this value behaves like `start`. - `right` - : The items are packed flush to each other toward the right edge of the alignment container in the appropriate axis. If the property's axis is not parallel with the inline axis, this value behaves like `start`. - `space-between` - : The items are evenly distributed within the alignment container. The spacing between each pair of adjacent items is the same. The first item is flush with the main-start edge, and the last item is flush with the main-end edge. - `baseline`, `first baseline`, `last baseline` - : Specifies participation in first- or last-baseline alignment: aligns the alignment baseline of the box's first or last baseline set with the corresponding baseline in the shared first or last baseline set of all the boxes in its baseline-sharing group. The fallback alignment for `first baseline` is `start`, the one for `last baseline` is `end`. - `space-around` - : The items are evenly distributed within the alignment container. The spacing between each pair of adjacent items is the same. The empty space before the first and after the last item equals half of the space between each pair of adjacent items. - `space-evenly` - : The items are evenly distributed within the alignment container. The spacing between each pair of adjacent items, the main-start edge and the first item, and the main-end edge and the last item, are all exactly the same. - `stretch` - : If the combined size of the items is less than the size of the alignment container, any `auto`-sized items have their size increased equally (not proportionally), while still respecting the constraints imposed by {{CSSxRef("max-height")}}/{{CSSxRef("max-width")}} (or equivalent functionality), so that the combined size exactly fills the alignment container - `safe` - : Used alongside an alignment keyword. If the chosen keyword means that the item overflows the alignment container causing data loss, the item is instead aligned as if the alignment mode were `start`. - `unsafe` - : Used alongside an alignment keyword. Regardless of the relative sizes of the item and alignment container, and regardless of whether overflow which causes data loss might happen, the given alignment value is honored. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Placing content in a flex container #### HTML ```html <div id="container"> <div class="small">Lorem</div> <div class="small">Lorem<br />ipsum</div> <div class="large">Lorem</div> <div class="large">Lorem<br />ipsum</div> <div class="large"></div> <div class="large"></div> </div> ``` ```html hidden <code>writing-mode:</code ><select id="writingMode"> <option value="horizontal-tb" selected>horizontal-tb</option> <option value="vertical-rl">vertical-rl</option> <option value="vertical-lr">vertical-lr</option> <option value="sideways-rl">sideways-rl</option> <option value="sideways-lr">sideways-lr</option></select ><code>;</code><br /> <code>direction:</code ><select id="direction"> <option value="ltr" selected>ltr</option> <option value="rtl">rtl</option></select ><code>;</code><br /> <code>place-content:</code ><select id="alignContentAlignment"> <option value="normal">normal</option> <option value="first baseline">first baseline</option> <option value="last baseline">last baseline</option> <option value="baseline">baseline</option> <option value="space-between">space-between</option> <option value="space-around">space-around</option> <option value="space-evenly" selected>space-evenly</option> <option value="stretch">stretch</option> <option value="center">center</option> <option value="start">start</option> <option value="end">end</option> <option value="flex-start">flex-start</option> <option value="flex-end">flex-end</option> <option value="safe">safe</option> <option value="unsafe">unsafe</option> </select> <select id="justifyContentAlignment"> <option value="normal">normal</option> <option value="space-between">space-between</option> <option value="space-around">space-around</option> <option value="space-evenly">space-evenly</option> <option value="stretch">stretch</option> <option value="center" selected>center</option> <option value="start">start</option> <option value="end">end</option> <option value="flex-start">flex-start</option> <option value="flex-end">flex-end</option> <option value="left">left</option> <option value="right">right</option> <option value="safe">safe</option> <option value="unsafe">unsafe</option></select ><code>;</code> ``` ```js hidden function update() { document.getElementById("container").style.placeContent = `${document.getElementById("alignContentAlignment").value} ` + `${document.getElementById("justifyContentAlignment").value}`; } const alignContentAlignment = document.getElementById("alignContentAlignment"); alignContentAlignment.addEventListener("change", update); const justifyContentAlignment = document.getElementById( "justifyContentAlignment", ); justifyContentAlignment.addEventListener("change", update); const writingM = document.getElementById("writingMode"); writingM.addEventListener("change", (evt) => { document.getElementById("container").style.writingMode = evt.target.value; }); const direction = document.getElementById("direction"); direction.addEventListener("change", (evt) => { document.getElementById("container").style.direction = evt.target.value; }); ``` #### CSS ```css #container { display: flex; height: 240px; width: 240px; flex-wrap: wrap; background-color: #8c8c8c; writing-mode: horizontal-tb; /* Can be changed in the live sample */ direction: ltr; /* Can be changed in the live sample */ place-content: flex-end center; /* Can be changed in the live sample */ } div > div { border: 2px solid #8c8c8c; width: 50px; background-color: #a0c8ff; } .small { font-size: 12px; height: 40px; } .large { font-size: 14px; height: 50px; } ``` #### Result {{EmbedLiveSample("Placing_content_in_a_flex_container", "370", "300")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - CSS Flexbox Guide: _[Basic Concepts of Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox)_ - CSS Flexbox Guide: _[Aligning items in a flex container](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Aligning_items_in_a_flex_container)_ - CSS Grid Guide: _[Box alignment in CSS Grid layouts](/en-US/docs/Web/CSS/CSS_grid_layout/Box_alignment_in_grid_layout)_ - [CSS Box Alignment](/en-US/docs/Web/CSS/CSS_box_alignment) - The {{CSSxRef("align-content")}} property - The {{CSSxRef("justify-content")}} property
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/background-repeat/index.md
--- title: background-repeat slug: Web/CSS/background-repeat page-type: css-property browser-compat: css.properties.background-repeat --- {{CSSRef}} The **`background-repeat`** [CSS](/en-US/docs/Web/CSS) property sets how background images are repeated. A background image can be repeated along the horizontal and vertical axes, or not repeated at all. {{EmbedInteractiveExample("pages/css/background-repeat.html")}} By default, the repeated images are clipped to the size of the element, but they can be scaled to fit (using `round`) or evenly distributed from end to end (using `space`). ## Syntax ```css /* Keyword values */ background-repeat: repeat-x; background-repeat: repeat-y; background-repeat: repeat; background-repeat: space; background-repeat: round; background-repeat: no-repeat; /* Two-value syntax: horizontal | vertical */ background-repeat: repeat space; background-repeat: repeat repeat; background-repeat: round space; background-repeat: no-repeat round; /* Global values */ background-repeat: inherit; background-repeat: initial; background-repeat: revert; background-repeat: revert-layer; background-repeat: unset; ``` ### Values - `<repeat-style>` - : The one-value syntax is a shorthand for the full two-value syntax: <table class="standard-table"> <tbody> <tr> <td><strong>Single value</strong></td> <td><strong>Two-value equivalent</strong></td> </tr> <tr> <td><code>repeat-x</code></td> <td><code>repeat no-repeat</code></td> </tr> <tr> <td><code>repeat-y</code></td> <td><code>no-repeat repeat</code></td> </tr> <tr> <td><code>repeat</code></td> <td><code>repeat repeat</code></td> </tr> <tr> <td><code>space</code></td> <td><code>space space</code></td> </tr> <tr> <td><code>round</code></td> <td><code>round round</code></td> </tr> <tr> <td><code>no-repeat</code></td> <td><code>no-repeat no-repeat</code></td> </tr> </tbody> </table> In the two-value syntax, the first value represents the horizontal repetition behavior and the second value represents the vertical behavior. Here is an explanation of how each option works for either direction: <table class="standard-table"> <tbody> <tr> <td><code>repeat</code></td> <td> The image is repeated as much as needed to cover the whole background image painting area. The last image will be clipped if it doesn't fit. </td> </tr> <tr> <td><code>space</code></td> <td> The image is repeated as much as possible without clipping. The first and last images are pinned to either side of the element, and whitespace is distributed evenly between the images. The {{cssxref("background-position")}} property is ignored unless only one image can be displayed without clipping. The only case where clipping happens using <code>space</code> is when there isn't enough room to display one image. </td> </tr> <tr> <td><code>round</code></td> <td> As the allowed space increases in size, the repeated images will stretch (leaving no gaps) until there is room (space left >= half of the image width) for another one to be added. When the next image is added, all of the current ones compress to allow room. Example: An image with an original width of 260px, repeated three times, might stretch until each repetition is 300px wide, and then another image will be added. They will then compress to 225px. </td> </tr> <tr> <td><code>no-repeat</code></td> <td> The image is not repeated (and hence the background image painting area will not necessarily be entirely covered). The position of the non-repeated background image is defined by the {{cssxref("background-position")}} CSS property. </td> </tr> </tbody> </table> ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting background-repeat #### HTML ```html <ol> <li> no-repeat <div class="one"></div> </li> <li> repeat <div class="two"></div> </li> <li> repeat-x <div class="three"></div> </li> <li> repeat-y <div class="four"></div> </li> <li> space <div class="five"></div> </li> <li> round <div class="six"></div> </li> <li> repeat-x, repeat-y (multiple images) <div class="seven"></div> </li> </ol> ``` #### CSS ```css /* Shared for all DIVS in example */ ol, li { margin: 0; padding: 0; } li { margin-bottom: 12px; } div { background-image: url(starsolid.gif); width: 160px; height: 70px; } /* Background repeats */ .one { background-repeat: no-repeat; } .two { background-repeat: repeat; } .three { background-repeat: repeat-x; } .four { background-repeat: repeat-y; } .five { background-repeat: space; } .six { background-repeat: round; } /* Multiple images */ .seven { background-image: url(starsolid.gif), url(favicon32.png); background-repeat: repeat-x, repeat-y; height: 144px; } ``` #### Result In this example, each list item is matched with a different value of `background-repeat`. {{EmbedLiveSample('Setting_background-repeat', 240, 560)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Using multiple backgrounds](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders/Using_multiple_backgrounds)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_cue-region/index.md
--- title: "::cue-region" slug: Web/CSS/::cue-region page-type: css-pseudo-element browser-compat: css.selectors.cue-region spec-urls: https://w3c.github.io/webvtt/#the-cue-region-pseudo-element --- {{CSSRef}}{{SeeCompatTable}} The **`::cue-region`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) matches {{DOMxRef("WebVTT API", "WebVTT", "", 1)}} cues within a selected element. This can be used to [style captions and other cues](/en-US/docs/Web/API/WebVTT_API#styling_webvtt_cues) in media with VTT tracks. ```css ::cue-region { color: yellow; font-weight: bold; } ``` The properties are applied to the entire set of cues as if they were a single unit. The only exception is that `background` and its longhand properties apply to each cue individually, to avoid creating boxes and obscuring unexpectedly large areas of the media. ## Syntax ```css-nolint ::cue-region | ::cue-region(<selector>) { /* ... */ } ``` ## Permitted properties Rules whose selectors include this element may only use the following CSS properties: - [`background`](/en-US/docs/Web/CSS/background) - [`background-attachment`](/en-US/docs/Web/CSS/background-attachment) - [`background-clip`](/en-US/docs/Web/CSS/background-clip) - [`background-color`](/en-US/docs/Web/CSS/background-color) - [`background-image`](/en-US/docs/Web/CSS/background-image) - [`background-origin`](/en-US/docs/Web/CSS/background-origin) - [`background-position`](/en-US/docs/Web/CSS/background-position) - [`background-repeat`](/en-US/docs/Web/CSS/background-repeat) - [`background-size`](/en-US/docs/Web/CSS/background-size) - [`color`](/en-US/docs/Web/CSS/color) - [`font`](/en-US/docs/Web/CSS/font) - [`font-family`](/en-US/docs/Web/CSS/font-family) - [`font-size`](/en-US/docs/Web/CSS/font-size) - [`font-stretch`](/en-US/docs/Web/CSS/font-stretch) - [`font-style`](/en-US/docs/Web/CSS/font-style) - [`font-variant`](/en-US/docs/Web/CSS/font-variant) - [`font-weight`](/en-US/docs/Web/CSS/font-weight) - [`line-height`](/en-US/docs/Web/CSS/line-height) - [`opacity`](/en-US/docs/Web/CSS/opacity) - [`outline`](/en-US/docs/Web/CSS/outline) - [`outline-color`](/en-US/docs/Web/CSS/outline-color) - [`outline-style`](/en-US/docs/Web/CSS/outline-style) - [`outline-width`](/en-US/docs/Web/CSS/outline-width) - [`ruby-position`](/en-US/docs/Web/CSS/ruby-position) - [`text-combine-upright`](/en-US/docs/Web/CSS/text-combine-upright) - [`text-decoration`](/en-US/docs/Web/CSS/text-decoration) - [`text-decoration-color`](/en-US/docs/Web/CSS/text-decoration-color) - [`text-decoration-line`](/en-US/docs/Web/CSS/text-decoration-line) - [`text-decoration-style`](/en-US/docs/Web/CSS/text-decoration-style) - [`text-decoration-thickness`](/en-US/docs/Web/CSS/text-decoration-thickness) - [`text-shadow`](/en-US/docs/Web/CSS/text-shadow) - [`visibility`](/en-US/docs/Web/CSS/visibility) - [`white-space`](/en-US/docs/Web/CSS/white-space) ## Specifications {{Specifications}} ## Browser compatibility There is no browser implementing this feature. ## See also - Other {{DOMxRef("WebVTT API", "WebVTT", "", 1)}} selectors: - {{CSSxRef("::cue")}} - {{CSSxRef(":past")}} - {{CSSxRef(":future")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/contain/index.md
--- title: contain slug: Web/CSS/contain page-type: css-property browser-compat: css.properties.contain --- {{CSSRef}} The **`contain`** [CSS](/en-US/docs/Web/CSS) property indicates that an element and its contents are, as much as possible, independent from the rest of the document tree. Containment enables isolating a subsection of the DOM, providing performance benefits by limiting calculations of layout, style, paint, size, or any combination to a DOM subtree rather than the entire page. Containment can also be used to scope CSS counters and quotes. {{EmbedInteractiveExample("pages/css/contain.html")}} There are four types of CSS containment: size, layout, style, and paint, which are set on the container. The property is a space-separated list of a subset of the five standard values or one of the two shorthand values. Changes to the contained properties within the container are not propagated outside of the contained element to the rest of the page. The main benefit of containment is that the browser does not have to re-render the DOM or page layout as often, leading to small performance benefits during the rendering of static pages and greater performance benefits in more dynamic applications. Using the `contain` property is useful on pages with groups of elements that are supposed to be independent, as it can prevent element internals from having side effects outside of its bounding-box. > **Note:** using `layout`, `paint`, `strict` or `content` values for this property creates: > > 1. A new [containing block](/en-US/docs/Web/CSS/Containing_block) (for the descendants whose {{cssxref("position")}} property is `absolute` or `fixed`). > 2. A new [stacking context](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context). > 3. A new [block formatting context](/en-US/docs/Web/CSS/CSS_display/Block_formatting_context). ## Syntax ```css /* Keyword values */ contain: none; contain: strict; contain: content; contain: size; contain: inline-size; contain: layout; contain: style; contain: paint; /* Multiple keywords */ contain: size paint; contain: size layout paint; contain: inline-size layout; /* Global values */ contain: inherit; contain: initial; contain: revert; contain: revert-layer; contain: unset; ``` ### Values The `contain` property can have any of the following values: - The keyword `none` **or** - One or more of the space-separated keywords `size` (or `inline-size`), `layout`, `style`, and `paint` in any order **or** - One of the shorthand values `strict` or `content` The keywords have the following meanings: - `none` - : The element renders as normal, with no containment applied. - `strict` - : All containment rules are applied to the element. This is equivalent to `contain: size layout paint style`. - `content` - : All containment rules except `size` are applied to the element. This is equivalent to `contain: layout paint style`. - `size` - : Size containment is applied to the element in both the inline and block directions. The size of the element can be computed in isolation, ignoring the child elements. This value cannot be combined with `inline-size`. - `inline-size` - : Inline size containment is applied to the element. The inline size of the element can be computed in isolation, ignoring the child elements. This value cannot be combined with `size`. - `layout` - : The internal layout of the element is isolated from the rest of the page. This means nothing outside the element affects its internal layout, and vice versa. - `style` - : For properties that can affect more than just an element and its descendants, the effects don't escape the containing element. Counters and quotes are scoped to the element and its contents. - `paint` - : Descendants of the element don't display outside its bounds. If the containing box is offscreen, the browser does not need to paint its contained elements — these must also be offscreen as they are contained completely by that box. If a descendant overflows the containing element's bounds, then that descendant will be clipped to the containing element's border-box. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Paint containment The following example shows how to use `contain: paint` to prevent an element's descendants from painting outside of its bounds. ```css div { width: 100px; height: 100px; background: red; margin: 10px; font-size: 20px; } ``` ```html <div style="contain: paint"> <p>This text will be clipped to the bounds of the box.</p> </div> <div> <p>This text will not be clipped to the bounds of the box.</p> </div> ``` {{EmbedLiveSample("Paint_containment", "100%", 280)}} ### Layout containment Consider the example below which shows how elements behave with and without layout containment applied: ```html <div class="card" style="contain: layout;"> <h2>Card 1</h2> <div class="fixed"><p>Fixed box 1</p></div> <div class="float"><p>Float box 1</p></div> </div> <div class="card"> <h2>Card 2</h2> <div class="fixed"><p>Fixed box 2</p></div> <div class="float"><p>Float box 2</p></div> </div> <div class="card"> <h2>Card 3</h2> <!-- ... --> </div> ``` ```css hidden p { margin: 4px; padding: 4px; } h2 { margin-bottom: 4px; padding: 10px; } div { border-radius: 4px; box-shadow: 0 2px 4px 0 gray; padding: 6px; margin: 6px; } ``` ```css .card { width: 70%; height: 90px; } .fixed { position: fixed; right: 10px; top: 10px; background: coral; } .float { float: left; margin: 10px; background: aquamarine; } ``` The first card has layout containment applied, and its layout is isolated from the rest of the page. We can reuse this card in other places on the page without worrying about layout recalculation of the other elements. If floats overlap the card bounds, elements on the rest of the page are not affected. When the browser recalculates the containing element's subtree, only that element is recalculated. Nothing outside of the contained element needs to be recalculated. Additionally, the fixed box uses the card as a layout container to position itself. The second and third cards have no containment. The layout context for the fixed box in the second card is the root element so the fixed box is positioned in the top right corner of the page. A float overlaps the second card's bounds causing the third card to have unexpected layout shift that's visible in the positioning of the `<h2>` element. When recalculation occurs, it is not limited to a container. This impacts performance and interferes with the rest of the page layout. {{EmbedLiveSample("Layout_containment", "100%", 350)}} ### Style containment Style containment scopes [counters](/en-US/docs/Web/CSS/CSS_counter_styles/Using_CSS_counters) and [quotes](/en-US/docs/Web/CSS/quotes) to the contained element. For CSS counters, the {{cssxref("counter-increment")}} and {{cssxref("counter-set")}} properties are scoped to the element as if the element is at the root of the document. #### Containment and counters The example below takes a look at how counters work when style containment is applied: ```html <ul> <li>Item A</li> <li>Item B</li> <li class="container">Item C</li> <li>Item D</li> <li>Item E</li> </ul> ``` ```css body { counter-reset: list-items; } li::before { counter-increment: list-items; content: counter(list-items) ": "; } .container { contain: style; } ``` Without containment, the counter would increment from 1 to 5 for each list item. Style containment causes the {{cssxref("counter-increment")}} property to be scoped to the element's subtree and the counter begins again at 1: {{EmbedLiveSample('Containment_and_counters', '100%', 140)}} #### Containment and quotes CSS quotes are similarly affected in that the [`content`](/en-US/docs/Web/CSS/content) values relating to quotes are scoped to the element: ```html <!-- With style containment --> <span class="open-quote"> outer <span style="contain: style;"> <span class="open-quote"> inner </span> </span> </span> <span class="close-quote"> close </span> <br /> <!-- Without containment --> <span class="open-quote"> outer <span> <span class="open-quote"> inner </span> </span> </span> <span class="close-quote"> close </span> ``` ```css body { quotes: "[" "]" "‹" "›"; } .open-quote:before { content: open-quote; } .close-quote:after { content: close-quote; } ``` Because of containment, the first closing quote ignores the inner span and uses the outer span's closing quote instead: {{EmbedLiveSample('Containment_and_quotes', '100%', 40)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS containment](/en-US/docs/Web/CSS/CSS_containment) - [CSS container queries](/en-US/docs/Web/CSS/CSS_containment/Container_queries) - CSS {{cssxref("content-visibility")}} property - CSS {{cssxref("position")}} property
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_generated_content/index.md
--- title: CSS generated content slug: Web/CSS/CSS_generated_content page-type: css-module spec-urls: https://drafts.csswg.org/css-content/ --- {{CSSRef}} The **CSS generated content** module defines how an element's content can be replaced and content can be added to a document with CSS. Generated content can be used for content replacement, in which case the content of a DOM node is replaced with a CSS `<image>`. The CSS generated content also enables generating language-specific quotes, creating custom list item numbers and bullets, and visually adding content by generating content on select pseudo-elements as anonymous replaced elements. ### Generated content in action {{EmbedGHLiveSample("css-examples/modules/generated_content.html", '100%',420)}} The HTML for this sample is a single, empty {{HTMLElement("div")}} inside an otherwise empty {{HTMLElement("body")}}. The snowman was created with [CSS images](/en-US/docs/Web/CSS/CSS_images) and [CSS backgrounds and borders](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders). The carrot nose was added using generated content: an empty box with a wide orange {{cssxref("border-left", "left border")}} added to the {{cssxref("::before")}} pseudo-element. The text is also generated content: "only one &lt;div>" was generated with the {{cssxref("content")}} property applied to the {{cssxref("::after")}} pseudo-element. To see the code for this animation, [view the source on GitHub](https://github.com/mdn/css-examples/blob/main/modules/generated_content.html). ## Reference ### Properties - {{cssxref("content")}} - {{cssxref("quotes")}} > **Note:** The CSS generated content module introduces four at-risk properties that have not been implemented: `string-set`, `bookmark-label`, `bookmark-level`, and `bookmark-state`. ### Functions The CSS generated content module introduces six yet-to-be implemented CSS functions including `content()`, `string()`, and `leader()`, and the three [`<target>`](/en-US/docs/Web/CSS/content#target) functions `target-counter()`, `target-counters()`, and `target-text()`. ### Data types - [`<content-list>`](/en-US/docs/Web/CSS/content#content-list) - `<content-replacement>` (see {{cssxref("image")}}) - {{cssxref("image")}} - [`<counter>`](/en-US/docs/Web/CSS/content#counter) - [`<quote>`](/en-US/docs/Web/CSS/content#quote) - [`<target>`](/en-US/docs/Web/CSS/content#target) ## Guides - ["How to" guide for generated content](/en-US/docs/Learn/CSS/Howto/Generated_content) - : Learn how to add text or image content to a document using the {{cssxref("content")}} property. - [Create fancy boxes with generated content](/en-US/docs/Learn/CSS/Howto/Create_fancy_boxes) - : Example of styling generated content for visual effects. ## Related concepts - [CSS pseudo-elements](/en-US/docs/Web/CSS/CSS_pseudo-elements) module - {{cssxref("::before")}} pseudo-element - {{cssxref("::after")}} pseudo-element - {{cssxref("::marker")}} pseudo-element - [CSS lists and counters](/en-US/docs/Web/CSS/CSS_lists) module - {{cssxref("counter", "counter()")}} function - {{cssxref("counters", "counters()")}} function - {{cssxref("counter-increment")}} property - {{cssxref("counter-reset")}} property - [CSS values and units](/en-US/docs/Web/CSS/CSS_Values_and_Units) module - {{cssxref("attr", "attr()")}} function - {{cssxref("string")}} data type - {{cssxref("image")}} data type ## Specifications {{Specifications}} ## See also - [CSS pseudo-elements](/en-US/docs/Web/CSS/CSS_pseudo-elements) module - [CSS lists and counters](/en-US/docs/Web/CSS/CSS_lists) module - [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/mask-border-slice/index.md
--- title: mask-border-slice slug: Web/CSS/mask-border-slice page-type: css-property browser-compat: css.properties.mask-border-slice --- {{CSSRef}} The **`mask-border-slice`** [CSS](/en-US/docs/Web/CSS) property divides the image set by {{cssxref("mask-border-source")}} into regions. These regions are used to form the components of an element's [mask border](/en-US/docs/Web/CSS/mask-border). ## Syntax ```css /* All sides */ mask-border-slice: 30%; /* top and bottom | left and right */ mask-border-slice: 10% 30%; /* top | left and right | bottom */ mask-border-slice: 30 30% 45; /* top | right | bottom | left */ mask-border-slice: 7 12 14 5; /* Using the `fill` keyword */ mask-border-slice: 10% fill 7 12; /* Global values */ mask-border-slice: inherit; mask-border-slice: initial; mask-border-slice: revert; mask-border-slice: revert-layer; mask-border-slice: unset; ``` The `mask-border-slice` property may be specified using one to four `<number-percentage>` values to represent the position of each image slice. Negative values are invalid; values greater than their corresponding dimension are clamped to `100%`. - When **one** position is specified, it creates all four slices at the same distance from their respective sides. - When **two** positions are specified, the first value creates slices measured from the **top and bottom**, the second creates slices measured from the **left and right**. - When **three** positions are specified, the first value creates a slice measured from the **top**, the second creates slices measured from the **left and right**, the third creates a slice measured from the **bottom**. - When **four** positions are specified, they create slices measured from the **top**, **right**, **bottom**, and **left** in that order (clockwise). The optional `fill` value, if used, can be placed anywhere in the declaration. ### Values - {{cssxref("&lt;number&gt;")}} - : Represents an edge offset in _pixels_ for raster images and _coordinates_ for vector images. For vector images, the number is relative to the element's size, not the size of the source image, so percentages are generally preferable in these cases. - {{cssxref("&lt;percentage&gt;")}} - : Represents an edge offset as a percentage of the source image's size: the width of the image for horizontal offsets, the height for vertical offsets. - `fill` - : Preserves the middle image region. Its width and height are sized to match the top and left image regions, respectively. ## Description The slicing process creates nine regions in total: four corners, four edges, and a middle region. Four slice lines, set a given distance from their respective sides, control the size of the regions. [![The nine regions defined by the border-image or border-image-slice properties](border-image-slice.png)](border-image-slice.png) The above diagram illustrates the location of each region. - Zones 1-4 are corner regions. Each one is used a single time to form the corners of the final border image. - Zones 5-8 are edge regions. These are [repeated, scaled, or otherwise modified](/en-US/docs/Web/CSS/mask-border-repeat) in the final border image to match the dimensions of the element. - Zone 9 is the middle region. It is discarded by default, but is used like a background image if the keyword `fill` is set. The {{cssxref("mask-border-repeat")}}, {{cssxref("mask-border-width")}}, and {{cssxref("mask-border-outset")}} properties determine how these regions are used to form the final mask border. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Basic usage This property doesn't appear to be supported anywhere yet. When it eventually starts to be supported, it will serve to define the size of the slices taken from the source image, and used to create the border mask. ```css mask-border-slice: 30 fill; ``` Chromium-based browsers support an outdated version of this property — `mask-box-image-slice` — with a prefix: ```css -webkit-mask-box-image-slice: 30 fill; ``` > **Note:** The [`mask-border`](/en-US/docs/Web/CSS/mask-border) page features a working example (using the out-of-date prefixed border mask properties supported in Chromium), so you can get an idea of the effect. > **Note:** The fill keyword needs to be included if you want the element's content to be visible. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("mask-border")}} - {{cssxref("mask-border-mode")}} - {{cssxref("mask-border-outset")}} - {{cssxref("mask-border-repeat")}} - {{cssxref("mask-border-source")}} - {{cssxref("mask-border-width")}} - [Illustrated description of the 1-to-4-value syntax](/en-US/docs/Web/CSS/Shorthand_properties#tricky_edge_cases)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-block-start-style/index.md
--- title: border-block-start-style slug: Web/CSS/border-block-start-style page-type: css-property browser-compat: css.properties.border-block-start-style --- {{CSSRef}} The **`border-block-start-style`** [CSS](/en-US/docs/Web/CSS) property defines the style of the logical block start border of an element, which maps to a physical border style depending on the element's writing mode, directionality, and text orientation. It corresponds to the {{cssxref("border-top-style")}}, {{cssxref("border-right-style")}}, {{cssxref("border-bottom-style")}}, or {{cssxref("border-left-style")}} property depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. {{EmbedInteractiveExample("pages/css/border-block-start-style.html")}} ## Syntax ```css /* <'border-style'> values */ border-block-start-style: dashed; border-block-start-style: dotted; border-block-start-style: groove; /* Global values */ border-block-start-style: inherit; border-block-start-style: initial; border-block-start-style: revert; border-block-start-style: revert-layer; border-block-start-style: unset; ``` Related properties are {{cssxref("border-block-end-style")}}, {{cssxref("border-inline-start-style")}}, and {{cssxref("border-inline-end-style")}}, which define the other border styles of the element. ### Values - `<'border-style'>` - : The line style of the border. See {{ cssxref("border-style") }}. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Dashed 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-lr; border: 5px solid blue; border-block-start-style: dashed; } ``` #### Results {{EmbedLiveSample("Dashed_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-style")}}, {{cssxref("border-right-style")}}, {{cssxref("border-bottom-style")}}, or {{cssxref("border-left-style")}}. - {{cssxref("writing-mode")}}, {{cssxref("direction")}}, {{cssxref("text-orientation")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-block-start-width/index.md
--- title: border-block-start-width slug: Web/CSS/border-block-start-width page-type: css-property browser-compat: css.properties.border-block-start-width --- {{CSSRef}} The **`border-block-start-width`** [CSS](/en-US/docs/Web/CSS) property defines the width of the logical block-start border of an element, which maps to a physical border width depending on the element's writing mode, directionality, and text orientation. It corresponds to the {{cssxref("border-top-width")}}, {{cssxref("border-right-width")}}, {{cssxref("border-bottom-width")}}, or {{cssxref("border-left-width")}} property depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. {{EmbedInteractiveExample("pages/css/border-block-start-width.html")}} ## Syntax ```css /* <'border-width'> values */ border-block-start-width: 5px; border-block-start-width: thick; /* Global values */ border-block-start-width: inherit; border-block-start-width: initial; border-block-start-width: revert; border-block-start-width: revert-layer; border-block-start-width: unset; ``` Related properties are {{cssxref("border-block-end-width")}}, {{cssxref("border-inline-start-width")}}, and {{cssxref("border-inline-end-width")}}, which define the other border widths of the element. ### Values - `<'border-width'>` - : The width of the border. See {{ cssxref("border-width") }}. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Border width with vertical text #### HTML ```html <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ```css div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; border: 1px solid blue; border-block-start-width: 5px; } ``` #### Results {{EmbedLiveSample("Border_width_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-width")}}, {{cssxref("border-right-width")}}, {{cssxref("border-bottom-width")}}, and {{cssxref("border-left-width")}} - {{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/column-count/index.md
--- title: column-count slug: Web/CSS/column-count page-type: css-property browser-compat: css.properties.column-count --- {{CSSRef}} The **`column-count`** [CSS](/en-US/docs/Web/CSS) property breaks an element's content into the specified number of columns. {{EmbedInteractiveExample("pages/css/column-count.html")}} ## Syntax ```css /* Keyword value */ column-count: auto; /* <integer> value */ column-count: 3; /* Global values */ column-count: inherit; column-count: initial; column-count: revert; column-count: revert-layer; column-count: unset; ``` ### Values - `auto` - : The number of columns is determined by other CSS properties, such as {{cssxref("column-width")}}. - {{cssxref("&lt;integer&gt;")}} - : Is a strictly positive {{cssxref("&lt;integer&gt;")}} describing the ideal number of columns into which the content of the element will be flowed. If the {{cssxref("column-width")}} is also set to a non-`auto` value, it merely indicates the maximum allowed number of columns. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Splitting a paragraph across three columns #### HTML ```html <p class="content-box"> This is a bunch of text split into three columns using the CSS `column-count` property. The text is equally distributed over the columns. </p> ``` #### CSS ```css .content-box { column-count: 3; } ``` #### Result {{EmbedLiveSample('Splitting_a_paragraph_across_three_columns', 'auto', 120)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSXref("column-width")}}, {{CSSXref("columns")}} shorthand - {{CSSXref("column-rule-color")}}, {{CSSXref("column-rule-style")}}, {{CSSXref("column-rule-width")}}, {{CSSXref("column-rule")}} shorthand - [Multiple-column Layout](/en-US/docs/Learn/CSS/CSS_layout/Multiple-column_Layout) (Learn Layout) - [Basic Concepts of Multicol](/en-US/docs/Web/CSS/CSS_multicol_layout/Basic_concepts)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/perspective/index.md
--- title: perspective slug: Web/CSS/perspective page-type: css-property browser-compat: css.properties.perspective --- {{CSSRef}} The **`perspective`** [CSS](/en-US/docs/Web/CSS) property determines the distance between the z=0 plane and the user in order to give a 3D-positioned element some perspective. {{EmbedInteractiveExample("pages/css/perspective.html")}} ## Syntax ```css /* Keyword value */ perspective: none; /* <length> values */ perspective: 20px; perspective: 3.5em; /* Global values */ perspective: inherit; perspective: initial; perspective: revert; perspective: revert-layer; perspective: unset; ``` ### Values - `none` - : Indicates that no perspective transform is to be applied. - `<length>` - : A {{cssxref("&lt;length&gt;")}} giving the distance from the user to the z=0 plane. It is used to apply a perspective transform to the children of the element. Negative values are syntax errors. If the value is smaller than `1px`, it is clamped to `1px`. ## Description Each 3D element with z>0 becomes larger; each 3D-element with z<0 becomes smaller. The strength of the effect is determined by the value of this property. Large values of `perspective` cause a small transformation; small values of `perspective` cause a large transformation. The parts of the 3D elements that are behind the user — i.e. their z-axis coordinates are greater than the value of the `perspective` CSS property — are not drawn. The _vanishing point_ is by default placed at the center of the element, but its position can be changed using the {{cssxref("perspective-origin")}} property. Using this property with a value other than `none` creates a new [stacking context](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context). Also, in that case, the object will act as a containing block for `position: fixed` elements that it contains. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting perspective An example showing how a cube varies if the `perspective` is set at different positions is given in [Using CSS transforms > Setting perspective](/en-US/docs/Web/CSS/CSS_transforms/Using_CSS_transforms#setting_perspective). ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Using CSS Transforms](/en-US/docs/Web/CSS/CSS_transforms/Using_CSS_transforms)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/fit-content_function/index.md
--- title: fit-content() slug: Web/CSS/fit-content_function page-type: css-function browser-compat: - css.properties.grid-template-columns.fit-content - css.properties.width.fit-content_function --- {{CSSRef}} The **`fit-content()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) clamps a given size to an available size according to the formula `min(maximum size, max(minimum size, argument))`. {{EmbedInteractiveExample("pages/css/function-fit-content.html")}} The function can be used as a track size in [CSS Grid](/en-US/docs/Web/CSS/CSS_grid_layout) properties, where the maximum size is defined by `max-content` and the minimum size by `auto`, which is calculated similar to `auto` (i.e., [`minmax(auto, max-content)`](/en-US/docs/Web/CSS/minmax)), except that the track size is clamped at _argument_ if it is greater than the `auto` minimum. See the {{cssxref("grid-template-columns")}} page for more information on the `max-content` and `auto` keywords. The `fit-content()` function can also be used as laid out box size for {{cssxref("width")}}, {{cssxref("height")}}, {{cssxref("min-width")}}, {{cssxref("min-height")}}, {{cssxref("max-width")}} and {{cssxref("max-height")}}, where the maximum and minimum sizes refer to the content size. ## Syntax The `fit-content()` function accepts a `<length>` or a `<percentage>` as an argument. ```css /* <length> values */ fit-content(200px) fit-content(5cm) fit-content(30vw) fit-content(100ch) /* <percentage> value */ fit-content(40%) ``` ### Values - {{cssxref("&lt;length&gt;")}} - : An absolute length. - {{cssxref("&lt;percentage&gt;")}} - : A percentage relative to the available space in the given axis. In grid properties it is relative to the inline size of the grid container in column tracks and to the block size of the grid container for row tracks. Otherwise it is relative to the available inline size or block size of the laid out box depending on the writing mode. ## Examples ### Sizing grid columns with fit-content #### HTML ```html <div id="container"> <div>Item as wide as the content.</div> <div> Item with more text in it. Because the contents of it are wider than the maximum width, it is clamped at 300 pixels. </div> <div>Flexible item</div> </div> ``` #### CSS ```css #container { display: grid; grid-template-columns: fit-content(300px) fit-content(300px) 1fr; grid-gap: 5px; box-sizing: border-box; height: 200px; width: 100%; background-color: #8cffa0; padding: 10px; } #container > div { background-color: #8ca0ff; padding: 5px; } ``` #### Result {{EmbedLiveSample("Sizing_grid_columns_with_fit-content", "100%", 200)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Related sizing keywords: {{cssxref("min-content")}}, {{cssxref("max-content")}} - Related CSS Grid properties: {{cssxref("grid-template")}}, {{cssxref("grid-template-rows")}}, {{cssxref("grid-template-columns")}}, {{cssxref("grid-template-areas")}}, {{cssxref("grid-auto-columns")}}, {{cssxref("grid-auto-rows")}}, {{cssxref("grid-auto-flow")}} - Grid Layout Guide: _[Line-based placement with CSS Grid](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_layout_using_line-based_placement)_ - Grid Layout Guide: _[Grid template areas - Grid definition shorthands](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_template_areas#grid_definition_shorthands)_
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/clear/index.md
--- title: clear slug: Web/CSS/clear page-type: css-property browser-compat: css.properties.clear --- {{CSSRef}} The **`clear`** [CSS](/en-US/docs/Web/CSS) property sets whether an element must be moved below (cleared) [floating](/en-US/docs/Web/CSS/float) elements that precede it. The `clear` property applies to floating and non-floating elements. {{EmbedInteractiveExample("pages/css/clear.html")}} When applied to non-floating blocks, it moves the [border edge](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model#border_area) of the element down until it is below the [margin edge](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model#margin_area) of all relevant floats. The non-floated block's top margin collapses. Vertical margins between two floated elements on the other hand will not collapse. When applied to floating elements, the margin edge of the bottom element is moved below the margin edge of all relevant floats. This affects the position of later floats, since later floats cannot be positioned higher than earlier ones. The floats that are relevant to be cleared are the earlier floats within the same [block formatting context](/en-US/docs/Web/CSS/CSS_display/Block_formatting_context). > **Note:** If an element contains only floated elements, its height collapses to nothing. If you want it to always be able to resize, so that it contains floating elements inside it, set the value of the element's [`display`](/en-US/docs/Web/CSS/display) property to [`flow-root`](/en-US/docs/Web/CSS/display#flow-root). > > ```css > #container { > display: flow-root; > } > ``` ## Syntax ```css /* Keyword values */ clear: none; clear: left; clear: right; clear: both; clear: inline-start; clear: inline-end; /* Global values */ clear: inherit; clear: initial; clear: revert; clear: revert-layer; clear: unset; ``` ### Values - `none` - : Is a keyword indicating that the element is _not_ moved down to clear past floating elements. - `left` - : Is a keyword indicating that the element is moved down to clear past _left_ floats. - `right` - : Is a keyword indicating that the element is moved down to clear past _right_ floats. - `both` - : Is a keyword indicating that the element is moved down to clear past _both_ left and right floats. - `inline-start` - : Is a keyword indicating that the element is moved down to clear floats on _start side of its containing block_, that is the _left_ floats on ltr scripts and the _right_ floats on rtl scripts. - `inline-end` - : Is a keyword indicating that the element is moved down to clear floats on _end side of its containing block_, that is the _right_ floats on ltr scripts and the _left_ floats on rtl scripts. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### clear: left #### HTML ```html <div class="wrapper"> <p class="black"> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus sit amet diam. Duis mattis varius dui. Suspendisse eget dolor. </p> <p class="red">Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p> <p class="left">This paragraph clears left.</p> </div> ``` #### CSS ```css .wrapper { border: 1px solid black; padding: 10px; } .left { border: 1px solid black; clear: left; } .black { float: left; margin: 0; background-color: black; color: #fff; width: 20%; } .red { float: left; margin: 0; background-color: pink; width: 20%; } p { width: 50%; } ``` {{ EmbedLiveSample('clear_left','100%','250') }} ### clear: right #### HTML ```html <div class="wrapper"> <p class="black"> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus sit amet diam. Duis mattis varius dui. Suspendisse eget dolor. </p> <p class="red">Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p> <p class="right">This paragraph clears right.</p> </div> ``` #### CSS ```css .wrapper { border: 1px solid black; padding: 10px; } .right { border: 1px solid black; clear: right; } .black { float: right; margin: 0; background-color: black; color: #fff; width: 20%; } .red { float: right; margin: 0; background-color: pink; width: 20%; } p { width: 50%; } ``` {{ EmbedLiveSample('clear_right','100%','250') }} ### clear: both #### HTML ```html <div class="wrapper"> <p class="black"> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus sit amet diam. Duis mattis varius dui. Suspendisse eget dolor. Fusce pulvinar lacus ac dui. </p> <p class="red"> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus sit amet diam. Duis mattis varius dui. Suspendisse eget dolor. </p> <p class="both">This paragraph clears both.</p> </div> ``` #### CSS ```css .wrapper { border: 1px solid black; padding: 10px; } .both { border: 1px solid black; clear: both; } .black { float: left; margin: 0; background-color: black; color: #fff; width: 20%; } .red { float: right; margin: 0; background-color: pink; width: 20%; } p { width: 45%; } ``` {{ EmbedLiveSample('clear_both','100%','300') }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS basic 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/nesting_selector/index.md
--- title: "& nesting selector" slug: Web/CSS/Nesting_selector page-type: css-selector browser-compat: css.selectors.nesting --- {{CSSRef}} The CSS **`&` nesting selector** explicitly states the relationship between parent and child rules when using [CSS nesting](/en-US/docs/Web/CSS/CSS_nesting). It makes the nested child rule selectors _relative to the parent element_. Without the `&` nesting selector, the child rule selector selects child elements. The child rule selectors have the same [specificity](/en-US/docs/Web/CSS/CSS_nesting/Nesting_and_specificity) weight as if they were within {{cssxref(":is", ":is()")}}. > **Note:** _Child rule_ does not mean _child element selector_. A child rule can target parent element or child elements depending on use of the `&` nesting selector. If not used in nested style rule, the `&` nesting selector represents the [scoping root](/en-US/docs/Web/CSS/:scope). ## Syntax ```css parentRule { /* parent rule style properties */ & childRule { /* child rule style properties */ } } ``` ### `&` nesting selector and whitespace Consider the following code where nesting is done _without_ the `&` nesting selector. ```css .parent-rule { /* parent rule properties */ .child-rule { /* child rule properties */ } } ``` When the browser parses the nested selectors, it automatically adds whitespace between the selectors to create a new CSS selector rule. The following code shows the equivalent non-nested rules: ```css .parent-rule { /* parent rule style properties */ } .parent-rule .child-rule { /* style properties for .child-rule descendants for .parent-rule ancestors */ } ``` When the nested rule needs to be attached (with no whitespace) to the parent rule, such as when using a {{cssxref('Pseudo-classes', 'pseudo-class')}} or creating [compound selectors](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#compound_selector), the `&` nesting selector must be immediately prepended to achieve the desired effect. Consider an example where we want to style an element, providing styles to be applied at all times, and also nesting some styles to be applied only on hover. If the `&` nesting selector is not included, whitespace is added and we end up with a ruleset that applies the nested styles to any _hovered descendant of the parent rule selector_. This is, however, not what we want. ```css .parent-rule { /* parent rule properties */ :hover { /* child rule properties */ } } /* the browser parses the above nested rules as shown below */ .parent-rule { /* parent rule properties */ } .parent-rule *:hover { /* child rule properties */ } ``` With the `&` nesting selector added with no whitespace, the elements matched by the parent rule will be styled when hovered. ```css .parent-rule { /* parent rule properties */ &:hover { /* child rule properties */ } } /* the browser parses the above nested rules as shown below */ .parent-rule { /* parent rule properties */ } .parent-rule:hover { /* child rule properties */ } ``` ## Appending the `&` nesting selector The `&` nesting selector can also be appended to reverse the context of the rules. ```css .card { /* .card styles */ .featured & { /* .featured .card styles */ } } /* the browser parses above nested rules as */ .card { /* .card styles */ } .featured .card { /* .featured .card styles */ } ``` The `&` nesting selector can be placed multiple times: ```css .card { /* .card styles */ .featured & & & { /* .featured .card .card .card styles */ } } /* the browser parses above nested rules as */ .card { /* .card styles */ } .featured .card .card .card { /* .featured .card .card .card styles */ } ``` ## Examples Both of the following examples produce the same output. The first one uses normal CSS styles and the second one uses the `&` nesting selector. ### Using normal CSS styles This example uses normal CSS styling. #### HTML ```html <p class="example"> This paragraph <a href="#">contains a link</a>, try hovering or focusing it. </p> ``` #### CSS ```css .example { font-family: system-ui; font-size: 1.2rem; } .example > a { color: tomato; } .example > a:hover, .example > a:focus { color: ivory; background-color: tomato; } ``` #### Result {{EmbedLiveSample('Original_CSS_styles','100%','65')}} ### Using `&` in nested CSS styles This example uses nested CSS styling. #### HTML ```html <p class="example"> This paragraph <a href="#">contains a link</a>, try hovering or focusing it. </p> ``` #### CSS ```css .example { font-family: system-ui; font-size: 1.2rem; & > a { color: tomato; &:hover, &:focus { color: ivory; background-color: tomato; } } } ``` #### Result {{EmbedLiveSample('Nested_CSS_styles','100%','65')}} ### Using `&` outside nested rule If not used in nested style rule, the `&` nesting selector represents the [scoping root](/en-US/docs/Web/CSS/:scope). ```html <p>Hover over the output box to change document's background color.</p> ``` ```css & { color: blue; font-weight: bold; } &:hover { background-color: wheat; } ``` #### Result In this case, all the styles apply to [document](/en-US/docs/Web/API/Document). {{EmbedLiveSample('Usage_outside_nested_rule','100%','65')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Using CSS nesting](/en-US/docs/Web/CSS/CSS_nesting/Using_CSS_nesting) - [CSS nesting](/en-US/docs/Web/CSS/CSS_nesting) module - [CSS selectors](/en-US/docs/Web/CSS/CSS_selectors) module
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/dashed-ident/index.md
--- title: <dashed-ident> slug: Web/CSS/dashed-ident page-type: css-type spec-urls: https://drafts.csswg.org/css-values/#dashed-idents --- {{CSSRef}} The **`<dashed-ident>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) denotes an arbitrary string used as an {{glossary("identifier")}}. ## Syntax The syntax of `<dashed-ident>` is similar to CSS identifiers (such as property names), except that it is [case-sensitive](https://en.wikipedia.org/wiki/Case_sensitivity). It starts with two dashes, followed by the user-defined identifier. The double dash at the beginning makes them easily identifiable when reading through a CSS code block, and helps to avoid name clashes with standard CSS keywords. Just like [`<custom-ident>`](/en-US/docs/Web/CSS/custom-ident) `<dashed-ident>`s are defined by the user, but unlike `<custom-ident>` [CSS](/en-US/docs/Web/CSS) will never define a `<dashed-ident>`. ## Examples ### Using with CSS custom properties When `<dashed-ident>` is used with [CSS custom properties](/en-US/docs/Web/CSS/Using_CSS_custom_properties), the property is declared first and then used within a [CSS var() function](/en-US/docs/Web/CSS/var). ```css html { --primary-color: red; --secondary-color: blue; --tertiary-color: green; } h1, h4 { color: var(--primary-color); } h2, h5 { color: var(--secondary-color); } h3, h6 { color: var(--tertiary-color); } ``` ### Using with @color-profile When `<dashed-ident>` is used with the [@color-profile](/en-US/docs/Web/CSS/@color-profile) at-rule, the at-rule is declared first and then used within a [CSS color() function](/en-US/docs/Web/CSS/color_value/color). ```css @color-profile --my-color-profile { src: url("https://example.org/SWOP2006_Coated5v2.icc"); } .header { background-color: color(--my-color-profile 0% 70% 20% 0%); } ``` ### Using with @font-palette-values When `<dashed-ident>` is used with the [@font-palette-values](/en-US/docs/Web/CSS/@font-palette-values) at-rule, the at-rule is declared first and then used as the value for the [font-palette](/en-US/docs/Web/CSS/font-palette) property. ```css @font-palette-values --my-palette { font-family: Bixa; base-palette: 1; override-colors: 0 #ff0000; } h1, h2, h3, h4 { font-palette: --my-palette; } ``` ## Specifications {{Specifications}} ## Browser compatibility _As this type is not a real type but a convenience type used to simplify the definition of other CSS syntax, there is no browser compatibility information as such._ ## See also - [&lt;ident&gt;](/en-US/docs/Web/CSS/ident) - [&lt;custom-ident&gt;](/en-US/docs/Web/CSS/custom-ident)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_fonts/index.md
--- title: CSS fonts slug: Web/CSS/CSS_fonts page-type: css-module spec-urls: https://drafts.csswg.org/css-fonts/ --- {{CSSRef}} The **CSS fonts** module defines font-related properties and how font resources are loaded. It lets you define the style of a font, such as its family, size and weight, and the glyph variants to use when multiple are available for a single character. A font is a resource file containing the visual representation of characters, mapping character codes to glyphs that represent letters, numbers, punctuation and even emojis of a typeface. A font family is a group of fonts that share common design styles and font properties, with each member of the group providing different ways of displaying the glyphs, varying by stroke weight, slant, or relative width, among other attributes. A font typically represents a single style of a typeface, such as Helvetica that is Bold and Italic. A font family is the complete set of styles. Including such a font in a document or design is done by defining a separate `@font-face` declaration for each font resource. The properties, at-rules, and descriptors of the CSS fonts module enable the downloading of multiple variations of a font. They also define the font file to use for a particular font characteristic, along with fallback instructions in case a resource fails to load. The CSS font selection mechanism describes the process of matching a given set of CSS font properties to a single font face. The CSS fonts module also supports variable fonts. Unlike regular fonts, where each style is implemented as a separate font file, variable fonts can contain all styles within a single file. By using a single `@font-face` declaration, you can import a variable font that includes all the styles. Depending on the font, this can include a multitude of font variants. Variable fonts are a part of the OpenType font specification. ## Reference ### Properties - {{cssxref("font")}} shorthand - {{cssxref("font-family")}} - {{cssxref("font-feature-settings")}} - {{cssxref("font-kerning")}} - {{cssxref("font-language-override")}} - {{cssxref("font-optical-sizing")}} - {{cssxref("font-palette")}} - {{cssxref("font-size")}} - {{cssxref("font-size-adjust")}} - {{cssxref("font-stretch")}} - {{cssxref("font-style")}} - {{cssxref("font-weight")}} - {{cssxref("font-synthesis")}} shorthand - {{cssxref("font-synthesis-small-caps")}} - {{cssxref("font-synthesis-style")}} - {{cssxref("font-synthesis-weight")}} - {{cssxref("font-variant")}} shorthand - {{cssxref("font-variant-alternates")}} - {{cssxref("font-variant-caps")}} - {{cssxref("font-variant-east-asian")}} - {{cssxref("font-variant-emoji")}} - {{cssxref("font-variant-ligatures")}} - {{cssxref("font-variant-numeric")}} - {{cssxref("font-variant-position")}} - {{cssxref("font-variation-settings")}} ### At-rules and descriptors - At-rule: {{cssxref("@font-face")}} - : Descriptors: - {{cssxref("@font-face/ascent-override", "ascent-override")}} - {{cssxref("@font-face/descent-override", "descent-override")}} - {{cssxref("@font-face/font-display", "font-display")}} - {{cssxref("@font-face/font-family", "font-family")}} - {{cssxref("@font-face/font-feature-settings", "font-feature-settings")}} - {{cssxref("@font-face/font-stretch", "font-stretch")}} - {{cssxref("@font-face/font-style", "font-style")}} - {{cssxref("@font-face/font-variation-settings", "font-variation-settings")}} - {{cssxref("@font-face/font-weight", "font-weight")}} - {{cssxref("@font-face/line-gap-override", "line-gap-override")}} - {{cssxref("@font-face/size-adjust", "size-adjust")}} - {{cssxref("@font-face/src", "src")}} - {{cssxref("@font-face/unicode-range", "unicode-range")}} - At-rule: {{cssxref("@font-feature-values")}} - : Descriptor: - {{cssxref("@font-feature-values/font-display", "font-display")}} - At-rule: {{cssxref("@font-palette-values")}} - : Descriptors: - {{cssxref("@font-palette-values/base-palette", "base-palette")}} - {{cssxref("@font-palette-values/font-family", "font-family")}} - {{cssxref("@font-palette-values/override-colors", "override-colors")}} ### Data types `font-size` types: - {{cssxref("absolute-size")}} - {{cssxref("relative-size")}} `font-family` type: - {{cssxref("generic-family")}} `font-feature-settings` type: - [`<feature-tag-value>`](/en-US/docs/Web/CSS/font-feature-settings#values) `font-format` type: - [`<font-format>`](/en-US/docs/Web/CSS/@supports#font-format) `font-stretch` type: - [`<font-stretch-css3>`](/en-US/docs/Web/CSS/font-stretch#values) `font-tech` types: - [`<color-font-tech>`](/en-US/docs/Web/CSS/@supports#font-tech) - [`<font-features-tech>`](/en-US/docs/Web/CSS/@supports#font-tech) - [`<font-tech>`](/en-US/docs/Web/CSS/@supports#font-tech) `font-variant` types: - [`<font-variant-css2>`](/en-US/docs/Web/CSS/font-variant) - [`<east-asian-variant-values>`](/en-US/docs/Web/CSS/font-variant#values) - [`<east-asian-width-values>`](/en-US/docs/Web/CSS/font-variant#values) `font-variant-ligatures` types: - [`<common-lig-values>`](/en-US/docs/Web/CSS/font-variant-ligatures#values) - [`<contextual-alt-values>`](/en-US/docs/Web/CSS/font-variant-ligatures#values) - [`<discretionary-lig-values>`](/en-US/docs/Web/CSS/font-variant-ligatures#values) - [`<historical-lig-values>`](/en-US/docs/Web/CSS/font-variant-ligatures#values) `font-variant-numeric` types: - [`<numeric-figure-values>`](/en-US/docs/Web/CSS/font-variant-numeric#values) - [`<numeric-fraction-values>`](/en-US/docs/Web/CSS/font-variant-numeric#values) - [`<numeric-spacing-values>`](/en-US/docs/Web/CSS/font-variant-numeric#values) `font-weight` type: - [`<font-weight-absolute>`](/en-US/docs/Web/CSS/font-weight#values) ### Interfaces - {{domxref("CSSFontFaceRule")}} - {{domxref("CSSFontFeatureValuesRule")}} - {{domxref("CSSFontPaletteValuesRule")}} ## Guides - [Learn: Fundamental text and font styling](/en-US/docs/Learn/CSS/Styling_text/Fundamentals) - : This beginner's learning article covers the basic fundamentals of text and font styling. It covers how to set the font weight, family, and style by using the {{cssxref("font")}} shorthand and how to align text and manage line and letter spacing. - [Learn: Web fonts](/en-US/docs/Learn/CSS/Styling_text/Web_fonts) - : This beginner's learning article explains how to use custom fonts on your web page to allow for more varied and custom text styling. - [OpenType font features guide](/en-US/docs/Web/CSS/CSS_fonts/OpenType_fonts_guide) - : Font features or variants refer to different glyphs or character styles contained within an OpenType font. These include things like ligatures (special glyphs that combine characters like 'fi' or 'ffl'), kerning (adjustments to the spacing between specific letterform pairings), fractions, numeral styles, and a number of others. These are all referred to as OpenType Features, and are made available to use on the web via specific properties and a low-level control property — {{cssxref("font-feature-settings")}}. This article provides you with all you need to know about using OpenType font features in CSS. - [Variable fonts guide](/en-US/docs/Web/CSS/CSS_fonts/Variable_fonts_guide) - : This article will help you get started with using variable fonts. - [Improving font performance](/en-US/docs/Learn/Performance/CSS#improving_font_performance) - : This article, part of the CSS performance guide, discusses font loading, loading only the required glyphs, and defining font display behavior with the `font-display` descriptor. ## Related concepts - {{cssxref("letter-spacing")}} CSS property - {{cssxref("line-height")}} CSS property - {{cssxref("text-transform")}} CSS property ## Specifications {{Specifications}} ## See also - [CSS font loading](/en-US/docs/Web/CSS/CSS_font_loading) module - [CSS font loading API](/en-US/docs/Web/API/CSS_Font_Loading_API) - [CSS text](/en-US/docs/Web/CSS/CSS_text) module - [CSS writing modes](/en-US/docs/Web/CSS/CSS_writing_modes) module
0
data/mdn-content/files/en-us/web/css/css_fonts
data/mdn-content/files/en-us/web/css/css_fonts/woff/index.md
--- title: The Web Open Font Format (WOFF) slug: Web/CSS/CSS_fonts/WOFF page-type: guide browser-compat: - css.at-rules.font-face.WOFF - css.at-rules.font-face.WOFF_2 --- **WOFF** (the **Web Open Font Format**) is a web font format developed by Mozilla in concert with Type Supply, LettError, and other organizations. It uses a compressed version of the same table-based `sfnt` structure used by TrueType, OpenType, and Open Font Format, but adds metadata and private-use data structures, including predefined fields allowing foundries and vendors to provide license information if desired. There are three main benefits to using WOFF: 1. The font data is compressed, so sites using WOFF will use less bandwidth and will load faster than if they used equivalent uncompressed TrueType or OpenType files. 2. Many font vendors that are unwilling to license their TrueType or OpenType format fonts for use on the web will license WOFF format fonts. This improves availability of fonts to site designers. 3. Both proprietary and free software browser vendors like the WOFF format, so it has the potential of becoming a truly universal, interoperable font format for the web, unlike other current font formats. There are two versions of WOFF: WOFF and WOFF2. They mostly differ in regard to the compression algorithm used. In {{cssxref("@font-face")}} they are identified by the `'woff'` and `'woff2'` format descriptor respectively. ## Using WOFF You can use the {{cssxref("@font-face")}} CSS property to use WOFF fonts for text in web content. It works exactly like OpenType and TrueType format fonts do, except it will likely let your content download more efficiently due to the addition of compression. ## Tools for working with WOFF fonts - [Tools for working with WOFF](https://github.com/odemiral/woff2sfnt-sfnt2woff) fonts are available. `sfnt2woff` and `woff2sfnt` convert between WOFF and OpenType. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("@font-face")}}
0
data/mdn-content/files/en-us/web/css/css_fonts
data/mdn-content/files/en-us/web/css/css_fonts/opentype_fonts_guide/index.md
--- title: OpenType font features guide slug: Web/CSS/CSS_fonts/OpenType_fonts_guide page-type: guide --- {{CSSRef}} Font features or variants refer to different glyphs or character styles contained within an OpenType font. These include things like ligatures (special glyphs that combine characters like 'fi' or 'ffl'), kerning (adjustments to the spacing between specific letterform pairings), fractions, numeral styles, and several others. These are all referred to as OpenType Features, and are made available to use on the web via specific properties and low-level control properties — {{cssxref("font-feature-settings")}}. This article provides you with all you need to know about using OpenType font features in CSS. Some fonts will have one or more of these features enabled by default (kerning and default ligatures are common examples), while others are left to the designer or developer to choose to enable in specific scenarios. In addition to broad feature sets like ligatures or lining figures (numerals that line up evenly as opposed to 'oldstyle', which look more like lower-case letters), there are also very specific ones such as stylistic sets (which might include several specific variants of glyphs meant to be used together), alternates (which might be one or more variants of the letter 'a'), or even language-specific alterations for East Asian languages. In the latter case, these alterations are actually necessary to properly express the language, so they go beyond the more stylistic preference of most other OpenType features. > **Warning:** There are many CSS attributes defined to leverage font features, but unfortunately many are not fully implemented. They are all defined and shown here, but many will only work using the lower-level {{cssxref("font-feature-settings")}} property. It's possible to write CSS to work both ways but this can become cumbersome. The issue with using `font-feature-settings` for everything is that every time you want to change one of the individual features, you have to redefine the entire string (similar to manipulating variable fonts with {{cssxref("font-variation-settings")}}). ## Discovering availability of features in fonts This is sometimes the trickiest thing to work out if you don't have any documentation that came with the fonts (many type designers and foundries will provide sample pages and CSS just for this very reason). But there are some sites that make it easier to figure out. You can visit [wakamaifondue.com](https://wakamaifondue.com), drop your font file on the circle where instructed, and in a few moments you'll have a full report on all the capabilities and features of your font. [Axis-praxis.org](https://www.axis-praxis.org/) also offers a similar capability, with the ability to click on the features to turn them on or off in a given text block. ## Why you would use them? Given that these features take a bit of work to discover and use, it may seem a fair question to ask why one would bother to use them. The answer lies in the specific features that will make a site more useful, readable, and polished: - **Ligatures** like 'ff' or 'fi' make letter spacing and reading more even and smooth. - **Fractions** can make home improvement and recipe sites much easier to read and understand. - **Numerals** within paragraphs of text set as 'oldstyle' sit more comfortably between lower-case letters, and likewise setting them as 'tabular numbers' will make them line up better when setting a list of costs in a table say. 'lining' figures on the other hand sit more uniformly on their own or in front of capitalized words. While none of these features individually will render a site useless due to their absence, each of them in turn can make a site easier to use and more memorable for its attention to detail. > OpenType features are like secret compartments in fonts. Unlock them and you'll find ways to make fonts look and behave differently in subtle and dramatic ways. Not all OpenType features are appropriate to use all of the time, but some features are critical for great typography. _-- Tim Brown, Head of Typography at Adobe_. ### Sometimes it's substance, not just style There are some cases — like with {{cssxref("font-variant-east-asian")}} — that OpenType features are directly tied to using different forms of certain glyphs, which can impact meaning and readability. In cases such as these, it's more than just a nicety, but rather an integral part of the content itself. ## The font features There are a number of different features to consider. They are grouped and explained here according to the main attributes and options covered in the W3C specifications. > **Note:** The examples below show the properties and some example combinations, along with the lower-level syntax equivalents. They may not match exactly due to browser implementation inconsistencies, but in many cases, the first example will match the second. The typefaces shown are Playfair Display, Source Serif Pro, IBM Plex Serif, Dancing Script, and Kokoro (all available and free to use, most are on Google Fonts and other services). ### Kerning Associated CSS property: {{cssxref("font-kerning")}} This refers to the spacing between specific glyph pairings. This is generally on by default (as recommended by the OpenType specification). It should be noted that if {{cssxref("letter-spacing")}} is also set on your text, that is applied after kerning. {{EmbedGHLiveSample("css-examples/font-features/font-kerning.html", '100%', 520)}} ### Alternates Associated CSS property: {{cssxref("font-variant-alternates")}} Fonts can supply a number of different alternatives for various glyphs, such as different styles of lower case 'a' or more or less elaborate swashes in a script typeface. This property can activate an entire set of alternates or just a specific one, depending on the values supplied. The example below is showing several different aspects of working with alternate characters. Fonts with alternate glyphs can make them available across the board or individually in separate stylistic sets, or even individual characters. In this example you can see two different typefaces, and the introduction of the {{cssxref("@font-feature-values")}} at-rule. This is used to define shortcuts or named options that can be defined per font family. This way you can create a named option that applies to only a single font, or one that is shared and can be applied more generally {{EmbedGHLiveSample("css-examples/font-features/font-variant-alternates.html", '100%', 800)}} In this case, `@stylistic(alternates)` will show all the alternate characters for either font. Applying this to just the word 'My' alters the way the 'M' renders, and applying `@styleset(alt-a)` only changes the lower case 'a'. Try changing the line ```css font-variant-alternates: styleset(alt-a); ``` to ```css font-variant-alternates: styleset(alt-g); ``` and notice that the lower case 'a' reverts to its regular form and the lower case 'g's changes instead. #### More about alternates - <https://www.w3.org/TR/css-fonts-4/#propdef-font-variant-alternates> ### Ligatures Associated CSS property: {{cssxref("font-variant-ligatures")}} Ligatures are glyphs that replace two or more separate glyphs in order to represent them more smoothly (from a spacing or aesthetic perspective). Some of the most common are letters like 'fi', 'fl', or 'ffl' — but there are many other possibilities. There are the most frequent ones (referred to as common ligatures), and there are also more specialized categories like 'discretionary ligatures', 'historical ligatures', and 'contextual alternates'. While these last ones are not technically ligatures, they are generally similar in that they replace specific combinations of letters when they appear together. While more common in script typefaces, in the below example they are used to create arrows: {{EmbedGHLiveSample("css-examples/font-features/font-variant-ligatures.html", '100%', 540)}} ### Position Associated CSS property: {{cssxref("font-variant-position")}} Position variants are used to enable typographic superscript and subscript glyphs. These are designed to work with the surrounding text without altering the baseline or line spacing. This is especially useful with the {{htmlelement("sub")}} or {{htmlelement("sup")}} elements. {{EmbedGHLiveSample("css-examples/font-features/font-variant-position.html", '100%', 550)}} ### Capitals Associated CSS property: {{cssxref("font-variant-caps")}} One of the more common use cases for OpenType features is proper small caps. These are capital letters sized to fit better amongst lower case letters and are generally used for acronyms and abbreviations. {{EmbedGHLiveSample("css-examples/font-features/font-variant-caps.html", '100%', 620)}} ### Numerals Associated CSS property: {{cssxref("font-variant-numeric")}} There are several different styles of numerals commonly included in fonts: - 'Lining' figures are all the same height and on the same baseline. - 'Oldstyle' figures are mixed height and designed to have the appearance of ascenders and descenders like other lower case letters. These are designed to be used inline with a copy so the numerals visually blend with the surrounding glyphs in a similar fashion to small caps. There is also the notion of spacing. Proportional spacing is the normal setting, whereas tabular spacing lines up numerals evenly regardless of character width, making it more appropriate for lining up tables of numbers in financial tables. There are two types of fractions supported through this property: - Diagonal slashed fractions. - Vertically stacked fractions. Ordinals are also supported (such as '1st' or '3rd'), as is a slashed zero if present in the font. #### Lining and old-style figures {{EmbedGHLiveSample("css-examples/font-features/font-variant-numeric.html", '100%', 560)}} #### Fractions, ordinals, and slashed zero {{EmbedGHLiveSample("css-examples/font-features/font-variant-numeric-frac.html", '100%', 600)}} ### East Asian Associated CSS property: {{cssxref("font-variant-east-asian")}} This allows access to various alternate forms of glyphs within a font. The example below shows a string of glyphs with only the OpenType set 'jis78' enabled. Uncheck the box below and you'll see more characters displayed. {{EmbedGHLiveSample("css-examples/font-features/font-variant-east-asian.html", '100%', 750)}} > **Note:** these glyphs were copied out of a font sample and are not intended as prose. ### Font variant shorthand The {{Cssxref("font-variant")}} property is the shorthand syntax for defining all of the above. Setting a value of `normal` resets all properties to their initial value. Setting a value of `none` sets `font-variant-ligatures` to none and all other properties to their initial value. (Meaning that if kerning is on by default, it will still be on even with a value of `none` being supplied here.) {{EmbedGHLiveSample("css-examples/font-features/font-variant.html", '100%', 600)}} ## Font feature settings {{cssxref("font-feature-settings")}} is the 'low level syntax' that allows explicit access to every named available OpenType feature. This gives a lot of control but has some disadvantages in how it impacts inheritance and — as mentioned above — if you wish to change one setting, you have to redeclare the entire string (unless you're using [CSS custom properties](/en-US/docs/Web/CSS/Using_CSS_custom_properties) to set the values). Because of this, it's best to use the standard properties shown above wherever possible. There are a huge number of possible features. You can see examples of a number of them above, and there are several resources available for finding more of them. The general syntax looks like this: ```css .small-caps { font-feature-settings: "smcp", "c2sc"; } ``` According to the specification you can either supply just the 4-character feature code or supply a 1 following the code (for enabling that feature) or a 0 (zero) to disable it. This is helpful if you have a feature like ligatures enabled by default but you would like to turn them off like so: ```css .no-ligatures { font-feature-settings: "liga" 0, "dlig" 0; } ``` ### More on font-feature-settings codes - ['The Complete CSS Demo for OpenType Features'](https://sparanoid.com/lab/opentype-features/) (can't vouch for the truth of the name, but it's pretty big) - [A list of OpenType features on Wikipedia](https://en.wikipedia.org/wiki/List_of_typographic_features) ## Using CSS feature detection for implementation Since not all properties are evenly implemented, it's good practice to set up your CSS using feature detection to utilize the correct properties, with {{cssxref("font-feature-settings")}} as the fallback. For example, small caps can be set several ways, but if you want to ensure that no matter what the underlying capitalization is that you end up with everything in small caps, it requires 2 settings with `font-feature-settings` versus a single property value using {{cssxref("font-variant-caps")}}. ```css .small-caps { font-feature-settings: "smcp", "c2sc"; } @supports (font-variant-caps: all-small-caps) { .small-caps { font-feature-settings: normal; font-variant-caps: all-small-caps; } } ``` ## See also ### Demos of CSS OpenType features in CSS - [The Complete CSS Demo for OpenType Features](https://sparanoid.com/lab/opentype-features/) ### Web font analysis tools - [Wakamai Fondue](https://wakamaifondue.com) - [Axis Praxis](https://www.axis-praxis.org/) ### W3C Specifications - [Font Feature Properties in CSS Fonts Module Level 3](https://drafts.csswg.org/css-fonts-3/#font-rend-props) - [font-variant-alternatives in CSS Fonts Module Level 4](https://www.w3.org/TR/css-fonts-4/#propdef-font-variant-alternates) ### Other resources - [Using OpenType features](https://helpx.adobe.com/fonts/using/use-open-type-features.html) by Tim Brown, Head of Typography, Adobe - [Adobe's Syntax for OpenType features in CSS](https://helpx.adobe.com/fonts/using/open-type-syntax.html)
0
data/mdn-content/files/en-us/web/css/css_fonts
data/mdn-content/files/en-us/web/css/css_fonts/variable_fonts_guide/index.md
--- title: Variable fonts guide slug: Web/CSS/CSS_fonts/Variable_fonts_guide page-type: guide --- {{CSSRef}} **Variable fonts** are an evolution of the OpenType font specification that enables many different variations of a typeface to be incorporated into a single file, rather than having a separate font file for every width, weight, or style. They let you access all the variations contained in a given font file via CSS and a single {{cssxref("@font-face")}} reference. This article will give you all you need to know to get you started using variable fonts. > **Note:** To use variable fonts on your operating system, you need to make sure that it is up to date. For example, Linux OSes need the latest Linux Freetype version, and macOS prior to High Sierra (10.13) does not support variable fonts. If your operating system is not up to date, you will not be able to use variable fonts in web pages or the Firefox Developer Tools. ## Variable Fonts: what they are, and how they differ To better understand what's different about variable fonts, it is worth reviewing what non-variable ones are like and how they compare. ### Standard (or Static) fonts In the past, a typeface would be produced as several individual fonts, and each font would represent one specific width/weight/style combination. So you would have separate files for 'Roboto Regular', 'Roboto Bold', and 'Roboto Bold Italic' — meaning that you could end up with 20 or 30 different font files to represent a complete typeface (it could be several times that for a large typeface that has different widths as well). In such a scenario, to use a typeface for typical use on a site for body copy you would need at least four files: regular, italic, bold, and bold italic. If you wanted to add more weights, like a lighter one for captions or a heavier one for extra emphasis, that would mean several more files. This results in more HTTP requests, and more data being downloaded (usually around 20k or more per file). ### Variable fonts With a variable font, all of those permutations can be contained in a single file. That file would be larger than a single font, but in most cases smaller or about the same size as the 4 you might load for body copy. The advantage in choosing the variable font is that you have access to the entire range of weights, widths, and styles available, rather than being constrained to only the few that you previously would have loaded separately. This allows for common typographic techniques such as setting different size headings in different weights for better readability at each size or using a slightly narrower width for data-dense displays. For comparison, it is typical in a typographic system for a magazine to use 10–15 or more different weight and width combinations throughout the publication — giving a much wider range of styles than currently typical on the web (or indeed practical for performance reasons alone). #### A note about font families, weights, and variants You might notice that we have been talking about having a specific font file for every weight and style (i.e. bold and italic and bold italic), rather than relying upon the browser to synthesize them. The reason for this is that most typefaces have very specific designs for bolder weights and italics that often include completely different characters (lower-case 'a' and 'g's are often quite different in italics, for example). To most accurately reflect the typeface design and avoid differences between browsers and how they may or may not synthesize the different styles, it's more accurate to load the specific font files where needed when using a non-variable font. You may also find that some variable fonts come split into two files: one for uprights and all their variations, and one containing the italic variations. This is sometimes done to reduce the overall file size in cases where the italics aren't needed or used. In all cases, it is still possible to link them with a common {{cssxref("font-family")}} name so you can call them using the same `font-family` and appropriate {{cssxref("font-style")}}. ## Introducing the 'variation axis' The heart of the new variable fonts format is the concept of an **axis of variation** describing the allowable range of that particular aspect of the typeface design. So the 'weight axis' describes how light or how bold the letterforms can be; the 'width axis' describes how narrow or how wide they can be; the 'italic axis' describes if italic letterforms are present and can be turned on or off accordingly, etc. Note that an axis can be a range or a binary choice. Weight might range from 1–999, whereas italic might be 0 or 1 (off or on). As defined in the specification, there are two kinds of axes: **registered** and **custom**: - Registered axes are those that are most frequently encountered, and common enough that the authors of the specification felt it was worth standardizing. The five currently registered axes are weight, width, slant, italic, and optical size. The W3C has undertaken to map them to existing CSS attributes, and in one case introduced a new one, which you'll see below. - Custom axes are limitless: the typeface designer can define and scope any axis they like and are just required to give it a four-letter **tag** to identify it within the font file format itself. You can use these four-letter tags in CSS to specify a point along that axis of variation, as will be shown in the code examples below. ### Registered axes and existing CSS attributes In this section we'll demonstrate the five registered axes defined with examples and the corresponding CSS. Where possible, both the standard and lower-level syntax are included. The lower-level syntax ({{cssxref("font-variation-settings")}}) was the first mechanism implemented to test the early implementations of variable font support and is necessary to utilize new or custom axes beyond the five registered ones. However, the W3C's intent was for this syntax not to be used when other attributes are available. Therefore wherever possible, the appropriate property should be used, with the lower-level syntax of `font-variation-settings` only being used to set values or axes not available otherwise. #### Notes 1. When using `font-variation-settings` it is important to note that axis names are case-sensitive. The registered axis names must be in lower case, and custom axes must be in upper case. For example: ```css font-variation-settings: "wght" 375, "GRAD" 88; ``` `wght` (weight) is a registered axis, and `GRAD` (grade) is a custom one. 2. If you have set values using `font-variation-settings` and want to change one of those values, you must redeclare all of them (in the same way as when you set OpenType font features using {{cssxref("font-feature-settings")}}). You can work around this limitation by using [CSS Custom Properties](/en-US/docs/Web/CSS/Using_CSS_custom_properties) (CSS variables) for the individual values, and modifying the value of an individual custom property. Example code follows at the end of the guide. ### Weight Weight (represented by the `wght` tag) defines the design axis of how thin or thick (light or heavy, in typical typographic terms) the strokes of the letterforms can be. For a long time in CSS there has existed the ability to specify this via the {{cssxref("font-weight")}} property, which takes numeric values ranging from 100 to 900 in increments of 100, and keywords like `normal` or `bold`, which are aliases for their corresponding numeric values (400 and 700 in this case). These are still applied when dealing with non-variable or variable fonts, but with variable ones, any number from 1 to 1000 is now valid. It should be noted that at this point there is no way in the `@font-face` declaration to 'map' a specific point on the variation axis of a variable font to the keyword `bold` (or any other keyword). This can generally be resolved fairly easily, but does require an extra step in writing your CSS: ```css font-weight: 375; font-variation-settings: "wght" 375; ``` The following live example's CSS can be edited to allow you to play with font-weight values. {{EmbedGHLiveSample("css-examples/variable-fonts/weight.html", '100%', 520)}} ### Width Width (represented by the `wdth` tag) defines the design axis of how narrow or wide (condensed or extended, in typographic terms) the letterforms can be. This is typically set in CSS using the {{cssxref("font-stretch")}} property, with values expressed as a percentage above or below 'normal' (100%), any number greater than 0 is technically valid—though it is far more likely that the range would fall closer to the 100% mark, such as 75%-125%. If a number value supplied is outside the range encoded in the font, the browser should render the font at the closest value allowed. > **Note:** The % symbol is not used when utilizing `font-variation-settings`. ```css font-stretch: 115%; font-variation-settings: "wdth" 115; ``` The following live example's CSS can be edited to allow you to play with font width values. {{EmbedGHLiveSample("css-examples/variable-fonts/width.html", '100%', 520)}} ### Italic The Italic (`ital`) axis can be set in the range `[0-1]`, where `0` specifies "not italic," `0.5` specifies "halfway italic," and `1` specifies "fully italic." Italic designs often include dramatically different letterforms from their upright counterparts, so in the transition from upright to italic, several glyph (or character) substitutions usually occur. Italic and oblique are often used somewhat interchangeably, but in truth are quite different. Oblique is defined in this context with the term `slant` (see the below section), and a typeface would typically have one or the other, but not both. In CSS, both italic and oblique are applied to text using the {{cssxref("font-style")}} property. Also note the introduction of `font-synthesis: none;` — which will prevent browsers from accidentally applying the variation axis and a synthesized italic. This can be used to prevent faux-bolding as well. ```css font-style: italic; font-variation-settings: "ital" 1; font-synthesis: none; ``` The following live example's CSS can be edited to allow you to play with font italics. {{EmbedGHLiveSample("css-examples/variable-fonts/italic.html", '100%', 520)}} ### Slant Slant (represented by the `slnt` tag), or as it's often referred to, 'oblique' — is different from true italics in that it changes the angle of the letterforms but doesn't perform any kind of character substitution. It is also variable, in that it is expressed as a numeric range. This allows the font to be varied anywhere along that axis. The allowed range is generally 0 (upright) to 20 degrees — any number value along that range can be supplied, so the font can be slanted just a tiny bit. However, any value from -90 to 90 degrees is valid. > **Note:** The `deg` keyword is not used when utilizing `font-variation-settings`. ```css font-style: oblique 14deg; font-variation-settings: "slnt" 14; ``` The following live example's CSS can be edited to allow you to play with font slant/oblique values. {{EmbedGHLiveSample("css-examples/variable-fonts/slant.html", '100%', 520)}} ### Optical size This is something new to digital fonts and CSS, but is a centuries-old technique in designing and creating metal type. Optical sizing refers to the practice of varying the overall stroke thickness of letterforms based on physical size. If the size was very small (such as an equivalent to 10 or 12px), the characters would have an overall thicker stroke, and perhaps other small modifications to ensure that it would reproduce and be readable at a physically smaller size. Conversely, when a much larger size was being used (like 48 or 60px), there might be much greater variation in thick and thin stroke weights, showing the typeface design more in line with the original intent. While this was originally done to compensate for the ink and paper printing process (very thin lines at small sizes often didn't print, giving the letterforms a broken appearance), it translates well to digital displays when compensating for screen quality and physical size rendering. Optical size values are generally intended to be automatically applied corresponding to `font-size`, but can also be manipulated using the lower-level `font-variation-settings` syntax. There is a new attribute, {{cssxref("font-optical-sizing")}}, created to support variable fonts in CSS. When using `font-optical-sizing`, the only allowed values are `auto` or `none` — so this attribute only allows for turning optical sizing on or off. However when using `font-variation-settings: 'opsz' <num>`, you can supply a numeric value. In most cases you would want to match the `font-size` (the physical size the type is being rendered) with the `opsz` value (which is how optical sizing is intended to be applied when using `auto`). The option to provide a specific value is provided so that should it be necessary to override the default — for legibility, aesthetic, or some other reason — a specific value can be applied. ```css font-optical-sizing: auto; font-variation-settings: "opsz" 36; ``` The following live example's CSS can be edited to allow you to play with optical size values. {{EmbedGHLiveSample("css-examples/variable-fonts/optical-sizing.html", '100%', 1020)}} ### Custom axes Custom axes are just that: they can be any axis of design variation that the typeface designer imagines. There may be some that become fairly common — or even become registered — but only time will tell. ### Grade Grade may become one of the more common custom axes as it has a known history in typeface design. The practice of designing different grades of a typeface was often done in reaction to intended use and printing technique. The term 'grade' refers to the relative weight or density of the typeface design, but differs from traditional 'weight' in that the physical space the text occupies does not change, so changing the text grade doesn't change the overall layout of the text or elements around it. This makes grade a useful axis of variation as it can be varied or animated without causing a reflow of the text itself. ```css font-variation-settings: "GRAD" 88; ``` The following live example's CSS can be edited to allow you to play with font grade values. {{EmbedGHLiveSample("css-examples/variable-fonts/grade.html", '100%', 520)}} ### Using a variable font: @font-face changes The syntax for loading variable fonts is very similar to any other web font, with a few notable differences, which are provided via upgrades to the traditional {{cssxref("@font-face")}} syntax now available in modern browsers. The basic syntax is the same, but the font technology can be specified, and allowable ranges for descriptors like `font-weight` and `font-stretch` can be supplied, rather than named according to the font file being loaded. #### Example for a standard upright (Roman) font ```css @font-face { font-family: "MyVariableFontName"; src: url("path/to/font/file/myvariablefont.woff2") format("woff2-variations"); font-weight: 125 950; font-stretch: 75% 125%; font-style: normal; } ``` #### Example for a font that includes both upright and italics ```css @font-face { font-family: "MyVariableFontName"; src: url("path/to/font/file/myvariablefont.woff2") format("woff2-variations"); font-weight: 125 950; font-stretch: 75% 125%; font-style: oblique 0deg 20deg; } ``` > **Note:** there is no set specific value for the upper-end degree measurement in this case; they indicate that there is an axis so the browser can know to render upright or italic (remember that italics are only on or off) #### Example for a font that contains only italics and no upright characters ```css @font-face { font-family: "MyVariableFontName"; src: url("path/to/font/file/myvariablefont.woff2") format("woff2-variations"); font-weight: 125 950; font-stretch: 75% 125%; font-style: italic; } ``` #### Example for a font that contains an oblique (slant) axis ```css @font-face { font-family: "MyVariableFontName"; src: url("path/to/font/file/myvariablefont.woff2") format("woff2-variations"); font-weight: 125 950; font-stretch: 75% 125%; font-style: oblique 0deg 12deg; } ``` > **Note:** Not all browsers have implemented the full syntax for font format, so test carefully. All browsers that support variable fonts will still render them if you set the format to just the file format, rather than format-variations (i.e. `woff2` instead of `woff2-variations`), but it's best to use the proper syntax if possible. > **Note:** Supplying value ranges for `font-weight`, `font-stretch`, and `font-style` will keep the browser from attempting to render an axis outside that range if you are using the appropriate attribute (i.e. `font-weight` or `font-stretch`), but will not block you from supplying an invalid value via `font-variation-settings`, so use with care. ## Working with older browsers Variable font support can be checked with CSS Feature Queries (see {{cssxref("@supports")}}), so it's possible to use variable fonts in production and scope the CSS calling the variable fonts inside a feature query block. ```css h1 { font-family: some-non-variable-font-family; } @supports (font-variation-settings: "wdth" 115) { h1 { font-family: some-variable-font-family; } } ``` ## Sample pages The following example pages show two different ways to structure your CSS. The first uses the standard attributes wherever possible. The second example uses CSS Custom Properties to set values for a `font-variation-settings` string and shows how you can more easily update single variable values by overriding a single variable rather than rewriting the whole string. Note the hover effect on the `h2`, which only alters the grade axis custom property value. {{EmbedGHLiveSample("css-examples/variable-fonts/sample-page.html", '100%', 1220)}} ## Resources - [W3C CSS Fonts Module 4 Specification](https://drafts.csswg.org/css-fonts-4/) (editor's draft) - [W3C GitHub issue queue](https://github.com/w3c/csswg-drafts/issues) - [Microsoft Open Type Variations introduction](https://docs.microsoft.com/typography/opentype/spec/otvaroverview) - [Microsoft OpenType Design-Variation Axis Tag Registry](https://docs.microsoft.com/typography/opentype/spec/dvaraxisreg) - [Wakamai Fondue](https://wakamaifondue.com) (a site that will tell you what your font can do via a simple drag-and-drop inspection interface) - [Axis Praxis](https://www.axis-praxis.org) (the original variable fonts playground site) - [V-Fonts.com](https://v-fonts.com) (a catalog of variable fonts and where to get them) - [Font Playground](https://play.typedetail.com) (another playground for variable fonts with some very unique approaches to user interface)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/max-width/index.md
--- title: max-width slug: Web/CSS/max-width page-type: css-property browser-compat: css.properties.max-width --- {{CSSRef}} The **`max-width`** [CSS](/en-US/docs/Web/CSS) property sets the maximum width of an element. It prevents the [used value](/en-US/docs/Web/CSS/used_value) of the {{cssxref("width")}} property from becoming larger than the value specified by `max-width`. {{EmbedInteractiveExample("pages/css/max-width.html")}} `max-width` overrides {{cssxref("width")}}, but {{cssxref("min-width")}} overrides `max-width`. ## Syntax ```css /* <length> value */ max-width: 3.5em; /* <percentage> value */ max-width: 75%; /* Keyword values */ max-width: none; max-width: max-content; max-width: min-content; max-width: fit-content; max-width: fit-content(20em); /* Global values */ max-width: inherit; max-width: initial; max-width: revert; max-width: revert-layer; max-width: unset; ``` ### Values - {{cssxref("&lt;length&gt;")}} - : Defines the `max-width` as an absolute value. - {{cssxref("&lt;percentage&gt;")}} - : Defines the `max-width` as a percentage of the containing block's width. - `none` - : No limit on the size of the box. - `max-content` - : The intrinsic preferred `max-width`. - `min-content` - : The intrinsic minimum `max-width`. - `fit-content` - : Use the available space, but not more than [max-content](/en-US/docs/Web/CSS/max-content), i.e `min(max-content, max(min-content, stretch))`. - `fit-content({{cssxref("&lt;length-percentage&gt;")}})` {{Experimental_Inline}} - : Uses the `fit-content` formula with the available space replaced by the specified argument, i.e. `min(max-content, max(min-content, argument))`. ## Accessibility concerns Ensure that elements set with a `max-width` are not truncated and/or do not obscure other content when the page is zoomed to increase text size. - [MDN Understanding WCAG, Guideline 1.4 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background) - [Understanding Success Criterion 1.4.4 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-scale.html) ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting max width in pixels In this example, the "child" will be either 150 pixels wide or the width of the "parent," whichever is smaller. #### HTML ```html <div id="parent"> <div id="child"> Fusce pulvinar vestibulum eros, sed luctus ex lobortis quis. </div> </div> ``` #### CSS ```css #parent { background: lightblue; width: 300px; } #child { background: gold; width: 100%; max-width: 150px; } ``` #### Result {{EmbedLiveSample("Setting_max_width_in_pixels", 350, 100)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [The box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model), {{cssxref("box-sizing")}} - {{cssxref("width")}}, {{cssxref("min-width")}} - The mapped logical properties: {{cssxref("max-inline-size")}}, {{cssxref("max-block-size")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_view-transition/index.md
--- title: "::view-transition" slug: Web/CSS/::view-transition page-type: css-pseudo-element status: - experimental browser-compat: css.selectors.view-transition --- {{CSSRef}}{{SeeCompatTable}} The **`::view-transition`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) represents the root of the [view transitions](/en-US/docs/Web/API/View_Transitions_API) overlay, which contains all view transitions and sits over the top of all other page content. During a view transition, `::view-transition` is included in the associated pseudo-element tree as explained in [The view transition process](/en-US/docs/Web/API/View_Transitions_API#the_view_transition_process). It is the top-level node of this tree, and has one or more {{cssxref("::view-transition-group")}}s as children. `::view-transition` is given the following default styling in the UA stylesheet: ```css html::view-transition { position: fixed; inset: 0; } ``` All {{cssxref("::view-transition-group")}} pseudo-elements are positioned relative to the view transition root. ## Syntax ```css ::view-transition { /* ... */ } ``` ## Examples ```css ::view-transition { background-color: rgb(0 0 0 / 25%); } ``` ## 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/touch-action/index.md
--- title: touch-action slug: Web/CSS/touch-action page-type: css-property browser-compat: css.properties.touch-action --- {{CSSRef}} The **`touch-action`** CSS property sets how an element's region can be manipulated by a touchscreen user (for example, by zooming features built into the browser). By default, panning (scrolling) and pinching gestures are handled exclusively by the browser. An application using {{domxref("Pointer_events", "Pointer events", "", 1)}} will receive a {{domxref("Element/pointercancel_event", "pointercancel")}} event when the browser starts handling a touch gesture. By explicitly specifying which gestures should be handled by the browser, an application can supply its own behavior in {{domxref("Element/pointermove_event", "pointermove")}} and {{domxref("Element/pointerup_event", "pointerup")}} listeners for the remaining gestures. Applications using {{domxref("Touch_events", "Touch events", "", 1)}} disable the browser handling of gestures by calling {{domxref("Event.preventDefault","preventDefault()")}}, but should also use `touch-action` to ensure the browser knows the intent of the application before any event listeners have been invoked. When a gesture is started, the browser intersects the `touch-action` values of the touched element and its ancestors, up to the one that implements the gesture (in other words, the first containing scrolling element). This means that in practice, `touch-action` is typically applied only to top-level elements which have some custom behavior, without needing to specify `touch-action` explicitly on any of that element's descendants. > **Note:** After a gesture starts, changes to `touch-action` will not have any impact on the behavior of the current gesture. ## Syntax ```css /* Keyword values */ touch-action: auto; touch-action: none; touch-action: pan-x; touch-action: pan-left; touch-action: pan-right; touch-action: pan-y; touch-action: pan-up; touch-action: pan-down; touch-action: pinch-zoom; touch-action: manipulation; /* Global values */ touch-action: inherit; touch-action: initial; touch-action: revert; touch-action: revert-layer; touch-action: unset; ``` The `touch-action` property may be specified as either: - One of the keywords `auto`, `none`, [`manipulation`](#manipulation), _or_ - One of the keywords `pan-x`, `pan-left`, `pan-right`, and/or one of the keywords `pan-y`, `pan-up`, `pan-down`, plus optionally the keyword `pinch-zoom`. ### Values - `auto` - : Enable browser handling of all panning and zooming gestures. - `none` - : Disable browser handling of all panning and zooming gestures. - `pan-x` - : Enable single-finger horizontal panning gestures. May be combined with **pan-y**, **pan-up**, **pan-down** and/or **pinch-zoom**. - `pan-y` - : Enable single-finger vertical panning gestures. May be combined with **pan-x**, **pan-left**, **pan-right** and/or **pinch-zoom**. - `manipulation` - : Enable panning and pinch zoom gestures, but disable additional non-standard gestures such as double-tap to zoom. Disabling double-tap to zoom removes the need for browsers to delay the generation of **click** events when the user taps the screen. This is an alias for "**pan-x pan-y pinch-zoom**" (which, for compatibility, is itself still valid). - `pan-left`, `pan-right`, `pan-up`, `pan-down` - : Enable single-finger gestures that begin by scrolling in the given direction(s). Once scrolling has started, the direction may still be reversed. Note that scrolling "up" (**pan-up**) means that the user is dragging their finger downward on the screen surface, and likewise **pan-left** means the user is dragging their finger to the right. Multiple directions may be combined except when there is a simpler representation (for example, **"pan-left pan-right**" is invalid since "**pan-x**" is simpler, but "**pan-left pan-down**" is valid). - `pinch-zoom` - : Enable multi-finger panning and zooming of the page. This may be combined with any of the **pan-** values. ## Accessibility concerns A declaration of `touch-action: none;` may inhibit operating a browser's zooming capabilities. This will prevent people experiencing low vision conditions from being able to read and understand page content. - [MDN Understanding WCAG, Guideline 1.4 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background) - [Understanding Success Criterion 1.4.4 | Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-scale.html) ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Disabling all gestures The most common usage is to disable all gestures on an element (and its non-scrollable descendants) that provides its own dragging and zooming behavior – such as a map or game surface. #### HTML ```html <div id="map"></div> ``` #### CSS ```css #map { height: 150vh; width: 70vw; background: linear-gradient(blue, green); touch-action: none; } ``` #### Result {{EmbedLiveSample('Disabling_all_gestures')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("pointer-events","pointer-events")}} - {{domxref("Pointer_events","Pointer Events")}} - WebKit Blog [More Responsive Tapping on iOS](https://webkit.org/blog/5610/more-responsive-tapping-on-ios/) - Google Developers Blog [Making touch scrolling fast by default](https://developer.chrome.com/blog/scrolling-intervention/) - [Scroll Snap](/en-US/docs/Web/CSS/CSS_scroll_snap)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/padding-block/index.md
--- title: padding-block slug: Web/CSS/padding-block page-type: css-shorthand-property browser-compat: css.properties.padding-block --- {{CSSRef}} The **`padding-block`** [CSS](/en-US/docs/Web/CSS) [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) defines the logical block start and end padding of an element, which maps to physical padding properties depending on the element's writing mode, directionality, and text orientation. {{EmbedInteractiveExample("pages/css/padding-block.html")}} ## Constituent properties This property is a shorthand for the following CSS properties: - {{cssxref("padding-block-start")}} - {{cssxref("padding-block-end")}} ## Syntax ```css /* <length> values */ padding-block: 10px 20px; /* An absolute length */ padding-block: 1em 2em; /* relative to the text size */ padding-block: 10px; /* sets both start and end values */ /* <percentage> values */ padding-block: 5% 2%; /* relative to the nearest block container's width */ /* Global values */ padding-block: inherit; padding-block: initial; padding-block: revert; padding-block: revert-layer; padding-block: unset; ``` The `padding-block` property may be specified with one or two values. If one value is given, it is used as the value for both {{cssxref("padding-block-start")}} and {{cssxref("padding-block-end")}}. If two values are given, the first is used for {{cssxref("padding-block-start")}} and the second for {{cssxref("padding-block-end")}}. ### Values The `padding-block` property takes the same values as the {{cssxref("padding-left")}} property. ## Description These values corresponds to the {{cssxref("padding-top")}} and {{cssxref("padding-bottom")}}, or {{cssxref("padding-right")}}, and {{cssxref("padding-left")}} property depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting block padding for vertical text #### HTML ```html <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ```css div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-rl; padding-block: 20px 40px; background-color: #c8c800; } ``` #### Result {{EmbedLiveSample("Setting_block_padding_for_vertical_text", 140, 140)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS Logical Properties and Values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values) - The mapped physical properties: {{cssxref("padding-top")}}, {{cssxref("padding-right")}}, {{cssxref("padding-bottom")}}, and {{cssxref("padding-left")}} - {{cssxref("writing-mode")}}, {{cssxref("direction")}}, {{cssxref("text-orientation")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/display-listitem/index.md
--- title: <display-listitem> slug: Web/CSS/display-listitem page-type: css-type browser-compat: css.properties.display.list-item --- {{CSSRef}} The `list-item` keyword causes the element to generate a `::marker` pseudo-element with the content specified by its {{CSSxRef("list-style")}} properties (for example a bullet point) together with a principal box of the specified type for its own contents. ## Syntax A single value of `list-item` will cause the element to behave like a list item. This can be used together with {{CSSxRef("list-style-type")}} and {{CSSxRef("list-style-position")}}. `list-item` can also be combined with any {{CSSxRef("&lt;display-outside&gt;")}} keyword and the `flow` or `flow-root` {{CSSxRef("&lt;display-inside&gt;")}} keywords. > **Note:** In browsers that support the two-value syntax, if no inner value is specified it will default to `flow`. If no outer value is specified, the principal box will have an outer display type of `block`. ## Formal syntax {{csssyntax}} ## Examples ### HTML ```html <div class="fake-list">I will display as a list item</div> ``` ### CSS ```css .fake-list { display: list-item; list-style-position: inside; } ``` ### Result {{EmbedLiveSample("Examples", "100%", 150)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("display")}} - {{CSSxRef("&lt;display-outside&gt;")}} - {{CSSxRef("&lt;display-inside&gt;")}} - {{CSSxRef("&lt;display-internal&gt;")}} - {{CSSxRef("&lt;display-box&gt;")}} - {{CSSxRef("&lt;display-legacy&gt;")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/-webkit-mask-position-y/index.md
--- title: "-webkit-mask-position-y" slug: Web/CSS/-webkit-mask-position-y page-type: css-property status: - non-standard browser-compat: css.properties.-webkit-mask-position-y --- {{CSSRef}}{{Non-standard_header}} The `-webkit-mask-position-y` CSS property sets the initial vertical position of a mask image. ## Syntax ```css /* Keyword values */ -webkit-mask-position-y: top; -webkit-mask-position-y: center; -webkit-mask-position-y: bottom; /* <percentage> values */ -webkit-mask-position-y: 100%; -webkit-mask-position-y: -50%; /* <length> values */ -webkit-mask-position-y: 50px; -webkit-mask-position-y: -1cm; /* Multiple values */ -webkit-mask-position-y: 50px, 25%, -3em; /* Global values */ -webkit-mask-position-y: inherit; -webkit-mask-position-y: initial; -webkit-mask-position-y: revert; -webkit-mask-position-y: revert-layer; -webkit-mask-position-y: unset; ``` ### Values - `<length-percentage>` - : A length indicating the position of the top side of the image relative to the box's top padding edge. Percentages are calculated against the vertical dimension of the box padding area. A value of `0%` means the top edge of the image is aligned with the box's top padding edge and a value of `100%` means the bottom edge of the image is aligned with the box's bottom padding edge. - `top` - : Equivalent to `0%`. - `bottom` - : Equivalent to `100%`. - `center` - : Equivalent to `50%`. ## Formal definition {{CSSInfo}} ## Formal syntax ```plain -webkit-mask-position-y = [ <length-percentage> | top | center | bottom ]# ``` ## Examples ### Vertically positioning a mask image ```css .exampleOne { -webkit-mask-image: url(mask.png); -webkit-mask-position-y: bottom; } .exampleTwo { -webkit-mask-image: url(mask.png); -webkit-mask-position-y: 25%; } ``` ## Specifications Not part of any standard. ## Browser compatibility {{Compat}} ## See also {{cssxref("mask-position", "-webkit-mask-position")}}, {{cssxref("-webkit-mask-position-x")}}, {{cssxref("mask-origin", "-webkit-mask-origin")}}, {{cssxref("-webkit-mask-attachment")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/-moz-user-input/index.md
--- title: "-moz-user-input" slug: Web/CSS/-moz-user-input page-type: css-property status: - deprecated - non-standard browser-compat: css.properties.-moz-user-input --- {{CSSRef}}{{Non-standard_Header}}{{Deprecated_Header}} In Mozilla applications, **`-moz-user-input`** determines if an element will accept user input. For elements that normally take user input, such as a {{HTMLElement("textarea")}}, the initial value of `-moz-user-input` is `enabled`. > **Note:** `-moz-user-input` was one of the proposals leading to the proposed CSS 3 {{cssxref("user-input")}} property, which has not yet reached Candidate Recommendation (call for implementations). A similar property, `user-focus`, was proposed in [early drafts of a predecessor of the User Interface for CSS3 specification](https://www.w3.org/TR/2000/WD-css3-userint-20000216), but was rejected by the working group. ## Syntax ```css /* Keyword values */ -moz-user-input: none; -moz-user-input: enabled; -moz-user-input: disabled; /* Global values */ -moz-user-input: inherit; -moz-user-input: initial; -moz-user-input: unset; ``` ### Values - `none` {{Deprecated_Inline}} {{Non-standard_Inline}} - : The element does not respond to user input, and it does not become {{CSSxRef(":active")}}. - `enabled` {{Deprecated_Inline}} {{Non-standard_Inline}} - : The element accepts user input. For textboxes, this is the default behavior. **Please note that this value is no longer supported in Firefox 60 onwards ([Firefox bug 1405087](https://bugzil.la/1405087)).** - `disabled` {{Deprecated_Inline}} {{Non-standard_Inline}} - : The element does not accept user input. However, this is not the same as setting `disabled` to true, in that the element is drawn normally. **Please note that this value is no longer supported in Firefox 60 onwards ([Firefox bug 1405087](https://bugzil.la/1405087)).** ## Formal definition {{CSSInfo}} ## Formal syntax ```plain -moz-user-input = auto | none | enabled | disabled ``` ## Examples ### Disabling user input for an element ```css input.example { /* The user will be able to select the text, but not change it. */ -moz-user-input: disabled; } ``` ## Specifications Not part of any standard. ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("-moz-user-focus")}} - {{CSSxRef("user-modify", "-moz-user-modify")}} - {{CSSxRef("user-select", "-moz-user-select")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/-webkit-text-stroke-color/index.md
--- title: "-webkit-text-stroke-color" slug: Web/CSS/-webkit-text-stroke-color page-type: css-property browser-compat: css.properties.-webkit-text-stroke-color --- {{CSSRef}} The **`-webkit-text-stroke-color`** CSS property specifies the stroke [color](/en-US/docs/Web/CSS/color_value) of characters of text. If this property is not set, the value of the {{cssxref("color")}} property is used. ## Syntax ```css /* <color> values */ -webkit-text-stroke-color: red; -webkit-text-stroke-color: #e08ab4; -webkit-text-stroke-color: rgb(200 100 0); /* Global values */ -webkit-text-stroke-color: inherit; -webkit-text-stroke-color: initial; -webkit-text-stroke-color: revert; -webkit-text-stroke-color: revert-layer; -webkit-text-stroke-color: unset; ``` ### Values - `<color>` - : The color of the stroke. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Varying the stroke color #### HTML ```html <p>Text with stroke</p> <input type="color" value="#ff0000" /> ``` #### CSS ```css p { margin: 0; font-size: 4em; -webkit-text-stroke-width: 3px; -webkit-text-stroke-color: #ff0000; /* Can be changed in the live sample */ } ``` ```js hidden const colorPicker = document.querySelector("input"); colorPicker.addEventListener("change", (evt) => { document.querySelector("p").style.webkitTextStrokeColor = evt.target.value; }); ``` #### Results {{EmbedLiveSample("Varying_the_stroke_color", "500px", "100px")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Surfin' Safari blog post announcing this feature](https://webkit.org/blog/85/introducing-text-stroke/) - [CSS-Tricks article explaining this feature](https://css-tricks.com/adding-stroke-to-web-text/) - {{cssxref("-webkit-text-fill-color")}} - {{cssxref("-webkit-text-stroke-width")}} - {{cssxref("-webkit-text-stroke")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/revert/index.md
--- title: revert slug: Web/CSS/revert page-type: css-keyword browser-compat: css.types.global_keywords.revert --- {{CSSRef}} The **`revert`** CSS keyword reverts the cascaded value of the property from its current value to the value the property would have had if no changes had been made by the current **{{Glossary("style origin")}}** to the current element. Thus, it resets the property either to user agent set value, to user set value, to its inherited value (if it is inheritable), or to initial value. It can be applied to any CSS property, including the CSS shorthand property {{cssxref("all")}}. This keyword removes from the cascade all of the styles that have been overridden until the style being rolled back to is reached. - If used by a site's own styles (the author origin), `revert` rolls back the property's cascaded value to the user's custom style, if one exists; otherwise, it rolls the style back to the user agent's default style. - If used in a user's custom stylesheet, or if the style was applied by the user (the user origin), `revert` rolls back the cascaded value to the user agent's default style. - If used within the user agent's default styles, this keyword is functionally equivalent to {{cssxref("unset")}}. The `revert` keyword works exactly the same as [`unset`](/en-US/docs/Web/CSS/unset) in many cases. The only difference is for properties that have values set by the browser or by custom stylesheets created by users (set on the browser side). Revert will not affect rules applied to children of an element you reset (but will remove effects of a parent rule on a child). So if you have a `color: green` for all sections and `all: revert` on a specific section, the color of the section will be black. But if you have a rule to make all paragraphs red, then all paragraphs will still be red in all sections. > **Note:** Revert is just a value. It is still possible to override the `revert` value using [specificity](/en-US/docs/Web/CSS/Specificity). > **Note:** The `revert` keyword is different from and should not be confused with the {{cssxref("initial")}} keyword, which uses the [initial value](/en-US/docs/Web/CSS/initial_value) defined on a per-property basis by the CSS specifications. In contrast, user-agent stylesheets set default values on the basis of CSS selectors. > > For example, the [initial value](/en-US/docs/Web/CSS/initial_value) for the [`display`](/en-US/docs/Web/CSS/display#formal_definition) property is `inline`, whereas a normal user-agent stylesheet sets the default {{cssxref("display")}} value of {{HTMLElement("div")}}s to `block`, of {{HTMLElement("table")}}s to `table`, etc. ## Examples ### Revert vs. unset Although `revert` and `unset` are similar, they differ for some properties for some elements. So in the below example, we set custom [`font-weight`](/en-US/docs/Web/CSS/font-weight#formal_definition), but then try to `revert` and `unset` it inline in the HTML document. The `revert` keyword will revert the text to bold because that is the default value for headers in most browsers. The `unset` keyword will keep the text normal because, as an inherited property, the `font-weight` would then inherit its value from the body. #### HTML ```html <h3 style="font-weight: revert; color: revert;"> This should have its original font-weight (bold) and color: black </h3> <p>Just some text</p> <h3 style="font-weight: unset; color: unset;"> This will still have font-weight: normal, but color: black </h3> <p>Just some text</p> ``` #### CSS ```css h3 { font-weight: normal; color: blue; } ``` #### Result {{EmbedLiveSample('Revert_vs_unset', 0, 200)}} ### Revert all Reverting all values is useful in a situation where you've made several style changes and then you want to revert to the browser default values. So in the above example, instead of reverting `font-weight` and `color` separately, you could just revert all of them at once - by applying the `revert` keyword on `all`. #### HTML ```html <h3>This will have custom styles</h3> <p>Just some text</p> <h3 style="all: revert">This should be reverted to browser/user defaults.</h3> <p>Just some text</p> ``` #### CSS ```css h3 { font-weight: normal; color: blue; border-bottom: 1px solid grey; } ``` #### Result {{EmbedLiveSample('Revert_all', 0, 200)}} ### Revert on a parent Reverting effectively removes the value for the element you select with some rule and this happens only for that element. To illustrate this, we will set a green color on a section and red color on a paragraph. #### HTML ```html <main> <section> <h3>This h3 will be dark green</h3> <p>Text in paragraph will be red.</p> This stray text will also be dark green. </section> <section class="with-revert"> <h3>This h3 will be steelblue</h3> <p>Text in paragraph will be red.</p> This stray text will also be steelblue. </section> </main> ``` #### CSS ```css hidden main { border: 3px solid steelblue; } section { margin: 0.5rem; border: 2px dashed darkgreen; } ``` ```css main { color: steelblue; } section { color: darkgreen; } p { color: red; } section.with-revert { color: revert; } ``` #### Result {{EmbedLiveSample('Revert_on_a_parent', '100%', '300px')}} Notice how the paragraph is still red even though a `color` property for the section was reverted. Also, note that both the header and plain text node are `steelblue`. The result of reverting makes it as if `section { color: darkgreen; }` did not exist for the section with `color: revert` applied. Also, if neither the user agent nor the user override the `<h3>` or `<section>` color values, then the `steelblue` color is inherited from `<main>`, as the {{cssxref("color")}} property is an inherited property. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Use the {{cssxref("initial")}} keyword to set a property to its initial value. - Use the {{cssxref("inherit")}} keyword to make an element's property the same as its parent. - Use the {{cssxref("revert-layer")}} keyword to reset a property to the value established in a previous cascade layer. - Use the {{cssxref("unset")}} keyword to set a property to its inherited value if it inherits or to its initial value if not. - The {{cssxref("all")}} property lets you reset all properties to their initial, inherited, reverted, or unset state at once.
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_-moz-loading/index.md
--- title: ":-moz-loading" slug: Web/CSS/:-moz-loading page-type: css-pseudo-class status: - non-standard --- {{CSSRef}}{{Non-standard_header}} The **`:-moz-loading`** [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 they have not started loading, such as images that haven't started to arrive yet. Note that images that are _in the process_ of loading _are not_ matched by this pseudo-class. > **Note:** This selector is mainly intended to be used by theme developers. ## Syntax ```css :-moz-loading { /* ... */ } ``` ## Examples ### Setting a background for images that are loading ```css :-moz-loading { background-color: #aaa; background-image: url(loading-animation.gif) center no-repeat; } ``` ## Specifications Not part of any standard. ## See also - {{cssxref(":-moz-broken")}}, {{cssxref(":-moz-suppressed")}}, {{cssxref(":-moz-user-disabled")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/round/index.md
--- title: round() slug: Web/CSS/round page-type: css-function browser-compat: css.types.round --- {{CSSRef}} The **`round()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) returns a rounded number based on a selected rounding strategy. Authors should use a [custom CSS property](/en-US/docs/Web/CSS/--*) (e.g., `--my-property`) for the rounding value, interval, or both; using the `round()` function is redundant if these have known values. ## Syntax ```css width: round(var(--width), 50px); width: round(up, 101px, var(--interval)); width: round(down, var(--height), var(--interval)); margin: round(to-zero, -105px, 10px); ``` ### Parameter The `round(<rounding-strategy>, valueToRound, roundingInterval)` function specifies an optional rounding strategy, a value (or mathematical expression) to be rounded and a rounding interval (or mathematical expression). The `valueToRound` is rounded according to the rounding strategy, to the nearest integer multiple of `roundingInterval`. - `<rounding-strategy>` - : The rounding strategy. This may be one of the following values: - `up` - : Round `valueToRound` up to the nearest integer multiple of `roundingInterval` (if the value is negative, it will become "more positive"). This is equivalent to the JavaScript [`Math.ceil()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil) method. - `down` - : Round `valueToRound` down to the nearest integer multiple of `roundingInterval` (if the value is negative, it will become "more negative"). This is equivalent to the JavaScript [`Math.floor()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor) method. - `nearest` (default) - : Round `valueToRound` to the nearest integer multiple of `roundingInterval`, which may be either above or below the value. If the `valueToRound` is half way between the rounding targets above and below (neither is "nearest"), it will be rounded up. Equivalent to JavaScript [`Math.round()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round). - `to-zero` - : Round `valueToRound` to the nearest integer multiple of `roundingInterval` closer to/towards zero (a positive number will decrease, while a negative value will become "less negative"). This is equivalent to the JavaScript [`Math.trunc()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc) method. - `valueToRound` - : The value to be rounded. This must be a {{CSSxREF("&lt;number&gt;")}}, {{CSSxREF("&lt;dimension&gt;")}}, or {{CSSxREF("&lt;percentage&gt;")}}, or a mathematical expression that resolves to one of those values. - `roundingInterval` - : The rounding interval. This is a {{CSSxREF("&lt;number&gt;")}}, {{CSSxREF("&lt;dimension&gt;")}}, or {{CSSxREF("&lt;percentage&gt;")}}, or a mathematical expression that resolves to one of those values. ### Return value The value of `valueToRound`, rounded to the nearest lower or higher integer multiple of `roundingInterval`, depending on the `rounding strategy`. - If `roundingInterval` is 0, the result is `NaN`. - If `valueToRound` and `roundingInterval` are both `infinite`, the result is `NaN`. - If `valueToRound` is infinite but `roundingInterval` is finite, the result is the same `infinity`. - If `valueToRound` is finite but `roundingInterval` is infinite, the result depends on the rounding strategy and the sign of `A`: - `up` - If `valueToRound` is positive (not zero), return `+∞`. If `valueToRound` is `0⁺`, return `0⁺`. Otherwise, return `0⁻`. - `down` - If `valueToRound` is negative (not zero), return `−∞`. If `valueToRound` is `0⁻`, return `0⁻`. Otherwise, return `0⁺`. - `nearest`, `to-zero` - If `valueToRound` is positive or `0⁺`, return `0⁺`. Otherwise, return `0⁻`. - The argument calculations can resolve to {{CSSxREF("&lt;number&gt;")}}, {{CSSxREF("&lt;dimension&gt;")}}, or {{CSSxREF("&lt;percentage&gt;")}}, but must have the same type, or else the function is invalid; the result will have the same type as the arguments. - If `valueToRound` is exactly equal to an integer multiple of `roundingInterval`, `round()` resolves to `valueToRound` exactly (preserving whether `valueToRound` is `0⁻` or `0⁺`, if relevant). Otherwise, there are two integer multiples of `roundingInterval` that are potentially "closest" to `valueToRound`, lower `roundingInterval` which is closer to `−∞` and upper `roundingInterval` which is closer to `+∞`. ### Formal syntax {{CSSSyntax}} ## Examples ### Round positive values This example demonstrates how the `round()` function's rounding strategies work for positive values. Of the five boxes below, the `round()` function is used to set the height of the last four. The value to be rounded is between 100 px and 125 px in each case, and the rounding value is 25px in all cases. The height of the boxes is therefore either rounded up to 125 px or down to 100 px. #### HTML The HTML defines 5 `div` elements that will be rendered as boxes by the CSS. The elements contain text indicating the rounding strategy, initial value, and expected final height of the box (in parentheses). ```html <div class="box box-1">height: 100px</div> <div class="box box-2">up 101px (125px)</div> <div class="box box-3">down 122px (100px)</div> <div class="box box-4">to-zero 120px (100px)</div> <div class="box box-5">nearest 117px (125px)</div> ``` #### CSS ```css hidden body { height: 100vh; display: flex; justify-content: center; align-items: center; gap: 50px; } ``` The CSS that is applied to all boxes is shown below. Note that we apply a [custom CSS property](/en-US/docs/Web/CSS/--*) named `--rounding-interval`, that we will use for the rounding interval. ```css div.box { width: 100px; height: 100px; background: lightblue; padding: 5px; --rounding-interval: 25px; } ``` The first `div` from the left isn't targeted with specific CSS rules, so it will have a default height of 100px. The CSS for `div` two, three, and four is shown below, which round, up, down, and to-zero, respectively. ```css div.box-2 { height: round(up, 101px, var(--rounding-interval)); } div.box-3 { height: round(down, 122px, var(--rounding-interval)); } div.box-4 { height: round(to-zero, 120px, var(--rounding-interval)); } ``` Notice how above we indicate the rounding interval using `var()` and the custom CSS property `--rounding-interval`. The last box is set without specifying a rounding strategy, and hence defaults to `nearest`. In this case, the nearest interval to 117 px is 125px, so it will round up. Just for contrast, here we specified hard coded values for both the rounding value and interval. While this is allowed, you wouldn't do this normally because there is no point rounding a number when you already know what the result must be. ```css div.box-5 { height: round(117px, 25px); } ``` #### Result If the browser supports the CSS `round()` function, you should see five columns with heights that are rounded as indicated by their contained text. {{EmbedLiveSample('Round positive values', '100%', '200px')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("mod")}} - {{CSSxRef("rem")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/initial/index.md
--- title: initial slug: Web/CSS/initial page-type: css-keyword browser-compat: css.types.global_keywords.initial --- {{CSSRef}} The **`initial`** CSS keyword applies the [initial (or default) value](/en-US/docs/Web/CSS/initial_value) of a property to an element. It can be applied to any CSS property, including the CSS shorthand property {{cssxref("all")}}. With `all` set to `initial`, all CSS properties can be restored to their respective initial values in one go instead of restoring each one separately. On [inherited properties](/en-US/docs/Web/CSS/Inheritance#inherited_properties), the initial value may be unexpected. You should consider using the {{cssxref("inherit")}}, {{cssxref("unset")}}, {{cssxref("revert")}}, or {{cssxref("revert-layer")}} keywords instead. ## Examples ### Using initial to reset color for an element #### HTML ```html <p> <span>This text is red.</span> <em>This text is in the initial color (typically black).</em> <span>This is red again.</span> </p> ``` #### CSS ```css p { color: red; } em { color: initial; } ``` #### Result {{EmbedLiveSample('Using_initial_to_reset_color_for_an_element')}} With the `initial` keyword in this example, `color` value on the `em` element is restored to the initial value of [`color`](/en-US/docs/Web/CSS/color#formal_definition), as defined in the specification. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Use the {{cssxref("inherit")}} keyword to make an element's property the same as its parent. - Use the {{cssxref("revert")}} keyword to reset a property to the value established by the user-agent stylesheet (or by user styles, if any exist). - Use the {{cssxref("revert-layer")}} keyword to reset a property to the value established in a previous cascade layer. - Use the {{cssxref("unset")}} keyword to set a property to its inherited value if it inherits or to its initial value if not. - The {{cssxref("all")}} property lets you reset all properties to their initial, inherited, reverted, or unset state at once.
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/font-synthesis/index.md
--- title: font-synthesis slug: Web/CSS/font-synthesis page-type: css-property browser-compat: css.properties.font-synthesis --- {{CSSRef}} The **`font-synthesis`** [shorthand](/en-US/docs/Web/CSS/Shorthand_properties) [CSS](/en-US/docs/Web/CSS) property lets you specify whether or not the browser may synthesize the bold, italic, small-caps, and/or subscript and superscript typefaces when they are missing in the specified font-family. {{EmbedInteractiveExample("pages/css/font-synthesis.html")}} ## Constituent properties This property is a shorthand for the following CSS properties: - [font-synthesis-weight](/en-US/docs/Web/CSS/font-synthesis-weight) - [font-synthesis-style](/en-US/docs/Web/CSS/font-synthesis-style) - [font-synthesis-small-caps](/en-US/docs/Web/CSS/font-synthesis-small-caps) - [font-synthesis-position](/en-US/docs/Web/CSS/font-synthesis-position) ## Syntax ```css /* none or one or more of the other keyword values */ font-synthesis: none; font-synthesis: weight; font-synthesis: style; font-synthesis: position; font-synthesis: small-caps style; /* property values can be in any order */ font-synthesis: style small-caps weight position; /* property values can be in any order */ /* Global values */ font-synthesis: inherit; font-synthesis: initial; font-synthesis: revert; font-synthesis: revert-layer; font-synthesis: unset; ``` ### Values - `none` - : Indicates that no bold, italic, or small-caps typeface may be synthesized by the browser. - `weight` - : Indicates that the missing bold typeface may be synthesized by the browser if needed. - `style` - : Indicates that the italic typeface may be synthesized by the browser if needed. - `small-caps` - : Indicates that the small-caps typeface may be synthesized by the browser if needed. - `position` - : Indicates that the subscript and superscript typeface may be synthesized by the browser, if needed, when using {{cssxref("font-variant-position")}}. ## Description Most standard Western fonts include italic and bold variants, and some fonts include a small-caps and subscript/superscript variants. However, many fonts do not. Fonts used for Chinese, Japanese, Korean and other logographic scripts tend not to include these variants and synthesizing them might impede the legibility or change the meaning of the text. In these cases, it may be desirable to switch off the browser's default font-synthesis. For example, using the [:lang()](/en-US/docs/Web/CSS/:lang) pseudo-class, you can disable the browser from synthesizing bold and oblique characters for a language, in this case Arabic: ```css *:lang(ar) { font-synthesis: none; } ``` The table below shows how a value of the shorthand `font-synthesis` property maps to the constituent longhand properties. | font-synthesis value | [font-synthesis-weight](/en-US/docs/Web/CSS/font-synthesis-weight) value | [font-synthesis-style](/en-US/docs/Web/CSS/font-synthesis-style) value | [font-synthesis-small-caps](/en-US/docs/Web/CSS/font-synthesis-small-caps) value | [font-synthesis-position](/en-US/docs/Web/CSS/font-synthesis-position) value | | :--------------------------------- | :----------------------------------------------------------------------- | :--------------------------------------------------------------------- | :------------------------------------------------------------------------------- | :--------------------------------------------------------------------------- | | `none` | `none` | `none` | `none` | `none` | | `weight` | `auto` | `none` | `none` | `none` | | `style` | `none` | `auto` | `none` | `none` | | `small-caps` | `none` | `none` | `auto` | `none` | | `position` | `none` | `none` | `none` | `auto` | | `weight style` | `auto` | `auto` | `none` | `none` | | `weight small-caps` | `auto` | `none` | `auto` | `none` | | `weight position` | `auto` | `none` | `none` | `auto` | | `style small-caps` | `none` | `auto` | `auto` | `none` | | `style position` | `none` | `auto` | `none` | `auto` | | `weight style small-caps` | `auto` | `auto` | `auto` | `none` | | `weight style position` | `auto` | `auto` | `none` | `auto` | | `weight small-caps position` | `auto` | `none` | `auto` | `auto` | | `style small-caps position` | `none` | `auto` | `auto` | `auto` | | `weight style small-caps position` | `auto` | `auto` | `auto` | `auto` | ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Disabling font synthesis This example shows the browser's default font-synthesis behavior and compares it with when the synthesis behavior is turned off. Notice that the example uses two imported fonts to demonstrate this behavior. You might not be able to replicate turning off of font-synthesis on fonts available on your operating system by default. #### HTML ```html <pre> DEFAULT </pre> <p class="english"> This font supports <strong>bold</strong> and <em>italic</em>. </p> <p class="chinese">这个字体支持<strong>加粗</strong>和<em>斜体</em></p> <br /> <pre> SYNTHESIS IS DISABLED </pre> <p class="english no-syn"> This font supports <strong>bold</strong> and <em>italic.</em> </p> <p class="chinese no-syn">这个字体支持<strong>加粗</strong>和<em>斜体</em></p> <br /> <pre> SYNTHESIS IS ENABLED </pre> <p class="english"> This font supports <strong>bold</strong> and <em>italic</em>. </p> <p class="chinese syn">这个字体支持<strong>加粗</strong>和<em>斜体</em></p> ``` #### CSS ```css @import url("https://fonts.googleapis.com/css2?family=Montserrat&display=swap"); @import url("https://fonts.googleapis.com/css2?family=Ma+Shan+Zheng&display=swap"); .english { font-family: "Montserrat", sans-serif; } .chinese { font-family: "Ma Shan Zheng"; } .no-syn { font-synthesis: none; } .syn { font-synthesis: style weight; } ``` #### Result {{EmbedLiveSample('Disabling font synthesis', '', '400')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("font-style")}} - {{cssxref("font-weight")}} - {{cssxref("font-variant-caps")}} - {{cssxref("font-variant-position")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/symbols/index.md
--- title: symbols() slug: Web/CSS/symbols page-type: css-function browser-compat: css.properties.list-style-type.symbols --- {{CSSRef}} The **`symbols()`** CSS function enables defining counter styles inline, directly as a value of properties such as {{cssxref("list-style")}}, providing a less powerful but simpler alternative to the {{cssxref("@counter-style")}} method of defining a counter style. Unlike {{cssxref("@counter-style")}}, which defines a reusable counter style, `symbols()` is _anonymous_ (i.e., it can only be used once). This function accepts strings and images as values. In comparison, the {{cssxref("@counter-style")}}'s [`symbols`](/en-US/docs/Web/CSS/@counter-style/symbols) descriptor also accepts identifiers. ## Syntax ```css symbols() = symbols( <symbols-type>? [ <string> | <image> ]+ ); ``` `<symbols-type>` can be one of the following: - `cyclic`: The system cycles through the given values in the order of their definition, and returns to the start when it reaches the end. - `numeric`: The system interprets the given values as the successive units of a place-value numbering system. - `alphabetic`: The system interprets the given values as the digits of an alphabetic numbering system, like a place-value numbering system but without `0`. - `symbolic`: The system cycles through the values, printing them an additional time at each cycle (one time for the first cycle, two times for the second, etc.). - `fixed`: The system cycles through the given values once, then falls back to Arabic numerals. ## Examples ### HTML ```html <ol> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> <li>Five</li> </ol> ``` ### CSS ```css ol { list-style: symbols(cyclic "*" "†" "‡"); } ``` ### Result {{EmbedLiveSample('Examples','100%',200)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("@counter-style")}} descriptors: {{cssxref("@counter-style/system","system")}}, {{cssxref("@counter-style/symbols", "symbols")}}, {{cssxref("@counter-style/additive-symbols", "additive-symbols")}}, {{cssxref("@counter-style/prefix", "prefix")}}, {{cssxref("@counter-style/suffix", "suffix")}}, {{cssxref("@counter-style/range", "range")}}, {{cssxref("@counter-style/pad", "pad")}}, {{cssxref("@counter-style/speak-as", "speak-as")}}, {{cssxref("@counter-style/fallback", "fallback")}} - List style properties: {{cssxref("list-style")}}, {{cssxref("list-style-type")}} - [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/box-flex-group/index.md
--- title: box-flex-group slug: Web/CSS/box-flex-group page-type: css-property status: - deprecated - non-standard browser-compat: css.properties.box-flex-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-flex-group`** [CSS](/en-US/docs/Web/CSS) property assigns the flexbox's child elements to a flex group. For flexible elements assigned to flex groups, the first flex group is 1 and higher values specify subsequent flex groups. The initial value is 1. When dividing up the box's extra space, the browser first considers all elements within the first flex group. Each element within that group is given extra space based on the ratio of that element's flexibility compared to the flexibility of other elements within the same flex group. If the space of all flexible children within the group has been increased to the maximum, the process repeats for the children within the next flex group, using any space left over from the previous flex group. Once there are no more flex groups, and there is still space remaining, the extra space is divided within the containing box according to the {{cssxref("box-pack")}} property. If the box would overflow after the preferred space of the children has been computed, then space is removed from flexible elements in a manner similar to that used when adding extra space. Each flex group is examined in turn and space is removed according to the ratio of the flexibility of each element. Elements do not shrink below their minimum widths. ## Syntax ```css /* <integer> values */ box-flex-group: 1; box-flex-group: 5; /* Global values */ box-flex-group: inherit; box-flex-group: initial; box-flex-group: unset; ``` The `box-flex-group` property is specified as any positive {{CSSxRef("&lt;integer&gt;")}}. ## Formal definition {{CSSInfo}} ## Formal syntax ```plain box-flex-group = <integer> ``` ## Examples ### Simple usage example In the original Flexbox spec, `box-flex-group` could be used to assign flex children to different groups to distribute flexible space between: ```css article:nth-child(1) { -webkit-box-flex-group: 1; } article:nth-child(2) { -webkit-box-flex-group: 2; } ``` This was only ever supported in WebKit-based browsers, with a prefix, and in subsequent versions of the spec this functionality does not have an equivalent. Instead, distribution of space inside the flex container is now handled using [`flex-basis`](/en-US/docs/Web/CSS/flex-basis), [`flex-grow`](/en-US/docs/Web/CSS/flex-grow), and [`flex-shrink`](/en-US/docs/Web/CSS/flex-shrink). ## 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/contain-intrinsic-height/index.md
--- title: contain-intrinsic-height slug: Web/CSS/contain-intrinsic-height page-type: css-property browser-compat: css.properties.contain-intrinsic-height --- {{CSSRef}} The **`contain-intrinsic-length`** [CSS](/en-US/docs/Web/CSS) property sets the height of an element that a browser can use for layout when the element is subject to [size containment](/en-US/docs/Web/CSS/CSS_containment#size_containment). ## Syntax ```css /* Keyword values */ contain-intrinsic-height: none; /* <length> values */ contain-intrinsic-height: 1000px; contain-intrinsic-height: 10rem; /* auto <length> */ contain-intrinsic-height: auto 300px; /* Global values */ contain-intrinsic-height: inherit; contain-intrinsic-height: initial; contain-intrinsic-height: revert; contain-intrinsic-height: revert-layer; contain-intrinsic-height: unset; ``` ### Values The following values may be specified for an element. - `none` - : The element has no intrinsic height. - `<length>` - : The element has the specified height ({{cssxref("&lt;length&gt;")}}). - `auto <length>` - : A remembered value of the "normally rendered" element height if one exists and the element is skipping its contents (for example, when it is offscreen); otherwise the specified `<length>`. ## Description The property is commonly applied alongside elements that can trigger size containment, such as [`contain: size`](/en-US/docs/Web/CSS/contain) and [`content-visibility`](/en-US/docs/Web/CSS/content-visibility), and may also be set using the [`contain-intrinsic-size`](/en-US/docs/Web/CSS/contain-intrinsic-size) [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties). Size containment allows a user agent to lay out an element as though it had a fixed size, preventing unnecessary reflows by avoiding the re-rendering of child elements to determine the actual size (thereby improving user experience). By default, size containment treats elements as though they had no contents, and may collapse the layout in the same way as if the contents had no height (or width). The `contain-intrinsic-height` property allows authors to specify an appropriate value to be used as the height for layout. The `auto <length>` value allows the height of the element to be stored if the element is ever "normally rendered" (with its child elements), and then used instead of the specified height when the element is skipping its contents. This allows offscreen elements with [`content-visibility: auto`](/en-US/docs/Web/CSS/content-visibility) to benefit from size containment without developers having to be as precise in their estimates of element size. The remembered value is not used if the child elements are being rendered (if size containment is enabled, the `<length>` will be used). ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples In addition to the example below, the {{CSSxRef("contain-intrinsic-size")}} page contains a live example that demonstrates the effect of modifying the intrinsic width and height. ### Setting the intrinsic height The HTML below defines an element "contained_element" that will be subject to size constraint, and which contains a child element. ```html <div id="contained_element"> <div class="child_element"></div> </div> ``` The CSS below sets the [`content-visibility`](/en-US/docs/Web/CSS/content-visibility) of `contained_element` to `auto`, so if the element is hidden it will be size constrained. The width and height that are used when it is size constrained are set at the same time using `contain-intrinsic-width` and `contain-intrinsic-height`, respectively. ```css #contained_element { border: 2px solid green; width: 151px; content-visibility: auto; contain-intrinsic-width: 152px; contain-intrinsic-height: 52px; } .child_element { border: 1px solid red; background: blue; height: 50px; width: 150px; } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [content-visibility: the new CSS property that boosts your rendering performance](https://web.dev/articles/content-visibility) (web.dev) - {{CSSxRef("contain-intrinsic-size")}} - {{CSSxRef("contain-intrinsic-width")}} - {{CSSxRef("contain-intrinsic-block-size")}} - {{CSSxRef("contain-intrinsic-inline-size")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/font-synthesis-small-caps/index.md
--- title: font-synthesis-small-caps slug: Web/CSS/font-synthesis-small-caps page-type: css-property browser-compat: css.properties.font-synthesis-small-caps --- {{CSSRef}} The **`font-synthesis-small-caps`** [CSS](/en-US/docs/Web/CSS) property lets you specify whether or not the browser may synthesize small-caps typeface when it is missing in a font family. Small-caps glyphs typically use the form of uppercase letters but are reduced to the size of lowercase letters. It is often convenient to use the shorthand property {{cssxref("font-synthesis")}} to control all typeface synthesis values. ## Syntax ```css /* Keyword values */ font-synthesis-small-caps: auto; font-synthesis-small-caps: none; /* Global values */ font-synthesis-small-caps: inherit; font-synthesis-small-caps: initial; font-synthesis-small-caps: revert; font-synthesis-small-caps: revert-layer; font-synthesis-small-caps: unset; ``` ### Values - `auto` - : Indicates that the missing small-caps typeface may be synthesized by the browser if needed. - `none` - : Indicates that the synthesis of the missing small-caps typeface by the browser is not allowed. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Disabling synthesis of small-caps typeface This example shows turning off synthesis of the small-caps typeface by the browser in the `Montserrat` font. #### HTML ```html <p class="english"> These are the default <span class="small-caps">small-caps</span>, <strong>bold</strong>, and <em>oblique</em> typefaces. </p> <p class="english no-syn"> The <span class="small-caps">small-caps</span> typeface is turned off here but not the <strong>bold</strong> and <em>oblique</em> typefaces. </p> ``` #### CSS ```css @import url("https://fonts.googleapis.com/css2?family=Montserrat&display=swap"); .english { font-family: "Montserrat", sans-serif; } .small-caps { font-variant: small-caps; } .no-syn { font-synthesis-small-caps: none; } ``` #### Result {{EmbedLiveSample('Disabling synthesis of small-caps typeface', '', '100')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [font-synthesis](/en-US/docs/Web/CSS/font-synthesis) shorthand, [font-synthesis-style](/en-US/docs/Web/CSS/font-synthesis-style), [font-synthesis-weight](/en-US/docs/Web/CSS/font-synthesis-weight) - {{cssxref("font-style")}}, {{cssxref("font-variant")}}, {{cssxref("font-variant-caps")}}, {{cssxref("font-weight")}} - [CanvasRenderingContext2D: fontVariantCaps property](/en-US/docs/Web/API/CanvasRenderingContext2D/fontVariantCaps)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/text-rendering/index.md
--- title: text-rendering slug: Web/CSS/text-rendering page-type: css-property browser-compat: css.properties.text-rendering --- {{CSSRef}} The **`text-rendering`** CSS property provides information to the rendering engine about what to optimize for when rendering text. The browser makes trade-offs among speed, legibility, and geometric precision. > **Note:** The `text-rendering` property is an SVG property that is not defined in any CSS standard. However, Gecko and WebKit browsers let you apply this property to HTML and XML content on Windows, macOS, and Linux. One very visible effect is `optimizeLegibility`, which enables ligatures (ff, fi, fl, etc.) in text smaller than 20px for some fonts (for example, Microsoft's _Calibri_, _Candara_, _Constantia_, and _Corbel_, or the _DejaVu_ font family). ## Syntax ```css /* Keyword values */ text-rendering: auto; text-rendering: optimizeSpeed; text-rendering: optimizeLegibility; text-rendering: geometricPrecision; /* Global values */ text-rendering: inherit; text-rendering: initial; text-rendering: revert; text-rendering: revert-layer; text-rendering: unset; ``` ### Values - `auto` {{Non-standard_Inline}} - : The browser makes educated guesses about when to optimize for speed, legibility, and geometric precision while drawing text. For differences in how this value is interpreted by the browser, see the compatibility table. - `optimizeSpeed` - : The browser emphasizes rendering speed over legibility and geometric precision when drawing text. It disables kerning and ligatures. - `optimizeLegibility` - : The browser emphasizes legibility over rendering speed and geometric precision. This enables kerning and optional ligatures. - `geometricPrecision` {{Non-standard_Inline}} - : The browser emphasizes geometric precision over rendering speed and legibility. Certain aspects of fonts — such as kerning — don't scale linearly. So this value can make text using those fonts look good. In SVG, when text is scaled up or down, browsers calculate the final size of the text (which is determined by the specified font size and the applied scale) and request a font of that computed size from the platform's font system. But if you request a font size of, say, 9 with a scale of 140%, the resulting font size of 12.6 doesn't explicitly exist in the font system, so the browser rounds the font size to 12 instead. This results in stair-step scaling of text. But the `geometricPrecision` property — when fully supported by the rendering engine — lets you scale your text fluidly. For large scale factors, you might see less-than-beautiful text rendering, but the size is what you would expect—neither rounded up nor down to the nearest font size supported by Windows or Linux. > **Note:** WebKit precisely applies the specified value, but Gecko treats the value the same as `optimizeLegibility`. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Automatic application of optimizeLegibility This demonstrates how `optimizeLegibility` is used by browsers automatically when the `font-size` is smaller than `20px`. #### HTML ```html <p class="small">LYoWAT - ff fi fl ffl</p> <p class="big">LYoWAT - ff fi fl ffl</p> ``` #### CSS ```css .small { font: 19.9px "Constantia", "Times New Roman", "Georgia", "Palatino", serif; } .big { font: 20px "Constantia", "Times New Roman", "Georgia", "Palatino", serif; } ``` #### Result {{ EmbedLiveSample('Automatic_application_of_optimizeLegibility') }} ### optimizeSpeed vs. optimizeLegibility This example shows the difference between the appearance of `optimizeSpeed` and `optimizeLegibility` (in your browser; other browsers may vary). #### HTML ```html <p class="speed">LYoWAT - ff fi fl ffl</p> <p class="legibility">LYoWAT - ff fi fl ffl</p> ``` #### CSS ```css p { font: 1.5em "Constantia", "Times New Roman", "Georgia", "Palatino", serif; } .speed { text-rendering: optimizeSpeed; } .legibility { text-rendering: optimizeLegibility; } ``` #### Result {{ EmbedLiveSample('optimizeSpeed_vs_optimizeLegibility') }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Drawing text in a `<canvas>`](/en-US/docs/Web/API/Canvas_API/Tutorial/Drawing_text) - [CSS Text Decoration](/en-US/docs/Web/CSS/CSS_text_decoration) CSS module - Related CSS properties - [`text-decoration`](/en-US/docs/Web/CSS/text-decoration) (and its longhand properties, such as [`text-decoration-line`](/en-US/docs/Web/CSS/text-decoration-line), [`text-decoration-style`](/en-US/docs/Web/CSS/text-decoration-style), and [`text-decoration-thickness`](/en-US/docs/Web/CSS/text-decoration-thickness)) - [`text-emphasis`](/en-US/docs/Web/CSS/text-emphasis) (and its longhand properties, including [`text-emphasis-color`](/en-US/docs/Web/CSS/text-emphasis-color), [`text-emphasis-position`](/en-US/docs/Web/CSS/text-emphasis-position), and [`text-emphasis-style`](/en-US/docs/Web/CSS/text-emphasis-style)) - [`text-shadow`](/en-US/docs/Web/CSS/text-shadow) - [`text-transform`](/en-US/docs/Web/CSS/text-transform) - The [SVG](/en-US/docs/Web/SVG) {{SVGAttr("text-rendering")}} attribute - [SVG and CSS](/en-US/docs/Web/SVG/Tutorial/SVG_and_CSS)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/acos/index.md
--- title: acos() slug: Web/CSS/acos page-type: css-function browser-compat: css.types.acos --- {{CSSRef}} The **`acos()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) is a trigonometric function that returns the inverse cosine of a number between `-1` and `1`. The function contains a single calculation that returns the number of radians representing an {{cssxref("&lt;angle&gt;")}} between `0deg` and `180deg`. ## Syntax ```css /* Single <number> values */ transform: rotate(acos(-0.2)); transform: rotate(acos(2 * 0.125)); /* Other values */ transform: rotate(acos(pi / 5)); transform: rotate(acos(e / 3)); ``` ### Parameter The `acos(number)` function accepts only one value as its parameter. - `number` - : A calculation which resolves to a {{cssxref("&lt;number&gt;")}} between `-1` and `1`. ### Return value The inverse cosine of an `number` will always return an {{cssxref("&lt;angle&gt;")}} between `0deg` and `180deg`. - If `number` is less than `-1` or greater than `1`, the result is `NaN`. - If `number` is exactly `1`, the result is `0`. ### Formal syntax {{CSSSyntax}} ## Examples ### Rotate elements The `acos()` function can be used to {{cssxref("transform-function/rotate", "rotate")}} elements as it return an {{cssxref("&lt;angle&gt;")}}. #### HTML ```html <div class="box box-1"></div> <div class="box box-2"></div> <div class="box box-3"></div> <div class="box box-4"></div> <div class="box box-5"></div> ``` #### CSS ```css hidden body { height: 100vh; display: flex; justify-content: center; align-items: center; gap: 50px; } ``` ```css div.box { width: 100px; height: 100px; background: linear-gradient(orange, red); } div.box-1 { transform: rotate(acos(1)); } div.box-2 { transform: rotate(acos(0.5)); } div.box-3 { transform: rotate(acos(0)); } div.box-4 { transform: rotate(acos(-0.5)); } div.box-5 { transform: rotate(acos(-1)); } ``` #### Result {{EmbedLiveSample('Rotate elements', '100%', '200px')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("sin")}} - {{CSSxRef("cos")}} - {{CSSxRef("tan")}} - {{CSSxRef("asin")}} - {{CSSxRef("atan")}} - {{CSSxRef("atan2")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/align-self/index.md
--- title: align-self slug: Web/CSS/align-self page-type: css-property browser-compat: css.properties.align-self --- {{CSSRef}} The **`align-self`** [CSS](/en-US/docs/Web/CSS) property overrides a grid or flex item's {{cssxref("align-items")}} value. In Grid, it aligns the item inside the {{glossary("Grid Areas", "grid area")}}. In Flexbox, it aligns the item on the {{glossary("cross axis")}}. {{EmbedInteractiveExample("pages/css/align-self.html")}} The property doesn't apply to block-level boxes, or to table cells. If a flexbox item's cross-axis margin is `auto`, then `align-self` is ignored. ## Syntax ```css /* Keyword values */ align-self: auto; align-self: normal; /* Positional alignment */ /* align-self does not take left and right values */ align-self: center; /* Put the item around the center */ align-self: start; /* Put the item at the start */ align-self: end; /* Put the item at the end */ align-self: self-start; /* Align the item flush at the start */ align-self: self-end; /* Align the item flush at the end */ align-self: flex-start; /* Put the flex item at the start */ align-self: flex-end; /* Put the flex item at the end */ /* Baseline alignment */ align-self: baseline; align-self: first baseline; align-self: last baseline; align-self: stretch; /* Stretch 'auto'-sized items to fit the container */ /* Overflow alignment */ align-self: safe center; align-self: unsafe center; /* Global values */ align-self: inherit; align-self: initial; align-self: revert; align-self: revert-layer; align-self: unset; ``` ### Values - `auto` - : Computes to the parent's {{cssxref("align-items")}} value. - `normal` - : The effect of this keyword is dependent of the layout mode we are in: - In absolutely-positioned layouts, the keyword behaves like `start` on _replaced_ absolutely-positioned boxes, and as `stretch` on _all other_ absolutely-positioned boxes. - In static position of absolutely-positioned layouts, the keyword behaves as `stretch`. - For flex items, the keyword behaves as `stretch`. - For grid items, this keyword leads to a behavior similar to the one of `stretch`, except for boxes with an aspect ratio or an intrinsic sizes where it behaves like `start`. - The property doesn't apply to block-level boxes, and to table cells. - `self-start` - : Aligns the items to be flush with the edge of the alignment container corresponding to the item's start side in the cross axis. - `self-end` - : Aligns the items to be flush with the edge of the alignment container corresponding to the item's end side in the cross axis. - `flex-start` - : The cross-start margin edge of the flex item is flushed with the cross-start edge of the line. - `flex-end` - : The cross-end margin edge of the flex item is flushed with the cross-end edge of the line. - `center` - : The flex item's margin box is centered within the line on the cross-axis. If the cross-size of the item is larger than the flex container, it will overflow equally in both directions. - `baseline`, `first baseline`, `last baseline` - : Specifies participation in first- or last-baseline alignment: aligns the alignment baseline of the box's first or last baseline set with the corresponding baseline in the shared first or last baseline set of all the boxes in its baseline-sharing group. The fallback alignment for `first baseline` is `start`, the one for `last baseline` is `end`. - `stretch` - : If the combined size of the items along the cross axis is less than the size of the alignment container and the item is `auto`-sized, its size is 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 of all `auto`-sized items exactly fills the alignment container along the cross axis. - `safe` - : If the size of the item overflows the alignment container, the item is instead aligned as if the alignment mode were `start`. - `unsafe` - : Regardless of the relative sizes of the item and alignment container, the given alignment value is honored. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### HTML ```html <section> <div>Item #1</div> <div>Item #2</div> <div>Item #3</div> </section> ``` ### CSS ```css section { display: flex; align-items: center; height: 120px; background: beige; } div { height: 60px; background: cyan; margin: 5px; } div:nth-child(3) { align-self: flex-end; background: pink; } ``` ### Result {{EmbedLiveSample('Examples')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - CSS Flexbox Guide: _[Basic Concepts of Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox)_ - CSS Flexbox Guide: _[Aligning items in a flex container](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Aligning_items_in_a_flex_container)_ - CSS Grid Guide: _[Box alignment in CSS Grid layouts](/en-US/docs/Web/CSS/CSS_grid_layout/Box_alignment_in_grid_layout)_ - [CSS Box Alignment](/en-US/docs/Web/CSS/CSS_box_alignment) - The {{cssxref("align-items")}} property
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/mask-border-source/index.md
--- title: mask-border-source slug: Web/CSS/mask-border-source page-type: css-property browser-compat: css.properties.mask-border-source --- {{CSSRef}} The **`mask-border-source`** [CSS](/en-US/docs/Web/CSS) property sets the source image used to create an element's [mask border](/en-US/docs/Web/CSS/mask-border). The {{cssxref("mask-border-slice")}} property is used to divide the source image into regions, which are then dynamically applied to the final mask border. ## Syntax ```css /* Keyword value */ mask-border-source: none; /* <image> values */ mask-border-source: url(image.jpg); mask-border-source: linear-gradient(to top, red, yellow); /* Global values */ mask-border-source: inherit; mask-border-source: initial; mask-border-source: revert; mask-border-source: revert-layer; mask-border-source: unset; ``` ### Values - `none` - : No mask border is used. - {{cssxref("&lt;image&gt;")}} - : Image reference to use for the mask border. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Basic usage This property doesn't appear to be supported anywhere yet. When it eventually starts to be supported, it will serve to define the source of the border mask. ```css mask-border-source: url(image.jpg); ``` Chromium-based browsers support an outdated version of this property — `mask-box-image-source` — with a prefix: ```css -webkit-mask-box-image-source: url(image.jpg); ``` > **Note:** The [`mask-border`](/en-US/docs/Web/CSS/mask-border) page features a working example (using the out-of-date prefixed border mask properties supported in Chromium), so you can get an idea of the effect. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("mask-border")}} - {{cssxref("mask-border-mode")}} - {{cssxref("mask-border-outset")}} - {{cssxref("mask-border-repeat")}} - {{cssxref("mask-border-width")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/unicode-bidi/index.md
--- title: unicode-bidi slug: Web/CSS/unicode-bidi page-type: css-property browser-compat: css.properties.unicode-bidi --- {{CSSRef}} The **`unicode-bidi`** [CSS](/en-US/docs/Web/CSS) property, together with the {{cssxref("direction")}} property, determines how bidirectional text in a document is handled. For example, if a block of content contains both left-to-right and right-to-left text, the user-agent uses a complex Unicode algorithm to decide how to display the text. The `unicode-bidi` property overrides this algorithm and allows the developer to control the text embedding. {{EmbedInteractiveExample("pages/css/unicode-bidi.html")}} The `unicode-bidi` and {{cssxref("direction")}} properties are the only properties that are not affected by the {{cssxref("all")}} shorthand. > **Warning:** This property is intended for Document Type Definition (DTD) designers. Web designers and similar authors **should not** override it. ## Syntax ```css /* Keyword values */ unicode-bidi: normal; unicode-bidi: embed; unicode-bidi: isolate; unicode-bidi: bidi-override; unicode-bidi: isolate-override; unicode-bidi: plaintext; /* Global values */ unicode-bidi: inherit; unicode-bidi: initial; unicode-bidi: revert; unicode-bidi: revert-layer; unicode-bidi: unset; ``` ### Values - `normal` - : The element does not offer an additional level of embedding with respect to the bidirectional algorithm. For inline elements, implicit reordering works across element boundaries. - `embed` - : If the element is inline, this value opens an additional level of embedding with respect to the bidirectional algorithm. The direction of this embedding level is given by the {{Cssxref("direction")}} property. - `bidi-override` - : For inline elements this creates an override. For block container elements this creates an override for inline-level descendants not within another block container element. This means that inside the element, reordering is strictly in sequence according to the {{Cssxref("direction")}} property; the implicit part of the bidirectional algorithm is ignored. - `isolate` - : This keyword indicates that the element's container directionality should be calculated without considering the content of this element. The element is therefore _isolated_ from its siblings. When applying its bidirectional-resolution algorithm, its container element treats it as one or several `U+FFFC Object Replacement Character`, i.e. like an image. - `isolate-override` - : This keyword applies the isolation behavior of the `isolate` keyword to the surrounding content and the override behavior of the `bidi-override` keyword to the inner content. - `plaintext` - : This keyword makes the elements directionality calculated without considering its parent bidirectional state or the value of the {{cssxref("direction")}} property. The directionality is calculated using the P2 and P3 rules of the Unicode Bidirectional Algorithm. This value allows the display of data that is already formatted using a tool following the Unicode Bidirectional Algorithm. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### CSS ```css .bible-quote { direction: rtl; unicode-bidi: embed; } ``` ### HTML ```html <div class="bible-quote">A line of text</div> <div>Another line of text</div> ``` ### Result {{EmbedLiveSample('Examples')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{Cssxref("direction")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/tab-size/index.md
--- title: tab-size slug: Web/CSS/tab-size page-type: css-property browser-compat: css.properties.tab-size --- {{CSSRef}} The **`tab-size`** CSS property is used to customize the width of tab characters (U+0009). {{EmbedInteractiveExample("pages/css/tab-size.html")}} ## Syntax ```css /* <integer> values */ tab-size: 4; tab-size: 0; /* <length> values */ tab-size: 10px; tab-size: 2em; /* Global values */ tab-size: inherit; tab-size: initial; tab-size: revert; tab-size: revert-layer; tab-size: unset; ``` ### Values - {{CSSxRef("&lt;integer&gt;")}} - : A multiple of the advance width of the space character (U+0020) to be used as the width of tabs. Must be nonnegative. - {{CSSxRef("&lt;length&gt;")}} - : The width of tabs. Must be nonnegative. ## Formal definition {{CSSInfo}} ## Formal syntax {{CSSSyntax}} ## Examples ### Expanding by character count ```css pre { tab-size: 4; /* Set tab size to 4 characters wide */ } ``` ### Collapse tabs ```css pre { tab-size: 0; /* Remove indentation */ } ``` ### Comparing to the default size This example compares a default tab size with a custom tab size. Note that {{cssxref("white-space")}} is set to `pre` to prevent the tabs from collapsing. #### HTML ```html <p>no tab</p> <p>&#0009;default tab size of 8 characters wide</p> <p class="custom">&#0009;custom tab size of 3 characters wide</p> <p>&nbsp;&nbsp;&nbsp;3 spaces, equivalent to the custom tab size</p> ``` #### CSS ```css p { white-space: pre; } .custom { tab-size: 3; } ``` #### Result {{EmbedLiveSample('Comparing_to_the_default_size')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref('white-space')}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_file-selector-button/index.md
--- title: "::file-selector-button" slug: Web/CSS/::file-selector-button page-type: css-pseudo-element browser-compat: css.selectors.file-selector-button --- {{CSSRef}} The **`::file-selector-button`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) represents the button of an {{HTMLElement("input") }} of [`type="file"`](/en-US/docs/Web/HTML/Element/input/file). {{EmbedInteractiveExample("pages/tabbed/pseudo-element-file-selector-button.html", "tabbed-shorter")}} ## Syntax ```css selector::file-selector-button ``` ## Examples ### Basic example #### HTML ```html <form> <label for="fileUpload">Upload file</label> <input type="file" id="fileUpload" /> </form> ``` #### CSS ```css hidden form { display: flex; gap: 1em; align-items: center; } ``` ```css input[type="file"]::file-selector-button { border: 2px solid #6c5ce7; padding: 0.2em 0.4em; border-radius: 0.2em; background-color: #a29bfe; transition: 1s; } input[type="file"]::file-selector-button:hover { background-color: #81ecec; border: 2px solid #00cec9; } ``` #### Result {{EmbedLiveSample("Basic_example", "100%", 150)}} Note that `::file-selector-button` is a whole element, and as such matches the rules from the UA stylesheet. In particular, fonts and colors won't necessarily inherit from the `input` element. ### Fallback example #### HTML ```html <form> <label for="fileUpload">Upload file</label> <input type="file" id="fileUpload" /> </form> ``` #### CSS ```css hidden form { display: flex; gap: 1em; align-items: center; } ``` ```css input[type="file"]::file-selector-button { border: 2px solid #6c5ce7; padding: 0.2em 0.4em; border-radius: 0.2em; background-color: #a29bfe; transition: 1s; } input[type="file"]::-ms-browse:hover { background-color: #81ecec; border: 2px solid #00cec9; } input[type="file"]::-webkit-file-upload-button:hover { background-color: #81ecec; border: 2px solid #00cec9; } input[type="file"]::file-selector-button:hover { background-color: #81ecec; border: 2px solid #00cec9; } ``` #### Result {{EmbedLiveSample("Fallback_example", "100%", 150)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [WebKit CSS extensions](/en-US/docs/Web/CSS/WebKit_Extensions) - [File and Directory Entries API](/en-US/docs/Web/API/File_and_Directory_Entries_API) - [File and Directory Entries API support in Firefox](/en-US/docs/Web/API/File_and_Directory_Entries_API/Firefox_support) - [`<input type="file">`](/en-US/docs/Web/HTML/Element/input/file)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/align-tracks/index.md
--- title: align-tracks slug: Web/CSS/align-tracks page-type: css-property status: - experimental browser-compat: css.properties.align-tracks --- {{CSSRef}}{{SeeCompatTable}} The **`align-tracks`** CSS property sets the alignment in the masonry axis for grid containers that have [masonry](/en-US/docs/Web/CSS/CSS_grid_layout/Masonry_layout) in their block axis. ## Syntax ```css /* Keyword values */ align-tracks: start; align-tracks: space-between; align-tracks: center; align-tracks: start, center, end; /* Global values */ align-tracks: inherit; align-tracks: initial; align-tracks: revert; align-tracks: revert-layer; align-tracks: unset; ``` The property can take a single value, in which case all tracks are aligned in the same way. If a list of values is used then the first value applies to the first track in the grid axis, the second to the next and so on. If there are fewer values than tracks, the last value is used for all remaining tracks. If there are more values than tracks, any additional values are ignored. ### Values - `start` - : The items are packed flush to each other toward the start edge of the alignment container in the masonry axis. - `end` - : The items are packed flush to each other toward the end edge of the alignment container in the masonry axis. - `center` - : The items are packed flush to each other toward the center of the alignment container along the masonry axis. - `normal` - : Acts as `start`. - `baseline first baseline` `last baseline` - : Specifies participation in first- or last-baseline alignment: aligns the alignment baseline of the box's first or last baseline set with the corresponding baseline in the shared first or last baseline set of all the boxes in its baseline-sharing group. The fallback alignment for `first baseline` is `start`, the one for `last baseline` is `end`. - `space-between` - : The items are evenly distributed within the alignment container along the masonry axis. The spacing between each pair of adjacent items is the same. The first item is flush with the main-start edge, and the last item is flush with the main-end edge. - `space-around` - : The items are evenly distributed within the alignment container along the masonry axis. The spacing between each pair of adjacent items is the same. The empty space before the first and after the last item equals half of the space between each pair of adjacent items. - `space-evenly` - : The items are evenly distributed within the alignment container along the masonry axis. The spacing between each pair of adjacent items, the main-start edge and the first item, and the main-end edge and the last item, are all exactly the same. - `stretch` - : The items stretch along the masonry axis to fill the content box. Items with definite size do not stretch. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Masonry layout with multiple values for align-tracks {{EmbedGHLiveSample("css-examples/grid/masonry/align-tracks.html", '100%', 900)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Related CSS properties: {{cssxref("justify-tracks")}}, {{cssxref("masonry-auto-flow")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_defined/index.md
--- title: ":defined" slug: Web/CSS/:defined page-type: css-pseudo-class browser-compat: css.selectors.defined --- {{CSSRef}} The **`:defined`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents any element that has been defined. This includes any standard element built in to the browser, and custom elements that have been successfully defined (i.e. with the {{domxref("CustomElementRegistry.define()")}} method). ```css /* Selects any defined element */ :defined { font-style: italic; } /* Selects any instance of a specific custom element */ simple-custom:defined { display: block; } ``` ## Syntax ```css :defined { /* ... */ } ``` ## Examples ### Hiding elements until they are defined The following snippets are taken from our [defined-pseudo-class](https://github.com/mdn/web-components-examples/tree/main/defined-pseudo-class) demo ([see it live also](https://mdn.github.io/web-components-examples/defined-pseudo-class/)). In this demo we define a very simple trivial custom element: ```js customElements.define( "simple-custom", class extends HTMLElement { constructor() { super(); let divElem = document.createElement("div"); divElem.textContent = this.getAttribute("text"); let shadowRoot = this.attachShadow({ mode: "open" }).appendChild(divElem); } }, ); ``` Then insert a copy of this element into the document, along with a standard `<p>`: ```html <simple-custom text="Custom element example text"></simple-custom> <p>Standard paragraph example text</p> ``` In the CSS we first include the following rules: ```css /* Give the two elements distinctive backgrounds */ p { background: yellow; } simple-custom { background: cyan; } /* Both the custom and the built-in element are given italic text */ :defined { font-style: italic; } ``` Then provide the following two rules to hide any instances of our custom element that are not defined, and display instances that are defined as block level elements: ```css simple-custom:not(:defined) { display: none; } simple-custom:defined { display: block; } ``` This is useful if you have a complex custom element that takes a while to load into the page — you might want to hide instances of the element until definition is complete, so that you don't end up with flashes of ugly unstyled elements on the page ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Web components](/en-US/docs/Web/API/Web_components)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/math-depth/index.md
--- title: math-depth slug: Web/CSS/math-depth page-type: css-property browser-compat: css.properties.math-depth --- {{CSSRef}} The **`math-depth`** property describes a notion of _depth_ for each element of a mathematical formula, with respect to the top-level container of that formula. This is used to scale the computed value of the [font-size](/en-US/docs/Web/CSS/font-size) of elements when `font-size: math` is applied. > **Note:** `font-size: math` is the default for `<math>` elements in the MathML Core [User Agent stylesheet](https://w3c.github.io/mathml-core/#user-agent-stylesheet), so it's not necessary to specify it explicitly. ## Syntax ```css /* Keyword values */ math-depth: auto-add; /* Relative values */ math-depth: add(2); math-depth: add(-2); /* Absolute value */ math-depth: 4; /* Global values */ math-depth: inherit; math-depth: initial; math-depth: revert; math-depth: revert-layer; math-depth: unset; ``` ### Values - `auto-add` - : Set to the inherited `math-depth` plus 1 when inherited [math-style](/en-US/docs/Web/CSS/math-style) is `compact`. - `add({{cssxref("&lt;integer&gt;")}})` - : Set to the inherited `math-depth` plus the specified integer. - {{cssxref("&lt;integer&gt;")}} - : Set to the specified integer. ## Formal definition {{cssinfo}} ## Formal syntax {{CSSSyntax}} ## Examples ### Specifying a math depth The following example shows the effect of changing the `math-depth` property on the font size of subformulas. The numbers in each subformula indicate the `math-depth` and scale factor applied. The first `<mtext>` element is used as a reference to other subformulas and has no specific styles applied. The second and third subformulas have `math-depth` set to `auto-add` and show the effect of scaling depending on the `math-style`. The last two subformulas show the effect of setting `math-depth` to a specific value. #### HTML ```html <p style="font-size: 3rem; margin: 1rem 0"> <math> <mtext>0</mtext> <!-- auto-add value has no effect when math-style is normal --> <mrow style="math-style: normal"> <mrow style="math-depth: auto-add"> <mtext>0</mtext> </mrow> </mrow> <!-- the inherited math-style is compact, so math-depth is set to 1 --> <mrow style="math-depth: auto-add"> <mtext>1</mtext> </mrow> <mrow style="math-depth: add(2)"> <mtext>2</mtext> <mrow style="math-depth: add(-1)"> <mtext>1</mtext> </mrow> <mrow style="math-depth: 0"> <mtext>0</mtext> </mrow> </mrow> </math> </p> ``` #### Result {{embedlivesample('Specifying_a_math_depth', 600, 100)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("font-size")}} - {{cssxref("math-style")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/@property/index.md
--- title: "@property" slug: Web/CSS/@property page-type: css-at-rule browser-compat: css.at-rules.property --- {{CSSRef}} The **`@property`** [CSS](/en-US/docs/Web/CSS) [at-rule](/en-US/docs/Web/CSS/At-rule) is part of the [CSS Houdini](/en-US/docs/Web/API/Houdini_APIs) umbrella of APIs. It allows developers to explicitly define their {{cssxref('--*', 'CSS custom properties')}}, allowing for property type checking and constraining, setting default values, and defining whether a custom property can inherit values or not. The `@property` rule represents a custom property registration directly in a stylesheet without having to run any JS. Valid `@property` rules result in a registered custom property, as if {{domxref('CSS.registerProperty_static', 'registerProperty()')}} had been called with equivalent parameters. ## Syntax ```css @property --property-name { syntax: "<color>"; inherits: false; initial-value: #c0ffee; } ``` ### Descriptors - {{cssxref("@property/syntax","syntax")}} - : Describes the allowable syntax for the property. May be a `<length>`, `<number>`, `<percentage>`, `<length-percentage>`, `<color>`, `<image>`, `<url>`, `<integer>`, `<angle>`, `<time>`, `<resolution>`, `<transform-function>`, or `<custom-ident>`, or a list of data type and keyword values. The `+` (space-separated) and `#` (comma-separated) multipliers indicate that a list of values is expected, for example `<color>#` means a comma-separated list of `<color>` values is the expected syntax. Vertical lines (`|`) can create "or" conditions for the expected syntax, for example `<length> | auto` accepts a `<length>` or `auto`, and `<color># | <integer>#` expects a comma-separated list of `<color>` values or a comma-separated list of `<integer>` values. - {{cssxref("@property/inherits","inherits")}} - : Controls whether the custom property registration specified by `@property` inherits by default. - {{cssxref("@property/initial-value","initial-value")}} - : Sets the initial value for the property. The `@property` rule must include both the {{cssxref("@property/syntax","syntax")}} and {{cssxref("@property/inherits","inherits")}} descriptors; if either are missing, the entire `@property` rule is invalid and ignored. The {{cssxref("@property/initial-value","initial-value")}} descriptor is also required, unless the syntax is the [`*` universal syntax definition](https://drafts.css-houdini.org/css-properties-values-api/#universal-syntax-definition) (e.g., `initial-value: *`). If the `initial-value` descriptor is required and omitted, the entire `@property` rule is invalid and ignored. Unknown descriptors are invalid and ignored, but do not invalidate the `@property` rule. ## Formal syntax {{csssyntax}} ## Examples In this example, we define two custom properties, `--item-size` and `--item-color`, that we'll use to define the size (width and height) and background color of the three following items. ```html <div class="container"> <div class="item one">Item one</div> <div class="item two">Item two</div> <div class="item three">Item three</div> </div> ``` The following code uses the CSS `@property` at-rule to define a custom property named `--item-size`. The property sets the initial value to `40%`, limiting valid values to {{cssxref("percentage")}} values only. This means, when used as the value for an item's size, its size will always be relative to its parent's size. The property is inheritable. ```css @property --item-size { syntax: "<percentage>"; inherits: true; initial-value: 40%; } ``` We define a second custom property, `--item-color`, using [JavaScript](/en-US/docs/Web/JavaScript) instead of CSS. The JavaScript {{domxref('CSS.registerProperty_static', 'registerProperty()')}} method is equivalent to `@property` at-rule. The property is defined to have an initial value of `aqua`, to accept only [`<color>`](/en-US/docs/Web/CSS/color_value) values, and is not inherited. ```js window.CSS.registerProperty({ name: "--item-color", syntax: "<color>", inherits: false, initialValue: "aqua", }); ``` We use the two custom properties to style the items: ```css .container { display: flex; height: 200px; border: 1px dashed black; /* set custom property values on parent */ --item-size: 20%; --item-color: orange; } /* use custom properties to set item size and background color */ .item { width: var(--item-size); height: var(--item-size); background-color: var(--item-color); } /* set custom property values on element itself */ .two { --item-size: initial; --item-color: inherit; } .three { /* invalid values */ --item-size: 1000px; --item-color: xyz; } ``` {{ EmbedLiveSample('examples', '100%', '250px') }} The two custom properties, `--item-size: 20%` and `--item-color: orange;` are set on the `container` parent, overriding the `40%` and `aqua` default values set when these custom properties were defined. The size is set to be inheritable; the color is not. For item one, none of these custom properties have been set. The `--item-size` is inheritable, so the value `20%` set on its parent `container` is used. On the other hand, the property `--item-color` is not inheritable, so the value `orange` set on the parent is not considered. Instead the default initial value `aqua` is used. For item two, CSS global keywords are set for both custom properties which are valid values for all value types and therefore valid no matter the `syntax` descriptor value. The `--item-size` is set to `initial` and uses the `initial-value: 40%;` set in the `@property` declaration. The `initial` value means the`initialValue` value for the property is used. The `--item-color` is set to `inherit`, explicitly inheriting the `orange` value from its parent even though the custom property is set to otherwise not be inherited. This is why item two is orange. For item three, the `--item-size` value gets set to `1000px`. While `1000px` is a {{cssxref("length")}} value, the `@property` declaration requires the value be a `<percentage>`, so the declaration is not valid and is ignored, meaning the inheritable `20%` set on the parent is used. The `xyz` value is also invalid. As `registerProperty()` set `--item-color` to not be inherited, the default initial value of `aqua` is used and not the parent's `orange` value. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("var")}} - [CSS Properties and Values API](/en-US/docs/Web/API/CSS_Properties_and_Values_API) - [CSS Painting API](/en-US/docs/Web/API/CSS_Painting_API) - [CSS Typed Object Model](/en-US/docs/Web/API/CSS_Typed_OM_API) - [Houdini APIs](/en-US/docs/Web/API/Houdini_APIs) - [Using CSS custom properties (variables)](/en-US/docs/Web/CSS/Using_CSS_custom_properties) guide - [CSS custom properties for cascading variables](/en-US/docs/Web/CSS/CSS_cascading_variables) module
0
data/mdn-content/files/en-us/web/css/@property
data/mdn-content/files/en-us/web/css/@property/syntax/index.md
--- title: syntax slug: Web/CSS/@property/syntax page-type: css-at-rule-descriptor browser-compat: css.at-rules.property.syntax --- {{CSSRef}} The **`syntax`** [CSS](/en-US/docs/Web/CSS) descriptor is required when using the {{cssxref("@property")}} [at-rule](/en-US/docs/Web/CSS/At-rule) and describes the allowable syntax for the property. ## Syntax The following are all valid syntax strings: ```css syntax: "<color>"; /* accepts a color */ syntax: "<length> | <percentage>"; /* accepts lengths or percentages but not calc expressions with a combination of the two */ syntax: "small | medium | large"; /* accepts one of these values set as custom idents. */ syntax: "*"; /* any valid token */ ``` ## Values A string with a supported syntax as defined by the specification. Supported syntaxes are a subset of [CSS types](/en-US/docs/Web/CSS/CSS_Types). These may be used along, or a number of types can be used in combination. - `"<length>"` - : Any valid {{cssxref("&lt;length&gt;")}} values. - `"<number>"` - : Any valid {{cssxref("&lt;number&gt;")}} values. - `"<percentage>"` - : Any valid {{cssxref("&lt;percentage&gt;")}} values. - `"<length-percentage>"` - : Any valid {{cssxref("&lt;length-percentage&gt;")}} values. - `"<color>"` - : Any valid {{cssxref("&lt;color&gt;")}} values. - `"<image>"` - : Any valid {{cssxref("&lt;image&gt;")}} values. - `"<url>"` - : Any valid {{cssxref("url","url()")}} values. - `"<integer>"` - : Any valid {{cssxref("&lt;integer&gt;")}} values. - `"<angle>"` - : Any valid {{cssxref("&lt;angle&gt;")}} values. - `"<time>"` - : Any valid {{cssxref("&lt;time&gt;")}} values. - `"<resolution>"` - : Any valid {{cssxref("&lt;resolution&gt;")}} values. - `"<transform-function>"` - : Any valid {{cssxref("&lt;transform-function&gt;")}} values. - `"<custom-ident>"` - : Any valid {{cssxref("&lt;custom-ident&gt;")}} values. - `"<transform-list>"` - : A list of valid {{cssxref("&lt;transform-function&gt;")}} values. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples Add type checking to `--my-color` {{cssxref('--*', 'custom property')}}, using the `<color>` syntax: Using [CSS](/en-US/docs/Web/CSS) {{cssxref('@property')}} [at-rule](/en-US/docs/Web/CSS/At-rule): ```css @property --my-color { syntax: "<color>"; inherits: false; initial-value: #c0ffee; } ``` Using [JavaScript](/en-US/docs/Web/JavaScript) {{domxref('CSS.registerProperty_static', 'CSS.registerProperty()')}}: ```js window.CSS.registerProperty({ name: "--my-color", syntax: "<color>", inherits: false, initialValue: "#c0ffee", }); ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS Properties and Values API](/en-US/docs/Web/API/CSS_Properties_and_Values_API) - [CSS Painting API](/en-US/docs/Web/API/CSS_Painting_API) - [CSS Typed Object Model](/en-US/docs/Web/API/CSS_Typed_OM_API) - [Houdini APIs](/en-US/docs/Web/API/Houdini_APIs)
0
data/mdn-content/files/en-us/web/css/@property
data/mdn-content/files/en-us/web/css/@property/inherits/index.md
--- title: inherits slug: Web/CSS/@property/inherits page-type: css-at-rule-descriptor browser-compat: css.at-rules.property.inherits --- {{CSSRef}} The **`inherits`** [CSS](/en-US/docs/Web/CSS) descriptor is required when using the {{cssxref("@property")}} [at-rule](/en-US/docs/Web/CSS/At-rule) and controls whether the custom property registration specified by `@property` inherits by default. ## Syntax ```css @property --property-name { syntax: "<color>"; inherits: false; initial-value: #c0ffee; } @property --property-name { syntax: "<color>"; inherits: true; initial-value: #c0ffee; } ``` ## Values - `true` - : The property inherits by default. - `false` - : The property does not inherit by default. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples Add type checking to `--my-color` {{cssxref('--*', 'custom property')}}, as a color, a default value, and not allow it to inherit its value: Using [CSS](/en-US/docs/Web/CSS) {{cssxref('@property')}} [at-rule](/en-US/docs/Web/CSS/At-rule): ```css @property --my-color { syntax: "<color>"; inherits: false; initial-value: #c0ffee; } ``` Using [JavaScript](/en-US/docs/Web/JavaScript) {{domxref('CSS.registerProperty_static', 'CSS.registerProperty()')}}: ```js window.CSS.registerProperty({ name: "--my-color", syntax: "<color>", inherits: false, initialValue: "#c0ffee", }); ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS Properties and Values API](/en-US/docs/Web/API/CSS_Properties_and_Values_API) - [CSS Painting API](/en-US/docs/Web/API/CSS_Painting_API) - [CSS Typed Object Model](/en-US/docs/Web/API/CSS_Typed_OM_API) - [Houdini APIs](/en-US/docs/Web/API/Houdini_APIs)
0
data/mdn-content/files/en-us/web/css/@property
data/mdn-content/files/en-us/web/css/@property/initial-value/index.md
--- title: initial-value slug: Web/CSS/@property/initial-value page-type: css-at-rule-descriptor browser-compat: css.at-rules.property.initial-value --- {{CSSRef}} The **`initial-value`** [CSS](/en-US/docs/Web/CSS) descriptor is required when using the {{cssxref("@property")}} [at-rule](/en-US/docs/Web/CSS/At-rule) unless the syntax accepts any valid token stream. It sets the initial-value for the property. The value chosen as the `initial-value` must parse correctly according to the syntax definition. Therefore, if syntax is `<color>` then the initial-value must be a valid {{cssxref("color")}} value. ## Syntax ```css @property --property-name { syntax: "<color>"; inherits: false; initial-value: #c0ffee; } @property --property-name { syntax: "<color>"; inherits: true; initial-value: #c0ffee; } ``` ## Values A string with a value which is a correct value for the chosen `syntax`. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples Add type checking to `--my-color` {{cssxref('--*', 'custom property')}}, as a color, the initial-value being a valid color: Using [CSS](/en-US/docs/Web/CSS) {{cssxref('@property')}} [at-rule](/en-US/docs/Web/CSS/At-rule): ```css @property --my-color { syntax: "<color>"; inherits: false; initial-value: #c0ffee; } ``` Using [JavaScript](/en-US/docs/Web/JavaScript) {{domxref('CSS.registerProperty_static', 'CSS.registerProperty()')}}: ```js window.CSS.registerProperty({ name: "--my-color", syntax: "<color>", inherits: false, initialValue: "#c0ffee", }); ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS Properties and Values API](/en-US/docs/Web/API/CSS_Properties_and_Values_API) - [CSS Painting API](/en-US/docs/Web/API/CSS_Painting_API) - [CSS Typed Object Model](/en-US/docs/Web/API/CSS_Typed_OM_API) - [Houdini APIs](/en-US/docs/Web/API/Houdini_APIs)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_highlight/index.md
--- title: "::highlight()" slug: Web/CSS/::highlight page-type: css-pseudo-element browser-compat: css.selectors.highlight --- {{CSSRef}} The **`::highlight()`** CSS [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) applies styles to a custom highlight. A custom highlight is a collection of {{domxref("Range")}} objects and is registered on a webpage using the {{domxref("HighlightRegistry")}}. ## Allowable properties Only certain CSS properties can be used with `::highlight()`: - {{CSSxRef("color")}} - {{CSSxRef("background-color")}} - {{CSSxRef("text-decoration")}} and its associated properties - {{CSSxRef("text-shadow")}} - {{CSSxRef("-webkit-text-stroke-color")}}, {{CSSxRef("-webkit-text-fill-color")}} and {{CSSxRef("-webkit-text-stroke-width")}} In particular, {{CSSxRef("background-image")}} is ignored. ## Syntax ```css-nolint ::highlight(custom-highlight-name) ``` ## Examples ### Highlighting characters #### HTML ```html <p id="rainbow-text">CSS Custom Highlight API rainbow</p> ``` #### CSS ```css #rainbow-text { font-family: monospace; font-size: 1.5rem; } ::highlight(rainbow-color-1) { color: #ad26ad; text-decoration: underline; } ::highlight(rainbow-color-2) { color: #5d0a99; text-decoration: underline; } ::highlight(rainbow-color-3) { color: #0000ff; text-decoration: underline; } ::highlight(rainbow-color-4) { color: #07c607; text-decoration: underline; } ::highlight(rainbow-color-5) { color: #b3b308; text-decoration: underline; } ::highlight(rainbow-color-6) { color: #ffa500; text-decoration: underline; } ::highlight(rainbow-color-7) { color: #ff0000; text-decoration: underline; } ``` #### JavaScript ```js const textNode = document.getElementById("rainbow-text").firstChild; if (!CSS.highlights) { textNode.textContent = "The CSS Custom Highlight API is not supported in this browser!"; } // Create and register highlights for each color in the rainbow. const highlights = []; for (let i = 0; i < 7; i++) { // Create a new highlight for this color. const colorHighlight = new Highlight(); highlights.push(colorHighlight); // Register this highlight under a custom name. CSS.highlights.set(`rainbow-color-${i + 1}`, colorHighlight); } // Iterate over the text, character by character. for (let i = 0; i < textNode.textContent.length; i++) { // Create a new range just for this character. const range = new Range(); range.setStart(textNode, i); range.setEnd(textNode, i + 1); // Add the range to the next available highlight, // looping back to the first one once we've reached the 7th. highlights[i % 7].add(range); } ``` #### Result {{ EmbedLiveSample("Highlighting characters") }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_playing/index.md
--- title: ":playing" slug: Web/CSS/:playing page-type: css-pseudo-class browser-compat: css.selectors.playing --- {{CSSRef}} The **`:playing`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) selector represents the playback state of an element that is playable, such as {{htmlelement("audio")}} or {{htmlelement("video")}}, when that element is "playing". An element is considered to be playing if it is currently playing the media resource, or if it has temporarily stopped for reasons other than user intent (such as {{cssxref(":buffering")}} or {{cssxref(":stalled")}}). ## Syntax ```css :playing { /* ... */ } ``` ## Examples ### CSS ```css :playing { border: 5px solid green; } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref(":buffering")}} - {{cssxref(":muted")}} - {{cssxref(":paused")}} - {{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/justify-items/index.md
--- title: justify-items slug: Web/CSS/justify-items page-type: css-property browser-compat: css.properties.justify-items --- {{CSSRef}} The [CSS](/en-US/docs/Web/CSS) **`justify-items`** property defines the default {{CSSxRef("justify-self")}} for all items of the box, giving them all a default way of justifying each box along the appropriate axis. {{EmbedInteractiveExample("pages/css/justify-items.html")}} The effect of this property is dependent of the layout mode we are in: - In block-level layouts, it aligns the items inside their containing block on the inline axis. - For absolutely-positioned elements, it aligns the items inside their containing block on the inline axis, accounting for the offset values of top, left, bottom, and right. - In table cell layouts, this property is _ignored_ ([more](/en-US/docs/Web/CSS/CSS_box_alignment/Box_alignment_in_block_abspos_tables) about alignment in block, absolute positioned and table layout) - In flexbox layouts, this property is _ignored_ ([more](/en-US/docs/Web/CSS/CSS_box_alignment/Box_alignment_in_flexbox) about alignment in Flexbox) - In grid layouts, it aligns the items inside their grid areas on the inline axis ([more](/en-US/docs/Web/CSS/CSS_box_alignment/Box_alignment_in_grid_layout) about alignment in grid layouts) ## Syntax ```css /* Basic keywords */ justify-items: normal; justify-items: stretch; /* Positional alignment */ justify-items: center; /* Pack items around the center */ justify-items: start; /* Pack items from the start */ justify-items: end; /* Pack items from the end */ justify-items: flex-start; /* Equivalent to 'start'. Note that justify-items is ignored in Flexbox layouts. */ justify-items: flex-end; /* Equivalent to 'end'. Note that justify-items is ignored in Flexbox layouts. */ justify-items: self-start; justify-items: self-end; justify-items: left; /* Pack items from the left */ justify-items: right; /* Pack items from the right */ /* Baseline alignment */ justify-items: baseline; justify-items: first baseline; justify-items: last baseline; /* Overflow alignment (for positional alignment only) */ justify-items: safe center; justify-items: unsafe center; /* Legacy alignment */ justify-items: legacy right; justify-items: legacy left; justify-items: legacy center; /* Global values */ justify-items: inherit; justify-items: initial; justify-items: revert; justify-items: revert-layer; justify-items: unset; ``` This property can take one of four different forms: - Basic keywords: one of the keyword values `normal` or `stretch`. - Baseline alignment: the `baseline` keyword, plus optionally one of `first` or `last`. - Positional alignment: one of: `center`, `start`, `end`, `flex-start`, `flex-end`, `self-start`, `self-end`, `left`, or `right`. Plus optionally `safe` or `unsafe`. - Legacy alignment: the `legacy` keyword, followed by one of `left` or `right`. ### Values - `normal` - : The effect of this keyword is dependent of the layout mode we are in: - In block-level layouts, the keyword is a synonym of `start`. - In absolutely-positioned layouts, the keyword behaved like `start` on _replaced_ absolutely-positioned boxes, and as `stretch` on _all other_ absolutely-positioned boxes. - In table cell layouts, this keyword has no meaning as this property is _ignored_. - In flexbox layouts, this keyword has no meaning as this property is _ignored._ - In grid layouts, this keyword leads to a behavior similar to the one of `stretch`, except for boxes with an aspect ratio or an intrinsic sizes where it behaves like `start`. - `start` - : The item is packed flush to each other toward the start edge of the alignment container in the appropriate axis. - `end` - : The item is packed flush to each other toward the end edge of the alignment container in the appropriate axis. - `flex-start` - : For items that are not children of a flex container, this value is treated like `start`. - `flex-end` - : For items that are not children of a flex container, this value is treated like `end`. - `self-start` - : The item is packed flush to the edge of the alignment container of the start side of the item, in the appropriate axis. - `self-end` - : The item is packed flush to the edge of the alignment container of the end side of the item, in the appropriate axis. - `center` - : The items are packed flush to each other toward the center of the alignment container. - `left` - : The items are packed flush to each other toward the left edge of the alignment container. If the property's axis is not parallel with the inline axis, this value behaves like `start`. - `right` - : The items are packed flush to each other toward the right edge of the alignment container in the appropriate axis. If the property's axis is not parallel with the inline axis, this value behaves like `start`. - `baseline`, `first baseline`, `last baseline` - : Specifies participation in first- or last-baseline alignment: aligns the alignment baseline of the box's first or last baseline set with the corresponding baseline in the shared first or last baseline set of all the boxes in its baseline-sharing group. The fallback alignment for `first baseline` is `start`, the one for `last baseline` is `end`. - `stretch` - : If the combined size of the items is less than the size of the alignment container, any `auto`-sized items have their size increased equally (not proportionally), while still respecting the constraints imposed by {{CSSxRef("max-height")}}/{{CSSxRef("max-width")}} (or equivalent functionality), so that the combined size exactly fills the alignment container. - `safe` - : If the size of the item overflows the alignment container, the item is instead aligned as if the alignment mode were `start`. - `unsafe` - : Regardless of the relative sizes of the item and alignment container, the given alignment value is honored. - `legacy` - : Makes the value inherited by the box descendants. Note that if a descendant has a `justify-self: auto` value, the `legacy` keyword is not considered by the descend, only the `left`, `right`, or `center` value associated to it. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Simple demonstration In the following example we have a simple 2 x 2 grid layout. Initially the grid container is given a `justify-items` value of `stretch` (the default), which causes the grid items to stretch across the entire width of their cells. If you hover or tab onto the grid container however, it is given a `justify-items` value of `center`, which causes the grid items to span only as wide as their content width, and align in the center of their cells. #### HTML ```html <article class="container" tabindex="0"> <span>First child</span> <span>Second child</span> <span>Third child</span> <span>Fourth child</span> </article> ``` #### CSS ```css html { font-family: helvetica, arial, sans-serif; letter-spacing: 1px; } article { background-color: red; display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 40px; grid-gap: 10px; margin: 20px; width: 300px; justify-items: stretch; } article:hover, article:focus { justify-items: center; } article span { background-color: black; color: white; margin: 1px; text-align: center; } article, span { padding: 10px; border-radius: 7px; } ``` #### Result {{EmbedLiveSample('Simple_demonstration', '100%', 200)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - CSS Grid Guide: _[Box alignment in CSS Grid layouts](/en-US/docs/Web/CSS/CSS_grid_layout/Box_alignment_in_grid_layout)_ - [CSS Box Alignment](/en-US/docs/Web/CSS/CSS_box_alignment) - The {{CSSxRef("place-items")}} shorthand property - The {{CSSxRef("justify-self")}} property - The {{CSSxRef("align-items")}} property
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_part/index.md
--- title: "::part()" slug: Web/CSS/::part page-type: css-pseudo-element browser-compat: css.selectors.part --- {{CSSRef}} The **`::part`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) represents any element within a [shadow tree](/en-US/docs/Web/API/Web_components/Using_shadow_DOM) that has a matching [`part`](/en-US/docs/Web/HTML/Global_attributes#part) attribute. ```css custom-element::part(foo) { /* Styles to apply to the `foo` part */ } ``` ## Syntax ```css ::part(<ident>+) { /* ... */ } ``` ## Examples ### HTML ```html <template id="tabbed-custom-element"> <style> *, ::before, ::after { box-sizing: border-box; padding: 1rem; } :host { display: flex; } </style> <div part="tab active">Tab 1</div> <div part="tab">Tab 2</div> <div part="tab">Tab 3</div> </template> <tabbed-custom-element></tabbed-custom-element> ``` ### CSS ```css tabbed-custom-element::part(tab) { color: #0c0dcc; border-bottom: transparent solid 2px; } tabbed-custom-element::part(tab):hover { background-color: #0c0d19; color: #ffffff; border-color: #0c0d33; } tabbed-custom-element::part(tab):hover:active { background-color: #0c0d33; color: #ffffff; } tabbed-custom-element::part(tab):focus { box-shadow: 0 0 0 1px #0a84ff inset, 0 0 0 1px #0a84ff, 0 0 0 4px rgb(10 132 255 / 30%); } tabbed-custom-element::part(active) { color: #0060df; border-color: #0a84ff !important; } ``` ### JavaScript ```js let template = document.querySelector("#tabbed-custom-element"); globalThis.customElements.define( template.id, class extends HTMLElement { constructor() { super().attachShadow({ mode: "open" }).append(template.content); } }, ); ``` ### Result {{EmbedLiveSample('Examples')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`part`](/en-US/docs/Web/HTML/Global_attributes#part) attribute - {{CSSxRef(":state",":state()")}} pseudo-class function - [`exportparts`](/en-US/docs/Web/HTML/Global_attributes#exportparts) attribute - [CSS shadow parts](/en-US/docs/Web/CSS/CSS_shadow_parts) module
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/grid-row-end/index.md
--- title: grid-row-end slug: Web/CSS/grid-row-end page-type: css-property browser-compat: css.properties.grid-row-end --- {{CSSRef}} The **`grid-row-end`** CSS property specifies a grid item's end position within the grid row by contributing a line, a span, or nothing (automatic) to its grid placement, thereby specifying the inline-end edge of its {{glossary("grid areas", "grid area")}}. {{EmbedInteractiveExample("pages/css/grid-row-end.html")}} ## Syntax ```css /* Keyword value */ grid-row-end: auto; /* <custom-ident> values */ grid-row-end: somegridarea; /* <integer> + <custom-ident> values */ grid-row-end: 2; grid-row-end: somegridarea 4; /* span + <integer> + <custom-ident> values */ grid-row-end: span 3; grid-row-end: span somegridarea; grid-row-end: 5 somegridarea span; /* Global values */ grid-row-end: inherit; grid-row-end: initial; grid-row-end: revert; grid-row-end: revert-layer; grid-row-end: unset; ``` ### Values - `auto` - : Is a keyword indicating that the property contributes nothing to the grid item's placement, indicating auto-placement, an automatic span, or a default span of `1`. - `<custom-ident>` - : If there is a named line with the name '\<custom-ident>-end', it contributes the first such line to the grid item's placement. > **Note:** Named grid areas automatically generate implicit named lines of this form, so specifying `grid-row-end: foo;` will choose the end edge of that named grid area (unless another line named `foo-end` was explicitly specified before it). Otherwise, this is treated as if the integer `1` had been specified along with the `<custom-ident>`. The `<custom-ident>` cannot take the `span` value. - `<integer> && <custom-ident>?` - : Contributes the nth grid line to the grid item's placement. If a negative integer is given, it instead counts in reverse, starting from the end edge of the explicit grid. If a name is given as a \<custom-ident>, only lines with that name are counted. If not enough lines with that name exist, all implicit grid lines are assumed to have that name for the purpose of finding this position. An {{cssxref("integer")}} value of `0` is invalid. - `span && [ <integer> || <custom-ident> ]` - : Contributes a grid span to the grid item's placement such that the row end edge of the grid item's grid area is n lines from the start edge. If a name is given as a \<custom-ident>, only lines with that name are counted. If not enough lines with that name exist, all implicit grid lines on the side of the explicit grid corresponding to the search direction are assumed to have that name for the purpose of counting this span. If the \<integer> is omitted, it defaults to `1`. Negative integers or 0 are invalid. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting row end for a grid item #### HTML ```html <div class="wrapper"> <div class="box1">One</div> <div class="box2">Two</div> <div class="box3">Three</div> <div class="box4">Four</div> <div class="box5">Five</div> </div> ``` #### CSS ```css .wrapper { display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 100px; } .box1 { grid-column-start: 1; grid-column-end: 4; grid-row-start: 1; grid-row-end: 3; } .box2 { grid-column-start: 1; grid-row-start: 3; grid-row-end: 5; } ``` ```css hidden * { box-sizing: border-box; } .wrapper { border: 2px solid #f76707; border-radius: 5px; background-color: #fff4e6; } .wrapper > div { border: 2px solid #ffa94d; border-radius: 5px; background-color: #ffd8a8; padding: 1em; color: #d9480f; } .nested { border: 2px solid #ffec99; border-radius: 5px; background-color: #fff9db; padding: 1em; } ``` #### Result {{ EmbedLiveSample('Setting_row_end_for_a_grid_item', '230', '420') }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Related CSS properties: {{cssxref("grid-row-start")}}, {{cssxref("grid-row")}}, {{cssxref("grid-column-start")}}, {{cssxref("grid-column-end")}}, {{cssxref("grid-column")}} - Grid Layout Guide: _[Line-based placement with CSS Grid](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_layout_using_line-based_placement)_ - Video tutorial: _[Line-based placement](https://gridbyexample.com/video/series-line-based-placement/)_
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/tan/index.md
--- title: tan() slug: Web/CSS/tan page-type: css-function browser-compat: css.types.tan --- {{CSSRef}} The **`tan()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) is a trigonometric function that returns the tangent of a number, which is a value between `−infinity` and `infinity`. The function contains a single calculation that must resolve to either a {{cssxref("&lt;number&gt;")}} or an {{cssxref("&lt;angle&gt;")}} by interpreting the result of the argument as radians. ## Syntax ```css /* Single <angle> values */ width: calc(100px * tan(45deg)); width: calc(100px * tan(0.125turn)); width: calc(100px * tan(0.785398163rad)); /* Single <number> values */ width: calc(100px * tan(0.5773502)); width: calc(100px * tan(1.732 - 1)); /* Other values */ width: calc(100px * tan(pi / 3)); width: calc(100px * tan(e)); ``` ### Parameter The `tan(angle)` function accepts only one value as its parameter. - `angle` - : A calculation which resolves to a {{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 tangent of an `angle` will always return a number between `−∞` and `+∞`. - If `angle` is `infinity`, `-infinity`, or `NaN`, the result is `NaN`. - If `angle` is `0⁻`, the result is `0⁻`. - If `angle` is one of the asymptote values (such as `90deg`, `270deg`, etc.), the result is _explicitly undefined_. Authors _must not_ rely on `tan()` returning any particular value for these inputs. ### Formal syntax {{CSSSyntax}} ## Examples ### Drawing parallelograms The `tan()` function can be used to draw a parallelogram with a given bounding box. #### HTML ```html <div class="parallelogram"></div> ``` #### CSS ```css hidden body { height: 100vh; display: flex; justify-content: center; align-items: center; } ``` ```css .parallelogram { --w: 400; --h: 200; --angle: 30deg; position: relative; width: calc(1px * var(--w)); height: calc(1px * var(--h)); } .parallelogram::before { content: ""; position: absolute; width: calc(100% - 100% * var(--h) / var(--w) * tan(var(--angle))); height: 100%; transform-origin: 0 100%; transform: skewX(calc(0deg - var(--angle))); background-color: red; } ``` #### Result {{EmbedLiveSample('Drawing parallelograms', '100%', '250px')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("sin")}} - {{CSSxRef("cos")}} - {{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/@page/index.md
--- title: "@page" slug: Web/CSS/@page page-type: css-at-rule browser-compat: css.at-rules.page --- {{CSSRef}} The **`@page`** at-rule is a CSS at-rule used to modify different aspects of printed pages. It targets and modifies the page's dimensions, orientation, and margins. The `@page` at-rule can be used to target all pages in a print-out or a subset using its various pseudo-classes. ## Syntax ```css /* Targets all the pages */ @page { size: 8.5in 9in; margin-top: 4in; } /* Targets all even-numbered pages */ @page :left { margin-top: 4in; } /* Targets all odd-numbered pages */ @page :right { size: 11in; margin-top: 4in; } /* Targets all selectors with `page: wide;` set */ @page wide { size: a4 landscape; } @page { /* margin box at top right showing page number */ @top-right { content: "Page " counter(pageNumber); } } ``` ### Page properties The `@page` at-rule can contain only [page descriptors](#page-descriptors) and [margin at-rules](#margin_at-rules). The following descriptors have been implemented by at least one browser: - [`margin`](/en-US/docs/Web/CSS/margin) - : Specifies the page margins. Individual margin properties [`margin-top`](/en-US/docs/Web/CSS/margin-top), [`margin-right`](/en-US/docs/Web/CSS/margin-right), [`margin-bottom`](/en-US/docs/Web/CSS/margin-bottom), and [`margin-left`](/en-US/docs/Web/CSS/margin-left) can also be used. - [`page-orientation`](/en-US/docs/Web/CSS/@page/page-orientation) - : Specifies the orientation of the page. This does not affect the layout of the page; the rotation is applied after the layout in the output medium. - [`size`](/en-US/docs/Web/CSS/@page/size) - : Specifies the target size and orientation of the page box's containing block. In the general case, where one page box is rendered onto one page sheet, it also indicates the size of the destination page sheet. The specification mentions following CSS properties to be applicable to page boxes via @page at-rule. But these have _not been supported_ by any user agent yet. <details> <summary>Remaining page properties</summary> | Feature | CSS properties | | --------------------- | --------------------- | | bidi properties | direction | | background properties | background-color | | | background-image | | | background-repeat | | | background-attachment | | | background-position | | | background | | border properties | border-top-width | | | border-right-width | | | border-bottom-width | | | border-left-width | | | border-width | | | border-top-color | | | border-right-color | | | border-bottom-color | | | border-left-color | | | border-color | | | border-top-style | | | border-right-style | | | border-bottom-style | | | border-left-style | | | border-short-style | | | border-top | | | border-right | | | border-bottom | | | border-left | | | border | | counter properties | counter-reset | | | counter-increment | | color | color | | font properties | font-family | | | font-size | | | font-style | | | font-variant | | | font-weight | | | font | | height properties | height | | | min-height | | | max-height | | line height | line-height | | margin properties | margin-top | | | margin-right | | | margin-bottom | | | margin-left | | | margin | | outline properties | outline-width | | | outline-style | | | outline-color | | | outline | | padding properties | padding-top | | | padding-right | | | padding-bottom | | | padding-left | | | padding | | quotes | quotes | | text properties | letter-spacing | | | text-align | | | text-decoration | | | text-indent | | | text-transform | | | white-space | | | word-spacing | | visibility | visibility | | width properties | width | | | min-width | | | max-width | </details> ## Description The @page rule defines properties of the page box. The `@page` at-rule can be accessed via the CSS object model interface {{domxref("CSSPageRule")}}. > **Note:** The W3C is discussing how to handle viewport-related {{cssxref("&lt;length&gt;")}} units, `vh`, `vw`, `vmin`, and `vmax`. Meanwhile do not use them within a `@page` at-rule. ### Related properties The `@page` at-rule, allows the user to assign a name to the rule, which is then called in a declaration using the `page` property. - {{Cssxref("page")}} - : Allows a selector to use a user defined **named page** ## Formal syntax {{csssyntax}} Where the `<page-body>` includes: - page-properties - page-margin properties and `<pseudo-selector>` represents these pseudo-classes: - [`:blank`](https://drafts.csswg.org/css-page/#blank-pseudo) - {{Cssxref(":first")}} - {{Cssxref(":left")}} - {{Cssxref(":right")}} ## Margin at-rules > **Warning:** The margin at-rules have not been implemented by any user agent (updated: August 2023). The margin at-rules are used inside of the `@page` at-rule. They each target a different section of the document printed page, styling the area of the printed page based on the property values set in the style block: ```css @page { @top-left { /* page-margin-properties */ } } ``` **`@top-left`** targets the top-left of the document and applies the changes based on the page-margin-properties set. Other margin-at rules include: ```css-nolint @top-left-corner @top-left @top-center @top-right @top-right-corner @bottom-left-corner @bottom-left @bottom-center @bottom-right @bottom-right-corner @left-top @left-middle @left-bottom @right-top @right-middle @right-bottom ``` ### Page-margin properties The page-margin properties are the set of CSS properties can be set in any individual margin at-rule. They include: <details> <summary>Page-margin properties</summary> | Feature | CSS properties | | --------------------- | --------------------- | | bidi properties | direction | | background properties | background-color | | | background-image | | | background-repeat | | | background-attachment | | | background-position | | | background | | border properties | border-top-width | | | border-right-width | | | border-bottom-width | | | border-left-width | | | border-width | | | border-top-color | | | border-right-color | | | border-bottom-color | | | border-left-color | | | border-color | | | border-top-style | | | border-right-style | | | border-bottom-style | | | border-left-style | | | border-short-style | | | border-top | | | border-right | | | border-bottom | | | border-left | | | border | | counter properties | counter-reset | | | counter-increment | | content | content | | color | color | | font properties | font-family | | | font-size | | | font-style | | | font-variant | | | font-weight | | | font | | height properties | height | | | min-height | | | max-height | | line height | line-height | | margin properties | margin-top | | | margin-right | | | margin-bottom | | | margin-left | | | margin | | outline properties | outline-width | | | outline-style | | | outline-color | | | outline | | padding properties | padding-top | | | padding-right | | | padding-bottom | | | padding-left | | | padding | | quotes | quotes | | text properties | letter-spacing | | | text-align | | | text-decoration | | | text-indent | | | text-transform | | | white-space | | | word-spacing | | vertical alignment | vertical-align | | visibility | visibility | | width properties | width | | | min-width | | | max-width | | z-index | z-index | </details> ## Named pages Named pages enable performing per-page layout and adding [page-breaks](/en-US/docs/Web/CSS/CSS_fragmentation) in a declarative manner when printing. Named pages can be applied using the {{Cssxref("page")}} property. This allows the user to create different page configurations for use in print layouts. An example of this can be found on the [`page`](/en-US/docs/Web/CSS/page#examples) examples. ## Examples ### Using the size property to change the page orientation This example shows how to split the `<section>`s into individual pages in `landscape` format with each page having a 20% margin when printed. #### HTML ```html <button>Print Webpage</button> <article> <section> <h2>Header</h2> <p> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consequatur facilis vitae voluptatibus odio consequuntur optio placeat? Id, nam sequi aut in dolorem dolores, laudantium, quasi totam ipsam aliquam quibusdam velit. </p> </section> <section> <h2>Header</h2> <p> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consequatur facilis vitae voluptatibus odio consequuntur optio placeat? Id, nam sequi aut in dolorem dolores, laudantium, quasi totam ipsam aliquam quibusdam velit. </p> </section> <section> <h2>Header</h2> <p> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consequatur facilis vitae voluptatibus odio consequuntur optio placeat? Id, nam sequi aut in dolorem dolores, laudantium, quasi totam ipsam aliquam quibusdam velit. </p> </section> </article> ``` #### CSS ```css @page { size: landscape; margin: 20%; } section { page-break-after: always; break-after: page; } @media print { button { display: none; } } ``` ```css hidden body { font-family: "Helvetica", sans-serif; background-color: silver; } article { width: 100%; } section { display: grid; background-color: white; border-radius: 0.6rem; justify-items: center; padding: 1rem; width: 50%; print-color-adjust: exact; -webkit-print-color-adjust: exact; margin: 0 auto; margin-block-end: 1.5rem; border: 1px dashed; } ``` #### JavaScript ```js const button = document.querySelector("button"); button.addEventListener("click", () => { window.print(); }); ``` #### Result Clicking the print button will launch a print dialog with the html sections split into individual pages. {{ EmbedLiveSample('Using the size property to change the page orientation', '100%', 520) }} ### @page pseudo-class examples Please refer to the various [pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes) of `@page` for examples. - [`:blank`](https://drafts.csswg.org/css-page/#blank-pseudo) - {{Cssxref(":first")}} - {{Cssxref(":left")}} - {{Cssxref(":right")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - The `@page` [`size`](/en-US/docs/Web/CSS/@page/size) descriptor - The {{Cssxref("page")}} property - See the [\[META\] CSS Paged Media Module Level 3](https://bugzilla.mozilla.org/show_bug.cgi?id=286443) ticket in Bugzilla for tracking progress on the subject (page-based counters, etc.) - [CSS paged media](/en-US/docs/Web/CSS/CSS_paged_media) module - [Paged.js: W3C paged media polyfill](https://pagedjs.org/documentation/1-the-big-picture)
0
data/mdn-content/files/en-us/web/css/@page
data/mdn-content/files/en-us/web/css/@page/page-orientation/index.md
--- title: page-orientation slug: Web/CSS/@page/page-orientation page-type: css-at-rule-descriptor browser-compat: css.at-rules.page.page-orientation --- {{CSSRef}} The **`page-orientation`** [CSS](/en-US/docs/Web/CSS) descriptor for the {{cssxref("@page")}} at-rule controls the rotation of a printed page. It handles the flow of content across pages when the orientation of a page is changed. This behavior differs from the [`size`](/en-US/docs/Web/CSS/@page/size) descriptor in that a user can define the direction in which to rotate the page. This descriptor helps with the layout and orientation of printed documents, especially when documents are printed double-sided. A user can specify how the pages will be rotated when printed. This is particularly useful to lay out content such as tables, which may be wider than the rest of the content, in a different orientation. > **Note:** [Margin boxes](/en-US/docs/Web/CSS/@page#margin_at-rules) and other positional elements have no special interaction with this descriptor. Margins are laid out as normal in the unrotated page, then rotated along with everything else. ## Syntax ```css /* Displays the print content in an upright position */ @page { page-orientation: upright; } /* Displays the print content rotated counter-clockwise */ @page { page-orientation: rotate-left; } /* Displays the print content rotated counter-clockwise */ @page { page-orientation: rotate-right; } ``` ## Values - `upright` - : No orientation is applied and the page is laid out and formatted as normal. - `rotate-left` - : After a page is laid out, the page must be displayed rotated a quarter turn to the left (counter-clockwise). - `rotate-right` - : After the page is laid out, the page must be displayed rotated a quarter turn to the right (clockwise). ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Rotating printed pages This example shows how the contents of a print document can be rotated to suit the page content and the page position. ```html hidden <fieldset id="printStyle"> <legend> Click Print. The page will be laid out in the defined orientation. </legend> <button id="print">Print</button> </fieldset> <div id="print-area"> <section class="upright"> <h2>Section in Portrait/Upright</h2> <p>This section will be printed in portrait and upright with:</p> <pre> .upright { size: portrait; page-orientation: upright; } </pre> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu convallis ligula, tincidunt malesuada tortor. Ut ac turpis erat. Mauris consequat, leo rhoncus venenatis elementum, sem nisl venenatis justo, non mattis diam massa vitae dolor. Aenean ac dolor et leo laoreet tincidunt. Suspendisse tempus risus nibh, a feugiat mauris pharetra a. Nulla mi dui, scelerisque vitae sollicitudin nec, placerat eget purus. Vivamus enim elit, scelerisque id venenatis eu, sodales vel leo. Quisque bibendum feugiat diam, ut feugiat urna suscipit et. Nulla lacinia metus a nisi volutpat interdum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum vitae elit vel orci malesuada bibendum ut vitae enim. Ut ultrices elit nec vestibulum blandit. In in eleifend dui. Nam nec aliquet nunc. Praesent convallis ipsum sed fermentum scelerisque. </p> <p> Praesent posuere, neque non fringilla ultricies, purus mi ullamcorper velit, vitae egestas nisl eros at ex. Nulla sed viverra libero. Praesent sed placerat magna, iaculis commodo lectus. Ut gravida ligula sed purus molestie, in accumsan est eleifend. Etiam consectetur nulla pretium blandit iaculis. Nunc semper libero ut mauris faucibus placerat. Cras ac justo ac est laoreet sollicitudin. Aliquam vel sapien ut sapien vestibulum dictum. </p> </section> <section class="left"> <h2>Section in Landscape/Left</h2> <p>This section will be printed in landscape and rotated left with:</p> <pre> .left { size: landscape; page-orientation: rotate-left; } </pre> <table> <thead> <tr> <th></th> <th>100m</th> <th>1500m</th> <th>Hurdles</th> <th>Long Jump</th> <th>High Jump</th> <th>Javelin</th> <th>Discus</th> </tr> </thead> <tbody> <tr> <th>Dave</th> <td>9.65</td> <td>3:49</td> <td>12.64</td> <td>8.54m</td> <td>1.95m</td> <td>56.65m</td> <td>47.63m</td> </tr> <tr> <th>Simon</th> <td>9.87</td> <td>3:52</td> <td>11.89</td> <td>8.16m</td> <td>1.96m</td> <td>59.03m</td> <td>45.72m</td> </tr> <tr> <th>Fred</th> <td>9.67</td> <td>3:52</td> <td>12.03</td> <td>8.04m</td> <td>2.01m</td> <td>62.58m</td> <td>46.83m</td> </tr> <tr> <th>Gary</th> <td>9.77</td> <td>3:56</td> <td>13.04</td> <td>7.96m</td> <td>2.02m</td> <td>63.87m</td> <td>47.73m</td> </tr> <tr> <th>Dick</th> <td>9.95</td> <td>3:44</td> <td>12.99</td> <td>5.66m</td> <td>1.97m</td> <td>56.43m</td> <td>43.87m</td> </tr> <tr> <th>Tom</th> <td>9.84</td> <td>3:48</td> <td>12.86</td> <td>6.87m</td> <td>1.95m</td> <td>67.03m</td> <td>42.73m</td> </tr> <tr> <th>Harry</th> <td>9.91</td> <td>3:53</td> <td>13.77</td> <td>7.34m</td> <td>1.94m</td> <td>62.84m</td> <td>46.72m</td> </tr> </tbody> </table> </section> <section class="right"> <h2>Section in Landscape/Right</h2> <p>This section will be printed in landscape and rotated right with:</p> <pre> .right { size: landscape; page-orientation: rotate-right; } </pre> <table> <thead> <tr> <th></th> <th>100m</th> <th>1500m</th> <th>Hurdles</th> <th>Long Jump</th> <th>High Jump</th> <th>Javelin</th> <th>Discus</th> </tr> </thead> <tbody> <tr> <th>Dave</th> <td>9.65</td> <td>3:49</td> <td>12.64</td> <td>8.54m</td> <td>1.95m</td> <td>56.65m</td> <td>47.63m</td> </tr> <tr> <th>Simon</th> <td>9.87</td> <td>3:52</td> <td>11.89</td> <td>8.16m</td> <td>1.96m</td> <td>59.03m</td> <td>45.72m</td> </tr> <tr> <th>Fred</th> <td>9.67</td> <td>3:52</td> <td>12.03</td> <td>8.04m</td> <td>2.01m</td> <td>62.58m</td> <td>46.83m</td> </tr> <tr> <th>Gary</th> <td>9.77</td> <td>3:56</td> <td>13.04</td> <td>7.96m</td> <td>2.02m</td> <td>63.87m</td> <td>47.73m</td> </tr> <tr> <th>Dick</th> <td>9.95</td> <td>3:44</td> <td>12.99</td> <td>5.66m</td> <td>1.97m</td> <td>56.43m</td> <td>43.87m</td> </tr> <tr> <th>Tom</th> <td>9.84</td> <td>3:48</td> <td>12.86</td> <td>6.87m</td> <td>1.95m</td> <td>67.03m</td> <td>42.73m</td> </tr> <tr> <th>Harry</th> <td>9.91</td> <td>3:53</td> <td>13.77</td> <td>7.34m</td> <td>1.94m</td> <td>62.84m</td> <td>46.72m</td> </tr> </tbody> </table> </section> </div> ``` #### CSS In this first part of the CSS code, [named pages](/en-US/docs/Web/CSS/@page#named_pages) are set up to define the direction in which to rotate the content. ```css @page upright { size: portrait; page-orientation: upright; } @page left { size: landscape; page-orientation: rotate-left; } @page right { size: landscape; page-orientation: rotate-right; } ``` ```css hidden fieldset { display: flex; flex-direction: row; justify-content: space-between; gap: 1rem; width: fit-content; } p { max-width: 60ch; } @media print { fieldset { display: none; } section { font-family: Roboto; font-size: 1.5rem; } } ``` The following second part of the CSS code declares a named page rule defined above for the selectors, such as `<section class="left">…</section>`. ```css @media print { .upright { page: upright; } .left { page: left; } .right { page: right; } } ``` ```js hidden const printButton = document.querySelector("#print"); printButton.addEventListener("click", () => { window.print(); }); ``` ### Result Click the print button to see the pages rotated. {{ EmbedLiveSample('Rotating_printed_pages', '100%', 520) }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}}
0
data/mdn-content/files/en-us/web/css/@page
data/mdn-content/files/en-us/web/css/@page/size/index.md
--- title: size slug: Web/CSS/@page/size page-type: css-at-rule-descriptor browser-compat: css.at-rules.page.size --- {{CSSRef}} The **`size`** [CSS](/en-US/docs/Web/CSS) [at-rule](/en-US/docs/Web/CSS/At-rule) descriptor, used with the {{cssxref("@page")}} at-rule, defines the size and orientation of the box which is used to represent a page. Most of the time, this size corresponds to the target size of the printed page if applicable. Size may either be defined with a "scalable" keyword (in this case the page will fill the available dimensions) or with absolute dimensions. ## Syntax ```css /* Keyword values for scalable size */ size: auto; size: portrait; size: landscape; /* <length> values */ /* 1 value: height = width */ size: 6in; /* 2 values: width then height */ size: 4in 6in; /* Keyword values for absolute size */ size: A4; size: B5; size: JIS-B4; size: letter; /* Mixing size and orientation */ size: A4 portrait; ``` ### Values - `auto` - : The user agent decides the size of the page. In most cases, the dimensions and orientation of the target sheet are used. - `landscape` - : The content of the page is displayed in landscape mode (i.e. the longest side of the box is horizontal). - `portrait` - : The content of the page is displayed in portrait mode (i.e. the longest side of the box is vertical). This is the default orientation. - `<length>` - : Any length value (see {{cssxref("&lt;length&gt;")}}). The first value corresponds to the width of the page box and the second one corresponds to its height. If only one value is provided, it is used for both width and height. - `<page-size>` - : A keyword which may be any of the following values: - A5 - : This matches the standard, ISO dimensions: 148mm x 210mm. - A4 - : This matches the standard, ISO dimensions: 210mm x 297mm. (most frequently used dimensions for personal printing.) - A3 - : This matches the standard, ISO dimensions: 297mm x 420mm. - B5 - : This matches the standard, ISO dimensions: 176mm x 250mm. - B4 - : This matches the standard, ISO dimensions: 250mm x 353mm. - JIS-B5 - : This correspond to the JIS standard dimensions: 182mm x 257mm. - JIS-B4 - : This correspond to the JIS standard dimensions: 257mm x 364mm. - letter - : This keyword is an equivalent to the dimensions of letter paper in North America i.e. 8.5in x 11in. - legal - : This keyword is an equivalent to the dimensions of legal papers in North America i.e. 8.5in x 14in. - ledger - : This keyword is an equivalent to the dimensions of ledger pages in North America i.e. 11in x 17in. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Specifying size and orientation ```css @page { size: A4 landscape; } ``` ### Specifying a custom size ```css @page { size: 4in 6in; } ``` ### Nesting inside a @media rule ```css @media print { @page { size: 50mm 150mm; } } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/scroll-margin-inline-end/index.md
--- title: scroll-margin-inline-end slug: Web/CSS/scroll-margin-inline-end page-type: css-property browser-compat: css.properties.scroll-margin-inline-end --- {{CSSRef}} The `scroll-margin-inline-end` property defines the margin of the scroll snap area at the end of the inline dimension that is used for snapping this box to the snapport. The scroll snap area is determined by taking the transformed border box, finding its rectangular bounding box (axis-aligned in the scroll container's coordinate space), then adding the specified outsets. {{EmbedInteractiveExample("pages/css/scroll-margin-inline-end.html")}} ## Syntax ```css /* <length> values */ scroll-margin-inline-end: 10px; scroll-margin-inline-end: 1em; /* Global values */ scroll-margin-inline-end: inherit; scroll-margin-inline-end: initial; scroll-margin-inline-end: revert; scroll-margin-inline-end: revert-layer; scroll-margin-inline-end: unset; ``` ### Values - {{CSSXref("&lt;length&gt;")}} - : An outset from the inline end edge of the scroll container. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Simple demonstration This example implements something very similar to the interactive example above, except that here we'll explain to you how it's implemented. The aim here is to create four horizontally-scrolling blocks, the second and third of which snap into place, near but not quite at the right of each block. #### HTML The HTML that represents the blocks is very simple: ```html <div class="scroller"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> </div> ``` #### CSS Let's walk through the CSS. The outer container is styled like this: ```css .scroller { text-align: left; width: 250px; height: 250px; overflow-x: scroll; display: flex; box-sizing: border-box; border: 1px solid #000; scroll-snap-type: x mandatory; } ``` The main parts relevant to the scroll snapping are `overflow-x: scroll`, which makes sure the contents will scroll and not be hidden, and `scroll-snap-type: x mandatory`, which dictates that scroll snapping must occur along the horizontal axis, and the scrolling will always come to rest on a snap point. The child elements are styled as follows: ```css .scroller > div { flex: 0 0 250px; width: 250px; background-color: #663399; color: #fff; font-size: 30px; display: flex; align-items: center; justify-content: center; scroll-snap-align: end; } .scroller > div:nth-child(2n) { background-color: #fff; color: #663399; } ``` The most relevant part here is `scroll-snap-align: end`, which specifies that the right-hand edges (the "ends" along the x axis, in our case) are the designated snap points. Last of all we specify the scroll margin values, a different one for the second and third child elements: ```css .scroller > div:nth-child(2) { scroll-margin-inline-end: 1rem; } .scroller > div:nth-child(3) { scroll-margin-inline-end: 2rem; } ``` This means that when scrolling past the middle child elements, the scrolling will snap to `1rem` outside the inline end edge of the second `<div>`, and `2rems` outside the inline end edge of the third `<div>`. #### Result Try it for yourself: {{EmbedLiveSample('Simple_demonstration', '100%', 300)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS scroll snap](/en-US/docs/Web/CSS/CSS_scroll_snap) - [Well-controlled scrolling with CSS scroll snap](https://web.dev/articles/css-scroll-snap)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/font-weight/index.md
--- title: font-weight slug: Web/CSS/font-weight page-type: css-property browser-compat: css.properties.font-weight --- {{CSSRef}} The **`font-weight`** [CSS](/en-US/docs/Web/CSS) property sets the weight (or boldness) of the font. The weights available depend on the {{cssxref("font-family")}} that is currently set. {{EmbedInteractiveExample("pages/css/font-weight.html")}} ## Syntax ```css /* <font-weight-absolute> keyword values */ font-weight: normal; font-weight: bold; /* <font-weight-absolute> numeric values [1,1000] */ font-weight: 100; font-weight: 200; font-weight: 300; font-weight: 400; /* normal */ font-weight: 500; font-weight: 600; font-weight: 700; /* bold */ font-weight: 800; font-weight: 900; /* Keyword values relative to the parent */ font-weight: lighter; font-weight: bolder; /* Global values */ font-weight: inherit; font-weight: initial; font-weight: revert; font-weight: revert-layer; font-weight: unset; ``` The `font-weight` property is specified using either a `<font-weight-absolute>` value or a relative weight value, as listed below. ### Values - `normal` - : Normal font weight. Same as `400`. - `bold` - : Bold font weight. Same as `700`. - `<number>` - : A {{cssxref("&lt;number&gt;")}} value between 1 and 1000, both values included. Higher numbers represent weights that are bolder than (or as bold as) lower numbers. This allows fine-grain control for [variable fonts](#variable_fonts). For non-variable fonts, if the exact specified weight is unavailable, a [fallback weight](#fallback_weights) algorithm is used — numeric values that are divisible by 100 correspond to common weight names, as described in the [Common weight name mapping](#common_weight_name_mapping) section below. - `lighter` - : One relative font weight lighter than the parent element. Note that only four font weights are considered for relative weight calculation; see the [Meaning of relative weights](#meaning_of_relative_weights) section below. - `bolder` - : One relative font weight heavier than the parent element. Note that only four font weights are considered for relative weight calculation; see the [Meaning of relative weights](#meaning_of_relative_weights) section below. ### Fallback weights If the exact weight given is unavailable, then the following rule is used to determine the weight actually rendered: - If the target weight given is between `400` and `500` inclusive: - Look for available weights between the target and `500`, in ascending order. - If no match is found, look for available weights less than the target, in descending order. - If no match is found, look for available weights greater than `500`, in ascending order. - If a weight less than `400` is given, look for available weights less than the target, in descending order. If no match is found, look for available weights greater than the target, in ascending order. - If a weight greater than `500` is given, look for available weights greater than the target, in ascending order. If no match is found, look for available weights less than the target, in descending order. ### Meaning of relative weights When `lighter` or `bolder` is specified, the below chart shows how the absolute font weight of the element is determined. Note that when using relative weights, only four font weights are considered — thin (100), normal (400), bold (700), and heavy (900). If a font family has more weights available, they are ignored for the purposes of relative weight calculation. <table class="standard-table"> <thead> <tr> <th>Inherited value</th> <th><code>bolder</code></th> <th><code>lighter</code></th> </tr> </thead> <tbody> <tr> <th>100</th> <td>400</td> <td>100</td> </tr> <tr> <th>200</th> <td>400</td> <td>100</td> </tr> <tr> <th>300</th> <td>400</td> <td>100</td> </tr> <tr> <th>400</th> <td>700</td> <td>100</td> </tr> <tr> <th>500</th> <td>700</td> <td>100</td> </tr> <tr> <th>600</th> <td>900</td> <td>400</td> </tr> <tr> <th>700</th> <td>900</td> <td>400</td> </tr> <tr> <th>800</th> <td>900</td> <td>700</td> </tr> <tr> <th>900</th> <td>900</td> <td>700</td> </tr> </tbody> </table> ### Common weight name mapping The numerical values `100` to `900` roughly correspond to the following common weight names (see the [OpenType specification](https://docs.microsoft.com/typography/opentype/spec/os2#usweightclass)): | Value | Common weight name | | ----- | --------------------------------------------------------------------------------------------------------------------------- | | 100 | Thin (Hairline) | | 200 | Extra Light (Ultra Light) | | 300 | Light | | 400 | Normal (Regular) | | 500 | Medium | | 600 | Semi Bold (Demi Bold) | | 700 | Bold | | 800 | Extra Bold (Ultra Bold) | | 900 | Black (Heavy) | | 950 | [Extra Black (Ultra Black)](https://docs.microsoft.com/dotnet/api/system.windows.fontweights?view=netframework-4.8#remarks) | ### Variable fonts While many fonts have a particular weight corresponding to one of the numbers in [Common weight name mapping](#common_weight_name_mapping), most variable fonts support a range of weights providing much finer granularity, giving designers and developers more control over the chosen weight. For TrueType or OpenType variable fonts, the "wght" variation is used to implement varying widths. This demo loads with `font-weight: 500;` set. Change the value of the `font-weight` property to see the weight of the text change. {{EmbedGHLiveSample("css-examples/variable-fonts/font-weight.html", '100%', 860)}} ## Accessibility concerns People experiencing low vision conditions may have difficulty reading text set with a `font-weight` value of `100` (Thin/Hairline) or `200` (Extra Light), especially if the font has a [low contrast color ratio](/en-US/docs/Web/CSS/color#accessibility_concerns). - [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.8 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-visual-presentation.html) ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting font weights #### HTML ```html <p> Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, "and what is the use of a book," thought Alice "without pictures or conversations?" </p> <div> I'm heavy<br /> <span>I'm lighter</span> </div> ``` #### CSS ```css /* Set paragraph text to be bold. */ p { font-weight: bold; } /* Set div text to two steps heavier than normal but less than a standard bold. */ div { font-weight: 600; } /* Set span text to be one step lighter than its parent. */ span { font-weight: lighter; } ``` #### Result {{EmbedLiveSample("Setting_font_weights","400","300")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("font-family")}} - {{cssxref("font-style")}} - [Fundamental text and font styling](/en-US/docs/Learn/CSS/Styling_text/Fundamentals) - [CSS fonts](/en-US/docs/Web/CSS/CSS_fonts) module
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/color-interpolation/index.md
--- title: color-interpolation slug: Web/CSS/color-interpolation page-type: css-property browser-compat: css.properties.color-interpolation --- {{CSSRef}} The `color-interpolation` CSS property is used in SVG to specify which color space to use for {{SVGElement("linearGradient")}} and {{SVGElement("radialGradient")}} SVG elements. ## Syntax ```css /* Keyword values */ color-interpolation: auto; color-interpolation: sRGB; color-interpolation: linearRGB; ``` ### Values - `auto` - : Indicates that the user agent can choose either the `sRGB` or `linearRGB` spaces for color interpolation. This option indicates that the author doesn't require that color interpolation occur in a particular color space. - `sRGB` - : Indicates that color interpolation should occur in the sRGB color space. Defaults to this initial value if no `color-interpolation` property is set. - `linearRGB` - : Indicates that color interpolation should occur in the linearized RGB color space as described in [the sRGB specification](https://webstore.iec.ch/publication/6169). ## Formal definition <table class="properties"> <tbody> <tr> <th scope="row">Value</th> <td><code>auto</code> | <code>sRGB</code> | <code>linearRGB</code></td> </tr> <tr> <th scope="row">Applies to</th> <td>{{SVGElement("linearGradient")}} and {{SVGElement("radialGradient")}}</td> </tr> <tr> <th scope="row">Default value</th> <td><code>auto</code></td> </tr> <tr> <th scope="row">Animatable</th> <td>discrete</td> </tr> </tbody> </table> ## Formal syntax {{csssyntax}} ## Example In the first SVG, the `color-interpolation` property is not included on the `<linearGradient>` element and color interpolation defaults to `sRGB`. The second example shows color interpolation using the `linearRGB` value. ```html <svg width="450" height="70"> <title>Example of using the color-interpolation CSS Property</title> <defs> <linearGradient id="sRGB"> <stop offset="0%" stop-color="white" /> <stop offset="25%" stop-color="blue" /> <stop offset="50%" stop-color="white" /> <stop offset="75%" stop-color="red" /> <stop offset="100%" stop-color="white" /> </linearGradient> </defs> <rect x="0" y="0" width="400" height="40" fill="url(#sRGB)" stroke="black" /> <text x="0" y="60" font-family="courier" font-size="16"> no color-interpolation (CSS property) </text> </svg> ``` ```html <svg width="450" height="70"> <title>Example of using the color-interpolation CSS Property</title> <defs> <linearGradient id="linearRGB"> <stop offset="0%" stop-color="white" /> <stop offset="25%" stop-color="blue" /> <stop offset="50%" stop-color="white" /> <stop offset="75%" stop-color="red" /> <stop offset="100%" stop-color="white" /> </linearGradient> </defs> <rect x="0" y="0" width="400" height="40" fill="url(#linearRGB)" stroke="black" /> <text x="0" y="60" font-family="courier" font-size="16"> color-interpolation: linearRGB; (CSS property) </text> </svg> ``` ```css svg { display: block; } #linearRGB { color-interpolation: linearRGB; } ``` {{EmbedLiveSample("Example", "100%", "140")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{SVGElement("linearGradient")}} - {{SVGElement("radialGradient")}} - {{SVGAttr("color-interpolation")}}
0