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/layout_cookbook | data/mdn-content/files/en-us/web/css/layout_cookbook/list_group_with_badges/index.md | ---
title: List group with badges
slug: Web/CSS/Layout_cookbook/List_group_with_badges
page-type: guide
browser-compat: css.properties.flex
---
{{CSSRef}}
In this recipe we will create a list group pattern with badges that indicate a count.

## Requirements
The list items should be displayed with the badges. The badge should be aligned right and vertically centered. The badge must be centered vertically whether there is a single line of content or multiple lines of text.
## Recipe
{{EmbedGHLiveSample("css-examples/css-cookbook/list-group-badges.html", '100%', 720)}}
> **Callout:**
>
> [Download this example](https://github.com/mdn/css-examples/blob/main/css-cookbook/list-group-badges--download.html)
## Choices made
Flexbox makes this particular pattern straightforward and also facilitates making changes to the layout.
To ensure the text and badge line up correctly, I use the {{cssxref("justify-content")}} property with a value of `space-between`. This places any extra space between the items. In the live example, if you remove this property, you will see the badge move to the end of the text on items with text shorter than the one line.
To align the content horizontally, I use the {{cssxref("align-items")}} property to align the text and badge on the cross axis. If you want the badge to align to the top of the content instead, change this to `align-items: flex-start`.
## See also
- [Box alignment in Flexbox](/en-US/docs/Web/CSS/CSS_box_alignment/Box_alignment_in_flexbox)
- [Aligning items in a flex container](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Aligning_items_in_a_flex_container)
- [CSS flexible box layout](/en-US/docs/Web/CSS/CSS_flexible_box_layout) module
| 0 |
data/mdn-content/files/en-us/web/css/layout_cookbook | data/mdn-content/files/en-us/web/css/layout_cookbook/sticky_footers/index.md | ---
title: Sticky footers
slug: Web/CSS/Layout_cookbook/Sticky_footers
page-type: guide
browser-compat: css.properties.grid
---
{{CSSRef}}
A sticky footer pattern is one where the footer of your page "sticks" to the bottom of the viewport in cases where the content is shorter than the viewport height. We'll look at a couple of techniques for creating one in this recipe.

## Requirements
The Sticky footer pattern needs to meet the following requirements:
- Footer sticks to the bottom of the viewport when content is short.
- If the content of the page extends past the viewport bottom, the footer then sits below the content as normal.
## The recipe
{{EmbedGHLiveSample("css-examples/css-cookbook/sticky-footer.html", '100%', 720)}}
> **Callout:**
>
> [Download this example](https://github.com/mdn/css-examples/blob/main/css-cookbook/sticky-footer--download.html)
> **Note:** In this example and the following one we are using a wrapper set to `min-height: 100%`. You can also achieve this for a full page by setting a {{cssxref("min-height")}} of `100vh` on the {{htmlelement("body")}} and then using it as your grid container.
## Choices made
In the above example we achieve the sticky footer using CSS Grid Layout. The `.wrapper` has a minimum height of `100%` which means it is as tall as the container it is in. We then create a single column grid layout with three rows, one row for each part of our layout.
Grid auto-placement will place our items in source order and so the header goes into the first auto sized track, the main content into the `1fr` track and the footer into the final auto sized track. The `1fr` track will take up all available space and so grows to fill the gap.
## Alternate method
You can also use Flexbox to create a sticky footer.
{{EmbedGHLiveSample("css-examples/css-cookbook/sticky-footer-flexbox.html", '100%', 720)}}
The flexbox example starts out in the same way, but we use `display:flex` rather than `display:grid` on the `.wrapper`; we also set `flex-direction` to `column`. Then we set our main content to `flex-grow: 1` and the other two elements to `flex-shrink: 0` β this prevents them from shrinking smaller when content fills the main area.
## Resources on MDN
- CSS properties: {{cssxref("display")}}, {{cssxref("min-height")}}, {{cssxref("grid-template-rows")}}, {{cssxref("flex-direction")}}, {{cssxref("flex-grow")}}, {{cssxref("flex-shrink")}}
- [Basic concepts of grid layout](/en-US/docs/Web/CSS/CSS_grid_layout/Basic_concepts_of_grid_layout)
- [CSS grid layout](/en-US/docs/Web/CSS/CSS_grid_layout) module
- [Basic concepts of flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox)
- [CSS flexible box layout](/en-US/docs/Web/CSS/CSS_flexible_box_layout) module
| 0 |
data/mdn-content/files/en-us/web/css/layout_cookbook | data/mdn-content/files/en-us/web/css/layout_cookbook/contribute_a_recipe/index.md | ---
title: Contribute a recipe
slug: Web/CSS/Layout_cookbook/Contribute_a_recipe
page-type: guide
---
{{CSSRef}}
If you would like to contribute an example for the Layout Cookbook, then this page explains the steps to take to have your example published.
## What makes a good recipe?
**The simplest possible version of any useful web design pattern**. Each line of CSS that you include should be there to help demonstrate the pattern, so leave out anything there purely to make the example look pretty. The idea is that someone can take the pattern and use it in a site with their own styles.
A recipe consists of:
- A live example, stored in the [CSS Examples GitHub repo](https://github.com/mdn/css-examples).
- A downloadable version of that example, also stored in the CSS Examples repo.
- A page in the [CSS layout cookbook](/en-US/docs/Web/CSS/Layout_cookbook) section of the site, which should include the following components:
1. Introduction
2. Requirements
3. Recipe
4. Decisions
5. Useful fallbacks or alternative methods (when relevant)
6. Accessibility concerns
7. Browser compatibility (only for CSS properties not fully supported)
8. Additional resources
## Steps to publish a recipe
To create a recipe and add it to the CSS Layout Cookbook, follow these steps:
1. [Build a pattern](#1._build_a_pattern)
2. [Create a live example](#2._create_a_live_example)
3. [Create a downloadable version](#3._create_a_downloadable_version)
4. [Open a pull request](#4._open_a_pull_request_with_your_example)
5. [Add your content to MDN](#5._create_your_page)
### 1. Build a pattern
Before turning your example into a recipe, start by creating your pattern as a basic HTML page. Think about what you are trying to demonstrate and keep it as simple as possible. Use descriptive words like "container" or "item" if adding class names.
Ensure that you've tested the HTML and CSS across multiple browsers, viewport sizes, and devices. Also ensure that any CSS styling follows accessibility guidelines. While it's okay to use CSS properties with limited support, be sure to include browser support information when creating the page, particularly in the browser compatibility section. In some cases, creating a second version of your example with fallback support can be helpful.
### 2. Create a live example
The live examples on cookbook pages, such as for [centering an element](/en-US/docs/Web/CSS/Layout_cookbook/Center_an_element), and elsewhere on MDN allow readers to play with the code and change relevant parts without being overwhelmed with all of the code. Your recipe will be demonstrated by way of one or more examples.
Fork the [CSS Examples repo](https://github.com/mdn/css-examples) and then take a look in the `css-cookbook` folder. There is a [cookbook-template.html](https://github.com/mdn/css-examples/blob/main/css-cookbook/cookbook-template.html) file. Copy this file and use it as a starting point. Save this in the `css-cookbook` directory with a name that makes sense for your pattern. The template contains comments to guide you in adding various parts at the appropriate places.
The important parts of this template are as follows:
- There is a stylesheet for the editor panels with some basic body styling and a JavaScript file for the editor functionality. Leave these files as they are.
- The `<head>` contains two style blocks. The first style block is for elements that readers do not need to change to play with the example. The second style block contains items that readers might want to play with. We typically add all our CSS to the first block, then choose the rules to move to the second block. The rules in the second block should be those that are fundamental to the pattern, perhaps those where a reader can change a CSS value and see the pattern update.
- You need to add the HTML for your component twice: first inside the section with the class `preview`, and then inside the `<textarea>` with the class `playable-html`.
- The editable CSS from the second `<head>` block must also be copied into the `playable-css` section.
A simple working example is [center.html](https://github.com/mdn/css-examples/blob/main/css-cookbook/center.html), which is embedded on the page [Center an element](/en-US/docs/Web/CSS/Layout_cookbook/Center_an_element). You can use this to see how to add the various bits correctly.
If you've forked the repo and have our CSS and JavaScript files with your example, opening your live example in a browser should display everything working exactly as it would appear on an MDN page.
#### Useful tips
- Do not indent the CSS and HTML inside the textareas; instead, align the code with the start of the lines. This will look better when it is rendered.
- If any images are required, put them in the directory with the examples. You are welcome to use any images already present.
- You can adjust the height of the textareas by changing the height in the inline styles.
### 3. Create a downloadable version
As the examples include all of our live example code, we want to provide readers with just the code they need for their example, omitting any unnecessary items. Create a copy of your live example, and add `--download` to its name. For example, the download version of `center.html` is `center--download.html`. This file will be similar to your initial example. It should be a basic version of your pattern as a single HTML page.
It can be handy to include the body CSS rules from our included stylesheet. Take a look at [`cookbook-template--download.html`](https://github.com/mdn/css-examples/blob/main/css-cookbook/cookbook-template--download.html) as a guide; these rules are provided as a starting point.
### 4. Open a pull request with your example
Open a pull request (PR) on the [CSS Examples repo](https://github.com/mdn/css-examples/pulls). This allows us to help you with any changes to the example that may be needed before you create your page. Plus, the example will need to be live to be included. This is why it makes sense to first create the code examples and then the explanatory guide. In your PR, explain the pattern and what you are demonstrating. See our [guidelines for opening a pull request](/en-US/docs/MDN/Community/Pull_requests#open_a_pull_request).
### 5. Create your page
After your example PR is merged, open a pull request to create a new page in the [Layout Cookbook directory](https://github.com/mdn/content/tree/main/files/en-us/web/css/layout_cookbook).
Use our [template for Cookbook pages](https://github.com/mdn/content/blob/main/files/en-us/web/css/layout_cookbook/contribute_a_recipe/cookbook_template/index.md?plain=1).
The template explains the requirements of each section, and you can refer to other cookbook examples for more help.
Remember to add a link to your new recipe on the main [Layout cookbook](/en-US/docs/Web/CSS/Layout_cookbook) page.
If you have any questions or want someone to take a look at your page, get in touch via any of our [communication channels](/en-US/docs/MDN/Community/Communication_channels).
## See also
- [Cookbook page template](/en-US/docs/Web/CSS/Layout_cookbook/Contribute_a_recipe/Cookbook_template)
- [CSS Examples repo](https://github.com/mdn/css-examples)
| 0 |
data/mdn-content/files/en-us/web/css/layout_cookbook/contribute_a_recipe | data/mdn-content/files/en-us/web/css/layout_cookbook/contribute_a_recipe/cookbook_template/index.md | ---
title: Cookbook template
slug: Web/CSS/Layout_cookbook/Contribute_a_recipe/Cookbook_template
page-type: guide
---
{{CSSRef}}
> **Note:** This is a template page for a CSS Cookbook page. Please use this as a raw template when you create a new cookbook page.
> _Comment in italics are information about how to use part of the template._
_Description of the problem this recipe solves or the pattern you are demonstrating._
## Requirements
_What does this pattern need to include, or what problems does it need to solve? List that here._
## Recipe
_Change the path to the example below to point to your merged example. The last parameter is the live example height, which you can change as needed._
{{EmbedGHLiveSample("css-examples/css-cookbook/center.html", '100%', 720)}}
_Change the link to point to your merged download version._
[Download the example](https://github.com/mdn/css-examples/blob/main/css-cookbook/center--download.html)
## Choices made
_Explain your decisions when creating the pattern. Why did you choose a certain method? If you want to add an additional example here β for example a version with fallbacks, please do. This section is deliberately loose as patterns range from the very simple to more complex._
## Useful fallbacks or alternative methods
_If there are useful alternative methods for building the recipe, or fallback recipes to use if you have to support non-supporting browsers, include them in separate sections down here._
## Accessibility concerns
_Include this is there are any specific things to watch out for in regard to accessibility. If not relevant for your pattern this can be omitted._
## Browser compatibility
_List the key properties you used in the `browser-compat` frontmatter metadata key. Then use the `\{{Compat}}` macro in this section to automatically generate a compatibility table for the listed properties._
## See also
- _Links of link of related properties: {{Cssxref("example-property")}}_
- _Links to article showing how to use the property in context: "Using β¦ article"_
- _Very good external links. Don't be afraid of external links, but they should be outstanding, and not only mention minor details._
| 0 |
data/mdn-content/files/en-us/web/css/layout_cookbook | data/mdn-content/files/en-us/web/css/layout_cookbook/media_objects/index.md | ---
title: "Recipe: Media objects"
slug: Web/CSS/Layout_cookbook/Media_objects
page-type: guide
browser-compat: css.properties.grid
---
{{CSSRef}}
The _Media Object_ is a pattern we see all over the web. It refers to a two-column box with an image on one side and descriptive text on the other, e.g. a social media post.

## Requirements
Media Object pattern needs some or all of the following characteristics:
- Stacked on Mobile, two columns on Desktop.
- The image can be on the left or right.
- The image might be small or large.
- Media Objects can be nested.
- The Media Object should clear the contents no matter which side is tallest.
## The recipe
{{EmbedGHLiveSample("css-examples/css-cookbook/media-objects.html", '100%', 2700)}}
> **Callout:**
>
> [Download this example](https://github.com/mdn/css-examples/blob/main/css-cookbook/media-objects--download.html)
## Choices made
I have chosen to use [grid layout](/en-US/docs/Web/CSS/CSS_grid_layout) for the media object as it allows me to control the layout in two dimensions when I need to. This means that when we have a footer, with short content above, the footer can be pushed down to the bottom of the media object.
Another reason to use grid layout is in order that I can use {{cssxref("fit-content")}} for the track sizing of the image. By using `fit-content` with a maximum size of 200 pixels, when we have a small image such as the icon, the track only gets as large as the size of that image β the `max-content` size. If the image is larger, the track stops growing at 200 pixels and as the image has a {{cssxref("max-width")}} of 100% applied, it scales down so that it continues to fit inside the column.
By using {{cssxref("grid-template-areas")}} to achieve the layout, I can see the pattern in the CSS. I define my grid once we have a max-width of 500 pixels, so on smaller devices the media object stacks.
An option for the pattern is to flip it to switch the image to the other side β this is done by adding the `media-flip` class, which defines a flipped grid template causing the layout to be mirrored.
When we nest one media object inside another we need to place it into the second track in the regular layout, and the first track when flipped.
## See also
- {{cssxref("fit-content")}} property
- [Using grid template areas](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_template_areas)
- [CSS grid layout](/en-US/docs/Web/CSS/CSS_grid_layout) module
| 0 |
data/mdn-content/files/en-us/web/css/layout_cookbook | data/mdn-content/files/en-us/web/css/layout_cookbook/card/index.md | ---
title: Card
slug: Web/CSS/Layout_cookbook/Card
page-type: guide
browser-compat: css.properties.grid
---
{{CSSRef}}
This pattern is a list of "card" components with optional footers. A card contains a title, an image, a description or other content, and an attribution or footer. Cards are generally displayed within a group or collection.

## Requirements
Create a group of cards, with each card component containing a heading, image, content, and, optionally, a footer.
Each card in the group of cards should be the same height. The optional card footer should stick to the bottom of the card.
The cards in the group should line up in two dimensions β both vertically and horizontally.
## Recipe
{{EmbedGHLiveSample("css-examples/css-cookbook/card.html", '100%', 1720)}}
> **Callout:**
>
> [Download this example](https://github.com/mdn/css-examples/blob/main/css-cookbook/card--download.html)
## Choices made
Each card is laid out using [CSS Grid Layout](/en-US/docs/Web/CSS/CSS_grid_layout) despite the layout being one-dimensional. This enables the use of content sizing for the grid tracks. To set up a single-column grid we can use the following:
```css
.card {
display: grid;
grid-template-rows: max-content 200px 1fr;
}
```
{{cssxref("display", "display: grid")}} converts the element into a grid container. The three values of the {{cssxref("grid-template-rows")}} property divide the grid into a minimum of three rows, defining the height of the first three children of the card, in order.
Each `card` contains a {{HTMLElement("header")}}, {{HTMLElement("image")}}, and {{HTMLElement("div")}}, in that order, with some also containing a {{HTMLElement("footer")}}.
The heading row, or track, is set to {{cssxref("max-content")}}, which prevents it from stretching. The image track is set to 200 pixels tall. The third track, where the content lives, is set to `1fr`. This means it will fill any additional space.
Any children beyond the three with explicitly defined sizes create rows in the implicit grid, which fits the content added to it. These are auto-sized by default. If a card contains a footer, it is auto-sized. The footer, when present, sticks to the bottom of the grid. The footer is auto-sized to fit its content; the content `<div>` then stretches take up any additional space.
The following ruleset creates the grid of cards:
```css
.cards {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
gap: 20px;
}
```
The {{cssxref("grid-template-columns")}} property defines the widths of the grid columns. In this case, we set the grid to auto-fill, with repeated columns that are minimally `230px` but allowed to grow to fill the available space. The {{cssxref("gap")}} property sets a gap of `20px` between adjacent rows and adjacent columns.
> **Note:** The various elements in separate cards do not align with each other, as each card is an independent grid. Lining up the components in each card with the same components in adjacent cards can be done with [subgrid](/en-US/docs/Web/CSS/CSS_grid_layout/Subgrid).
## Alternative methods
[Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout) can also be used to lay out each card. With flexbox, the dimensions of each card's rows are set with the {{cssxref("flex")}} property on each row, rather than on the card container.
With flexbox, the dimensions of the flex items are defined on the children rather than the parent. Whether you choose to use grid or flexbox depends on your preference, whether you prefer controlling the tracks from the container or prefer adding rules to the items.
We chose grid for the cards as, generally, you want cards to be lined up both vertically and horizontally. Additionally, lining up the components within each card to the components of adjacent cards can be done with subgrid. Flex has no hack-free equivalent to subgrid.
## Accessibility concerns
Depending on the content of your card, there may be things you could or should do to enhance accessibility. See [Inclusive Components: Card](https://inclusive-components.design/cards/) by Heydon Pickering, for a very detailed explanation of these issues.
## See also
- {{Cssxref("grid-template-columns")}}, {{Cssxref("grid-template-rows")}}, {{Cssxref("gap")}}
- [Inclusive Components: Card](https://inclusive-components.design/cards/)
- [CSS Grid Layout](/en-US/docs/Web/CSS/CSS_grid_layout) module
| 0 |
data/mdn-content/files/en-us/web/css/layout_cookbook | data/mdn-content/files/en-us/web/css/layout_cookbook/split_navigation/index.md | ---
title: Split navigation
slug: Web/CSS/Layout_cookbook/Split_Navigation
page-type: guide
browser-compat: css.properties.flex
---
{{CSSRef}}
The **split navigation** is a navigation pattern where one or more elements are separated from the rest of the navigation items.

## Requirements
A common navigation pattern is to have one element pushed away from the others. We can use flexbox to achieve this, without needing to make the two sets of items into two separate flex containers.
## Recipe
{{EmbedGHLiveSample("css-examples/css-cookbook/split-navigation.html", '100%', 520)}}
> **Callout:**
>
> [Download this example](https://github.com/mdn/css-examples/blob/main/css-cookbook/split-navigation--download.html)
## Choices made
This pattern combines auto margins with flexbox to split the items.
An auto margin absorbs all available space in the direction it is applied. This is how centering a block with auto margins works β you have a margin on each side of the block trying to take up all of the space, thus pushing the block into the middle.
In this case the left auto margin takes up any available space and pushes the item over to the right. You could apply the class `push` to any item in the list.
## See also
- [CSS flexible box layout](/en-US/docs/Web/CSS/CSS_flexible_box_layout) module
- {{cssxref("display")}} property
- {{cssxref("margin")}} property
| 0 |
data/mdn-content/files/en-us/web/css/layout_cookbook | data/mdn-content/files/en-us/web/css/layout_cookbook/column_layouts/index.md | ---
title: Column layouts
slug: Web/CSS/Layout_cookbook/Column_layouts
page-type: guide
browser-compat: css.properties.flex
---
{{CSSRef}}
You will often need to create a layout which has a number of columns, and CSS provides several ways to do this. Whether you use [Multi-column](/en-US/docs/Web/CSS/CSS_multicol_layout), [Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout), or [Grid](/en-US/docs/Web/CSS/CSS_grid_layout) layout will depend on what you are trying to achieve, and in this recipe we explore these options.

## Requirements
There are a number of design patterns you might want to achieve with your columns:
- [A continuous thread of content broken up into newspaper-style columns](#a-continuous-thread-of-content--multi-column-layout).
- [A single row of items arranged as columns, with all heights being equal](#a-single-row-of-items-with-equal-heights--flexbox).
- [Multiple rows of columns lined up by row and column](#lining-items-up-in-rows-and-columns--grid-layout).
## The recipes
You need to choose different layout methods in order to achieve your requirements.
### A continuous thread of content β multi-column layout
If you create columns using multi-column layout your text will remain as a continuous stream filling each column in turn. The columns must all be the same size, and you are unable to target an individual column or the content of an individual column.
You can control the gaps between columns with the {{cssxref("column-gap")}} or {{cssxref("gap")}} properties, and add a rule between columns using {{cssxref("column-rule")}}.
{{EmbedGHLiveSample("css-examples/css-cookbook/columns-multicol.html", '100%', 720)}}
In this example, we used the {{cssxref("column-width")}} property to set a minimum width that the columns need to be before the browser adds an additional column. The {{cssxref("columns")}} shorthand property can be used to set the `column-width` and {{cssxref("column-count")}} properties, either of which can define the maximum number of columns allowed.
> **Callout:**
>
> [Download this example](https://github.com/mdn/css-examples/blob/main/css-cookbook/columns-multicol--download.html)
Use multicol when:
- You want your text to display in newspaper-like columns.
- You have a set of small items you want to break into columns.
- You do not need to target individual column boxes for styling.
### A single row of items with equal heights β flexbox
Flexbox can be used to break content into columns by setting {{cssxref("display", "display: flex;")}} to make a parent element a flex-container. Just adding this one property turns all the children (child elements, pseudo-elements, and text nodes) into flex items along a single line. Setting the same {{cssxref("flex")}} shorthand property with a single numeric value distributes all the available space equally, generally making all the flex items the same size as long as none have non-wrapping content forcing the item to be larger.
Margins or the `gap` property can be used to create gaps between items, but there is currently no CSS property that adds rules between flex items.
{{EmbedGHLiveSample("css-examples/css-cookbook/columns-flexbox.html", '100%', 720)}}
> **Callout:**
>
> [Download this example](https://github.com/mdn/css-examples/blob/main/css-cookbook/columns-flexbox--download.html)
To create a layout with flex items that wrap onto new rows, set the {{cssxref("flex-wrap")}} property on the container to `wrap`. Note that each flex line distributes space for that line only. Items in one line will not necessarily line up with items on other lines, as you'll see in the example below. This is why flexbox is described as one-dimensional. It is designed for controlling layout as a row or a column, but not both at the same time.
{{EmbedGHLiveSample("css-examples/css-cookbook/columns-flexbox-wrapping.html", '100%', 720)}}
> **Callout:**
>
> [Download this example](https://github.com/mdn/css-examples/blob/main/css-cookbook/columns-flexbox-wrapping--download.html)
Use flexbox:
- For single rows or columns of items.
- When you want to do alignment on the cross axis after laying out your items.
- When you are happy for wrapped items to share out space along their line only and not line up with items in other lines.
### Lining items up in rows and columns β grid layout
If you want a two-dimensional grid where items line up in rows _and_ columns, then you should choose CSS Grid Layout. Similar to how flexbox works on the direct children of the flex container, grid layout works on the direct children of the grid container. Just set {{cssxref("display", "display: grid;")}} on the container. Properties set on this container β like {{cssxref("grid-template-columns")}} and {{cssxref("grid-template-rows")}} β define how the items are distributed along rows and columns.
{{EmbedGHLiveSample("css-examples/css-cookbook/columns-grid.html", '100%', 720)}}
> **Callout:**
>
> [Download this example](https://github.com/mdn/css-examples/blob/main/css-cookbook/columns-grid--download.html)
Use Grid:
- For multiple rows or columns of items.
- When you want to be able to align the items on the block and inline axes.
- When you want items to line up in rows and columns.
## Resources on MDN
- [Guide to Multi-column Layout](/en-US/docs/Web/CSS/CSS_multicol_layout)
- [Guide to Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout)
- [Guide to CSS Grid Layout](/en-US/docs/Web/CSS/CSS_grid_layout)
| 0 |
data/mdn-content/files/en-us/web/css/layout_cookbook | data/mdn-content/files/en-us/web/css/layout_cookbook/center_an_element/index.md | ---
title: Center an element
slug: Web/CSS/Layout_cookbook/Center_an_element
page-type: guide
browser-compat: css.properties.grid
---
{{CSSRef}}
In this recipe, you will see how to center one box inside another by using [flexbox](#using_flexbox) and [grid](#using_grid). Centering both horizontally and vertically is simple and straightforward.

## Requirements
To place an item into the center of another box horizontally and vertically.
## Recipe
{{EmbedGHLiveSample("css-examples/css-cookbook/center.html", '100%', 720)}}
> **Callout:**
>
> [Download this example](https://github.com/mdn/css-examples/blob/main/css-cookbook/center--download.html)
## Using flexbox
To center a box within another box, first turn the containing box into a [flex container](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox#the_flex_container) by setting its {{cssxref("display")}} property to `flex`. Then set {{cssxref("align-items")}} to `center` for vertical centering (on the block axis) and {{cssxref("justify-content")}} to `center` for horizontal centering (on the inline axis). And that's all it takes to center one box inside another!
### HTML
```html
<div class="container">
<div class="item">I am centered!</div>
</div>
```
### CSS
```css
div {
border: solid 3px;
padding: 1em;
max-width: 75%;
}
.container {
display: flex;
align-items: center;
justify-content: center;
height: 8em;
}
```
We set a height for the container to demonstrate that the inner item is indeed vertically centered within the container.
### Result
{{ EmbedLiveSample('Using_flexbox', 400, 200) }}
Instead of applying `align-items: center;` on the container, you can also vertically center the inner item by setting {{cssxref("align-self")}} to `center` on the inner item itself.
## Using grid
Another method you can use for centering one box inside another is to first make the containing box a [grid container](/en-US/docs/Web/CSS/CSS_grid_layout/Basic_concepts_of_grid_layout#grid_container) and then set its {{cssxref("place-items")}} property to `center` to center align its items on both the block and inline axes.
### HTML
```html
<div class="container">
<div class="item">I am centered!</div>
</div>
```
### CSS
```css
div {
border: solid 3px;
padding: 1em;
max-width: 75%;
}
.container {
display: grid;
place-items: center;
height: 8em;
}
```
### Result
{{ EmbedLiveSample('Using_grid', 400, 200) }}
Instead of applying `place-items: center;` on the container, you can achieve the same centering by setting {{cssxref("place-content", "place-content: center;")}} on the container or by applying either {{cssxref("place-self", "place-self: center")}} or {{cssxref("margin", "margin: auto;")}} on the inner item itself.
## Resources on MDN
- [Box Alignment in Flexbox](/en-US/docs/Web/CSS/CSS_box_alignment/Box_alignment_in_flexbox)
- [CSS Box alignment guide](/en-US/docs/Web/CSS/CSS_box_alignment)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_doublecolon_cue/index.md | ---
title: "::cue"
slug: Web/CSS/::cue
page-type: css-pseudo-element
browser-compat: css.selectors.cue
---
{{CSSRef}}
The **`::cue`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) matches [WebVTT](/en-US/docs/Web/API/WebVTT_API) cues within a selected element. This can be used to [style captions and other cues](/en-US/docs/Web/API/WebVTT_API#styling_webvtt_cues) in media with VTT tracks.
{{EmbedInteractiveExample("pages/tabbed/pseudo-element-cue.html", "tabbed-shorter")}}
The properties are applied to the entire set of cues as if they were a single unit. The only exception is that `background` and its longhand properties apply to each cue individually, to avoid creating boxes and obscuring unexpectedly large areas of the media.
## Syntax
```css-nolint
::cue | ::cue(<selector>) {
/* ... */
}
```
## Permitted properties
Rules whose selectors include this element may only use the following CSS properties:
- [`background`](/en-US/docs/Web/CSS/background)
- [`background-attachment`](/en-US/docs/Web/CSS/background-attachment)
- [`background-clip`](/en-US/docs/Web/CSS/background-clip)
- [`background-color`](/en-US/docs/Web/CSS/background-color)
- [`background-image`](/en-US/docs/Web/CSS/background-image)
- [`background-origin`](/en-US/docs/Web/CSS/background-origin)
- [`background-position`](/en-US/docs/Web/CSS/background-position)
- [`background-repeat`](/en-US/docs/Web/CSS/background-repeat)
- [`background-size`](/en-US/docs/Web/CSS/background-size)
- [`color`](/en-US/docs/Web/CSS/color)
- [`font`](/en-US/docs/Web/CSS/font)
- [`font-family`](/en-US/docs/Web/CSS/font-family)
- [`font-size`](/en-US/docs/Web/CSS/font-size)
- [`font-stretch`](/en-US/docs/Web/CSS/font-stretch)
- [`font-style`](/en-US/docs/Web/CSS/font-style)
- [`font-variant`](/en-US/docs/Web/CSS/font-variant)
- [`font-weight`](/en-US/docs/Web/CSS/font-weight)
- [`line-height`](/en-US/docs/Web/CSS/line-height)
- [`opacity`](/en-US/docs/Web/CSS/opacity)
- [`outline`](/en-US/docs/Web/CSS/outline)
- [`outline-color`](/en-US/docs/Web/CSS/outline-color)
- [`outline-style`](/en-US/docs/Web/CSS/outline-style)
- [`outline-width`](/en-US/docs/Web/CSS/outline-width)
- [`ruby-position`](/en-US/docs/Web/CSS/ruby-position)
- [`text-combine-upright`](/en-US/docs/Web/CSS/text-combine-upright)
- [`text-decoration`](/en-US/docs/Web/CSS/text-decoration)
- [`text-decoration-color`](/en-US/docs/Web/CSS/text-decoration-color)
- [`text-decoration-line`](/en-US/docs/Web/CSS/text-decoration-line)
- [`text-decoration-style`](/en-US/docs/Web/CSS/text-decoration-style)
- [`text-decoration-thickness`](/en-US/docs/Web/CSS/text-decoration-thickness)
- [`text-shadow`](/en-US/docs/Web/CSS/text-shadow)
- [`visibility`](/en-US/docs/Web/CSS/visibility)
- [`white-space`](/en-US/docs/Web/CSS/white-space)
## Examples
### Styling WebVTT cues as white-on-black
The following CSS sets the cue style so that the text is white and the background is a translucent black box.
```css
::cue {
color: #fff;
background-color: rgb(0 0 0 / 60%);
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Web Video Tracks Format (WebVTT)](/en-US/docs/Web/API/WebVTT_API)
- {{HTMLElement("track")}}, {{HTMLElement("video")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_-moz-last-node/index.md | ---
title: ":-moz-last-node"
slug: Web/CSS/:-moz-last-node
page-type: css-pseudo-class
status:
- non-standard
---
{{Non-standard_header}}{{CSSRef}}
The **`:-moz-last-node`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) is a [Mozilla extension](/en-US/docs/Web/CSS/Mozilla_Extensions) that represents any element that is the last child node of some other element. It differs from {{cssxref(":last-child")}} because it does not match a last-child element with (non-whitespace) text after it.
> **Note:** Any whitespace at the end of an element is ignored for the determination of `:-moz-last-node`.
## Syntax
```css
:-moz-last-node {
/* ... */
}
```
## Examples
### CSS
```css
span:-moz-last-node {
background-color: lime;
}
```
### HTML
```html
<p>
<span>This does not match.</span>
<span>This matches!</span>
</p>
<p>
<span>This doesn't match because it's followed by text.</span>
Blahblah.
</p>
```
### Result
{{EmbedLiveSample("Examples")}}
## Specifications
Not part of any standard.
## See also
- {{cssxref(":-moz-first-node")}}
- {{cssxref(":last-child")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/text-decoration/index.md | ---
title: text-decoration
slug: Web/CSS/text-decoration
page-type: css-shorthand-property
browser-compat: css.properties.text-decoration
---
{{CSSRef}}
The **`text-decoration`** [shorthand](/en-US/docs/Web/CSS/Shorthand_properties) [CSS](/en-US/docs/Web/CSS) property sets the appearance of decorative lines on text. It is a shorthand for {{cssxref("text-decoration-line")}}, {{cssxref("text-decoration-color")}}, {{cssxref("text-decoration-style")}}, and the newer {{cssxref("text-decoration-thickness")}} property.
{{EmbedInteractiveExample("pages/css/text-decoration.html")}}
Text decorations are drawn across descendant text elements. This means that if an element specifies a text decoration, then a child element can't remove the decoration. For example, in the markup `<p>This text has <em>some emphasized words</em> in it.</p>`, the style rule `p { text-decoration: underline; }` would cause the entire paragraph to be underlined. The style rule `em { text-decoration: none; }` would not cause any change; the entire paragraph would still be underlined. However, the rule `em { text-decoration: overline; }` would cause a second decoration to appear on "some emphasized words".
## Constituent properties
This property is a shorthand for the following CSS properties:
- [`text-decoration-color`](/en-US/docs/Web/CSS/text-decoration-color)
- [`text-decoration-line`](/en-US/docs/Web/CSS/text-decoration-line)
- [`text-decoration-style`](/en-US/docs/Web/CSS/text-decoration-style)
- [`text-decoration-thickness`](/en-US/docs/Web/CSS/text-decoration-thickness)
## Syntax
```css
text-decoration: underline;
text-decoration: overline red;
text-decoration: none;
/* Global values */
text-decoration: inherit;
text-decoration: initial;
text-decoration: revert;
text-decoration: revert-layer;
text-decoration: unset;
```
The `text-decoration` property is specified as one or more space-separated values representing the various longhand text-decoration properties.
### Values
- {{cssxref("text-decoration-line")}}
- : Sets the kind of decoration used, such as `underline` or `line-through`.
- {{cssxref("text-decoration-color")}}
- : Sets the color of the decoration.
- {{cssxref("text-decoration-style")}}
- : Sets the style of the line used for the decoration, such as `solid`, `wavy`, or `dashed`.
- {{cssxref("text-decoration-thickness")}}
- : Sets the thickness of the line used for the decoration.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Demonstration of text-decoration values
```css
.under {
text-decoration: underline red;
}
.over {
text-decoration: wavy overline lime;
}
.line {
text-decoration: line-through;
}
.plain {
text-decoration: none;
}
.underover {
text-decoration: dashed underline overline;
}
.thick {
text-decoration: solid underline purple 4px;
}
.blink {
text-decoration: blink;
}
```
```html
<p class="under">This text has a line underneath it.</p>
<p class="over">This text has a line over it.</p>
<p class="line">This text has a line going through it.</p>
<p>
This <a class="plain" href="#">link will not be underlined</a>, as links
generally are by default. Be careful when removing the text decoration on
anchors since users often depend on the underline to denote hyperlinks.
</p>
<p class="underover">This text has lines above <em>and</em> below it.</p>
<p class="thick">
This text has a really thick purple underline in supporting browsers.
</p>
<p class="blink">
This text might blink for you, depending on the browser you use.
</p>
```
#### Result
{{EmbedLiveSample('Examples','auto','520')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- The individual text-decoration properties are {{cssxref("text-decoration-line")}}, {{cssxref("text-decoration-color")}}, {{cssxref("text-decoration-style")}}, and {{cssxref("text-decoration-thickness")}}.
- The {{cssxref("text-decoration-skip-ink")}}, {{cssxref("text-underline-offset")}}, and {{cssxref("text-underline-position")}} properties also affect text-decoration, but are not included in the shorthand.
- The {{cssxref("list-style")}} attribute controls the appearance of items in HTML {{HTMLElement("ol")}} and {{HTMLElement("ul")}} lists.
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/css_properties_and_values_api/index.md | ---
title: CSS properties and values API
slug: Web/CSS/CSS_properties_and_values_API
page-type: css-module
spec-urls: https://www.w3.org/TR/css-properties-values-api-1/
---
{{CSSRef}}
The **CSS properties and values API** module defines a method for registering new CSS properties, defining the property's data type, inheritance behavior, and, optionally, an initial value.
This API expands on [CSS custom properties for cascading variables](/en-US/docs/Web/CSS/CSS_cascading_variables) module, which allows authors to define custom properties in CSS using [two dash syntax (`--`)](/en-US/docs/Web/CSS/--*).
The CSS properties and values API is part of the [CSS Houdini](/en-US/docs/Web/CSS/CSS_Houdini) umbrella of APIs.
Custom properties let you reuse values across a project to simplify complex or repetitive stylesheets.
Basic custom properties are defined in the [CSS custom properties for cascading variables](/en-US/docs/Web/CSS/CSS_cascading_variables) module.
The CSS properties and values API expands on that module, enabling adding metadata to custom properties using CSS with the [`@property`](/en-US/docs/Web/CSS/@property) at-rule or, alternatively, using JavaScript's {{domxref('CSS/registerProperty_static', 'CSS.registerProperty')}} method.
Whether registered with CSS or JavaScript, setting metadata on custom properties provides for an expected data type that the browser can use depending on the context, defines an initial value, and lets you control inheritance.
CSS properties and values API custom property registration is more robust than the more basic CSS cascading variable custom property declaration, especially when it comes to transitioning and animating values as browsers can interpolate between custom values of this type, whereas properties that use [two dash syntax (`--`)](/en-US/docs/Web/CSS/--*) behave more like a string substitution.
## Properties and values API in action
To see how custom properties and values can be used via API, hover over the box below.
```js hidden
CSS.registerProperty({
name: "--stop-color",
syntax: "<color>",
inherits: false,
initialValue: "cornflowerblue",
});
```
```css hidden
.box {
padding: 1rem;
width: 90%;
height: 4rem;
font-family: sans-serif;
font-size: large;
color: white;
border-radius: 0.5rem;
}
.box {
background: linear-gradient(to right, var(--stop-color), lavenderblush);
transition: --stop-color 2s;
}
.box:hover {
--stop-color: aquamarine;
}
```
```html hidden
<div class="box"><p>Linear gradient with transition</p></div>
```
{{EmbedLiveSample("Properties and values API in action",600,120)}}
The box has a [backround](/en-US/docs/Web/CSS/background) consisting of a [linear gradient](/en-US/docs/Web/CSS/gradient/linear-gradient) from `--stop-color` (the custom property) to [`lavenderblush`](/en-US/docs/Web/CSS/named-color).
The value of `--stop-color` is set to `cornflowerblue` at first, but when you hover over the box, `--stop-color` [transitions](/en-US/docs/Web/CSS/transition) to `aquamarine` over two seconds (`linear-gradient(to right, aquamarine, lavenderblush)`).
## Reference
### At-rules
- {{cssxref("@property")}}
- [syntax](/en-US/docs/Web/CSS/@property#descriptors) descriptor
- [`+` and `#`](/en-US/docs/Web/CSS/@property#descriptors) multipliers
- [`|`](/en-US/docs/Web/CSS/@property#descriptors) combinator
- [inherits](/en-US/docs/Web/CSS/@property#descriptors) descriptor
- [initial-value](/en-US/docs/Web/CSS/@property#descriptors) descriptor
### Interfaces and APIs
- {{domxref('CSSPropertyRule')}}
- {{domxref('CSS/registerProperty_static', 'CSS.registerProperty()')}}
## Guides
- [Using the CSS properties and values API](/en-US/docs/Web/API/CSS_Properties_and_Values_API/guide)
- : Explains how to register custom properties in CSS and JavaScript, with hints on handling undefined and invalid values, fallbacks, and inheritance.
- [Houdini APIs](/en-US/docs/Web/API/Houdini_APIs)
- : Explains what CSS Houdini is and its advantages, along with a list of available APIs and their statuses.
## Related concepts
- {{cssxref("var")}}
- [CSSRule](/en-US/docs/Web/API/CSSRule)
- [CSSStyleValue](/en-US/docs/Web/API/CSSStyleValue)
- [CSS scoping](/en-US/docs/Web/CSS/CSS_scoping)
- [Using shadow DOM](/en-US/docs/Web/API/Web_components/Using_shadow_DOM)
- [CSS Typed Object Model API](/en-US/docs/Web/API/CSS_Typed_OM_API)
- [CSS Painting API](/en-US/docs/Web/API/CSS_Painting_API)
- [Worklet](/en-US/docs/Web/API/Worklet)
## Specifications
{{Specifications}}
## See also
- [CSS cascade and inheritance](/en-US/docs/Web/CSS/CSS_cascade)
- [CSS scoping](/en-US/docs/Web/CSS/CSS_scoping) module
- [Using shadow DOM](/en-US/docs/Web/API/Web_components/Using_shadow_DOM)
- [CSS Painting API](/en-US/docs/Web/API/CSS_Painting_API) module
- [Worklet](/en-US/docs/Web/API/Worklet) interface
- [CSS `env()`](/en-US/docs/Web/CSS/env)
- [CSS Typed Object Model](/en-US/docs/Web/API/CSS_Typed_OM_API)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/border-right/index.md | ---
title: border-right
slug: Web/CSS/border-right
page-type: css-shorthand-property
browser-compat: css.properties.border-right
---
{{CSSRef}}
The **`border-right`** [shorthand](/en-US/docs/Web/CSS/Shorthand_properties) [CSS](/en-US/docs/Web/CSS) property sets all the properties of an element's right [border](/en-US/docs/Web/CSS/border).
{{EmbedInteractiveExample("pages/css/border-right.html")}}
As with all shorthand properties, `border-right` always sets the values of all of the properties that it can set, even if they are not specified. It sets those that are not specified to their default values. Consider the following code:
```css
border-right-style: dotted;
border-right: thick green;
```
It is actually the same as this one:
```css
border-right-style: dotted;
border-right: none thick green;
```
The value of {{cssxref("border-right-style")}} given before `border-right` is ignored. Since the default value of {{cssxref("border-right-style")}} is `none`, not specifying the `border-style` part results in no border.
## Constituent properties
This property is a shorthand for the following CSS properties:
- {{cssxref("border-right-color")}}
- {{cssxref("border-right-style")}}
- {{cssxref("border-right-width")}}
## Syntax
```css
border-right: 1px;
border-right: 2px dotted;
border-right: medium dashed green;
/* Global values */
border-right: inherit;
border-right: initial;
border-right: revert;
border-right: revert-layer;
border-right: unset;
```
The three values of the shorthand property can be specified in any order, and one or two of them may be omitted.
### Values
- `<br-width>`
- : See {{cssxref("border-right-width")}}.
- `<br-style>`
- : See {{cssxref("border-right-style")}}.
- {{cssxref("<color>")}}
- : See {{cssxref("border-right-color")}}.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Applying a right border
#### HTML
```html
<div>This box has a border on the right side.</div>
```
#### CSS
```css
div {
border-right: 4px dashed blue;
background-color: gold;
height: 100px;
width: 100px;
font-weight: bold;
text-align: center;
}
```
#### Results
{{EmbedLiveSample('Applying_a_right_border')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("border")}}
- {{cssxref("border-block")}}
- {{cssxref("outline")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/cssom_view/index.md | ---
title: CSSOM view
slug: Web/CSS/CSSOM_view
page-type: css-module
browser-compat: css.properties.scroll-behavior
---
{{CSSRef}}
The **CSSOM view** module lets you manipulate the visual view of a document, in particular its scrolling behavior.
## Reference
### Properties
- {{cssxref("scroll-behavior")}}
## Guides
- [Coordinate systems](/en-US/docs/Web/CSS/CSSOM_view/Coordinate_systems)
- : A guide to the coordinate systems used to specify the position of a location in a display context, whether that context is a window on a monitor, a viewport on a mobile device, or a position on a sheet of paper when printing.
## Related concepts
- {{glossary("cssom")}} glossary term
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
| 0 |
data/mdn-content/files/en-us/web/css/cssom_view | data/mdn-content/files/en-us/web/css/cssom_view/coordinate_systems/index.md | ---
title: Coordinate systems
slug: Web/CSS/CSSOM_view/Coordinate_systems
page-type: guide
---
{{CSSRef}}
When specifying the location of a pixel in a graphics context (just like when specifying coordinate systems in [algebra](https://en.wikipedia.org/wiki/Algebra)), its position is defined relative to a fixed point in the context. This fixed point is called the [origin](<https://en.wikipedia.org/wiki/Origin_(mathematics)>). The position is specified as the number of pixels offset from the origin along each dimension of the context.
This guide describes the standard coordinate systems used by the CSS object model. These are generally only different in terms of where their origin is located.
## Dimensions
In the coordinate systems used by web technologies, convention dictates that the horizontal offset is called the _x-coordinate_, where a negative value indicates a position to the left of the origin and a positive value is to the right of the origin. The _y-coordinate_ specifies the vertical offset, with a negative value being above the origin and a positive value being below the origin.
On the web, the default origin is the _top_-left corner of a given context (with positive y-coordinate values being below the origin). Note that this is unlike most mathematical models, where the origin is at the _bottom_-left corner, with positive y-coordinate values being above the origin.
When using the third dimension to layer objects from front to back, we use the z-axis. The z-axis runs from the viewer to the screen's surface. The CSS z-index attribute affects where positioned elements sit on this axis, giving the effect of moving away from or toward the viewer.
> **Note:** It's actually possible to change the definitions and orientations of these coordinate systems using CSS properties such as {{cssxref("transform")}}. However, we'll only talk about the standard coordinate system for now.
## Standard CSSOM coordinate systems
There are four standard coordinate systems used by the CSS object model.
To help visualize the main systems, the following diagram shows a monitor with a browser window that contains content scrolled outside of the viewport.
Page content that is scrolled outside of the viewport is shown as semi-transparent above the browser window to indicate where the origin for "page" coordinates would be.
The origin of the "client", "page", and "viewport" coordinates systems are highlighted.

### Offset
Coordinates specified using the "offset" model use the top-left corner of the element being examined, or on which an event has occurred.
For example, when a {{domxref("MouseEvent", "mouse event", "", 1)}} occurs, the position of the mouse as specified in the event's {{domxref("MouseEvent.offsetX", "offsetX")}} and {{domxref("MouseEvent.offsetY", "offsetY")}} properties are given relative to the top-left corner of the node to which the event has been delivered. The origin is inset by the distances specified by {{cssxref("padding-left")}} and {{cssxref("padding-top")}}.
### Viewport
The "viewport" (or "client") coordinate system uses as its origin the top-left corner of the viewport or browsing context in which the event occurred. This is the entire viewing area in which the document is presented.
On a desktop computer, for example, the {{domxref("MouseEvent.clientX")}} and {{domxref("MouseEvent.clientY")}} properties indicate the position of the mouse cursor at the moment the event occurred, relative to the top-left corner of the {{domxref("window")}}.
When using a stylus or a pointer, the {{domxref("Touch.clientX")}} and {{domxref("Touch.clientY")}} coordinates in a {{domxref("TouchEvent", "touch event")}} are relative to the same origin.
The top-left corner of the window is always (0, 0), regardless of the content of the document or any scrolling that may have been done. In other words, scrolling the document will change the viewport coordinates of a given position within the document.
### Page
The "page" coordinate system gives the position of a pixel relative to the top-left corner of the entire rendered {{domxref("Document")}}.
That means that a point in an element within the document will have the same coordinates after the user scrolls horizontally or vertically in the document unless the element moves via layout changes.
Mouse events' {{domxref("MouseEvent.pageX", "pageX")}} and {{domxref("MouseEvent.pageY", "pageY")}} properties provide the position of the mouse at the time the event was generated, given relative to the top-left corner of the document.
{{domxref("Touch.pageX")}} and {{domxref("Touch.pageY")}} coordinates in a {{domxref("TouchEvent", "touch event")}} are relative to the same origin.
### Screen
Finally, we come to the "screen" model where the origin is the top-left corner of the user's screen space.
Each point in this coordinate system represents a single logical pixel, and so values increment and decrement by integer values along each axis.
The position of a given point within a document will change if the containing window is moved, for example, or if the user's screen geometry changes (by changing display resolution or by adding or removing monitors to their system).
The {{domxref("MouseEvent.screenX")}} and {{domxref("MouseEvent.screenY")}} properties give the coordinates of a mouse event's position relative to the screen's origin.
{{domxref("Touch.screenX")}} and {{domxref("Touch.screenY")}} coordinates in a {{domxref("TouchEvent", "touch event")}} are relative to the same origin.
## Example
Let's take a look at an example that logs mouse coordinates in an element.
Whenever the mouse enters, moves around inside, or exits the inner box, the events are handled by logging the current mouse coordinates in each of the four available systems.
### JavaScript
For the JavaScript, the code sets up the event handlers on the inner box by calling {{domxref("EventTarget.addEventListener", "addEventListener()")}} for each of the types {{domxref("Element/mouseenter_event", "mouseenter")}}, {{domxref("Element/mousemove_event", "mousemove")}}, and {{domxref("Element/mouseleave_event", "mouseleave")}}.
For each of the events, we're calling the `setCoords()` function which sets the inner text of the `<p>` element with the coordinates for each system.
```js
const log = document.querySelector(".log");
const inner = document.querySelector(".inner");
function setCoords(e) {
log.innerText = `
Offset X/Y: ${e.offsetX}, ${e.offsetY}
Viewport X/Y: ${e.clientX}, ${e.clientY}
Page X/Y: ${e.pageX}, ${e.pageY}
Screen X/Y: ${e.screenX}, ${e.screenY}`;
}
inner.addEventListener("mousemove", setCoords);
inner.addEventListener("mouseenter", setCoords);
inner.addEventListener("mouseleave", setCoords);
```
### HTML
The HTML contains a `<p>` with the `"log"` class, which displays the data from the mouse events.
```html
<div class="outer">
<div class="inner">
<p class="log">Mouse over this section to view coordinates</p>
</div>
</div>
```
### CSS
The class `"outer"` for the containing box is intentionally too wide to view the effects of mouse coordinates when the content is scrolled.
The `"inner"` paragraph is where mouse events are tracked and logged.
```css
.outer {
width: 1000px;
}
.inner {
font-family: monospace;
position: relative;
width: 500px;
height: 150px;
top: 25px;
left: 100px;
background-color: darkblue;
color: white;
cursor: crosshair;
user-select: none;
}
.log {
position: relative;
width: 100%;
text-align: center;
}
```
### Result
Here you can see the results in action. As you mouse in and around the blue box, watch the values of the mouse's X and Y coordinates change in the various coordinate systems.
{{EmbedLiveSample("Example", 600, 250)}}
## See also
- [Using CSS transforms](/en-US/docs/Web/CSS/CSS_transforms/Using_CSS_transforms): how to alter a coordinate system
- Coordinates of a {{domxref("MouseEvent", "Mouse event")}}:
- {{domxref("MouseEvent.offsetX")}} and {{domxref("MouseEvent.offsetY")}}
- {{domxref("MouseEvent.clientX")}} and {{domxref("MouseEvent.clientY")}}
- {{domxref("MouseEvent.pageX")}} and {{domxref("MouseEvent.pageY")}}
- {{domxref("MouseEvent.screenX")}} and {{domxref("MouseEvent.screenY")}}
- Coordinates of a {{domxref("Touch", "Touch event")}}:
- {{domxref("Touch.clientX")}} and {{domxref("Touch.clientY")}}
- {{domxref("Touch.pageX")}} and {{domxref("Touch.pageY")}}
- {{domxref("Touch.screenX")}} and {{domxref("Touch.screenY")}}
| 0 |
data/mdn-content/files/en-us/web/css/cssom_view | data/mdn-content/files/en-us/web/css/cssom_view/coordinate_systems/css-coords.svg | <svg height="1104.573" stroke-miterlimit="10" style="fill-rule:nonzero;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round" viewBox="0 0 1539.99 828.533" width="2053.061" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h1539.99v828.533H0V0Z" fill="#fff"/><path d="M319.832 160h884.338c9.85 0 17.83 7.841 17.83 17.513v484.974c0 9.672-7.98 17.513-17.83 17.513H319.832c-9.848 0-17.832-7.841-17.832-17.513V177.513c0-9.672 7.984-17.513 17.832-17.513Z" fill="#ddd"/><path d="M322 180h880v478.543H322V180Z" fill="#a4b2da"/><text font-family="Helvetica" font-size="33" transform="translate(20 158.294)">
<tspan textLength="185.238" x="34.762" y="32">screen (0, 0)</tspan>
</text><path d="M942 380H382.047V260H942" fill="#7f19fd" fill-opacity=".5"/><path d="M373.629 380h576.742c6.422 0 11.629 3.92 11.629 8.756v242.488c0 4.836-5.207 8.756-11.629 8.756H373.629c-6.422 0-11.629-3.92-11.629-8.756V388.756c0-4.836 5.207-8.756 11.629-8.756Z" fill="#ddd"/><path d="M376.795 402.088a7.087 7.087 0 1 1 14.175-.001 7.087 7.087 0 0 1-14.175.001Z" fill="#e94420"/><path d="M402.31 402.088a7.087 7.087 0 1 1 14.175-.001 7.087 7.087 0 0 1-14.175.001Z" fill="#ef9f46"/><path d="M427.825 402.088a7.087 7.087 0 1 1 14.175-.001 7.087 7.087 0 0 1-14.175.001Z" fill="#68c40c"/><path d="M942 620H382.047V420H942" fill="#7f19fd"/><path d="M502 340h400v40H502v-40Z" fill="#dafcef" fill-opacity=".5"/><path d="M502 420h400v40H502v-40Z" fill="#dafcef" fill-opacity=".9"/><path d="M320.935 166.65V195m-14.175-14.175H335" fill="none" stroke="#000" stroke-dasharray="2" stroke-linecap="butt" stroke-width="2"/><path d="M310.993 180.825H242" fill="none" stroke="#000" stroke-linecap="butt" stroke-width="2"/><path d="m307.993 187.825 12-7-12-7v14Z"/><text font-family="Helvetica" font-size="33" transform="translate(20 235.294)">
<tspan textLength="159.602" x="60.398" y="32">page (0, 0)</tspan>
</text><text font-family="Helvetica" font-size="33" transform="translate(1262 280)">
<tspan textLength="203.656" x="0" y="32">Page content </tspan>
<tspan textLength="275.15" x="0" y="72">scrolled outside of </tspan>
<tspan textLength="177.923" x="0" y="112">the viewport</tspan>
</text><path d="M380.582 243v33.35M362 259.675h37.019" fill="none" stroke="#000" stroke-dasharray="2" stroke-linecap="butt" stroke-width="2"/><path d="M370.994 260H242" fill="none" stroke="#000" stroke-linecap="butt" stroke-width="2"/><path d="m367.994 267 12-7-12-7v14Z"/><text font-family="Helvetica" font-size="33" transform="translate(21 395.587)">
<tspan textLength="209.07" x="10.93" y="32">viewport (0, 0)</tspan>
</text><path d="M381.935 406v28.35M1002 260v120m-634.24 40.175H396M982 260h20m-20 120h20m0-60h240" fill="none" stroke="#000" stroke-dasharray="2" stroke-linecap="butt" stroke-width="2"/><path d="M370.994 420.175H242" fill="none" stroke="#000" stroke-linecap="butt" stroke-width="2"/><path d="m367.994 427.175 12-7-12-7v14Z"/></svg> | 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/-webkit-mask-composite/index.md | ---
title: "-webkit-mask-composite"
slug: Web/CSS/-webkit-mask-composite
page-type: css-property
status:
- non-standard
browser-compat: css.properties.-webkit-mask-composite
---
{{CSSRef}}{{Non-standard_header}}
The **`-webkit-mask-composite`** property specifies the manner in which multiple mask images applied to the same element are composited with one another. Mask images are composited in the opposite order that they are declared with the {{CSSxRef("mask-image", "-webkit-mask-image")}} property.
> **Note:** There is a standardized {{CSSxRef("mask-composite")}} property covering parts of this non-standard property using different keywords.
## Syntax
```css
/* Keyword values */
-webkit-mask-composite: clear;
-webkit-mask-composite: copy;
-webkit-mask-composite: source-over;
-webkit-mask-composite: source-in;
-webkit-mask-composite: source-out;
-webkit-mask-composite: source-atop;
-webkit-mask-composite: destination-over;
-webkit-mask-composite: destination-in;
-webkit-mask-composite: destination-out;
-webkit-mask-composite: destination-atop;
-webkit-mask-composite: xor;
/* Global values */
-webkit-mask-composite: inherit;
-webkit-mask-composite: initial;
-webkit-mask-composite: revert;
-webkit-mask-composite: revert-layer;
-webkit-mask-composite: unset;
```
### Values
- `clear`
- : Overlapping pixels in the source mask image and the destination mask image are cleared.
- `copy`
- : The source mask image replaces the destination mask image.
- `source-over`
- : The source mask image is rendered over the destination mask image.
- `source-in`
- : Overlapping pixels in the source mask image and the destination mask image are replaced by the pixels of the source mask image; all other pixels are cleared.
- `source-out`
- : Overlapping pixels in the source mask image and the destination mask image are cleared; all remaining pixels of the source mask image are rendered.
- `source-atop`
- : The pixels of the destination mask image are rendered. The pixels of the source mask image are rendered only if they overlap a nontransparent portion of the destination mask image. This causes the source mask image to have no effect.
- `destination-over`
- : The destination mask image is rendered over the source mask image.
- `destination-in`
- : Overlapping pixels in the source mask image and the destination mask image remain the pixels of the destination mask image; all other pixels are cleared.
- `destination-out`
- : Overlapping pixels in the source mask image and the destination mask image are cleared; all remaining pixels of the source mask image are rendered.
- `destination-atop`
- : The pixels of the source mask image are rendered. The pixels of the destination mask image are rendered only if they overlap a nontransparent portion of the destination mask image. This causes the destination mask image to have no effect.
- `xor`
- : Overlapping pixels in the source mask image and the destination mask image become fully transparent if they are both fully opaque.
## Formal definition
{{CSSInfo}}
## Formal syntax
```plain
-webkit-mask-composite =
<composite-style>#
```
## Examples
### Compositing with XOR
```css
.example {
-webkit-mask-image: url(mask1.png), url("mask2.png");
-webkit-mask-composite: xor, source-over;
}
```
## Specifications
Not part of any standard. This property is specified as {{CSSxRef("mask-composite")}} using different values.
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef("mask-composite")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/rem/index.md | ---
title: rem()
slug: Web/CSS/rem
page-type: css-function
browser-compat: css.types.rem
---
{{CSSRef}}
The **`rem()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) returns a remainder 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 remainder is the value left over when one operand, the dividend, is divided by a second operand, the divisor. It always takes the sign of the dividend.
> For example, the CSS `rem(27, 5)` function returns the remainder of `2`. When dividing 27 by 5, the result is 5 with a remainder of 2. The full calculation is `27 / 5 = 5 * 5 + 2`.
## Syntax
```css
/* Unitless <number> */
line-height: rem(21, 2); /* 1 */
line-height: rem(14, 5); /* 4 */
line-height: rem(5.5, 2); /* 1.5 */
/* Unit based <percentage> and <dimension> */
margin: rem(14%, 3%); /* 2% */
margin: rem(18px, 5px); /* 3px */
margin: rem(10rem, 6rem); /* 4rem */
margin: rem(26vmin, 7vmin); /* 5vmin */
margin: rem(1000px, 29rem); /* 72px - if root font-size is 16px */
/* Negative/positive values */
rotate: rem(200deg, 30deg); /* 20deg */
rotate: rem(140deg, -90deg); /* 50deg */
rotate: rem(-90deg, 20deg); /* -10deg */
rotate: rem(-55deg, -15deg); /* -10deg */
/* Calculations */
scale: rem(10 * 2, 1.7); /* 1.3 */
rotate: rem(10turn, 18turn / 3); /* 4turn */
transition-duration: rem(20s / 2, 3000ms * 2); /* 4s */
```
### Parameter
The `rem(dividend, divisor)` function accepts two comma-separated values as its parameters. Both parameters must have the same type, [number](/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 remainder, that is, the operation left over.
- If `divisor` is `0`, the result is `NaN`.
- If `dividend` is `infinite`, the result is `NaN`.
- If `dividend` is positive the result is positive (`0βΊ`), and if `dividend` is negative the result is negative (`0β»`).
### Formal syntax
{{CSSSyntax}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef("round")}}
- {{CSSxRef("mod")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/-moz-float-edge/index.md | ---
title: "-moz-float-edge"
slug: Web/CSS/-moz-float-edge
page-type: css-property
status:
- deprecated
- non-standard
browser-compat: css.properties.-moz-float-edge
---
{{CSSRef}}{{Non-standard_header}}{{Deprecated_Header}}
The non-standard **`-moz-float-edge`** [CSS](/en-US/docs/Web/CSS) property specifies whether the height and width properties of the element include the margin, border, or padding thickness.
## Syntax
```css
/* Keyword values */
-moz-float-edge: content-box;
-moz-float-edge: margin-box;
/* Global values */
-moz-float-edge: inherit;
-moz-float-edge: initial;
-moz-float-edge: unset;
```
### Values
- `content-box`
- : The height and width properties include the content, but not the padding, border or margin.
- `margin-box`
- : The height and width properties include the content, padding, border and margin.
## Formal definition
{{CSSInfo}}
## Formal syntax
```plain
-moz-float-edge =
content-box | margin-box
```
## Examples
### HTML
```html
<div class="box">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
```
### CSS
```css
.box {
display: block;
height: 5px;
margin: 0.5em auto 0.5em auto;
color: gray;
-moz-float-edge: margin-box;
box-sizing: border-box;
}
```
### Result
{{ EmbedLiveSample('Examples') }}
## Specifications
Not part of any standard.
## Browser compatibility
{{Compat}}
## See also
- [Firefox bug 432891](https://bugzil.la/432891)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_-moz-user-disabled/index.md | ---
title: ":-moz-user-disabled"
slug: Web/CSS/:-moz-user-disabled
page-type: css-pseudo-class
status:
- non-standard
---
{{CSSRef}}{{Non-standard_header}}
The **`:-moz-user-disabled`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) is a [Mozilla extension](/en-US/docs/Web/CSS/Mozilla_Extensions) that matches elements representing images that were not loaded because images have been entirely disabled by the user's preferences.
> **Note:** This selector is mainly intended to be used by theme developers.
## Syntax
```css
:-moz-user-disabled {
/* ... */
}
```
## Examples
### Styling user-disabled elements
```css
:-moz-user-disabled {
background-color: lightgray;
padding: 8px;
}
```
## Specifications
Not part of any standard.
## See also
- {{cssxref(":-moz-broken")}}, {{cssxref(":-moz-loading")}}, {{cssxref(":-moz-suppressed")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/shape/index.md | ---
title: <shape>
slug: Web/CSS/shape
page-type: css-type
status:
- deprecated
browser-compat: css.types.shape
---
{{CSSRef}}{{deprecated_header}}
The **`<shape>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) defines the specific form (shape) of a region. The region represents the part of an element to which the {{cssxref("clip")}} property applies.
> **Note:** `<shape>` and `rect()` work in conjunction with {{cssxref("clip")}}, which has been deprecated in favor of {{cssxref("clip-path")}}. When possible, use `clip-path` and the {{cssxref("<basic-shape>")}} data type instead.
## Syntax
The `<shape>` data type is specified using the `rect()` function, which produces a region in the form of a rectangle.
`rect()`
```css
rect(top, right, bottom, left)
```
### Values

- _top_
- : Is a {{cssxref("length")}} representing the offset for the top of the rectangle relative to the top border of the element's box.
- _right_
- : Is a {{cssxref("length")}} representing the offset for the right of the rectangle relative to the left border of the element's box.
- _bottom_
- : Is a {{cssxref("length")}} representing the offset for the bottom of the rectangle relative to the top border of the element's box.
- _left_
- : Is a {{cssxref("length")}} representing the offset for the left of the rectangle relative to the left border of the element's box.
## Interpolation
When animated, values of the `<shape>` data type are interpolated over their `top`, `right`, `bottom`, and `left` components, each treated as a real, floating-point number. The speed of the interpolation is determined by the [easing function](/en-US/docs/Web/CSS/easing-function) associated with the animation.
## Example
### Example demonstrating correct use of the rect() function
```css
img.clip04 {
clip: rect(10px, 20px, 20px, 10px);
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- Related CSS property: {{ cssxref("clip") }}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/angle/index.md | ---
title: <angle>
slug: Web/CSS/angle
page-type: css-type
browser-compat: css.types.angle
---
{{CSSRef}}
The **`<angle>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) represents an angle value expressed in degrees, gradians, radians, or turns. It is used, for example, in {{cssxref("<gradient>")}}s and in some {{cssxref("transform")}} functions.
{{EmbedInteractiveExample("pages/css/type-angle.html")}}
## Syntax
The `<angle>` data type consists of a {{cssxref("<number>")}} followed by one of the units listed below. As with all dimensions, there is no space between the unit literal and the number. The angle unit is optional after the number `0`.
Optionally, it may be preceded by a single `+` or `-` sign. Positive numbers represent clockwise angles, while negative numbers represent counterclockwise angles. For static properties of a given unit, any angle can be represented by various equivalent values. For example, `90deg` equals `-270deg`, and `1turn` equals `4turn`. For dynamic properties, like when applying an {{cssxref("animation")}} or {{cssxref("transition")}}, the effect will nevertheless be different.
### Units
- `deg`
- : Represents an angle in [degrees](https://en.wikipedia.org/wiki/Degree_%28angle%29). One full circle is `360deg`. Examples: `0deg`, `90deg`, `14.23deg`.
- `grad`
- : Represents an angle in [gradians](https://en.wikipedia.org/wiki/Gradian). One full circle is `400grad`. Examples: `0grad`, `100grad`, `38.8grad`.
- `rad`
- : Represents an angle in [radians](https://en.wikipedia.org/wiki/Radian). One full circle is 2Ο radians which approximates to `6.2832rad`. `1rad` is 180/Ο degrees. Examples: `0rad`, `1.0708rad`, `6.2832rad`.
- `turn`
- : Represents an angle in a number of turns. One full circle is `1turn`. Examples: `0turn`, `0.25turn`, `1.2turn`.
## Examples
### Setting a clockwise right angle
<table class="standard-table">
<tbody>
<tr>
<td><img class="default internal" src="angle90.png" alt="A diagram showing a clockwise 90-degree rotation along a circle by moving from the topmost point to the rightmost point." /></td>
<td><code>90deg = 100grad = 0.25turn β 1.5708rad</code></td>
</tr>
</tbody>
</table>
### Setting a flat angle
<table class="standard-table">
<tbody>
<tr>
<td><img class="default internal" src="angle180.png" alt="A diagram showing a clockwise 180-degree rotation along a circle by moving from the topmost point to the bottommost point." /></td>
<td><code>180deg = 200grad = 0.5turn β 3.1416rad</code></td>
</tr>
</tbody>
</table>
### Setting a counterclockwise right angle
<table class="standard-table">
<tbody>
<tr>
<td><img class="default internal" src="angleminus90.png" alt="A diagram showing a counterclockwise 90-degree rotation along a circle by moving from the topmost point to the leftmost point." /></td>
<td><code>-90deg = -100grad = -0.25turn β -1.5708rad</code></td>
</tr>
</tbody>
</table>
### Setting a null angle
<table class="standard-table">
<tbody>
<tr>
<td><img class="default internal" src="angle0.png" alt="A diagram showing a 0-degree rotation. There is no movement." /></td>
<td><code>0 = 0deg = 0grad = 0turn = 0rad</code></td>
</tr>
</tbody>
</table>
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [CSS data types](/en-US/docs/Web/CSS/CSS_Types)
- The [`<gradient>`](/en-US/docs/Web/CSS/gradient) type
- CSS rotation transforms: [`rotate()`](/en-US/docs/Web/CSS/transform-function/rotate), [`rotate3d()`](/en-US/docs/Web/CSS/transform-function/rotate3d), [`rotateX()`](/en-US/docs/Web/CSS/transform-function/rotateX), [`rotateY()`](/en-US/docs/Web/CSS/transform-function/rotateY), and [`rotateZ()`](/en-US/docs/Web/CSS/transform-function/rotateZ)
- [CSS transforms](/en-US/docs/Web/CSS/CSS_transforms)
- [Using CSS transforms](/en-US/docs/Web/CSS/CSS_transforms/Using_CSS_transforms)
- [Using CSS gradients](/en-US/docs/Web/CSS/CSS_images/Using_CSS_gradients)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/hypot/index.md | ---
title: hypot()
slug: Web/CSS/hypot
page-type: css-function
browser-compat: css.types.hypot
---
{{CSSRef}}
The **`hypot()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) is an exponential function that returns the [square root](https://en.wikipedia.org/wiki/Square_root) of the sum of squares of its parameters.
While {{CSSxRef("pow")}} and {{CSSxRef("sqrt")}} only work on unitless numbers, `hypot()` accepts values with units, but they all must have the same [type](/en-US/docs/Web/CSS/CSS_Types).
## Syntax
```css
/* A <number> value */
width: hypot(2em); /* 2em */
width: hypot(3em, 4em); /* 5em */
width: hypot(30px, 40px); /* 50px */
width: hypot(48px, 64px); /* 80px */
width: hypot(3px, 4px, 5px); /* 7.0710678118654755px */
```
### Parameters
The `hypot(x [, ...]#)` function accepts one or more comma-separated calculations as its parameters.
- `x`, `x2`, ..., `xN`
- : A calculation that resolves to a {{CSSxRef("<number>")}}, {{CSSxRef("<dimension>")}}, or {{CSSxRef("<percentage>")}}.
### Return value
Returns a {{CSSxRef("<number>")}}, {{CSSxRef("<dimension>")}}, or {{CSSxRef("<percentage>")}} (based on the inputs), which is the square root of the sum of squares of its parameters.
- If any of the inputs is `infinite`, the result is `+β`.
- If a single parameter is provided, the result is the absolute value of its input. `hypot(2em)` and `hypot(-2em)` both resolve to `2em`.
### Formal syntax
{{CSSSyntax}}
## Examples
### Sizes based on hypot function
This example shows how you can use the `hypot()` function to calculate sizes.
#### HTML
```html
<div class="boxes">
<div class="box">100px</div>
<div class="box one">100px</div>
<div class="box two">141.42px</div>
<div class="box three">250px</div>
</div>
```
#### CSS
Here we are using [CSS custom properties](/en-US/docs/Web/CSS/Using_CSS_custom_properties) to define the sizes to be used. First we declare the first size (`--size-0`) which is then used to calculate the other sizes.
- `--size-1` is calculated with the hypotenuse of `--size-0` (100px). This takes the square value and, as there is no other value, returns the square root of the value, which results in 100px.
- `--size-2` is calculated with the hypotenuse of `--size-0` (100px), twice. This takes the square of the value (100px \* 100px = 10000px<sup>2</sup>) and adds it to the square of `--size-0` again (10000px<sup>2</sup> + 10000px<sup>2</sup> = 20000px<sup>2</sup>) and returns the square root of the sum (β(20000px<sup>2</sup>)), which results in 141.42px.
- `--size-3` is calculated with the hypotenuse `--size-0` \* 1.5 (150px) and `--size-0` \* 2 (200px). The result is the square root of the sum of their squares: The values are squared (22500px<sup>2</sup> and 40000px<sup>2</sup>) and added together (62500px<sup>2</sup>), with the sum square-rooted (β(62500px<sup>2</sup>)) being 250px.
```css
:root {
--size-0: 100px;
--size-1: hypot(var(--size-0)); /* 100px */
--size-2: hypot(var(--size-0), var(--size-0)); /* 141.42px */
--size-3: hypot(
calc(var(--size-0) * 1.5),
calc(var(--size-0) * 2)
); /* 250px */
}
```
```css hidden
.boxes {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}
.box {
width: var(--size-0);
height: var(--size-0);
background-color: tomato;
color: white;
display: flex;
align-items: center;
justify-content: center;
}
```
The sizes are then applied as the `width` and `height` values of the selectors.
```css
.one {
width: var(--size-1);
height: var(--size-1);
}
.two {
width: var(--size-2);
height: var(--size-2);
}
.three {
width: var(--size-3);
height: var(--size-3);
}
```
#### Result
{{EmbedLiveSample('Sizes based on hypot function', '100%', '270px')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef("pow")}}
- {{CSSxRef("sqrt")}}
- {{CSSxRef("log")}}
- {{CSSxRef("exp")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/display-box/index.md | ---
title: <display-box>
slug: Web/CSS/display-box
page-type: css-type
browser-compat: css.properties.display.contents
---
{{CSSRef}}
These keywords define whether an element generates display boxes at all.
## Syntax
Valid `<display-box>` values:
- `contents`
- : These elements don't produce a specific box by themselves. They are replaced by their pseudo-box and their child boxes. Please note that the CSS Display Level 3 spec defines how the `contents` value should affect "unusual elements" β elements that aren't rendered purely by CSS box concepts such as replaced elements. See [Appendix B: Effects of display: contents on Unusual Elements](https://drafts.csswg.org/css-display/#unbox) for more details.
_Due to a bug in browsers this will currently remove the element from the accessibility tree β screen readers will not look at what's inside. See the [Accessibility concerns](#accessibility_concerns) section below for more details._
- `none`
- : Turns off the display of an element so that it has no effect on layout (the document is rendered as though the element did not exist). All descendant elements also have their display turned off.
To have an element take up the space that it would normally take, but without actually rendering anything, use the {{CSSxRef("visibility")}} property instead.
## Accessibility concerns
Current implementations in most 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`. This will cause the element β and in some browser versions, its descendant elements β to no longer be announced by screen reading technology. This is incorrect behavior according to the [CSSWG specification](https://drafts.csswg.org/css-display/#the-display-properties).
- [More accessible markup with display: contents | Hidde de Vries](https://hidde.blog/more-accessible-markup-with-display-contents/)
- [Display: Contents Is Not a CSS Reset | Adrian Roselli](https://adrianroselli.com/2018/05/display-contents-is-not-a-css-reset.html)
## Formal syntax
{{csssyntax}}
## Examples
In this first example, the paragraph with a class of secret is set to `display: none`; the box and any content is now not rendered.
### display: none
#### HTML
```html
<p>Visible text</p>
<p class="secret">Invisible text</p>
```
#### CSS
```css
p.secret {
display: none;
}
```
#### Result
{{EmbedLiveSample("display_none", "100%", 60)}}
### display: contents
In this example the outer {{htmlelement("div")}} has a 2-pixel red border and a width of 300px. However it also has `display: contents` specified therefore this `<div>` will not be rendered, the border and width will no longer apply, and the child element will be displayed as if the parent had never existed.
#### HTML
```html
<div class="outer">
<div>Inner div.</div>
</div>
```
#### CSS
```css
.outer {
border: 2px solid red;
width: 300px;
display: contents;
}
.outer > div {
border: 1px solid green;
}
```
#### Result
{{EmbedLiveSample("display_contents", 300, 60)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef("display")}}
- {{CSSxRef("<display-outside>")}}
- {{CSSxRef("<display-inside>")}}
- {{CSSxRef("<display-listitem>")}}
- {{CSSxRef("<display-internal>")}}
- {{CSSxRef("<display-legacy>")}}
- [Display: Contents Is Not a CSS Reset | Adrian Roselli](https://adrianroselli.com/2018/05/display-contents-is-not-a-css-reset.html)
- [More accessible markup with display: contents β hiddedevries.nl](https://hidde.blog/more-accessible-markup-with-display-contents/)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/text-justify/index.md | ---
title: text-justify
slug: Web/CSS/text-justify
page-type: css-property
browser-compat: css.properties.text-justify
---
{{CSSRef}}
The **`text-justify`** CSS property sets what type of justification should be applied to text when {{cssxref("text-align")}}`: justify;` is set on an element.
## Syntax
```css
text-justify: none;
text-justify: auto;
text-justify: inter-word;
text-justify: inter-character;
text-justify: distribute; /* Deprecated value */
/* Global values */
text-justify: inherit;
text-justify: initial;
text-justify: revert;
text-justify: revert-layer;
text-justify: unset;
```
### Values
- `none`
- : The text justification is turned off. This has the same effect as not setting {{cssxref("text-align")}} at all, although it is useful if you need to turn justification on and off for some reason.
- `auto`
- : The browser chooses the best type of justification for the current situation based on a balance between performance and quality, but also on what is most appropriate for the language of the text (e.g., English, CJK languages, etc.). This is the default justification used if `text-justify` is not set at all.
- `inter-word`
- : The text is justified by adding space between words (effectively varying {{cssxref("word-spacing")}}), which is most appropriate for languages that separate words using spaces, like English or Korean.
- `inter-character`
- : The text is justified by adding space between characters (effectively varying {{cssxref("letter-spacing")}}), which is most appropriate for languages like Japanese.
- `distribute` {{deprecated_inline}}
- : Exhibits the same behavior as `inter-character`; this value is kept for backwards compatibility.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Demonstration of the different values of text-justify
```html hidden
<p class="none">
<code>text-justify: none</code> β<br />Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Nunc ornare maximus vehicula. Duis nisi velit, dictum id
mauris vitae, lobortis pretium quam. Quisque sed nisi pulvinar, consequat
justo id, feugiat leo. Cras eu elementum dui.
</p>
<p class="auto">
<code>text-justify: auto</code> β<br />Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Nunc ornare maximus vehicula. Duis nisi velit, dictum id
mauris vitae, lobortis pretium quam. Quisque sed nisi pulvinar, consequat
justo id, feugiat leo. Cras eu elementum dui.
</p>
<p class="dist">
<code>text-justify: distribute</code> β<br />Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nunc ornare maximus vehicula. Duis nisi velit,
dictum id mauris vitae, lobortis pretium quam. Quisque sed nisi pulvinar,
consequat justo id, feugiat leo. Cras eu elementum dui.
</p>
<p class="word">
<code>text-justify: inter-word</code> β<br />Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nunc ornare maximus vehicula. Duis nisi velit,
dictum id mauris vitae, lobortis pretium quam. Quisque sed nisi pulvinar,
consequat justo id, feugiat leo. Cras eu elementum dui.
</p>
<p class="char">
<code>text-justify: inter-character</code> β<br />Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nunc ornare maximus vehicula. Duis nisi velit,
dictum id mauris vitae, lobortis pretium quam. Quisque sed nisi pulvinar,
consequat justo id, feugiat leo. Cras eu elementum dui.
</p>
```
```css
p {
font-size: 1.5em;
border: 1px solid black;
padding: 10px;
width: 95%;
margin: 10px auto;
text-align: justify;
}
.none {
text-justify: none;
}
.auto {
text-justify: auto;
}
.dist {
text-justify: distribute;
}
.word {
text-justify: inter-word;
}
.char {
text-justify: inter-character;
}
```
{{EmbedLiveSample("Examples","100%",400)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("text-align")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/alpha-value/index.md | ---
title: <alpha-value>
slug: Web/CSS/alpha-value
page-type: css-type
spec-urls: https://drafts.csswg.org/css-color/#typedef-color-alpha-value
---
{{CSSRef}}
The **`<alpha-value>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) represents a value that can be either a {{cssxref("<number>")}} or a {{cssxref("<percentage>")}}, specifying the **{{Glossary("alpha", "alpha channel")}}** or **transparency** of a color.
## Syntax
The value of an `<alpha-value>` is given as either a [`<number>`](/en-US/docs/Web/CSS/number) or a {{cssxref("percentage")}}.
If given as a number, the useful range is 0 (fully transparent) to 1.0 (fully opaque), with decimal values in between; that is, 0.5 indicates that half of the foreground color is used and half of the background color is used. Values outside the range of 0 to 1 are permitted, but are [clamped](<https://en.wikipedia.org/wiki/Clamping_(graphics)>) to lie within the range 0 to 1.
If the alpha value is given as a percentage, 0% corresponds to fully transparent while 100% indicates fully opaque.
## Formal syntax
{{csssyntax}}
## Interpolation
When animated, values of the `<alpha-value>` CSS data type are {{Glossary("interpolation", "interpolated")}} as real, floating-point numbers. The speed of the interpolation is determined by the [easing function](/en-US/docs/Web/CSS/easing-function) associated with the animation.
## Examples
### Setting text color opacity
The [`rgb()`](/en-US/docs/Web/CSS/color_value/rgb) function accepts a fourth optional value to specify an alpha value.
The following example shows how to apply a color with 60% opacity using the alpha value:
```css
/* <rgb()> */
color: rgb(34 12 64 / 60%);
```
### Setting shape image threshold
Here an alpha value is used to determine which parts of an image are considered part of a shape:
```css
/* shape-image-threshold */
shape-image-threshold: 70%;
shape-image-threshold: 0.7;
```
## Specifications
{{Specifications}}
## See also
- [Fundamental text and font styling](/en-US/docs/Learn/CSS/Styling_text/Fundamentals)
- [CSS data types](/en-US/docs/Web/CSS/CSS_Types)
- [CSS Color](/en-US/docs/Web/CSS/CSS_colors)
- [`<color>`](/en-US/docs/Web/CSS/color_value)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/box-shadow/index.md | ---
title: box-shadow
slug: Web/CSS/box-shadow
page-type: css-property
browser-compat: css.properties.box-shadow
---
{{CSSRef}}
The **`box-shadow`** [CSS](/en-US/docs/Web/CSS) property adds shadow effects around an element's frame. You can set multiple effects separated by commas. A box shadow is described by X and Y offsets relative to the element, blur and spread radius, and color.
{{EmbedInteractiveExample("pages/css/box-shadow.html")}}
The `box-shadow` property enables you to cast a drop shadow from the frame of almost any element. If a {{cssxref("border-radius")}} is specified on the element with a box shadow, the box shadow takes on the same rounded corners. The z-ordering of multiple box shadows is the same as multiple [text shadows](/en-US/docs/Web/CSS/text-shadow) (the first specified shadow is on top).
[Box-shadow generator](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders/Box-shadow_generator) is an interactive tool allowing you to generate a `box-shadow`.
## Syntax
```css
/* Keyword values */
box-shadow: none;
/* A color and two length values */
/* <color> | <length> | <length> */
box-shadow: red 60px -16px;
/* Three length values and a color */
/* <length> | <length> | <length> | <color> */
box-shadow: 10px 5px 5px black;
/* Four length values and a color */
/* <length> | <length> | <length> | <length> | <color> */
box-shadow: 2px 2px 2px 1px rgb(0 0 0 / 20%);
/* inset, length values, and a color */
/* <inset> | <length> | <length> | <color> */
box-shadow: inset 5em 1em gold;
/* Any number of shadows, separated by commas */
box-shadow:
3px 3px red inset,
-1em 0 0.4em olive;
/* Global values */
box-shadow: inherit;
box-shadow: initial;
box-shadow: revert;
box-shadow: revert-layer;
box-shadow: unset;
```
Specify a single box-shadow using:
- Two, three, or four {{cssxref("length")}} values.
- If only two values are given, they are interpreted as `<offset-x>` and `<offset-y>` values.
- If a third value is given, it is interpreted as a `<blur-radius>`.
- If a fourth value is given, it is interpreted as a `<spread-radius>`.
- Optionally, the `inset` keyword.
- Optionally, a [`<color>`](#color) value.
To specify multiple shadows, provide a comma-separated list of shadows.
### Values
- `<color>` {{optional_inline}}
- : Specifies color for the shadow. See {{cssxref("<color>")}} values for possible keywords and notations.
If not specified, the value of the {{cssxref("color")}} property defined in the parent element is used.
- `<length>`
- : Specifies the offset length of the shadow. This parameter accepts two, three, or four values. Third and fourth values are optional. They are interpreted as follows:
- If two values are specified, they are interpreted as `<offset-x>` (horizontal offset) and `<offset-y>` (vertical offset) values. Negative `<offset-x>` value places the shadow to the left of the element. Negative `<offset-y>` value places the shadow above the element.\
If not specified, the value of `0` is used for the missing length. If both `<offset-x>` and `<offset-y>` are set to `0`, the shadow is placed behind the element (and may generate a blur effect if `<blur-radius>` and/or `<spread-radius>` is set).
- If three values are specified, the third value is interpreted as `<blur-radius>`. The larger this value, the bigger the blur, so the shadow becomes bigger and lighter. Negative values are not allowed. If not specified, it will be set to`0` (meaning that the shadow's edge will be sharp). The specification does not include an exact algorithm for how the blur radius should be calculated; however, it does elaborate as follows:
> β¦for a long, straight shadow edge, this should create a color transition the length of the blur distance that is perpendicular to and centered on the shadow's edge, and that ranges from the full shadow color at the radius endpoint inside the shadow to fully transparent at the endpoint outside it.
- If four values are specified, the fourth value is interpreted as `<spread-radius>`. Positive values will cause the shadow to expand and grow bigger, negative values will cause the shadow to shrink. If not specified, it will be set to `0` (that is, the shadow will be the same size as the element).
- `inset` {{optional_inline}}
- : Changes the shadow from an outer box-shadow to an inner box-shadow (as if the content is pressed into the box). Inset shadows are drawn inside the box's border (even if the border is transparent), and they appear above the background but below the content. By default, the shadow behaves like a drop shadow, giving the appearance that the box is elevated above its content. This is the default behavior when `inset` is not specified.
### Interpolation
When animating shadows, such as when multiple shadow values on a box transition to new values on hover, the values are interpolated. {{Glossary("Interpolation")}} determines intermediate values of properties, such as the blur radius, spread radius, and color, as shadows transition. For each shadow in a list of shadows, the color, x, y, blur, and spread transition; the color as [`<color>`](/en-US/docs/Web/CSS/color_value), and the other values as {{cssxref("length")}}s.
In interpolating multiple shadows between two comma-separated lists of multiple box shadows, the shadows are paired, in order, with interpolation occurring between paired shadows. If the lists of shadows have different lengths, then the shorter list is padded at the end with shadows whose color is `transparent`, and X, Y, and blur are `0`, with the inset, or lack of inset, being set to match. If in any pair of shadows, one has `inset` set and the other does not, the entire shadow list is uninterpolated; the shadows will change to the new values without an animating effect.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting three shadows
In this example, we include three shadows: an inset shadow, a regular drop shadow, and a 2px shadow that creates a border effect (we could have used an {{cssxref('outline')}} instead for that third shadow).
#### HTML
```html
<blockquote>
<q>
You may shoot me with your words,<br />
You may cut me with your eyes,<br />
You may kill me with your hatefulness,<br />
But still, like air, I'll rise.
</q>
<p>— Maya Angelou</p>
</blockquote>
```
#### CSS
```css
blockquote {
padding: 20px;
box-shadow:
inset 0 -3em 3em rgb(0 200 0 / 30%),
0 0 0 2px white,
0.3em 0.3em 1em rgb(200 0 0 / 60%);
}
```
#### Result
{{EmbedLiveSample('Setting_three_shadows', '300', '300')}}
### Setting zero for offset and blur
When the `x-offset`, `y-offset`, and `blur` are all zero, the box shadow will be a solid-colored outline of equal-size on all sides. The shadows are drawn back to front, so the first shadow sits on top of subsequent shadows. When the `border-radius` is set to 0, as is the default, the corners of the shadow will be, well, corners. Had we put in a `border-radius` of any other value, the corners would have been rounded.
We added a margin the size of the widest box-shadow to ensure the shadow doesn't overlap adjacent elements or go beyond the border of the containing box. A box-shadow does not impact [box model](/en-US/docs/Web/CSS/CSS_box_model) dimensions.
#### HTML
```html
<div><p>Hello World</p></div>
```
#### CSS
```css
p {
box-shadow:
0 0 0 2em #f4aab9,
0 0 0 4em #66ccff;
margin: 4em;
padding: 1em;
}
```
<!-- these colors are intentionally pink and blue. WCAG requires color contrast between text and background, not between border colors. -->
#### Result
{{EmbedLiveSample('Setting_zero_for_offset_and_blur', '300', '300')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- The {{cssxref("<color>")}} data type (for specifying the shadow color)
- {{cssxref("text-shadow")}}
- {{cssxref("filter-function/drop-shadow", "drop-shadow()")}}
- [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/_doublecolon_view-transition-group/index.md | ---
title: "::view-transition-group"
slug: Web/CSS/::view-transition-group
page-type: css-pseudo-element
status:
- experimental
browser-compat: css.selectors.view-transition-group
---
{{CSSRef}}{{SeeCompatTable}}
The **`::view-transition-group`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) represents a single view transition group.
During a view transition, `::view-transition-group` is included in the associated pseudo-element tree as explained in [The view transition process](/en-US/docs/Web/API/View_Transitions_API#the_view_transition_process). It is only ever a child of {{cssxref("::view-transition")}}, and has a {{cssxref("::view-transition-image-pair")}} as a child.
`::view-transition-group` is given the following default styling in the UA stylesheet:
```css
html::view-transition-group(*) {
position: absolute;
top: 0;
left: 0;
animation-duration: 0.25s;
animation-fill-mode: both;
}
```
By default, selected elements initially mirror the size and position of the {{cssxref("::view-transition-old")}} pseudo-element representing the "old" view state, or the {{cssxref("::view-transition-new")}} pseudo-element representing the "new" view state if there isn't an "old" view state.
If there's both an "old" and "new" view state, styles in the view transition style sheet animate this pseudo-element's {{cssxref("width")}} and {{cssxref("height")}} from the size of the "old" view state's border box to that of the "new" view state's border box.
> **Note:** View transition style sheet styles are dynamically generated during the view transition; see the specification [setup transition pseudo-elements](https://drafts.csswg.org/css-view-transitions-1/#setup-transition-pseudo-elements) and [update pseudo-element styles](https://drafts.csswg.org/css-view-transitions-1/#update-pseudo-element-styles) sections for more details.
In addition, the element's transform is animated from the "old" view state's screen space transform to the new view state's screen space transform. This style is generated dynamically since the values of animated properties are determined at the time that the transition begins.
## Syntax
```css-nolint
::view-transition-group(<pt-name-selector>) {
/* ... */
}
```
`<pt-name-selector>` can be one of the following values:
- `*`
- : Causes the pseudo-element to match all view transition groups.
- `root`
- : Causes the pseudo-element to match the default `root` view transition group created by the user agent to contain the view transition for the overall page, meaning any element not assigned to its own specific view transition group via the {{cssxref("view-transition-name")}} property.
- {{cssxref("custom-ident")}}
- : Causes the pseudo-element to match a specific view transition group created by assigning the given {{cssxref("custom-ident")}} to an element via the {{cssxref("view-transition-name")}} property.
## Examples
```css
view-transition-group(embed-container) {
animation-duration: 0.3s;
animation-timing-function: ease;
z-index: 1;
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [View Transitions API](/en-US/docs/Web/API/View_Transitions_API)
- [Smooth and simple transitions with the View Transitions API](https://developer.chrome.com/docs/web-platform/view-transitions/)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/font-smooth/index.md | ---
title: font-smooth
slug: Web/CSS/font-smooth
page-type: css-property
status:
- non-standard
browser-compat: css.properties.font-smooth
---
{{CSSRef}} {{ Non-standard_header }}
The **`font-smooth`** [CSS](/en-US/docs/Web/CSS) property controls the application of anti-aliasing when fonts are rendered.
## Syntax
```css
/* Keyword values */
font-smooth: auto;
font-smooth: never;
font-smooth: always;
/* <length> value */
font-smooth: 2em;
/* Global values */
font-smooth: inherit;
font-smooth: initial;
font-smooth: revert;
font-smooth: revert-layer;
font-smooth: unset;
```
> **Note:** WebKit implements a similar property, but with different values: **`-webkit-font-smoothing`**. It only works on macOS.
>
> - `auto` - Let the browser decide (Uses subpixel anti-aliasing when available; this is the default)
> - `none` - Turn font smoothing off; display text with jagged sharp edges.
> - `antialiased` - Smooth the font on the level of the pixel, as opposed to the subpixel. Switching from subpixel rendering to anti-aliasing for light text on dark backgrounds makes it look lighter.
> - `subpixel-antialiased` - On most non-retina displays, this will give the sharpest text.
> **Note:** Firefox implements a similar property, but with different values: **`-moz-osx-font-smoothing`**. It only works on macOS.
>
> - `auto` - Allow the browser to select an optimization for font smoothing, typically `grayscale`.
> - `grayscale` - Render text with grayscale anti-aliasing, as opposed to the subpixel. Switching from subpixel rendering to anti-aliasing for light text on dark backgrounds makes it look lighter.
## Formal definition
{{cssinfo}}
## Formal syntax
```plain
font-smooth =
auto | never | always | <absolute-size> | <length>
```
## Examples
### Basic usage example
The following example shows the Safari/Chromium and Firefox equivalents that turn on font-smoothing on macOS. In both cases the smoothed font should look slightly lighter in weight.
For those of you not on a macOS system, here is a screenshot (the live version appears later on):

#### HTML
```html
<p>Without font smoothing</p>
<p class="smoothed">With font smoothing</p>
```
#### CSS
```css
html {
background-color: black;
color: white;
font-size: 3rem;
}
p {
text-align: center;
}
.smoothed {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
```
#### Result
{{EmbedLiveSample('Basic_usage_example', '100%', 260)}}
## Specifications
Not part of any standard.
## Browser compatibility
{{Compat}}
## See also
- [Please Stop "Fixing" Font Smoothing β UsabilityPost](https://usabilitypost.com/2012/11/05/stop-fixing-font-smoothing/)
- [Laissez-faire font smoothing and anti-aliasing](https://www.zachleat.com/web/font-smooth/)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_-moz-suppressed/index.md | ---
title: ":-moz-suppressed"
slug: Web/CSS/:-moz-suppressed
page-type: css-pseudo-class
status:
- non-standard
---
{{CSSRef}}{{Non-standard_header}}
The **`:-moz-suppressed`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) is a [Mozilla extension](/en-US/docs/Web/CSS/Mozilla_Extensions) that matches elements representing images that were suppressed because loading images from the specified site has been blocked.
> **Note:** This selector is mainly intended to be used by theme developers.
## Syntax
```css
:-moz-suppressed {
/* ... */
}
```
## Examples
### Styling elements that have been blocked
```css
:-moz-suppressed {
background: yellow;
padding: 8px;
}
```
## Specifications
Not part of any standard.
## See also
- {{cssxref(":-moz-broken")}}, {{cssxref(":-moz-loading")}}, {{cssxref(":-moz-user-disabled")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/computed_value/index.md | ---
title: Computed value
slug: Web/CSS/computed_value
page-type: guide
spec-urls: https://www.w3.org/TR/CSS22/cascade.html#computed-value
---
{{CSSRef}}
The **computed value** of a [CSS](/en-US/docs/Web/CSS) property is the value that is transferred from parent to child during inheritance. It is calculated from the [specified value](/en-US/docs/Web/CSS/specified_value) by:
1. Handling the special values {{cssxref("inherit")}}, {{cssxref("initial")}}, {{cssxref("revert")}}, {{cssxref("revert-layer")}}, and {{cssxref("unset")}}.
2. Doing the computation needed to reach the value described in the "Computed value" line in the property's definition table.
The computation needed to reach a property's computed value typically involves converting relative values (such as those in `em` units or percentages) to absolute values. For example, if an element has specified values `font-size: 16px` and `padding-top: 2em`, then the computed value of `padding-top` is `32px` (double the font size).
However, for some properties (those where percentages are relative to something that may require layout to determine, such as `width`, `margin-right`, `text-indent`, and `top`), percentage-specified values turn into percentage-computed values. Additionally, unitless numbers specified on the `line-height` property become the computed value, as specified. The relative values that remain in the computed value become absolute when the [used value](/en-US/docs/Web/CSS/used_value) is determined.
> **Note:** The {{domxref("Window.getComputedStyle", "getComputedStyle()")}} DOM API returns the [resolved value](/en-US/docs/Web/CSS/resolved_value), which may either be the computed value or the [used value](/en-US/docs/Web/CSS/used_value), depending on the property.
## 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)
- [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/shape-outside/index.md | ---
title: shape-outside
slug: Web/CSS/shape-outside
page-type: css-property
browser-compat: css.properties.shape-outside
---
{{CSSRef}}
The **`shape-outside`** [CSS](/en-US/docs/Web/CSS) property defines a shapeβwhich may be non-rectangularβaround which adjacent inline content should wrap. By default, inline content wraps around its margin box; `shape-outside` provides a way to customize this wrapping, making it possible to wrap text around complex objects rather than simple boxes.
{{EmbedInteractiveExample("pages/css/shape-outside.html")}}
## Syntax
```css
/* Keyword values */
shape-outside: none;
shape-outside: margin-box;
shape-outside: content-box;
shape-outside: border-box;
shape-outside: padding-box;
/* Function values */
shape-outside: circle();
shape-outside: ellipse();
shape-outside: inset(10px 10px 10px 10px);
shape-outside: polygon(10px 10px, 20px 20px, 30px 30px);
shape-outside: path("M100,0 A100,100 0 1,1 100,200 A100,100 0 1,1 100,0");
/* <url> value */
shape-outside: url(image.png);
/* <gradient> value */
shape-outside: linear-gradient(45deg, #fff 150px, red 150px);
/* Global values */
shape-outside: inherit;
shape-outside: initial;
shape-outside: revert;
shape-outside: revert-layer;
shape-outside: unset;
```
The `shape-outside` property is specified using the values from the list below, which define the _float area_ for _float elements_. The float area determines the shape around which inline content (float elements) wrap.
### Values
- `none`
- : The float area is unaffected. Inline content wraps around the element's margin box, like usual.
- `<shape-box>`
- : The float area is computed according to the shape of a float element's edges (as defined by the [CSS box model](/en-US/docs/Web/CSS/CSS_box_model/Introduction_to_the_CSS_box_model)). This can be `margin-box`, `border-box`, `padding-box`, or `content-box`. The shape includes any curvature created by the {{cssxref("border-radius")}} property (behavior which is similar to {{cssxref("background-clip")}}).
- `margin-box`
- : Defines the shape enclosed by the outside margin edge. The corner radii of this shape are determined by the corresponding {{cssxref("border-radius")}} and {{cssxref("margin")}} values. If the `border-radius / margin` ratio is `1` or more, then the margin box corner radius is `border-radius + margin`. If the ratio is less than `1`, then the margin box corner radius is `border-radius + (margin * (1 + (ratio - 1) ^ 3))`.
- `border-box`
- : Defines the shape enclosed by the outside border edge. The shape follows the normal border radius shaping rules for the outside of the border.
- `padding-box`
- : Defines the shape enclosed by the outside padding edge. The shape follows the normal border radius shaping rules for the inside of the border.
- `content-box`
- : Defines the shape enclosed by the outside content edge. Each corner radius of this box is the larger of `0` or `border-radius - border-width - padding`.
- {{cssxref("<basic-shape>")}}
- : The float area is computed based on the shape created by of one of {{cssxref("basic-shape/inset","inset()")}}, {{cssxref("basic-shape/circle","circle()")}}, {{cssxref("basic-shape/ellipse","ellipse()")}}, {{cssxref("basic-shape/polygon","polygon()")}} or, as added in the level 2 specification, `path()`. If a `<shape-box>` is also supplied, it defines the reference box for the `<basic-shape>` function. Otherwise, the reference box defaults to `margin-box`.
- {{cssxref("<image>")}}
- : The float area is extracted and computed based on the alpha channel of the specified {{cssxref("<image>")}} as defined by {{cssxref("shape-image-threshold")}}.
> **Note:** If the image is invalid, the effect is as if the keyword `none` had been specified. Additionally, the image must be served with {{Glossary("CORS")}} headers allowing its use.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Funneling text
#### HTML
```html
<div class="main">
<div class="left"></div>
<div class="right"></div>
<p>
Sometimes a web page's text content appears to be funneling your attention
towards a spot on the page to drive you to follow a particular link.
Sometimes you don't notice.
</p>
</div>
```
#### CSS
```css
.main {
width: 530px;
}
.left,
.right {
background-color: lightgray;
height: 12ex;
width: 40%;
}
.left {
clip-path: polygon(0 0, 100% 100%, 0 100%);
float: left;
shape-outside: polygon(0 0, 100% 100%, 0 100%);
}
.right {
clip-path: polygon(100% 0, 100% 100%, 0 100%);
float: right;
shape-outside: polygon(100% 0, 100% 100%, 0 100%);
}
p {
text-align: center;
}
```
#### Result
{{EmbedLiveSample("funneling_text", "100%", 130)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [CSS shapes](/en-US/docs/Web/CSS/CSS_shapes)
- [Overview of shapes](/en-US/docs/Web/CSS/CSS_shapes/Overview_of_shapes)
- {{cssxref("<basic-shape>")}}
- {{cssxref("shape-margin")}}
- {{cssxref("shape-image-threshold")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/border-inline-start-color/index.md | ---
title: border-inline-start-color
slug: Web/CSS/border-inline-start-color
page-type: css-property
browser-compat: css.properties.border-inline-start-color
---
{{CSSRef}}
The **`border-inline-start-color`** [CSS](/en-US/docs/Web/CSS) property defines the color of the logical inline start border of an element, which maps to a physical border color depending on the element's writing mode, directionality, and text orientation. It corresponds to the {{cssxref("border-top-color")}}, {{cssxref("border-right-color")}}, {{cssxref("border-bottom-color")}}, or {{cssxref("border-left-color")}} property depending on the values defined for {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}}.
{{EmbedInteractiveExample("pages/css/border-inline-start-color.html")}}
## Syntax
```css
border-inline-start-color: red;
border-inline-start-color: #ee4141;
/* Global values */
border-inline-start-color: inherit;
border-inline-start-color: initial;
border-inline-start-color: revert;
border-inline-start-color: revert-layer;
border-inline-start-color: unset;
```
Related properties are {{cssxref("border-block-start-color")}}, {{cssxref("border-block-end-color")}}, and {{cssxref("border-inline-end-color")}}, which define the other border colors of the element.
### Values
- {{CSSXref("<color>")}}
- : The color of the border.
## 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: 10px solid blue;
border-inline-start-color: red;
}
```
{{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-color")}}, {{cssxref("border-right-color")}}, {{cssxref("border-bottom-color")}}, and {{cssxref("border-left-color")}}
- {{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/print-color-adjust/index.md | ---
title: print-color-adjust
slug: Web/CSS/print-color-adjust
page-type: css-property
browser-compat: css.properties.print-color-adjust
---
{{CSSRef}}
The **`print-color-adjust`** CSS property sets what, if anything, the {{Glossary("user agent")}} may do to optimize the appearance of the element on the output device.
By default, the browser is allowed to make any adjustments to the element's appearance it determines to be necessary and prudent given the type and capabilities of the output device.
## Syntax
```css
print-color-adjust: economy;
print-color-adjust: exact;
/* Global values */
print-color-adjust: inherit;
print-color-adjust: initial;
print-color-adjust: revert;
print-color-adjust: revert-layer;
print-color-adjust: unset;
```
The `print-color-adjust` property's value must be one of the following keywords.
### Values
- `economy`
- : The user agent is allowed to make adjustments to the element as it deems appropriate and prudent in order to optimize the output for the device it's being rendered for.
For example, when printing, a browser might opt to leave out all background images and to adjust text colors to be sure the contrast is optimized for reading on white paper.
This is the default.
- `exact`
- : The element's content has been specifically and carefully crafted to use colors, images, and styles in a thoughtful and/or important way, such that being altered by the browser might actually make things worse rather than better.
The appearance of the content should not be changed except by the user's request.
For example, a page might include a list of information with rows whose background colors alternate between white and a light grey.
Removing the background color would decrease the legibility of the content.
## Usage notes
There are a number of reasons a browser might wish to deviate from the specified appearance, such as:
- The content uses text and background colors that will be too similar on the output device for legibility purposes.
- If the output device is a printer, and to save ink, dark or extremely dense background images might be removed.
- When printing a page, the browser might want to replace light-colored text on a dark background with dark text on a white background.
Any options the user agent offers the user to allow them to control the use of color and images will take priority over the value of `print-color-adjust`.
In other words, there isn't any guarantee that `print-color-adjust` will do anything.
Not only can the user override the behavior, but each user agent is allowed to decide for itself how to handle `print-color-adjust` in any given situation.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Preserving low contrast
In this example, a box is shown which uses a {{cssxref("background-image")}} and a translucent {{cssxref("gradient/linear-gradient", "linear-gradient()")}} function atop a black background color to have a dark blue gradient behind medium red text.
For whatever reason, this is the desired appearance in any rendering environment, including on paper, so we also use `print-color-adjust: exact` to tell the browser not to make color or style adjustments to the box when rendering it.
#### CSS
```css
.my-box {
background-color: black;
background-image: linear-gradient(rgb(0 0 180 / 50%), rgb(70 140 220 / 50%));
color: #900;
width: 15rem;
height: 6rem;
text-align: center;
font:
24px "Helvetica",
sans-serif;
display: flex;
align-items: center;
justify-content: center;
print-color-adjust: exact;
}
```
#### HTML
```html
<div class="my-box">
<p>Need more contrast!</p>
</div>
```
#### Result
{{EmbedLiveSample("Preserving_low_contrast", 640, 120)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Applying color to HTML elements using CSS](/en-US/docs/Web/CSS/CSS_colors/Applying_color)
- Other color-related properties: {{cssxref("color")}}, {{cssxref("background-color")}}, {{cssxref("border-color")}}, {{cssxref("outline-color")}}, {{cssxref("text-decoration-color")}}, {{cssxref("text-emphasis-color")}}, {{cssxref("text-shadow")}}, {{cssxref("caret-color")}}, and {{cssxref("column-rule-color")}}
- {{cssxref("background-image")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/asin/index.md | ---
title: asin()
slug: Web/CSS/asin
page-type: css-function
browser-compat: css.types.asin
---
{{CSSRef}}
The **`asin()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) is a trigonometric function that returns the inverse sine of a number between `-1` and `1`. The function contains a single calculation that returns the number of radians representing an {{cssxref("<angle>")}} between `-90deg` and `90deg`.
## Syntax
```css
/* Single <number> values */
transform: rotate(asin(-0.2));
transform: rotate(asin(2 * 0.125));
/* Other values */
transform: rotate(asin(pi / 5));
transform: rotate(asin(e / 3));
```
### Parameter
The `asin(number)` function accepts only one value as its parameter.
- `number`
- : A calculation which resolves to a {{cssxref("<number>")}} between `-1` and `1`.
### Return value
The inverse sine of an `number` will always return an {{cssxref("<angle>")}} between `-90deg` and `90deg`.
- If `number` is less than `-1` or greater than `1`, the result is `NaN`.
- If `number` is `0β»`, the result is `0β»`.
### Formal syntax
{{CSSSyntax}}
## Examples
### Rotate elements
The `asin()` function can be used to {{cssxref("transform-function/rotate", "rotate")}} elements as it return an {{cssxref("<angle>")}}.
#### HTML
```html
<div class="box box-1"></div>
<div class="box box-2"></div>
<div class="box box-3"></div>
<div class="box box-4"></div>
<div class="box box-5"></div>
```
#### CSS
```css hidden
body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
gap: 50px;
}
```
```css
div.box {
width: 100px;
height: 100px;
background: linear-gradient(orange, red);
}
div.box-1 {
transform: rotate(asin(1));
}
div.box-2 {
transform: rotate(asin(0.5));
}
div.box-3 {
transform: rotate(asin(0));
}
div.box-4 {
transform: rotate(asin(-0.5));
}
div.box-5 {
transform: rotate(asin(-1));
}
```
#### Result
{{EmbedLiveSample('Rotate elements', '100%', '200px')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef("sin")}}
- {{CSSxRef("cos")}}
- {{CSSxRef("tan")}}
- {{CSSxRef("acos")}}
- {{CSSxRef("atan")}}
- {{CSSxRef("atan2")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_host-context/index.md | ---
title: ":host-context()"
slug: Web/CSS/:host-context
page-type: css-pseudo-class
browser-compat: css.selectors.host-context
---
{{CSSRef}}
The **`:host-context()`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) function selects the shadow host of the [shadow DOM](/en-US/docs/Web/API/Web_components/Using_shadow_DOM) containing the CSS it is used inside (so you can select a custom element from inside its shadow DOM) β but only if the selector given as the function's parameter matches the shadow host's ancestor(s) in the place it sits inside the DOM hierarchy.
In other words, this allows a custom element, or anything within that custom element's shadow DOM, to apply different styles based on its position within the outer DOM or classes/attributes applied to ancestor elements.
One typical use of this is with a descendant selector expression β for example `h1` β to select only instances of the custom element that are inside an `<h1>`. Another typical use would be to allow inner elements to react to classes or attributes on any ancestor elements - for example, applying a different text color when a `.dark-theme` class is applied to `<body>`.
> **Note:** This has no effect when used outside a shadow DOM.
{{EmbedInteractiveExample("pages/tabbed/pseudo-class-host-context.html", "tabbed-shorter")}}
```css
/* Selects a shadow root host, only if it is
a descendant of the selector argument given */
:host-context(h1) {
font-weight: bold;
}
/* Changes paragraph text color from black to white when
a .dark-theme class is applied to the document body */
p {
color: #000;
}
:host-context(body.dark-theme) p {
color: #fff;
}
```
## Syntax
```css-nolint
:host-context(<compound-selector>) {
/* ... */
}
```
## Examples
### Selectively styling shadow hosts
The following snippets are taken from our [host-selectors example](https://github.com/mdn/web-components-examples/tree/main/host-selectors) ([see it live also](https://mdn.github.io/web-components-examples/host-selectors/)).
In this example we have a simple custom element β `<context-span>` β that you can wrap around text:
```html
<h1>
Host selectors <a href="#"><context-span>example</context-span></a>
</h1>
```
Inside the element's constructor, we create `style` and `span` elements, fill the `span` with the content of the custom element, and fill the `style` element with some CSS rules:
```js
const style = document.createElement("style");
const span = document.createElement("span");
span.textContent = this.textContent;
const shadowRoot = this.attachShadow({ mode: "open" });
shadowRoot.appendChild(style);
shadowRoot.appendChild(span);
style.textContent =
"span:hover { text-decoration: underline; }" +
":host-context(h1) { font-style: italic; }" +
':host-context(h1):after { content: " - no links in headers!" }' +
":host(.footer) { color : red; }" +
":host { background: rgb(0 0 0 / 10%); padding: 2px 5px; }";
```
The `:host-context(h1) { font-style: italic; }` and `:host-context(h1):after { content: " - no links in headers!" }` rules style the instance of the `<context-span>` element (the shadow host in this instance) inside the `<h1>`. We've used it to make it clear that the custom element shouldn't appear inside the `<h1>` in our design.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Web components](/en-US/docs/Web/API/Web_components)
- CSS {{cssxref(":host")}} pseudo-class
- CSS {{cssxref(":host_function", ":host()")}} pseudo-class
- CSS {{cssxref(":state",":state()")}} pseudo-class
- CSS {{CSSXref("::slotted")}} pseudo-element
- HTML {{HTMLElement("template")}} element
- [CSS scoping](/en-US/docs/Web/CSS/CSS_scoping) module
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/image-orientation/index.md | ---
title: image-orientation
slug: Web/CSS/image-orientation
page-type: css-property
browser-compat: css.properties.image-orientation
---
{{CSSRef}}
The **`image-orientation`** [CSS](/en-US/docs/Web/CSS) property specifies a layout-independent correction to the orientation of an image.
{{EmbedInteractiveExample("pages/css/image-orientation.html")}}
## Syntax
```css
/* keyword values */
image-orientation: none;
image-orientation: from-image; /* Use EXIF data from the image */
/* Global values */
image-orientation: inherit;
image-orientation: initial;
image-orientation: revert;
image-orientation: revert-layer;
image-orientation: unset;
```
### Values
- `none`
- : Does not apply any additional image rotation; the image is oriented as encoded or as other CSS property values dictate.
- `from-image`
- : Default initial value. The [EXIF](https://en.wikipedia.org/wiki/EXIF) information contained in the image is used to rotate the image appropriately.
> **Warning:** `image-orientation: none;` **does not** override the orientation of non-secure-origin images as encoded by their [EXIF](https://en.wikipedia.org/wiki/EXIF) information, due to security concerns. Find out more from [the CSS working group draft issue](https://github.com/w3c/csswg-drafts/issues/5165).
## Description
This property is intended _only_ to be used for the purpose of correcting the orientation of images which were shot with the camera rotated. It should _not_ be used for arbitrary rotations. For any purpose other than correcting an image's orientation due to how it was shot or scanned, use a {{cssxref("transform")}} property with the `rotate` keyword to specify rotation. This includes any user-directed changes to the orientation of the image, or changes required for printing in portrait versus landscape orientation.
If used in conjunction with other CSS properties, such as a {{cssxref("<transform-function>")}}, any `image-orientation` rotation is applied before any other transformations.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Orienting image from image data
The following image has been rotated through 180 degrees, and the `image-orientation` property is used to correct its orientation based on the EXIF data in the image. By changing the `image-orientation` to `none` you can see the effect of the property.
#### CSS
```css
#image {
image-orientation: from-image; /* Can be changed in the live sample */
}
```
```css hidden
img {
margin: 0.5rem 0;
}
label {
font-family: monospace;
}
```
```html hidden
<img id="image" src="oriole.jpg" alt="Orientation taken from the image" />
<div>
<input
type="radio"
id="from-image"
name="orientation"
value="from-image"
checked />
<label for="from-image">from-image</label>
</div>
<div>
<input type="radio" id="none" name="orientation" value="none" />
<label for="none">none</label>
</div>
```
```js hidden
document.addEventListener("change", (evt) => {
document.getElementById("image").style.imageOrientation = evt.target.value;
});
```
#### Result
{{EmbedLiveSample("Orienting_image_from_image_data", "100%", 900)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- Other image-related CSS properties: {{cssxref("object-fit")}}, {{cssxref("object-position")}}, {{cssxref("image-orientation")}}, {{cssxref("image-rendering")}}, {{cssxref("image-resolution")}}.
- {{cssxref("transform")}} and {{cssxref("rotate")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/mask-clip/index.md | ---
title: mask-clip
slug: Web/CSS/mask-clip
page-type: css-property
browser-compat: css.properties.mask-clip
---
{{CSSRef}}
The **`mask-clip`** [CSS](/en-US/docs/Web/CSS) property determines the area which is affected by a mask. The painted content of an element must be restricted to this area.
## Syntax
```css
/* <coord-box> values */
mask-clip: content-box;
mask-clip: padding-box;
mask-clip: border-box;
mask-clip: fill-box;
mask-clip: stroke-box;
mask-clip: view-box;
/* Keyword values */
mask-clip: no-clip;
/* Non-standard keyword values */
-webkit-mask-clip: border;
-webkit-mask-clip: padding;
-webkit-mask-clip: content;
-webkit-mask-clip: text;
/* Multiple values */
mask-clip: padding-box, no-clip;
mask-clip: view-box, fill-box, border-box;
/* Global values */
mask-clip: inherit;
mask-clip: initial;
mask-clip: revert;
mask-clip: revert-layer;
mask-clip: unset;
```
One or more of the keyword values listed below, separated by commas.
### Values
- `content-box`
- : The painted content is clipped to the content box.
- `padding-box`
- : The painted content is clipped to the padding box.
- `border-box`
- : The painted content is clipped to the border box.
- `fill-box`
- : The painted content is clipped to the object bounding box.
- `stroke-box`
- : The painted content is clipped to the stroke bounding box.
- `view-box`
- : Uses the nearest SVG viewport as reference box. If a [`viewBox`](/en-US/docs/Web/SVG/Attribute/viewBox) attribute is specified for the element creating the SVG viewport, the reference box is positioned at the origin of the coordinate system established by the `viewBox` attribute and the dimension of the reference box is set to the width and height values of the `viewBox` attribute.
- `no-clip`
- : The painted content is not clipped.
- `border` {{non-standard_inline}}
- : This keyword behaves the same as `border-box`.
- `padding` {{non-standard_inline}}
- : This keyword behaves the same as `padding-box`.
- `content` {{non-standard_inline}}
- : This keyword behaves the same as `content-box`.
- `text` {{non-standard_inline}}
- : This keyword clips the mask image to the text of the element.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Clipping a mask to the border box
Change the `mask-clip` value to any of the allowed values detailed above. If viewing the example in a Chromium-based browser change the value of `-webkit-mask-clip`.
{{EmbedGHLiveSample("css-examples/masking/mask-clip.html", '100%', 800)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Clipping and Masking in CSS](https://css-tricks.com/clipping-masking-css/)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/css_fragmentation/index.md | ---
title: CSS fragmentation
slug: Web/CSS/CSS_fragmentation
page-type: css-module
spec-urls: https://drafts.csswg.org/css-break/
---
{{CSSRef}}
The **CSS fragmentation** module defines how content is displayed when it is broken (fragmented) across multiple [pages](/en-US/docs/Web/CSS/CSS_paged_media), regions, or [columns](/en-US/docs/Web/CSS/CSS_multicol_layout).
Fragmentation occurs when an inline box wraps onto multiple lines. It also occurs when a block spans more than one column inside a column layout container, or spans a page break when printed. Each piece of the rendering for the element is called a _fragment_.
## Reference
### Properties
- {{cssxref("box-decoration-break")}}
- {{cssxref("break-after")}}
- {{cssxref("break-before")}}
- {{cssxref("break-inside")}}
- {{cssxref("orphans")}}
- {{cssxref("widows")}}
## Specifications
{{Specifications}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/blend-mode/index.md | ---
title: <blend-mode>
slug: Web/CSS/blend-mode
page-type: css-type
browser-compat: css.types.blend-mode
---
{{CSSRef}}
The **`<blend-mode>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) describes how colors should appear when elements overlap. It is used in the {{cssxref("background-blend-mode")}} and {{cssxref("mix-blend-mode")}} properties.
## Syntax
The `<blend-mode>` data type is defined using a keyword value chosen from the list below.
### Values
- `normal`
- : The final color is the top color, regardless of what the bottom color is.
The effect is like two opaque pieces of paper overlapping.
- `multiply`
- : The final color is the result of multiplying the top and bottom colors.
A black layer leads to a black final layer, and a white layer leads to no change.
The effect is like two images printed on transparent film overlapping.
- `screen`
- : The final color is the result of inverting the colors, multiplying them, and inverting that value.
A black layer leads to no change, and a white layer leads to a white final layer.
The effect is like two images shone onto a projection screen.
- `overlay`
- : The final color is the result of `multiply` if the bottom color is darker, or `screen` if the bottom color is lighter.
This blend mode is equivalent to `hard-light` but with the layers swapped.
- `darken`
- : The final color is composed of the darkest values of each color channel.
- `lighten`
- : The final color is composed of the lightest values of each color channel.
- `color-dodge`
- : The final color is the result of dividing the bottom color by the inverse of the top color.
A black foreground leads to no change. A foreground with the inverse color of the backdrop leads to a fully lit color.
This blend mode is similar to `screen`, but the foreground need only be as light as the inverse of the backdrop to create a fully lit color.
- `color-burn`
- : The final color is the result of inverting the bottom color, dividing the value by the top color, and inverting that value.
A white foreground leads to no change. A foreground with the inverse color of the backdrop leads to a black final image.
This blend mode is similar to `multiply`, but the foreground need only be as dark as the inverse of the backdrop to make the final image black.
- `hard-light`
- : The final color is the result of `multiply` if the top color is darker, or `screen` if the top color is lighter.
This blend mode is equivalent to `overlay` but with the layers swapped.
The effect is similar to shining a _harsh_ spotlight on the backdrop.
- `soft-light`
- : The final color is similar to `hard-light`, but softer.
This blend mode behaves similar to `hard-light`.
The effect is similar to shining a _diffused_ spotlight on the backdrop*.*
- `difference`
- : The final color is the result of subtracting the darker of the two colors from the lighter one.
A black layer has no effect, while a white layer inverts the other layer's color.
- `exclusion`
- : The final color is similar to `difference`, but with less contrast.
As with `difference`, a black layer has no effect, while a white layer inverts the other layer's color.
- `hue`
- : The final color has the _hue_ of the top color, while using the _saturation_ and _luminosity_ of the bottom color.
- `saturation`
- : The final color has the _saturation_ of the top color, while using the _hue_ and _luminosity_ of the bottom color.
A pure gray backdrop, having no saturation, will have no effect.
- `color`
- : The final color has the _hue_ and _saturation_ of the top color, while using the _luminosity_ of the bottom color.
The effect preserves gray levels and can be used to colorize the foreground.
- `luminosity`
- : The final color has the _luminosity_ of the top color, while using the _hue_ and _saturation_ of the bottom color.
This blend mode is equivalent to `color`, but with the layers swapped.
## Description
For each pixel among the layers to which it is applied, a blend mode takes the colors of the foreground and the background, performs a calculation on them, and returns a new color value.
Changes between blend modes are not interpolated. Any change occurs immediately.
## Formal syntax
{{csssyntax}}
## Examples
### Example using "normal"
```html hidden
<div id="div"></div>
```
```css
#div {
width: 300px;
height: 300px;
background: url("br.png"), url("tr.png");
background-blend-mode: normal;
}
```
{{ EmbedLiveSample('Example using "normal"', "300", "350") }}
### Example using "multiply"
```html hidden
<div id="div"></div>
```
```css
#div {
width: 300px;
height: 300px;
background: url("br.png"), url("tr.png");
background-blend-mode: multiply;
}
```
{{ EmbedLiveSample('Example using "multiply"', "300", "350") }}
### Example using "screen"
```html hidden
<div id="div"></div>
```
```css
#div {
width: 300px;
height: 300px;
background: url("br.png"), url("tr.png");
background-blend-mode: screen;
}
```
{{ EmbedLiveSample('Example using "screen"', "300", "350") }}
### Example using "overlay"
```html hidden
<div id="div"></div>
```
```css
#div {
width: 300px;
height: 300px;
background: url("br.png"), url("tr.png");
background-blend-mode: overlay;
}
```
{{ EmbedLiveSample('Example using "overlay"', "300", "350") }}
### Example using "darken"
```html hidden
<div id="div"></div>
```
```css
#div {
width: 300px;
height: 300px;
background: url("br.png"), url("tr.png");
background-blend-mode: darken;
}
```
{{ EmbedLiveSample('Example using "darken"', "300", "350") }}
### Example using "lighten"
```html hidden
<div id="div"></div>
```
```css
#div {
width: 300px;
height: 300px;
background: url("br.png"), url("tr.png");
background-blend-mode: lighten;
}
```
{{ EmbedLiveSample('Example using "lighten"', "300", "350") }}
### Example using "color-dodge"
```html hidden
<div id="div"></div>
```
```css
#div {
width: 300px;
height: 300px;
background: url("br.png"), url("tr.png");
background-blend-mode: color-dodge;
}
```
{{ EmbedLiveSample('Example using "color-dodge"', "300", "350") }}
### Example using "color-burn"
```html hidden
<div id="div"></div>
```
```css
#div {
width: 300px;
height: 300px;
background: url("br.png"), url("tr.png");
background-blend-mode: color-burn;
}
```
{{ EmbedLiveSample('Example using "color-burn"', "300", "350") }}
### Example using "hard-light"
```html hidden
<div id="div"></div>
```
```css
#div {
width: 300px;
height: 300px;
background: url("br.png"), url("tr.png");
background-blend-mode: hard-light;
}
```
{{ EmbedLiveSample('Example using "hard-light"', "300", "350") }}
### Example using "soft-light"
```html hidden
<div id="div"></div>
```
```css
#div {
width: 300px;
height: 300px;
background: url("br.png"), url("tr.png");
background-blend-mode: soft-light;
}
```
{{ EmbedLiveSample('Example using "soft-light"', "300", "350") }}
### Example using "difference"
```html hidden
<div id="div"></div>
```
```css
#div {
width: 300px;
height: 300px;
background: url("br.png"), url("tr.png");
background-blend-mode: difference;
}
```
{{ EmbedLiveSample('Example using "difference"', "300", "350") }}
### Example using "exclusion"
```html hidden
<div id="div"></div>
```
```css
#div {
width: 300px;
height: 300px;
background: url("br.png"), url("tr.png");
background-blend-mode: exclusion;
}
```
{{ EmbedLiveSample('Example using "exclusion"', "300", "350") }}
### Example using "hue"
```html hidden
<div id="div"></div>
```
```css
#div {
width: 300px;
height: 300px;
background: url("br.png"), url("tr.png");
background-blend-mode: hue;
}
```
{{ EmbedLiveSample('Example using "hue"', "300", "350") }}
### Example using "saturation"
```html hidden
<div id="div"></div>
```
```css
#div {
width: 300px;
height: 300px;
background: url("br.png"), url("tr.png");
background-blend-mode: saturation;
}
```
{{ EmbedLiveSample('Example using "saturation"', "300", "350") }}
### Example using "color"
```html hidden
<div id="div"></div>
```
```css
#div {
width: 300px;
height: 300px;
background: url("br.png"), url("tr.png");
background-blend-mode: color;
}
```
{{ EmbedLiveSample('Example using "color"', "300", "350") }}
### Example using "luminosity"
```html hidden
<div id="div"></div>
```
```css
#div {
width: 300px;
height: 300px;
background: url("br.png"), url("tr.png");
background-blend-mode: luminosity;
}
```
{{ EmbedLiveSample('Example using "luminosity"', "300", "350") }}
### Blend mode comparison
In the following example, we have a `<div>` with two background images set on it β a Firefox logo on top of a linear gradient. Below it, we have a provided a `<select>` menu that allows you to change the `background-blend-mode` applied to the `<div>`, allowing you to compare the different blend mode effects.
#### HTML
```html
<div></div>
<p>Choose a blend-mode:</p>
<select>
<option selected>normal</option>
<option>multiply</option>
<option>screen</option>
<option>overlay</option>
<option>darken</option>
<option>lighten</option>
<option>color-dodge</option>
<option>color-burn</option>
<option>hard-light</option>
<option>soft-light</option>
<option>difference</option>
<option>exclusion</option>
<option>hue</option>
<option>saturation</option>
<option>color</option>
<option>luminosity</option>
</select>
```
#### CSS
```css
div {
width: 300px;
height: 300px;
background:
url(https://mdn.dev/archives/media/attachments/2020/07/29/17350/3b4892b7e820122ac6dd7678891d4507/firefox.png)
no-repeat center,
linear-gradient(to bottom, blue, orange);
}
```
#### JavaScript
```js
const selectElem = document.querySelector("select");
const divElem = document.querySelector("div");
selectElem.addEventListener("change", () => {
divElem.style.backgroundBlendMode = selectElem.value;
});
```
#### Result
{{EmbedLiveSample('Blend_mode_comparison', '100%', 400)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- The [CSS compositing and blending](/en-US/docs/Web/CSS/CSS_compositing_and_blending) module that defines the `<blend-mode>` values.
- Properties that use this data type: {{cssxref("background-blend-mode")}}, {{cssxref("mix-blend-mode")}}
Description to various blend modes on other website:
- [Blend modes](https://en.wikipedia.org/wiki/Blend_modes) on Wikipedia
- [Blending modes in Adobe Photoshop](https://helpx.adobe.com/photoshop/using/blending-modes.html) by Adobe
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/outline-width/index.md | ---
title: outline-width
slug: Web/CSS/outline-width
page-type: css-property
browser-compat: css.properties.outline-width
---
{{CSSRef}}
The [CSS](/en-US/docs/Web/CSS) **`outline-width`** property sets the thickness of an element's outline. An outline is a line that is drawn around an element, outside the {{cssxref("border")}}.
{{EmbedInteractiveExample("pages/css/outline-width.html")}}
It is often more convenient to use the shorthand property {{cssxref("outline")}} when defining the appearance of an outline.
## Syntax
```css
/* Keyword values */
outline-width: thin;
outline-width: medium;
outline-width: thick;
/* <length> values */
outline-width: 1px;
outline-width: 0.1em;
/* Global values */
outline-width: inherit;
outline-width: initial;
outline-width: revert;
outline-width: revert-layer;
outline-width: unset;
```
The `outline-width` property is specified as any one of the values listed below.
### Values
- {{cssxref("<length>")}}
- : The width of the outline specified as a `<length>`.
- `thin`
- : Depends on the user agent. Typically equivalent to `1px` in desktop browsers (including Firefox).
- `medium`
- : Depends on the user agent. Typically equivalent to `3px` in desktop browsers (including Firefox).
- `thick`
- : Depends on the user agent. Typically equivalent to `5px` in desktop browsers (including Firefox).
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting an element's outline width
#### HTML
```html
<span id="thin">thin</span>
<span id="medium">medium</span>
<span id="thick">thick</span>
<span id="twopixels">2px</span>
<span id="oneex">1ex</span>
<span id="em">1.2em</span>
```
#### CSS
```css
span {
outline-style: solid;
display: inline-block;
margin: 20px;
}
#thin {
outline-width: thin;
}
#medium {
outline-width: medium;
}
#thick {
outline-width: thick;
}
#twopixels {
outline-width: 2px;
}
#oneex {
outline-width: 1ex;
}
#em {
outline-width: 1.2em;
}
```
#### Result
{{EmbedLiveSample('Setting_an_elements_outline_width', '100%', '80')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("outline")}}
- {{cssxref("outline-color")}}
- {{cssxref("outline-style")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/offset/index.md | ---
title: offset
slug: Web/CSS/offset
page-type: css-shorthand-property
browser-compat: css.properties.offset
---
{{CSSRef}}
The **`offset`** CSS [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) sets all the properties required for animating an element along a defined path. The offset properties together help to define an _offset transform_, a [transform](/en-US/docs/Web/CSS/CSS_transforms/Using_CSS_transforms) that aligns a point in an element ([offset-anchor](/en-US/docs/Web/CSS/offset-anchor)) to an _offset position_ ([offset-position](/en-US/docs/Web/CSS/offset-position)) on a path ([offset-path](/en-US/docs/Web/CSS/offset-path)) at various points along the path ([offset-distance](/en-US/docs/Web/CSS/offset-distance)) and optionally rotates the element ([offset-rotate](/en-US/docs/Web/CSS/offset-rotate)) to follow the direction of the path.
> **Note:** Early versions of the spec called this property `motion`.
{{EmbedInteractiveExample("pages/css/offset.html")}}
## Constituent properties
This property is a shorthand for the following CSS properties:
- {{cssxref("offset-anchor")}}
- {{cssxref("offset-distance")}}
- {{cssxref("offset-path")}}
- {{cssxref("offset-position")}}
- {{cssxref("offset-rotate")}}
## Syntax
```css
/* Offset position */
offset: auto;
offset: 10px 30px;
offset: none;
/* Offset path */
offset: ray(45deg closest-side);
offset: path("M 100 100 L 300 100 L 200 300 z");
offset: url(arc.svg);
/* Offset path with distance and/or rotation */
offset: url(circle.svg) 100px;
offset: url(circle.svg) 40%;
offset: url(circle.svg) 30deg;
offset: url(circle.svg) 50px 20deg;
/* Including offset anchor */
offset: ray(45deg closest-side) / 40px 20px;
offset: url(arc.svg) 2cm / 0.5cm 3cm;
offset: url(arc.svg) 30deg / 50px 100px;
/* Global values */
offset: inherit;
offset: initial;
offset: revert;
offset: revert-layer;
offset: unset;
```
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Animating an element along a path
#### HTML
```html
<div id="offsetElement"></div>
```
#### CSS
```css
@keyframes move {
from {
offset-distance: 0%;
}
to {
offset-distance: 100%;
}
}
#offsetElement {
width: 50px;
height: 50px;
background-color: blue;
offset: path("M 100 100 L 300 100 L 200 300 z") auto;
animation: move 3s linear infinite;
}
```
#### Result
{{EmbedLiveSample("Animating_an_element_along_a_path", 350, 350)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("offset-anchor")}}
- {{cssxref("offset-distance")}}
- {{cssxref("offset-path")}}
- {{cssxref("offset-position")}}
- {{cssxref("offset-rotate")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/list-style/index.md | ---
title: list-style
slug: Web/CSS/list-style
page-type: css-shorthand-property
browser-compat: css.properties.list-style
---
{{CSSRef}}
The **`list-style`** CSS [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) allows you to set all the list style properties at once.
{{EmbedInteractiveExample("pages/css/list-style.html")}}
The values of this property are applied to list items, including {{HTMLElement("li")}} elements and elements with `{{cssxref("display")}}: list-item;`. Because this property is inherited, it can be set on a parent element (normally {{HTMLElement("ol")}} or {{HTMLElement("ul")}}) to make the same list styling apply to all the nested items.
## Constituent properties
This property is a shorthand for the following CSS properties:
- [`list-style-image`](/en-US/docs/Web/CSS/list-style-image)
- [`list-style-position`](/en-US/docs/Web/CSS/list-style-position)
- [`list-style-type`](/en-US/docs/Web/CSS/list-style-type)
## Syntax
```css
/* type */
list-style: square;
/* image */
list-style: url("../img/shape.png");
/* position */
list-style: inside;
/* two values */
list-style: georgian outside;
list-style: url("img/pip.svg") inside;
/* three values */
list-style: lower-roman url("img/shape.png") outside;
/* Keyword value */
list-style: none;
/* Global values */
list-style: inherit;
list-style: initial;
list-style: revert;
list-style: revert-layer;
list-style: unset;
```
The `list-style` property is specified as one, two, or three values in any order. If {{cssxref("list-style-type")}} and {{cssxref("list-style-image")}} are both set, the `list-style-type` is used as a fallback if the image is unavailable.
### Values
- {{cssxref("list-style-type")}}
- : A `<counter-style>`, {{cssxref("string")}}, or `none`. If omitted in the shorthand, the default `disc` value is used. See {{cssxref("list-style-type")}}.
- {{cssxref("list-style-image")}}
- : An {{cssxref("image")}} or `none`. If omitted, the default `none` value is used. See {{cssxref("list-style-image")}}.
- {{cssxref("list-style-position")}}
- : Either `inside` or `outside`. If omitted, the default `outside` value is used. See {{cssxref("list-style-position")}}.
- `none`
- : No list style is used.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting list style type and position
#### HTML
```html
List 1
<ul class="one">
<li>List Item1</li>
<li>List Item2</li>
<li>List Item3</li>
</ul>
List 2
<ul class="two">
<li>List Item A</li>
<li>List Item B</li>
<li>List Item C</li>
</ul>
```
#### CSS
```css
.one {
list-style: circle;
}
.two {
list-style: square inside;
}
```
#### Result
{{EmbedLiveSample('Setting_list_style_type_and_position', 'auto', 240)}}
## Accessibility concerns
Safari does not recognize ordered or unordered lists as lists in the accessibility tree if they have a `list-style` value of `none`, unless the list is nested within the {{HTMLElement("nav")}} navigation element. This [behavior is intentional](https://webkit.org/b/170179#c1) and is not considered a bug.
To ensure lists are announced as lists, include [`role="list"`](/en-US/docs/Web/Accessibility/ARIA/Roles/list_role) to {{HTMLElement("ol")}} and {{HTMLElement("ul")}} elements, especially if the list is not nested in a `<nav>`. This restores list semantics without affecting the design:
```html
<ul role="list">
<li>An item</li>
<li>Another item</li>
</ul>
```
If an ARIA `role` is not an option for your code, CSS can be used instead. Adding non-empty [pseudo-content](/en-US/docs/Web/CSS/content) such as text or images before each list item can restore list semantics, but impacts the visual appearance. Safari determines if the added pseudo-content suffices as accessible content, restoring list semantics if so. Generally, Safari considers text and images as sufficient, which is why the `content: "+ ";` shown below works (but requires additional styling to not affect the design).
```css
ul {
list-style: none;
}
ul li::before {
content: "+ ";
}
```
A declaration of `content: "";` (an empty string) is ignored, as are `content` values that contain only spaces, such as `content: " ";`.
These CSS workarounds should only be used when an HTML solution is unavailable, and only after testing to ensure that they don't result in unexpected behaviors that may negatively impact user experience.
- ['Fixing' Lists](https://www.scottohara.me/blog/2019/01/12/lists-and-safari.html) (2023)
- [VoiceOver and list-style-type: none](https://gerardkcohen.me/writing/2017/voiceover-list-style-type.html) (2017)
- [Understanding WCAG: Create content that can be presented in different ways](/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: Info and relationships | WCAG 2.1](https://www.w3.org/WAI/WCAG21/Understanding/info-and-relationships.html)
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- Component properties: {{Cssxref("list-style-type")}}, {{Cssxref("list-style-image")}}, and {{Cssxref("list-style-position")}}
- {{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/offset-path/index.md | ---
title: offset-path
slug: Web/CSS/offset-path
page-type: css-property
browser-compat: css.properties.offset-path
---
{{CSSRef}}
The **`offset-path`** [CSS](/en-US/docs/Web/CSS) property specifies a path for an element to follow and determines the element's positioning within the path's parent container or the SVG coordinate system. The path is a line, a curve, or a geometrical shape along which the element gets positioned or moves.
The `offset-path` property is used in combination with the {{cssxref("offset-distance")}}, {{cssxref("offset-rotate")}}, and {{cssxref("offset-anchor")}} properties to control the position and orientation of the element along a path.
{{EmbedInteractiveExample("pages/css/offset-path.html")}}
## Syntax
```css
/* Default */
offset-path: none;
/* Line segment */
offset-path: ray(45deg closest-side contain);
offset-path: ray(contain 150deg at center center);
offset-path: ray(45deg);
/* URL */
offset-path: url(#myCircle);
/* Basic shape */
offset-path: circle(50% at 25% 25%);
offset-path: ellipse(50% 50% at 25% 25%);
offset-path: inset(50% 50% 50% 50%);
offset-path: polygon(30% 0%, 70% 0%, 100% 50%, 30% 100%, 0% 70%, 0% 30%);
offset-path: path("M 0,200 Q 200,200 260,80 Q 290,20 400,0 Q 300,100 400,200");
offset-path: rect(5px 5px 160px 145px round 20%);
offset-path: xywh(0 5px 100% 75% round 15% 0);
/* Coordinate box */
offset-path: content-box;
offset-path: padding-box;
offset-path: border-box;
offset-path: fill-box;
offset-path: stroke-box;
offset-path: view-box;
/* Global values */
offset-path: inherit;
offset-path: initial;
offset-path: revert;
offset-path: revert-layer;
offset-path: unset;
```
### Values
The `offset-path` property takes as its value an `<offset-path>` value, a [`<coord-box>`](/en-US/docs/Web/CSS/box-edge#values) value, or both, or the `none` keyword. The `<offset-path>` value is a {{cssxref("ray","ray()")}} function, a {{cssxref("url","<url>")}} value, or a [`<basic-shape>`](/en-US/docs/Web/CSS/basic-shape) value.
- `none`
- : Specifies that the element does not follow any offset path. The `none` value is equivalent to the element not having any [offset transform](/en-US/docs/Web/CSS/offset). The element's movement in this case is determined by its default position properties, such as {{cssxref("top")}} and {{cssxref("left")}}, instead of an offset path. This is the default value.
- `<offset-path>`
- : A `ray()` function, a `<url>` value, or a `<basic-shape>` value that specifies the geometrical offset path. If omitted, the path shape for the `<coord-box>` value is `inset(0 round X)`, where `X` is the value of {{cssxref("border-radius")}} of the element that establishes the [containing block](/en-US/docs/Web/CSS/Containing_block).
- {{cssxref("ray","ray()")}}
- : Defines a line starting at a set position, of a set length, and extending at the specified angle. The `ray()` function accepts up to four parameters β an {{CSSxRef("angle")}}, an optional size value, the optional keyword `contain`, and an optional `at <position>`.
- {{cssxref("url","<url>")}}
- : Specifies the ID of an [SVG shape element](/en-US/docs/Web/SVG/Tutorial/Basic_Shapes). The path is the shape of the SVG {{SVGElement("circle")}}, {{SVGElement("ellipse")}}, {{SVGElement("line")}}, {{SVGElement("path")}}, {{SVGElement("polygon")}}, {{SVGElement("polyline")}}, or {{SVGElement("rect")}} element referenced by its `id` in the `url()` function. If the URL does not reference a shape element or is otherwise invalid, the resolved value for the offset path is `path("M0,0")` (which is a valid `<basic-shape>` value).
- {{cssxref("basic-shape")}}
- : Specifies the offset path as the equivalent path of a {{cssxref("basic-shape", "CSS basic shape function")}}, such as {{cssxref("basic-shape/circle","circle()")}}, {{cssxref("basic-shape/ellipse","ellipse()")}}, {{cssxref("basic-shape/inset","inset()")}}, {{cssxref("path","path()")}}, {{cssxref("basic-shape/polygon","polygon()")}}, {{cssxref("basic-shape/rect","rect()")}}, or {{cssxref("basic-shape/xywh","xywh()")}}. For example, if the `<basic_shape>` is an `ellipse()` function, then the path is the outline of the ellipse, starting at the rightmost point of the ellipse, proceeding clockwise through a full rotation. For `ellipse()` and `circle()`, which accept the `at <position>` parameter, if the `<position>` is omitted, the position defaults to `center` unless the element has an {{cssxref("offset-position")}} specified. In this case, the `offset-position` value is used for the `at <position>` parameter.
- [`<coord-box>`](/en-US/docs/Web/CSS/box-edge#values)
- : Specifies the size information of the [reference box](/en-US/docs/Web/CSS/CSS_shapes/Basic_shapes#the_reference_box) containing the path. The reference box is derived from the element that establishes the containing block for this element. This parameter is optional. If not specified, the default value is `border-box` in CSS contexts. In SVG contexts, the value is treated as `view-box`. If `ray()` or `<basic-shape>` is used to define the offset path, the `<coord-box>` value provides the reference box for the ray or the `<basic-shape>`, respectively. If `<url>` is used to define the offset path, the `<coord-box>` value provides the viewport and user coordinate system for the shape element, with the origin (`0 0`) at the top left corner and size being `1px`.
## Description
The `offset-path` property defines a path an animated element can follow. An offset path is either a specified path with one or multiple sub-paths or the geometry of a not-styled basic shape. The element's exact position on the offset path is determined by the {{cssxref("offset-distance")}} property. Each shape or path must define an initial position for the computed value of `0` for {{cssxref("offset-distance")}} and an initial direction which specifies the rotation of the object to the initial position.
Early versions of the spec called this property `motion-path`. It was changed to `offset-path` because the property describes static positions, not motion.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Creating an offset-path using box-edge positioning
This example demonstrates using various `<coord-box>` values in the `offset-path` property.
```html hidden
<div class="box blueBox"></div>
<div class="box redBox"></div>
<div class="box greenBox"></div>
```
```css hidden
body {
width: 300px;
height: 200px;
border-radius: 50px;
border: dashed aqua;
border-width: 25px;
padding: 25px;
margin: 50px;
}
```
```css
.box {
width: 40px;
height: 20px;
animation: move 8000ms infinite ease-in-out;
}
.blueBox {
background-color: blue;
offset-path: border-box;
offset-distance: 5%;
}
.greenBox {
background-color: green;
offset-path: padding-box;
offset-distance: 8%;
}
.redBox {
background-color: red;
offset-path: content-box;
offset-distance: 12%;
}
@keyframes move {
0%,
20% {
offset-distance: 0%;
}
80%,
100% {
offset-distance: 100%;
}
}
```
In this example, the margin, border, and padding have been purposely given large values to demonstrate the placement of the blue, green, and red rectangles on their respective `<coord-box>` edges: border-box, padding-box, and content-box.

#### Result
{{EmbedLiveSample('Creating an offset-path using box-edge positioning', '100%', 400)}}
### Creating an offset-path using path()
In this example, the {{svgelement("svg")}} element creates a house with a chimney and also defines two halves of a scissor. The house and chimney are composed of rectangles and polygons, and the scissor halves are represented by two distinct path elements. In the CSS code, the `offset-path` property is used to specify a path to follow for the two scissor halves. This CSS-defined path is identical to the one represented by the `<path>` element in the SVG, which is the outline of the house including the chimney.
```html live-sample___offset_path_path
<svg
xmlns="http://www.w3.org/2000/svg"
width="700"
height="450"
viewBox="350 0 1400 900">
<title>House and Scissors</title>
<rect x="595" y="423" width="610" height="377" fill="blue" />
<polygon points="506,423 900,190 1294,423" fill="yellow" />
<polygon points="993,245 993,190 1086,190 1086,300" fill="red" />
<path
id="house"
d="M900,190 L993,245 V201 A11,11 0 0,1 1004,190 H1075 A11,11 0 0,1 1086,201 V300 L1294,423 H1216 A11,11 0 0,0 1205,434 V789 A11,11 0 0,1 1194,800 H606 A11,11 0 0,1 595,789 V434 A11,11 0 0,0 584,423 H506 L900,190"
fill="none"
stroke="black"
stroke-width="13"
stroke-linejoin="round"
stroke-linecap="round" />
<path
id="firstScissorHalf"
class="scissorHalf"
d="M30,0 H-10 A10,10 0 0,0 -20,10 A20,20 0 1,1 -40,-10 H20 A10,10 0 0,1 30,0 M-40,20 A10,10 1 0,0 -40,0 A10,10 1 0,0 -40,20 M0,0"
transform="translate(0,0)"
fill="green"
stroke="black"
stroke-width="5"
stroke-linejoin="round"
stroke-linecap="round"
fill-rule="evenodd" />
<path
id="secondScissorHalf"
class="scissorHalf"
d="M30,0 H-10 A10,10 0 0,1 -20,-10 A20,20 0 1,0 -40,10 H20 A10,10 0 0,0 30,0 M-40,-20 A10,10 1 0,0 -40,0 A10,10 1 0,0 -40,-20 M0,0"
transform="translate(0,0)"
fill="forestgreen"
stroke="black"
stroke-width="5"
stroke-linejoin="round"
stroke-linecap="round"
fill-rule="evenodd" />
</svg>
```
```css live-sample___offset_path_path
.scissorHalf {
offset-path: path(
"M900,190 L993,245 V201 A11,11 0 0,1 1004,190 H1075 A11,11 0 0,1 1086,201 V300 L1294,423 H1216 A11,11 0 0,0 1205,434 V789 A11,11 0 0,1 1194,800 H606 A11,11 0 0,1 595,789 V434 A11,11 0 0,0 584,423 H506 L900,190"
);
animation: followpath 4s linear infinite;
}
@keyframes followpath {
to {
offset-distance: 100%;
}
}
```
#### Result
Without the `offset-path` property, the two halves of the scissors would default to the top-left corner of the canvas. However, by using `offset-path`, the two scissor halves are aligned with the starting point of the SVG path, allowing them to move along it.
{{EmbedLiveSample('offset_path_path', '100%', '450')}}
### Creating an offset-path using url()
This example illustrates how to refer to an SVG shape to define the shape of the path that an element can follow. The green circle (defined by `.target`) follows the path of a rectangle, which is defined by passing the SVG shape's ID (`svgRect`) to the `offset-path` property by using `url()`.
The SVG rectangle that defines the path shape is shown here only to visually demonstrate that the green circle is indeed following the path defined by this rectangle.
```html live-sample___offset_path_url
<div class="outer">
<div class="target"></div>
</div>
<svg width="400" height="200" xmlns="http://www.w3.org/2000/svg" >
<rect id="svgRect" x="50" y="50" width="200" height="100" />
</svg>
</div>
```
```css hidden live-sample___offset_path_url
.outer {
position: absolute;
}
```
```css live-sample___offset_path_url
.target {
width: 50px;
height: 50px;
border-radius: 50%;
background-color: green;
offset-path: url(#svgRect);
offset-anchor: auto;
animation: move 5s linear infinite;
}
#svgRect {
fill: antiquewhite;
stroke: black;
stroke-width: 2;
}
@keyframes move {
0% {
offset-distance: 0%;
}
100% {
offset-distance: 100%;
}
}
```
{{EmbedLiveSample('live-sample___offset_path_url', '100%', '250')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("offset")}}
- {{cssxref("offset-distance")}}
- {{cssxref("offset-rotate")}}
- [SVG \<path>](/en-US/docs/Web/SVG/Tutorial/Paths)
- {{cssxref("path","path()")}}
- Other demos:
- [Examples using various shapes values](https://codepen.io/team/css-tricks/pen/WZdKMq) on Codepen by CSS-Tricks
- [Moving a triangle along a curved path](https://codepen.io/ericwilligers/pen/jMbJPp) on Codepen by Eric Willigers
- [Moving a pair of scissors along the shape of a house](https://codepen.io/ericwilligers/pen/bwVZNa) on Codepen by Eric Willigers
- [Moving multiple pairs of eyes](https://jsfiddle.net/ericwilligers/r1snqdan/) on JSFiddle by Eric Willigers
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/css_paged_media/index.md | ---
title: CSS paged media
slug: Web/CSS/CSS_paged_media
page-type: css-module
spec-urls:
- https://drafts.csswg.org/css-page/
- https://drafts.csswg.org/css-break/
---
{{CSSRef}}
The **CSS paged media** module defines the properties that control the presentation of content for print or any other media that splits content into discrete pages. It allows you to set page breaks, control printable area, style left and right pages differently, and control breaks inside elements.
## Reference
### Properties
- {{cssxref("break-after")}}
- {{cssxref("break-before")}}
- {{cssxref("break-inside")}}
- {{cssxref("orphans")}}
- {{cssxref("widows")}}
### At-rules
- {{cssxref('@page')}}
### Pseudo-classes
- {{cssxref(':blank')}}
- {{cssxref(':first')}}
- {{cssxref(':left')}}
- {{cssxref(':right')}}
## Specifications
{{Specifications}}
## See also
- [Printing](/en-US/docs/Web/CSS/CSS_media_queries/Printing) guide
- [CSS media queries](/en-US/docs/Web/CSS/CSS_media_queries) module
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/mask-repeat/index.md | ---
title: mask-repeat
slug: Web/CSS/mask-repeat
page-type: css-property
browser-compat: css.properties.mask-repeat
---
{{CSSRef}}
The **`mask-repeat`** [CSS](/en-US/docs/Web/CSS) property sets how mask images are repeated. A mask image can be repeated along the horizontal axis, the vertical axis, both axes, or not repeated at all.
By default, the repeated images are clipped to the size of the element, but they can be scaled to fit (using `round`) or evenly distributed from end to end (using `space`).
## Syntax
```css
/* One-value syntax */
mask-repeat: repeat-x;
mask-repeat: repeat-y;
mask-repeat: repeat;
mask-repeat: space;
mask-repeat: round;
mask-repeat: no-repeat;
/* Two-value syntax: horizontal | vertical */
mask-repeat: repeat space;
mask-repeat: repeat repeat;
mask-repeat: round space;
mask-repeat: no-repeat round;
/* Multiple values */
mask-repeat:
space round,
no-repeat;
mask-repeat:
round repeat,
space,
repeat-x;
/* Global values */
mask-repeat: inherit;
mask-repeat: initial;
mask-repeat: revert;
mask-repeat: revert-layer;
mask-repeat: unset;
```
One or more `<repeat-style>` values, separated by commas.
### Values
- `<repeat-style>`
- : The one-value syntax is a shorthand for the full two-value syntax:
<table class="standard-table">
<thead>
<tr>
<th>Single value</th>
<th>Two-value equivalent</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>repeat-x</code></td>
<td><code>repeat no-repeat</code></td>
</tr>
<tr>
<td><code>repeat-y</code></td>
<td><code>no-repeat repeat</code></td>
</tr>
<tr>
<td><code>repeat</code></td>
<td><code>repeat repeat</code></td>
</tr>
<tr>
<td><code>space</code></td>
<td><code>space space</code></td>
</tr>
<tr>
<td><code>round</code></td>
<td><code>round round</code></td>
</tr>
<tr>
<td><code>no-repeat</code></td>
<td><code>no-repeat no-repeat</code></td>
</tr>
</tbody>
</table>
In the two-value syntax, the first value represents the horizontal repetition behavior and the second value represents the vertical behavior. Here is an explanation of how each option works for either direction:
<table class="standard-table">
<tbody>
<tr>
<td><code>repeat</code></td>
<td>
The image is repeated as much as needed to cover the whole mask painting
area. The last image will be clipped if it doesn't fit.
</td>
</tr>
<tr>
<td><code>space</code></td>
<td>
The image is repeated as much as possible without clipping. The first
and last images are pinned to either side of the element, and whitespace
is distributed evenly between the images. The
{{cssxref("mask-position")}} property is ignored unless only one
image can be displayed without clipping. The only case where clipping
happens using <code>space</code> is when there isn't enough room to
display one image.
</td>
</tr>
<tr>
<td><code>round</code></td>
<td>
As the allowed space increases in size, the repeated images will stretch
(leaving no gaps) until there is room for another one to be added. When
the next image is added, all of the current ones compress to allow room.
Example: An image with an original width of 260px, repeated three times,
might stretch until each repetition is 300px wide, and then another
image will be added. They will then compress to 225px.
</td>
</tr>
<tr>
<td><code>no-repeat</code></td>
<td>
The image is not repeated (and hence the mask painting area will not
necessarily be entirely covered). The position of the non-repeated mask
image is defined by the {{cssxref("mask-position")}} CSS
property.
</td>
</tr>
</tbody>
</table>
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting repeat for a single mask
{{EmbedGHLiveSample("css-examples/masking/mask-repeat.html", '100%', 700)}}
### Multiple mask image support
You can specify a different `<repeat-style>` for each mask image, separated by commas:
```css
.examplethree {
mask-image: url("mask1.png"), url("mask2.png");
mask-repeat: repeat-x, repeat-y;
}
```
Each image is matched with the corresponding repeat style, from first specified to last.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Clipping and Masking in CSS](https://css-tricks.com/clipping-masking-css/)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/css_flexible_box_layout/index.md | ---
title: CSS flexible box layout
slug: Web/CSS/CSS_flexible_box_layout
page-type: css-module
spec-urls: https://drafts.csswg.org/css-flexbox/
---
{{CSSRef}}
The **CSS flexible box layout** module defines a CSS box model optimized for user interface design, and the layout of items in one dimension. In the flex layout model, the children of a flex container can be laid out in any direction, and can "flex" their sizes, either growing to fill unused space or shrinking to avoid overflowing the parent. Both horizontal and vertical alignment of the children can be easily manipulated.
## Basic example
In the following example a container has been set to `display: flex`, which means that the three child items become flex items. The value of `justify-content` has been set to `space-between` in order to space the items out evenly on the main axis. An equal amount of space is placed between each item with the left and right items being flush with the edges of the flex container. You can also see that the items are stretching on the cross axis, due to the default value of `align-items` being `stretch`. The items stretch to the height of the flex container, making them each appear as tall as the tallest item.
{{EmbedGHLiveSample("css-examples/flexbox/basics/simple-example.html", '100%', 600)}}
## Reference
### Properties
- {{cssxref("flex")}}
- {{cssxref("flex-basis")}}
- {{cssxref("flex-direction")}}
- {{cssxref("flex-flow")}}
- {{cssxref("flex-grow")}}
- {{cssxref("flex-shrink")}}
- {{cssxref("flex-wrap")}}
- {{cssxref("order")}}
### Properties for alignment
The properties `align-content`, `align-self`, `align-items` and `justify-content` initially appeared in the Flexbox specification, but are now defined in Box Alignment. The Flexbox spec now refers to the Box Alignment specification for up to date definitions. Also additional alignment properties are now defined in Box Alignment.
- {{cssxref("justify-content")}}
- {{cssxref("align-content")}}
- {{cssxref("align-items")}}
- {{cssxref("align-self")}}
- {{cssxref("place-content")}}
- {{cssxref("place-items")}}
- {{cssxref("row-gap")}}
- {{cssxref("column-gap")}}
- {{cssxref("gap")}}
## Guides
- [Basic concepts of flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox)
- : An overview of the features of Flexbox
- [Relationship of flexbox to other layout methods](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Relationship_of_flexbox_to_other_layout_methods)
- : How Flexbox relates to other layout methods, and other CSS specifications
- [Aligning items in a flex container](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Aligning_items_in_a_flex_container)
- : How the Box Alignment properties work with Flexbox.
- [Ordering flex items](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Ordering_flex_items)
- : Explaining the different ways to change the order and direction of items, and covering the potential issues in doing so.
- [Controlling ratios of flex items along the main axis](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Controlling_ratios_of_flex_items_along_the_main_axis)
- : Explaining the flex-grow, flex-shrink and flex-basis properties.
- [Mastering wrapping of flex items](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Mastering_wrapping_of_flex_items)
- : How to create flex containers with multiple lines and control the display of the items in those lines.
- [Typical use cases of flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Typical_use_cases_of_flexbox)
- : Common design patterns that are typical Flexbox use cases.
## Specifications
{{Specifications}}
## See also
- [CSS display](/en-US/docs/Web/CSS/CSS_display) module
- [Using the multi-keyword syntax with CSS display](/en-US/docs/Web/CSS/display/multi-keyword_syntax_of_display)
- Glossary terms:
- {{Glossary("Flexbox")}}
- {{Glossary("Flex Container")}}
- {{Glossary("Flex Item")}}
- {{Glossary("Main Axis")}}
- {{Glossary("Cross Axis")}}
- {{Glossary("Flex")}}
| 0 |
data/mdn-content/files/en-us/web/css/css_flexible_box_layout | data/mdn-content/files/en-us/web/css/css_flexible_box_layout/basic_concepts_of_flexbox/basics7.svg | <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" width="2041.742" height="797.663" stroke-miterlimit="10" style="fill-rule:nonzero;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round" viewBox="0 0 1531.5 598.322">
<defs>
<path id="a" d="M39.974 139.907H1459.03v279.815H39.974z" />
</defs>
<path fill="#fff" d="M0 0h1531.5v598.322H0z" />
<path fill="#4f79eb" stroke="#000" stroke-linecap="butt" stroke-width="2" d="M39.974 139.907h279.814v279.815H39.974z" /><text fill="#fff" font-family="Helvetica" font-size="128" transform="translate(145.667 185.775)">
<tspan x="0" y="124" textLength="71.188">a</tspan>
</text>
<path fill="#4f79eb" stroke="#000" stroke-linecap="butt" stroke-width="2" d="M319.788 139.907h279.814v279.815H319.788z" /><text fill="#fff" font-family="Helvetica" font-size="128" transform="translate(425.481 185.775)">
<tspan x="0" y="124" textLength="71.188">b</tspan>
</text>
<path fill="#4f79eb" stroke="#000" stroke-linecap="butt" stroke-width="2" d="M599.602 139.907h279.815v279.815H599.602z" /><text fill="#fff" font-family="Helvetica" font-size="128" transform="translate(705.296 185.775)">
<tspan x="0" y="124" textLength="64">c</tspan>
</text>
<mask id="b" width="1425.06" height="285.815" x="36.974" y="136.907" maskUnits="userSpaceOnUse">
<path fill="#fff" d="M36.974 136.907h1425.06v285.815H36.974z" />
<use xlink:href="#a" fill-rule="evenodd" />
</mask>
<use xlink:href="#a" fill="none" stroke="#000" stroke-dasharray="8" stroke-linecap="butt" stroke-width="6" mask="url(#b)" /><text font-family="Helvetica" font-size="48" transform="translate(439.708 21.625)">
<tspan x="40.301" y="47" textLength="519">Container width = 500px</tspan>
</text><text font-family="Helvetica" font-size="48" transform="translate(919.391 501.307)">
<tspan x="110.086" y="47" textLength="379.43">Available = 200px</tspan>
</text>
<path fill="none" stroke="#000" stroke-linecap="butt" stroke-width="5" d="M1441.5 99.934H57.493" />
<path d="m61.868 99.934 13.125-17.5-35 17.5 35 17.5zM1437.12 99.934l-13.12 17.5 35-17.5-35-17.5z" />
<path fill="none" stroke="#000" stroke-linecap="butt" stroke-width="5" d="M1441.51 459.695H896.92" />
<path d="m901.295 459.695 13.125-17.5-35 17.5 35 17.5zM1437.13 459.695l-13.12 17.5 35-17.5-35-17.5z" />
</svg> | 0 |
data/mdn-content/files/en-us/web/css/css_flexible_box_layout | data/mdn-content/files/en-us/web/css/css_flexible_box_layout/basic_concepts_of_flexbox/index.md | ---
title: Basic concepts of flexbox
slug: Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox
page-type: guide
---
{{CSSRef}}
The flexible box layout module, usually referred to as flexbox, was designed as a one-dimensional layout model, and as a method that could offer space distribution between items in an interface and powerful alignment capabilities. This article gives an outline of the main features of flexbox, which we will be exploring in more detail in the rest of these guides.
When we describe flexbox as being one-dimensional we are describing the fact that flexbox deals with layout in one dimension at a time β either as a row or as a column. This can be contrasted with the two-dimensional model of [CSS Grid Layout](/en-US/docs/Web/CSS/CSS_grid_layout), which controls columns and rows together.
## The two axes of flexbox
When working with flexbox you need to think in terms of two axes β the main axis and the cross axis. The main axis is defined by the {{cssxref("flex-direction")}} property, and the cross axis runs perpendicular to it. Everything we do with flexbox refers back to these axes, so it is worth understanding how they work from the outset.
### The main axis
The main axis is defined by `flex-direction`, which has four possible values:
- `row`
- `row-reverse`
- `column`
- `column-reverse`
Should you choose `row` or `row-reverse`, your main axis will run along the row in the **inline direction**.

Choose `column` or `column-reverse` and your main axis will run from the top of the page to the bottom β in the **block direction**.

### The cross axis
The cross axis runs perpendicular to the main axis, therefore if your `flex-direction` (main axis) is set to `row` or `row-reverse` the cross axis runs down the columns.

If your main axis is `column` or `column-reverse` then the cross axis runs along the rows.

## Start and end lines
Another vital area of understanding is how flexbox makes no assumption about the writing mode of the document. In the past, CSS was heavily weighted towards horizontal and left-to-right writing modes. Modern layout methods encompass the range of writing modes and so we no longer assume that a line of text will start at the top left of a document and run towards the right-hand side, with new lines appearing one under the other.
You can [read more about the relationship between flexbox and the Writing Modes specification](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Relationship_of_flexbox_to_other_layout_methods#writing_modes) in a later article; however, the following description should help explain why we do not talk about left and right and top and bottom when we describe the direction that our flex items flow in.
If the `flex-direction` is `row` and I am working in English, then the start edge of the main axis will be on the left, the end edge on the right.

If I were to work in Arabic, then the start edge of my main axis would be on the right and the end edge on the left.

In both cases the start edge of the cross-axis is at the top of the flex container and the end edge at the bottom, as both languages have a horizontal writing mode.
After a while, thinking about start and end rather than left and right becomes natural, and will be useful to you when dealing with other layout methods such as CSS Grid Layout which follow the same patterns.
## The flex container
An area of a document that is laid out using flexbox is called a **flex container**. To create a flex container, set the area's {{cssxref("display")}} property to `flex`. When we do this, the direct children of that container become **flex items**. You can explicitly control whether the container itself is displayed inline or in block formatting context using `inline flex` or `inline-flex` for inline flex containers or `block flex` or `flex` for block level flex containers.
As with all properties in CSS, some initial values are defined, so the contents of a new flex container will behave in the following way:
- Items display in a row (the `flex-direction` property's default is `row`).
- The items start from the start edge of the main axis.
- The items do not stretch on the main dimension but can shrink.
- The items will stretch to fill the size of the cross-axis.
- The {{cssxref("flex-basis")}} property is set to `auto`. This means that, in each case, it will be equal to the flex item {{cssxref("width")}} in horizontal writing mode, and the flex item {{cssxref("height")}} in vertical writing mode. If the corresponding `width`/`height` is also set to `auto`, the `flex-basis` content value is used instead.
- The {{cssxref("flex-wrap")}} property is set to `nowrap`. This means that the flex items will always remain in a single row or column, overflowing their container if their combined `width`/`height` exceeds the containing element `width`/`height`.
The result of this is that your items will all line up in a row, using the size of the content as their size in the main axis. If there are more items than can fit in the container, they will not wrap but will instead overflow. If some items are taller than others, all items will stretch along the full length of the cross-axis.
You can see in the live example below how this looks. Try editing the items or adding additional items to test the initial behavior of flexbox.
{{EmbedGHLiveSample("css-examples/flexbox/basics/the-flex-container.html", '100%', 480)}}
### Changing flex-direction
Adding the {{cssxref("flex-direction")}} property to the flex container allows us to change the direction in which our flex items display. Setting `flex-direction: row-reverse` will keep the items displaying along the row, however the start and end lines are switched.
If we change `flex-direction` to `column` the main axis switches and our items now display in a column. Set `column-reverse` and the start and end lines are again switched.
The live example below has `flex-direction` set to `row-reverse`. Try the other values β `row`, `column` and `column-reverse` β to see what happens to the content.
{{EmbedGHLiveSample("css-examples/flexbox/basics/flex-direction.html", '100%', 350)}}
## Multi-line flex containers with flex-wrap
While flexbox is a one dimensional model, it is possible to cause our flex items to wrap onto multiple lines. In doing so, you should consider each line as a new flex container. Any space distribution will happen across that line, without reference to the lines on either side.
To cause wrapping behavior add the property {{cssxref("flex-wrap")}} with a value of `wrap`. Now, should your items be too large to all display in one line, they will wrap onto another line. The live sample below contains items that have been given a width, the total width of the items being too wide for the flex container. As `flex-wrap` is set to `wrap`, the items wrap. Set it to `nowrap`, which is also the initial value, and they will instead shrink to fit the container because they are using initial flexbox values that allows items to shrink. Using `nowrap` would cause an overflow if the items were not able to shrink, or could not shrink small enough to fit.
{{EmbedGHLiveSample("css-examples/flexbox/basics/flex-wrap.html", '100%', 400)}}
Find out more about wrapping flex items in the guide [Mastering Wrapping of Flex Items](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Mastering_wrapping_of_flex_items).
## The flex-flow shorthand
You can combine the two properties `flex-direction` and `flex-wrap` into the {{cssxref("flex-flow")}} shorthand. The first value specified is `flex-direction` and the second value is `flex-wrap`.
In the live example below try changing the first value to one of the allowable values for `flex-direction` - `row`, `row-reverse`, `column` or `column-reverse`, and also change the second to `wrap` and `nowrap`.
{{EmbedGHLiveSample("css-examples/flexbox/basics/flex-flow.html", '100%', 400)}}
## Properties applied to flex items
To have more control over flex items we can target them directly. We do this by way of three properties:
- {{cssxref("flex-grow")}}
- {{cssxref("flex-shrink")}}
- {{cssxref("flex-basis")}}
We will take a brief look at these properties in this overview, and you can gain a fuller understanding in the guide [Controlling Ratios of Flex Items on the Main Axis](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Controlling_ratios_of_flex_items_along_the_main_axis).
Before we can make sense of these properties we need to consider the concept of **available space**. What we are doing when we change the value of these flex properties is to change the way that available space is distributed amongst our items. This concept of available space is also important when we come to look at aligning items.
If we have three 100 pixel-wide items in a container which is 500 pixels wide, then the space we need to lay out our items is 300 pixels. This leaves 200 pixels of available space. If we don't change the initial values then flexbox will put that space after the last item.

If we instead would like the items to grow and fill the space, then we need to have a method of distributing the leftover space between the items. This is what the `flex` properties that we apply to the items themselves, will do.
### The flex-basis property
The `flex-basis` is what defines the size of that item in terms of the space it leaves as available space. The initial value of this property is `auto` β in this case the browser looks to see if the items have a size. In the example above, all of the items have a width of 100 pixels and so this is used as the `flex-basis`.
If the items don't have a size then the content's size is used as the flex-basis. This is why when we just declare `display: flex` on the parent to create flex items, the items all move into a row and take only as much space as they need to display their contents.
### The flex-grow property
With the `flex-grow` property set to a positive integer, flex items can grow along the main axis from their `flex-basis`. This will cause the item to stretch and take up any available space on that axis, or a proportion of the available space if other items are allowed to grow too.
If we gave all of our items in the example above a `flex-grow` value of 1 then the available space in the flex container would be equally shared between our items and they would stretch to fill the container on the main axis.
The flex-grow property can be used to distribute space in proportion. If we give our first item a `flex-grow` value of 2, and the other items a value of 1 each, 2 parts of the available space will be given to the first item (100px out of 200px in the case of the example above), 1 part each the other two (50px each out of the 200px total).
### The flex-shrink property
Where the `flex-grow` property deals with adding space in the main axis, the `flex-shrink` property controls how it is taken away. If we do not have enough space in the container to lay out our items, and `flex-shrink` is set to a positive integer, then the item can become smaller than the `flex-basis`. As with `flex-grow`, different values can be assigned in order to cause one item to shrink faster than others β an item with a higher value set for `flex-shrink` will shrink faster than its siblings that have lower values.
The minimum size of the item will be taken into account while working out the actual amount of shrinkage that will happen, which means that flex-shrink has the potential to appear less consistent than flex-grow in behavior. We'll therefore take a more detailed look at how this algorithm works in the article [Controlling Ratios of items along the main axis](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Controlling_ratios_of_flex_items_along_the_main_axis).
> **Note:** These values for `flex-grow` and `flex-shrink` are proportions. Typically if we had all of our items set to `flex: 1 1 200px` and then wanted one item to grow at twice the rate, we would set that item to `flex: 2 1 200px`. However you could also use `flex: 10 1 200px` and `flex: 20 1 200px` if you wanted.
### Shorthand values for the flex properties
You will very rarely see the `flex-grow`, `flex-shrink`, and `flex-basis` properties used individually; instead they are combined into the {{cssxref("flex")}} shorthand. The `flex` shorthand allows you to set the three values in this order β `flex-grow`, `flex-shrink`, `flex-basis`.
The live example below allows you to test out the different values of the flex shorthand; remember that the first value is `flex-grow`. Giving this a positive value means the item can grow. The second is `flex-shrink` β with a positive value the items can shrink, but only if their total values overflow the main axis. The final value is `flex-basis`; this is the value the items are using as their base value to grow and shrink from.
{{EmbedGHLiveSample("css-examples/flexbox/basics/flex-properties.html", '100%', 510)}}
There are also some predefined shorthand values which cover most of the use cases. You will often see these used in tutorials, and in many cases these are all you will need to use. The predefined values are as follows:
- `flex: initial`
- `flex: auto`
- `flex: none`
- `flex: <positive-number>`
Setting `flex: initial` resets the item to the initial values of flexbox. This is the same as `flex: 0 1 auto`. In this case the value of `flex-grow` is 0, so items will not grow larger than their `flex-basis` size. The value of `flex-shrink` is 1, so items can shrink if they need to rather than overflowing. The value of `flex-basis` is `auto`. Items will either use any size set on the item in the main dimension, or they will get their size from the content size.
Using `flex: auto` is the same as using `flex: 1 1 auto`; everything is as with `flex:initial` but in this case the items can grow and fill the container as well as shrink if required.
Using `flex: none` will create fully inflexible flex items. It is as if you wrote `flex: 0 0 auto`. The items cannot grow or shrink but will be laid out using flexbox with a `flex-basis` of `auto`.
The shorthand you often see in tutorials is `flex: 1` or `flex: 2` and so on. This is as if you used `flex: 1 1 0` or `flex: 2 1 0` and so on, respectively. The items can grow and shrink from a `flex-basis` of 0.
Try these shorthand values in the live example below.
{{EmbedGHLiveSample("css-examples/flexbox/basics/flex-shorthands.html", '100%', 510)}}
## Alignment, justification and distribution of free space between items
A key feature of flexbox is the ability to align and justify items on the main- and cross-axes, and to distribute space between flex items. Note that these properties are to be set on the flex container, not on the items themselves.
### align-items
The {{cssxref("align-items")}} property will align the items on the cross axis.
The initial value for this property is `stretch` and this is why flex items stretch to the height of the flex container by default. This might be dictated by the height of the tallest item in the container, or by a size set on the flex container itself.
You could instead set `align-items` to `flex-start` in order to make the items line up at the start of the flex container, `flex-end` to align them to the end, or `center` to align them in the center. Try this in the live example β I have given the flex container a height in order that you can see how the items can be moved around inside the container. See what happens if you set the value of align-items to:
- `stretch`
- `flex-start`
- `flex-end`
- `center`
{{EmbedGHLiveSample("css-examples/flexbox/basics/align-items.html", '100%', 520)}}
### justify-content
The {{cssxref("justify-content")}} property is used to align the items on the main axis, the direction in which `flex-direction` has set the flow. The initial value is `flex-start` which will line the items up at the start edge of the container, but you could also set the value to `flex-end` to line them up at the end, or `center` to line them up in the center.
You can also use the value `space-between` to take all the spare space after the items have been laid out, and share it out evenly between the items so there will be an equal amount of space between each item. To cause an equal amount of space on the right and left of each item use the value `space-around`. With `space-around`, items have a half-size space on either end. Or, to cause items to have equal space around them use the value `space-evenly`. With `space-evenly`, items have a full-size space on either end.
Try the following values of `justify-content` in the live example:
- `flex-start`
- `flex-end`
- `center`
- `space-around`
- `space-between`
- `space-evenly`
{{EmbedGHLiveSample("css-examples/flexbox/basics/justify-content.html", '100%', 380)}}
In the article [Aligning Items in a Flex Container](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Aligning_items_in_a_flex_container) we will explore these properties in more depth, in order to have a better understanding of how they work. These simple examples however will be useful in the majority of use cases.
### justify-items
The [`justify-items`](/en-US/docs/Web/CSS/justify-items) property is ignored in flexbox layouts.
## Next steps
After reading this article you should have an understanding of the basic features of flexbox. In the next article, we will look at [how this specification relates to other parts of CSS](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Relationship_of_flexbox_to_other_layout_methods).
| 0 |
data/mdn-content/files/en-us/web/css/css_flexible_box_layout | data/mdn-content/files/en-us/web/css/css_flexible_box_layout/basic_concepts_of_flexbox/basics6.svg | <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" width="1465.767" height="455.011" stroke-miterlimit="10" style="fill-rule:nonzero;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round" viewBox="0 0 1099.46 341.301">
<defs>
<path id="a" d="M139.907 119.921h859.43v159.894h-859.43z" />
</defs>
<path fill="#fff" d="M0 0h1099.46v341.301H0z" />
<path fill="#4f79eb" d="M859.43 139.907h119.921v119.921H859.43zM579.616 139.907h119.92v119.921h-119.92z" /><text fill="#fff" font-family="Helvetica" font-size="60" transform="translate(622.746 159.89)">
<tspan x="0" y="54" font-family="GeezaPro" textLength="35.045">Ψ¬</tspan>
</text><text fill="#fff" font-family="Helvetica" font-size="60" transform="translate(903.008 159.894)">
<tspan x="0" y="54" font-family="GeezaPro" textLength="17.55">Ψ§</tspan>
</text>
<path fill="#4f79eb" d="M719.523 139.907h119.921v119.921H719.523z" /><text fill="#fff" font-family="Helvetica" font-size="60" transform="translate(766.47 159.894)">
<tspan x="0" y="54" font-family="GeezaPro" textLength="38.382">Ψ¨</tspan>
</text>
<mask id="b" width="865.43" height="165.894" x="136.907" y="116.921" maskUnits="userSpaceOnUse">
<path fill="#fff" d="M136.907 116.921h865.43v165.894h-865.43z" />
<use xlink:href="#a" fill-rule="evenodd" />
</mask>
<use xlink:href="#a" fill="none" stroke="#000" stroke-dasharray="4" stroke-linecap="butt" stroke-width="6" mask="url(#b)" />
<path fill="none" stroke="#000" stroke-linecap="butt" stroke-width="2" d="M981.319 59.96H839.444" />
<path d="m978.319 66.96 12-7-12-7z" /><text font-family="Helvetica" font-size="33" transform="translate(279.814 39.974)">
<tspan x="55.249" y="32" textLength="452.977">Main Axis - flex-direction: row</tspan>
</text>
<path fill="none" stroke="#000" stroke-linecap="butt" stroke-width="2" d="m159.885 60.316 159.902-.626" />
<path d="m162.858 53.304-11.973 7.047 12.027 6.953z" /><text font-family="Helvetica" font-size="33" transform="translate(47.23 179.881)">
<tspan x="0" y="32" textLength="58.717">End</tspan>
</text><text font-family="Helvetica" font-size="33" transform="translate(1017.57 179.854)">
<tspan x="0" y="32" textLength="69.69">Start</tspan>
</text>
</svg> | 0 |
data/mdn-content/files/en-us/web/css/css_flexible_box_layout | data/mdn-content/files/en-us/web/css/css_flexible_box_layout/basic_concepts_of_flexbox/basics3.svg | <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" width="450mm" height="347.782" stroke-miterlimit="10" style="fill-rule:nonzero;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round" viewBox="0 0 1275.75 260.869">
<defs>
<path id="a" d="M300.249 59.965h839.441v159.894H300.249z" />
</defs>
<path fill="#fff" d="M0 0h1275.75v260.869H0z" />
<path fill="#4f79eb" d="M320.235 79.951h119.921v119.921H320.235z" /><text fill="#fff" font-family="Helvetica" font-size="60" transform="translate(363.366 99.934)">
<tspan x="0" y="58" textLength="33.369">a</tspan>
</text>
<path fill="#4f79eb" d="M460.143 79.951h119.92v119.921h-119.92z" /><text fill="#fff" font-family="Helvetica" font-size="60" transform="translate(507.09 99.938)">
<tspan x="0" y="58" textLength="33.369">b</tspan>
</text>
<path fill="#4f79eb" d="M600.05 79.951h119.92v119.921H600.05z" /><text fill="#fff" font-family="Helvetica" font-size="60" transform="translate(646.997 99.938)">
<tspan x="0" y="58" textLength="30">c</tspan>
</text>
<mask id="b" width="845.444" height="165.894" x="297.249" y="56.965" maskUnits="userSpaceOnUse">
<path fill="#fff" d="M297.249 56.965h845.444v165.894H297.249z" />
<use xlink:href="#a" fill-rule="evenodd" />
</mask>
<use xlink:href="#a" fill="none" stroke="#000" stroke-dasharray="4" stroke-linecap="butt" stroke-width="6" mask="url(#b)" /><text font-family="Helvetica" font-size="24" transform="translate(80.23 116.802)">
<tspan x="85.688" y="23" textLength="113.367">Cross Axis
</tspan>
<tspan x="3" y="52" textLength="196.055">Flex-direction: row</tspan>
</text>
<path fill="none" stroke="#000" stroke-linecap="butt" stroke-width="2" d="m280.37 68.96-.108 30.978" />
<path d="m287.359 71.985-6.958-12.024-7.042 11.975z" />
<path fill="none" stroke="#000" stroke-linecap="butt" stroke-width="2" d="m280.139 216.808.123-30.966" />
<path d="m273.151 213.78 6.952 12.028 7.048-11.972z" />
</svg> | 0 |
data/mdn-content/files/en-us/web/css/css_flexible_box_layout | data/mdn-content/files/en-us/web/css/css_flexible_box_layout/basic_concepts_of_flexbox/basics5.svg | <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" width="1465.767" height="455.011" stroke-miterlimit="10" style="fill-rule:nonzero;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round" viewBox="0 0 1099.46 341.301">
<defs>
<path id="a" d="M150.88 119.921h839.444v159.894H150.88z" />
</defs>
<path fill="#fff" d="M0 0h1099.46v341.301H0z" />
<path fill="#4f79eb" d="M170.867 139.907h119.921v119.921H170.867z" /><text fill="#fff" font-family="Helvetica" font-size="60" transform="translate(213.998 159.89)">
<tspan x="0" y="58" textLength="33.369">a</tspan>
</text>
<path fill="#4f79eb" d="M310.774 139.907h119.921v119.921H310.774z" /><text fill="#fff" font-family="Helvetica" font-size="60" transform="translate(357.721 159.894)">
<tspan x="0" y="58" textLength="33.369">b</tspan>
</text>
<path fill="#4f79eb" d="M450.682 139.907h119.92v119.921h-119.92z" /><text fill="#fff" font-family="Helvetica" font-size="60" transform="translate(497.629 159.894)">
<tspan x="0" y="58" textLength="30">c</tspan>
</text>
<mask id="b" width="845.444" height="165.894" x="147.88" y="116.921" maskUnits="userSpaceOnUse">
<path fill="#fff" d="M147.88 116.921h845.444v165.894H147.88z" />
<use xlink:href="#a" fill-rule="evenodd" />
</mask>
<use xlink:href="#a" fill="none" stroke="#000" stroke-dasharray="4" stroke-linecap="butt" stroke-width="6" mask="url(#b)" />
<path fill="none" stroke="#000" stroke-linecap="butt" stroke-width="2" d="M981.319 59.96H839.444" />
<path d="m978.319 66.96 12-7-12-7z" /><text font-family="Helvetica" font-size="33" transform="translate(279.814 39.974)">
<tspan x="55.249" y="32" textLength="452.977">Main Axis - flex-direction: row</tspan>
</text>
<path fill="none" stroke="#000" stroke-linecap="butt" stroke-width="2" d="m159.885 60.316 159.902-.626" />
<path d="m162.858 53.304-11.973 7.047 12.027 6.953z" /><text font-family="Helvetica" font-size="33" transform="translate(47.23 179.881)">
<tspan x="0" y="32" textLength="69.69">Start</tspan>
</text><text font-family="Helvetica" font-size="33" transform="translate(1017.57 179.854)">
<tspan x="0" y="32" textLength="58.717">End</tspan>
</text>
</svg> | 0 |
data/mdn-content/files/en-us/web/css/css_flexible_box_layout | data/mdn-content/files/en-us/web/css/css_flexible_box_layout/basic_concepts_of_flexbox/basics1.svg | <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" width="1225.324" height="347.782" stroke-miterlimit="10" style="fill-rule:nonzero;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round" viewBox="0 0 919.108 260.869">
<defs>
<path id="a" d="M39.974 79.947h839.443v139.907H39.973z" />
</defs>
<path fill="#fff" d="M0 0h919.108v260.869H0z" />
<path fill="#4f79eb" d="M59.96 99.934h119.921v99.933H59.961z" /><text fill="#fff" font-family="Helvetica" font-size="60" transform="translate(103.538 107.881)">
<tspan x="0" y="58" textLength="33.369">a</tspan>
</text>
<path fill="#4f79eb" d="M199.868 99.934h119.92v99.933h-119.92z" /><text fill="#fff" font-family="Helvetica" font-size="60" transform="translate(243.445 107.881)">
<tspan x="0" y="58" textLength="33.369">b</tspan>
</text>
<path fill="#4f79eb" d="M339.775 99.934h119.92v99.933h-119.92z" /><text fill="#fff" font-family="Helvetica" font-size="60" transform="translate(383.353 107.881)">
<tspan x="0" y="58" textLength="30">c</tspan>
</text>
<path fill="none" stroke="#000" stroke-linecap="butt" stroke-width="2" d="M870.417 59.677H699.536" />
<path d="m867.417 66.677 12-7-12-7z" />
<mask id="b" width="845.444" height="145.907" x="36.974" y="76.947" maskUnits="userSpaceOnUse">
<path fill="#fff" d="M36.974 76.947h845.444v145.907H36.974z" />
<use xlink:href="#a" fill-rule="evenodd" />
</mask>
<use xlink:href="#a" fill="none" stroke="#000" stroke-dasharray="4" stroke-linecap="butt" stroke-width="6" mask="url(#b)" /><text font-family="Helvetica" font-size="33" transform="translate(239.841 39.69)">
<tspan x="0" y="32" textLength="452.977">Main Axis - flex-direction: row</tspan>
</text>
<path fill="none" stroke="#000" stroke-linecap="butt" stroke-width="2" d="m48.975 60.033 170.878-.669" />
<path d="m51.947 53.02-11.973 7.048 12.028 6.953z" />
</svg> | 0 |
data/mdn-content/files/en-us/web/css/css_flexible_box_layout | data/mdn-content/files/en-us/web/css/css_flexible_box_layout/basic_concepts_of_flexbox/basics4.svg | <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" width="1307.569" height="667.73" stroke-miterlimit="10" style="fill-rule:nonzero;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round" viewBox="0 0 980.8 500.86">
<defs>
<path id="a" d="M39.974 80.23h899.403V459.98H39.974z" />
</defs>
<path fill="#fff" d="M0 0h980.8v500.86H0z" />
<path fill="#4f79eb" d="M59.96 100.217h859.43v99.934H59.96z" /><text fill="#fff" font-family="Helvetica" font-size="60" transform="translate(454.126 100.217)">
<tspan x="23.289" y="58" textLength="33.369">a</tspan>
</text>
<path fill="#4f79eb" d="M59.96 220.138h859.43v99.934H59.96z" /><text fill="#fff" font-family="Helvetica" font-size="60" transform="translate(474.113 220.138)">
<tspan x="6.087" y="58" textLength="33.369">b</tspan>
</text>
<path fill="#4f79eb" d="M59.96 340.058h859.43v99.934H59.96z" /><text fill="#fff" font-family="Helvetica" font-size="60" transform="translate(454.126 340.058)">
<tspan x="27.758" y="58" textLength="30">c</tspan>
</text>
<mask id="b" width="905.404" height="385.748" x="36.974" y="77.231" maskUnits="userSpaceOnUse">
<path fill="#fff" d="M36.974 77.231h905.404v385.748H36.974z" />
<use xlink:href="#a" fill-rule="evenodd" />
</mask>
<use xlink:href="#a" fill="none" stroke="#000" stroke-dasharray="4" stroke-linecap="butt" stroke-width="6" mask="url(#b)" />
<path fill="none" stroke="#000" stroke-linecap="butt" stroke-width="2" d="M930.377 39.974H759.496" />
<path d="m927.377 46.974 12-7-12-7z" /><text font-family="Helvetica" font-size="33" transform="translate(219.854 19.987)">
<tspan x="0" y="32" textLength="515.351">Cross Axis - flex-direction: column</tspan>
</text>
<path fill="none" stroke="#000" stroke-linecap="butt" stroke-width="2" d="M48.978 40.33c14.029-.056 150.889-.591 150.889-.591" />
<path d="m51.95 33.318-11.972 7.046 12.027 6.953z" />
</svg> | 0 |
data/mdn-content/files/en-us/web/css/css_flexible_box_layout | data/mdn-content/files/en-us/web/css/css_flexible_box_layout/basic_concepts_of_flexbox/basics2.svg | <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" width="500.2mm" height="612.185" stroke-miterlimit="10" style="fill-rule:nonzero;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round" viewBox="0 0 1418.07 459.196">
<defs>
<path id="a" d="M359.762 39.974h899.408v379.748H359.762z" />
</defs>
<path fill="#fff" d="M0 0h1418.07v459.196H0z" />
<path fill="#4f79eb" d="M379.748 59.96h859.432v99.934H379.748z" /><text fill="#fff" font-family="Helvetica" font-size="60" transform="translate(773.914 59.96)">
<tspan x="23.289" y="58" textLength="33.369">a</tspan>
</text>
<path fill="#4f79eb" d="M379.748 179.881h859.432v99.934H379.748z" /><text fill="#fff" font-family="Helvetica" font-size="60" transform="translate(793.901 179.881)">
<tspan x="6.087" y="58" textLength="33.369">b</tspan>
</text>
<path fill="#4f79eb" d="M379.748 299.801h859.432v99.934H379.748z" /><text fill="#fff" font-family="Helvetica" font-size="60" transform="translate(773.914 299.801)">
<tspan x="27.758" y="58" textLength="30">c</tspan>
</text>
<mask id="b" width="905.404" height="385.748" x="356.762" y="36.974" maskUnits="userSpaceOnUse">
<path fill="#fff" d="M356.762 36.974h905.404v385.748H356.762z" />
<use xlink:href="#a" fill-rule="evenodd" />
</mask>
<use xlink:href="#a" fill="none" stroke="#000" stroke-dasharray="4" stroke-linecap="butt" stroke-width="6" mask="url(#b)" />
<path fill="none" stroke="#000" stroke-linecap="butt" stroke-width="2" d="m319.757 48.982-.388 110.911" />
<path d="m326.746 52.006-6.958-12.024-7.042 11.975z" />
<path fill="none" stroke="#000" stroke-linecap="butt" stroke-width="2" d="m319.795 410.712.44-110.911" />
<path d="m312.807 407.684 6.952 12.028 7.048-11.972z" /><text font-family="Helvetica" font-size="30" transform="translate(19.987 199.868)">
<tspan x="159.738" y="29" textLength="126.709">Main axis
</tspan>
<tspan x="3" y="65" textLength="300.132">flex-direction: column</tspan>
</text>
</svg> | 0 |
data/mdn-content/files/en-us/web/css/css_flexible_box_layout | data/mdn-content/files/en-us/web/css/css_flexible_box_layout/typical_use_cases_of_flexbox/index.md | ---
title: Typical use cases of flexbox
slug: Web/CSS/CSS_flexible_box_layout/Typical_use_cases_of_flexbox
page-type: guide
---
{{CSSRef}}
In this guide, we will take a look at some of the common use cases for flexbox β those places where it makes more sense than another layout method.
## Why choose flexbox?
In a perfect world of browser support, the reason you'd choose to use flexbox is because you want to lay a collection of items out in one direction or another. As you lay out your items you want to control the dimensions of the items in that one dimension, or control the spacing between items. These are the uses that flexbox was designed for. You can read more about the difference between flexbox and CSS Grid Layout in [Relationship of Flexbox to other layout methods](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Relationship_of_flexbox_to_other_layout_methods), where we discuss how flexbox fits into the overall picture of CSS Layout.
In reality we also often use Flexbox for jobs that might be better done by Grid Layout, as a fallback for Grid, and also in order to get alignment capabilities. This is something that may well change once Box Alignment is implemented in Block Layout. In this guide we'll look at some of the typical things you might use flexbox for today.
## Navigation
A common pattern for navigation is to have a list of items displayed as a horizontal bar. This pattern, as basic as it seems, was difficult to achieve before flexbox. It forms the most simple of flexbox examples, and could be considered the ideal flexbox use case.
When we have a set of items that we want to display horizontally, we may well end up with additional space. We need to decide what to do with that space, and have a couple of options. We either display the space outside of the items β therefore spacing them out with white space between or around them β or we absorb the extra space inside the items and therefore need a method of allowing the items to grow and take up this space.
### Space distributed outside the items
To distribute the space between or around the items, we use the alignment properties in flexbox, and the {{cssxref("justify-content")}} property. You can read more about this property in [Aligning Items in a flex container](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Aligning_items_in_a_flex_container), which deals with aligning items on the main axis.
In the below live example we display the items at their natural size and by using `justify-content: space-between` make equal amounts of space between the items. You can change how the space is distributed using the `space-around` value, or where supported, `space-evenly`. You could also use `flex-start` to place the space at the end of the items, `flex-end` to place it before them, or `center` to center the navigation items.
{{EmbedGHLiveSample("css-examples/flexbox/use-cases/navigation.html", '100%', 550)}}
### Space distributed within the items
A different pattern for navigation would be to distribute the available space within the items themselves, rather than create space between them. In this case we would use the {{cssxref("flex")}} properties to allow items to grow and shrink in proportion to one another as described in [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).
If you wanted to respect the size property of my navigation items but have the available space shared out equally among them, then you might use `flex: auto`, which is the shorthand for `flex: 1 1 auto` β all items grow and shrink from a flex-basis of auto. This would mean that the longer item would have more space because it started from a larger size, even though the same amount of available space is assigned to it as the others.
In the live example below try changing `flex: auto` to `flex: 1`. This is the shorthand for `flex: 1 1 0` and causes all of the items to become the same width, as they are working from a flex-basis of 0 allowing all of the space to be distributed evenly.
{{EmbedGHLiveSample("css-examples/flexbox/use-cases/navigation-flex.html", '100%', 550)}}
## Split navigation
Another way to align items on the main axis is to use auto margins. This enables the design pattern of a navigation bar where one group of items are aligned left and another group aligned right. Here we are using the auto margins technique described in [Using auto margins for main axis alignment](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Aligning_items_in_a_flex_container#using_auto_margins_for_main_axis_alignment).
The items are aligned on the main axis with `flex-start` as this is the initial behavior of flexbox. The [`gap`](/en-US/docs/Web/CSS/gap) property has been used to create gaps between items. And we are aligning the last item to the right by giving it a left margin of auto. You can move the class from one item to another to change where the split happens.
{{EmbedGHLiveSample("css-examples/flexbox/use-cases/split-navigation.html", '100%', 550)}}
## Center item
Before flexbox, developers would joke that the hardest problem in web design was vertical centering. This has now been made straightforward using the alignment properties in flexbox, as the following live example shows.
You can play with the alignment, aligning the item to the start with `flex-start` or end with `flex-end`.
{{EmbedGHLiveSample("css-examples/flexbox/use-cases/center.html", '100%', 700)}}
In the future we may not need to make a container a flex container just to center a single item, as the Box Alignment properties will ultimately be implemented in Block layout. For now however, if you need to properly center one thing inside another, flexbox is the way to do it. As in the example above, make a container into a flex container, and then use either `align-items` on the parent element or target the flex item itself with `align-self`.
## Card layout pushing footer down
Whether you use flexbox or CSS Grid to lay out a list of card components, these layout methods only work on direct children of the flex or grid component. This means that if you have variable amounts of content, the card will stretch to the height of the grid area or flex container. Any content inside uses regular block layout, meaning that on a card with less content the footer will rise up to the bottom of the content rather than stick to the bottom of the card.

Flexbox can solve this. We make the card a flex container, with {{cssxref("flex-direction")}}`: column`. We then set the content area to `flex: 1`, which is the shorthand for `flex: 1 1 0` β the item can grow and shrink from a flex basis of `0`. As this is the only item that can grow, it takes up all available space in the flex container and pushes the footer to the bottom. If you remove the `flex` property from the live example you will see how the footer then moves up to sit directly under the content.
{{EmbedGHLiveSample("css-examples/flexbox/use-cases/cards.html", '100%', 800)}}
## Media objects
The media object is a common pattern in web design β this pattern has an image or other element to one side and text to the right. Ideally a media object should be able to be flipped β moving the image from left to right.
We see this pattern everywhere, used for comments, and anywhere we need to display images and descriptions. With flexbox we can allow the part of the media object containing the image to take its sizing information from the image, and then the body of the media object flexes to take up the remaining space.
In the live example below you can see our media object. I have used the alignment properties to align the items on the cross axis to `flex-start`, and then set the `.content` flex item to `flex: 1`. As with our column layout card pattern above, using `flex: 1` means this part of the card can grow.
{{EmbedGHLiveSample("css-examples/flexbox/use-cases/media.html", '100%', 600)}}
Some things that you might want to try in this live example relate to the different ways you might want to constrain the media object in your design.
To prevent the image from growing too large, you should add a {{cssxref("max-width")}} to the image. As that side of the media object uses the initial values of flexbox, it can shrink, but not grow, and uses a `flex-basis` of auto. Any {{cssxref("width")}} or max-width applied to the image will become the `flex-basis`.
```css
.image img {
max-width: 100px;
}
```
You could also allow both sides to grow and shrink in proportion. If you set both sides to `flex: 1`, they will grow and shrink from a {{cssxref("flex-basis")}} of 0, so you will end up with two equal-sized columns. You could either take the content as a guide and set both to `flex: auto`, in which case they would grow and shrink from the size of the content or any size applied directly to the flex items such as a width on the image.
```css
.media .content {
flex: 1;
padding: 10px;
}
.image {
flex: 1;
}
```
You could also give each side different {{cssxref("flex-grow")}} factors, for example setting the side with the image to `flex: 1` and the content side to `flex: 3`. This will mean they use a `flex-basis` of `0` but distribute that space at different rates according to the `flex-grow` factor you have assigned. The flex properties we use to do this are described in detail in the guide [Controlling ratios of flex items along the main axis](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Controlling_ratios_of_flex_items_along_the_main_axis).
```css
.media .content {
flex: 3;
padding: 10px;
}
.image {
flex: 1;
}
```
### Flipping the media object
To switch the display of the media object so that the image is on the right and the content is on the left we can use the `flex-direction` property set to `row-reverse`. The media object now displays the other way around. I have achieved this in the live example by adding a class of `flipped` alongside the existing `.media` class. This means you can see how the display changes by removing that class from the HTML.
{{EmbedGHLiveSample("css-examples/flexbox/use-cases/media-flipped.html", '100%', 650)}}
## Form controls
Flexbox is particularly useful when it comes to styling form controls. Forms have lots of markup and lots of small elements that we typically want to align with each other. A common pattern is to have an {{htmlelement("input")}} element paired with a {{htmlelement("button")}}, perhaps for a search form or where you want your visitor to enter an email address.
Flexbox makes this type of layout easy to achieve. I have contained my `<button>` and `<input>` field in a wrapper which I have given a border and set to `display: flex`. I then use the flex properties to allow the `<input>` field to grow, while the button does not grow. This means we have a pair of fields, with the text field growing and shrinking as the available space changes.
{{EmbedGHLiveSample("css-examples/flexbox/use-cases/input-button.html", '100%', 550)}}
You could add a label or icon to the left as easily as we popped the button onto the right. I have added a label, and other than some styling for background color I didn't need to change the layout. The stretchy input field now has a little less space to play with but it uses the space left after the two items are accounted for.
{{EmbedGHLiveSample("css-examples/flexbox/use-cases/label-input-button.html", '100%', 550)}}
Patterns like this can make it much easier to create a library of form elements for your design, which easily accommodate additional elements being added. You are taking advantage of the flexibility of flexbox by mixing items that do not grow with those that do.
## Conclusion
While exploring the above patterns you have hopefully started to see how you can think through the best way to use flexbox to achieve the result that you want. Quite often you have more than one choice. Mix items that cannot stretch with those that can, use the content to inform the size, or allow flexbox to share out space in proportion. It's up to you.
Think about the best way to present the content that you have and then see how flexbox or other layout methods can help you achieve it.
| 0 |
data/mdn-content/files/en-us/web/css/css_flexible_box_layout | data/mdn-content/files/en-us/web/css/css_flexible_box_layout/aligning_items_in_a_flex_container/index.md | ---
title: Aligning items in a flex container
slug: Web/CSS/CSS_flexible_box_layout/Aligning_items_in_a_flex_container
page-type: guide
---
{{CSSRef}}
One of the reasons that flexbox quickly caught the interest of web developers is that it brought proper alignment capabilities to the web for the first time. It enabled proper vertical alignment, so we can at last easily center a box. In this guide, we will take a thorough look at how the alignment and justification properties work in Flexbox.
To center our box we use the `align-items` property to align our item on the cross axis, which in this case is the block axis running vertically. We use `justify-content` to align the item on the main axis, which in this case is the inline axis running horizontally.

You can take a look at the code of this example below. Change the size of the container or nested element and the nested element always remains centered.
{{EmbedGHLiveSample("css-examples/flexbox/alignment/intro.html", '100%', 700)}}
## Properties that control alignment
The properties we will look at in this guide are as follows.
- {{cssxref("justify-content")}} β controls alignment of all items on the main axis.
- {{cssxref("align-items")}} β controls alignment of all items on the cross axis.
- {{cssxref("align-self")}} β controls alignment of an individual flex item on the cross axis.
- {{cssxref("align-content")}} β described in the spec as for "packing flex lines"; controls space between flex lines on the cross axis.
- {{cssxref("gap")}}, {{cssxref("column-gap")}}, and {{cssxref("row-gap")}} β used to create gaps or gutters between flex items.
We will also discover how auto margins can be used for alignment in flexbox.
## The Cross Axis
The `align-items` and `align-self` properties control alignment of our flex items on the cross axis, down the columns if `flex-direction` is `row` and along the row if `flex-direction` is `column`.
We are making use of cross-axis alignment in the most simple flex example. If we add `display: flex` to a container, the child items all become flex items arranged in a row. They will all stretch to be as tall as the tallest item, as that item is defining the height of the items on the cross axis. If your flex container has a height set, then the items will stretch to that height, regardless of how much content is in the item.


The reason the items become the same height is that the initial value of `align-items`, the property that controls alignment on the cross axis, is set to `stretch`.
We can use other values to control how the items align:
- `align-items: flex-start`
- `align-items: flex-end`
- `align-items: center`
- `align-items: stretch`
- `align-items: baseline`
In the live example below, the value of `align-items` is `stretch`. Try the other values and see how all of the items align against each other in the flex container.
{{EmbedGHLiveSample("css-examples/flexbox/alignment/align-items.html", '100%', 520)}}
### Aligning one item with `align-self`
The `align-items` property sets the `align-self` property on all of the flex items as a group. This means you can explicitly declare the `align-self` property to target a single item. The `align-self` property accepts all of the same values as `align-items` plus a value of `auto`, which will reset the value to that which is defined on the flex container.
In this next live example, the flex container has `align-items: flex-start`, which means the items are all aligned to the start of the cross axis. I have targeted the first item using a `first-child` selector and set that item to `align-self: stretch`; another item has been selected using its class of `selected` and given `align-self: center`. You can change the value of `align-items` or change the values of `align-self` on the individual items to see how this works.
{{EmbedGHLiveSample("css-examples/flexbox/alignment/align-self.html", '100%', 650)}}
### Changing the main axis
So far we have looked at the behavior when our `flex-direction` is `row`, and while working in a language written top to bottom. This means that the main axis runs along the row horizontally, and our cross axis alignment moves the items up and down.

If we change our `flex-direction` to column, `align-items` and `align-self` will align the items to the left and right.

You can try this out in the example below, which has a flex container with `flex-direction: column` yet otherwise is exactly the same as the previous example.
{{EmbedGHLiveSample("css-examples/flexbox/alignment/align-self-column.html", '100%', 730)}}
## Aligning content on the cross axis β the align-content property
So far we have been aligning the items, or an individual item inside the area defined by the flex-container. If you have a wrapped multiple-line flex container then you might also want to use the `align-content` property to control the distribution of space between the rows. In the specification this is described as [packing flex lines](https://drafts.csswg.org/css-flexbox/#align-content-property).
For `align-content` to work you need more height in your flex container than is required to display the items. It then works on all the items as a set, and dictates what happens with that free space, and the alignment of the entire set of items within it.
The `align-content` property takes the following values:
- `align-content: flex-start`
- `align-content: flex-end`
- `align-content: center`
- `align-content: space-between`
- `align-content: space-around`
- `align-content: stretch`
- `align-content: space-evenly` (not defined in the Flexbox specification)
In the live example below, the flex container has a height of 400 pixels, which is more than needed to display our items. The value of `align-content` is `space-between`, which means that the available space is shared out _between_ the flex lines, which are placed flush with the start and end of the container on the cross axis.
Try out the other values to see how the `align-content` property works.
{{EmbedGHLiveSample("css-examples/flexbox/alignment/align-content.html", '100%', 850)}}
Once again we can switch our `flex-direction` to `column` in order to see how this property behaves when we are working by column. As before, we need enough space in the cross axis to have some free space after displaying all of the items.
{{EmbedGHLiveSample("css-examples/flexbox/alignment/align-content-column.html", '100%', 860)}}
> **Note:** The value `space-evenly` is not defined in the flexbox specification and is a later addition to the Box Alignment specification. Browser support for this value is not as good as that of the values defined in the flexbox spec.
## Aligning content on the main axis
Now that we have seen how alignment works on the cross axis, we can take a look at the main axis. Here we only have one property available to us β `justify-content`. This is because we are only dealing with items as a group on the main axis. With `justify-content` we control what happens with available space, should there be more space than is needed to display the items.
In our initial example with `display: flex` on the container, the items display as a row and all line up at the start of the container. This is due to the initial value of `justify-content` being `flex-start`. Any available space is placed at the end of the items.

The `justify-content` property accepts the same values as `align-content`.
- `justify-content: flex-start`
- `justify-content: flex-end`
- `justify-content: center`
- `justify-content: space-between`
- `justify-content: space-around`
- `justify-content: space-evenly` (not defined in the Flexbox specification)
In the example below, the value of `justify-content` is `space-between`. The available space after displaying the items is distributed between the items. The left and right item line up flush with the start and end.
{{EmbedGHLiveSample("css-examples/flexbox/alignment/justify-content.html", '100%', 480)}}
If the main axis is in the block direction because `flex-direction` is set to `column`, then `justify-content` will distribute space between items in that dimension as long as there is space in the flex container to distribute.
{{EmbedGHLiveSample("css-examples/flexbox/alignment/justify-content-column.html", '100%', 880)}}
### Alignment and Writing Modes
Remember that with all of these alignment methods, the values of `flex-start` and `flex-end` are writing mode-aware. If the value of `justify-content` is `flex-start` and the writing mode is left-to-right as in English, the items will line up starting at the left side of the container.

However if the writing mode is right-to-left as in Arabic, the items will line up starting at the right side of the container.

The live example below has the `direction` property set to `rtl` to force a right-to-left flow for our items. You can remove this, or change the values of `justify-content` to see how flexbox behaves when the start of the inline direction is on the right.
{{EmbedGHLiveSample("css-examples/flexbox/alignment/justify-content-writing-mode.html", '100%', 440)}}
## Alignment and flex-direction
The start line will also change if you change the `flex-direction` property β for example using `row-reverse` instead of `row`.
In this next example I have items laid out with `flex-direction: row-reverse` and `justify-content: flex-end`. In a left to right language the items all line up on the left. Try changing `flex-direction: row-reverse` to `flex-direction: row`. You will see that the items now move to the right-hand side.
{{EmbedGHLiveSample("css-examples/flexbox/alignment/justify-content-reverse.html", '100%', 440)}}
While this may all seem a little confusing, the rule to remember is that unless you do something to change it, flex items lay themselves out in the direction that words are laid out in the language of your document along the inline, row axis. `flex-start` will be where the start of a sentence of text would begin.

You can switch them to display in the block direction for the language of your document by selecting `flex-direction: column`. Then `flex-start` will then be where the top of your first paragraph of text would start.

If you change `flex-direction` to one of the reverse values, they will lay themselves out from the end axis and in the reverse order to the way words are written in the language of your document. Then, `flex-start` will change to the end of that axis β so to the location where your lines would wrap if working in rows, or at the end of your last paragraph of text in the block direction.


## Using auto margins for main axis alignment
We don't have a `justify-items` or `justify-self` property available to us on the main axis as our items are treated as a group on that axis. However it is possible to do some individual alignment in order to separate an item or a group of items from others by using auto margins along with flexbox.
A common pattern is a navigation bar where some key items are aligned to the right, with the main group on the left. You might think that this should be a use case for a `justify-self` property, however consider the image below. I have three items on one side and two on the other. If I were able to use `justify-self` on item _d_, it would also change the alignment of item _e_ that follows, which may or may not be my intention.

Instead we can target item 4 and separate it from the first three items by giving it a `margin-left` value of `auto`. Auto margins will take up all of the space that they can in their axis β it is how centering a block with margin auto left and right works. Each side tries to take as much space as it can, and so the block is pushed into the middle.
In this live example, I have flex items arranged into a row with the basic flex values, and the class `push` has `margin-left: auto`. You can try removing this, or adding the class to another item to see how it works.
{{EmbedGHLiveSample("css-examples/flexbox/alignment/auto-margins.html", '100%', 470)}}
## Creating gaps between items
To create a gap between flex items, use the {{cssxref("gap")}}, {{cssxref("column-gap")}}, and {{cssxref("row-gap")}} properties. The {{cssxref("column-gap")}} property creates gaps between items in a row. The {{cssxref("row-gap")}} property creates gaps between flex lines, when you have {{cssxref("flex-wrap")}} set to `wrap`. The {{cssxref("gap")}} property is a shorthand that sets both together.
{{EmbedGHLiveSample("css-examples/box-alignment/flexbox/gap.html", '100%', 700)}}
## See also
- [Box alignment](/en-US/docs/Web/CSS/CSS_box_alignment)
- [Box alignment in flexbox](/en-US/docs/Web/CSS/CSS_box_alignment/Box_alignment_in_flexbox)
- [Box alignment in grid layout](/en-US/docs/Web/CSS/CSS_box_alignment/Box_alignment_in_grid_layout)
| 0 |
data/mdn-content/files/en-us/web/css/css_flexible_box_layout | data/mdn-content/files/en-us/web/css/css_flexible_box_layout/mastering_wrapping_of_flex_items/index.md | ---
title: Mastering wrapping of flex items
slug: Web/CSS/CSS_flexible_box_layout/Mastering_wrapping_of_flex_items
page-type: guide
---
{{CSSRef}}
Flexbox was designed as a single dimensional layout, meaning that it deals with laying out items as a row or as a column β but not both at once. There is however the ability to wrap flex items onto new lines, creating new rows if {{cssxref("flex-direction")}} is `row` and new columns if `flex-direction` is `column`. In this guide I will explain how this works, what it is designed for and what situations really require [CSS Grid Layout](/en-US/docs/Web/CSS/CSS_grid_layout) rather than flexbox.
## Making things wrap
The initial value of the {{cssxref("flex-wrap")}} property is `nowrap`. This means that if you have a set of flex items that are too wide for their container, they will overflow it. If you want to cause them to wrap once they become too wide you must add the `flex-wrap` property with a value of `wrap`, or use the shorthand {{cssxref("flex-flow")}} with values of `row wrap` or `column wrap`.
Items will then wrap in the container. In the next example I have ten items all with a `flex-basis` of `160px` and the ability to grow and shrink. Once the first row gets to a point where there is not enough space to place another 160 pixel item, a new flex line is created for the items and so on until all of the items are placed. As the items can grow, they will expand larger than 160 px in order to fill each row completely. If there is only one item on the final line it will stretch to fill the entire line.
{{EmbedGHLiveSample("css-examples/flexbox/wrapping/row-wrap.html", '100%', 650)}}
We can see the same thing happening with columns. The container will need to have a height in order that the items will start wrapping and creating new columns, and items will stretch taller to fill each column completely.
{{EmbedGHLiveSample("css-examples/flexbox/wrapping/column-wrap.html", '100%', 810)}}
## Wrapping and flex-direction
Wrapping works as you might expect when combined with `flex-direction`. If `flex-direction` is set to `row-reverse` then the items will start from the end edge of the container and lay themselves out in reverse ordered lines.
{{EmbedGHLiveSample("css-examples/flexbox/wrapping/row-reverse-wrap.html", '100%', 750)}}
Note that the reversing is only happening in the inline, row direction. We start on the right then go onto the second line and again start from the right. We aren't reversing in both directions, starting from the bottom coming up the container!
## Single-dimensional layout explained
As we have seen from the above examples if our items are allowed to grow and shrink, when there are fewer items in the last row or column then those items grow to fill the available space.
There is no method in flexbox to tell items in one row to line up with items in the row above β each flex line acts like a new flex container. It deals with space distribution across the main axis. If there is only one item, and that item is allowed to grow, it will fill the axis just as if you had a single item flex container.
If you want layout in two dimensions then you probably want Grid Layout. We can compare our wrapped row example above with the CSS Grid version of that layout to see the difference. The following live sample uses CSS Grid Layout to create a layout that has as many columns of at least 160 pixels as will fit, distributing the extra space between all columns. However, in this case the items stay in their grid and don't stretch out when there are fewer of them on the final row.
{{EmbedGHLiveSample("css-examples/flexbox/wrapping/grid-example.html", '100%', 700)}}
This is the difference between one and two-dimensional layout. In a one dimensional method like flexbox, we only control the row or column. In two dimensional layout like grid we control both at the same time. If you want the space distribution row by row, use flexbox. If you don't, use Grid.
## How do flexbox-based grid systems work?
Typically flexbox-based grid systems work by taking flexbox back to the familiar world of float-based layouts. If you assign percentage widths to flex items β either as `flex-basis` or by adding a width to the item itself leaving the value of `flex-basis` as `auto` β you can get the impression of a two dimensional layout. You can see this working in the example below.
Here I have set `flex-grow` and `flex-shrink` to `0` to make inflexible flex items and I'm then controlling flexibility using percentages, just like we used to do in float layouts.
{{EmbedGHLiveSample("css-examples/flexbox/wrapping/flex-grid.html", '100%', 650)}}
If you need flex items to line up in the cross axis, controlling the width in this way will achieve that. In most cases however, adding widths to flex items in this way demonstrates that you would probably be better served by switching to grid layout for that component.
## Creating gutters between items
To create gaps or gutters between flex items, use the {{CSSXref('gap')}} property.
The gap property in CSS is a shorthand for `row-gap` and `column-gap`, specifying the size of gutters, which is the space between rows and columns within grid, flex, and multi-column layouts.
In Flexbox, the `gap` property is applied to the flex container. It creates a fixed space between adjacent flex items. However, the `gap` property is not the only thing that can put space between items. Margins, paddings, `justify-content`, and `align-content` can also increase the size of the gutter, affecting the actual size of the gap.
To see how the `gap` property differs from `margin` in both axes, try changing the `gap` value in the container `.box` and adding a `margin` value to the `.box > *` rule in the stylesheet below. Click the Reset button to revert to the previous values.
{{EmbedGHLiveSample("css-examples/flexbox/wrapping/gaps.html", '100%', 830)}}
## Collapsed items
The flexbox specification details what should happen if a flex item is collapsed by setting `visibility: collapse` on an item. See the MDN documentation for the {{cssxref("visibility")}} property. The specification describes the behavior as follows:
> "Specifying visibility:collapse on a flex item causes it to become a collapsed flex item, producing an effect similar to visibility:collapse on a table-row or table-column: the collapsed flex item is removed from rendering entirely, but leaves behind a "strut" that keeps the flex line's cross-size stable. Thus, if a flex container has only one flex line, dynamically collapsing or uncollapsing items may change the flex container's main size, but is guaranteed to have no effect on its cross size and won't cause the rest of the page's layout to "wobble". Flex line wrapping is re-done after collapsing, however, so the cross-size of a flex container with multiple lines might or might not change." - [Collapsed items](https://www.w3.org/TR/css-flexbox-1/#visibility-collapse)
This behavior is useful if you want to target flex items using JavaScript to show and hide content for example. The example in the specification demonstrates one such pattern.
In the following live example, I have a non-wrapped flex container. The third item has more content than the others yet is set to `visibility: collapse`; therefore, the flex container is retaining a _strut_ of the height required to display this item. If you remove `visibility: collapse` from the CSS or change the value to `visible`, you will see the item appear, and the space is redistributed between non-collapsed items; the height of the flex container should not change.
> **Note:** Use Firefox for the below two examples as Chrome and Safari treat collapse as hidden.
{{EmbedGHLiveSample("css-examples/flexbox/wrapping/visibility-collapse.html", '100%', 650)}}
When dealing with multiple-line flex containers however you need to understand that the wrapping is re-done _after_ collapsing. So the browser needs to re-do the wrapping behavior to account for the new space that the collapsed item has left in the inline direction.
This means that items might end up on a different line to the one they started on. In the case of an item being shown and hidden it could well cause the items to end up in a different row.
I have created this behavior in the next live example. You can see how the stretching changes row based on the location of the collapsed item. If you add more content to the second item, it changes row once it gets long enough. That top row then only becomes as tall as a single line of text.
{{EmbedGHLiveSample("css-examples/flexbox/wrapping/wrapped-visibility-collapse.html", '100%', 750)}}
If this causes a problem for your layout it may require a rethinking of the structure, for example putting each row into a separate flex container in order that they can't shift rows.
### Using `visibility: hidden` and `display: none`
In previous live example, try using `visibility: hidden` or `display: none` instead of `visiblity: collapse`. Using `visibility: hidden`, the item is made invisible but the box is kept in the formatting structure, so it still behaves as if it were part of the layout.
When you use `display: none`, the item is completely removed from the formatting structure. Not only is it invisible but the structure is removed as well. This means counters ignore it and things like transitions do not run.
| 0 |
data/mdn-content/files/en-us/web/css/css_flexible_box_layout | data/mdn-content/files/en-us/web/css/css_flexible_box_layout/relationship_of_flexbox_to_other_layout_methods/index.md | ---
title: Relationship of flexbox to other layout methods
slug: Web/CSS/CSS_flexible_box_layout/Relationship_of_flexbox_to_other_layout_methods
page-type: guide
---
{{CSSRef}}
In this article we will take a look at how Flexbox fits in with all the other CSS modules. We'll find out which specifications you also need to take notice of if you want to learn flexbox, and find out why flexbox is different to some other modules.
> **Note:** CSS versions 1 and 2 were a single monolithic specification where all of CSS was defined in one large document. As CSS became a more feature rich language, maintaining one huge specification became problematic, with different parts of CSS moving on at different speeds. CSS was therefore modularized, and the various CSS Specifications are different modules that make up CSS today. These modules relate to each other, and are at different stages of development.
## The box alignment module
For many people the first reason they start to look at flexbox is because of the ability to properly align flex items inside a flex container. Flexbox provides access to properties that allow the alignment of items on their cross axis and justification of items on the main axis.
These properties started life in the flexbox specification, but are now also part of the [Box Alignment Specification](https://www.w3.org/TR/css-align-3/). This specification details how alignment works in all layout β not just flexbox. Box alignment deals with alignment and justification, including creating gaps or gutters between flex items.
The reason that the Box alignment properties remain detailed in the flexbox specification as well as being in box alignment is to ensure that completion of the flexbox spec is not held up by box alignment, which has to detail these methods for all layout types. There is a note in the flexbox spec stating that in the future, once it is completed, the definitions in Box Alignment Level 3 will supersede those of flexbox:
> "Note: While the alignment properties are defined in CSS Box Alignment \[CSS-ALIGN-3], Flexible Box Layout reproduces the definitions of the relevant ones here so as to not create a normative dependency that may slow down advancement of the spec. These properties apply only to flex layout until CSS Box Alignment Level 3 is finished and defines their effect for other layout modes. Additionally, any new values defined in the Box Alignment module will apply to Flexible Box Layout; in other words, the Box Alignment module, once completed, will supersede the definitions here."
In a later article in this series β [Aligning items in a flex container](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Aligning_items_in_a_flex_container) β we will take a thorough look at how the Box Alignment properties apply to flex items.
## Writing Modes
In the [Basic concepts of flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox) article, I explained that flexbox is **writing mode aware**. Writing modes are fully detailed in the CSS [Writing Modes specification](https://www.w3.org/TR/css-writing-modes-3/), which details how CSS supports the various different writing modes that exist internationally. We need to be aware of how this will impact our flex layouts as writing mode changes the direction that blocks are laid out in our document. Understanding **block** and **inline** directions is key to new layout methods.
It is worth noting that we might want to change the writing mode of our document for reasons other than publishing content in a language that uses a different writing mode. See [this article](https://24ways.org/2016/css-writing-modes/) for a full description of writing modes and ways to use them, both for content in other languages and for creative reasons.
### The writing modes
The writing modes specification defines the following values of the {{cssxref("writing-mode")}} property, which serve to change the direction that blocks are laid out on the page, to match the direction that blocks lay out when content is formatted in that particular writing mode. You can change the live example below to these modes in order to see what happens to the flex layout.
- `horizontal-tb`
- `vertical-rl`
- `vertical-lr`
- `sideways-rl`
- `sideways-lr`
{{EmbedGHLiveSample("css-examples/flexbox/relationship/writing-modes.html", '100%', 360)}}
Note that `sideways-rl` and `sideways-lr` have support only in Firefox currently. There are also some known issues with regard to `writing-mode` and flexbox. You can see more information on browser support in the [MDN documentation for writing-mode](/en-US/docs/Web/CSS/writing-mode). However if you are planning on using writing modes in your layout, carefully testing the results is advisable β not least because it would be easy to make things hard to read!
Note that you would not normally use CSS and the `writing-mode` property to change an entire document to another writing mode. This would be done via HTML, by adding a `dir` and `lang` attribute to the `html` element to indicate the document language and default text direction. This would mean that the document would display correctly even if CSS did not load.
## Flexbox and other layout methods
The flexbox specification contains a [definition of what happens](https://www.w3.org/TR/css-flexbox-1/#flex-containers) if an item uses another layout method and then becomes a flex item. For example, if an item is floated and then its parent becomes a flex container. Or, how a flex container behaves as part of layout.
An element set to `display: flex` behaves in most ways like any other block level container that establishes a containing block. Floats will not intrude, and the containers' margins will not collapse.
With regard to flex items, if an item was floated or cleared and then becomes a flex item due to the parent having `display: flex` applied, the floating and clearing will no longer happen, and the item will not be taken out of normal flow in the way that floats are. If you have used the {{cssxref("vertical-align")}} property, as used with `inline-block` or table layout for alignment, this will no longer affect the item and you can use the alignment properties of flexbox instead.
In this next live example the child elements have been floated, and then their container has had `display: flex` added. If you remove `display: flex`, you should see that the `.box` element collapses as we have no clearing applied. This demonstrates that the float is happening. Re-apply `display: flex` and the collapsing does not happen. This is because the items no longer have a float applied, as they have been transformed into flex items.
{{EmbedGHLiveSample("css-examples/flexbox/relationship/floats.html", '100%', 430)}}
## Flexbox and Grid Layout
[CSS Grid Layout](/en-US/docs/Web/CSS/CSS_grid_layout) and Flexbox generally act in the same way with regards to overwriting other methods. You might however want to use flexbox as a fallback for grid layout, as there is better support for flexbox in older browsers. This approach works very well. If a flex item becomes a grid item, then the `flex` properties that may have been assigned to the child elements will be ignored.
You can use the Box Alignment properties across both layout methods, so using flexbox as a fallback for grid layout can work very well.
### Flex and grid β what's the difference?
A common question is to ask what the difference is between Flexbox and CSS Grid Layout β why do we have two specifications that sometimes appear to be doing the same thing?
The most straightforward answer to this question is defined in the specifications themselves. Flexbox is a one-dimensional layout method whereas Grid Layout is a two-dimensional layout method. The example below has a flex layout. As already described in the Basic concepts article, flex items can be allowed to wrap but, once they do so, each line becomes a flex container of its own. When space is distributed flexbox does not look at the placement of items in other rows and tries to line things up with each other.
{{EmbedGHLiveSample("css-examples/flexbox/relationship/flex-layout.html", '100%', 750)}}
If we create a very similar layout using Grid, we can control the layout in both rows and columns.
{{EmbedGHLiveSample("css-examples/flexbox/relationship/grid-layout.html", '100%', 700)}}
These examples point to another key difference between these layout methods. In Grid Layout you do the majority of sizing specification on the container, setting up tracks and then placing items into them. In flexbox, while you create a flex container and set the direction at that level, any control over item sizing needs to happen on the items themselves.
In some cases you could happily use either layout method, but as you become confident with both you will find each one suiting different layout needs, and you will end up with both methods in your CSS. There is rarely a right or wrong answer.
As a ground rule, if you are adding widths to flex items in order to make items in one row of a wrapped flex container line up with the items above them you really want two-dimensional layout. In this case it is likely that the component would be better laid out using CSS Grid Layout. It isn't the case that you should use flexbox for small components and grid layout for larger ones; a tiny component can be two dimensional, and a large layout can be represented better with layout in one dimension. Try things out β we have a choice in layout method for the first time, so take advantage of it.
For more comparisons of grid and flexbox see the article [Relationship of Grid Layout to other layout methods](/en-US/docs/Web/CSS/CSS_grid_layout/Relationship_of_grid_layout_with_other_layout_methods). This article details many of the ways that Grid Layout differs from flex layout, and demonstrates some of the extra functionality you get when using Grid Layout such as layering of items on the grid. This may also help in your decision as to which layout method to use.
## Flexbox and display: contents
The `contents` value of the {{cssxref("display")}} property is a new value that is described in the spec as follows:
> "The element itself does not generate any boxes, but its children and pseudo-elements still generate boxes as normal. For the purposes of box generation and layout, the element must be treated as if it had been replaced with its children and pseudo-elements in the document tree."
This value of `display` controls box generation, and whether the element should generate a box that we can style and see on the page, or whether instead the box it would normally create should be removed and the child elements essentially moved up to participate in whatever layout method the parent would have been part of. This is much easier to see with an example.
In the following live example I have a flex container with three child elements. One of these flex items has two elements nested inside it, which would not ordinarily participate in flex layout. Flex layout only applies to the direct children of a flex container.
By adding `display: contents` to the wrapper around the nested elements, you can see that the item has disappeared from the layout, allowing the two sub-children to be laid out as if they were direct children of the flex container. You can try removing the `display: contents` line to see it return.
Note that this only removes the box from the layout; the sub-children don't become direct children in any other way. You can see that as I have used a direct child selector to add the background and borders to the flex items, this has not been applied to our nested children. They have been laid out as flex items, but as they are not direct children they do not get the other styling.
> **Warning:** Current implementations in most browsers will remove any element with `display: contents` from the accessibility tree (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 specification, see [`display: contents`](/en-US/docs/Web/CSS/display#display_contents).
Also, having removed the box you cannot then use it to β for example β add a background color behind the nested sub children. If you remove `display: contents` in this live example you will see that the direct child we are removing has an orange background color. This also disappears when the box disappears.
{{EmbedGHLiveSample("css-examples/flexbox/relationship/display-contents.html", '100%', 650)}}
Browser support for `display:contents` is limited and required for this demo to work. Firefox supports `display: contents` already, and the value is being implemented in Chrome. Once there is better browser support this feature will be very useful in circumstances where you need the markup for semantic reasons but do not want to display the box that it would generate by default.
| 0 |
data/mdn-content/files/en-us/web/css/css_flexible_box_layout | data/mdn-content/files/en-us/web/css/css_flexible_box_layout/ordering_flex_items/index.md | ---
title: Ordering flex items
slug: Web/CSS/CSS_flexible_box_layout/Ordering_flex_items
page-type: guide
---
{{CSSRef}}
New layout methods such as Flexbox and Grid bring with them the possibility of controlling the order of content. In this article, we will take a look at ways in which you can change the visual order of your content when using Flexbox. We will also consider the implications of reordering items from an accessibility point of view.
## Reverse the display of the items
the {{cssxref("flex-direction")}} property can take one of four values:
- `row`
- `column`
- `row-reverse`
- `column-reverse`
The first two values keep the items in the same order that they appear in the document source order and display them sequentially from the start line.


The second two values reverse the items by switching the start and end lines.


Remember that the start line relates to writing modes. The row-related examples above demonstrate how `row` and `row-reverse` work in a left-to-right language such as English. If you are working in a right-to-left language like Arabic then `row` would start on the right, `row-reverse` on the left.

This can seem like a neat way to display things in reverse order however you should be mindful that the items are only _visually_ displayed in reverse order. The specification says the following on this matter:
> "Note: The reordering capabilities of flex layout intentionally affect only the visual rendering, leaving speech order and navigation based on the source order. This allows authors to manipulate the visual presentation while leaving the source order intact for non-CSS UAs and for linear models such as speech and sequential navigation." - [Ordering and Orientation](https://www.w3.org/TR/css-flexbox-1/#flow-order)
If your items were links or some other element that the user could tab to, then the tabbing order would be the order that these items appear in the document source β not your visual order.
If you are using a reverse value, or otherwise reordering your items, you should consider whether you actually need to change the logical order in the source. The specification continues with a warning not to use reordering to fix issues in your source:
> "Authors _must not_ use order or the \*-reverse values of flex-flow/flex-direction as a substitute for correct source ordering, as that can ruin the accessibility of the document."
> **Note:** For some years Firefox had a bug whereby it would attempt to follow the visual order and not the source order, making it behave differently from other browsers. This has now been fixed. You should always take the source order as the logical order of the document as all up-to-date user agents will be following the specification and doing so.
In the live example below I have added a focus style in order that as you tab from link to link you can see which is highlighted. If you change the order using `flex-direction` you can see how the tab order continues to follow the order that the items are listed in the source.
{{EmbedGHLiveSample("css-examples/flexbox/order/flex-direction.html", '100%', 440)}}
In the same way that changing the value of `flex-direction` does not change the order in which items are navigated to, changing this value does not change paint order. It is a visual reversal of the items only.
## The order property
In addition to reversing the order in which flex items are visually displayed, you can target individual items and change where they appear in the visual order with the {{cssxref("order")}} property.
The `order` property is designed to lay the items out in _ordinal groups_. What this means is that items are assigned an integer that represents their group. The items are then placed in the visual order according to that integer, lowest values first. If more than one item has the same integer value, then within that group the items are laid out as per source order.
As an example, I have 5 flex items, and assign `order` values as follows:
- Source item 1: `order: 2`
- Source item 2: `order: 3`
- Source item 3: `order: 1`
- Source item 4: `order: 3`
- Source item 5: `order: 1`
These items would be displayed on the page in the following order:
- Source item 3: `order: 1`
- Source item 5: `order: 1`
- Source item 1: `order: 2`
- Source item 2: `order: 3`
- Source item 4: `order: 3`

You can play around with the values in this live example below and see how that changes the order. Also, try changing `flex-direction` to `row-reverse` and see what happens β the start line is switched so the ordering begins from the opposite side.
{{EmbedGHLiveSample("css-examples/flexbox/order/order.html", '100%', 500)}}
Flex items have a default `order` value of `0`, therefore items with an integer value greater than 0 will be displayed after any items that have not been given an explicit `order` value.
You can also use negative values with `order`, which can be quite useful. If you want to make one item display first and leave the order of all other items unchanged, you can give that item order of `-1`. As this is lower than 0 the item will always be displayed first.
In the live code example below I have items laid out using Flexbox. By changing which item has the class `active` assigned to it in the HTML, you can change which item displays first and therefore becomes full width at the top of the layout, with the other items displaying below it.
{{EmbedGHLiveSample("css-examples/flexbox/order/negative-order.html", '100%', 520)}}
The items are displayed in what is described in the specification as _order-modified document order_. The value of the order property is taken into account before the items are displayed.
Order also changes the paint order of the items; items with a lower value for `order` will be painted first and those with a higher value for `order` painted afterwards.
## The order property and accessibility
Use of the `order` property has exactly the same implications for accessibility as changing the direction with `flex-direction`. Using `order` changes the order in which items are painted, and the order in which they appear visually. It does not change the sequential navigation order of the items. Therefore if a user is tabbing between the items, they could find themselves jumping around your layout in a very confusing way.
By tabbing around any of the live examples on this page, you can see how `order` is potentially creating a strange experience for anyone not using a pointing device of some kind. To read more about this disconnect of visual order and logical order and some of the potential problems it raises for accessibility, see the following resources.
- [Flexbox and the keyboard navigation disconnect](https://tink.uk/flexbox-the-keyboard-navigation-disconnect/)
- [HTML Source Order vs CSS Display Order](https://adrianroselli.com/2015/10/html-source-order-vs-css-display-order.html)
- [The Responsive Order Conflict for Keyboard Focus](https://alastairc.uk/2017/06/the-responsive-order-conflict/)
## Use cases for order
There are sometimes places where the fact that the logical and therefore reading order of flex items is separate from the visual order, is helpful. Used carefully the `order` property can allow for some useful common patterns to be easily implemented.
You might have a design, perhaps a card that will display a news item. The heading of the news item is the key thing to highlight and would be the element that a user might jump to if they were tabbing between headings to find the content they wanted to read. The card also has a date; the finished design we want to create is something like this.

Visually the date appears above the heading, in the source. However, if the card was read out by a screen reader I would prefer that the title was announced first and then the publication date. We can make this so using the `order` property.
The card is going to be our flex container, with `flex-direction` set to column. I then give the date an `order` of `-1`. This pulls it up above the heading.
{{EmbedGHLiveSample("css-examples/flexbox/order/usecase-order.html", '100%', 730)}}
These small tweaks are the sort of cases where the `order` property makes sense. Keep the logical order as the reading and tab order of the document, and maintain that in the most accessible and structured fashion. Then use `order` for purely visual design tweaks. When doing so take care that you are not reordering items that could be accessed by the keyboard as a user is tabbing around. Especially when using newer layout methods you should ensure that your browser testing includes testing the site using only a keyboard, rather than a mouse or a touchscreen. You will quickly see if your development choices make getting around the content difficult.
| 0 |
data/mdn-content/files/en-us/web/css/css_flexible_box_layout | data/mdn-content/files/en-us/web/css/css_flexible_box_layout/controlling_ratios_of_flex_items_along_the_main_axis/index.md | ---
title: Controlling ratios of flex items along the main axis
slug: Web/CSS/CSS_flexible_box_layout/Controlling_ratios_of_flex_items_along_the_main_axis
page-type: guide
---
{{CSSRef}}
In this guide we will be exploring the three properties that are applied to flex items, which enable us to control the size and flexibility of the items along the main axis β {{CSSxRef("flex-grow")}}, {{CSSxRef("flex-shrink")}}, and {{CSSxRef("flex-basis")}}. Fully understanding how these properties work with growing and shrinking items is the real key to mastering flexbox.
## A first look
Our three properties control the following aspects of a flex item's flexibility:
- `flex-grow`: How much of the positive free space does this item get?
- `flex-shrink`: How much negative free space can be removed from this item?
- `flex-basis`: What is the size of the item before growing and shrinking happens?
The properties are usually expressed as the shorthand {{CSSxRef("flex")}} property. The following code would set the `flex-grow` property to `2`, `flex-shrink` to `1` and `flex-basis` to `auto`.
```css
.item {
flex: 2 1 auto;
}
```
If you have read the article [Basic Concepts of Flexbox](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox), then you will have already had an introduction to the properties. Here we will explore them in depth in order that you can fully understand what the browser is doing when you use them.
## Important concepts when working on the main axis
There are a few concepts worth digging into before looking at how the flex properties work to control ratios along the main axis. These relate to the _natural_ size of flex items before any growing or shrinking takes place, and to the concept of free space.
### Flex item sizing
In order to work out how much space there is available to lay out flex items, the browser needs to know how big the item is to start with. How is this worked out for items that don't have a width or a height applied using an absolute length unit?
There is a concept in CSS of {{CSSxRef('min-content')}} and {{CSSxRef('max-content')}}; these keywords can be used in place of a {{cssxref("length")}} unit.
In the live example below for instance I have two paragraph elements that contain a string of text. The first paragraph has a width of `min-content`. You should be able to see that the text has taken all of the soft wrapping opportunities available to it, becoming as small as it can be without overflowing. This then, is the `min-content` size of that string. Essentially, the longest word in the string is dictating the size.
The second paragraph has a value of `max-content` and so it does the opposite. It gets as big as it possibly can be, taking no soft-wrapping opportunities. It would overflow the box it is in if that container was too narrow.
{{EmbedGHLiveSample("css-examples/flexbox/ratios/min-max-content.html", '100%', 750)}}
Remember this behavior and what effects `min-content` and `max-content` have as we explore `flex-grow` and `flex-shrink` later in this article.
### Positive and negative free space
To talk about these properties we need to understand the concept of **positive and negative free space**. When a flex container has positive free space, it has more space than is required to display the flex items inside the container. For example, if I have a 500 pixel-wide container, {{CSSxRef("flex-direction")}} is `row`, and I have three flex items each 100 pixels wide, then I have 200 pixels of positive free space, which could be distributed between the items if I wanted them to fill the container.

We have negative free space when the natural size of the items adds up to larger than the available space in the flex container. If I have a 500 pixel-wide container like the one above, but the three flex items are each 200 pixels wide, the total space I need will be 600 pixels, so I have 100 pixels of negative free space. This could be removed from the items in order to make them fit the container.

It is this distribution of positive free space and removal of negative free space that we need to understand in order to understand the flex properties.
In the following examples I am working with {{CSSxRef("flex-direction")}} set to row, therefore the size of items will always come from their width. We will be calculating the positive and negative free space created by comparing the total width of all the items with the container width. You could equally try out each example with `flex-direction: column`. The main axis would then be the column, and you would then need to compare the height of the items and that of the container they are in to work out the positive and negative free space.
## The flex-basis property
The {{CSSxRef("flex-basis")}} property specifies the initial size of the flex item before any space distribution happens. The initial value for this property is `auto`. If `flex-basis` is set to `auto` then to work out the initial size of the item the browser first checks if the main size of the item has an absolute size set. This would be the case if you had given your item a width of 200 pixels. In that case `200px` would be the `flex-basis` for this item.
If your item is instead auto-sized, then `auto` resolves to the size of its content. At this point your knowledge of `min-` and `max-content` sizing becomes useful, as flexbox will take the `max-content` size of the item as the `flex-basis`. The following live example can help to demonstrate this.
In this example I have created a series of inflexible boxes, with both `flex-grow` and `flex-shrink` set to `0`. Here we can see how the first item β which has an explicit width of 150 pixels set as the main size β takes a `flex-basis` of `150px`, whereas the other two items have no width and so are sized according to their content width.
{{EmbedGHLiveSample("css-examples/flexbox/ratios/flex-basis.html", '100%', 500)}}
In addition to the `auto` keyword, you can use the `content` keyword as the `flex-basis`. This will result in the `flex-basis` being taken from the content size even if there is a width set on the item. You can also get the same effect by using `auto` as the flex-basis and ensuring that your item does not have a width set, in order that it will be auto-sized.
If you want flexbox to completely ignore the size of the item when doing space distribution then set `flex-basis` to `0`. This essentially tells flexbox that all the space is up for grabs, and to share it out in proportion. We will see examples of this as we move on to look at `flex-grow`.
## The flex-grow property
The {{CSSxRef("flex-grow")}} property specifies the **flex grow factor**, which determines how much the flex item will grow relative to the rest of the flex items in the flex container when the positive free space is distributed.
If all of your items have the same `flex-grow` factor then space will be distributed evenly between all of them. If this is the situation that you want then typically you would use `1` as the value, however you could give them all a `flex-grow` of `88`, or `100`, or `1.2` if you like β it is a ratio. If the factor is the same for all, and there is positive free space in the flex container then it will be distributed equally to all.
### Combining `flex-grow` and `flex-basis`
Things can get confusing in terms of how `flex-grow` and `flex-basis` interact. Let's consider the case of three flex items of differing content lengths and the following `flex` rules applied to them:
`flex: 1 1 auto;`
In this case the `flex-basis` value is `auto` and the items don't have a width set, and so are auto-sized. This means that flexbox is looking at the `max-content` size of the items. After laying the items out we have some positive free space in the flex container, shown in this image as the hatched area:

We are working with a `flex-basis` equal to the content size so the available space to distribute is subtracted from the total available space (the width of the flex container), and the leftover space is then shared out equally among each item. Our bigger item ends up bigger because it started from a bigger size, even though it has the same amount of spare space assigned to it as the others:

If what you actually want is three equally-sized items, even if they start out at different sizes, you should use this:
`flex: 1 1 0;`
Here we are saying that the size of the item for the purposes of our space distribution calculation is `0` β all the space is up for grabs and as all of the items have the same `flex-grow` factor, they each get an equal amount of space distributed. The end result is three equal width, flexible items.
Try changing the `flex-grow` factor from 1 to 0 in this live example to see the different behavior:
{{EmbedGHLiveSample("css-examples/flexbox/ratios/flex-grow.html", '100%', 520)}}
### Giving items different flex-grow factors
Our understanding of how `flex-grow` works with `flex-basis` allows us to have further control over our individual item sizes by assigning items different `flex-grow` factors. If we keep our `flex-basis` at `0` so all of the space can be distributed, we could assign each of the three flex items a different `flex-grow` factor. In the example below I am using the following values:
- `1` for the first item.
- `1` for the second item.
- `2` for the third item.
Working from a `flex-basis` of `0` this means that the available space is distributed as follows. We need to add up the flex grow factors, then divide the total amount of positive free space in the flex container by that number, which in this case is 4. We then share out the space according to the individual values β the first item gets one part, the second one part, the third two parts. This means that the third item is twice the size of the first and second items.
{{EmbedGHLiveSample("css-examples/flexbox/ratios/flex-grow-ratios.html", '100%', 520)}}
Remember that you can use any positive value here. It is the ratio between one item and the others that matters. You can use large numbers, or decimals β it is up to you. To test that out change the values assigned in the above example to `.25`, `.25`, and `.50` β you should see the same result.
## The flex-shrink property
The {{CSSxRef("flex-shrink")}} property specifies the **flex shrink factor**, which determines how much the flex item will shrink relative to the rest of the flex items in the flex container when negative free space is distributed.
This property deals with situations where the browser calculates the `flex-basis` values of the flex items, and finds that they are too large to fit into the flex container. As long as `flex-shrink` has a positive value the items will shrink in order that they do not overflow the container.
So where `flex-grow` deals with adding available space, `flex-shrink` manages taking away space to make boxes fit into their container without overflowing.
In the next live example I have three items in a flex container; I've given each a width of 200 pixels, and the container is 500 pixels wide. With `flex-shrink` set to `0` the items are not allowed to shrink and so they overflow the box.
{{EmbedGHLiveSample("css-examples/flexbox/ratios/flex-shrink.html", '100%', 500)}}
Change the `flex-shrink` value to `1` and you will see each item shrink by the same amount, in order that all of the items now fit in the box. They have become smaller than their initial width in order to do so.
### Combining `flex-shrink` and `flex-basis`
You could say that `flex-shrink` works in pretty much the same way as `flex-grow`. However there are two reasons why it isn't _quite_ the same.
While it is usually subtle, defined in the specification is one reason why `flex-shrink` isn't quite the same for negative space as `flex-grow` is for positive space:
> "Note: The flex shrink factor is multiplied by the flex base size when distributing negative space. This distributes negative space in proportion to how much the item is able to shrink, so that e.g. a small item won't shrink to zero before a larger item has been noticeably reduced."
The second reason is that flexbox prevents small items from shrinking to zero size during this removal of negative free space. The items will be floored at their `min-content` size β the size that they become if they take advantage of any soft wrapping opportunities available to them.
You can see this `min-content` flooring happen in the below example, where the `flex-basis` is resolving to the size of the content. If you change the width on the flex container β increasing it to 700px for example β and then reduce the flex item width, you can see that the first two items will wrap, however they will never become smaller than that `min-content` size. As the box gets smaller space is then just removed from the third item.
{{EmbedGHLiveSample("css-examples/flexbox/ratios/flex-shrink-min-content.html", '100%', 500)}}
In practice the shrinking behavior does tend to give you reasonable results. You don't usually want your content to disappear completely or for boxes to get smaller than their minimum content, so the above rules make sense in terms of sensible behavior for content that needs to be shrunk in order to fit into a container.
### Giving items different `flex-shrink` factors
In the same way as `flex-grow`, you can give flex-items different `flex-shrink` factors. This can help change the default behavior if, for example, you want an item to shrink more or less rapidly than its siblings or not shrink at all.
In the following live example the first item has a `flex-shrink` factor of 1, the second `0` (so it won't shrink at all), and the third `4`. The third item therefore shrinks more rapidly than the first. Play around with the different values β as for `flex-grow` you can use decimals or larger numbers here. Choose whatever makes most sense to you.
{{EmbedGHLiveSample("css-examples/flexbox/ratios/flex-shrink-ratios.html", '100%', 570)}}
## Mastering sizing of flex items
The key to really understanding how flex item sizing works is in understanding the number of things that come into play. Consider the following aspects, which we have already discussed in these guides:
### What sets the base size of the item?
1. Is `flex-basis` set to `auto`, and does the item have a width set? If so, the size will be based on that width.
2. Is `flex-basis` set to `auto` or `content`? If so, the size is based on the item size.
3. Is `flex-basis` a length unit, but not zero? If so this is the size of the item.
4. Is `flex-basis` set to `0`? if so then the item size is not taken into consideration for the space-sharing calculation.
### Do we have available space?
Items can't grow with no positive free space, and they won't shrink unless there is negative free space.
1. If we took all of the items and added up their widths (or heights if working in a column), is that total **less** than the total width (or height) of the container? If so, then you have positive free space and `flex-grow` comes into play.
2. If we took all of the items and added up their widths (or heights if working in a column), is that total **more** than the total width (or height) of the container? If so, you have negative free space and `flex-shrink` comes into play.
### Other ways to distribute space
If you do not want space added to the items, remember that you can deal with free space between or around items using the alignment properties described in the guide to aligning items in a flex container. The {{CSSxRef("justify-content")}} property will enable the distribution of free space between or around items. You can also use auto margins on flex items to absorb space and create gaps between items.
With all the flex tools at your disposal you will find that most tasks can be achieved, although it might take a little bit of experimentation at first.
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/scrollbar-width/index.md | ---
title: scrollbar-width
slug: Web/CSS/scrollbar-width
page-type: css-property
browser-compat: css.properties.scrollbar-width
---
{{CSSRef}}
The **`scrollbar-width`** property allows the author to set the maximum thickness of an element's scrollbars when they are shown.
## Syntax
```css
/* Keyword values */
scrollbar-width: auto;
scrollbar-width: thin;
scrollbar-width: none;
/* Global values */
scrollbar-width: inherit;
scrollbar-width: initial;
scrollbar-width: revert;
scrollbar-width: revert-layer;
scrollbar-width: unset;
```
### Values
- `<scrollbar-width>`
- : Defines the width of the scrollbar as a keyword. It must be one of the following values:
<table class="standard-table">
<tbody>
<tr>
<td><code>auto</code></td>
<td>The default scrollbar width for the platform.</td>
</tr>
<tr>
<td><code>thin</code></td>
<td>
A thin scrollbar width variant on platforms that provide that option, or
a thinner scrollbar than the default platform scrollbar width.
</td>
</tr>
<tr>
<td><code>none</code></td>
<td>No scrollbar shown, however the element will still be scrollable.</td>
</tr>
</tbody>
</table>
> **Note:** User Agents must apply any `scrollbar-width` value set on the root element to the viewport.
## Accessibility concerns
Use this property with caution β setting `scrollbar-width` to `thin` or `none` can make content hard or impossible to scroll if the author does not provide an alternative scrolling mechanism. While swiping gestures or mouse wheels can enable scrolling on such content, some devices have no scroll alternative.
WCAG criterion 2.1.1 (Keyboard) has been in place for a long time to advise on basic keyboard accessibility, and this should include scrolling of content areas. And introduced in WCAG 2.1, criterion 2.5.5 (Target Size) advises that touch targets should be at least 44px in width and height (although the problem is compounded on high-resolution screens; thorough testing is advised).
- [MDN Understanding WCAG, Guideline 2.1 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Operable#guideline_2.1_β_keyboard_accessible_make_all_functionality_available_from_a_keyboard)
- [MDN Understanding WCAG, Guideline 2.5 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Operable#guideline_2.5_input_modalities_make_it_easier_for_users_to_operate_functionality_through_various_inputs_beyond_keyboard)
- [Understanding Success Criterion 2.1.1 | W3C Understanding WCAG 2.1](https://www.w3.org/WAI/WCAG21/Understanding/keyboard)
- [Understanding Success Criterion 2.5.5 | W3C Understanding WCAG 2.1](https://www.w3.org/WAI/WCAG21/Understanding/target-size.html)
## Formal definition
{{CSSInfo}}
## Formal syntax
{{CSSSyntax}}
## Examples
### Sizing overflow scrollbars
#### CSS
```css
.scroller {
width: 300px;
height: 100px;
overflow-y: scroll;
scrollbar-width: thin;
}
```
#### 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("Sizing_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-color")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/border-image-repeat/index.md | ---
title: border-image-repeat
slug: Web/CSS/border-image-repeat
page-type: css-property
browser-compat: css.properties.border-image-repeat
---
{{CSSRef}}
The **`border-image-repeat`** [CSS](/en-US/docs/Web/CSS) property defines how the [edge regions](/en-US/docs/Web/CSS/border-image-slice#edge-regions) and [middle region](/en-US/docs/Web/CSS/border-image-slice#middle-region) of a source image are adjusted to fit the dimensions of an element's [border image](/en-US/docs/Web/CSS/border-image). The middle region can be displayed by using the keyword "fill" in the border-image-slice property.
{{EmbedInteractiveExample("pages/css/border-image-repeat.html")}}
## Syntax
```css
/* Keyword value */
border-image-repeat: stretch;
border-image-repeat: repeat;
border-image-repeat: round;
border-image-repeat: space;
/* top and bottom | left and right */
border-image-repeat: round stretch;
/* Global values */
border-image-repeat: inherit;
border-image-repeat: initial;
border-image-repeat: revert;
border-image-repeat: revert-layer;
border-image-repeat: unset;
```
The `border-image-repeat` property may be specified using one or two values chosen from the list of values below.
- When **one** value is specified, it applies the same behavior on **all four sides**.
- When **two** values are specified, the first applies to the **top, middle, and bottom**, the second to the **left and right**.
### Values
- `stretch`
- : The source image's edge regions are stretched to fill the gap between each border.
- `repeat`
- : The source image's edge regions are tiled (repeated) to fill the gap between each border. Tiles may be clipped to achieve the proper fit.
- `round`
- : The source image's edge regions are tiled (repeated) to fill the gap between each border. Tiles may be stretched to achieve the proper fit.
- `space`
- : The source image's edge regions are tiled (repeated) to fill the gap between each border. Extra space will be distributed in between tiles to achieve the proper fit.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Repeating border images
#### CSS
```css
#bordered {
width: 12rem;
margin-bottom: 1rem;
padding: 1rem;
border: 40px solid;
border-image: url("border.png") 27;
border-image-repeat: stretch; /* Can be changed in the live sample */
}
```
```html hidden
<div id="bordered">You can try out various border repetition rules on me!</div>
<select id="repetition">
<option value="stretch">stretch</option>
<option value="repeat">repeat</option>
<option value="round">round</option>
<option value="space">space</option>
<option value="stretch repeat">stretch repeat</option>
<option value="space round">space round</option>
</select>
```
```js hidden
const repetition = document.getElementById("repetition");
repetition.addEventListener("change", (evt) => {
document.getElementById("bordered").style.borderImageRepeat =
evt.target.value;
});
```
#### Results
{{EmbedLiveSample("Repeating_border_images", "auto", 200)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Backgrounds and borders](/en-US/docs/Web/CSS/CSS_backgrounds_and_borders)
- [Learn CSS: Backgrounds and borders](/en-US/docs/Learn/CSS/Building_blocks/Backgrounds_and_borders)
- [Border images in CSS: A key focus area for Interop 2023](/en-US/blog/border-images-interop-2023/) on MDN blog (2023)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/ruby-align/index.md | ---
title: ruby-align
slug: Web/CSS/ruby-align
page-type: css-property
status:
- experimental
browser-compat: css.properties.ruby-align
---
{{CSSRef}}{{SeeCompatTable}}
The **`ruby-align`** CSS property defines the distribution of the different ruby elements over the base.
## Syntax
```css
/* Keyword values */
ruby-align: start;
ruby-align: center;
ruby-align: space-between;
ruby-align: space-around;
/* Global values */
ruby-align: inherit;
ruby-align: initial;
ruby-align: revert;
ruby-align: revert-layer;
ruby-align: unset;
```
### Values
- `start`
- : Is a keyword indicating that the ruby will be aligned with the start of the base text.
- `center`
- : Is a keyword indicating that the ruby will be aligned at the middle of the base text.
- `space-between`
- : Is a keyword indicating that the extra space will be distributed between the elements of the ruby.
- `space-around`
- : Is a keyword indicating that the extra space will be distributed between the elements of the ruby, and around it.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Ruby aligned at the start of the base text
#### HTML
```html
<ruby>
<rb>This is a long text to check</rb>
<rp>οΌ</rp><rt>short ruby</rt><rp>οΌ</rp>
</ruby>
```
#### CSS
```css
ruby {
ruby-align: start;
}
```
#### Result
{{EmbedLiveSample("Ruby_aligned_at_the_start_of_the_base_text", 180, 40)}}
### Ruby aligned at the center of the base text
#### HTML
```html
<ruby>
<rb>This is a long text to check</rb>
<rp>οΌ</rp><rt>short ruby</rt><rp>οΌ</rp>
</ruby>
```
#### CSS
```css
ruby {
ruby-align: center;
}
```
#### Result
{{EmbedLiveSample("Ruby_aligned_at_the_center_of_the_base_text", 180, 40)}}
### Extra space distributed between ruby elements
#### HTML
```html
<ruby>
<rb>This is a long text to check</rb>
<rp>οΌ</rp><rt>short ruby</rt><rp>οΌ</rp>
</ruby>
```
#### CSS
```css
ruby {
ruby-align: space-between;
}
```
#### Result
{{EmbedLiveSample("Extra_space_distributed_between_ruby_elements", 180, 40)}}
### Extra space distributed between and around ruby elements
#### HTML
```html
<ruby>
<rb>This is a long text to check</rb>
<rp>οΌ</rp><rt>short ruby</rt><rp>οΌ</rp>
</ruby>
```
#### CSS
```css
ruby {
ruby-align: space-around;
}
```
#### Result
{{EmbedLiveSample("Extra_space_distributed_between_and_around_ruby_elements", 180, 40)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- HTML Ruby elements: {{HTMLElement("ruby")}}, {{HTMLElement("rt")}}, {{HTMLElement("rp")}}, and {{HTMLElement("rtc")}}.
- CSS Ruby properties: {{cssxref("ruby-position")}}, {{cssxref("ruby-merge")}}.
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/css_houdini/index.md | ---
title: CSS Houdini
slug: Web/CSS/CSS_Houdini
page-type: guide
status:
- experimental
---
{{CSSRef}}
**CSS Houdini** is a set of APIs that expose parts of the CSS engine. This makes it easier for developers to create extensions for CSS. These extensions might be to polyfill features that are not yet available in a browser, experiment with new ways of doing layout, or add creative borders or other effects.
While many Houdini examples showcase the creative possibilities of the APIs, there are many practical use cases. For example, you can use Houdini to create advanced custom properties with type checking and default values.
## Basic example
A regular [CSS custom property](/en-US/docs/Web/CSS/--*) consists of a property name and a value. Therefore I might create a custom property called `--background-color` and expect it to be given a color value. The value is then used in the CSS as if it were the color value.
```css
:root {
--background-color: blue;
}
.box {
background-color: var(--background-color);
}
```
In the above example however, there is nothing to stop someone using some other value for this property, perhaps setting it to a length. Having done so, anywhere that the property is used would have no background color as `background-color: 12px` is not valid. When browsers come across CSS they don't recognize as valid they throw that line away.
Using {{cssxref("@property")}} however, we can declare the custom property with a {{CSSxRef("@property/syntax","syntax")}} of `<color>`. This shows that we need this property to have a value which is a valid color.
```css
@property --background-color {
syntax: "<color>";
inherits: false;
initial-value: blue;
}
```
## Houdini worklets
A feature of Houdini is the {{domxref("Worklet")}}. A worklet is a module, written in JavaScript, that extends CSS using one of the Houdini APIs. You can see an example worklet on the {{domxref("PaintWorkletGlobalScope.registerPaint()")}} page. Once a worklet has been registered you can use it in CSS just like any other value. This means that even if you are not a JavaScript developer, you can access Houdini APIs by using worklets other people have created.
The [Houdini.how](https://houdini.how/) website has a number of worklets that you can try on your own site.
## Reference
### CSS at-rule and descriptors
The {{CSSxRef("@property")}} at-rule allows you to register an advanced custom property.
- {{CSSxRef("@property")}}
- {{CSSxRef("@property/inherits","inherits")}}
- {{CSSxRef("@property/initial-value","initial-value")}}
- {{CSSxRef("@property/syntax","syntax")}}
### Houdini API references
- [CSS Properties and Values API](/en-US/docs/Web/API/CSS_Properties_and_Values_API)
- [CSS Typed Object Model API](/en-US/docs/Web/API/CSS_Typed_OM_API)
- [CSS Painting API](/en-US/docs/Web/API/CSS_Painting_API)
- {{domxref("Worklet")}} reference
### Houdini guides
- [Properties and Values API Guide](/en-US/docs/Web/API/CSS_Properties_and_Values_API/guide)
- [Typed OM API Guide](/en-US/docs/Web/API/CSS_Typed_OM_API/Guide)
- [Using the CSS Painting API](/en-US/docs/Web/API/CSS_Painting_API/Guide)
## External resources
- [Interactive introduction to Houdini](https://houdini.glitch.me/)
- [A Practical Overview of CSS Houdini](https://www.smashingmagazine.com/2020/03/practical-overview-css-houdini/)
- [Smarter custom properties with Houdini's new API](https://web.dev/articles/css-props-and-vals)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_dir/index.md | ---
title: ":dir()"
slug: Web/CSS/:dir
page-type: css-pseudo-class
browser-compat: css.selectors.dir
---
{{CSSRef}}
The **`:dir()`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) matches elements based on the directionality of the text contained in them.
```css
/* Selects any element with right-to-left text */
:dir(rtl) {
background-color: red;
}
```
The `:dir()` pseudo-class uses only the _semantic_ value of the directionality, i.e., the one defined in the document itself. It doesn't account for _styling_ directionality, i.e., the directionality set by CSS properties such as {{cssxref("direction")}}.
> **Note:** Be aware that the behavior of the `:dir()` pseudo-class is not equivalent to the `[dir=β¦]` [attribute selectors](/en-US/docs/Web/CSS/Attribute_selectors). The latter match the HTML [`dir`](/en-US/docs/Web/HTML/Global_attributes#dir) attribute, and ignore elements that lack it β even if they inherit a direction from their parent. (Similarly, `[dir=rtl]` and `[dir=ltr]` won't match the `auto` value.) In contrast, `:dir()` will match the value calculated by the {{glossary("user agent")}}, even if inherited.
> **Note:** In HTML, the direction is determined by the [`dir`](/en-US/docs/Web/HTML/Global_attributes#dir) attribute. Other document types may have different methods.
## Syntax
The `:dir()` pseudo-class requires one parameter, representing the text directionality you want to target.
```css-nolint
:dir([ltr | rtl]) {
/* ... */
}
```
### Parameters
- `ltr`
- : Target left-to-right elements.
- `rtl`
- : Target right-to-left elements.
## Examples
### HTML
```html
<div dir="rtl">
<span>test1</span>
<div dir="ltr">
test2
<div dir="auto">Χ’Φ΄ΧΦ°Χ¨Φ΄ΧΧͺ</div>
</div>
</div>
```
### CSS
```css
:dir(ltr) {
background-color: yellow;
}
:dir(rtl) {
background-color: powderblue;
}
```
### Result
{{ EmbedLiveSample('Examples') }}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- Language-related pseudo-classes: {{cssxref(":lang")}}, {{cssxref(":dir")}}
- HTML [`lang`](/en-US/docs/Web/HTML/Global_attributes#lang) attribute
- HTML [`translate`](/en-US/docs/Web/HTML/Global_attributes#translate) attribute
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/cross-fade/index.md | ---
title: cross-fade()
slug: Web/CSS/cross-fade
page-type: css-function
browser-compat: css.types.image.cross-fade
---
{{CSSRef}}
The **`cross-fade()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) can be used to blend two or more images at a defined transparency.
It can be used for many simple image manipulations, such as tinting an image with a solid color or highlighting a particular area of the page by combining an image with a radial gradient.
## Syntax
> **Warning:** The specification and current implementations have different syntaxes.
> The specification syntax is explained first.
### Specification syntax
The `cross-fade()` function takes a list of images with a percentage defining how much of each image is retained in terms of opacity when it is blended with the other images. The percent value must be coded without quotes, must contain the `'%'` symbol, and its value must be between 0% and 100%.
The function can be used in CSS anywhere an ordinary image reference can be used.
#### Cross-fade percentages
Think of the percentage as an opacity value for each image. This means a value of 0% means the image is fully transparent while a value of 100% makes the image fully opaque.
```css
cross-fade(url(white.png) 0%, url(black.png) 100%); /* fully black */
cross-fade(url(white.png) 25%, url(black.png) 75%); /* 25% white, 75% black */
cross-fade(url(white.png) 50%, url(black.png) 50%); /* 50% white, 50% black */
cross-fade(url(white.png) 75%, url(black.png) 25%); /* 75% white, 25% black */
cross-fade(url(white.png) 100%, url(black.png) 0%); /* fully white */
cross-fade(url(green.png) 75%, url(red.png) 75%); /* both green and red at 75% */
```
If any percentages are omitted, all the specified percentages are summed together and subtracted from `100%`.
If the result is greater than 0%, the result is then divided equally between all images with omitted percentages.
In the simplest case, two images are faded between each other. To do that, only one of the images needs to have a percentage, the other one will be faded accordingly.
For example, a value of 0% defined for the first image yields only the second image, while 100% yields only the first.
A 25% value renders the first image at 25% and the second at 75%. The 75% value is the inverse, showing the first image at 75% and the second at 25%.
The above could also have been written as:
```css
cross-fade(url(white.png) 0%, url(black.png)); /* fully black */
cross-fade(url(white.png) 25%, url(black.png)); /* 25% white, 75% black */
cross-fade(url(white.png), url(black.png)); /* 50% white, 50% black */
cross-fade(url(white.png) 75%, url(black.png)); /* 75% white, 25% black */
cross-fade(url(white.png) 100%, url(black.png)); /* fully white */
cross-fade(url(green.png) 75%, url(red.png) 75%); /* both green and red at 75% */
```
If no percentages are declared, both the images will be 50% opaque, with a cross-fade rendering as an even merge of both images.
The 50%/50% example seen above did not need to have the percentages listed, as when a percentage value is omitted, the included percentages are added together and subtracted from 100%.
The result, if greater than 0, is then divided equally between all images with omitted percentages.
In the last example, the sum of both percentages is not 100%, and therefore both images include their respective opacities.
If no percentages are declared and three images are included, each image will be 33.33% opaque. The two following are lines (almost) identical:
```css
cross-fade(url(red.png), url(yellow.png), url(blue.png)); /* all three will be 33.3333% opaque */
cross-fade(url(red.png) 33.33%, url(yellow.png) 33.33%, url(blue.png) 33.33%);
```
### Older, implemented syntax
```css
cross-fade( <image>, <image>, <percentage> )
```
The specification for the `cross-fade()` function allows for multiple images and for each image to have transparency values independent of the other values.
This was not always the case.
The original syntax, which has been implemented in some browsers, only allowed for two images, with the sum of the transparency of those two images being exactly 100%.
The original syntax is supported in Safari and supported with the `-webkit-` prefix in Chrome, Opera, and other blink-based browsers.
```css
cross-fade(url(white.png), url(black.png), 0%); /* fully black */
cross-fade(url(white.png), url(black.png), 25%); /* 25% white, 75% black */
cross-fade(url(white.png), url(black.png), 50%); /* 50% white, 50% black */
cross-fade(url(white.png), url(black.png), 75%); /* 75% white, 25% black */
cross-fade(url(white.png), url(black.png), 100%); /* fully white */
```
In the implemented syntax, the two comma-separated images are declared first, followed by a comma and required percent value. Omitting the comma or percent invalidates the value.
The percent is the opacity of the first declared image. The included percentage is subtracted from 100%, with the difference being the opacity of the second image.
The green/red example (with the percentages totaling 150%) and the yellow/red/blue example (with three images) from the specification syntax section, are not possible in this implementation.
## 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.
When using background images, make sure the contrast in color is great enough that any text is legible over the image as well as if the images are missing.
- [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 syntax
{{csssyntax}}
## Examples
### Older syntax for cross-fade
#### HTML
```html
<div class="crossfade"></div>
```
#### CSS
```css
.crossfade {
width: 300px;
height: 300px;
background-image: -webkit-cross-fade(url("br.png"), url("tr.png"), 75%);
background-image: cross-fade(url("br.png"), url("tr.png"), 75%);
}
```
#### Result
{{EmbedLiveSample("Older_syntax_for_cross-fade", "330", "330")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("image")}}
- {{cssxref("url")}}
- {{cssxref("image/image", "image()")}}
- {{cssxref("image/image-set", "image-set()")}}
- {{cssxref("element")}}
- [Using CSS gradients](/en-US/docs/Web/CSS/CSS_images/Using_CSS_gradients)
- Gradient functions: {{cssxref("gradient/linear-gradient", "linear-gradient()")}}, {{cssxref("gradient/radial-gradient", "radial-gradient()")}}, {{cssxref("gradient/repeating-linear-gradient", "repeating-linear-gradient()")}}, {{cssxref("gradient/repeating-radial-gradient", "repeating-radial-gradient()")}}, {{cssxref("gradient/conic-gradient", "conic-gradient()")}}, {{cssxref("gradient/repeating-conic-gradient", "repeating-conic-gradient()")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/clip/index.md | ---
title: clip
slug: Web/CSS/clip
page-type: css-property
status:
- deprecated
browser-compat: css.properties.clip
---
{{CSSRef}}{{Deprecated_Header}}
> **Warning:** Where possible, authors are encouraged to use the newer {{cssxref("clip-path")}} property instead.
The **`clip`** [CSS](/en-US/docs/Web/CSS) property defines a visible portion of an element. The `clip` property applies only to absolutely positioned elements β that is, elements with {{cssxref("position","position:absolute")}} or {{cssxref("position","position:fixed")}}.
## Syntax
```css
/* Keyword value */
clip: auto;
/* <shape> values */
clip: rect(1px, 10em, 3rem, 2ch);
/* Global values */
clip: inherit;
clip: initial;
clip: revert;
clip: revert-layer;
clip: unset;
```
### Values
- {{cssxref("shape")}}
- : A rectangular {{cssxref("shape")}} of the form `rect(<top>, <right>, <bottom>, <left>)`. The `<top>` and `<bottom>` values are offsets from the _inside top border edge_ of the box, while `<right>` and `<left>` are offsets from the _inside left border edge_ of the box β that is, the extent of the padding box.
The `<top>`, `<right>`, `<bottom>`, and `<left>` values may be either a {{cssxref("<length>")}} or `auto`. If any side's value is `auto`, the element is clipped to that side's _inside border edge_.
- `auto`
- : The element does not clip (default). This is different from `rect(auto, auto, auto, auto)`, which clips to the element's inside border edges.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Clipping an image
```html
<p class="dotted-border">
<img src="macarons.png" alt="Original graphic" />
<img id="top-left" src="macarons.png" alt="Graphic clipped to upper left" />
<img id="middle" src="macarons.png" alt="Graphic clipped towards middle" />
<img
id="bottom-right"
src="macarons.png"
alt="Graphic clipped to bottom right" />
</p>
```
```css
.dotted-border {
border: dotted;
position: relative;
width: 390px;
height: 400px;
}
#top-left,
#middle,
#bottom-right {
position: absolute;
top: 0;
}
#top-left {
left: 400px;
clip: rect(0, 130px, 90px, 0);
}
#middle {
left: 270px;
clip: rect(100px, 260px, 190px, 130px);
}
#bottom-right {
left: 140px;
clip: rect(200px, 390px, 290px, 260px);
}
```
{{EmbedLiveSample('clipping_an_image', '', '450px')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- This property is deprecated. Use {{cssxref("clip-path")}} instead.
- Related CSS properties:
- {{cssxref("text-overflow")}}
- {{cssxref("white-space")}}
- {{cssxref("overflow-x")}}
- {{cssxref("overflow-y")}}
- {{cssxref("overflow")}}
- {{cssxref("display")}}
- {{cssxref("position")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/column-rule-width/index.md | ---
title: column-rule-width
slug: Web/CSS/column-rule-width
page-type: css-property
browser-compat: css.properties.column-rule-width
---
{{CSSRef}}
The **`column-rule-width`** [CSS](/en-US/docs/Web/CSS) property sets the width of the line drawn between columns in a multi-column layout.
{{EmbedInteractiveExample("pages/css/column-rule-width.html")}}
## Syntax
```css
/* Keyword values */
column-rule-width: thin;
column-rule-width: medium;
column-rule-width: thick;
/* <length> values */
column-rule-width: 1px;
column-rule-width: 2.5em;
/* Global values */
column-rule-width: inherit;
column-rule-width: initial;
column-rule-width: revert;
column-rule-width: revert-layer;
column-rule-width: unset;
```
The `column-rule-width` property is specified as a single `<'border-width'>` value.
### Values
- `<'border-width'>`
- : Is a keyword defined by {{ cssxref("border-width") }} describing the width of the rule. It may be either a {{cssxref("<length>")}} or one of the `thin`, `medium`, or `thick` keywords.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting a thick column rule
#### HTML
```html
<p>
This is a bunch of text split into three columns. The `column-rule-width`
property is used to change the width of the line that is drawn between
columns. Don't you think that's wonderful?
</p>
```
#### CSS
```css
p {
column-count: 3;
column-rule-style: solid;
column-rule-width: thick;
}
```
#### Result
{{EmbedLiveSample("Setting_a_thick_column_rule")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Multiple-column Layout](/en-US/docs/Learn/CSS/CSS_layout/Multiple-column_Layout)
- {{CSSXref("column-rule-style")}}
- {{CSSXref("column-rule-color")}}
- {{CSSXref("column-rule")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/grid-column/index.md | ---
title: grid-column
slug: Web/CSS/grid-column
page-type: css-shorthand-property
browser-compat: css.properties.grid-column
---
{{CSSRef}}
The **`grid-column`** CSS [shorthand property](/en-US/docs/Web/CSS/Shorthand_properties) specifies a grid item's size and location within a {{glossary("grid column")}} by contributing a line, a span, or nothing (automatic) to its grid placement, thereby specifying the inline-start and inline-end edge of its {{glossary("grid areas", "grid area")}}.
{{EmbedInteractiveExample("pages/css/grid-column.html")}}
## Constituent properties
This property is a shorthand for the following CSS properties:
- [`grid-column-end`](/en-US/docs/Web/CSS/grid-column-end)
- [`grid-column-start`](/en-US/docs/Web/CSS/grid-column-start)
## Syntax
```css
/* Keyword values */
grid-column: auto;
grid-column: auto / auto;
/* <custom-ident> values */
grid-column: somegridarea;
grid-column: somegridarea / someothergridarea;
/* <integer> + <custom-ident> values */
grid-column: somegridarea 4;
grid-column: 4 somegridarea / 6;
/* span + <integer> + <custom-ident> values */
grid-column: span 3;
grid-column: span somegridarea;
grid-column: 5 somegridarea span;
grid-column: span 3 / 6;
grid-column: span somegridarea / span someothergridarea;
grid-column: 5 somegridarea span / 2 span;
/* Global values */
grid-column: inherit;
grid-column: initial;
grid-column: revert;
grid-column: revert-layer;
grid-column: unset;
```
This property is specified as one or two `<grid-line>` values.
If two `<grid-line>` values are given, they are separated by `/`.
The `grid-column-start` longhand is set to the value before the slash, and the `grid-column-end` longhand is set to the value after the slash.
Each `<grid-line>` value can be specified as:
- either the `auto` keyword
- or a `<custom-ident>` value
- or an `<integer>` value
- or both `<custom-ident>` and `<integer>`, separated by a space
- or the keyword `span` together with either a `<custom-ident>` or an `<integer>` or both.
### Values
- `auto`
- : Is a keyword indicating that the property contributes nothing to the grid item's placement, indicating auto-placement, an automatic span, or a default span of `1`.
- `<custom-ident>`
- : If there is a named line with the name `<custom-ident>-start`/`<custom-ident>-end`, it contributes the first such line to the grid item's placement.
> **Note:** Named grid areas automatically generate implicit named lines of this form, so specifying `grid-column: foo;` will choose the start/end edge of that named grid area (unless another line named `foo-start`/`foo-end` was explicitly specified before it).
Otherwise, this is treated as if the integer `1` had been specified along with the `<custom-ident>`.
- `<integer> && <custom-ident>?`
- : Contributes the nth grid line to the grid item's placement. If a negative integer is given, it instead counts in reverse, starting from the end edge of the explicit grid.
If a name is given as a `<custom-ident>`, only lines with that name are counted. If not enough lines with that name exist, all implicit grid lines are assumed to have that name for the purpose of finding this position.
An {{cssxref("integer")}} value of `0` is invalid.
- `span && [ <integer> || <custom-ident> ]`
- : Contributes a grid span to the grid item's placement such that the corresponding edge of the grid item's grid area is n lines from the opposite edge.
If a name is given as a `<custom-ident>`, only lines with that name are counted. If not enough lines with that name exist, all implicit grid lines on the side of the explicit grid corresponding to the search direction are assumed to have that name for the purpose of counting this span.
If the `<integer>` is omitted, it defaults to `1`. Negative integers or 0 are invalid.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting grid column size and location
#### HTML
```html
<div id="grid">
<div id="item1"></div>
<div id="item2"></div>
<div id="item3"></div>
</div>
```
#### CSS
```css
#grid {
display: grid;
height: 100px;
grid-template-columns: repeat(6, 1fr);
grid-template-rows: 100px;
}
#item1 {
background-color: lime;
}
#item2 {
background-color: yellow;
grid-column: 2 / 4;
}
#item3 {
background-color: blue;
grid-column: span 2 / 7;
}
```
#### Result
{{EmbedLiveSample("Setting_grid_column_size_and_location", "100%", "100px")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- Related CSS properties: {{cssxref("grid-row")}}, {{cssxref("grid-row-start")}}, {{cssxref("grid-row-end")}}, {{cssxref("grid-column-start")}}, {{cssxref("grid-column-end")}}
- Grid Layout Guide: _[Line-based placement with CSS Grid](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_layout_using_line-based_placement)_
- Video tutorial: _[Line-based placement](https://gridbyexample.com/video/series-line-based-placement/)_
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/ray/index.md | ---
title: ray()
slug: Web/CSS/ray
page-type: css-function
browser-compat: css.types.ray
---
{{CSSRef}}
The **`ray()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) defines the [`offset-path`](/en-US/docs/Web/CSS/offset-path) line segment that an animated element can follow. The line segment is referred to as "ray". The ray begins from an {{cssxref("offset-position")}} and extends in the direction of the specified angle. The length of a ray can be constrained by specifying a size and using the `contain` keyword.
## Syntax
```css
/* all parameters specified */
offset-path: ray(50deg closest-corner contain at 100px 20px);
/* two parameters specified, order does not matter */
offset-path: ray(contain 200deg);
/* only one parameter specified */
offset-path: ray(45deg);
```
### Parameters
The parameters can be specified in any order.
- [`<angle>`](/en-US/docs/Web/CSS/angle)
- : Specifies the direction in which the line segment extends from the offset starting position. The angle `0deg` lies on the y-axis pointing up, and positive angles increase in the clockwise direction.
- `<size>`
- : Specifies the length of the line segment, which is the distance between {{cssxref("offset-distance")}} `0%` and `100%`, relative to the containing box. This is an optional parameter (`closest-side` is used if no `<size>` is specified). It accepts one of the following keyword values:
`closest-side`: Distance between the ray's starting point and the closest side of the [containing block](/en-US/docs/Web/CSS/Containing_block) of the element. If the ray's starting point lies on an edge of the containing block, the length of the line segment is zero. If the ray's starting point is outside the containing block, the edge of the containing block is considered to extend to infinity. This is the default value.
`closest-corner`: Distance between the ray's starting point and the closest corner in the element's containing block. If the ray's starting point lies on a corner of the containing block, the length of the line segment is zero.
`farthest-side`: Distance between the ray's starting point and the farthest side of the containing block of the element. If the ray's starting point is outside the containing block, the edge of the containing block is considered to extend to infinity.
`farthest-corner`: Distance between the ray's starting point and the farthest corner in the element's containing block.
`sides`: Distance between the ray's starting point and the point where the line segment intersects the containing block's boundary. If the starting point is on or outside the containing block's boundary, the length of the line segment is zero.
- `contain`
- : Reduces the length of the line segment so that the element stays within the containing block even at `offset-distance: 100%`. Specifically, the segment's length is reduced by half the width or half the height of the element's border box, whichever is greater, and never less than zero. This is an optional parameter.
- `at <position>`
- : Specifies the point where the ray begins and where the element is placed in its containing block. This is an optional parameter. If included, the `<position>` value must be preceded by the `at` keyword. If omitted, the value used is the `offset-position` value of the element. If omitted and the element doesn't have an `offset-position` value, the value used for the ray's starting position is `offset-position: normal`, which places the element at the center (or `50% 50%`) of the containing block.
## Description
The `ray()` function positions an element along a path by specifying its location in a two-dimensional space through an angle and a distance from a reference point (polar coordinates). This feature makes the `ray()` function useful for creating 2D spatial transitions. For comparison, this approach differs from the method of specifying a point by its horizontal and vertical distances from a fixed origin (rectangular coordinates), which is used by the {{cssxref("translate","translate()")}} function, and from moving an element along a defined path through animation.
As `ray()` works in 2D space, it's important to consider both the initial position and orientation of the element. When the `ray()` function is applied as the `offset-path` value on an element, here's how you can control these aspects:
- The element is initially positioned by moving the element's [`offset-anchor`](/en-US/docs/Web/CSS/offset-anchor) point to the element's offset starting position. By default, the ray's starting position is determined by the {{cssxref("offset-position")}} value. If `offset-position` is explicitly specified as `normal` (or omitted and allowed to default to `normal`), the element is positioned at the `center` (or `50% 50%`) of its containing block. Specifying `offset-position: auto` sets the starting position at the `top left` corner (or `0 0`) of the element's position.
- The element is initially rotated such that its [inline axis](/en-US/docs/Web/CSS/CSS_grid_layout/Box_alignment_in_grid_layout#the_two_axes_of_a_grid_layout) β its direction of text flow β aligns with the angle specified by `ray()`. For example, with the `ray()` angle of `0deg`, which lies on the y-axis pointing up, the element's inline axis is rotated to be vertical to match the ray's angle. The element maintains this rotation throughout its path. To customize this behavior, use the {{cssxref("offset-rotate")}} property, which allows you to specify a different rotation angle or direction for the element, enabling more precise control over its appearance as it follows the path. For example, setting `offset-rotate: 0deg` will remove any rotation applied by `ray()`, aligning back the element's inline axis with the direction of text flow.
## Formal syntax
{{csssyntax}}
## Examples
### Defining the angle and starting position for a ray
This example shows how to work with an element's starting position and how the element's orientation is impacted by the specified ray angle.
#### CSS
```css hidden
body {
width: fit-content;
height: fit-content;
}
.container {
width: 80vw;
height: 100px;
border: 1px dashed black;
margin: 0 0.5em 2em 2em;
text-align: center;
}
pre {
font-size: 1em;
text-align: right;
padding-right: 10px;
line-height: 1em;
}
.box {
display: flex;
justify-content: center;
align-items: center;
width: 50px;
height: 50px;
}
.box + .box {
opacity: 1;
}
```
```css
.box {
background-color: palegreen;
border-top: 4px solid black;
opacity: 20%;
}
.box:first-of-type {
position: absolute;
}
.box1 {
offset-path: ray(0deg);
}
.box2 {
offset-path: ray(150deg);
}
.box3 {
offset-rotate: 0deg;
offset-position: 20% 40%;
offset-path: ray(150deg);
}
.box4 {
offset-position: 0 0;
offset-path: ray(0deg);
}
.box5 {
offset-path: ray(60deg closest-side at bottom right);
}
```
```html hidden
<pre>/* original */</pre>
<div class="container">
<div class="box">0</div>
<div class="box box0">0</div>
</div>
<pre>
offset-path: ray(0deg);
/* Default offset starting position is 50% 50% */
</pre>
<div class="container">
<div class="box">0</div>
<div class="box box1">1</div>
</div>
<pre>
offset-path: ray(150deg);
</pre>
<div class="container">
<div class="box">0</div>
<div class="box box2">2</div>
</div>
<pre>
offset-rotate: 0deg;
offset-position: 20% 40%;
offset-path: ray(150deg);
</pre>
<div class="container">
<div class="box">0</div>
<div class="box box3">3</div>
</div>
<pre>
offset-position: 0 0;
offset-path: ray(0deg);
</pre>
<div class="container">
<div class="box">0</div>
<div class="box box4">4</div>
</div>
<pre>
offset-path: ray(60deg closest-side at bottom right);
</pre>
<div class="container">
<div class="box">0</div>
<div class="box box5">5</div>
</div>
```
Similar to {{cssxref("transform-origin")}}, the default anchor point is at the center of an element. This anchor point can be modified using the [`offset-anchor`](/en-US/docs/Web/CSS/offset-anchor) property.
In this example, various `offset-path: ray()` values are applied to the boxes numbered `1` to `5`. The "containing block" of each box is depicted with a dashed border. A faded box in the upper left corner shows each box's default position without any `offset-position` or `offset-path` applied, allowing for a side-by-side comparison. The top of each box is highlighted with a `solid` border to illustrate variations in ray starting points and orientations. After positioning at the ray's starting point, a box aligns with the direction of the specified ray angle. If {{cssxref("offset-position")}} is not specified, the default offset starting position of the ray is the center (or `50% 50%`) of the box's containing block.
#### Result
{{EmbedLiveSample('Giving an angle to the ray', '100%', 1100)}}
- `box1` gets initially positioned such that its anchor point (its center) is at the default offset starting position (`50% 50%` of the containing block). `box1` is also rotated to orient it towards the `0deg` angle of the ray. This will now be the starting point of the path. You can observe the change in position and rotation of the box by comparing it to the faded `box0` on the left. The box is rotated to match the `0deg` angle along y-axis, pointing up. The box rotation is evident from the orientation of the number inside the box.
- In `box2`, a greater positive angle of `150deg` is applied to the ray to show how the ray angle works. Starting from the top-left corner, the box is rotated in a clockwise direction to reach the specified angle of `150deg`.
- `box2` and `box3` have the same `offset-path` values. In `box3`, an [`offset-rotate`](/en-US/docs/Web/CSS/offset-rotate) of `0deg` is also applied to the element. As a result, the element will remain rotated at this specific angle all along the ray's path, and the element will not rotate in the direction of the path. Notice in `box3` that the ray path is at `150deg`, but the box orientation will not change along the path because of `offset-rotate`. Also note that the `offset-path` property of `box3` does not specify a starting `<position>`, so the ray's starting position is derived from the element's `offset-position`, which in this case is `top 20% left 40%`.
- The `offset-position` of `box4` is set to top-left corner (`0 0`) of the containing block, and as a result, the element's anchor point and the offset starting position coincide. The ray angle of `0deg` is applied to the element at this starting point.
- In `box5`, the `offset-path` property specifies the `at <position>` value, which places the box at the `bottom` and `right` edge of the element's containing block and `60deg` is applied to the ray's angle.
### Animating an element along the ray
In this example, the first shape is shown as a reference for its position and orientation. A ray motion path is applied on the other shapes.
#### CSS
```css
body {
display: grid;
grid-template-columns: 200px 100px;
gap: 40px;
margin-left: 40px;
}
.container {
transform-style: preserve-3d;
width: 150px;
height: 100px;
border: 2px dotted green;
}
.shape {
width: 40px;
height: 40px;
background: #2bc4a2;
margin: 5px;
text-align: center;
line-height: 40px;
clip-path: polygon(0% 0%, 70% 0%, 100% 50%, 70% 100%, 0% 100%, 30% 50%);
animation: move 5000ms infinite alternate ease-in-out;
}
.shape2 {
offset-path: ray(120deg sides contain);
}
.shape3 {
offset-rotate: 0deg;
offset-path: ray(120deg sides contain);
}
.shape4 {
offset-position: auto;
offset-path: ray(120deg closest-corner);
}
.shape5 {
offset-position: auto;
offset-path: ray(120deg farthest-corner);
}
@keyframes move {
0%, 20% {
offset-distance: 0%;
}
80%, 100% {
offset-distance: 100%;
}
```
```html hidden
<div>
<div class="container">
<div class=" shape shape1">—</div>
</div>
</div>
<pre>/* no offset-path applied */</pre>
<div>
<div class="container">
<div class="shape shape2">—</div>
</div>
</div>
<pre>offset-path: ray(120deg sides contain);</pre>
<div>
<div class="container">
<div class="shape shape3">—</div>
</div>
</div>
<pre>offset-path: ray(120deg sides contain);
offset-rotate: 0deg;</pre>
<div>
<div class="container">
<div class="shape shape4">—</div>
</div>
</div>
<pre>
offset-position: auto;
offset-path: ray(120deg closest-corner)</pre>
<div>
<div class="container">
<div class="shape shape5">—</div>
</div>
</div>
<pre>
offset-position: auto;
offset-path: ray(120deg farthest-corner)</pre>
</div>
```
#### Result
{{EmbedLiveSample('Animating an element along the ray', '100%', 750)}}
In the first two samples where `offset-path` is applied, notice the orientation of the shape without {{cssxref("offset-rotate")}} and with `offset-rotate`. Both these samples use the default {{cssxref("offset-position")}} value `normal`, and therefore, the path motion starts from `50% 50%`. The last two `offset-path` samples show the impact of corner `<size>` values: `closest-corner` and `farthest-corner`. The `closest-corner` value creates a very short offset-path because the shape is already at the corner (`offset-position: auto`). The `farthest-corner` value creates the longest offset-path, going from the top-left corner of the containing block to the bottom-right corner.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [`offset-distance`](/en-US/docs/Web/CSS/offset-distance)
- [`offset-path`](/en-US/docs/Web/CSS/offset-path)
- [`offset-rotate`](/en-US/docs/Web/CSS/offset-rotate)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/pseudo-elements/index.md | ---
title: Pseudo-elements
slug: Web/CSS/Pseudo-elements
page-type: landing-page
spec-urls:
- https://drafts.csswg.org/css-pseudo/
- https://drafts.csswg.org/css-position-4/
- https://drafts.csswg.org/css-shadow-parts/
- https://w3c.github.io/webvtt/
---
{{CSSRef}}
A CSS **pseudo-element** is a keyword added to a selector that lets you style a specific part of the selected element(s).
## Syntax
```css
selector::pseudo-element {
property: value;
}
```
For example, {{CSSxRef("::first-line")}} can be used to change the font of the first line of a paragraph.
```css
/* The first line of every <p> element. */
p::first-line {
color: blue;
text-transform: uppercase;
}
```
Double colons (`::`) are used for pseudo-elements. This distinguishes pseudo-elements from [pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes) that use single colon (`:`) in their notation.
You can use only one pseudo-element in a selector. The pseudo-element must appear after all the other components in the [complex](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#complex_selector) or [compound](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#compound_selector) selector in which it appears. For example, you can select a paragraph's first line using `p::first-line` but not the first-line's children or a hovered first line. So both `p::first-line > *` and `p::first-line:hover` are invalid.
While it is not possible to select an element based on its _state_ by using pseudo-elements, a pseudo-element can be used to select and style a part of an element that already has a state applied to it. For example, `p:hover::first-line` selects the first line (pseudo-element) of a paragraph when the paragraph itself is being hovered (pseudo-class).
> **Note:** When a [selector list](/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#selector_list) contains an invalid selector, the entire style block is ignored.
## List of pseudo-elements
Pseudo-elements defined by a set of CSS specifications include the following:
A
- {{CSSxRef("::after")}}
B
- {{CSSxRef("::backdrop")}}
- {{CSSxRef("::before")}}
C
- {{CSSxRef("::cue")}}
- {{CSSxRef("::cue-region")}}
F
- {{CSSxRef("::first-letter")}}
- {{CSSxRef("::first-line")}}
- {{CSSxRef("::file-selector-button")}}
G
- {{CSSxRef("::grammar-error")}} {{Experimental_Inline}}
M
- {{CSSxRef("::marker")}}
P
- {{CSSxRef("::part", "::part()")}}
- {{CSSxRef("::placeholder")}}
S
- {{CSSxRef("::selection")}}
- {{CSSxRef("::slotted", "::slotted()")}}
- {{CSSxRef("::spelling-error")}} {{Experimental_Inline}}
T
- {{CSSxRef("::target-text")}} {{Experimental_Inline}}
> **Note:** Browsers support the single colon syntax only for the original four pseudo-elements: `::before`, `::after`, `::first-line`, and `::first-letter`.
## Specifications
{{Specifications}}
## See also
- [CSS pseudo-element](/en-US/docs/Web/CSS/CSS_pseudo-elements) module
- [Pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes)
- [CSS selectors](/en-US/docs/Web/CSS/CSS_selectors) module
- [CSS building blocks: Pseudo-classes and pseudo-elements](/en-US/docs/Learn/CSS/Building_blocks/Selectors/Pseudo-classes_and_pseudo-elements)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/container-type/index.md | ---
title: container-type
slug: Web/CSS/container-type
page-type: css-property
browser-compat: css.properties.container-type
---
{{CSSRef}}
An element can be established as a query container for [container size queries](/en-US/docs/Web/CSS/CSS_containment/Container_queries) using the **`container-type`** [CSS](/en-US/docs/Web/CSS) property. `container-type` is used to define the type of size containment used in a container query.
Size containment turns off the ability of an element to get size information from its contents, which is important for container queries to avoid infinite loops. If this were not the case, a CSS rule inside a container query could change the content size, which in turn could make the query evaluate to false and change the parent element's size, which in turn could change the content size and flip the query back to true, and so on.
The container size has to be set explicitly or by context β for example, block elements, flex containers, and grid containers stretching to the full width of their parent. If an explicit or contextual size is not available, elements with size containment will collapse.
> **Note:** When using the `container-type` and {{cssxref("container-name")}} properties, the `style` and `layout` values of the {{cssxref("contain")}} property are automatically applied.
## Syntax
```css
/* Keyword values */
container-type: normal;
container-type: size;
container-type: inline-size;
/* Global Values */
container-type: inherit;
container-type: initial;
container-type: revert;
container-type: revert-layer;
container-type: unset;
```
### Values
- `size`
- : Establishes a query container for container size queries in both the [inline and block](/en-US/docs/Web/CSS/CSS_logical_properties_and_values/Basic_concepts_of_logical_properties_and_values#block_and_inline_dimensions) dimensions.
Applies layout containment, style containment, and size containment to the container.
Size containment is applied to the element in both the inline and block directions. The size of the element can be computed in isolation, ignoring the child elements.
- `inline-size`
- : Establishes a query container for dimensional queries on the [inline axis](/en-US/docs/Web/CSS/CSS_logical_properties_and_values/Basic_concepts_of_logical_properties_and_values#block_and_inline_dimensions) of the container.
Applies layout, style, and inline-size containment to the element.
Inline size containment is applied to the element. The inline size of the element can be computed in isolation, ignoring the child elements.
- `normal`
- : The element is not a query container for any container size queries, but remains a query container for container style queries.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{CSSSyntax}}
## Examples
### Establishing inline size containment
Given the following HTML example which is a card component with an image, a title, and some text:
```html
<div class="container">
<div class="card">
<h3>Normal card</h3>
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</div>
</div>
</div>
<div class="container wide">
<div class="card">
<h3>Wider card</h3>
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</div>
</div>
</div>
```
To create a container context, add the `container-type` property to an element.
The following uses the `inline-size` value to create a containment context for the [inline axis](/en-US/docs/Web/CSS/CSS_logical_properties_and_values/Basic_concepts_of_logical_properties_and_values#block_and_inline_dimensions) of the container:
```css
.container {
container-type: inline-size;
width: 300px;
height: 120px;
}
.wide {
width: 500px;
}
```
```css hidden
h3 {
height: 2rem;
margin: 0.5rem;
}
.card {
height: 100%;
}
.content {
background-color: wheat;
height: 100%;
}
.container {
margin: 1rem;
border: 2px dashed red;
overflow: hidden;
}
```
Writing a container query via the {{Cssxref("@container")}} at-rule will apply styles to the elements of the container when it is wider than 400px:
```css
@container (min-width: 400px) {
.card {
display: grid;
grid-template-columns: 1fr 2fr;
}
}
```
{{EmbedLiveSample('Establishing_inline_size_containment', '100%', 300)}}
## 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-name")}} property
- CSS {{cssxref("content-visibility")}} property
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/visibility/index.md | ---
title: visibility
slug: Web/CSS/visibility
page-type: css-property
browser-compat: css.properties.visibility
---
{{CSSRef}}
The **`visibility`** CSS property shows or hides an element without changing the layout of a document. The property can also hide rows or columns in a {{HTMLElement("table")}}.
{{EmbedInteractiveExample("pages/css/visibility.html")}}
To both hide an element _and remove it from the document layout_, set the {{cssxref("display")}} property to `none` instead of using `visibility`.
## Syntax
```css
/* Keyword values */
visibility: visible;
visibility: hidden;
visibility: collapse;
/* Global values */
visibility: inherit;
visibility: initial;
visibility: revert;
visibility: revert-layer;
visibility: unset;
```
The `visibility` property is specified as one of the keyword values listed below.
### Values
- `visible`
- : The element box is visible.
- `hidden`
- : The element box is invisible (not drawn), but still affects layout as normal. Descendants of the element will be visible if they have `visibility` set to `visible`. The element cannot receive focus (such as when navigating through [tab indexes](/en-US/docs/Web/HTML/Global_attributes/tabindex)).
- `collapse`
- : The `collapse` keyword has different effects for different elements:
- For {{HTMLElement("table")}} rows, columns, column groups, and row groups, the row(s) or column(s) are hidden and the space they would have occupied is removed (as if `{{Cssxref("display")}}: none` were applied to the column/row of the table). However, the size of other rows and columns is still calculated as though the cells in the collapsed row(s) or column(s) are present. This value allows for the fast removal of a row or column from a table without forcing the recalculation of widths and heights for the entire table.
- Collapsed flex items and ruby annotations are hidden, and the space they would have occupied is removed.
- For other elements, `collapse` is treated the same as `hidden`.
## Accessibility concerns
Using a `visibility` value of `hidden` 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.
## Interpolation
When animated, visibility values are interpolated between _visible_ and _not-visible_. One of the start or ending values must therefore be `visible` or no {{Glossary("interpolation")}} can happen. The value is interpolated as a discrete step, where values of the easing function between `0` and `1` map to `visible` and other values of the easing function (which occur only at the start/end of the transition or as a result of `cubic-bezier()` functions with y values outside of \[0, 1]) map to the closer endpoint.
## Notes
- Support for `visibility: collapse` is missing or partially incorrect in some modern browsers. It may not be correctly treated like `visibility: hidden` on elements other than table rows and columns.
- `visibility: collapse` may change the layout of a table if the table has nested tables within the cells that are collapsed, unless `visibility: visible` is specified explicitly on nested tables.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{CSSSyntax}}
## Examples
### Basic example
#### HTML
```html
<p class="visible">The first paragraph is visible.</p>
<p class="not-visible">The second paragraph is NOT visible.</p>
<p class="visible">
The third paragraph is visible. Notice the second paragraph is still occupying
space.
</p>
```
#### CSS
```css
.visible {
visibility: visible;
}
.not-visible {
visibility: hidden;
}
```
{{EmbedLiveSample('Basic_example')}}
### Table example
#### HTML
```html
<table>
<tr>
<td>1.1</td>
<td class="collapse">1.2</td>
<td>1.3</td>
</tr>
<tr class="collapse">
<td>2.1</td>
<td>2.2</td>
<td>2.3</td>
</tr>
<tr>
<td>3.1</td>
<td>3.2</td>
<td>3.3</td>
</tr>
</table>
```
#### CSS
```css
.collapse {
visibility: collapse;
}
table {
border: 1px solid red;
}
td {
border: 1px solid gray;
}
```
{{EmbedLiveSample('Table_example')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("display")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/mask-border-width/index.md | ---
title: mask-border-width
slug: Web/CSS/mask-border-width
page-type: css-property
browser-compat: css.properties.mask-border-width
---
{{CSSRef}}
The **`mask-border-width`** [CSS](/en-US/docs/Web/CSS) property sets the width of an element's [mask border](/en-US/docs/Web/CSS/mask-border).
## Syntax
```css
/* Keyword value */
mask-border-width: auto;
/* <length> value */
mask-border-width: 1rem;
/* <percentage> value */
mask-border-width: 25%;
/* <number> value */
mask-border-width: 3;
/* top and bottom | left and right */
mask-border-width: 2em 3em;
/* top | left and right | bottom */
mask-border-width: 5% 15% 10%;
/* top | right | bottom | left */
mask-border-width: 5% 2em 10% auto;
/* Global values */
mask-border-width: inherit;
mask-border-width: initial;
mask-border-width: revert;
mask-border-width: revert-layer;
mask-border-width: unset;
```
The `mask-border-width` property may be specified using one, two, three, or four values chosen from the list of values below.
- When **one** value is specified, it applies the same width to **all four sides**.
- When **two** values are specified, the first width applies to the **top and bottom**, the second to the **left and right**.
- When **three** values are specified, the first width applies to the **top**, the second to the **left and right**, the third to the **bottom**.
- When **four** values are specified, the widths apply to the **top**, **right**, **bottom**, and **left** in that order (clockwise).
### Values
- `<length-percentage>`
- : The width of the mask border, specified as a {{cssxref("<length>")}} or a {{cssxref("<percentage>")}}. Percentages are relative to the _width_ of the border area for horizontal offsets and the _height_ of the border area for vertical offsets. Must not be negative.
- `<number>`
- : The width of the mask border, specified as a multiple of the corresponding {{cssxref("border-width")}}. Must not be negative.
- `auto`
- : The width of the mask border is made equal to the intrinsic width or height (whichever is applicable) of the corresponding {{cssxref("mask-border-slice")}}. If the image does not have the required intrinsic dimension, the corresponding `border-width` is used instead.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Basic usage
This property doesn't appear to be supported anywhere yet. When it eventually starts to be supported, it will serve to define the width of the border mask β setting this to a different value to [`mask-border-slice`](/en-US/docs/Web/CSS/mask-border-slice) will cause the slices to be scaled to fit the border mask.
```css
mask-border-width: 30 fill;
```
Chromium-based browsers support an outdated version of this property β `mask-box-image-width` β with a prefix:
```css
-webkit-mask-box-image-width: 20px;
```
> **Note:** The [`mask-border`](/en-US/docs/Web/CSS/mask-border) page features a working example (using the out-of-date prefixed border mask properties supported in Chromium), so you can get an idea of the effect.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("mask-border")}}
- {{cssxref("mask-border-mode")}}
- {{cssxref("mask-border-outset")}}
- {{cssxref("mask-border-repeat")}}
- {{cssxref("mask-border-source")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_doublecolon_-webkit-progress-value/index.md | ---
title: "::-webkit-progress-value"
slug: Web/CSS/::-webkit-progress-value
page-type: css-pseudo-element
status:
- non-standard
browser-compat: css.selectors.-webkit-progress-value
---
{{CSSRef}}{{Non-standard_header}}
The **`::-webkit-progress-value`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) represents the filled-in portion of the bar of a {{HTMLElement("progress")}} element. It is a child of the {{cssxref("::-webkit-progress-bar")}} pseudo-element.
> **Note:** In order to let `::-webkit-progress-value` take effect, {{cssxref("appearance")}} needs to be set to `none` on the `<progress>` element.
## Syntax
```css
::-webkit-progress-value {
/* ... */
}
```
## Examples
This example will only work in browsers based on Blink or WebKit.
### HTML
```html
<progress value="10" max="50"></progress>
```
### CSS
```css
progress {
-webkit-appearance: none;
}
::-webkit-progress-value {
background-color: orange;
}
```
### Result
{{EmbedLiveSample("Examples", 200, 50)}}
### Result screenshot
A progress bar using the style above would look like this:

## Specifications
Not part of any standard.
## Browser compatibility
{{Compat}}
## See also
- The pseudo-elements used by WebKit/Blink to style other parts of a {{HTMLElement("progress")}} element:
- {{ cssxref("::-webkit-progress-bar") }}
- {{ cssxref("::-webkit-progress-inner-element") }}
- {{ cssxref("::-moz-progress-bar") }}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_doublecolon_-moz-list-bullet/index.md | ---
title: "::-moz-list-bullet"
slug: Web/CSS/::-moz-list-bullet
page-type: css-pseudo-element
status:
- non-standard
---
{{CSSRef}}{{Non-standard_header}}
The **`::-moz-list-bullet`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) is a [Mozilla extension](/en-US/docs/Web/CSS/Mozilla_Extensions) that represents the marker (typically a bullet) of a list item ({{htmlelement("li")}}) in an unordered list ({{htmlelement("ul")}}).
## Syntax
```css
li::-moz-list-bullet {
/* ... */
}
```
## Examples
### Styling list item markers
#### HTML
```html
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
```
#### CSS
```css
::-moz-list-bullet {
color: red;
font-size: 1.5em;
}
```
#### Result
{{ EmbedLiveSample('Styling list item markers') }}
## Specifications
Not part of any standard.
## See also
- {{cssxref("::-moz-list-number")}}
- {{cssxref("::marker")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/vertical-align/index.md | ---
title: vertical-align
slug: Web/CSS/vertical-align
page-type: css-property
browser-compat: css.properties.vertical-align
---
{{CSSRef}}
The **`vertical-align`** [CSS](/en-US/docs/Web/CSS) property sets vertical alignment of an inline, inline-block or table-cell box.
{{EmbedInteractiveExample("pages/css/vertical-align.html")}}
The vertical-align property can be used in two contexts:
- To vertically align an inline-level element's box inside its containing line box. For example, it could be used to [vertically position an image in a line of text](#vertical_alignment_in_a_line_box).
- To vertically align [the content of a cell in a table](#vertical_alignment_in_a_table_cell).
Note that `vertical-align` only applies to inline, inline-block and table-cell elements: you can't use it to vertically align [block-level elements](/en-US/docs/Glossary/Block-level_content).
## Syntax
```css
/* Keyword values */
vertical-align: baseline;
vertical-align: sub;
vertical-align: super;
vertical-align: text-top;
vertical-align: text-bottom;
vertical-align: middle;
vertical-align: top;
vertical-align: bottom;
/* <length> values */
vertical-align: 10em;
vertical-align: 4px;
/* <percentage> values */
vertical-align: 20%;
/* Global values */
vertical-align: inherit;
vertical-align: initial;
vertical-align: revert;
vertical-align: revert-layer;
vertical-align: unset;
```
The `vertical-align` property is specified as one of the values listed below.
### Values for inline elements
#### Parent-relative values
These values vertically align the element relative to its parent element:
- `baseline`
- : Aligns the baseline of the element with the baseline of its parent. The baseline of some [replaced elements](/en-US/docs/Web/CSS/Replaced_element), like {{HTMLElement("textarea")}}, is not specified by the HTML specification, meaning that their behavior with this keyword may vary between browsers.
- `sub`
- : Aligns the baseline of the element with the subscript-baseline of its parent.
- `super`
- : Aligns the baseline of the element with the superscript-baseline of its parent.
- `text-top`
- : Aligns the top of the element with the top of the parent element's font.
- `text-bottom`
- : Aligns the bottom of the element with the bottom of the parent element's font.
- `middle`
- : Aligns the middle of the element with the baseline plus half the x-height of the parent.
- {{cssxref("<length>")}}
- : Aligns the baseline of the element to the given length above the baseline of its parent. A negative value is allowed.
- {{cssxref("<percentage>")}}
- : Aligns the baseline of the element to the given percentage above the baseline of its parent, with the value being a percentage of the {{Cssxref("line-height")}} property. A negative value is allowed.
#### Line-relative values
The following values vertically align the element relative to the entire line:
- `top`
- : Aligns the top of the element and its descendants with the top of the entire line.
- `bottom`
- : Aligns the bottom of the element and its descendants with the bottom of the entire line.
For elements that do not have a baseline, the bottom margin edge is used instead.
### Values for table cells
- `baseline` (and `sub`, `super`, `text-top`, `text-bottom`, `<length>`, and `<percentage>`)
- : Aligns the baseline of the cell with the baseline of all other cells in the row that are baseline-aligned.
- `top`
- : Aligns the top padding edge of the cell with the top of the row.
- `middle`
- : Centers the padding box of the cell within the row.
- `bottom`
- : Aligns the bottom padding edge of the cell with the bottom of the row.
Negative values are allowed.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Basic example
#### HTML
```html
<div>
An <img src="frame_image.svg" alt="link" width="32" height="32" /> image with
a default alignment.
</div>
<div>
An
<img class="top" src="frame_image.svg" alt="link" width="32" height="32" />
image with a text-top alignment.
</div>
<div>
An
<img class="bottom" src="frame_image.svg" alt="link" width="32" height="32" />
image with a text-bottom alignment.
</div>
<div>
An
<img class="middle" src="frame_image.svg" alt="link" width="32" height="32" />
image with a middle alignment.
</div>
```
#### CSS
```css
img.top {
vertical-align: text-top;
}
img.bottom {
vertical-align: text-bottom;
}
img.middle {
vertical-align: middle;
}
```
#### Result
{{EmbedLiveSample("Basic_example")}}
### Vertical alignment in a line box
#### HTML
```html-nolint
<p>
top: <img style="vertical-align: top" src="star.png" alt="star"/>
middle: <img style="vertical-align: middle" src="star.png" alt="star"/>
bottom: <img style="vertical-align: bottom" src="star.png" alt="star"/>
super: <img style="vertical-align: super" src="star.png" alt="star"/>
sub: <img style="vertical-align: sub" src="star.png" alt="star"/>
</p>
<p>
text-top: <img style="vertical-align: text-top" src="star.png" alt="star"/>
text-bottom: <img style="vertical-align: text-bottom" src="star.png" alt="star"/>
0.2em: <img style="vertical-align: 0.2em" src="star.png" alt="star"/>
-1em: <img style="vertical-align: -1em" src="star.png" alt="star"/>
20%: <img style="vertical-align: 20%" src="star.png" alt="star"/>
-100%: <img style="vertical-align: -100%" src="star.png" alt="star"/>
</p>
```
```css hidden
#* {
box-sizing: border-box;
}
img {
margin-right: 0.5em;
}
p {
height: 3em;
padding: 0 0.5em;
font-family: monospace;
text-decoration: underline overline;
margin-left: auto;
margin-right: auto;
width: 80%;
}
```
#### Result
{{EmbedLiveSample("Vertical_alignment_in_a_line_box", '100%', 160, "", "")}}
### Vertical alignment in a table cell
#### HTML
```html
<table>
<tr>
<td style="vertical-align: baseline">baseline</td>
<td style="vertical-align: top">top</td>
<td style="vertical-align: middle">middle</td>
<td style="vertical-align: bottom">bottom</td>
<td>
<p>
There is a theory which states that if ever anyone discovers exactly
what the Universe is for and why it is here, it will instantly disappear
and be replaced by something even more bizarre and inexplicable.
</p>
<p>
There is another theory which states that this has already happened.
</p>
</td>
</tr>
</table>
```
#### CSS
```css
table {
margin-left: auto;
margin-right: auto;
width: 80%;
}
table,
th,
td {
border: 1px solid black;
}
td {
padding: 0.5em;
font-family: monospace;
}
```
#### Result
{{EmbedLiveSample("Vertical_alignment_in_a_table_cell", '100%', 230, "", "")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Typical use cases of Flexbox, section "Center item"](/en-US/docs/Web/CSS/CSS_flexible_box_layout/Typical_use_cases_of_flexbox#center_item)
- {{Cssxref("line-height")}}, {{Cssxref("text-align")}}, {{Cssxref("margin")}}
- [Understanding `vertical-align`, or "How (Not) To Vertically Center Content"](http://phrogz.net/css/vertical-align/index.html)
- [Vertical-Align: All You Need To Know](https://christopheraue.net/design/vertical-align)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/vertical-align/frame_image.svg | <svg version="1.2" baseProfile="tiny" width="37.833" height="37.833" viewBox="3000 13000 1001 1001" preserveAspectRatio="xMidYMid" fill-rule="evenodd" stroke-width="28.222" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" xml:space="preserve"><defs class="ClipPathGroup"><clipPath id="a" clipPathUnits="userSpaceOnUse"><path d="M3000 13000h1001v1001H3000z"/></clipPath></defs><g class="SlideGroup"><g class="Slide" clip-path="url(#a)"><path fill="none" stroke="#000" d="M3500 14000h-500v-1000h1000v1000h-500zm500 0-1000-1000m0 1000 1000-1000"/></g></g></svg> | 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_focus-within/index.md | ---
title: ":focus-within"
slug: Web/CSS/:focus-within
page-type: css-pseudo-class
browser-compat: css.selectors.focus-within
---
{{CSSRef}}
The **`:focus-within`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) matches an element if the element or any of its descendants are focused. In other words, it represents an element that is itself matched by the {{CSSxRef(":focus")}} pseudo-class or has a descendant that is matched by `:focus`. (This includes descendants in [shadow trees](/en-US/docs/Web/API/Web_components/Using_shadow_DOM).)
{{EmbedInteractiveExample("pages/tabbed/pseudo-class-focus-within.html", "tabbed-shorter")}}
This selector is useful, to take a common example, for highlighting an entire {{HTMLElement("form")}} container when the user focuses on one of its {{HTMLElement("input")}} fields.
## Syntax
```css
:focus-within {
/* ... */
}
```
## Examples
In this example, the form will receive special coloring styles when either text input receives focus.
### HTML
```html
<p>Try typing into this form.</p>
<form>
<label for="given_name">Given Name:</label>
<input id="given_name" type="text" />
<br />
<label for="family_name">Family Name:</label>
<input id="family_name" type="text" />
</form>
```
### CSS
```css
form {
border: 1px solid;
color: gray;
padding: 4px;
}
form:focus-within {
background: #ff8;
color: black;
}
input {
margin: 4px;
}
```
### Result
{{EmbedLiveSample("Examples", 500, 150)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef(":focus")}}
- {{CSSxRef(":focus-visible")}}
- [Grab your user's attention with the focus-within selector](https://dev.to/vtrpldn/grab-your-user-s-attention-with-the-focus-within-css-selector-4d4)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/word-spacing/index.md | ---
title: word-spacing
slug: Web/CSS/word-spacing
page-type: css-property
browser-compat: css.properties.word-spacing
---
{{CSSRef}}
The **`word-spacing`** [CSS](/en-US/docs/Web/CSS) property sets the length of space between words and between tags.
{{EmbedInteractiveExample("pages/css/word-spacing.html")}}
## Syntax
```css
/* Keyword value */
word-spacing: normal;
/* <length> values */
word-spacing: 3px;
word-spacing: 0.3em;
/* Global values */
word-spacing: inherit;
word-spacing: initial;
word-spacing: revert;
word-spacing: revert-layer;
word-spacing: unset;
```
### Values
- `normal`
- : The normal inter-word spacing, as defined by the current font and/or the browser.
- {{cssxref("length")}}
- : Specifies extra spacing in addition to the intrinsic inter-word spacing defined by the font.
## Examples
### HTML
```html
<div id="mozdiv1">Lorem ipsum dolor sit amet.</div>
<div id="mozdiv2">Lorem ipsum dolor sit amet.</div>
```
### CSS
```css
#mozdiv1 {
word-spacing: 15px;
}
#mozdiv2 {
word-spacing: 5em;
}
```
{{ EmbedLiveSample('Examples') }}
## Accessibility concerns
A large positive or negative `word-spacing` value will make the sentences the styling is applied to unreadable. For text styled with a very large positive value, the words will be so far apart that it will no longer appear to be a sentence. For text styled with a large negative value, the words will overlap each other to the point where the beginning and end of each word is unrecognizable.
Legible `word-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)
## Formal definition
{{CSSInfo}}
## Formal syntax
{{CSSSyntax}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("letter-spacing")}}
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/timeline-scope/index.md | ---
title: timeline-scope
slug: Web/CSS/timeline-scope
page-type: css-property
status:
- experimental
browser-compat: css.properties.timeline-scope
---
{{CSSRef}}{{seecompattable}}
The **`timeline-scope`** [CSS](/en-US/docs/Web/CSS) property modifies the scope of a named animation timeline.
By default, a named timeline (i.e. declared using {{cssxref("scroll-timeline-name")}} or {{cssxref("view-timeline-name")}}) can only be set as the controlling timeline of a direct descendant element (i.e. by setting {{cssxref("animation-timeline")}} on it with the timeline name as its value). This is the timeline's default "scope".
`timeline-scope` is given the name of a timeline defined on a descendant element; this causes the scope of the timeline to be increased to the element that `timeline-scope` is set on and any of its descendants. In other words, that element and any of its descendant elements can now be controlled using that timeline.
> **Note:** If no timeline (or more than one timeline) exists with the name given for the `timeline-scope` value, an inactive timeline with the specified name is created.
## Syntax
```css
timeline-scope: none;
timeline-scope: custom_name_for_timeline;
```
### Values
Allowed values for `timeline-scope` are:
- `none`
- : There is no change in timeline scope.
- `<dashed-ident>`
- : Specifies the name of an existing named timeline (i.e. declared using {{cssxref("scroll-timeline-name")}} or {{cssxref("view-timeline-name")}}) defined on a descendant element. This causes the timeline scope to be increased to the element that `timeline-scope` is set on and any of its descendants.
> **Note:** [`<dashed-ident>`](/en-US/docs/Web/CSS/custom-ident) values must start with `--`, which helps to avoid name clashes with standard CSS keywords.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
In this example, a scroll timeline named `--myScroller` is defined using the `scroll-timeline-name` property on the element with the `scroller` class (the scrolling element). This is then applied to the animation on the element with the `box` and `animation` classes (the animated element) using `animation-timeline: --myScroller`. The key point to note here is that the animated element is not a descendant of the scrolling element β to make this work, we increase the scope of the `--myScroller` timeline by setting `timeline-scope: --myScroller` on the {{htmlelement("body")}}.
### HTML
The HTML for the example is shown below.
```html
<div class="content">
<div class="box animation"></div>
</div>
<div class="scroller">
<div class="long-element"></div>
</div>
```
### CSS
The CSS is as follows.
First of all, we set the `<body>`'s height to `100vh`, and lay its two child elements out as two equal columns using flexbox. We also set `timeline-scope: --myScroller` on it so that the `--myScroller` timeline can be set as the controlling timeline for an animation set on the `<body>` and any element inside it.
```css
body {
margin: 0;
height: 100vh;
display: flex;
/* increases the timeline scope from the .scroller <div> element
to the whole <body> */
timeline-scope: --myScroller;
}
.content,
.scroller {
flex: 1;
}
```
Next, the scrolling element has the `--myScroller` timeline set on it, `overflow` so that it will scroll, and it is given a background color so that its boundary is clear to see. The scrolling element's child long element is given a large height so that the scrolling element will actually scroll.
```css
.scroller {
overflow: scroll;
scroll-timeline-name: --myScroller;
background: deeppink;
}
.long-element {
height: 2000px;
}
```
Next, we give the animated element some rudimentary styling, and apply an animation to it. We also apply the `--myScroller` timeline to it using `animation-timeline: --myScroller`. To reiterate, this is only possible because earlier we set `timeline-scope: --myScroller` on the `<body>` element β the animated element is **not** a descendant of the scrolling element.
```css
.box {
width: 100px;
height: 100px;
border-radius: 10px;
background-color: rebeccapurple;
position: fixed;
top: 20px;
left: 0%;
}
.animation {
animation: rotate-appear;
animation-timeline: --myScroller;
}
@keyframes rotate-appear {
from {
rotate: 0deg;
left: 0%;
}
to {
rotate: 720deg;
left: 100%;
}
}
```
### Result
Scroll the vertical bar on the pink area to see the square animate.
{{EmbedLiveSample("Examples", "100%", "320px")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [`animation-timeline`](/en-US/docs/Web/CSS/animation-timeline)
- [`scroll-timeline`](/en-US/docs/Web/CSS/scroll-timeline), [`scroll-timeline-name`](/en-US/docs/Web/CSS/scroll-timeline-name)
- [`view-timeline`](/en-US/docs/Web/CSS/view-timeline), [`view-timeline-name`](/en-US/docs/Web/CSS/view-timeline-name)
- [CSS scroll-driven animations](/en-US/docs/Web/CSS/CSS_scroll-driven_animations)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/_colon_state/index.md | ---
title: ":state()"
slug: Web/CSS/:state
page-type: css-pseudo-class
status:
- experimental
browser-compat: css.selectors.state
---
{{CSSRef}}{{SeeCompatTable}}
The **`:state()`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) matches [custom elements](/en-US/docs/Web/API/Web_components/Using_custom_elements) that have the specified custom state.
## Syntax
The `:state()` pseudo-class takes as its argument a custom identifier that represents the state of the custom element to match.
```css-nolint
:state(<custom identifier>) {
/* ... */
}
```
## Description
Elements can transition between states due to user interaction and other factors.
For instance, an element can be in the "hover" state when a user hovers over the element, or a link can be in the "visited" state after a user clicks on it.
Elements provided by browsers can be styled based on these states using CSS pseudo-classes such as [`:hover`](/en-US/docs/Web/CSS/:hover) and [`:visited`](/en-US/docs/Web/CSS/:visited).
Similarly, [autonomous custom elements](/en-US/docs/Web/API/Web_components/Using_custom_elements#types_of_custom_element) (custom elements that are not derived from built-in elements) can expose their states, allowing pages that use the elements to style them using the CSS `:state()` pseudo-class.
The states of a custom element are represented by string values.
These values are added to or removed from a [`CustomStateSet`](/en-US/docs/Web/API/CustomStateSet) object associated with the element.
The CSS `:state()` pseudo-class matches an element when the identifier, passed as an argument, is present in the `CustomStateSet` of the element.
The `:state()` pseudo-class can also be used to match custom states within the implementation of a custom element.
This is achieved by using `:state()` within the [`:host()`](/en-US/docs/Web/CSS/:host_function) pseudo-class function, which matches a state only within the shadow DOM of the current custom element.
Additionally, the [`::part()`](/en-US/docs/Web/CSS/::part) pseudo-element followed by the `:state()` pseudo-class allows matching on the [shadow parts](/en-US/docs/Web/CSS/CSS_shadow_parts) of a custom element that are in a particular state. (**Shadow parts** are parts of a custom element's shadow tree that are explicitly exposed to a containing page for styling purposes.)
## Examples
### Matching a custom state
This CSS shows how to change the border of the autonomous custom element `<labeled-checkbox>` to `red` when it is in the "checked" state.
```css
labeled-checkbox {
border: dashed red;
}
labeled-checkbox:state(checked) {
border: solid;
}
```
For a live example of this code in action, see the [Matching the custom state of a custom checkbox element](/en-US/docs/Web/API/CustomStateSet#matching_the_custom_state_of_a_custom_checkbox_element) example on the `CustomStateSet` page.
### Matching a custom state in a custom element's shadow DOM
This example shows how the `:state()` pseudo-class can be used within the [`:host()`](/en-US/docs/Web/CSS/:host_function) pseudo-class function to match custom states within the implementation of a custom element.
The following CSS injects a grey `[x]` before the element when it is in the "checked" state.
```css
:host(:state(checked))::before {
content: "[x]";
}
```
For a live example of this code in action, see the [Matching the custom state of a custom checkbox element](/en-US/docs/Web/API/CustomStateSet#matching_the_custom_state_of_a_custom_checkbox_element) example on the `CustomStateSet` page.
### Matching a custom state in a shadow part
This example shows how the `:state()` pseudo-class can be used to target the [shadow parts](/en-US/docs/Web/CSS/CSS_shadow_parts) of a custom element.
Shadow parts are defined and named using the [`part`](/en-US/docs/Web/HTML/Global_attributes#part) attribute.
For example, consider a custom element named `<question-box>` that uses a `<labeled-checkbox>` custom element as a shadow part named `checkbox`:
```js
shadowRoot.innerHTML = `<labeled-checkbox part='checkbox'>Yes</labeled-checkbox>`;
```
The CSS below shows how the [`::part()`](/en-US/docs/Web/CSS/::part) pseudo-element can be used to match against the `'checkbox'` shadow part.
It then shows how the `::part()` pseudo-element followed by the `:state()` pseudo-class can be used to match against the same part when it is in the `checked` state.
```css
question-box::part(checkbox) {
color: red;
}
question-box::part(checkbox):state(checked) {
color: green;
}
```
For a live example of this code in action, see the [Matching a custom state in a shadow part of a custom element](/en-US/docs/Web/API/CustomStateSet#matching_a_custom_state_in_a_shadow_part_of_a_custom_element) example on the `CustomStateSet` page.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [`CustomStateSet`](/en-US/docs/Web/API/CustomStateSet)
- [Pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes)
- [Pseudo-classes and pseudo-elements](/en-US/docs/Learn/CSS/Building_blocks/Selectors/Pseudo-classes_and_pseudo-elements)
- [Custom states and custom state pseudo-class CSS selectors](/en-US/docs/Web/API/Web_components/Using_custom_elements#custom_states_and_custom_state_pseudo-class_css_selectors) in [Using custom elements](/en-US/docs/Web/API/Web_components/Using_custom_elements)
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/grid-template-areas/index.md | ---
title: grid-template-areas
slug: Web/CSS/grid-template-areas
page-type: css-property
browser-compat: css.properties.grid-template-areas
---
{{CSSRef}}
The **`grid-template-areas`** CSS property specifies named {{glossary("grid areas")}}, establishing the cells in the grid and assigning them names.
{{EmbedInteractiveExample("pages/css/grid-template-areas.html")}}
Those areas are not associated with any particular grid item, but can be referenced from the grid-placement properties {{cssxref("grid-row-start")}}, {{cssxref("grid-row-end")}}, {{cssxref("grid-column-start")}}, {{cssxref("grid-column-end")}}, and their shorthands {{cssxref("grid-row")}}, {{cssxref("grid-column")}}, and {{cssxref("grid-area")}}.
## Syntax
```css
/* Keyword value */
grid-template-areas: none;
/* <string> values */
grid-template-areas: "a b";
grid-template-areas:
"a b b"
"a c d";
/* Global values */
grid-template-areas: inherit;
grid-template-areas: initial;
grid-template-areas: revert;
grid-template-areas: revert-layer;
grid-template-areas: unset;
```
### Values
- `none`
- : The grid container doesn't define any named grid areas.
- `{{cssxref("<string>")}}+`
- : A row is created for every separate string listed, and a column is created for each cell in the string. Multiple cell tokens with the same name within and between rows create a single named grid area that spans the corresponding grid cells. Unless those cells form a rectangle, the declaration is invalid.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Specifying named grid areas
#### HTML
```html
<div id="page">
<header>Header</header>
<nav>Navigation</nav>
<main>Main area</main>
<footer>Footer</footer>
</div>
```
#### CSS
```css
#page {
display: grid;
width: 100%;
height: 250px;
grid-template-areas:
"head head"
"nav main"
"nav foot";
grid-template-rows: 50px 1fr 30px;
grid-template-columns: 150px 1fr;
}
#page > header {
grid-area: head;
background-color: #8ca0ff;
}
#page > nav {
grid-area: nav;
background-color: #ffa08c;
}
#page > main {
grid-area: main;
background-color: #ffff64;
}
#page > footer {
grid-area: foot;
background-color: #8cffa0;
}
```
#### Result
{{EmbedLiveSample("Specifying_named_grid_areas", "100%", "285px")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- Related CSS properties: {{cssxref("grid-template-rows")}}, {{cssxref("grid-template-columns")}}, {{cssxref("grid-template")}}
- Grid Layout Guide: _[Grid template areas](/en-US/docs/Web/CSS/CSS_grid_layout/Grid_template_areas)_
- Video tutorial: _[Grid Template Areas](https://gridbyexample.com/video/grid-template-areas/)_
| 0 |
data/mdn-content/files/en-us/web/css | data/mdn-content/files/en-us/web/css/@font-face/index.md | ---
title: "@font-face"
slug: Web/CSS/@font-face
page-type: css-at-rule
browser-compat: css.at-rules.font-face
---
{{CSSRef}}
The **`@font-face`** [CSS](/en-US/docs/Web/CSS) [at-rule](/en-US/docs/Web/CSS/At-rule) specifies a custom font with which to display text; the font can be loaded from either a remote server or a locally-installed font on the user's own computer.
## Syntax
```css
@font-face {
font-family: "Trickster";
src:
local("Trickster"),
url("trickster-COLRv1.otf") format("opentype") tech(color-COLRv1),
url("trickster-outline.otf") format("opentype"),
url("trickster-outline.woff") format("woff");
}
```
### Descriptors
- {{cssxref("@font-face/ascent-override", "ascent-override")}}
- : Defines the ascent metric for the font.
- {{cssxref("@font-face/descent-override", "descent-override")}}
- : Defines the descent metric for the font.
- {{cssxref("@font-face/font-display", "font-display")}}
- : Determines how a font face is displayed based on whether and when it is downloaded and ready to use.
- {{cssxref("@font-face/font-family", "font-family")}}
- : Specifies a name that will be used as the font face value for font properties.
- {{cssxref("@font-face/font-stretch", "font-stretch")}}
- : A {{cssxref("font-stretch")}} value. Accepts two values to specify a range that is supported by a font-face, for example `font-stretch: 50% 200%;`
- {{cssxref("@font-face/font-style", "font-style")}}
- : A {{cssxref("font-style")}} value. Accepts two values to specify a range that is supported by a font-face, for example `font-style: oblique 20deg 50deg;`
- {{cssxref("@font-face/font-weight", "font-weight")}}
- : A {{cssxref("font-weight")}} value. Accepts two values to specify a range that is supported by a font-face, for example `font-weight: 100 400;`
> **Note:** The font-variant descriptor was removed from the specification in 2018. The {{cssxref("font-variant")}} value property is supported, but there is no descriptor equivalent.
- {{cssxref("@font-face/font-feature-settings", "font-feature-settings")}}
- : Allows control over advanced typographic features in OpenType fonts.
- {{cssxref("@font-face/font-variation-settings", "font-variation-settings")}}
- : Allows low-level control over OpenType or TrueType font variations, by specifying the four letter axis names of the features to vary, along with their variation values.
- {{cssxref("@font-face/line-gap-override", "line-gap-override")}}
- : Defines the line gap metric for the font.
- {{cssxref("@font-face/size-adjust", "size-adjust")}}
- : Defines a multiplier for glyph outlines and metrics associated with this font. This makes it easier to harmonize the designs of various fonts when rendered at the same font size.
- {{cssxref("@font-face/src", "src")}}
- : Specifies references to font resources including hints about the font format and technology. It is required for the @font-face rule to be valid.
- {{cssxref("@font-face/unicode-range", "unicode-range")}}
- : The range of Unicode code points to be used from the font.
## Description
It's common to use both `url()` and `local()` together, so that the user's installed copy of the font is used if available, falling back to downloading a copy of the font if it's not found on the user's device.
If the `local()` function is provided, specifying a font name to look for on the user's device, and if the {{Glossary("user agent")}} finds a match, that local font is used. Otherwise, the font resource specified using the `url()` function is downloaded and used.
Browsers attempt to load resources in their list declaration order, so usually `local()` should be written before `url()`. Both functions are optional, so a rule block containing only one or more `local()` without `url()` is possible.
If a more specific fonts with `format()` or `tech()` values are desired, these should be listed _before_ versions that don't have these values, as the less-specific variant would otherwise be tried and used first.
By allowing authors to provide their own fonts, `@font-face` makes it possible to design content without being limited to the so-called "web-safe" fonts (that is, the fonts which are so common that they're considered to be universally available). The ability to specify the name of a locally-installed font to look for and use makes it possible to customize the font beyond the basics while making it possible to do so without relying on an internet connection.
> **Note:** Fallback strategies for loading fonts on older browsers are described in the [`src` descriptor page](/en-US/docs/Web/CSS/@font-face/src#fallbacks_for_older_browsers).
The `@font-face` at-rule may be used not only at the top level of a CSS, but also inside any [CSS conditional-group at-rule](/en-US/docs/Web/CSS/At-rule#conditional_group_rules).
### Font MIME Types
| Format | MIME type |
| ---------------------- | ------------ |
| TrueType | `font/ttf` |
| OpenType | `font/otf` |
| Web Open Font Format | `font/woff` |
| Web Open Font Format 2 | `font/woff2` |
### Notes
- Web fonts are subject to the same domain restriction (font files must be on the same domain as the page using them), unless [HTTP access controls](/en-US/docs/Web/HTTP/CORS) are used to relax this restriction.
- `@font-face` cannot be declared within a CSS selector. For example, the following will not work:
```css example-bad
.className {
@font-face {
font-family: "MyHelvetica";
src: local("Helvetica Neue Bold"), local("HelveticaNeue-Bold"),
url("MgOpenModernaBold.ttf");
font-weight: bold;
}
}
```
## Formal syntax
{{csssyntax}}
## Examples
### Specifying a downloadable font
This example specifies a downloadable font to use, applying it to the entire body of the document:
```html
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Web Font Sample</title>
<style media="screen, print">
@font-face {
font-family: "Bitstream Vera Serif Bold";
src: url("https://mdn.github.io/css-examples/web-fonts/VeraSeBd.ttf");
}
body {
font-family: "Bitstream Vera Serif Bold", serif;
}
</style>
</head>
<body>
This is Bitstream Vera Serif Bold.
</body>
</html>
```
The output of this example code looks like so:
{{EmbedGHLiveSample("css-examples/web-fonts/basic-web-font.html", '100%', '100')}}
### Specifying local font alternatives
In this example, the user's local copy of "Helvetica Neue Bold" is used; if the user does not have that font installed (both the full font name and the Postscript name are tried), then the downloadable font named "MgOpenModernaBold.ttf" is used instead:
```css
@font-face {
font-family: "MyHelvetica";
src: local("Helvetica Neue Bold"), local("HelveticaNeue-Bold"),
url("MgOpenModernaBold.ttf");
font-weight: bold;
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [About WOFF](/en-US/docs/Web/CSS/CSS_fonts/WOFF)
- [FontSquirrel @font-face generator](https://www.fontsquirrel.com/tools/webfont-generator)
- [Beautiful fonts with @font-face](https://hacks.mozilla.org/2009/06/beautiful-fonts-with-font-face/)
- [Font Library](https://fontlibrary.org/)
| 0 |
data/mdn-content/files/en-us/web/css/@font-face | data/mdn-content/files/en-us/web/css/@font-face/font-display/index.md | ---
title: font-display
slug: Web/CSS/@font-face/font-display
page-type: css-at-rule-descriptor
browser-compat: css.at-rules.font-face.font-display
---
{{CSSRef}}
The **`font-display`** descriptor for the [`@font-face`](/en-US/docs/Web/CSS/@font-face) at-rule determines how a font face is displayed based on whether and when it is downloaded and ready to use.
## Syntax
```css
/* Keyword values */
font-display: auto;
font-display: block;
font-display: swap;
font-display: fallback;
font-display: optional;
```
### Values
- `auto`
- : The font display strategy is defined by the user agent.
- `block`
- : Gives the font face a short block period and an infinite swap period.
- `swap`
- : Gives the font face an extremely small block period and an infinite swap period.
- `fallback`
- : Gives the font face an extremely small block period and a short swap period.
- `optional`
- : Gives the font face an extremely small block period and no swap period.
> **Note:** In Firefox, the preferences `gfx.downloadable_fonts.fallback_delay`
> and `gfx.downloadable_fonts.fallback_delay_short` provide the duration
> of the "short" and "extremely small" periods, respectively.
## Description
The font display timeline is based on a timer that begins the moment the user agent attempts to use a given downloaded font face. The timeline is divided into the three periods below which dictate the rendering behavior of any elements using the font face:
- Font block period: If the font face is not loaded, any element attempting to use it must render an _invisible_ fallback font face. If the font face successfully loads during this period, it is used normally.
- Font swap period: If the font face is not loaded, any element attempting to use it must render a fallback font face. If the font face successfully loads during this period, it is used normally.
- Font failure period: If the font face is not loaded, the user agent treats it as a failed load causing normal font fallback.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Specifying fallback font-display
```css
@font-face {
font-family: ExampleFont;
src:
url(/path/to/fonts/examplefont.woff) format("woff"),
url(/path/to/fonts/examplefont.eot) format("eot");
font-weight: 400;
font-style: normal;
font-display: fallback;
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("@font-face/font-family", "font-family")}}
- {{cssxref("@font-face/font-stretch", "font-stretch")}}
- {{cssxref("@font-face/font-style", "font-style")}}
- {{cssxref("@font-face/font-weight", "font-weight")}}
- {{cssxref("font-feature-settings", "font-feature-settings")}}
- {{cssxref("@font-face/font-variation-settings", "font-variation-settings")}}
- {{cssxref("@font-face/src", "src")}}
- {{cssxref("@font-face/unicode-range", "unicode-range")}}
| 0 |
data/mdn-content/files/en-us/web/css/@font-face | data/mdn-content/files/en-us/web/css/@font-face/size-adjust/index.md | ---
title: size-adjust
slug: Web/CSS/@font-face/size-adjust
page-type: css-at-rule-descriptor
browser-compat: css.at-rules.font-face.size-adjust
---
{{CSSRef}}
The **`size-adjust`** CSS descriptor for the {{cssxref("@font-face")}} at-rule defines a multiplier for glyph outlines and metrics associated with this font. This makes it easier to harmonize the designs of various fonts when rendered at the same font size.
The `size-adjust` descriptor behaves in a similar fashion to the {{cssxref("font-size-adjust")}} property. It calculates an adjustment per font by matching ex heights.
## Syntax
```css
size-adjust: 90%;
```
### Values
- `<percentage>`
- : A {{cssxref("<percentage>")}} value with an initial value of 100%.
All metrics associated with this font are scaled by the given percentage. This includes glyph advances, baseline tables, and overrides provided by {{cssxref("@font-face")}} descriptors.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Overriding metrics of a fallback font
The `size-adjust` property can help when overriding the metrics of a fallback font to better match those of a primary web font.
```css
@font-face {
font-family: web-font;
src: url("https://example.com/font.woff");
}
@font-face {
font-family: local-font;
src: local(Local Font);
size-adjust: 90%;
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("@font-face/font-display", "font-display")}} descriptor
- {{cssxref("@font-face/font-family", "font-family")}} descriptor
- {{cssxref("@font-face/font-weight", "font-weight")}} descriptor
- {{cssxref("@font-face/font-style", "font-style")}} descriptor
- {{cssxref("@font-face/font-stretch", "font-stretch")}} descriptor
- {{cssxref("font-feature-settings", "font-feature-settings")}}
- {{cssxref("@font-face/font-variation-settings", "font-variation-settings")}} descriptor
- {{cssxref("@font-face/src", "src")}} descriptor
- {{cssxref("@font-face/unicode-range", "unicode-range")}} descriptor
- {{cssxref('font-size-adjust')}} property
| 0 |
data/mdn-content/files/en-us/web/css/@font-face | data/mdn-content/files/en-us/web/css/@font-face/unicode-range/index.md | ---
title: unicode-range
slug: Web/CSS/@font-face/unicode-range
page-type: css-at-rule-descriptor
browser-compat: css.at-rules.font-face.unicode-range
---
{{CSSRef}}
The **`unicode-range`** CSS descriptor sets the specific range of characters to be used from a font defined using the {{cssxref("@font-face")}} at-rule and made available for use on the current page. If the page doesn't use any character in this range, the font is not downloaded; if it uses at least one, the whole font is downloaded.
## Syntax
```css
/* <unicode-range> values */
unicode-range: U+26; /* single code point */
unicode-range: U+0-7F;
unicode-range: U+0025-00FF; /* code point range */
unicode-range: U+4??; /* wildcard range */
unicode-range: U+0025-00FF, U+4??; /* multiple values */
```
### Values
- **_single code point_**
- : A single Unicode character code point, for example `U+26`.
- **_code point range_**
- : A range of Unicode code points. So for example, `U+0025-00FF` means _include all characters in the range `U+0025` to `U+00FF`_.
- **_wildcard range_**
- : A range of Unicode code points containing wildcard characters, that is using the `'?'` character, so for example `U+4??` means _include all characters in the range `U+400` to `U+4FF`_.
## Description
The purpose of this descriptor is to allow the font resources to be segmented so that a browser only needs to download the font resource needed for the text content of a particular page. For example, a site with many localizations could provide separate font resources for English, Greek and Japanese. For users viewing the English version of a page, the font resources for Greek and Japanese fonts wouldn't need to be downloaded, saving bandwidth.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Using a different font for a single character
In this example we create a simple HTML containing a single {{HTMLElement("div")}} element, including an ampersand, that we want to style with a different font. To make it obvious, we will use a sans-serif font, _Helvetica_, for the text, and a serif font, _Times New Roman_, for the ampersand.
In the CSS we are in effect defining a completely separate {{cssxref("@font-face")}} that only includes a single character in it, meaning that only this character will be styled with this font. We could also have done this by wrapping the ampersand in a {{HTMLElement("span")}} and applying a different font just to that, but that is an extra element and rule set.
#### HTML
```html
<div>Me & You = Us</div>
```
#### CSS
```css
@font-face {
font-family: "Ampersand";
src: local("Times New Roman");
unicode-range: U+26;
}
div {
font-size: 4em;
font-family: Ampersand, Helvetica, sans-serif;
}
```
#### Result
{{EmbedLiveSample("Using_a_different_font_for_a_single_character", 500,104)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("@font-face/font-display", "font-display")}}
- {{cssxref("@font-face/font-family", "font-family")}}
- {{cssxref("@font-face/font-stretch", "font-stretch")}}
- {{cssxref("@font-face/font-style", "font-style")}}
- {{cssxref("@font-face/font-weight", "font-weight")}}
- {{cssxref("font-feature-settings", "font-feature-settings")}}
- {{cssxref("@font-face/font-variation-settings", "font-variation-settings")}}
- {{cssxref("@font-face/src", "src")}}
| 0 |
data/mdn-content/files/en-us/web/css/@font-face | data/mdn-content/files/en-us/web/css/@font-face/font-feature-settings/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/@font-face | data/mdn-content/files/en-us/web/css/@font-face/font-feature-settings/index.md | ---
title: font-feature-settings
slug: Web/CSS/@font-face/font-feature-settings
page-type: css-at-rule-descriptor
browser-compat: css.at-rules.font-face.font-feature-settings
---
{{CSSRef}}
The **`font-feature-settings`** CSS descriptor allows you to define the initial settings to use for the font defined by the {{cssxref("@font-face")}} at-rule. You can further use this descriptor to control typographic font features such as ligatures, small caps, and swashes, for the font defined by `@font-face`. The values for this descriptor are the same as the {{cssxref("font-feature-settings")}} property, except for the global keyword values.
Since this descriptor sets feature values on the font object in the `@font-face` at-rule and not on an entire element, only some glyphs in an element may be rendered using this descriptor.
## Syntax
```css
/* Use the default settings */
font-feature-settings: normal;
/* Set values for OpenType feature tags */
font-feature-settings: "smcp";
font-feature-settings: "smcp" on;
font-feature-settings: "swsh" 2;
```
### Values
This descriptor is specified as either the keyword `normal` or as a comma-separated list of `<feature-tag-value>` values. When rendering text, the list of OpenType `<feature-tag-value>` values are passed to the text layout engine to enable or disable font features.
- `normal`
- : Indicates that text is laid out using default font settings. This is the default value.
- `<feature-tag-value>`
- : Represents a space-separated tuple consisting of a tag name and an optional value.
The tag name is always a {{cssxref("<string>")}} of four {{Glossary("ASCII")}} characters. If the tag name has more or fewer characters or if it contains characters outside the `U+20` β `U+7E` code point range, the descriptor is invalid.
The optional value can be a positive integer or the keyword `on` or `off`. The keywords `on` and `off` are synonyms for the values `1` and `0`, respectively. If no value is set, the default is `1`. For non-boolean OpenType features (e.g., [stylistic alternates](https://learn.microsoft.com/en-ca/typography/opentype/spec/features_pt#tag-salt)), the value implies a particular glyph to be selected; for boolean features, the value turns the feature on or off.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Enabling swash glyphs using the @font-face at-rule
In this example, the tag name `swsh` and a boolean value `1` are used as the value for the `font-feature-settings` descriptor in the `@font-face` at-rule.
#### HTML
```html
<p class="swashoff">Swash is off here</p>
<p class="swashon">Swash is on here</p>
```
#### CSS
```css
@font-face {
font-family: MonteCarlo;
src: url("montecarlo-regular.woff2");
}
@font-face {
font-family: MonteCarlo2;
src: url("montecarlo-regular.woff2");
font-feature-settings: "swsh" 1;
}
p {
font-size: 3rem;
margin: 0.7rem 3rem;
}
.swashoff {
font-family: MonteCarlo;
}
.swashon {
font-family: MonteCarlo2;
}
```
#### Result
{{EmbedLiveSample("Enabling swash glyphs using the @font-face rule", 0, 230)}}
Line 1 shows the default ornate design of the [MonteCarlo](https://github.com/googlefonts/monte-carlo) font, and line 2 shows the default glyphs being replaced with [swash](https://learn.microsoft.com/en-ca/typography/opentype/spec/features_pt#tag-swsh) glyphs.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- Other `@font-face` descriptors: {{cssxref("@font-face/font-family", "font-family")}}, {{cssxref("@font-face/font-style", "font-style")}}, {{cssxref("@font-face/font-variation-settings", "font-variation-settings")}}, {{cssxref("@font-face/font-weight", "font-weight")}}, {{cssxref("@font-face/src", "src")}}
- Related font properties: {{cssxref("font-feature-settings")}}, {{cssxref("font-variant-alternates")}}, {{cssxref("font-variation-settings")}}
| 0 |
data/mdn-content/files/en-us/web/css/@font-face | data/mdn-content/files/en-us/web/css/@font-face/font-family/index.md | ---
title: font-family
slug: Web/CSS/@font-face/font-family
page-type: css-at-rule-descriptor
browser-compat: css.at-rules.font-face.font-family
---
{{CSSRef}}
The **`font-family`** CSS descriptor sets the font family for a font specified in an {{cssxref("@font-face")}} at-rule.
The value is used for name matching against a particular `@font-face` when styling elements using the [`font-family`](/en-US/docs/Web/CSS/font-family) property.
Any name may be used, and this overrides any name specified in the underlying font data.
## Syntax
```css
/* <string> values */
font-family: "font family";
font-family: "another font family";
/* <custom-ident> value */
font-family: examplefont;
```
### Values
- `<family-name>`
- : Specifies the name of the font family.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting the font family name
```css
@font-face {
font-family: "Some font family";
src: url("some_font_name.ttf");
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("@font-face/font-display", "font-display")}}
- {{cssxref("@font-face/font-stretch", "font-stretch")}}
- {{cssxref("@font-face/font-style", "font-style")}}
- {{cssxref("@font-face/font-weight", "font-weight")}}
- {{cssxref("font-feature-settings", "font-feature-settings")}}
- {{cssxref("@font-face/font-variation-settings", "font-variation-settings")}}
- {{cssxref("@font-face/src", "src")}}
- {{cssxref("@font-face/unicode-range", "unicode-range")}}
| 0 |
data/mdn-content/files/en-us/web/css/@font-face | data/mdn-content/files/en-us/web/css/@font-face/font-variation-settings/index.md | ---
title: font-variation-settings
slug: Web/CSS/@font-face/font-variation-settings
page-type: css-at-rule-descriptor
browser-compat: css.at-rules.font-face.font-variation-settings
---
{{CSSRef}}
The **`font-variation-settings`** CSS descriptor allows authors to specify low-level OpenType or TrueType font variations in the {{cssxref("@font-face")}} at-rule. The values for this descriptor are the same as the {{cssxref("font-variation-settings")}} property, except for the global keyword values.
Since this descriptor sets variation values on the font object in the `@font-face` at-rule and not on an entire element, only some glyphs in an element may be rendered using this descriptor.
## Syntax
```css
/* Use the default settings */
font-variation-settings: normal;
/* Set values for OpenType axis names */
font-variation-settings: "xhgt" 0.7;
```
### Values
- `normal`
- : Text is laid out using default settings.
- `<string> <number>`
- : When rendering text, the list of OpenType axis names is passed to the text layout engine to enable or disable font features. Each setting is always a {{cssxref("<string>")}} of 4 {{Glossary("ASCII")}} characters, followed by a {{cssxref("number")}} indicating the axis value. 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.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting font weight and stretch in a @font-face rule
```css
@font-face {
font-family: "OpenTypeFont";
src: url("open_type_font.woff2") format("woff2");
font-weight: normal;
font-style: normal;
font-variation-settings:
"wght" 400,
"wdth" 300;
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- Other `@font-face` descriptors: {{cssxref("@font-face/font-display", "font-display")}}, {{cssxref("@font-face/font-family", "font-family")}}, {{cssxref("font-feature-settings", "font-feature-settings")}}, {{cssxref("@font-face/font-stretch", "font-stretch")}}, {{cssxref("@font-face/font-style", "font-style")}}, {{cssxref("@font-face/font-weight", "font-weight")}}, {{cssxref("@font-face/src", "src")}}, {{cssxref("@font-face/unicode-range", "unicode-range")}}
- Related font properties: {{cssxref("font-feature-settings")}}, {{cssxref("font-variation-settings")}}
| 0 |
data/mdn-content/files/en-us/web/css/@font-face | data/mdn-content/files/en-us/web/css/@font-face/font-weight/index.md | ---
title: font-weight
slug: Web/CSS/@font-face/font-weight
page-type: css-at-rule-descriptor
browser-compat: css.at-rules.font-face.font-weight
---
{{CSSRef}}
The **`font-weight`** CSS descriptor allows authors to specify font weights for the fonts specified in the {{cssxref("@font-face")}} at-rule. The {{cssxref("font-weight")}} property can separately be used to set how thick or thin characters in text should be displayed.
For a particular font family, authors can download various font faces which correspond to the different styles of the same font family, and then use the `font-weight` descriptor to explicitly specify the font face's weights. The values for the CSS descriptor is same as that of its corresponding font property.
There are generally limited weights available for a particular font family. When a specified weight doesn't exist, a nearby weight is used. Fonts lacking bold typeface are often synthesized by the user agent. To prevent this, use the {{cssxref('font-synthesis')}} shorthand property.
## Syntax
```css
/* Single values */
font-weight: normal;
font-weight: bold;
font-weight: 400;
/* Multiple Values */
font-weight: normal bold;
font-weight: 300 500;
```
The `font-weight` property is described using any one of the values listed below.
### Values
- `normal`
- : Normal font weight. Same as `400`.
- `bold`
- : Bold font weight. Same as `700`.
- `<number>`
- : A {{cssxref("<number>")}} value between 1 and 1000, inclusive. Higher numbers represent weights that are bolder than (or as bold as) lower numbers. Certain commonly used values correspond to common weight names, as described in the [Common weight name mapping](#common_weight_name_mapping) section below.
In earlier versions of the `font-weight` specification, the property accepts only keyword values and the numeric values 100, 200, 300, 400, 500, 600, 700, 800, and 900; non-variable fonts can only really make use of these set values, although fine-grained values (e.g. 451) will be translated to one of these values for non-variable fonts.
CSS Fonts Level 4 extends the syntax to accept any number between 1 and 1000, inclusive, and introduces [Variable fonts](#variable_fonts), which can make use of this much finer-grained range of font weights.
### Common weight name mapping
The numerical values `100` to `900` roughly correspond to the following common weight names:
| Value | Common weight name |
| ----- | ------------------------- |
| 100 | Thin (Hairline) |
| 200 | Extra Light (Ultra Light) |
| 300 | Light |
| 400 | Normal |
| 500 | Medium |
| 600 | Semi Bold (Demi Bold) |
| 700 | Bold |
| 800 | Extra Bold (Ultra Bold) |
| 900 | Black (Heavy) |
### Variable fonts
Most fonts have a particular weight which corresponds to one of the numbers in [Common weight name mapping](#common_weight_name_mapping). However some fonts, called variable fonts, can support a range of weights with more or less fine granularity, and this can give the designer a much closer degree of control over the chosen weight.
For TrueType or OpenType variable fonts, the "wght" variation is used to implement varying weights.
## Accessibility concerns
People experiencing low vision conditions may have difficulty reading text set with a `font-weight` value of `100` (Thin/Hairline) or `200` (Extra Light), especially if the font has a [low contrast color ratio](/en-US/docs/Web/CSS/color#accessibility_concerns).
- [MDN Understanding WCAG, Guideline 1.4 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background)
- [Understanding Success Criterion 1.4.8 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-visual-presentation.html)
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting normal font weight in a @font-face rule
The following finds a local Open Sans font or imports it, and allows using the font for normal font weights.
```css
@font-face {
font-family: "Open Sans";
src:
local("Open Sans") format("woff2"),
url("/fonts/OpenSans-Regular-webfont.woff") format("woff");
font-weight: 400;
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("@font-face/font-display", "font-display")}}
- {{cssxref("@font-face/font-family", "font-family")}}
- {{cssxref("@font-face/font-stretch", "font-stretch")}}
- {{cssxref("@font-face/font-style", "font-style")}}
- {{cssxref("font-feature-settings", "font-feature-settings")}}
- {{cssxref("@font-face/font-variation-settings", "font-variation-settings")}}
- {{cssxref("@font-face/src", "src")}}
- {{cssxref("@font-face/unicode-range", "unicode-range descriptor")}}
| 0 |
data/mdn-content/files/en-us/web/css/@font-face | data/mdn-content/files/en-us/web/css/@font-face/font-stretch/index.md | ---
title: font-stretch
slug: Web/CSS/@font-face/font-stretch
page-type: css-at-rule-descriptor
browser-compat: css.at-rules.font-face.font-stretch
---
{{CSSRef}}
The **`font-stretch`** CSS descriptor allows authors to specify a normal, condensed, or expanded face for the fonts specified in the {{cssxref("@font-face")}} at-rule.
For a particular font family, authors can download various font faces which correspond to the different styles of the same font family, and then use the `font-stretch` descriptor to explicitly specify the font face's stretch. The values for the CSS descriptor is same as that of its corresponding font property.
## Syntax
```css
/* Single values */
font-stretch: ultra-condensed;
font-stretch: extra-condensed;
font-stretch: condensed;
font-stretch: semi-condensed;
font-stretch: normal;
font-stretch: semi-expanded;
font-stretch: expanded;
font-stretch: extra-expanded;
font-stretch: ultra-expanded;
font-stretch: 50%;
font-stretch: 100%;
font-stretch: 200%;
/* multiple values */
font-stretch: 75% 125%;
font-stretch: condensed ultra-condensed;
```
The `font-stretch` property is described using any one of the values listed below.
### Values
- `normal`
- : Specifies a normal font face.
- `semi-condensed`, `condensed`, `extra-condensed`, `ultra-condensed`
- : Specifies a more condensed font face than normal, with ultra-condensed as the most condensed.
- `semi-expanded`, `expanded`, `extra-expanded`, `ultra-expanded`
- : Specifies a more expanded font face than normal, with ultra-expanded as the most expanded.
- `<percentage>`
- : A {{cssxref("<percentage>")}} value between 50% and 200% (inclusive). Negative values are not allowed for this property.
In earlier versions of the `font-stretch` specification, the property accepts only the nine keyword values. CSS Fonts Level 4 extends the syntax to accept a `<percentage>` value as well. This enables variable fonts to offer something more like a continuum of character widths. For TrueType or OpenType variable fonts, the "wdth" variation is used to implement varying widths.
If the font does not provide a face that exactly matches the given value, then values less than 100% map to a narrower face, and values greater than or equal to 100% map to a wider face.
### Keyword to numeric mapping
The table below shows the mapping between keyword values and numeric percentages:
<table class="fullwidth-table standard-table">
<thead>
<tr>
<th scope="col">Keyword</th>
<th scope="col">Percentage</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>ultra-condensed</code></td>
<td>50%</td>
</tr>
<tr>
<td><code>extra-condensed</code></td>
<td>62.5%</td>
</tr>
<tr>
<td><code>condensed</code></td>
<td>75%</td>
</tr>
<tr>
<td><code>semi-condensed</code></td>
<td>87.5%</td>
</tr>
<tr>
<td><code>normal</code></td>
<td>100%</td>
</tr>
<tr>
<td><code>semi-expanded</code></td>
<td>112.5%</td>
</tr>
<tr>
<td><code>expanded</code></td>
<td>125%</td>
</tr>
<tr>
<td><code>extra-expanded</code></td>
<td>150%</td>
</tr>
<tr>
<td><code>ultra-expanded</code></td>
<td>200%</td>
</tr>
</tbody>
</table>
### Variable fonts
Most fonts have a particular width which corresponds to one of the keyterm values. However some fonts, called variable fonts, can support a range of stretching with more or less fine granularity, and this can give the designer a much closer degree of control over the chosen weight. For this, percentage ranges are useful.
For TrueType or OpenType variable fonts, the "wdth" variation is used to implement varying glyph widths.
## Accessibility concerns
People with dyslexia and other cognitive conditions may have difficulty reading fonts that are too condensed, especially if the font has a [low contrast color ratio](/en-US/docs/Web/CSS/color#accessibility_concerns).
- [MDN Understanding WCAG, Guideline 1.4 explanations](/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background)
- [Understanding Success Criterion 1.4.8 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-visual-presentation.html)
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Setting a percentage range for font-stretch
The following find a local Open Sans font or import it, and allow using the font for normal, semi-condensed and semi-expanded states.
```css
@font-face {
font-family: "Open Sans";
src:
local("Open Sans") format("woff2"),
url("/fonts/OpenSans-Regular-webfont.woff") format("woff");
font-stretch: 87.5% 112.5%;
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("@font-face/font-display", "font-display")}}
- {{cssxref("@font-face/font-family", "font-family")}}
- {{cssxref("@font-face/font-weight", "font-weight")}}
- {{cssxref("@font-face/font-style", "font-style")}}
- {{cssxref("font-feature-settings", "font-feature-settings")}}
- {{cssxref("@font-face/font-variation-settings", "font-variation-settings")}}
- {{cssxref("@font-face/src", "src")}}
- {{cssxref("@font-face/unicode-range", "unicode-range descriptor")}}
| 0 |
data/mdn-content/files/en-us/web/css/@font-face | data/mdn-content/files/en-us/web/css/@font-face/font-style/index.md | ---
title: font-style
slug: Web/CSS/@font-face/font-style
page-type: css-at-rule-descriptor
browser-compat: css.at-rules.font-face.font-style
---
{{CSSRef}}
The **`font-style`** CSS descriptor allows authors to specify font styles for the fonts specified in the {{cssxref("@font-face")}} at-rule.
For a particular font family, authors can download various font faces that correspond to the different styles of the same font family and then use the `font-style` descriptor to explicitly specify the font face's style. The values for this CSS descriptor are the same as that of the corresponding {{cssxref("font-style")}} property.
## Syntax
```css
font-style: normal;
font-style: italic;
font-style: oblique;
font-style: oblique 30deg;
font-style: oblique 30deg 50deg;
```
### Values
- `normal`
- : Selects the normal version of the font-family.
- `italic`
- : Specifies that font-face is an italicized version of the normal font.
- `oblique`
- : Specifies that the font-face is an artificially sloped version of the normal font.
- `oblique` with angle
- : Selects a font classified as `oblique`, and additionally specifies an angle for the slant of the text.
- `oblique` with angle range
- : Selects a font classified as `oblique`, and additionally specifies a range of allowable angle for the slant of the text. Note that a range is only supported when the `font-style` is `oblique`; for `font-style: normal` or `italic`, no second value is allowed.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Specifying an italic font style
As an example, consider the garamond font family, in its normal form, we get the following result:
```css
@font-face {
font-family: garamond;
src: url("garamond.ttf");
}
```

The italicized version of this text uses the same glyphs present in the unstyled version, but they are artificially sloped by a few degrees.

On the other hand, if a true italicized version of the font family exists, we can include it in the `src` descriptor and specify the font style as italic, so that it is clear that the font is italicized. True italics use different glyphs and are a bit different from their upright counterparts, having some unique features and generally have a rounded and calligraphic quality. These fonts are specially created by font designers and are **not** artificially sloped.
```css
@font-face {
font-family: garamond;
src: url("garamond-italic.ttf");
font-style: italic;
}
```

## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("@font-face/font-display", "font-display")}}
- {{cssxref("@font-face/font-family", "font-family")}}
- {{cssxref("@font-face/font-stretch", "font-stretch")}}
- {{cssxref("@font-face/font-weight", "font-weight")}}
- {{cssxref("font-feature-settings", "font-feature-settings")}}
- {{cssxref("@font-face/font-variation-settings", "font-variation-settings")}}
- {{cssxref("@font-face/src", "src")}}
- {{cssxref("@font-face/unicode-range", "unicode-range")}}
| 0 |
data/mdn-content/files/en-us/web/css/@font-face | data/mdn-content/files/en-us/web/css/@font-face/src/index.md | ---
title: src
slug: Web/CSS/@font-face/src
page-type: css-at-rule-descriptor
browser-compat: css.at-rules.font-face.src
---
{{CSSRef}}
The **`src`** CSS descriptor for the {{cssxref("@font-face")}} at-rule specifies the resource containing font data. It is required for the `@font-face` rule to be valid.
## Syntax
```css
/* <url> values */
src: url(https://somewebsite.com/path/to/font.woff); /* Absolute URL */
src: url(path/to/font.woff); /* Relative URL */
src: url("path/to/font.woff"); /* Quoted URL */
src: url(path/to/svgFont.svg#example); /* Fragment identifying font */
/* <font-face-name> values */
src: local(font); /* Unquoted name */
src: local(some font); /* Name containing space */
src: local("font"); /* Quoted name */
src: local("some font"); /* Quoted name containing a space */
/* <tech(<font-tech>)> values */
src: url(path/to/fontCOLRv1.otf) tech(color-COLRv1);
src: url(path/to/fontCOLR-svg.otf) tech(color-SVG);
/* <format(<font-format>)> values */
src: url(path/to/font.woff) format("woff");
src: url(path/to/font.otf) format("opentype");
/* Multiple resources */
src:
url(path/to/font.woff) format("woff"),
url(path/to/font.otf) format("opentype");
/* Multiple resources with font format and technologies */
src:
url("trickster-COLRv1.otf") format(opentype) tech(color-COLRv1),
url("trickster-outline.otf") format(opentype);
```
### Values
- `url()`
- : Specifies an external reference consisting of a {{cssxref("<url>")}}, followed by optional hints using the `format()` and `tech()` component values that specify the format and font technology of the resource referenced by the URL. The `format()` and `tech()` components are a comma-separated list of strings of known [font formats](#font_formats) and technologies. If a user agent doesn't support the font technology or formats, it skips downloading the font resource. If no format or technology hints are supplied, the font resource is always downloaded.
- `format()`
- : An optional declaration that follows the `url()` value that provides a hint for the user agent on the font format.
If the value is not supported or invalid, the browser may not download the resource, potentially saving bandwidth.
If omitted, the browser will download the resource and then detect the format.
If including a font source for backward-compatibility that is not in the list of [defined keywords](#formal_syntax), enclose the format string in quotes.
Possible values are described in the [Font formats](#font_formats) section below.
- `tech()` {{Experimental_inline}}
- : An optional declaration that follows the `url()` value that provides a hint for the user agent on the font technology.
The value for `tech()` may be one of the keywords described in [Font technologies](#font_technologies).
- `local(<font-face-name>)`
- : Specifies the font name should the font be available on the user's device.
Enclosing the font name in quotes is optional.
> **Note:** For OpenType and TrueType fonts, `<font-face-name>` is used to match either the Postscript name or the full font name in the name table of locally available fonts. Which type of name is used varies by platform and font, so you should include both of these names to assure proper matching across platforms. Platform substitutions for a given font name must not be used.
> **Note:** Locally available fonts may have been preinstalled on the user's device, or may have been actively installed by the user.
>
> While the set of preinstalled fonts is likely to be the same for all users of a particular device, the set of user-installed fonts is not. By discovering the set of user-installed fonts, a site can therefore build a {{glossary("fingerprinting", "fingerprint")}} for the device, helping the site to track users across the web.
>
> To prevent this, user agents may ignore user-installed fonts when using `local()`.
- `<font-face-name>`
- : Specifies the full name or postscript name of a locally-installed font face using the `local()` component value, which uniquely identifies a single font face within a larger family.
The name can optionally be enclosed in quotes. The font face name [is not case-sensitive](https://drafts.csswg.org/css-fonts-3/#font-family-casing).
> **Note:** The {{domxref("Local Font Access API", "Local Font Access API", "", "nocode")}} can be used to access the user's locally installed font data β this includes higher-level details such as names, styles, and families, as well as the raw bytes of the underlying font files.
## Description
The value of this descriptor is a prioritized, comma-separated list of external references or locally-installed font face names, where each resource is specified using `url()` or `local()`.
When a font is needed, the {{glossary("user agent")}} iterates over the set of references listed using the first one it can successfully activate.
Fonts containing invalid data or local font faces that are not found are ignored and the user agent loads the next font in the list.
If multiple `src` descriptors are set, only the last declared rule that is able to load a resource is applied.
If the last `src` descriptor can load a resource and doesn't include a `local()` font, the browser may download external font files and ignore the local version even if there is one available on the device.
> **Note:** Values within descriptors that the browser considers invalid are ignored.
> Some browsers will ignore the whole descriptor if any item is invalid, even if only one item is invalid.
> This may affect design of fallbacks.
> See [Browser compatibility](#browser_compatibility) for more information.
As with other URLs in CSS, the URL may be relative, in which case it is resolved relative to the location of the style sheet containing the `@font-face` rule. In the case of SVG fonts, the URL points to an element within a document containing SVG font definitions. If the element reference is omitted, a reference to the first defined font is implied. Similarly, font container formats that can contain more than one font load only one of the fonts for a given `@font-face` rule. Fragment identifiers are used to indicate which font to load. If a container format lacks a defined fragment identifier scheme, a simple 1-based indexing scheme (e.g., "font-collection#1" for the first font, "font-collection#2" for the second font, etc.) is used.
If the font file is a container for multiple fonts, a fragment identifier is included to indicate the sub-font that should be used, as shown below:
```css
/* WhichFont is the PostScript name of a font in the font file */
src: url(collection.otc#WhichFont);
/* WhichFont is the element id of a font in the SVG Font file */
src: url(fonts.svg#WhichFont);
```
### Font formats
The following table shows the valid font keywords and their corresponding font formats.
To check if a font format is supported by a browser within CSS, use the {{cssxref("@supports", "@supports")}} rule.
| Keyword | Font Format | Common extensions |
| ------------------- | --------------------- | ----------------- |
| `collection` | OpenType Collection | .otc, .ttc |
| `embedded-opentype` | Embedded OpenType | .eot |
| `opentype` | OpenType | .otf, .ttf |
| `svg` | SVG Font (deprecated) | .svg, .svgz |
| `truetype` | TrueType | .ttf |
| `woff` | WOFF 1.0 | .woff |
| `woff2` | WOFF 2.0 | .woff2 |
> **Note:**
>
> - `format(svg)` stands for [SVG fonts](/en-US/docs/Web/SVG/Tutorial/SVG_fonts), and `tech(color-SVG)` stands for [OpenType fonts with SVG table](https://learn.microsoft.com/en-us/typography/opentype/spec/svg) (also called OpenType-SVG color fonts), which are completely different.
> - The `opentype` and `truetype` values are equivalent whether the font file uses cubic bezier curves (within CFF/CFF2 table) or quadratic bezier curves (within glyph table).
Older non-normalized `format()` values have the following equivalent syntax; provided as a string enclosed in quotes for backward-compatibility reasons:
| Old syntax | Equivalent syntax |
| ------------------------------- | ----------------------------------- |
| `format("woff2-variations")` | `format(woff2) tech(variations)` |
| `format("woff-variations")` | `format(woff) tech(variations)` |
| `format("opentype-variations")` | `format(opentype) tech(variations)` |
| `format("truetype-variations")` | `format(truetype) tech(variations)` |
### Font technologies
The following table shows valid values for the `tech()` descriptor and their corresponding font technologies.
To check if a font technology is supported by a browser within CSS, use the {{cssxref("@supports", "@supports")}} at-rule.
| Keyword | Description |
| :------------------ | :-------------------------------------------------------------------------------------------- |
| `color-cbdt` | Color bitmap data tables |
| `color-colrv0` | Multi-colored glyphs via COLR version 0 table |
| `color-colrv1` | Multi-colored glyphs via COLR version 1 table |
| `color-sbix` | Standard bitmap graphics tables |
| `color-svg` | SVG multi-colored tables |
| `features-aat` | TrueType `morx` and `kerx` tables |
| `features-graphite` | Graphite features, namely `Silf`, `Glat` , `Gloc` , `Feat`, and `Sill` tables |
| `features-opentype` | OpenType `GSUB` and `GPOS` tables |
| `incremental` | Incremental font loading |
| `palettes` | Font palettes by means of `font-palette` to select one of many color palettes in the font |
| `variations` | Font variations in TrueType and OpenType fonts to control the font axis, weight, glyphs, etc. |
## Formal definition
{{cssinfo}}
## Formal syntax
```plain
<url> [ format( <font-format> ) ]? [ tech( <font-tech># ) ]? |
local( <family-name> )
<font-format> = [ <string> | collection | embedded-opentype | opentype | svg | truetype | woff | woff2 ]
<font-tech> = [ <font-features-tech> | <color-font-tech> | variations | palettes | incremental-patch | incremental-range | incremental-auto ]
<font-features-tech> = [ features-opentype | features-aat | features-graphite ]
<color-font-tech> = [ color-COLRv0 | color-COLRv1 | color-SVG | color-sbix | color-CBDT ]
```
## Examples
### Specifying font resources using url() and local()
The example below shows how to define two font faces with the same font family. The `font-family` is named `MainText`. The first font face has a regular font, and the second one is a bold version of the same font family.
```css
/* Defining a regular font face */
@font-face {
font-family: MainText;
src: local(Futura-Medium),
url('FuturaMedium.woff') format("woff"),
url('FuturaMedium.otf') format("opentype");
format("opentype");
}
/* Defining a different bold font face for the same family */
@font-face {
font-family: MainText;
src: local(Gill Sans Bold), /* full font name */
local(GillSans-Bold), /* postscript name */
url('GillSansBold.woff') format("woff"),
url('GillSansBold.otf') format("opentype"),
url("GillSansBold.svg#MyFontBold"); /* Referencing an SVG font fragment by id */
font-weight: bold;
}
/* Using the regular font face */
p {
font-family: MainText;
}
/* Font-family is inherited, but bold fonts are used */
p.bold {
font-weight: bold;
}
```
### Specifying font resources using tech() and format() values
The following example shows how to use the `tech()` and `format()` values to specify font resources.
A font using `color-colrv1` technology and `opentype` format is specified using the `tech()` and `format()` values.
A color font will be activated if the user agent supports it, and an `opentype` non-color is provided as a fallback.
```css
@font-face {
font-family: "Trickster";
src:
url("trickster-COLRv1.otf") format(opentype) tech(color-COLRv1),
url("trickster-outline.otf") format(opentype);
}
/* Using the font face */
p {
font-family: "Trickster";
}
```
### Specifying fallbacks for older browsers
Browsers should use a `@font-face` with a single `src` descriptor listing possible sources for the font.
Since the browser will use the first resource that it is able to load, items should be specified in the order of your preference for their usage.
Generally this means that local files should appear before remote files and that resources with `format()` or `tech()` constraints should appear before resources that don't have them (otherwise the less-constrained version would always be selected).
For example:
```css
@font-face {
font-family: "MgOpenModernaBold";
src:
url("MgOpenModernaBoldIncr.otf") format("opentype") tech(incremental),
url("MgOpenModernaBold.otf") format(opentype);
}
```
A browser that does not support `tech()` above should ignore the first item and attempt to load the second resource.
Some browsers do not yet [ignore invalid items](#browser_compatibility), and instead fail the whole `src` descriptor if any value is invalid.
If working with these browsers you can specify multiple `src` descriptors as fallbacks.
Note that multiple `src` descriptors are attempted in reverse-order, so at the end we have our normal descriptor with all the items.
```css
@font-face {
font-family: "MgOpenModernaBold";
src: url("MgOpenModernaBold.otf") format(opentype);
src: url("MgOpenModernaBoldIncr.otf") format("opentype") tech(incremental);
src:
url("MgOpenModernaBoldIncr.otf") format("opentype") tech(incremental),
url("MgOpenModernaBold.otf") format(opentype);
}
```
### Checking if the user agent supports a font
The following example shows how to check if the user agent supports a font technology using the {{cssxref("@supports")}} rule.
The block of CSS inside `@supports` will be applied if the user agent supports `color-COLRv1` technology.
```css
@supports font-tech(color-COLRv1) {
@font-face {
font-family: "Trickster";
src: url("trickster-COLRv1.otf") format(opentype) tech(color-COLRv1);
}
.colored_text {
font-family: "Trickster";
}
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("@font-face", "@font-face")}}
- {{cssxref("@supports", "@supports")}}
- {{cssxref("@font-face/font-display", "font-display")}}
- {{cssxref("@font-face/font-family", "font-family")}}
- {{cssxref("@font-face/font-stretch", "font-stretch")}}
- {{cssxref("@font-face/font-style", "font-style")}}
- {{cssxref("@font-face/font-weight", "font-weight")}}
- {{cssxref("font-feature-settings", "font-feature-settings")}}
- {{cssxref("@font-face/font-variation-settings", "font-variation-settings")}}
- {{cssxref("@font-face/unicode-range", "unicode-range")}}
| 0 |
data/mdn-content/files/en-us/web/css/@font-face | data/mdn-content/files/en-us/web/css/@font-face/ascent-override/index.md | ---
title: ascent-override
slug: Web/CSS/@font-face/ascent-override
page-type: css-at-rule-descriptor
browser-compat: css.at-rules.font-face.ascent-override
---
{{CSSRef}}
The **`ascent-override`** CSS descriptor for the {{cssxref("@font-face")}} at-rule defines the ascent metric for the font. The ascent metric is the height above the baseline that CSS uses to lay out line boxes in an inline formatting context.
## Syntax
```css
ascent-override: normal;
ascent-override: 90%;
```
### Values
- `normal`
- : The default value. When used the metric value is obtained from the font file.
- `<percentage>`
- : A {{cssxref("<percentage>")}} value.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Overriding metrics of a fallback font
The `ascent-override` property can help when overriding the metrics of a fallback font to better match those of a primary web font.
```css
@font-face {
font-family: web-font;
src: url("https://example.com/font.woff");
}
@font-face {
font-family: local-font;
src: local(Local Font);
ascent-override: 125%;
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("@font-face/descent-override", "descent-override")}}
- {{cssxref("@font-face/font-display", "font-display")}}
- {{cssxref("@font-face/font-family", "font-family")}}
- {{cssxref("@font-face/font-weight", "font-weight")}}
- {{cssxref("@font-face/font-style", "font-style")}}
- {{cssxref("@font-face/font-stretch", "font-stretch")}}
- {{cssxref("font-feature-settings", "font-feature-settings")}}
- {{cssxref("@font-face/font-variation-settings", "font-variation-settings")}}
- {{cssxref("@font-face/line-gap-override", "line-gap-override")}}
- {{cssxref("@font-face/src", "src")}}
- {{cssxref("@font-face/size-adjust", "size-adjust")}}
- {{cssxref("@font-face/unicode-range", "unicode-range descriptor")}}
| 0 |
data/mdn-content/files/en-us/web/css/@font-face | data/mdn-content/files/en-us/web/css/@font-face/descent-override/index.md | ---
title: descent-override
slug: Web/CSS/@font-face/descent-override
page-type: css-at-rule-descriptor
browser-compat: css.at-rules.font-face.descent-override
---
{{CSSRef}}
The **`descent-override`** CSS descriptor for the {{cssxref("@font-face")}} at-rule defines the descent metric for the font. The descent metric is the height below the baseline that CSS uses to lay out line boxes in an inline formatting context.
## Syntax
```css
descent-override: normal;
descent-override: 90%;
```
### Values
- `normal`
- : The default value. When used the metric value is obtained from the font file.
- `<percentage>`
- : A {{cssxref("<percentage>")}} value.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Overriding metrics of a fallback font
The `descent-override` property can help when overriding the metrics of a fallback font to better match those of a primary web font.
```css
@font-face {
font-family: web-font;
src: url("https://example.com/font.woff");
}
@font-face {
font-family: local-font;
src: local(Local Font);
descent-override: 125%;
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("@font-face/ascent-override", "ascent-override")}}
- {{cssxref("@font-face/font-display", "font-display")}}
- {{cssxref("@font-face/font-family", "font-family")}}
- {{cssxref("@font-face/font-weight", "font-weight")}}
- {{cssxref("@font-face/font-style", "font-style")}}
- {{cssxref("@font-face/font-stretch", "font-stretch")}}
- {{cssxref("font-feature-settings", "font-feature-settings")}}
- {{cssxref("@font-face/font-variation-settings", "font-variation-settings")}}
- {{cssxref("@font-face/line-gap-override", "line-gap-override")}}
- {{cssxref("@font-face/src", "src")}}
- {{cssxref("@font-face/size-adjust", "size-adjust")}}
- {{cssxref("@font-face/unicode-range", "unicode-range descriptor")}}
| 0 |
data/mdn-content/files/en-us/web/css/@font-face | data/mdn-content/files/en-us/web/css/@font-face/line-gap-override/index.md | ---
title: line-gap-override
slug: Web/CSS/@font-face/line-gap-override
page-type: css-at-rule-descriptor
browser-compat: css.at-rules.font-face.line-gap-override
---
{{CSSRef}}
The **`line-gap-override`** CSS descriptor for the {{cssxref("@font-face")}} at-rule defines the line-gap metric for the font. The line-gap metric is the font recommended line-gap or external leading.
## Syntax
```css
line-gap-override: normal;
line-gap-override: 90%;
```
### Values
- `normal`
- : The default value. When used the metric value is obtained from the font file.
- `<percentage>`
- : A {{cssxref("<percentage>")}} value.
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Overriding metrics of a fallback font
The `line-gap-override` property can help when overriding the metrics of a fallback font to better match those of a primary web font.
```css
@font-face {
font-family: web-font;
src: url("https://example.com/font.woff");
}
@font-face {
font-family: local-font;
src: local(Local Font);
line-gap-override: 125%;
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("@font-face/descent-override", "descent-override")}}
- {{cssxref("@font-face/font-display", "font-display")}}
- {{cssxref("@font-face/font-family", "font-family")}}
- {{cssxref("@font-face/font-weight", "font-weight")}}
- {{cssxref("@font-face/font-style", "font-style")}}
- {{cssxref("@font-face/font-stretch", "font-stretch")}}
- {{cssxref("font-feature-settings", "font-feature-settings")}}
- {{cssxref("@font-face/font-variation-settings", "font-variation-settings")}}
- {{cssxref("@font-face/line-gap-override", "line-gap-override")}}
- {{cssxref("@font-face/src", "src")}}
- {{cssxref("@font-face/size-adjust", "size-adjust")}}
- {{cssxref("@font-face/unicode-range", "unicode-range descriptor")}}
| 0 |
Subsets and Splits