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/color-scheme/index.md
--- title: color-scheme slug: Web/CSS/color-scheme page-type: css-property browser-compat: css.properties.color-scheme --- {{CSSRef}} The **`color-scheme`** [CSS](/en-US/docs/Web/CSS) property allows an element to indicate which color schemes it can comfortably be rendered in. Common choices for operating system color schemes are "light" and "dark", or "day mode" and "night mode". When a user selects one of these color schemes, the operating system makes adjustments to the user interface. This includes [form controls](/en-US/docs/Learn/Forms), [scrollbars](/en-US/docs/Web/CSS/CSS_scrollbars_styling), and the used values of [CSS system colors](/en-US/docs/Web/CSS/CSS_colors). {{EmbedInteractiveExample("pages/css/color-scheme.html")}} ## Syntax ```css color-scheme: normal; color-scheme: light; color-scheme: dark; color-scheme: light dark; color-scheme: only light; /* Global values */ color-scheme: inherit; color-scheme: initial; color-scheme: revert; color-scheme: revert-layer; color-scheme: unset; ``` The `color-scheme` property's value must be one of the following keywords. ### Values - `normal` - : Indicates that the element isn't aware of any color schemes, and so should be rendered using the browser's default color scheme. - `light` - : Indicates that the element can be rendered using the operating system light color scheme. - `dark` - : Indicates that the element can be rendered using the operating system dark color scheme. - `only` - : Forbids the user agent from overriding the color scheme for the element. Can be used to turn off color overrides caused by Chrome's [Auto Dark Theme](https://developer.chrome.com/blog/auto-dark-theme/#per-element-opt-out), by applying `color-scheme: only light;` on a specific element or `:root`. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Declaring color scheme preferences To opt the entire page into the user's color scheme preferences, declare `color-scheme` on the {{cssxref(":root")}} element. ```css :root { color-scheme: light dark; } ``` To opt in specific elements to the user's color scheme preferences, declare `color-scheme` on those elements. ```css header { color-scheme: only light; } main { color-scheme: light dark; } footer { color-scheme: only dark; } ``` ### Styling based on color schemes To style elements based on color scheme preferences, use the [`prefers-color-scheme`](/en-US/docs/Web/CSS/@media/prefers-color-scheme) media query. The example below opts in the entire page to using both light and dark operating system color schemes via the `color-scheme` property, and then uses `prefers-color-scheme` to specify the desired foreground and background colors for individual elements in those color schemes. ```css :root { color-scheme: light dark; } @media (prefers-color-scheme: light) { .element { color: black; background-color: white; } } @media (prefers-color-scheme: dark) { .element { color: white; background-color: black; } } ``` Alternatively, use the experimental [`light-dark()`](/en-US/docs/Web/CSS/color_value/light-dark) [`<color>` function](/en-US/docs/Web/CSS/CSS_Functions#color_functions) to set the foreground and background colors for the different color schemes using a more compact code structure: ```css :root { color-scheme: light dark; } .element { color: light-dark(black, white); background-color: light-dark(white, black); } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`prefers-color-scheme`](/en-US/docs/Web/CSS/@media/prefers-color-scheme) media query to detect user preferences for color schemes. - {{CSSXref("color_value/light-dark", "light-dark()")}} color function to set colors for both light and dark color schemes. - [Applying color to HTML elements using CSS](/en-US/docs/Web/CSS/CSS_colors/Applying_color) - Other color-related properties: {{cssxref("color")}}, {{cssxref("accent-color")}}, {{cssxref("background-color")}}, {{cssxref("border-color")}}, {{cssxref("outline-color")}}, {{cssxref("text-decoration-color")}}, {{cssxref("text-emphasis-color")}}, {{cssxref("text-shadow")}}, {{cssxref("caret-color")}}, and {{cssxref("column-rule-color")}} - {{cssxref("background-image")}} - {{cssxref("print-color-adjust")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/syntax/index.md
--- title: Syntax slug: Web/CSS/Syntax page-type: guide --- {{CSSRef}} The basic goal of the Cascading Stylesheet ([CSS](/en-US/docs/Web/CSS)) language is to allow a browser engine to paint elements of the page with specific features, like colors, positioning, or decorations. The _CSS syntax_ reflects this goal and its basic building blocks are: - The **property** which is an identifier, that is a human-readable _name_, that defines which feature is considered. - The **value** which describe how the feature must be handled by the engine. Each property has a set of valid values, defined by a formal grammar, as well as a semantic meaning, implemented by the browser engine. ## CSS declarations Setting CSS properties to specific values is the core function of the CSS language. A property and value pair is called a **declaration**, and any CSS engine calculates which declarations apply to every single element of a page in order to appropriately lay it out, and to style it. Both properties and values are case-insensitive by default in CSS. The pair is separated by a colon, '`:`' (`U+003A COLON`), and white spaces before, between, and after properties and values, but not necessarily inside, are ignored. ![css syntax - declaration.png](css_syntax_-_declaration.png) There are [hundreds of different properties](/en-US/docs/Web/CSS/Reference) in CSS and a practically endless number of different values. Not all pairs of properties and values are allowed and each property defines what are the valid values. When a value is not valid for a given property, the declaration is deemed _invalid_ and is wholly ignored by the CSS engine. ## CSS declaration blocks Declarations are grouped in **blocks**, that is in a structure delimited by an opening brace, '`{`' (`U+007B LEFT CURLY BRACKET`), and a closing one, '`}`' (`U+007D RIGHT CURLY BRACKET`). Blocks sometimes can be nested, so opening and closing braces must be matched. ![css syntax - block.png](css_syntax_-_block.png) Such blocks are naturally called **declaration blocks** and declarations inside them are separated by a semicolon, '`;`' (`U+003B SEMICOLON`). A declaration block may be empty, that is containing null declaration. White spaces around declarations are ignored. The last declaration of a block doesn't need to be terminated by a semicolon, though it is often considered _good style_ to do it as it prevents forgetting to add it when extending the block with another declaration. A CSS declaration block is visualized in the diagram below. ![css syntax - declarations block.png](declaration-block.png) > **Note:** The content of a CSS declaration block, that is a list of semicolon-separated declarations, without the initial and closing braces, can be put inside an HTML [`style`](/en-US/docs/Web/HTML/Global_attributes#style) attribute. ## CSS rulesets If style sheets could only apply a declaration to each element of a Web page, they would be pretty useless. The real goal is to apply different declarations to different parts of the document. CSS allows this by associating conditions with declarations blocks. Each (valid) declaration block is preceded by one or more comma-separated [**selectors**](/en-US/docs/Web/CSS/CSS_selectors), which are conditions selecting some elements of the page. A [selector list](/en-US/docs/Web/CSS/Selector_list) and an associated declarations block, together, are called a **ruleset**, or often a **rule**. A CSS ruleset (or rule) is visualized in the diagram below. ![css syntax - ruleset.png](ruleset.png) As an element of the page may be matched by several selectors, and therefore by several rules potentially containing a given property several times, with different values, the CSS standard defines which one has precedence over the other and must be applied: this is called the [cascade](/en-US/docs/Learn/CSS/Building_blocks/Cascade_and_inheritance) algorithm. > **Note:** It is important to note that even if a ruleset characterized by a group of selectors is a kind of shorthand replacing rulesets with a single selector each, this doesn't apply to the validity of the ruleset itself. > > This leads to an important consequence: if one single basic selector is invalid, like when using an unknown pseudo-element or pseudo-class, the whole _selector_ is invalid and therefore the entire rule is ignored (as invalid too). ## CSS statements Rulesets are the main building blocks of a style sheet, which often consists of only a big list of them. But there is other information that a Web author wants to convey in the style sheet, like the character set, other external style sheets to import, font face or list counter descriptions and many more. It will use other and specific kinds of statements to do that. A **statement** is a building block that begins with any non-space characters and ends at the first closing brace or semicolon (outside a string, non-escaped and not included into another {}, () or \[] pair). ![css syntax - statements Venn diag.png](css_syntax_-_statements_venn_diag.png) There are two kinds of statements: - **Rulesets** (or _rules_) that, as seen, associate a collection of CSS declarations to a condition described by a [selector](/en-US/docs/Web/CSS/CSS_selectors). - **At-rules** that start with an at sign, '`@`' (`U+0040 COMMERCIAL AT`), followed by an identifier and then continuing up to the end of the statement, that is up to the next semicolon (;) outside of a block, or the end of the next block. Each type of [at-rules](/en-US/docs/Web/CSS/At-rule), defined by the identifier, may have its own internal syntax, and semantics of course. They are used to convey meta-data information (like {{ cssxref("@charset") }} or {{ cssxref("@import") }}), conditional information (like {{ cssxref("@media") }} or {{ cssxref("@document") }}), or descriptive information (like {{ cssxref("@font-face") }}). Any statement which isn't a ruleset or an at-rule is invalid and ignored. ### Nested statements There is another group of statements – the **nested statements**. These are statements that can be used in a specific subset of at-rules – the _conditional group rules_. These statements only apply if a specific condition is matched: the `@media` at-rule content is applied only if the device on which the browser runs matches the expressed condition; the `@document` at-rule content is applied only if the current page matches some conditions, and so on. In CSS1 and CSS2.1, only _rulesets_ could be used inside conditional group rules. That was very restrictive and this restriction was lifted in [_CSS Conditionals Level 3_](/en-US/docs/Web/CSS/CSS_conditional_rules). Now, though still experimental and not supported by every browser, conditional group rules can contain a wider range of content: rulesets but also some, but not all, at-rules. ## See also - CSS key concepts: - **CSS syntax** - [Comments](/en-US/docs/Web/CSS/Comments) - [Specificity](/en-US/docs/Web/CSS/Specificity) - [Inheritance](/en-US/docs/Web/CSS/Inheritance) - [Box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model) - [Layout modes](/en-US/docs/Web/CSS/Layout_mode) - [Visual formatting models](/en-US/docs/Web/CSS/Visual_formatting_model) - [Margin collapsing](/en-US/docs/Web/CSS/CSS_box_model/Mastering_margin_collapsing) - Values - [Initial values](/en-US/docs/Web/CSS/initial_value) - [Computed values](/en-US/docs/Web/CSS/computed_value) - [Used values](/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/initial-letter/index.md
--- title: initial-letter slug: Web/CSS/initial-letter page-type: css-property status: - experimental browser-compat: css.properties.initial-letter --- {{CSSRef}}{{SeeCompatTable}} The `initial-letter` CSS property sets styling for dropped, raised, and sunken initial letters. ## Syntax ```css /* Keyword values */ initial-letter: normal; /* Numeric values */ initial-letter: 1.5; /* Initial letter occupies 1.5 lines */ initial-letter: 3; /* Initial letter occupies 3 lines */ initial-letter: 3 2; /* Initial letter occupies 3 lines and sinks 2 lines */ /* Global values */ initial-letter: inherit; initial-letter: initial; initial-letter: revert; initial-letter: revert-layer; initial-letter: unset; ``` The keyword value `normal`, or a `<number>` optionally followed by an `<integer>`. ### Values - `normal` - : No special initial-letter effect. Text behaves as normal. - `<number>` - : Defines the size of the initial letter, in terms of how many lines it occupies. Negative values are not allowed. - `<integer>` - : Defines the number of lines the initial letter should sink when the size of it is given. Values must be greater than zero. If omitted, it duplicates the size value, floored to the nearest positive whole number. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting initial letter size #### HTML ```html <p class="normal">Initial letter is normal</p> <p class="onefive">Initial letter occupies 1.5 lines</p> <p class="three">Initial letter occupies 3 lines</p> ``` #### CSS ```css .normal::first-letter { -webkit-initial-letter: normal; initial-letter: normal; } .onefive::first-letter { -webkit-initial-letter: 1.5; initial-letter: 1.5; } .three::first-letter { -webkit-initial-letter: 3; initial-letter: 3; } ``` #### Result {{EmbedLiveSample('Setting_initial_letter_size', 250, 180)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("initial-letter-align")}} - [Drop caps in CSS](https://www.oddbird.net/2017/01/03/initial-letter/)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/line-height-step/index.md
--- title: line-height-step slug: Web/CSS/line-height-step page-type: css-property status: - experimental browser-compat: css.properties.line-height-step --- {{CSSRef}}{{SeeCompatTable}} The **`line-height-step`** CSS property sets the step unit for line box heights. When the property is set, line box heights are rounded up to the closest multiple of the unit. ## Syntax ```css /* Point values */ line-height-step: 18pt; /* Global values */ line-height-step: inherit; line-height-step: initial; line-height-step: revert; line-height-step: revert-layer; line-height-step: unset; ``` The `line-height-step` property is specified as any one of the following: - a `<length>`. ### Values - `<length>` - : The specified {{cssxref("&lt;length&gt;")}} is used in the calculation of the line box height step. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting step unit for line box height In the following example, the height of line box in each paragraph is rounded up to the step unit. The line box in `<h1>` does not fit into one step unit and thus occupies two, but it is still centered within the two step unit. ```css :root { font-size: 12pt; --my-grid: 18pt; line-height-step: var(--my-grid); } h1 { font-size: 20pt; margin-top: calc(2 * var(--my-grid)); } ``` The result of these rules is shown below in the following screenshot: ![How the line-height-step property affects the appearance of text.](line-grid-center.png) ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{Cssxref("font")}} - {{Cssxref("font-size")}} - {{Cssxref("line-height")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/widows/index.md
--- title: widows slug: Web/CSS/widows page-type: css-property browser-compat: css.properties.widows --- {{CSSRef}} The **`widows`** [CSS](/en-US/docs/Web/CSS) property sets the minimum number of lines in a block container that must be shown at the _top_ of a [page](/en-US/docs/Web/CSS/CSS_paged_media), region, or [column](/en-US/docs/Web/CSS/CSS_multicol_layout). In typography, a _widow_ is the last line of a paragraph that appears alone at the top of a page. (The paragraph is continued from a prior page.) ## Syntax ```css /* <integer> values */ widows: 2; widows: 3; /* Global values */ widows: inherit; widows: initial; widows: revert; widows: revert-layer; widows: unset; ``` ### Values - {{cssxref("&lt;integer&gt;")}} - : The minimum number of lines that can stay by themselves at the top of a new fragment after a fragmentation break. The value must be positive. ## Formal definition {{CSSInfo}} ## Formal syntax {{CSSSyntax}} ## Examples ### Controlling column widows #### HTML ```html <div> <p>This is the first paragraph containing some text.</p> <p> This is the second paragraph containing some more text than the first one. It is used to demonstrate how widows work. </p> <p> This is the third paragraph. It has a little bit more text than the first one. </p> </div> ``` #### CSS ```css div { background-color: #8cffa0; columns: 3; widows: 2; } p { background-color: #8ca0ff; } p:first-child { margin-top: 0; } ``` #### Result {{EmbedLiveSample("Controlling_column_widows", 400, 160)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("orphans")}} - [Paged media](/en-US/docs/Web/CSS/CSS_paged_media)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/scroll-margin-inline/index.md
--- title: scroll-margin-inline slug: Web/CSS/scroll-margin-inline page-type: css-shorthand-property browser-compat: css.properties.scroll-margin-inline --- {{CSSRef}} The `scroll-margin-inline` [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) sets the scroll margins of an element in the inline dimension. {{EmbedInteractiveExample("pages/css/scroll-margin-inline.html")}} ## Constituent properties This property is a shorthand for the following CSS properties: - [`scroll-margin-inline-end`](/en-US/docs/Web/CSS/scroll-margin-inline-end) - [`scroll-margin-inline-start`](/en-US/docs/Web/CSS/scroll-margin-inline-start) ## Syntax ```css /* <length> values */ scroll-margin-inline: 10px; scroll-margin-inline: 1em 0.5em; /* Global values */ scroll-margin-inline: inherit; scroll-margin-inline: initial; scroll-margin-inline: revert; scroll-margin-inline: revert-layer; scroll-margin-inline: unset; ``` ### Values - {{CSSXref("&lt;length&gt;")}} - : An outset from the corresponding edge of the scroll container. ## Description The scroll-margin values represent outsets defining the scroll snap area that is used for snapping this box to the snapport. The scroll snap area is determined by taking the transformed border box, finding its rectangular bounding box (axis-aligned in the scroll container's coordinate space), then adding the specified outsets. ## Formal definition {{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: 1rem; } .scroller > div:nth-child(3) { scroll-margin-inline: 2rem; } ``` This means that when scrolling past the middle child elements, the scrolling will snap to `1rem` outside the inline end edge of the second `<div>`, and `2rems` outside the inline end edge of the third `<div>`. > **Note:** Here we are setting `scroll-margin` on the start _and_ end of the inline axis (x in our case), but only the end edge is really relevant. It would work just as well here to only set a scroll margin on that one edge, for example with `scroll-margin-inline: 0 1rem`, or `scroll-margin-inline-end: 1rem`. #### Result Try it for yourself: {{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-language-override/index.md
--- title: font-language-override slug: Web/CSS/font-language-override page-type: css-property browser-compat: css.properties.font-language-override --- {{CSSRef}} The **`font-language-override`** CSS property controls the use of language-specific glyphs in a typeface. By default, HTML's `lang` attribute tells browsers to display glyphs designed specifically for that language. For example, a lot of fonts have a special character for the digraph `fi` that merge the dot on the "i" with the "f." However, if the language is set to Turkish the typeface will likely know not to use the merged glyph; Turkish has two versions of the "i," one with a dot (`i`) and one without (`Δ±`), and using the ligature would incorrectly transform a dotted "i" into a dotless "i." The `font-language-override` property lets you override the typeface behavior for a specific language. This is useful, for example, when the typeface you're using lacks proper support for the language. For instance, if a typeface doesn't have proper rules for the Azeri language, you can force the font to use Turkish glyphs, which follow similar rules. ## Syntax ```css /* Keyword value */ font-language-override: normal; /* <string> values */ font-language-override: "ENG"; /* Use English glyphs */ font-language-override: "TRK"; /* Use Turkish glyphs */ /* Global values */ font-language-override: inherit; font-language-override: initial; font-language-override: revert; font-language-override: revert-layer; font-language-override: unset; ``` The `font-language-override` property is specified as the keyword `normal` or a `<string>`. ### Values - `normal` - : Tells the browser to use font glyphs that are appropriate for the language specified by the `lang` attribute. This is the default value. - {{cssxref("string")}} - : Tells the browser to use font glyphs that are appropriate for the language specified by the string. The string must match a language tag found in the [OpenType language system](https://docs.microsoft.com/typography/opentype/spec/languagetags). For example, "ENG" is English, and "KOR" is Korean. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Using Danish glyphs #### HTML ```html <p class="para1">Default language setting.</p> <p class="para2"> This is a string with the <code>font-language-override</code> set to Danish. </p> ``` #### CSS ```css p.para1 { font-language-override: normal; } p.para2 { font-language-override: "DAN"; } ``` #### Result {{ EmbedLiveSample('Using Danish glyphs') }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("font-variant")}}, {{cssxref("font-variant-position")}}, {{cssxref("font-variant-east-asian")}}, {{cssxref("font-variant-caps")}}, {{cssxref("font-variant-ligatures")}}, {{cssxref("font-variant-numeric")}}, {{cssxref("font-variant-alternates")}}, {{cssxref("font-synthesis")}}, {{cssxref("font-kerning")}}.
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_text_decoration/index.md
--- title: CSS text decoration slug: Web/CSS/CSS_text_decoration page-type: css-module spec-urls: https://drafts.csswg.org/css-text-decor/ --- {{CSSRef}} The **CSS text decoration** module defines features relating to text decoration, such as underlines, text shadows, and emphasis marks. ## Reference ### Properties - {{cssxref("text-decoration")}} - {{cssxref("text-decoration-color")}} - {{cssxref("text-decoration-line")}} - {{cssxref("text-decoration-skip-ink")}} - {{cssxref("text-decoration-style")}} - {{cssxref("text-decoration-thickness")}} - {{cssxref("text-emphasis")}} - {{cssxref("text-emphasis-color")}} - {{cssxref("text-emphasis-position")}} - {{cssxref("text-emphasis-style")}} - {{cssxref("text-shadow")}} - {{cssxref("text-underline-offset")}} - {{cssxref("text-underline-position")}} ## Examples ```css .under { text-decoration: underline red; } .over { text-decoration: wavy overline lime; } .line { text-decoration: line-through; } .plain { text-decoration: none; } .underover { text-decoration: dashed underline overline; } .thick { text-decoration: solid underline purple 4px; } .blink { text-decoration: blink; } ``` ```html <p class="under">This text has a line underneath it.</p> <p class="over">This text has a line over it.</p> <p class="line">This text has a line going through it.</p> <p> This <a class="plain" href="#">link will not be underlined</a>, as links generally are by default. Be careful when removing the text decoration on anchors since users often depend on the underline to denote hyperlinks. </p> <p class="underover">This text has lines above <em>and</em> below it.</p> <p class="thick"> This text has a really thick purple underline in supporting browsers. </p> <p class="blink"> This text might blink for you, depending on the browser you use. </p> ``` {{EmbedLiveSample('Examples','auto','320')}} ## Specifications {{Specifications}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/align-items/index.md
--- title: align-items slug: Web/CSS/align-items page-type: css-property browser-compat: css.properties.align-items --- {{CSSRef}} The [CSS](/en-US/docs/Web/CSS) **`align-items`** property sets the {{cssxref("align-self")}} value on all direct children as a group. In Flexbox, it controls the alignment of items on the {{glossary("Cross Axis")}}. In Grid Layout, it controls the alignment of items on the Block Axis within their {{glossary("Grid Areas", "grid area")}}. The interactive example below demonstrates some of the values for `align-items` using grid layout. {{EmbedInteractiveExample("pages/css/align-items.html")}} ## Syntax ```css /* Basic keywords */ align-items: normal; align-items: stretch; /* Positional alignment */ /* align-items does not take left and right values */ align-items: center; align-items: start; align-items: end; align-items: flex-start; align-items: flex-end; align-items: self-start; align-items: self-end; /* Baseline alignment */ align-items: baseline; align-items: first baseline; align-items: last baseline; /* Overflow alignment (for positional alignment only) */ align-items: safe center; align-items: unsafe center; /* Global values */ align-items: inherit; align-items: initial; align-items: revert; align-items: revert-layer; align-items: unset; ``` ### Values - `normal` - : The effect of this keyword is dependent of the layout mode we are in: - In absolutely-positioned layouts, the keyword behaves like `start` on _replaced_ absolutely-positioned boxes, and as `stretch` on _all other_ absolutely-positioned boxes. - In static position of absolutely-positioned layouts, the keyword behaves as `stretch`. - For flex items, the keyword behaves as `stretch`. - For grid items, this keyword leads to a behavior similar to the one of `stretch`, except for boxes with an aspect ratio or an intrinsic sizes where it behaves like `start`. - The property doesn't apply to block-level boxes, and to table cells. - `flex-start` - : Used in flex layout only, aligns the flex items flush against the flex container's main-start or cross-start side. - `flex-end` - : Used in flex layout only, aligns the flex items flush against the flex container's main-end or cross-end side. - `center` - : The flex items' margin boxes are centered within the line on the cross-axis. If the cross-size of an item is larger than the flex container, it will overflow equally in both directions. - `start` - : The items are packed flush to each other toward the start edge of the alignment container in the appropriate axis. - `end` - : The items are packed flush to each other toward the end edge of the alignment container in the appropriate axis. - `self-start` - : The items are packed flush to the edge of the alignment container's start side of the item, in the appropriate axis. - `self-end` - : The items are packed flush to the edge of the alignment container's end side of the item, in the appropriate axis. - `baseline`, `first baseline`, `last baseline` - : All flex items are aligned such that their [flex container baselines](https://drafts.csswg.org/css-flexbox-1/#flex-baselines) align. The item with the largest distance between its cross-start margin edge and its baseline is flushed with the cross-start edge of the line. - `stretch` - : If the items are smaller than the alignment container, auto-sized items will be equally enlarged to fill the container, respecting the items' width and height limits. - `safe` - : Used alongside an alignment keyword. If the chosen keyword means that the item overflows the alignment container causing data loss, the item is instead aligned as if the alignment mode were `start`. - `unsafe` - : Used alongside an alignment keyword. Regardless of the relative sizes of the item and alignment container and whether overflow which causes data loss might happen, the given alignment value is honored. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### CSS ```css #container { height: 200px; width: 240px; align-items: center; /* Can be changed in the live sample */ background-color: #8c8c8c; } .flex { display: flex; flex-wrap: wrap; } .grid { display: grid; grid-template-columns: repeat(auto-fill, 50px); } div > div { box-sizing: border-box; border: 2px solid #8c8c8c; width: 50px; display: flex; align-items: center; justify-content: center; } #item1 { background-color: #8cffa0; min-height: 30px; } #item2 { background-color: #a0c8ff; min-height: 50px; } #item3 { background-color: #ffa08c; min-height: 40px; } #item4 { background-color: #ffff8c; min-height: 60px; } #item5 { background-color: #ff8cff; min-height: 70px; } #item6 { background-color: #8cffff; min-height: 50px; font-size: 30px; } select { font-size: 16px; } .row { margin-top: 10px; } ``` ### HTML ```html <div id="container" class="flex"> <div id="item1">1</div> <div id="item2">2</div> <div id="item3">3</div> <div id="item4">4</div> <div id="item5">5</div> <div id="item6">6</div> </div> <div class="row"> <label for="display">display: </label> <select id="display"> <option value="flex">flex</option> <option value="grid">grid</option> </select> </div> <div class="row"> <label for="values">align-items: </label> <select id="values"> <option value="normal">normal</option> <option value="flex-start">flex-start</option> <option value="flex-end">flex-end</option> <option value="center" selected>center</option> <option value="baseline">baseline</option> <option value="stretch">stretch</option> <option value="start">start</option> <option value="end">end</option> <option value="self-start">self-start</option> <option value="self-end">self-end</option> <option value="first baseline">first baseline</option> <option value="last baseline">last baseline</option> <option value="safe center">safe center</option> <option value="unsafe center">unsafe center</option> <option value="safe right">safe right</option> <option value="unsafe right">unsafe right</option> <option value="safe end">safe end</option> <option value="unsafe end">unsafe end</option> <option value="safe self-end">safe self-end</option> <option value="unsafe self-end">unsafe self-end</option> <option value="safe flex-end">safe flex-end</option> <option value="unsafe flex-end">unsafe flex-end</option> </select> </div> ``` ```js hidden const values = document.getElementById("values"); const display = document.getElementById("display"); const container = document.getElementById("container"); values.addEventListener("change", (evt) => { container.style.alignItems = evt.target.value; }); display.addEventListener("change", (evt) => { container.className = evt.target.value; }); ``` ### Result {{EmbedLiveSample("Examples", "260px", "290px")}} ## 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-self")}} property
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/inheritance/index.md
--- title: Inheritance slug: Web/CSS/Inheritance page-type: guide --- {{CSSRef}} In CSS, **inheritance** controls what happens when no value is specified for a property on an element. CSS properties can be categorized in two types: - **inherited properties**, which by default are set to the [computed value](/en-US/docs/Web/CSS/computed_value) of the parent element - **non-inherited properties**, which by default are set to [initial value](/en-US/docs/Web/CSS/initial_value) of the property Refer to [any CSS property](/en-US/docs/Web/CSS/Reference#index) definition to see whether a specific property inherits by default ("Inherited: yes") or not ("Inherited: no"). ## Inherited properties When no value for an **inherited property** has been specified on an element, the element gets the [computed value](/en-US/docs/Web/CSS/computed_value) of that property on its parent element. Only the root element of the document gets the [initial value](/en-US/docs/Web/CSS/initial_value) given in the property's summary. A typical example of an inherited property is the [`color`](/en-US/docs/Web/CSS/color) property. Consider the following style rules and the markup: ```css p { color: green; } ``` ```html <p>This paragraph has <em>emphasized text</em> in it.</p> ``` {{EmbedLiveSample("Inherited properties","",40)}} The words "emphasized text" will appear green, since the `em` element has inherited the value of the [`color`](/en-US/docs/Web/CSS/color) property from the `p` element. It does _not_ get the initial value of the property (which is the color that is used for the root element when the page specifies no color). ## Non-inherited properties When no value for a **non-inherited property** has been specified on an element, the element gets the [initial value](/en-US/docs/Web/CSS/initial_value) of that property (as specified in the property's summary). A typical example of a non-inherited property is the {{ Cssxref("border") }} property. Consider the following style rules and the markup: ```css p { border: medium solid; } ``` ```html <p>This paragraph has <em>emphasized text</em> in it.</p> ``` {{EmbedLiveSample("Non-inherited properties","",40)}} The words "emphasized text" will not have another border (since the initial value of [`border-style`](/en-US/docs/Web/CSS/border-style) is `none`). ## Notes The [`inherit`](/en-US/docs/Web/CSS/inherit) keyword allows authors to explicitly specify inheritance. It works on both inherited and non-inherited properties. You can control inheritance for all properties at once using the [`all`](/en-US/docs/Web/CSS/all) shorthand property, which applies its value to all properties. For example: ```css p { all: revert; font-size: 200%; font-weight: bold; } ``` This reverts the style of the paragraphs' [`font`](/en-US/docs/Web/CSS/font) property to the user agent's default unless a user stylesheet exists, in which case that is used instead. Then it doubles the font size and applies a [`font-weight`](/en-US/docs/Web/CSS/font-weight) of `"bold"`. ### Overriding inheritance, an example Using our previous example with [`border`](/en-US/docs/Web/CSS/border), if we explicitly set the inheritance with `inherit`, we get the following: ```css p { border: medium solid; } em { border: inherit; } ``` ```html <p>This paragraph has <em>emphasized text</em> in it.</p> ``` {{EmbedLiveSample("Overriding inheritance, an example","",40)}} We can see here another border around the word "emphasized text". ## See also - CSS values for controlling inheritance: [`inherit`](/en-US/docs/Web/CSS/inherit), [`initial`](/en-US/docs/Web/CSS/initial), [`revert`](/en-US/docs/Web/CSS/revert), [`revert-layer`](/en-US/docs/Web/CSS/revert-layer), and [`unset`](/en-US/docs/Web/CSS/unset) - [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) - [Box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model) - [Layout modes](/en-US/docs/Web/CSS/Layout_mode) - [Visual formatting models](/en-US/docs/Web/CSS/Visual_formatting_model) - [Margin collapsing](/en-US/docs/Web/CSS/CSS_box_model/Mastering_margin_collapsing) - Values - [Initial values](/en-US/docs/Web/CSS/initial_value) - [Computed values](/en-US/docs/Web/CSS/computed_value) - [Used values](/en-US/docs/Web/CSS/used_value) - [Actual values](/en-US/docs/Web/CSS/actual_value) - [Value definition syntax](/en-US/docs/Web/CSS/Value_definition_syntax) - [Shorthand properties](/en-US/docs/Web/CSS/Shorthand_properties) - [Replaced elements](/en-US/docs/Web/CSS/Replaced_element)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/overflow-y/index.md
--- title: overflow-y slug: Web/CSS/overflow-y page-type: css-property browser-compat: css.properties.overflow-y --- {{CSSRef}} The **`overflow-y`** [CSS](/en-US/docs/Web/CSS) property sets what shows when content overflows a block-level element's top and bottom edges. This may be nothing, a scroll bar, or the overflow content. This property may also be set by using the [`overflow`](/en-US/docs/Web/CSS/overflow) shorthand property. {{EmbedInteractiveExample("pages/css/overflow-y.html")}} ## Syntax ```css /* Keyword values */ overflow-y: visible; overflow-y: hidden; overflow-y: clip; overflow-y: scroll; overflow-y: auto; /* Global values */ overflow-y: inherit; overflow-y: initial; overflow-y: revert; overflow-y: revert-layer; overflow-y: unset; ``` The `overflow-y` property is specified as a single {{CSSXref("overflow_value", "&lt;overflow&gt;")}} keyword value. If {{cssxref("overflow-x")}} is `hidden`, `scroll`, or `auto` and the `overflow-y` property is `visible` (default), the value will be implicitly computed as `auto`. ### Values - `visible` - : Overflow content is not clipped and may be visible outside the element's padding box at the top and bottom edges. The element box is not a {{glossary("scroll container")}}. - `hidden` - : Overflow content is clipped if necessary to fit vertically in the elements' padding box. No scroll bars are provided. - `clip` - : Overflow content is clipped at the element's _overflow clip edge_ that is defined using the [`overflow-clip-margin`](/en-US/docs/Web/CSS/overflow-clip-margin) property. As a result, content overflows the element's padding box by the {{cssxref("&lt;length&gt;")}} value of `overflow-clip-margin` or by `0px` if not set. The difference between `clip` and `hidden` is that the `clip` keyword also forbids all scrolling, including programmatic scrolling. No new formatting context is created. To establish a formatting context, use `overflow: clip` along with {{cssxref("display", "display: flow-root", "#flow-root")}}. The element box is not a scroll container. - `scroll` - : Overflow content is clipped if necessary to fit vertically inside the element's padding box. Browsers display scroll bars in the vertical direction whether or not any content is actually clipped. (This prevents scroll bars from appearing or disappearing when the content changes.) Printers may still print overflowing content. - `auto` - : Overflow content is clipped at the element's padding box, and overflow content can be scrolled into view. Unlike `scroll`, user agents display scroll bars _only if_ the content is overflowing, hiding scroll bars by default. If content fits inside the element's padding box, it looks the same as with `visible`, but still establishes a new block-formatting context. > **Note:** The keyword value `overlay` is a legacy value alias for `auto`. With `overlay`, the scroll bars are drawn on top of the content instead of taking up space. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting overflow-y behavior #### HTML ```html <ul> <li> <code>overflow-y:hidden</code> β€” hides the text outside the box <div id="div1"> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. </div> </li> <li> <code>overflow-y:scroll</code> β€” always adds a scrollbar <div id="div2"> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. </div> </li> <li> <code>overflow-y:visible</code> β€” displays the text outside the box if needed <div id="div3"> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. </div> </li> <li> <code>overflow-y:auto</code> β€” equivalent to <code>scroll</code> on most browsers <div id="div4"> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. </div> </li> </ul> ``` #### CSS ```css div { border: 1px solid black; width: 250px; height: 100px; } #div1 { overflow-y: hidden; margin-bottom: 12px; } #div2 { overflow-y: scroll; margin-bottom: 12px; } #div3 { overflow-y: visible; margin-bottom: 120px; } #div4 { overflow-y: auto; margin-bottom: 120px; } ``` #### Result {{EmbedLiveSample("Setting_overflow-y_behavior", "100%", "780")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{Cssxref("clip")}}, {{Cssxref("display")}}, {{cssxref("text-overflow")}}, {{cssxref("white-space")}} - [CSS overflow](/en-US/docs/Web/CSS/CSS_overflow) module - [CSS building blocks: Overflowing content](/en-US/docs/Learn/CSS/Building_blocks/Overflowing_content)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_-moz-color-swatch/index.md
--- title: "::-moz-color-swatch" slug: Web/CSS/::-moz-color-swatch page-type: css-pseudo-element status: - non-standard browser-compat: css.selectors.-moz-color-swatch --- {{CSSRef}}{{Non-standard_header}} The **`::-moz-color-swatch`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) is a [Mozilla extension](/en-US/docs/Web/CSS/Mozilla_Extensions) that represents the color selected in an {{HTMLElement("input")}} of `type="color"`. > **Note:** Using `::-moz-color-swatch` with anything but an `<input type="color">` doesn't match anything and has no effect. ## Syntax ```css ::-moz-color-swatch { /* ... */ } ``` ## Examples ### HTML ```html <input type="color" value="#de2020" /> ``` ### CSS ```css input[type="color"]::-moz-color-swatch { border-radius: 10px; border-style: none; } ``` ### Result {{EmbedLiveSample("Examples", 300, 50)}} ## Specifications Not part of any standard. ## Browser compatibility {{Compat}} ## See also - Similar pseudo-elements used by other browsers: - {{cssxref("::-webkit-color-swatch")}}, pseudo-element supported by WebKit and Blink (Safari, Chrome, and Opera)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-inline-style/index.md
--- title: border-inline-style slug: Web/CSS/border-inline-style page-type: css-property browser-compat: css.properties.border-inline-style --- {{CSSRef}} The **`border-inline-style`** [CSS](/en-US/docs/Web/CSS) property defines the style of the logical inline 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-inline-style.html")}} The border style in the other dimension can be set with {{cssxref("border-block-style")}}, which sets {{cssxref("border-block-start-style")}}, and {{cssxref("border-block-end-style")}}. ## Syntax ```css /* <'border-style'> values */ border-inline-style: dashed; border-inline-style: dotted; border-inline-style: groove; /* Global values */ border-inline-style: inherit; border-inline-style: initial; border-inline-style: revert; border-inline-style: revert-layer; border-inline-style: unset; ``` ### Values - `<'border-style'>` - : The line style of the border. See {{ cssxref("border-style") }}. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting border-inline-style #### HTML ```html <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ```css div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; border: 5px solid blue; border-inline-style: dashed; } ``` {{EmbedLiveSample("Setting border-inline-style", 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_logical_properties_and_values/index.md
--- title: CSS logical properties and values slug: Web/CSS/CSS_logical_properties_and_values page-type: css-module spec-urls: https://drafts.csswg.org/css-logical/ --- {{CSSRef}} The **CSS logical properties and values** module introduces logical properties and values that provide the ability to control layout through logical, rather than physical, direction and dimension mappings. The module also defines logical properties and values for properties previously defined in CSS 2.1. Logical properties define direction‐relative equivalents of their corresponding physical properties. ### Block vs. inline Logical properties and values use the abstract terms _block_ and _inline_ to describe the direction in which they flow. The physical meaning of these terms depends on the [writing mode](/en-US/docs/Web/CSS/CSS_writing_modes). - Block dimension - : The dimension perpendicular to the flow of text within a line, i.e., the vertical dimension in horizontal writing modes, and the horizontal dimension in vertical writing modes. For standard English text, it is the vertical dimension. - Inline dimension - : The dimension parallel to the flow of text within a line, i.e., the horizontal dimension in horizontal writing modes, and the vertical dimension in vertical writing modes. For standard English text, it is the horizontal dimension. ### New properties and values CSS was initially designed with only physical coordinates in its controls. The module defines new flow–relative equivalents for many [values](/en-US/docs/Web/CSS/CSS_Values_and_Units) and [properties](/en-US/docs/Glossary/Property/CSS). Some physical properties now have logical equivalents. Properties that accept physical values (`top`, `bottom`, `left`, `right`) now also accept flow-relative logical values (`block-start`, `block-end`, `inline-start`, `inline-end`). The transition to logical axes is ongoing and not fully defined by the module; some properties don't yet have logical equivalents. ## Reference ### Properties for sizing - {{CSSxRef("block-size")}} - {{CSSxRef("inline-size")}} - {{CSSxRef("max-block-size")}} - {{CSSxRef("max-inline-size")}} - {{CSSxRef("min-block-size")}} - {{CSSxRef("min-inline-size")}} ### Properties for margins - {{CSSxRef("margin")}} (`logical` {{Experimental_Inline}} keyword) - {{CSSxRef("margin-block")}} - {{CSSxRef("margin-block-end")}} - {{CSSxRef("margin-block-start")}} - {{CSSxRef("margin-inline")}} - {{CSSxRef("margin-inline-end")}} - {{CSSxRef("margin-inline-start")}} ### Properties for paddings - {{CSSxRef("padding")}} (`logical` {{Experimental_Inline}} keyword) - {{CSSxRef("padding-block")}} - {{CSSxRef("padding-block-end")}} - {{CSSxRef("padding-block-start")}} - {{CSSxRef("padding-inline")}} - {{CSSxRef("padding-inline-end")}} - {{CSSxRef("padding-inline-start")}} ### Properties for borders - {{CSSxRef("border-block")}} - {{CSSxRef("border-block-color")}} - {{CSSxRef("border-block-end")}} - {{CSSxRef("border-block-end-color")}} - {{CSSxRef("border-block-end-style")}} - {{CSSxRef("border-block-end-width")}} - {{CSSxRef("border-block-start")}} - {{CSSxRef("border-block-start-color")}} - {{CSSxRef("border-block-start-style")}} - {{CSSxRef("border-block-start-width")}} - {{CSSxRef("border-block-style")}} - {{CSSxRef("border-block-width")}} - {{CSSxRef("border-color")}} - {{CSSxRef("border-inline")}} - {{CSSxRef("border-inline-color")}} - {{CSSxRef("border-inline-end")}} - {{CSSxRef("border-inline-end-color")}} - {{CSSxRef("border-inline-end-style")}} - {{CSSxRef("border-inline-end-width")}} - {{CSSxRef("border-inline-start")}} - {{CSSxRef("border-inline-start-color")}} - {{CSSxRef("border-inline-start-style")}} - {{CSSxRef("border-inline-start-width")}} - {{CSSxRef("border-inline-style")}} - {{CSSxRef("border-inline-width")}} - {{CSSxRef("border-style")}} - {{CSSxRef("border-width")}} ### Properties for border radius - {{CSSxRef("border-radius")}} - {{CSSxRef("border-start-start-radius")}} - {{CSSxRef("border-start-end-radius")}} - {{CSSxRef("border-end-start-radius")}} - {{CSSxRef("border-end-end-radius")}} ### Properties for positioning - {{CSSxRef("inset")}} - {{CSSxRef("inset-block")}} - {{CSSxRef("inset-block-end")}} - {{CSSxRef("inset-block-start")}} - {{CSSxRef("inset-inline")}} - {{CSSxRef("inset-inline-end")}} - {{CSSxRef("inset-inline-start")}} ### Properties for size containment - {{CSSxRef("contain-intrinsic-block-size")}} - {{CSSxRef("contain-intrinsic-inline-size")}} ### Properties for scrolling - {{CSSxRef("overflow-block")}} - {{CSSxRef("overflow-inline")}} - {{CSSxRef("overscroll-behavior-block")}} - {{CSSxRef("overscroll-behavior-inline")}} ### Properties for floating - {{CSSxRef("clear")}} (`inline-end` and `inline-start` keywords) - {{CSSxRef("float")}} (`inline-end` and `inline-start` keywords) ### Other properties - {{CSSxRef("caption-side")}} (`inline-end` and `inline-start` keywords) - {{CSSxRef("resize")}} (`block` and `inline` keywords) - {{CSSxRef("text-align")}} (`end` and `start` keywords) ### Deprecated properties - `offset-block-end` {{Non-standard_Inline}} {{Deprecated_Inline}} (now {{CSSxRef("inset-block-end")}}) - `offset-block-start` {{Non-standard_Inline}} {{Deprecated_Inline}} (now {{CSSxRef("inset-block-start")}}) - `offset-inline-end` {{Non-standard_Inline}} {{Deprecated_Inline}} (now {{CSSxRef("inset-inline-end")}}) - `offset-inline-start` {{Non-standard_Inline}} {{Deprecated_Inline}} (now {{CSSxRef("inset-inline-start")}}) ### Unsupported properties The following properties don't have logical equivalents: - {{CSSxRef("background-position-x")}} - {{CSSxRef("background-position-y")}} ### Unsupported values The following properties accept only physical values: - {{CSSxRef("text-underline-position")}} - {{CSSxRef("box-shadow")}} - {{CSSxRef("text-shadow")}} - {{CSSxRef("clip-path")}} - {{CSSxRef("&lt;position&gt;")}} - {{CSSxRef("background-position")}} - {{CSSxRef("object-position")}} - {{CSSxRef("mask-position")}} - {{CSSxRef("offset-position")}} - {{CSSxRef("offset-anchor")}} - {{CSSxRef("transform-origin")}} - {{CSSxRef("perspective-origin")}} ## Guides - [Basic concepts of logical properties and values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values/Basic_concepts_of_logical_properties_and_values) - [Logical properties for sizing](/en-US/docs/Web/CSS/CSS_logical_properties_and_values/Sizing) - [Logical properties for margins, borders, and padding](/en-US/docs/Web/CSS/CSS_logical_properties_and_values/Margins_borders_padding) - [Logical properties for floating and positioning](/en-US/docs/Web/CSS/CSS_logical_properties_and_values/Floating_and_positioning) ## Specifications {{Specifications}} ## Browser compatibility See the individual property pages for full compatibility information.
0
data/mdn-content/files/en-us/web/css/css_logical_properties_and_values
data/mdn-content/files/en-us/web/css/css_logical_properties_and_values/sizing/index.md
--- title: Logical properties for sizing slug: Web/CSS/CSS_logical_properties_and_values/Sizing page-type: guide --- {{CSSRef}} In this guide we will explain the flow-relative mappings between physical dimension properties and logical properties used for sizing elements on our pages. When specifying the size of an item, the [Logical Properties and Values](https://drafts.csswg.org/css-logical/) specification gives you the ability to indicate sizing as it relates to the flow of text (inline and block) rather than physical sizing which relates to the physical dimensions of horizontal and vertical (e.g. left and right). While these flow relative mappings may well become the default for many of us, in a design you may well use both physical and logical sizing. You might want some features to always relate to the physical dimensions whatever the writing mode. ## Mappings for dimensions The table below provides mappings between logical and physical properties. These mappings assume that you are in a `horizontal-tb` writing mode, such as English or Arabic, in which case {{CSSxRef("width")}} would be mapped to {{CSSxRef("inline-size")}}. If you were in a vertical writing mode then {{CSSxRef("inline-size")}} would be mapped to {{CSSxRef("height")}}. | Logical Property | Physical Property | | ------------------------------ | ------------------------- | | {{CSSxRef("inline-size")}} | {{CSSxRef("width")}} | | {{CSSxRef("block-size")}} | {{CSSxRef("height")}} | | {{CSSxRef("min-inline-size")}} | {{CSSxRef("min-width")}} | | {{CSSxRef("min-block-size")}} | {{CSSxRef("min-height")}} | | {{CSSxRef("max-inline-size")}} | {{CSSxRef("max-width")}} | | {{CSSxRef("max-block-size")}} | {{CSSxRef("max-height")}} | ## Width and height example The logical mappings for {{CSSxRef("width")}} and {{CSSxRef("height")}} are {{CSSxRef("inline-size")}}, which sets the length in the inline dimension and {{CSSxRef("block-size")}}, which sets the length in the block dimension. When working in English, replacing `width` with `inline-size` and `height` with `block-size` will give the same layout. In the live example below I have set the Writing Mode to `horizontal-tb`. Change it to `vertical-rl` and you will see that the first example β€” which uses `width` and `height` β€” remains the same size in each dimension, despite the text becoming vertical. The second example β€” which uses `inline-size` and `block-size` β€” will follow the text direction as if the entire block has rotated. {{EmbedGHLiveSample("css-examples/logical/size-inline-block.html", '100%', 500)}} ## Min-width and min-height example There are also mappings for {{CSSxRef("min-width")}} and {{CSSxRef("min-height")}} β€” these are {{CSSxRef("min-inline-size")}} and {{CSSxRef("min-block-size")}}. These work in the same way as the `inline-size` and `block-size` properties, but setting a minimum rather than a fixed size. Try changing the example below to `vertical-rl`, as with the first example, to see the effect it has. I am using `min-height` in the first example and `min-block-size` in the second. {{EmbedGHLiveSample("css-examples/logical/size-min.html", "100%", 500)}} ## Max-width and max-height example Finally you can use {{CSSxRef("max-inline-size")}} and {{CSSxRef("max-block-size")}} as logical replacements for {{CSSxRef("max-width")}} and {{CSSxRef("max-height")}}. Try playing with the below example in the same way as before. {{EmbedGHLiveSample("css-examples/logical/size-max.html", "100%", 500)}} ## Logical keywords for resize The {{CSSxRef("resize")}} property sets whether or not an item can be resized and has physical values of `horizontal` and `vertical`. The `resize` property also has logical keyword values. Using `resize: inline` allows resizing in the inline dimension and `resize: block` allow resizing in the block dimension. The keyword value of `both` for the resize property works whether you are thinking physically or logically. It sets both dimensions at once. Try playing with the below example. {{EmbedGHLiveSample("css-examples/logical/size-resize.html", "100%", 700)}}
0
data/mdn-content/files/en-us/web/css/css_logical_properties_and_values
data/mdn-content/files/en-us/web/css/css_logical_properties_and_values/floating_and_positioning/index.md
--- title: Logical properties for floating and positioning slug: Web/CSS/CSS_logical_properties_and_values/Floating_and_positioning page-type: guide --- {{CSSRef}} The [Logical Properties and Values specification](https://drafts.csswg.org/css-logical/) contains logical mappings for the physical values of {{cssxref("float")}} and {{cssxref("clear")}}, and also for the positioning properties used with [positioned layout](/en-US/docs/Web/CSS/CSS_positioned_layout). This guide takes a look at how to use these. ## Mapped properties and values The table below details the properties and values discussed in this guide along with their physical mappings. They assume a horizontal {{cssxref("writing-mode")}}, with a left-to-right direction. | Logical property or value | Physical property or value | | ---------------------------------- | -------------------------------- | | {{cssxref("float")}}: inline-start | {{cssxref("float")}}: left | | {{cssxref("float")}}: inline-end | {{cssxref("float")}}: right | | {{cssxref("clear")}}: inline-start | {{cssxref("clear")}}: left | | {{cssxref("clear")}}: inline-end | {{cssxref("clear")}}: right | | {{cssxref("inset-inline-start")}} | {{cssxref("left")}} | | {{cssxref("inset-inline-end")}} | {{cssxref("right")}} | | {{cssxref("inset-block-start")}} | {{cssxref("top")}} | | {{cssxref("inset-block-end")}} | {{cssxref("bottom")}} | | {{cssxref("text-align")}}: start | {{cssxref("text-align")}}: left | | {{cssxref("text-align")}}: end | {{cssxref("text-align")}}: right | In addition to these mapped properties there are some additional shorthand properties made possible by being able to address block and inline dimensions. These have no mapping to physical properties, aside from the {{cssxref("inset")}} property. | Logical property | Purpose | | --------------------------- | ------------------------------------------------------------------------------- | | {{cssxref("inset-inline")}} | Sets both of the above inset values for the inline dimension simultaneously. | | {{cssxref("inset-block")}} | Sets both of the above inset values for the block dimension simultaneously. | | {{cssxref("inset")}} | Sets all four inset values simultaneously with physical mapping of multi-value. | ## Float and clear example The physical values used with the {{cssxref("float")}} and {{cssxref("clear")}} properties are `left`, `right` and `both`. The Logical Properties specification defines the values `inline-start` and `inline-end` as mappings for `left` and `right`. In the example below I have two boxes β€” the first has the box floated with `float: left`, the second with `float: inline-start`. If you change the `writing-mode` to `vertical-rl` or the `direction` to `rtl` you will see that the left-floated box always sticks to the left, whereas the `inline-start`-floated item follows the `direction` and `writing-mode`. {{EmbedGHLiveSample("css-examples/logical/float.html", '100%', 700)}} ## Example: Inset properties for positioned layout Positioning generally allows us to position an element in a manner relative to its containing block β€” we essentially inset the item relative to where it would fall based on normal flow. To do this we have historically used the physical properties {{cssxref("top")}}, {{cssxref("right")}}, {{cssxref("bottom")}} and {{cssxref("left")}}. These properties take a length or a percentage as a value, and relate to the user's screen dimensions. New properties have been created in the Logical Properties specification for when you want the positioning to relate to the flow of text in your writing mode. These are as follows: {{cssxref("inset-block-start")}}, {{cssxref("inset-block-end")}}, {{cssxref("inset-inline-start")}} and {{cssxref("inset-inline-end")}}. In the below example I have used the `inset-block-start` and `inset-inline-end` properties to position the blue box using absolute positioning inside the area with the grey dotted border, which has `position: relative`. Change the `writing-mode` property to `vertical-rl`, or add `direction: rtl`, and see how the flow relative box stays with the text direction. {{EmbedGHLiveSample("css-examples/logical/positioning-inset.html", '100%', 700)}} ## New two- and four-value shorthands As with other properties in the specification we have some new shorthand properties, which give the ability to set two or four values at once. - {{cssxref("inset")}} β€” sets all four sides together with physical mapping. - {{cssxref("inset-inline")}} β€” sets both logical inline insets. - {{cssxref("inset-block")}} β€” sets both logical block insets. ## Example: Logical values for text-align The {{cssxref("text-align")}} property has logical values that relate to text direction β€” rather than using `left` and `right` we can use `start` and `end`. In the below example I have set `text-align: right` in the first block and `text-align: end` in the second. If you change the value of `direction` to `rtl` you will see that the alignment stays to the right for the first block, but goes to the logical end on the left in the second. {{EmbedGHLiveSample("css-examples/logical/text-align.html", '100%', 700)}} This works more consistently when using box alignment that uses start and end rather than physical directions for alignment.
0
data/mdn-content/files/en-us/web/css/css_logical_properties_and_values
data/mdn-content/files/en-us/web/css/css_logical_properties_and_values/basic_concepts_of_logical_properties_and_values/index.md
--- title: Basic concepts of logical properties and values slug: Web/CSS/CSS_logical_properties_and_values/Basic_concepts_of_logical_properties_and_values page-type: guide --- {{CSSRef}} The Logical Properties and Values Specification introduces flow-relative mappings for many of the properties and values in CSS. This article introduces the specification, and explains flow relative properties and values. ## Why do we need logical properties? CSS traditionally has sized things according to the physical dimensions of the screen. Therefore we describe boxes as having a {{CSSxRef("width")}} and {{CSSxRef("height")}}, position items from the `top` and `left`, float things left, assign borders, margin, and padding to the `top`, `right`, `bottom`, `left`, etc. The [Logical Properties and Values specification](https://drafts.csswg.org/css-logical/) defines mappings for these physical values to their logical, or flow relative, counterparts β€” e.g. `start` and `end` as opposed to `left` and `right`/`top` and `bottom`. An example of why these mappings might be needed is as follows. I have a Layout using CSS Grid, the grid container has a width applied and I am using the {{CSSxRef("align-self")}} and {{CSSxRef("justify-self")}} properties to align the items. These properties are flow relative β€” `justify-self: start` aligns the item to the start on the inline dimension, `align-self: start` does the same on the block dimension. ![A grid in a horizontal writing mode](grid-horizontal-width-sm.png) If I now change the writing mode of this component to `vertical-rl` using the {{CSSxRef("writing-mode")}} property, the alignment continues to work in the same way. The inline dimension is now running vertically and the block dimension horizontally. The grid doesn't look the same, however, as the width assigned to the container is a horizontal measure, a measure tied to the physical and not the logical or flow relative running of the text. ![A grid in vertical writing mode.](grid-vertical-width-sm.png) If instead of the `width` property we use the logical property {{CSSxRef("inline-size")}}, the component now works the same way no matter which writing mode it is displayed using. ![A grid layout in vertical writing mode](grid-vertical-inline-size-small.png) You can try this out in the live example below. Change `writing-mode` from `vertical-rl` to `horizontal-tb` on `.grid` to see how the different properties change the layout. {{EmbedGHLiveSample("css-examples/logical/intro-grid-example.html", '100%', 700)}} When working with a site in a writing mode other than a horizontal, top to bottom one, or when using writing modes for creative reasons, being able to relate to the flow of the content makes a lot of sense. ## Block and inline dimensions A key concept of working with flow relative properties and values is the two dimensions of block and inline. As we saw above, newer CSS layout methods such as Flexbox and Grid Layout use the concepts of `block` and `inline` rather than `right` and `left`/`top` and `bottom` when aligning items. The `inline` dimension is the dimension along which a line of text runs in the writing mode in use. Therefore, in an English document with the text running horizontally left to right, or an Arabic document with the text running horizontally right to left, the inline dimension is _horizontal_. Switch to a vertical writing mode (e.g. a Japanese document) and the inline dimension is now _vertical_, as lines in that writing mode run vertically. The block dimension is the other dimension, and the direction in which blocks β€” such as paragraphs β€” display one after the other. In English and Arabic, these run vertically, whereas in any vertical writing mode these run horizontally. The below diagram shows the inline and block directions in a horizontal writing mode: ![diagram showing the inline axis running horizontally, block axis vertically.](mdn-horizontal.png) This diagram shows block and inline in a vertical writing mode: ![Diagram showing the block axis running horizontally the inline axis vertically.](mdn-vertical.png) ## See also - [Box alignment in grid layout](/en-US/docs/Web/CSS/CSS_grid_layout/Box_alignment_in_grid_layout) - [Box alignment in flex layout](/en-US/docs/Web/CSS/CSS_box_alignment/Box_alignment_in_flexbox) - [Flow layout and writing modes](/en-US/docs/Web/CSS/CSS_flow_layout/Flow_layout_and_writing_modes) - [Understanding logical properties and values](https://www.smashingmagazine.com/2018/03/understanding-logical-properties-values/) on Smashing Magazine (2018)
0
data/mdn-content/files/en-us/web/css/css_logical_properties_and_values
data/mdn-content/files/en-us/web/css/css_logical_properties_and_values/margins_borders_padding/index.md
--- title: Logical properties for margins, borders, and padding slug: Web/CSS/CSS_logical_properties_and_values/Margins_borders_padding page-type: guide --- {{CSSRef}} The [Logical Properties and Values specification](https://drafts.csswg.org/css-logical/) defines flow-relative mappings for the various margin, border, and padding properties and their shorthands. In this guide, we take a look at these. If you have looked at the main page for the [CSS logical properties and values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values) module, you will see there are a huge number of properties listed. This is mostly because there are four longhand values each for margin, border, and padding side, plus all the shorthand values. ## Mappings for margins, borders, and padding The specification details mappings for each logical value to a physical counterpart. In the table below I have given these mapped values assuming that the {{cssxref("writing-mode")}} in use is `horizontal-tb` β€” with a left to right direction. The inline direction therefore runs horizontally β€” left to right β€” and {{cssxref("margin-inline-start")}} would be equivalent to {{cssxref("margin-left")}}. If you were using a `horizontal-tb` writing mode with a right-to-left text direction then {{cssxref("margin-inline-start")}} would be the same as {{cssxref("margin-right")}}, and in a vertical writing mode it would be the same as using {{cssxref("margin-top")}}. | Logical property | Physical Property | | ---------------------------------------- | ----------------------------------------- | | {{cssxref("border-block-end")}} | {{cssxref("border-bottom")}} | | {{cssxref("border-block-end-color")}} | {{cssxref("border-bottom-color")}} | | {{cssxref("border-block-end-style")}} | {{cssxref("border-bottom-style")}} | | {{cssxref("border-block-end-width")}} | {{cssxref("border-bottom-width")}} | | {{cssxref("border-block-start")}} | {{cssxref("border-top")}} | | {{cssxref("border-block-start-color")}} | {{cssxref("border-top-color")}} | | {{cssxref("border-block-start-style")}} | {{cssxref("border-top-style")}} | | {{cssxref("border-block-start-width")}} | {{cssxref("border-top-width")}} | | {{cssxref("border-inline-end")}} | {{cssxref("border-right")}} | | {{cssxref("border-inline-end-color")}} | {{cssxref("border-right-color")}} | | {{cssxref("border-inline-end-style")}} | {{cssxref("border-right-style")}} | | {{cssxref("border-inline-end-width")}} | {{cssxref("border-right-width")}} | | {{cssxref("border-inline-start")}} | {{cssxref("border-left")}} | | {{cssxref("border-inline-start-color")}} | {{cssxref("border-left-color")}} | | {{cssxref("border-inline-start-style")}} | {{cssxref("border-left-style")}} | | {{cssxref("border-inline-start-width")}} | {{cssxref("border-left-width")}} | | {{cssxref("border-start-start-radius")}} | {{cssxref("border-top-left-radius")}} | | {{cssxref("border-end-start-radius")}} | {{cssxref("border-bottom-left-radius")}} | | {{cssxref("border-start-end-radius")}} | {{cssxref("border-top-right-radius")}} | | {{cssxref("border-end-end-radius")}} | {{cssxref("border-bottom-right-radius")}} | | {{cssxref("margin-block-end")}} | {{cssxref("margin-bottom")}} | | {{cssxref("margin-block-start")}} | {{cssxref("margin-top")}} | | {{cssxref("margin-inline-end")}} | {{cssxref("margin-right")}} | | {{cssxref("margin-inline-start")}} | {{cssxref("margin-left")}} | | {{cssxref("padding-block-end")}} | {{cssxref("padding-bottom")}} | | {{cssxref("padding-block-start")}} | {{cssxref("padding-top")}} | | {{cssxref("padding-inline-end")}} | {{cssxref("padding-right")}} | | {{cssxref("padding-inline-start")}} | {{cssxref("padding-left")}} | There are also some additional shorthands, made possible because we can target both block or both inline edges of the box simultaneously. These shorthands have no physical equivalent. | Property | Purpose | | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | | {{cssxref("border-block")}} | Sets {{cssxref("border-color")}}, {{cssxref("border-style")}}, and {{cssxref("border-width")}} for both block borders. | | {{cssxref("border-block-color")}} | Sets `border-color` for both block borders. | | {{cssxref("border-block-style")}} | Sets `border-style` for both block borders. | | {{cssxref("border-block-width")}} | Sets `border-width` for both block borders. | | {{cssxref("border-inline")}} | Sets `border-color`, `-style`, and `-width` for both inline borders. | | {{cssxref("border-inline-color")}} | Sets `border-color` for both inline borders. | | {{cssxref("border-inline-style")}} | Sets `border-style` for both inline borders. | | {{cssxref("border-inline-width")}} | Sets `border-width` for both inline borders. | | {{cssxref("margin-block")}} | Sets all the block {{cssxref("margin")}}s. | | {{cssxref("margin-inline")}} | Sets all the inline `margin`s. | | {{cssxref("padding-block")}} | Sets the block {{cssxref("padding")}}. | | {{cssxref("padding-inline")}} | Sets the inline `padding`. | ## Margin examples The mapped margin properties of {{cssxref("margin-inline-start")}}, {{cssxref("margin-inline-end")}}, {{cssxref("margin-block-start")}}, and {{cssxref("margin-inline-end")}} can be used instead of their physical counterparts. In the example below I have created two boxes and added different sized margins to each edge. I have added an extra container with a border to make the margin more obvious to see. One box uses physical properties and the other logical properties. Try changing the {{cssxref("direction")}} property to `rtl` to cause the boxes to display in a right-to-left direction, the margins on the first box will stay in the same place, while the margins on the inline dimension of the second box will switch. You can also try changing the `writing-mode` from `horizontal-tb` to `vertical-rl`. Again, notice how the margins stay in the same place for the first box, but switch around to follow the text direction in the second. {{EmbedGHLiveSample("css-examples/logical/margin-longhands.html", '100%', 700)}} ### Margin shorthands As we can now target both sides of a box β€” either both inline sides or both block sides β€” there are new shorthands available, {{cssxref("margin-inline")}} and {{cssxref("margin-block")}}, which accept two values. The first value will apply to the start of that dimension, the second to the end. If you only use one value it is applied to both. In a horizontal writing mode this CSS would apply a 5px margin to the top of the box and a 10px margin to the bottom. ```css .box { margin-block: 5px 10px; } ``` ## Padding examples The mapped padding properties of {{cssxref("padding-inline-start")}}, {{cssxref("padding-inline-end")}}, {{cssxref("padding-block-start")}}, and {{cssxref("padding-inline-end")}} can be used instead of their physical counterparts. In the example below I have two boxes, one of which is using physical padding properties and the other logical padding properties. With a `writing-mode` of `horizontal-tb`, both boxes should appear the same. Try changing the `direction` property to `rtl` to cause the boxes to display in a right-to-left direction. The padding on the first box will stay in the same place, whereas the padding on the inline dimension of the second box will switch. You can also try changing the `writing-mode` from `horizontal-tb` to `vertical-rl`. Again, notice how the padding stays in the same place for the first box, but switches around to follow the text direction in the second. {{EmbedGHLiveSample("css-examples/logical/padding-longhands.html", '100%', 700)}} ### Padding shorthands As with margin, there are two-value shorthands for padding β€” {{cssxref("padding-inline")}} and {{cssxref("padding-block")}} β€” which allow you to set the padding of the two inline, and two block dimensions, respectively. In a horizontal `writing-mode` this CSS would apply `5px` of padding to the top of the box and 10px of padding to the bottom: ```css .box { padding-block: 5px 10px; } ``` ## Border examples The border properties are the main reason that Logical Properties and Values seems to have so many properties, as we have the longhands for the color, width, and style of the border on each side of a box, along with the shorthand to set all three at once for each side. As with margin and padding we have a mapped version of each physical property. The demo below uses some longhands and three shorthand values. As with the other demos try changing the `direction` property to `rtl` to cause the boxes to display in a right-to-left direction, or changing the `writing-mode` from `horizontal-tb` to `vertical-rl`. {{EmbedGHLiveSample("css-examples/logical/border-longhands.html", '100%', 700)}} ### New border shorthands There are two-value shorthands to set the width, style, and color of the block or inline dimension, and shorthands to set all three values in the block or inline dimension. The below code, in a horizontal writing mode, would give you a 2px green solid border on the top and bottom of the box, and a 4px dotted purple border on the left and right. ```css .box { border-block: 2px solid green; border-inline-width: 4px; border-inline-style: dotted; border-inline-color: rebeccapurple; } ``` ### Flow relative border-radius properties The specification has flow-relative equivalents for the {{cssxref("border-radius")}} longhands. The below example, in a horizontal `writing-mode`, would set the top-right border radius to 1em, the bottom-right to 0, the bottom-left to 20px and the top-left to 40px. ```css .box { border-end-start-radius: 1em; border-end-end-radius: 0; border-start-end-radius: 20px; border-start-start-radius: 40px; } ``` ## Indicating logical values for the 4-value shorthand syntax The specification makes a suggestion for the four-value shorthands such as the `margin` property, however the final decision on how this should be indicated is as yet unresolved, and is discussed in [this issue](https://github.com/w3c/csswg-drafts/issues/1282). Using any four-value shorthand such as `margin`, `padding`, or `border` will currently use the physical versions, so if following the flow of the document is important, use the longhand properties for the time being.
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_-moz-first-node/index.md
--- title: ":-moz-first-node" slug: Web/CSS/:-moz-first-node page-type: css-pseudo-class status: - non-standard --- {{Non-standard_header}}{{CSSRef}} The **`:-moz-first-node`** [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 represents any element that is the first child node of some other element. It differs from {{Cssxref(":first-child")}} because it does not match a first-child element with (non-whitespace) text before it. > **Note:** Any whitespace at the start of an element is ignored for the determination of `:-moz-first-node`. ## Syntax ```css :-moz-first-node { /* ... */ } ``` ## Examples ### CSS ```css span:-moz-first-node { background-color: lime; } ``` ### HTML ```html <p> <span>This matches!</span> <span>This doesn't match.</span> </p> <p> Blahblah. <span>This doesn't match because it's preceded by text.</span> </p> ``` ### Result {{EmbedLiveSample("Examples")}} ## Specifications Not part of any standard. ## See also - {{cssxref(":-moz-last-node")}} - {{cssxref(":first-child")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/angle-percentage/index.md
--- title: <angle-percentage> slug: Web/CSS/angle-percentage page-type: css-type browser-compat: css.types.angle-percentage --- {{CSSRef}} The **`<angle-percentage>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) represents a value that can be either a {{Cssxref("angle")}} or a {{Cssxref("percentage")}}. Where an `<angle-percentage>` is specified as an allowable type, this means that the percentage resolves to an angle and therefore can be used in a {{Cssxref("calc", "calc()")}} expression. ## Syntax Refer to the documentation for {{Cssxref("angle")}} and {{Cssxref("percentage")}} for details of the individual syntaxes allowed by this type. ## Formal syntax {{csssyntax}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS data types](/en-US/docs/Web/CSS/CSS_Types) - [Using CSS gradients](/en-US/docs/Web/CSS/CSS_images/Using_CSS_gradients) - [`conic-gradient()`](/en-US/docs/Web/CSS/gradient/conic-gradient) and [`repeating-conic-gradient()`](/en-US/docs/Web/CSS/gradient/repeating-conic-gradient)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/animation-range-end/index.md
--- title: animation-range-end slug: Web/CSS/animation-range-end page-type: css-property status: - experimental browser-compat: css.properties.animation-range-end --- {{CSSRef}}{{SeeCompatTable}} The **`animation-range-end`** [CSS](/en-US/docs/Web/CSS) property is used to set the end of an animation's attachment range along its timeline, i.e. where along the timeline an animation will end. The `animation-range-end` and {{cssxref("animation-range-start")}} properties can also be set using the [`animation-range`](/en-US/docs/Web/CSS/animation-range) shorthand property. > **Note:** {{cssxref("animation-range-end")}} is included in the {{cssxref("animation")}} shorthand as a reset-only value. This means that including `animation` resets a previously-declared `animation-range-end` value to `normal`, but a specific value cannot be set via `animation`. When creating [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations), you need to declare `animation-range-end` after declaring any `animation` shorthand for it to take effect. ## Syntax ```css /* Keyword or length percentage value */ animation-range-end: normal; animation-range-end: 80%; animation-range-end: 700px; /* Named timeline range value */ animation-range-end: cover; animation-range-end: contain; animation-range-end: cover 80%; animation-range-end: contain 700px; ``` ### Values Allowed values for `animation-range-end` are `normal`, a {{cssxref("length-percentage")}}, a `<timeline-range-name>`, or a `<timeline-range-name>` with a `<length-percentage>` following it. See [`animation-range`](/en-US/docs/Web/CSS/animation-range) for a detailed description of the available values. Also check out the [View Timeline Ranges Visualizer](https://scroll-driven-animations.style/tools/view-timeline/ranges/), which shows exactly what the different values mean in an easy visual format. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Creating a named view progress timeline with range end A view progress timeline named `--subjectReveal` is defined using the `view-timeline` property on a subject element with a `class` of `animation`. This is then set as the timeline for the same element using `animation-timeline: --subjectReveal;`. The result is that the subject element animates as it moves upwards through the document as it is scrolled. An `animation-range-end` declaration is also set to make the animation end earlier than expected. #### HTML The HTML for the example is shown below. ```html <div class="content"> <h1>Content</h1> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Risus quis varius quam quisque id. Et ligula ullamcorper malesuada proin libero nunc consequat interdum varius. Elit ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at augue. </p> <p> Dolor sed viverra ipsum nunc aliquet. Sed sed risus pretium quam vulputate dignissim. Tortor aliquam nulla facilisi cras. A erat nam at lectus urna duis convallis convallis. Nibh ipsum consequat nisl vel pretium lectus. Sagittis aliquam malesuada bibendum arcu vitae elementum. Malesuada bibendum arcu vitae elementum curabitur vitae nunc sed velit. </p> <div class="subject animation"></div> <p> Adipiscing enim eu turpis egestas pretium aenean pharetra magna ac. Arcu cursus vitae congue mauris rhoncus aenean vel. Sit amet cursus sit amet dictum. Augue neque gravida in fermentum et. Gravida rutrum quisque non tellus orci ac auctor augue mauris. Risus quis varius quam quisque id diam vel quam elementum. Nibh praesent tristique magna sit amet purus gravida quis. Duis ultricies lacus sed turpis tincidunt id aliquet. In egestas erat imperdiet sed euismod nisi. Eget egestas purus viverra accumsan in nisl nisi scelerisque. Netus et malesuada fames ac. </p> </div> ``` #### CSS The `subject` element and its containing `content` element are styled minimally, and the text content is given some basic font settings: ```css .subject { width: 300px; height: 200px; margin: 0 auto; background-color: deeppink; } .content { width: 75%; max-width: 800px; margin: 0 auto; } p, h1 { font-family: Arial, Helvetica, sans-serif; } h1 { font-size: 3rem; } p { font-size: 1.5rem; line-height: 1.5; } ``` The `<div>` with the class of `subject` is also given a class of `animation` β€” this is where `view-timeline` is set to define a named view progress timeline. It is also given an `animation-timeline` name with the same value to declare that this will be the element animated as the view progress timeline is progressed. We also give it an `animation-range-end` declaration to make the animation end earlier than expected. Last, an animation is specified on the element that animates its opacity and scale, causing it to fade in and size up as it moves up the scroller. ```css .animation { view-timeline: --subjectReveal block; animation-timeline: --subjectReveal; animation-name: appear; animation-range-end: contain 50%; animation-fill-mode: both; animation-duration: 1ms; /* Firefox requires this to apply the animation */ } @keyframes appear { from { opacity: 0; transform: scaleX(0); } to { opacity: 1, transform: scaleX(1); } } ``` #### Result Scroll to see the subject element being animated. {{EmbedLiveSample("Creating a named view progress timeline with range end", "100%", "480px")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`animation-timeline`](/en-US/docs/Web/CSS/animation-timeline) - [`animation-range`](/en-US/docs/Web/CSS/animation-range), [`animation-range-start`](/en-US/docs/Web/CSS/animation-range-start) - [`scroll-timeline`](/en-US/docs/Web/CSS/scroll-timeline), [`scroll-timeline-axis`](/en-US/docs/Web/CSS/scroll-timeline-axis), [`scroll-timeline-name`](/en-US/docs/Web/CSS/scroll-timeline-name) - {{cssxref("timeline-scope")}} - [`view-timeline-inset`](/en-US/docs/Web/CSS/view-timeline-inset) - The JavaScript equivalent: The `rangeEnd` property available in {{domxref("Element.animate()")}} calls - [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/view-timeline-inset/index.md
--- title: view-timeline-inset slug: Web/CSS/view-timeline-inset page-type: css-property status: - experimental browser-compat: css.properties.view-timeline-inset --- {{CSSRef}}{{SeeCompatTable}} The **`view-timeline-inset`** [CSS](/en-US/docs/Web/CSS) property is used to specify one or two values representing an adjustment to the position of the scrollport (see {{glossary("Scroll container")}} for more details) in which the subject element of a _named view progress timeline_ animation is deemed to be visible. Put another way, this allows you to specify start and/or end inset (or outset) values that offset the position of the timeline. This can be combined with or used instead of {{cssxref("animation-range")}} and its longhand properties, which can be used to set the attachment range of an animation along its timeline. See [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations) for more details. ## Syntax ```css /* Single value */ view-timeline-inset: auto; view-timeline-inset: 200px; view-timeline-inset: 20%; /* Two values */ view-timeline-inset: 20% auto; view-timeline-inset: auto 200px; view-timeline-inset: 20% 200px; ``` ### Values Allowed values for `view-timeline-inset` are: - `auto` - : If set, the corresponding {{cssxref("scroll-padding")}} (or equivalent longhand value) for that edge of the scrollport is used. If this is not set (or set to `auto`), the value will usually be 0, although some user agents may use heuristics to determine a different default value if appropriate. - {{cssxref("length-percentage")}} - : Any valid `<length-percentage>` value is accepted as an inset/outset value. - If the value is positive, the position of the animation's start/end will be moved inside the scrollport by the specified length or percentage. - If the value is negative, the position of the animation's start/end will be moved outside the scrollport by the specified length or percentage, i.e. it will start animating before it appears in the scrollport, or finish animating after it leaves the scrollport. If two values are provided, the first value represents the start inset/outset in the relevant axis (where the animation begins) and the second value represents the end inset/outset (where the animation ends). If only one value is provided, the start and end inset/outset are both set to the same value. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Creating a named view progress timeline with inset A view progress timeline named `--subjectReveal` is defined using the `view-timeline` property on a subject element with a `class` of `animation`. This is then set as the timeline for the same element using `animation-timeline: --subjectReveal;`. The result is that the subject element animates as it moves upwards through the document as it is scrolled. A `view-timeline-inset` declaration is also set to make the animation begin later than expected, and finish earlier. #### HTML The HTML for the example is shown below. ```html <div class="content"> <h1>Content</h1> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Risus quis varius quam quisque id. Et ligula ullamcorper malesuada proin libero nunc consequat interdum varius. Elit ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at augue. </p> <p> Dolor sed viverra ipsum nunc aliquet. Sed sed risus pretium quam vulputate dignissim. Tortor aliquam nulla facilisi cras. A erat nam at lectus urna duis convallis convallis. Nibh ipsum consequat nisl vel pretium lectus. Sagittis aliquam malesuada bibendum arcu vitae elementum. Malesuada bibendum arcu vitae elementum curabitur vitae nunc sed velit. </p> <div class="subject animation"></div> <p> Adipiscing enim eu turpis egestas pretium aenean pharetra magna ac. Arcu cursus vitae congue mauris rhoncus aenean vel. Sit amet cursus sit amet dictum. Augue neque gravida in fermentum et. Gravida rutrum quisque non tellus orci ac auctor augue mauris. Risus quis varius quam quisque id diam vel quam elementum. Nibh praesent tristique magna sit amet purus gravida quis. Duis ultricies lacus sed turpis tincidunt id aliquet. In egestas erat imperdiet sed euismod nisi. Eget egestas purus viverra accumsan in nisl nisi scelerisque. Netus et malesuada fames ac. </p> </div> ``` #### CSS The `subject` element and its containing `content` element are styled minimally, and the text content is given some basic font settings: ```css .subject { width: 300px; height: 200px; margin: 0 auto; background-color: deeppink; } .content { width: 75%; max-width: 800px; margin: 0 auto; } p, h1 { font-family: Arial, Helvetica, sans-serif; } h1 { font-size: 3rem; } p { font-size: 1.5rem; line-height: 1.5; } ``` The `<div>` with the class of `subject` is also given a class of `animation` β€” this is where `view-timeline` is set to define a named view progress timeline. We also give it a `view-timeline-inset` declaration to make the animation begin later than expected, and finish earlier. It is also given an `animation-timeline` name with the same value to declare that this will be the element animated as the view progress timeline is progressed. Last, an animation is specified on the element that animates its opacity and scale, causing it to fade in and size up as it moves up the scroller. ```css .animation { view-timeline: --subjectReveal block; view-timeline-inset: 70% -100px; animation-timeline: --subjectReveal; animation-name: appear; animation-fill-mode: both; animation-duration: 1ms; /* Firefox requires this to apply the animation */ } @keyframes appear { from { opacity: 0; transform: scaleX(0); } to { opacity: 1, transform: scaleX(1); } } ``` #### Result Scroll to see the subject element being animated. {{EmbedLiveSample("Creating a named view progress timeline with inset", "100%", "480px")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`animation-timeline`](/en-US/docs/Web/CSS/animation-timeline) - {{cssxref("timeline-scope")}} - [`view-timeline`](/en-US/docs/Web/CSS/view-timeline), [`view-timeline-axis`](/en-US/docs/Web/CSS/view-timeline-axis), [`view-timeline-name`](/en-US/docs/Web/CSS/view-timeline-name) - [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_shapes/index.md
--- title: CSS shapes slug: Web/CSS/CSS_shapes page-type: css-module spec-urls: https://drafts.csswg.org/css-shapes/ --- {{CSSRef}} The **CSS shapes** module describes geometric shapes that can be in CSS. For the [Level 1 specification](https://drafts.csswg.org/css-shapes/), CSS shapes can be applied to floating elements. The specification defines a number of different ways to define a shape on a floated element, causing wrapping lines to wrap round the shape rather than following the rectangle of the element's box. ## Basic example The example below shows an image that has been floated left, and the `shape-outside` property applied with a value of `circle(50%)`. This creates a circle shape, and the content wrapping the float now wraps around that shape. This changes the length of the wrapping text's line boxes. {{EmbedGHLiveSample("css-examples/shapes/overview/circle.html", '100%', 720)}} ## Reference ### Properties - {{cssxref("shape-image-threshold")}} - {{cssxref("shape-margin")}} - {{cssxref("shape-outside")}} ### Data types - {{cssxref("&lt;basic-shape&gt;")}} ## Guides - [Overview of shapes](/en-US/docs/Web/CSS/CSS_shapes/Overview_of_shapes) - [Shapes from box values](/en-US/docs/Web/CSS/CSS_shapes/From_box_values) - [Basic shapes](/en-US/docs/Web/CSS/CSS_shapes/Basic_shapes) - [Shapes from images](/en-US/docs/Web/CSS/CSS_shapes/Shapes_from_images) ## Specifications {{Specifications}} ## See also - [CSS Shapes resources](https://codepen.io/KristopherVanSant/post/css-shapes-resources) - [CSS Shapes 101](https://alistapart.com/article/css-shapes-101/) - [Creating non-rectangular layouts with CSS Shapes](https://www.sarasoueidan.com/blog/css-shapes/) - [How to use CSS Shapes in your web design](https://webdesign.tutsplus.com/tutorials/how-to-use-css-shapes-in-your-web-design--cms-27498) - [How to get started with CSS Shapes](https://www.webdesignerdepot.com/2015/03/how-to-get-started-with-css-shapes/) - [What I learned in one weekend with CSS Shapes](https://medium.com/@MHarreither/what-i-learned-in-one-weekend-with-css-shapes-66ae9be69cc5) - [CSS vs. SVG: Shapes and arbitrarily-shaped UI components](https://blog.adobe.com/en/publish/2015/09/01/css-vs-svg-shapes-and-arbitrarily-shaped-ui-components) - [Edit shape paths in CSS β€” Firefox Developer Tools](https://firefox-source-docs.mozilla.org/devtools-user/page_inspector/how_to/edit_css_shapes/index.html)
0
data/mdn-content/files/en-us/web/css/css_shapes
data/mdn-content/files/en-us/web/css/css_shapes/from_box_values/index.md
--- title: Shapes from box values slug: Web/CSS/CSS_shapes/From_box_values page-type: guide --- {{CSSRef}} A straightforward way to create a shape is to use a value from the CSS Box Model. This article explains how to do this. The [box values](https://drafts.csswg.org/css-shapes-1/#shapes-from-box-values) allowable as a shape value are: - `content-box` - `padding-box` - `border-box` - `margin-box` The `border-radius` values are also supported, this means that you can have something in your page with a curved border, and your shape can follow the created shape. ## CSS box model The values listed above correspond to the various parts of the CSS Box Model. A box in CSS has content, padding, border, and margin. ![The Box Model consists of the margin, border, padding and content boxes.](box-model.png) By using Box Values for Shapes we can wrap our content around the edges defined by these values. In all of the examples below I am using an element which has padding, a border, and a margin defined in order that you can see the different ways in which content will flow. ### margin-box The `margin-box` is the shape defined by the outside margin edge and includes the corner radius of the shape, should {{cssxref("border-radius")}} have been used in defining the element. In the example below, we have a circular purple item which is a {{htmlelement("div")}} with a height, width, and background color. The `border-radius` property has been used to create a circle by setting `border-radius: 50%`. As the element has a margin, you can see that the content is flowing around the circular shape and the margin applied to it. {{EmbedGHLiveSample("css-examples/shapes/box/margin-box.html", '100%', 800)}} ### border-box The `border-box` value is the shape defined by the outside border edge. This shape follows all of the normal border radius shaping rules for the outside of the border. You still have a border, even if you have not used the CSS {{cssxref("border")}} property. In this case it will be the same as `padding-box`, the shape defined by the outside padding edge. In the example below you can see how the text now follows the line created by the border. Change the border size and the content follows it. {{EmbedGHLiveSample("css-examples/shapes/box/border-box.html", '100%', 800)}} ### padding-box The `padding-box` value defines the shape enclosed by the outside padding edge. This shape follows all of the normal border radius shaping rules for the inside of the border. If you have no padding then `padding-box` is the same as `content-box`. {{EmbedGHLiveSample("css-examples/shapes/box/padding-box.html", '100%', 800)}} ### content-box The `content-box` value defines the shape enclosed by the outside content edge. Each corner radius of this box is the larger of 0 or border-radius βˆ’ border-width βˆ’ padding. This Means that it is impossible to have a negative value here. {{EmbedGHLiveSample("css-examples/shapes/box/content-box.html", '100%', 800)}} ## When to use box values Using box values is a simple way to create shapes; however, this is by nature only going to work with very simple shapes that can be defined using the well-supported `border-radius` property. The examples shown above show one such use case. You can create a circular shape using border-radius and then curve text around it. You can create some interesting effects however with just this simple technique. In my final example of this section, I have floated two elements left and right, giving each a border-radius of 100% in the direction closest to the text. {{EmbedGHLiveSample("css-examples/shapes/box/bottom-margin-box.html", '100%', 800)}} For more complex shapes, you will need to use one of the [basic shapes](/en-US/docs/Web/CSS/CSS_shapes/Basic_shapes) as a value, or define your shape from an image as covered in other guides in this section.
0
data/mdn-content/files/en-us/web/css/css_shapes
data/mdn-content/files/en-us/web/css/css_shapes/basic_shapes/index.md
--- title: Basic shapes slug: Web/CSS/CSS_shapes/Basic_shapes page-type: guide --- {{CSSRef}} CSS Shapes can be defined using the {{cssxref("&lt;basic-shape&gt;")}} type, and in this guide I'll explain how each of the different values accepted by this type work. They range from simple circles to complex polygons. Before looking at shapes, it is worth understanding two pieces of information that go together to make these shapes possible: - The `<basic-shape>` type - The reference box ## The \<basic-shape> type The `<basic-shape>` type is used as the value for all of our basic shapes. This type uses Functional Notation: the type of shape is followed by parenthese, inside of which are additional values used to describe the shape. The arguments which are accepted vary depending on the shape that you are creating. We will cover these in the examples below. ## The reference box Understanding the reference box used by CSS Shapes is important when using basic shapes, as it defines each shape's coordinate system. You have already met the reference box in [the guide on creating shapes from Box Values](/en-US/docs/Web/CSS/CSS_shapes/From_box_values), which directly uses the reference box to create the shape. The Firefox Shapes Inspector helpfully shows the reference box in use when you inspect a shape. In the screenshot below I have created a circle, using `shape-outside: circle(50%)`. The floated element has 20 pixels of padding, border and margin applied, and the Shapes Inspector highlights these reference boxes. When using a basic shape, the reference box used by default is the margin-box. You can see in the screenshot that the shape is being defined with reference to that part of the Box Model. ![An imaged clipped into a circle floated left, with a paragraph of text. The left edge of the text is circular abutting the clipped shape on the outside of the margin with the margin following the shape clipping.](shapes-reference-box.png) You can add the various box values after your basic shape definition. Therefore the default behavior is as if you have defined. ```css .shape { shape-outside: circle(50%) margin-box; } ``` You can therefore change this in order that your shape uses the different parts of the box model, for example to use the border. ```css .shape { shape-outside: circle(50%) border-box; } ``` What is worth noting is that the `margin-box` will clip the shape, therefore shapes created in reference to other shapes which extend past the margin box will have the shape clipped to the margin box. We will see this in the following examples of basic shapes. For an excellent description of references boxes as they apply to CSS Shapes, see [Understanding Reference Boxes for CSS Shapes](http://razvancaliman.com/writing/css-shapes-reference-boxes/). ## inset() The `inset()` type defines a rectangle, which may not seem very useful as floating an item will give you a rectangular shape around it. However the `inset()` types enables the definition of offsets, thus pulling the content in over the shape. Therefore `inset()` takes four values for the top, right, bottom and left values plus a final value for `border-radius`. The below CSS creates a rectangular shape inset from the reference box of the floated element 20 pixels from the top and bottom and 10 pixels from the left and right, with a border-radius value of 10 pixels. ```css .shape { float: left; shape-outside: inset(20px 10px 20px 10px round 10px); } ``` Using the same rules as we use for the margin shorthand, you can set more than one offset at once. If there is only one value, it applies to all sides. If there are two values, the top and bottom offsets are set to the first value and the right and left offsets are set to the second. If there are three values, the top is set to the first value, the left and right are set to the second, and the bottom is set to the third. If there are four values, they apply to the top, right, bottom, and left, respectively. So, the above rules could also be described as: ```css .shape { float: left; shape-outside: inset(20px 10px round 10px); } ``` In the example below we have an `inset()` shape used to pull content over the floated element. Change the offset values to see how the shape changes. {{EmbedGHLiveSample("css-examples/shapes/basic-shape/inset.html", '100%', 800)}} You can also add the Box Value that you wish to use as a reference box. In the example below change the reference box from `margin-box` to `border-box`, `padding-box` or `content-box` to see how the reference box used as the starting point before offsets are calculated changes. {{EmbedGHLiveSample("css-examples/shapes/basic-shape/inset-box.html", '100%', 800)}} ## circle() The `circle()` value for `shape-outside` can accept two possible arguments. The first is the `shape-radius`. Both `circle()` and `ellipse()` values for `shape-outside` are specified as accepting this argument of `<shape-radius>`. This argument can be a length or percentage but can also be one of the keywords `closest-side` or `farthest-side`. The keyword **`closest-side`** uses the length from the center of the shape to the closest side of the reference box. For circles, this is the closest side in any dimension. For ellipses, this is the closest side in the radius dimension. The keyword **`farthest-side`** uses the length from the center of the shape to the farthest side of the reference box. For circles, this is the farthest side in any dimension. For ellipses, this is the farthest side in the radius dimension. The second argument is a `position`. If omitted this will be set to `center`. However you can use any valid position here to indicate the position of the center of the circle. Our circle therefore accepts one radius value, which may be a length, a percentage or the closest-side or farthest side keyword then optionally the keyword **at** followed by a position value. In the below example I have created a circle on an item with a width of 100 pixels, plus a margin of 20 pixels. This gives a total width for the reference box of 140 pixels. I have given a value of 50% for the shape-radius value which means that our radius is 70px. I have then set the position value to 30%. {{EmbedGHLiveSample("css-examples/shapes/basic-shape/circle.html", '100%', 800)}} In the live example you can play with increasing or decreasing the size of the circle by changing the size of the radius, moving the circle around with the position value, or setting a reference box as we did for `inset()`. As an additional example, if you use the keywords `top left` for position, you can make a quarter circle shape in the top left corner of the page. The example below uses generated content to create a quarter circle shape for text to flow around. {{EmbedGHLiveSample("css-examples/shapes/basic-shape/circle-generated.html", '100%', 700)}} ### The shape will be clipped by the margin box When describing Reference Boxes I explained that the margin-box will clip the shape. You can see this by moving the center of our circle towards the content by setting the position to 60%. The center of the circle is now nearer the content and the circle extends past the margin-box. This means that the extension becomes clipped and squared off. ```css img { float: left; shape-outside: circle(50% at 60%); } ``` ![The circle shape is clipped by the margin box](shapes-circle-clipped.png) ## ellipse() An ellipse is essentially a squashed circle and so `ellipse()` acts in a very similar way to `circle()` except that we have to specify two radii x and y in that order. These may then be followed by position values as with `circle()` to move the center of the ellipse around. In the example below we have an ellipse with an x radius of 40%, a y radius of 50% and the position being left. This means that the center of the ellipse is on the left edge of the box giving us a half ellipse shape to wrap our text around. You can change these values to see how the ellipse changes. {{EmbedGHLiveSample("css-examples/shapes/basic-shape/ellipse.html", '100%', 800)}} The keyword values of `closest-side` and `farthest-side` are useful to create a quick ellipse based on the size of the floated element reference box. {{EmbedGHLiveSample("css-examples/shapes/basic-shape/ellipse-keywords.html", '100%', 800)}} ## polygon() The final Basic Shape is the most complex and enables the creation of many side shapes by way of creating a `polygon()`. This shape accepts three or more pairs of values (a polygon must at least draw a triangle). These values are co-ordinates drawn with reference to the reference box. In the example below I have created a shape for text to follow using the `polygon()`, you can change any of the values to see how the shape is changed. {{EmbedGHLiveSample("css-examples/shapes/basic-shape/polygon.html", '100%', 800)}} You may well find the Firefox Shape Inspector very useful here to create your polygon shape. The screenshot below shows the shape highlighted in the tool. ![The polygon basic shape, highlighted with the Shapes Inspector.](shapes-polygon.png) Another useful resource is [Clippy](https://bennettfeely.com/clippy/) - a tool for creating shapes for `clip-path`, as the values for Basic Shapes are the same as those used for `clip-path`.
0
data/mdn-content/files/en-us/web/css/css_shapes
data/mdn-content/files/en-us/web/css/css_shapes/shapes_from_images/index.md
--- title: Shapes from images slug: Web/CSS/CSS_shapes/Shapes_from_images page-type: guide --- {{CSSRef}} In this guide, we will take a look at how we can create a shape from an image file with an alpha channel or even from a CSS Gradient. This is a very flexible way to create shapes. Rather than drawing a path with a complex polygon in CSS, you can create the shape in a graphics program and then use the path created by the pixels less opaque than a threshold value. ## Creating shapes from images To use an image for creating a shape, the image needs to have an Alpha Channel, an area that is not fully opaque. The {{cssxref("shape-image-threshold")}} property is used to set a threshold for this opacity. Pixels that are more opaque than this value will be used to calculate the area of the shape. In the example below, there is an image of a star with a solid red area and an area that is fully transparent. The path to the image file is used as the value for the {{cssxref("shape-outside")}} property. The content now wraps around the star shape. {{EmbedGHLiveSample("css-examples/shapes/image/simple-example.html", '100%', 800)}} You can use {{cssxref("shape-margin")}} to move the text away from the shape, giving a margin around the created shape and the text. {{EmbedGHLiveSample("css-examples/shapes/image/margin.html", '100%', 800)}} ## CORS compatibility Something that you will run into when creating shapes from an image is that the image you use must be [CORS compatible](/en-US/docs/Web/HTTP/CORS). An image hosted on the same domain as your site should work, however, if your images are hosted on a different domain such as on a CDN you should ensure that they are sending the correct headers to enable them to be used for Shapes. Due to this requirement for CORS-compatible images, if you are previewing your file locally without using a local web server, your shape will not work. ### Is it a CORS issue? DevTools can help you to identify CORS errors. In Chrome the Console will alert you to CORS problems. In Firefox if you inspect the property you will be alerted to the fact that the image could not be loaded. This should alert you to the fact that your image cannot be used as the source of a shape due to CORS. ## Setting a threshold The {{cssxref("shape-image-threshold")}} property enables the creation of shapes from areas which are not fully transparent. If the value of `shape-image-threshold` is `0.0` (which is the initial value) then the area must be fully transparent. If the value is `1.0` then it is fully opaque. Values in between mean that you can set a semi-transparent area as the defining area. In the example below I am using a similar image to the initial example, however, in this image the background of the star is not fully transparent, it has a 20% opacity as created in my graphics program. If I set `shape-image-threshold` to `0.3` then I see the shape, if I set it to something smaller than `0.2` I do not get the shape. {{EmbedGHLiveSample("css-examples/shapes/image/threshold.html", '100%', 800)}} ## Using images with generated content In the above example, I have both used the image as the value of {{cssxref("shape-outside")}} and also added it to the page. Many demos do this as it helps to show the shape we are following, however, the `shape-outside` property is not related to the image that is displayed on the page and so you do not need to display an image to use an image to create a shape. You do need something to float, but that could be some generated content as in the below example. I am floating generated content and using a larger star image to shape my content without displaying any image on the page. {{EmbedGHLiveSample("css-examples/shapes/image/generated-content.html", '100%', 800)}} ## Creating shapes using a gradient Because a [CSS gradient](/en-US/docs/Web/CSS/CSS_images/Using_CSS_gradients) is treated as an image, you can use a gradient to generate a shape by having transparent or semi-transparent areas as part of the gradient. The next example uses generated content. The content has been floated, giving it a background image of a linear gradient. I am using that same value as the value of {{cssxref("shape-outside")}}. The linear gradient goes from purple to transparent. By changing the value of {{cssxref("shape-image-threshold")}}, you can decide how transparent the pixels need to be that create the shape. You can play with that value in the example below to see how the diagonal line will move across the shape depending on that value. You could also try removing the background image completely, thus using the gradient purely to create the shape and not displaying it on the page at all. {{EmbedGHLiveSample("css-examples/shapes/image/gradient.html", '100%', 800)}} The next example uses a radial gradient with an ellipse, once again using a transparent part of the gradient to create the shape. {{EmbedGHLiveSample("css-examples/shapes/image/radial-gradient.html", '100%', 800)}} You can experiment directly in these live examples to see how changing the gradient will change the path of your shape.
0
data/mdn-content/files/en-us/web/css/css_shapes
data/mdn-content/files/en-us/web/css/css_shapes/overview_of_shapes/index.md
--- title: Overview of shapes slug: Web/CSS/CSS_shapes/Overview_of_shapes page-type: guide --- {{CSSRef}} The [CSS Shapes Level 1 Specification](https://www.w3.org/TR/css-shapes/) describes geometric shapes in CSS. They are, in Level 1 of the specification, designed to be applied to floated items. This article provides an overview of what you can do with shapes. You could for example float an item left, which would cause the text to wrap round the right and bottom of the item in a rectangular fashion. If you then apply a circle shape, the text would then wrap round the line of the circle. There are a number of ways to create these Shapes and in these guides we will find out how CSS Shapes work, and consider some ways you might like to use them. ## What does the specification define? The specification defines three new properties: - {{cssxref("shape-outside")}} β€” allows definition of basic shapes - {{cssxref("shape-image-threshold")}} β€” Sets an opacity threshold value. If an image is being used to define the shape, only the parts of the image that are the same opacity or greater than the threshold value are used in the shape. Any other parts are ignored. - {{cssxref("shape-margin")}} β€” sets a margin around the defined shape ## Defining basic shapes The `shape-outside` property allows us to a define a shape. It takes a variety of values, all of which define different shapes, specified in the {{cssxref("&lt;basic-shape&gt;")}} datatype. We can start by looking at a very simple case. In the following example I have an image floated left. I have then applied the `shape-outside` property to it with a value of `circle(50%)`. The result is that the content now curves around the circular shape rather than following the rectangle created by the box of the image. {{EmbedGHLiveSample("css-examples/shapes/overview/circle.html", '100%', 720)}} As in this level of the specification an element has to be floated in order to apply `<basic-shape>` to it; this has the side-effect of creating a simple fallback for many cases. If you do not have Shapes support in the browser, the user will see content flowing around the sides of a rectangular box as before. If they do have Shapes support then the visual display is enhanced. ### Basic shapes The value `circle(50%)` is an example of a basic shape. The specification defines four `<basic-shape>` values, which are: - `inset()` - `circle()` - `ellipse()` - `polygon()` Using the value `inset()` wraps text around a rectangular shape however you are able to add offset values, thus pulling the line boxes of any wrapping content closer to the object than would otherwise happen. We have already seen how `circle()` creates a circular shape. An `ellipse()` is essentially a squashed circle. If none of these simple shapes do the trick you can create a `polygon()` and make the shape as complex as you want. In our [Guide to Basic Shapes](/en-US/docs/Web/CSS/CSS_shapes/Basic_shapes) we explore each of the possible Basic Shapes and how to create them. ### Shapes from the box value Shapes can also be created around the box value. Therefore, you could create your shape on: - `border-box` - `padding-box` - `content-box` - `margin-box` In the example below, you can change the value `border-box` to any of the other allowed values to see how the shape moves closer or further away from the box. {{EmbedGHLiveSample("css-examples/shapes/overview/box.html", '100%', 810)}} To explore the box values in more detail, see our guide covering [Shapes from box values](/en-US/docs/Web/CSS/CSS_shapes/From_box_values). ### Shapes from images An interesting way to generate your path is to use an image with an alpha channel β€” the text will then wrap around the non-transparent parts of the image. This allows the overlay of wrapped content around an image, or the use of an image which is never displayed on the page purely as a method of creating a complex shape without needing to carefully map a polygon. Note that images used in this way must be [CORS compatible](/en-US/docs/Web/HTTP/CORS), otherwise `shape-outside` will act as if `none` had been given as the value, and you will get no shape. In this next example, we have an image with a fully transparent area, and we are using an image as the URL value for `shape-outside`. The shape is created around the opaque area β€” the image of the balloon. {{EmbedGHLiveSample("css-examples/shapes/overview/image.html", '100%', 800)}} #### `shape-image-threshold` The `shape-image-threshold` property is used to set the threshold of image transparency used to define the area of the image used for the shape. If the value of `shape-image-threshold` is `0.0` (which is the initial value) then the area must be fully transparent. If the value is `1.0` then it is fully opaque. Values in between mean that you can set a semi-transparent area as the defining area of the shape. You can see the threshold in action if we use a gradient as the image on which to define our shape. In the example below, if you change the threshold the path that the shape takes changes based on the level of opacity you have selected. {{EmbedGHLiveSample("css-examples/shapes/overview/threshold.html", '100%', 820)}} We take a deeper look at creating shapes from images in the [Shapes from Images](/en-US/docs/Web/CSS/CSS_shapes/Shapes_from_images) guide. ## The `shape-margin` property The {{cssxref("shape-margin")}} property adds a margin to `shape-outside`. This will further shorten the line boxes of any content wrapping the shape, pushing it away from the shape itself. In the example below we have added a `shape-margin` to a basic shape. Change the margin to push the text further away from the path the shape would take by default. {{EmbedGHLiveSample("css-examples/shapes/overview/shape-margin.html", '100%', 800)}} ## Using Generated Content as the floated item In the examples above, we have used images or a visible element to define the shape, meaning that you can see the shape on the page. Instead, you might want to cause some text to flow along a non-rectangular invisible line. You can do this with Shapes, however you will still need a floated item, which you can then make invisible. That could be a redundant element inserted into the document, an empty {{htmlelement("div")}} or {{htmlelement("span")}} perhaps, but our preference is to use generated content. This means we can keep things used for styling inside the CSS. In this next example, we use generated content to insert an element with height and width of 150px. We can then use Basic Shapes, Box Values or even the Alpha Channel of an image to create a shape for the text to wrap around. {{EmbedGHLiveSample("css-examples/shapes/overview/generated-content.html", '100%', 850)}} ## Relationship to `clip-path` The Basic Shapes and Box values used to create Shapes are the same as those used as values for {{cssxref("clip-path")}}. Therefore if you want to create a shape using an image, and also clip away part of that image, you can use the same values. The image below is a square image with a blue background. We have defined a shape using `shape-outside: ellipse(40% 50%);` and also used `clip-path: ellipse(40% 50%);` to clip away the same area that we have used to define the shape. {{EmbedGHLiveSample("css-examples/shapes/overview/clip-path.html", '100%', 800)}} ## Developer Tools for Shapes Along with CSS Shapes support in the browser, Firefox are shipping a [Shape Path Editor](https://firefox-source-docs.mozilla.org/devtools-user/page_inspector/how_to/edit_css_shapes/index.html) in the Firefox DevTools. This tool means that you can inspect any shapes on your page, and even change the values in the live page. If your polygon isn't quite right you can use the Shapes Editor to tweak it, then copy the new value back into your CSS. The Shape Path Editor will be enabled by default in Firefox 60 for shapes generated via `clip-path`. You can also use it to edit shapes generated via `shape-outside`, but only when you enable it via the `layout.css.shape-outside.enabled` pref. ## Future CSS Shapes Features The initial Shapes specification included a property `shape-inside` for creating shapes inside an element. This property, along with the possibility of creating shapes on non-floated elements, has been moved to [level 2](https://drafts.csswg.org/css-shapes-2/) of the specification. As the `shape-inside` property was initially in Level 1 of the specification, you may find tutorials on the web detailing both properties.
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-top/index.md
--- title: border-top slug: Web/CSS/border-top page-type: css-shorthand-property browser-compat: css.properties.border-top --- {{CSSRef}} The **`border-top`** [shorthand](/en-US/docs/Web/CSS/Shorthand_properties) [CSS](/en-US/docs/Web/CSS) property sets all the properties of an element's top [border](/en-US/docs/Web/CSS/border). {{EmbedInteractiveExample("pages/css/border-top.html")}} As with all shorthand properties, `border-top` always sets the values of all of the properties that it can set, even if they are not specified. It sets those that are not specified to their default values. Consider the following code: ```css border-top-style: dotted; border-top: thick green; ``` It is actually the same as this one: ```css border-top-style: dotted; border-top: none thick green; ``` The value of {{cssxref("border-top-style")}} given before `border-top` is ignored. Since the default value of {{cssxref("border-top-style")}} is `none`, not specifying the `border-style` part results in no border. ## Constituent properties This property is a shorthand for the following CSS properties: - [`border-top-color`](/en-US/docs/Web/CSS/border-top-color) - [`border-top-style`](/en-US/docs/Web/CSS/border-top-style) - [`border-top-width`](/en-US/docs/Web/CSS/border-top-width) ## Syntax ```css border-top: 1px; border-top: 2px dotted; border-top: medium dashed green; /* Global values */ border-top: inherit; border-top: initial; border-top: revert; border-top: revert-layer; border-top: unset; ``` The three values of the shorthand property can be specified in any order, and one or two of them may be omitted. ### Values - `<br-width>` - : See {{cssxref("border-top-width")}}. - `<br-style>` - : See {{cssxref("border-top-style")}}. - {{cssxref("&lt;color&gt;")}} - : See {{cssxref("border-top-color")}}. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Applying a top border #### HTML ```html <div>This box has a border on the top side.</div> ``` #### CSS ```css div { border-top: 4px dashed blue; background-color: gold; height: 100px; width: 100px; font-weight: bold; text-align: center; } ``` #### Results {{EmbedLiveSample('Applying_a_top_border')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`border`](/en-US/docs/Web/CSS/border) - [`border-block`](/en-US/docs/Web/CSS/border-block) - [`outline`](/en-US/docs/Web/CSS/outline)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_not/index.md
--- title: ":not()" slug: Web/CSS/:not page-type: css-pseudo-class browser-compat: css.selectors.not --- {{CSSRef}} The **`:not()`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents elements that do not match a list of selectors. Since it prevents specific items from being selected, it is known as the _negation pseudo-class_. {{EmbedInteractiveExample("pages/tabbed/pseudo-class-not.html", "tabbed-shorter")}} The `:not()` pseudo-class has a number of [quirks, tricks, and unexpected results](#description) that you should be aware of before using it. ## Syntax The `:not()` pseudo-class requires a comma-separated list of one or more selectors as its argument. The list must not contain another negation selector or a [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements). ```css-nolint :not(<complex-selector-list>) { /* ... */ } ``` ## Description There are several unusual effects and outcomes when using `:not()` that you should keep in mind when using it: - Useless selectors can be written using this pseudo-class. For example, `:not(*)` matches any element which is not an element, which is obviously nonsense, so the accompanying rule will never be applied. - This pseudo-class can increase the [specificity](/en-US/docs/Web/CSS/Specificity) of a rule. For example, `#foo:not(#bar)` will match the same element as the simpler `#foo`, but has the higher specificity of two `id` selectors. - The specificity of the `:not()` pseudo-class is replaced by the specificity of the most specific selector in its comma-separated argument of selectors; providing the same specificity as if it had been written [`:not(:is(argument))`](/en-US/docs/Web/CSS/:is). - `:not(.foo)` will match anything that isn't `.foo`, _including {{HTMLElement("html")}} and {{HTMLElement("body")}}._ - This selector will match everything that is "not an X". This may be surprising when used with [descendant combinators](/en-US/docs/Web/CSS/Descendant_combinator), since there are multiple paths to select a target element. For instance, `body :not(table) a` will still apply to links inside a {{HTMLElement("table")}}, since {{HTMLElement("tr")}}, {{HTMLElement("tbody")}}, {{HTMLElement("th")}}, {{HTMLElement("td")}}, {{HTMLElement("caption")}}, etc. can all match the `:not(table)` part of the selector. - You can negate several selectors at the same time. Example: `:not(.foo, .bar)` is equivalent to `:not(.foo):not(.bar)`. - If any selector passed to the `:not()` pseudo-class is invalid or not supported by the browser, the whole rule will be invalidated. The effective way to overcome this behavior is to use [`:is()`](/en-US/docs/Web/CSS/:is) pseudo-class, which accepts a forgiving selector list. For example `:not(.foo, :invalid-pseudo-class)` will invalidate a whole rule, but `:not(:is(.foo, :invalid-pseudo-class))` will match any (_including {{HTMLElement("html")}} and {{HTMLElement("body")}}_) element that isn't `.foo`. ## Examples ### Using :not() with valid selectors This example shows some simple cases of using `:not()`. #### HTML ```html <p>I am a paragraph.</p> <p class="fancy">I am so very fancy!</p> <div>I am NOT a paragraph.</div> <h2> <span class="foo">foo inside h2</span> <span class="bar">bar inside h2</span> </h2> ``` #### CSS ```css .fancy { text-shadow: 2px 2px 3px gold; } /* <p> elements that don't have a class `.fancy` */ p:not(.fancy) { color: green; } /* Elements that are not <p> elements */ body :not(p) { text-decoration: underline; } /* Elements that are not <div>s or `.fancy` */ body :not(div):not(.fancy) { font-weight: bold; } /* Elements that are not <div>s or `.fancy` */ body :not(div, .fancy) { text-decoration: overline underline; } /* Elements inside an <h2> that aren't a <span> with a class of `.foo` */ h2 :not(span.foo) { color: red; } ``` #### Result {{EmbedLiveSample('Using_not_with_valid_selectors', '100%', 320)}} ### Using :not() with invalid selectors This example shows the use of `:not()` with invalid selectors and how to prevent invalidation. #### HTML ```html <p class="foo">I am a paragraph with .foo</p> <p class="bar">I am a paragraph with .bar</p> <div>I am a div without a class</div> <div class="foo">I am a div with .foo</div> <div class="bar">I am a div with .bar</div> <div class="foo bar">I am a div with .foo and .bar</div> ``` #### CSS ```css /* Invalid rule, does nothing */ p:not(.foo, :invalid-pseudo-class) { color: red; font-style: italic; } /* Select all <p> elements without the `foo` class */ p:not(:is(.foo, :invalid-pseudo-class)) { color: green; border-top: dotted thin currentcolor; } /* Select all <div> elements without the `foo` or the `bar` class */ div:not(.foo, .bar) { color: red; font-style: italic; } /* Select all <div> elements without the `foo` or the `bar` class */ div:not(:is(.foo, .bar)) { border-bottom: dotted thin currentcolor; } ``` #### Result {{EmbedLiveSample('Using_not_with_invalid_selectors', '100%', 320)}} The `p:not(.foo, :invalid-pseudo-class)` rule is invalid because it contains an invalid selector. The `:is()` pseudo-class accepts a forgiving selector list, so the `:is(.foo, :invalid-pseudo-class)` rule is valid and equivalent to `:is(.foo)`. Thus, the `p:not(:is(.foo, :invalid-pseudo-class))` rule is valid and equivalent to `p:not(.foo)`. If `:invalid-pseudo-class` was a valid selector, the first two rules above would still be equivalent (the last two rules showcase that). The use of `:is()` makes the rule more robust. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes) - [Pseudo-classes and pseudo-elements](/en-US/docs/Learn/CSS/Building_blocks/Selectors/Pseudo-classes_and_pseudo-elements) - Other functional CSS pseudo-classes: - {{cssxref(":has", ":has()")}} - {{cssxref(":is", ":is()")}} - {{cssxref(":where", ":where()")}} - [How :not() chains multiple selectors](/en-US/blog/css-not-pseudo-multiple-selectors/) on MDN blog (2023)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/min-content/index.md
--- title: min-content slug: Web/CSS/min-content page-type: css-keyword browser-compat: css.properties.width.min-content --- {{CSSRef}} The `min-content` sizing keyword represents the intrinsic minimum width of the content. For text content this means that the content will take all soft-wrapping opportunities, becoming as small as the longest word. ## Syntax ```css /* Used as a length */ width: min-content; inline-size: min-content; height: min-content; block-size: min-content; /* used in grid tracks */ grid-template-columns: 200px 1fr min-content; ``` ## Examples ### Using min-content for box sizing #### HTML ```html <div class="item">Item</div> <div class="item">Item with more text in it.</div> ``` #### CSS ```css .item { width: min-content; background-color: #8ca0ff; padding: 5px; margin-bottom: 1em; } ``` #### Result {{EmbedLiveSample("Using_min-content_for_box_sizing", "100%", 200)}} ### Sizing grid columns with min-content #### HTML ```html <div id="container"> <div>Item</div> <div>Item with more text in it.</div> <div>Flexible item</div> </div> ``` #### CSS ```css #container { display: grid; grid-template-columns: min-content min-content 1fr; grid-gap: 5px; box-sizing: border-box; height: 200px; width: 100%; background-color: #8cffa0; padding: 10px; } #container > div { background-color: #8ca0ff; padding: 5px; } ``` #### Result {{EmbedLiveSample("Sizing_grid_columns_with_min-content", "100%", 200)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Related sizing keywords: {{cssxref("max-content")}}, {{cssxref("fit-content")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/clip-path/index.md
--- title: clip-path slug: Web/CSS/clip-path page-type: css-property browser-compat: css.properties.clip-path --- {{CSSRef}} The **`clip-path`** [CSS](/en-US/docs/Web/CSS) property creates a clipping region that sets what part of an element should be shown. Parts that are inside the region are shown, while those outside are hidden. {{EmbedInteractiveExample("pages/css/clip-path.html")}} ## Syntax ```css /* Keyword values */ clip-path: none; /* <clip-source> values */ clip-path: url(resources.svg#c1); /* <geometry-box> values */ clip-path: margin-box; clip-path: border-box; clip-path: padding-box; clip-path: content-box; clip-path: fill-box; clip-path: stroke-box; clip-path: view-box; /* <basic-shape> values */ clip-path: inset(100px 50px); clip-path: circle(50px at 0 100px); clip-path: ellipse(50px 60px at 0 10% 20%); clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); clip-path: path( "M0.5,1 C0.5,1,0,0.7,0,0.3 A0.25,0.25,1,1,1,0.5,0.3 A0.25,0.25,1,1,1,1,0.3 C1,0.7,0.5,1,0.5,1 Z" ); clip-path: rect(5px 5px 160px 145px round 20%); clip-path: xywh(0 5px 100% 75% round 15% 0); /* Box and shape values combined */ clip-path: padding-box circle(50px at 0 100px); /* Global values */ clip-path: inherit; clip-path: initial; clip-path: revert; clip-path: revert-layer; clip-path: unset; ``` The `clip-path` property is specified as one or a combination of the values listed below. ### Values - `<clip-source>` - : A {{cssxref("url", "url()")}} referencing an [SVG](/en-US/docs/Web/SVG) {{SVGElement("clipPath")}} element. - {{cssxref("&lt;basic-shape&gt;")}} - : A shape whose size and position is defined by the `<geometry-box>` value. If no geometry box is specified, the `border-box` will be used as the reference box. One of: - {{cssxref("basic-shape/inset","inset()")}} - : Defines an inset rectangle. - {{cssxref("basic-shape/circle","circle()")}} - : Defines a circle using a radius and a position. - {{cssxref("basic-shape/ellipse","ellipse()")}} - : Defines an ellipse using two radii and a position. - {{cssxref("basic-shape/polygon","polygon()")}} - : Defines a polygon using an SVG filling rule and a set of vertices. - {{cssxref("path","path()")}} - : Defines a shape using an optional SVG filling rule and an SVG path definition. - {{cssxref("basic-shape/rect","rect()")}} - : Defines a rectangle using the specified distances from the edges of the reference box. - {{cssxref("basic-shape/xywh","xywh()")}} - : Defines a rectangle using the specified distances from the top and left edges of the reference box and the specified width and height of the rectangle. - `<geometry-box>` - : If specified in combination with a `<basic-shape>`, this value defines the reference box for the basic shape. If specified by itself, it causes the edges of the specified box, including any corner shaping (such as a {{cssxref("border-radius")}}), to be the clipping path. The geometry box can be one of the following values: - `margin-box` - : Uses the [margin box](/en-US/docs/Web/CSS/CSS_shapes/From_box_values#margin-box) as the reference box. - `border-box` - : Uses the [border box](/en-US/docs/Web/CSS/CSS_shapes/From_box_values#border-box) as the reference box. - `padding-box` - : Uses the [padding box](/en-US/docs/Web/CSS/CSS_shapes/From_box_values#padding-box) as the reference box. - `content-box` - : Uses the [content box](/en-US/docs/Web/CSS/CSS_shapes/From_box_values#content-box) as the reference box. - `fill-box` - : Uses the object bounding box as the reference box. - `stroke-box` - : Uses the stroke bounding box as the reference box. - `view-box` - : Uses the nearest SVG viewport as the reference box. If a {{SVGAttr("viewBox")}} attribute is specified for the element creating the SVG viewport, the reference box is positioned at the origin of the coordinate system established by the `viewBox` attribute and the dimension of the size of the reference box is set to the width and height values of the `viewBox` attribute. - `none` - : No clipping path is created. > **Note:** A computed value other than **`none`** results in the creation of a new [stacking context](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context) the same way that CSS {{cssxref("opacity")}} does for values other than `1`. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Comparison of HTML and SVG ```html hidden <svg class="defs"> <defs> <clipPath id="myPath" clipPathUnits="objectBoundingBox"> <path d="M0.5,1 C0.5,1,0,0.7,0,0.3 A0.25,0.25,1,1,1,0.5,0.3 A0.25,0.25,1,1,1,1,0.3 C1,0.7,0.5,1,0.5,1 Z" /> </clipPath> </defs> </svg> <div class="grid"> <div class="col"> <div class="note">clip-path: none</div> <div class="row"> <div class="cell"> <span>HTML</span> <div class="container"> <p class="none">I LOVE<br /><em>clipping</em></p> </div> </div> <div class="cell"> <span>SVG</span> <div class="container view-box"> <svg viewBox="0 0 192 192"> <g class="none"> <rect x="24" y="24" width="144" height="144" /> <text x="96" y="91">I LOVE</text> <text x="96" y="109" class="em">clipping</text> </g> </svg> </div> </div> </div> <div class="note"> clip-path: url(#myPath)<br /><br /> Assuming the following clipPath definition: <pre> &lt;svg&gt; &lt;clipPath id="myPath" clipPathUnits="objectBoundingBox"&gt; &lt;path d="M0.5,1 C 0.5,1,0,0.7,0,0.3 A 0.25,0.25,1,1,1,0.5,0.3 A 0.25,0.25,1,1,1,1,0.3 C 1,0.7,0.5,1,0.5,1 Z" /&gt; &lt;/clipPath&gt; &lt;/svg&gt;</pre > </div> <div class="row"> <div class="cell"> <span>HTML</span> <div class="container"> <p class="svg">I LOVE<br /><em>clipping</em></p> </div> </div> <div class="cell"> <span>SVG</span> <div class="container view-box"> <svg viewBox="0 0 192 192"> <g class="svg"> <rect x="24" y="24" width="144" height="144" /> <text x="96" y="91">I LOVE</text> <text x="96" y="109" class="em">clipping</text> </g> </svg> </div> </div> </div> <div class="note"> clip-path: path('M15,45 A30,30,0,0,1,75,45 A30,30,0,0,1,135,45 Q135,90,75,130 Q15,90,15,45 Z') </div> <div class="row"> <div class="cell"> <span>HTML</span> <div class="container"> <p class="svg2">I LOVE<br /><em>clipping</em></p> </div> </div> <div class="cell"> <span>SVG</span> <div class="container view-box"> <svg viewBox="0 0 192 192"> <g class="svg2"> <rect x="24" y="24" width="144" height="144" /> <text x="96" y="91">I LOVE</text> <text x="96" y="109" class="em">clipping</text> </g> </svg> </div> </div> </div> <div class="note">clip-path: circle(25%)</div> <div class="row"> <div class="cell"> <span>HTML</span> <div class="container"> <p class="shape1">I LOVE<br /><em>clipping</em></p> </div> </div> <div class="cell"> <span>SVG</span> <div class="container view-box"> <svg viewBox="0 0 192 192"> <g class="shape1"> <rect x="24" y="24" width="144" height="144" /> <text x="96" y="91">I LOVE</text> <text x="96" y="109" class="em">clipping</text> </g> </svg> </div> </div> </div> <div class="note">clip-path: circle(25% at 25% 25%)</div> <div class="row"> <div class="cell"> <span>HTML</span> <div class="container"> <p class="shape2">I LOVE<br /><em>clipping</em></p> </div> </div> <div class="cell"> <span>SVG</span> <div class="container view-box"> <svg viewBox="0 0 192 192"> <g class="shape2"> <rect x="24" y="24" width="144" height="144" /> <text x="96" y="91">I LOVE</text> <text x="96" y="109" class="em">clipping</text> </g> </svg> </div> </div> </div> <div class="note">clip-path: fill-box circle(25% at 25% 25%)</div> <div class="row"> <div class="cell"> <span>HTML</span> <div class="container"> <p class="shape3">I LOVE<br /><em>clipping</em></p> </div> </div> <div class="cell"> <span>SVG</span> <div class="container view-box"> <svg viewBox="0 0 192 192"> <g class="shape3"> <rect x="24" y="24" width="144" height="144" /> <text x="96" y="91">I LOVE</text> <text x="96" y="109" class="em">clipping</text> </g> </svg> </div> </div> </div> <div class="note">clip-path: stroke-box circle(25% at 25% 25%)</div> <div class="row"> <div class="cell"> <span>HTML</span> <div class="container"> <p class="shape4">I LOVE<br /><em>clipping</em></p> </div> </div> <div class="cell"> <span>SVG</span> <div class="container view-box"> <svg viewBox="0 0 192 192"> <g class="shape4"> <rect x="24" y="24" width="144" height="144" /> <text x="96" y="91">I LOVE</text> <text x="96" y="109" class="em">clipping</text> </g> </svg> </div> </div> </div> <div class="note">clip-path: view-box circle(25% at 25% 25%)</div> <div class="row"> <div class="cell"> <span>HTML</span> <div class="container"> <p class="shape5">I LOVE<br /><em>clipping</em></p> </div> </div> <div class="cell"> <span>SVG</span> <div class="container view-box"> <svg viewBox="0 0 192 192"> <g class="shape5"> <rect x="24" y="24" width="144" height="144" /> <text x="96" y="91">I LOVE</text> <text x="96" y="109" class="em">clipping</text> </g> </svg> </div> </div> </div> <div class="note">clip-path: margin-box circle(25% at 25% 25%)</div> <div class="row"> <div class="cell"> <span>HTML</span> <div class="container"> <p class="shape6">I LOVE<br /><em>clipping</em></p> </div> </div> <div class="cell"> <span>SVG</span> <div class="container view-box"> <svg viewBox="0 0 192 192"> <g class="shape6"> <rect x="24" y="24" width="144" height="144" /> <text x="96" y="91">I LOVE</text> <text x="96" y="109" class="em">clipping</text> </g> </svg> </div> </div> </div> <div class="note">clip-path: border-box circle(25% at 25% 25%)</div> <div class="row"> <div class="cell"> <span>HTML</span> <div class="container"> <p class="shape7">I LOVE<br /><em>clipping</em></p> </div> </div> <div class="cell"> <span>SVG</span> <div class="container view-box"> <svg viewBox="0 0 192 192"> <g class="shape7"> <rect x="24" y="24" width="144" height="144" /> <text x="96" y="91">I LOVE</text> <text x="96" y="109" class="em">clipping</text> </g> </svg> </div> </div> </div> <div class="note">clip-path: padding-box circle(25% at 25% 25%)</div> <div class="row"> <div class="cell"> <span>HTML</span> <div class="container"> <p class="shape8">I LOVE<br /><em>clipping</em></p> </div> </div> <div class="cell"> <span>SVG</span> <div class="container view-box"> <svg viewBox="0 0 192 192"> <g class="shape8"> <rect x="24" y="24" width="144" height="144" /> <text x="96" y="91">I LOVE</text> <text x="96" y="109" class="em">clipping</text> </g> </svg> </div> </div> </div> <div class="note">clip-path: content-box circle(25% at 25% 25%)</div> <div class="row"> <div class="cell"> <span>HTML</span> <div class="container"> <p class="shape9">I LOVE<br /><em>clipping</em></p> </div> </div> <div class="cell"> <span>SVG</span> <div class="container view-box"> <svg viewBox="0 0 192 192"> <g class="shape9"> <rect x="24" y="24" width="144" height="144" /> <text x="96" y="91">I LOVE</text> <text x="96" y="109" class="em">clipping</text> </g> </svg> </div> </div> </div> </div> </div> ``` ```css html, body { height: 100%; box-sizing: border-box; background: #eee; } .grid { width: 100%; height: 100%; display: flex; font: 1em monospace; } .row { display: flex; flex: 1 auto; flex-direction: row; flex-wrap: wrap; } .col { flex: 1 auto; } .cell { margin: 0.5em; padding: 0.5em; background-color: #fff; overflow: hidden; text-align: center; flex: 1; } .note { background: #fff3d4; padding: 1em; margin: 0.5em 0.5em 0; font: 0.8em sans-serif; text-align: left; white-space: nowrap; } .note + .row .cell { margin-top: 0; } .container { display: inline-block; border: 1px dotted grey; position: relative; } .container::before { content: "margin"; position: absolute; top: 2px; left: 2px; font: italic 0.6em sans-serif; } .view-box { box-shadow: 1rem 1rem 0 #efefef inset, -1rem -1rem 0 #efefef inset; } .container.view-box::after { content: "view-box"; position: absolute; left: 1.1rem; top: 1.1rem; font: italic 0.6em sans-serif; } .cell span { display: block; margin-bottom: 0.5em; } p { font-family: sans-serif; background: #000; color: pink; margin: 2em; padding: 3em 1em; border: 1em solid pink; width: 6em; } .none { clip-path: none; } .svg { clip-path: url(#myPath); } .svg2 { clip-path: path( "M15,45 A30,30,0,0,1,75,45 A30,30,0,0,1,135,45 Q135,90,75,130 Q15,90,15,45 Z" ); } .shape1 { clip-path: circle(25%); } .shape2 { clip-path: circle(25% at 25% 25%); } .shape3 { clip-path: fill-box circle(25% at 25% 25%); } .shape4 { clip-path: stroke-box circle(25% at 25% 25%); } .shape5 { clip-path: view-box circle(25% at 25% 25%); } .shape6 { clip-path: margin-box circle(25% at 25% 25%); } .shape7 { clip-path: border-box circle(25% at 25% 25%); } .shape8 { clip-path: padding-box circle(25% at 25% 25%); } .shape9 { clip-path: content-box circle(25% at 25% 25%); } .defs { width: 0; height: 0; margin: 0; } pre { margin-bottom: 0; } svg { margin: 1em; font-family: sans-serif; width: 192px; height: 192px; } svg rect { stroke: pink; stroke-width: 16px; } svg text { fill: pink; text-anchor: middle; } svg text.em { font-style: italic; } ``` {{EmbedLiveSample("Comparison_of_HTML_and_SVG", "100%", "800px")}} ### Complete example #### HTML ```html <img id="clipped" src="mdn.svg" alt="MDN logo" /> <svg height="0" width="0"> <defs> <clipPath id="cross"> <rect y="110" x="137" width="90" height="90" /> <rect x="0" y="110" width="90" height="90" /> <rect x="137" y="0" width="90" height="90" /> <rect x="0" y="0" width="90" height="90" /> </clipPath> </defs> </svg> <select id="clipPath"> <option value="none">none</option> <option value="circle(100px at 110px 100px)">circle</option> <option value="url(#cross)" selected>cross</option> <option value="inset(20px round 20px)">inset</option> <option value="rect(10px 10px 180px 220px round 20px)">rect</option> <option value="xywh(0 20% 90% 67% round 0 0 5% 5px)">xywh</option> <option value="path('M 0 200 L 0,110 A 110,90 0,0,1 240,100 L 200 340 z')"> path </option> </select> ``` #### CSS ```css #clipped { margin-bottom: 20px; clip-path: url(#cross); } ``` ```js hidden const clipPathSelect = document.getElementById("clipPath"); clipPathSelect.addEventListener("change", (evt) => { document.getElementById("clipped").style.clipPath = evt.target.value; }); ``` #### Result {{EmbedLiveSample("Complete_example", 230, 250)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Shapes in clipping and masking – and how to use them](https://hacks.mozilla.org/2017/06/css-shapes-clipping-and-masking/) - CSS properties: {{cssxref("mask")}}, {{cssxref("filter")}} - [Applying SVG effects to HTML content](/en-US/docs/Web/SVG/Applying_SVG_effects_to_HTML_content) - SVG attributes: - {{SVGAttr("clip-path")}} - {{SVGAttr("clip-rule")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/clip-path/mdn.svg
<svg xmlns="http://www.w3.org/2000/svg" height="200" width="226.855"><defs><linearGradient gradientTransform="translate(-353.18 -4908.622) scale(6.99647)" gradientUnits="userSpaceOnUse" id="a" y2="701.6" x2="66.7" y1="730.2" x1="66.7"><stop offset="0" style="stop-color:#2075bc;stop-opacity:1"/><stop offset="1" style="stop-color:#29aae1;stop-opacity:1"/></linearGradient><linearGradient gradientTransform="translate(-353.18 -4908.622) scale(6.99647)" gradientUnits="userSpaceOnUse" id="b" y2="701.6" x2="54.6" y1="730.2" x1="54.6"><stop offset="0" style="stop-color:#0a6aa8;stop-opacity:1"/><stop offset="1" style="stop-color:#1699c8;stop-opacity:1"/></linearGradient><linearGradient gradientTransform="translate(-353.18 -4908.622) scale(6.99647)" gradientUnits="userSpaceOnUse" id="c" y2="701.6" x2="70.7" y1="730.2" x1="70.7"><stop offset="0" style="stop-color:#0a6aa8;stop-opacity:1"/><stop offset="1" style="stop-color:#1699c8;stop-opacity:1"/></linearGradient></defs><path style="fill:url(#a)" d="m56.89 0-.353.354L0 22.969V200l56.537-21.555L113.427 200l56.538-21.555L226.855 200V22.969L169.965.354 169.61 0v.354l-56.183 22.261L56.89.354V0zm43.026 42.215c.968.017 1.938.077 2.91.187 7.067 1.767 13.783 4.595 20.85 6.008 6.36-1.767 14.487-3.533 20.494.707 3.887 3.887 7.773 8.48 6.006 14.487 10.954 12.014 34.983 13.427 41.697 22.615 1.06 1.413.353 11.66 2.473 17.668l.707 2.828c-2.12 4.24-7.068 15.9-5.301 13.426-1.767 2.473-3.534 3.18-8.48 2.12-4.24 2.828-6.714 4.24-11.307 6.714-4.947 1.06-15.9-2.474-20.848-3.534-9.187-1.766-9.894.354-18.021 4.594-12.014 6.007-9.541 20.85-14.135 29.33 0 1.06.354 1.766.707 2.826s.707 1.766.707 2.473c-13.78 1.767-27.209-.352-39.576-6.36-9.54-4.593-17.667-11.661-24.381-20.142 1.413-.707 3.178-1.766 4.592-2.473 1.06-.353 2.121-1.06 2.828-1.414H60.07c-3.18-.706-1.413-.353-3.886-.353 2.826-3.18 6.715-6.006 7.068-6.36l.352-.353c-3.534 1.06-8.834 2.474-11.66 5.3 1.06-4.946 4.594-8.128 6.36-12.015-4.24 2.12-8.481 4.949-12.015 8.13 0-3.888 4.595-7.776 6.715-10.956 1.413-2.12 3.534-3.886 4.594-6.36-4.24 1.414-14.135 6.713-18.022 9.186 1.767-6.007 9.895-15.193 14.488-19.787-4.593.353-14.134 6.007-18.021 8.127 0-.353.353-.707 0-1.06 3.18-4.948 12.72-12.721 17.314-16.608-5.3.707-15.9 6.36-20.847 8.127 4.24-7.774 18.374-17.313 25.088-22.967l-16.254 4.24c-2.474 0-4.595 1.766-6.715 1.413 8.48-8.481 25.796-23.322 37.103-30.39 0 0 13.665-9.626 28.184-9.374z"/><path style="fill:url(#b)" d="M56.89 0 0 22.969V200l56.89-21.555v-37.304a85.988 85.988 0 0 1-2.472-2.979 68.24 68.24 0 0 0 2.473-1.33v-2.936c-.21.011-.344.026-.707.026.226-.255.469-.503.707-.752v-3.707c-1.89.797-3.674 1.773-4.948 3.047.823-3.838 3.128-6.615 4.948-9.48v-1.8c-3.761 2.02-7.461 4.566-10.602 7.393 0-3.887 4.595-7.775 6.715-10.955 1.148-1.722 2.753-3.216 3.887-5.04v-1.05c-4.53 1.687-13.615 6.562-17.315 8.916 1.767-6.007 9.895-15.193 14.488-19.787-4.593.353-14.134 6.007-18.021 8.127 0-.353.353-.707 0-1.06 3.18-4.948 12.72-12.721 17.314-16.608-5.3.707-15.9 6.36-20.847 8.127 4.108-7.531 17.444-16.688 24.38-22.395v-.388l-15.546 4.056c-2.474 0-4.595 1.766-6.715 1.413 5.224-5.225 13.802-12.857 22.262-19.604V0z"/><path style="fill:url(#c)" d="m169.965 0-56.537 22.969v22.627c3.386 1.083 6.775 2.12 10.248 2.814 6.36-1.767 14.487-3.533 20.494.707 3.887 3.887 7.773 8.48 6.006 14.487 4.891 5.364 12.39 8.613 19.789 11.386V0zm-26.397 124.818c-4.455.05-6.377 2.037-12.472 5.217-12.014 6.007-9.541 20.85-14.135 29.33 0 1.06.354 1.766.707 2.826s.707 1.766.707 2.473a74.51 74.51 0 0 1-4.947.465V200l56.537-21.555v-49.47c-4.947 1.06-15.9-2.474-20.848-3.534-2.297-.441-4.063-.64-5.549-.623z"/></svg>
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/dimension/index.md
--- title: <dimension> slug: Web/CSS/dimension page-type: css-type browser-compat: css.types.dimension --- {{CSSRef}} The **`<dimension>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) represents a {{CSSxRef("&lt;number&gt;")}} with a unit attached to it, for example `10px`. CSS uses dimensions to specify distances ({{CSSxRef("&lt;length&gt;")}}), durations ({{CSSxRef("&lt;time&gt;")}}), frequencies ({{CSSxRef("&lt;frequency&gt;")}}), resolutions ({{CSSxRef("&lt;resolution&gt;")}}), and other quantities. ## Syntax The syntax of `<dimension>` is a {{CSSxRef("&lt;number&gt;")}} immediately followed by a unit which is an identifier. Unit identifiers are case insensitive. ## Examples ### Valid dimensions ```plain example-good 12px 12 pixels 1rem 1 rem 1.2pt 1.2 points 2200ms 2200 milliseconds 5s 5 seconds 200hz 200 Hertz 200Hz 200 Hertz (values are case insensitive) ``` ### Invalid dimensions ```plain example-bad 12 px The unit must come immediately after the number. 12"px" Units are identifiers and therefore unquoted. 3sec The seconds unit is abbreviated "s" not "sec". ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS data types](/en-US/docs/Web/CSS/CSS_Types) - [Learn to style HTML using CSS](/en-US/docs/Learn/CSS) - CSS distances ({{CSSxRef("&lt;length&gt;")}}), durations ({{CSSxRef("&lt;time&gt;")}}), frequencies ({{CSSxRef("&lt;frequency&gt;")}}), and resolutions ({{CSSxRef("&lt;resolution&gt;")}})
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/page-break-after/index.md
--- title: page-break-after slug: Web/CSS/page-break-after page-type: css-property browser-compat: css.properties.page-break-after --- {{CSSRef}} > **Warning:** This property has been replaced by the {{cssxref("break-after")}} property. The **`page-break-after`** CSS property adjusts page breaks _after_ the current element. {{EmbedInteractiveExample("pages/css/page-break-after.html")}} ## Syntax ```css /* Keyword values */ page-break-after: auto; page-break-after: always; page-break-after: avoid; page-break-after: left; page-break-after: right; page-break-after: recto; page-break-after: verso; /* Global values */ page-break-after: inherit; page-break-after: initial; page-break-after: revert; page-break-after: revert-layer; page-break-after: unset; ``` This property applies to block elements that generate a box. It won't apply on an empty {{HTMLElement("div")}} that won't generate a box. ### Values - `auto` - : Initial value. Automatic page breaks (neither forced nor forbidden). - `always` - : Always force page breaks after the element. - `avoid` - : Avoid page breaks after the element. - `left` - : Force page breaks after the element so that the next page is formatted as a left page. It's the page placed on the left side of the spine of the book or the back side of the page in duplex printing. - `right` - : Force page breaks after the element so that the next page is formatted as a right page. It's the page placed on the right side of the spine of the book or the front side of the page in duplex printing. - `recto` {{experimental_inline}} - : If pages progress left-to-right, then this acts like `right`. If pages progress right-to-left, then this acts like `left`. - `verso` {{experimental_inline}} - : If pages progress left-to-right, then this acts like `left`. If pages progress right-to-left, then this acts like `right`. ## Page break aliases The `page-break-after` property is now a legacy property, replaced by {{cssxref("break-after")}}. For compatibility reasons, `page-break-after` should be treated by browsers as an alias of `break-after`. This ensures that sites using `page-break-after` continue to work as designed. A subset of values should be aliased as follows: | page-break-after | break-after | | ---------------- | ----------- | | `auto` | `auto` | | `left` | `left` | | `right` | `right` | | `avoid` | `avoid` | | `always` | `page` | ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting a page break after footnotes ```css /* move to a new page after footnotes */ div.footnotes { page-break-after: always; } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("break-before")}}, {{cssxref("break-after")}}, {{cssxref("break-inside")}} - {{cssxref("page-break-before")}}, {{cssxref("page-break-inside")}} - {{cssxref("orphans")}}, {{cssxref("widows")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/transition/index.md
--- title: transition slug: Web/CSS/transition page-type: css-shorthand-property browser-compat: css.properties.transition --- {{CSSRef}} The **`transition`** [CSS](/en-US/docs/Web/CSS) property is a [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) for {{ cssxref("transition-property") }}, {{ cssxref("transition-duration") }}, {{ cssxref("transition-timing-function") }}, {{ cssxref("transition-delay") }}, and {{ cssxref("transition-behavior") }}. {{EmbedInteractiveExample("pages/css/transition.html")}} Transitions enable you to define the transition between two states of an element. Different states may be defined using [pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes) like {{cssxref(":hover")}} or {{cssxref(":active")}} or dynamically set using JavaScript. ## Constituent properties This property is a shorthand for the following CSS properties: - [`transition-behavior`](/en-US/docs/Web/CSS/transition-behavior) {{experimental_inline}} - [`transition-delay`](/en-US/docs/Web/CSS/transition-delay) - [`transition-duration`](/en-US/docs/Web/CSS/transition-duration) - [`transition-property`](/en-US/docs/Web/CSS/transition-property) - [`transition-timing-function`](/en-US/docs/Web/CSS/transition-timing-function) ## Syntax ```css /* Apply to 1 property */ /* property name | duration */ transition: margin-right 4s; /* property name | duration | delay */ transition: margin-right 4s 1s; /* property name | duration | easing function */ transition: margin-right 4s ease-in-out; /* property name | duration | easing function | delay */ transition: margin-right 4s ease-in-out 1s; /* property name | duration | behavior */ transition: display 4s allow-discrete; /* Apply to 2 properties */ transition: margin-right 4s, color 1s; /* Apply to all changed properties */ transition: all 0.5s ease-out allow-discrete; transition: 200ms linear 50ms; /* Global values */ transition: inherit; transition: initial; transition: revert; transition: revert-layer; transition: unset; ``` The `transition` property value is specified as one of the following: - The special value `none`, which specifies that no transitions will occur on this element. This is the default value. - One or more single-property transitions, separated by commas. Each single-property transition describes the transition that should be applied to a single property or all properties. It includes: - zero or one value representing the property or properties to which the transition should apply. This can be set as: - A {{cssxref("&lt;custom-ident&gt;")}} representing a single property. - The special value `all`, which specifies that the transition will be applied to all properties that change as the element changes state. - No value, in which case a value of `all` will be inferred and the specified transition will still apply to all changing properties. - zero or one {{cssxref("&lt;easing-function&gt;")}} value representing the easing function to use - zero, one, or two {{cssxref("&lt;time&gt;")}} values. The first value that can be parsed as a time is assigned to the {{cssxref("transition-duration")}}, and the second value that can be parsed as a time is assigned to {{cssxref("transition-delay")}}. - zero or one value declaring whether to start transitions for properties whose animation behavior is [discrete](/en-US/docs/Web/CSS/CSS_animated_properties#discrete). The value, if present, is either the keyword `allow-discrete` or the keyword `normal`. If you specify `all` as the transition property for one single-property transition, but then specify subsequent single-property transitions with {{cssxref("&lt;custom-ident&gt;")}} values, those subsequent transitions will override the first one. For example: ```css transition: all 200ms, opacity 400ms; ``` In this case, all the properties that change as the element changes state will transition with a duration of 200ms except for {{cssxref("opacity")}}, which will take 400ms to transition. See [how things are handled](/en-US/docs/Web/CSS/CSS_transitions/Using_CSS_transitions#when_property_value_lists_are_of_different_lengths) when lists of property values aren't the same length. In short, extra transition descriptions beyond the number of properties actually being animated are ignored. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Basic example In this example, when the user hovers over the element, there is a one-second delay before the four-second `font-size` transition occurs. #### HTML ```html <a class="target">Hover over me</a> ``` #### CSS We include two {{cssxref("time")}} values. In the `transition` shorthand, the first `<time>` value is the `transition-duration`. The second time value is the `transition-delay`. Both default to `0s` if omitted. ```css .target { font-size: 14px; transition: font-size 4s 1s; } .target:hover { font-size: 36px; } ``` {{EmbedLiveSample('Basic_example', 600, 100)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS transitions](/en-US/docs/Web/CSS/CSS_transitions) module - [Using CSS transitions](/en-US/docs/Web/CSS/CSS_transitions/Using_CSS_transitions) - {{ domxref("TransitionEvent") }}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/counter-set/index.md
--- title: counter-set slug: Web/CSS/counter-set page-type: css-property browser-compat: css.properties.counter-set --- {{CSSRef}} The **`counter-set`** [CSS](/en-US/docs/Web/CSS) property sets [CSS counters](/en-US/docs/Web/CSS/CSS_counter_styles/Using_CSS_counters) to the given values. The `counter-set` property will create a new counter for each named counter in the list of space-separated counter and value pairs that doesn't already exist. If a named counter in the list is missing a value, the value of the counter will be set to `0`. {{EmbedInteractiveExample("pages/css/counter-set.html")}} > **Note:** The counter's value can be incremented or decremented using the {{cssxref("counter-increment")}} CSS property. ## Syntax ```css /* Set "my-counter" to 0 */ counter-set: my-counter; /* Set "my-counter" to -1 */ counter-set: my-counter -1; /* Set "counter1" to 1, and "counter2" to 4 */ counter-set: counter1 1 counter2 4; /* Cancel any counter that could have been set in less specific rules */ counter-set: none; /* Global values */ counter-set: inherit; counter-set: initial; counter-set: revert; counter-set: revert-layer; counter-set: unset; ``` The `counter-set` property is specified as either one of the following: - A `<custom-ident>` naming the counter, followed optionally by an `<integer>`. You may specify as many counters to reset as you want, with each name or name-number pair separated by a space. - The keyword value `none`. ### Values - {{cssxref("custom-ident", "&lt;custom-ident&gt;")}} - : The name of the counter to set. - {{cssxref("&lt;integer&gt;")}} - : The value to set the counter to on each occurrence of the element. Defaults to `0` if not specified. If there isn't currently a counter of the given name on the element, the element will create a new counter of the given name with a starting value of `0` (though it may then immediately set or increment that value to something different). - `none` - : No counter set is to be performed. This can be used to override a `counter-set` defined in a less specific rule. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting named counters ```css h1 { counter-set: chapter section 1 page; /* Sets the chapter and page counters to 0, and the section counter to 1 */ } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Using CSS Counters](/en-US/docs/Web/CSS/CSS_counter_styles/Using_CSS_counters) - {{cssxref("counter-increment")}} - {{cssxref("counter-reset")}} - {{cssxref("@counter-style")}} - {{cssxref("counter", "counter()")}} and {{cssxref("counters", "counters()")}} functions - {{cssxref("content")}} property - [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/padding-inline-end/index.md
--- title: padding-inline-end slug: Web/CSS/padding-inline-end page-type: css-property browser-compat: css.properties.padding-inline-end --- {{CSSRef}} The **`padding-inline-end`** [CSS](/en-US/docs/Web/CSS) property defines the logical inline end padding of an element, which maps to a physical padding depending on the element's writing mode, directionality, and text orientation. {{EmbedInteractiveExample("pages/css/padding-inline-end.html")}} ## Syntax ```css /* <length> values */ padding-inline-end: 10px; /* An absolute length */ padding-inline-end: 1em; /* A length relative to the text size */ /* <percentage> value */ padding-inline-end: 5%; /* A padding relative to the block container's width */ /* Global values */ padding-inline-end: inherit; padding-inline-end: initial; padding-inline-end: revert; padding-inline-end: revert-layer; padding-inline-end: unset; ``` ### Values - {{cssxref("&lt;length&gt;")}} - : The size of the padding as a fixed value. Must be nonnegative. - {{cssxref("&lt;percentage&gt;")}} - : The size of the padding as a percentage, relative to the [inline-size](/en-US/docs/Web/CSS/CSS_flow_layout/Block_and_inline_layout_in_normal_flow) (_width_ in a horizontal language) of the [containing block](/en-US/docs/Web/CSS/Containing_block). Must be nonnegative. ## Description The `padding-inline-end` property is defined in the specification as taking the same values as the {{cssxref("padding-top")}} property. However, the physical property it maps to depends on the values set for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. Therefore, it could map to {{cssxref("padding-bottom")}}, {{cssxref("padding-right")}}, or {{cssxref("padding-left")}}. It relates to {{cssxref("padding-block-start")}}, {{cssxref("padding-block-end")}}, and {{cssxref("padding-inline-start")}}, which define the other paddings of the element. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting inline end padding for vertical text #### HTML ```html <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ```css div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; padding-inline-end: 20px; background-color: #c8c800; } ``` #### Result {{EmbedLiveSample("Setting_inline_end_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/_colon_out-of-range/index.md
--- title: ":out-of-range" slug: Web/CSS/:out-of-range page-type: css-pseudo-class browser-compat: css.selectors.out-of-range --- {{CSSRef}} The **`:out-of-range`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents an {{htmlelement("input")}} element whose current value is outside the range limits specified by the [`min`](/en-US/docs/Web/HTML/Element/input#min) and [`max`](/en-US/docs/Web/HTML/Element/input#max) attributes. {{EmbedInteractiveExample("pages/tabbed/pseudo-class-out-of-range.html", "tabbed-shorter")}} This pseudo-class is useful for giving the user a visual indication that a field's current value is outside the permitted limits. > **Note:** This pseudo-class only applies to elements that have (and can take) a range limitation. In the absence of such a limitation, the element can neither be "in-range" nor "out-of-range." ## Syntax ```css :out-of-range { /* ... */ } ``` ## Examples ### HTML ```html <form action="" id="form1"> <p>Values between 1 and 10 are valid.</p> <ul> <li> <input id="value1" name="value1" type="number" placeholder="1 to 10" min="1" max="10" value="12" /> <label for="value1">Your value is </label> </li> </ul> </form> ``` ### CSS ```css li { list-style: none; margin-bottom: 1em; } input { border: 1px solid black; } input:in-range { background-color: rgb(0 255 0 / 25%); } input:out-of-range { background-color: rgb(255 0 0 / 25%); border: 2px solid red; } input:in-range + label::after { content: "okay."; } input:out-of-range + label::after { content: "out of range!"; } ``` ### Result {{EmbedLiveSample('Examples', 600, 140)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref(":in-range")}} - [Form data validation](/en-US/docs/Learn/Forms/Form_validation)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_nesting/index.md
--- title: CSS nesting slug: Web/CSS/CSS_nesting page-type: css-module spec-urls: https://drafts.csswg.org/css-nesting-1/ --- {{CSSRef}} The **CSS nesting** module defines a syntax for nesting selectors, providing the ability to nest one style rule inside another, with the selector of the child rule relative to the selector of the parent rule. CSS nesting is different from CSS preprocessors such as [Sass](https://sass-lang.com/) in that it is parsed by the browser rather than being pre-compiled by a CSS preprocessor. CSS nesting helps with the readability, modularity, and maintainability of CSS stylesheets. It also potentially helps reduce the size of CSS files, thereby decreasing the amount of data downloaded by users. ## Reference ### Selectors - [`&` nesting selector](/en-US/docs/Web/CSS/Nesting_selector) ## Guides - [Using CSS nesting](/en-US/docs/Web/CSS/CSS_nesting/Using_CSS_nesting) - : Explains how to use CSS nesting. - [CSS nesting at-rules](/en-US/docs/Web/CSS/CSS_nesting/Nesting_at-rules) - : Explains how to nest at-rules. - [CSS nesting and specificity](/en-US/docs/Web/CSS/CSS_nesting/Nesting_and_specificity) - : Explains the differences in specificity when nesting CSS. ## Related concepts - [Selectors and combinators](/en-US/docs/Web/CSS/CSS_selectors/Selectors_and_combinators) - [Pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes) - [CSS preprocessor](/en-US/docs/Glossary/CSS_preprocessor) ## Specifications {{Specifications}} ## See also - [Specificity](/en-US/docs/Web/CSS/Specificity) - [CSS cascade and inheritance module](/en-US/docs/Web/CSS/CSS_cascade) - [CSS selectors module](/en-US/docs/Web/CSS/CSS_selectors)
0
data/mdn-content/files/en-us/web/css/css_nesting
data/mdn-content/files/en-us/web/css/css_nesting/nesting_at-rules/index.md
--- title: CSS nesting at-rules slug: Web/CSS/CSS_nesting/Nesting_at-rules page-type: guide --- {{CSSRef}} Any [at-rule](/en-US/docs/Web/CSS/At-rule) whose body contains style rules can be nested inside another style rule using CSS nesting. Style rules nested inside at-rules take their nesting selector definition from the nearest ancestor style rule. Properties can be directly included inside a nested at-rule, acting as if they were nested in a `& {...}` block. ## at-rules that can be nested - {{cssxref('@media')}} - {{cssxref('@supports')}} - {{cssxref('@layer')}} - {{cssxref('@scope')}} - {{cssxref('@container')}} ## Examples ### Nesting `@media` at-rule In this example we see three blocks of CSS. The first one shows how to write typical at-rule nesting, the second is an expanded way of writing the nesting as the browser parses it, and the third one shows the non-nested equivalent. #### Nested CSS ```css .foo { display: grid; @media (orientation: landscape) { grid-auto-flow: column; } } ``` #### Expanded nested CSS ```css .foo { display: grid; @media (orientation: landscape) { & { grid-auto-flow: column; } } } ``` #### Non-nested equivalent ```css .foo { display: grid; } @media (orientation: landscape) { .foo { grid-auto-flow: column; } } ``` ### Multiple nested `@media` at-rules At-rules can be nested within other at-rules. Below you can see an example of this, and how it would be written without nesting. #### Nested at-rules ```css .foo { display: grid; @media (orientation: landscape) { grid-auto-flow: column; @media (min-width: 1024px) { max-inline-size: 1024px; } } } ``` #### Non-nested equivalent ```css .foo { display: grid; } @media (orientation: landscape) { .foo { grid-auto-flow: column; } } @media (orientation: landscape) and (min-width: 1024px) { .foo { max-inline-size: 1024px; } } ``` ### Nesting Cascade Layers (`@layer`) [Cascade Layers](/en-US/docs/Web/CSS/@layer) can be nested to [create child-layers](/en-US/docs/Web/CSS/@layer#nesting_layers). These are joined with a `.`(dot). #### Defining the parent & child layers We start by defining the named cascade layers, prior to using them, without any style assignments. ```css @layer base { @layer support; } ``` #### Assigning rules to layers with nesting Here the `.foo` selector assigns its rules to the **base** `@layer`. The nested **support** `@layer` creates the `base.support` sub-layer, and the `&` nesting selector is used to create the rules for the `.foo .bar` selector . ```css .foo { @layer base { block-size: 100%; @layer support { & .bar { min-block-size: 100%; } } } } ``` #### Equivalent without nesting ```css @layer base { .foo { block-size: 100%; } } @layer base.support { .foo .bar { min-block-size: 100%; } } ``` ## See also - [CSS Nesting](/en-US/docs/Web/CSS/CSS_nesting) module - [`&` nesting selector](/en-US/docs/Web/CSS/Nesting_selector) - [Using CSS nesting](/en-US/docs/Web/CSS/CSS_nesting/Using_CSS_nesting) - [Nesting and specificity](/en-US/docs/Web/CSS/CSS_nesting/Nesting_and_specificity) - [Nesting container queries](/en-US/docs/Web/CSS/CSS_containment/Container_size_and_style_queries#nested_queries)
0
data/mdn-content/files/en-us/web/css/css_nesting
data/mdn-content/files/en-us/web/css/css_nesting/nesting_and_specificity/index.md
--- title: CSS nesting and specificity slug: Web/CSS/CSS_nesting/Nesting_and_specificity page-type: guide --- {{CSSRef}} The {{cssxref('specificity')}} of the `&` nesting selector is calculated using the largest specificity in the associated selector list. This is identical to how specificity is calculated when using the {{cssxref(':is',':is()')}} function. ```html <b class="foo"> <c>Blue text</c> </b> ``` ## `&` nesting syntax ```css-nolint #a, b { & c { color: blue; } } .foo c { color: red; } ``` ## `:is()` syntax ```css :is(#a, b) { & c { color: blue; } } .foo c { color: red; } ``` In this example, the id selector (`#a`) has a specificity of [`1-0-0`](/en-US/docs/Web/CSS/Specificity#selector_weight_categories), while the type selector (`b`) has a specificity of `0-0-1`. The [`&` nesting selector](/en-US/docs/Web/CSS/Nesting_selector) and `:is()` pseudo-class both take a specificity of `1-0-0`, even though the `#a` id selector is never used. The `.foo` class selector has a specificity of `0-1-0`. This makes the total specificity `1-0-1` for `& c` and `0-1-1` for `.foo c`, meaning that `color: blue;` wins out. ## See also - [CSS nesting](/en-US/docs/Web/CSS/CSS_nesting) module - [`&` nesting selector](/en-US/docs/Web/CSS/Nesting_selector) - [Using CSS nesting](/en-US/docs/Web/CSS/CSS_nesting/Using_CSS_nesting) - [Nesting at-rules](/en-US/docs/Web/CSS/CSS_nesting/Nesting_at-rules)
0
data/mdn-content/files/en-us/web/css/css_nesting
data/mdn-content/files/en-us/web/css/css_nesting/using_css_nesting/index.md
--- title: Using CSS nesting slug: Web/CSS/CSS_nesting/Using_CSS_nesting page-type: guide --- {{CSSRef}} The [CSS nesting](/en-US/docs/Web/CSS/CSS_nesting) module allows you to write your stylesheets so that they are easier to read, more modular, and more maintainable. As you are not constantly repeating selectors, the file size can also be reduced. CSS nesting is different from CSS preprocessors such as [Sass](https://sass-lang.com/) in that it is parsed by the browser rather than being pre-compiled by a CSS preprocessor. Also, in CSS nesting, the [specificity of the `&` nesting selector](/en-US/docs/Web/CSS/CSS_nesting/Nesting_and_specificity) is similar to the {{cssxref(':is',':is()')}} function; it is calculated using the highest specificity in the associated selector list. This guide shows different ways to arrange nesting in CSS. ## Child selectors You can use CSS nesting to create child selectors of a parent, which in turn can be used to target child elements of specific parents. This can be done with or without the [`&` nesting selector](/en-US/docs/Web/CSS/Nesting_selector). There are certain instances where using the `&` nesting selector can be necessary or helpful: - When joining selectors together, such as using [compound selectors](#compound_selectors) or [pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes). - For backwards compatability. - As a visual indicator to aid with readability, when seeing the `&` nesting selector you know that CSS nesting is being used. ```css /* Without nesting selector */ parent { /* parent styles */ child { /* child of parent styles */ } } /* With nesting selector */ parent { /* parent styles */ & child { /* child of parent styles */ } } /* the browser will parse both of these as */ parent { /* parent styles */ } parent child { /* child of parent styles */ } ``` ### Examples In these examples, one without and one with the `&` nesting selector, the `<input>` inside the `<label>` is being styled differently to the `<input>` that is a sibling of a `<label>`. This demonstrates the impact of omitting the `&` nesting selector. > **Note:** This example demonstrates different outputs in browsers implementing the original specification versus the current nesting spec. The original, pre-August 2023 nesting spec that was implemented in Chrome or Safari, requires the `&` nesting combinator. If your browser supports the current spec, the output of both examples matches that of the second example. #### Without nesting selector ##### HTML ```html-nolint <form> <label for="name">Name: <input type="text" id="name" /> </label> <label for="email">email:</label> <input type="text" id="email" /> </form> ``` ##### CSS ```css hidden form, label { display: flex; flex-direction: column; gap: 0.5rem; } ``` ```css input { /* styles for input not in a label */ border: tomato 2px solid; } label { /* styles for label */ font-family: system-ui; font-size: 1.25rem; input { /* styles for input in a label */ border: blue 2px dashed; } } ``` ##### Result {{EmbedLiveSample('Without_nesting_selector','100%','120')}} #### With nesting selector ##### HTML ```html-nolint <form> <label for="name">Name: <input type="text" id="name" /> </label> <label for="email">email:</label> <input type="text" id="email" /> </form> ``` ##### CSS ```css hidden form, label { display: flex; flex-direction: column; gap: 0.5rem; } ``` ```css input { /* styles for input not in a label */ border: tomato 2px solid; } label { /* styles for label */ font-family: system-ui; font-size: 1.25rem; & input { /* styles for input in a label */ border: blue 2px dashed; } } ``` ##### Result {{EmbedLiveSample('With_nesting_selector','100%','120')}} ## Combinators [CSS Combinators](/en-US/docs/Learn/CSS/Building_blocks/Selectors/Combinators) can also be used with or without the `&` nesting selector. ### Example #### Nesting the sibling combinator In this example, the first paragraph after each `<h2>` is targeted with the [next-sibling combinator (`+`)](/en-US/docs/Web/CSS/Next-sibling_combinator) using CSS nesting. ##### HTML ```html <h2>Heading</h2> <p>This is the first paragraph.</p> <p>This is the second paragraph.</p> ``` ##### CSS ```css h2 { color: tomato; + p { color: white; background-color: black; } } /* this code can also be written with the & nesting selector */ /* h2 { color: tomato; & + p { color: white; background-color: black; } } */ ``` ##### Result {{EmbedLiveSample('Nesting_the_sibling_combinator','100%','135')}} ## Compound selectors When using [compound selectors](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#compound_selector) in nested CSS you **have** to use the `&` nesting selector. This is because the browser will automatically add whitespace between selectors that do not use the `&` nesting selector. In order to target an element with `class="a b"` the `&` nesting selector is needed otherwise the whitespace will break the compound selector. ```css .a { /* styles for element with class="a" */ .b { /* styles for element with class="b" which is a descendant of class="a" */ } &.b { /* styles for element with class="a b" */ } } /* the browser parses this as */ .a { /* styles for element with class="a" */ } .a .b { /* styles for element with class="b" which is a descendant of class="a" */ } .a.b { /* styles for element with class="a b" */ } ``` ### Example #### Nesting and compound selectors In this example the `&` nesting selector is used to create compound selectors to style elements with multiple classes. ##### HTML ```html <div class="notices"> <div class="notice"> <h2 class="notice-heading">Notice</h2> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p> </div> <div class="notice warning"> <h2 class="warning-heading">Warning</h2> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p> </div> <div class="notice success"> <h2 class="success-heading">Success</h2> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p> </div> </div> ``` ##### CSS Styles for the `.notices` to create a column using {{cssxref('CSS_flexible_box_layout', 'flexbox layout')}}. ```css .notices { display: flex; flex-direction: column; gap: 0.5rem; width: 90%; margin: auto; } ``` In the CSS code below, nesting is used to create compound selectors both with and without `&`. The top-level selector defines the basic styles for elements with `class="notice"`. The `&` nesting selector is then used to create compound selectors for elements with either `class="notice warning"` or `class="notice success"`. Additionally, the use of nesting to create compound selectors without explicitly using `&` can be seen in the selector `.notice .notice-heading:before`. ```css .notice { width: 90%; justify-content: center; border-radius: 1rem; border: black solid 2px; background-color: #ffc107; color: black; padding: 1rem; .notice-heading:before { /* equivalent to `.notice .notice-heading:before` */ content: "β„ΉοΈŽ "; } &.warning { /* equivalent to `.notice.warning` */ background-color: #d81b60; border-color: #d81b60; color: white; .warning-heading:before { /* equivalent to `.notice.warning .warning-heading:before` */ content: "! "; } } &.success { /* equivalent to `.notice.success` */ background-color: #004d40; border-color: #004d40; color: white; .success-heading:before { /* equivalent to `.notice.success .success-heading:before` */ content: "βœ“ "; } } } ``` ##### Result {{EmbedLiveSample('Nesting_and_compound_selectors','100%', '455')}} ## Appended nesting selector The `&` nesting selector can also be appended to a nested selector which has the effect of reversing the context. This can be useful when we have styles for a child element that change when a parent element is given a different class: ```html <div> <span class="foo">text</span> </div> ``` As opposed to: ```html <div class="bar"> <span class="foo">text</span> </div> ``` ```css .foo { /* .foo styles */ .bar & { /* .bar .foo styles */ } } ``` ### Example #### Appending nesting selector In this example there are 3 cards, one of which is featured. The cards are all exactly the same except the featured card will have an alternative color for the heading. By appending the `&` nesting selector the style for the `.featured .h2` can be nested in the style for the `h2`. ##### HTML ```html <div class="wrapper"> <article class="card"> <h2>Card 1</h2> <p>Lorem ipsum dolor, sit amet consectetur adipisicing elit.</p> </article> <article class="card featured"> <h2>Card 2</h2> <p>Lorem ipsum dolor, sit amet consectetur adipisicing elit.</p> </article> <article class="card"> <h2>Card 3</h2> <p>Lorem ipsum dolor, sit amet consectetur adipisicing elit.</p> </article> </div> ``` ##### CSS ```css .wrapper { display: flex; flex-direction: row; gap: 0.25rem; font-family: system-ui; } ``` In the following CSS, we are creating the styles for `.card` and `.card h2`. Then, in the `h2` style block, we nest the `.featured` class with the `&` nesting selector appended which creates a style for `.card :is(.featured h2)`, which is equivalent to `:is(.card h2):is(.featured h2)`. ```css .card { padding: 0.5rem; border: 1px solid black; border-radius: 0.5rem; & h2 { /* equivalent to `.card h2` */ color: slateblue; .featured & { /* equivalent to `:is(.card h2):is(.featured h2)` */ color: tomato; } } } ``` ##### Result {{EmbedLiveSample('Appending_nesting_selector','100%','250')}} ## Concatenation (is not possible) In CSS preprocessors such as [Sass](https://sass-lang.com/), it is possible to use nesting to join strings to create new classes. This is common in CSS methodologies such as [BEM](https://getbem.com/naming/). ```css example-bad .component { &__child-element { } } /* In Sass this becomes */ .component__child-element { } ``` > **Warning:** This is not possible in CSS nesting: when a [combinator](/en-US/docs/Learn/CSS/Building_blocks/Selectors/Combinators) is not used, the nested selector is treated as a [type selector](/en-US/docs/Web/CSS/Type_selectors). Allowing concatenation would break this. In [compound selectors](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#compound_selector), the type selector must come first. Writing `&Element` (a [type selector](/en-US/docs/Web/CSS/Type_selectors)) makes the CSS selector, and the entire selector block, invalid. As the type selector must come first, the compound selector must be written as `Element&`. ```css example-good .my-class { element& { } } /* the browser parses this to become a compound selector */ .my-class { } element.my-class { } ``` ## Invalid nested style rules If a nested CSS rule is invalid then all of the enclosed styles will be ignored. This does not affect the parent or preceding rules. In the following example, there is an invalid selector (`%` is not a valid character for selectors). The rule that includes this selector is ignored, but subsequent valid rules are not. ```css example-bad .parent { /* .parent styles these work fine */ & %invalid { /* %invalid styles all of which are ignored */ } & .valid { /* .parent .valid styles these work fine */ } } ``` ## See also - [CSS nesting](/en-US/docs/Web/CSS/CSS_nesting) module - [`&` nesting selector](/en-US/docs/Web/CSS/Nesting_selector) - [Nesting `@` at-rules](/en-US/docs/Web/CSS/CSS_nesting/Nesting_at-rules) - [Nesting and specificity](/en-US/docs/Web/CSS/CSS_nesting/Nesting_and_specificity)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/text-overflow/index.md
--- title: text-overflow slug: Web/CSS/text-overflow page-type: css-property browser-compat: css.properties.text-overflow --- {{CSSRef}} The **`text-overflow`** [CSS](/en-US/docs/Web/CSS) property sets how hidden overflow content is signaled to users. It can be clipped, display an ellipsis ('`…`'), or display a custom string. {{EmbedInteractiveExample("pages/css/text-overflow.html")}} The `text-overflow` property doesn't force an overflow to occur. To make text overflow its container, you have to set other CSS properties: {{cssxref("overflow")}} and {{cssxref("white-space")}}. For example: ```css overflow: hidden; white-space: nowrap; ``` The `text-overflow` property only affects content that is overflowing a block container element in its _inline_ progression direction (not text overflowing at the bottom of a box, for example). ## Syntax ```css text-overflow: clip; text-overflow: ellipsis ellipsis; text-overflow: ellipsis " [..]"; /* Global values */ text-overflow: inherit; text-overflow: initial; text-overflow: revert; text-overflow: revert-layer; text-overflow: unset; ``` The `text-overflow` property may be specified using one or two values. If one value is given, it specifies overflow behavior for the end of the line (the right end for left-to-right text, the left end for right-to-left text). If two values are given, the first specifies overflow behavior for the left end of the line, and the second specifies it for the right end of the line. The property accepts either a keyword value (`clip` or `ellipsis`) or a `<string>` value. ### Values - `clip` - : The default for this property. This keyword value will truncate the text at the limit of the [content area](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model), therefore the truncation can happen in the middle of a character. To clip at the transition between characters you can specify `text-overflow` as an empty string, if that is supported in your target browsers: `text-overflow: '';`. - `ellipsis` - : This keyword value will display an ellipsis (`'…'`, `U+2026 HORIZONTAL ELLIPSIS`) to represent clipped text. The ellipsis is displayed inside the [content area](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model), decreasing the amount of text displayed. If there is not enough space to display the ellipsis, it is clipped. - `<string>` {{experimental_inline}} - : The {{cssxref("&lt;string&gt;")}} to be used to represent clipped text. The string is displayed inside the [content area](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model), shortening the size of the displayed text. If there is not enough space to display the string itself, it is clipped. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### One-value syntax This example shows different values for `text-overflow` applied to a paragraph, for left-to-right and right-to-left text. #### HTML ```html <div class="ltr"> <h2>Left to right text</h2> <pre>clip</pre> <p class="overflow-clip"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p> <pre>ellipsis</pre> <p class="overflow-ellipsis"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p> <pre>" [..]"</pre> <p class="overflow-string"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p> </div> <div class="rtl"> <h2>Right to left text</h2> <pre>clip</pre> <p class="overflow-clip"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p> <pre>ellipsis</pre> <p class="overflow-ellipsis"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p> <pre>" [..]"</pre> <p class="overflow-string"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p> </div> ``` #### CSS ```css p { width: 200px; border: 1px solid; padding: 2px 5px; /* Both of the following are required for text-overflow */ white-space: nowrap; overflow: hidden; } .overflow-clip { text-overflow: clip; } .overflow-ellipsis { text-overflow: ellipsis; } .overflow-string { text-overflow: " [..]"; } body { display: flex; justify-content: space-around; } .ltr > p { direction: ltr; } .rtl > p { direction: rtl; } ``` #### Result {{EmbedLiveSample('One-value_syntax', 600, 320)}} ### Two-value syntax This example shows the two-value syntax for `text-overflow`, where you can define different overflow behavior for the start and end of the text. To show the effect we have to scroll the line so the start of the line is also hidden. #### HTML ```html <pre>clip clip</pre> <p class="overflow-clip-clip"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p> <pre>clip ellipsis</pre> <p class="overflow-clip-ellipsis"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p> <pre>ellipsis ellipsis</pre> <p class="overflow-ellipsis-ellipsis"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p> <pre>ellipsis " [..]"</pre> <p class="overflow-ellipsis-string"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p> ``` #### CSS ```css p { width: 200px; border: 1px solid; padding: 2px 5px; /* Both of the following are required for text-overflow */ white-space: nowrap; overflow: scroll; } .overflow-clip-clip { text-overflow: clip clip; } .overflow-clip-ellipsis { text-overflow: clip ellipsis; } .overflow-ellipsis-ellipsis { text-overflow: ellipsis ellipsis; } .overflow-ellipsis-string { text-overflow: ellipsis " [..]"; } ``` #### JavaScript ```js // Scroll each paragraph so the start is also hidden const paras = document.querySelectorAll("p"); for (const para of paras) { para.scroll(100, 0); } ``` #### Result {{EmbedLiveSample('Two-value_syntax', 600, 360)}} ## Specifications {{Specifications}} A previous version of this interface reached the _Candidate Recommendation_ status. As some not-listed-at-risk features needed to be removed, the spec was demoted to the _Working Draft_ level, explaining why browsers implemented this property unprefixed, though not at the CR state. ## Browser compatibility {{Compat}} ## See also - Related CSS properties: {{cssxref("overflow")}}, {{cssxref("white-space")}} - CSS properties that control line breaks in words: {{cssxref("overflow-wrap")}}, {{cssxref("word-break")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_has/index.md
--- title: ":has()" slug: Web/CSS/:has page-type: css-pseudo-class browser-compat: css.selectors.has --- {{CSSRef}} The functional **`:has()`** CSS [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents an element if any of the [relative selectors](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#relative_selector) that are passed as an argument match at least one element when anchored against this element. This pseudo-class presents a way of selecting a parent element or a previous sibling element with respect to a reference element by taking a [relative selector list](/en-US/docs/Web/CSS/Selector_list#relative_selector_list) as an argument. ```css /* Selects an h1 heading with a paragraph element that immediately follows the h1 and applies the style to h1 */ h1:has(+ p) { margin-bottom: 0; } ``` The `:has()` pseudo-class takes on the [specificity](/en-US/docs/Web/CSS/Specificity) of the most specific selector in its arguments the same way as {{CSSxRef(":is", ":is()")}} and {{CSSxRef(":not", ":not()")}} do. ## Syntax ```css-nolint :has(<relative-selector-list>) { /* ... */ } ``` If the `:has()` pseudo-class itself is not supported in a browser, the entire selector block will fail unless `:has()` is in a forgiving selector list, such as in [`:is()`](/en-US/docs/Web/CSS/:is) and [`:where()`](/en-US/docs/Web/CSS/:where)). The `:has()` pseudo-class cannot be nested within another `:has()`. This is because many pseudo-elements exist conditionally based on the styling of their ancestors and allowing these to be queried by `:has()` can introduce cyclic querying. Pseudo-elements are also not valid selectors within `:has()` and pseudo-elements are not valid anchors for `:has()`. ## Examples ### With the sibling combinator The `:has()` style declaration in the following example adjusts the spacing after `<h1>` headings if they are immediately followed by an `<h2>` heading. #### HTML ```html <section> <article> <h1>Morning Times</h1> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p> </article> <article> <h1>Morning Times</h1> <h2>Delivering you news every morning</h2> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p> </article> </section> ``` #### CSS ```css hidden section { display: flex; align-items: start; justify-content: space-around; } article { display: inline-block; width: 40%; } h1, h2 { font-size: 1.2em; } h2 { font-size: 1em; color: rgb(150 149 149); } ``` ```css h1, h2 { margin: 0 0 1rem 0; } h1:has(+ h2) { margin: 0 0 0.25rem 0; } ``` #### Result {{EmbedLiveSample('With_the_sibling_combinator', 600, 150)}} This example shows two similar texts side-by-side for comparison – the left one with an `H1` heading followed by a paragraph and the right one with an `H1` heading followed by an `H2` heading and then a paragraph. In the example on the right, `:has()` helps to select the `H1` element that is immediately followed by an `H2` element (indicated by the next-sibling combinator[`+`](/en-US/docs/Web/CSS/Next-sibling_combinator)) and the CSS rule reduces the spacing after such an `H1` element. Without the `:has()` pseudo-class, you cannot use CSS selectors to select a preceding sibling of a different type or a parent element. ### With the :is() pseudo-class This example builds on the previous example to show how to select multiple elements with `:has()`. #### HTML ```html <section> <article> <h1>Morning Times</h1> <h2>Delivering you news every morning</h2> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p> </article> <article> <h1>Morning Times</h1> <h2>Delivering you news every morning</h2> <h3>8:00 am</h3> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p> </article> </section> ``` #### CSS ```css hidden section { display: flex; align-items: start; justify-content: space-around; } article { display: inline-block; width: 40%; } h1 { font-size: 1.2em; } h2 { font-size: 1em; color: rgb(150 149 149); } h3 { font-size: 0.9em; color: darkgrey; } ``` ```css h1, h2, h3 { margin: 0 0 1rem 0; } :is(h1, h2, h3):has(+ :is(h2, h3, h4)) { margin: 0 0 0.25rem 0; } ``` #### Result {{EmbedLiveSample('With_the_:is()_pseudo-class', 600, 170)}} Here, the first [`:is()`](/en-US/docs/Web/CSS/:is) pseudo-class is used to select any of the heading elements in the list. The second `:is()` pseudo-class is used to pass a list of next-sibling selectors as an argument to `:has()`. The `:has()` pseudo-class helps to select any `H1`, `H2`, or `H3` element that is immediately followed by (indicated by [`+`](/en-US/docs/Web/CSS/Next-sibling_combinator)) an `H2`, `H3`, or `H4` element and the CSS rule reduces the spacing after such `H1`, `H2`, or `H3` elements. This selector could have also been written as: ```css :is(h1, h2, h3):has(+ h2, + h3, + h4) { margin: 0 0 0.25rem 0; } ``` ### Logical operations The `:has()` relational selector can be used to check if one of the multiple features is true or if all the features are true. By using comma-separated values inside the `:has()` relational selector, you are checking to see if any of the parameters exist. `x:has(a, b)` will style `x` if descendant `a` OR `b` exists. By chaining together multiple `:has()` relational selectors together, you are checking to see if all of the parameters exist. `x:has(a):has(b)` will style `x` if descendant `a` AND `b` exist. ```css body:has(video, audio) { /* styles to apply if the content contains audio OR video */ } body:has(video):has(audio) { /* styles to apply if the content contains both audio AND video */ } ``` ## Analogy between :has() and regular expressions Interestingly, we can relate some CSS `:has()` constructs with the [lookahead assertion](/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Lookahead_assertion) in regular expressions because they both allow you to select elements (or strings in regular expressions) based on a condition without actually selecting the condition matching the element (or string) itself. ### Positive lookahead (?=pattern) In the regular expression `abc(?=xyz)`, the string `abc` is matched only if it is immediately followed by the string `xyz`. As it is a lookahead operation, the `xyz` is not included in the match. The analogous construct in CSS would be `.abc:has(+ .xyz)`: it selects the element `.abc` only if there is a next sibling `.xyz`. The part `:has(+ .xyz)` acts as a lookahead operation because the element `.abc` is selected and not the element `.xyz`. ### Negative lookahead (?!pattern) Similarly, for the negative lookahead case, in the regular expression `abc(?!xyz)`, the string `abc` is matched only if it is _not_ followed by `xyz`. The analogous CSS construct `.abc:has(+ :not(.xyz))` doesn't select the element `.abc` if the next element is `.xyz`. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [`:is()`](/en-US/docs/Web/CSS/:is), [`:where()`](/en-US/docs/Web/CSS/:where), [`:not()`](/en-US/docs/Web/CSS/:not) - [CSS selectors and combinators](/en-US/docs/Web/CSS/CSS_selectors/Selectors_and_combinators) - [CSS selector structure](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure) - [Selector list](/en-US/docs/Web/CSS/Selector_list) - [CSS selector module](/en-US/docs/Web/CSS/CSS_selectors) - [Locating DOM elements using selectors](/en-US/docs/Web/API/Document_object_model/Locating_DOM_elements_using_selectors)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/@container/index.md
--- title: "@container" slug: Web/CSS/@container page-type: css-at-rule browser-compat: css.at-rules.container --- {{CSSRef}} The **`@container`** [CSS](/en-US/docs/Web/CSS) [at-rule](/en-US/docs/Web/CSS/At-rule) is a conditional group rule that applies styles to a [containment context](/en-US/docs/Web/CSS/CSS_containment/Container_queries#naming_containment_contexts). Style declarations are filtered by a condition and applied to the container if the condition is true. The condition is evaluated when the container changes size. The {{cssxref("container-name")}} property specifies a list of query container names. These names can be used by `@container` rules to filter which query containers are targeted. The optional, case-sensitive `<container-name>` filters the query containers that are targeted by the query. Once an eligible query container has been selected for an element, each container feature in the `<container-condition>` is evaluated against that query container. ## Syntax The `@container` at-rule has the following syntax: ```plain @container <container-condition> { <stylesheet> } ``` For example: ```css @container (width > 400px) { h2 { font-size: 1.5em; } } /* with an optional <container-name> */ @container tall (height > 30rem) { h2 { line-height: 1.6; } } ``` ### Values - `<container-condition>` - : An optional `<container-name>` and a `<container-query>`. Styles defined in the `<stylesheet>` are applied if the condition is true. - `<container-name>` - : Optional. The name of the container that the styles will be applied to when the query evaluates to true, specified as an {{cssxref("ident")}}. - `<container-query>` - : A set of features that are evaluated against the query container when the size of the container changes. - `<stylesheet>` - : A set of CSS declarations. ### Logical keywords in container queries Logical keywords can be used to define the container condition: - `and` combines two or more conditions. - `or` combines two or more conditions. - `not` negates the condition. Only one 'not' condition is allowed per container query and cannot be used with the `and` or `or` keywords. ```css @container (width > 400px) and (height > 400px) { /* <stylesheet> */ } @container (width > 400px) or (height > 400px) { /* <stylesheet> */ } @container not (width < 400px) { /* <stylesheet> */ } ``` ### Named containment contexts A containment context can be named using the {{cssxref("container-name")}} property. ```css .post { container-name: sidebar; container-type: inline-size; } ``` The shorthand syntax for this is to use {{cssxref("container")}} in the form `container: <name> / <type>`, for example: ```css .post { container: sidebar / inline-size; } ``` In container queries, the {{cssxref("container-name")}} property is used to filter the set of containers to those with a matching query container name: ```css @container sidebar (width > 400px) { /* <stylesheet> */ } ``` Details about usage and naming restrictions are described in the {{cssxref("container-name")}} page. ### Descriptors The following descriptors can be used within the container condition: - `aspect-ratio` - : The {{cssxref("aspect-ratio")}} of the container calculated as the width to the height of the container expressed as a {{cssxref("ratio")}} value. - `block-size` - : The {{cssxref("block-size")}} of the container expressed as a {{cssxref("length")}} value. - `height` - : The height of the container expressed as a {{cssxref("length")}} value. - `inline-size` - : The {{cssxref("inline-size")}} of the container expressed as a {{cssxref("length")}} value. - `orientation` - : The [orientation](/en-US/docs/Web/CSS/@media/orientation) of the container, either `landscape` or `portrait`. - `width` - : The width of the container expressed as a {{cssxref("length")}} value. ## Examples ### Setting styles based on a container's size Consider the following example of a card component with a title and some text: ```html <div class="post"> <div class="card"> <h2>Card title</h2> <p>Card content</p> </div> </div> ``` A container context can be created using the `container-type` property, in this case using the `inline-size` value on the `.post` class. You can then use the `@container` at-rule to apply styles to the element with the `.card` class in a container that's narrower than `650px`. ```js hidden const post = document.querySelector(".post"); const span = document.createElement("span"); span.innerHTML = ".post width: " + post.clientWidth + "px"; post.parentNode.insertBefore(span, post.nextSibling); // update on resize window.addEventListener("resize", () => { span.innerHTML = ".post width: " + post.clientWidth + "px"; }); ``` ```css hidden span { display: block; text-align: center; } .card { margin: 10px; border: 2px dotted; font-size: 1.5em; } .post { border: 2px solid; } ``` ```css /* A container context based on inline size */ .post { container-type: inline-size; } /* Apply styles if the container is narrower than 650px */ @container (width < 650px) { .card { width: 50%; background-color: gray; font-size: 1em; } } ``` {{EmbedLiveSample("Setting_styles_based_on_a_container's_size", "100%", 230)}} ### Creating named container contexts Given the following HTML example which is a card component with a title and some text: ```html <div class="post"> <div class="card"> <h2>Card title</h2> <p>Card content</p> </div> </div> ``` First, create a container context using the `container-type` and `container-name` properties. The shorthand syntax for this declaration is described in the {{cssxref("container")}} page. ```css .post { container-type: inline-size; container-name: summary; } ``` Next, target that container by adding the name to the container query: ```css @container summary (min-width: 400px) { .card { font-size: 1.5em; } } ``` ### Nested container queries It's not possible to target multiple containers in a single container query. It is possible to nest container queries which has the same effect. The following query evaluates to true and applies the declared style if the container named `summary` is wider than `400px` and has an ancestor container wider than `800px`: ```css @container summary (min-width: 400px) { @container (min-width: 800px) { /* <stylesheet> */ } } ``` ### Container style queries {{CSSRef}}{{SeeCompatTable}} Container queries can also evaluate the computed style of the container element. A _container style query_ is a `@container` query that uses one or more `style()` functional notations. The boolean syntax and logic combining style features into a style query is the same as for [CSS feature queries](/en-US/docs/Web/CSS/CSS_conditional_rules/Using_feature_queries). ```css @container style(<style-feature>), not style(<style-feature>), style(<style-feature>) and style(<style-feature>), style(<style-feature>) or style(<style-feature>) { /* <stylesheet> */ } ``` The parameter of each `style()` is a single `<style-feature>`. A **`<style-feature>`** is a valid CSS [declaration](/en-US/docs/Web/CSS/Syntax#css_declarations), a CSS property, or a [`<custom-property-name>`](/en-US/docs/Web/CSS/var#values). ```css @container style(--themeBackground), not style(background-color: red), style(color: green) and style(background-color: transparent), style(--themeColor: blue) or style(--themeColor: purple) { /* <stylesheet> */ } ``` A style feature without a value evaluates to true if the computed value is different from the initial value for the given property. If the `<style-feature>` passed as the `style()` function's argument is a declaration, the style query evaluates to true if the declaration's value is the same as the computed value of that property for the container being queried. Otherwise, it resolves to false. The following container query checks if the {{cssxref("computed_value")}} of the container element's `--accent-color` is `blue`: ```css @container style(--accent-color: blue) { /* <stylesheet> */ } ``` > **Note:** If a custom property has a value of `blue`, the equivalent hexidecimal code `#0000ff` will not match unless the property has been defined as a color with {{cssxref("@property")}} so the browser can properly compare computed values. Style features that query a shorthand property are true if the computed values match for each of its longhand properties, and false otherwise. For example, `@container style(border: 2px solid red)` will resolve to true if all 12 longhand properties (`border-bottom-style`, etc.) that make up that shorthand are true. The global `revert` and `revert-layer` are invalid as values in a `<style-feature>` and cause the container style query to be false. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Container queries](/en-US/docs/Web/CSS/CSS_containment/Container_queries) - [Using container size and style queries](/en-US/docs/Web/CSS/CSS_containment/Container_size_and_style_queries) - {{Cssxref("container-name")}} - {{Cssxref("container-type")}} - {{Cssxref("contain")}} - {{Cssxref("content-visibility")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/inline_formatting_context/index.md
--- title: Inline formatting context slug: Web/CSS/Inline_formatting_context page-type: guide --- {{CSSRef}} This article explains the inline formatting context. ## Core concepts The inline formatting context is part of the visual rendering of a web page. Inline boxes are laid out one after the other, in the direction sentences run in the writing mode in use: - In a horizontal writing mode, boxes are laid out horizontally, starting on the left. - In a vertical writing mode they would be laid out vertically starting at the top. In the example below, the two ({{HTMLElement("div")}}) elements with the black borders form a [block formatting context](/en-US/docs/Web/CSS/CSS_display/Block_formatting_context), inside which each word participates in an inline formatting context. The boxes in the horizontal writing mode run horizontally, and the vertical writing mode boxes run vertically. {{EmbedGHLiveSample("css-examples/inline-formatting/inline.html", '100%', 720)}} Boxes forming a line are contained by a rectangular area called a line box. This box will be large enough to contain all of the inline boxes in that line; when there is no more room in the inline direction another line will be created. Therefore, a paragraph is a set of inline line boxes, stacked in the block direction. When an inline box is split, margins, borders, and padding have no visual effect where the split occurs. In the next example there is a ({{HTMLElement("span")}}) element wrapping a set of words wrapping onto two lines. The border on the `<span>` breaks at the wrapping point. {{EmbedGHLiveSample("css-examples/inline-formatting/break.html", '100%', 720)}} Margins, borders, and padding in the inline direction are respected. In the example below you can see how the margin, border, and padding on the inline `<span>` element are added. {{EmbedGHLiveSample("css-examples/inline-formatting/mbp.html", '100%', 920)}} > **Note:** I am using the logical, flow-relative properties β€” {{cssxref("padding-inline-start")}} rather than {{cssxref("padding-left")}} β€” so that they work in the inline dimension whether the text is horizontal or vertical. Read more about these properties in [Logical Properties and Values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values). ## Alignment in the block direction Inline boxes may be aligned in the block direction in different ways, using the {{cssxref("vertical-align")}} property, which will align on the block axis in vertical writing modes (therefore not vertically at all!). In the example below the large text is making the line box of the first sentence larger, therefore the `vertical-align` property can be used to align the inline boxes either side of it. I have used the value `top`, try changing it to `middle`, `bottom`, or `baseline`. {{EmbedGHLiveSample("css-examples/inline-formatting/align.html", '100%', 920)}} ## Alignment in the inline direction If there is additional space in the inline direction, the {{cssxref("text-align")}} property can be used to align the inline boxes within their line box. Try changing the value of `text-align` below to `end`. {{EmbedGHLiveSample("css-examples/inline-formatting/text-align.html", '100%', 920)}} ## Effect of floats Line boxes usually have the same size in the inline direction, therefore the same width if working in a horizontal writing mode, or height if working in a vertical writing mode. If there is a {{cssxref("float")}} within the same block formatting context however, the float will cause the line boxes that wrap the float to become shorter. {{EmbedGHLiveSample("css-examples/flow/formatting-contexts/float.html", '100%', 720)}} ## See also - [Block formatting context](/en-US/docs/Web/CSS/CSS_display/Block_formatting_context) - [Visual Formatting Model](/en-US/docs/Web/CSS/Visual_formatting_model)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_-moz-handler-disabled/index.md
--- title: ":-moz-handler-disabled" slug: Web/CSS/:-moz-handler-disabled page-type: css-pseudo-class status: - non-standard --- {{CSSRef}} {{Non-standard_header}} The **`:-moz-handler-disabled`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) is a [Mozilla extension](/en-US/docs/Web/CSS/Mozilla_Extensions) that matches elements that can't be displayed because their handlers have been disabled by the user. > **Note:** This selector is mainly intended to be used by theme developers. ## Syntax ```css :-moz-handler-disabled { /* ... */ } ``` ## Specifications Not part of any standard. ## See also - {{ cssxref(":-moz-handler-blocked") }} - {{ cssxref(":-moz-handler-crashed") }}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/image-rendering/index.md
--- title: image-rendering slug: Web/CSS/image-rendering page-type: css-property browser-compat: css.properties.image-rendering --- {{CSSRef}} The **`image-rendering`** [CSS](/en-US/docs/Web/CSS) property sets an image scaling algorithm. The property applies to an element itself, to any images set in its other properties, and to its descendants. {{EmbedInteractiveExample("pages/css/image-rendering.html")}} The {{Glossary("user agent")}} will scale an image when the page author specifies dimensions other than its natural size. Scaling may also occur due to user interaction (zooming). For example, if the natural size of an image is `100Γ—100px`_,_ but its actual dimensions are `200Γ—200px` (or `50Γ—50px`), then the image will be upscaled (or downscaled) using the algorithm specified by `image-rendering`. This property has no effect on non-scaled images. ## Syntax ```css /* Keyword values */ image-rendering: auto; image-rendering: crisp-edges; image-rendering: pixelated; /* Global values */ image-rendering: inherit; image-rendering: initial; image-rendering: revert; image-rendering: revert-layer; image-rendering: unset; ``` ### Values - `auto` - : The scaling algorithm is UA dependent. Since version 1.9 (Firefox 3.0), Gecko uses _bilinear_ resampling (high quality). - `smooth` {{Experimental_Inline}} - : The image should be scaled with an algorithm that maximizes the appearance of the image. In particular, scaling algorithms that "smooth" colors are acceptable, such as bilinear interpolation. This is intended for images such as photos. - `high-quality` {{Experimental_Inline}} - : Identical to `smooth`, but with a preference for higher-quality scaling. If system resources are constrained, images with `high-quality` should be prioritized over those with any other value, when considering which images to degrade the quality of and to what degree. - `crisp-edges` - : The image is scaled with an algorithm such as "nearest neighbor" that preserves contrast and edges in the image. Generally intended for images such as pixel art or line drawings, no blurring or color smoothing occurs. - `pixelated` - : The image is scaled with the "nearest neighbor" or similar algorithm to the nearest integer multiple of the original image size, then uses smooth interpolation to bring the image to the final desired size. This is intended to preserve a "pixelated" look without introducing scaling artifacts when the upscaled resolution isn't an integer multiple of the original. > **Note:** The values `optimizeQuality` and `optimizeSpeed` present in an early draft (and coming from its SVG counterpart {{SVGAttr("image-rendering")}}) are defined as synonyms for the `smooth` and `pixelated` values respectively. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting image scaling algorithms In practical use, the `pixelated` and `crisp-edges` rules can be combined to provide some fallback for each other. (Just prepend the actual rules with the fallback.) The [Canvas API](/en-US/docs/Web/API/Canvas_API) can provide a [fallback solution for `pixelated`](http://phrogz.net/tmp/canvas_image_zoom.html) through manual image data manipulation or with [`imageSmoothingEnabled`](/en-US/docs/Web/API/CanvasRenderingContext2D/imageSmoothingEnabled). ```html hidden <div> <img class="auto" alt="A small photo of some white and yellow flower against a leafy green background. The image is about 33% smaller than the size it is being displayed at. This upscaling causes the image to appear blurry, with notable soft edges between objects." src="blumen.jpg" /> <img class="pixelated" alt="The same photo as the previous image, which is also being upscaled the same amount. Browsers that support the pixelated value for the image-rendering property display the image as very pixelated. Individual pixels are clearly visible and edges appear much sharper." src="blumen.jpg" /> <img class="crisp-edges" alt="The same photo as the previous images, which is also being upscaled the same amount. Browsers that support the crisp-edges value for the image-rendering property display the image as very pixelated. In these examples, there is virtually no perceivable difference between the pixelated and crisp-edges versions." src="blumen.jpg" /> </div> ``` ```css hidden img { height: 200px; } ``` #### CSS ```css .auto { image-rendering: auto; } .pixelated { image-rendering: pixelated; } .crisp-edges { image-rendering: -webkit-optimize-contrast; image-rendering: crisp-edges; } ``` #### Result {{EmbedLiveSample('Setting_image_scaling_algorithms')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} > **Note:** Although `crisp-edges` is supposed to use a pixel-art scaler like in the specification example, in practice no browsers (as of January 2020) do so. [In Firefox](https://searchfox.org/mozilla-central/rev/1061fae5e225a99ef5e43dbdf560a91a0c0d00d1/gfx/wr/webrender/src/resource_cache.rs#1356), `crisp-edges` or `pixelated` is interpreted as nearest-neighbor, and `auto` is interpolated as trilinear or linear. > > For behavior on Chromium and Safari (WebKit), see the [`GetInterpolationQuality`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/style/computed_style.cc;l=1160) function and [`CSSPrimitiveValue::operator ImageRendering()`](https://github.com/WebKit/WebKit/blob/9b26fc6081e0db8a1304cf4b4f8f1c67efb9bc0c/Source/WebCore/css/CSSPrimitiveValueMappings.h#L4045) respectively. ## See also - Other image-related CSS properties: {{cssxref("object-fit")}}, {{cssxref("object-position")}}, {{cssxref("image-orientation")}}, {{cssxref("image-rendering")}}, {{cssxref("image-resolution")}}.
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/@font-palette-values/index.md
--- title: "@font-palette-values" slug: Web/CSS/@font-palette-values page-type: css-at-rule browser-compat: css.at-rules.font-palette-values --- {{CSSRef}} The **`@font-palette-values`** [CSS](/en-US/docs/Web/CSS) [at-rule](/en-US/docs/Web/CSS/At-rule) allows you to customize the default values of [font-palette](/en-US/docs/Web/CSS/font-palette) created by the font-maker. ## Syntax ```css @font-palette-values --identifier { font-family: Bixa; } .my-class { font-palette: --identifier; } ``` The [&lt;dashed-ident&gt;](/en-US/docs/Web/CSS/dashed-ident) is a user defined identifier, that while it looks like a [CSS custom property](/en-US/docs/Web/CSS/Using_CSS_custom_properties) behaves in a different way and is not wrapped in a [CSS var() function](/en-US/docs/Web/CSS/var). ### Descriptors - [font-family](/en-US/docs/Web/CSS/@font-palette-values/font-family) - : Specifies the name of the font family that this palette can be applied to. - [base-palette](/en-US/docs/Web/CSS/@font-palette-values/base-palette) - : Specifies the name or index of the base-palette, created by the font-maker, to use. - [override-colors](/en-US/docs/Web/CSS/@font-palette-values/override-colors) - : Specifies the colors in the base palette to override. ## Formal syntax {{csssyntax}} ## Examples ### Overriding colors in an existing palette This example shows how you can change some or all of the colors in a color font. #### HTML ```html <p>default colors</p> <p class="alternate">alternate colors</p> ``` #### CSS ```css @import url(https://fonts.googleapis.com/css2?family=Bungee+Spice); p { font-family: "Bungee Spice"; font-size: 2rem; } @font-palette-values --Alternate { font-family: "Bungee Spice"; override-colors: 0 #00ffbb, 1 #007744; } .alternate { font-palette: --Alternate; } ``` #### Result When overriding colors of the normal or base-palette at index 0 you do not need to declare which base-palette to use. This should only be done when overriding a different base-palette. If you are overriding all the colors then there is also no need to specify the base-palette to use. {{EmbedLiveSample("Overriding colors in an existing palette")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("font-palette", "font-palette")}} property - {{cssxref("@font-palette-values/font-family", "font-family")}} descriptor - {{cssxref("@font-palette-values/base-palette", "base-palette")}} descriptor - {{cssxref("@font-palette-values/override-colors", "override-colors")}} descriptor - {{domxref("CSSFontPaletteValuesRule")}}
0
data/mdn-content/files/en-us/web/css/@font-palette-values
data/mdn-content/files/en-us/web/css/@font-palette-values/font-family/index.md
--- title: font-family slug: Web/CSS/@font-palette-values/font-family page-type: css-at-rule-descriptor browser-compat: css.at-rules.font-palette-values.font-family --- {{CSSRef}} The [@font-palette-values](/en-US/docs/Web/CSS/@font-palette-values) [descriptor](/en-US/docs/Glossary/CSS_Descriptor) **`font-family`** is used to specify which font-family palette values are to be applied to. This need to match exactly the values used when setting the CSS [font-family](/en-US/docs/Web/CSS/font-family). ## Syntax ```css @font-palette-values --Dark-mode { font-family: "Bungee Spice"; /* other palette settings follow */ } ``` Other palette values that follow apply only to the specified font family. You can create [@font-palette-values](/en-US/docs/Web/CSS/@font-palette-values) for other font families by using the same [&lt;dashed-ident&gt;s](/en-US/docs/Web/CSS/dashed-ident). This means that if you have multiple Color Fonts and can use the same identifier for each. ### Values - `<family-name>` - : Specifies the name of the [font-family](/en-US/docs/Web/CSS/font-family). ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Using matching family names In this example, when the `font-family` descriptor is used in the [@font-palette-values](/en-US/docs/Web/CSS/@font-palette-values) at-rule, the same value is used for the `font-family`, as when it is declared. #### HTML ```html <h2>This is spicy</h2> <h2 class="extra-spicy">This is extra hot & spicy</h2> ``` #### CSS ```css @import url(https://fonts.googleapis.com/css2?family=Bungee+Spice); @font-palette-values --bungee-extra-spicy { font-family: "Bungee Spice"; override-colors: 0 DarkRed, 1 Red; } h2 { font-family: "Bungee Spice"; } h2.extra-spicy { font-palette: --bungee-extra-spicy; } ``` #### Result {{EmbedLiveSample("Using matching family names")}} ### Using the same palette identifier for multiple font-families In this example, two [@font-palette-values](/en-US/docs/Web/CSS/@font-palette-values) at-rules are set for two font families, but both the at-rules use the same dashed-ident identifier, `--Dark Mode`. This helps to set the [font-palette](/en-US/docs/Web/CSS/font-palette) property for multiple elements, `h1` and `h2` in this case, at the same time. This can be useful when you want to update font colors to match your site's branding. ```css @font-palette-values --Dark-Mode { font-family: "Bungee Spice"; /* palette settings for Bungee Spice */ } @font-palette-values --Dark-Mode { font-family: Bixa; /* palette settings for Bixa */ } h1, h2 { font-palette: --Dark-Mode; } h1 { font-family: "Bungee Spice"; } h2 { font-family: Bixa; } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("@font-face/font-family", "font-family")}} - {{cssxref("@font-palette-values/", "@font-palette-values")}} - {{cssxref("@font-palette-values/font-family", "font-family")}} descriptor - {{cssxref("@font-palette-values/override-colors", "override-colors")}} descriptor - {{cssxref("font-palette/", "font-palette")}} property - {{domxref("CSSFontPaletteValuesRule.fontFamily")}}
0
data/mdn-content/files/en-us/web/css/@font-palette-values
data/mdn-content/files/en-us/web/css/@font-palette-values/base-palette/index.md
--- title: base-palette slug: Web/CSS/@font-palette-values/base-palette page-type: css-at-rule-descriptor browser-compat: css.at-rules.font-palette-values.base-palette --- {{CSSRef}} The **`base-palette`** CSS [descriptor](/en-US/docs/Glossary/CSS_Descriptor) is used to specify the name or index of a pre-defined palette to be used for creating a new palette. If the specified `base-palette` does not exist, then the palette defined at index 0 will be used. ## Syntax ```css @font-palette-values --one { base-palette: 1; } ``` The `base-palette` [descriptor](/en-US/docs/Glossary/CSS_Descriptor) is specified using a zero-based index of the font-maker created palettes. ### Values - `<index>` - : Specifies the index of the pre-defined palette to use. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Changing the default palette in a font Using the [Rocher Color Font](https://www.harbortype.com/fonts/rocher-color/), this example shows two instances of switching the default palette in the font to an alternate palette created by the font-maker. #### HTML ```html <h2>default base-palette</h2> <h2 class="two">base-palette at index 2</h2> <h2 class="five">base-palette at index 5</h2> ``` #### CSS ```css @font-face { font-family: "Rocher"; src: url("[path-to-font]/RocherColorGX.woff2") format("woff2"); } h2 { font-family: "Rocher"; } @font-palette-values --two { font-family: "Rocher"; base-palette: 2; } @font-palette-values --five { font-family: "Rocher"; base-palette: 5; } .two { font-palette: --two; } .five { font-palette: --five; } ``` #### Result ![Example showing 3 different base-palettes of Rocher color font](./rocher-color-font-alt-base-palettes.jpg) ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("@font-palette-values/", "@font-palette-values")}} - {{cssxref("@font-palette-values/font-family", "font-family")}} descriptor - {{cssxref("@font-palette-values/override-colors", "override-colors")}} descriptor - {{cssxref("font-palette/", "font-palette")}} property - {{domxref("CSSFontPaletteValuesRule.basePalette")}}
0
data/mdn-content/files/en-us/web/css/@font-palette-values
data/mdn-content/files/en-us/web/css/@font-palette-values/override-colors/index.md
--- title: override-colors slug: Web/CSS/@font-palette-values/override-colors page-type: css-at-rule-descriptor browser-compat: css.at-rules.font-palette-values.override-colors --- {{CSSRef}} The **`override-colors`** CSS [descriptor](/en-US/docs/Glossary/CSS_Descriptor) is used to override colors in the chosen [base-palette](/en-US/docs/Web/CSS/@font-palette-values/base-palette) for a color font. ## Syntax ```css /* basic syntax */ override-colors: <index of color> <color>; /* using color names */ override-colors: 0 red; /* using hex-color */ override-colors: 0 #f00; /* using rgb */ override-colors: 0 rgb(255 0 0); /* overriding multiple colors */ override-colors: 0 #f00, 1 #0f0, 2 #00f; /* overriding multiple colors with readability */ override-colors: 0 #f00, 1 #0f0, 2 #00f; ``` The `override-colors` [descriptor](/en-US/docs/Glossary/CSS_Descriptor) takes a comma-separated list of the color index and new color value. The color index is zero-based and any [color value](/en-US/docs/Web/CSS/color_value) can be used. For each key-value pair of index and color, the color with the index in the specified [base-palette](/en-US/docs/Web/CSS/@font-palette-values/base-palette) will be overwritten. If the color font does not have a color at the specified index, it will be ignored. ### Values - `[ <integer [0,∞]> <absolute-color-base> ]` - : Specifies the index of a color in a [base-palette](/en-US/docs/Web/CSS/@font-palette-values/base-palette) and the color to overwrite it with. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Changing colors of emojis This example shows how to override colors in the [Noto Color Emoji](https://fonts.google.com/noto/specimen/Noto+Color+Emoji/) color font to match your site's brand. #### HTML ```html <section class="hats"> <div class="hat"> <h2>Original Hat</h2> <div class="emoji">🎩</div> </div> <div class="hat"> <h2>Red Hat</h2> <div class="emoji red-hat">🎩</div> </div> </section> ``` #### CSS ```css hidden .hats { display: flex; flex-direction: row; justify-content: space-around; } ``` ```css-nolint @font-face { font-family: "Noto Color Emoji"; font-style: normal; font-weight: 400; src: url(https://fonts.gstatic.com/l/font?kit=Yq6P-KqIXTD0t4D9z1ESnKM3-HpFabts6diywYkdG3gjD0U&skey=a373f7129eaba270&v=v24) format("woff2"); } .emoji { font-family: "Noto Color Emoji"; font-size: 3rem; } @font-palette-values --red { font-family: "Noto Color Emoji"; override-colors: 0 rgb(74 11 0), 1 rgb(149 22 1), 2 rgb(183 27 1), 3 rgb(193 28 1), 4 rgb(230 34 1); } .red-hat { font-palette: --red; } ``` #### Result {{EmbedLiveSample("Changing colors of emojis")}} ### Changing a color in an alternate base-palette Using [Rocher Color Font](https://www.harbortype.com/fonts/rocher-color/), this example shows how to override one color in the font. #### HTML ```html <h2 class="normal-palette">Normal Palette</h2> <h2 class="override-palette">Override Palette</h2> ``` #### CSS ```css @font-face { font-family: "Rocher"; src: url("[path-to-font]/RocherColorGX.woff2") format("woff2"); } h2 { font-family: "Rocher"; } @font-palette-values --override-palette { font-family: "Rocher"; base-palette: 3; } @font-palette-values --override-palette { font-family: "Rocher"; base-palette: 3; override-colors: 0 rebeccapurple; } .normal-palette { font-palette: --normal-palette; } .override-palette { font-palette: --override-palette; } ``` #### Result This example shows the that in `base-palette` `3`, the color at index 0 is overridden with `rebeccapurple`. ![Example showing base-palette and base-palette with 1 color overridden](override-base-palette-color.jpg) ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("@font-palette-values/", "@font-palette-values")}} - {{cssxref("@font-palette-values/base-palette", "base-palette")}} - {{cssxref("@font-palette-values/font-family", "font-family")}} - {{cssxref("font-palette/", "font-palette")}} - {{domxref("CSSFontPaletteValuesRule.overrideColors")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/place-self/index.md
--- title: place-self slug: Web/CSS/place-self page-type: css-shorthand-property browser-compat: css.properties.place-self --- {{CSSRef}} The **`place-self`** [CSS](/en-US/docs/Web/CSS) [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) allows you to align an individual item in both the block and inline directions at once (i.e. the {{cssxref("align-self")}} and {{cssxref("justify-self")}} properties) in a relevant layout system such as [Grid](/en-US/docs/Web/CSS/CSS_grid_layout) or [Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout). If the second value is not present, the first value is also used for it. {{EmbedInteractiveExample("pages/css/place-self.html")}} ## Constituent properties This property is a shorthand for the following CSS properties: - [`align-self`](/en-US/docs/Web/CSS/align-self) - [`justify-self`](/en-US/docs/Web/CSS/justify-self) ## Syntax ```css /* Keyword values */ place-self: auto center; place-self: normal start; /* Positional alignment */ place-self: center normal; place-self: start auto; place-self: end normal; place-self: self-start auto; place-self: self-end normal; place-self: flex-start auto; place-self: flex-end normal; /* Baseline alignment */ place-self: baseline normal; place-self: first baseline auto; place-self: last baseline normal; place-self: stretch auto; /* Global values */ place-self: inherit; place-self: initial; place-self: revert; place-self: revert-layer; place-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. ## 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 has [`justify-items`](/en-US/docs/Web/CSS/justify-items) and [`align-items`](/en-US/docs/Web/CSS/align-items) values of `stretch` β€” the defaults β€” which causes the grid items to stretch across the entire width of their cells. The second, third, and fourth grid items are then given different values of `place-self`, to show how these override the default placements. These values cause the grid items to span only as wide/tall as their content width/height, and align in different positions across their cells, in the block and inline directions. #### HTML ```html <article class="container"> <span>First</span> <span>Second</span> <span>Third</span> <span>Fourth</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: 80px; grid-gap: 10px; margin: 20px; width: 300px; } span:nth-child(2) { place-self: start center; } span:nth-child(3) { place-self: center start; } span:nth-child(4) { place-self: end; } article span { background-color: black; color: white; margin: 1px; text-align: center; } article, span { padding: 10px; border-radius: 7px; } ``` #### Result {{EmbedLiveSample('Simple_demonstration', '100%', 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-self")}} property - The {{cssxref("justify-self")}} property
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/offset-anchor/index.md
--- title: offset-anchor slug: Web/CSS/offset-anchor page-type: css-property browser-compat: css.properties.offset-anchor --- {{CSSRef}} The **`offset-anchor`** [CSS](/en-US/docs/Web/CSS) property specifies the point inside the box of an element traveling along an {{cssxref("offset-path")}} that is actually moving along the path. {{EmbedInteractiveExample("pages/css/offset-anchor.html")}} ## Syntax ```css /* Keyword values */ offset-anchor: top; offset-anchor: bottom; offset-anchor: left; offset-anchor: right; offset-anchor: center; offset-anchor: auto; /* <percentage> values */ offset-anchor: 25% 75%; /* <length> values */ offset-anchor: 0 0; offset-anchor: 1cm 2cm; offset-anchor: 10ch 8em; /* Edge offsets values */ offset-anchor: bottom 10px right 20px; offset-anchor: right 3em bottom 10px; /* Global values */ offset-anchor: inherit; offset-anchor: initial; offset-anchor: revert; offset-anchor: revert-layer; offset-anchor: unset; ``` ### Values - `auto` - : `offset-anchor` is given the same value as the element's {{cssxref("transform-origin")}}, unless {{cssxref("offset-path")}} is `none`, in which case it takes its value from {{cssxref("offset-position")}}. - `<position>` - : A {{cssxref("&lt;position&gt;")}} defines an x/y coordinate, to place an item relative to the edges of an element's box. It can be defined using one to four values. For more specifics, see the {{cssxref("&lt;position&gt;")}} and {{cssxref("background-position")}} reference pages. Note that the 3-value position syntax does not work for any usage of `<position>`, except for in `background(-position)`. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting various offset-anchor values In the following example, we have three {{htmlelement("div")}} elements nested in {{htmlelement("section")}} elements. Each `<div>` is given the same {{cssxref("offset-path")}} (a horizontal line 200 pixels long) and animated to move along it. The three are then given different {{cssxref("background-color")}} and `offset-anchor` values. Each `<section>` has been styled with a linear gradient to give it a horizontal line running through its center, to give you a visual display of where the `<div>`'s offset paths are running. This allows you to see what effect the different `offset-anchor` values have β€” the first one, `auto`, causes the `<div>`'s center point to move along the path. The other two cause the `<div>`'s top-right and bottom-left points to move along the path, respectively. #### HTML ```html <section> <div class="offset-anchor1"></div> </section> <section> <div class="offset-anchor2"></div> </section> <section> <div class="offset-anchor3"></div> </section> ``` #### CSS ```css div { offset-path: path("M 0,20 L 200,20"); animation: move 3000ms infinite alternate ease-in-out; width: 40px; height: 40px; } section { background-image: linear-gradient( to bottom, transparent, transparent 49%, #000 50%, #000 51%, transparent 52% ); border: 1px solid #ccc; margin-bottom: 10px; } .offset-anchor1 { offset-anchor: auto; background: cyan; } .offset-anchor2 { offset-anchor: right top; background: purple; } .offset-anchor3 { offset-anchor: left bottom; background: magenta; } @keyframes move { 0% { offset-distance: 0%; } 100% { offset-distance: 100%; } } ``` #### Result {{EmbedLiveSample('Setting_various_offset-anchor_values', '100%', '300')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("offset")}} - {{cssxref("offset-distance")}} - {{cssxref("offset-rotate")}} - [SVG `<path>`](/en-US/docs/Web/SVG/Tutorial/Paths)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_autofill/index.md
--- title: ":autofill" slug: Web/CSS/:autofill page-type: css-pseudo-class browser-compat: css.selectors.autofill --- {{CSSRef}} The **`:autofill`** CSS [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) matches when an {{HTMLElement("input")}} element has its value autofilled by the browser. The class stops matching if the user edits the field. {{EmbedInteractiveExample("pages/tabbed/pseudo-class-autofill.html", "tabbed-shorter")}} > **Note:** The user agent style sheets of many browsers use `!important` in their `:-webkit-autofill` style declarations, making them non-overridable by webpages without resorting to JavaScript hacks. For example Chrome has the following in its internal stylesheet: > > ```css > background-color: rgb(232 240 254) !important; > background-image: none !important; > color: -internal-light-dark(black, white) !important; > ``` > > This means that you cannot set the {{cssxref('background-color')}}, {{cssxref('background-image')}}, or {{cssxref('color')}} in your own rules. ## Syntax ```css :autofill { /* ... */ } ``` ## Examples The following example demonstrates the use of the `:autofill` pseudo-class to change the border of a text field that has been autocompleted by the browser. For the best browser compatibility use both `:-webkit-autofill` and `:autofill`. ```css input { border: 3px solid grey; border-radius: 3px; } input:-webkit-autofill { border: 3px solid blue; } input:autofill { border: 3px solid blue; } ``` ```html <form method="post" action=""> <label for="email">Email</label> <input type="email" name="email" id="email" autocomplete="email" /> </form> ``` {{EmbedLiveSample('Examples')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Chromium issue 46543: Auto-filled input text box yellow background highlight cannot be turned off](https://crbug.com/46543) - [WebKit bug 66032: Allow site authors to override autofilled fields' colors.](https://webkit.org/b/66032) - [Mozilla bug 740979: implement `:-moz-autofill` pseudo-class on input elements with an autofilled value](https://bugzil.la/740979) - [User Interface Module Level 4: more selectors](https://wiki.csswg.org/spec/css4-ui#more-selectors)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/forced-color-adjust/index.md
--- title: forced-color-adjust slug: Web/CSS/forced-color-adjust page-type: css-property browser-compat: css.properties.forced-color-adjust --- {{CSSRef}} The **`forced-color-adjust`** CSS property allows authors to opt certain elements out of forced colors mode. This then restores the control of those values to CSS. ## Syntax ```css forced-color-adjust: auto; forced-color-adjust: none; /* Global values */ forced-color-adjust: inherit; forced-color-adjust: initial; forced-color-adjust: revert; forced-color-adjust: revert-layer; forced-color-adjust: unset; ``` The `forced-color-adjust` property's value must be one of the following keywords. ### Values - `auto` - : The element's colors are adjusted by the {{Glossary("user agent")}} in forced colors mode. This is the default. - `none` - : The element's colors are not automatically adjusted by the {{Glossary("user agent")}} in forced colors mode. ## Usage notes This property should only be used to makes changes that will support a user's color and contrast requirements. For example, if you become aware that the color optimizations made by the {{Glossary("user agent")}} result in a poor experience when in a high contrast or dark mode. Using this property would enable tweaking of the result in that mode to provide a better experience. **It should not be used to prevent user choices being respected**. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Preserving colors In the example below the first box will use the color scheme that the user has set. For example in Windows High Contrast mode black scheme it will have a black background and white text. The second box will preserve the site colors set on the `.box` class. By using the [`forced-colors`](/en-US/docs/Web/CSS/@media/forced-colors) media feature you could add any other optimizations for forced color mode alongside the `forced-color-adjust` property. #### CSS ```css .box { border: 5px solid grey; background-color: #ccc; width: 300px; margin: 20px; padding: 10px; } @media (forced-colors: active) { .forced { forced-color-adjust: none; } } ``` #### HTML ```html <div class="box"> <p>This is a box which should use your color preferences.</p> </div> <div class="box forced"> <p>This is a box which should stay the colors set by the site.</p> </div> ``` #### Result {{EmbedLiveSample("Preserving_colors", 640, 300)}} The following screenshot shows the image above in Windows High Contrast Mode: ![The example above in high contrast mode shows the first box with a black background the second with the grey background of the CSS.](windows-high-contrast.jpg) ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Applying color to HTML elements using CSS](/en-US/docs/Web/CSS/CSS_colors/Applying_color) - [Styling for Windows high contrast with standards for forced colors.](https://blogs.windows.com/msedgedev/2020/09/17/styling-for-windows-high-contrast-with-new-standards-for-forced-colors/) - {{cssxref("print-color-adjust")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-block-start/index.md
--- title: border-block-start slug: Web/CSS/border-block-start page-type: css-shorthand-property browser-compat: css.properties.border-block-start --- {{CSSRef}} The **`border-block-start`** [CSS](/en-US/docs/Web/CSS) property is a [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) for setting the individual logical block-start border property values in a single place in the style sheet. {{EmbedInteractiveExample("pages/css/border-block-start.html")}} ## Constituent properties This property is a shorthand for the following CSS properties: - [`border-block-start-color`](/en-US/docs/Web/CSS/border-block-start-color) - [`border-block-start-style`](/en-US/docs/Web/CSS/border-block-start-style) - [`border-block-start-width`](/en-US/docs/Web/CSS/border-block-start-width) ## Syntax ```css border-block-start: 1px; border-block-start: 2px dotted; border-block-start: medium dashed blue; /* Global values */ border-block-start: inherit; border-block-start: initial; border-block-start: revert; border-block-start: revert-layer; border-block-start: unset; ``` `border-block-start` can be used to set the values for one or more of {{cssxref("border-block-start-width")}}, {{cssxref("border-block-start-style")}}, and {{cssxref("border-block-start-color")}}. The physical border to which it maps depends on the element's writing mode, directionality, and text orientation. It corresponds to the {{cssxref("border-top")}}, {{cssxref("border-right")}}, {{cssxref("border-bottom")}}, or {{cssxref("border-left")}} property depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. Related properties are {{cssxref("border-block-end")}}, {{cssxref("border-inline-start")}}, and {{cssxref("border-inline-end")}}, which define the other borders of the element. ### Values The `border-block-start` is specified with one or more of the following, in any order: - `<'border-width'>` - : The width of the border. See {{cssxref("border-width")}}. - `<'border-style'>` - : The line style of the border. See {{cssxref("border-style")}}. - {{CSSXref("&lt;color&gt;")}} - : The color of the border. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Border with vertical text #### HTML ```html <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ```css div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-rl; border-block-start: 5px dashed blue; } ``` {{EmbedLiveSample("Border_with_vertical_text", 140, 140)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS Logical Properties and Values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values) - This property maps to one of the physical border properties: {{cssxref("border-top")}}, {{cssxref("border-right")}}, {{cssxref("border-bottom")}}, or {{cssxref("border-left")}}. - {{cssxref("writing-mode")}}, {{cssxref("direction")}}, {{cssxref("text-orientation")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-bottom/index.md
--- title: border-bottom slug: Web/CSS/border-bottom page-type: css-shorthand-property browser-compat: css.properties.border-bottom --- {{CSSRef}} The **`border-bottom`** [shorthand](/en-US/docs/Web/CSS/Shorthand_properties) [CSS](/en-US/docs/Web/CSS) property sets an element's bottom [border](/en-US/docs/Web/CSS/border). It sets the values of {{cssxref("border-bottom-width")}}, {{cssxref("border-bottom-style")}} and {{cssxref("border-bottom-color")}}. {{EmbedInteractiveExample("pages/css/border-bottom.html")}} As with all shorthand properties, `border-bottom` always sets the values of all of the properties that it can set, even if they are not specified. It sets those that are not specified to their default values. Consider the following code: ```css border-bottom-style: dotted; border-bottom: thick green; ``` It is actually the same as this one: ```css border-bottom-style: dotted; border-bottom: none thick green; ``` The value of {{cssxref("border-bottom-style")}} given before `border-bottom` is ignored. Since the default value of {{cssxref("border-bottom-style")}} is `none`, not specifying the `border-style` part results in no border. ## Constituent properties This property is a shorthand for the following CSS properties: - {{cssxref("border-bottom-color")}} - {{cssxref("border-bottom-style")}} - {{cssxref("border-bottom-width")}} ## Syntax ```css border-bottom: 1px; border-bottom: 2px dotted; border-bottom: medium dashed blue; /* Global values */ border-bottom: inherit; border-bottom: initial; border-bottom: revert; border-bottom: revert-layer; border-bottom: unset; ``` The three values of the shorthand property can be specified in any order, and one or two of them may be omitted. ### Values - `<br-width>` - : See {{cssxref("border-bottom-width")}}. - `<br-style>` - : See {{cssxref("border-bottom-style")}}. - {{cssxref("&lt;color&gt;")}} - : See {{cssxref("border-bottom-color")}}. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Applying a bottom border #### HTML ```html <div>This box has a border on the bottom side.</div> ``` #### CSS ```css div { border-bottom: 4px dashed blue; background-color: gold; height: 100px; width: 100px; font-weight: bold; text-align: center; } ``` #### Results {{EmbedLiveSample('Applying_a_bottom_border')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("border")}} - {{cssxref("border-block")}} - {{cssxref("outline")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-collapse/index.md
--- title: border-collapse slug: Web/CSS/border-collapse page-type: css-property browser-compat: css.properties.border-collapse --- {{CSSRef}} The **`border-collapse`** [CSS](/en-US/docs/Web/CSS) property sets whether cells inside a {{htmlElement("table")}} have shared or separate borders. {{EmbedInteractiveExample("pages/css/border-collapse.html")}} When cells are collapsed, the {{cssxref("border-style")}} value of `inset` behaves like `ridge`, and `outset` behaves like `groove`. When cells are separated, the distance between cells is defined by the {{cssxref("border-spacing")}} property. ## Syntax ```css /* Keyword values */ border-collapse: collapse; border-collapse: separate; /* Global values */ border-collapse: inherit; border-collapse: initial; border-collapse: revert; border-collapse: revert-layer; border-collapse: unset; ``` The `border-collapse` property is specified as a single keyword, which may be chosen from the list below. ### Values - `collapse` - : Adjacent cells have shared borders (the collapsed-border table rendering model). - `separate` - : Adjacent cells have distinct borders (the separated-border table rendering model). ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### A colorful table of browser engines #### HTML ```html <table class="separate"> <caption> <code>border-collapse: separate</code> </caption> <tbody> <tr> <th>Browser</th> <th>Layout Engine</th> </tr> <tr> <td class="fx">Firefox</td> <td class="gk">Gecko</td> </tr> <tr> <td class="ed">Edge</td> <td class="tr">EdgeHTML</td> </tr> <tr> <td class="sa">Safari</td> <td class="wk">Webkit</td> </tr> <tr> <td class="ch">Chrome</td> <td class="bk">Blink</td> </tr> <tr> <td class="op">Opera</td> <td class="bk">Blink</td> </tr> </tbody> </table> <table class="collapse"> <caption> <code>border-collapse: collapse</code> </caption> <tbody> <tr> <th>Browser</th> <th>Layout Engine</th> </tr> <tr> <td class="fx">Firefox</td> <td class="gk">Gecko</td> </tr> <tr> <td class="ed">Edge</td> <td class="tr">EdgeHTML</td> </tr> <tr> <td class="sa">Safari</td> <td class="wk">Webkit</td> </tr> <tr> <td class="ch">Chrome</td> <td class="bk">Blink</td> </tr> <tr> <td class="op">Opera</td> <td class="bk">Blink</td> </tr> </tbody> </table> ``` #### CSS ```css .collapse { border-collapse: collapse; } .separate { border-collapse: separate; } table { display: inline-table; margin: 1em; border: dashed 5px; } table th, table td { border: solid 3px; } .fx { border-color: orange blue; } .gk { border-color: black red; } .ed { border-color: blue gold; } .tr { border-color: aqua; } .sa { border-color: silver blue; } .wk { border-color: gold blue; } .ch { border-color: red yellow green blue; } .bk { border-color: navy blue teal aqua; } .op { border-color: red; } ``` #### Result {{ EmbedLiveSample('A_colorful_table_of_browser_engines', 400, 300) }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("border-spacing")}}, {{cssxref("border-style")}} - The `border-collapse` property alters the appearance of the {{htmlelement("table")}} HTML element.
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/shape-margin/index.md
--- title: shape-margin slug: Web/CSS/shape-margin page-type: css-property browser-compat: css.properties.shape-margin --- {{CSSRef}} The **`shape-margin`** [CSS](/en-US/docs/Web/CSS) property sets a margin for a CSS shape created using {{cssxref("shape-outside")}}. {{EmbedInteractiveExample("pages/css/shape-margin.html")}} The margin lets you adjust the distance between the edges of the shape (the **float element**) and the surrounding content. ## Syntax ```css /* <length> values */ shape-margin: 10px; shape-margin: 20mm; /* <percentage> value */ shape-margin: 60%; /* Global values */ shape-margin: inherit; shape-margin: initial; shape-margin: revert; shape-margin: revert-layer; shape-margin: unset; ``` ### Values - `<length-percentage>` - : Sets the margin of the shape to a {{cssxref("&lt;length&gt;")}} value or to a {{cssxref("&lt;percentage&gt;")}} of the width of the element's containing block. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Adding a margin to a polygon #### HTML ```html <section> <div class="shape"></div> We are not quite sure of any one thing in biology; our knowledge of geology is relatively very slight, and the economic laws of society are uncertain to every one except some individual who attempts to set them forth; but before the world was fashioned the square on the hypotenuse was equal to the sum of the squares on the other two sides of a right triangle, and it will be so after this world is dead; and the inhabitant of Mars, if one exists, probably knows its truth as we know it. </section> ``` #### CSS ```css section { max-width: 400px; } .shape { float: left; width: 150px; height: 150px; background-color: maroon; clip-path: polygon(0 0, 150px 150px, 0 150px); shape-outside: polygon(0 0, 150px 150px, 0 150px); shape-margin: 20px; } ``` #### Result {{EmbedLiveSample("Adding_a_margin_to_a_polygon", 500, 250)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS Shapes](/en-US/docs/Web/CSS/CSS_shapes) - [Overview of CSS Shapes](/en-US/docs/Web/CSS/CSS_shapes/Overview_of_shapes) - {{cssxref("shape-outside")}} - {{cssxref("shape-image-threshold")}} - {{cssxref("&lt;basic-shape&gt;")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/font-synthesis-weight/index.md
--- title: font-synthesis-weight slug: Web/CSS/font-synthesis-weight page-type: css-property browser-compat: css.properties.font-synthesis-weight --- {{CSSRef}} The **`font-synthesis-weight`** [CSS](/en-US/docs/Web/CSS) property lets you specify whether or not the browser may synthesize the bold typeface when it is missing in a font family. It is often convenient to use the shorthand property {{cssxref("font-synthesis")}} to control all typeface synthesis values. ## Syntax ```css /* Keyword values */ font-synthesis-weight: auto; font-synthesis-weight: none; /* Global values */ font-synthesis-weight: inherit; font-synthesis-weight: initial; font-synthesis-weight: revert; font-synthesis-weight: revert-layer; font-synthesis-weight: unset; ``` ### Values - `auto` - : Indicates that the missing bold typeface may be synthesized by the browser if needed. - `none` - : Indicates that the synthesis of the missing bold typeface by the browser is not allowed. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Disabling synthesis of bold typeface This example shows turning off synthesis of the bold typeface by the browser in the `Montserrat` font. #### HTML ```html <p class="english"> This is the default <strong>bold typeface</strong> and <em>oblique typeface</em>. </p> <p class="english no-syn"> The <strong>bold typeface</strong> is turned off here but not the <em>oblique typeface</em>. </p> ``` #### CSS ```css @import url("https://fonts.googleapis.com/css2?family=Montserrat&display=swap"); .english { font-family: "Montserrat", sans-serif; } .no-syn { font-synthesis-weight: none; } ``` #### Result {{EmbedLiveSample('Disabling synthesis of bold typeface', '', '100')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [font-synthesis](/en-US/docs/Web/CSS/font-synthesis) shorthand, [font-synthesis-small-caps](/en-US/docs/Web/CSS/font-synthesis-small-caps), [font-synthesis-style](/en-US/docs/Web/CSS/font-synthesis-style) - {{cssxref("font-style")}}, {{cssxref("font-variant")}}, {{cssxref("font-weight")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/orphans/index.md
--- title: orphans slug: Web/CSS/orphans page-type: css-property browser-compat: css.properties.orphans --- {{CSSRef}} The **`orphans`** [CSS](/en-US/docs/Web/CSS) property sets the minimum number of lines in a block container that must be shown at the _bottom_ of a [page](/en-US/docs/Web/CSS/CSS_paged_media), region, or [column](/en-US/docs/Web/CSS/CSS_multicol_layout). In typography, an _orphan_ is the first line of a paragraph that appears alone at the bottom of a page. (The paragraph continues on a following page.) ## Syntax ```css /* <integer> values */ orphans: 2; orphans: 3; /* Global values */ orphans: inherit; orphans: initial; orphans: revert; orphans: revert-layer; orphans: unset; ``` ### Values - {{cssxref("&lt;integer&gt;")}} - : The minimum number of lines that can stay by themselves at the bottom of a fragment before a fragmentation break. The value must be positive. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting a minimum orphan size of three lines #### HTML ```html <div> <p>This is the first paragraph containing some text.</p> <p> This is the second paragraph containing some more text than the first one. It is used to demonstrate how orphans work. </p> <p> This is the third paragraph. It has a little bit more text than the first one. </p> </div> ``` #### CSS ```css div { background-color: #8cffa0; height: 150px; columns: 3; orphans: 3; } p { background-color: #8ca0ff; } p:first-child { margin-top: 0; } ``` #### Result {{EmbedLiveSample("Setting_a_minimum_orphan_size_of_three_lines", 380, 150)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("widows")}} - [Paged media](/en-US/docs/Web/CSS/CSS_paged_media)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/font-stretch/index.md
--- title: font-stretch slug: Web/CSS/font-stretch page-type: css-property browser-compat: css.properties.font-stretch --- {{CSSRef}} The **`font-stretch`** [CSS](/en-US/docs/Web/CSS) property selects a normal, condensed, or expanded face from a font. {{EmbedInteractiveExample("pages/css/font-stretch.html")}} ## Syntax ```css /* <font-stretch-css3> keyword values */ font-stretch: normal; font-stretch: ultra-condensed; font-stretch: extra-condensed; font-stretch: condensed; font-stretch: semi-condensed; font-stretch: semi-expanded; font-stretch: expanded; font-stretch: extra-expanded; font-stretch: ultra-expanded; /* Percentage values */ font-stretch: 50%; font-stretch: 100%; font-stretch: 200%; /* Global values */ font-stretch: inherit; font-stretch: initial; font-stretch: revert; font-stretch: revert-layer; font-stretch: unset; ``` This property may be specified as a single `<font-stretch-css3>` keyword value or a single {{cssxref("&lt;percentage&gt;")}} value. ### Values - `normal` - : Specifies a normal font face. - `semi-condensed`, `condensed`, `extra-condensed`, `ultra-condensed` - : Specifies a more condensed font face than normal, with `ultra-condensed` as the most condensed. - `semi-expanded`, `expanded`, `extra-expanded`, `ultra-expanded` - : Specifies a more expanded font face than normal, with `ultra-expanded` as the most expanded. - `<percentage>` - : A {{cssxref("&lt;percentage&gt;")}} value between 50% and 200% (inclusive). Negative values are not allowed for this property. ### Keyword to numeric mapping The table below shows the mapping between the `<font-stretch-css3>` keyword values and numeric percentages: | Keyword | Percentage | | ----------------- | ---------- | | `ultra-condensed` | 50% | | `extra-condensed` | 62.5% | | `condensed` | 75% | | `semi-condensed` | 87.5% | | `normal` | 100% | | `semi-expanded` | 112.5% | | `expanded` | 125% | | `extra-expanded` | 150% | | `ultra-expanded` | 200% | ## Description Some font families offer additional faces in which the characters are narrower than the normal face (_condensed_ faces) or wider than the normal face (_expanded_ faces). You can use `font-stretch` to select a condensed or expanded face from such fonts. If the font you are using does not offer condensed or expanded faces, this property has no effect. ### Font face selection The face selected for a given value of `font-stretch` depends on the faces supported by the font in question. If the font does not provide a face that exactly matches the given value, then values less than 100% map to a narrower face, and values greater than or equal to 100% map to a wider face. The table below demonstrates the effect of supplying various different percentage values of `font-stretch` on two different fonts: ```css hidden @font-face { font-family: "Inconsolata"; src: url("https://fonts.gstatic.com/s/inconsolata/v31/QlddNThLqRwH-OJ1UHjlKENVzlm-WkL3GZQmAwPyya15.woff2") format("woff2"); font-stretch: 50% 200%; } @font-face { font-family: "Anek Malayalam"; src: url("https://fonts.gstatic.com/s/anekmalayalam/v4/6qLUKZActRTs_mZAJUZWWkhke0nYa-f6__Azq3-gP1W7db9_.woff2") format("woff2"); font-stretch: 75% 125%; } td { border: solid; border-width: 1px; } #inconsolata td { font: 90px Inconsolata, sans-serif; } #anek-malayalam td { font: 90px "Anek Malayalam"; } #inconsolata td:nth-child(2), #anek-malayalam td:nth-child(2) { font-stretch: 50%; } #inconsolata td:nth-child(3), #anek-malayalam td:nth-child(3) { font-stretch: 62.5%; } #inconsolata td:nth-child(4), #anek-malayalam td:nth-child(4) { font-stretch: 75%; } #inconsolata td:nth-child(5), #anek-malayalam td:nth-child(5) { font-stretch: 87.5%; } #inconsolata td:nth-child(6), #anek-malayalam td:nth-child(6) { font-stretch: 100%; } #inconsolata td:nth-child(7), #anek-malayalam td:nth-child(7) { font-stretch: 112.5%; } #inconsolata td:nth-child(8), #anek-malayalam td:nth-child(8) { font-stretch: 125%; } #inconsolata td:nth-child(9), #anek-malayalam td:nth-child(9) { font-stretch: 150%; } #inconsolata td:nth-child(10), #anek-malayalam td:nth-child(10) { font-stretch: 200%; } ``` ```html hidden <table class="standard-table"> <thead> <tr> <th scope="row"></th> <th scope="col">50%</th> <th scope="col">62.5%</th> <th scope="col">75%</th> <th scope="col">87.5%</th> <th scope="col">100%</th> <th scope="col">112.5%</th> <th scope="col">125%</th> <th scope="col">150%</th> <th scope="col">200%</th> </tr> </thead> <tbody> <tr id="inconsolata"> <th scope="row">Inconsolata</th> <td>e</td> <td>e</td> <td>e</td> <td>e</td> <td>e</td> <td>e</td> <td>e</td> <td>e</td> <td>e</td> </tr> <tr id="anek-malayalam"> <th scope="row">Anek Malayalam</th> <td>e</td> <td>e</td> <td>e</td> <td>e</td> <td>e</td> <td>e</td> <td>e</td> <td>e</td> <td>e</td> </tr> </tbody> </table> ``` {{EmbedLiveSample('Font_face_selection', "100%", "300px")}} - [Anek Malayalam](https://fonts.google.com/specimen/Anek+Malayalam) is a variable google font that supports widths from 75% to 125%. Values below and above this range select the closest matching font. - [Inconsolata](https://fonts.google.com/specimen/Inconsolata) is a variable font that offers a continuous range of widths from 50% to 200%. <!-- Note, dynamically obtained woff2 from Google fonts using query: https://fonts.googleapis.com/css2?family=Inconsolata:[email protected] --> ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting font stretch percentages {{EmbedGHLiveSample("css-examples/variable-fonts/font-stretch.html", '100%', 950)}} ## Specifications {{Specifications}} > **Note:** The `font-stretch` property was initially defined in CSS 2, but dropped in CSS 2.1 due to the lack of browser implementation. It was brought back in CSS 3. ## Browser compatibility {{Compat}} ## See also - {{cssxref("font-style")}} - {{cssxref("font-weight")}} - [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/font-style/index.md
--- title: font-style slug: Web/CSS/font-style page-type: css-property browser-compat: css.properties.font-style --- {{CSSRef}} The **`font-style`** [CSS](/en-US/docs/Web/CSS) property sets whether a font should be styled with a normal, italic, or oblique face from its {{cssxref("font-family")}}. {{EmbedInteractiveExample("pages/css/font-style.html")}} **Italic** font faces are generally cursive in nature, usually using less horizontal space than their unstyled counterparts, while **oblique** faces are usually just sloped versions of the regular face. When the specified style is not available, both italic and oblique faces are simulated by artificially sloping the glyphs of the regular face (use {{cssxref("font-synthesis")}} to control this behavior). ## Syntax ```css font-style: normal; font-style: italic; font-style: oblique; font-style: oblique 10deg; /* Global values */ font-style: inherit; font-style: initial; font-style: revert; font-style: revert-layer; font-style: unset; ``` The `font-style` property is specified as a single keyword chosen from the list of values below, which can optionally include an angle if the keyword is `oblique`. ### Values - `normal` - : Selects a font that is classified as `normal` within a {{Cssxref("font-family")}}. - `italic` - : Selects a font that is classified as `italic`. If no italic version of the face is available, one classified as `oblique` is used instead. If neither is available, the style is artificially simulated. - `oblique` - : Selects a font that is classified as `oblique`. If no oblique version of the face is available, one classified as `italic` is used instead. If neither is available, the style is artificially simulated. - `oblique` [`<angle>`](/en-US/docs/Web/CSS/angle) - : Selects a font classified as `oblique`, and additionally specifies an angle for the slant of the text. If one or more oblique faces are available in the chosen font family, the one that most closely matches the specified angle is chosen. If no oblique faces are available, the browser will synthesize an oblique version of the font by slanting a normal face by the specified amount. Valid values are degree values of `-90deg` to `90deg` inclusive. If an angle is not specified, an angle of 14 degrees is used. Positive values are slanted to the end of the line, while negative values are slanted towards the beginning. In general, for a requested angle of 14 degrees or greater, larger angles are preferred; otherwise, smaller angles are preferred (see the spec's [font matching section](https://drafts.csswg.org/css-fonts-4/#font-matching-algorithm) for the precise algorithm). ### Variable fonts Variable fonts can offer a fine control over the degree to which an oblique face is slanted. You can select this using the `<angle>` modifier for the `oblique` keyword. For TrueType or OpenType variable fonts, the `"slnt"` variation is used to implement varying slant angles for oblique, and the `"ital"` variation with a value of 1 is used to implement italic values. See {{cssxref("font-variation-settings")}}. > **Note:** For the example below to work, you'll need a browser that supports the CSS Fonts Level 4 syntax in which `font-style: oblique` can accept an `<angle>`. The demo loads with `font-style: oblique 23deg;`. Change the value to see the slant of the text change. {{EmbedGHLiveSample("css-examples/variable-fonts/oblique.html", '100%', 860)}} ## Accessibility concerns Large sections of text set with a `font-style` value of `italic` may be difficult for people with cognitive concerns such as Dyslexia to read. - [MDN Understanding WCAG, Guideline 1.4 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background) - [W3C Understanding WCAG 2.1](https://www.w3.org/TR/WCAG21/#visual-presentation) ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Font styles ```html hidden <p class="normal">This paragraph is normal.</p> <p class="italic">This paragraph is italic.</p> <p class="oblique">This paragraph is oblique.</p> ``` ```css .normal { font-style: normal; } .italic { font-style: italic; } .oblique { font-style: oblique; } ``` {{ EmbedLiveSample('Font_styles') }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("font-family")}} - {{cssxref("font-weight")}} - [Fundamental text and font styling](/en-US/docs/Learn/CSS/Styling_text/Fundamentals)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_spelling-error/index.md
--- title: "::spelling-error" slug: Web/CSS/::spelling-error page-type: css-pseudo-element browser-compat: css.selectors.spelling-error --- {{CSSRef}} The **`::spelling-error`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) represents a text segment which the {{glossary("user agent")}} has flagged as incorrectly spelled. ## Allowable properties Only a small subset of CSS properties can be used in a rule with `::spelling-error` in its selector: - {{cssxref("color")}} - {{cssxref("background-color")}} - {{cssxref("cursor")}} - {{cssxref("caret-color")}} - {{cssxref("outline")}} and its longhands - {{cssxref("text-decoration")}} and its associated properties - {{cssxref("text-emphasis-color")}} - {{cssxref("text-shadow")}} ## Syntax ```css ::spelling-error { /* ... */ } ``` ## Examples ### Simple document spell check In this example, eventual supporting browsers should highlight any flagged spelling errors with the styles shown. #### HTML ```html <p contenteditable spellcheck="true"> My friends are coegdfgfddffbgning to the party tonight. </p> ``` #### CSS ```css ::spelling-error { text-decoration: wavy red underline; } ``` #### Result {{EmbedLiveSample('Simple_document_spell_check', '100%', 60)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("::grammar-error")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-end-start-radius/index.md
--- title: border-end-start-radius slug: Web/CSS/border-end-start-radius page-type: css-property browser-compat: css.properties.border-end-start-radius --- {{CSSRef}} The **`border-end-start-radius`** [CSS](/en-US/docs/Web/CSS) property defines a logical border radius on an element, which maps to a physical border radius depending on the element's {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. This is useful when building styles to work regardless of the [text orientation](/en-US/docs/Web/CSS/text-orientation) and [writing mode](/en-US/docs/Web/CSS/CSS_writing_modes). {{EmbedInteractiveExample("pages/css/border-end-start-radius.html")}} This property affects the corner between the block-end and the inline-start sides of the element. For instance, in a `horizontal-tb` writing mode with `ltr` direction, it corresponds to the {{CSSxRef("border-bottom-left-radius")}} property. ## Syntax ```css /* <length> values */ /* With one value the corner will be a circle */ border-end-start-radius: 10px; border-end-start-radius: 1em; /* With two values the corner will be an ellipse */ border-end-start-radius: 1em 2em; /* Global values */ border-end-start-radius: inherit; border-end-start-radius: initial; border-end-start-radius: revert; border-end-start-radius: revert-layer; border-end-start-radius: unset; ``` ### Values - `<length-percentage>` - : Denotes the size of the circle radius or the semi-major and semi-minor axes of the ellipse. As absolute length it can be expressed in any unit allowed by the CSS {{cssxref("&lt;length&gt;")}} data type. Percentages for the horizontal axis refer to the width of the box, percentages for the vertical axis refer to the height of the box. Negative values are invalid. ## Formal definition {{CSSInfo}} ## Formal syntax {{CSSSyntax}} ## Examples ### Border radius with vertical text #### HTML ```html <div> <p class="exampleText">Example</p> </div> ``` #### CSS ```css div { background-color: rebeccapurple; width: 120px; height: 120px; border-end-start-radius: 10px; } .exampleText { writing-mode: vertical-rl; padding: 10px; background-color: #fff; border-end-start-radius: 10px; } ``` #### Results {{EmbedLiveSample("Border_radius_with_vertical_text", 140, 140)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS Logical Properties and Values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values) - The mapped physical property: {{CSSxRef("border-top-right-radius")}} - {{CSSxRef("writing-mode")}}, {{CSSxRef("direction")}}, {{CSSxRef("text-orientation")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/margin-block-end/index.md
--- title: margin-block-end slug: Web/CSS/margin-block-end page-type: css-property browser-compat: css.properties.margin-block-end --- {{CSSRef}} The **`margin-block-end`** [CSS](/en-US/docs/Web/CSS) property defines the logical block end margin of an element, which maps to a physical margin depending on the element's writing mode, directionality, and text orientation. {{EmbedInteractiveExample("pages/css/margin-block-end.html")}} ## Syntax ```css /* <length> values */ margin-block-end: 10px; /* An absolute length */ margin-block-end: 1em; /* relative to the text size */ margin-block-end: 5%; /* relative to the nearest block container's width */ /* Keyword values */ margin-block-end: auto; /* Global values */ margin-block-end: inherit; margin-block-end: initial; margin-block-end: revert; margin-block-end: revert-layer; margin-block-end: unset; ``` It corresponds to the {{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")}}. It relates to {{cssxref("margin-block-start")}}, {{cssxref("margin-inline-start")}}, and {{cssxref("margin-inline-end")}}, which define the other margins of the element. ### Values The `margin-block-end` property takes the same values as the {{cssxref("margin-left")}} property. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting block 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-rl; margin-block-end: 20px; background-color: #c8c800; } ``` #### Result {{EmbedLiveSample("Setting_block_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) - 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/css_functions/index.md
--- title: CSS value functions slug: Web/CSS/CSS_Functions page-type: guide --- {{CSSRef}} **CSS value functions** are statements that invoke special data processing or calculations to return a [CSS](/en-US/docs/Web/CSS) [value](/en-US/docs/Web/CSS/CSS_Values_and_Units) for a CSS property. CSS value functions represent more complex [data types](/en-US/docs/Web/CSS/CSS_Types) and they may take some input arguments to calculate the return value. ## Syntax ```css selector { property: function([argument]? [, argument]!); } ``` The value syntax starts with the **name of the function**, followed by a left parenthesis `(`. Next up are the argument(s), and the function is finished off with a closing parenthesis `)`. Functions can take multiple arguments, which are formatted similarly to CSS property values. Whitespace is allowed, but they are optional inside the parentheses. In some functional notations multiple arguments are separated by commas, while others use spaces. > **Note:** The CSS value functions are used as property values and should not be confused with pseudo-classes. The [functional pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes#functional_pseudo-classes), [linguistic pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes#linguistic_pseudo-classes), and several [tree-structural pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes#tree-structural_pseudo-classes) require parameter values, but they're not value functions. The [conditional at-rules](/en-US/docs/Web/CSS/At-rule#conditional_group_rules) are also not value functions; the parentheses are used for groupings. ## Transform functions The {{CSSxRef("&lt;transform-function&gt;")}} CSS [data type](/en-US/docs/Web/CSS/CSS_Types) represent appearance transformation. It is used as a value of {{CSSxRef("transform")}} property. ### Translate functions - {{CSSxRef("transform-function/translateX", "translateX()")}} - : Translates an element horizontally. - {{CSSxRef("transform-function/translateY", "translateY()")}} - : Translates an element vertically. - {{CSSxRef("transform-function/translateZ", "translateZ()")}} - : Translates an element along the z-axis. - {{CSSxRef("transform-function/translate", "translate()")}} - : Translates an element on the 2D plane. - {{CSSxRef("transform-function/translate3d", "translate3d()")}} - : Translates an element in 3D space. ### Rotation functions - {{CSSxRef("transform-function/rotateX", "rotateX()")}} - : Rotates an element around the horizontal axis. - {{CSSxRef("transform-function/rotateY", "rotateY()")}} - : Rotates an element around the vertical axis. - {{CSSxRef("transform-function/rotateZ", "rotateZ()")}} - : Rotates an element around the z-axis. - {{CSSxRef("transform-function/rotate", "rotate()")}} - : Rotates an element around a fixed point on the 2D plane. - {{CSSxRef("transform-function/rotate3d", "rotate3d()")}} - : Rotates an element around a fixed axis in 3D space. ### Scaling functions - {{CSSxRef("transform-function/scaleX", "scaleX()")}} - : Scales an element up or down horizontally. - {{CSSxRef("transform-function/scaleY", "scaleY()")}} - : Scales an element up or down vertically. - {{CSSxRef("transform-function/scaleZ", "scaleZ()")}} - : Scales an element up or down along the z-axis. - {{CSSxRef("transform-function/scale", "scale()")}} - : Scales an element up or down on the 2D plane. - {{CSSxRef("transform-function/scale3d", "scale3d()")}} - : Scales an element up or down in 3D space. ### Skew functions - {{CSSxRef("transform-function/skewX", "skewX()")}} - : Skews an element in the horizontal direction. - {{CSSxRef("transform-function/skewY", "skewY()")}} - : Skews an element in the vertical direction. - {{CSSxRef("transform-function/skew", "skew()")}} - : Skews an element on the 2D plane. ### Matrix functions - {{CSSxRef("transform-function/matrix", "matrix()")}} - : Describes a homogeneous 2D transformation matrix. - {{CSSxRef("transform-function/matrix3d", "matrix3d()")}} - : Describes a 3D transformation as a 4Γ—4 homogeneous matrix. ### Perspective functions - {{CSSxRef("transform-function/perspective", "perspective()")}} - : Sets the distance between the user and the z=0 plane. ## Math functions The math functions allow CSS numeric values to be written as mathematical expressions. Each of the pages below contains detailed information about a math function's syntax, browser compatibility data, examples, and more. For a holistic introduction to CSS math functions, see [Using CSS math functions](/en-US/docs/Web/CSS/CSS_Functions/Using_CSS_math_functions). ### Basic arithmetic - {{CSSxRef("calc", "calc()")}} - : Performs basic arithmetic calculations on numerical values. ### Comparison functions - {{CSSxRef("min", "min()")}} - : Calculates the smallest of a list of values. - {{CSSxRef("max", "max()")}} - : Calculates the largest of a list of values. - {{CSSxRef("clamp", "clamp()")}} - : Calculates the central of a minimum, central, and maximum values. ### Stepped value functions - {{CSSxRef("round", "round()")}} - : Calculates a rounded number based on a rounding strategy. - {{CSSxRef("mod", "mod()")}} - : Calculates a modulus (with the same sign as the divisor) when dividing one number by another. - {{CSSxRef("rem", "rem()")}} - : Calculates a remainder (with the same sign as the dividend) when dividing one number by another. ### Trigonometric functions - {{CSSxRef("sin", "sin()")}} - : Calculates the trigonometric sine of a number. - {{CSSxRef("cos", "cos()")}} - : Calculates the trigonometric cosine of a number. - {{CSSxRef("tan", "tan()")}} - : Calculates the trigonometric tangent of a number. - {{CSSxRef("asin", "asin()")}} - : Calculates the trigonometric inverse sine of a number. - {{CSSxRef("acos", "acos()")}} - : Calculates the trigonometric inverse cosine of a number. - {{CSSxRef("atan", "atan()")}} - : Calculates the trigonometric inverse tangent of a number. - {{CSSxRef("atan2", "atan2()")}} - : Calculates the trigonometric inverse tangent of two-numbers in a plane. ### Exponential functions - {{CSSxRef("pow", "pow()")}} - : Calculates the base raised to the power of a number. - {{CSSxRef("sqrt", "sqrt()")}} - : Calculates the square root of a number. - {{CSSxRef("hypot", "hypot()")}} - : Calculates the square root of the sum of the squares of its arguments. - {{CSSxRef("log", "log()")}} - : Calculates the logarithm of a number. - {{CSSxRef("exp", "exp()")}} - : Calculates `e` raised to the power of a number. ### Sign-related functions - {{CSSxRef("abs", "abs()")}} - : Calculates the absolute value of a number. - {{CSSxRef("sign", "sign()")}} - : Calculates the sign (positive or negative) of the number. ## Filter functions The {{CSSxRef("&lt;filter-function&gt;")}} CSS [data type](/en-US/docs/Web/CSS/CSS_Types) represents a graphical effect that can change the appearance of an input image. It is used in the {{CSSxRef("filter")}} and {{CSSxRef("backdrop-filter")}} properties. - {{CSSxRef("filter-function/blur", "blur()")}} - : Increases the image gaussian blur. - {{CSSxRef("filter-function/brightness", "brightness()")}} - : Brightens or darkens an image. - {{CSSxRef("filter-function/contrast", "contrast()")}} - : Increases or decreases the image contrast. - {{CSSxRef("filter-function/drop-shadow", "drop-shadow()")}} - : Applies a drop shadow behind an image. - {{CSSxRef("filter-function/grayscale", "grayscale()")}} - : Converts an image to grayscale. - {{CSSxRef("filter-function/hue-rotate", "hue-rotate()")}} - : Changes the overall hue of an image. - {{CSSxRef("filter-function/invert", "invert()")}} - : Inverts the colors of an image. - {{CSSxRef("filter-function/opacity", "opacity()")}} - : Adds transparency to an image. - {{CSSxRef("filter-function/saturate", "saturate()")}} - : Changes the overall saturation of an image. - {{CSSxRef("filter-function/sepia", "sepia()")}} - : Increases the sepia of an image. ## Color functions The {{CSSxRef("color_value","&lt;color&gt;")}} CSS [data type](/en-US/docs/Web/CSS/CSS_Types) specifies different color representations. - {{CSSxRef("color_value/rgb", "rgb()")}} - : Defines a given color according to its red, green, blue and alpha (transparency) components. - {{CSSxRef("color_value/hsl", "hsl()")}} - : Defines a given color according to its hue, saturation, lightness and alpha (transparency) components. - {{CSSxRef("color_value/hwb", "hwb()")}} - : Defines a given color according to its hue, whiteness and blackness components. - {{CSSxRef("color_value/lch", "lch()")}} - : Defines a given color according to its lightness, chroma and hue components. - {{CSSxRef("color_value/oklch", "oklch()")}} - : Defines a given color according to its lightness, chroma, hue and alpha (transparency) components. - {{CSSxRef("color_value/lab", "lab()")}} - : Defines a given color according to its lightness, a-axis distance and b-axis distance in the lab colorspace. - {{CSSxRef("color_value/oklab", "oklab()")}} - : Defines a given color according to its lightness, a-axis distance, b-axis distance in the lab colorspace and alpha (transparency). - {{CSSxRef("color_value/color", "color()")}} - : Specifies a particular, specified colorspace rather than the implicit sRGB colorspace. - {{CSSxRef("color_value/color-mix", "color-mix()")}} - : Mixes two color values in a given colorspace by a given amount. - {{CSSxRef("color_value/color-contrast", "color-contrast()")}} {{Experimental_Inline}} - : Selects the highest color contrast from a list of colors, compare to a base color value. - {{CSSxRef("color_value/device-cmyk", "device-cmyk()")}} {{Experimental_Inline}} - : Defines CMYK colors in a device-independent way. - {{CSSXref("color_value/light-dark", "light-dark()")}} {{Experimental_Inline}} - : Returns one of two provided colors based on the current color scheme. ## Image functions The {{CSSxRef("&lt;image&gt;")}} CSS [data type](/en-US/docs/Web/CSS/CSS_Types) provides graphical representation of images or gradients. ### Gradient functions - {{CSSxRef("gradient/linear-gradient","linear-gradient()")}} - : Linear gradients transition colors progressively along an imaginary line. - {{CSSxRef("gradient/radial-gradient","radial-gradient()")}} - : Radial gradients transition colors progressively from a center point (origin). - {{CSSxRef("gradient/conic-gradient", "conic-gradient()")}} - : Conic gradients transition colors progressively around a circle. - {{CSSxRef("gradient/repeating-linear-gradient","repeating-linear-gradient()")}} - : Is similar to `linear-gradient()` and takes the same arguments, but it repeats the color stops infinitely in all directions so as to cover its entire container. - {{CSSxRef("gradient/repeating-radial-gradient","repeating-radial-gradient()")}} - : Is similar to `radial-gradient()` and takes the same arguments, but it repeats the color stops infinitely in all directions so as to cover its entire container. - {{CSSxRef("gradient/repeating-conic-gradient","repeating-conic-gradient()")}} - : Is similar to `conic-gradient()` and takes the same arguments, but it repeats the color stops infinitely in all directions so as to cover its entire container. ### Image functions - {{CSSxRef("image/image","image()")}} {{Experimental_Inline}} - : Defines an {{CSSxRef("&lt;image&gt;")}} in a similar fashion to the {{CSSxRef("url", "url()")}} function, but with added functionality including specifying the image's directionality and fallback images for when the preferred image is not supported. - {{CSSxRef("image/image-set","image-set()")}} - : Picks the most appropriate CSS image from a given set, primarily for high pixel density screens. - {{CSSxRef("cross-fade", "cross-fade()")}} - : Blends two or more images at a defined transparency. - {{CSSxRef("element", "element()")}} {{Experimental_Inline}} - : Defines an {{CSSxRef("&lt;image&gt;")}} value generated from an arbitrary HTML element. - {{CSSxRef("image/paint", "paint()")}} - : Defines an {{CSSxRef("&lt;image&gt;")}} value generated with a PaintWorklet. ## Counter functions CSS counter functions are generally used with the {{CSSxRef("content")}} property, although in theory, they may be used wherever a {{CSSxRef("&lt;string&gt;")}} is supported. - {{CSSxRef("counter", "counter()")}} - : Returns a string representing the current value of the named counter if there is one. - {{CSSxRef("counters", "counters()")}} - : Enables nested counters, returning a concatenated string representing the current values of the named counters, if there are any. - {{CSSxRef("symbols", "symbols()")}} - : Defines the counter styles inline, directly as the value of a property. ## Shape functions The {{CSSxRef("&lt;basic-shape&gt;")}} CSS [data type](/en-US/docs/Web/CSS/CSS_Types) represents a graphical shape. It is used in the {{CSSxRef("clip-path")}}, {{CSSxRef("offset-path")}}, and {{CSSxRef("shape-outside")}} properties. - {{CSSxRef("basic-shape/circle","circle()")}} - : Defines a circle shape. - {{CSSxRef("basic-shape/ellipse","ellipse()")}} - : Defines an ellipse shape. - {{CSSxRef("basic-shape/inset","inset()")}} - : Defines an inset rectangle shape. - {{CSSxRef("basic-shape/rect","rect()")}} {{Experimental_Inline}} - : Defines a rectangle shape using the distances from the top and left edges of the reference box. - {{CSSxRef("basic-shape/xywh","xywh()")}} {{Experimental_Inline}} - : Defines a rectangle shape using the specified distances from the top and left edges of the reference box and the rectangle width and height. - {{CSSxRef("basic-shape/polygon","polygon()")}} - : Defines a polygon shape. - {{CSSxRef("path", "path()")}} - : Accepts an SVG path string to enable a shape to be drawn. ## Reference functions The following functions are used as a value of properties to reference a value defined elsewhere. - {{CSSxRef("attr", "attr()")}} - : Uses the attributes defined on HTML element. - {{CSSxRef("env", "env()")}} - : Uses the user-agent defined as environment variable. - {{CSSxRef("url", "url()")}} - : Uses a file from the specified URL. - {{CSSxRef("var", "var()")}} - : Uses the custom property value instead of any part of a value of another property. ## Grid functions The following functions are used to define a [CSS Grid](/en-US/docs/Web/CSS/CSS_grid_layout). - {{CSSxRef("fit-content", "fit-content()")}} - : Clamps a given size to an available size according to the formula `min(maximum size, max(minimum size, argument))`. - {{CSSxRef("minmax", "minmax()")}} - : Defines a size range greater-than or equal-to _min_ and less-than or equal-to _max_. - {{CSSxRef("repeat", "repeat()")}} - : Represents a repeated fragment of the track list, allowing a large number of columns or rows that exhibit a recurring pattern. ## Font functions CSS font functions are used with the {{CSSxRef("font-variant-alternates")}} property to control the use of alternate glyphs. - {{CSSxRef("font-variant-alternates#stylistic", "stylistic()")}} - : Enables stylistic alternates for individual characters. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `salt`, like `salt 2`. - {{CSSxRef("font-variant-alternates#styleset", "styleset()")}} - : Enables stylistic alternatives for sets of characters. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `ssXY`, such as `ss02`. - {{CSSxRef("font-variant-alternates#character-variant", "character-variant()")}} - : Enables specific stylistic alternatives for characters. It is similar to `styleset()`, but doesn't create coherent glyphs for a set of characters; individual characters will have independent and not necessarily coherent styles. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `cvXY`, such as `cv02`. - {{CSSxRef("font-variant-alternates#swash", "swash()")}} - : Enables [swash](https://en.wikipedia.org/wiki/Swash_%28typography%29) glyphs. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType values `swsh` and `cswh`, such as `swsh 2` and `cswh 2`. - {{CSSxRef("font-variant-alternates#ornaments", "ornaments()")}} - : Enables ornaments such as [fleurons](https://en.wikipedia.org/wiki/Fleuron_%28typography%29) and other dingbat glyphs. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `ornm`, such as `ornm 2`. - {{CSSxRef("font-variant-alternates#annotation", "annotation()")}} - : Enables annotations such as circled digits or inverted characters. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `nalt`, such as `nalt 2`. ## Easing functions The following functions are used as a value in transition and animation properties. - {{cssxref("easing-function#linear_easing_function", "linear()")}} - : Easing function that interpolates linearly between its points. - {{cssxref("easing-function#cubic_b%C3%A9zier_easing_function", "cubic-bezier()")}} - : Easing function that defines a cubic BΓ©zier curve. - {{cssxref("easing-function#step_easing_function", "steps()")}} - : Iteration along a specified number of stops along the transition, displaying each stop for equal lengths of time. ## Animation functions The following functions are used as a value of different `animation-timeline` properties. See {{CSSxRef("animation-timeline")}} for more details about these. - {{cssxref("animation-timeline/scroll", "scroll()")}} - : Sets the {{cssxref("animation-timeline")}} of an element to an _anonymous scroll progress timeline_. - {{cssxref("animation-timeline/view", "view()")}} - : Sets the {{cssxref("animation-timeline")}} of an element to an _anonymous view progress timeline_. ## See also - [CSS Values and Units](/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)
0
data/mdn-content/files/en-us/web/css/css_functions
data/mdn-content/files/en-us/web/css/css_functions/using_css_math_functions/index.md
--- title: Using CSS math functions slug: Web/CSS/CSS_Functions/Using_CSS_math_functions page-type: guide --- {{CSSRef}} **CSS math functions** allow a property value - such as the `height`, `animation-duration`, or `font-size` of an element - to be written as a mathematical expression. Without using any math, the built-in [CSS units](/en-US/docs/Learn/CSS/Building_blocks/Values_and_units) like `rem`, `vw`, and `%` are often flexible enough to style HTML elements to achieve a particular user experience. However, there are cases where we might feel limited by expressing an element's style using a single value and unit. Consider the following examples: 1. We want to set the height of a content area to be "the height of the viewport minus the height of a navbar." 2. We want to add the width of two elements together to define the width of a third element. 3. We want to prevent a variable `font-size` of some text from growing beyond a certain size. In all of these cases, we need to rely on math to achieve the desired outcomes. One solution could be to rely on mathematical functions defined by JavaScript, and dynamically set element styles based on results calculated by our scripts. In many instances, including in the examples above, **we can instead utilize math functions built directly into CSS**. This solution is often simpler to implement and faster for the browser to execute than using JavaScript. In total, developers can use a combination of [nearly two dozen CSS math functions](/en-US/docs/Web/CSS/CSS_Functions#math_functions) in their stylesheets. In this guide, we'll exemplify four of the more commonly-used, and introduce those more advanced. ## `calc()`: Basic math operations In the first two of our three examples above, we want to set the style of an element according to the result of an addition or subtraction operation. This is exactly one of the use cases for {{CSSxRef("calc", "calc()")}}. The **`calc()`** function lets you specify CSS property values using **addition, subtraction, multiplication, and division**. It is often used to combine two CSS values that have different units, such as `%` and `px`. The `calc()` math function takes a mathematical expression as a parameter and returns the result of that expression, e.g.: ```css property: calc(expression); ``` ### `calc()` Example Click on the play icon below to see the `calc()` example in the code playground and try it for yourself. ```html hidden <div class="calc1"> <code>width: calc(10px + 100px);</code> </div> <div class="calc2"> <code>width: calc(2em * 5);</code> </div> <div class="calc3"> <code>width: calc(100% - 32px);</code> </div> <div class="calc4"> <code>width: calc(var(--predefined-width) - calc(16px * 2));</code> </div> ``` ```css div { background-color: black; margin: 4px 0; width: 100%; } div > code { display: block; background-color: red; color: white; height: 48px; } .calc1 > code { /* Output width: `110px` */ width: calc(10px + 100px); } .calc2 > code { /* Output width: `10em` */ width: calc(2em * 5); } .calc3 > code { /* Output width: Depends on the container's width */ width: calc(100% - 32px); } .calc4 > code { --predefined-width: 100%; /* Output width: Depends on the container's width */ width: calc(var(--predefined-width) - calc(16px * 2)); } ``` {{EmbedLiveSample('calc_Example', '100%', 212) }} ## `min()`: Finding the minimum value in a set There are cases where we don't want the value of a CSS property to exceed a certain number. Say, for example, we want the width of our content container to be the smaller of "the full width of our screen" and "500 pixels." In those cases, we can use the CSS math function {{CSSxRef("min", "min()")}}. The `min()` math function takes a set of comma-separated values as arguments and returns the smallest of those values, e.g.: ```css property: min(<first value>, <second value>, <third value>, ...); ``` This function is often used to compare two CSS values that have different units, such as `%` and `px`. ### `min()` Example Click on the play icon below to see the `min()` example in the code playground and try it for yourself. ```html hidden <div class="min1"> <code>width: min(9999px, 50%);</code> </div> <div class="min2"> <code>width: min(9999px, 100%);</code> </div> <div class="min3"> <code>width: min(120px, 150px, 90%);</code> </div> <div class="min4"> <code>width: min(80px, 90%);</code> </div> ``` ```css div { background-color: black; margin: 4px 0; width: 100%; } div > code { display: block; background-color: darkblue; color: white; height: 48px; } .min1 > code { /* Output width: Depends on the container's width; */ /* on this page, likely to be `50%` of the container's width */ width: min(9999px, 50%); } .min2 > code { /* Output width: Depends on the container's width; */ /* on this page, likely to be `100%` of the container's width */ width: min(9999px, 100%); } .min3 > code { /* Output width: Depends on the container's width; */ /* on this page, likely to be `120px` of the container's width */ width: min(120px, 150px, 90%); } .min4 > code { /* Output width: Depends on the container's width; */ /* on this page, likely to be `80px` of the container's width */ width: min(80px, 90%); } ``` {{EmbedLiveSample('min_Example', '100%', 212) }} ## `max()`: Finding the maximum value in a set Similar to `min()`, sometimes we don't want the value of a CSS property to go below a certain number. For example, we might want the width of our content container to be the _larger_ of "the full width of our screen" and "500 pixels." In those cases, we can use the CSS math function {{CSSxRef("max", "max()")}}. The `max()` math function takes a set of comma-separated values as arguments and returns the largest of those values, e.g.: ```css property: max(<first value>, <second value>, <third value>, ...); ``` This function is often used to compare two CSS values that have different units, such as `%` and `px`. Notice the similarities and differences between the examples for `min()` and `max()`. ### `max()` Example Click on the play icon below to see the `max()` example in the code playground and try it for yourself. ```html hidden <div class="max1"> <code>width: max(50px, 50%);</code> </div> <div class="max2"> <code>width: max(50px, 100%);</code> </div> <div class="max3"> <code>width: max(20px, 50px, 90%);</code> </div> <div class="max4"> <code>width: max(80px, 80%);</code> </div> ``` ```css div { background-color: black; margin: 4px 0; width: 100%; height: 48px; } div > code { display: block; background-color: darkmagenta; color: white; height: 48px; } .max1 > code { /* Output width: Depends on the container's width; */ /* on this page, likely to be `50%` of the container's width */ width: max(50px, 50%); } .max2 > code { /* Output width: Depends on the container's width; */ /* on this page, likely to be `100%` of the container's width */ width: max(50px, 100%); } .max3 > code { /* Output width: Depends on the container's width; */ /* on this page, likely to be `90%` of the container's width */ width: max(20px, 50px, 90%); } .max4 > code { /* Output width: Depends on the container's width; */ /* on this page, likely to be `80%` of the container's width */ width: max(80px, 80%); } ``` {{EmbedLiveSample('max_Example', '100%', 212) }} ## `clamp()`: Constraining a value between two values We can combine the functions of `min()` and `max()` by using {{CSSxRef("clamp", "clamp()")}}. The `clamp()` math function takes a minimum value, the value to be clamped, and the maximum value as arguments, e.g.: ```css property: clamp(<minimum value>, <value to be clamped>, <maximum value>); ``` - If the value to be clamped is less than the passed minimum value, the function will return the minimum value. - If the value to be clamped is greater than the passed maximum value, the function will return the maximum value. - If the value to be clamped is between the passed minimum and maximum values, the function will return the original value to be clamped. This function is often used to compare two CSS values that have different units, such as `%` and `px`. ### `clamp()` Example Click on the play icon below to see the `clamp()` example in the code playground and try it for yourself. ```html hidden <div class="clamp1"> <code>width: clamp(10%, 1px, 90%);</code> </div> <div class="clamp2"> <code>width: clamp(10%, 9999px, 90%);</code> </div> <div class="clamp3"> <code>width: clamp(125px, 1px, 250px);</code> </div> <div class="clamp4"> <code>width: clamp(25px, 9999px, 150px);</code> </div> ``` ```css div { background-color: black; margin: 4px 0; width: 100%; height: 48px; } div > code { display: block; background-color: darkgreen; color: white; height: 48px; } .clamp1 > code { /* Output width: Depends on the container's width; */ /* on this page, likely to be `20%` of the container's width */ width: clamp(20%, 1px, 80%); } .clamp2 > code { /* Output width: Depends on the container's width; */ /* on this page, likely to be `90%` of the container's width */ width: clamp(10%, 9999px, 90%); } .clamp3 > code { /* Output width: `125px` */ width: clamp(125px, 1px, 250px); } .clamp4 > code { /* Output width: `150px` */ width: clamp(25px, 9999px, 150px); } ``` {{EmbedLiveSample('clamp_Example', '100%', 212) }} ## Advanced CSS Math Functions When laying out and styling DOM elements, the four basic math functions {{CSSxRef("calc", "calc()")}}, {{CSSxRef("min", "min()")}}, {{CSSxRef("max", "max()")}}, and {{CSSxRef("clamp", "clamp()")}} are often sufficient. However, for advanced uses like mathematics learning materials, 3D visualizations, or CSS animations, you may consider using: - [Stepped value functions](/en-US/docs/Web/CSS/CSS_Functions#stepped_value_functions) - {{CSSxRef("round", "round()")}}: calculates a **value given a rounding strategy** - {{CSSxRef("mod", "mod()")}}: calculates the **remainder** of a division operation with the **same sign as the divisor** - {{CSSxRef("rem", "rem()")}}: calculates the **remainder** of a division operation with the **same sign as the dividend** - [Trigonometric functions](/en-US/docs/Web/CSS/CSS_Functions#trigonometric_functions) - {{CSSxRef("sin", "sin()")}}: calculates the **trigonometric sine** of a number - {{CSSxRef("cos", "cos()")}}: calculates the **trigonometric cosine** of a number - {{CSSxRef("tan", "tan()")}}: calculates the **trigonometric tangent** of a number - {{CSSxRef("asin", "asin()")}}: calculates the **trigonometric inverse** sine of a number - {{CSSxRef("acos", "acos()")}}: calculates the **trigonometric inverse** cosine of a number - {{CSSxRef("atan", "atan()")}}: calculates the **trigonometric inverse** tangent of a number - {{CSSxRef("atan2", "atan2()")}}: calculates the **trigonometric inverse** tangent given two numbers - [Exponential functions](/en-US/docs/Web/CSS/CSS_Functions#exponential_functions) - {{CSSxRef("pow", "pow()")}}: calculates a number **raised to the power** of another number - {{CSSxRef("sqrt", "sqrt()")}}: calculates the **square root** of a number - {{CSSxRef("hypot", "hypot()")}}: calculates the **square root of the sum of the squares** of the given numbers - {{CSSxRef("log", "log()")}}: calculates the **logarithm** of a number (with `e` as the default base) - {{CSSxRef("exp", "exp()")}}: calculates **`e` raised to the power** of another number - [Sign functions](/en-US/docs/Web/CSS/CSS_Functions#sign-related_functions) - {{CSSxRef("abs", "abs()")}}: calculates the **absolute value** of a number - {{CSSxRef("sign", "sign()")}}: calculates the **sign (positive, negative, or zero)** of a number ## Final thoughts - You can use CSS math functions to create responsive user interfaces without writing any JavaScript code. - CSS math functions can sometimes be used instead of [CSS media queries](/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries) to define layout breakpoints. - In 2023, members of the Interop Project [selected "CSS Math Functions" as a focus area of improvement](https://github.com/web-platform-tests/interop/blob/main/2023/README.md#css-math-functions). This means that browser vendors are working together to ensure that CSS math functions perform the same across browsers and devices.
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/atan/index.md
--- title: atan() slug: Web/CSS/atan page-type: css-function browser-compat: css.types.atan --- {{CSSRef}} The **`atan()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) is a trigonometric function that returns the inverse tangent of a number between `-∞` and `+∞`. The function contains a single calculation that returns the number of radians representing an {{cssxref("&lt;angle&gt;")}} between `-90deg` and `90deg`. ## Syntax ```css /* Single <number> values */ transform: rotate(atan(1)); transform: rotate(atan(4 * 50)); /* Other values */ transform: rotate(atan(pi / 2)); transform: rotate(atan(e * 3)); ``` ### Parameter The `atan(number)` function accepts only one value as its parameter. - `number` - : A calculation which resolves to a {{cssxref("&lt;number&gt;")}} between `-∞` and `+∞`. ### Return value The inverse tangent of an `number` will always return an {{cssxref("&lt;angle&gt;")}} between `-90deg` and `90deg`. - If `number` is `0⁻`, the result is `0⁻`. - If `number` is `+∞` the result is `90deg`. - If `number` is `-∞` the result is `-90deg`. That is: - `atan(-infinity)` representing `-90deg`. - `atan(-1)` representing `-45deg` - `atan(0)` representing `0deg` - `atan(1)` representing `45deg` - `atan(infinity)` representing `90deg`. ### Formal syntax {{CSSSyntax}} ## Examples ### Rotate elements The `atan()` 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(atan(-99999)); } div.box-2 { transform: rotate(atan(-1)); } div.box-3 { transform: rotate(atan(0)); } div.box-4 { transform: rotate(atan(1)); } div.box-5 { transform: rotate(atan(99999)); } ``` #### Result {{EmbedLiveSample('Rotate elements', '100%', '200px')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("sin")}} - {{CSSxRef("cos")}} - {{CSSxRef("tan")}} - {{CSSxRef("asin")}} - {{CSSxRef("acos")}} - {{CSSxRef("atan2")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_host/index.md
--- title: ":host" slug: Web/CSS/:host page-type: css-pseudo-class browser-compat: css.selectors.host --- {{CSSRef}} The **`:host`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) selects the shadow host of the [shadow DOM](/en-US/docs/Web/API/Web_components/Using_shadow_DOM) containing the CSS it is used inside β€” in other words, this allows you to select a custom element from inside its shadow DOM. > **Note:** This has no effect when used outside a shadow DOM. {{EmbedInteractiveExample("pages/tabbed/pseudo-class-host.html", "tabbed-shorter")}} ```css /* Selects a shadow root host */ :host { font-weight: bold; } ``` ## Syntax ```css :host { /* ... */ } ``` ## Examples ### Styling the shadow host The following snippets are taken from our [host-selectors example](https://github.com/mdn/web-components-examples/tree/main/host-selectors) ([see it live also](https://mdn.github.io/web-components-examples/host-selectors/)). In this example we have a simple custom element β€” `<context-span>` β€” that you can wrap around text: ```html <h1> Host selectors <a href="#"><context-span>example</context-span></a> </h1> ``` Inside the element's constructor, we create `style` and `span` elements, fill the `span` with the content of the custom element, and fill the `style` element with some CSS rules: ```js const style = document.createElement("style"); const span = document.createElement("span"); span.textContent = this.textContent; const shadowRoot = this.attachShadow({ mode: "open" }); shadowRoot.appendChild(style); shadowRoot.appendChild(span); style.textContent = "span:hover { text-decoration: underline; }" + ":host-context(h1) { font-style: italic; }" + ':host-context(h1):after { content: " - no links in headers!" }' + ":host-context(article, aside) { color: gray; }" + ":host(.footer) { color : red; }" + ":host { background: rgb(0 0 0 / 10%); padding: 2px 5px; }"; ``` The `:host { background: rgb(0 0 0 / 10%); padding: 2px 5px; }` rule styles all instances of the `<context-span>` element (the shadow host in this instance) in the document. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Web components](/en-US/docs/Web/API/Web_components) - {{cssxref(":host_function", ":host()")}} - {{cssxref(":host-context", ":host-context()")}} - {{CSSxref("::slotted")}} - {{CSSxRef(":state",":state()")}} - [CSS scoping](/en-US/docs/Web/CSS/CSS_scoping) module
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_colon_is/index.md
--- title: ":is()" slug: Web/CSS/:is page-type: css-pseudo-class browser-compat: css.selectors.is --- {{CSSRef}} The **`:is()`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) function takes a selector list as its argument, and selects any element that can be selected by one of the selectors in that list. This is useful for writing large selectors in a more compact form. > **Note:** Originally named `:matches()` (and `:any()`), this selector was renamed to `:is()` in [CSSWG issue #3258](https://github.com/w3c/csswg-drafts/issues/3258). {{EmbedInteractiveExample("pages/tabbed/pseudo-class-is.html", "tabbed-shorter")}} Pseudo-elements are not valid in the selector list for `:is()`. ### Difference between :is() and :where() The difference between the two is that `:is()` counts towards the specificity of the overall selector (it takes the specificity of its most specific argument), whereas [`:where()`](/en-US/docs/Web/CSS/:where) has a specificity value of 0. This is demonstrated by the [example on the `:where()` reference page](/en-US/docs/Web/CSS/:where#examples). ### Forgiving Selector Parsing The specification defines `:is()` and `:where()` as accepting a [forgiving selector list](https://drafts.csswg.org/selectors-4/#typedef-forgiving-selector-list). In CSS when using a selector list, if any of the selectors are invalid then the whole list is deemed invalid. When using `:is()` or `:where()` instead of the whole list of selectors being deemed invalid if one fails to parse, the incorrect or unsupported selector will be ignored and the others used. ```css :is(:valid, :unsupported) { /* … */ } ``` Will still parse correctly and match `:valid` even in browsers which don't support `:unsupported`, whereas: ```css :valid, :unsupported { /* … */ } ``` Will be ignored in browsers which don't support `:unsupported` even if they support `:valid`. ## Examples ### Simplifying list selectors The `:is()` pseudo-class can greatly simplify your CSS selectors. For example, take the following CSS: ```css /* 3-deep (or more) unordered lists use a square */ ol ol ul, ol ul ul, ol menu ul, ol dir ul, ol ol menu, ol ul menu, ol menu menu, ol dir menu, ol ol dir, ol ul dir, ol menu dir, ol dir dir, ul ol ul, ul ul ul, ul menu ul, ul dir ul, ul ol menu, ul ul menu, ul menu menu, ul dir menu, ul ol dir, ul ul dir, ul menu dir, ul dir dir, menu ol ul, menu ul ul, menu menu ul, menu dir ul, menu ol menu, menu ul menu, menu menu menu, menu dir menu, menu ol dir, menu ul dir, menu menu dir, menu dir dir, dir ol ul, dir ul ul, dir menu ul, dir dir ul, dir ol menu, dir ul menu, dir menu menu, dir dir menu, dir ol dir, dir ul dir, dir menu dir, dir dir dir { list-style-type: square; } ``` You can replace it with: ```css /* 3-deep (or more) unordered lists use a square */ :is(ol, ul, menu, dir) :is(ol, ul, menu, dir) :is(ul, menu, dir) { list-style-type: square; } ``` ### Simplifying section selectors The `:is()` pseudo-class is particularly useful when dealing with HTML [sections and headings](/en-US/docs/Web/HTML/Element/Heading_Elements). Since {{HTMLElement("section")}}, {{HTMLElement("article")}}, {{HTMLElement("aside")}}, and {{HTMLElement("nav")}} are commonly nested together, without `:is()`, styling them to match one another can be tricky. For example, without `:is()`, styling all the {{HTMLElement("Heading_Elements", "h1")}} elements at different depths could be very complicated: ```css /* Level 0 */ h1 { font-size: 30px; } /* Level 1 */ section h1, article h1, aside h1, nav h1 { font-size: 25px; } /* Level 2 */ section section h1, section article h1, section aside h1, section nav h1, article section h1, article article h1, article aside h1, article nav h1, aside section h1, aside article h1, aside aside h1, aside nav h1, nav section h1, nav article h1, nav aside h1, nav nav h1 { font-size: 20px; } /* Level 3 */ /* don't even think about it! */ ``` Using `:is()`, though, it's much easier: ```css /* Level 0 */ h1 { font-size: 30px; } /* Level 1 */ :is(section, article, aside, nav) h1 { font-size: 25px; } /* Level 2 */ :is(section, article, aside, nav) :is(section, article, aside, nav) h1 { font-size: 20px; } /* Level 3 */ :is(section, article, aside, nav) :is(section, article, aside, nav) :is(section, article, aside, nav) h1 { font-size: 15px; } ``` ### :is() does not select pseudo-elements The `:is()` pseudo-class does not match pseudo-elements. So rather than this: ```css example-bad some-element:is(::before, ::after) { display: block; } ``` or this: ```css example-bad :is(some-element::before, some-element::after) { display: block; } ``` instead do: ```css example-good some-element::before, some-element::after { display: block; } ``` ## Syntax ```css-nolint :is(<forgiving-selector-list>) { /* ... */ } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef(":where", ":where()")}} - Like `:is()`, but with 0 [specificity](/en-US/docs/Web/CSS/Specificity). - [Selector list](/en-US/docs/Web/CSS/Selector_list) - [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/outline-offset/index.md
--- title: outline-offset slug: Web/CSS/outline-offset page-type: css-property browser-compat: css.properties.outline-offset --- {{CSSRef}} The **`outline-offset`** CSS property sets the amount of space between an [outline](/en-US/docs/Web/CSS/outline) and the edge or border of an element. {{EmbedInteractiveExample("pages/css/outline-offset.html")}} ## Syntax ```css /* <length> values */ outline-offset: 3px; outline-offset: 0.2em; /* Global values */ outline-offset: inherit; outline-offset: initial; outline-offset: revert; outline-offset: revert-layer; outline-offset: unset; ``` ### Values - `{{cssxref("&lt;length&gt;")}}` - : The width of the space between the element and its outline. A negative value places the outline inside the element. A value of `0` places the outline so that there is no space between it and the element. ## Description An outline is a line that is drawn around an element, outside the border edge. The space between an element and its outline is transparent. In other words, it is the same as the parent element's background. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting outline offset in pixels #### HTML ```html <p>Gallia est omnis divisa in partes tres.</p> ``` #### CSS ```css p { outline: 1px dashed red; outline-offset: 10px; background: yellow; border: 1px solid blue; margin: 15px; } ``` #### Result {{EmbedLiveSample('Setting_outline_offset_in_pixels')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("outline")}} - {{cssxref("outline-color")}} - {{cssxref("outline-style")}} - {{cssxref("outline-width")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/@import/index.md
--- title: "@import" slug: Web/CSS/@import page-type: css-at-rule browser-compat: css.at-rules.import --- {{CSSRef}} The **`@import`** [CSS](/en-US/docs/Web/CSS) [at-rule](/en-US/docs/Web/CSS/At-rule) is used to import style rules from other valid stylesheets. An `@import` rule _must_ be defined at the top of the stylesheet, before any other at-rule (except [@charset](/en-US/docs/Web/CSS/@charset) and [@layer](/en-US/docs/Web/CSS/@layer)) and style declarations, or it will be ignored. ## Syntax ```css @import url; @import url layer; @import url layer(layer-name); @import url layer(layer-name) supports(supports-condition); @import url layer(layer-name) supports(supports-condition) list-of-media-queries; @import url layer(layer-name) list-of-media-queries; @import url supports(supports-condition); @import url supports(supports-condition) list-of-media-queries; @import url list-of-media-queries; ``` where: - _url_ - : Is a {{CSSxRef("&lt;string&gt;")}}, a `<url>`, or a {{CSSxRef("url")}} function representing the location of the resource to import. The URL may be absolute or relative. - _list-of-media-queries_ - : Is a comma-separated list of [media queries](/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries), which specify the media-dependent conditions for applying the CSS rules defined in the linked URL. If the browser does not support any of these queries, it does not load the linked resource. - _layer-name_ - : Is the name of a [cascade layer](/en-US/docs/Web/CSS/@layer) into which the contents of the linked resource are imported. - _supports-condition_ {{experimental_inline}} - : Indicates the feature(s) that the browser must support in order for the stylesheet to be imported. If the browser does not conform to the conditions specified in the _supports-condition_, it may not fetch the linked stylesheet, and even if downloaded through some other path, will not load it. The syntax of `supports()` is almost identical to that described in {{CSSxRef("@supports")}}, and that topic can be used as a more complete reference. ## Description Imported rules must come before all other types of rules, except {{CSSxRef("@charset")}} rules and layer creating [`@layer`](/en-US/docs/Web/CSS/@layer) statements. ```css example-bad * { margin: 0; padding: 0; } /* more styles */ @import url("my-imported-styles.css"); ``` As the `@import` at-rule is declared after the styles it is invalid and hence ignored. ```css example-good @import url("my-imported-styles.css"); * { margin: 0; padding: 0; } /* more styles */ ``` The `@import` rule is not a [nested statement](/en-US/docs/Web/CSS/Syntax#nested_statements). Therefore, it cannot be used inside [conditional group at-rules](/en-US/docs/Web/CSS/At-rule#conditional_group_rules). So that {{glossary("user agent", "user agents")}} can avoid retrieving resources for unsupported media types, authors may specify media-dependent import conditions. These conditional imports specify comma-separated [media queries](/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries) after the URL. In the absence of any media query, the import is not conditional on the media used. Specifying `all` for the `list-of-media-queries` has the same effect. Similarly, user agents can use the `supports()` function in an `@import` at-rule to only fetch resources if a particular feature set is (or is not) supported. This allows authors to take advantage of recently introduced CSS features, while providing graceful fallbacks for older browser versions. Note that the conditions in the `supports()` function of an `@import` at-rule can be obtained in JavaScript using {{domxref("CSSImportRule.supportsText")}}. The `@import` rule can also be used to create a [cascade layer](/en-US/docs/Web/CSS/@layer) by importing rules from a linked resource. Rules can also be imported into an existing cascade layer. The `layer` keyword or the `layer()` function is used with `@import` for this purpose. Declarations in style rules from imported stylesheets interact with the cascade as if they were written literally into the stylesheet at the point of the import. ## Formal syntax {{csssyntax}} ## Examples ### Importing CSS rules ```css @import "custom.css"; @import url("chrome://communicator/skin/"); ``` The two examples above show how to specify the _url_ as a `<string>` and as a `url()` function. ### Importing CSS rules conditional on media queries ```css @import url("fineprint.css") print; @import url("bluish.css") print, screen; @import "common.css" screen; @import url("landscape.css") screen and (orientation: landscape); ``` The `@import` rules in the above examples show media-dependent conditions that will need to be true before the linked CSS rules are applied. So for instance, the last `@import` rule will load the `landscape.css` stylesheet only on a screen device in landscape orientation. ### Importing CSS rules conditional on feature support ```css @import url("gridy.css") supports(display: grid) screen and (max-width: 400px); @import url("flexy.css") supports(not (display: grid) and (display: flex)) screen and (max-width: 400px); ``` The `@import` rules above illustrate how you might import a layout that uses a grid if `display: grid` is supported, and otherwise imports CSS that uses `display: flex`. While you can only have one `supports()` statement, you can combine any number of feature checks with `not`, `and`, and `or`, as long as you wrap each condition to be tested in parentheses. You can also use parentheses to indicate precedence. Note that if you just have a single declaration then you don't need to wrap it in additional parenthese: this is shown in the first example above. The examples above show support conditions using simple declaration syntax. You can also specify CSS functions in `supports()`, and it will evaluate to `true` if they are supported and can be evaluated on the user-agent. For example, the code below shows an `@import` that is conditional on both [child combinators](/en-US/docs/Web/CSS/Child_combinator) (`selector()`) and the `font-tech()` function: ```css @import url("whatever.css") supports((selector(h2 > p)) and (font-tech(color-COLRv1))); ``` ### Importing CSS rules into a cascade layer ```css @import "theme.css" layer(utilities); ``` In the above example, a cascade layer named `utilities` is created and it will include rules from the imported stylesheet `theme`. ```css @import url(headings.css) layer(default); @import url(links.css) layer(default); @layer default { audio[controls] { display: block; } } ``` In the above example, the rules in `headings.css` and `links.css` stylesheets cascade within the same layer as the `audio[controls]` rule. ```css @import "theme.css" layer(); @import "style.css" layer; ``` This is an example of creating two separate unnamed cascade layers and importing the linked rules into each one separately. A cascade layer declared without a name is an unnamed cascade layer. Unnamed cascade layers are finalized when created: they do not provide any means for re-arranging or adding styles and they cannot be referenced from outside. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("@media")}} - {{CSSxRef("@supports")}} - [CSS cascade and inheritance](/en-US/docs/Web/CSS/CSS_cascade) module
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/atan2/index.md
--- title: atan2() slug: Web/CSS/atan2 page-type: css-function browser-compat: css.types.atan2 --- {{CSSRef}} The **`atan2()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) is a trigonometric function that returns the inverse tangent of two values between `-infinity` and `infinity`. The function accepts two arguments and returns the number of radians representing an {{cssxref("&lt;angle&gt;")}} between `-180deg` and `180deg`. ## Syntax ```css /* Two <number> values */ transform: rotate(atan2(3, 2)); /* Two <dimension> values */ transform: rotate(atan2(1rem, -0.5rem)); /* Two <percentage> values */ transform: rotate(atan2(20%, -30%)); /* Other values */ transform: rotate(atan2(pi, 45)); transform: rotate(atan2(e, 30)); ``` ### Parameters The `atan2(y, x)` function accepts two comma-separated values as its parameters. Each value can be a {{cssxref("&lt;number&gt;")}}, a {{cssxref("&lt;dimension&gt;")}}, or a {{cssxref("&lt;percentage&gt;")}}. Both values must be of the same type, although if they are {{cssxref("&lt;dimension&gt;")}} they can be of different units (example: `atan2(100px, 5vw)` is valid). - `y` - : The y-coordinate of the point. A calculation which resolves to a {{cssxref("&lt;number&gt;")}}, a {{cssxref("&lt;dimension&gt;")}}, or a {{cssxref("&lt;percentage&gt;")}}. - `x` - : The x-coordinate of the point. A calculation which resolves to a {{cssxref("&lt;number&gt;")}}, a {{cssxref("&lt;dimension&gt;")}}, or a {{cssxref("&lt;percentage&gt;")}}. ### Return value Given two values `x` and `y`, the function `atan2(y, x)` calculates and returns the {{cssxref("&lt;angle&gt;")}} between the positive x-axis and the ray from the origin to the point `(x, y)`. ### Formal syntax {{CSSSyntax}} ## Examples ### Rotate elements The `atan2()` 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(atan2(3, 2)); } div.box-2 { transform: rotate(atan2(3%, -2%)); } div.box-3 { transform: rotate(atan2(-1, 0.5)); } div.box-4 { transform: rotate(atan2(1, 0.5)); } div.box-5 { transform: rotate(atan2(1rem, -0.5rem)); } ``` #### Result {{EmbedLiveSample('Rotate elements', '100%', '200px')}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("sin")}} - {{CSSxRef("cos")}} - {{CSSxRef("tan")}} - {{CSSxRef("asin")}} - {{CSSxRef("acos")}} - {{CSSxRef("atan")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/gap/index.md
--- title: gap slug: Web/CSS/gap page-type: css-shorthand-property browser-compat: css.properties.gap --- {{CSSRef}} The **`gap`** [CSS](/en-US/docs/Web/CSS) [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) sets the gaps ({{glossary("gutters")}}) between rows and columns. Early versions of the specification called this property `grid-gap`, and to maintain compatibility with legacy websites, browsers will still accept `grid-gap` as an alias for `gap`. {{EmbedInteractiveExample("pages/css/gap.html")}} ## Constituent properties This property is a shorthand for the following CSS properties: - {{cssxref("column-gap")}} - {{cssxref("row-gap")}} ## Syntax ```css /* One <length> value */ gap: 20px; gap: 1em; gap: 3vmin; gap: 0.5cm; /* One <percentage> value */ gap: 16%; gap: 100%; /* Two <length> values */ gap: 20px 10px; gap: 1em 0.5em; gap: 3vmin 2vmax; gap: 0.5cm 2mm; /* One or two <percentage> values */ gap: 16% 100%; gap: 21px 82%; /* calc() values */ gap: calc(10% + 20px); gap: calc(20px + 10%) calc(10% - 5px); /* Global values */ gap: inherit; gap: initial; gap: revert; gap: revert-layer; gap: unset; ``` This property is specified as a value for `<'row-gap'>` followed optionally by a value for `<'column-gap'>`. If `<'column-gap'>` is omitted, it's set to the same value as `<'row-gap'>`. `<'row-gap'>` and `<'column-gap'>` are each specified as a `<length>` or a `<percentage>`. ### Values - {{CSSxRef("&lt;length&gt;")}} - : Is the width of the gutter separating the grid lines. - {{CSSxRef("&lt;percentage&gt;")}} - : Is the width of the gutter separating the grid lines, relative to the dimension of the element. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Flex layout #### HTML ```html <div id="flexbox"> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> </div> ``` #### CSS ```css #flexbox { display: flex; flex-wrap: wrap; width: 300px; gap: 20px 5px; } #flexbox > div { border: 1px solid green; background-color: lime; flex: 1 1 auto; width: 100px; height: 50px; } ``` #### Result {{EmbedLiveSample("Flex_layout", "auto", 250)}} ### Grid layout #### HTML ```html <div id="grid"> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> </div> ``` #### CSS ```css #grid { display: grid; height: 200px; grid-template: repeat(3, 1fr) / repeat(3, 1fr); gap: 20px 5px; } #grid > div { border: 1px solid green; background-color: lime; } ``` #### Result {{EmbedLiveSample("Grid_layout", "auto", 250)}} ### Multi-column layout #### HTML ```html <p class="content-box"> This is some multi-column text with a 40px column gap created with the CSS <code>gap</code> property. Don't you think that's fun and exciting? I sure do! </p> ``` #### CSS ```css .content-box { column-count: 3; gap: 40px; } ``` #### Result {{EmbedLiveSample("Multi-column_layout", "auto", "120px")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Related CSS properties: {{CSSxRef("row-gap")}}, {{CSSxRef("column-gap")}} - Grid Layout Guide: _[Basic concepts of grid layout - Gutters](/en-US/docs/Web/CSS/CSS_grid_layout/Basic_concepts_of_grid_layout#gutters)_
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-block/index.md
--- title: border-block slug: Web/CSS/border-block page-type: css-shorthand-property browser-compat: css.properties.border-block --- {{CSSRef}} The **`border-block`** [CSS](/en-US/docs/Web/CSS) property is a [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) for setting the individual logical block border property values in a single place in the style sheet. {{EmbedInteractiveExample("pages/css/border-block.html")}} `border-block` can be used to set the values for one or more of {{cssxref("border-block-width")}}, {{cssxref("border-block-style")}}, and {{cssxref("border-block-color")}} setting both the start and end in the block dimension at once. The physical borders to which it maps depends on the element's writing mode, directionality, and text orientation. It corresponds to the {{cssxref("border-top")}} and {{cssxref("border-bottom")}} or {{cssxref("border-right")}}, and {{cssxref("border-left")}} properties depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. The borders in the other dimension can be set with {{cssxref("border-inline")}}, which sets {{cssxref("border-inline-start")}}, and {{cssxref("border-inline-end")}}. ## Constituent properties This property is a shorthand for the following CSS properties: - [`border-block-color`](/en-US/docs/Web/CSS/border-block-color) - [`border-block-style`](/en-US/docs/Web/CSS/border-block-style) - [`border-block-width`](/en-US/docs/Web/CSS/border-block-width) ## Syntax ```css border-block: 1px; border-block: 2px dotted; border-block: medium dashed blue; /* Global values */ border-block: inherit; border-block: initial; border-block: revert; border-block: revert-layer; border-block: unset; ``` ### Values The `border-block` is specified with one or more of the following, in any order: - `<'border-width'>` - : The width of the border. See {{cssxref("border-width")}}. - `<'border-style'>` - : The line style of the border. See {{cssxref("border-style")}}. - {{CSSXref("&lt;color&gt;")}} - : The color of the border. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Border with vertical text #### HTML ```html <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ```css div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-rl; border-block: 5px dashed blue; } ``` #### Results {{EmbedLiveSample("Border_with_vertical_text", 140, 140)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS Logical Properties and Values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values) - This property maps to one of the physical border properties: {{cssxref("border-top")}}, {{cssxref("border-right")}}, {{cssxref("border-bottom")}}, or {{cssxref("border-left")}}. - {{cssxref("writing-mode")}}, {{cssxref("direction")}}, {{cssxref("text-orientation")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/sign/index.md
--- title: sign() slug: Web/CSS/sign page-type: css-function browser-compat: css.types.sign --- {{CSSRef}} The **`sign()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) contains one calculation, and returns `-1` if the numeric value of the argument is negative, `+1` if the numeric value of the argument is positive, `0⁺` if the numeric value of the argument is 0⁺, and `0⁻` if the numeric value of the argument is 0⁻. > **Note:** While `{{CSSxRef("abs")}}` returns the absolute value of the argument, `sign()` returns the sign of the argument. ## Syntax ```css /* property: sign( expression ) */ top: sign(20vh - 100px); ``` ### Parameters The `sign(x)` function accepts only one value as its parameter. - `x` - : A calculation which resolves to a number. ### Return value A number representing the sign of `A`: - If `x` is positive, returns `1`. - If `x` is negative, returns `-1`. - If `x` is positive zero, returns `0`. - If `x` is negative zero, returns `-0`. - Otherwise, returns `NaN`. ### Formal syntax {{CSSSyntax}} ## Examples ### Background image position For example, in {{cssxref("background-position")}} positive percentages resolve to a negative length, and vice versa, if the background image is larger than the background area. Thus `sign(10%)` might return `1` or `-1`, depending on how the percentage is resolved! (Or even `0`, if it's resolved against a zero length.) ```css div { background-position: sign(10%); } ``` ### Position direction Another use case is to control the {{cssxref("position")}} of the element. Either a positive or a negative value. ```css div { position: absolute; top: calc(100px * sign(var(--value))); } ``` ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("abs")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/min/index.md
--- title: min() slug: Web/CSS/min page-type: css-function browser-compat: css.types.min --- {{CSSRef}} The **`min()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) lets you set the smallest (most negative) value from a list of comma-separated expressions as the value of a CSS property value. The `min()` function can be used anywhere a {{CSSxRef("&lt;length&gt;")}}, {{CSSxRef("&lt;frequency&gt;")}}, {{CSSxRef("&lt;angle&gt;")}}, {{CSSxRef("&lt;time&gt;")}}, {{CSSxRef("&lt;percentage&gt;")}}, {{CSSxRef("&lt;number&gt;")}}, or {{CSSxRef("&lt;integer&gt;")}} is allowed. {{EmbedInteractiveExample("pages/css/function-min.html")}} In the first above example, the width will be at most 200px, but will be smaller if the viewport is less than 400px wide (in which case 1vw would be 4px, so 50vw would be 200px). This technique uses an absolute unit to specify a fixed maximum value for the property, and a relative unit to allow the value to shrink to suit smaller viewports. ## Syntax The `min()` function takes one or more comma-separated expressions as its parameter, with the smallest (most negative) expression value result used as the value. The expressions can be math expressions (using arithmetic operators), literal values, or other expressions, such as {{CSSxRef("attr", "attr()")}}, that evaluate to a valid argument type (like {{CSSxRef("&lt;length&gt;")}}). You can use different units for each value in your expression, if you wish. You may also use parentheses to establish computation order when needed. ### Notes - Math expressions involving percentages for widths and heights on table columns, table column groups, table rows, table row groups, and table cells in both auto and fixed layout tables _may_ be treated as if `auto` had been specified. - It is permitted to nest `max()` and other `min()` functions as expression values. The expressions are full math expressions, so you can use direct addition, subtraction, multiplication and division without using the `calc()` function itself. - The expression can be values combining the addition ( + ), subtraction ( - ), multiplication ( \* ) and division ( / ) operators, using standard operator precedence rules. Make sure to put a space on each side of the + and - operands. The operands in the expression may be any `<length>` syntax value. - You can (and often need to) combine `min()` and `max()` values, or use `min()` within a `clamp()` or `calc()` function. - You can provide more than two arguments, if you have multiple constraints to apply. ### Formal syntax {{CSSSyntax}} ## Accessibility concerns When using `min()` to set a maximum font size, ensure that the font can still be scaled at least 200% for readability (without assistive technology like a zoom function). - [MDN Understanding WCAG, Guideline 1.4 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background) - [Understanding Success Criterion 1.4.4 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-scale.html) ## Examples ### Setting a maximum size for a label and input Another use case for `min()` is to set a maximum size on responsive form controls: enabling the width of labels and inputs to shrink as the width of the form shrinks. Let's look at some CSS: ```css input, label { padding: 2px; box-sizing: border-box; display: inline-block; width: min(40%, 400px); background-color: pink; } form { margin: 4px; border: 1px solid black; padding: 4px; } ``` Here, the form itself, along with the margin, border, and padding, will be 100% of its parent's width. We declare the input and label to be the lesser of 40% of the form width up to the padding or 400px wide, whichever is smaller. In other words, the widest that the label and input can be is 400px. The narrowest they will be is 40% of the form's width, which on a smartwatch's screen is very small. ```html <form> <label for="misc">Type something:</label> <input type="text" id="misc" name="misc" /> </form> ``` {{EmbedLiveSample("Setting_a_maximum_size_for_a_label_and_input", "100%", "110")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("calc", "calc()")}} - {{CSSxRef("clamp", "clamp()")}} - {{CSSxRef("max", "max()")}} - [CSS Values](/en-US/docs/Learn/CSS/Building_blocks/Values_and_units)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/next-sibling_combinator/index.md
--- title: Next-sibling combinator slug: Web/CSS/Next-sibling_combinator page-type: css-combinator browser-compat: css.selectors.next-sibling --- {{CSSRef}} The **next-sibling combinator** (`+`) separates two selectors and matches the second element only if it _immediately_ follows the first element, and both are children of the same parent {{DOMxRef("element")}}. ```css /* Paragraphs that come immediately after any image */ img + p { font-weight: bold; } ``` ## Syntax ```css-nolint /* The white space around the + combinator is optional but recommended. */ former_element + target_element { style properties } ``` ## Examples ### CSS ```css li:first-of-type + li { color: red; } ``` ### HTML ```html <ul> <li>One</li> <li>Two!</li> <li>Three</li> </ul> ``` ### Result {{EmbedLiveSample("Examples", "100%", 100)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Subsequent-sibling combinator](/en-US/docs/Web/CSS/Subsequent-sibling_combinator)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/animation-duration/index.md
--- title: animation-duration slug: Web/CSS/animation-duration page-type: css-property browser-compat: css.properties.animation-duration --- {{CSSRef}} The **`animation-duration`** [CSS](/en-US/docs/Web/CSS) property sets the length of time that an animation takes to complete one cycle. {{EmbedInteractiveExample("pages/css/animation-duration.html")}} It is often convenient to use the shorthand property {{ cssxref("animation") }} to set all animation properties at once. ## Syntax ```css /* Single animation */ animation-duration: auto; /* Default */ animation-duration: 6s; animation-duration: 120ms; /* Multiple animations */ animation-duration: 1.64s, 15.22s; animation-duration: 10s, 35s, 230ms; /* Global values */ animation-duration: inherit; animation-duration: initial; animation-duration: revert; animation-duration: revert-layer; animation-duration: unset; ``` ### Values - `auto` {{Experimental_Inline}} - : For time-based animations, `auto` is equivalent to a value of `0s` (see below). For [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations), `auto` fills the entire timeline with the animation. - `{{cssxref("&lt;time&gt;")}}` - : The time that an animation takes to complete one cycle. This may be specified in either seconds (`s`) or milliseconds (`ms`). The value must be positive or zero and the unit is required. If no value is provided, the default value of `0s` is used, in which case the animation still executes (the [`animationStart`](/en-US/docs/Web/API/Element/animationstart_event) and [`animationEnd`](/en-US/docs/Web/API/Element/animationend_event) events are fired). Whether or not the animation will be visible when the duration is `0s` will depend on the value of [`animation-fill-mode`](/en-US/docs/Web/CSS/animation-fill-mode), as explained below: - If `animation-fill-mode` is set to `backwards` or `both`, the first frame of the animation as defined by `animation-direction` will be displayed during [`animation-delay`](/en-US/docs/Web/CSS/animation-delay) countdown. - If `animation-fill-mode` is set to `forwards` or `both`, the last frame of the animation will be displayed, as defined by `animation-direction`, after the `animation-delay` expires. - If `animation-fill-mode` is set to `none`, the animation will have no visible effect. > **Note:** Negative values are invalid, causing the declaration to be ignored. Some early, prefixed, implementations may consider them as identical to `0s`. > **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:** When creating [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations), specifying an `animation-duration` value in seconds or milliseconds doesn't really make sense. In tests, it seemed to have no effect on scroll progress timeline animations, while on view progress timeline animations it seemed to push the animation to happen nearer the end of the timeline. However, Firefox requires an `animation-duration` to be set for it to successfully apply the animation. You are therefore advised to set `animation-duration` to `1ms` so that animations will work in Firefox, but the effect is not altered too much by it. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting animation duration This animation has an animation-duration of 0.7 seconds. #### 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("Setting animation duration","100%","250")}} 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-fill-mode")}}, {{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-padding/index.md
--- title: scroll-padding slug: Web/CSS/scroll-padding page-type: css-shorthand-property browser-compat: css.properties.scroll-padding --- {{CSSRef}} The **`scroll-padding`** [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) sets scroll padding on all sides of an element at once, much like the {{cssxref("padding")}} property does for padding on an element. {{EmbedInteractiveExample("pages/css/scroll-padding.html")}} The `scroll-padding-*` properties define offsets for the _optimal viewing region_ of the scrollport: the region used as the target region for placing things in view of the user. This allows the author to exclude regions of the scrollport that are obscured by other content (such as fixed-positioned toolbars or sidebars), or to put more breathing room between a targeted element and the edges of the scrollport. ## Constituent properties This property is a shorthand for the following CSS properties: - {{CSSXref("scroll-padding-bottom")}} - {{CSSXref("scroll-padding-left")}} - {{CSSXref("scroll-padding-right")}} - {{CSSXref("scroll-padding-top")}} ## Syntax ```css /* Keyword values */ scroll-padding: auto; /* <length> values */ scroll-padding: 10px; scroll-padding: 1em 0.5em 1em 1em; scroll-padding: 10%; /* Global values */ scroll-padding: inherit; scroll-padding: initial; scroll-padding: revert; scroll-padding: revert-layer; scroll-padding: unset; ``` ### Values - {{cssxref("&lt;length-percentage&gt;")}} - : An inwards offset from the corresponding edge of the scrollport, as a valid {{cssxref("&lt;length&gt;")}} or a {{cssxref("&lt;percentage&gt;")}}. - `auto` - : The offset is determined by the user agent. This will generally be `0px`, but the user agent is free to detect and do something else if a non-zero value is more appropriate. ## Formal definition {{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/counter-reset/index.md
--- title: counter-reset slug: Web/CSS/counter-reset page-type: css-property browser-compat: css.properties.counter-reset --- {{CSSRef}} The **`counter-reset`** [CSS](/en-US/docs/Web/CSS) property creates named [CSS counters](/en-US/docs/Web/CSS/CSS_counter_styles/Using_CSS_counters) and initializes them to a specific value. It supports creating counters that count up from one to the number of elements, as well as those that count down from the number of elements to one. {{EmbedInteractiveExample("pages/css/counter-reset.html")}} ## Syntax ```css /* Create a counter with initial default value 0 */ counter-reset: my-counter; /* Create a counter and initialize as "-3" */ counter-reset: my-counter -3; /* Create a reversed counter with initial default value */ counter-reset: reversed(my-counter); /* Create a reversed counter and initialize as "-1" */ counter-reset: reversed(my-counter) -1; /* Create reversed and regular counters at the same time */ counter-reset: reversed(pages) 10 items 1 reversed(sections) 4; /* Remove all counter-reset declarations in less specific rules */ counter-reset: none; /* Global values */ counter-reset: inherit; counter-reset: initial; counter-reset: revert; counter-reset: revert-layer; counter-reset: unset; ``` ### Values The `counter-reset` property accepts a list of one or more space-separated counter names or the keyword `none`. For counter names, regular counters use the format `<counter-name>`, and reversed counters use `reversed(<counter-name>)`, where `<counter-name>` is a {{cssxref("custom-ident", "&lt;custom-ident&gt;")}} or `list-item` for the built-in {{HTMLElement("ol")}} counter. Optionally, each counter name can be followed by an `<integer>` to set its initial value. - {{cssxref("custom-ident", "&lt;custom-ident&gt;")}} - : Specifies the counter name to create and initialize using the {{cssxref("custom-ident", "&lt;custom-ident&gt;")}} format. - {{cssxref("&lt;integer&gt;")}} - : The value to reset the counter to on each occurrence of the element. Defaults to `0` if not specified. - `none` - : Specifies that no counter initialization should occur. This value is useful for overriding `counter-reset` values in less specific rules. ## Description The `counter-reset` property can create both regular and, in browsers that support it, reversed counters. You can create multiple regular and reversed counters, each separated by a space. Counters can be a standalone name or a space-separated name-value pair. After creating a counter using `counter-reset`, you can adjust its value by using the {{cssxref("counter-set")}} property. This is counterintuitive because, despite its name, the `counter-reset` property is used for creating and initializing counters, while the `counter-set` property is used for resetting the value of an existing counter. Setting `counter-increment: none` on a selector with greater specificity overrides the creation of the named counter set on selectors with lower specificity. ### Default initial values The default initial values of both regular and reversed counters make it easy to implement the two most common numbering patterns: counting up from one to the number of elements and counting down from the number of elements to one, respectively. By including a counter value for a named counter, your counter can count up or down, starting at an integer value. Regular counters default to `0` if no reset value is provided. By default, regular counters increment by one, which can be adjusted with the {{cssxref("counter-increment")}} property. ```css h1 { /* Create the counters "chapter" and "page" and set to initial default value. Create the counter "section" and set to "4". */ counter-reset: chapter section 4 page; } ``` ### Reversed counters When creating reversed counters without a value, the counter will start with the value equal to the number of elements in the set, counting down so the last element in the set is `1`. By default, reverse counters decrement by one; this can also be changed with the `counter-increment` property. ```css h1 { /* Create reversed counters "chapter" and "section". Set "chapter" as the number of elements and "section" as "10". Create the counter "pages" with the initial default value. */ counter-reset: reversed(chapter) reversed(section) 10 pages; } ``` ### Built-in `list-item` counter Ordered lists ({{HTMLElement("ol")}}) come with built-in `list-item` counters that control their numbering. These counters automatically increase or decrease by one with each list item. The `counter-reset` property can be used to reset the `list-item` counters. Like with other counters, you can override the default increment value for `list-item` counters by using the {{cssxref("counter-increment")}} property. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Overriding the `list-item` counter In this example, the `counter-reset` property is used to set a starting value for an implicit `list-item` counter. #### HTML ```html <ol> <li>First</li> <li>Second</li> <li>Third</li> <li>Fourth</li> <li>Fifth</li> </ol> ``` #### CSS Using `counter-reset`, we set the implicit `list-item` counter to start at a value other than the default `1`: ```css ol { counter-reset: list-item 3; } ``` #### Result {{EmbedLiveSample("Overriding the list-item counter", 140, 300)}} Using `counter-reset`, we were able to set the implicit `list-item` counter to start counting at `3`, similar to the effect of writing [`<ol start="3">`](/en-US/docs/Web/HTML/Element/ol#start) in HTML. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [Using CSS Counters](/en-US/docs/Web/CSS/CSS_counter_styles/Using_CSS_counters) guide - {{cssxref("counter-increment")}} property - {{cssxref("counter-set")}} property - {{cssxref("@counter-style")}} at-rule - {{cssxref("counter", "counter()")}} and {{cssxref("counters", "counters()")}} functions - {{cssxref("content")}} property - {{cssxref("::marker")}} pseudo-class - [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/box-flex/index.md
--- title: box-flex slug: Web/CSS/box-flex page-type: css-property status: - deprecated - non-standard browser-compat: css.properties.box-flex --- {{CSSRef}}{{Non-standard_Header}}{{Deprecated_Header}} > **Warning:** This is a property for controlling parts of the XUL box model. It does not match either the old CSS Flexible Box Layout Module drafts for '`box-flex`' (which were based on this property) or the behavior of '`-webkit-box-flex`' (which is based on those drafts). See [flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox) for information about the current standard. The **`-moz-box-flex`** and **`-webkit-box-flex`** [CSS](/en-US/docs/Web/CSS) properties specify how a `-moz-box` or `-webkit-box` grows to fill the box that contains it, in the direction of the containing box's layout. ## Syntax ```css /* <number> values */ -moz-box-flex: 0; -moz-box-flex: 2; -moz-box-flex: 3.5; -webkit-box-flex: 0; -webkit-box-flex: 2; -webkit-box-flex: 3.5; /* Global values */ -moz-box-flex: inherit; -moz-box-flex: initial; -moz-box-flex: revert; -moz-box-flex: revert-layer; -moz-box-flex: unset; -webkit-box-flex: inherit; -webkit-box-flex: initial; -webkit-box-flex: revert; -webkit-box-flex: revert-layer; -webkit-box-flex: unset; ``` The `box-flex` property is specified as a {{CSSxRef("&lt;number&gt;")}}. If the value is 0, the box does not grow. If it is greater than 0, the box grows to fill a proportion of the available space. ## Notes The containing box allocates the available extra space in proportion to the flex value of each of the content elements. Content elements that have zero flex do not grow. If only one content element has nonzero flex, then it grows to fill the available space. Content elements that have the same flex grow by the same absolute amounts. If the flex value is set using the element's `flex` attribute, then the style is ignored. To make XUL elements in a containing box the same size, set the containing box's `equalsize` attribute to the value `always`. This attribute does not have a corresponding CSS property. A trick to make all content elements in a containing box the same size, is to give them all a fixed size (e.g. `height: 0`), and the same `box-flex` value greater than zero (e.g. `-moz-box-flex: 1`). ## Formal definition {{cssinfo}} ## Formal syntax ```plain box-flex = <number> ``` ## Examples ### Setting box-flex ```html <!doctype html> <html lang="en-US"> <head> <meta charset="UTF-8" /> <title>-moz-box-flex example</title> <style> div.example { display: -moz-box; display: -webkit-box; border: 1px solid black; width: 100%; } div.example > p:nth-child(1) { -moz-box-flex: 1; /* Mozilla */ -webkit-box-flex: 1; /* WebKit */ border: 1px solid black; } div.example > p:nth-child(2) { -moz-box-flex: 0; /* Mozilla */ -webkit-box-flex: 0; /* WebKit */ border: 1px solid black; } </style> </head> <body> <div class="example"> <p>I will expand to fill extra space</p> <p>I will not expand</p> </div> </body> </html> ``` ## Specifications Not part of any standard. ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("box-orient")}} - {{CSSxRef("box-pack")}} - {{CSSxRef("box-direction")}} - {{CSSxRef("flex")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/masonry-auto-flow/index.md
--- title: masonry-auto-flow slug: Web/CSS/masonry-auto-flow page-type: css-property status: - experimental browser-compat: css.properties.masonry-auto-flow --- {{CSSRef}}{{SeeCompatTable}} The **`masonry-auto-flow`** CSS property modifies how items are placed when using [masonry](/en-US/docs/Web/CSS/CSS_grid_layout/Masonry_layout) in [CSS Grid Layout](/en-US/docs/Web/CSS/CSS_grid_layout). ## Syntax ```css /* Keyword values */ masonry-auto-flow: pack; masonry-auto-flow: next; masonry-auto-flow: ordered; masonry-auto-flow: definite-first; masonry-auto-flow: next ordered; /* Global values */ masonry-auto-flow: inherit; masonry-auto-flow: initial; masonry-auto-flow: revert; masonry-auto-flow: revert-layer; masonry-auto-flow: unset; ``` This property may take one of two forms: - A single keyword: one of `pack`, `next`, `definite-first`, or `ordered` - Two keywords, for example `next ordered`. ### Values - `pack` - : As per the default masonry algorithm, items will be placed into the track with the most room. - `next` - : Items will be placed one after the other in the grid axis. - `definite-first` - : Display as in the default masonry algorithm, placing items with a definite place first before placing other masonry items. - `ordered` - : Ignore any items with a definite placement, and place everything according to order-modified document order. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Using the next keyword #### HTML ```html <div id="grid"> <div id="item1"></div> <div id="item2"></div> <div id="item3"></div> <div id="item4"></div> <div id="item5"></div> </div> <select id="flow"> <option value="pack">pack</option> <option value="next">next</option> </select> ``` #### CSS ```css #grid { height: 200px; width: 200px; display: grid; gap: 10px; grid-template-columns: repeat(3, 1fr); grid-template-rows: masonry; masonry-auto-flow: pack; } #item1 { background-color: lime; height: 2em; } #item2 { background-color: yellow; } #item3 { background-color: blue; height: 3em; } #item4 { background-color: red; height: 2.5em; } #item5 { background-color: aqua; height: 4em; } ``` ```js const selectElem = document.querySelector("select"); function changeMasonryFlow() { const grid = document.getElementById("grid"); const direction = document.getElementById("flow"); const masonryAutoFlow = direction.value === "pack" ? "pack" : "next"; grid.style.masonryAutoFlow = masonryAutoFlow; } selectElem.addEventListener("change", changeMasonryFlow); ``` #### Result {{EmbedLiveSample("Using_the_next_keyword", "200px", "230px")}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - Related CSS properties: {{cssxref("align-tracks")}}, {{cssxref("justify-tracks")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_values_and_units/index.md
--- title: CSS values and units slug: Web/CSS/CSS_Values_and_Units page-type: guide spec-urls: - https://drafts.csswg.org/css-values/ - https://drafts.csswg.org/css-color/ - https://drafts.csswg.org/css-images/ --- {{CSSRef}} Every CSS declaration includes a property / value pair. Depending on the property, the value can include a single integer or keyword, to a series of keywords and values with or without units. There are a common set of data types β€” values and units β€” that CSS properties accept. Below is an overview of most of these data types. Refer to the page for each value type for more detailed information. ## Textual data types - {{cssxref("&lt;custom-ident&gt;")}} - Pre-defined keywords as an `<ident>` - {{cssxref("&lt;string&gt;")}} - {{cssxref("url","url()")}} Text data types are either `<string>`, a quoted series of characters, or an `<ident>`, a "CSS Identifier" which is an unquoted string. A `<string>` must be quoted with either single or double quotes. CSS Identifiers, listed in the specifications as `<ident>` or `<custom-ident>`, must be unquoted. In the CSS specifications, values that can be defined by the web developer, like keyframe animations, font-family names, or grid areas are listed as a {{cssxref("&lt;custom-ident&gt;")}}, {{cssxref("&lt;string&gt;")}}, or both. When both quoted and unquoted user defined text values are permitted, the specification will list `<custom-ident> | <string>`, meaning quotes are optional, such as is the case with animation names: ```css @keyframe validIdent { /* keyframes go here */ } @keyframe 'validString' { /* keyframes go here */ } ``` Some text values are not valid if encompassed in quotes. For example, the value of {{cssxref("grid-area")}} can be a `<custom-ident>`, so if we had a grid area named `content` we would use it without quotes: ```css .item { grid-area: content; } ``` In comparison, a data type that is a {{cssxref("&lt;string&gt;")}}, such as a string value of the {{cssxref("content")}} property, must be quoted: ```css .item::after { content: "This is my content."; } ``` While you can generally create any name you want, including using emojis, the identifier can't be `none`, `unset`, `initial`, or `inherit`, start with a digit or two dashes, and generally you don't want it to be any other pre-defined CSS keyword. See the {{cssxref("&lt;custom-ident&gt;")}} and {{cssxref("&lt;string&gt;")}} reference pages for more details. ### Pre-defined keyword values Pre-defined keywords are text values defined by the specification for that property. These keywords are also CSS Identifiers and are therefore used without quotes. When viewing CSS property value syntax in a CSS specification or the MDN property page, allowable keywords will be listed in the following form. The following values are the pre-defined keyword values allowed for {{cssxref("float")}}. ```plain left | right | none | inline-start | inline-end ``` Such values are used without quotes: ```css .box { float: left; } ``` ### CSS-wide values In addition to the pre-defined keywords that are part of the specification for a property, all CSS properties accept the CSS-wide property values {{cssxref("initial")}}, {{cssxref("inherit")}}, {{cssxref("unset")}}, {{cssxref("revert")}}, and {{cssxref("revert-layer")}}, which explicitly specify defaulting behaviors. - {{cssxref("initial")}} - : Represents the value specified as the property's initial value. - {{cssxref("inherit")}} - : Represents the computed value of the property on the element's parent, provided it is inherited. - {{cssxref("unset")}} - : Acts as either `inherit` or `initial`, depending on whether the property is inherited or not. - {{cssxref("revert")}} - : Resets the property to its inherited value if it inherits from its parent or to the default value established by the user agent's stylesheet (or by user styles, if any exist). - {{cssxref("revert-layer")}} - : Rolls back the value of a property in a [cascade layer](/en-US/docs/Web/CSS/@layer) to the value of the property in a CSS rule matching the element in a previous cascade layer. The value of the property with this keyword is recalculated as if no rules were specified on the target element in the current cascade layer. ### URLs A {{cssxref("url","url()")}} type uses functional notation, which accepts a `<string>` that is a URL. This may be an absolute URL or a relative URL. For example, if you wanted to include a background image, you might use either of the following. ```css .box { background-image: url("images/my-background.png"); } .box { background-image: url("https://www.exammple.com/images/my-background.png"); } ``` The parameter for `url()` can be either quoted or unquoted. If unquoted, it is parsed as a `<url-token>`, which has extra requirements including the escaping of certain characters. See {{cssxref("url","url()")}} for more information. ## Numeric data types - {{cssxref("&lt;integer&gt;")}} - {{cssxref("&lt;number&gt;")}} - {{cssxref("&lt;dimension&gt;")}} - {{cssxref("&lt;percentage&gt;")}} ### Integers An integer is one or more decimal digits, `0` through `9`, such as `1024` or `-55`. An integer may be preceded by a `+` or `-` symbol, with no space between the symbol and the integer. ### Numbers A {{cssxref("&lt;number&gt;")}} represents a real number, which may or may not have a decimal point with a fractional component, for example `0.255`, `128` or `-1.2`. Numbers may also be preceded by a `+` or `-` symbol. ### Dimensions A {{cssxref("&lt;dimension&gt;")}} is a `<number>` with a unit attached to it, for example `45deg`, `100ms`, or `10px`. The attached unit identifier is case insensitive. There is never a space or any other characters between the number and the unit identifier: i.e. `1 cm` is not valid. CSS uses dimensions to specify: - {{cssxref("&lt;length&gt;")}} (Distance units) - {{cssxref("&lt;angle&gt;")}} - {{cssxref("&lt;time&gt;")}} - {{cssxref("&lt;frequency&gt;")}} - {{cssxref("&lt;flex&gt;")}} - {{cssxref("&lt;resolution&gt;")}} These are all covered in subsections below. #### Distance units Where a distance unit, also known as a length, is allowed as a value for a property, this is described as the {{cssxref("&lt;length&gt;")}} type. There are two types of lengths in CSS: relative and absolute. Relative length units specify a length in relation to something else. There are two types of relative lengths: font-relative lengths and viewport-percentage lengths. These both come in two types. Font-relative length units are either local font-relative or root font-relative. Viewport percentage lengths are either relative to the viewport height or width size or, as defined in the [CSS Containment module](/en-US/docs/Web/CSS/CSS_containment), relative to a [container](/en-US/docs/Web/CSS/CSS_containment/Container_queries#container_query_length_units). ##### Local font-relative lengths Local font-relative lengths are relative to the "local" font size or line height, specifying a length in relation to a computed size of a feature of the [element](/en-US/docs/Web/HTML/Element) itself, or relative to the element's inherited value in the case of a circular reference, such as the `em` value for a {{cssxref("font-size")}} property or a `lh` value for a {{cssxref("line-height")}} property. For example, `em` is relative to the font size on the element and `ex` is relative to the x-height of the element's font. | Unit | Relative to | | ----- | -------------------------------------------------------------------------------------------------------------------------------------- | | `cap` | Cap height (the nominal height of capital letters) of the element's font. | | `ch` | Average character advance of a narrow glyph in the element's font, as represented by the "0" (ZERO, U+0030) glyph. | | `em` | Font size of the element's font. | | `ex` | x-height of the element's font. | | `ic` | Average character advance of a full-width glyph in the element's font, as represented by the "ζ°΄" (CJK water ideograph, U+6C34) glyph. | | `lh` | Line height of the element. | ##### Root font-relative lengths Root font-relative lengths specify a length in relation to the element's {{CSSxRef(":root", "root element")}} ancestor, such as {{HTMLElement("HTML")}} or {{SVGElement("SVG")}}. For example, `rem` is relative to the font size on the root element and `rex` is the x-height of the root element's font. | Unit | Relative to | | ------ | ------------------------------------------------------------------------------------------------------------------------------------------- | | `rcap` | Cap height (the nominal height of capital letters) of the root element's font. | | `rch` | Average character advance of a narrow glyph in the root element's font, as represented by the "0" (ZERO, U+0030) glyph. | | `rem` | Font size of the root element's font. | | `rex` | x-height of the root element's font. | | `ric` | Average character advance of a full-width glyph in the root element's font, as represented by the "ζ°΄" (CJK water ideograph, U+6C34) glyph. | | `rlh` | Line height of the root element. | ##### Viewport units Viewport unit lengths specify a length relative to the dimensions of the [viewport](/en-US/docs/Glossary/Viewport). For example, `vw` is relative to the width of the viewport and `vh` is relative to the height of the viewport. | Unit | Relative to | | ------ | ---------------------------------------------------------------------------------------------------------------------------------- | | `dvh` | 1% of the [dynamic](/en-US/docs/Web/CSS/length#dynamic) viewport's height. | | `dvw` | 1% of the [dynamic](/en-US/docs/Web/CSS/length#dynamic) viewport's width. | | `lvh` | 1% of the [large](/en-US/docs/Web/CSS/length#large) viewport's height. | | `lvw` | 1% of the [large](/en-US/docs/Web/CSS/length#large) viewport's width. | | `svh` | 1% of the [small](/en-US/docs/Web/CSS/length#small) viewport's height. | | `svw` | 1% of the [small](/en-US/docs/Web/CSS/length#small) viewport's width. | | `vb` | 1% of viewport's size in the root element's [block axis](/en-US/docs/Web/CSS/CSS_logical_properties_and_values#block_vs._inline). | | `vh` | 1% of viewport's height. | | `vi` | 1% of viewport's size in the root element's [inline axis](/en-US/docs/Web/CSS/CSS_logical_properties_and_values#block_vs._inline). | | `vmax` | 1% of viewport's larger dimension. | | `vmin` | 1% of viewport's smaller dimension. | | `vw` | 1% of viewport's width. | ##### Container units Container query length units specify a length relative to the dimensions of a [query container](/en-US/docs/Web/CSS/CSS_containment/Container_queries). For example, `cqw` is relative to the width of the query container and `cqh` is relative to the height of the query container. | Unit | Relative to | | ------- | ------------------------------------- | | `cqb` | 1% of a query container's block size | | `cqh` | 1% of a query container's height | | `cqi` | 1% of a query container's inline size | | `cqmax` | The larger value of `cqi` or `cqb` | | `cqmin` | The smaller value of `cqi` or `cqb` | | `cqw` | 1% of a query container's width | #### Absolute length units Absolute length units are fixed to a physical length: either an inch or a centimeter. Many of these units are therefore more useful when the output is a fixed size media, such as print. For example, `mm` is a physical millimeter, 1/10th of a centimeter. | Unit | Name | Equivalent to | | ---- | ------------------- | ------------------- | | `cm` | Centimeters | 1cm = 96px/2.54 | | `in` | Inches | 1in = 2.54cm = 96px | | `mm` | Millimeters | 1mm = 1/10th of 1cm | | `pc` | Picas | 1pc = 1/6th of 1in | | `pt` | Points | 1pt = 1/72th of 1in | | `px` | Pixels | 1px = 1/96th of 1in | | `Q` | Quarter-millimeters | 1Q = 1/40th of 1cm | When including a length value, if the length is `0`, the unit identifier is not required. Otherwise, the unit identifier is required, is case insensitive, and must come immediately after the numeric part of the value, with no space in-between. ##### Angle units Angle values are represented by the type {{cssxref("&lt;angle&gt;")}} and accept the following values: | Unit | Name | Description | | ------ | -------- | ---------------------------------------- | | `deg` | Degrees | There are 360 degrees in a full circle. | | `grad` | Gradians | There are 400 gradians in a full circle. | | `rad` | Radians | There are 2Ο€ radians in a full circle. | | `turn` | Turns | There is 1 turn in a full circle. | ##### Time units Time values are represented by the type {{cssxref("&lt;time&gt;")}}. When including a time value, the unit identifier β€” the `s` or `ms` β€” is required. It accepts the following values. | Unit | Name | Description | | ---- | ------------ | ----------------------------------------- | | `ms` | Milliseconds | There are 1,000 milliseconds in a second. | | `s` | Seconds | | ##### Frequency units Frequency values are represented by the type {{cssxref("&lt;frequency&gt;")}}. It accepts the following values. | Unit | Name | Description | | ----- | --------- | ------------------------------------------------ | | `Hz` | Hertz | Represents the number of occurrences per second. | | `kHz` | KiloHertz | A kiloHertz is 1000 Hertz. | `1Hz`, which can also be written as `1hz` or `1HZ`, is one cycle per second. ##### Flex units Flex units are represented by the type {{cssxref("&lt;flex&gt;")}}. It accepts the following value. | Unit | Name | Description | | ---- | ---- | ---------------------------------------------------- | | `fr` | Flex | Represents a flexible length within a grid container | ##### Resolution units Resolution units are represented by the type {{cssxref("&lt;resolution&gt;")}}. They represent the size of a single dot in a graphical representation, such as a screen, by indicating how many of these dots fit in a CSS inch, centimeter, or pixel. It accepts the following values: | Unit | Description | | ----------- | -------------------- | | `dpcm` | Dots per centimeter. | | `dpi` | Dots per inch. | | `dppx`, `x` | Dots per px unit. | #### Percentages A {{cssxref("&lt;percentage&gt;")}} is a type that represents a fraction of some other value. Percentage values are always relative to another quantity, for example a length. Each property that allows percentages also defines the quantity to which the percentage refers. This quantity can be a value of another property of the same element, the value of a property of an ancestor element, a measurement of a containing block, or something else. As an example, if you specify the {{cssxref("width")}} of a box as a percentage, it refers to the percentage of the box's parent's computed width: ```css .box { width: 50%; } ``` ### Mixing percentages and dimensions Some properties accept a dimension that could be either one of two types, for example a `<length>` **or** a `<percentage>`. In this case the allowed value is detailed in the specification as a combination unit, e.g. {{cssxref("&lt;length-percentage&gt;")}}. Other possible combinations are as follows: - {{cssxref("&lt;frequency-percentage&gt;")}} - {{cssxref("&lt;angle-percentage&gt;")}} - {{cssxref("&lt;time-percentage&gt;")}} ### Special data types (defined in other specs) - {{cssxref("&lt;color&gt;")}} - {{cssxref("&lt;image&gt;")}} - {{cssxref("&lt;position&gt;")}} #### Color The {{cssxref("&lt;color&gt;")}} value specifies the color of an element feature (e.g. it's background color), and is defined in the [CSS Color Module](https://drafts.csswg.org/css-color-3/). #### Image The {{cssxref("&lt;image&gt;")}} value specifies all the different types of image that can be used in CSS, and is defined in the [CSS Image Values and Replaced Content Module](https://www.w3.org/TR/css-images-4/). #### Position The {{cssxref("&lt;position&gt;")}} type defines 2D positioning of an object inside a positioning area, for example a background image inside a container. This type is interpreted as a {{cssxref("background-position")}} and therefore specified in the [CSS Backgrounds and Borders specification](https://www.w3.org/TR/css-backgrounds-3/). ### Functional notation - {{cssxref("calc", "calc()")}} - {{cssxref("min", "min()")}} - {{cssxref("max", "max()")}} - {{cssxref("minmax", "minmax()")}} - {{cssxref("clamp", "clamp()")}} - {{cssxref("toggle", "toggle()")}} - {{cssxref("attr", "attr()")}} [Functional notation](/en-US/docs/Web/CSS/CSS_Functions) is a type of value that can represent more complex types or invoke special processing by CSS. The syntax starts with the name of the function immediately followed by a left parenthesis `(` followed by the argument(s) to the notation followed by a right parenthesis `)`. Functions can take multiple arguments, which are formatted similarly to a CSS property value. White space is allowed, but optional inside the parentheses. (But see notes regarding whitespace within pages for `min()`, `max()`, `minmax()`, and `clamp()` functions.) Some legacy functional notations such as `rgba()` use commas, but generally commas are only used to separate items in a list. If a comma is used to separate arguments, white space is optional before and after the comma. ## Specifications {{Specifications}} ## See also - [CSS Basic Data Types](/en-US/docs/Web/CSS/CSS_Types) - [Introduction to CSS: Values and Units](/en-US/docs/Learn/CSS/Building_blocks/Values_and_units) - [Trigonometric functions in CSS](https://web.dev/articles/css-trig-functions)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_after/index.md
--- title: "::after" slug: Web/CSS/::after page-type: css-pseudo-element browser-compat: css.selectors.after --- {{CSSRef}} In CSS, **`::after`** creates a [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) that is the last child of the selected element. It is often used to add cosmetic content to an element with the {{CSSxRef("content")}} property. It is inline by default. {{EmbedInteractiveExample("pages/tabbed/pseudo-element-after.html", "tabbed-standard")}} > **Note:** The pseudo-elements generated by `::before` and `::after` are [contained by the element's formatting box](https://www.w3.org/TR/CSS2/generate.html#before-after-content), and thus don't apply to _[replaced elements](/en-US/docs/Web/CSS/Replaced_element)_ such as {{HTMLElement("img")}}, or to {{HTMLElement("br")}} elements. ## Syntax ```css-nolint ::after { content: /* value */; /* properties */ } ``` If the [`content`](/en-US/docs/Web/CSS/content) property is not specified, has an invalid value, or has `normal` or `none` as a value, then the `::after` pseudo-element is not rendered. It behaves as if `display: none` is set. > **Note:** CSS introduced the `::after` notation (with two colons) to distinguish [pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes) from [pseudo-elements](/en-US/docs/Web/CSS/Pseudo-elements). For backward compatibility, browsers also accept `:after`, introduced earlier. ## Examples ### Simple usage Let's create two classes: one for boring paragraphs and one for exciting ones. We can use these classes to add pseudo-elements to the end of paragraphs. #### HTML ```html <p class="boring-text">Here is some plain old boring text.</p> <p>Here is some normal text that is neither boring nor exciting.</p> <p class="exciting-text">Contributing to MDN is easy and fun.</p> ``` #### CSS ```css .exciting-text::after { content: " <- EXCITING!"; color: green; } .boring-text::after { content: " <- BORING"; color: red; } ``` #### Result {{EmbedLiveSample('Simple_usage', 500, 150)}} ### Decorative example We can style text or images in the {{CSSxRef("content")}} property almost any way we want. #### HTML ```html <span class="ribbon">Look at the orange box after this text. </span> ``` #### CSS ```css .ribbon { background-color: #5bc8f7; } .ribbon::after { content: "This is a fancy orange box."; background-color: #ffba10; border-color: black; border-style: dotted; } ``` #### Result {{EmbedLiveSample('Decorative_example', 450, 20)}} ### Tooltips This example uses `::after`, in conjunction with the [`attr()`](/en-US/docs/Web/CSS/attr) CSS expression and a `data-descr` [custom data attribute](/en-US/docs/Web/HTML/Global_attributes/data-*), to create tooltips. No JavaScript is required! We can also support keyboard users with this technique, by adding a `tabindex` of `0` to make each `span` keyboard focusable, and using a CSS `:focus` selector. This shows how flexible `::before` and `::after` can be, though for the most accessible experience a semantic disclosure widget created in some other way (such as with [details and summary](/en-US/docs/Web/HTML/Element/details) elements) is likely to be more appropriate. #### HTML ```html <p> Here we have some <span tabindex="0" data-descr="collection of words and punctuation"> text </span> with a few <span tabindex="0" data-descr="small popups that appear when hovering"> tooltips</span >. </p> ``` #### CSS ```css span[data-descr] { position: relative; text-decoration: underline; color: #00f; cursor: help; } span[data-descr]:hover::after, span[data-descr]:focus::after { content: attr(data-descr); position: absolute; left: 0; top: 24px; min-width: 200px; border: 1px #aaaaaa solid; border-radius: 10px; background-color: #ffffcc; padding: 12px; color: #000000; font-size: 14px; z-index: 1; } ``` #### Result {{EmbedLiveSample('Tooltips', 450, 120)}} ## Accessibility concerns Using an `::after` pseudo-element to add content is discouraged, as it is not reliably accessible to screen readers. ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{CSSxRef("::before")}} - {{CSSxRef("content")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/shape-image-threshold/index.md
--- title: shape-image-threshold slug: Web/CSS/shape-image-threshold page-type: css-property browser-compat: css.properties.shape-image-threshold --- {{CSSRef}} The **`shape-image-threshold`** [CSS](/en-US/docs/Web/CSS) property sets the alpha channel threshold used to extract the shape using an image as the value for {{cssxref("shape-outside")}}. {{EmbedInteractiveExample("pages/css/shape-image-threshold.html")}} Any pixels whose alpha component's value is greater than the threshold are considered to be part of the shape for the purposes of determining its boundaries. For example, a value of `0.5` means that the shape will enclose all the pixels that are more than 50% opaque. ## Syntax ```css /* <number> value */ shape-image-threshold: 0.7; /* Global values */ shape-image-threshold: inherit; shape-image-threshold: initial; shape-image-threshold: revert; shape-image-threshold: revert-layer; shape-image-threshold: unset; ``` ### Values - {{cssxref("&lt;alpha-value&gt;")}} - : Sets the threshold used for extracting a shape from an image. The shape is defined by the pixels whose alpha value is greater than the threshold. Values outside the range 0.0 (fully transparent) to 1.0 (fully opaque) are clamped to this range. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### Aligning text to a gradient This example creates a {{HTMLElement("div")}} block with a gradient background image. The gradient is established as a CSS shape using `shape-outside`, so that pixels within the gradient which are at least 20% opaque (that is, those pixels with an alpha component greater than 0.2) are considered part of the shape. #### HTML ```html <div id="gradient-shape"></div> <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vel at commodi voluptates enim, distinctio officia. Saepe optio accusamus doloribus sint facilis itaque ab nulla, dolor molestiae assumenda cum sit placeat adipisci, libero quae nihil porro debitis laboriosam inventore animi impedit nostrum nesciunt quisquam expedita! Dolores consectetur iure atque a mollitia dicta repudiandae illum exercitationem aliquam repellendus ipsum porro modi, id nemo eligendi, architecto ratione quibusdam iusto nisi soluta? Totam inventore ea eum sed velit et eligendi suscipit accusamus iusto dolore, at provident eius alias maxime pariatur non deleniti ipsum sequi rem eveniet laboriosam magni expedita? </p> ``` #### CSS ```css #gradient-shape { width: 150px; height: 150px; float: left; background-image: linear-gradient(30deg, black, transparent 80%, transparent); shape-outside: linear-gradient(30deg, black, transparent 80%, transparent); shape-image-threshold: 0.2; } ``` The shape is established here using {{cssxref("background-image")}} with a linear gradient rather than an image file. The same gradient is also used as the image from which the shape is derived for establishing the float area, using the {{cssxref("shape-outside")}} property. The 20% opacity threshold for treating gradient pixels as part of the shape is then established using `shape-image-threshold` with a value of `0.2`. #### Result {{EmbedLiveSample('Aligning_text_to_a_gradient', 600, 230)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS Shapes](/en-US/docs/Web/CSS/CSS_shapes) - [Overview of CSS Shapes](/en-US/docs/Web/CSS/CSS_shapes/Overview_of_shapes) - {{cssxref("&lt;basic-shape&gt;")}} - {{cssxref("shape-outside")}} - {{cssxref("shape-margin")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/outline-style/index.md
--- title: outline-style slug: Web/CSS/outline-style page-type: css-property browser-compat: css.properties.outline-style --- {{CSSRef}} The **`outline-style`** [CSS](/en-US/docs/Web/CSS) property sets the style of an element's outline. An outline is a line that is drawn around an element, outside the {{cssxref("border")}}. {{EmbedInteractiveExample("pages/css/outline-style.html")}} It is often more convenient to use the shorthand property {{cssxref("outline")}} when defining the appearance of an outline. ## Syntax ```css /* Keyword values */ outline-style: auto; outline-style: none; outline-style: dotted; outline-style: dashed; outline-style: solid; outline-style: double; outline-style: groove; outline-style: ridge; outline-style: inset; outline-style: outset; /* Global values */ outline-style: inherit; outline-style: initial; outline-style: revert; outline-style: revert-layer; outline-style: unset; ``` The `outline-style` property is specified as any one of the values listed below. ### Values - `auto` - : Permits the user agent to render a custom outline style. - `none` - : No outline is used. The {{cssxref("outline-width")}} is `0`. - `dotted` - : The outline is a series of dots. - `dashed` - : The outline is a series of short line segments. - `solid` - : The outline is a single line. - `double` - : The outline is two single lines. The {{cssxref("outline-width")}} is the sum of the two lines and the space between them. - `groove` - : The outline looks as though it were carved into the page. - `ridge` - : The opposite of `groove`: the outline looks as though it were extruded from the page. - `inset` - : The outline makes the box look as though it were embedded in the page. - `outset` - : The opposite of `inset`: the outline makes the box look as though it were coming out of the page. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting outline style to auto The `auto` value indicates a custom outline style, described in [the specification](https://www.w3.org/TR/css-ui-3/#outline-style) as "typically a style \[that] is either a user interface default for the platform, or perhaps a style that is richer than can be described in detail in CSS, e.g. a rounded edge outline with semi-translucent outer pixels that appears to glow". #### HTML ```html <div> <p class="auto">Outline Demo</p> </div> ``` #### CSS ```css .auto { outline-style: auto; /* same result as "outline: auto" */ } /* To make the Demo clearer */ * { outline-width: 10px; padding: 15px; } ``` #### Result {{ EmbedLiveSample('Setting_outline_style_to_auto') }} ### Setting outline style to dashed and dotted #### HTML ```html <div> <div class="dotted"> <p class="dashed">Outline Demo</p> </div> </div> ``` #### CSS ```css .dotted { outline-style: dotted; /* same result as "outline: dotted" */ } .dashed { outline-style: dashed; } /* To make the Demo clearer */ * { outline-width: 10px; padding: 15px; } ``` #### Result {{ EmbedLiveSample('Setting_outline_style_to_dashed_and_dotted') }} ### Setting outline style to solid and double #### HTML ```html <div> <div class="solid"> <p class="double">Outline Demo</p> </div> </div> ``` #### CSS ```css .solid { outline-style: solid; } .double { outline-style: double; } /* To make the Demo clearer */ * { outline-width: 10px; padding: 15px; } ``` #### Result {{ EmbedLiveSample('Setting_outline_style_to_solid_and_double') }} ### Setting outline style to groove and ridge #### HTML ```html <div> <div class="groove"> <p class="ridge">Outline Demo</p> </div> </div> ``` #### CSS ```css .groove { outline-style: groove; } .ridge { outline-style: ridge; } /* To make the Demo clearer */ * { outline-width: 10px; padding: 15px; } ``` #### Result {{ EmbedLiveSample('Setting_outline_style_to_groove_and_ridge') }} ### Setting outline style to inset and outset #### HTML ```html <div> <div class="inset"> <p class="outset">Outline Demo</p> </div> </div> ``` #### CSS ```css .inset { outline-style: inset; } .outset { outline-style: outset; } /* To make the Demo clearer */ * { outline-width: 10px; padding: 15px; } ``` #### Result {{ EmbedLiveSample('Setting_outline_style_to_inset_and_outset') }} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("outline")}} - {{cssxref("outline-color")}} - {{cssxref("outline-width")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/_doublecolon_-moz-progress-bar/index.md
--- title: "::-moz-progress-bar" slug: Web/CSS/::-moz-progress-bar page-type: css-pseudo-element status: - non-standard --- {{CSSRef}}{{Non-standard_header}} The **`::-moz-progress-bar`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) is a [Mozilla extension](/en-US/docs/Web/CSS/Mozilla_Extensions) that represents the progress bar inside a {{HTMLElement("progress")}} element. (The bar represents the amount of progress that has been made.) If you want to select the unfinished part of {{HTMLElement("progress")}} in Mozilla, please select the {{HTMLElement("progress")}} directly. ## Syntax ```css ::-moz-progress-bar { /* ... */ } ``` ## Examples ### HTML ```html <progress value="30" max="100">30%</progress> <progress max="100">Indeterminate</progress> ``` ### CSS ```css ::-moz-progress-bar { background-color: red; } /* Force indeterminate bars to have zero width */ :indeterminate::-moz-progress-bar { width: 0; } ``` ### Result {{EmbedLiveSample('Examples')}} ## Specifications Not part of any standard. ## See also - {{HTMLElement("progress")}} - {{ cssxref("::-webkit-progress-bar") }} - {{ cssxref("::-webkit-progress-value") }} - {{ cssxref("::-webkit-progress-inner-element") }}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/zoom/index.md
--- title: zoom slug: Web/CSS/zoom page-type: css-property status: - non-standard browser-compat: css.properties.zoom --- {{CSSRef}}{{Non-standard_header}} The non-standard **`zoom`** [CSS](/en-US/docs/Web/CSS) property can be used to control the magnification level of an element. {{cssxref("transform-function/scale", "transform: scale()")}} should be used instead of this property, if possible. However, unlike CSS Transforms, `zoom` affects the layout size of the element. ## Syntax ```css /* Keyword values */ zoom: normal; zoom: reset; /* <percentage> values */ zoom: 50%; zoom: 200%; /* <number> values */ zoom: 1.1; zoom: 0.7; /* Global values */ zoom: inherit; zoom: initial; zoom: revert; zoom: revert-layer; zoom: unset; ``` ### Values - `normal` - : Render this element at its normal size. - `reset` {{non-standard_inline}} - : Do not (de)magnify this element if the user applies non-pinch-based zooming (e.g. by pressing <kbd>Ctrl</kbd> \- <kbd>-</kbd> or <kbd>Ctrl</kbd> \+ <kbd>+</kbd> keyboard shortcuts) to the document. **Do not use** this value, _use the standard `unset` value instead_. - {{cssxref("&lt;percentage&gt;")}} - : Zoom factor. `100%` is equivalent to `normal`. Values larger than `100%` zoom in. Values smaller than `100%` zoom out. - {{cssxref("&lt;number&gt;")}} - : Zoom factor. Equivalent to the corresponding percentage (`1.0` = `100%` = `normal`). Values larger than `1.0` zoom in. Values smaller than `1.0` zoom out. ## Formal definition {{cssinfo}} ## Formal syntax ```plain zoom = normal | reset | <number> | <percentage> ``` ## Examples ### First example #### HTML ```html <p class="small">Small</p> <p class="normal">Normal</p> <p class="big">Big</p> ``` #### CSS ```css hidden body { display: flex; align-items: center; justify-content: space-around; height: 100vh; } ``` ```css .small { zoom: 75%; } .normal { zoom: normal; } .big { zoom: 2.5; } p:hover { zoom: unset; } ``` #### Result {{EmbedLiveSample('First_example')}} ### Second example #### HTML ```html <div id="a" class="circle"></div> <div id="b" class="circle"></div> <div id="c" class="circle"></div> ``` #### CSS ```css div.circle { width: 25px; height: 25px; border-radius: 100%; text-align: center; vertical-align: middle; display: inline-block; zoom: 1.5; } div#a { background-color: gold; zoom: normal; } div#b { background-color: green; zoom: 200%; } div#c { background-color: blue; zoom: 2.9; } ``` #### Result {{EmbedLiveSample('Second_example')}} ## Specifications Not part of any standard. Apple has [a description in the Safari CSS Reference](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html#//apple_ref/doc/uid/TP30001266-SW15). Rossen Atanassov of Microsoft has [an unofficial draft specification proposal on GitHub](https://github.com/atanassov/css-zoom). ## Browser compatibility {{Compat}} ## See also - [`zoom` entry in CSS-Tricks' CSS Almanac](https://css-tricks.com/almanac/properties/z/zoom/) - [Bug 390936: Implement Internet Explorer `zoom` property for CSS](https://bugzil.la/390936) on the Firefox issue tracker Bugzilla
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/width/index.md
--- title: width slug: Web/CSS/width page-type: css-property browser-compat: css.properties.width --- {{CSSRef}} The **`width`** CSS property sets an element's width. By default, it sets the width of the [content area](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model#content_area), but if {{cssxref("box-sizing")}} is set to `border-box`, it sets the width of the [border area](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model#border_area). {{EmbedInteractiveExample("pages/css/width.html")}} The specified value of `width` applies to the content area so long as its value remains within the values defined by {{cssxref("min-width")}} and {{cssxref("max-width")}}. - If the value for `width` is less than the value for `min-width`, then `min-width` overrides `width`. - If the value for `width` is greater than the value for `max-width`, then `max-width` overrides `width`. ## Syntax ```css /* <length> values */ width: 300px; width: 25em; /* <percentage> value */ width: 75%; /* Keyword values */ width: max-content; width: min-content; width: fit-content; width: fit-content(20em); width: auto; /* Global values */ width: inherit; width: initial; width: revert; width: revert-layer; width: unset; ``` ### Values - {{cssxref("&lt;length&gt;")}} - : Defines the width as a distance value. - {{cssxref("&lt;percentage&gt;")}} - : Defines the width as a percentage of the [containing block](/en-US/docs/Web/CSS/Containing_block)'s width. - `auto` - : The browser will calculate and select a width for the specified element. - `max-content` - : The intrinsic preferred width. - `min-content` - : The intrinsic minimum width. - `fit-content` - : 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, <length-percentage>))`. ## Accessibility concerns Ensure that elements set with a `width` aren't truncated and/or don't obscure other content when the page is zoomed to increase text size. - [MDN Understanding WCAG, Guideline 1.4 explanations](/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 ### Default width ```css p.goldie { background: gold; } ``` ```html <p class="goldie">The Mozilla community produces a lot of great software.</p> ``` {{EmbedLiveSample('Default_width', '500px', '64px')}} ### Example using pixels and ems ```css .px_length { width: 200px; background-color: red; color: white; border: 1px solid black; } .em_length { width: 20em; background-color: white; color: red; border: 1px solid black; } ``` ```html <div class="px_length">Width measured in px</div> <div class="em_length">Width measured in em</div> ``` {{EmbedLiveSample('Example using pixels and ems', '500px', '64px')}} ### Example with percentage ```css .percent { width: 20%; background-color: silver; border: 1px solid red; } ``` ```html <div class="percent">Width in percentage</div> ``` {{EmbedLiveSample('Example using percentage', '500px', '64px')}} ### Example using "max-content" ```css p.maxgreen { background: lightgreen; width: intrinsic; /* Safari/WebKit uses a non-standard name */ width: -moz-max-content; /* Firefox/Gecko */ width: -webkit-max-content; /* Chrome */ width: max-content; } ``` ```html <p class="maxgreen">The Mozilla community produces a lot of great software.</p> ``` {{EmbedLiveSample('Example using "max-content"', '500px', '64px')}} ### Example using "min-content" ```css p.minblue { background: lightblue; width: -moz-min-content; /* Firefox */ width: -webkit-min-content; /* Chrome */ width: min-content; } ``` ```html <p class="minblue">The Mozilla community produces a lot of great software.</p> ``` {{EmbedLiveSample('Example using "min-content"', '500px', '155px')}} ## 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("height")}} - {{cssxref("box-sizing")}} - {{cssxref("min-width")}}, {{cssxref("max-width")}} - The mapped logical properties: {{cssxref("block-size")}}, {{cssxref("inline-size")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/word-break/index.md
--- title: word-break slug: Web/CSS/word-break page-type: css-property browser-compat: css.properties.word-break --- {{CSSRef}} The **`word-break`** [CSS](/en-US/docs/Web/CSS) property sets whether line breaks appear wherever the text would otherwise overflow its content box. {{EmbedInteractiveExample("pages/css/word-break.html")}} ## Syntax ```css /* Keyword values */ word-break: normal; word-break: break-all; word-break: keep-all; word-break: auto-phrase; /* experimental */ word-break: break-word; /* deprecated */ /* Global values */ word-break: inherit; word-break: initial; word-break: revert; word-break: revert-layer; word-break: unset; ``` The `word-break` property is specified as a single keyword chosen from the list of values below. ### Values - `normal` - : Use the default line break rule. - `break-all` - : To prevent overflow, word breaks should be inserted between any two characters (excluding Chinese/Japanese/Korean text). - `keep-all` - : Word breaks should not be used for Chinese/Japanese/Korean (CJK) text. Non-CJK text behavior is the same as for `normal`. - `auto-phrase` {{Experimental_Inline}} - : Has the same effect as `word-break: normal` except that language-specific analysis is performed to improve word breaks by not placing them in the middle of natural phrases. - `break-word` {{Deprecated_Inline}} - : Has the same effect as `overflow-wrap: anywhere` combined with `word-break: normal`, regardless of the actual value of the {{cssxref("overflow-wrap")}} property. > **Note:** In contrast to `word-break: break-word` and `overflow-wrap: break-word` (see {{cssxref("overflow-wrap")}}), `word-break: break-all` will create a break at the exact place where text would otherwise overflow its container (even if putting an entire word on its own line would negate the need for a break). The specification also lists an additional value, `manual`, which is not currently supported in any browsers. When implemented, `manual` will have the same effect as `word-break: normal` except that breaks won't be automatically inserted in Southeast Asian languages. This is needed because, in such languages, user agents frequently place breaks in suboptimal positions. `manual` will allow you to insert line breaks in optimal positions manually. ## Formal definition {{CSSInfo}} ## Formal syntax {{csssyntax}} ## Examples ### HTML ```html <p>1. <code>word-break: normal</code></p> <p class="normal narrow"> This is a long and Honorificabilitudinitatibus califragilisticexpialidocious Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu γ‚°γƒ¬γƒΌγƒˆγƒ–γƒͺγƒ†γƒ³γŠγ‚ˆγ³εŒ—γ‚’γ‚€γƒ«γƒ©γƒ³γƒ‰ι€£εˆηŽ‹ε›½γ¨γ„γ†θ¨€θ‘‰γ―ζœ¬ε½“γ«ι•·γ„θ¨€θ‘‰ </p> <p>2. <code>word-break: break-all</code></p> <p class="breakAll narrow"> This is a long and Honorificabilitudinitatibus califragilisticexpialidocious Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu γ‚°γƒ¬γƒΌγƒˆγƒ–γƒͺγƒ†γƒ³γŠγ‚ˆγ³εŒ—γ‚’γ‚€γƒ«γƒ©γƒ³γƒ‰ι€£εˆηŽ‹ε›½γ¨γ„γ†θ¨€θ‘‰γ―ζœ¬ε½“γ«ι•·γ„θ¨€θ‘‰ </p> <p>3. <code>word-break: keep-all</code></p> <p class="keepAll narrow"> This is a long and Honorificabilitudinitatibus califragilisticexpialidocious Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu γ‚°γƒ¬γƒΌγƒˆγƒ–γƒͺγƒ†γƒ³γŠγ‚ˆγ³εŒ—γ‚’γ‚€γƒ«γƒ©γƒ³γƒ‰ι€£εˆηŽ‹ε›½γ¨γ„γ†θ¨€θ‘‰γ―ζœ¬ε½“γ«ι•·γ„θ¨€θ‘‰ </p> <p>4. <code>word-break: manual</code></p> <p class="manual narrow"> This is a long and Honorificabilitudinitatibus califragilisticexpialidocious Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu γ‚°γƒ¬γƒΌγƒˆγƒ–γƒͺγƒ†γƒ³γŠγ‚ˆγ³εŒ—γ‚’γ‚€γƒ«γƒ©γƒ³γƒ‰ι€£εˆηŽ‹ε›½γ¨γ„γ†θ¨€θ‘‰γ―ζœ¬ε½“γ«ι•·γ„θ¨€θ‘‰ </p> <p>5. <code>word-break: auto-phrase</code></p> <p class="autoPhrase narrow"> This is a long and Honorificabilitudinitatibus califragilisticexpialidocious Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu γ‚°γƒ¬γƒΌγƒˆγƒ–γƒͺγƒ†γƒ³γŠγ‚ˆγ³εŒ—γ‚’γ‚€γƒ«γƒ©γƒ³γƒ‰ι€£εˆηŽ‹ε›½γ¨γ„γ†θ¨€θ‘‰γ―ζœ¬ε½“γ«ι•·γ„θ¨€θ‘‰ </p> <p>6. <code>word-break: break-word</code></p> <p class="breakWord narrow"> This is a long and Honorificabilitudinitatibus califragilisticexpialidocious Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu γ‚°γƒ¬γƒΌγƒˆγƒ–γƒͺγƒ†γƒ³γŠγ‚ˆγ³εŒ—γ‚’γ‚€γƒ«γƒ©γƒ³γƒ‰ι€£εˆηŽ‹ε›½γ¨γ„γ†θ¨€θ‘‰γ―ζœ¬ε½“γ«ι•·γ„θ¨€θ‘‰ </p> ``` ### CSS ```css .narrow { padding: 10px; border: 1px solid; width: 500px; margin: 0 auto; font-size: 20px; line-height: 1.5; letter-spacing: 1px; } .normal { word-break: normal; } .breakAll { word-break: break-all; } .keepAll { word-break: keep-all; } .manual { word-break: manual; } .autoPhrase { word-break: auto-phrase; } .breakWord { word-break: break-word; } ``` {{EmbedLiveSample('Examples', '100%', 600)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - {{cssxref("overflow-wrap")}} - {{cssxref("hyphens")}} - {{cssxref("line-break")}} - [Guide to wrapping and breaking text](/en-US/docs/Web/CSS/CSS_text/Wrapping_breaking_text)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/inset-block/index.md
--- title: inset-block slug: Web/CSS/inset-block page-type: css-shorthand-property browser-compat: css.properties.inset-block --- {{CSSRef}} The **`inset-block`** [CSS](/en-US/docs/Web/CSS) property defines the logical block start and end offsets of an element, which maps to physical offsets depending on the element's writing mode, directionality, and text orientation. It corresponds to the {{cssxref("top")}} and {{cssxref("bottom")}}, or {{cssxref("right")}} and {{cssxref("left")}} properties depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. {{EmbedInteractiveExample("pages/css/inset-block.html")}} ## Constituent properties This property is a shorthand for the following CSS properties: - {{cssxref("inset-block-end")}} - {{cssxref("inset-block-start")}} ## Syntax ```css /* <length> values */ inset-block: 3px 10px; inset-block: 2.4em 3em; inset-block: 10px; /* value applied to start and end */ /* <percentage>s of the width or height of the containing block */ inset-block: 10% 5%; /* Keyword value */ inset-block: auto; /* Global values */ inset-block: inherit; inset-block: initial; inset-block: revert; inset-block: revert-layer; inset-block: unset; ``` ### Values The `inset-block` property takes the same values as the {{cssxref("left")}} property. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting block start and end offsets #### HTML ```html <div> <p class="exampleText">Example text</p> </div> ``` #### CSS ```css div { background-color: yellow; width: 120px; height: 120px; } .exampleText { writing-mode: vertical-lr; position: relative; inset-block: 20px 50px; background-color: #c8c800; } ``` #### Result {{EmbedLiveSample("Setting_block_start_and_end_offsets", 140, 140)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - The mapped physical properties: {{cssxref("top")}}, {{cssxref("right")}}, {{cssxref("bottom")}}, and {{cssxref("left")}} - The mapped physical shortcut: {{cssxref("inset")}} - The mapped inline shortcut: {{cssxref("inset-inline")}} - {{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/animation-iteration-count/index.md
--- title: animation-iteration-count slug: Web/CSS/animation-iteration-count page-type: css-property browser-compat: css.properties.animation-iteration-count --- {{CSSRef}} The **`animation-iteration-count`** [CSS](/en-US/docs/Web/CSS) property sets the number of times an animation sequence should be played before stopping. {{EmbedInteractiveExample("pages/css/animation-iteration-count.html")}} It is often convenient to use the shorthand property {{cssxref("animation")}} to set all animation properties at once. ## Syntax ```css /* Keyword value */ animation-iteration-count: infinite; /* <number> values */ animation-iteration-count: 3; animation-iteration-count: 2.4; /* Multiple values */ animation-iteration-count: 2, 0, infinite; /* Global values */ animation-iteration-count: inherit; animation-iteration-count: initial; animation-iteration-count: revert; animation-iteration-count: revert-layer; animation-iteration-count: unset; ``` The **`animation-iteration-count`** property is specified as one or more comma-separated values. ### Values - `infinite` - : The animation will repeat forever. - `{{cssxref("&lt;number&gt;")}}` - : The number of times the animation will repeat; this is `1` by default. You may specify non-integer values to play part of an animation cycle: for example, `0.5` will play half of the animation cycle. Negative values are invalid. > **Note:** When you specify multiple comma-separated values on an `animation-*` property, they are applied to the animations in the order in which the {{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:** When creating [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations), specifying an `animation-iteration-count` causes the animation to repeat that number of times over the course of the timeline's progression. If an `animation-iteration-count` is not provided, the animation will only occur once. `infinite` is a valid value for scroll-driven animations, but it results in an animation that doesn't work. ## Formal definition {{cssinfo}} ## Formal syntax {{csssyntax}} ## Examples ### Setting iteration count This animation will run 10 times. #### 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; animation-iteration-count: 10; } @keyframes rotate { 0% { transform: rotate(0); } 100% { transform: rotate(360deg); } } ``` #### Result Hover over the rectangle to start the animation. {{EmbedLiveSample("Setting iteration count","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-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/_doublecolon_-webkit-scrollbar/index.md
--- title: "::-webkit-scrollbar" slug: Web/CSS/::-webkit-scrollbar page-type: css-pseudo-element status: - non-standard browser-compat: - css.selectors.-webkit-scrollbar - css.selectors.-webkit-scrollbar-button - css.selectors.-webkit-scrollbar-thumb - css.selectors.-webkit-scrollbar-track - css.selectors.-webkit-scrollbar-track-piece - css.selectors.-webkit-scrollbar-corner - css.selectors.-webkit-resizer --- {{CSSRef}}{{Non-standard_Header}} The `::-webkit-scrollbar` CSS pseudo-element affects the style of an element's scrollbar when it has scrollable overflow. > **Note:** The `::-webkit-scrollbar` vendor-prefixed pseudo-element is not supported on all browsers (see [Browser compatibility](#browser_compatibility)). > The {{cssxref("scrollbar-color")}} and {{cssxref("scrollbar-width")}} standard properties may be used as an alternative for browsers that do not support this pseudo-element. When these properties are set, `::-webkit-scrollbar` styling is disabled. ## CSS Scrollbar Selectors You can use the following pseudo-elements to customize various parts of the scrollbar for WebKit browsers: - `::-webkit-scrollbar` β€” the entire scrollbar. - `::-webkit-scrollbar-button` β€” the buttons on the scrollbar (arrows pointing upwards and downwards that scroll one line at a time). - `::-webkit-scrollbar:horizontal{}` β€” the horizontal scrollbar. - `::-webkit-scrollbar-thumb` β€” the draggable scrolling handle. - `::-webkit-scrollbar-track` β€” the track (progress bar) of the scrollbar, where there is a gray bar on top of a white bar. - `::-webkit-scrollbar-track-piece` β€” the part of the track (progress bar) not covered by the handle. - `::-webkit-scrollbar:vertical{}` β€” the vertical scrollbar. - `::-webkit-scrollbar-corner` β€” the bottom corner of the scrollbar, where both horizontal and vertical scrollbars meet. This is often the bottom-right corner of the browser window. - `::-webkit-resizer` β€” the draggable resizing handle that appears at the bottom corner of some elements. ## Examples ### CSS ```css .visible-scrollbar, .invisible-scrollbar, .mostly-customized-scrollbar { display: block; width: 10em; overflow: auto; height: 2em; } .invisible-scrollbar::-webkit-scrollbar { display: none; } /* Demonstrate a "mostly customized" scrollbar * (won't be visible otherwise if width/height is specified) */ .mostly-customized-scrollbar::-webkit-scrollbar { width: 5px; height: 8px; background-color: #aaa; /* or add it to the track */ } /* Add a thumb */ .mostly-customized-scrollbar::-webkit-scrollbar-thumb { background: #000; } ``` ### HTML ```html <div class="visible-scrollbar"> Etiam sagittis sem sed lacus laoreet, eu fermentum eros auctor. Proin at nulla elementum, consectetur ex eget, commodo ante. Sed eros mi, bibendum ut dignissim et, maximus eget nibh. Phasellus blandit quam turpis, at mollis velit pretium ut. Nunc consequat efficitur ultrices. Nullam hendrerit posuere est. Nulla libero sapien, egestas ac felis porta, cursus ultricies quam. Vestibulum tincidunt accumsan sapien, a fringilla dui semper in. Vivamus consectetur ipsum a ornare blandit. Aenean tempus at lorem sit amet faucibus. Curabitur nibh justo, faucibus sed velit cursus, mattis cursus dolor. Pellentesque id pretium est. Quisque convallis nisi a diam malesuada mollis. Aliquam at enim ligula. </div> <div class="invisible-scrollbar"> Thisisaveeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerylongword </div> <div class="mostly-customized-scrollbar"> Thisisaveeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerylongword<br /> And pretty tall<br /> thing with weird scrollbars.<br /> Who thought scrollbars could be made weird? </div> ``` ### Result {{EmbedLiveSample("Examples")}} ## Specifications Not part of any standard. ## Browser compatibility {{Compat}} ## See also - WebKit blog on [Styling Scrollbars](https://webkit.org/blog/363/styling-scrollbars/) - {{CSSxRef("scrollbar-width")}} - {{CSSxRef("scrollbar-color")}}
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/css_images/index.md
--- title: CSS images slug: Web/CSS/CSS_images page-type: css-module spec-urls: - https://drafts.csswg.org/css-images/ - https://compat.spec.whatwg.org/#css-%3Cimage%3E-type - https://drafts.csswg.org/css-values/#urls --- {{CSSRef}} The **CSS images** module defines the types of images that can be used (the {{CSSxRef("&lt;image&gt;")}} type, containing URLs, gradients and other types of images), how to resize them and how they, and other replaced content, interact with the different layout models. ## Reference ### Properties - {{CSSxRef("image-orientation")}} - {{CSSxRef("image-rendering")}} - {{CSSxRef("image-resolution")}} - {{CSSxRef("object-fit")}} - {{CSSxRef("object-position")}} ### Functions - {{CSSxRef("gradient/linear-gradient", "linear-gradient()")}} - {{CSSxRef("gradient/radial-gradient", "radial-gradient()")}} - {{CSSxRef("gradient/repeating-linear-gradient", "repeating-linear-gradient()")}} - {{CSSxRef("gradient/repeating-radial-gradient", "repeating-radial-gradient()")}} - {{CSSxRef("gradient/conic-gradient", "conic-gradient()")}} - {{CSSxRef("gradient/repeating-conic-gradient", "repeating-conic-gradient()")}} - {{CSSxRef("url", "url()")}} - {{CSSxRef("element", "element()")}} - {{CSSxRef("image/image", "image()")}} - {{CSSxRef("cross-fade", "cross-fade()")}} ### Data types - {{CSSxRef("&lt;gradient&gt;")}} - {{CSSxRef("&lt;image&gt;")}} ## Guides - [Using CSS gradients](/en-US/docs/Web/CSS/CSS_images/Using_CSS_gradients) - : Presents a specific type of CSS images, _gradients_, and how to create and use these. - [Implementing image sprites in CSS](/en-US/docs/Web/CSS/CSS_images/Implementing_image_sprites_in_CSS) - : Describes the common technique grouping several images in one single document to save download requests and speed up the availability of a page. ## Specifications {{Specifications}}
0
data/mdn-content/files/en-us/web/css/css_images
data/mdn-content/files/en-us/web/css/css_images/implementing_image_sprites_in_css/index.md
--- title: Implementing image sprites in CSS slug: Web/CSS/CSS_images/Implementing_image_sprites_in_CSS page-type: guide --- {{CSSRef}} **Image sprites** are used in numerous web apps where multiple images are used. Rather than include each image as a separate image file, it is much more memory- and bandwidth-friendly to send them as a single image; using background position as a way to distinguish between individual images in the same image file, so the number of HTTP requests is reduced. > **Note:** When using HTTP/2, it may in fact be more bandwidth-friendly to use multiple small requests. ## Implementation Suppose an image is given to every item with class `toolbtn`: ```css .toolbtn { background: url(myfile.png); display: inline-block; height: 20px; width: 20px; } ``` A background position can be added either as two x, y values after the {{cssxref("url", "url()")}} in the background, or as {{cssxref("background-position")}}. For example: ```css #btn1 { background-position: -20px 0px; } #btn2 { background-position: -40px 0px; } ``` This would slide the starting point of the background image for the element with the ID `btn1` 20 pixels to the left and the element with the ID `btn2` 40 pixels to the left (assuming they have the class `toolbtn` assigned and are affected by the image rule above). Similarly, you can also make hover states with: ```css #btn:hover { background-position: <pixels shifted right>px <pixels shifted down>px; } ``` ## See also - [Full working demo at CSS Tricks](https://css-tricks.com/snippets/css/perfect-css-sprite-sliding-doors-button/)
0
data/mdn-content/files/en-us/web/css/css_images
data/mdn-content/files/en-us/web/css/css_images/using_css_gradients/index.md
--- title: Using CSS gradients slug: Web/CSS/CSS_images/Using_CSS_gradients page-type: guide --- {{CSSRef}} **CSS gradients** are represented by the {{cssxref("&lt;gradient&gt;")}} data type, a special type of {{cssxref("&lt;image&gt;")}} made of a progressive transition between two or more colors. You can choose between three types of gradients: _linear_ (created with the {{cssxref("gradient/linear-gradient", "linear-gradient()")}} function), _radial_ (created with the {{cssxref("gradient/radial-gradient", "radial-gradient()")}} function), and _conic_ (created with the {{cssxref("gradient/conic-gradient", "conic-gradient()")}} function). You can also create repeating gradients with the {{cssxref("gradient/repeating-linear-gradient", "repeating-linear-gradient()")}}, {{cssxref("gradient/repeating-radial-gradient", "repeating-radial-gradient()")}}, and {{cssxref("gradient/repeating-conic-gradient", "repeating-conic-gradient()")}} functions. Gradients can be used anywhere you would use an `<image>`, such as in backgrounds. Because gradients are dynamically generated, they can negate the need for the raster image files that traditionally were used to achieve similar effects. In addition, because gradients are generated by the browser, they look better than raster images when zoomed in, and can be resized on the fly. We'll start by introducing linear gradients, then introduce features that are supported in all gradient types using linear gradients as the example, then move on to radial, conic and repeating gradients ## Using linear gradients A linear gradient creates a band of colors that progress in a straight line. ### A basic linear gradient To create the most basic type of gradient, all you need is to specify two colors. These are called _color stops_. You must have at least two, but you can have as many as you want. ```html hidden <div class="simple-linear"></div> ``` ```css hidden div { width: 120px; height: 120px; } ``` ```css .simple-linear { background: linear-gradient(blue, pink); } ``` {{ EmbedLiveSample('A_basic_linear_gradient', 120, 120) }} ### Changing the direction By default, linear gradients run from top to bottom. You can change their rotation by specifying a direction. ```html hidden <div class="horizontal-gradient"></div> ``` ```css hidden div { width: 120px; height: 120px; } ``` ```css .horizontal-gradient { background: linear-gradient(to right, blue, pink); } ``` {{ EmbedLiveSample('Changing_the_direction', 120, 120) }} ### Diagonal gradients You can even make the gradient run diagonally, from corner to corner. ```html hidden <div class="diagonal-gradient"></div> ``` ```css hidden div { width: 200px; height: 100px; } ``` ```css .diagonal-gradient { background: linear-gradient(to bottom right, blue, pink); } ``` {{ EmbedLiveSample('Diagonal_gradients', 200, 100) }} ### Using angles If you want more control over its direction, you can give the gradient a specific angle. ```html hidden <div class="angled-gradient"></div> ``` ```css hidden div { width: 120px; height: 120px; } ``` ```css .angled-gradient { background: linear-gradient(70deg, blue, pink); } ``` {{ EmbedLiveSample('Using_angles', 120, 120) }} When using an angle, `0deg` creates a vertical gradient running bottom to top, `90deg` creates a horizontal gradient running left to right, and so on in a clockwise direction. Negative angles run in the counterclockwise direction. ![Four boxes listing angle and showing associated gradient from red to white. 0deg starts at the bottom and goes up. 90deg starts at left and goes right. 180deg starts at the top and goes down. -90deg starts at right and goes left.](linear_red_angles.png) ## Declaring colors & creating effects All CSS gradient types are a range of position-dependent colors. The colors produced by CSS gradients can vary continuously with position, producing smooth color transitions. It is also possible to create bands of solid colors, and hard transitions between two colors. The following are valid for all gradient functions: ### Using more than two colors You don't have to limit yourself to two colorsβ€”you may use as many as you like! By default, colors are evenly spaced along the gradient. ```html hidden <div class="auto-spaced-linear-gradient"></div> ``` ```css hidden div { width: 120px; height: 120px; } ``` ```css .auto-spaced-linear-gradient { background: linear-gradient(red, yellow, blue, orange); } ``` {{ EmbedLiveSample('Using_more_than_two_colors', 120, 120) }} ### Positioning color stops You don't have to leave your color stops at their default positions. To fine-tune their locations, you can give each one zero, one, or two percentage or, for radial and linear gradients, absolute length values. If you specify the location as a percentage, `0%` represents the starting point, while `100%` represents the ending point; however, you can use values outside that range if necessary to get the effect you want. If you leave a location unspecified, the position of that particular color stop will be automatically calculated for you, with the first color stop being at `0%` and the last color stop being at `100%`, and any other color stops being half way between their adjacent color stops. ```html hidden <div class="multicolor-linear"></div> ``` ```css hidden div { width: 120px; height: 120px; } ``` ```css .multicolor-linear { background: linear-gradient(to left, lime 28px, red 77%, cyan); } ``` {{ EmbedLiveSample('Positioning_color_stops', 120, 120) }} ### Creating hard lines To create a hard line between two colors, creating a stripe instead of a gradual transition, adjacent color stops can be set to the same location. In this example, the colors share a color stop at the `50%` mark, halfway through the gradient: ```html hidden <div class="striped"></div> ``` ```css hidden div { width: 120px; height: 120px; } ``` ```css .striped { background: linear-gradient(to bottom left, cyan 50%, palegoldenrod 50%); } ``` {{ EmbedLiveSample('Creating_hard_lines', 120, 120) }} ### Gradient hints By default, the gradient transitions evenly from one color to the next. You can include a color-hint to move the midpoint of the transition value to a certain point along the gradient. In this example, we've moved the midpoint of the transition from the 50% mark to the 10% mark. ```html hidden <div class="color-hint"></div> <div class="simple-linear"></div> ``` ```css hidden div { width: 120px; height: 120px; float: left; margin-right: 10px; } ``` ```css .color-hint { background: linear-gradient(blue, 10%, pink); } .simple-linear { background: linear-gradient(blue, pink); } ``` {{ EmbedLiveSample('Gradient_hints', 120, 120) }} ### Creating color bands & stripes To include a solid, non-transitioning color area within a gradient, include two positions for the color stop. Color stops can have two positions, which is equivalent to two consecutive color stops with the same color at different positions. The color will reach full saturation at the first color stop, maintain that saturation through to the second color stop, and transition to the adjacent color stop's color through the adjacent color stop's first position. ```html hidden <div class="multiposition-stops"></div> <div class="multiposition-stop2"></div> ``` ```css hidden div { width: 120px; height: 120px; float: left; margin-right: 10px; box-sizing: border-box; } ``` ```css .multiposition-stops { background: linear-gradient( to left, lime 20%, red 30%, red 45%, cyan 55%, cyan 70%, yellow 80% ); background: linear-gradient( to left, lime 20%, red 30% 45%, cyan 55% 70%, yellow 80% ); } .multiposition-stop2 { background: linear-gradient( to left, lime 25%, red 25%, red 50%, cyan 50%, cyan 75%, yellow 75% ); background: linear-gradient( to left, lime 25%, red 25% 50%, cyan 50% 75%, yellow 75% ); } ``` {{ EmbedLiveSample('Creating_color_bands_stripes', 120, 120) }} In the first example above, the lime goes from the 0% mark, which is implied, to the 20% mark, transitions from lime to red over the next 10% of the width of the gradient, reach solid red at the 30% mark, and staying solid red up until 45% through the gradient, where it fades to cyan, being fully cyan for 15% of the gradient, and so on. In the second example, the second color stop for each color is at the same location as the first color stop for the adjacent color, creating a striped effect. In both examples, the gradient is written twice: the first is the CSS Images Level 3 method of repeating the color for each stop and the second example is the CSS Images Level 4 multiple color stop method of including two color-stop-lengths in a linear-color-stop declaration. ### Controlling the progression of a gradient By default, a gradient evenly progresses between the colors of two adjacent color stops, with the midpoint between those two color stops being the midpoint color value. You can control the {{Glossary("interpolation")}}, or progression, between two color stops by including a color hint location. In this example, the color reaches the midpoint between lime and cyan 20% of the way through the gradient rather than 50% of the way through. The second example does not contain the hint to highlight the difference the color hint can make: ```html hidden <div class="colorhint-gradient"></div> <div class="regular-progression"></div> ``` ```css hidden div { width: 120px; height: 120px; float: left; margin-right: 10px; box-sizing: border-box; } ``` ```css .colorhint-gradient { background: linear-gradient(to top, lime, 20%, cyan); } .regular-progression { background: linear-gradient(to top, lime, cyan); } ``` {{ EmbedLiveSample('Controlling_the_progression_of_a_gradient', 120, 120) }} ### Overlaying gradients Gradients support transparency, so you can stack multiple backgrounds to achieve some pretty fancy effects. The backgrounds are stacked from top to bottom, with the first specified being on top. ```html hidden <div class="layered-image"></div> ``` ```css hidden div { width: 300px; height: 150px; } ``` ```css .layered-image { background: linear-gradient(to right, transparent, mistyrose), url("critters.png"); } ``` {{ EmbedLiveSample('Overlaying_gradients', 300, 150) }} ### Stacked gradients You can even stack gradients with other gradients. As long as the top gradients aren't entirely opaque, the gradients below will still be visible. ```html hidden <div class="stacked-linear"></div> ``` ```css hidden div { width: 200px; height: 200px; } ``` ```css .stacked-linear { background: linear-gradient( 217deg, rgb(255 0 0 / 80%), rgb(255 0 0 / 0%) 70.71% ), linear-gradient(127deg, rgb(0 255 0 / 80%), rgb(0 255 0 / 0%) 70.71%), linear-gradient(336deg, rgb(0 0 255 / 80%), rgb(0 0 255 / 0%) 70.71%); } ``` {{ EmbedLiveSample('Stacked_gradients', 200, 200) }} ## Using radial gradients Radial gradients are similar to linear gradients, except that they radiate out from a central point. You can dictate where that central point is. You can also make them circular or elliptical. ### A basic radial gradient As with linear gradients, all you need to create a radial gradient are two colors. By default, the center of the gradient is at the 50% 50% mark, and the gradient is elliptical matching the aspect ratio of its box: ```html hidden <div class="simple-radial"></div> ``` ```css hidden div { width: 240px; height: 120px; } ``` ```css .simple-radial { background: radial-gradient(red, blue); } ``` {{ EmbedLiveSample('A_basic_radial_gradient', 120, 120) }} ### Positioning radial color stops Again like linear gradients, you can position each radial color stop with a percentage or absolute length. ```html hidden <div class="radial-gradient"></div> ``` ```css hidden div { width: 120px; height: 120px; } ``` ```css .radial-gradient { background: radial-gradient(red 10px, yellow 30%, #1e90ff 50%); } ``` {{ EmbedLiveSample('Positioning_radial_color_stops', 120, 120) }} ### Positioning the center of the gradient You can position the center of the gradient with keyterms, percentage, or absolute lengths, length and percentage values repeating if only one is present, otherwise in the order of position from the left and position from the top. ```html hidden <div class="radial-gradient"></div> ``` ```css hidden div { width: 120px; height: 240px; } ``` ```css .radial-gradient { background: radial-gradient(at 0% 30%, red 10px, yellow 30%, #1e90ff 50%); } ``` {{ EmbedLiveSample('Positioning_the_center_of_the_gradient', 120, 120) }} ### Sizing radial gradients Unlike linear gradients, you can specify the size of radial gradients. Possible values include `closest-corner`, `closest-side`, `farthest-corner`, and `farthest-side`, with `farthest-corner` being the default. Circles can also be sized with a length, and ellipses a length or percentage. #### Example: `closest-side` for ellipses This example uses the `closest-side` size value, which means the size is set by the distance from the starting point (the center) to the closest side of the enclosing box. ```html hidden <div class="radial-ellipse-side"></div> ``` ```css hidden div { width: 240px; height: 100px; } ``` ```css .radial-ellipse-side { background: radial-gradient( ellipse closest-side, red, yellow 10%, #1e90ff 50%, beige ); } ``` {{ EmbedLiveSample('Example_closest-side_for_ellipses', 240, 100) }} #### Example: `farthest-corner` for ellipses This example is similar to the previous one, except that its size is specified as `farthest-corner`, which sets the size of the gradient by the distance from the starting point to the farthest corner of the enclosing box from the starting point. ```html hidden <div class="radial-ellipse-far"></div> ``` ```css hidden div { width: 240px; height: 100px; } ``` ```css .radial-ellipse-far { background: radial-gradient( ellipse farthest-corner at 90% 90%, red, yellow 10%, #1e90ff 50%, beige ); } ``` {{ EmbedLiveSample('Example_farthest-corner_for_ellipses', 240, 100) }} #### Example: `closest-side` for circles This example uses `closest-side`, which makes the circle's radius to be the distance between the center of the gradient and the closest side. In this case the radius is the distance between the center and the bottom edge, because the gradient is placed 25% from the left and 25% from the bottom, and the div element's height is smaller than the width. ```html hidden <div class="radial-circle-close"></div> ``` ```css hidden div { width: 240px; height: 120px; } ``` ```css .radial-circle-close { background: radial-gradient( circle closest-side at 25% 75%, red, yellow 10%, #1e90ff 50%, beige ); } ``` {{ EmbedLiveSample('Example_closest-side_for_circles', 240, 120) }} #### Example: length or percentage for ellipses For ellipses only, you can size the ellipse using a length or percentage. The first value represents the horizontal radius, the second the vertical radius, where you use a percentage this corresponds to the size of the box in that dimension. In the below example I have used a percentage for the horizontal radius. ```html hidden <div class="radial-ellipse-size"></div> ``` ```css hidden div { width: 240px; height: 120px; } ``` ```css .radial-ellipse-size { background: radial-gradient( ellipse 50% 50px, red, yellow 10%, #1e90ff 50%, beige ); } ``` {{ EmbedLiveSample('Example_length_or_percentage_for_ellipses', 240, 120) }} #### Example: length for circles For circles the size may be given as a {{cssxref("length")}}, which is the size of the circle. ```html hidden <div class="radial-circle-size"></div> ``` ```css hidden div { width: 240px; height: 120px; } ``` ```css .radial-circle-size { background: radial-gradient(circle 50px, red, yellow 10%, #1e90ff 50%, beige); } ``` {{ EmbedLiveSample('Example_length_for_circles', 240, 120) }} ### Stacked radial gradients Just like linear gradients, you can also stack radial gradients. The first specified is on top, the last on the bottom. ```html hidden <div class="stacked-radial"></div> ``` ```css hidden div { width: 200px; height: 200px; } ``` ```css .stacked-radial { background: radial-gradient( circle at 50% 0, rgb(255 0 0 / 50%), rgb(255 0 0 / 0%) 70.71% ), radial-gradient( circle at 6.7% 75%, rgb(0 0 255 / 50%), rgb(0 0 255 / 0%) 70.71% ), radial-gradient( circle at 93.3% 75%, rgb(0 255 0 / 50%), rgb(0 255 0 / 0%) 70.71% ) beige; border-radius: 50%; } ``` {{ EmbedLiveSample('Stacked_radial_gradients', 200, 200) }} ## Using conic gradients The **`conic-gradient()`** [CSS](/en-US/docs/Web/CSS) function creates an image consisting of a gradient with color transitions rotated around a center point (rather than radiating from the center). Example conic gradients include pie charts and {{glossary("color wheel", "color wheels")}}, but they can also be used for creating checker boards and other interesting effects. The conic-gradient syntax is similar to the radial-gradient syntax, but the color-stops are placed around a gradient arc, the circumference of a circle, rather than on the gradient line emerging from the center of the gradient, and the color-stops are percentages or degrees: absolute lengths are not valid. In a radial gradient, the colors transition from the center of an ellipse, outward, in all directions. With conic gradients, the colors transition as if spun around the center of a circle, starting at the top and going clockwise. Similar to radial gradients, you can position the center of the gradient. Similar to linear gradients, you can change the gradient angle. ### A basic conic gradient As with linear and radial gradients, all you need to create a conic gradient are two colors. By default, the center of the gradient is at the 50% 50% mark, with the start of the gradient facing up: ```html hidden <div class="simple-conic"></div> ``` ```css hidden div { width: 120px; height: 120px; } ``` ```css .simple-conic { background: conic-gradient(red, blue); } ``` {{ EmbedLiveSample('A_basic_conic_gradient', 120, 120) }} ### Positioning the conic center Like radial gradients, you can position the center of the conic gradient with keyterms, percentage, or absolute lengths, with the keyword "at" ```html hidden <div class="conic-gradient"></div> ``` ```css hidden div { width: 120px; height: 120px; } ``` ```css .conic-gradient { background: conic-gradient(at 0% 30%, red 10%, yellow 30%, #1e90ff 50%); } ``` {{ EmbedLiveSample('Positioning_the_conic_center', 120, 120) }} ### Changing the angle By default, the different color stops you specify are spaced equidistantly around the circle. You can position the starting angle of the conic gradient using the "from" keyword at the beginning followed by an angle or a length, and you can specify different positions for the colors stops by including an angle or length after them. ```html hidden <div class="conic-gradient"></div> ``` ```css hidden div { width: 120px; height: 120px; } ``` ```css .conic-gradient { background: conic-gradient(from 45deg, red, orange 50%, yellow 85%, green); } ``` {{ EmbedLiveSample('Changing_the_angle', 120, 120) }} ## Using repeating gradients The {{cssxref("gradient/linear-gradient", "linear-gradient()")}}, {{cssxref("gradient/radial-gradient", "radial-gradient()")}}, and {{cssxref("gradient/conic-gradient", "conic-gradient()")}} functions don't support automatically repeated color stops. However, the {{cssxref("gradient/repeating-linear-gradient", "repeating-linear-gradient()")}}, {{cssxref("gradient/repeating-radial-gradient", "repeating-radial-gradient()")}}, and {{cssxref("gradient/repeating-conic-gradient", "repeating-conic-gradient()")}} functions are available to offer this functionality. The size of the gradient line or arc that repeats is the length between the first color stop value and the last color stop length value. If the first color stop just has a color and no color stop length, the value defaults to 0. If the last color stop has just a color and no color stop length, the value defaults to 100%. If neither is declared, the gradient line is 100% meaning the linear and conic gradients will not repeat and the radial gradient will only repeat if the radius of the gradient is smaller than the length between the center of the gradient and the farthest corner. If the first color stop is declared, and the value is greater than 0, the gradient will repeat, as the size of the line or arc is the difference between the first color stop and last color stop is less than 100% or 360 degrees. ### Repeating linear gradients This example uses {{cssxref("gradient/repeating-linear-gradient", "repeating-linear-gradient()")}} to create a gradient that progresses repeatedly in a straight line. The colors get cycled over again as the gradient repeats. In this case the gradient line is 10px long. ```html hidden <div class="repeating-linear"></div> ``` ```css hidden div { width: 120px; height: 120px; } ``` ```css .repeating-linear { background: repeating-linear-gradient( -45deg, red, red 5px, blue 5px, blue 10px ); } ``` {{ EmbedLiveSample('Repeating_linear_gradients', 120, 120) }} ### Multiple repeating linear gradients Similar to regular linear and radial gradients, you can include multiple gradients, one on top of the other. This only makes sense if the gradients are partially transparent allowing subsequent gradients to show through the transparent areas, or if you include different [background-sizes](/en-US/docs/Web/CSS/background-size), optionally with different [background-position](/en-US/docs/Web/CSS/background-position) property values, for each gradient image. We are using transparency. In this case the gradient lines are 300px, 230px, and 300px long. ```html hidden <div class="multi-repeating-linear"></div> ``` ```css hidden div { width: 600px; height: 400px; } ``` ```css .multi-repeating-linear { background: repeating-linear-gradient( 190deg, rgb(255 0 0 / 50%) 40px, rgb(255 153 0 / 50%) 80px, rgb(255 255 0 / 50%) 120px, rgb(0 255 0 / 50%) 160px, rgb(0 0 255 / 50%) 200px, rgb(75 0 130 / 50%) 240px, rgb(238 130 238 / 50%) 280px, rgb(255 0 0 / 50%) 300px ), repeating-linear-gradient( -190deg, rgb(255 0 0 / 50%) 30px, rgb(255 153 0 / 50%) 60px, rgb(255 255 0 / 50%) 90px, rgb(0 255 0 / 50%) 120px, rgb(0 0 255 / 50%) 150px, rgb(75 0 130 / 50%) 180px, rgb(238 130 238 / 50%) 210px, rgb(255 0 0 / 50%) 230px ), repeating-linear-gradient(23deg, red 50px, orange 100px, yellow 150px, green 200px, blue 250px, indigo 300px, violet 350px, red 370px); } ``` {{ EmbedLiveSample('Multiple_repeating_linear_gradients', 600, 400) }} ### Plaid gradient To create plaid we include several overlapping gradients with transparency. In the first background declaration we listed every color stop separately. The second background property declaration using the multiple position color stop syntax: ```html hidden <div class="plaid-gradient"></div> ``` ```css hidden div { width: 200px; height: 200px; } ``` ```css .plaid-gradient { background: repeating-linear-gradient( 90deg, transparent, transparent 50px, rgb(255 127 0 / 25%) 50px, rgb(255 127 0 / 25%) 56px, transparent 56px, transparent 63px, rgb(255 127 0 / 25%) 63px, rgb(255 127 0 / 25%) 69px, transparent 69px, transparent 116px, rgb(255 206 0 / 25%) 116px, rgb(255 206 0 / 25%) 166px ), repeating-linear-gradient( 0deg, transparent, transparent 50px, rgb(255 127 0 / 25%) 50px, rgb(255 127 0 / 25%) 56px, transparent 56px, transparent 63px, rgb(255 127 0 / 25%) 63px, rgb(255 127 0 / 25%) 69px, transparent 69px, transparent 116px, rgb(255 206 0 / 25%) 116px, rgb(255 206 0 / 25%) 166px ), repeating-linear-gradient( -45deg, transparent, transparent 5px, rgb(143 77 63 / 25%) 5px, rgb(143 77 63 / 25%) 10px ), repeating-linear-gradient(45deg, transparent, transparent 5px, rgb( 143 77 63 / 25% ) 5px, rgb(143 77 63 / 25%) 10px); background: repeating-linear-gradient( 90deg, transparent 0 50px, rgb(255 127 0 / 25%) 50px 56px, transparent 56px 63px, rgb(255 127 0 / 25%) 63px 69px, transparent 69px 116px, rgb(255 206 0 / 25%) 116px 166px ), repeating-linear-gradient( 0deg, transparent 0 50px, rgb(255 127 0 / 25%) 50px 56px, transparent 56px 63px, rgb(255 127 0 / 25%) 63px 69px, transparent 69px 116px, rgb(255 206 0 / 25%) 116px 166px ), repeating-linear-gradient( -45deg, transparent 0 5px, rgb(143 77 63 / 25%) 5px 10px ), repeating-linear-gradient(45deg, transparent 0 5px, rgb(143 77 63 / 25%) 5px 10px); } ``` {{ EmbedLiveSample('Plaid_gradient', 200, 200) }} ### Repeating radial gradients This example uses {{cssxref("gradient/repeating-radial-gradient", "repeating-radial-gradient()")}} to create a gradient that radiates repeatedly from a central point. The colors get cycled over and over as the gradient repeats. ```html hidden <div class="repeating-radial"></div> ``` ```css hidden div { width: 120px; height: 120px; } ``` ```css .repeating-radial { background: repeating-radial-gradient( black, black 5px, white 5px, white 10px ); } ``` {{ EmbedLiveSample('Repeating_radial_gradients', 120, 120) }} ### Multiple repeating radial gradients ```html hidden <div class="multi-target"></div> ``` ```css hidden div { width: 250px; height: 150px; } ``` ```css .multi-target { background: repeating-radial-gradient( ellipse at 80% 50%, rgb(0 0 0 / 50%), rgb(0 0 0 / 50%) 15px, rgb(255 255 255 / 50%) 15px, rgb(255 255 255 / 50%) 30px ) top left no-repeat, repeating-radial-gradient( ellipse at 20% 50%, rgb(0 0 0 / 50%), rgb(0 0 0 / 50%) 10px, rgb(255 255 255 / 50%) 10px, rgb(255 255 255 / 50%) 20px ) top left no-repeat yellow; background-size: 200px 200px, 150px 150px; } ``` {{ EmbedLiveSample('Multiple_repeating_radial_gradients', 250, 150) }} ## See also - Gradient functions: {{cssxref("gradient/linear-gradient", "linear-gradient()")}}, {{cssxref("gradient/radial-gradient", "radial-gradient()")}}, {{cssxref("gradient/conic-gradient", "conic-gradient()")}}, {{cssxref("gradient/repeating-linear-gradient", "repeating-linear-gradient()")}}, {{cssxref("gradient/repeating-radial-gradient", "repeating-radial-gradient()")}}, {{cssxref("gradient/repeating-conic-gradient", "repeating-conic-gradient()")}} - Gradient-related CSS data types: {{cssxref("&lt;gradient&gt;")}}, {{cssxref("&lt;image&gt;")}} - Gradient-related CSS properties: {{cssxref("background")}}, {{cssxref("background-image")}} - [CSS Gradients Patterns Gallery, by Lea Verou](https://projects.verou.me/css3patterns/) - [CSS Gradients Library, by Estelle Weyl](https://standardista.com/cssgradients/) - [Gradient CSS Generator](https://cssgenerator.org/gradient-css-generator.html)
0
data/mdn-content/files/en-us/web/css
data/mdn-content/files/en-us/web/css/border-start-start-radius/index.md
--- title: border-start-start-radius slug: Web/CSS/border-start-start-radius page-type: css-property browser-compat: css.properties.border-start-start-radius --- {{CSSRef}} The **`border-start-start-radius`** [CSS](/en-US/docs/Web/CSS) property defines a logical border radius on an element, which maps to a physical border radius that depends on the element's {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}. This is useful when building styles to work regardless of the [text orientation](/en-US/docs/Web/CSS/text-orientation) and [writing mode](/en-US/docs/Web/CSS/CSS_writing_modes). {{EmbedInteractiveExample("pages/css/border-start-start-radius.html")}} This property affects the corner between the block-start and the inline-start sides of the element. For instance, in a `horizontal-tb` writing mode with `ltr` direction, it corresponds to the {{CSSxRef("border-top-left-radius")}} property. ## Syntax ```css /* <length> values */ /* With one value the corner will be a circle */ border-start-start-radius: 10px; border-start-start-radius: 1em; /* With two values the corner will be an ellipse */ border-start-start-radius: 1em 2em; /* Global values */ border-start-start-radius: inherit; border-start-start-radius: initial; border-start-start-radius: revert; border-start-start-radius: revert-layer; border-start-start-radius: unset; ``` ### Values - `<length-percentage>` - : Denotes the size of the circle radius or the semi-major and semi-minor axes of the ellipse. As absolute length it can be expressed in any unit allowed by the CSS {{cssxref("&lt;length&gt;")}} data type. Percentages for the horizontal axis refer to the width of the box, percentages for the vertical axis refer to the height of the box. Negative values are invalid. ## Formal definition {{CSSInfo}} ## Formal syntax {{CSSSyntax}} ## Examples ### Border radius with vertical text #### HTML ```html <div> <p class="exampleText">Example</p> </div> ``` #### CSS ```css div { background-color: rebeccapurple; width: 120px; height: 120px; border-start-start-radius: 10px; } .exampleText { writing-mode: vertical-rl; padding: 10px; background-color: #fff; border-start-start-radius: 10px; } ``` #### Results {{EmbedLiveSample("Border_radius_with_vertical_text", 140, 140)}} ## Specifications {{Specifications}} ## Browser compatibility {{Compat}} ## See also - [CSS Logical Properties and Values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values) - The mapped physical property: {{CSSxRef("border-top-left-radius")}} - {{CSSxRef("writing-mode")}}, {{CSSxRef("direction")}}, {{CSSxRef("text-orientation")}}
0