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/position_value/index.md | ---
title: <position>
slug: Web/CSS/position_value
page-type: css-type
browser-compat: css.types.position
---
{{CSSRef}}
The **`<position>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) denotes a two-dimensional coordinate used to set a location relative to an element box. It is used in the {{cssxref("background-position")}}, {{cssxref("object-position")}}, {{cssxref("mask-position")}} {{cssxref("offset-position")}}, {{cssxref("offset-anchor")}} and {{cssxref("transform-origin")}} properties.
> **Note:** The final position described by the `<position>` value does not need to be inside the element's box.
## Syntax

The `<position>` data type is specified with one or two keywords, with optional offsets.
The keyword values are `center`, `top`, `right`, `bottom`, and `left`. Each keyword represents either an edge of the element's box or the center line between two edges. Depending on the context, `center` represents either the center between the left and right edges, or the center between the top and bottom edges.
If specified, an offset can be either a relative {{cssxref("<percentage>")}} value or an absolute {{cssxref("<length>")}} value. Positive values are offset towards the right or the bottom, whichever is appropriate. Negative values are offset in the opposite directions.
If only a single offset value is specified, it defines the x-coordinate, with the value for the other axis defaulting to `center`.
```css
/* 1-value syntax */
keyword /* Either the horizontal or vertical position; the other axis defaults to center */
value /* The position on the x-axis; the y-axis defaults to 50% */
/* 2-value syntax */
keyword keyword /* A keyword for each direction (the order is irrelevant) */
keyword value /* A keyword for horizontal position, value for vertical position */
value keyword /* A value for horizontal position, keyword for vertical position */
value value /* A value for each direction (horizontal then vertical) */
/* 4-value syntax */
keyword value keyword value /* Each value is an offset from the keyword that precedes it */
```
> **Note:** The {{cssxref("background-position")}} property also accepts a three-value syntax. This is not allowed in other properties that use `<position>`.
## Interpolation
When animated, a point's abscissa and ordinate values are interpolated independently. However, because the speed of the interpolation is determined by a single [easing function](/en-US/docs/Web/CSS/easing-function) for both coordinates, the point will move in a straight line.
## Formal syntax
{{csssyntax}}
## Examples
### Valid positions
```plain example-good
center
left
center top
right 8.5%
bottom 12vmin right -6px
10% 20%
8rem 14px
```
### Invalid positions
```plain example-bad
left right
bottom top
10px 15px 20px 15px
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [CSS Values and Units](/en-US/docs/Web/CSS/CSS_Values_and_Units)
- [CSS Values and Units introduction](/en-US/docs/Learn/CSS/Building_blocks/Values_and_units)
- {{cssxref("background-position")}}
- {{cssxref("gradient/radial-gradient", "radial-gradient()")}}
- {{cssxref("gradient/conic-gradient", "conic-gradient()")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/flex-wrap/index.md | ---
title: flex-wrap
slug: Web/CSS/flex-wrap
page-type: css-property
browser-compat: css.properties.flex-wrap
---
{{CSSRef}}
The **`flex-wrap`** [CSS](/en-US/docs/Web/CSS) property sets whether flex items are forced onto one line or can wrap onto multiple lines. If wrapping is allowed, it sets the direction that lines are stacked.
{{EmbedInteractiveExample("pages/css/flex-wrap.html")}}
See [Using CSS flexible boxes](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox) for more properties and information.
## Syntax
```css
flex-wrap: nowrap; /* Default value */
flex-wrap: wrap;
flex-wrap: wrap-reverse;
/* Global values */
flex-wrap: inherit;
flex-wrap: initial;
flex-wrap: revert;
flex-wrap: revert-layer;
flex-wrap: unset;
```
The `flex-wrap` property is specified as a single keyword chosen from the list of values below.
### Values
The following values are accepted:
- `nowrap`
- : The flex items are laid out in a single line which may cause the flex container to overflow. The **cross-start** is either equivalent to **start** or **before** depending on the {{cssxref("flex-direction")}} value. This is the default value.
- `wrap`
- : The flex items break into multiple lines. The **cross-start** is either equivalent to **start** or **before** depending `flex-direction` value and the **cross-end** is the opposite of the specified **cross-start**.
- `wrap-reverse`
- : Behaves the same as `wrap` but **cross-start** and **cross-end** are permuted.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting flex container wrap values
#### HTML
```html
<h4>This is an example for flex-wrap:wrap</h4>
<div class="content">
<div class="red">1</div>
<div class="green">2</div>
<div class="blue">3</div>
</div>
<h4>This is an example for flex-wrap:nowrap</h4>
<div class="content1">
<div class="red">1</div>
<div class="green">2</div>
<div class="blue">3</div>
</div>
<h4>This is an example for flex-wrap:wrap-reverse</h4>
<div class="content2">
<div class="red">1</div>
<div class="green">2</div>
<div class="blue">3</div>
</div>
```
#### CSS
```css
/* Common Styles */
.content,
.content1,
.content2 {
color: #fff;
font: 100 24px/100px sans-serif;
height: 150px;
width: 897px;
text-align: center;
}
.content div,
.content1 div,
.content2 div {
height: 50%;
width: 300px;
}
.red {
background: orangered;
}
.green {
background: yellowgreen;
}
.blue {
background: steelblue;
}
/* Flexbox Styles */
.content {
display: flex;
flex-wrap: wrap;
}
.content1 {
display: flex;
flex-wrap: nowrap;
}
.content2 {
display: flex;
flex-wrap: wrap-reverse;
}
```
#### Results
{{ EmbedLiveSample('Setting flex container wrap values', '', '700') }}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- CSS {{CSSXRef("flex-flow")}} shorthand property for the CSS `flex-wrap` and {{CSSXRef("flex-direction")}} properties.
- Flexbox Guide: _[Basic Concepts of Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox)_
- CSS Flexbox Guide: _[Mastering wrapping of flex items](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Mastering_wrapping_of_flex_items)_
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/@supports/index.md | ---
title: "@supports"
slug: Web/CSS/@supports
page-type: css-at-rule
browser-compat: css.at-rules.supports
---
{{CSSRef}}
The **`@supports`** [CSS](/en-US/docs/Web/CSS) [at-rule](/en-US/docs/Web/CSS/At-rule) lets you specify CSS declarations that depend on a browser's support for CSS features.
Using this at-rule is commonly called a _feature query_.
The rule must be placed at the top level of your code or nested inside any other [conditional group at-rule](/en-US/docs/Web/CSS/At-rule#conditional_group_rules).
{{EmbedInteractiveExample("pages/tabbed/at-rule-supports.html", "tabbed-standard")}}
In JavaScript, `@supports` can be accessed via the CSS object model interface {{DOMxRef("CSSSupportsRule")}}.
## Syntax
The `@supports` at-rule consists of a block of statements with a _supports condition._
The supports condition is a set of one or more name-value pairs (e.g., `<property>: <value>`).
```css
@supports (<supports-condition>) {
/* If the condition is true, use the CSS in this block. */
}
```
The conditions can be combined by conjunctions (`and`), disjunctions (`or`), and/or negations (`not`).
```css
@supports (<supports-condition>) and (<supports-condition>) {
/* If both conditions are true, use the CSS in this block. */
}
```
The precedence of operators can be defined with parentheses.
Supports conditions can use either a `<property>: <value>` declaration syntax or a `<function()>` syntax.
The following sections describe the use of each type of supports condition.
### Declaration syntax
The declaration syntax checks if a browser supports the specified `<property>: <value>` declaration.
The declaration must be surrounded by parentheses.
The following example returns true and applies the CSS style if the browser supports the expression `transform-origin: 5% 5%`:
```css
@supports (transform-origin: 5% 5%) {
}
```
### Function syntax
The function syntax checks if a browser supports values or expressions within the function.
The functions supported in the function syntax are described in the following sections.
#### `selector()` {{Experimental_Inline}}
This function evaluates if a browser supports the specified selector syntax.
The following example returns true and applies the CSS style if the browser supports the [child combinator](/en-US/docs/Web/CSS/Child_combinator):
```css
@supports selector(h2 > p) {
}
```
#### `font-tech()`
This function checks if a browser supports the specified font technology for layout and rendering.
The following example returns true and applies the CSS style if the browser supports the `COLRv1` font technology:
```css
@supports font-tech(color-COLRv1) {
}
```
The table below describes the font technologies (`<font-tech>`), including color font technologies (`<color-font-tech>`), font feature technologies (`<font-features-tech>`), and other available font technologies that can be queried using the `font-tech()` function:
| Technology | Supports |
| :----------------------------- | :-------------------------------------------------------------------------------------------- |
| **`<color-font-tech>`** | |
| `color-colrv0` | Multi-colored glyphs via COLR version 0 table |
| `color-colrv1` | Multi-colored glyphs via COLR version 1 table |
| `color-svg` | SVG multi-colored tables |
| `color-sbix` | Standard bitmap graphics tables |
| `color-cbdt` | Color bitmap data tables |
| **`<font-features-tech>`** | |
| `features-opentype` | OpenType `GSUB` and `GPOS` tables |
| `features-aat` | TrueType `morx` and `kerx` tables |
| `features-graphite` | Graphite features, namely `Silf`, `Glat` , `Gloc` , `Feat`, and `Sill` tables |
| **Other `<font-tech>` values** | |
| `incremental-patch` | Incremental font loading using the patch subset method |
| `incremental-range` | Incremental font loading using the range request method |
| `incremental-auto` | Incremental font loading using method negotiation |
| `variations` | Font variations in TrueType and OpenType fonts to control the font axis, weight, glyphs, etc. |
| `palettes` | Font palettes by means of `font-palette` to select one of many color palettes in the font |
#### `font-format()`
This function checks if a browser supports the specified font format for layout and rendering.
The following example returns true and applies the CSS style if the browser supports the `opentype` font format:
```css
@supports font-format(opentype) {
}
```
The following table describes the available formats (`<font-format>` values) that can be queried with this function:
| Format | Description | File extensions |
| :------------------ | :------------------------------ | :-------------- |
| `collection` | OpenType Collection | `.otc`, `.ttc` |
| `embedded-opentype` | Embedded OpenType | `.eot` |
| `opentype` | OpenType | `.ttf`, `.otf` |
| `svg` | SVG Font (deprecated) | `.svg`, `.svgz` |
| `truetype` | TrueType | `.ttf` |
| `woff` | WOFF 1.0 (Web Open Font Format) | `.woff` |
| `woff2` | WOFF 2.0 (Web Open Font Format) | `.woff2` |
### The not operator
The `not` operator precedes an expression resulting in the negation of the expression.
The following returns true if the browser's {{CSSxRef("transform-origin")}} property considers `10em 10em 10em` **to be invalid:**
```css
@supports not (transform-origin: 10em 10em 10em) {
}
```
As with any operator, the `not` operator can be applied to a declaration of any complexity.
The following examples are both valid:
```css
@supports not (not (transform-origin: 2px)) {
}
@supports (display: grid) and (not (display: inline-grid)) {
}
```
> **Note:** There is no need to enclose the `not` operator between two parentheses at the top level.
> To combine it with other operators, like `and` and `or`, the parentheses are required.
### The and operator
The `and` operator creates a new expression from the conjunction of two shorter expressions. It returns true only if **both** of the shorter expressions are also true. The following example returns true if and only if the two shorter expressions are simultaneously true:
```css
@supports (display: table-cell) and (display: list-item) {
}
```
Multiple conjunctions can be juxtaposed without the need of more parentheses. The following are both equivalent:
```css
@supports (display: table-cell) and (display: list-item) and (display: contents) {
}
@supports (display: table-cell) and
((display: list-item) and (display: contents)) {
}
```
### The or operator
The `or` operator creates a new expression from the disjunction of two shorter expressions. It returns true if **one or both** of the shorter expressions is also true. The following example returns true if at least one of the two shorter expressions is true:
```css
@supports (transform-style: preserve) or (-moz-transform-style: preserve) {
}
```
Multiple disjunctions can be juxtaposed without the need of more parentheses. The following are both equivalent:
```css
@supports (transform-style: preserve) or (-moz-transform-style: preserve) or (-webkit-transform-style: preserve) {}
@supports (transform-style: preserve-3d) or ((-moz-transform-style: preserve-3d) or (-webkit-transform-style: preserve-3d))) {}
```
> **Note:** When using both `and` and `or` operators, the parentheses must be used to define the order in which they apply. Otherwise, the condition is invalid and the whole rule is ignored.
## Formal syntax
{{csssyntax}}
## Examples
### Testing for the support of a CSS property
```css
@supports (animation-name: test) {
/* CSS applied when animations are supported without a prefix */
@keyframes {
/* Other at-rules can be nested inside */
}
}
```
### Testing for the support of a given CSS property or a prefixed version
```css
@supports (text-stroke: 10px) or (-webkit-text-stroke: 10px) {
/* CSS applied when text-stroke, prefixed or not, is supported */
}
```
### Testing for the non-support of a specific CSS property
```css
@supports not ((text-align-last: justify) or (-moz-text-align-last: justify)) {
/* CSS to provide fallback alternative for text-align-last: justify */
}
```
### Testing for the support of a selector
CSS conditional rules provide the ability to test for the support of a selector such as {{cssxref(":has",":has()")}}.
```css
/* This rule won't be applied in browsers that don't support :has() */
ul:has(> li li) {
/* CSS is applied when the :has(…) pseudo-class is supported */
}
@supports not selector(:has(a, b)) {
/* Fallback for when :has() is unsupported */
ul > li,
ol > li {
/* The above expanded for browsers that don't support :has(…) */
}
}
/* Note: So far, there's no browser that supports the `of` argument of :nth-child(…) */
@supports selector(:nth-child(1n of a, b)) {
/* This rule needs to be inside the @supports block, otherwise
it will be partially applied in browsers which don't support
the `of` argument of :nth-child(…) */
:is(:nth-child(1n of ul, ol) a, details > summary) {
/* CSS applied when the :is(…) selector and
the `of` argument of :nth-child(…) are both supported */
}
}
```
### Testing for the support of a font technology
The following example applies the CSS style if the browser supports the `COLRv1` font technology:
```css
@import url("https://fonts.googleapis.com/css2?family=Bungee+Spice");
@supports font-tech(color-COLRv1) {
font-family: "Bungee Spice";
}
```
It's also possible to test for the support of a font technology by using the `tech` function inside the {{CSSxRef("@font-face")}} at-rule.
If a browser doesn't support the font technology, a fallback font (`Bungee-fallback.otf`) can be used instead.
```css
@font-face {
font-family: "Bungee Spice";
src:
url("https://fonts.googleapis.com/css2?family=Bungee+Spice") tech(color-COLRv1),
url("Bungee-fallback.otf") format("opentype");
}
```
### Testing for the support of a font format
The following example applies the CSS style if the browser supports the `woff2` font format:
```css
@supports font-format(woff2) {
font-family: "Open Sans";
src: url("open-sans.woff2") format("woff2");
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Using feature queries](/en-US/docs/Web/CSS/CSS_conditional_rules/Using_feature_queries)
- The CSSOM class {{DOMxRef("CSSSupportsRule")}}, and the {{DOMxref("CSS.supports_static", "CSS.supports()")}} method that allows the same check to be performed via JavaScript.
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/resolved_value/index.md | ---
title: Resolved value
slug: Web/CSS/resolved_value
page-type: guide
spec-urls: https://drafts.csswg.org/cssom/#resolved-values
---
{{CSSRef}}
The **resolved value** of a [CSS](/en-US/docs/Web/CSS) property is the value returned by {{domxref("Window.getComputedStyle", "getComputedStyle()")}}.
For most properties, it is the [computed value](/en-US/docs/Web/CSS/computed_value), but for a few legacy properties (including {{cssxref("width")}} and {{cssxref("height")}}), it is instead the [used value](/en-US/docs/Web/CSS/used_value). See the specification link below for more per-property details.
## Specifications
{{Specifications}}
## See also
- {{domxref("window.getComputedStyle")}}
- CSS key concepts:
- [CSS syntax](/en-US/docs/Web/CSS/Syntax)
- [At-rules](/en-US/docs/Web/CSS/At-rule)
- [Comments](/en-US/docs/Web/CSS/Comments)
- [Specificity](/en-US/docs/Web/CSS/Specificity)
- [Inheritance](/en-US/docs/Web/CSS/Inheritance)
- [Box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model)
- [Layout modes](/en-US/docs/Web/CSS/Layout_mode)
- [Visual formatting models](/en-US/docs/Web/CSS/Visual_formatting_model)
- [Margin collapsing](/en-US/docs/Web/CSS/CSS_box_model/Mastering_margin_collapsing)
- Values
- [Initial values](/en-US/docs/Web/CSS/initial_value)
- [Computed values](/en-US/docs/Web/CSS/computed_value)
- [Used values](/en-US/docs/Web/CSS/used_value)
- [Actual values](/en-US/docs/Web/CSS/actual_value)
- [Value definition syntax](/en-US/docs/Web/CSS/Value_definition_syntax)
- [Shorthand properties](/en-US/docs/Web/CSS/Shorthand_properties)
- [Replaced elements](/en-US/docs/Web/CSS/Replaced_element)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/css_animated_properties/index.md | ---
title: Animatable CSS properties
slug: Web/CSS/CSS_animated_properties
page-type: landing-page
---
{{CSSRef}}
[CSS Animations](/en-US/docs/Web/CSS/CSS_animations) and [Transitions](/en-US/docs/Web/CSS/CSS_transitions) rely on the concept of **animatable** properties, and all CSS properties are animatable unless otherwise specified. Each property's _animation type_ determines how values [combine](https://drafts.csswg.org/css-values/#combining-values) - interpolate, add, or accumulate - for this property. Transitions only involve interpolation, whereas animations may use all three combination methods.
> **Note:** The animation type for each CSS property is listed in its "Formal definition" table (E.g., {{CSSXref("color", "", "#formal_definition")}}).
> **Note:** The interpolation method for each CSS data type is described in its "Interpolation" section (E.g., {{CSSXref("<length>", "", "#interpolation")}}).
## Animation types
There are mainly four animation types as defined in the [Web Animations](https://drafts.csswg.org/web-animations-1/#animating-properties) specification:
- Not animatable
- : The property is not animatable. It is not processed when listed in an animation keyframe and is unaffected by transitions.
> **Note:** An animation effect targeting only properties that are not animatable will still exhibit the usual behavior for an animation effect (E.g., firing the {{DOMXref("Element/animationstart_event", "animationstart")}} event).
- Discrete
- : The property's values are not additive, and interpolation swaps from the start value to the end value at `50%`. Specifically, denoting by `p` the progress value:
- If `p < 0.5`, then `V_result = V_start`;
- If `p ≥ 0.5`, then `V_result = V_end`.
- By computed value
- : Corresponding individual components of the computed values are combined using the indicated procedure for that value type. If the number of components or the types of corresponding components do not match, or if any component value uses discrete animation and the two corresponding values do not match, then the property values combine as discrete.
- Repeatable list
- : Same as by computed value except that if the two lists have differing numbers of items, they are first repeated to the least common multiple numbers of items. Each item is then combined by computed value. If a pair of values cannot be combined or any component value uses discrete animation, then the property values combine as discrete.
Some properties have specific interpolation behavior not covered by these four types. In this case, refer to the property's "Interpolation" section (E.g., {{CSSXref("visibility", "", "#interpolation")}}).
## Animating custom properties
For custom properties registered using the {{DOMXref("CSS/registerProperty_static", "registerProperty()")}} method, the animation type is by computed value, with the computed value type [determined](https://drafts.css-houdini.org/css-properties-values-api/#calculation-of-computed-values) by the property's syntax definition.
For unregistered custom properties, the animation type is discrete.
## See also
- [Using CSS Animations](/en-US/docs/Web/CSS/CSS_animations/Using_CSS_animations)
- [Using CSS Transitions](/en-US/docs/Web/CSS/CSS_transitions/Using_CSS_transitions)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/@starting-style/index.md | ---
title: "@starting-style"
slug: Web/CSS/@starting-style
page-type: css-at-rule
status:
- experimental
browser-compat: css.at-rules.starting-style
---
{{CSSRef}}{{SeeCompatTable}}
The **`@starting-style`** [CSS](/en-US/docs/Web/CSS) [at-rule](/en-US/docs/Web/CSS/At-rule) is used to define starting values for properties set on an element that you want to transition from when the element receives its first style update, i.e. when an element is first displayed on a previously loaded page.
## Syntax
The `@starting-style` at rule can be used in two ways:
1. As a standalone block, in which case it contains one or more rulesets defining starting style declarations and selecting the elements they apply to:
```css
@starting-style {
rulesets
}
```
2. Nested within an existing ruleset, in which case it contains one or more declarations defining starting property values for the elements already selected by that ruleset:
```css
selector { /* existing ruleset */
/* ... */
@starting-style {
declarations
}
}
```
## Description
To avoid unexpected behavior, [CSS transitions](/en-US/docs/Web/CSS/CSS_transitions) are by default not triggered on an element's initial style update, or when its {{CSSxRef("display")}} type changes from `none` to another value. To enable first-style transitions, `@starting-style` rules are needed. They provide starting styles for elements that do not have a previous state, defining the property values to transition from.
`@starting-style` is especially useful when creating entry and exit transitions for elements displayed in the [top layer](/en-US/docs/Glossary/Top_layer) (such as [popovers](/en-US/docs/Web/API/Popover_API) and modal {{htmlelement("dialog")}}s), elements that are changing to and from `display: none`, and elements when first added to or removed from the DOM.
> **Note:** `@starting-style` is only relevant to CSS transitions. When using [CSS animations](/en-US/docs/Web/CSS/CSS_animations) to implement such effects, `@starting-style` is not needed. See [Using CSS animations](/en-US/docs/Web/CSS/CSS_animations/Using_CSS_animations) for an example.
There are two ways to use `@starting-style`: as a standalone rule or nested within a ruleset.
Let's consider a scenario where we want to animate a [popover](/en-US/docs/Web/API/Popover_API) when shown (that is, when added to the top layer). The "original rule" specifying the styles for the open popover could look something like this (see the [popover example](#animating_a_popover) below):
```css
[popover]:popover-open {
opacity: 1;
transform: scaleX(1);
}
```
To specify the starting values of the popover's properties that will be animated using the first method, you include a standalone `@starting-style` block in your CSS:
```css
@starting-style {
[popover]:popover-open {
opacity: 0;
transform: scaleX(0);
}
}
```
> **Note:** The `@starting-style` at-rule and the "original rule" have the same {{cssxref("specificity")}}. To ensure that starting styles get applied, include the `@starting-style` at-rule _after_ the "original rule". If you specify the `@starting-style` at-rule before the "original rule", the original styles will override the starting styles.
To specify the starting style for the popover using the nested method, you can nest the `@starting-style` block inside the "original rule":
```css
[popover]:popover-open {
opacity: 1;
transform: scaleX(1);
@starting-style {
opacity: 0;
transform: scaleX(0);
}
}
```
### When exactly are starting styles used?
It is important to understand that an element will transition from its `@starting-style` styles when it is first rendered in the DOM, or when it transitions from {{cssxref("display", "display: none")}} to a visible value. When it transitions back from its initial visible state, it will no longer use the `@starting-style` styles as it is now visible in the DOM. Instead, it will transition back to whatever styles exist for that element's default state.
In effect, there are three style states to manage in these situations — starting-style state, transitioned state, and default state. It is possible for the "to" and "from" transitions to be different in such cases. You can see a proof of this in our [Demonstration of when starting styles are used](#demonstration_of_when_starting_styles_are_used) example, below.
## Formal syntax
{{csssyntax}}
## Examples
### Basic @starting-style usage
Transition an element's {{cssxref("background-color")}} from transparent to green when it is initially rendered:
```css
#target {
transition: background-color 1.5s;
background-color: green;
}
@starting-style {
#target {
background-color: transparent;
}
}
```
Transition the {{cssxref("opacity")}} of an element when it changes its {{cssxref("display")}} value to or from `none`:
```css
#target {
transition-property: opacity, display;
transition-duration: 0.5s;
display: block;
opacity: 1;
@starting-style {
opacity: 0;
}
}
#target.hidden {
display: none;
opacity: 0;
}
```
### Demonstration of when starting styles are used
In this example, a button is pressed to create a {{htmlelement("div")}} element, give it a `class` of `showing`, and add it to the DOM.
`showing` is given a `@starting-style` of `background-color: red` and a style of `background-color: blue` to transition to. The default `div` ruleset contains `background-color: yellow`, and is also where the `transition` is set.
When the `<div>` is first added to the DOM, you'll see the background transition from red to blue. After a timeout, we remove the `showing` class from the `<div>` via JavaScript. At that point it transitions from blue back to yellow, not red. This proves that the starting styles are only used when the element is first rendered in the DOM. Once it has appeared, the element transitions back to the default style set on it.
After another timeout, we then remove the `<div>` from the DOM altogether, resetting the initial state of the example so it can be run again.
#### HTML
```html
<button>Display <code><div></code></button>
```
#### CSS
```css hidden
div {
width: 200px;
height: 100px;
border: 1px solid black;
margin-top: 10px;
}
div::after {
content: "class: " attr(class);
position: relative;
top: 3px;
left: 3px;
}
```
```css
div {
background-color: yellow;
transition: background-color 3s;
}
div.showing {
background-color: skyblue;
}
@starting-style {
div.showing {
background-color: red;
}
}
```
#### JavaScript
```js
const btn = document.querySelector("button");
btn.addEventListener("click", () => {
btn.disabled = true;
const divElem = document.createElement("div");
divElem.classList.add("showing");
document.body.append(divElem);
setTimeout(() => {
divElem.classList.remove("showing");
setTimeout(() => {
divElem.remove();
btn.disabled = false;
}, 3000);
}, 3000);
});
```
#### Result
The code renders as follows:
{{ EmbedLiveSample("Demonstration of when starting styles are used", "100%", "150") }}
### Animating a popover
In this example, a [popover](/en-US/docs/Web/API/Popover_API) is animated using [CSS transitions](/en-US/docs/Web/CSS/CSS_transitions). Basic entry and exit animations are provided using the {{CSSxRef("transition")}} property.
#### HTML
The HTML contains a {{htmlelement("div")}} element declared as a popover using the [popover](/en-US/docs/Web/HTML/Global_attributes/popover) attribute and a {{htmlelement("button")}} element designated as the popover's display control using its [popovertarget](/en-US/docs/Web/HTML/Element/button#popovertarget) attribute.
```html
<button popovertarget="mypopover">Show the popover</button>
<div popover="auto" id="mypopover">I'm a Popover! I should animate.</div>
```
#### CSS
In this example, we want to animate two properties, [`opacity`](/en-US/docs/Web/CSS/opacity) and [`transform`](/en-US/docs/Web/CSS/transform) (specifically, a horizontally scaling transform), to make the popover fade in and out as well as grow and shrink horizontally.
```css
html {
font-family: Arial, Helvetica, sans-serif;
}
[popover]:popover-open {
opacity: 1;
transform: scaleX(1);
}
[popover] {
font-size: 1.2rem;
padding: 10px;
/* Final state of the exit animation */
opacity: 0;
transform: scaleX(0);
transition:
opacity 0.7s,
transform 0.7s,
overlay 0.7s allow-discrete,
display 0.7s allow-discrete;
/* Equivalent to
transition: all 0.7s allow-discrete; */
}
/* Include after the [popover]:popover-open rule */
@starting-style {
[popover]:popover-open {
opacity: 0;
transform: scaleX(0);
}
}
/* Transition for the popover's backdrop */
[popover]::backdrop {
background-color: rgb(0 0 0 / 0%);
transition:
display 0.7s allow-discrete,
overlay 0.7s allow-discrete,
background-color 0.7s;
/* Equivalent to
transition: all 0.7s allow-discrete; */
}
[popover]:popover-open::backdrop {
background-color: rgb(0 0 0 / 25%);
}
/* Nesting (&) is not supported for pseudo-elements
so specify a standalone starting-style block. */
@starting-style {
[popover]:popover-open::backdrop {
background-color: rgb(0 0 0 / 0%);
}
}
```
To achieve this, we have set a starting state for these properties on the default hidden state of the popover element (selected via `[popover]`), and an ending state on the open state of the popover (selected via the [`:popover-open`](/en-US/docs/Web/CSS/:popover-open) pseudo-class).
We then set a [`transition`](/en-US/docs/Web/CSS/transition) property to animate between the two states. A starting state for the animation is included inside a `@starting-style` at-rule to enable the entry animation.
Because the animated element is being promoted to the [top layer](/en-US/docs/Glossary/Top_layer) when shown and removed from the top layer when hidden (with [`display: none`](/en-US/docs/Web/CSS/display)), some extra steps are required to ensure the animation works in both directions:
- `display` is added to the list of transitioned elements to ensure the animated element is visible (set to `display: block` or another visible `display` value) throughout both the entry and exit animations. Without this, the exit animation would not be visible; in effect, the popover would just disappear. Note that the [`transition-behavior: allow-discrete`](/en-US/docs/Web/CSS/transition-behavior) value is also set in the shorthand to activate the animation.
- [`overlay`](/en-US/docs/Web/CSS/overlay) is added to the list of transitioned elements to ensure that the removal of the element from the top layer is deferred until the animation ends. This doesn't make a huge difference for simple animations such as this one, but in more complex cases, not doing this can result in the element being removed from the overlay too quickly, meaning the animation is not smooth or effective. Again, `transition-behavior: allow-discrete` is required in this case for the animation to occur.
> **Note:** We've also included a transition on the [`::backdrop`](/en-US/docs/Web/CSS/::backdrop) that appears behind the popover when it opens, to provide a nice darkening animation. `[popover]:popover-open::backdrop` is used to select the backdrop when the popover is open.
#### Result
The code renders as follows:
{{ EmbedLiveSample("Animating a popover", "100%", "200") }}
> **Note:** Because popovers change from `display: none` to `display: block` each time they are shown, the popover transitions from its `@starting-style` styles to its `[popover]:popover-open` styles every time the entry transition occurs. When the popover closes, it transitions from its `[popover]:popover-open` state to the default `[popover]` state.
> **Note:** You can find an example that demonstrates transitioning a {{htmlelement("dialog")}} element and its backdrop as it is shown and hidden on the `<dialog>` reference page — see [Transitioning dialog elements](/en-US/docs/Web/HTML/Element/dialog#transitioning_dialog_elements).
### Transitioning elements on DOM addition and removal
This example contains a button which, when pressed, appends new elements to a {{htmlelement("section")}} container. Each element, in turn, contains a nested button, which when pressed, removes the element. This example demonstrates how to use transitions to animate elements when they are added to or removed from the DOM.
#### HTML
```html
<button>Create new column</button>
<section></section>
```
#### JavaScript
JavaScript enables the addition and removal of elements:
```js
const btn = document.querySelector("button");
const sectionElem = document.querySelector("section");
btn.addEventListener("click", createColumn);
function randomColor() {
function randomNum() {
return Math.floor(Math.random() * 255);
}
return `rgb(${randomNum()} ${randomNum()} ${randomNum()})`;
}
function createColumn() {
const divElem = document.createElement("div");
divElem.style.backgroundColor = randomColor();
const closeBtn = document.createElement("button");
closeBtn.textContent = "✖";
closeBtn.setAttribute("aria-label", "close");
divElem.append(closeBtn);
sectionElem.append(divElem);
closeBtn.addEventListener("click", () => {
divElem.classList.add("fade-out");
setTimeout(() => {
divElem.remove();
}, 1000);
});
}
```
When the "Create new column" button is clicked, the `createColumn()` function is called. This creates a {{htmlelement("div")}} element with a randomly generated background color and a {{htmlelement("button")}} element to close the `<div>`. It then appends the `<button>` to the `<div>` and the `<div>` to the `<section>` container.
We then add an event listener to the close button via {{domxref("EventTarget.addEventListener", "addEventListener")}}. Clicking the close button does two things:
- Adds the `fade-out` class to the `<div>`. Adding the class triggers the exit animation set on that class.
- Removes the `<div>` after a 1000ms delay. The {{domxref("setTimeout()")}} delays removal of the `<div>` from the DOM (via {{domxref("Element.remove()")}}) until after the animation ends.
#### CSS
We include a {{cssxref("transition")}} that animates the {{cssxref("opacity")}} and {{cssxref("scale")}} of each column as they are added and removed:
```css hidden
html * {
box-sizing: border-box;
font-family: sans-serif;
}
body {
margin: 0;
display: flex;
flex-direction: column;
height: 100vh;
gap: 10px;
}
body > button {
margin: 10px 10px 0 10px;
}
section {
display: flex;
flex: 1;
gap: 10px;
margin: 10px;
}
```
```css
div {
flex: 1;
border: 1px solid gray;
position: relative;
background: linear-gradient(
to right,
rgb(255 255 255 / 0%),
rgb(255 255 255 / 50%)
);
opacity: 1;
scale: 1 1;
transition:
opacity 0.7s,
scale 0.7s,
display 0.7s allow-discrete;
all 0.7s allow-discrete
/* Equivalent to
transition: all 0.7s allow-discrete; */
}
/* Include after the `div` rule */
@starting-style {
div {
opacity: 0;
scale: 1 0;
}
}
.fade-out {
opacity: 0;
display: none;
scale: 1 0;
}
div > button {
font-size: 1.6rem;
background: none;
border: 0;
text-shadow: 2px 1px 1px white;
border-radius: 15px;
position: absolute;
top: 1px;
right: 1px;
cursor: pointer;
}
```
To animate the [`opacity`](/en-US/docs/Web/CSS/opacity) and [`scale`](/en-US/docs/Web/CSS/scale) of each `<div>` as it is added to the DOM and then reverse the animation as it is removed from the DOM, we:
- Specify the ending state of the properties we want to transition on the `div { ... }` rule.
- Specify the starting state from which to transition the properties inside a `@starting-style` block.
- Specify the exit animation inside the `.fade-out` rule — this is the class that the JavaScript assigns to the `<div>` elements when their close buttons are pressed. Besides setting the `opacity` and `scale` ending states, we also set [`display: none`](/en-US/docs/Web/CSS/display) on the `<div>`s — we want them to become immediately unavailable when removed from the UI.
- Specify the [`transition`](/en-US/docs/Web/CSS/transition) list inside the `div { ... }` rule to animate `opacity`, `scale`, and `display`. Note that for `display`, the [`transition-behavior: allow-discrete`](/en-US/docs/Web/CSS/transition-behavior) value is also set in the shorthand so that it will animate.
#### Result
The final result looks like this:
{{ EmbedLiveSample("Transitioning elements on DOM addition and removal", "100%", "400") }}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [CSS transitions](/en-US/docs/Web/CSS/CSS_transitions) module
- [`overlay`](/en-US/docs/Web/CSS/overlay)
- [`transition-behavior`](/en-US/docs/Web/CSS/transition-behavior)
- {{domxref("CSSStartingStyleRule")}}
- [Four new CSS features for smooth entry and exit animations](https://developer.chrome.com/blog/entry-exit-animations/) on developer.chrome.com (2023)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/border-top-color/index.md | ---
title: border-top-color
slug: Web/CSS/border-top-color
page-type: css-property
browser-compat: css.properties.border-top-color
---
{{CSSRef}}
The **`border-top-color`** CSS property sets the color of an element's top [border](/en-US/docs/Web/CSS/border). It can also be set with the shorthand CSS properties {{cssxref("border-color")}} or {{cssxref("border-top")}}.
{{EmbedInteractiveExample("pages/css/border-top-color.html")}}
## Syntax
```css
/* <color> values */
border-top-color: red;
border-top-color: #ffbb00;
border-top-color: rgb(255 0 0);
border-top-color: hsl(100deg 50% 25% / 75%);
border-top-color: currentcolor;
border-top-color: transparent;
/* Global values */
border-top-color: inherit;
border-top-color: initial;
border-top-color: revert;
border-top-color: revert-layer;
border-top-color: unset;
```
The `border-top-color` property is specified as a single value.
### Values
- {{cssxref("<color>")}}
- : The color of the top border.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### A simple div with a border
#### HTML
```html
<div class="mybox">
<p>
This is a box with a border around it. Note which side of the box is
<span class="redtext">red</span>.
</p>
</div>
```
#### CSS
```css
.mybox {
border: solid 0.3em gold;
border-top-color: red;
width: auto;
}
.redtext {
color: red;
}
```
#### Result
{{EmbedLiveSample('A_simple_div_with_a_border')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- The border-related CSS shorthand properties: {{cssxref("border")}}, {{cssxref("border-top")}}, and {{cssxref("border-color")}}.
- The color-related CSS properties for the other borders: {{cssxref("border-right-color")}}, {{cssxref("border-bottom-color")}}, and {{cssxref("border-left-color")}}.
- The other border-related CSS properties applying to the same border: {{cssxref("border-top-style")}} and {{cssxref("border-top-width")}}.
- The default [`currentcolor`](/en-US/docs/Web/CSS/color_value#currentcolor_keyword) color value.
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_read-write/index.md | ---
title: ":read-write"
slug: Web/CSS/:read-write
page-type: css-pseudo-class
browser-compat: css.selectors.read-write
---
{{CSSRef}}
The **`:read-write`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents an element (such as `input` or `textarea`) that is editable by the user.
{{EmbedInteractiveExample("pages/tabbed/pseudo-class-read-write.html", "tabbed-shorter")}}
## Syntax
```css
:read-write {
/* ... */
}
```
## Examples
### Confirming form information in read-only/read-write controls
One use of `readonly` form controls is to allow the user to check and verify information that they may have entered in an earlier form (for example, shipping details), while still being able to submit the information along with the rest of the form. We do just this in the example below.
The `:read-only` pseudo-class is used to remove all the styling that makes the inputs look like clickable fields, making them look more like read-only paragraphs. The `:read-write` pseudo-class on the other hand is used to provide some nicer styling to the editable `<textarea>`.
```css
input:-moz-read-only,
textarea:-moz-read-only,
input:read-only,
textarea:read-only {
border: 0;
box-shadow: none;
background-color: white;
}
textarea:-moz-read-write,
textarea:read-write {
box-shadow: inset 1px 1px 3px #ccc;
border-radius: 5px;
}
```
You can find the full source code at [readonly-confirmation.html](https://github.com/mdn/learning-area/blob/main/html/forms/pseudo-classes/readonly-confirmation.html); this renders like so:
{{EmbedGHLiveSample("learning-area/html/forms/pseudo-classes/readonly-confirmation.html", '100%', 660)}}
### Styling read-write non-form controls
This selector doesn't just select {{htmlElement("input")}}/{{htmlElement("textarea")}} elements — it will select _any_ element that can be edited by the user, such as a {{htmlelement("p")}} element with [`contenteditable`](/en-US/docs/Web/HTML/Global_attributes#contenteditable) set on it.
```html
<p contenteditable>This paragraph is editable; it is read-write.</p>
<p>This paragraph is not editable; it is read-only.</p>
```
```css
p {
font-size: 150%;
padding: 5px;
border-radius: 5px;
}
p:read-only {
background-color: red;
color: white;
}
p:read-write {
background-color: lime;
}
```
{{EmbedLiveSample('Styling_read-write_non-form_controls', '100%', 400)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref(":read-only")}}
- HTML [`contenteditable`](/en-US/docs/Web/HTML/Global_attributes#contenteditable) attribute
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/border-image-source/index.md | ---
title: border-image-source
slug: Web/CSS/border-image-source
page-type: css-property
browser-compat: css.properties.border-image-source
---
{{CSSRef}}
The **`border-image-source`** [CSS](/en-US/docs/Web/CSS) property sets the source image used to create an element's [border image](/en-US/docs/Web/CSS/border-image).
{{EmbedInteractiveExample("pages/css/border-image-source.html")}}
The {{cssxref("border-image-slice")}} property is used to divide the source image into regions, which are then dynamically applied to the final border image.
## Syntax
```css
/* Keyword value */
border-image-source: none;
/* <image> values */
border-image-source: url(image.jpg);
border-image-source: linear-gradient(to top, red, yellow);
/* Global values */
border-image-source: inherit;
border-image-source: initial;
border-image-source: revert;
border-image-source: revert-layer;
border-image-source: unset;
```
### Values
- `none`
- : No border image is used. The appearance defined by {{cssxref("border-style")}} is displayed instead.
- {{cssxref("<image>")}}
- : Image reference to use for the border.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Basic example
```css
.box {
border-image-source: url("image.png");
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("border")}}
- {{cssxref("outline")}}
- {{cssxref("box-shadow")}}
- {{cssxref("background-image")}}
- {{cssxref("url", "url()")}} function
- [Border images in CSS: A key focus area for Interop 2023](/en-US/blog/border-images-interop-2023/) on MDN blog (2023)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/border-top-right-radius/index.md | ---
title: border-top-right-radius
slug: Web/CSS/border-top-right-radius
page-type: css-property
browser-compat: css.properties.border-top-right-radius
---
{{CSSRef}}
The **`border-top-right-radius`** [CSS](/en-US/docs/Web/CSS) property rounds the top-right corner of an element by specifying the radius (or the radius of the semi-major and semi-minor axes) of the ellipse defining the curvature of the corner.
{{EmbedInteractiveExample("pages/css/border-top-right-radius.html")}}
The rounding can be a circle or an ellipse, or if one of the value is `0` no rounding is done and the corner is square.

A background, being an image or a color, is clipped at the border, even a rounded one; the exact location of the clipping is defined by the value of the {{cssxref("background-clip")}} property.
> **Note:** If the value of this property is not set in a {{cssxref("border-radius")}} shorthand property that is applied to the element after the `border-top-right-radius` CSS property, the value of this property is then reset to its initial value by the [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties).
## Syntax
```css
/* the corner is a circle */
/* border-top-right-radius: radius */
border-top-right-radius: 3px;
/* the corner is an ellipse */
/* border-top-right-radius: horizontal vertical */
border-top-right-radius: 0.5em 1em;
border-top-right-radius: inherit;
/* Global values */
border-top-right-radius: inherit;
border-top-right-radius: initial;
border-top-right-radius: revert;
border-top-right-radius: revert-layer;
border-top-right-radius: unset;
```
With one value:
- the value is a {{cssxref("<length>")}} or a {{cssxref("<percentage>")}} denoting the radius of the circle to use for the border in that corner.
With two values:
- the first value is a {{cssxref("<length>")}} or a {{cssxref("<percentage>")}} denoting the horizontal semi-major axis of the ellipse to use for the border in that corner.
- the second value is a {{cssxref("<length>")}} or a {{cssxref("<percentage>")}} denoting the vertical semi-major axis of the ellipse to use for the border in that corner.
### Values
- `<length-percentage>`
- : Denotes the size of the circle radius or the semi-major and semi-minor axes of the ellipse. As absolute length it can be expressed in any unit allowed by the CSS {{cssxref("<length>")}} data type. Percentages for the horizontal axis refer to the width of the box, percentages for the vertical axis refer to the height of the box. Negative values are invalid.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Arc of a circle
A single `<length>` value produces an arc of a circle.
```html hidden
<div></div>
```
```css
div {
border-top-right-radius: 40px;
background-color: lightgreen;
border: solid 1px black;
width: 100px;
height: 100px;
}
```
{{EmbedLiveSample("Arc_of_a_circle")}}
### Arc of an ellipse
Two different `<length>` values produce an arc of an ellipse.
```html hidden
<div></div>
```
```css
div {
border-top-right-radius: 40px 20px;
background-color: lightgreen;
border: solid 1px black;
width: 100px;
height: 100px;
}
```
{{EmbedLiveSample("Arc_of_an_ellipse")}}
### Square element with percentage radius
A square element with a single `<percentage>` value produces an arc of a circle.
```html hidden
<div></div>
```
```css
div {
border-top-right-radius: 40%;
background-color: lightgreen;
border: solid 1px black;
width: 100px;
height: 100px;
}
```
{{EmbedLiveSample("Square_element_with_percentage_radius")}}
### Non-square element with percentage radius
A non-square element with a single `<percentage>` value produces an arc of an ellipse.
```html hidden
<div></div>
```
```css
div {
border-top-right-radius: 40%;
background-color: lightgreen;
border: solid 1px black;
width: 200px;
height: 100px;
}
```
{{EmbedLiveSample("Non-square_element_with_percentage_radius")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("border-radius")}} shorthand property
- {{cssxref("border-bottom-right-radius")}}, {{cssxref("border-bottom-left-radius")}}, and {{cssxref("border-top-left-radius")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/writing-mode/index.md | ---
title: writing-mode
slug: Web/CSS/writing-mode
page-type: css-property
browser-compat: css.properties.writing-mode
---
{{CSSRef}}
The **`writing-mode`** [CSS](/en-US/docs/Web/CSS) property sets whether lines of text are laid out horizontally or vertically, as well as the direction in which blocks progress. When set for an entire document, it should be set on the root element (`html` element for HTML documents).
{{EmbedInteractiveExample("pages/css/writing-mode.html")}}
This property specifies the _block flow direction_, which is the direction in which block-level containers are stacked, and the direction in which inline-level content flows within a block container. Thus, it also determines the ordering of block-level content.
## Syntax
```css
/* Keyword values */
writing-mode: horizontal-tb;
writing-mode: vertical-rl;
writing-mode: vertical-lr;
/* Global values */
writing-mode: inherit;
writing-mode: initial;
writing-mode: revert;
writing-mode: revert-layer;
writing-mode: unset;
```
The `writing-mode` property is specified as one of the values listed below. The flow direction in horizontal scripts is also affected by the [directionality of that script](https://www.w3.org/International/questions/qa-scripts.en), either left-to-right (`ltr`, like English and most other languages) or right-to-left (`rtl`, like Hebrew or Arabic).
### Values
- `horizontal-tb`
- : For `ltr` scripts, content flows horizontally from left to right. For `rtl` scripts, content flows horizontally from right to left. The next horizontal line is positioned below the previous line.
- `vertical-rl`
- : For `ltr` scripts, content flows vertically from top to bottom, and the next vertical line is positioned to the left of the previous line. For `rtl` scripts, content flows vertically from bottom to top, and the next vertical line is positioned to the right of the previous line.
- `vertical-lr`
- : For `ltr` scripts, content flows vertically from top to bottom, and the next vertical line is positioned to the right of the previous line. For `rtl` scripts, content flows vertically from bottom to top, and the next vertical line is positioned to the left of the previous line.
- `sideways-rl`
- : For `ltr` scripts, content flows vertically from top to bottom. For `rtl` scripts, content flows vertically from bottom to top. All the glyphs, even those in vertical scripts, are set sideways toward the right.
- `sideways-lr`
- : For `ltr` scripts, content flows vertically from bottom to top. For `rtl` scripts, content flows vertically from top to bottom. All the glyphs, even those in vertical scripts, are set sideways toward the left.
- `lr` {{deprecated_inline}}
- : Deprecated except for SVG1 documents. For CSS, use `horizontal-tb` instead.
- `lr-tb` {{deprecated_inline}}
- : Deprecated except for SVG1 documents. For CSS, use `horizontal-tb` instead.
- `rl` {{deprecated_inline}}
- : Deprecated except for SVG1 documents. For CSS, use `horizontal-tb` instead.
- `tb` {{deprecated_inline}}
- : Deprecated except for SVG1 documents. For CSS, use `vertical-lr` instead.
- `tb-lr` {{deprecated_inline}}
- : Deprecated except for SVG1 documents. For CSS, use `vertical-lr` instead.
- `tb-rl` {{deprecated_inline}}
- : Deprecated except for SVG1 documents. For CSS, use `vertical-rl` instead.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{CSSSyntax}}
## Examples
### Using multiple writing modes
This example demonstrates all of the writing modes, showing each with text in various languages.
#### HTML
The HTML is a {{HTMLElement("table")}} with each writing mode in a row with a column showing text in various scripts using that writing mode.
```html
<table>
<caption>
Using multiple writing modes
</caption>
<tr>
<th>Value</th>
<th>Vertical script</th>
<th>Horizontal (LTR) script</th>
<th>Horizontal (RTL) script</th>
<th>Mixed script</th>
</tr>
<tr class="text1">
<th>horizontal-tb</th>
<td>我家没有电脑。</td>
<td>Example text</td>
<td>מלל ארוך לדוגמא</td>
<td>1994年に至っては</td>
</tr>
<tr class="text2">
<th>vertical-lr</th>
<td>我家没有电脑。</td>
<td>Example text</td>
<td>מלל ארוך לדוגמא</td>
<td>1994年に至っては</td>
</tr>
<tr class="text3">
<th>vertical-rl</th>
<td>我家没有电脑。</td>
<td>Example text</td>
<td>מלל ארוך לדוגמא</td>
<td>1994年に至っては</td>
</tr>
<tr class="experimental text4">
<th>sideways-lr</th>
<td>我家没有电脑。</td>
<td>Example text</td>
<td>מלל ארוך לדוגמא</td>
<td>1994年に至っては</td>
</tr>
<tr class="experimental text5">
<th>sideways-rl</th>
<td>我家没有电脑。</td>
<td>Example text</td>
<td>מלל ארוך לדוגמא</td>
<td>1994年に至っては</td>
</tr>
</table>
<p class="notice">
Your browser does not support the <code>sideways-lr</code> or
<code>sideways-rl</code> values.
</p>
```
#### CSS
```css hidden
table {
border-collapse: collapse;
}
td,
th {
border: 2px black solid;
padding: 4px;
}
th {
background-color: lightgray;
}
.experimental {
display: none;
}
.notice {
display: table-row;
font-weight: bold;
text-align: center;
}
@supports (writing-mode: sideways-lr) {
.experimental {
display: table-row;
}
.notice {
display: none;
}
}
```
The CSS that adjusts the directionality of the content looks like this:
```css
.text1 td {
writing-mode: horizontal-tb;
}
.text2 td {
writing-mode: vertical-lr;
}
.text3 td {
writing-mode: vertical-rl;
}
.text4 td {
writing-mode: sideways-lr;
}
.text5 td {
writing-mode: sideways-rl;
}
```
#### Result
{{EmbedLiveSample("Using_multiple_writing_modes", 400, 700)}}
### Using writing-mode with transforms
If your browser doesn't support `sideways-lr`, a workaround is to use {{cssxref("transform")}} to achieve a similar effect depending on the script direction.
The effect of `vertical-rl` is the same as with `sideways-lr`, so no transformation is required for left-to-right scripts.
In some cases, rotating the text 180 degrees is sufficient to achieve the effect of `sideways-lr`, but font glyphs may not be designed to be rotated, so this may produce unexpected positioning or rendering.
#### HTML
```html
<table>
<caption>
Using writing-mode with transforms
</caption>
<thead>
<tr>
<th>Vertical LR</th>
<th>Vertical LR with transform</th>
<th>Sideways LR</th>
<th>Only rotate</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<span class="vertical-lr">我家没有电脑。</span>
<span class="vertical-lr">Example text</span>
</td>
<td>
<span class="vertical-lr rotated">我家没有电脑。</span>
<span class="vertical-lr rotated">Example text</span>
</td>
<td>
<span class="sideways-lr">我家没有电脑。</span>
<span class="sideways-lr">Example text</span>
</td>
<td>
<span class="only-rotate">我家没有电脑。</span>
<span class="only-rotate">Example text</span>
</td>
</tr>
</tbody>
</table>
```
#### CSS
```css
.vertical-lr {
writing-mode: vertical-lr;
}
.rotated {
transform: rotate(180deg);
}
.sideways-lr {
writing-mode: sideways-lr;
}
.only-rotate {
inline-size: fit-content;
transform: rotate(-90deg);
}
```
```css hidden
table {
border-collapse: collapse;
}
td,
th {
border: 2px black solid;
padding: 4px;
}
th {
background-color: lightgray;
}
span {
display: inline-block;
width: 1.5em;
text-align: center;
}
```
#### Result
{{EmbedLiveSample("Using_writing-mode_with_transforms", 400, 200)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- SVG [`writing-mode`](/en-US/docs/Web/SVG/Attribute/writing-mode) attribute
- {{Cssxref("direction")}}
- {{Cssxref("unicode-bidi")}}
- {{Cssxref("text-orientation")}}
- {{Cssxref("text-combine-upright")}}
- [CSS logical properties](/en-US/docs/Web/CSS/CSS_logical_properties_and_values)
- [Styling vertical text (Chinese, Japanese, Korean and Mongolian)](https://www.w3.org/International/articles/vertical-text/) on W3.org (2022)
- [CSS writing modes](/en-US/docs/Web/CSS/CSS_writing_modes) module
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/font-kerning/index.md | ---
title: font-kerning
slug: Web/CSS/font-kerning
page-type: css-property
browser-compat: css.properties.font-kerning
---
{{CSSRef}}
The **`font-kerning`** CSS property sets the use of the kerning information stored in a font.
{{EmbedInteractiveExample("pages/css/font-kerning.html")}}
_Kerning_ defines how letters are spaced. In _well-kerned_ fonts, this feature makes character spacing more uniform and pleasant to read than it would otherwise be.
In the image below, for instance, the examples on the left do not use kerning, while the ones on the right do:

## Syntax
```css
font-kerning: auto;
font-kerning: normal;
font-kerning: none;
/* Global values */
font-kerning: inherit;
font-kerning: initial;
font-kerning: revert;
font-kerning: revert-layer;
font-kerning: unset;
```
### Values
- `auto`
- : The browser determines whether font kerning should be used or not. For example, some browsers will disable kerning on small fonts, since applying it could harm the readability of text.
- `normal`
- : Font kerning information stored in the font must be applied.
- `none`
- : Font kerning information stored in the font is disabled.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Enabling and disabling kerning
#### HTML
```html
<div id="kern"></div>
<div id="nokern"></div>
<textarea id="input">AV T. ij</textarea>
```
#### CSS
```css
div {
font-size: 2rem;
font-family: serif;
}
#nokern {
font-kerning: none;
}
#kern {
font-kerning: normal;
}
```
#### JavaScript
```js
const input = document.getElementById("input");
const kern = document.getElementById("kern");
const nokern = document.getElementById("nokern");
input.addEventListener("keyup", () => {
kern.textContent = input.value; /* Update content */
nokern.textContent = input.value;
});
kern.textContent = input.value; /* Initialize content */
nokern.textContent = input.value;
```
{{ EmbedLiveSample('Enabling_and_disabling_kerning') }}
## 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("letter-spacing")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/object-position/index.md | ---
title: object-position
slug: Web/CSS/object-position
page-type: css-property
browser-compat: css.properties.object-position
---
{{CSSRef}}
The **`object-position`** [CSS](/en-US/docs/Web/CSS) property specifies the alignment of the selected [replaced element](/en-US/docs/Web/CSS/Replaced_element)'s contents within the element's box. Areas of the box which aren't covered by the replaced element's object will show the element's background.
You can adjust how the replaced element's object's intrinsic size (that is, its natural size) is adjusted to fit within the element's box using the {{cssxref("object-fit")}} property.
{{EmbedInteractiveExample("pages/css/object-position.html")}}
## Syntax
```css
/* Keyword values */
object-position: top;
object-position: bottom;
object-position: left;
object-position: right;
object-position: center;
/* <percentage> values */
object-position: 25% 75%;
/* <length> values */
object-position: 0 0;
object-position: 1cm 2cm;
object-position: 10ch 8em;
/* Edge offsets values */
object-position: bottom 10px right 20px;
object-position: right 3em bottom 10px;
object-position: top 0 right 10px;
/* Global values */
object-position: inherit;
object-position: initial;
object-position: revert;
object-position: revert-layer;
object-position: unset;
```
### Values
- {{cssxref("<position>")}}
- : From one to four values that define the 2D position of the element. Relative or absolute offsets can be used.
> **Note:** The position can be set so that the replaced element is drawn outside its box.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Positioning image content
#### HTML
Here we see HTML that includes two {{HTMLElement("img")}} elements, each displaying the MDN logo.
```html
<img id="object-position-1" src="mdn.svg" alt="MDN Logo" />
<img id="object-position-2" src="mdn.svg" alt="MDN Logo" />
```
#### CSS
The CSS includes default styling for the `<img>` element itself, as well as separate styles for each of the two images.
```css
img {
width: 300px;
height: 250px;
border: 1px solid black;
background-color: silver;
margin-right: 1em;
object-fit: none;
}
#object-position-1 {
object-position: 10px;
}
#object-position-2 {
object-position: 100% 10%;
}
```
The first image is positioned with its left edge inset 10 pixels from the left edge of the element's box. The second image is positioned with its right edge flush against the right edge of the element's box and is located 10% of the way down the height of the element's box.
#### Result
{{ EmbedLiveSample('Positioning_image_content', '100%','600px') }}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- Other image-related CSS properties: {{cssxref("object-fit")}}, {{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/object-position/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/_colon_hover/index.md | ---
title: ":hover"
slug: Web/CSS/:hover
page-type: css-pseudo-class
browser-compat: css.selectors.hover
---
{{CSSRef}}
The **`:hover`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) matches when the user interacts with an element with a pointing device, but does not necessarily activate it. It is generally triggered when the user hovers over an element with the cursor (mouse pointer).
{{EmbedInteractiveExample("pages/tabbed/pseudo-class-hover.html", "tabbed-shorter")}}
Styles defined by the `:hover` pseudo-class will be overridden by any subsequent link-related pseudo-class ({{ cssxref(":link") }}, {{ cssxref(":visited") }}, or {{ cssxref(":active") }}) that has at least equal specificity. To style links appropriately, put the `:hover` rule after the `:link` and `:visited` rules but before the `:active` one, as defined by the _LVHA-order_: `:link` — `:visited` — `:hover` — `:active`.
> **Note:** The `:hover` pseudo-class is problematic on touchscreens. Depending on the browser, the `:hover` pseudo-class might never match, match only for a moment after touching an element, or continue to match even after the user has stopped touching and until the user touches another element. Web developers should make sure that content is accessible on devices with limited or non-existent hovering capabilities.
## Syntax
```css
:hover {
/* ... */
}
```
## Examples
### Basic example
#### HTML
```html
<a href="#">Try hovering over this link.</a>
```
#### CSS
```css
a {
background-color: powderblue;
transition: background-color 0.5s;
}
a:hover {
background-color: gold;
}
```
#### Result
{{EmbedLiveSample("Basic_example")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Chromium bug #370155: Don't make `:hover` sticky on tap on sites that set a mobile viewport](https://crbug.com/370155)
- [Chromium bug #306581: Immediately show hover and active states on touch when page isn't scrollable.](https://crbug.com/306581)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_-moz-locale-dir_rtl/index.md | ---
title: ":-moz-locale-dir(rtl)"
slug: Web/CSS/:-moz-locale-dir_rtl
page-type: css-pseudo-class
status:
- non-standard
---
{{CSSRef}}{{Non-standard_header}}
The **`:-moz-locale-dir(rtl)`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) is a [Mozilla extension](/en-US/docs/Web/CSS/Mozilla_Extensions) that matches an element if the user interface is being displayed right-to-left. This is determined by the preference `intl.uidirection.locale` (where `locale` is the current locale) being set to "rtl".
> **Note:** This selector is mainly used by extensions and themes to adapt the user interface based on the user's locale. (This can vary from window to window, and even from tab to tab.) It also allows extensions to work even when they don't support the user's default locale, since they can support both left-to-right and right-to-left layouts regardless of locale specifics.
> **Warning:** This selector does not work properly from HTML; it never matches, no matter whether the UI locale is left-to-right or right-to-left.
## Syntax
```css
:-moz-locale-dir(rtl) {
/* ... */
}
```
## Examples
This example will not work if you're not using Firefox, and might not work properly even in Firefox due to an issue with using this selector in HTML.
### HTML
```html
<p>If you're using a right-to-left interface, this should be red.</p>
```
### CSS
```css
p:-moz-locale-dir(rtl) {
color: red;
}
```
### Result
{{EmbedLiveSample("Examples")}}
## Specifications
Not part of any standard.
## See also
- {{CSSxRef(":dir", ":dir(…)")}}
- {{CSSxRef(":-moz-locale-dir_ltr", ":-moz-locale-dir(ltr)")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/-webkit-text-stroke-width/index.md | ---
title: "-webkit-text-stroke-width"
slug: Web/CSS/-webkit-text-stroke-width
page-type: css-property
browser-compat: css.properties.-webkit-text-stroke-width
---
{{CSSRef}}
The **`-webkit-text-stroke-width`** [CSS](/en-US/docs/Web/CSS) property specifies the width of the stroke for text.
## Syntax
```css
/* Keyword values */
-webkit-text-stroke-width: thin;
-webkit-text-stroke-width: medium;
-webkit-text-stroke-width: thick;
/* <length> values */
-webkit-text-stroke-width: 2px;
-webkit-text-stroke-width: 0.1em;
-webkit-text-stroke-width: 1mm;
-webkit-text-stroke-width: 5pt;
/* Global values */
-webkit-text-stroke-width: inherit;
-webkit-text-stroke-width: initial;
-webkit-text-stroke-width: revert;
-webkit-text-stroke-width: revert-layer;
-webkit-text-stroke-width: unset;
```
### Values
- `<line-width>`
- : The width of the stroke.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Varying stroke widths
#### CSS
```css
p {
margin: 0;
font-size: 4em;
-webkit-text-stroke-color: red;
}
#thin {
-webkit-text-stroke-width: thin;
}
#medium {
-webkit-text-stroke-width: 3px;
}
#thick {
-webkit-text-stroke-width: 1.5mm;
}
```
#### HTML
```html
<p id="thin">Thin stroke</p>
<p id="medium">Medium stroke</p>
<p id="thick">Thick stroke</p>
```
#### Results
{{EmbedLiveSample("Varying_stroke_widths", "450px", "230px")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Surfin' Safari blog post announcing this feature](https://webkit.org/blog/85/introducing-text-stroke/)
- [CSS-Tricks article explaining this feature](https://css-tricks.com/adding-stroke-to-web-text/)
- {{cssxref("-webkit-text-stroke-color")}}
- {{cssxref("-webkit-text-stroke")}}
- {{cssxref("-webkit-text-fill-color")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/offset-rotate/index.md | ---
title: offset-rotate
slug: Web/CSS/offset-rotate
page-type: css-property
browser-compat: css.properties.offset-rotate
---
{{CSSRef}}
The **`offset-rotate`** CSS property defines the orientation/direction of the element as it is positioned along the {{cssxref("offset-path")}}.
{{EmbedInteractiveExample("pages/css/offset-rotate.html")}}
> **Note:** Early versions of the spec called this property `motion-rotation`.
## Syntax
```css
/* Follow the path direction, with optional additional angle */
offset-rotate: auto;
offset-rotate: auto 45deg;
/* Follow the path direction but facing the opposite direction of `auto` */
offset-rotate: reverse;
/* Keep a constant rotation regardless the position on the path */
offset-rotate: 90deg;
offset-rotate: 0.5turn;
/* Global values */
offset-rotate: inherit;
offset-rotate: initial;
offset-rotate: revert;
offset-rotate: revert-layer;
offset-rotate: unset;
```
- `auto`
- : The element is rotated by the angle of the direction of the {{cssxref("offset-path")}}, relative to the positive x-axis. This is the default value.
- `{{cssxref("<angle>")}}`
- : The element has a constant clockwise rotation transformation applied to it by the specified rotation angle.
- `auto <angle>`
- : If `auto` is followed by an {{cssxref("<angle>")}}, the computed value of the angle is added to the computed value of `auto`.
- `reverse`
- : The element is rotated similar to `auto`, except it faces the opposite direction. It is the same as specifying a value of `auto 180deg`.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting element orientation along its offset path
#### HTML
```html
<div></div>
<div></div>
<div></div>
```
#### CSS
```css
div {
width: 40px;
height: 40px;
background: #2bc4a2;
margin: 20px;
clip-path: polygon(0% 0%, 70% 0%, 100% 50%, 70% 100%, 0% 100%, 30% 50%);
animation: move 5000ms infinite alternate ease-in-out;
offset-path: path("M20,20 C20,50 180,-10 180,20");
}
div:nth-child(1) {
offset-rotate: auto;
}
div:nth-child(2) {
offset-rotate: auto 90deg;
}
div:nth-child(3) {
offset-rotate: 30deg;
}
@keyframes move {
100% {
offset-distance: 100%;
}
}
```
#### Result
{{EmbedLiveSample('Setting_element_orientation_along_its_offset_path', '100%', '200')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("offset")}}
- {{cssxref("offset-anchor")}}
- {{cssxref("offset-distance")}}
- {{cssxref("offset-path")}}
- {{cssxref("offset-position")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/-webkit-line-clamp/index.md | ---
title: "-webkit-line-clamp"
slug: Web/CSS/-webkit-line-clamp
page-type: css-property
browser-compat: css.properties.-webkit-line-clamp
---
{{CSSRef}}
The **`-webkit-line-clamp`** CSS property allows limiting of the contents of a {{Glossary("block")}} to the specified number of lines.
It only works in combination with the {{cssxref("display")}} property set to `-webkit-box` or `-webkit-inline-box` and the {{cssxref("box-orient", "-webkit-box-orient")}} property set to `vertical`.
In most cases you will also want to set {{cssxref("overflow")}} to `hidden`, otherwise the contents won't be clipped but an ellipsis will still be shown after the specified number of lines.
When applied to anchor elements, the truncating can happen in the middle of the text, not necessarily at the end.
> **Note:** This property was originally implemented in WebKit and has some issues. It got standardized in [CSS Overflow Module Level 4](https://drafts.csswg.org/css-overflow-4/#propdef--webkit-line-clamp) for legacy support. The [CSS Overflow Module Level 4](https://drafts.csswg.org/css-overflow-4/#propdef-line-clamp) specification also defines a {{cssxref("line-clamp")}} property, which is meant to replace this property and avoid its issues.
## Syntax
```css
/* Keyword value */
-webkit-line-clamp: none;
/* <integer> values */
-webkit-line-clamp: 3;
-webkit-line-clamp: 10;
/* Global values */
-webkit-line-clamp: inherit;
-webkit-line-clamp: initial;
-webkit-line-clamp: revert;
-webkit-line-clamp: revert-layer;
-webkit-line-clamp: unset;
```
### Values
- `none` {{experimental_inline}}
- : This value specifies that the content won't be clamped.
- {{cssxref("integer")}}
- : This value specifies the number of lines after which the content will be clamped. It must be greater than 0.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{CSSSyntax}}
## Examples
### Truncating a paragraph
#### HTML
```html
<p>
In this example the <code>-webkit-line-clamp</code> property is set to
<code>3</code>, which means the text is clamped after three lines. An ellipsis
will be shown at the point where the text is clamped.
</p>
```
#### CSS
```css
p {
width: 300px;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
}
```
#### Result
{{EmbedLiveSample("Truncating_a_paragraph", "100%", "130")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Line Clampin' (Truncating Multiple Line Text)](https://css-tricks.com/line-clampin/)
- {{cssxref("line-clamp")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/line-height/index.md | ---
title: line-height
slug: Web/CSS/line-height
page-type: css-property
browser-compat: css.properties.line-height
---
{{CSSRef}}
The **`line-height`** [CSS](/en-US/docs/Web/CSS) property sets the height of a line box. It's commonly used to set the distance between lines of text. On block-level elements, it specifies the minimum height of line boxes within the element. On non-[replaced](/en-US/docs/Web/CSS/Replaced_element) inline elements, it specifies the height that is used to calculate line box height.
{{EmbedInteractiveExample("pages/css/line-height.html")}}
## Syntax
```css
/* Keyword value */
line-height: normal;
/* Unitless values: use this number multiplied
by the element's font size */
line-height: 3.5;
/* <length> values */
line-height: 3em;
/* <percentage> values */
line-height: 34%;
/* Global values */
line-height: inherit;
line-height: initial;
line-height: revert;
line-height: revert-layer;
line-height: unset;
```
The `line-height` property is specified as any one of the following:
- a `<number>`
- a `<length>`
- a `<percentage>`
- the keyword `normal`.
### Values
- `normal`
- : Depends on the user agent. Desktop browsers (including Firefox) use a default value of roughly **`1.2`**, depending on the element's `font-family`.
- `<number>` (unitless)
- : The used value is this unitless {{cssxref("<number>")}} multiplied by the element's own font size. The computed value is the same as the specified `<number>`. In most cases, **this is the preferred way** to set `line-height` and avoid unexpected results due to inheritance.
- `<length>`
- : The specified {{cssxref("<length>")}} is used in the calculation of the line box height. Values given in **em** units may produce unexpected results (see example below).
- `<percentage>`
- : Relative to the font size of the element itself. The computed value is this {{cssxref("<percentage>")}} multiplied by the element's computed font size. **Percentage** values may produce unexpected results (see the second example below).
## Accessibility concerns
Use a minimum value of `1.5` for `line-height` for main paragraph content. This will help people experiencing low vision conditions, as well as people with cognitive concerns such as Dyslexia. If the page is zoomed to increase the text size, using a unitless value ensures that the line height will scale proportionately.
[W3C Understanding WCAG 2.1](https://www.w3.org/TR/WCAG21/#visual-presentation)
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Basic example
```css
/* All rules below have the same resultant line height */
/* number/unitless */
div {
line-height: 1.2;
font-size: 10pt;
}
/* length */
div {
line-height: 1.2em;
font-size: 10pt;
}
/* percentage */
div {
line-height: 120%;
font-size: 10pt;
}
/* font shorthand */
div {
font:
10pt/1.2 Georgia,
"Bitstream Charter",
serif;
}
```
It is often more convenient to set `line-height` by using the {{cssxref("font")}} shorthand as shown above, but this requires the `font-family` property to be specified as well.
### Prefer unitless numbers for line-height values
This example shows why it is better to use {{cssxref("<number>")}} values instead of {{cssxref("<length>")}} values. We will use two {{HTMLElement("div")}} elements. The first, with the green border, uses a unitless `line-height` value. The second, with the red border, uses a `line-height` value defined in `em`s.
#### HTML
```html
<div class="box green">
<h1>Avoid unexpected results by using unitless line-height.</h1>
Length and percentage line-heights have poor inheritance behavior.
</div>
<div class="box red">
<h1>Avoid unexpected results by using unitless line-height.</h1>
Length and percentage line-heights have poor inheritance behavior
</div>
<!-- The first <h1> line-height is calculated from its own font-size (30px × 1.1) = 33px -->
<!-- The second <h1> line-height results from the red div's font-size (15px × 1.1) = 16.5px, probably not what you want -->
```
#### CSS
```css
.green {
line-height: 1.1;
border: solid limegreen;
}
.red {
line-height: 1.1em;
border: solid red;
}
h1 {
font-size: 30px;
}
.box {
width: 18em;
display: inline-block;
vertical-align: top;
font-size: 15px;
}
```
#### Result
{{EmbedLiveSample('Prefer_unitless_numbers_for_line-height_values', 600, 200)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{Cssxref("font")}}, {{Cssxref("font-size")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/css_display/index.md | ---
title: CSS display
slug: Web/CSS/CSS_display
page-type: css-module
browser-compat: css.properties.display
---
{{CSSRef}}
The **CSS display** module defines how the CSS formatting box tree is generated from the document element tree and defines properties controlling it.
## Reference
### Properties
- {{CSSxRef("display")}}
### Data types
- {{CSSxRef("<display-outside>")}}
- {{CSSxRef("<display-inside>")}}
- {{CSSxRef("<display-listitem>")}}
- {{CSSxRef("<display-box>")}}
- {{CSSxRef("<display-internal>")}}
- {{CSSxRef("<display-legacy>")}}
## Guides
- [Using the multi-keyword syntax with CSS display](/en-US/docs/Web/CSS/display/multi-keyword_syntax_of_display)
- : Describes the multi-keyword syntax and compares this syntax with legacy single-keyword values.
### Flow layout (display: block, display: inline)
- [Block and inline layout in normal flow](/en-US/docs/Web/CSS/CSS_flow_layout/Block_and_inline_layout_in_normal_flow)
- [Flow layout and overflow](/en-US/docs/Web/CSS/CSS_flow_layout/Flow_layout_and_overflow)
- [Flow layout and writing modes](/en-US/docs/Web/CSS/CSS_flow_layout/Flow_layout_and_writing_modes)
- [Introduction to formatting contexts](/en-US/docs/Web/CSS/CSS_flow_layout/Introduction_to_formatting_contexts)
- [In flow and out of flow](/en-US/docs/Web/CSS/CSS_flow_layout/In_flow_and_out_of_flow)
### Flexible box layout
- [Basic concepts of flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox)
- [Aligning items in a flex container](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Aligning_items_in_a_flex_container)
- [Controlling ratios of flex items along the main axis](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Controlling_ratios_of_flex_items_along_the_main_axis)
- [Mastering wrapping of flex items](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Mastering_wrapping_of_flex_items)
- [Ordering flex items](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Ordering_flex_items)
- [Relationship of flexbox to other layout methods](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Relationship_of_flexbox_to_other_layout_methods)
- [Typical use cases of flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Typical_use_cases_of_flexbox)
### Grid layout
- [Basic concepts of grid layout](/en-US/docs/Web/CSS/CSS_grid_layout/Basic_concepts_of_grid_layout)
- [Relationship of grid layout to other layout methods](/en-US/docs/Web/CSS/CSS_grid_layout/Relationship_of_grid_layout_with_other_layout_methods)
- [Line-based placement](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_layout_using_line-based_placement)
- [Grid template areas](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_template_areas)
- [Layout using named grid lines](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_layout_using_named_grid_lines)
- [Auto-placement in grid layout](/en-US/docs/Web/CSS/CSS_grid_layout/Auto-placement_in_grid_layout)
- [Box alignment in grid layout](/en-US/docs/Web/CSS/CSS_grid_layout/Box_alignment_in_grid_layout)
- [Grids, logical values and writing modes](/en-US/docs/Web/CSS/CSS_grid_layout/Grids_logical_values_and_writing_modes)
- [CSS Grid Layout and accessibility](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_layout_and_accessibility)
- [CSS Grid Layout and progressive enhancement](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_layout_and_progressive_enhancement)
- [Realizing common layouts using grids](/en-US/docs/Web/CSS/CSS_grid_layout/Realizing_common_layouts_using_grids)
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [CSS flexible box layout](/en-US/docs/Web/CSS/CSS_flexible_box_layout) module
- [CSS grid layout](Web/CSS/CSS_grid_layout) module
| 0 |
data/mdn-content/files/en-us/web/css/css_display | data/mdn-content/files/en-us/web/css/css_display/block_formatting_context/index.md | ---
title: Block formatting context
slug: Web/CSS/CSS_display/Block_formatting_context
page-type: guide
spec-urls: https://drafts.csswg.org/css-display/#block-formatting-context
---
{{CSSRef}}
A **block formatting context** (BFC) is a part of a visual CSS rendering of a web page. It's the region in which the layout of block boxes occurs and in which floats interact with other elements.
A block formatting context is created by at least one of the following:
- The root element of the document (`<html>`).
- Floats (elements where {{ cssxref("float") }} isn't `none`).
- Absolutely positioned elements (elements where {{ cssxref("position") }} is `absolute` or `fixed`).
- Inline-blocks (elements with {{ cssxref("display") }}`: inline-block`).
- Table cells (elements with {{ cssxref("display") }}`: table-cell`, which is the default for HTML table cells).
- Table captions (elements with {{ cssxref("display") }}`: table-caption`, which is the default for HTML table captions).
- Anonymous table cells implicitly created by the elements with {{ cssxref("display") }}`: table`, `table-row`, `table-row-group`, `table-header-group`, `table-footer-group` (which is the default for HTML tables, table rows, table bodies, table headers, and table footers, respectively), or `inline-table`.
- Block elements where {{ cssxref("overflow") }} has a value other than `visible` and `clip`.
- {{ cssxref("display") }}`: flow-root`.
- Elements with {{ cssxref("contain") }}`: layout`, `content`, or `paint`.
- Flex items (direct children of the element with {{ cssxref("display") }}`: flex` or `inline-flex`) if they are neither [flex](/en-US/docs/Glossary/Flex_Container) nor [grid](/en-US/docs/Glossary/Grid_Container) nor [table](/en-US/docs/Web/CSS/CSS_table) containers themselves.
- Grid items (direct children of the element with {{ cssxref("display") }}`: grid` or `inline-grid`) if they are neither [flex](/en-US/docs/Glossary/Flex_Container) nor [grid](/en-US/docs/Glossary/Grid_Container) nor [table](/en-US/docs/Web/CSS/CSS_table) containers themselves.
- Multicol containers (elements where {{ cssxref("column-count") }} or {{ cssxref("column-width") }} isn't `auto`, including elements with `column-count: 1`).
- {{ cssxref("column-span") }}`: all` should always create a new formatting context, even when the `column-span: all` element isn't contained by a multicol container ([Spec change](https://github.com/w3c/csswg-drafts/commit/a8634b96900279916bd6c505fda88dda71d8ec51), [Chrome bug](https://crbug.com/709362)).
Formatting contexts affect layout, but typically, we create a new block formatting context for the positioning and clearing floats rather than changing the layout, because an element that establishes a new block formatting context will:
- contain internal floats.
- exclude external floats.
- suppress [margin collapsing](/en-US/docs/Web/CSS/CSS_box_model/Mastering_margin_collapsing).
> **Note:** A Flex/Grid container({{ cssxref("display") }}: flex/grid/inline-flex/inline-grid) establishes a new Flex/Grid formatting context, which is similar to block formatting context except layout. There's no floating children available inside a flex/grid container, but exclude external floats and suppress margin collapsing still works.
## Examples
### Contain internal floats
Make float content and alongside content the same height.
Let's have a look at a couple of these in order to see the effect creating a new BFC.
In the following example, we have a floated element inside a `<div>` with a `border` applied. The content of that `<div>` has floated alongside the floated element. As the content of the float is taller than the content alongside it, the border of the `<div>` now runs through the float. As explained in the [guide to in-flow and out of flow elements](/en-US/docs/Web/CSS/CSS_flow_layout/In_flow_and_out_of_flow), the float has been taken out of flow so the `background` and `border` of the `<div>` only contain the content and not the float.
**using `overflow: auto`**
Setting `overflow: auto` or set other values than the initial value of `overflow: visible` created a new BFC containing the float. Our `<div>` now becomes a mini-layout inside our layout. Any child element will be contained inside it.
The problem with using `overflow` to create a new BFC is that the `overflow` property is meant for telling the browser how you want to deal with overflowing content. There are some occasions in which you will find you get unwanted scrollbars or clipped shadows when you use this property purely to create a BFC. In addition, it is potentially not readable for a future developer, as it might not be obvious why you used `overflow` for this purpose. If you use `overflow`, it is a good idea to comment the code to explain.
**using `display: flow-root`**
A newer value of `display` lets us create a new BFC without any other potentially problematic side-effects. Using `display: flow-root` on the containing block creates a new BFC .
With `display: flow-root;` on the `<div>`, everything inside that container participates in the block formatting context of that container, and floats will not poke out of the bottom of the element.
The value name of `flow-root` makes sense when you understand you are creating something that acts like the `root` element (`<html>` element in browser) in terms of how it creates a new context for the flow layout inside it.
#### HTML
```html
<section>
<div class="box">
<div class="float">I am a floated box!</div>
<p>I am content inside the container.</p>
</div>
</section>
<section>
<div class="box" style="overflow:auto">
<div class="float">I am a floated box!</div>
<p>I am content inside the <code>overflow:auto</code> container.</p>
</div>
</section>
<section>
<div class="box" style="display:flow-root">
<div class="float">I am a floated box!</div>
<p>I am content inside the <code>display:flow-root</code> container.</p>
</div>
</section>
```
#### CSS
```css
section {
height: 150px;
}
.box {
background-color: rgb(224 206 247);
border: 5px solid rebeccapurple;
}
.box[style] {
background-color: aliceblue;
border: 5px solid steelblue;
}
.float {
float: left;
width: 200px;
height: 100px;
background-color: rgb(255 255 255 / 50%);
border: 1px solid black;
padding: 10px;
}
```
{{EmbedLiveSample("Contain_internal_floats", 200, 480)}}
### Exclude external floats
In the following example, we are using `display:flow-root` and floats to implement double columns layout. We are able to do this because an element in the normal flow that establishes a new BFC does not overlap the margin box of any floats in the same block formatting context as the element itself.
#### HTML
```html
<section>
<div class="float">Try to resize this outer float</div>
<div class="box"><p>Normal</p></div>
</section>
<section>
<div class="float">Try to resize this outer float</div>
<div class="box" style="display:flow-root">
<p><code>display:flow-root</code></p>
</div>
</section>
```
#### CSS
```css
section {
height: 150px;
}
.box {
background-color: rgb(224 206 247);
border: 5px solid rebeccapurple;
}
.box[style] {
background-color: aliceblue;
border: 5px solid steelblue;
}
.float {
float: left;
overflow: hidden; /* required by resize:both */
resize: both;
margin-right: 25px;
width: 200px;
height: 100px;
background-color: rgb(255 255 255 / 75%);
border: 1px solid black;
padding: 10px;
}
```
{{EmbedLiveSample("Exclude_external_floats", 200, 330)}}
Rather than inline-blocks with width:\<percentage>, in this case we don't have to specify the width of the right div.
Note that flexbox is a more efficient way to implement multi-column layout in modern CSS.
### Prevent margin collapsing
You can create a new BFC to avoid [margin collapsing](/en-US/docs/Web/CSS/CSS_box_model/Mastering_margin_collapsing) between two neighbor elements.
#### Margin collapsing example
In this example we have two adjacent {{HTMLElement("div")}} elements, which each have a vertical margin of `10px`. Because of margin collapsing, the vertical gap between them is 10 pixels, not the 20 we might expect.
```html
<div class="blue"></div>
<div class="red"></div>
```
```css
.blue,
.red {
height: 50px;
margin: 10px 0;
}
.blue {
background: blue;
}
.red {
background: red;
}
```
{{EmbedLiveSample("Margin collapsing example", 120, 170)}}
#### Preventing margin collapsing
In this example we wrap the second `<div>` in an outer one, to create a new BFC and prevent margin collapsing.
```html
<div class="blue"></div>
<div class="outer">
<div class="red"></div>
</div>
```
```css
.blue,
.red {
height: 50px;
margin: 10px 0;
}
.blue {
background: blue;
}
.red {
background: red;
}
.outer {
overflow: hidden;
background: transparent;
}
```
{{EmbedLiveSample("Preventing margin collapsing", 120, 170)}}
## Specifications
{{Specifications}}
## See also
- {{ cssxref("float") }}, {{ cssxref("clear") }}
- CSS key concepts:
- [CSS syntax](/en-US/docs/Web/CSS/Syntax)
- [At-rules](/en-US/docs/Web/CSS/At-rule)
- [Comments](/en-US/docs/Web/CSS/Comments)
- [Specificity](/en-US/docs/Web/CSS/Specificity)
- [Inheritance](/en-US/docs/Web/CSS/Inheritance)
- [Box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model)
- [Layout modes](/en-US/docs/Web/CSS/Layout_mode)
- [Visual formatting models](/en-US/docs/Web/CSS/Visual_formatting_model)
- [Margin collapsing](/en-US/docs/Web/CSS/CSS_box_model/Mastering_margin_collapsing)
- Values
- [Initial values](/en-US/docs/Web/CSS/initial_value)
- [Computed values](/en-US/docs/Web/CSS/computed_value)
- [Used values](/en-US/docs/Web/CSS/used_value)
- [Actual values](/en-US/docs/Web/CSS/actual_value)
- [Value definition syntax](/en-US/docs/Web/CSS/Value_definition_syntax)
- [Shorthand properties](/en-US/docs/Web/CSS/Shorthand_properties)
- [Replaced elements](/en-US/docs/Web/CSS/Replaced_element)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_link/index.md | ---
title: ":link"
slug: Web/CSS/:link
page-type: css-pseudo-class
browser-compat: css.selectors.link
---
{{CSSRef}}
The **`:link`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents an element that has not yet been visited. It matches every unvisited {{HTMLElement("a")}} or {{HTMLElement("area")}} element that has an `href` attribute.
{{EmbedInteractiveExample("pages/tabbed/pseudo-class-link.html", "tabbed-shorter")}}
Styles defined by the `:link` and [`:visited`](/en-US/docs/Web/CSS/:visited) pseudo-classes can be overridden by any subsequent user-action pseudo-classes ({{cssxref(":hover")}} or {{cssxref(":active")}}) that have at least equal specificity. To style links appropriately, put the `:link` rule before all other link-related rules, as defined by the _LVHA-order_: `:link` — `:visited` — `:hover` — `:active`. The `:visited` pseudo-class and `:link` pseudo-class are mutually exclusive.
> **Note:** Use {{cssxref(":any-link")}} to select an element independent of whether it has been visited or not.
## Syntax
```css
:link {
/* ... */
}
```
## Examples
By default, most browsers apply a special {{cssxref("color")}} value to visited links. Thus, the links in this example will probably have special font colors only before you visit them. (After that, you'll need to clear your browser history to see them again.) However, the {{cssxref("background-color")}} values are likely to remain, as most browsers do not set that property on visited links by default.
### HTML
```html
<a href="#ordinary-target">This is an ordinary link.</a><br />
<a href="">You've already visited this link.</a><br />
<a>Placeholder link (won't get styled)</a>
```
### CSS
```css
a:link {
background-color: gold;
color: green;
}
```
### Result
{{EmbedLiveSample("Examples")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- Link-related pseudo-classes: {{ cssxref(":visited") }}, {{ cssxref(":hover") }}, {{ cssxref(":active") }}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/tutorials/index.md | ---
title: CSS Tutorials
slug: Web/CSS/Tutorials
page-type: landing-page
---
{{CSSRef}}
Learning CSS may be a daunting task.
In order to help you, we have written numerous **tutorials about CSS**.
Some are aimed at complete beginners, while others present complex features to be used by more experienced users.
This page lists them all, with a short description.
They are grouped by complexity so that you can choose the most appropriate for your level.
## Beginner-level CSS tutorials
- [CSS basics](/en-US/docs/Learn/Getting_started_with_the_web/CSS_basics)
- : This guide is aimed at complete beginners: You haven't written one single line of CSS? — this is for you.
It explains the fundamental concepts of the language and guides you in writing basic stylesheets.
- [Using multiple backgrounds](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders/Using_multiple_backgrounds)
- : Backgrounds are fundamental for nice styling: CSS allows you to set several of them on each box. This tutorial explains how they interact and how to achieve nice effects.
- [Resizing background images](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders/Resizing_background_images)
- : CSS allows you to resize images used as an element's background.
This tutorial describes how to achieve this in a simple way.
- [Using media queries](/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries)
- : The size of the screens, or the kind of devices like touchscreens or printed sheets vary greatly nowadays.
Media queries are the fundamental building blocks in building websites that render everywhere in their best quality.
- [Understanding CSS z-index](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index)
- : Controlling superposition of boxes is a basic feature that is very quickly needed by Web developers.
Though not that difficult, it requires a basic knowledge of CSS.
## Intermediate-level CSS tutorials
After the release of CSS 2 (Level 1), new features have been added to CSS.
Some of them are _fancy_ and are pretty self-contained.
They are easy to use for anybody with a fair knowledge of basic concepts.
- [CSS Counter Styles](/en-US/docs/Web/API/CSS_Counter_Styles)
- : Counting items and pages is an easy task in CSS. Learn to use {{cssxref("counter-reset")}}, {{cssxref("counter-increment")}}, {{cssxref("counters", "counters()")}}, and {{cssxref("counter", "counter()")}}.
- [CSS Animations](/en-US/docs/Web/CSS/CSS_animations/Using_CSS_animations)
- : CSS Animations allow you to define configurations of style, as [keyframes](/en-US/docs/Web/CSS/@keyframes), and to transition between them defining an animation.
- [CSS Transitions](/en-US/docs/Web/CSS/CSS_transitions/Using_CSS_transitions)
- : CSS Transitions allow you to define an animation between several styles and to control the way this transition happens.
- [CSS Transforms](/en-US/docs/Web/CSS/CSS_transforms/Using_CSS_transforms)
- : Transforms allow you to change the position of elements by modifying their coordinate space: it allows for translating, rotating, and deforming them in the 2D or 3D spaces.
- [CSS Gradients](/en-US/docs/Web/CSS/CSS_images/Using_CSS_gradients)
- : Gradients are images that transition smoothly from one color to another.
There are several types of gradients allowed in CSS: linear or radial, repeating or not.
This tutorial describes how to use them.
## Advanced-level CSS tutorials
CSS also got new features allowing you to create complex layouts.
Though the simplest way to achieve such layout, they are more complex to use for people without too much experience.
- [CSS multi-column layouts](/en-US/docs/Web/CSS/CSS_multicol_layout)
- : CSS3 introduces a new layout allowing you to easily define multiple columns in an element.
Though multi-column text is not that common on devices like screens, this is particularly useful on printed pages, or for indexes.
- [CSS flexible boxes layouts](/en-US/docs/Web/CSS/CSS_flexible_box_layout)
- : This new layout allow you to give boxes flexibility, allowing them to be resized smoothly.
It is a powerful way to describe complex interfaces.
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/border-start-end-radius/index.md | ---
title: border-start-end-radius
slug: Web/CSS/border-start-end-radius
page-type: css-property
browser-compat: css.properties.border-start-end-radius
---
{{CSSRef}}
The **`border-start-end-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-start-end-radius.html")}}
This property affects the corner between the block-start and the inline-end sides of the element. For instance, in a `horizontal-tb` writing mode with `ltr` direction, it corresponds to the {{CSSxRef("border-top-right-radius")}} property.
## Syntax
```css
/* <length> values */
/* With one value the corner will be a circle */
border-start-end-radius: 10px;
border-start-end-radius: 1em;
/* With two values the corner will be an ellipse */
border-start-end-radius: 1em 2em;
/* Global values */
border-start-end-radius: inherit;
border-start-end-radius: initial;
border-start-end-radius: revert;
border-start-end-radius: revert-layer;
border-start-end-radius: unset;
```
### Values
- `<length-percentage>`
- : Denotes the size of the circle radius or the semi-major and semi-minor axes of the ellipse. As absolute length it can be expressed in any unit allowed by the CSS {{cssxref("<length>")}} data type. Percentages for the horizontal axis refer to the width of the box, percentages for the vertical axis refer to the height of the box. Negative values are invalid.
## Formal definition
{{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-end-radius: 10px;
}
.exampleText {
writing-mode: vertical-rl;
padding: 10px;
background-color: #fff;
border-start-end-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-bottom-left-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/content-visibility/index.md | ---
title: content-visibility
slug: Web/CSS/content-visibility
page-type: css-property
status:
- experimental
browser-compat: css.properties.content-visibility
---
{{CSSRef}}{{SeeCompatTable}}
The **`content-visibility`** [CSS](/en-US/docs/Web/CSS) property controls whether or not an element renders its contents at all, along with forcing a strong set of containments, allowing user agents to potentially omit large swathes of layout and rendering work until it becomes needed. It enables the user agent to skip an element's rendering work (including layout and painting) until it is needed — which makes the initial page load much faster.
> **Note:** The {{domxref("element/contentvisibilityautostatechange_event", "contentvisibilityautostatechange")}} event fires on any element with `content-visibility: auto` set on it when its rendering work starts or stops being skipped. This provides a convenient way for an app's code to start or stop rendering processes (e.g. drawing on a {{htmlelement("canvas")}}) when they are not needed, thereby conserving processing power.
{{EmbedInteractiveExample("pages/css/content-visibility.html")}}
## Syntax
```css
/* Keyword values */
content-visibility: visible;
content-visibility: hidden;
content-visibility: auto;
/* Global values */
content-visibility: inherit;
content-visibility: initial;
content-visibility: revert;
content-visibility: revert-layer;
content-visibility: unset;
```
### Values
- `visible`
- : No effect. The element's contents are laid out and rendered as normal.
- `hidden`
- : The element [skips its contents](/en-US/docs/Web/CSS/CSS_containment#skips_its_contents). The skipped contents must not be accessible to user-agent features, such as find-in-page, tab-order navigation, etc., nor be selectable or focusable. This is similar to giving the contents `display: none`.
- `auto`
- : The element turns on layout containment, style containment, and paint containment. If the element is not [relevant to the user](/en-US/docs/Web/CSS/CSS_containment#relevant_to_the_user), it also skips its contents. Unlike hidden, the skipped contents must still be available as normal to user-agent features such as find-in-page, tab order navigation, etc., and must be focusable and selectable as normal.
## Description
### Animating and transitioning content-visibility
[Supporting browsers](#browser_compatibility) animate/transition `content-visibility` with a variation on the [discrete animation type](/en-US/docs/Web/CSS/CSS_animated_properties#discrete).
Discrete animation generally means that the property will flip between two values 50% of the way through the animation. In the case of `content-visibility`, however, the browser will flip between the two values to show the animated content for the entire animation duration. So, for example:
- When animating `content-visibility` from `hidden` to `visible`, the value will flip to `visible` at `0%` of the animation duration so it is visible throughout.
- When animating `content-visibility` from `visible` to `hidden`, the value will flip to `hidden` at `100%` of the animation duration so it is visible throughout.
This behavior is useful for creating entry/exit animations where you want to, for example, remove some content from the DOM with `content-visibility: hidden`, but you want a smooth transition (such as a fade-out) rather than it disappearing immediately.
When animating `content-visibility` with [CSS transitions](/en-US/docs/Web/CSS/CSS_transitions), [`transition-behavior: allow-discrete`](/en-US/docs/Web/CSS/transition-behavior) needs to be set on `content-visibility`. This effectively enables `content-visibility` transitions.
> **Note:** When transitioning an element's `content-visibility` value, you don't need to provide a set of starting values for transitioned properties using a [`@starting-style`](/en-US/docs/Web/CSS/@starting-style) block, like you do when [transitioning `display`](/en-US/docs/Web/CSS/display#animating_display). This is because `content-visibility` doesn't hide an element from the DOM like `display` does: it just skips rendering the element's content.
## Formal definition
{{cssinfo}}
## Formal syntax
{{CSSSyntax}}
## Accessibility concerns
Off-screen content within a `content-visibility: auto` property remains in the document object model and the accessibility tree. This allows improving page performance with `content-visibility: auto` without negatively impacting accessibility.
Since styles for off-screen content are not rendered, elements intentionally hidden with `display: none` or `visibility: hidden` _will still appear in the accessibility tree_.
If you don't want an element to appear in the accessibility tree, use `aria-hidden="true"`.
## Examples
### Using auto to reduce rendering cost of long pages
The following example shows the use of `content-visibility: auto` to skip painting and rendering of off-screen sections.
When a `section` is out of the viewport then the painting of the content is skipped until the section comes close to the viewport, this helps with both load and interactions on the page.
#### HTML
```html
<section>
<!-- Content for each section… -->
</section>
<section>
<!-- Content for each section… -->
</section>
<section>
<!-- Content for each section… -->
</section>
<!-- … -->
```
#### CSS
The `contain-intrinsic-size` property adds a default size of 500px to the height and width of each `section` element. After a section is rendered, it will retain its rendered intrinsic size, even when it is scrolled out of the viewport.
```css
section {
content-visibility: auto;
contain-intrinsic-size: auto 500px;
}
```
### Using hidden to manage visibility
The following example shows how to manage content visibility with JavaScript.
Using `content-visibility: hidden;` instead of `display: none;` preserves the rendering state of content when hidden and rendering is faster.
#### HTML
```html
<div class="hidden">
<button class="toggle">Show</button>
<p>
This content is initially hidden and can be shown by clicking the button.
</p>
</div>
<div class="visible">
<button class="toggle">Hide</button>
<p>
This content is initially visible and can be hidden by clicking the button.
</p>
</div>
```
#### CSS
The `content-visibility` property is set on paragraphs that are direct children of elements with the `visible` and `hidden` classes. In our example, we can show and hide content in paragraphs depending on the CSS class of parent div elements.
The `contain-intrinsic-size` property is included to represent the content size. This helps to reduce layout shift when content is hidden.
```css
p {
contain-intrinsic-size: 0 1.1em;
border: dotted 2px;
}
.hidden > p {
content-visibility: hidden;
}
.visible > p {
content-visibility: visible;
}
```
#### JavaScript
```js
const handleClick = (event) => {
const button = event.target;
const div = button.parentElement;
button.textContent = div.classList.contains("visible") ? "Show" : "Hide";
div.classList.toggle("hidden");
div.classList.toggle("visible");
};
document.querySelectorAll("button.toggle").forEach((button) => {
button.addEventListener("click", handleClick);
});
```
#### Result
{{ EmbedLiveSample('Using hidden to manually manage visibility') }}
### Animating content-visibility
In this example, we have a {{htmlelement("div")}} element, the content of which can be toggled between shown and hidden by clicking or pressing any key.
#### HTML
```html
<p>
Click anywhere on the screen or press any key to toggle the
<code><div></code> content between hidden and showing.
</p>
<div>
This is a <code><div></code> element that animates between
<code>content-visibility: hidden;</code>and
<code>content-visibility: visible;</code>. We've also animated the text color
to create a smooth animation effect.
</div>
```
#### CSS
In the CSS we initially set `content-visibility: hidden;` on the `<div>` to hide its content. We then set up `@keyframe` animations and attach them to classes to show and hide the `<div>`, animating `content-visibility` and [`color`](/en-US/docs/Web/CSS/color) so that you get a smooth animation effect as the content is shown/hidden.
```css
div {
font-size: 1.6rem;
padding: 20px;
border: 3px solid red;
border-radius: 20px;
width: 480px;
content-visibility: hidden;
}
/* Animation classes */
.show {
animation: show 0.7s ease-in forwards;
}
.hide {
animation: hide 0.7s ease-out forwards;
}
/* Animation keyframes */
@keyframes show {
0% {
content-visibility: hidden;
color: rgb(0 0 0 / 0%);
}
100% {
content-visibility: visible;
color: rgb(0 0 0 / 100%);
}
}
@keyframes hide {
0% {
content-visibility: visible;
color: rgb(0 0 0 / 100%);
}
100% {
content-visibility: hidden;
color: rgb(0 0 0 / 0%);
}
}
```
#### JavaScript
Finally, we use JavaScript to apply the `.show` and `.hide` classes to the `<div>` as appropriate to apply the animations as it is toggled between shown and hidden states.
```js
const divElem = document.querySelector("div");
const htmlElem = document.querySelector(":root");
htmlElem.addEventListener("click", showHide);
document.addEventListener("keydown", showHide);
function showHide() {
if (divElem.classList[0] === "show") {
divElem.classList.remove("show");
divElem.classList.add("hide");
} else {
divElem.classList.remove("hide");
divElem.classList.add("show");
}
}
```
#### Result
The rendered result looks like this:
{{ EmbedLiveSample("Animating content-visibility", "100%", "300") }}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [CSS Containment](/en-US/docs/Web/CSS/CSS_containment)
- [`contain-intrinsic-size`](/en-US/docs/Web/CSS/contain-intrinsic-size)
- {{domxref("element/contentvisibilityautostatechange_event", "contentvisibilityautostatechange")}}
- [content-visibility: the new CSS property that boosts your rendering performance](https://web.dev/articles/content-visibility) (web.dev)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/transform/index.md | ---
title: transform
slug: Web/CSS/transform
page-type: css-property
browser-compat: css.properties.transform
---
{{CSSRef}}
The **`transform`** [CSS](/en-US/docs/Web/CSS) property lets you rotate, scale, skew, or translate an element.
It modifies the coordinate space of the CSS [visual formatting model](/en-US/docs/Web/CSS/Visual_formatting_model).
{{EmbedInteractiveExample("pages/css/transform.html")}}
If the property has a value different than `none`, a [stacking context](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context) will be created.
In that case, the element will act as a [containing block](/en-US/docs/Web/CSS/Containing_block) for any `position: fixed;` or `position: absolute;` elements that it contains.
> **Warning:** Only transformable elements can be `transform`ed.
> That is, all elements whose layout is governed by the CSS box model except for: [non-replaced inline boxes](/en-US/docs/Glossary/Inline-level_content), [table-column boxes](/en-US/docs/Web/HTML/Element/col), and [table-column-group boxes](/en-US/docs/Web/HTML/Element/colgroup).
## Syntax
```css
/* Keyword values */
transform: none;
/* Function values */
transform: matrix(1, 2, 3, 4, 5, 6);
transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
transform: perspective(17px);
transform: rotate(0.5turn);
transform: rotate3d(1, 2, 3, 10deg);
transform: rotateX(10deg);
transform: rotateY(10deg);
transform: rotateZ(10deg);
transform: translate(12px, 50%);
transform: translate3d(12px, 50%, 3em);
transform: translateX(2em);
transform: translateY(3in);
transform: translateZ(2px);
transform: scale(2, 0.5);
transform: scale3d(2.5, 1.2, 0.3);
transform: scaleX(2);
transform: scaleY(0.5);
transform: scaleZ(0.3);
transform: skew(30deg, 20deg);
transform: skewX(30deg);
transform: skewY(1.07rad);
/* Multiple function values */
transform: translateX(10px) rotate(10deg) translateY(5px);
transform: perspective(500px) translate(10px, 0, 20px) rotateY(3deg);
/* Global values */
transform: inherit;
transform: initial;
transform: revert;
transform: revert-layer;
transform: unset;
```
The `transform` property may be specified as either the keyword value `none` or as one or more `<transform-function>` values.
### Values
- {{cssxref("<transform-function>")}}
- : One or more of the [CSS transform functions](/en-US/docs/Web/CSS/transform-function) to be applied.
The transform functions are multiplied in order from left to right, meaning that composite transforms are effectively [applied in order from right to left](#transform_order).
- `none`
- : Specifies that no transform should be applied.
## Accessibility concerns
Scaling/zooming animations are problematic for accessibility, as they are a common trigger for certain types of migraine.
If you need to include such animations on your website, you should provide a control to allow users to turn off animations, preferably site-wide.
Also, consider making use of the {{cssxref("@media/prefers-reduced-motion", "prefers-reduced-motion")}} media feature — use it to write a [media query](/en-US/docs/Web/CSS/CSS_media_queries) that will turn off animations if the user has reduced animation specified in their system preferences.
Find out more:
- [MDN Understanding WCAG, Guideline 2.3 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Operable#guideline_2.3_—_seizures_and_physical_reactions_do_not_design_content_in_a_way_that_is_known_to_cause_seizures_or_physical_reactions)
- [Understanding Success Criterion 2.3.3 | W3C Understanding WCAG 2.1](https://www.w3.org/WAI/WCAG21/Understanding/animation-from-interactions)
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Translating and rotating an element
#### HTML
```html
<div>Transformed element</div>
```
#### CSS
```css
div {
border: solid red;
transform: translate(30px, 20px) rotate(20deg);
width: 140px;
height: 60px;
}
```
#### Result
{{EmbedLiveSample("Translating_and_rotating_an_element", "400", "160")}}
### Transform order
The order of transform functions matters. In this example, two boxes are rotated and translated by the same values; only the transform function order is different.
#### HTML
```html
<div class="original"></div>
<div class="one">1</div>
<div class="two">2</div>
```
#### CSS
```css hidden
div {
height: 200px;
width: 200px;
position: absolute;
left: 200px;
top: 50px;
font-size: 4rem;
line-height: 200px;
text-align: center;
}
.original {
border: 1px dashed;
}
.original:before,
.original:after {
content: "";
position: absolute;
top: 100px;
width: 500px;
left: -150px;
height: 1px;
border-top: 2px dotted;
}
.original:after {
transform: rotate(135deg);
}
.one {
background-color: #ccc;
}
.two {
background-color: #d6bb72;
}
```
```css
.one {
transform: translateX(200px) rotate(135deg);
}
.two {
transform: rotate(135deg) translateX(200px);
}
```
#### Result
{{EmbedLiveSample("Transform_order", "400", "460")}}
When an element is rotated before being translated, the translate direction is on the rotated axis. The axis as indicated with the dotted lines.
### More examples
Please see [Using CSS transforms](/en-US/docs/Web/CSS/CSS_transforms/Using_CSS_transforms) and {{cssxref("<transform-function>")}} for more examples.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Using CSS transforms](/en-US/docs/Web/CSS/CSS_transforms/Using_CSS_transforms)
- {{cssxref("<transform-function>")}} data type with all the transform functions explained.
- Individual CSS properties: {{cssxref('translate')}}, {{cssxref('rotate')}}, and {{cssxref('scale')}} (there is no `skew` property).
- Online tool to visualize CSS Transform functions: [CSS Transform Playground](https://css-transform.moro.es/)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/container-name/index.md | ---
title: container-name
slug: Web/CSS/container-name
page-type: css-property
browser-compat: css.properties.container-name
---
{{CSSRef}}
The **container-name** [CSS](/en-US/docs/Web/CSS) property specifies a list of query container names used by the [@container](/en-US/docs/Web/CSS/@container) at-rule in a [container query](/en-US/docs/Web/CSS/CSS_containment/Container_queries).
A container query will apply styles to elements based on the size of the nearest ancestor with a containment context.
When a containment context is given a name, it can be specifically targeted using the {{Cssxref("@container")}} at-rule instead of the nearest ancestor with containment.
> **Note:** When using the {{cssxref("container-type")}} and `container-name` properties, the `style` and `layout` values of the {{cssxref("contain")}} property are automatically applied.
## Syntax
```css
/* A single name */
container-name: myLayout;
/* Multiple names */
container-name: myPageLayout myComponentLibrary;
/* Global Values */
container-name: inherit;
container-name: initial;
container-name: revert;
container-name: revert-layer;
container-name: unset;
```
### Values
- `<container-name>`
- : A case-sensitive string that is used to identify the container.
The following conditions apply:
- The name can be any valid {{cssxref("custom-ident")}}, but must not equal `default`.
- The name value must not be in quotes.
- The dashed ident intended to denote author-defined identifiers (e.g., `--container-name`) is permitted.
- A list of multiple names separated by a space is allowed.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{CSSSyntax}}
## Examples
### Using a container name
Given the following HTML example which is a card component with a title and some text:
```html
<div class="card">
<div class="post-meta">
<h2>Card title</h2>
<p>My post details.</p>
</div>
<div class="post-excerpt">
<p>
A preview of my <a href="https://example.com">blog post</a> about cats.
</p>
</div>
</div>
```
To create a containment context, add the `container-type` property to an element in CSS.
The following example creates two containment contexts, one for the card meta information and one for the post excerpt:
> **Note:** A shorthand syntax for these declarations are described in the {{cssxref("container")}} page.
```css
.post-meta {
container-type: inline-size;
}
.post-excerpt {
container-type: inline-size;
container-name: excerpt;
}
```
Writing a container query via the {{Cssxref("@container")}} at-rule will apply styles to the elements of the container when the query evaluates to true.
The following example has two container queries, one that will apply only to the contents of the `.post-excerpt` element and one that will apply to both the `.post-meta` and `.post-excerpt` contents:
```css
@container excerpt (min-width: 400px) {
p {
visibility: hidden;
}
}
@container (min-width: 400px) {
p {
font-size: 2rem;
}
}
```
For more information on writing container queries, see the [CSS Container Queries](/en-US/docs/Web/CSS/CSS_containment/Container_queries) page.
### Using multiple container names
You can also provide multiple names to a container context separated by a space:
```css
.post-meta {
container-type: inline-size;
container-name: meta card;
}
```
This will allow you to target the container using either name in the {{cssxref("@container")}} at-rule.
This is useful if you want to target the same container with multiple container queries where either condition could be true:
```css
@container meta (max-width: 500px) {
p {
visibility: hidden;
}
}
@container card (max-height: 200px) {
h2 {
font-size: 1.5em;
}
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [CSS container queries](/en-US/docs/Web/CSS/CSS_containment/Container_queries)
- [Using container size and style queries](/en-US/docs/Web/CSS/CSS_containment/Container_size_and_style_queries)
- {{Cssxref("@container")}} at-rule
- CSS {{Cssxref("container")}} shorthand property
- CSS {{Cssxref("container-type")}} property
- CSS {{cssxref("content-visibility")}} property
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/namespace_separator/index.md | ---
title: Namespace separator
slug: Web/CSS/Namespace_separator
page-type: css-combinator
browser-compat: css.selectors.namespace
---
{{CSSRef}}
The **namespace separator** (`|`) separates the selector from the namespace, identifying the {{glossary("namespace")}}, or lack thereof, for a type selector.
```css
/* Links in the namespace named myNameSpace */
myNameSpace|a {
font-weight: bold;
}
/* paragraphs in any namespace (including no namespace) */
*|p {
color: darkblue;
}
/* heading level 2 not in a namespace */
|h2 {
margin-bottom: 0;
}
```
[Type selectors](/en-US/docs/Web/CSS/Type_selectors) and the [universal selector](/en-US/docs/Web/CSS/Universal_selectors) allow an optional namespace component. When a namespace has been previously declared via {{CSSXref("@namespace")}}, these selectors can be namespaced by prepending the selector with the name of the namespace separated by the namespace separator (`|`). This is useful when dealing with documents containing multiple namespaces such as HTML with inline SVG or MathML, or XML that mixes multiple vocabularies.
- `ns|h1` - matches `<h1>` elements in namespace `ns`
- `*|h1` - matches all `<h1>` elements
- `|h1` - matches all `<h1>` elements outside of any declared or implied namespace
## Syntax
```css
namespace|element { style properties }
```
## Examples
By default, all elements in an HTML or SVG element have a namespace as the `http://www.w3.org/1999/xhtml` and `http://www.w3.org/2000/svg` namespace are implied. The {{domxref("document.createElementNS")}} method, with an empty string for the namespace parameter, can be used to create elements with no namespace.
### Named namespace example
In this example, all elements are in a namespace.
#### HTML
No namespaces are explicitly declared in the HTML or within the SVG.
```html
<p>This paragraph <a href="#">has a link</a>.</p>
<svg width="400" viewBox="0 0 400 20">
<a href="#">
<text x="0" y="15">Link created in SVG</text>
</a>
</svg>
```
#### CSS
The CSS declares two namespaces, then assigns styles to links globally (`a`), to links in no namespace (`|a`), to links in any namespace or no namespace (`*|a`), and then to two different named namespaces (`svgNamespace|a` and `htmlNameSpace|a`).
```css
@namespace svgNamespace url("http://www.w3.org/2000/svg");
@namespace htmlNameSpace url("http://www.w3.org/1999/xhtml");
/* All `<a>`s in the default namespace, in this case, all `<a>`s */
a {
font-size: 1.4rem;
}
/* no namespace */
|a {
text-decoration: wavy overline lime;
font-weight: bold;
}
/* all namespaces (including no namespace) */
*|a {
color: red;
fill: red;
font-style: italic;
}
/* only the svgNamespace namespace, which is <svg> content */
svgNamespace|a {
color: green;
fill: green;
}
/* The htmlNameSpace namespace, which is the HTML document */
htmlNameSpace|a {
text-decoration-line: line-through;
}
```
#### Result
{{EmbedLiveSample("Named_namespace_example", "100%", 100)}}
The selector `|a`, a link not in a namespace, doesn't match any links. In HTML, the `http://www.w3.org/1999/xhtml` is implied, meaning all HTML is in a namespace, even if none is explicitly declared. In SVG, even if not explicitly set, the `http://www.w3.org/2000/svg` namespace is also implied. This means all the content is within at least one namespace.
### Default namespace and no namespace
In this example, we use JavaScript to create an element without a namespace and append it to the document. We set the SVG namespace to be the default namespace by defining the unnamed namespace with `@namespace`.
> **Note:** If a default, or unnamed, namespace is defined, universal and type selectors apply only to elements in that namespace.
#### HTML
No namespaces are explicitly declared in the HTML or within the SVG.
```html
<p><a href="#">A link</a> in the implied HTML namespace.</p>
<svg width="400" viewBox="0 0 400 20">
<a href="#">
<text x="0" y="15">Link created in SVG namespace</text>
</a>
</svg>
```
#### JavaScript
With JavaScript, with {{DOMXRef("document.createElementNS")}}, we create an anchor link without a namespace, then append the link.
```js
// create 'no namespace' anchor
const a = document.createElementNS("", "a");
a.href = "#";
a.appendChild(document.createTextNode("Link created without a namespace"));
document.body.appendChild(a);
```
#### CSS
We declare a namespace with {{cssxref("@namespace")}}. By omitting the name for the namespace, the `@namespace` declaration creates a default namespace.
```css
/* By omitting a name, this sets SVG as the default namespace */
@namespace url("http://www.w3.org/2000/svg");
/* `<a>` in the default (set to SVG) namespace */
a {
font-size: 1.4rem;
}
/* `<svg>` and `<p>` in the default (set to SVG) namespace */
svg,
p {
border: 5px solid gold;
}
/* links outside of any namespace */
|a {
text-decoration: wavy underline purple;
font-weight: bold;
}
/* links with any namespace or no namespace */
*|a {
font-style: italic;
color: magenta;
fill: magenta;
}
```
#### Result
{{EmbedLiveSample("Default_namespace_and_no_namespace", "100%", 100)}}
The selector with no namespace separator, the `a`, matched only the SVG `<a>` elements, as SVG was set as the default namespace.
The selector with no namespace, the `|a`, matched the JavaScript defined and appended `<a>`, as that node is the only node that doesn't have a default namespace.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [`@namespace`](/en-US/docs/Web/CSS/@namespace)
- [`Document.createElementNS()`](/en-US/docs/Web/API/Document/createElementNS) method
- [`Element.namespaceURI`](/en-US/docs/Web/API/Element/namespaceURI) property
- [CSS type selector](/en-US/docs/Web/CSS/Type_selectors)
- [CSS universal selector](/en-US/docs/Web/CSS/Universal_selectors)
- [CSS selector module](/en-US/docs/Web/CSS/CSS_selectors)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/calc-constant/index.md | ---
title: <calc-constant>
slug: Web/CSS/calc-constant
page-type: css-type
browser-compat: css.types.calc-constant
---
{{CSSRef}}
The **`<calc-constant>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) represents well-defined constants such as `e` and `pi`. Rather than require authors to manually type out several digits of these mathematical constants or calculate them, a few of them are provided directly by CSS for convenience.
## Syntax
The `<calc-constant>` type defines numeric constants that can be used in [CSS math functions](/en-US/docs/Web/CSS/CSS_Functions#math_functions).
### Values
- `e`
- : The base of the natural logarithm, approximately equal to `2.7182818284590452354`.
- `pi`
- : The ratio of a circle's circumference to its diameter, approximately equal to `3.1415926535897932`.
- `infinity` & `-infinity`
- : An infinite value, used to indicate the largest/smallest possible value.
- `NaN`
- : A value representing "Not a Number" canonical casing.
### Notes
Serializing the arguments inside [`calc()`](/en-US/docs/Web/CSS/calc) follows the IEEE-754 standard for floating point math which means there's a few cases to be aware of regarding constants like `infinity` and `NaN`:
- Dividing by zero will return positive or negative `infinity` depending on the sign of the numerator.
- Adding, subtracting or multiplying `infinity` to anything will return `infinity` unless it produces `NaN` (see below).
- Any operation with at least one `NaN` argument will return `NaN`.
This means `0 / 0`, `infinity / infinity`, `0 * infinity`, `infinity + (-infinity)`, and `infinity - infinity` will all return `NaN`.
- Positive and negative zero are possible values (`0⁺` and `0⁻`).
This has the following effects:
- Multiplication or division that produces zero with exactly one negative argument (`-5 * 0` or `1 / (-infinity)`) or negative result from combinations in the other math functions will return `0⁻`.
- `0⁻ + 0⁻` or `0⁻ - 0` will return `0⁻`.
All other additions or subtractions that would produce a zero will return `0⁺`.
- Multiplying or dividing `0⁻` with a positive number (including `0⁺`) will return a negative result (either `0⁻` or `-infinity`), while multiplying or dividing `0⁻` with a negative number will return a positive result.
Examples of how these rules apply are shown in the [Infinity, NaN, and division by zero](#infinity_nan_and_division_by_zero) section.
> **Note:** It's rare to need to use `infinity` as an argument in `calc()`, but it can be used to avoid hardcoded "magic numbers" or making sure a certain value is always larger than another value.
> It may be useful if you need to make it obvious that a property has "the largest possible value" for that data type.
### Formal syntax
{{CSSSyntax}}
## Description
Mathematical constants can only be used inside [CSS math functions](/en-US/docs/Web/CSS/CSS_Functions#math_functions) for calculations. Math constants are not CSS keywords, but if they are used outside of a calculation, they're treated like any other keyword.
For example:
- `animation-name: pi;` refers to an animation named "pi", not the `pi` numeric constant.
- `line-height: e;` is invalid, but `line-height: calc(e);` is valid.
- `rotate(1rad * pi);` won't work because {{CSSxRef("transform-function/rotate", "rotate()")}} is not a math function. Use `rotate(calc(1rad * pi));`
In math functions, `<calc-constant>` values are evaluated as {{CSSxRef("number")}} values, therefore `e` and `pi` act as numeric constants.
Both `infinity` and `NaN` are slightly different, they are considered as degenerate numeric constants.
While not technically numbers, they act as {{CSSxRef("number")}} values, so to get an infinite {{CSSxRef("length")}}, for example, requires an expression like `calc(infinity * 1px)`.
The `infinity` and `NaN` values are included mostly to make serialization simpler and more obvious, but can be used to indicate a "largest possible value", since an infinite value is clamped to the allowed range.
It's rare for this to be reasonable, but when using infinity its much simpler than just putting an enormous number in a stylesheet or hardcoding magic numbers.
All constants are case-insensitive except for `NaN`, which makes `calc(Pi)`, `calc(E)` and `calc(InFiNiTy)` valid:
```plain example-good
e
-e
E
pi
-pi
Pi
infinity
-infinity
InFiNiTy
NaN
```
The following are all invalid:
```plain example-bad
nan
Nan
NAN
```
## Examples
### Using e and pi in `calc()`
The following example shows how to use `e` inside `calc()` to rotate an element with an exponentially-increasing angle.
The second box shows how to use `pi` inside a [`sin()`](/en-US/docs/Web/CSS/sin) function.
```css hidden
#wrapper {
display: flex;
flex-direction: row;
justify-content: space-evenly;
}
.container {
display: flex;
flex-direction: column;
align-items: left;
width: 200px;
}
.container > div {
width: 100px;
height: 100px;
margin: 10px;
}
span {
font-family: monospace;
font-size: 0.8em;
}
#e {
background-color: blue;
}
#pi {
background-color: blue;
}
```
```html
<div id="wrapper">
<div class="container">
<div id="e"></div>
<input type="range" min="0" max="7" step="0.01" value="0" id="e-slider" />
<label for="e-slider">e:</label>
<span id="e-value"></span>
</div>
<div class="container">
<div id="pi"></div>
<input type="range" min="0" max="1" step="0.01" value="0" id="pi-slider" />
<label for="pi-slider">pi:</label>
<span id="pi-value"></span>
</div>
</div>
```
```js
// sliders
const eInput = document.querySelector("#e-slider");
const piInput = document.querySelector("#pi-slider");
// spans for displaying values
const eValue = document.querySelector("#e-value");
const piValue = document.querySelector("#pi-value");
eInput.addEventListener("input", function () {
e.style.transform = "rotate(calc(1deg * pow(" + this.value + ", e)))";
eValue.textContent = e.style.transform;
});
piInput.addEventListener("input", function () {
pi.style.rotate = "calc(sin(" + this.value + " * pi) * 100deg)";
piValue.textContent = pi.style.rotate;
});
```
{{EmbedLiveSample('Using_e_and_pi_in_calc', 'auto', '200')}}
### Infinity, NaN, and division by zero
The following example shows the computed value of the `width` property when dividing by zero, followed by how serialization with different `calc()` constants look when viewed in the console:
```html
<div></div>
```
```css
div {
height: 50px;
background-color: red;
width: calc(1px / 0);
}
```
```js
const div = document.querySelector("div");
console.log(div.offsetWidth); // 17895698 (infinity clamped to largest value for width)
function logSerializedWidth(value) {
div.style.width = value;
console.log(div.style.width);
}
logSerializedWidth("calc(1px / 0)"); // calc(infinity * 1px)
logSerializedWidth("calc(1px / -0)"); // calc(-infinity * 1px)
logSerializedWidth("calc(1px * -infinity * -infinity)"); // calc(infinity * 1px)
logSerializedWidth("calc(1px * -infinity * infinity)"); // calc(-infinity * 1px)
logSerializedWidth("calc(1px * (NaN + 1))"); // calc(NaN * 1px)
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef("<calc-sum>")}}
- {{CSSxRef("<calc-product>")}}
- {{CSSxRef("<calc-value>")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_target-within/index.md | ---
title: ":target-within"
slug: Web/CSS/:target-within
page-type: css-pseudo-class
status:
- experimental
browser-compat: css.selectors.target-within
---
{{CSSRef}}{{SeeCompatTable}}
The **`:target-within`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents an element that is a target element or _contains_ an element that is a target. A target element is a unique element with an [`id`](/en-US/docs/Web/HTML/Global_attributes#id) matching the URL's fragment. In other words, it represents an element that is itself matched by the {{CSSxRef(":target")}} pseudo-class or has a descendant that is matched by `:target`. (This includes descendants in [shadow trees](/en-US/docs/Web/API/Web_components/Using_shadow_DOM).)
```css
/* Selects a <div> when one of its descendants is a target */
div:target-within {
background: cyan;
}
```
## Syntax
```css
:target-within {
/* ... */
}
```
## Examples
### Highlighting an article
The `:target-within` pseudo-class can be used to highlight the article if anything inside it has been directly linked to. The `:target` pseudo-class is also being used to show which item has been targeted.
#### HTML
```html
<h3>Table of Contents</h3>
<ol>
<li><a href="#p1">Jump to the first paragraph!</a></li>
<li><a href="#p2">Jump to the second paragraph!</a></li>
</ol>
<article>
<h3>My Fun Article</h3>
<p id="p1">
You can target <i>this paragraph</i> using a URL fragment. Click on the link
above to try out!
</p>
<p id="p2">
This is <i>another paragraph</i>, also accessible from the links above.
Isn't that delightful?
</p>
</article>
```
#### CSS
```css
article:target-within {
background-color: gold;
}
/* Add a pseudo-element inside the target element */
p:target::before {
font: 70% sans-serif;
content: "►";
color: limegreen;
margin-right: 0.25em;
}
/* Style italic elements within the target element */
p:target i {
color: red;
}
```
#### Result
{{EmbedLiveSample('Examples', 500, 300)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef(":target")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/margin-block/index.md | ---
title: margin-block
slug: Web/CSS/margin-block
page-type: css-shorthand-property
browser-compat: css.properties.margin-block
---
{{CSSRef}}
The **`margin-block`** [CSS](/en-US/docs/Web/CSS) [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) defines the logical block start and end margins of an element, which maps to physical margins depending on the element's writing mode, directionality, and text orientation.
{{EmbedInteractiveExample("pages/css/margin-block.html")}}
## Constituent properties
This property is a shorthand for the following CSS properties:
- {{cssxref("margin-block-start")}}
- {{cssxref("margin-block-end")}}
## Syntax
```css
/* <length> values */
margin-block: 10px 20px; /* An absolute length */
margin-block: 1em 2em; /* relative to the text size */
margin-block: 5% 2%; /* relative to the nearest block container's width */
margin-block: 10px; /* sets both start and end values */
/* Keyword values */
margin-block: auto;
/* Global values */
margin-block: inherit;
margin-block: initial;
margin-block: revert;
margin-block: revert-layer;
margin-block: unset;
```
This property corresponds to the {{CSSxRef("margin-top")}} and {{CSSxRef("margin-bottom")}}, or the {{CSSxRef("margin-right")}} and {{CSSxRef("margin-left")}} properties, depending on the values defined for {{CSSxRef("writing-mode")}}, {{CSSxRef("direction")}}, and {{CSSxRef("text-orientation")}}.
The `margin-block` property may be specified using one or two values.
- When **one** value is specified, it applies the same margin to **both start and end**.
- When **two** values are specified, the first margin applies to the **start**, the second to the **end**.
### Values
The `margin-block` property takes the same values as the {{CSSxRef("margin", "", "#values")}} property.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting block start and end margins
#### CSS
```css
div {
background-color: yellow;
width: 120px;
height: auto;
border: 1px solid green;
}
p {
margin: 0;
margin-block: 20px 40px;
background-color: tan;
}
.verticalExample {
writing-mode: vertical-rl;
}
```
#### HTML
```html
<div>
<p>Example text</p>
</div>
<div class="verticalExample">
<p>Example text</p>
</div>
```
#### Result
{{EmbedLiveSample("Setting_block_start_and_end_margins", 140, 200)}}
## 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/background/index.md | ---
title: background
slug: Web/CSS/background
page-type: css-shorthand-property
browser-compat: css.properties.background
---
{{CSSRef}}
The **`background`** [shorthand](/en-US/docs/Web/CSS/Shorthand_properties) [CSS](/en-US/docs/Web/CSS) property sets all background style properties at once, such as color, image, origin and size, or repeat method. Component properties not set in the `background` shorthand property value declaration are set to their default values.
{{EmbedInteractiveExample("pages/css/background.html")}}
## Constituent properties
This property is a shorthand for the following CSS properties:
- {{cssxref("background-attachment")}}
- {{cssxref("background-clip")}}
- {{cssxref("background-color")}}
- {{cssxref("background-image")}}
- {{cssxref("background-origin")}}
- {{cssxref("background-position")}}
- {{cssxref("background-repeat")}}
- {{cssxref("background-size")}}
## Syntax
```css
/* Using a <background-color> */
background: green;
/* Using a <bg-image> and <repeat-style> */
background: url("test.jpg") repeat-y;
/* Using a <box> and <background-color> */
background: border-box red;
/* A single image, centered and scaled */
background: no-repeat center/80% url("../img/image.png");
/* Global values */
background: inherit;
background: initial;
background: revert;
background: revert-layer;
background: unset;
```
The `background` property is specified as one or more background layers, separated by commas.
The syntax of each layer is as follows:
- Each layer may include zero or one occurrences of any of the following values:
- `<attachment>`
- `<bg-image>`
- `<position>`
- `<bg-size>`
- `<repeat-style>`
- The `<bg-size>` value may only be included immediately after `<position>`, separated with the '/' character, like this: "`center/80%`".
- The `<box>` value may be included zero, one, or two times. If included once, it sets both {{cssxref("background-origin")}} and {{cssxref("background-clip")}}. If it is included twice, the first occurrence sets {{cssxref("background-origin")}}, and the second sets {{cssxref("background-clip")}}.
- The `<background-color>` value may only be included in the last layer specified.
### Values
- `<attachment>`
- : See {{cssxref("background-attachment")}}. Default: `scroll`.
- `<box>`
- : See {{cssxref("background-clip")}} and {{cssxref("background-origin")}}. Default: `border-box` and `padding-box` respectively.
- `<background-color>`
- : See {{cssxref("background-color")}}. Default: `transparent`.
- `<bg-image>`
- : See {{Cssxref("background-image")}}. Default: `none`.
- `<position>`
- : See {{cssxref("background-position")}}. Default: 0% 0%.
- `<repeat-style>`
- : See {{cssxref("background-repeat")}}. Default: `repeat`.
- `<bg-size>`
- : See {{cssxref("background-size")}}. Default: `auto`.
The following three lines of CSS are equivalent:
```css
background: none;
background: transparent;
background: repeat scroll 0% 0% / auto padding-box border-box none transparent;
```
## Accessibility concerns
Browsers do not provide any special information on background images to assistive technology. This is important primarily for screen readers, as a screen reader will not announce its presence and therefore convey nothing to its users. If the image contains information critical to understanding the page's overall purpose, it is better to describe it semantically in the document.
- [MDN Understanding WCAG, Guideline 1.1 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.1_—_providing_text_alternatives_for_non-text_content)
- [Understanding Success Criterion 1.1.1 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/2016/NOTE-UNDERSTANDING-WCAG20-20161007/text-equiv-all.html)
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting backgrounds with color keywords and images
#### HTML
```html
<p class="topbanner">
Starry sky<br />
Twinkle twinkle<br />
Starry sky
</p>
<p class="warning">Here is a paragraph</p>
<p></p>
```
#### CSS
```css
.warning {
background: pink;
}
.topbanner {
background: url("starsolid.gif") #99f repeat-y fixed;
}
```
#### Result
{{EmbedLiveSample("Setting_backgrounds_with_color_keywords_and_images")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("box-decoration-break")}}
- [Using gradients](/en-US/docs/Web/CSS/CSS_images/Using_CSS_gradients)
- [Using multiple backgrounds](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders/Using_multiple_backgrounds)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_checked/index.md | ---
title: ":checked"
slug: Web/CSS/:checked
page-type: css-pseudo-class
browser-compat: css.selectors.checked
---
{{CSSRef}}
The **`:checked`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) selector represents any **radio** ([`<input type="radio">`](/en-US/docs/Web/HTML/Element/input/radio)), **checkbox** ([`<input type="checkbox">`](/en-US/docs/Web/HTML/Element/input/checkbox)), or **option** ({{HTMLElement("option")}} in a {{HTMLElement("select")}}) element that is checked or toggled to an `on` state.
{{EmbedInteractiveExample("pages/tabbed/pseudo-class-checked.html", "tabbed-shorter")}}
The user can engage this state by checking/selecting an element, or disengage it by unchecking/deselecting the element.
> **Note:** Because browsers often treat `<option>`s as [replaced elements](/en-US/docs/Web/CSS/Replaced_element), the extent to which they can be styled with the `:checked` pseudo-class varies from browser to browser.
## Syntax
```css
:checked {
/* ... */
}
```
## Examples
### Basic example
#### HTML
```html
<div>
<input type="radio" name="my-input" id="yes" value="yes" />
<label for="yes">Yes</label>
<input type="radio" name="my-input" id="no" value="no" />
<label for="no">No</label>
</div>
<div>
<input type="checkbox" name="my-checkbox" id="opt-in" />
<label for="opt-in">Check me!</label>
</div>
<select name="my-select" id="fruit">
<option value="opt1">Apples</option>
<option value="opt2">Grapes</option>
<option value="opt3">Pears</option>
</select>
```
#### CSS
```css
div,
select {
margin: 8px;
}
/* Labels for checked inputs */
input:checked + label {
color: red;
}
/* Radio element, when checked */
input[type="radio"]:checked {
box-shadow: 0 0 0 3px orange;
}
/* Checkbox element, when checked */
input[type="checkbox"]:checked {
box-shadow: 0 0 0 3px hotpink;
}
/* Option elements, when selected */
option:checked {
box-shadow: 0 0 0 3px lime;
color: red;
}
```
#### Result
{{EmbedLiveSample("Basic_example")}}
### Toggling elements with a hidden checkbox
This example utilizes the `:checked` pseudo-class to let the user toggle content based on the state of a checkbox, all without using [JavaScript](/en-US/docs/Web/JavaScript).
#### HTML
```html
<input type="checkbox" id="expand-toggle" />
<table>
<thead>
<tr>
<th>Column #1</th>
<th>Column #2</th>
<th>Column #3</th>
</tr>
</thead>
<tbody>
<tr class="expandable">
<td>[more text]</td>
<td>[more text]</td>
<td>[more text]</td>
</tr>
<tr>
<td>[cell text]</td>
<td>[cell text]</td>
<td>[cell text]</td>
</tr>
<tr>
<td>[cell text]</td>
<td>[cell text]</td>
<td>[cell text]</td>
</tr>
<tr class="expandable">
<td>[more text]</td>
<td>[more text]</td>
<td>[more text]</td>
</tr>
<tr class="expandable">
<td>[more text]</td>
<td>[more text]</td>
<td>[more text]</td>
</tr>
</tbody>
</table>
<label for="expand-toggle" id="expand-btn">Toggle hidden rows</label>
```
#### CSS
```css
/* Hide the toggle checkbox */
#expand-toggle {
display: none;
}
/* Hide expandable content by default */
.expandable {
visibility: collapse;
background: #ddd;
}
/* Style the button */
#expand-btn {
display: inline-block;
margin-top: 12px;
padding: 5px 11px;
background-color: #ff7;
border: 1px solid;
border-radius: 3px;
}
/* Show hidden content when the checkbox is checked */
#expand-toggle:checked ~ * .expandable {
visibility: visible;
}
/* Style the button when the checkbox is checked */
#expand-toggle:checked ~ #expand-btn {
background-color: #ccc;
}
```
#### Result
{{EmbedLiveSample("Toggling_elements_with_a_hidden_checkbox", "auto", 220)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Web forms — working with user data](/en-US/docs/Learn/Forms)
- [Styling web forms](/en-US/docs/Learn/Forms/Styling_web_forms)
- Related HTML elements: [`<input type="checkbox">`](/en-US/docs/Web/HTML/Element/input/checkbox), [`<input type="radio">`](/en-US/docs/Web/HTML/Element/input/radio), {{HTMLElement("select")}}, and {{HTMLElement("option")}}
- [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/column_combinator/index.md | ---
title: Column combinator
slug: Web/CSS/Column_combinator
page-type: css-combinator
status:
- experimental
browser-compat: css.selectors.column
---
{{CSSRef}} {{SeeCompatTable}}
The **column combinator** (`||`) is placed between two CSS selectors. It matches only those elements matched by the second selector that belong to the column elements matched by the first.
```css
/* Table cells that belong to the "selected" column */
col.selected||td {
background: gray;
}
```
## Syntax
```css-nolint
/* The white space around the || combinator is optional but recommended. */
column-selector || cell-selector {
/* style properties */
}
```
## Examples
### HTML
```html
<table border="1">
<colgroup>
<col span="2" />
<col class="selected" />
</colgroup>
<tbody>
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
</tr>
<tr>
<td colspan="2">D</td>
<td>E</td>
</tr>
<tr>
<td>F</td>
<td colspan="2">G</td>
</tr>
</tbody>
</table>
```
### CSS
```css
col.selected||td {
background: gray;
color: white;
font-weight: bold;
}
```
### Result
{{EmbedLiveSample("Examples", "100%")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{HTMLElement("col")}}
- {{HTMLElement("colgroup")}}
- {{CSSxRef("grid")}}
- {{CSSxRef(":nth-of-type")}}
- {{CSSxRef(":nth-last-of-type")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/flex-direction/index.md | ---
title: flex-direction
slug: Web/CSS/flex-direction
page-type: css-property
browser-compat: css.properties.flex-direction
---
{{CSSRef}}
The **`flex-direction`** [CSS](/en-US/docs/Web/CSS) property sets how flex items are placed in the flex container defining the main axis and the direction (normal or reversed).
{{EmbedInteractiveExample("pages/css/flex-direction.html")}}
Note that the values `row` and `row-reverse` are affected by the directionality of the flex container. If its [`dir`](/en-US/docs/Web/HTML/Global_attributes#dir) attribute is `ltr`, `row` represents the horizontal axis oriented from the left to the right, and `row-reverse` from the right to the left; if the `dir` attribute is `rtl`, `row` represents the axis oriented from the right to the left, and `row-reverse` from the left to the right.
## Syntax
```css
/* The direction text is laid out in a line */
flex-direction: row;
/* Like <row>, but reversed */
flex-direction: row-reverse;
/* The direction in which lines of text are stacked */
flex-direction: column;
/* Like <column>, but reversed */
flex-direction: column-reverse;
/* Global values */
flex-direction: inherit;
flex-direction: initial;
flex-direction: revert;
flex-direction: revert-layer;
flex-direction: unset;
```
### Values
The following values are accepted:
- `row`
- : The flex container's main-axis is defined to be the same as the text direction. The **main-start** and **main-end** points are the same as the content direction.
- `row-reverse`
- : Behaves the same as `row` but the **main-start** and **main-end** points are opposite to the content direction.
- `column`
- : The flex container's main-axis is the same as the block-axis. The **main-start** and **main-end** points are the same as the **before** and **after** points of the writing-mode.
- `column-reverse`
- : Behaves the same as `column` but the **main-start** and **main-end** are opposite to the content direction.
## Accessibility concerns
Using the `flex-direction` property with values of `row-reverse` or `column-reverse` will create a disconnect between the visual presentation of content and DOM order. This will adversely affect users experiencing low vision navigating with the aid of assistive technology such as a screen reader. If the visual (CSS) order is important, then screen reader users will not have access to the correct reading order.
- [Flexbox & the keyboard navigation disconnect — Tink](https://tink.uk/flexbox-the-keyboard-navigation-disconnect/)
- [Source Order Matters | Adrian Roselli](https://adrianroselli.com/2015/09/source-order-matters.html)
- [MDN Understanding WCAG, Guideline 1.3 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.3_%e2%80%94_create_content_that_can_be_presented_in_different_ways)
- [Understanding Success Criterion 1.3.2 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/content-structure-separation-sequence.html)
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Reversing flex container columns and rows
#### HTML
```html
<h4>This is a Column-Reverse</h4>
<div id="col-rev" class="content">
<div class="box red">A</div>
<div class="box lightblue">B</div>
<div class="box yellow">C</div>
</div>
<h4>This is a Row-Reverse</h4>
<div id="row-rev" class="content">
<div class="box red">A</div>
<div class="box lightblue">B</div>
<div class="box yellow">C</div>
</div>
```
#### CSS
```css
.content {
width: 200px;
height: 200px;
border: 1px solid #c3c3c3;
display: flex;
}
.box {
width: 50px;
height: 50px;
}
#col-rev {
flex-direction: column-reverse;
}
#row-rev {
flex-direction: row-reverse;
}
.red {
background-color: red;
}
.lightblue {
background-color: lightblue;
}
.yellow {
background-color: yellow;
}
```
#### Result
{{EmbedLiveSample('Reversing_flex_container_columns_and_rows', '', '550')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- CSS {{CSSXRef("flex-flow")}} shorthand property for the CSS `flex-direction` and {{CSSXRef("flex-wrap")}} properties.
- CSS Flexbox Guide: _[Basic Concepts of Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox)_
- CSS Flexbox Guide: _[Ordering flex items](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Ordering_flex_items)_
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/alternative_style_sheets/index.md | ---
title: Alternative style sheets
slug: Web/CSS/Alternative_style_sheets
page-type: guide
browser-compat: html.elements.link.rel.alternate_stylesheet
---
{{CSSRef}}
Specifying **alternative style sheets** in a web page provides a way for users to see multiple versions of a page, based on their needs or preferences.
> **Note:** This feature is not well supported in browsers without an extension. To offer alternative presentations that work with a user's existing preferences, see the CSS [media features](/en-US/docs/Web/CSS/@media#media_features) {{cssxref("@media/prefers-color-scheme","prefers-color-scheme")}} and {{cssxref("@media/prefers-contrast","prefers-contrast")}}.
Firefox lets the user select the stylesheet using the _View > Page Style_ submenu. Other browsers require an extension to enable this functionality. The web page can also provide its own user interface to let the user switch styles.
## An example: specifying the alternative stylesheets
The alternate stylesheets are commonly specified using a {{HTMLElement("link")}} element with `rel="alternate stylesheet"` and `title="…"` attributes. For example:
```html
<link href="reset.css" rel="stylesheet" />
<link href="default.css" rel="stylesheet" title="Default Style" />
<link href="fancy.css" rel="alternate stylesheet" title="Fancy" />
<link href="basic.css" rel="alternate stylesheet" title="Basic" />
```
In this example, the styles "Default Style", "Fancy", and "Basic" will be listed in the _Page Style_ submenu, with "Default Style" pre-selected. When the user selects a different style, the page will immediately be re-rendered using that style sheet.
No matter what style is selected, the rules from the reset.css stylesheet will always be applied.
### Try it out
[Try a working example here](https://mdn.github.io/css-examples/alt-style-sheets/).
## Details
Any stylesheet in a document falls into one of the following categories:
- **Persistent** (has `rel="stylesheet"`, no `title=""`): always applies to the document.
- **Preferred** (has `rel="stylesheet"`, with `title="…"` specified): applied by default, but {{domxref("StyleSheet.disabled", "disabled", "", 1)}} if an alternate stylesheet is selected. **There can only be one preferred stylesheet**, so providing stylesheets with different title attributes will cause some of them to be ignored.
- **Alternate** (`rel="alternate stylesheet"`, with `title="…"` specified): disabled by default, can be selected.
When style sheets are referenced with a `title` attribute on the {{HTMLElement("link", "<link rel=\"stylesheet\">")}} or {{HTMLElement("style")}} element, the title becomes one of the choices offered to the user. Style sheets linked with the same `title` are part of the same choice. Style sheets linked without a `title` attribute are always applied.
Use `rel="stylesheet"` to link to the default style, and `rel="alternate stylesheet"` to link to alternative style sheets. This tells the browser which style sheet title should be selected by default, and makes that default selection apply in browsers that do not support alternate style sheets.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/page/index.md | ---
title: page
slug: Web/CSS/page
page-type: css-property
browser-compat: css.properties.page
---
{{CSSRef}}
The **`page`** [CSS](/en-US/docs/Web/CSS) property is used to specify the named page, a specific type of page defined by the {{cssxref("@page")}} [at-rule](/en-US/docs/Web/CSS/At-rule).
If there are multiple selectors that are using a named page consecutively then a forced page break using [`break-after`](/en-US/docs/Web/CSS/break-after) may be needed.
## Syntax
```css
/* set a named page */
page: exampleName;
page: chapterIntro;
/* Use ancestors named page */
page: auto; /* default value */
/* Global values */
page: inherit;
page: initial;
page: revert;
page: revert-layer;
page: unset;
```
### Values
- `auto`
- : Default value. Use the value of the nearest ancestor with a non-`auto` value. If no ancestor has a named page value set, the used value for auto is the empty string.
- {{cssxref("custom-ident")}}
- : Case-sensitive name defined in a [`@page`](/en-US/docs/Web/CSS/@page) at-rule.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Named page example
#### HTML
There are two parts to this HTML:
- The print controls
- The content to be printed
The print controls allow the user to select how the `section`s in the `article` will be printed.
```html
<!-- print options -->
<fieldset id="printStyle">
<legend>How would you like to print</legend>
<label for="single"
><input type="radio" id="single" name="type" value="single" checked />No
Pages</label
>
<label for="double"
><input type="radio" id="grouped" name="type" value="grouped" />Pages with
Grouped Chapters</label
>
<label for="double"
><input type="radio" id="paged" name="type" value="paged" />Chapters
Paged</label
>
<button id="print">Print</button>
</fieldset>
<!-- Content to be printed -->
<article id="print-area" data-print="single">
<section id="toc">
<h2>Table of contents</h2>
<ul>
<li>Foreword</li>
<li>Introduction</li>
<li>Chapter One - named pages</li>
<li>Chapter Two - page orientation</li>
<li>Chapter Three - page margins</li>
<li>Conclusion</li>
</ul>
</section>
<section id="foreword">
<h2>Foreword</h2>
<p>
This book is all about how the CSS <code>@page</code> at-rule can help
with printing HTML books.
</p>
</section>
<section id="introduction">
<h2>Introduction</h2>
<p>
This book is a concept to show how an <em>HTML</em> document can easily be
printed out in pages.
</p>
</section>
<section id="chapter1" class="chapter">
<h2>Named pages</h2>
<p>Lorem ipsum</p>
</section>
<section id="chapter2" class="chapter">
<h2>Page Orientation</h2>
<p>Lorem ipsum</p>
</section>
<section id="chapter3" class="chapter">
<h2>Page Margins</h2>
<p>There are 16 page margins that can be set:</p>
<ul>
<li>@top-left-corner</li>
<li>@top-left</li>
<li>@top-middle</li>
<li>@top-right</li>
<li>@top-right-corner</li>
<li>@left-top</li>
<li>@left-middle</li>
<li>@left-bottom</li>
<li>@right-top</li>
<li>@right-middle</li>
<li>@right-bottom</li>
<li>@bottom-left-corner</li>
<li>@bottom-left</li>
<li>@bottom-middle</li>
<li>@bottom-right</li>
<li>@bottom-right-corner</li>
</ul>
<p>They can be used to show what appears in these parts of the margin</p>
</section>
<section id="conclusion">
<h2>Conclusion</h2>
<p>Now go ahead and write books.</p>
</section>
</article>
```
#### CSS
```css hidden
fieldset {
display: flex;
flex-direction: row;
justify-content: space-between;
gap: 1rem;
width: fit-content;
}
```
The first part of the CSS sets up the **named** pages, these include the size and orientation and also some content to go in the [`@top-middle` margin](/en-US/docs/Web/CSS/@page#margin_at-rules) of the printed pages.
```css
@page toc {
size: a4 portrait;
@top-middle {
content: "Table of contents";
}
}
@page foreword {
size: a4 portrait;
@top-middle {
content: "Foreword";
}
}
@page introduction {
size: a4 portrait;
@top-middle {
content: "Introduction";
}
}
@page conclusion {
size: a4 portrait;
@top-middle {
content: "Conclusion";
}
}
@page chapter {
size: a4 landscape;
@top-middle {
content: "Chapter";
}
}
```
The next part of the CSS uses [attribute selectors](/en-US/docs/Web/CSS/Attribute_selectors) to apply the print dimensions, orientation, and margins defined in the named `@page` rules defined in the previous CSS section to elements using the `page` property.
The sections with `class="chapter"` are concurrent and appear as one page. The `break-after: page;` is used to split them up, which splits each chapter into a separately printed page.
```css
@media print {
fieldset {
display: none;
}
section {
font-size: 2rem;
font-family: Roboto;
}
.chapter {
border: tomato 2px solid;
}
[data-print="grouped"] > #toc,
[data-print="paged"] > #toc {
page: toc;
font-family: Courier;
}
[data-print="grouped"] > #foreword,
[data-print="paged"] > #foreword {
page: foreword;
font-family: Courier;
}
[data-print="grouped"] > #introduction,
[data-print="paged"] > #introduction {
page: introduction;
font-family: Courier;
}
[data-print="grouped"] > #conclusion,
[data-print="paged"] > #conclusion {
page: conclusion;
font-family: Courier;
}
[data-print="grouped"] > .chapter,
[data-print="paged"] > .chapter {
page: chapter;
}
[data-print="paged"] > .chapter {
border: none;
break-after: page;
}
.chapter > ul {
columns: 2;
}
}
```
#### JavaScript
The JavaScript updates the value of the `data-print` attribute, which is the attribute on which the named page is applied, when you select a different printing option:
```js
const printArea = document.querySelector("#print-area");
const printButton = document.querySelector("#print");
const printOption = document.querySelector("#printStyle");
printOption.addEventListener("change", (event) => {
if (event.target.value === "single") {
printArea.dataset.print = "single";
} else if (event.target.value === "grouped") {
printArea.dataset.print = "grouped";
} else {
printArea.dataset.print = "paged";
}
});
printButton.addEventListener("click", () => {
window.print();
});
```
#### Result
What is printed, and what is shown in the print preview dialog, will change depending on which print style radio button is selected.
{{ EmbedLiveSample('Named page example', '100%', 520) }}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_focus-visible/index.md | ---
title: ":focus-visible"
slug: Web/CSS/:focus-visible
page-type: css-pseudo-class
browser-compat: css.selectors.focus-visible
---
{{CSSRef}}
The **`:focus-visible`** pseudo-class applies while an element matches the {{CSSxRef(":focus")}} pseudo-class and the UA ({{glossary("User Agent")}}) determines via heuristics that the focus should be made evident on the element. (Many browsers show a "focus ring" by default in this case.)
{{EmbedInteractiveExample("pages/tabbed/pseudo-class-focus-visible.html", "tabbed-shorter")}}
This selector is useful to provide a different focus indicator based on the user's input modality (mouse vs. keyboard).
## Syntax
```css
:focus-visible {
/* ... */
}
```
## :focus vs :focus-visible
Originally, user-agent CSS set focus styles based only on the `:focus` pseudo-class, styling most focused elements with a focus ring outline. This meant all elements, including all links and buttons, had a focus ring applied when focused, which many found ugly. Because of the appearance, some authors removed the user-agent outline focus styles. Changing focus style can decrease usability, while removing focus styles makes keyboard navigation inaccessible for sighted users.
Browsers no longer visibly indicate focus (such as by drawing a "focus ring"), around each element when it has focus. Instead, they use a variety of heuristics to provide focus indicators only when it would be most helpful to the user. For instance, when a button is clicked using a pointing device, the focus is generally not visually indicated, but when a text box needing user input has focus, focus is indicated. While focus styles are always required when users are navigating the page with the keyboard or when focus is managed via scripts, focus styles are not required when the user knows where they are putting focus, such as when they use a pointing device such as a mouse or finger to physically set focus on an element, unless that element continues to need user attention.
The `:focus` pseudo-class always matches the currently-focused element. The `:focus-visible` pseudo-class also matches the focused element, but only if the user needs to be informed where the focus currently is. Because the `:focus-visible` pseudo-class matches the focused element when needed, using the `:focus-visible` (instead of the `:focus` pseudo-class) allows authors to change the appearance of the focus indicator without changing when the focus indicator appears.
When the [`:focus`](/en-US/docs/Web/CSS/:focus) pseudo-class is used, it always targets the currently focused element. This means that when a user employs a pointing device, a visible focus ring appears around the focused element, which some consider obtrusive. The `:focus-visible` pseudo-class respects user agents' selective focus indication behavior while still allowing focus indicator customization.
## Examples
### Comparing :focus and :focus-visible
This example presents three pairs of controls. Each pair consists of a [`text`](/en-US/docs/Web/HTML/Element/input/text) input and a button.
- The first pair does not add any custom styles for focus states, and shows the default case.
- The second pair adds styles using the `:focus` pseudo-class.
- The third pair add styles using the `:focus-visible` pseudo-class.
```html
<input type="text" value="Default styles" /><br />
<button>Default styles</button><br />
<input class="focus-only" type="text" value=":focus" /><br />
<button class="focus-only">:focus</button><br />
<input class="focus-visible-only" type="text" value=":focus-visible" /><br />
<button class="focus-visible-only">:focus-visible</button>
```
```css
input,
button {
margin: 10px;
}
.focus-only:focus {
outline: 2px solid black;
}
.focus-visible-only:focus-visible {
outline: 4px dashed darkorange;
}
```
If you click each element in turn, you will see that when `:focus` is used to style the focus ring, the UA draws the focus ring when the user clicks the button. However, when `:focus-visible` is used to style the focus ring, the UA does not draw the focus ring when the user clicks the button, just like in the default case.
If you then tab through each element, you will see that in all three cases — default, `:focus`, and `:focus-visible` — the UA draws the focus ring around the button when the user navigates to it with the keyboard.
This shows how `:focus-visible` enables a designer to follow the browser's logic in determining when a focus ring should be shown.
{{EmbedLiveSample("Comparing :focus and :focus-visible", "100%", 300)}}
### Providing a :focus fallback
If your code has to work in old browser versions that do not support `:focus-visible`, check supports of `:focus-visible` with {{cssxref("@supports")}} and repeat the same focus styling in it, but inside a `:focus` rule. Note that even if you do not specify anything at all for `:focus`, old browsers will simply display the native outline, which can be enough.
```html
<button class="button with-fallback" type="button">Button with fallback</button>
<button class="button without-fallback" type="button">
Button without fallback
</button>
```
```css
.button {
margin: 10px;
border: 2px solid darkgray;
border-radius: 4px;
}
.button:focus-visible {
/* Draw the focus when :focus-visible is supported */
outline: 3px solid deepskyblue;
outline-offset: 3px;
}
@supports not selector(:focus-visible) {
.button.with-fallback:focus {
/* Fallback for browsers without :focus-visible support */
outline: 3px solid deepskyblue;
outline-offset: 3px;
}
}
```
{{EmbedLiveSample("Selectively_showing_the_focus_indicator", "100%", 72)}}
## Accessibility concerns
### Low vision
Make sure the visual focus indicator can be seen by people with low vision. This will also benefit anyone use a screen in a brightly lit space (like outside in the sun). [WCAG 2.1 SC 1.4.11 Non-Text Contrast](https://www.w3.org/WAI/WCAG21/Understanding/non-text-contrast.html) requires that the visual focus indicator be at least 3 to 1.
- Accessible Visual Focus Indicators: [Give Your Site Some Focus! Tips for Designing Useful and Usable Focus Indicators](https://www.deque.com/blog/give-site-focus-tips-designing-usable-focus-indicators/)
### Cognition
It may not be obvious as to why the focus indicator is appearing and disappearing if a person is using mixed forms of input. For users with cognitive concerns, or who are less technologically literate, this lack of consistent behavior for interactive elements may be confusing.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef(":focus")}}
- {{CSSxRef(":focus-within")}}
- [A polyfill for `:focus-visible`](https://github.com/WICG/focus-visible)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/scroll-timeline/index.md | ---
title: scroll-timeline
slug: Web/CSS/scroll-timeline
page-type: css-shorthand-property
status:
- experimental
browser-compat: css.properties.scroll-timeline
---
{{CSSRef}}{{SeeCompatTable}}
The **`scroll-timeline`** [CSS](/en-US/docs/Web/CSS) [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) is used to define a _named scroll progress timeline_, which is progressed through by scrolling a scrollable element (_scroller_) between top and bottom (or left and right). `scroll-timeline` is set on the scroller that will provide the timeline. The starting scroll position represents 0% progress and the ending scroll position represents 100% progress. If the 0% position and 100% position coincide (i.e., the scroll container has no overflow to scroll), the timeline is inactive.
`scroll-timeline` can contain two constituent values — a name for the named scroll progress timeline, and an optional scroll axis value.
The name is then referenced in an [`animation-timeline`](/en-US/docs/Web/CSS/animation-timeline) declaration to indicate the container's element that is used to drive the progress of the animation through the scrolling action.
> **Note:** If the scroller does not overflow its container in the axis dimension or if the overflow is hidden or clipped, no timeline will be created.
## Constituent properties
This property is a shorthand for the following CSS properties:
- [`scroll-timeline-name`](/en-US/docs/Web/CSS/scroll-timeline-name)
- [`scroll-timeline-axis`](/en-US/docs/Web/CSS/scroll-timeline-axis)
## Syntax
```css
/* two values: one each for scroll-timeline-name and scroll-timeline-axis */
scroll-timeline: --custom_name_for_timeline block;
scroll-timeline: --custom_name_for_timeline inline;
scroll-timeline: --custom_name_for_timeline y;
scroll-timeline: --custom_name_for_timeline x;
scroll-timeline: none block;
scroll-timeline: none inline;
scroll-timeline: none y;
scroll-timeline: none x;
/* one value: scroll-timeline-name */
scroll-timeline: none;
scroll-timeline: --custom_name_for_timeline;
```
The `scroll-timeline` shorthand property can be applied to a container element as a combination of the `<scroll-timeline-name>` and `<scroll-timeline-axis>` values. At least one of the values must be specified. If both the values are specified, the order followed must be the `<scroll-timeline-name>` value followed by the `<scroll-timeline-axis>` value.
> **Note:** `<scroll-timeline-name>`s must be [`<dashed-ident>`](/en-US/docs/Web/CSS/dashed-ident) values, which means they must start with `--`. This helps avoid name clashes with standard CSS keywords.
### Values
- `<scroll-timeline-name>`
- : See [`scroll-timeline-name`](/en-US/docs/Web/CSS/scroll-timeline-name).
- `<scroll-timeline-axis>`
- : See [`scroll-timeline-axis`](/en-US/docs/Web/CSS/scroll-timeline-axis). The default value is `block`.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Creating a named scroll progress timeline animation
In this example, a scroll timeline named `--squareTimeline` is defined using the `scroll-timeline-name` property on the element with the ID `container`.
This is then applied to the animation on the `#square` element using `animation-timeline: --squareTimeline`.
#### HTML
The HTML for the example is shown below.
```html
<div id="container">
<div id="square"></div>
<div id="stretcher"></div>
</div>
```
#### CSS
The CSS for the container sets it as the source of a scroll timeline named `--squareTimeline` using the `scroll-timeline` property.
It also sets the scrollbar to use for the timeline as the vertical scrollbar (this is not actually needed as it is the default).
The height of the container is set to `300px`, and the container is also set to create a vertical scrollbar if it overflows (the CSS `height` rule on the `stretcher` element below does make the content overflow its container).
```css
#container {
height: 300px;
overflow-y: scroll;
scroll-timeline: --squareTimeline y;
/* Firefox supports the older "vertical" syntax */
scroll-timeline: --squareTimeline vertical;
position: relative;
}
```
The CSS below defines a square that rotates according to the timeline provided by the `animation-timeline` property, which is set to the `--squareTimeline` timeline named above.
```css
#square {
background-color: deeppink;
width: 100px;
height: 100px;
animation-name: rotateAnimation;
animation-duration: 1ms; /* Firefox requires this to apply the animation */
animation-timeline: --squareTimeline;
position: absolute;
bottom: 0;
}
#stretcher {
height: 600px;
background: #dedede;
}
@keyframes rotateAnimation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
```
The `stretcher` CSS rule sets the block height to `600px`, which creates content that overflows the container element, thereby creating scroll bars.
Without this element, the content would not overflow the container, there would be no scrollbar, and hence no scroll timeline to associate with the animation timeline.
#### Result
Scroll the vertical bar to see the square animate as you scroll.
{{EmbedLiveSample("Creating_a_named_scroll_progress_timeline_animation", "100%", "320px")}}
The square animates as you scroll, and the animation duration when using `scroll-timeline` depends on the scroll speed (nevertheless, the `animation-duration` property has been defined so you can make out the scroll-driven animation).
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [`animation-timeline`](/en-US/docs/Web/CSS/animation-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")}}
- [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/class_selectors/index.md | ---
title: Class selectors
slug: Web/CSS/Class_selectors
page-type: css-selector
browser-compat: css.selectors.class
---
{{CSSRef}}
The [CSS](/en-US/docs/Web/CSS) **class selector** matches elements based on the contents of their [`class`](/en-US/docs/Web/HTML/Global_attributes#class) attribute.
```css
/* All elements with class="spacious" */
.spacious {
margin: 2em;
}
/* All <li> elements with class="spacious" */
li.spacious {
margin: 2em;
}
/* All <li> elements with a class list that includes both "spacious" and "elegant" */
/* For example, class="elegant retro spacious" */
li.spacious.elegant {
margin: 2em;
}
```
## Syntax
```css
.class_name { style properties }
```
Note that this is equivalent to the following {{Cssxref("Attribute_selectors", "attribute selector")}}:
```css
[class~=class_name] { style properties }
```
## Examples
### CSS
```css
.red {
color: #f33;
}
.yellow-bg {
background: #ffa;
}
.fancy {
font-weight: bold;
text-shadow: 4px 4px 3px #77f;
}
```
### HTML
```html
<p class="red">This paragraph has red text.</p>
<p class="red yellow-bg">
This paragraph has red text and a yellow background.
</p>
<p class="red fancy">This paragraph has red text and "fancy" styling.</p>
<p>This is just a regular paragraph.</p>
```
### Result
{{EmbedLiveSample('Examples')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [CSS Selectors](/en-US/docs/Web/CSS/CSS_selectors)
- [Learn CSS: Selectors](/en-US/docs/Learn/CSS/Building_blocks/Selectors)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/border-spacing/index.md | ---
title: border-spacing
slug: Web/CSS/border-spacing
page-type: css-property
browser-compat: css.properties.border-spacing
---
{{CSSRef}}
The **`border-spacing`** [CSS](/en-US/docs/Web/CSS) property sets the distance between the borders of adjacent cells in a {{htmlelement("table")}}. This property applies only when {{cssxref("border-collapse")}} is `separate`.
{{EmbedInteractiveExample("pages/css/border-spacing.html")}}
The `border-spacing` value is also used along the outside edge of the table, where the distance between the table's border and the cells in the first/last column or row is the sum of the relevant (horizontal or vertical) `border-spacing` and the relevant (top, right, bottom, or left) {{cssxref("padding")}} on the table.
> **Note:** The `border-spacing` property is equivalent to the deprecated `cellspacing` attribute of the `<table>` element, except that `border-spacing` has an optional second value that can be used to set different horizontal and vertical spacing.
## Syntax
```css
/* <length> */
border-spacing: 2px;
/* horizontal <length> | vertical <length> */
border-spacing: 1cm 2em;
/* Global values */
border-spacing: inherit;
border-spacing: initial;
border-spacing: revert;
border-spacing: revert-layer;
border-spacing: unset;
```
The `border-spacing` property may be specified as either one or two values.
- When **one** `<length>` value is specified, it defines both the horizontal and vertical spacings between cells.
- When **two** `<length>` values are specified, the first value defines the horizontal spacing between cells (i.e., the space between cells in adjacent _columns_), and the second value defines the vertical spacing between cells (i.e., the space between cells in adjacent _rows_).
### Values
- {{cssxref("<length>")}}
- : The size of the spacing as a fixed value.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Spacing and padding table cells
This example applies a spacing of `.5em` vertically and `1em` horizontally between a table's cells. Note how, along its outside edges, the table's `padding` values are added to its `border-spacing` values.
#### HTML
```html
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
```
#### CSS
```css
table {
border-spacing: 1em 0.5em;
padding: 0 2em 1em 0;
border: 1px solid orange;
}
td {
width: 1.5em;
height: 1.5em;
background: #d2d2d2;
text-align: center;
vertical-align: middle;
}
```
#### Result
{{ EmbedLiveSample('Spacing_and_padding_table_cells', 400, 200) }}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("border-collapse")}}, {{cssxref("border-style")}}
- The `border-spacing` 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/scroll-snap-stop/index.md | ---
title: scroll-snap-stop
slug: Web/CSS/scroll-snap-stop
page-type: css-property
browser-compat: css.properties.scroll-snap-stop
---
{{CSSRef}}
The **`scroll-snap-stop`** [CSS](/en-US/docs/Web/CSS) property defines whether or not the scroll container is allowed to "pass over" possible snap positions.
{{EmbedInteractiveExample("pages/css/scroll-snap-stop.html")}}
## Syntax
```css
/* Keyword values */
scroll-snap-stop: normal;
scroll-snap-stop: always;
/* Global values */
scroll-snap-stop: inherit;
scroll-snap-stop: initial;
scroll-snap-stop: revert;
scroll-snap-stop: revert-layer;
scroll-snap-stop: unset;
```
### Values
- `normal`
- : When the visual {{Glossary("viewport")}} of this element's scroll container is scrolled, it may "pass over" possible snap positions.
- `always`
- : The scroll container must not "pass over" a possible snap position; and must snap to the first of this elements' snap positions.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting different snap stops
The example below demonstrates the contrast between the `always` and `normal` values of `scroll-snap-stop`. The difference in the two `scroll-snap-stop` values is more noticeable when the `scroll-snap-type` property is set to `mandatory`, which is what is used in this example.
#### HTML
```html
<p>scroll-snap-stop: always (X Mandatory)</p>
<div class="x mandatory-scroll-snapping always-stop">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
<p>scroll-snap-stop: always (X Mandatory) on odd child elements</p>
<div class="x mandatory-scroll-snapping always-stop-odd">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
<p>scroll-snap-stop: always (X Mandatory) on even child elements</p>
<div class="x mandatory-scroll-snapping always-stop-even">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
<p>scroll-snap-stop: normal (X Mandatory)</p>
<div class="x mandatory-scroll-snapping normal-stop">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
<p>scroll-snap-stop: always (Y Mandatory)</p>
<div class="y mandatory-scroll-snapping always-stop">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
<p>scroll-snap-stop: normal (Y Mandatory)</p>
<div class="y mandatory-scroll-snapping normal-stop">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
```
#### CSS
```css hidden
/* setup */
body {
height: 100%;
display: flex;
align-items: center;
justify-content: space-between;
flex-flow: column nowrap;
font-family: monospace;
text-align: center;
}
div[class] {
font-size: 3rem;
display: flex;
overflow: auto;
flex: none;
}
.x {
width: 50%;
min-width: 15rem;
height: 6rem;
flex-flow: row nowrap;
}
.y {
width: 30%;
min-width: 12rem;
height: 12rem;
flex-flow: column nowrap;
}
div > div {
flex: none;
outline: 1px solid #333;
}
.x > div {
width: 90%;
height: 100%;
}
.y > div {
width: 100%;
height: 80%;
}
/* coloration */
div > div:nth-child(even) {
background-color: #87ea87;
}
div > div:nth-child(odd) {
background-color: #87ccea;
}
```
```css
/* setting up mandatory scroll-snap on parent */
.x.mandatory-scroll-snapping {
scroll-snap-type: x mandatory;
}
.y.mandatory-scroll-snapping {
scroll-snap-type: y mandatory;
}
/* defining scroll-snap alignment on children */
div > div {
scroll-snap-align: center;
}
/* defining scroll-snap stop on children */
.always-stop > div {
scroll-snap-stop: always;
}
.always-stop-odd > div:nth-of-type(odd) {
scroll-snap-stop: always;
}
.always-stop-even > div:nth-of-type(even) {
scroll-snap-stop: always;
}
.normal-stop > div {
scroll-snap-stop: normal;
}
```
#### Result
Scroll from left to right and from top to bottom in the X and Y boxes below, respectively. In the X and Y boxes where the `scroll-snap-stop` property is set to `always`, the scrolling is forced to stop at the snap point even when you scroll fast. However, in the boxes where the `scroll-snap-stop` property is set to `normal`, the snap points are skipped when you scroll fast.
If required, you can be selective about the items that are `always` stopped at inside the scroll container. This is demonstrated in the example below by targeting odd and even items; you can choose a different strategy based on your requirement. In the example below, scrolling does not "pass over" odd and even items in the second and third boxes, respectively.
{{EmbedLiveSample("Snapping_in_different_axes", "100%", "1080")}}
## 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/border-block-end-width/index.md | ---
title: border-block-end-width
slug: Web/CSS/border-block-end-width
page-type: css-property
browser-compat: css.properties.border-block-end-width
---
{{CSSRef}}
The **`border-block-end-width`** [CSS](/en-US/docs/Web/CSS) property defines the width of the logical block-end border of an element, which maps to a physical border width depending on the element's writing mode, directionality, and text orientation. It corresponds to the {{cssxref("border-top-width")}}, {{cssxref("border-right-width")}}, {{cssxref("border-bottom-width")}}, or {{cssxref("border-left-width")}} property depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}.
{{EmbedInteractiveExample("pages/css/border-block-end-width.html")}}
## Syntax
```css
/* <'border-width'> values */
border-block-end-width: 5px;
border-block-end-width: thick;
/* Global values */
border-block-end-width: inherit;
border-block-end-width: initial;
border-block-end-width: revert;
border-block-end-width: revert-layer;
border-block-end-width: unset;
```
Related properties are {{cssxref("border-block-start-width")}}, {{cssxref("border-inline-start-width")}}, and {{cssxref("border-inline-end-width")}}, which define the other border widths of the element.
### Values
- `<'border-width'>`
- : The width of the border. See {{ cssxref("border-width") }}.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Border width with vertical text
#### HTML
```html
<div>
<p class="exampleText">Example text</p>
</div>
```
#### CSS
```css
div {
background-color: yellow;
width: 120px;
height: 120px;
}
.exampleText {
writing-mode: vertical-lr;
border: 1px solid blue;
border-block-end-width: 5px;
}
```
#### Results
{{EmbedLiveSample("Border_width_with_vertical_text", 140, 140)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [CSS Logical Properties and Values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values)
- This property maps to one of the physical border properties: {{cssxref("border-top-width")}}, {{cssxref("border-right-width")}}, {{cssxref("border-bottom-width")}}, and {{cssxref("border-left-width")}}
- {{cssxref("writing-mode")}}, {{cssxref("direction")}}, {{cssxref("text-orientation")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/-webkit-touch-callout/index.md | ---
title: "-webkit-touch-callout"
slug: Web/CSS/-webkit-touch-callout
page-type: css-property
status:
- non-standard
browser-compat: css.properties.-webkit-touch-callout
---
{{CSSRef}}{{Non-standard_header}}
The `-webkit-touch-callout` [CSS](/en-US/docs/Web/CSS) property controls the display of the default callout shown when you touch and hold a touch target.
When a target is touched and held on iOS, Safari displays a callout information about the link. This property allows disabling that behavior.
## Syntax
```css
/* Keyword values */
-webkit-touch-callout: default;
-webkit-touch-callout: none;
/* Global values */
-webkit-touch-callout: initial;
-webkit-touch-callout: inherit;
-webkit-touch-callout: revert;
-webkit-touch-callout: revert-layer;
-webkit-touch-callout: unset;
```
### Values
- `default`
- : The default callout is displayed.
- `none`
- : The callout is disabled.
## Formal definition
{{CSSInfo}}
## Formal syntax
```plain
-webkit-touch-callout =
default | none
```
## Examples
### Turn off touch callout
```css
.example {
-webkit-touch-callout: none;
}
```
## 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-_webkit_touch_callout).
## Browser compatibility
{{Compat}}
## See also
- [WebKit CSS extensions](/en-US/docs/Web/CSS/WebKit_Extensions)
- [-webkit-touch-callout in the Apple developer documentation](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html#//apple_ref/doc/uid/TP30001266-_webkit_touch_callout)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/border-style/index.md | ---
title: border-style
slug: Web/CSS/border-style
page-type: css-shorthand-property
browser-compat: css.properties.border-style
---
{{CSSRef}}
The **`border-style`** [shorthand](/en-US/docs/Web/CSS/Shorthand_properties) [CSS](/en-US/docs/Web/CSS) property sets the line style for all four sides of an element's border.
{{EmbedInteractiveExample("pages/css/border-style.html")}}
## Constituent properties
This property is a shorthand for the following CSS properties:
- [`border-bottom-style`](/en-US/docs/Web/CSS/border-bottom-style)
- [`border-left-style`](/en-US/docs/Web/CSS/border-left-style)
- [`border-right-style`](/en-US/docs/Web/CSS/border-right-style)
- [`border-top-style`](/en-US/docs/Web/CSS/border-top-style)
## Syntax
```css
/* Keyword values */
border-style: none;
border-style: hidden;
border-style: dotted;
border-style: dashed;
border-style: solid;
border-style: double;
border-style: groove;
border-style: ridge;
border-style: inset;
border-style: outset;
/* top and bottom | left and right */
border-style: dotted solid;
/* top | left and right | bottom */
border-style: hidden double dashed;
/* top | right | bottom | left */
border-style: none solid dotted dashed;
/* Global values */
border-style: inherit;
border-style: initial;
border-style: revert;
border-style: revert-layer;
border-style: unset;
```
The `border-style` property may be specified using one, two, three, or four values.
- When **one** value is specified, it applies the same style to **all four sides**.
- When **two** values are specified, the first style applies to the **top and bottom**, the second to the **left and right**.
- When **three** values are specified, the first style applies to the **top**, the second to the **left and right**, the third to the **bottom**.
- When **four** values are specified, the styles apply to the **top**, **right**, **bottom**, and **left** in that order (clockwise).
Each value is a keyword chosen from the list below.
### Values
- `<line-style>`
- : Describes the style of the border. It can have the following values:
- `none`
- : Like the `hidden` keyword, displays no border. Unless a {{cssxref("background-image")}} is set, the computed value of the same side's {{cssxref("border-width")}} will be `0`, even if the specified value is something else. In the case of table cell and border collapsing, the `none` value has the _lowest_ priority: if any other conflicting border is set, it will be displayed.
- `hidden`
- : Like the `none` keyword, displays no border. Unless a {{cssxref("background-image")}} is set, the computed value of the same side's {{cssxref("border-width")}} will be `0`, even if the specified value is something else. In the case of table cell and border collapsing, the `hidden` value has the _highest_ priority: if any other conflicting border is set, it won't be displayed.
- `dotted`
- : Displays a series of rounded dots. The spacing of the dots is not defined by the specification and is implementation-specific. The radius of the dots is half the computed value of the same side's {{cssxref("border-width")}}.
- `dashed`
- : Displays a series of short square-ended dashes or line segments. The exact size and length of the segments are not defined by the specification and are implementation-specific.
- `solid`
- : Displays a single, straight, solid line.
- `double`
- : Displays two straight lines that add up to the pixel size defined by {{cssxref("border-width")}}.
- `groove`
- : Displays a border with a carved appearance. It is the opposite of `ridge`.
- `ridge`
- : Displays a border with an extruded appearance. It is the opposite of `groove`.
- `inset`
- : Displays a border that makes the element appear embedded. It is the opposite of `outset`. When applied to a table cell with {{cssxref("border-collapse")}} set to `collapsed`, this value behaves like `ridge`.
- `outset`
- : Displays a border that makes the element appear embossed. It is the opposite of `inset`. When applied to a table cell with {{cssxref("border-collapse")}} set to `collapsed`, this value behaves like `groove`.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### All property values
Here is an example of all the property values.
#### HTML
```html
<pre class="b1">none</pre>
<pre class="b2">hidden</pre>
<pre class="b3">dotted</pre>
<pre class="b4">dashed</pre>
<pre class="b5">solid</pre>
<pre class="b6">double</pre>
<pre class="b7">groove</pre>
<pre class="b8">ridge</pre>
<pre class="b9">inset</pre>
<pre class="b10">outset</pre>
```
#### CSS
```css
pre {
height: 80px;
width: 120px;
margin: 20px;
padding: 20px;
display: inline-block;
background-color: palegreen;
border-width: 5px;
box-sizing: border-box;
}
/* border-style example classes */
.b1 {
border-style: none;
}
.b2 {
border-style: hidden;
}
.b3 {
border-style: dotted;
}
.b4 {
border-style: dashed;
}
.b5 {
border-style: solid;
}
.b6 {
border-style: double;
}
.b7 {
border-style: groove;
}
.b8 {
border-style: ridge;
}
.b9 {
border-style: inset;
}
.b10 {
border-style: outset;
}
```
#### Result
{{EmbedLiveSample('All_property_values', "1200", 450)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- The border-related shorthand CSS properties: {{Cssxref("border")}}, {{Cssxref("border-width")}}, {{Cssxref("border-color")}}, {{Cssxref("border-radius")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/box-lines/index.md | ---
title: box-lines
slug: Web/CSS/box-lines
page-type: css-property
status:
- deprecated
- non-standard
browser-compat: css.properties.box-lines
---
{{CSSRef}}{{Non-standard_header}}{{Deprecated_Header}}
> **Warning:** This is a property of the original CSS Flexible Box Layout Module draft. It has been replaced in the specification. See [flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox) for information about the current standard.
The **`box-lines`** [CSS](/en-US/docs/Web/CSS) property determines whether the box may have a single or multiple lines (rows for horizontally oriented boxes, columns for vertically oriented boxes).
By default a horizontal box will lay out its children in a single row, and a vertical box will lay out its children in a single column. This behavior can be changed using the `box-lines` property. The default value is `single`, which means that all elements will be placed in a single row or column, and any elements that don't fit will be considered overflow.
If a value of `multiple` is specified, however, then the box is allowed to expand to multiple lines (that is, multiple rows or columns) in order to accommodate all of its children. The box must attempt to fit its children on as few lines as possible by shrinking all elements down to their minimum widths or heights if necessary.
If the children in a horizontal box still do not fit on a line after being reduced to their minimum widths, then children are moved one by one onto a new line, until the elements remaining on the previous line fit. This process can repeat to an arbitrary number of lines. If a line contains only a single element that doesn't fit, then the element should stay on that line and overflow out of the box. The later lines are placed below the earlier lines in normal direction boxes and above in reverse direction boxes. The height of a line is the height of the largest child in that line. No additional space appears between the lines apart from the margins on the largest elements in each line. For calculating the height of a line, margins with a computed value of auto should be treated as having a value of 0.
A similar process occurs for children in a vertical box. Later lines in normal direction boxes are placed to the right of earlier lines and to the left in reverse direction boxes.
Once the number of lines has been determined, elements with a computed value for {{CSSxRef("box-flex")}} other than `0` stretch as necessary in an attempt to fill the remaining space on the lines. Each line computes flexes independently, so only elements on that line are considered when evaluating {{CSSxRef("box-flex")}} and {{CSSxRef("box-flex-groups")}}. The packing of elements in a line, as specified by the {{CSSxRef("box-pack")}} property, is also computed independently for each line.
## Syntax
```css
/* Keyword values */
box-lines: single;
box-lines: multiple;
/* Global values */
box-lines: inherit;
box-lines: initial;
box-lines: unset;
```
The `box-lines` property is specified as one of the keyword values listed below.
### Values
- `single`
- : Box elements lay out in a single row or column.
- `multiple`
- : Box elements layout in multiple rows or columns.
## Formal definition
{{cssinfo}}
## Formal syntax
```plain
box-lines =
single | multiple
```
## Examples
### Simple usage example
In the original version of the spec, `box-lines` allowed you to specify that you wanted your flex container's children to wrap onto multiple lines. This was only supported in WebKit-based browsers, with a prefix.
```css
div {
display: box;
box-orient: horizontal;
box-lines: multiple;
}
```
The modern flexbox equivalent is [`flex-wrap`](/en-US/docs/Web/CSS/flex-wrap).
## Specifications
Not part of any standard.
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef("flex")}}
- {{CSSxRef("flex-basis")}}
- {{CSSxRef("flex-grow")}}
- {{CSSxRef("flex-shrink")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/font-variant-alternates/ofl.txt | Copyright 2011 The MonteCarlo Project Authors (https://github.com/googlefonts/monte-carlo)
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/font-variant-alternates/index.md | ---
title: font-variant-alternates
slug: Web/CSS/font-variant-alternates
page-type: css-property
browser-compat: css.properties.font-variant-alternates
---
{{CSSRef}}
The **`font-variant-alternates`** CSS property controls the usage of alternate glyphs. These alternate glyphs may be referenced by alternative names defined in {{cssxref("@font-feature-values")}}.
The {{cssxref("@font-feature-values")}} at-rule can be used to associate, for a given font face, a human-readable name with a numeric index that controls a particular OpenType font feature. For features that select alternative glyphs (`stylistic`, `styleset`, `character-variant`, `swash`, `ornament` or `annotation`), the `font-variant-alternates` property can then reference the human-readable name in order to apply the associated feature.
This allows CSS rules to enable alternative glyphs without needing to know the specific index values that a particular font uses to control them.
## Syntax
```css
/* Keyword values */
font-variant-alternates: normal;
font-variant-alternates: historical-forms;
/* Functional notation values */
font-variant-alternates: stylistic(user-defined-ident);
font-variant-alternates: styleset(user-defined-ident);
font-variant-alternates: character-variant(user-defined-ident);
font-variant-alternates: swash(user-defined-ident);
font-variant-alternates: ornaments(user-defined-ident);
font-variant-alternates: annotation(user-defined-ident);
font-variant-alternates: swash(ident1) annotation(ident2);
/* Global values */
font-variant-alternates: inherit;
font-variant-alternates: initial;
font-variant-alternates: revert;
font-variant-alternates: revert-layer;
font-variant-alternates: unset;
```
This property may take one of two forms:
- either the keyword `normal`
- or one or more of the other keywords and functions listed below, space-separated, in any order.
### Values
- `normal`
- : This keyword deactivates alternate glyphs.
- `historical-forms`
- : This keyword enables historical forms — glyphs that were common in the past but not today. It corresponds to the OpenType value `hist`.
- `stylistic()`
- : This function enables stylistic alternates for individual characters. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `salt`, like `salt 2`.
- `styleset()`
- : This function enables stylistic alternatives for sets of characters. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `ssXY`, like `ss02`.
- `character-variant()`
- : This function enables specific stylistic alternatives for characters. It is similar to `styleset()`, but doesn't create coherent glyphs for a set of characters; individual characters will have independent and not necessarily coherent styles. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `cvXY`, like `cv02`.
- `swash()`
- : This function enables [swash](https://en.wikipedia.org/wiki/Swash_%28typography%29) glyphs. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType values `swsh` and `cswh`, like `swsh 2` and `cswh 2`.
- `ornaments()`
- : This function enables ornaments, like [fleurons](https://en.wikipedia.org/wiki/Fleuron_%28typography%29) and other dingbat glyphs. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `ornm`, like `ornm 2`.
> **Note:** In order to preserve text semantics, font designers should include ornaments that don't match Unicode dingbat characters as ornamental variants of the bullet character (U+2022). Be aware that some existing fonts don't follow this advice.
- `annotation()`
- : This function enables annotations, like circled digits or inverted characters. The parameter is a font-specific name mapped to a number. It corresponds to the OpenType value `nalt`, like `nalt 2`.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Enabling swash glyphs
In this example, we use the `@font-feature-values` at-rule to define a name for the `swash` feature of the [MonteCarlo](https://github.com/googlefonts/monte-carlo) font. The rule maps the name `"fancy"` to the index value `1`.
We can then use that name inside `font-variant-alternates` to switch on swashes for that font. This is the equivalent of a line like `font-feature-settings: "swsh" 1`, except that the CSS applying the feature does not need to include, or even know, the index value needed for this particular font.
#### HTML
```html
<p>A Fancy Swash</p>
<p class="variant">A Fancy Swash</p>
```
#### CSS
```css
@font-face {
font-family: MonteCarlo;
src: url("montecarlo-regular.woff2");
}
@font-feature-values "MonteCarlo" {
@swash {
fancy: 1;
}
}
p {
font-family: "MonteCarlo";
font-size: 3rem;
margin: 0.7rem 3rem;
}
.variant {
font-variant-alternates: swash(fancy);
}
```
#### Result
{{EmbedLiveSample("Enabling swash glyphs", 0, 230)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [`font-variant`](/en-US/docs/Web/CSS/font-variant)
- [`font-variant-caps`](/en-US/docs/Web/CSS/font-variant-caps)
- [`font-variant-east-asian`](/en-US/docs/Web/CSS/font-variant-east-asian)
- [`font-variant-emoji`](/en-US/docs/Web/CSS/font-variant-emoji)
- [`font-variant-ligatures`](/en-US/docs/Web/CSS/font-variant-ligatures)
- [`font-variant-numeric`](/en-US/docs/Web/CSS/font-variant-numeric)
- [`font-variant-position`](/en-US/docs/Web/CSS/font-variant-position)
- [`@font-feature-values`](/en-US/docs/Web/CSS/@font-feature-values)
- [`font-feature-settings`](/en-US/docs/Web/CSS/font-feature-settings)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/list-style-position/index.md | ---
title: list-style-position
slug: Web/CSS/list-style-position
page-type: css-property
browser-compat: css.properties.list-style-position
---
{{CSSRef}}
The **`list-style-position`** [CSS](/en-US/docs/Web/CSS) property sets the position of the {{cssxref("::marker")}} relative to a list item.
{{EmbedInteractiveExample("pages/css/list-style-position.html")}}
## Syntax
```css
/* Keyword values */
list-style-position: inside;
list-style-position: outside;
/* Global values */
list-style-position: inherit;
list-style-position: initial;
list-style-position: revert;
list-style-position: revert-layer;
list-style-position: unset;
```
The `list-style-position` property is specified as one of the keyword values listed below.
### Values
- `inside`
- : The {{cssxref("::marker")}} is the first element among the list item's contents.
- `outside`
- : The {{cssxref("::marker")}} is outside the principal block box. This is the default value for {{cssxref("list-style")}}.
## Description
This property is applied to list items, i.e., elements with `{{cssxref("display")}}: list-item;`. [By default](https://html.spec.whatwg.org/multipage/rendering.html#lists) this includes {{HTMLElement("li")}} elements. Because this property is inherited, it can be set on the parent element (normally {{HTMLElement("ol")}} or {{HTMLElement("ul")}}) to let it apply to all list items.
If a block element is the first child of a list element declared as `list-style-position: inside`, then the block element is placed on the line after the marker-box.
It is often more convenient to use the shorthand {{cssxref("list-style")}}.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting list item position
#### HTML
```html
<ul class="inside">
List 1
<li>List Item 1-1</li>
<li>List Item 1-2</li>
<li>List Item 1-3</li>
<li>List Item 1-4</li>
</ul>
<ul class="outside">
List 2
<li>List Item 2-1</li>
<li>List Item 2-2</li>
<li>List Item 2-3</li>
<li>List Item 2-4</li>
</ul>
<ul class="inside-img">
List 3
<li>List Item 3-1</li>
<li>List Item 3-2</li>
<li>List Item 3-3</li>
<li>List Item 3-4</li>
</ul>
```
#### CSS
```css
.inside {
list-style-position: inside;
list-style-type: square;
}
.outside {
list-style-position: outside;
list-style-type: circle;
}
.inside-img {
list-style-position: inside;
list-style-image: url("starsolid.gif");
}
```
#### Result
{{EmbedLiveSample("Setting_list_item_position", 200, 420)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{Cssxref("list-style")}} shorthand
- {{Cssxref("list-style-type")}} property
- {{Cssxref("list-style-image")}} property
- {{cssxref("::marker")}} pseudo-element
- [CSS lists and counters](/en-US/docs/Web/CSS/CSS_lists) module
- [CSS counter styles](/en-US/docs/Web/CSS/CSS_counter_styles) module
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/child_combinator/index.md | ---
title: Child combinator
slug: Web/CSS/Child_combinator
page-type: css-combinator
browser-compat: css.selectors.child
---
{{CSSRef}}
The **child combinator** (`>`) is placed between two CSS selectors. It matches only those elements matched by the second selector that are the direct children of elements matched by the first.
```css
/* List items that are children of the "my-things" list */
ul.my-things > li {
margin: 2em;
}
```
Elements matched by the second selector must be the immediate children of the elements matched by the first selector. This is stricter than the [descendant combinator](/en-US/docs/Web/CSS/Descendant_combinator), which matches all elements matched by the second selector for which there exists an ancestor element matched by the first selector, regardless of the number of "hops" up the DOM.
## Syntax
```css-nolint
/* The white space around the > combinator is optional but recommended. */
selector1 > selector2 { /* style properties */ }
```
## Examples
### CSS
```css
span {
background-color: aqua;
}
div > span {
background-color: yellow;
}
```
### HTML
```html
<div>
<span>
Span #1, in the div.
<span>Span #2, in the span that's in the div.</span>
</span>
</div>
<span>Span #3, not in the div at all.</span>
```
### Result
{{EmbedLiveSample("Examples", "100%", 100)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Descendant combinator](/en-US/docs/Web/CSS/Descendant_combinator)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/css_selectors/index.md | ---
title: CSS selectors
slug: Web/CSS/CSS_selectors
page-type: css-module
spec-urls: https://drafts.csswg.org/selectors/
---
{{CSSRef}}
The **CSS selectors** module defines the patterns to select elements to which a set of CSS rules are then applied along with their {{cssxref("specificity")}}. The CSS selectors module provides us with more than 60 selectors and five combinators. [Other modules](#related_concepts) provide additional pseudo-class selectors and pseudo-elements.
In CSS, selectors are patterns used to match, or select, the elements you want to style. Selectors are also used in JavaScript to enable selecting the DOM nodes to return as a [`NodeList`](/en-US/docs/Web/API/NodeList).
Selectors, whether used in CSS or JavaScript, enable targeting HTML elements based on their type, attributes, current states, and even position in the DOM. Combinators allow you to be more precise when selecting elements by enabling selecting elements based on their relationship to other elements.
## Reference
### Combinators and separators
- `+` ([Next-sibling combinator](/en-US/docs/Web/CSS/Next-sibling_combinator))
- `>` ([Child combinator](/en-US/docs/Web/CSS/Child_combinator))
- `||` ([Column combinator](/en-US/docs/Web/CSS/Column_combinator)) {{Experimental_Inline}}
- `~` ([Subsequent sibling combinator](/en-US/docs/Web/CSS/Subsequent-sibling_combinator))
- " " ([Descendant combinator](/en-US/docs/Web/CSS/Descendant_combinator))
- `|` ([Namespace separator](/en-US/docs/Web/CSS/Namespace_separator))
### Selectors
- {{CSSXref(":active")}}
- {{CSSXref(":any-link")}}
- {{CSSXref(":autofill")}}
- {{CSSXref(":blank")}}
- {{CSSXref(":buffering")}}
- {{CSSXref(":checked")}}
- {{CSSXref(":current")}}
- {{CSSXref(":current", ":current()")}}
- {{CSSXref(":default")}}
- {{CSSXref(":defined")}}
- {{CSSXref(":dir", ":dir()")}}
- {{CSSXref(":disabled")}}
- {{CSSXref(":empty")}}
- {{CSSXref(":enabled")}}
- {{CSSXref(":first-child")}}
- {{CSSXref(":first-of-type")}}
- {{CSSXref(":focus")}}
- {{CSSXref(":focus-visible")}}
- {{CSSXref(":focus-within")}}
- {{CSSXref(":fullscreen")}}
- {{CSSXref(":future")}}
- {{CSSXref(":has", ":has()")}}
- {{CSSXref(":hover")}}
- {{CSSXref(":indeterminate")}}
- {{CSSXref(":in-range")}}
- {{CSSXref(":invalid")}}
- {{CSSXref(":is", ":is()")}}
- {{CSSXref(":lang", ":lang()")}}
- {{CSSXref(":last-child")}}
- {{CSSXref(":last-of-type")}}
- {{CSSXref(":link")}}
- {{CSSXref(":local-link")}}
- `:matches()` (obsolete legacy selector alias for {{CSSXref( ":is", ":is()")}})
- {{CSSXref(":modal")}}
- {{CSSXref(":muted")}}
- {{CSSXref(":not", ":not()")}}
- {{CSSXref(":nth-child", ":nth-child()")}}
- {{CSSXref(":nth-of-type", ":nth-of-type()")}}
- {{CSSXref(":nth-last-child", ":nth-last-child()")}}
- {{CSSXref(":nth-last-of-type", ":nth-last-of-type()")}}
- {{CSSXref(":only-child")}}
- {{CSSXref(":only-of-type")}}
- {{CSSXref(":optional")}}
- {{CSSXref(":out-of-range")}}
- {{CSSXref(":past")}}
- {{CSSXref(":paused")}}
- {{CSSXref(":picture-in-picture")}}
- {{CSSXref(":placeholder-shown")}}
- {{CSSXref(":playing")}}
- {{CSSXref(":read-only")}}
- {{CSSXref(":read-write")}}
- {{CSSXref(":required")}}
- {{CSSXref(":root")}}
- {{CSSXref(":scope")}}
- {{CSSXref(":seeking")}}
- {{CSSXref(":stalled")}}
- {{CSSXref(":target")}}
- {{CSSXref(":target-within")}}
- {{CSSXref(":user-invalid")}}
- {{CSSXref(":user-valid")}}
- {{CSSXref(":valid")}}
- {{CSSXref(":visited")}}
- {{CSSXref(":volume-locked")}}
- {{CSSXref(":where", ":where()")}}
- [`:-webkit-` pseudo-classes](/en-US/docs/Web/CSS/WebKit_Extensions#pseudo-classes)
- [Attribute selectors](/en-US/docs/Web/CSS/Attribute_selectors)
- [Class selector](/en-US/docs/Web/CSS/Class_selectors)
- [ID selectors](/en-US/docs/Web/CSS/ID_selectors)
- [Type selectors](/en-US/docs/Web/CSS/Type_selectors)
- [Universal selectors](/en-US/docs/Web/CSS/Universal_selectors)
## Terms
- {{glossary("Pseudo-class")}} glossary term
- [Functional pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes#functional_pseudo-classes)
- [Combinators](/en-US/docs/Web/CSS/CSS_selectors/Selectors_and_combinators#combinators)
- [Simple selector](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#simple_selector)
- [Compound selector](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#compound_selector)
- [Complex selector](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#complex_selector)
- [Relative selector](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#relative_selector)
- [Selector list](/en-US/docs/Web/CSS/Selector_list)
- [Specificity](/en-US/docs/Web/CSS/Specificity)
## Guides
- [CSS selectors and combinators](/en-US/docs/Web/CSS/CSS_selectors/Selectors_and_combinators)
- : Overview of the different types of simple selectors and various combinators defined in the CSS selectors and the CSS pseudo modules.
- [CSS selector structure](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure)
- : Explanation of the structure of CSS selectors and the terminologies introduced in the CSS selectors module, ranging from "simple selector" to "forgiving relative selector list".
- [Pseudo classes](/en-US/docs/Web/CSS/Pseudo-classes)
- : Lists the pseudo-classes, selectors that allow the selection of elements based on state information that is not contained in the document tree, defined in the various CSS modules and HTML.
- [Learn: CSS selectors](/en-US/docs/Learn/CSS/Building_blocks/Selectors)
- : Part of CSS building blocks, includes tutorials on [Type, class, and ID selectors](/en-US/docs/Learn/CSS/Building_blocks/Selectors/Type_Class_and_ID_Selectors), [Attribute selectors](/en-US/docs/Learn/CSS/Building_blocks/Selectors/Attribute_selectors), [Pseudo-classes and pseudo-elements](/en-US/docs/Learn/CSS/Building_blocks/Selectors/Pseudo-classes_and_pseudo-elements), [Combinators](/en-US/docs/Learn/CSS/Building_blocks/Selectors/Combinators), [Cascade, specificity, and inheritance](/en-US/docs/Learn/CSS/Building_blocks/Cascade_and_inheritance), and [Cascade layers](/en-US/docs/Learn/CSS/Building_blocks/Cascade_layers).
- [Using the `:target` pseudo-class in selectors](/en-US/docs/Web/CSS/CSS_selectors/Using_the_:target_pseudo-class_in_selectors)
- : Learn how to use the {{CSSXref(":target")}} pseudo-class to style the target element a URL's fragment identifier.
- [Learn: UI pseudo-classes](/en-US/docs/Learn/Forms/UI_pseudo-classes)
- : Learn the different UI pseudo-classes available for styling forms in different states.
- [Locating DOM elements using selectors](/en-US/docs/Web/API/Document_object_model/Locating_DOM_elements_using_selectors)
- : The selectors API enables using selectors in JavaScript to retrieve element nodes from the DOM.
## Related concepts
- {{CSSXref(":popover-open")}} pseudo-class
- {{CSSXref(":state","state()")}} pseudo-class
- [CSS nesting](/en-US/docs/Web/CSS/CSS_nesting) module
- : [`&` nesting selector](/en-US/docs/Web/CSS/Nesting_selector)
- [CSS scoping](/en-US/docs/Web/CSS/CSS_scoping) module
- {{CSSXref(":host")}} pseudo-class
- {{CSSXref(":host_function", ":host()")}} pseudo-class
- {{cssxref(":host-context", ":host-context()")}} pseudo-class
- {{CSSXref("::slotted")}} pseudo-element
- [CSS pseudo-element module](/en-US/docs/Web/CSS/CSS_pseudo-elements) (representing entities not included in HTML)
- {{CSSXref("::after")}}
- {{CSSXref("::before")}}
- {{CSSXref("::file-selector-button")}}
- {{CSSXref("::first-letter")}}
- {{CSSXref("::first-line")}}
- {{CSSXref("::grammar-error")}}
- {{CSSXref("::marker")}}
- {{CSSXref("::placeholder")}}
- {{CSSXref("::selection")}}
- {{CSSXref("::spelling-error")}}
- {{CSSXref("::target-text")}}
- [CSS shadow parts module](/en-US/docs/Web/CSS/CSS_shadow_parts)
- {{CSSXref("::part")}} pseudo-element
- [CSS positioned layout module](/en-US/docs/Web/CSS/CSS_positioned_layout)
- {{CSSxRef("::backdrop")}}
- Other [pseudo-elements](/en-US/docs/Web/CSS/Pseudo-elements)
- {{CSSxRef("::cue")}}
- {{CSSxRef("::cue-region")}}
- {{CSSXref("@namespace")}} at-rule
- {{cssxref("important", "!important")}}
- [Specificity](/en-US/docs/Web/CSS/Specificity)
- [Cascade](/en-US/docs/Web/CSS/Cascade)
- {{domxref("Document.querySelector")}} method
- {{domxref("Document.querySelectorAll")}} method
- {{domxref("NodeList.forEach()")}} method
## Specifications
{{Specifications}}
## See also
- [CSS pseudo-element module](/en-US/docs/Web/CSS/CSS_pseudo-elements)
- [CSS cascade and inheritance module](/en-US/docs/Web/CSS/CSS_cascade)
- [CSS nesting module](/en-US/docs/Web/CSS/CSS_nesting)
- [Using shadow DOM](/en-US/docs/Web/API/Web_components/Using_shadow_DOM)
| 0 |
data/mdn-content/files/en-us/web/css/css_selectors | data/mdn-content/files/en-us/web/css/css_selectors/selectors_and_combinators/index.md | ---
title: CSS selectors and combinators
slug: Web/CSS/CSS_selectors/Selectors_and_combinators
page-type: guide
spec-urls:
- https://drafts.csswg.org/selectors/
- https://drafts.csswg.org/css-pseudo/
---
{{CSSRef}}
CSS selectors are used to define a pattern of the elements that you want to select for applying a set of CSS rules on the selected elements. Combinators define the relationship between the selectors. Using various selectors and combinators, you can precisely select and style the desired elements based on their type, attributes, state, or relationship to other elements.
## Types of selectors
There are over 80 selectors and combinators. CSS selectors can be grouped into the following categories based on the type of elements they can select.
### Basic selectors
The [type selector](/en-US/docs/Web/CSS/Type_selectors) selects all elements that have the given node name. For example, `div` will select all {{HTMLElement("div")}} elements and `input` will match any {{HTMLElement("input")}} element. The [universal selector](/en-US/docs/Web/CSS/Universal_selectors), denoted with an asterisk (`*`), is a special type selector that selects all elements.
The [class selector](/en-US/docs/Web/CSS/Class_selectors) selects all elements that have the given `class` attribute denoted by the class name prefixed with a period (`.`). For example, `.index` will match any element that has `class="index"`. The [ID selector](/en-US/docs/Web/CSS/ID_selectors) selects an element based on the value of its `id` attribute. The selector is the `id` prefixed with a "number sign" (U+0023, `#`). For example, `#toc` will match the element that has `id="toc"`. Both [`class`](/en-US/docs/Web/HTML/Global_attributes/class) and [`id`](/en-US/docs/Web/HTML/Global_attributes/id) are global attributes. There should be only one element with a given `id` in a document; but if there is more than one, the ID selector will match all the elements with that `id`.
When combining a type or universal selector with a class or id selector to create a [compound selector](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#compound_selector), the type or universal selector must precede the class or id.
#### CSS
In this example, we declare four [simple selectors](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#simple_selector) and one [compound selector](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#compound_selector) using the four basic selector types, as described above.
```css
* {
font-style: italic;
}
p {
color: red;
}
.myClass {
text-decoration: underline;
}
#myId {
font-family: monospace;
}
p.myClass#myId {
font-size: 1.5rem;
}
```
#### HTML
```html
<p class="myClass" id="myId">I match everything.</p>
<p>I match the universal and type selectors only.</p>
```
#### Result
{{EmbedLiveSample("Basic selectors", "100%", 100)}}
## Combinators
Using CSS combinators, we can combine selectors to select DOM nodes based on their relationship to other elements within the document node tree. This combining of selectors with combinators creates [complex selectors](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#complex_selector).
### Descendant combinator
The [descendant combinator](/en-US/docs/Web/CSS/Descendant_combinator), denoted with one or more spaces, selects nodes that are descendants of the first element. For example, `div span` will match all {{HTMLElement("span")}} elements that are inside a {{HTMLElement("div")}} element.
### Child combinator
The [child combinator](/en-US/docs/Web/CSS/Child_combinator) is more specific than the descendant combinator. Denoted with the greater than character (`>`), the child combinator selects nodes that are direct children of the first element. Comparing with our previous example, `div > span` will match only the {{HTMLElement("span")}} elements that are direct children of a {{HTMLElement("div")}} element.
### Subsequent-sibling combinator
In addition to descendant selectors, CSS also enables selecting elements based on their siblings. The [subsequent-sibling combinator](/en-US/docs/Web/CSS/Subsequent-sibling_combinator), denoted with a tilde (`~`), selects siblings. Given `A ~ B`, all elements matching `B` will be selected if they are preceded by `A`, provided both `A` and `B` share the same parent. For example, `h2 ~ p` will match all {{HTMLElement("p")}} elements that follow an {{HTMLElement("Heading_Elements", "h2")}}, immediately or not.
### Next-sibling combinator
The [next-sibling combinator](/en-US/docs/Web/CSS/Next-sibling_combinator), denoted by the plus symbol (`+`), is similar to the subsequent-sibling. However, given `A + B`, it only matches `B` if `B` is immediately preceded by `A`, with both sharing the same parent. Amending our previous example, `h2 + p` will match only the single `<p>` element that _immediately_ follows an `<h2>` element.
### Column combinator
There is also a [column combinator](/en-US/docs/Web/CSS/Column_combinator), denoted by two pipe characters (`||`), which, when supported, selects nodes that belong to a column. For example, `col || td` will match all {{HTMLElement("td")}} elements that belong to the scope of the {{HTMLElement("col")}}.
### Namespace separator
The [namespace separator](/en-US/docs/Web/CSS/Namespace_separator) is another combinator that is generally used in conjunction with the {{CSSXref("@namespace")}} at-rule. This combinator is denoted by a single pipe character (`|`). It enables limiting [type selectors](/en-US/docs/Web/CSS/Type_selectors) and the [universal selector](/en-US/docs/Web/CSS/Universal_selectors) to a specific namespace. For example, by defining a namespace such as `@namespace SVG url('http://www.w3.org/2000/svg');`, you can include selectors that target elements nested in an SVG namespace only. Declaring `SVG|a` would match links within SVGs and not those in the rest of the document. Namespacing can be useful to target MathML, SVG, or other XML-based content within your HTML.
#### CSS
In this example, we declare five [relative selectors](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#relative_selector) using [simple selectors](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#simple_selector) combined with combinators.
```css
h2 + p ~ p {
font-style: italic;
}
h2 + p + p {
color: red;
}
.myClass + p {
text-decoration: underline;
}
#myId > .myClass {
outline: 3px dashed red;
}
> p {
font-size: 1.1rem;
}
```
#### HTML
```html
<h2 class="myClass" id="myId">
No selectors match. <span class="myClass">This span has an outline</span> as
it is both myClass and a child of #myId.
</h2>
<p>The first paragraph is underlined. All the paragraphs are 1.1rem.</p>
<p>
The second paragraph is red. This and the following paragraphs are italic.
</p>
<p>The third paragraph is NOT red. It is italic and 1.1rem.</p>
<p class="myClass">
Does not have an outline; this is a sibling of H2, not a child. It is italic
and 1.1rem.
</p>
```
#### Result
{{EmbedLiveSample("Combinators", "100%", 300)}}
### Creating complex selectors with CSS nesting
The above complex selectors can also be defined using simple selectors, combinators, and [CSS nesting](/en-US/docs/Web/CSS/CSS_nesting), with or without the [`&` nesting selector](/en-US/docs/Web/CSS/Nesting_selector).
#### CSS
In this example, we replicate the same five relative selectors using simple selectors combined with combinators, but this time with CSS nesting.
```css
h2 {
& + p {
& ~ p {
font-style: italic;
}
& + p {
color: red;
}
}
}
.myClass {
& + p {
text-decoration: underline;
}
}
#myId {
& > .myClass {
outline: 3px dashed red;
}
}
> p {
font-size: 1.1rem;
}
```
#### HTML
```html
<h2 class="myClass" id="myId">
No selectors match. <span class="myClass">This span has an outline</span> as
it is both myClass and a child of #myId.
</h2>
<p>The first paragraph is underlined. All the paragraphs are 1.1rem.</p>
<p>
The second paragraph is red. This and the following paragraphs are italic.
</p>
<p>The third paragraph is NOT red. It is italic and 1.1rem.</p>
<p class="myClass">
Does not have an outline; this is a sibling of H2, not a child. It is italic
and 1.1rem.
</p>
```
#### Result
{{EmbedLiveSample("creating_complex_selectors_with_css_nesting", "100%", 300)}}
## Attribute selectors
[Attribute selectors](/en-US/docs/Web/CSS/Attribute_selectors) select all elements that, depending on how the selector is written, either have the given attribute or have the given attribute with a substring value match.
For example, `[type]` will match all elements that have the `type` attribute set (to any value), and `[type="submit"]` will match `<input type="submit">` and `<button type="submit">`, or any element with `type="submit"` set, even though this attribute-value pair is only supported on {{HTMLElement("input")}} and {{HTMLElement("button")}} elements. The match is case-insensitive.
The case sensitivity of the attribute depends on the language. Generally, in HTML, if an attribute is {{glossary("enumerated")}}, the value in the selector is case-insensitive, even if the value is not one of the enumerated values or if the attribute is not a valid value for the element on which it is set. For non-enumerated attributes, like `class`, `id`, or any `data-*` attribute, or for non-HTML attributes, like `role` or `aria-*` attributes, the value match is case-sensitive; the match can be made case-insensitive with a case-insensitive modifier (`i`).
## Pseudo-class selectors
The [CSS selectors](/en-US/docs/Web/CSS/CSS_selectors) module defines over 60 [pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes). Pseudo-classes are [simple selectors](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#simple_selector), prefixed with a colon (`:`), that allow the selection of elements based on state information that is not contained in the document tree. {{CSSxRef("pseudo-classes")}} can be used to style an element based on its _state_.
For example, the {{cssxref(":target")}} simple selector targets element of a URL containing a fragment identifier, and the [`a:visited`](/en-US/docs/Web/CSS/:visited) [compound selector](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#compound_selector) matches all {{HTMLElement("a")}} elements that have been visited by a user.
The pseudo-classes can be categorized as [element display state](/en-US/docs/Web/CSS/Pseudo-classes#element_display_state_pseudo-classes), [input](/en-US/docs/Web/CSS/Pseudo-classes#input_pseudo-classes), [linguistic](/en-US/docs/Web/CSS/Pseudo-classes#linguistic_pseudo-classes), [location](/en-US/docs/Web/CSS/Pseudo-classes#location_pseudo-classes), [resource state](/en-US/docs/Web/CSS/Pseudo-classes#resource_state_pseudo-classes), [time-dimensional](/en-US/docs/Web/CSS/Pseudo-classes#time-dimensional_pseudo-classes), [tree-structural](/en-US/docs/Web/CSS/Pseudo-classes#tree-structural_pseudo-classes), [user action](/en-US/docs/Web/CSS/Pseudo-classes#user_action_pseudo-classes), and [functional](/en-US/docs/Web/CSS/Pseudo-classes#functional_pseudo-classes).
Multiple pseudo-classes can be combined to create [compound selectors](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#compound_selector). When combining a pseudo-class into a compound selector with a type or universal selector, the pseudo-class must follow the type selector or universal selector, if present.
## Pseudo-element selectors
Not all CSS selectors are defined in the [CSS selectors module](/en-US/docs/Web/CSS). CSS pseudo-element selectors are defined in the [CSS pseudo-elements](/en-US/docs/Web/CSS/CSS_pseudo-elements) module.
CSS [pseudo-elements](/en-US/docs/Web/CSS/Pseudo-elements), prefixed with two colons (`::`), represent entities that are not included in HTML. For example, the simple {{cssxref("::marker")}} selector selects list item bullets, and the compound selector [`p::first-line`](/en-US/docs/Web/CSS/::first-line) matches the first line of all {{HTMLElement("p")}} elements.
## Specifications
{{Specifications}}
See the [pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes#specifications) and [pseudo-elements](/en-US/docs/Web/CSS/Pseudo-elements#specifications) specification tables for details on those.
## See also
- [Selector list](/en-US/docs/Web/CSS/Selector_list)
- [CSS selector structure](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure)
- [Specificity](/en-US/docs/Web/CSS/Specificity)
- [CSS nesting module](/en-US/docs/Web/CSS/CSS_nesting)
| 0 |
data/mdn-content/files/en-us/web/css/css_selectors | data/mdn-content/files/en-us/web/css/css_selectors/selector_structure/index.md | ---
title: CSS selector structure
slug: Web/CSS/CSS_selectors/Selector_structure
page-type: guide
spec-urls: https://drafts.csswg.org/selectors/
---
{{CSSRef}}
The CSS selector represents a particular pattern of element or elements in a tree structure. The term "selector" can refer to a [simple selector](#simple_selector), a [compound selector](#compound_selector), or a [complex selector](#complex_selector). When included in the `:has()` pseudo-class as a parameter, these selectors are referred to as [relative selectors](#relative_selector), representing elements relative to one or more anchor elements.
These selectors can be combined into a comma-separated [selector list](#selector_list). If any selector in a [non-forgiving selector](/en-US/docs/Web/CSS/Selector_list#valid_and_invalid_selector_lists) list is invalid, the entire selector list is invalidated.
### Simple selector
A **simple selector** is a selector with a single component, such as a single type selector, attribute selector, or pseudo-class, that's not used in combination with or contains any other selector component or combinator. A given element is said to match a simple selector when that simple selector accurately describes the element. Any selector that contains a single [basic selector](/en-US/docs/Web/CSS/CSS_selectors/Selectors_and_combinators#basic_selectors), [attribute selector](/en-US/docs/Web/CSS/Attribute_selectors), [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes), or [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) selector is a simple selector.
```css
#myId {
}
[pattern*="\d"] {
}
```
### Compound selector
A **compound selector** is a sequence of [simple selectors](#simple_selector) that are not separated by a [combinator](/en-US/docs/Web/CSS/CSS_selectors/Selectors_and_combinators#combinators). A compound selector represents a set of simultaneous conditions on a single element. A given element is said to match a compound selector when the element matches all the simple selectors in the compound selector.
```css
a#selected {
}
[type="checkbox"]:checked:focus {
}
```
In a compound selector, the [type selector](/en-US/docs/Web/CSS/Type_selectors) or [universal selector](/en-US/docs/Web/CSS/Universal_selectors) must come first in the sequence of selectors. Only one type selector or universal selector is allowed in the sequence. As whitespace represents the [descendant combinator](/en-US/docs/Web/CSS/Descendant_combinator), no whitespace is allowed between the simple selectors that make up a compound selector.
### Complex selector
A **complex selector** is a sequence of one or more simple and/or compound selectors that are separated by combinators, including the white space [descendant combinator](/en-US/docs/Web/CSS/Descendant_combinator).
A complex selector represents a set of simultaneous conditions on a set of elements.
```css
a#selected > .icon {
}
.box h2 + p {
}
```
Selectors can be read from right to left. For example, `a#selected > .icon` matches all elements with a class of `icon` that are the direct children of the `<a>` element with the id `selected`. The selector `.box h2 + p` matches the first `<p>`s to come immediately after any `<h2>` elements that are descendants of any element with the class of `box`.
### Relative selector
A **relative selector** is a selector representing an element relative to one or more anchor elements preceded by a combinator. Relative selectors that don't begin with an explicit combinator have an implied [descendant combinator](/en-US/docs/Web/CSS/Descendant_combinator).
```css
+ div#topic > #reference {
}
> .icon {
}
dt:has(+ img) ~ dd {
}
```
### Selector list
A [**selector list**](/en-US/docs/Web/CSS/Selector_list) is a comma-separated list of simple, compound, and/or complex selectors. A given element is said to match a selector list when the element matches any (at least one) of the selectors in that selector list.
```css
#main,
article.heading {
}
```
If any selector in a [non-forgiving selector](/en-US/docs/Web/CSS/Selector_list#valid_and_invalid_selector_lists) list is invalid, the entire selector list is invalidated.
```css
#main,
:bad-pseudoclass,
.validClass {
/* `:bad-pseudoclass` is invalid, invalidating this style block */
}
```
The {{cssxref(":is", ":is()")}} and {{cssxref(":where", ":where()")}} pseudo-classes can be used to construct [forgiving selector lists](/en-US/docs/Web/CSS/Selector_list#forgiving_selector_list).
## Specifications
{{Specifications}}
## See also
- [CSS selectors and combinators](/en-US/docs/Web/CSS/CSS_selectors/Selectors_and_combinators)
- [Forgiving selector list](/en-US/docs/Web/CSS/Selector_list#forgiving_selector_list)
- {{DOMXref("Document.querySelector()")}}
- {{DOMXref("Document.querySelectorAll()")}}
- [CSS selectors](/en-US/docs/Web/CSS/CSS_selectors) module
- [CSS pseudo-elements](/en-US/docs/Web/CSS/CSS_pseudo-elements) module
| 0 |
data/mdn-content/files/en-us/web/css/css_selectors | data/mdn-content/files/en-us/web/css/css_selectors/using_the__colon_target_pseudo-class_in_selectors/index.md | ---
title: Using the :target pseudo-class in selectors
slug: Web/CSS/CSS_selectors/Using_the_:target_pseudo-class_in_selectors
page-type: guide
---
{{CSSRef}}
When a URL points at a specific piece of a document, it can be difficult for the user to notice. Find out how you can use some simple CSS to draw attention to the target of a URL and improve the user's experience.
## Picking a Target
The [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) {{cssxref(":target")}} is used to style the target element of a URL containing a fragment identifier. For example, the URL `https://developer.mozilla.org/en-US/docs/Web/CSS#reference` contains the fragment identifier `#reference`. In HTML, identifiers are found as the values of either `id` or `name` attributes, since the two share the same namespace. Thus, the example URL would point to the heading "reference" in that document.
Suppose you wish to style any `h2` element that is the target of a URL, but do not want any other kind of element to get a target style. This is simple enough:
```css
h2:target {
outline: 2px solid;
}
```
It's also possible to create styles that are specific to a particular fragment of the document. This is done using the same identifying value that is found in the URI. Thus, to add a background color to the `#reference` fragment, we would write:
```css
#reference:target {
background-color: yellow;
}
```
## Targeting all elements
If the intent is to create a "blanket" style that will apply to all targeted elements, then the universal selector comes in handy:
```css
:target {
color: red;
}
```
## Example
In the following example, there are five links that point to elements in the same document. Selecting the "First" link, for example, will cause `<h1 id="one">` to become the target element. Note that the document may jump to a new scroll position, since target elements are placed on the top of the browser window if possible.
```html
<h4 id="one">…</h4>
<p id="two">…</p>
<div id="three">…</div>
<a id="four">…</a> <em id="five">…</em>
<a href="#one">First</a>
<a href="#two">Second</a>
<a href="#three">Third</a>
<a href="#four">Fourth</a>
<a href="#five">Fifth</a>
```
## Conclusion
In cases where a fragment identifier points to a portion of the document, readers may become confused about which part of the document they're supposed to be reading. By styling the target of a URI, reader confusion can be reduced or eliminated.
## See also
- {{cssxref(":target")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/position/index.md | ---
title: position
slug: Web/CSS/position
page-type: css-property
browser-compat: css.properties.position
---
{{CSSRef}}
The **`position`** [CSS](/en-US/docs/Web/CSS) property sets how an element is positioned in a document. The {{Cssxref("top")}}, {{Cssxref("right")}}, {{Cssxref("bottom")}}, and {{Cssxref("left")}} properties determine the final location of positioned elements.
{{EmbedInteractiveExample("pages/css/position.html")}}
## Syntax
```css
position: static;
position: relative;
position: absolute;
position: fixed;
position: sticky;
/* Global values */
position: inherit;
position: initial;
position: revert;
position: revert-layer;
position: unset;
```
### Values
- `static`
- : The element is positioned according to the normal flow of the document. The {{cssxref("top")}}, {{cssxref("right")}}, {{cssxref("bottom")}}, {{cssxref("left")}}, and {{cssxref("z-index")}} properties have _no effect_. This is the default value.
- `relative`
- : The element is positioned according to the normal flow of the document, and then offset _relative to itself_ based on the values of `top`, `right`, `bottom`, and `left`. The offset does not affect the position of any other elements; thus, the space given for the element in the page layout is the same as if position were `static`.
This value creates a new [stacking context](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context) when the value of `z-index` is not `auto`. Its effect on `table-*-group`, `table-row`, `table-column`, `table-cell`, and `table-caption` elements is undefined.
- `absolute`
- : The element is removed from the normal document flow, and no space is created for the element in the page layout. The element is positioned relative to its closest positioned ancestor (if any) or to the initial [containing block](/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block). Its final position is determined by the values of `top`, `right`, `bottom`, and `left`.
This value creates a new [stacking context](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context) when the value of `z-index` is not `auto`. The margins of absolutely positioned boxes do not [collapse](/en-US/docs/Web/CSS/CSS_box_model/Mastering_margin_collapsing) with other margins.
- `fixed`
- : The element is removed from the normal document flow, and no space is created for the element in the page layout. The element is positioned relative to its initial [containing block](/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block), which is the viewport in the case of visual media. Its final position is determined by the values of `top`, `right`, `bottom`, and `left`.
This value always creates a new [stacking context](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context). In printed documents, the element is placed in the same position on _every page_.
- `sticky`
- : The element is positioned according to the normal flow of the document, and then offset relative to its _nearest scrolling ancestor_ and [containing block](/en-US/docs/Web/CSS/Containing_block) (nearest block-level ancestor), including table-related elements, based on the values of `top`, `right`, `bottom`, and `left`. The offset does not affect the position of any other elements.
This value always creates a new [stacking context](/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context). Note that a sticky element "sticks" to its nearest ancestor that has a "scrolling mechanism" (created when `overflow` is `hidden`, `scroll`, `auto`, or `overlay`), even if that ancestor isn't the nearest actually scrolling ancestor.
> **Note:** At least one [inset](/en-US/docs/Web/CSS/inset) property ({{cssxref("top")}}, {{cssxref("inset-block-start")}}, {{cssxref("right")}}, {{cssxref("inset-inline-end")}}, etc.) needs to be set to a non-`auto` value for the axis on which the element needs to be made sticky. If both `inset` properties for an axis are set to `auto`, on that axis the `sticky` value will behave as `relative`.
## Description
### Types of positioning
- A **positioned element** is an element whose [computed](/en-US/docs/Web/CSS/computed_value) `position` value is either `relative`, `absolute`, `fixed`, or `sticky`. (In other words, it's anything except `static`.)
- A **relatively positioned element** is an element whose [computed](/en-US/docs/Web/CSS/computed_value) `position` value is `relative`. The {{Cssxref("top")}} and {{Cssxref("bottom")}} properties specify the vertical offset from its normal position; the {{Cssxref("left")}} and {{Cssxref("right")}} properties specify the horizontal offset.
- An **absolutely positioned element** is an element whose [computed](/en-US/docs/Web/CSS/computed_value) `position` value is `absolute` or `fixed`. The {{Cssxref("top")}}, {{Cssxref("right")}}, {{Cssxref("bottom")}}, and {{Cssxref("left")}} properties specify offsets from the edges of the element's [containing block](/en-US/docs/Web/CSS/Containing_block). (The containing block is the ancestor relative to which the element is positioned.) If the element has margins, they are added to the offset. The element establishes a new [block formatting context](/en-US/docs/Web/CSS/CSS_display/Block_formatting_context) (BFC) for its contents.
- A **stickily positioned element** is an element whose [computed](/en-US/docs/Web/CSS/computed_value) `position` value is `sticky`. It's treated as relatively positioned until its [containing block](/en-US/docs/Web/CSS/Containing_block) crosses a specified threshold (such as setting {{Cssxref("top")}} to value other than auto) within its flow root (or the container it scrolls within), at which point it is treated as "stuck" until meeting the opposite edge of its [containing block](/en-US/docs/Web/CSS/Containing_block).
Most of the time, absolutely positioned elements that have {{Cssxref("height")}} and {{Cssxref("width")}} set to `auto` are sized so as to fit their contents. However, non-[replaced](/en-US/docs/Web/CSS/Replaced_element), absolutely positioned elements can be made to fill the available vertical space by specifying both {{Cssxref("top")}} and {{Cssxref("bottom")}} and leaving {{Cssxref("height")}} unspecified (that is, `auto`). They can likewise be made to fill the available horizontal space by specifying both {{Cssxref("left")}} and {{Cssxref("right")}} and leaving {{Cssxref("width")}} as `auto`.
Except for the case just described (of absolutely positioned elements filling the available space):
- If both `top` and `bottom` are specified (technically, not `auto`), `top` wins.
- If both `left` and `right` are specified, `left` wins when {{Cssxref("direction")}} is `ltr` (English, horizontal Japanese, etc.) and `right` wins when {{Cssxref("direction")}} is `rtl` (Persian, Arabic, Hebrew, etc.).
## Accessibility concerns
Ensure that elements positioned with an `absolute` or `fixed` value do not obscure other content when the page is zoomed to increase text size.
- [MDN Understanding WCAG, Guideline 1.4 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background)
- [Visual Presentation: Understanding SC 1.4.8 | Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-visual-presentation.html)
### Performance & Accessibility
Scrolling elements containing `fixed` or `sticky` content can cause performance and accessibility issues. As a user scrolls, the browser must repaint the sticky or fixed content in a new location. Depending on the content needing to be repainted, the browser performance, and the device's processing speed, the browser may not be able to manage repaints at 60 fps, causing accessibility concerns for people with sensitivities and jank for everyone. One solution is to add {{cssxref("will-change", "will-change: transform")}} to the positioned elements to render the element in its own layer, improving repaint speed and therefore improving performance and accessibility.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Relative positioning
Relatively positioned elements are offset a given amount from their normal position within the document, but without the offset affecting other elements. In the example below, note how the other elements are placed as if "Two" were taking up the space of its normal location.
#### HTML
```html
<div class="box" id="one">One</div>
<div class="box" id="two">Two</div>
<div class="box" id="three">Three</div>
<div class="box" id="four">Four</div>
```
#### CSS
```css
* {
box-sizing: border-box;
}
.box {
display: inline-block;
width: 100px;
height: 100px;
background: red;
color: white;
}
#two {
position: relative;
top: 20px;
left: 20px;
background: blue;
}
```
{{EmbedLiveSample('Relative_positioning', '', '200px')}}
### Absolute positioning
Elements that are relatively positioned remain in the normal flow of the document. In contrast, an element that is absolutely positioned is taken out of the flow; thus, other elements are positioned as if it did not exist. The absolutely positioned element is positioned relative to its _nearest positioned ancestor_ (i.e., the nearest ancestor that is not `static`). If a positioned ancestor doesn't exist, it is positioned relative to the ICB (initial containing block — see also the [W3C definition](https://www.w3.org/TR/CSS2/visudet.html#containing-block-details)), which is the containing block of the document's root element.
#### HTML
```html
<h1>Absolute positioning</h1>
<p>
I am a basic block level element. My adjacent block level elements sit on new
lines below me.
</p>
<p class="positioned">
By default we span 100% of the width of our parent element, and we are as tall
as our child content. Our total width and height is our content + padding +
border width/height.
</p>
<p>
We are separated by our margins. Because of margin collapsing, we are
separated by the width of one of our margins, not both.
</p>
<p>
inline elements <span>like this one</span> and <span>this one</span> sit on
the same line as one another, and adjacent text nodes, if there is space on
the same line. Overflowing inline elements
<span>wrap onto a new line if possible — like this one containing text</span>,
or just go on to a new line if not, much like this image will do:
<img src="long.jpg" />
</p>
```
#### CSS
```css
* {
box-sizing: border-box;
}
body {
width: 500px;
margin: 0 auto;
}
p {
background: aqua;
border: 3px solid blue;
padding: 10px;
margin: 10px;
}
span {
background: red;
border: 1px solid black;
}
.positioned {
position: absolute;
background: yellow;
top: 30px;
left: 30px;
}
```
#### Result
{{EmbedLiveSample('Absolute_positioning', '', '420px')}}
### Fixed positioning
Fixed positioning is similar to absolute positioning, with the exception that the element's [containing block](/en-US/docs/Web/CSS/Containing_block) is the initial containing block established by the _viewport_, unless any ancestor has `transform`, `perspective`, or `filter` property set to something other than `none` (see [CSS Transforms Spec](https://www.w3.org/TR/css-transforms-1/#propdef-transform)), which then causes that ancestor to take the place of the elements [containing block](/en-US/docs/Web/CSS/Containing_block). This can be used to create a "floating" element that stays in the same position regardless of scrolling. In the example below, box "One" is fixed at 80 pixels from the top of the page and 10 pixels from the left. Even after scrolling, it remains in the same place relative to the viewport. Also, when the [`will-change`](/en-US/docs/Web/CSS/will-change) property is set to `transform`, a new containing block is established.
#### HTML
```html
<div class="outer">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam congue tortor
eget pulvinar lobortis. Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae; Nam ac dolor augue. Pellentesque mi mi,
laoreet et dolor sit amet, ultrices varius risus. Nam vitae iaculis elit.
Aliquam mollis interdum libero. Sed sodales placerat egestas. Vestibulum ut
arcu aliquam purus viverra dictum vel sit amet mi. Duis nisl mauris, aliquam
sit amet luctus eget, dapibus in enim. Sed velit augue, pretium a sem
aliquam, congue porttitor tortor. Sed tempor nisl a lorem consequat, id
maximus erat aliquet. Sed sagittis porta libero sed condimentum. Aliquam
finibus lectus nec ante congue rutrum. Curabitur quam quam, accumsan id
ultrices ultrices, tempor et tellus.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam congue tortor
eget pulvinar lobortis. Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae; Nam ac dolor augue. Pellentesque mi mi,
laoreet et dolor sit amet, ultrices varius risus. Nam vitae iaculis elit.
Aliquam mollis interdum libero. Sed sodales placerat egestas. Vestibulum ut
arcu aliquam purus viverra dictum vel sit amet mi. Duis nisl mauris, aliquam
sit amet luctus eget, dapibus in enim. Sed velit augue, pretium a sem
aliquam, congue porttitor tortor. Sed tempor nisl a lorem consequat, id
maximus erat aliquet. Sed sagittis porta libero sed condimentum. Aliquam
finibus lectus nec ante congue rutrum. Curabitur quam quam, accumsan id
ultrices ultrices, tempor et tellus.
</p>
<div class="box" id="one">One</div>
</div>
```
#### CSS
```css
* {
box-sizing: border-box;
}
.box {
width: 100px;
height: 100px;
background: red;
color: white;
}
#one {
position: fixed;
top: 80px;
left: 10px;
background: blue;
}
.outer {
width: 500px;
height: 300px;
overflow: scroll;
padding-left: 150px;
}
```
#### Result
{{EmbedLiveSample('Fixed_positioning', '', '300px')}}
### Sticky positioning
Sticky positioning can be thought of as a hybrid of relative and fixed positioning when its nearest scrolling ancestor is the viewport. A stickily positioned element is treated as relatively positioned until it crosses a specified threshold, at which point it is treated as fixed until it reaches the boundary of its parent. For example:
```css
#one {
position: sticky;
top: 10px;
}
```
The above CSS rule would position the element with id _one_ relatively until the viewport was scrolled such that the element would be less than 10 pixels from the top. Beyond that threshold, the element would be fixed to 10 pixels from the top.
A common use for sticky positioning is for the headings in an alphabetized list. The "B" heading will appear just below the items that begin with "A" until they are scrolled offscreen. Rather than sliding offscreen with the rest of the content, the "B" heading will then remain fixed to the top of the viewport until all the "B" items have scrolled offscreen, at which point it will be covered up by the "C" heading, and so on.
You must specify a threshold with at least one of `top`, `right`, `bottom`, or `left` for sticky positioning to behave as expected. Otherwise, it will be indistinguishable from relative positioning.
#### HTML
```html
<dl>
<div>
<dt>A</dt>
<dd>Andrew W.K.</dd>
<dd>Apparat</dd>
<dd>Arcade Fire</dd>
<dd>At The Drive-In</dd>
<dd>Aziz Ansari</dd>
</div>
<div>
<dt>C</dt>
<dd>Chromeo</dd>
<dd>Common</dd>
<dd>Converge</dd>
<dd>Crystal Castles</dd>
<dd>Cursive</dd>
</div>
<div>
<dt>E</dt>
<dd>Explosions In The Sky</dd>
</div>
<div>
<dt>T</dt>
<dd>Ted Leo & The Pharmacists</dd>
<dd>T-Pain</dd>
<dd>Thrice</dd>
<dd>TV On The Radio</dd>
<dd>Two Gallants</dd>
</div>
</dl>
```
#### CSS
```css
* {
box-sizing: border-box;
}
dl > div {
background: #fff;
padding: 24px 0 0 0;
}
dt {
background: #b8c1c8;
border-bottom: 1px solid #989ea4;
border-top: 1px solid #717d85;
color: #fff;
font:
bold 18px/21px Helvetica,
Arial,
sans-serif;
margin: 0;
padding: 2px 0 0 12px;
position: -webkit-sticky;
position: sticky;
top: -1px;
}
dd {
font:
bold 20px/45px Helvetica,
Arial,
sans-serif;
margin: 0;
padding: 0 0 0 12px;
white-space: nowrap;
}
dd + dd {
border-top: 1px solid #ccc;
}
```
#### Result
{{EmbedLiveSample('Sticky_positioning', '', '300px')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Learn CSS: Positioning](/en-US/docs/Learn/CSS/CSS_layout/Positioning)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_modal/index.md | ---
title: ":modal"
slug: Web/CSS/:modal
page-type: css-pseudo-class
browser-compat: css.selectors.modal
---
{{CSSRef}}
The **`:modal`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) matches an element that is in a state in which it excludes all interaction with elements outside it until the interaction has been dismissed. Multiple elements can be selected by the `:modal` pseudo-class at the same time, but only one of them will be active and able to receive input.
{{EmbedInteractiveExample("pages/tabbed/pseudo-class-modal.html", "tabbed-shorter")}}
## Syntax
```css
:modal {
/* ... */
}
```
## Usage notes
Examples of elements that will prevent user interaction with the rest of the page and will be selected by the `:modal` pseudo-class include:
- The [`dialog`](/en-US/docs/Web/HTML/Element/dialog) element opened with the `showModal()` API.
- The element selected by the [`:fullscreen`](/en-US/docs/Web/CSS/:fullscreen) pseudo-class when opened with the `requestFullscreen()` API.
## Examples
### Styling a modal dialog
This example styles a modal dialog that opens when the "Update details" button is activated. This example has been built on top of the {{HTMLElement("dialog")}} element [example](/en-US/docs/Web/HTML/Element/dialog#advanced_example).
```html hidden
<!-- Simple modal dialog containing a form -->
<dialog id="favDialog">
<form method="dialog">
<p>
<label
>Favorite animal:
<select>
<option value="default">Choose…</option>
<option>Brine shrimp</option>
<option>Red panda</option>
<option>Spider monkey</option>
</select>
</label>
</p>
<div>
<button value="cancel">Cancel</button>
<button id="confirmBtn" value="default">Confirm</button>
</div>
</form>
</dialog>
<p>
<button id="updateDetails">Update details</button>
</p>
<output></output>
```
#### CSS
```css
:modal {
border: 5px solid red;
background-color: yellow;
box-shadow: 3px 3px 10px rgb(0 0 0 / 50%);
}
```
```js hidden
const updateButton = document.getElementById("updateDetails");
const favDialog = document.getElementById("favDialog");
const outputBox = document.querySelector("output");
const selectEl = favDialog.querySelector("select");
const confirmBtn = favDialog.querySelector("#confirmBtn");
// If a browser doesn't support the dialog, then hide the
// dialog contents by default.
if (typeof favDialog.showModal !== "function") {
favDialog.hidden = true;
// Your fallback script
}
// "Update details" button opens the <dialog> modally
updateButton.addEventListener("click", () => {
if (typeof favDialog.showModal === "function") {
favDialog.showModal();
} else {
outputBox.value = "Sorry, the dialog API is not supported by this browser.";
}
});
// "Favorite animal" input sets the value of the submit button
selectEl.addEventListener("change", (e) => {
confirmBtn.value = selectEl.value;
});
// "Confirm" button of form triggers "close" on dialog because of [method="dialog"]
favDialog.addEventListener("close", () => {
outputBox.value = `${
favDialog.returnValue
} button clicked - ${new Date().toString()}`;
});
```
### Result
{{EmbedLiveSample("Styling_a_modal_dialog", "100%", 300)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [`dialog`](/en-US/docs/Web/HTML/Element/dialog) element
- Other element display state pseudo-classes: {{CSSxRef(":fullscreen")}} and {{CSSxRef(":picture-in-picture")}}
- Complete list of [pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/min-width/index.md | ---
title: min-width
slug: Web/CSS/min-width
page-type: css-property
browser-compat: css.properties.min-width
---
{{CSSRef}}
The **`min-width`** [CSS](/en-US/docs/Web/CSS) property sets the minimum width of an element. It prevents the [used value](/en-US/docs/Web/CSS/used_value) of the {{cssxref("width")}} property from becoming smaller than the value specified for `min-width`.
{{EmbedInteractiveExample("pages/css/min-width.html")}}
The element's width is set to the value of `min-width` whenever `min-width` is larger than {{Cssxref("max-width")}} or {{Cssxref("width")}}.
## Syntax
```css
/* <length> value */
min-width: 3.5em;
/* <percentage> value */
min-width: 10%;
/* Keyword values */
min-width: max-content;
min-width: min-content;
min-width: fit-content;
min-width: fit-content(20em);
/* Global values */
min-width: inherit;
min-width: initial;
min-width: revert;
min-width: revert-layer;
min-width: unset;
```
### Values
- {{cssxref("<length>")}}
- : Defines the `min-width` as an absolute value.
- {{cssxref("<percentage>")}}
- : Defines the `min-width` as a percentage of the containing block's width.
- `auto`
- : The browser will calculate and select a `min-width` for the specified element.
- `max-content`
- : The intrinsic preferred `min-width`.
- `min-content`
- : The intrinsic minimum `min-width`.
- `fit-content`
- : Use the available space, but not more than [max-content](/en-US/docs/Web/CSS/max-content), i.e `min(max-content, max(min-content, stretch))`.
- `fit-content({{cssxref("<length-percentage>")}})` {{Experimental_Inline}}
- : Uses the `fit-content` formula with the available space replaced by the specified argument, i.e. `min(max-content, max(min-content, argument))`.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting minimum element width
```css
table {
min-width: 75%;
}
form {
min-width: 0;
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{Cssxref("width")}}, {{Cssxref("max-width")}}
- The [box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model), {{Cssxref("box-sizing")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/border-block-width/index.md | ---
title: border-block-width
slug: Web/CSS/border-block-width
page-type: css-property
browser-compat: css.properties.border-block-width
---
{{CSSRef}}
The **`border-block-width`** [CSS](/en-US/docs/Web/CSS) property defines the width of the logical block borders of an element, which maps to a physical border width depending on the element's writing mode, directionality, and text orientation. It corresponds to the {{cssxref("border-top-width")}} and {{cssxref("border-bottom-width")}}, or {{cssxref("border-left-width")}}, and {{cssxref("border-right-width")}} property depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}.
{{EmbedInteractiveExample("pages/css/border-block-width.html")}}
The border width in the other dimension can be set with {{cssxref("border-inline-width")}}, which sets {{cssxref("border-inline-start-width")}}, and {{cssxref("border-inline-end-width")}}.
## Syntax
```css
/* <'border-width'> values */
border-block-width: 5px;
border-block-width: thick;
/* Global values */
border-block-width: inherit;
border-block-width: initial;
border-block-width: revert;
border-block-width: revert-layer;
border-block-width: unset;
```
### Values
- `<'border-width'>`
- : The width of the border. See {{ cssxref("border-width") }}.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Border width with vertical text
#### HTML
```html
<div>
<p class="exampleText">Example text</p>
</div>
```
#### CSS
```css
div {
background-color: yellow;
width: 120px;
height: 120px;
}
.exampleText {
writing-mode: vertical-lr;
border: 1px solid blue;
border-block-width: 5px;
}
```
#### Results
{{EmbedLiveSample("Border_width_with_vertical_text", 140, 140)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [CSS Logical Properties and Values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values)
- This property maps to one of the physical border properties: {{cssxref("border-top-width")}}, {{cssxref("border-right-width")}}, {{cssxref("border-bottom-width")}}, and {{cssxref("border-left-width")}}
- {{cssxref("writing-mode")}}, {{cssxref("direction")}}, {{cssxref("text-orientation")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/border-top-width/index.md | ---
title: border-top-width
slug: Web/CSS/border-top-width
page-type: css-property
browser-compat: css.properties.border-top-width
---
{{CSSRef}}
The **`border-top-width`** [CSS](/en-US/docs/Web/CSS) property sets the width of the top border of an element.
{{EmbedInteractiveExample("pages/css/border-top-width.html")}}
## Syntax
```css
/* Keyword values */
border-top-width: thin;
border-top-width: medium;
border-top-width: thick;
/* <length> values */
border-top-width: 10em;
border-top-width: 3vmax;
border-top-width: 6px;
/* Global keywords */
border-top-width: inherit;
border-top-width: initial;
border-top-width: revert;
border-top-width: revert-layer;
border-top-width: unset;
```
### Values
- `<line-width>`
- : Defines the width of the border, either as an explicit nonnegative {{cssxref("<length>")}} or a keyword. If it's a keyword, it must be one of the following values:
- `thin`
- `medium`
- `thick`
> **Note:** Because the specification doesn't define the exact thickness denoted by each keyword, the precise result when using one of them is implementation-specific. Nevertheless, they always follow the pattern `thin ≤ medium ≤ thick`, and the values are constant within a single document.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### HTML
```html
<div>Element 1</div>
<div>Element 2</div>
```
### CSS
```css
div {
border: 1px solid red;
margin: 1em 0;
}
div:nth-child(1) {
border-top-width: thick;
}
div:nth-child(2) {
border-top-width: 2em;
}
```
### Result
{{EmbedLiveSample('Examples', '100%')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- The other border-width-related CSS properties: {{Cssxref("border-left-width")}}, {{Cssxref("border-right-width")}}, {{Cssxref("border-bottom-width")}}, and {{Cssxref("border-width")}}.
- The other border-top-related CSS properties: {{Cssxref("border")}}, {{Cssxref("border-top")}}, {{Cssxref("border-top-style")}}, and {{Cssxref("border-top-color")}}.
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/css_motion_path/index.md | ---
title: CSS motion path
slug: Web/CSS/CSS_motion_path
page-type: css-module
browser-compat: css.properties.offset-path
---
{{CSSRef}}
The **CSS motion path** module allows authors to animate any graphical object along a custom path.
The idea is that when you want to animate an element moving along a path, you previously only had animating translation, position, etc. at your disposal, which wasn't ideal and only allowed for simple movements. With {{cssxref("offset-path")}} you can define a specific path of any shape you want. You then animate it along that path by animating {{cssxref("offset-distance")}}, and can choose to rotate it at any point using {{cssxref("offset-rotate")}}.
## Basic example
```html
<div id="motion-demo"></div>
```
```css
#motion-demo {
offset-path: path("M20,20 C20,100 200,0 200,100");
animation: move 3000ms infinite alternate ease-in-out;
width: 40px;
height: 40px;
background: cyan;
}
@keyframes move {
0% {
offset-distance: 0%;
}
100% {
offset-distance: 100%;
}
}
```
{{EmbedLiveSample('Basic_example', '100%', 150)}}
## Reference
### Properties
- {{cssxref("offset")}}
- {{cssxref("offset-anchor")}}
- {{cssxref("offset-distance")}}
- {{cssxref("offset-path")}}
- {{cssxref("offset-position")}}
- {{cssxref("offset-rotate")}}
### Functions
- {{cssxref("ray")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/user-modify/index.md | ---
title: user-modify
slug: Web/CSS/user-modify
page-type: css-property
status:
- deprecated
- non-standard
browser-compat: css.properties.user-modify
---
{{CSSRef}}{{Non-standard_Header}}{{Deprecated_Header}}
The **`user-modify`** property has no effect in Firefox. It was originally planned to determine whether or not the content of an element can be edited by a user.
> **Warning:** This property has been replaced by the [`contenteditable`](/en-US/docs/Web/HTML/Global_attributes#contenteditable) attribute.
## Syntax
```css
/* Keyword values */
user-modify: read-only;
user-modify: read-write;
user-modify: write-only;
/* Global values */
user-modify: inherit;
user-modify: initial;
user-modify: revert;
user-modify: unset;
```
The `-moz-user-modify` property is specified as one of the keyword values from the list below.
### Values
- `read-only`
- : Default value. Contents are read-only.
- `read-write`
- : The user is able to read and write contents.
- `read-write-plaintext-only` {{Non-standard_Inline}} {{Deprecated_Inline}}
- : Same as `read-write`, but rich text formatting will be lost.
- `write-only`
- : The user is able to edit the content, but not to read it.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{CSSSyntax}}
## Examples
### HTML
```html
<div class="readwrite">The user is able to change this text.</div>
```
### CSS
```css
.readwrite {
-moz-user-modify: read-write;
-webkit-user-modify: read-write;
}
```
## Specifications
Not part of any standard.
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef("-moz-user-focus")}}
- {{CSSxRef("-moz-user-input")}}
- {{CSSxRef("user-select", "-moz-user-select")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/border-image/index.md | ---
title: border-image
slug: Web/CSS/border-image
page-type: css-property
browser-compat: css.properties.border-image
---
{{CSSRef}}
The **`border-image`** [CSS](/en-US/docs/Web/CSS) property draws an image around a given element. It replaces the element's regular [border](/en-US/docs/Web/CSS/border).
{{EmbedInteractiveExample("pages/css/border-image.html")}}
> **Note:** You should specify a separate {{cssxref("border-style")}} in case the border image fails to load. Although the specification doesn't strictly require it, some browsers don't render the border image if {{cssxref("border-style")}} is `none` or {{cssxref("border-width")}} is `0`.
## Constituent properties
This property is a shorthand for the following CSS properties:
- [`border-image-outset`](/en-US/docs/Web/CSS/border-image-outset)
- [`border-image-repeat`](/en-US/docs/Web/CSS/border-image-repeat)
- [`border-image-slice`](/en-US/docs/Web/CSS/border-image-slice)
- [`border-image-source`](/en-US/docs/Web/CSS/border-image-source)
- [`border-image-width`](/en-US/docs/Web/CSS/border-image-width)
## Syntax
```css
/* source | slice */
border-image: linear-gradient(red, blue) 27;
/* source | slice | repeat */
border-image: url("/images/border.png") 27 space;
/* source | slice | width */
border-image: linear-gradient(red, blue) 27 / 35px;
/* source | slice | width | outset | repeat */
border-image: url("/images/border.png") 27 23 / 50px 30px / 1rem round space;
/* Global values */
border-image: inherit;
border-image: initial;
border-image: revert;
border-image: revert-layer;
border-image: unset;
```
The `border-image` property may be specified with anywhere from one to five of the values listed below.
> **Note:** If the [computed value](/en-US/docs/Web/CSS/computed_value) of {{cssxref("border-image-source")}} is `none`, or if the image cannot be displayed, the {{cssxref("border-style")}} will be displayed instead.
### Values
- `<'border-image-source'>`
- : The source image. See {{cssxref("border-image-source")}}.
- `<'border-image-slice'>`
- : The dimensions for slicing the source image into regions. Up to four values may be specified. See {{cssxref("border-image-slice")}}.
- `<'border-image-width'>`
- : The width of the border image. Up to four values may be specified. See {{cssxref("border-image-width")}}.
- `<'border-image-outset'>`
- : The distance of the border image from the element's outside edge. Up to four values may be specified. See {{cssxref("border-image-outset")}}.
- `<'border-image-repeat'>`
- : Defines how the edge regions of the source image are adjusted to fit the dimensions of the border image. Up to two values may be specified. See {{cssxref("border-image-repeat")}}.
## Accessibility concerns
Assistive technology cannot parse border images. If the image contains information critical to understanding the page's overall purpose, it is better to describe it semantically in the document.
- [MDN Understanding WCAG, Guideline 1.1 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.1_—_providing_text_alternatives_for_non-text_content)
- [Understanding Success Criterion 1.1.1 | Understanding WCAG 2.0](https://www.w3.org/TR/2016/NOTE-UNDERSTANDING-WCAG20-20161007/text-equiv-all.html)
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Bitmap
In this example, we will apply a diamond pattern to an element's borders. The source for the border image is a ".png" file of 81 by 81 pixels, with three diamonds going vertically and horizontally:

#### HTML
```html
<div id="bitmap">
This element is surrounded by a bitmap-based border image!
</div>
```
#### CSS
To match the size of a single diamond, we will use a value of 81 divided by 3, or `27`, for slicing the image into corner and edge regions. To center the border image on the edge of the element's background, we will make the outset values equal to half of the width values. Finally, a repeat value of `round` will make the border slices fit evenly, i.e., without clipping or gaps.
```css
#bitmap {
width: 200px;
background-color: #ffa;
border: 36px solid orange;
margin: 30px;
padding: 10px;
border-image: url("border.png") 27 / 36px 28px 18px 8px / 18px 14px 9px 4px
round;
}
```
#### Result
{{EmbedLiveSample('Bitmap', '100%', 200)}}
### Gradient
#### HTML
```html
<div id="gradient">
This element is surrounded by a gradient-based border image!
</div>
```
#### CSS
```css
#gradient {
width: 200px;
border: 30px solid;
border-image: repeating-linear-gradient(45deg, #f33, #3bf, #f33 30px) 60;
padding: 20px;
}
```
#### Result
{{EmbedLiveSample('Gradient')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("border")}}
- {{cssxref("outline")}}
- {{cssxref("box-shadow")}}
- {{cssxref("background-image")}}
- {{cssxref("url", "url()")}} function
- Gradient functions: {{CSSxRef("gradient/conic-gradient", "conic-gradient()")}}, {{CSSxRef("gradient/repeating-conic-gradient", "repeating-conic-gradient()")}}, {{CSSxRef("gradient/linear-gradient", "linear-gradient()")}}, {{CSSxRef("gradient/repeating-linear-gradient", "repeating-linear-gradient()")}}, {{CSSxRef("gradient/radial-gradient", "radial-gradient()")}}, {{CSSxRef("gradient/repeating-radial-gradient", "repeating-radial-gradient()")}}
- [Border images in CSS: A key focus area for Interop 2023](/en-US/blog/border-images-interop-2023/) on MDN blog (2023)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_nth-last-child/index.md | ---
title: ":nth-last-child()"
slug: Web/CSS/:nth-last-child
page-type: css-pseudo-class
browser-compat: css.selectors.nth-last-child
---
{{CSSRef}}
The **`:nth-last-child()`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) matches elements based on their position among a group of siblings, counting from the end.
{{EmbedInteractiveExample("pages/tabbed/pseudo-class-nth-last-child.html", "tabbed-shorter")}}
## Syntax
The `nth-last-child` pseudo-class is specified with a single argument, which represents the pattern for matching elements, counting from the end.
```css-nolint
:nth-last-child(<nth> [of <complex-selector-list>]?) {
/* ... */
}
```
### Keyword values
- `odd`
- : Represents elements whose numeric position in a series of siblings is odd: 1, 3, 5, etc., counting from the end.
- `even`
- : Represents elements whose numeric position in a series of siblings is even: 2, 4, 6, etc., counting from the end.
### Functional notation
- `<An+B>`
- : Represents elements whose numeric position in a series of siblings matches the pattern `An+B`, for every positive integer or zero value of `n`, where:
- `A` is an integer step size,
- `B` is an integer offset,
- `n` is all nonnegative integers, starting from 0.
It can be read as the `An+B`-th element of a list. The index of the first element, counting from the end, is `1`. The `A` and `B` must both have {{cssxref("<integer>")}} values.
### The `of <selector>` syntax
By passing a selector argument, we can select the **nth-last** element that matches that selector. For example, the following selector matches the last three _important_ list items, which are assigned with `class="important"`.
```css
:nth-last-child(-n + 3 of li.important) {
}
```
> **Note:** This is different from moving the selector outside of the function, like:
```css
li.important: nth-last-child(-n + 3);
```
This selector applies a style to list items if they are also within the last three children.
## Examples
### Example selectors
- `tr:nth-last-child(odd)` or `tr:nth-last-child(2n+1)`
- : Represents the odd rows of an HTML table: 1, 3, 5, etc., counting from the end.
- `tr:nth-last-child(even)` or `tr:nth-last-child(2n)`
- : Represents the even rows of an HTML table: 2, 4, 6, etc., counting from the end.
- `:nth-last-child(7)`
- : Represents the seventh element, counting from the end.
- `:nth-last-child(5n)`
- : Represents elements 5, 10, 15, etc., counting from the end.
- `:nth-last-child(3n+4)`
- : Represents elements 4, 7, 10, 13, etc., counting from the end.
- `:nth-last-child(-n+3)`
- : Represents the last three elements among a group of siblings.
- `p:nth-last-child(n)` or `p:nth-last-child(n+1)`
- : Represents every `<p>` element among a group of siblings. This is the same as a simple `p` selector. (Since `n` starts at zero, while the last element begins at one, `n` and `n+1` will both select the same elements.)
- `p:nth-last-child(1)` or `p:nth-last-child(0n+1)`
- : Represents every `<p>` that is the first element among a group of siblings, counting from the end. This is the same as the {{cssxref(":last-child")}} selector.
### Table example
#### HTML
```html
<table>
<tbody>
<tr>
<td>First line</td>
</tr>
<tr>
<td>Second line</td>
</tr>
<tr>
<td>Third line</td>
</tr>
<tr>
<td>Fourth line</td>
</tr>
<tr>
<td>Fifth line</td>
</tr>
</tbody>
</table>
```
#### CSS
```css
table {
border: 1px solid blue;
}
/* Selects the last three elements */
tr:nth-last-child(-n + 3) {
background-color: pink;
}
/* Selects every element starting from the second to last item */
tr:nth-last-child(n + 2) {
color: blue;
}
/* Select only the last second element */
tr:nth-last-child(2) {
font-weight: 600;
}
```
#### Result
{{EmbedLiveSample('Table_example', 300, 150)}}
### Quantity query
A _quantity query_ styles elements depending on how many of them there are. In this example, list items turn red when there are at least three of them in a given list. This is accomplished by combining the capabilities of the `nth-last-child` pseudo-class and the [subsequent-sibling combinator](/en-US/docs/Web/CSS/Subsequent-sibling_combinator).
#### HTML
```html
<h4>A list of four items (styled):</h4>
<ol>
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
</ol>
<h4>A list of two items (unstyled):</h4>
<ol>
<li>One</li>
<li>Two</li>
</ol>
```
#### CSS
```css
/* If there are at least three list items,
style them all */
li:nth-last-child(n + 3),
li:nth-last-child(3) ~ li {
color: red;
}
```
#### Result
{{EmbedLiveSample('Quantity_query', '100%', 270)}}
### `of <selector>` syntax example
In this example, there is an unordered list of names. Some items have a `noted` class applied and are then highlighted with a thick bottom border.
#### HTML
```html
<ul>
<li class="noted">Diego</li>
<li>Shilpa</li>
<li class="noted">Caterina</li>
<li>Jayla</li>
<li>Tyrone</li>
<li>Ricardo</li>
<li class="noted">Gila</li>
<li>Sienna</li>
<li>Titilayo</li>
<li class="noted">Lexi</li>
<li>Aylin</li>
<li>Leo</li>
<li>Leyla</li>
<li class="noted">Bruce</li>
<li>Aisha</li>
<li>Veronica</li>
<li class="noted">Kyouko</li>
<li>Shireen</li>
<li>Tanya</li>
<li class="noted">Marlene</li>
</ul>
```
#### CSS
```css
* {
font-family: sans-serif;
}
ul {
display: flex;
flex-wrap: wrap;
list-style: none;
font-size: 1.2rem;
padding-left: 0;
}
li {
margin: 0.125rem;
padding: 0.25rem;
border: 1px solid tomato;
}
.noted {
border-bottom: 5px solid tomato;
}
```
In the following CSS we are targeting the **odd** list items that are marked with `class="noted"`.
```css
li:nth-last-child(odd of .noted) {
background-color: tomato;
border-bottom-color: seagreen;
}
```
#### Result
Items with `class="noted"` have a think bottom border and items 1, 7, 14, and 20 have a solid background as they are the _odd_ list items with `class="noted"`.
{{EmbedLiveSample('of_selector_syntax_example', 550, 120)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{Cssxref(":nth-child")}}
- {{Cssxref(":nth-last-of-type")}}
- [Quantity Queries for CSS](https://alistapart.com/article/quantity-queries-for-css/)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/box-pack/index.md | ---
title: box-pack
slug: Web/CSS/box-pack
page-type: css-property
status:
- deprecated
- non-standard
browser-compat: css.properties.box-pack
---
{{CSSRef}}{{Non-standard_header}}{{Deprecated_Header}}
> **Warning:** This is a property of the original CSS Flexible Box Layout Module draft, and has been replaced by a newer standard. See [flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox) for information about the current standard.
The **`-moz-box-pack`** and **`-webkit-box-pack`** [CSS](/en-US/docs/Web/CSS) properties specify how a `-moz-box` or `-webkit-box` packs its contents in the direction of its layout. The effect of this is only visible if there is extra space in the box.
The direction of layout depends on the element's orientation: horizontal or vertical.
## Syntax
```css
/* Keyword values */
box-pack: start;
box-pack: center;
box-pack: end;
box-pack: justify;
/* Global values */
box-pack: inherit;
box-pack: initial;
box-pack: unset;
```
The `box-pack` property is specified as one of the keyword values listed below.
### Values
- `start`
- : The box packs contents at the start, leaving any extra space at the end.
- `center`
- : The box packs contents in the center, dividing any extra space equally between the start and the end.
- `end`
- : The box packs contents at the end, leaving any extra space at the start.
- `justify`
- : The space is divided evenly in-between each child, with none of the extra space placed before the first child or after the last child. If there is only one child, treat the value as if it were `start`.
## Notes
The edge of the box designated the _start_ for packing purposes depends on the box's orientation and direction:
- For horizontal elements, the _start_ is the top edge.
- For vertical elements, the _start_ is the left edge.
<table class="standard-table">
<tbody>
<tr>
<th></th>
<th><strong>Normal</strong></th>
<th><strong>Reverse</strong></th>
</tr>
<tr>
<th><strong>Horizontal</strong></th>
<td>left</td>
<td>right</td>
</tr>
<tr>
<th><strong>Vertical</strong></th>
<td>top</td>
<td>bottom</td>
</tr>
</tbody>
</table>
The edge opposite to the start is designated the _end_.
If the packing is set using the element's `pack` attribute, then the style is ignored.
## Formal definition
{{CSSInfo}}
## Formal syntax
```plain
box-pack =
start | center | end | justify
```
## Examples
### Examples of box-pack
```css
div.example {
border-style: solid;
display: -moz-box; /* Mozilla */
display: -webkit-box; /* WebKit */
/* Make this box taller than the children,
so there is room for the box-pack */
height: 300px;
/* Make this box wide enough to show the contents
are centered horizontally */
width: 300px;
/* Children should be oriented vertically */
-moz-box-orient: vertical; /* Mozilla */
-webkit-box-orient: vertical; /* WebKit */
/* Align children to the horizontal center of this box */
-moz-box-align: center; /* Mozilla */
-webkit-box-align: center; /* WebKit */
/* Pack children to the bottom of this box */
-moz-box-pack: end; /* Mozilla */
-webkit-box-pack: end; /* WebKit */
}
div.example p {
/* Make children narrower than their parent,
so there is room for the box-align */
width: 200px;
}
```
```html
<div class="example">
<p>I will be second from the bottom of div.example, centered horizontally.</p>
<p>I will be on the bottom of div.example, centered horizontally.</p>
</div>
```
{{EmbedLiveSample('Examples', 310, 310)}}
## Specifications
Not part of any standard.
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef("box-orient")}}
- {{CSSxRef("box-direction")}}
- {{CSSxRef("box-align")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/margin-top/index.md | ---
title: margin-top
slug: Web/CSS/margin-top
page-type: css-property
browser-compat: css.properties.margin-top
---
{{CSSRef}}
The **`margin-top`** [CSS](/en-US/docs/Web/CSS) property sets the [margin area](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model#margin_area) on the top of an element. A positive value places it farther from its neighbors, while a negative value places it closer.
{{EmbedInteractiveExample("pages/css/margin-top.html")}}
This property has no effect on _non-[replaced](/en-US/docs/Web/CSS/Replaced_element)_ inline elements, such as {{HTMLElement("span")}} or {{HTMLElement("code")}}.
## Syntax
```css
/* <length> values */
margin-top: 10px; /* An absolute length */
margin-top: 1em; /* relative to the text size */
margin-top: 5%; /* relative to the nearest block container's width */
/* Keyword values */
margin-top: auto;
/* Global values */
margin-top: inherit;
margin-top: initial;
margin-top: revert;
margin-top: revert-layer;
margin-top: unset;
```
The `margin-top` property is specified as the keyword `auto`, or a `<length>`, or a `<percentage>`. Its value can be positive, zero, or negative.
### Values
- {{cssxref("<length>")}}
- : The size of the margin as a fixed value.
- {{cssxref("<percentage>")}}
- : The size of the margin as a percentage, relative to the inline size (_width_ in a horizontal language, defined by {{cssxref("writing-mode")}}) of the [containing block](/en-US/docs/Web/CSS/Containing_block).
- `auto`
- : The browser selects a suitable value to use. See {{cssxref("margin")}}.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting positive and negative top margins
```css
.content {
margin-top: 5%;
}
.sidebox {
margin-top: 10px;
}
.logo {
margin-top: -5px;
}
#footer {
margin-top: 1em;
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("margin-right")}}, {{cssxref("margin-bottom")}}, and {{cssxref("margin-left")}} and the {{cssxref("margin")}} shorthand
- The mapped logical properties: {{cssxref("margin-block-start")}}, {{cssxref("margin-block-end")}}, {{cssxref("margin-inline-start")}}, and {{cssxref("margin-inline-end")}} and the shorthands {{cssxref("margin-block")}} and {{cssxref("margin-inline")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/border/index.md | ---
title: border
slug: Web/CSS/border
page-type: css-shorthand-property
browser-compat: css.properties.border
---
{{CSSRef}}
The **`border`** [shorthand](/en-US/docs/Web/CSS/Shorthand_properties) [CSS](/en-US/docs/Web/CSS) property sets an element's border. It sets the values of {{Cssxref("border-width")}}, {{Cssxref("border-style")}}, and {{Cssxref("border-color")}}.
{{EmbedInteractiveExample("pages/css/border.html")}}
## Constituent properties
This property is a shorthand for the following CSS properties:
- [`border-color`](/en-US/docs/Web/CSS/border-color)
- [`border-style`](/en-US/docs/Web/CSS/border-style)
- [`border-width`](/en-US/docs/Web/CSS/border-width)
## Syntax
```css
/* style */
border: solid;
/* width | style */
border: 2px dotted;
/* style | color */
border: outset #f33;
/* width | style | color */
border: medium dashed green;
/* Global values */
border: inherit;
border: initial;
border: revert;
border: revert-layer;
border: unset;
```
The `border` property may be specified using one, two, or three of the values listed below. The order of the values does not matter.
> **Note:** The border will be invisible if its style is not defined. This is because the style defaults to `none`.
### Values
- `<line-width>`
- : Sets the thickness of the border. Defaults to `medium` if absent. See {{Cssxref("border-width")}}.
- {{cssxref("<line-style>")}}
- : Sets the style of the border. Defaults to `none` if absent. See {{Cssxref("border-style")}}.
- {{cssxref("<color>")}}
- : Sets the color of the border. Defaults to `currentcolor` if absent. See {{Cssxref("border-color")}}.
## Description
As with all shorthand properties, any omitted sub-values will be set to their [initial value](/en-US/docs/Web/CSS/initial_value). Importantly, `border` cannot be used to specify a custom value for {{cssxref("border-image")}}, but instead sets it to its initial value, i.e., `none`.
The `border` shorthand is especially useful when you want all four borders to be the same. To make them different from each other, however, you can use the longhand {{Cssxref("border-width")}}, {{Cssxref("border-style")}}, and {{Cssxref("border-color")}} properties, which accept different values for each side. Alternatively, you can target one border at a time with the physical (e.g., {{Cssxref("border-top")}} ) and logical (e.g., {{Cssxref("border-block-start")}}) border properties.
### Borders vs. outlines
Borders and [outlines](/en-US/docs/Web/CSS/outline) are very similar. However, outlines differ from borders in the following ways:
- Outlines never take up space, as they are drawn outside of an element's content.
- According to the spec, outlines don't have to be rectangular, although they usually are.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting a pink outset border
#### HTML
```html
<div>I have a border, an outline, and a box shadow! Amazing, isn't it?</div>
```
#### CSS
```css
div {
border: 0.5rem outset pink;
outline: 0.5rem solid khaki;
box-shadow: 0 0 0 2rem skyblue;
border-radius: 12px;
font: bold 1rem sans-serif;
margin: 2rem;
padding: 1rem;
outline-offset: 0.5rem;
}
```
#### Result
{{EmbedLiveSample('Setting_a_pink_outset_border')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{Cssxref("border-width")}}
- {{Cssxref("border-style")}}
- {{Cssxref("border-color")}}
- {{Cssxref("outline")}}
- [Backgrounds and borders](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders)
- [Learn CSS: Backgrounds and borders](/en-US/docs/Learn/CSS/Building_blocks/Backgrounds_and_borders)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/scroll-margin-block/index.md | ---
title: scroll-margin-block
slug: Web/CSS/scroll-margin-block
page-type: css-shorthand-property
browser-compat: css.properties.scroll-margin-block
---
{{CSSRef}}
The `scroll-margin-block` [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) sets the scroll margins of an element in the block dimension.
{{EmbedInteractiveExample("pages/css/scroll-margin-block.html")}}
## Constituent properties
This property is a shorthand for the following CSS properties:
- [`scroll-margin-block-end`](/en-US/docs/Web/CSS/scroll-margin-block-end)
- [`scroll-margin-block-start`](/en-US/docs/Web/CSS/scroll-margin-block-start)
## Syntax
```css
/* <length> values */
scroll-margin-block: 10px;
scroll-margin-block: 1em 0.5em;
/* Global values */
scroll-margin-block: inherit;
scroll-margin-block: initial;
scroll-margin-block: revert;
scroll-margin-block: revert-layer;
scroll-margin-block: unset;
```
### Values
- {{CSSXref("<length>")}}
- : An outset from the corresponding edge of the scroll container.
## Description
The scroll-margin values represent outsets defining the scroll snap area that is used for snapping this box to the snapport. The scroll snap area is determined by taking the transformed border box, finding its rectangular bounding box (axis-aligned in the scroll container's coordinate space), then adding the specified outsets.
## Formal definition
{{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/custom-ident/index.md | ---
title: <custom-ident>
slug: Web/CSS/custom-ident
page-type: css-type
spec-urls:
- https://drafts.csswg.org/css-values/#custom-idents
- https://drafts.csswg.org/css-will-change/#valdef-will-change-custom-ident
- https://drafts.csswg.org/css-counter-styles/#typedef-counter-style-name
- https://drafts.csswg.org/css-lists/#counter-properties
---
{{CSSRef}}
The **`<custom-ident>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) denotes an arbitrary user-defined string used as an {{glossary("identifier")}}. It is case-sensitive, and certain values are forbidden in various contexts to prevent ambiguity.
## Syntax
The syntax of `<custom-ident>` is similar to CSS identifiers (such as property names), except that it is [case-sensitive](https://en.wikipedia.org/wiki/Case_sensitivity). It consists of one or more characters, where characters can be any of the following:
- any alphabetical character (`A` to `Z`, or `a` to `z`),
- any decimal digit (`0` to `9`),
- a hyphen (`-`),
- an underscore (`_`),
- an [escaped character](#escaping_characters) (preceded by a backslash, `\`),
- a [Unicode](https://en.wikipedia.org/wiki/Unicode) character (in the format of a backslash, `\`, followed by one to six hexadecimal digits, representing its Unicode code point)
Note that `id1`, `Id1`, `iD1`, and `ID1` are all different identifiers as they are [case-sensitive](https://en.wikipedia.org/wiki/Case_sensitivity).
### Escaping characters
Any Unicode code point can be included as part of a `<custom-ident>` or quoted {{cssxref("string")}} by escaping it.
In CSS, there are several ways to escape a character. Escape sequences start with a backslash (`\`), and continue with:
- One to six hex (`ABCDEF0123456789`) digits. The hex digits can optionally be followed by white space. The hex escape sequence gets replaced by the Unicode code point whose value is given by those digits. The whitespace allows the sequences to be followed by actual hex digits (versus replaced ones).
- Any Unicode code point that is not a hex digit or a newline character.
Examples:
- "&B" can be written as `\26 B` or `\000026B`.
- "hi.there" can be written as `hi\.there` or `hi\002Ethere`.
- "toto?" can be written as `toto\?`, `toto\3F`, or `toto\00003F`.
To include actual white space after an escape sequence, include two white spaces in the escape sequence.
### Forbidden values
A `<custom-ident>` must not be placed between single or double quotes as this would be identical to a {{CSSxRef("<string>")}}. Moreover, the first character must not be a decimal digit, nor a hyphen (`-`) followed by a decimal digit.
To prevent ambiguity, each property that uses `<custom-ident>` forbids the use of specific values:
- {{CSSxRef("animation-name")}}
- : Forbids the global CSS values (`unset`, `initial`, and `inherit`), as well as `none`.
- {{CSSxRef("counter-reset")}}, {{CSSxRef("counter-increment")}}
- : Forbids the global CSS values (`unset`, `initial`, and `inherit`), as well as `none`.
- {{CSSxRef("@counter-style")}}, {{CSSxRef("list-style-type")}}
- : Forbids the global CSS values (`unset`, `initial`, and `inherit`), as well as the values:
- `none`
- `inline`
- `outside`
Also, quite a few predefined values are implemented by the different browsers:
- `disc`
- `circle`
- `square`
- `decimal`
- `cjk-decimal`
- `decimal-leading-zero`
- `lower-roman`
- `upper-roman`
- `lower-greek`
- `lower-alpha`
- `lower-latin`
- `upper-alpha`
- `upper-latin`
- `arabic-indic`
- `armenian`
- `bengali`
- `cambodian`
- `cjk-earthly-branch`
- `cjk-heavenly-stem`
- `cjk-ideographic`
- `devanagari`
- `ethiopic-numeric`
- `georgian`
- `gujarati`
- `gurmukhi`
- `hebrew`
- `hiragana`
- `hiragana-iroha`
- `japanese-formal`
- `japanese-informal`
- `kannada`
- `katakana`
- `katakana-iroha`
- `khmer`
- `korean-hangul-formal`
- `korean-hanja-formal`
- `korean-hanja-informal`
- `lao`
- `lower-armenian`
- `malayalam`
- `mongolian`
- `myanmar`
- `oriya`
- `persian`
- `simp-chinese-formal`
- `simp-chinese-informal`
- `tamil`
- `telugu`
- `thai`
- `tibetan`
- `trad-chinese-formal`
- `trad-chinese-informal`
- `upper-armenian`
- `disclosure-open`
- `disclosure-close`
- {{CSSxRef("grid-row-start")}}, {{CSSxRef("grid-row-end")}}, {{CSSxRef("grid-column-start")}}, {{CSSxRef("grid-column-end")}}
- : Forbids the `span` value.
- {{CSSxRef("view-transition-name")}}
- : Forbids the global CSS values (`unset`, `initial`, and `inherit`), as well as `none`.
- {{CSSxRef("will-change")}}
- : Forbids the global CSS values (`unset`, `initial`, and `inherit`), as well as the values `will-change`, `auto`, `scroll-position`, and `contents`.
## Examples
### Valid identifiers
```plain example-good
nono79 A mix of alphanumeric characters and numbers
ground-level A mix of alphanumeric characters and a dash
-test A dash followed by alphanumeric characters
_internal An underscore followed by alphanumeric characters
\22 toto A Unicode character followed by a sequence of alphanumeric characters
bili\.bob A correctly escaped period
```
### Invalid identifiers
```plain example-bad
34rem It must not start with a decimal digit.
-12rad It must not start with a dash followed by a decimal digit.
bili.bob Only alphanumeric characters, _, and - needn't be escaped.
'bilibob' This would be a <string>.
"bilibob" This would be a <string>.
```
## Specifications
{{Specifications}}
## Browser compatibility
_As this type is not a real type but a convenience type used to simplify the description of allowed values, there is no browser compatibility information as such._
## See also
- [<ident>](/en-US/docs/Web/CSS/ident)
- [<dashed-ident>](/en-US/docs/Web/CSS/dashed-ident)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_doublecolon_-webkit-slider-thumb/index.md | ---
title: "::-webkit-slider-thumb"
slug: Web/CSS/::-webkit-slider-thumb
page-type: css-pseudo-element
status:
- experimental
browser-compat: css.selectors.-webkit-slider-thumb
---
{{CSSRef}}{{SeeCompatTable}}
The **`::-webkit-slider-thumb`** CSS [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) represents the "thumb" that the user can move within the "groove" of an {{HTMLElement("input")}} of `type="range"` to alter its numerical value.
## Syntax
```css
::-webkit-slider-thumb {
/* ... */
}
```
## Specifications
Not part of any standard.
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("::-webkit-slider-runnable-track")}}
- Similar pseudo-elements used by other browsers:
- {{cssxref("::-moz-range-thumb")}}
- [CSS-Tricks: Styling Cross-Browser Compatible Range Inputs with CSS](https://css-tricks.com/styling-cross-browser-compatible-range-inputs-css/)
- [QuirksMode: Styling and scripting sliders](https://www.quirksmode.org/blog/archives/2015/11/styling_and_scr.html)
- [Couple of Gotchas to Watch-out For](https://brennaobrien.com/blog/2014/05/style-input-type-range-in-every-browser.html)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/max-content/index.md | ---
title: max-content
slug: Web/CSS/max-content
page-type: css-keyword
browser-compat: css.properties.width.max-content
---
{{CSSRef}}
The `max-content` sizing keyword represents the intrinsic maximum width or height of the content. For text content this means that the content will not wrap at all even if it causes overflows.
## Syntax
```css
/* Used as a length */
width: max-content;
inline-size: max-content;
height: max-content;
block-size: max-content;
/* used in grid tracks */
grid-template-columns: 200px 1fr max-content;
```
## Examples
### Using max-content for box sizing
#### HTML
```html
<div id="container">
<div class="item">Item</div>
<div class="item">
Item with more text in it which will overflow the fixed width box.
</div>
</div>
```
#### CSS
```css
#container {
background-color: #8cffa0;
padding: 10px;
width: 200px;
}
.item {
width: max-content;
background-color: #8ca0ff;
padding: 5px;
margin-bottom: 1em;
}
```
#### Result
{{EmbedLiveSample("Using_max-content_for_box_sizing", "100%", 200)}}
### Sizing grid columns with max-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: max-content max-content 1fr;
grid-gap: 5px;
box-sizing: border-box;
height: 200px;
width: 100%;
background-color: #8cffa0;
padding: 10px;
}
#container > div {
background-color: #8ca0ff;
padding: 5px;
}
```
#### Result
{{EmbedLiveSample("Sizing_grid_columns_with_max-content", "100%", 200)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- Related sizing keywords: {{cssxref("min-content")}}, {{cssxref("fit-content")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/scroll-padding-inline-start/index.md | ---
title: scroll-padding-inline-start
slug: Web/CSS/scroll-padding-inline-start
page-type: css-property
browser-compat: css.properties.scroll-padding-inline-start
---
{{CSSRef}}
The `scroll-padding-inline-start` property defines offsets for the start edge in the inline dimension of the _optimal viewing region_ of the scrollport: the region used as the target region for placing things in view of the user. This allows the author to exclude regions of the scrollport that are obscured by other content (such as fixed-positioned toolbars or sidebars) or to put more breathing room between a targeted element and the edges of the scrollport.
{{EmbedInteractiveExample("pages/css/scroll-padding-inline-start.html")}}
## Syntax
```css
/* Keyword values */
scroll-padding-inline-start: auto;
/* <length> values */
scroll-padding-inline-start: 10px;
scroll-padding-inline-start: 1em;
scroll-padding-inline-start: 10%;
/* Global values */
scroll-padding-inline-start: inherit;
scroll-padding-inline-start: initial;
scroll-padding-inline-start: revert;
scroll-padding-inline-start: revert-layer;
scroll-padding-inline-start: unset;
```
### Values
- `<length-percentage>`
- : An inwards offset from the inline start edge of the scrollport, as a valid length or a percentage.
- `auto`
- : The offset is determined by the user agent. This will generally be 0px, but a user agent is able to detect and do something else if a non-zero value is more appropriate.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [CSS scroll snap](/en-US/docs/Web/CSS/CSS_scroll_snap)
- [Well-controlled scrolling with CSS scroll snap](https://web.dev/articles/css-scroll-snap)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/mod/index.md | ---
title: mod()
slug: Web/CSS/mod
page-type: css-function
browser-compat: css.types.mod
---
{{CSSRef}}
The **`mod()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) returns a modulus left over when the first parameter is divided by the second parameter, similar to the JavaScript [remainder operator (`%`)](/en-US/docs/Web/JavaScript/Reference/Operators/Remainder). The modulus is the value left over when one operand, the dividend, is divided by a second operand, the divisor. It always takes the sign of the divisor.
> For example, the CSS `mod(21, -4)` function returns the remainder of `-1`. When dividing 21 by -4, the result is 5 with a remainder of -1. The full calculation is `21 / -4 = -4 * 5 - 1`.
## Syntax
```css
/* Unitless <number> */
line-height: mod(7, 2); /* 1 */
line-height: mod(14, 5); /* 4 */
line-height: mod(3.5, 2); /* 1.5 */
/* Unit based <percentage> and <dimension> */
margin: mod(15%, 2%); /* 1% */
margin: mod(18px, 4px); /* 2px */
margin: mod(19rem, 5rem); /* 4rem */
margin: mod(29vmin, 6vmin); /* 5vmin */
margin: mod(1000px, 29rem); /* 72px - if root font-size is 16px */
/* Negative/positive values */
rotate: mod(100deg, 30deg); /* 10deg */
rotate: mod(135deg, -90deg); /* -45deg */
rotate: mod(-70deg, 20deg); /* 10deg */
rotate: mod(-70deg, -15deg); /* -10deg */
/* Calculations */
scale: mod(10 * 2, 1.7); /* 1.3 */
rotate: mod(10turn, 18turn / 3); /* 4turn */
transition-duration: mod(20s / 2, 3000ms * 2); /* 4s */
```
### Parameter
The `mod(dividend, divisor)` function accepts two comma-separated values as its parameters. Both parameters must have the same type, [number](/en-US/docs/Web/CSS/number), [dimension](/en-US/docs/Web/CSS/dimension), or {{cssxref("percentage")}}, for the function to be valid. While the units in the two parameters don't need to be the same, they do need of the same dimension type, such as {{cssxref("length")}}, {{cssxref("angle")}}, {{cssxref("time")}}, or {{cssxref("frequency")}} to be valid.
- `dividend`
- : A calculation that resolves to a {{CSSxREF("<number>")}}, {{CSSxREF("<dimension>")}}, or {{CSSxREF("<percentage>")}} representing the dividend.
- `divisor`
- : A calculation that resolves to a {{CSSxREF("<number>")}}, {{CSSxREF("<dimension>")}}, or {{CSSxREF("<percentage>")}} representing the divisor.
### Return value
Returns a {{CSSxREF("<number>")}}, {{CSSxREF("<dimension>")}}, or {{CSSxREF("<percentage>")}} (corresponds to the parameters' type) representing the modulus, that is, the operation left over.
- If `divisor` is `0`, the result is `NaN`.
- If `dividend` is `infinite`, the result is `NaN`.
- If `divisor` is positive the result is positive (`0⁺`), and if `divisor` is negative the result is negative (`0⁻`).
### Formal syntax
{{CSSSyntax}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef("round")}}
- {{CSSxRef("rem")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_-moz-window-inactive/index.md | ---
title: ":-moz-window-inactive"
slug: Web/CSS/:-moz-window-inactive
page-type: css-pseudo-class
status:
- non-standard
browser-compat: css.selectors.-moz-window-inactive
---
{{CSSRef}}{{Non-standard_header}}
The **`:-moz-window-inactive`** [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 any element while it's in an inactive window.
`:-moz-window-inactive` works in content HTML documents, too.
> **Note:** Prior to the addition of this pseudo-class, giving different styles to background windows was achieved by setting an attribute (`active="true"`) on the top-level XUL chrome window. This attribute is no longer used.
## Syntax
```css
:-moz-window-inactive {
/* ... */
}
```
## Examples
This example alters the appearance of a box's background depending on whether its window is active or not.
### HTML
```html
<div id="mybox">
<p>This is a box!</p>
</div>
```
### CSS
```css
#mybox {
background: linear-gradient(to bottom, yellow, cyan);
width: 200px;
height: 200px;
}
#mybox:-moz-window-inactive {
background: cyan;
}
```
### Result
The result of this code is shown below. You can view this as a {{LiveSampleLink('Examples', 'separate page')}} as well.
{{EmbedLiveSample('Examples', 220, 220)}}
## Specifications
Not part of any standard.
## Browser compatibility
{{Compat}}
## See also
- [Mozilla CSS extensions](/en-US/docs/Web/CSS/Mozilla_Extensions)
- Related CSS selectors:
- [`:active`](/en-US/docs/Web/CSS/:active)
- The {{domxref("Document.activeElement")}} property for regular DOM, and the {{domxref("ShadowRoot.activeElement")}} property for [shadow DOM](/en-US/docs/Web/API/Web_components/Using_shadow_DOM) roots.
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/column-span/index.md | ---
title: column-span
slug: Web/CSS/column-span
page-type: css-property
browser-compat: css.properties.column-span
---
{{CSSRef}}
The **`column-span`** [CSS](/en-US/docs/Web/CSS) property makes it possible for an element to span across all columns when its value is set to `all`.
{{EmbedInteractiveExample("pages/css/column-span.html")}}
An element that spans more than one column is called a **spanning element**.
## Syntax
```css
/* Keyword values */
column-span: none;
column-span: all;
/* Global values */
column-span: inherit;
column-span: initial;
column-span: revert;
column-span: revert-layer;
column-span: unset;
```
The `column-span` property is specified as one of the keyword values listed below.
### Values
- `none`
- : The element does not span multiple columns.
- `all`
- : The element spans across all columns. Content in the normal flow that appears before the element is automatically balanced across all columns before the element appears. The element establishes a new block formatting context.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Making a heading span columns
In this example, the heading is made to span across all the columns of the article.
#### HTML
```html
<article>
<h2>Header spanning all of the columns</h2>
<p>
The h2 should span all the columns. The rest of the text should be
distributed among the columns.
</p>
<p>
This is a bunch of text split into three columns using the CSS `columns`
property. The text is equally distributed over the columns.
</p>
<p>
This is a bunch of text split into three columns using the CSS `columns`
property. The text is equally distributed over the columns.
</p>
<p>
This is a bunch of text split into three columns using the CSS `columns`
property. The text is equally distributed over the columns.
</p>
<p>
This is a bunch of text split into three columns using the CSS `columns`
property. The text is equally distributed over the columns.
</p>
</article>
```
#### CSS
```css
article {
columns: 3;
}
h2 {
column-span: all;
}
```
#### Result
{{EmbedLiveSample('Making_a_heading_span_columns', 'auto', 260)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Spanning and balancing columns](/en-US/docs/Web/CSS/CSS_multicol_layout/Spanning_balancing_columns)
- [Inline-level elements](/en-US/docs/Glossary/Inline-level_content)
- {{domxref("HTMLSpanElement")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/replaced_element/index.md | ---
title: Replaced elements
slug: Web/CSS/Replaced_element
page-type: guide
---
{{CSSRef}}
In [CSS](/en-US/docs/Web/CSS), a **replaced element** is an element whose representation is outside the scope of CSS; they're external objects whose representation is independent of the CSS formatting model.
Put in simpler terms, they're elements whose contents are not affected by the current document's styles. The position of the replaced element can be affected using CSS, but not the contents of the replaced element itself. Some replaced elements, such as {{HTMLElement("iframe")}} elements, may have stylesheets of their own, but they don't inherit the styles of the parent document.
The only other impact CSS can have on a replaced element is that there are properties which support controlling the positioning of the element's content within its box. See [Controlling object position within the content box](#controlling_object_position_within_the_content_box) for further information.
## Replaced elements
Typical replaced elements are:
- {{HTMLElement("iframe")}}
- {{HTMLElement("video")}}
- {{HTMLElement("embed")}}
- {{HTMLElement("img")}}
Some elements are treated as replaced elements only in specific cases:
- {{HTMLElement("option")}}
- {{HTMLElement("audio")}}
- {{HTMLElement("canvas")}}
- {{HTMLElement("object")}}
HTML spec also says that an {{HTMLElement("input")}} element can be replaced, because {{HTMLElement("input")}} elements of the `"image"` type are replaced elements similar to {{HTMLElement("img")}}. However, other form controls, including other types of {{HTMLElement("input")}} elements, are explicitly listed as non-replaced elements (the spec describes their default platform-specific rendering with the term "Widgets").
Objects inserted using the CSS {{cssxref("content")}} property are _anonymous replaced elements_. They are "anonymous" because they don't exist in the HTML markup.
## Using CSS with replaced elements
CSS handles replaced elements specifically in some cases, like when calculating margins and some `auto` values.
Note that some replaced elements, but not all, have intrinsic dimensions or a defined baseline, which is used by some CSS properties, such as {{cssxref("vertical-align")}}. Only replaced elements can ever have intrinsic dimensions.
### Controlling object position within the content box
Certain CSS properties can be used to specify how the object contained within the replaced element should be positioned within the element's box area. These are defined by the [CSS Images](https://drafts.csswg.org/css-images/) specification:
- {{cssxref("object-fit")}}
- : Specifies how the replaced element's content object should be fitted to the containing element's box.
- {{cssxref("object-position")}}
- : Specifies the alignment of the replaced element's content object within the element's box.
## See also
- [HTML Spec](https://html.spec.whatwg.org/multipage/rendering.html#replaced-elements)
- {{glossary("void element", "Void elements")}}
- CSS key concepts:
- [CSS syntax](/en-US/docs/Web/CSS/Syntax)
- [At-rules](/en-US/docs/Web/CSS/At-rule)
- [Comments](/en-US/docs/Web/CSS/Comments)
- [Specificity](/en-US/docs/Web/CSS/Specificity)
- [Inheritance](/en-US/docs/Web/CSS/Inheritance)
- [Box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model)
- [Layout modes](/en-US/docs/Web/CSS/Layout_mode)
- [Visual formatting models](/en-US/docs/Web/CSS/Visual_formatting_model)
- [Margin collapsing](/en-US/docs/Web/CSS/CSS_box_model/Mastering_margin_collapsing)
- Values
- [Initial values](/en-US/docs/Web/CSS/initial_value)
- [Computed values](/en-US/docs/Web/CSS/computed_value)
- [Used values](/en-US/docs/Web/CSS/used_value)
- [Actual values](/en-US/docs/Web/CSS/actual_value)
- [Value definition syntax](/en-US/docs/Web/CSS/Value_definition_syntax)
- [Shorthand properties](/en-US/docs/Web/CSS/Shorthand_properties)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/font-variation-settings/index.md | ---
title: font-variation-settings
slug: Web/CSS/font-variation-settings
page-type: css-property
browser-compat: css.properties.font-variation-settings
---
{{CSSRef}}
The **`font-variation-settings`** CSS property provides low-level control over [variable font](/en-US/docs/Web/CSS/CSS_fonts/Variable_fonts_guide) characteristics by letting you specify the four letter axis names of the characteristics you want to vary along with their values.
{{EmbedInteractiveExample("pages/css/font-variation-settings.html")}}
## Syntax
```css
/* Use the default settings */
font-variation-settings: normal;
/* Set values for variable font axis names */
font-variation-settings: "XHGT" 0.7;
/* Global values */
font-variation-settings: inherit;
font-variation-settings: initial;
font-variation-settings: revert;
font-variation-settings: revert-layer;
font-variation-settings: unset;
```
### Values
This property's value can take one of two forms:
- `normal`
- : Text is laid out using default settings.
- `<string> <number>`
- : When rendering text, the list of variable font axis names is passed to the text layout engine to enable or disable font features. Each setting is always one or more pairs consisting of a {{cssxref("<string>")}} of 4 ASCII characters followed by a {{cssxref("number")}} indicating the axis value to set. If the `<string>` has more or fewer characters or contains characters outside the U+20 - U+7E code point range, the whole property is invalid. The `<number>` can be fractional or negative, depending on the value range available in your font, as defined by the font designer.
## Description
This property is a low-level mechanism designed to set variable font features where no other way to enable or access those features exist. You should only use it when no basic properties exist to set those features (e.g. {{cssxref("font-weight")}}, {{cssxref("font-style")}}).
Font characteristics set using `font-variation-settings` will always override those set using the corresponding basic font properties, e.g. `font-weight`, no matter where they appear in the cascade. In some browsers, this is currently only true when the {{cssxref("@font-face")}} declaration includes a {{cssxref("@font-face/font-weight", "font-weight")}} range.
### Registered and custom axes
Variable font axes come in two types: **registered** and **custom**.
Registered axes are the most commonly encountered — common enough that the authors of the specification felt they were worth standardizing. Note that this doesn't mean that the author has to include all of these in their font.
Here are the registered axes along with their corresponding CSS properties:
<table class="standard-table">
<thead>
<tr>
<th scope="col">Axis Tag</th>
<th scope="col">CSS Property</th>
</tr>
</thead>
<tbody>
<tr>
<td>"wght"</td>
<td>{{cssxref("font-weight")}}</td>
</tr>
<tr>
<td>"wdth"</td>
<td>{{cssxref("font-stretch")}}</td>
</tr>
<tr>
<td>"slnt" (slant)</td>
<td>{{cssxref("font-style")}}: <code>oblique + angle</code></td>
</tr>
<tr>
<td>"ital"</td>
<td>{{cssxref("font-style")}}: <code>italic</code></td>
</tr>
<tr>
<td>"opsz"</td>
<td><p>{{cssxref("font-optical-sizing")}}</p></td>
</tr>
</tbody>
</table>
Custom axes can be anything the font designer wants to vary in their font, for example ascender or descender heights, the size of serifs, or anything else they can imagine. Any axis can be used as long as it is given a unique 4-character axis. Some will end up becoming more common, and may even become registered over time.
> **Note:** Registered axis tags are identified using lower-case tags, whereas custom axes should be given upper-case tags. Note that font designers aren't forced to follow this practice in any way, and some won't. The important takeaway here is that axis tags are case-sensitive.
To use variable fonts on your operating system, you need to make sure that it is up to date. For example Linux OSes need the latest Linux Freetype version, and macOS before 10.13 does not support variable fonts. If your operating system is not up to date, you will not be able to use variable fonts in web pages or the Firefox Developer Tools.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
You can find a number of other variable font examples in our [Variable fonts guide](/en-US/docs/Web/CSS/CSS_fonts/Variable_fonts_guide).
### Controlling variable font weight (wght)
You can edit the CSS in the example below to play with different font weight values. See what happens when you specify a value outside the weight range.
{{EmbedGHLiveSample("css-examples/variable-fonts/weight.html", '100%', 940)}}
### Controlling variable font slant (slnt)
You can edit the CSS in the example below to play with different font slant/oblique values.
{{EmbedGHLiveSample("css-examples/variable-fonts/slant.html", '100%', 940)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Variable fonts guide](/en-US/docs/Web/CSS/CSS_fonts/Variable_fonts_guide)
- [OpenType font variations overview](https://learn.microsoft.com/en-us/typography/opentype/spec/otvaroverview) on microsoft.com
- [OpenType design-variation axis tag registry](https://docs.microsoft.com/typography/opentype/spec/dvaraxisreg) on microsoft.com
- [OpenType variable fonts](https://www.axis-praxis.org/) on axis-praxis.org
- [Variable fonts](https://v-fonts.com/) on v-fonts.com
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/css_lists/index.md | ---
title: CSS lists and counters
slug: Web/CSS/CSS_lists
page-type: css-module
spec-urls: https://drafts.csswg.org/css-lists/
---
{{CSSRef}}
The **CSS lists and counters** module enables styling and positioning of list item bullets and manipulating their values with a combination of strings, counters, and other features.
A list item's marker, whether a bullet symbol or ordinal counter, is its defining feature. List items are not limited to {{HTMLElement("li")}} elements nested within {{HTMLElement("ol")}} or {{HTMLElement("ul")}} elements. Rather, list items are any element with `display: list-item` set.
This module defines CSS features to set and reset a list's counters, set which [counter-styles](/en-US/docs/Web/CSS/CSS_counter_styles) or symbols to use as its markers, and position those markers. It also provides developers with the ability to create customized markers.
## Reference
### Properties
- {{cssxref("counter-increment")}}
- {{cssxref("counter-reset")}}
- {{cssxref("counter-set")}}
- {{cssxref("list-style-image")}}
- {{cssxref("list-style-type")}}
- {{cssxref("list-style-position")}}
- {{cssxref("list-style")}} shorthand
There is also a `marker-side` property, which is yet to be fully defined or implemented.
### Pseudo-elements
- {{cssxref("::marker")}}
### Functions
- {{cssxref("counter")}}
- {{cssxref("counters")}}
### Data types
- [`<counter>`](/en-US/docs/Web/CSS/content#counter)
- [`<counter-name>`](/en-US/docs/Web/CSS/counter#counter-name)
- [`<counter-style>`](/en-US/docs/Web/CSS/counter#counter-style)
## Guides
- [Consistent list indentation](/en-US/docs/Web/CSS/CSS_lists/Consistent_list_indentation)
- : Explains how to achieve consistent list indentation across different browsers.
- [Using CSS Counters](/en-US/docs/Web/CSS/CSS_counter_styles/Using_CSS_counters)
- : Explains how to use the CSS counter properties to control list counters.
## Related concepts
- [CSS counter styles](/en-US/docs/Web/CSS/CSS_counter_styles)
- {{cssxref("@counter-style")}} at-rule
- [`<counter-style-name>`](/en-US/docs/Web/CSS/@counter-style#counter-style-name) data type
- [`<symbol>`](/en-US/docs/Web/CSS/@counter-style/symbols#values) data type
- {{cssxref("symbols", "symbols()")}} function
- {{HTMLElement("ol")}} `start`, `reversed`, and `type` attributes
- {{HTMLElement("ul")}} `type` attribute
- {{HTMLElement("li")}} `type` and `value` attributes
## Specifications
{{Specifications}}
## See also
- [CSS counter styles](/en-US/docs/Web/CSS/CSS_counter_styles) module
- [CSS pseudo-elements](/en-US/docs/Web/CSS/CSS_pseudo-elements) module
- [CSS generated content](/en-US/docs/Web/CSS/CSS_generated_content) module
| 0 |
data/mdn-content/files/en-us/web/css/css_lists | data/mdn-content/files/en-us/web/css/css_lists/consistent_list_indentation/index.md | ---
title: Consistent list indentation
slug: Web/CSS/CSS_lists/Consistent_list_indentation
page-type: guide
---
{{CSSRef}}
One of the most common style changes made to lists is a change in the indentation distance—that is, how far the list items are pushed over to the right. This article will help you understand indenting list items so that list item markers are visible.
To understand why this is the case, and more importantly how to avoid the problem altogether, it's necessary to examine the details of list construction.
## Making a List
### The stand-alone list item
First, we consider the pure list item, not nested in a list of items. When using the HTML {{htmlelement("li")}} element, the browser sets the {{cssxref("display")}} value to `list-item`. Whether list items not nested in a list are provided a marker (otherwise known as a "bullet") depends on the browser. We can remove that bullet with {{cssxref("list-style-type")}}`: none`.
```css
li {
border: 1px dashed red;
}
li:nth-of-type(n + 4) {
list-style-type: none;
}
```
```css hidden
li {
width: 15em;
}
```
```html hidden
<p>Default bullets depend on the browser:</p>
<li>A list item</li>
<li>A list item</li>
<li>A list item</li>
<p>These list items have their bullets removed:</p>
<li>A list item</li>
<li>A list item</li>
<li>A list item</li>
```
{{EmbedLiveSample("The stand-alone list item", "100%", 200)}}
That dotted red border represents the outer edges of the content area of each list item. At this point, the list items have no padding or borders.
### List items nested in a list
Now we wrap these in a parent element; in this case, we'll wrap them in an unordered list (i.e., `<ul>`). According to the CSS box model, the list items' boxes must be displayed within the parent element's content area.
```css
ul {
border: 1px dashed blue;
}
li {
border: 1px dashed red;
list-style-type: none;
}
```
```css hidden
body {
width: 15em;
}
```
```html hidden
<ul>
<li>A list item</li>
<li>A list item</li>
<li>A list item</li>
</ul>
```
{{EmbedLiveSample("List items nested in a list", "100%", 150)}}
The dotted blue border shows us the edges of the `<ul>` element's content area. That parent comes with both margin and padding. Browsers set the following default styles on unordered lists:
```css
ul {
/* user-agent styles */
display: block;
list-style-type: disc;
margin-block-start: 1em;
margin-block-end: 1em;
padding-inline-start: 40px;
}
```
### Default bullet position
Now we put the list item markers back in. Since this is an unordered list, the list items inherit `list-style-type: disc;` browser styles, which are filled-circle "bullets," from their `<ul>` parent.
```css
li {
border: 1px dashed red;
}
ul {
border: 1px dotted blue;
}
ul:last-of-type {
list-style-position: inside;
}
```
```css hidden
ul {
width: 15em;
}
```
```html hidden
<p>These default to <code>list-style-position: outside</code>.</p>
<ul>
<li>A list item</li>
<li>A list item</li>
<li>A list item</li>
</ul>
<p>These have <code>list-style-position: inside</code> set.</p>
<ul>
<li>A list item</li>
<li>A list item</li>
<li>A list item</li>
</ul>
```
{{EmbedLiveSample("Inheriting `list-style-type`", "100%", 220)}}
Visually, the markers are _outside_ the content area of the `<ul>`, but that's not the important part here. What's key is that the markers are placed outside the "principal box" of the `<li>` elements, not the `<ul>`. They're sort of like appendages to the list items, hanging outside the content-area of the `<li>` but still attached to the `<li>`.
This is why, in every modern browser, markers are placed outside any border set for an `<li>` element when the value of {{cssxref("list-style-position")}} defaults to or is explicitly set to `outside`. When we changed it to `inside`, the markers were brought inside the `<li>`'s content, as though they're an inline box placed at the very beginning of the `<li>`.
## Default indentation
As noted above, all browsers provide the `<ul>` parent both margin and padding. While user agents CSS differ somewhat, they all include:
```css
ul,
ol {
/* user-agent styles */
display: block;
list-style-type: disc;
margin-block-start: 1em;
margin-block-end: 1em;
padding-inline-start: 40px;
}
ol {
list-style-type: decimal;
}
li {
display: list-item;
text-align: match-parent;
}
::marker {
unicode-bidi: isolate;
font-variant-numeric: tabular-nums;
text-transform: none;
}
```
All browsers set {{cssxref("padding-inline-start")}} to 40 pixels for the `<ul>` element by default. In left-to-right languages, like English, this is the left _padding_. Any padding set in the author style sheets (that's your stylesheet) takes precedence.
If you want to be explicit, set the following in your style sheets to ensure, unless otherwise overridden, the list items in the main content area of your document, contained in the {{htmlelement("main")}} section, are properly indented:
```css
:where(main ol, main ul) {
margin-inline-start: 0;
padding-inline-start: 40px;
}
```
And always nest your `<li>` elements in a `<ul>` or `<ol>`.
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/min-height/index.md | ---
title: min-height
slug: Web/CSS/min-height
page-type: css-property
browser-compat: css.properties.min-height
---
{{CSSRef}}
The **`min-height`** [CSS](/en-US/docs/Web/CSS) property sets the minimum height of an element. It prevents the [used value](/en-US/docs/Web/CSS/used_value) of the {{cssxref("height")}} property from becoming smaller than the value specified for `min-height`.
{{EmbedInteractiveExample("pages/css/min-height.html")}}
The element's height is set to the value of `min-height` whenever `min-height` is larger than {{cssxref("max-height")}} or {{cssxref("height")}}.
## Syntax
```css
/* <length> value */
min-height: 3.5em;
/* <percentage> value */
min-height: 10%;
/* Keyword values */
min-height: max-content;
min-height: min-content;
min-height: fit-content;
min-height: fit-content(20em);
/* Global values */
min-height: inherit;
min-height: initial;
min-height: revert;
min-height: revert-layer;
min-height: unset;
```
### Values
- {{cssxref("<length>")}}
- : Defines the `min-height` as an absolute value.
- {{cssxref("<percentage>")}}
- : Defines the `min-height` as a percentage of the containing block's height.
- `auto`
- : The browser will calculate and select a `min-height` for the specified element.
- `max-content`
- : The intrinsic preferred `min-height`.
- `min-content`
- : The intrinsic minimum `min-height`.
- `fit-content`
- : Use the available space, but not more than [max-content](/en-US/docs/Web/CSS/max-content), i.e `min(max-content, max(min-content, stretch))`.
- `fit-content({{cssxref("<length-percentage>")}})` {{Experimental_Inline}}
- : Uses the `fit-content` formula with the available space replaced by the specified argument, i.e. `min(max-content, max(min-content, argument))`.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting min-height
```css
table {
min-height: 75%;
}
form {
min-height: 0;
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [The box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model), {{cssxref("box-sizing")}}
- {{cssxref("height")}}, {{cssxref("max-height")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/user-select/index.md | ---
title: user-select
slug: Web/CSS/user-select
page-type: css-property
browser-compat: css.properties.user-select
---
{{CSSRef}}
The **`user-select`** [CSS](/en-US/docs/Web/CSS) property controls whether the user can select text. This doesn't have any effect on content loaded as part of a browser's user interface (its {{Glossary("Chrome", "chrome")}}), except in textboxes.
{{EmbedInteractiveExample("pages/css/user-select.html")}}
## Syntax
```css
/* Keyword values */
user-select: none;
user-select: auto;
user-select: text;
user-select: contain;
user-select: all;
/* Global values */
user-select: inherit;
user-select: initial;
user-select: revert;
user-select: revert-layer;
user-select: unset;
```
> **Note:** `user-select` is not an inherited property, though the initial `auto` value makes it behave like it is inherited most of the time. WebKit/Chromium-based browsers _do_ implement the property as inherited, which violates the behavior described in the spec, and this will bring some issues. Until now, Chromium has chosen to [fix the issues](https://chromium.googlesource.com/chromium/src/+/b01af0b296ecb855aac95c4ed335d188e6eac2de) to make the final behavior meet the specifications.
### Values
- `none`
- : The text of the element and its sub-elements is not selectable. Note that the {{domxref("Selection")}} object can contain these elements.
- `auto`
- : The used value of `auto` is determined as follows:
- On the `::before` and `::after` pseudo elements, the used value is `none`
- If the element is an editable element, the used value is `contain`
- Otherwise, if the used value of `user-select` on the parent of this element is `all`, the used value is `all`
- Otherwise, if the used value of `user-select` on the parent of this element is `none`, the used value is `none`
- Otherwise, the used value is `text`
- `text`
- : The text can be selected by the user.
- `all`
- : The content of the element shall be selected atomically: If a selection would contain part of the element, then the selection must contain the entire element including all its descendants. If a double-click or context-click occurred in sub-elements, the highest ancestor with this value will be selected.
- `contain`
- : Enables selection to start within the element; however, the selection will be contained by the bounds of that element.
> **Note:** CSS UI 4 [renamed](https://github.com/w3c/csswg-drafts/commit/3f1d9db96fad8d9fc787d3ed66e2d5ad8cfadd05) the `element` value to `contain`.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### HTML
```html
<p>You should be able to select this text.</p>
<p class="unselectable">Hey, you can't select this text!</p>
<p class="all">Clicking once will select all of this text.</p>
```
### CSS
```css
.unselectable {
-webkit-user-select: none; /* Safari */
user-select: none;
}
.all {
-webkit-user-select: all;
user-select: all;
}
```
### Result
{{EmbedLiveSample("Examples")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Polyfill for `user-select: contain`](https://github.com/github/user-select-contain-polyfill)
- {{Cssxref("::selection")}} pseudo-element
- The JavaScript {{domxref("Selection")}} object
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/-webkit-tap-highlight-color/index.md | ---
title: "-webkit-tap-highlight-color"
slug: Web/CSS/-webkit-tap-highlight-color
page-type: css-property
status:
- non-standard
browser-compat: css.properties.-webkit-tap-highlight-color
---
{{CSSRef}}{{Non-standard_header}}
**`-webkit-tap-highlight-color`** is a non-standard CSS property that sets the color of the highlight that appears over a link while it's being tapped. The highlighting indicates to the user that their tap is being successfully recognized, and indicates which element they're tapping on.
## Syntax
```css
-webkit-tap-highlight-color: red;
-webkit-tap-highlight-color: transparent; /* for removing the highlight */
/* Global values */
-webkit-tap-highlight-color: inherit;
-webkit-tap-highlight-color: initial;
-webkit-tap-highlight-color: revert;
-webkit-tap-highlight-color: revert-layer;
-webkit-tap-highlight-color: unset;
```
### Values
A {{Cssxref("<color>")}}.
## Formal definition
{{CSSInfo}}
## Formal syntax
```plain
-webkit-tap-highlight-color =
<color>
```
## Specifications
Not part of any standard. Apple has [a description in the Safari Web Content Guide](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/AdjustingtheTextSize/AdjustingtheTextSize.html#//apple_ref/doc/uid/TP40006510-SW5).
## Browser compatibility
{{Compat}}
## See also
- [WebKit CSS extensions](/en-US/docs/Web/CSS/WebKit_Extensions)
- Related CSS pseudo-classes:
- [`:hover`](/en-US/docs/Web/CSS/:hover)
- [`:active`](/en-US/docs/Web/CSS/:active)
- [`:visited`](/en-US/docs/Web/CSS/:visited)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/font-variant-emoji/index.md | ---
title: font-variant-emoji
slug: Web/CSS/font-variant-emoji
page-type: css-property
browser-compat: css.properties.font-variant-emoji
---
{{CSSRef}}
The **`font-variant-emoji`** [CSS](/en-US/docs/Web/CSS) property specifies the default presentation style for displaying emojis.
Traditionally, this was done by appending a _Variation Selector_, `U+FE0E` for text and `U+FE0F` for emoji, to the emoji code point. Only emojis listed as contributing to a [Unicode emoji presentation sequence](https://www.unicode.org/emoji/charts/emoji-variants.html) are affected by this property.
## Syntax
```css
/* Keyword values */
font-variant-emoji: normal;
font-variant-emoji: text;
font-variant-emoji: emoji;
font-variant-emoji: unicode;
/* Global values */
font-variant-emoji: inherit;
font-variant-emoji: initial;
font-variant-emoji: revert;
font-variant-emoji: revert-layer;
font-variant-emoji: unset;
```
The `font-variant-emoji` property is specified using a single keyword value from the list below.
### Values
- `normal`
- : Allows a browser to choose how to display the emoji. This often follows the operating system setting.
- `text`
- : Renders the emoji as if it were using the unicode text variation selector (`U+FE0E`).
- `emoji`
- : Renders the emoji as if it were using the unicode emoji variation selector (`U+FE0F`).
- `unicode`
- : Renders the emoji in accordance with the [Emoji presentation properties](https://www.unicode.org/reports/tr51/tr51-23.html#Emoji_Presentation). If the `U+FE0E` or `U+FE0F` variation selector is present, then it will override this value setting.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{CSSSyntax}}
## Examples
### Changing the way an emoji is displayed
This example shows how you can render an emoji in its `text` or `emoji` presentation.
#### HTML
```html hidden
<p class="nosupport">
Your Browser does not support <code>font-variant-emoji</code>. This image
shows how it is rendered with support.
</p>
<img
class="nosupport"
src="./font-variant-emoji-example.jpg"
alt="a telephone emoji show as text, black and white next to a telephone emoji shown as emoji full color and graphical representation" />
```
```html
<section class="emojis">
<div class="emoji">
<h2>text presentation</h2>
<div class="text-presentation">☎</div>
</div>
<div class="emoji">
<h2>emoji presentation</h2>
<div class="emoji-presentation">☎</div>
</div>
</section>
```
#### CSS
```css hidden
@supports (font-variant-emoji: emoji) {
.nosupport {
display: none;
}
.emojis {
display: flex;
flex-direction: row;
justify-content: space-around;
}
.emoji > div {
font-size: 2rem;
}
}
@supports not (font-variant-emoji: emoji) {
.emojis {
display: none;
}
}
```
```css
.text-presentation {
font-variant-emoji: text;
}
.emoji-presentation {
font-variant-emoji: emoji;
}
```
#### Result
{{ EmbedLiveSample('Changing the way an emoji is displayed') }}
## Accessibility concerns
While the use of emojis may seem fun, you should consider their impact on accessibility, specifically for users with visual and cognitive impairments. Consider the following factors while using emojis:
- Display on screen-readers: Screen-readers will read out the alt text of an emoji. Keep this in mind to consider the position of an emoji in the content. Repeated and overuse of emojis will have a detrimental effect on screen-reader users. It is better to use emojis than emoticons; emoticons will be read out as punctuation characters.
- Contrast with background: When using emojis, consider their colors and how that will work with the background color, especially if you have background colors that can change, such as light/dark modes.
- Intent of use: Do not use emojis to replace words because your understanding of the emoji meaning may differ from that of the users'. Also consider that emojis might have different meanings in different cultures and geographies. Our recommendation is to preferably limit usage to commonly known emojis.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [font-variant](/en-US/docs/Web/CSS/font-variant)
- [font-variant-alternates](/en-US/docs/Web/CSS/font-variant-alternates)
- [font-variant-caps](/en-US/docs/Web/CSS/font-variant-caps)
- [font-variant-east-asian](/en-US/docs/Web/CSS/font-variant-east-asian)
- [font-variant-ligatures](/en-US/docs/Web/CSS/font-variant-ligatures)
- [font-variant-numeric](/en-US/docs/Web/CSS/font-variant-numeric)
- [Emojis and accessibility: How to use them properly](https://uxdesign.cc/emojis-in-accessibility-how-to-use-them-properly-66b73986b803)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/letter-spacing/index.md | ---
title: letter-spacing
slug: Web/CSS/letter-spacing
page-type: css-property
browser-compat: css.properties.letter-spacing
---
{{CSSRef}}
The **`letter-spacing`** [CSS](/en-US/docs/Web/CSS) property sets the horizontal spacing behavior between text characters. This value is added to the natural spacing between characters while rendering the text. Positive values of `letter-spacing` causes characters to spread farther apart, while negative values of `letter-spacing` bring characters closer together.
{{EmbedInteractiveExample("pages/css/letter-spacing.html")}}
## Syntax
```css
/* Keyword value */
letter-spacing: normal;
/* <length> values */
letter-spacing: 0.3em;
letter-spacing: 3px;
letter-spacing: 0.3px;
/* Global values */
letter-spacing: inherit;
letter-spacing: initial;
letter-spacing: revert;
letter-spacing: revert-layer;
letter-spacing: unset;
```
### Values
- `normal`
- : The normal letter spacing for the current font. Unlike a value of `0`, this keyword allows the {{glossary("user agent")}} to alter the space between characters in order to justify text.
- {{cssxref("<length>")}}
- : Specifies extra inter-character space _in addition to_ the default space between characters. Values may be negative, but there may be implementation-specific limits. User agents may not further increase or decrease the inter-character space in order to justify text.
## Accessibility concerns
A large positive or negative `letter-spacing` value will make the word(s) the styling is applied to unreadable. For text styled with a very large positive value, the letters will be so far apart that the word(s) will appear like a series of individual, unconnected letters. For text styled with a very large negative value, the letters will overlap each other to the point where the word(s) may be unrecognizable.
Legible letter-spacing must be determined on a case-by-case basis, as different font families have different character widths. There is no one value that can ensure all font families automatically maintain their legibility.
- [MDN Understanding WCAG, Guideline 1.4 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background)
- [Understanding Success Criterion 1.4.8 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-visual-presentation.html)
## Internationalization concerns
Some written languages should not have any letter spacing applied. For instance, languages that use the Arabic script expect connected letters to remain visually connected, as in the following example. Applying letter spacing will lead the text to look broken.
> <p lang="ar" dir="rtl">شسيبتنمك</p>
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting letter spacing
#### HTML
```html
<p class="normal">letter spacing</p>
<p class="em-wide">letter spacing</p>
<p class="em-wider">letter spacing</p>
<p class="em-tight">letter spacing</p>
<p class="px-wide">letter spacing</p>
```
#### CSS
```css
.normal {
letter-spacing: normal;
}
.em-wide {
letter-spacing: 0.4em;
}
.em-wider {
letter-spacing: 1em;
}
.em-tight {
letter-spacing: -0.05em;
}
.px-wide {
letter-spacing: 6px;
}
```
#### Result
{{ EmbedLiveSample('Setting_letter_spacing', 440, 185) }}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("font-kerning")}}
- {{cssxref("word-spacing")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/border-inline-end-width/index.md | ---
title: border-inline-end-width
slug: Web/CSS/border-inline-end-width
page-type: css-property
browser-compat: css.properties.border-inline-end-width
---
{{CSSRef}}
The **`border-inline-end-width`** [CSS](/en-US/docs/Web/CSS) property defines the width of the logical inline-end border of an element, which maps to a physical border width depending on the element's writing mode, directionality, and text orientation. It corresponds to the {{cssxref("border-top-width")}}, {{cssxref("border-right-width")}}, {{cssxref("border-bottom-width")}}, or {{cssxref("border-left-width")}} property depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}.
{{EmbedInteractiveExample("pages/css/border-inline-end-width.html")}}
## Syntax
```css
/* <'border-width'> values */
border-inline-end-width: 2px;
border-inline-end-width: thick;
/* Global values */
border-inline-end-width: inherit;
border-inline-end-width: initial;
border-inline-end-width: revert;
border-inline-end-width: revert-layer;
border-inline-end-width: unset;
```
Related properties are {{cssxref("border-block-start-width")}}, {{cssxref("border-block-end-width")}}, and {{cssxref("border-inline-start-width")}}, which define the other border widths of the element.
### Values
- `<'border-width'>`
- : The width of the border. See {{ cssxref("border-width") }}.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Applying a border with vertical text
#### HTML
```html
<div>
<p class="exampleText">Example text</p>
</div>
```
#### CSS
```css
div {
background-color: yellow;
width: 120px;
height: 120px;
}
.exampleText {
writing-mode: vertical-lr;
border: 1px solid blue;
border-inline-end-width: 5px;
}
```
#### Results
{{EmbedLiveSample("Applying_a_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-width")}}, {{cssxref("border-right-width")}}, {{cssxref("border-bottom-width")}}, and {{cssxref("border-left-width")}}
- {{cssxref("writing-mode")}}, {{cssxref("direction")}}, {{cssxref("text-orientation")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_last-of-type/index.md | ---
title: ":last-of-type"
slug: Web/CSS/:last-of-type
page-type: css-pseudo-class
browser-compat: css.selectors.last-of-type
---
{{CSSRef}}
The **`:last-of-type`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents the last element of its type among a group of sibling elements.
{{EmbedInteractiveExample("pages/tabbed/pseudo-class-last-of-type.html", "tabbed-shorter")}}
## Syntax
```css
:last-of-type {
/* ... */
}
```
## Examples
### Styling the last paragraph
#### HTML
```html
<h2>Heading</h2>
<p>Paragraph 1</p>
<p>Paragraph 2</p>
```
#### CSS
```css
p:last-of-type {
color: red;
font-style: italic;
}
```
#### Result
{{EmbedLiveSample('Styling_the_last_paragraph')}}
### Nested elements
This example shows how nested elements can also be targeted. Note that the [universal selector](/en-US/docs/Web/CSS/Universal_selectors) (`*`) is implied when no simple selector is written.
#### HTML
```html
<article>
<div>This `div` is first.</div>
<div>This <span>nested `span` is last</span>!</div>
<div>
This <em>nested `em` is first</em>, but this <em>nested `em` is last</em>!
</div>
<p>This `p` qualifies!</p>
<div>This is the final `div`!</div>
</article>
```
#### CSS
```css
article :last-of-type {
background-color: pink;
}
```
#### Result
{{EmbedLiveSample('Nested_elements', 500)}}
### Multiple selectors elements
This HTML example contains nested elements of different types. The CSS contains both type selectors and class selectors.
#### HTML
```html
<p>This `p` is not selected.</p>
<p>This `p` is not selected either.</p>
<p>
This `p` is last `p` element of its parent e.g. `body` selected by `p` type
selector.
</p>
<div class="container">
<div class="item">This `div` is not selected.</div>
<div class="item">This `div` is not selected either.</div>
<div class="item">
This `div` is last `div` element of its parent `div` selected by `.container
.item` class selector.
</div>
<p class="item">
This `p` is last `p` element of its parent `div` selected by `.container
.item` class selector.
</p>
</div>
```
#### CSS
```css
p:last-of-type {
background: skyblue;
}
.container .item:last-of-type {
color: red;
font-weight: bold;
}
```
#### Result
{{EmbedLiveSample('Multiple_selectors_elements', 500)}}
The last `<div>` and the last `<p>` are both red and bold as the `.item:last-of-type` selects the last of every type if that last element also has the `item` class.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref(":last-child")}}, {{Cssxref(":nth-last-of-type")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/scrollbar-color/index.md | ---
title: scrollbar-color
slug: Web/CSS/scrollbar-color
page-type: css-property
browser-compat: css.properties.scrollbar-color
---
{{CSSRef}}
The **`scrollbar-color`** [CSS](/en-US/docs/Web/CSS) property sets the color of the scrollbar track and thumb.
The **track** refers to the background of the scrollbar, which is generally fixed regardless of the scrolling position.
The **thumb** refers to the moving part of the scrollbar, which usually floats on top of the track.
When `scrollbar-color` value is set on the document's root element, the values are applied to the viewport scrollbars.
## Syntax
```css
/* Keyword values */
scrollbar-color: auto;
/* <color> values */
scrollbar-color: rebeccapurple green; /* Two valid colors.
The first applies to the thumb of the scrollbar, the second to the track. */
/* Global values */
scrollbar-color: inherit;
scrollbar-color: initial;
scrollbar-color: revert;
scrollbar-color: revert-layer;
scrollbar-color: unset;
```
### Values
- `<scrollbar-color>`
- : Defines the color of the scrollbar.
<table class="standard-table">
<tbody>
<tr>
<td><code>auto</code></td>
<td>
Default platform rendering for the track portion of the scrollbar, in
the absence of any other related scrollbar color properties.
</td>
</tr>
<tr>
<td><code><color> <color></code></td>
<td>
Applies the first color to the scrollbar thumb, the second to the
scrollbar track.
</td>
</tr>
</tbody>
</table>
> **Note:** [`@media (forced-colors: active)`](/en-US/docs/Web/CSS/@media/forced-colors) sets {{cssxref("scrollbar-color")}} to `auto`.
## Accessibility concerns
When using `scrollbar-color` property with specific color values, authors should ensure the specified colors have enough contrast between them. For keyword values, UAs should ensure the colors they use have enough contrast. See [Techniques for WCAG 2.0: G183: Using a contrast ratio of 3:1](https://www.w3.org/TR/WCAG20-TECHS/G183.html).
## Formal definition
{{CSSInfo}}
## Formal syntax
{{CSSSyntax}}
## Examples
### Coloring overflow scrollbars
#### CSS
```css
.scroller {
width: 300px;
height: 100px;
overflow-y: scroll;
scrollbar-color: #007 #bada55;
}
```
#### HTML
```html
<div class="scroller">
Veggies es bonus vobis, proinde vos postulo essum magis kohlrabi welsh onion
daikon amaranth tatsoi tomatillo melon azuki bean garlic. Gumbo beet greens
corn soko endive gumbo gourd. Parsley shallot courgette tatsoi pea sprouts
fava bean collard greens dandelion okra wakame tomato. Dandelion cucumber
earthnut pea peanut soko zucchini.
</div>
```
#### Result
{{EmbedLiveSample("Coloring_overflow_scrollbars")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [CSS overflow](/en-US/docs/Web/CSS/CSS_overflow) module
- [CSS scrollbars styling](/en-US/docs/Web/CSS/CSS_scrollbars_styling) module
- {{CSSxRef("overflow")}}
- {{CSSxRef("scrollbar-gutter")}}
- {{CSSxRef("scrollbar-width")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/layout_mode/index.md | ---
title: Layout mode
slug: Web/CSS/Layout_mode
page-type: guide
---
{{CSSRef}}
A [CSS](/en-US/docs/Web/CSS) **layout mode**, sometimes called _layout_, is an algorithm that determines the position and size of boxes based on the way they interact with their sibling and ancestor boxes. There are several of them:
- _[Normal flow](/en-US/docs/Web/CSS/CSS_flow_layout)_ — all elements are part of normal flow until you do something to take them out of it. Normal flow includes _block layout_, designed for laying out boxes such as paragraphs and _inline layout_, which lays out inline items such as text.
- [_Table layout_](/en-US/docs/Web/CSS/CSS_table), designed for laying out tables.
- _Float layout_, designed to cause an item to position itself left or right with the rest of the content in normal flow wrapping around it.
- [_Positioned layout_](/en-US/docs/Web/CSS/CSS_positioned_layout), designed for positioning elements without much interaction with other elements.
- [_Multi-column layout_](/en-US/docs/Web/CSS/CSS_multicol_layout), designed for laying content out in columns as in a newspaper.
- [_Flexible box layout_](/en-US/docs/Web/CSS/CSS_flexible_box_layout), designed for laying out complex pages that can be resized smoothly.
- [_Grid layout_](/en-US/docs/Web/CSS/CSS_grid_layout), designed for laying out elements relative to a fixed grid.
> **Note:** Not all [CSS properties](/en-US/docs/Web/CSS/Reference) apply to all _layout modes_. Most of them apply to one or two of them and have no effect if they are set on an element participating in another layout mode.
## See also
- CSS key concepts:
- [CSS syntax](/en-US/docs/Web/CSS/Syntax)
- [At-rules](/en-US/docs/Web/CSS/At-rule)
- [Comments](/en-US/docs/Web/CSS/Comments)
- [Specificity](/en-US/docs/Web/CSS/Specificity)
- [Inheritance](/en-US/docs/Web/CSS/Inheritance)
- [Box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model)
- [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/-moz-image-region/index.md | ---
title: "-moz-image-region"
slug: Web/CSS/-moz-image-region
page-type: css-property
status:
- non-standard
browser-compat: css.properties.-moz-image-region
---
{{CSSRef}}{{Non-standard_Header}}
For certain XUL elements and pseudo-elements that use an image from the {{CSSxRef("list-style-image")}} property, this property specifies a region of the image that is used in place of the whole image. This allows elements to use different pieces of the same image to improve performance.
The syntax is similar to the {{CSSxRef("clip")}} property. All four values are relative to the upper left corner of the image.
## Syntax
```css
/* Keyword value */
-moz-image-region: auto;
/* <shape> value */
-moz-image-region: rect(0, 8px, 4px, 4px);
/* Global values */
-moz-image-region: inherit;
-moz-image-region: initial;
-moz-image-region: unset;
```
### Values
- `auto`
- : Automatically defines the region of the image to use.
- [`<shape>`](/en-US/docs/Web/CSS/shape)
- : A shape defining the part of the image to use. The `rect()` function defines a rectangle to use as shape. Its parameters define the top, right, bottom, and left offsets of the edges of the image, in this order.
## Formal definition
{{CSSInfo}}
## Formal syntax
```plain
-moz-image-region =
<shape> | auto
```
## Examples
### Clipping an image
```css
#example-button {
/* display only the 4x4 area from the top left of this image */
list-style-image: url("chrome://example/skin/example.png");
-moz-image-region: rect(0px, 4px, 4px, 0px);
}
#example-button:hover {
/* use the 4x4 area to the right of the first for the hovered button */
-moz-image-region: rect(0px, 8px, 4px, 4px);
}
```
## Specifications
Not part of any standard.
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef("-moz-image-rect")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/transition-timing-function/index.md | ---
title: transition-timing-function
slug: Web/CSS/transition-timing-function
page-type: css-property
browser-compat: css.properties.transition-timing-function
---
{{CSSRef}}
The **`transition-timing-function`** CSS property sets how intermediate values are calculated for CSS properties being affected by a [transition effect](/en-US/docs/Web/CSS/CSS_transitions/Using_CSS_transitions).
{{EmbedInteractiveExample("pages/css/transition-timing-function.html")}}
This, in essence, lets you establish an acceleration curve so that the speed of the transition can vary over its duration.
This acceleration curve is defined using one {{cssxref("<easing-function>")}} for each property to be transitioned.
You may specify multiple easing functions; each one will be applied to the corresponding property as specified by the {{ cssxref("transition-property") }} property, which acts as a `transition-property` list. If there are fewer easing functions specified than in the `transition-property` list, the user agent must calculate which value is used by repeating the list of values until there is one for each transition property. If there are more easing functions, the list is truncated to the right size. In both cases, the CSS declaration stays valid.
## Syntax
```css
/* Keyword values */
transition-timing-function: ease;
transition-timing-function: ease-in;
transition-timing-function: ease-out;
transition-timing-function: ease-in-out;
transition-timing-function: linear;
transition-timing-function: step-start;
transition-timing-function: step-end;
/* Function values */
transition-timing-function: steps(4, jump-end);
transition-timing-function: cubic-bezier(0.1, 0.7, 1, 0.1);
/* Steps Function keywords */
transition-timing-function: steps(4, jump-start);
transition-timing-function: steps(10, jump-end);
transition-timing-function: steps(20, jump-none);
transition-timing-function: steps(5, jump-both);
transition-timing-function: steps(6, start);
transition-timing-function: steps(8, end);
/* Multiple easing functions */
transition-timing-function: ease, step-start, cubic-bezier(0.1, 0.7, 1, 0.1);
/* Global values */
transition-timing-function: inherit;
transition-timing-function: initial;
transition-timing-function: revert;
transition-timing-function: revert-layer;
transition-timing-function: unset;
```
### Values
- `<easing-function>`
- : Each {{cssxref("<easing-function>")}} represents the easing function to link to the corresponding property to transition, as defined in {{ cssxref("transition-property") }}.
The non-step keyword values (ease, linear, ease-in-out, etc.) each represent cubic Bézier curve with fixed four point values, with the cubic-bezier() function value allowing for a non-predefined value. The step easing functions divides the input time into a specified number of intervals that are equal in length. It is defined by a number of steps and a step position.
- `ease`
- : Equal to `cubic-bezier(0.25, 0.1, 0.25, 1.0)`, the default value, increases in velocity towards the middle of the transition, slowing back down at the end.
- `linear`
- : Equal to `cubic-bezier(0.0, 0.0, 1.0, 1.0)`, transitions at an even speed.
- `ease-in`
- : Equal to `cubic-bezier(0.42, 0, 1.0, 1.0)`, starts off slowly, with the transition speed increasing until complete.
- `ease-out`
- : Equal to `cubic-bezier(0, 0, 0.58, 1.0)`, starts transitioning quickly, slowing down as the transition continues.
- `ease-in-out`
- : Equal to `cubic-bezier(0.42, 0, 0.58, 1.0)`, starts transitioning slowly, speeds up, and then slows down again.
- `cubic-bezier(p1, p2, p3, p4)`
- : An author-defined cubic-Bezier curve, where the p1 and p3 values must be in the range of 0 to 1.
- `steps( n, <jumpterm>)`
- : Displays the transition along _n stops along the transition, displaying each stop for_ equal lengths of time. For example, if _n_ is 5, there are 5 steps. Whether the transition holds temporarily at 0%, 20%, 40%, 60% and 80%, on the 20%, 40%, 60%, 80% and 100%, or makes 5 stops between the 0% and 100% along the transition, or makes 5 stops including the 0% and 100% marks (on the 0%, 25%, 50%, 75%, and 100%) depends on which of the following jump terms is used:
- `jump-start`
- : Denotes a left-continuous function, so that the first jump happens when the transition begins;
- `jump-end`
- : Denotes a right-continuous function, so that the last jump happens when the animation ends;
- `jump-none`
- : There is no jump on either end. Instead, holding at both the 0% mark and the 100% mark, each for 1/n of the duration
- `jump-both`
- : Includes pauses at both the 0% and 100% marks, effectively adding a step during the transition time.
- `start`
- : Same as `jump-start.`
- `end`
- : Same as `jump-end.`
- `step-start`
- : Equal to `steps(1, jump-start)`
- `step-end`
- : Equal to `steps(1, jump-end)`
## Accessibility concerns
Some animations can be helpful such as to guide users to understand what actions are expected, to show relationships within the user interface, and to inform users as to what actions have occurred. Animations can help reduce cognitive load, prevent change blindness, and establish better recall in spatial relationships. However, some animations can be problematic for people with cognitive concerns such as Attention Deficit Hyperactivity Disorder (ADHD) and certain kinds of motion can be a trigger for Vestibular disorders, epilepsy, and migraine and Scotopic sensitivity.
Consider providing a mechanism for pausing or disabling animation, as well as using the [Reduced Motion Media Query](/en-US/docs/Web/CSS/@media/prefers-reduced-motion) (or equivalent [User Agent client hint](/en-US/docs/Web/HTTP/Client_hints#user-agent_client_hints) {{HTTPHeader("Sec-CH-Prefers-Reduced-Motion")}}) to create a complimentary experience for users who have expressed a preference for less animation.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Cubic-Bezier examples
```html hidden
<div class="parent">
<div class="ease">ease</div>
<div class="easein">ease-in</div>
<div class="easeout">ease-out</div>
<div class="easeinout">ease-in-out</div>
<div class="linear">linear</div>
<div class="cb">cubic-bezier(0.2,-2,0.8,2)</div>
</div>
```
```css hidden
.parent {
}
.parent > div[class] {
width: 12em;
min-width: 12em;
margin-bottom: 4px;
background-color: black;
border: 1px solid red;
color: white;
transition-property: all;
transition-duration: 7s;
}
.parent > div.box1 {
width: 90vw;
min-width: 24em;
background-color: magenta;
color: yellow;
border: 1px solid orange;
transition-property: all;
transition-duration: 2s;
}
```
```js hidden
function updateTransition() {
const els = document.querySelectorAll(".parent > div[class]");
for (let i = 0; i < els.length; i++) {
els[i].classList.toggle("box1");
}
}
const intervalID = setInterval(updateTransition, 10000);
```
```css
.ease {
transition-timing-function: ease;
}
.easein {
transition-timing-function: ease-in;
}
.easeout {
transition-timing-function: ease-out;
}
.easeinout {
transition-timing-function: ease-in-out;
}
.linear {
transition-timing-function: linear;
}
.cb {
transition-timing-function: cubic-bezier(0.2, -2, 0.8, 2);
}
```
{{EmbedLiveSample("Cubic-Bezier_examples")}}
### Step examples
```html hidden
<div class="parent">
<div class="jump-start">jump-start</div>
<div class="jump-end">jump-end</div>
<div class="jump-both">jump-both</div>
<div class="jump-none">jump-none</div>
<div class="step-start">step-start</div>
<div class="step-end">step-end</div>
</div>
```
```css hidden
.parent {
}
.parent > div[class] {
width: 12em;
min-width: 12em;
margin-bottom: 4px;
background-color: black;
border: 1px solid red;
color: white;
transition-property: all;
transition-duration: 7s;
}
.parent > div.box1 {
width: 90vw;
min-width: 24em;
background-color: magenta;
color: yellow;
border: 1px solid orange;
transition-property: all;
transition-duration: 2s;
}
```
```js hidden
function updateTransition() {
const els = document.querySelectorAll(".parent > div[class]");
for (let i = 0; i < els.length; i++) {
els[i].classList.toggle("box1");
}
}
const intervalID = setInterval(updateTransition, 10000);
```
```css
.jump-start {
transition-timing-function: steps(5, jump-start);
}
.jump-end {
transition-timing-function: steps(5, jump-end);
}
.jump-none {
transition-timing-function: steps(5, jump-none);
}
.jump-both {
transition-timing-function: steps(5, jump-both);
}
.step-start {
transition-timing-function: step-start;
}
.step-end {
transition-timing-function: step-end;
}
```
{{EmbedLiveSample("Step_examples")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Using CSS transitions](/en-US/docs/Web/CSS/CSS_transitions/Using_CSS_transitions)
- [`<easing-function>`](/en-US/docs/Web/CSS/easing-function)
- {{cssxref('transition')}}
- {{cssxref('transition-property')}}
- {{cssxref('transition-duration')}}
- {{cssxref('transition-delay')}}
- {{domxref("TransitionEvent")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/border-inline-start-width/index.md | ---
title: border-inline-start-width
slug: Web/CSS/border-inline-start-width
page-type: css-property
browser-compat: css.properties.border-inline-start-width
---
{{CSSRef}}
The **`border-inline-start-width`** [CSS](/en-US/docs/Web/CSS) property defines the width of the logical inline-start border of an element, which maps to a physical border width depending on the element's writing mode, directionality, and text orientation. It corresponds to the {{cssxref("border-top-width")}}, {{cssxref("border-right-width")}}, {{cssxref("border-bottom-width")}}, or {{cssxref("border-left-width")}} property depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}.
{{EmbedInteractiveExample("pages/css/border-inline-start-width.html")}}
## Syntax
```css
/* <'border-width'> values */
border-inline-start-width: 5px;
border-inline-start-width: thick;
/* Global values */
border-inline-start-width: inherit;
border-inline-start-width: initial;
border-inline-start-width: revert;
border-inline-start-width: revert-layer;
border-inline-start-width: unset;
```
Related properties are {{cssxref("border-block-start-width")}}, {{cssxref("border-block-end-width")}}, and {{cssxref("border-inline-end-width")}}, which define the other border widths of the element.
### Values
- `<'border-width'>`
- : The width of the border. See {{ cssxref("border-width") }}.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### HTML
```html
<div>
<p class="exampleText">Example text</p>
</div>
```
### CSS
```css
div {
background-color: yellow;
width: 120px;
height: 120px;
}
.exampleText {
writing-mode: vertical-lr;
border: 1px solid blue;
border-inline-start-width: 5px;
}
```
{{EmbedLiveSample("Examples", 140, 140)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [CSS Logical Properties and Values](/en-US/docs/Web/CSS/CSS_logical_properties_and_values)
- This property maps to one of the physical border properties: {{cssxref("border-top-width")}}, {{cssxref("border-right-width")}}, {{cssxref("border-bottom-width")}}, and {{cssxref("border-left-width")}}
- {{cssxref("writing-mode")}}, {{cssxref("direction")}}, {{cssxref("text-orientation")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_target/index.md | ---
title: ":target"
slug: Web/CSS/:target
page-type: css-pseudo-class
browser-compat: css.selectors.target
---
{{CSSRef}}
The **`:target`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents a unique element (the _target element_) with an [`id`](/en-US/docs/Web/HTML/Global_attributes#id) matching the URL's fragment.
```css
/* Selects an element with an ID matching the current URL's fragment */
:target {
border: 2px solid black;
}
```
For example, the following URL has a fragment (denoted by the _#_ sign) that points to an element called `section2`:
```url
http://www.example.com/index.html#section2
```
The following element would be selected by a `:target` selector when the current URL is equal to the above:
```html
<section id="section2">Example</section>
```
## Syntax
```css
:target {
/* ... */
}
```
> **Note:** Due to [a possible bug in the CSS specification](https://discourse.wicg.io/t/target-css-does-not-work-because-shadowroot-does-not-set-a-target-element/2070), `:target` doesn't work within a [web component](/en-US/docs/Web/API/Web_components) because the [shadow root](/en-US/docs/Web/API/ShadowRoot) doesn't pass the target element down to the shadow tree.
## Examples
### A table of contents
The `:target` pseudo-class can be used to highlight the portion of a page that has been linked to from a table of contents.
#### HTML
```html
<h3>Table of Contents</h3>
<ol>
<li><a href="#p1">Jump to the first paragraph!</a></li>
<li><a href="#p2">Jump to the second paragraph!</a></li>
<li>
<a href="#nowhere">
This link goes nowhere, because the target doesn't exist.
</a>
</li>
</ol>
<h3>My Fun Article</h3>
<p id="p1">
You can target <i>this paragraph</i> using a URL fragment. Click on the link
above to try out!
</p>
<p id="p2">
This is <i>another paragraph</i>, also accessible from the links above. Isn't
that delightful?
</p>
```
#### CSS
```css
p:target {
background-color: gold;
}
/* Add a pseudo-element inside the target element */
p:target::before {
font: 70% sans-serif;
content: "►";
color: limegreen;
margin-right: 0.25em;
}
/* Style italic elements within the target element */
p:target i {
color: red;
}
```
#### Result
{{EmbedLiveSample('A_table_of_contents', 500, 300)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Using the :target pseudo-class in selectors](/en-US/docs/Web/CSS/CSS_selectors/Using_the_:target_pseudo-class_in_selectors)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/display/index.md | ---
title: display
slug: Web/CSS/display
page-type: css-property
browser-compat: css.properties.display
---
{{CSSRef}}
The **`display`** [CSS](/en-US/docs/Web/CSS) property sets whether an element is treated as a [block or inline box](/en-US/docs/Web/CSS/CSS_flow_layout) and the layout used for its children, such as [flow layout](/en-US/docs/Web/CSS/CSS_flow_layout), [grid](/en-US/docs/Web/CSS/CSS_grid_layout) or [flex](/en-US/docs/Web/CSS/CSS_flexible_box_layout).
Formally, the **`display`** property sets an element's inner and outer _display types_. The outer type sets an element's participation in [flow layout](/en-US/docs/Web/CSS/CSS_flow_layout); the inner type sets the layout of children. Some values of `display` are fully defined in their own individual specifications; for example the detail of what happens when `display: flex` is declared is defined in the CSS Flexible Box Model specification.
{{EmbedInteractiveExample("pages/css/display.html")}}
## Syntax
```css
/* precomposed values */
display: block;
display: inline;
display: inline-block;
display: flex;
display: inline-flex;
display: grid;
display: inline-grid;
display: flow-root;
/* box generation */
display: none;
display: contents;
/* multi-keyword syntax */
display: block flex;
display: block flow;
display: block flow-root;
display: block grid;
display: inline flex;
display: inline flow;
display: inline flow-root;
display: inline grid;
/* other values */
display: table;
display: table-row; /* all table elements have an equivalent CSS display value */
display: list-item;
/* Global values */
display: inherit;
display: initial;
display: revert;
display: revert-layer;
display: unset;
```
The CSS `display` property is specified using keyword values.
## Grouped values
The keyword values can be grouped into six value categories.
### Outside
- {{CSSxRef("<display-outside>")}}
- : These keywords specify the element's outer display type, which is essentially its role in flow layout:
- `block`
- : The element generates a block box, generating line breaks both before and after the element when in the normal flow.
- `inline`
- : The element generates one or more inline boxes that do not generate line breaks before or after themselves. In normal flow, the next element will be on the same line if there is space.
> **Note:** When browsers that support multi-keyword syntax encounter a display property that only has an **outer** value (e.g., `display: block` or `display: inline`), the inner value is set to `flow` (e.g., `display: block flow` and `display: inline flow`).
> **Note:** To be sure layouts work on older browsers, you may use single-value syntax, for example `display: inline flex` could have the following fallback
>
> ```css
> .container {
> display: inline-flex;
> display: inline flex;
> }
> ```
>
> See [Using the multi-keyword syntax with CSS display](/en-US/docs/Web/CSS/display/multi-keyword_syntax_of_display) for more information.
### Inside
- {{CSSxRef("<display-inside>")}}
- : These keywords specify the element's inner display type, which defines the type of formatting context that its contents are laid out in (assuming it is a non-replaced element):
- `flow` {{Experimental_Inline}}
- : The element lays out its contents using flow layout (block-and-inline layout).
If its outer display type is `inline` or `run-in`, and it is participating in a block or inline formatting context, then it generates an inline box. Otherwise it generates a block container box.
Depending on the value of other properties (such as {{CSSxRef("position")}}, {{CSSxRef("float")}}, or {{CSSxRef("overflow")}}) and whether it is itself participating in a block or inline formatting context, it either establishes a new [block formatting context](/en-US/docs/Web/CSS/CSS_display/Block_formatting_context) (BFC) for its contents or integrates its contents into its parent formatting context.
- `flow-root`
- : The element generates a block box that establishes a new [block formatting context](/en-US/docs/Web/CSS/CSS_display/Block_formatting_context), defining where the formatting root lies.
- `table`
- : These elements behave like HTML {{HTMLElement("table")}} elements. It defines a block-level box.
- `flex`
- : The element behaves like a block-level element and lays out its content according to the [flexbox model](/en-US/docs/Web/CSS/CSS_flexible_box_layout).
- `grid`
- : The element behaves like a block-level element and lays out its content according to the [grid model](/en-US/docs/Web/CSS/CSS_grid_layout/Basic_concepts_of_grid_layout).
- `ruby` {{Experimental_Inline}}
- : The element behaves like an inline-level element and lays out its content according to the ruby formatting model. It behaves like the corresponding HTML {{HTMLElement("ruby")}} elements.
> **Note:** When browsers that support multi-keyword syntax encounter a display property that only has an **inner** value (e.g., `display: flex` or `display: grid`), the outer value is set to `block` (e.g., `display: block flex` and `display: block grid`).
### List Item
- {{CSSxRef("<display-listitem>")}}
- : The element generates a block box for the content and a separate list-item inline box.
A single value of `list-item` will cause the element to behave like a list item.
This can be used together with {{CSSxRef("list-style-type")}} and {{CSSxRef("list-style-position")}}.
`list-item` can also be combined with any {{CSSxRef("<display-outside>")}} keyword and the `flow` or `flow-root` {{CSSxRef("<display-inside>")}} keywords.
> **Note:** In browsers that support the multi-keyword syntax, if no inner value is specified, it will default to `flow`.
> If no outer value is specified, the principal box will have an outer display type of `block`.
### Internal
- {{CSSxRef("<display-internal>")}}
- : Some layout models such as `table` and `ruby` have a complex internal structure, with several different roles that their children and descendants can fill.
This section defines those "internal" display values, which only have meaning within that particular layout mode.
- `table-row-group`
- : These elements behave like {{HTMLElement("tbody")}} HTML elements.
- `table-header-group`
- : These elements behave like {{HTMLElement("thead")}} HTML elements.
- `table-footer-group`
- : These elements behave like {{HTMLElement("tfoot")}} HTML elements.
- `table-row`
- : These elements behave like {{HTMLElement("tr")}} HTML elements.
- `table-cell`
- : These elements behave like {{HTMLElement("td")}} HTML elements.
- `table-column-group`
- : These elements behave like {{HTMLElement("colgroup")}} HTML elements.
- `table-column`
- : These elements behave like {{HTMLElement("col")}} HTML elements.
- `table-caption`
- : These elements behave like {{HTMLElement("caption")}} HTML elements.
- `ruby-base` {{Experimental_Inline}}
- : These elements behave like {{HTMLElement("rb")}} HTML elements.
- `ruby-text` {{Experimental_Inline}}
- : These elements behave like {{HTMLElement("rt")}} HTML elements.
- `ruby-base-container` {{Experimental_Inline}}
- : These elements are generated as anonymous boxes.
- `ruby-text-container` {{Experimental_Inline}}
- : These elements behave like {{HTMLElement("rtc")}} HTML elements.
### Box
- {{CSSxRef("<display-box>")}}
- : These values define whether an element generates display boxes at all.
- `contents`
- : These elements don't produce a specific box by themselves. They are replaced by their pseudo-box and their child boxes. Please note that the CSS Display Level 3 spec defines how the `contents` value should affect "unusual elements" — elements that aren't rendered purely by CSS box concepts such as replaced elements. See [Appendix B: Effects of display: contents on Unusual Elements](https://drafts.csswg.org/css-display/#unbox) for more details.
- `none`
- : Turns off the display of an element so that it has no effect on layout (the document is rendered as though the element did not exist). All descendant elements also have their display turned off.
To have an element take up the space that it would normally take, but without actually rendering anything, use the {{CSSxRef("visibility")}} property instead.
### Precomposed
- {{CSSxRef("<display-legacy>")}}
- : CSS 2 used a single-keyword, precomposed syntax for the `display` property, requiring separate keywords for block-level and inline-level variants of the same layout mode.
- `inline-block`
- : The element generates a block box that will be flowed with surrounding content as if it were a single inline box (behaving much like a replaced element would).
It is equivalent to `inline flow-root`.
- `inline-table`
- : The `inline-table` value does not have a direct mapping in HTML. It behaves like an HTML {{HTMLElement("table")}} element, but as an inline box, rather than a block-level box. Inside the table box is a block-level context.
It is equivalent to `inline table`.
- `inline-flex`
- : The element behaves like an inline-level element and lays out its content according to the flexbox model.
It is equivalent to `inline flex`.
- `inline-grid`
- : The element behaves like an inline-level element and lays out its content according to the grid model.
It is equivalent to `inline grid`.
### Which syntax should you use?
The [CSS display module](/en-US/docs/Web/CSS/CSS_display) describes a multi-keyword syntax for values you can use with the `display` property to explicitly define **outer** and **inner** display.
The single keyword values (precomposed `<display-legacy>` values) are supported for backward-compatibility.
For example, using two values you can specify an inline flex container as follows:
```css
.container {
display: inline flex;
}
```
This can also be specified using the legacy single value:
```css
.container {
display: inline-flex;
}
```
For more information on these changes, see the [Using the multi-keyword syntax with CSS display](/en-US/docs/Web/CSS/display/multi-keyword_syntax_of_display) guide.
### Global
```css
/* Global values */
display: inherit;
display: initial;
display: unset;
```
## Description
The individual pages for the different types of value that `display` can have set on it feature multiple examples of those values in action — see the [Syntax](#syntax) section. In addition, see the following material, which covers the various values of display in depth.
### Multi-keyword values
- [Using the multi-keyword syntax with CSS display](/en-US/docs/Web/CSS/display/multi-keyword_syntax_of_display)
### CSS Flow Layout (display: block, display: inline)
- [Block and Inline Layout in Normal Flow](/en-US/docs/Web/CSS/CSS_flow_layout/Block_and_inline_layout_in_normal_flow)
- [Flow Layout and Overflow](/en-US/docs/Web/CSS/CSS_flow_layout/Flow_layout_and_overflow)
- [Flow Layout and Writing Modes](/en-US/docs/Web/CSS/CSS_flow_layout/Flow_layout_and_writing_modes)
- [Formatting Contexts Explained](/en-US/docs/Web/CSS/CSS_flow_layout/Introduction_to_formatting_contexts)
- [In Flow and Out of Flow](/en-US/docs/Web/CSS/CSS_flow_layout/In_flow_and_out_of_flow)
### display: flex
- [Basic concepts of flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox)
- [Aligning Items in a Flex Container](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Aligning_items_in_a_flex_container)
- [Controlling Ratios of Flex Items Along the Main Axis](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Controlling_ratios_of_flex_items_along_the_main_axis)
- [Mastering Wrapping of Flex Items](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Mastering_wrapping_of_flex_items)
- [Ordering Flex Items](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Ordering_flex_items)
- [Relationship of flexbox to other layout methods](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Relationship_of_flexbox_to_other_layout_methods)
- [Typical use cases of Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Typical_use_cases_of_flexbox)
### display: grid
- [Basic Concepts of Grid Layout](/en-US/docs/Web/CSS/CSS_grid_layout/Basic_concepts_of_grid_layout)
- [Relationship to other layout methods](/en-US/docs/Web/CSS/CSS_grid_layout/Relationship_of_grid_layout_with_other_layout_methods)
- [Line-based placement](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_layout_using_line-based_placement)
- [Grid template areas](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_template_areas)
- [Layout using named grid lines](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_layout_using_named_grid_lines)
- [Auto-placement in grid layout](/en-US/docs/Web/CSS/CSS_grid_layout/Auto-placement_in_grid_layout)
- [Box alignment in grid layout](/en-US/docs/Web/CSS/CSS_grid_layout/Box_alignment_in_grid_layout)
- [Grids, logical values and writing modes](/en-US/docs/Web/CSS/CSS_grid_layout/Grids_logical_values_and_writing_modes)
- [CSS Grid Layout and Accessibility](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_layout_and_accessibility)
- [CSS Grid Layout and Progressive Enhancement](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_layout_and_progressive_enhancement)
- [Realizing common layouts using grids](/en-US/docs/Web/CSS/CSS_grid_layout/Realizing_common_layouts_using_grids)
### Animating display
[Supporting browsers](#browser_compatibility) animate `display` with a [discrete animation type](/en-US/docs/Web/CSS/CSS_animated_properties#discrete). This generally means that the property will flip between two values 50% through animating between the two.
There is one exception, which is when animating to or from `display: none`. In this case, the browser will flip between the two values so that the animated content is shown for the entire animation duration. So for example:
- When animating `display` from `none` to `block` (or another visible `display` value), the value will flip to `block` at `0%` of the animation duration so it is visible throughout.
- When animating `display` from `block` (or another visible `display` value) to `none`, the value will flip to `none` at `100%` of the animation duration so it is visible throughout.
This behavior is useful for creating entry/exit animations where you want to for example remove a container from the DOM with `display: none`, but have it fade out with [`opacity`](/en-US/docs/Web/CSS/opacity) rather than disappearing immediately.
When animating `display` with [CSS animations](/en-US/docs/Web/CSS/CSS_animations), you need to provide the starting `display` value in an explicit keyframe (for example using `0%` or `from`). See [Using CSS animations](/en-US/docs/Web/CSS/CSS_animations/Using_CSS_animations) for an example.
When animating `display` with [CSS transitions](/en-US/docs/Web/CSS/CSS_transitions), two additional features are needed:
- [`@starting-style`](/en-US/docs/Web/CSS/@starting-style) provides starting values for properties you want to transition from when the animated element is first shown. This is needed to avoid unexpected behavior. By default, CSS transitions are not triggered on an element's first style update or when the `display` type changes from `none` to another type.
- [`transition-behavior: allow-discrete`](/en-US/docs/Web/CSS/transition-behavior) needs to be set on the {{cssxref("transition-property")}} declaration (or the {{cssxref("transition")}} shorthand) to enable `display` transitions.
For examples of transitioning the `display` property, see the [`@starting-style`](/en-US/docs/Web/CSS/@starting-style#examples) and [`transition-behavior`](/en-US/docs/Web/CSS/transition-behavior#examples) pages.
## Accessibility concerns
### display: none
Using a `display` value of `none` on an element will remove it from the [accessibility tree](/en-US/docs/Learn/Accessibility/What_is_accessibility#accessibility_apis). This will cause the element and all its descendant elements to no longer be announced by screen reading technology.
If you want to visually hide the element, a more accessible alternative is to use [a combination of properties](https://gomakethings.com/hidden-content-for-better-a11y/#hiding-the-link) to remove it visually from the screen but keep it parsable by assistive technology such as screen readers.
### display: contents
Current implementations in some browsers will remove from the [accessibility tree](/en-US/docs/Learn/Accessibility/What_is_accessibility#accessibility_apis) any element with a `display` value of `contents` (but descendants will remain). This will cause the element itself to no longer be announced by screen reading technology. This is incorrect behavior according to the [CSS specification](https://drafts.csswg.org/css-display/#valdef-display-contents).
- [More accessible markup with display: contents | Hidde de Vries](https://hidde.blog/more-accessible-markup-with-display-contents/)
- [Display: Contents Is Not a CSS Reset | Adrian Roselli](https://adrianroselli.com/2018/05/display-contents-is-not-a-css-reset.html)
### Tables
In some browsers, changing the `display` value of a {{HTMLElement("table")}} element to `block`, `grid`, or `flex` will alter its representation in the [accessibility tree](/en-US/docs/Learn/Accessibility/What_is_accessibility#accessibility_apis). This will cause the table to no longer be announced properly by screen reading technology.
- [Short note on what CSS display properties do to table semantics — The Paciello Group](https://www.tpgi.com/short-note-on-what-css-display-properties-do-to-table-semantics/)
- [Hidden content for better a11y | Go Make Things](https://gomakethings.com/hidden-content-for-better-a11y/)
- [MDN Understanding WCAG, Guideline 1.3 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.3_%e2%80%94_create_content_that_can_be_presented_in_different_ways)
- [Understanding Success Criterion 1.3.1 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/content-structure-separation-programmatic.html)
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### display value comparison
In this example we have two block-level container elements, each one with three inline children. Below that, we have a select menu that allows you to apply different `display` values to the containers, allowing you to compare and contrast how the different values affect the element's layout, and that of their children.
We've included {{cssxref("padding")}} and {{cssxref("background-color")}} on the containers and their children, so that it is easier to see the effect the display values are having.
#### HTML
```html
<article class="container">
<span>First</span>
<span>Second</span>
<span>Third</span>
</article>
<article class="container">
<span>First</span>
<span>Second</span>
<span>Third</span>
</article>
<div>
<label for="display">Choose a display value:</label>
<select id="display">
<option selected>block</option>
<option>inline</option>
<option>inline-block</option>
<option>inline flow-root</option>
<option>none</option>
<option>flex</option>
<option>inline-flex</option>
<option>inline flex</option>
<option>grid</option>
<option>inline-grid</option>
<option>inline grid</option>
<option>table</option>
<option>block table</option>
<option>list-item</option>
</select>
</div>
```
#### CSS
```css
html {
font-family: helvetica, arial, sans-serif;
letter-spacing: 1px;
padding-top: 10px;
}
article {
background-color: red;
}
article span {
background-color: black;
color: white;
margin: 1px;
}
article,
span {
padding: 10px;
border-radius: 7px;
}
article,
div {
margin: 20px;
}
```
#### JavaScript
```js
const articles = document.querySelectorAll(".container");
const select = document.querySelector("select");
function updateDisplay() {
articles.forEach((article) => {
article.style.display = select.value;
});
}
select.addEventListener("change", updateDisplay);
updateDisplay();
```
#### Result
{{EmbedLiveSample('display_value_comparison','100%', 440)}}
Note that some multi-keyword values are added for illustration which have the following equivalents:
- `inline-block` = `inline flow-root`
- `inline-flex` = `inline flex`
- `inline-grid` = `inline grid`
- `table` = `block table`
You can find more examples in the pages for each separate display data type under [Grouped values](#grouped_values)
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Block and inline layout in normal flow](/en-US/docs/Web/CSS/CSS_flow_layout/Block_and_inline_layout_in_normal_flow)
- [Introduction to formatting contexts](/en-US/docs/Web/CSS/CSS_flow_layout/Introduction_to_formatting_contexts)
- {{CSSxRef("visibility")}}, {{CSSxRef("float")}}, {{CSSxRef("position")}}
- {{CSSxRef("grid")}}, {{CSSxRef("flex")}}
| 0 |
data/mdn-content/files/en-us/web/css/display | data/mdn-content/files/en-us/web/css/display/multi-keyword_syntax_of_display/index.md | ---
title: Using the multi-keyword syntax with CSS display
slug: Web/CSS/display/multi-keyword_syntax_of_display
page-type: guide
---
{{CSSRef}}
The [CSS display module](/en-US/docs/Web/CSS/CSS_display) defines a multi-keyword syntax for the CSS [`display`](/en-US/docs/Web/CSS/display) property. This guide explains the multi-keyword syntax.
> **Note:** multi-keyword syntax is also referred to as "two-value syntax" or "multi-value syntax."
## What happens when we change the value of the display property?
One of the first things we learn about CSS is that some elements are block-level and some are inline-level. These are their [outer](/en-US/docs/Web/CSS/display-outside) display types. For example, an `<h1>` or a `<p>` are block-level by default, and a `<span>` is inline-level. Using the {{cssxref("display")}} property we can switch between block and inline. For example to make a heading inline we would use the following CSS:
```css
h1 {
display: inline;
}
```
The `display` property also lets us use [CSS Grid Layout](/en-US/docs/Web/CSS/CSS_grid_layout) and [Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout) when `display: grid` or `display: flex` is set. The important concept to understand is that changing an element's `display` value can change the formatting context of its direct children. When you use `display: flex` or `display: grid`, the element's children become flex or grid items and respond to the properties in grid and flexbox specifications.
What grid and flexbox demonstrate, however, is that an element has both an **outer** and an **inner** display type. The outer display type describes whether the element is block-level or inline-level. The inner display type describes how the children of that box behave.
As an example, when we use `display: flex` we create a block-level container, with flex children. The children are described as participating in a flex formatting context. You can see this if you take a `<span>` — normally an inline-level element — and apply `display: flex` to it. The `<span>` becomes a block-level element. It behaves as block-level things do in relationship to other boxes in the layout. It's as if you had applied `display: block` to the span, however we also get the changed behavior of the children.
The live example below has a `<span>` with `display: flex` applied. It has become a block-level box taking up all available space in the inline direction. You can now use `justify-content: space-between` to put this space between the two flex items.
{{EmbedGHLiveSample("css-examples/display/multi-keyword/span-flex.html", '100%', 440)}}
It's also possible to create inline flex containers. If you use the single value `inline-flex` you will have an inline-level box with flex children. The children behave in the same way as the flex children of a block-level container. The only thing that has changed is that the parent is now an inline-level box. It therefore behaves like other inline-level things, and doesn't take up the full width (or size in the inline dimension) that a block-level box does. This means that some following text could come up alongside the flex container.
{{EmbedGHLiveSample("css-examples/display/multi-keyword/inline-flex.html", '100%', 440)}}
The same is true when working with grid layout. Using `display: grid` will give you a block-level box, which creates a grid formatting context for the direct children. Using `display: inline-grid` will create an inline-level box, which creates a grid formatting context for the children.
## Using the multi-keyword syntax
As you can see from the above explanation, the `display` property has considerable powers. In addition to indicating whether something is block-level or inline-level in relationship to other boxes on the page, it also indicates the formatting context inside the box it is applied to. To better describe this behavior, the `display` property allows for two values — an outer and inner value — to be set on it. The original single-value syntax is also valid.
This means that instead of setting `display: flex` to create a block-level box with flex children, we use `display: block flex`. Instead of `display: inline-flex` to create an inline-level box with flex children, we use `display: inline flex`. The example below demonstrates these values.
{{EmbedGHLiveSample("css-examples/display/multi-keyword/multi-keyword-flex.html", '100%', 640)}}
There are mappings for all of the existing values of `display`; the most common ones are listed in the table below. To see a full list take a look at the table found in the [`display` property specification](https://drafts.csswg.org/css-display/#display-value-summary).
| Single value | Multi value |
| -------------- | ------------------ |
| `block` | `block flow` |
| `flow-root` | `block flow-root` |
| `inline` | `inline flow` |
| `inline-block` | `inline flow-root` |
| `flex` | `block flex` |
| `inline-flex` | `inline flex` |
| `grid` | `block grid` |
| `inline-grid` | `inline grid` |
## display: block flow-root and display: inline flow-root
Regarding how this multi-value syntax helps clarify CSS layout, we can look at some values in the table above that might be less familiar to you. The multi-keyword `display: block flow-root` maps to a single value; `display: flow-root`. This value's only purpose is to create a new [Block Formatting Context](/en-US/docs/Web/CSS/CSS_display/Block_formatting_context) (BFC). A BFC ensures that everything inside your box stays inside, and things outside the box cannot intrude into it.
In the example below, two `<p>` elements, one inside a `<div>` demonstrate how display values affect formatting contexts.
The first `<div>` element with the demo controls is hidden so we can focus on the elements that follow instead.
The elements that we should focus on are the "parent", "child", and "sibling" `<div>` and `<p>` elements which you can differentiate by their IDs.
What's notable about this layout is that there is no content between the parent and child elements, and the child element has a top margin applied.
You might expect the top margin to effectively push the child element down within the parent element, but what happens instead is something called [_margin collapse_](/en-US/docs/Web/CSS/CSS_box_model/Mastering_margin_collapsing).
In this case, the margin of the child element extends well above the parent's bounding box and pushes the parent element further down the page.
This is easier to see if you inspect the box model of the child element [in your browser's developer tools](/en-US/docs/Learn/CSS/Building_blocks/The_box_model#use_browser_devtools_to_view_the_box_model).
Change the selected option in the `<select>` element to see the effect of different `display` values.
You can use any value with `flow-root` to create a new formatting context for the parent, making the child element margin relative to its parent's outer edge and avoiding the margin collapse.
Changing between `display: flow-root` and `display: block flow-root` will achieve the same effect as the single-value `flow-root` keyword.
```js hidden
function changeDisplayType() {
var parentDiv = document.getElementById("parent");
var siblingDiv = document.getElementById("sibling");
var displayType = document.getElementById("displayType").value;
parentDiv.style.display = displayType;
siblingDiv.style.display = displayType;
}
```
```css hidden
#controls {
padding: 1rem;
outline: 2px dashed black;
}
body {
margin: 10px;
font-family: sans-serif;
}
```
```css
div,
p {
outline: 2px solid black;
background-color: cornflowerblue;
display: block;
margin-bottom: 2rem;
}
#parent {
background-color: oldlace;
min-height: 2rem;
}
#child {
margin-top: 4rem;
outline: 2px dashed red;
}
#sibling {
background-color: lavender;
}
```
```html hidden
<div id="controls">
<label for="displayType">display:</label>
<select id="displayType" onchange="changeDisplayType()">
<option value="block">block</option>
<option value="flow-root">flow-root</option>
<option value="block flow-root">block flow-root</option>
<option value="inline">inline</option>
<option value="inline flow-root">inline flow-root</option>
</select>
</div>
```
```html
<div id="parent">
<p id="child">The #child paragraph (nested in #parent).</p>
</div>
<p id="sibling">The #sibling paragraph (sibling of #parent).</p>
```
{{EmbedLiveSample("display_block_flow-root_and_display_inline_flow-root", '90%', 380)}}
The `flow-root` value makes sense if you think about block and inline layout, which is sometimes called [normal flow](/en-US/docs/Learn/CSS/CSS_layout/Normal_Flow). Our HTML page creates a new formatting context (floats and margins cannot extend out from the boundaries) and our content lays out in normal flow, using block and inline layout, unless we change the value of `display` to use some other formatting context. Creating a grid or flex container also creates a new formatting context (a grid or flex formatting context, respectively.) These also contain everything inside them. However, if you want to contain floats and margins but continue using block and inline layout, you can create a new flow root, and start over with block and inline layout. From that point downwards everything is contained inside the new flow root.
This is why `display: flow-root` can be written using the multi-keyword syntax `display: block flow-root`. You are creating a block formatting context, with a block-level box and children participating in normal flow. What about the matched pair `display: inline flow-root`? This is the current way of describing `display: inline-block`.
The value `display: inline-block` has been around since the early days of CSS. The reason we tend to use it is to allow padding to push inline items away from an element, when creating navigation items for example, or when wanting to add a background with padding to an inline element as in the example below.
{{EmbedGHLiveSample("css-examples/display/multi-keyword/inline-block.html", '100%', 440)}}
An element with `display: inline-block` however, will also contain floats. It contains everything inside the inline-level box. Therefore `display: inline-block` does exactly what `display: flow-root` does, but with an inline-level, rather than a block-level box. The two-value syntax accurately describes what is happening with this value. In the example above, you can change `display: inline-block` to `display: inline flow-root` and get the same result.
## What about the old values of display?
The single values of `display` are described in the specification as legacy values, and currently you gain no benefit from using the multi-keyword versions, as there is a direct mapping for each multi-keyword version to a legacy version, as demonstrated in the table above.
To deal with single values of `display` [the specification](https://www.w3.org/TR/css-display-3/#outer-role) explains what to do if only the outer value of `block` or `inline` is used:
> "If a `<display-outside>` value is specified but `<display-inside>` is omitted, the element's inner display type defaults to flow."
This means that the behavior is exactly as it is in a single value world. If you specify `display: block` or `display: inline`, that changes the outer display value of the box but any children continue in normal flow.
If only an inner value of `flex`, `grid`, or `flow-root` is specified then [the specification](https://www.w3.org/TR/css-display-3/#inner-model) explains that the outer value should be set to `block`:
> "If a `<display-inside>` value is specified but `<display-outside>` is omitted, the element's outer display type defaults to block—except for ruby, which defaults to inline."
Finally, we have some legacy [pre-composed inline-level values](https://www.w3.org/TR/css-display-3/#legacy-display) of:
- `inline-block`
- `inline-table`
- `inline-flex`
- `inline-grid`
If a supporting browser comes across these as single values then it treats them the same as the multi-keyword versions:
- `inline flow-root`
- `inline table`
- `inline flex`
- `inline grid`
So all of the current situations are neatly covered, meaning that we maintain compatibility of existing and new sites that use the single values, while allowing the spec to evolve.
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_blank/index.md | ---
title: ":blank"
slug: Web/CSS/:blank
page-type: css-pseudo-class
status:
- experimental
browser-compat: css.selectors.blank
---
{{CSSRef}}{{SeeCompatTable}}
> **Note:** The `:blank` selector is considered at risk, as the CSSWG keeps changing it.
>
> See [CSSWG issue #1967](https://github.com/w3c/csswg-drafts/issues/1967).
The **`:blank`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) selects empty user input elements (e.g. {{HTMLElement("input")}} or {{HTMLElement("textarea")}}).
## Syntax
```css
:blank {
/* ... */
}
```
## Examples
### Simple :blank example
In eventual supporting browsers, the `:blank` pseudo-class will enable developers to highlight in some way input controls that are not required, but still have no content filled in, perhaps as a reminder to users.
#### HTML
```html
<textarea></textarea>
```
#### CSS
```css
textarea:blank {
border: 3px solid red;
}
```
#### Result
{{EmbedLiveSample('Simple_blank_example', '100%', 150)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef(":empty")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/subsequent-sibling_combinator/index.md | ---
title: Subsequent-sibling combinator
slug: Web/CSS/Subsequent-sibling_combinator
page-type: css-combinator
browser-compat: css.selectors.subsequent-sibling
---
{{CSSRef}}
The **subsequent-sibling combinator** (`~`, a tilde) separates two selectors and matches _all instances_ of the second element that follow the first element (not necessarily immediately) and share the same parent element.
In the following example, the subsequent-sibling combinator (`~`) helps to select and style paragraphs that are both siblings of an image and appear after any image.
```css
img ~ p {
color: red;
}
```
## Syntax
```css-nolint
/* The white space around the ~ combinator is optional but recommended. */
former_element ~ target_element { style properties }
```
## Examples
### Using the combinator with simple selectors
This example shows the use of the `~` combinator when both the selectors are simple selectors (`p` and `span`).
```html
<article>
<span>This is not red because it appears before any paragraph.</span>
<p>Here is a paragraph.</p>
<code>Here is some code.</code>
<span>
This span is red because it appears after the paragraph, even though there
are other nodes in between.
</span>
<p>Whatever it may be, keep smiling.</p>
<h1>Dream big</h1>
<span>
Doesn't matter how many or what kind of nodes are in between, all spans from
the same parent after a paragraph are red.
</span>
</article>
<span>
This span is not red because it doesn't share a parent with a paragraph.
</span>
```
```css
p ~ span {
color: red;
}
```
{{EmbedLiveSample("Using the combinator with simple selectors", "auto", 300)}}
### Using the combinator with complex selectors
This example contains two [complex selectors](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#complex_selector), both using the subsequent-sibling combinator: `.foo p ~ span` and `.foo p ~ .foo span`.
- The first complex selector, `.foo p ~ span`, matches all spans that come after a paragraph _if_ the span and paragraph share the same parent **and** that parent or an ancestor of that parent has the class `.foo`.
- The second complex selector, `.foo p ~ .foo span`, matches all spans that are a descendant of the element with class `.foo` _if_ that element is a sibling of the previously mentioned paragraph.
The example below shows that the target element in the complex selector must share the same parent as the initial element in the complex selector.
```html
<h1>Dream big</h1>
<span>And yet again this is a red span!</span>
<div class="foo">
<p>Here is another paragraph.</p>
<span>A blue span</span>
<div class="foo">
<span>A green span</span>
</div>
</div>
```
```css
.foo p ~ span {
color: blue;
}
.foo p ~ .foo span {
color: green;
}
```
{{EmbedLiveSample("Using the combinator with complex selectors", "auto", 200)}}
In the above HTML, the two siblings of `.foo p` are `span` and `.foo`. The green `span` is a descendant of the `.foo` class, which is a sibling of `p`.
- When the target selector is `span`, the `span` element that is a sibling of `p` is selected. The `p` element is a descendant of `.foo`, so are its `span` siblings.
- In `.foo p ~ .foo span`, the target selector is `span` that is a descendant of `.foo`. In this case, the `span` element that's a descendent of `.foo` is selected if that `.foo` is a sibling of `p`; essentially, both are nested in an ancestor of `.foo`.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Next-sibling combinator](/en-US/docs/Web/CSS/Next-sibling_combinator)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/text-emphasis-color/index.md | ---
title: text-emphasis-color
slug: Web/CSS/text-emphasis-color
page-type: css-property
browser-compat: css.properties.text-emphasis-color
---
{{CSSRef}}
The **`text-emphasis-color`** [CSS](/en-US/docs/Web/CSS) property sets the color of emphasis marks. This value can also be set using the {{cssxref("text-emphasis")}} shorthand.
{{EmbedInteractiveExample("pages/css/text-emphasis-color.html")}}
## Syntax
```css
/* Initial value */
text-emphasis-color: currentcolor;
/* <color> */
text-emphasis-color: #555;
text-emphasis-color: blue;
text-emphasis-color: rgb(90 200 160 / 80%);
text-emphasis-color: transparent;
/* Global values */
text-emphasis-color: inherit;
text-emphasis-color: initial;
text-emphasis-color: revert;
text-emphasis-color: revert-layer;
text-emphasis-color: unset;
```
### Values
- `<color>`
- : Defines the color of the emphasis marks. If no color is present, it defaults to `currentcolor`.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Emphasis with a color and custom character
#### CSS
```css
em {
text-emphasis-color: green;
text-emphasis-style: "*";
}
```
#### HTML
```html
<p>Here's an example:</p>
<em>This has emphasis marks!</em>
```
#### Result
{{EmbedLiveSample("Emphasis_with_a_color_and_custom_character", 450, 100)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- The {{cssxref("<color>")}} data type
- The other emphasis mark related properties: {{cssxref('text-emphasis-style')}}, {{cssxref('text-emphasis')}}, and {{cssxref("text-emphasis-position")}}.
- Other color-related properties: {{cssxref("color")}}, {{cssxref("background-color")}}, {{cssxref("border-color")}}, {{cssxref("outline-color")}}, {{cssxref("text-emphasis-color")}}, {{cssxref("text-shadow")}}, {{cssxref("caret-color")}}, and {{cssxref("column-rule-color")}}
- [Applying color to HTML elements using CSS](/en-US/docs/Web/CSS/CSS_colors/Applying_color)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_where/index.md | ---
title: ":where()"
slug: Web/CSS/:where
page-type: css-pseudo-class
browser-compat: css.selectors.where
---
{{CSSRef}}
The **`:where()`** [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.
The difference between `:where()` and {{CSSxRef(":is", ":is()")}} is that `:where()` always has 0 [specificity](/en-US/docs/Web/CSS/Specificity), whereas `:is()` takes on the specificity of the most specific selector in its arguments.
{{EmbedInteractiveExample("pages/tabbed/pseudo-class-where.html", "tabbed-shorter")}}
### 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
:where(: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
### Comparing :where() and :is()
This example shows how `:where()` works, and also illustrates the difference between `:where()` and `:is()`.
Take the following HTML:
```html
<article>
<h2>:is()-styled links</h2>
<section class="is-styling">
<p>
Here is my main content. This
<a href="https://mozilla.org">contains a link</a>.
</p>
</section>
<aside class="is-styling">
<p>
Here is my aside content. This
<a href="https://developer.mozilla.org">also contains a link</a>.
</p>
</aside>
<footer class="is-styling">
<p>
This is my footer, also containing
<a href="https://github.com/mdn">a link</a>.
</p>
</footer>
</article>
<article>
<h2>:where()-styled links</h2>
<section class="where-styling">
<p>
Here is my main content. This
<a href="https://mozilla.org">contains a link</a>.
</p>
</section>
<aside class="where-styling">
<p>
Here is my aside content. This
<a href="https://developer.mozilla.org">also contains a link</a>.
</p>
</aside>
<footer class="where-styling">
<p>
This is my footer, also containing
<a href="https://github.com/mdn">a link</a>.
</p>
</footer>
</article>
```
In this somewhat-contrived example, we have two articles that each contain a section, an aside, and a footer. They differ by the classes used to mark the child elements.
To make selecting the links inside them simpler, but still distinct, we _could_ use `:is()` or `:where()`, in the following manner:
```css
html {
font-family: sans-serif;
font-size: 150%;
}
:is(section.is-styling, aside.is-styling, footer.is-styling) a {
color: red;
}
:where(section.where-styling, aside.where-styling, footer.where-styling) a {
color: orange;
}
```
However, what if we later want to override the color of links in the footers using a simple selector?
```css
footer a {
color: blue;
}
```
This won't work for the red links, because the selectors inside `:is()` count towards the specificity of the overall selector, and class selectors have a higher specificity than element selectors.
However, selectors inside `:where()` have specificity 0, so the orange footer link will be overridden by our simple selector.
> **Note:** You can also find this example on GitHub; see [is-where](https://mdn.github.io/css-examples/is-where/).
{{EmbedLiveSample('Examples', '100%', 600)}}
## Syntax
```css-nolint
:where(<complex-selector-list>) {
/* ... */
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef(":is", ":is()")}}
- [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/border-image-slice/index.md | ---
title: border-image-slice
slug: Web/CSS/border-image-slice
page-type: css-property
browser-compat: css.properties.border-image-slice
---
{{CSSRef}}
The **`border-image-slice`** [CSS](/en-US/docs/Web/CSS) property divides the image specified by {{cssxref("border-image-source")}} into regions. These regions form the components of an element's [border image](/en-US/docs/Web/CSS/border-image).
{{EmbedInteractiveExample("pages/css/border-image-slice.html")}}
The slicing process creates nine regions in total: four corners, four edges, and a middle region. Four slice lines, set a given distance from their respective sides, control the size of the regions.
[](/en-US/docs/Web/CSS/border-image-slice/border-image-slice.png)
The above diagram illustrates the location of each region.
- Zones 1-4 are corner regions. Each one is used a single time to form the corners of the final border image.
- Zones 5-8 are edge regions. These are [repeated, scaled, or otherwise modified](/en-US/docs/Web/CSS/border-image-repeat) in the final border image to match the dimensions of the element.
- Zone 9 is the middle region. It is discarded by default, but is used like a background image if the keyword `fill` is set.
The {{cssxref("border-image-repeat")}}, {{cssxref("border-image-width")}}, and {{cssxref("border-image-outset")}} properties determine how these regions are used to form the final border image.
## Syntax
```css
/* All sides */
border-image-slice: 30%;
/* top and bottom | left and right */
border-image-slice: 10% 30%;
/* top | left and right | bottom */
border-image-slice: 30 30% 45;
/* top | right | bottom | left */
border-image-slice: 7 12 14 5;
/* Using the `fill` keyword */
border-image-slice: 10% fill;
border-image-slice: fill 10%;
/* Global values */
border-image-slice: inherit;
border-image-slice: initial;
border-image-slice: revert;
border-image-slice: revert-layer;
border-image-slice: unset;
```
The `border-image-slice` property may be specified using one to four `<number-percentage>` values to represent the position of each image slice. Negative values are invalid; values greater than their corresponding dimension are clamped to `100%`.
- When **one** position is specified, it creates all four slices at the same distance from their respective sides.
- When **two** positions are specified, the first value creates slices measured from the **top and bottom**, the second creates slices measured from the **left and right**.
- When **three** positions are specified, the first value creates a slice measured from the **top**, the second creates slices measured from the **left and right**, the third creates a slice measured from the **bottom**.
- When **four** positions are specified, they create slices measured from the **top**, **right**, **bottom**, and **left** in that order (clockwise).
The optional `fill` value, if used, can be placed anywhere in the declaration.
### Values
- {{cssxref("<number>")}}
- : Represents an edge offset in _pixels_ for raster images and _coordinates_ for vector images. For vector images, the number is relative to the element's size, not the size of the source image, so percentages are generally preferable in these cases.
- {{cssxref("<percentage>")}}
- : Represents an edge offset as a percentage of the source image's size: the width of the image for horizontal offsets, the height for vertical offsets.
- `fill`
- : Preserves the middle image region and displays it like a background image, but stacked above the actual {{cssxref("background")}}. Its width and height are sized to match the top and left image regions, respectively.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Adjustable border width and slice
The following example shows a simple `<div>` with a border image set on it. The source image for the borders is as follows:

The diamonds are 30px across, therefore setting 30 pixels as the value for both [`border-width`](/en-US/docs/Web/CSS/border-width) and `border-image-slice` will get you complete and fairly crisp diamonds in your border:
```css
border-width: 30px;
border-image-slice: 30;
```
These are the default values we have used in this example. However, we have also provided two sliders to allow you to dynamically change the values of the above two properties, allowing you to appreciate the effect they have:
`border-image-slice` Changes the size of the image slice sampled for use in each border and border corner (and the content area, if the `fill` keyword is used) — varying this away from 30 causes the border to look somewhat irregular, but can have some interesting effects.
`border-width`: Changes the width of the border. The sampled image size is scaled to fit inside the border, which means that if the width is bigger than the slice, the image can start to look somewhat pixelated (unless of course you use an SVG image).
#### HTML
```html
<div class="wrapper">
<div></div>
</div>
<ul>
<li>
<label for="width">slide to adjust <code>border-width</code></label>
<input type="range" min="10" max="45" id="width" />
<output id="width-output">30px</output>
</li>
<li>
<label for="slice">slide to adjust <code>border-image-slice</code></label>
<input type="range" min="10" max="45" id="slice" />
<output id="slice-output">30</output>
</li>
</ul>
```
#### CSS
```css
.wrapper {
width: 400px;
height: 300px;
}
div > div {
width: 300px;
height: 200px;
border-width: 30px;
border-style: solid;
border-image: url(https://interactive-examples.mdn.mozilla.net/media/examples/border-diamonds.png);
border-image-slice: 30;
border-image-repeat: round;
}
li {
display: flex;
place-content: center;
}
```
#### JavaScript
```js
const widthSlider = document.getElementById("width");
const sliceSlider = document.getElementById("slice");
const widthOutput = document.getElementById("width-output");
const sliceOutput = document.getElementById("slice-output");
const divElem = document.querySelector("div > div");
widthSlider.addEventListener("input", () => {
const newValue = `${widthSlider.value}px`;
divElem.style.borderWidth = newValue;
widthOutput.textContent = newValue;
});
sliceSlider.addEventListener("input", () => {
const newValue = sliceSlider.value;
divElem.style.borderImageSlice = newValue;
sliceOutput.textContent = newValue;
});
```
#### Result
{{EmbedLiveSample('Adjustable_border_width_and_slice', '100%', 400)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Illustrated description of the 1-to-4-value syntax](/en-US/docs/Web/CSS/Shorthand_properties#tricky_edge_cases)
- [Border images in CSS: A key focus area for Interop 2023](/en-US/blog/border-images-interop-2023/) on MDN blog (2023)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/css_overflow/index.md | ---
title: CSS overflow
slug: Web/CSS/CSS_overflow
page-type: css-module
spec-urls: https://drafts.csswg.org/css-overflow/#propdef-overflow
---
{{CSSRef}}
The **CSS overflow** module properties enable you to handle scrollable overflow in visual media.
Overflow happens when the content in an element box extends past one or more of the box's edges. **Scrollable overflow** is the content that appears outside the element box for which you might want to add a scrolling mechanism. CSS overflow properties enable you to control what happens when content overflows an element box.
Painting effects that overflow the content but do not participate in the CSS box model do not affect layout. This type of overflow is also known as {{Glossary("ink overflow")}}. Examples of ink overflows include box shadows, border images, text decoration, overhanging glyphs, and outlines. Ink overflows do not extend the scrollable overflow region.
## Overflow in action
Use the following interactive example to see the effects of various `overflow` property values on the content overflow and scrollbars in the adjacent fixed-size box.
The example also includes options to change the values for the `overflow-clip-margin` and `width` properties, as well as to programmatically scroll the content if the overflow property creates a {{Glossary("scroll container")}}. Select `overflow: clip` and see the effect of different `overflow-clip-margin` values. Select `overflow: hidden` or `overflow: scroll` to check out different `ScrollLeft` and `ScrollTop` slider settings.
{{EmbedGHLiveSample("css-examples/modules/overflow.html", '100%', 320)}}
A link is included in content box above to demonstrate the effects of keyboard focus on overflow and scroll behaviors. Try tabbing to the link or programmatically scrolling the content: the content will scroll only if the enumerated `<overflow>` value created a scroll container.
## Reference
### CSS properties
- {{CSSxRef("overflow")}} shorthand
- {{CSSxRef("overflow-block")}}
- {{CSSxRef("overflow-clip-margin")}}
- {{CSSxRef("overflow-inline")}}
- {{CSSxRef("overflow-x")}}
- {{CSSxRef("overflow-y")}}
- {{CSSxRef("scroll-behavior")}}
- {{CSSxRef("scrollbar-gutter")}}
- {{CSSxRef("text-overflow")}}
- {{CSSxRef("block-ellipsis")}}
- {{CSSxRef("continue")}} {{experimental_inline}}
- {{CSSxRef("line-clamp")}} {{experimental_inline}}
- {{CSSxRef("max-lines")}} {{experimental_inline}}
- {{CSSxRef("-webkit-line-clamp")}} {{non-standard_inline}}
### Data types
- [`<overflow>`](/en-US/docs/Web/CSS/overflow_value) enumerated values
## Guides
- [Overflowing content](/en-US/docs/Learn/CSS/Building_blocks/Overflowing_content)
- : CSS building block: learn what overflow is and how to manage it.
- {{Experimental_Inline}} [Creating a named scroll timeline](/en-US/docs/Web/CSS/scroll-timeline-name#creating_a_named_scroll_timeline)
- : The CSS scroll timeline {{cssxref('scroll-timeline-name')}} and {{cssxref('scroll-timeline-axis')}} properties, along with the {{cssxref('scroll-timeline')}} shorthand, create animations tied to the scroll offset of a scroll container.
## Related concepts
- {{CSSxRef("scrollbar-width")}} CSS property
- {{CSSxRef("scrollbar-color")}} CSS property
- {{CSSxRef("scrollbar-gutter")}} CSS property
- {{CSSxRef("scroll-behavior")}} CSS property
- {{cssxref("scroll-margin")}} CSS shorthand property
- {{cssxref("scroll-padding")}} CSS shorthand property
- {{cssxref("scroll-snap-align")}} CSS property
- {{cssxref("scroll-snap-stop")}} CSS property
- {{cssxref("scroll-snap-type")}} CSS property
- {{cssxref("text-overflow")}} CSS property
- {{CSSxRef("::-webkit-scrollbar")}} pseudo-element
- [`scrollbar`](/en-US/docs/Web/Accessibility/ARIA/Roles/scrollbar_role) ARIA role
- Element {{domxref("Element.scroll", "scroll()")}} method
- Element {{domxref("Element.scrollBy", "scrollBy()")}} method
- Element {{domxref("Element.scrollIntoView", "scrollIntoView()")}} method
- Element {{domxref("Element.scrollTo", "scrollTo()")}} method
- Element {{domxref("Element.scrollTop", "scrollTop")}} property
- Element {{domxref("Element.scrollLeft", "scrollLeft")}} property
- Element {{domxref("Element.scrollWidth", "scrollWidth")}} property
- Element {{domxref("Element.scrollHeight", "scrollHeight")}} property
- Document {{domxref("Document.scroll_event", "scroll")}} event
- {{Glossary("Scroll container")}} glossary term
- {{Glossary("Ink overflow")}} glossary term
## Specifications
{{Specifications}}
## See also
- [CSS scrollbars styling](/en-US/docs/Web/CSS/CSS_scrollbars_styling) module
- [CSS scroll snap](/en-US/docs/Web/CSS/CSS_scroll_snap) module
- [CSSOM view](/en-US/docs/Web/CSS/CSSOM_view) module
- How to [debug scrollable overflow](https://firefox-source-docs.mozilla.org/devtools-user/page_inspector/how_to/debug_scrollable_overflow/index.html)
| 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.