Mask-Image and Mix-Blend-Mode | Stunning Aesthetics with CSS

Mask-Image

The mask-image property allows you to mask an element with an image, revealing only the parts of the element that correspond to transparent areas of the image.

Syntax:

CSS

mask-image: url(image.png);

Example:

HTML

<div class=”masked-element”>

  <img src=”image.jpg”>

</div>

CSS

.masked-element {

  mask-image: url(mask.png);

  -webkit-mask-image: url(mask.png); /* For older WebKit browsers */

}

Mix-Blend-Mode

The mix-blend-mode property allows you to blend an element with its background or other elements.

Syntax:

CSS

mix-blend-mode: mode;

Common Modes:

  • normal: No blending.
  • multiply: Multiplies the colors.
  • screen: Inverts the colors and adds them together.
  • overlay: Blends the colors based on their relative luminance.
  • darken: Darkens the base color by the blend color.
  • lighten: Lightens the base color by the blend color.
  • color-dodge: Brightens the base color by the blend color.
  • color-burn: Darkens the base color by the blend color.
  • hard-light: Combines the effects of multiply and screen.
  • soft-light: Combines the effects of overlay and screen.
  • difference: Subtracts the colors.
  • exclusion: Inverts the colors and subtracts them.
  • hue: Replaces the hue of the base color with the hue of the blend color.
  • saturation: Replaces the saturation of the base color with the saturation of the blend color.
  • color: Replaces the color of the base color with the color of the blend color.
  • luminosity: Replaces the luminosity of the base color with the luminosity of the blend color.

Example:

CSS

.element {

  mix-blend-mode: multiply;

}

Combining Mask-Image and Mix-Blend-Mode

You can combine mask-image and mix-blend-mode to create unique and visually interesting effects.

Example:

CSS

.masked-element {

  mask-image: url(mask.png);

  mix-blend-mode: multiply;

}

Best Practices

  • Test on various devices: Ensure that these effects work as expected on different browsers and screen sizes.
  • Consider performance: Excessive use of masking and blending can impact performance.
  • Experiment with different modes: Try different mix-blend-mode values to achieve the desired effect.

By effectively using mask-image and mix-blend-mode, you can create visually appealing and dynamic web designs.

CSS clip-path | Stunning Aesthetics with CSS
Introduction to Responsive Images | Responsive Images

Get industry recognized certification – Contact us

keyboard_arrow_up
Open chat
Need help?
Hello 👋
Can we help you?