Title assumes ~275 WPM reading, as used on DEV.to
1. Clip Paths
Clip paths allow you to "clip" elements into a shape, represented in CSS with the polygon
, circle
, or ellipse
functions. For example:
div {
background-image: url(background.jpg);
clip-path: polygon(0 0, 100% 0, 100% 85%, 0 100%);
}
Clip paths are written with the clip-path
property for clipping element content, or the background-clip
property for clipping element backgrounds.
The CSS polygon
function is one of the most common for clipping, and is composed of a list of points (vertices). Each point is written as x y
.
For example: 0 0
would signify the top left, whereas 100% 100%
would signify the bottom right. The example above uses a point on the bottom right that is not fully at the bottom (only 85%), producing a diagonal effect.
Clip paths are especially popular in flat design for creating slanted areas as shown in the example. I use this on my personal website to draw attention to background images in certain pages.
Basic clip-path usage is supported in all major browsers except Edge and IE: see CanIUse Data for Clip Paths.
You can create your own clip-paths yourself, or you can use a tool like Clippy to automatically generate clip path CSS for you.
2. Blend Modes
Blend modes allow you to blend an element's content with its parent element(s) or its background using specific methods.
Let's say you were trying to overlay a yellow color over a background image. Ordinarily:
div {
background-image: linear-gradient(yellow, yellow)), url(background.jpg);
}
In this case, the yellow color and the image were simply added together to create final result. However, if we wanted to blend the yellow into the image instead of adding it, we could use a blend mode called screen
:
div {
background-image: linear-gradient(yellow, yellow)), url(background.jpg);
background-blend-mode: screen;
}
Blend modes are specified in backgrounds with the background-blend-mode
property, and in elements (for blending with backgrounds or parents) with the mix-blend-mode
property.
Possible blend modes include: screen
, multiply
, hard-light
, difference
, and more. More information on possible blend modes and their effects can be found here on the MDN web docs.
Blend modes are supported in all major browsers except Edge and IE: see CanIUse Data for Background Blend Modes.
3. CSS Filters
CSS filters provide a vast array of options for filtering elements visually. For example:
img {
filter: blur(10px);
}
Other filters include: sepia
, invert
, grayscale
, and more.
CSS filters have a vast variety of uses, for example: CSS filters have become popular in creating a dark mode effect on sites using the invert
filter.
The filter
property is supported in all major browsers except IE: see CanIUse Data for CSS Filters.
Thanks for reading!
I hope you enjoyed this post, and found some of the CSS features mentioned to be useful.
Thanks for scrolling.
β Gabriel Romualdo, January 3, 2020
Top comments (6)
Great write up.
Quick tip:
You wrote: β Fred Adams, January 3, 2019
I think you meant: β Fred Adams, January 3, 2020
Thanks for spotting that! Just a clumsy mistake, sorry. It's fixed now, and thanks again.
β Gabriel
π
Features like these remind me why I love CSS.
And dislike IE ;)
Thanks for these! I especially found clip path useful :)
Thanks for sharing this, especially the blend mode.