Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS module landing page #23898

Merged
merged 36 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f55fccb
Test: let me know what you think
estelle Jan 26, 2023
689d0cb
glossary
estelle Jan 26, 2023
ce1365e
animation
estelle Jan 27, 2023
6281187
animation
estelle Jan 27, 2023
233c738
animation
estelle Jan 27, 2023
6a51071
tweaks
estelle Jan 27, 2023
199bb14
tweaks
estelle Jan 27, 2023
57cb928
animation example
estelle Jan 27, 2023
d60ef1a
prefers reduced motion
estelle Jan 27, 2023
cd36a8a
ground cover
estelle Jan 27, 2023
dab1526
details
estelle Jan 27, 2023
2e84504
details
estelle Jan 27, 2023
5beee71
change associated to related
estelle Jan 27, 2023
4ebd970
tweaks
estelle Jan 27, 2023
98913a5
make example keyboard stoppable
estelle Jan 27, 2023
d95f4bb
tweaks
estelle Jan 28, 2023
d3dfdd1
tests for discussions
estelle Jan 30, 2023
efeb0dc
tests for discussions
estelle Jan 30, 2023
9bb88de
tests for discussions
estelle Jan 30, 2023
38dd438
tests for discussions
estelle Jan 30, 2023
57420b3
updated to Animation example to explain the code
estelle Jan 30, 2023
8c0a670
updated to Animation example to explain the code
estelle Jan 30, 2023
51e9591
make C&B match the template
estelle Jan 30, 2023
7070256
updated to C&B example to explain the code
estelle Jan 31, 2023
a065682
updated to C&B: define filter in see also section
estelle Jan 31, 2023
89f98f9
link to blob
estelle Jan 31, 2023
9670b09
Apply suggestions from code review
estelle Jan 31, 2023
9376a0a
Update index.md
estelle Jan 31, 2023
f7440d9
add experimental
estelle Jan 31, 2023
54ed767
Update files/en-us/web/css/compositing_and_blending/index.md
estelle Jan 31, 2023
e23117b
missing property, experimental inline on other
estelle Jan 31, 2023
40c98ae
testing spaces
estelle Jan 31, 2023
57f6b89
spacing
estelle Jan 31, 2023
ece7d6d
spacing
estelle Jan 31, 2023
e2561e3
remove extra character
dipikabh Feb 1, 2023
b37f4c1
add black line before heading
dipikabh Feb 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 87 additions & 10 deletions files/en-us/web/css/compositing_and_blending/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Compositing and Blending
title: CSS compositing and blending
slug: Web/CSS/Compositing_and_Blending
page-type: css-module
tags:
Expand All @@ -8,15 +8,81 @@ tags:
- Guide
- Overview
- Reference
browser-compat:
- css.properties.background-blend-mode
- css.properties.isolation
- css.properties.mix-blend-mode
spec-urls:
- https://drafts.fxtf.org/compositing/
- https://www.w3.org/TR/compositing-1/
---

{{CSSRef}}

**Compositing and Blending** is a CSS module that defines how shapes of different elements are combined into a single image.
The **compositing and blending** CSS module defines how an element's background layers can be blended together, how an element can be blended with its container, and whether the element must create a new [stacking context](/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context).

The properties in this CSS module can be used to define the blending mode that should be used, if any, to blend an element's background images and colors into a single background image. This module provides 16 blending modes. You can also define how an element's borders, background, and content, including text, emojis, and images, should be blended with the background of its container.

### Compositing and blending in action

In this example, each box has a border, two striped background images, and a solid color background. The common background for all the boxes contains a pattern of circles. The three boxes in the second row are set to blend with the background of the container.
estelle marked this conversation as resolved.
Show resolved Hide resolved

```html hidden
<section>
<div><span>Normal, with no blending</span></div>
<div><span>Multiplies colors</span></div>
<div><span>Multiplies based on background color</span></div>
<div>Normal, with no blending</div>
<div>Multiplies colors</div>
<div>Multiplies based on background color</div>
</section>
```

```css hidden
/* creates a div with two offset striped background images and a background color. */
div {
width: 200px;
height: 200px;
background-image:
repeating-linear-gradient(45deg, red 0 15px, pink 15px 30px),
repeating-linear-gradient(-45deg, blue 0 15px, lightblue 15px 30px);
background-size: 150px 150px;
background-repeat: no-repeat;
background-position: top left, bottom right;
background-color: palegoldenrod;
text-align: center;
padding-top: 150px;
font-family: sans-serif;
box-sizing: border-box;
border: 5px solid black;
}
div:nth-of-type(3n+1){
background-blend-mode: normal;
}
div:nth-of-type(3n+2){
background-blend-mode: multiply;
}
div:nth-of-type(3n+3){
background-blend-mode: overlay;
}
div:nth-of-type(n + 4) {
mix-blend-mode: difference;
}
/* put a pink background with transparent round holes that covers the entire element, and lay the examples in two rows with three columns each */
section {
padding: 0.75em;
background: radial-gradient(circle, transparent 0 20px, rgb(255, 200, 200) 20px);
background-size: 60px 60px;
background-position: center;
display: inline-grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 1em;
}
/* make some of the text more legible */
span {
background-color: #ffffff99;
}
```

{{ EmbedLiveSample('Compositing_and_blending_in_action', "630", "300") }}

Notice how the background, border, and the content are all impacted as a result of the blending. To see the code for this sample, [view the source on Github](https://github.com/mdn/content/blob/main/files/en-us/web/css/compositing_and_blending/index.md?plain=1).

## Reference

Expand All @@ -26,14 +92,25 @@ browser-compat:
- {{cssxref("isolation")}}
- {{cssxref("mix-blend-mode")}}

### Data types
## Related concepts

- {{cssxref("&lt;blend-mode&gt;")}}
- {{cssxref("blend-mode")}} data type
- {{cssxref("filter")}} CSS property
- {{cssxref("backdrop-filter")}} CSS property
- {{cssxref("mask-composite")}} CSS property
- {{cssxref("background-color")}} CSS property
- {{cssxref("background-image")}} CSS property
- {{glossary("stacking context")}} glossary term
- {{ SVGElement("feBlend")}} SVG filter primitive
- {{ SVGElement("feComposite")}} SVG filter primitive
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should/can there be an order to list these? alphabetical within a category

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set them in order of relevance. Filter, which does something similar, seemed more relevant than background properties, which I then did put in alphabetical order.


## Specifications

{{Specifications}}

## Browser compatibility
## See also

{{Compat}}
- Properties in the [CSS filter effects](/en-US/docs/Web/CSS/Filter_Effects) module enable applying filters effects, such as blurring and changing color intensity, to images, backgrounds, and borders.
- [Compositing And Blending In CSS](https://www.sarasoueidan.com/blog/compositing-and-blending-in-css/) (2015)
- [Editing Images in CSS: Blend Modes](https://code.tutsplus.com/tutorials/editing-images-in-css-blend-modes--cms-26058) (2022)
- [web.dev: blend modes](https://web.dev/learn/css/blend-modes/) (2021)
Loading