🇺🇦 Proudly Ukrainian — every project with us helps support Ukraine's defense and lasting peace in Europe.

Meet the team →
← All articles

November 28, 2024

Effortlessly Remove Image Backgrounds

Learn how to seamlessly remove image backgrounds using the CSS mix-blend-mode property.

Effortlessly Remove Image Backgrounds

When working with web designs, image backgrounds can sometimes clash with the website’s overall aesthetic. Fortunately, there’s a simple CSS solution that doesn’t require complex editing or redesigns: the mix-blend-mode property.

💡The Challenge

Imagine this:

  • You’ve created a beautiful, responsive layout that functions perfectly.
  • But some images have backgrounds that don’t match your site’s design—standing out in an unwanted way.

Your first instinct might be to redesign your layout or adjust the site’s background colors to match those of the images. But there’s a better solution.

The Solution: mix-blend-mode 🤔

CSS’s mix-blend-mode property can blend an image’s background seamlessly into its container. Here’s how it works:

  1. The Setup:
    • Place each image inside a div container with the desired background color.Apply the mix-blend-mode property to the image element.
    • Example CSS: img { mix-blend-mode: darken; }
  2. How It Works:
    • The browser compares the colors of each pixel in the image with the corresponding pixel in the container’s background.
    • With the darken blend mode:
      • Darker pixels between the image and background are retained.
      • Lighter pixels from the image (typically the image’s background) blend into the container’s background.

Most product images have darker, more saturated colors for the product itself compared to their lighter, plain backgrounds. When using mix-blend-mode: darken, the image’s darker product pixels remain intact, while the lighter background pixels merge with the container’s color. This gives the illusion that the image background has been “removed,” when in reality, it has blended into the surrounding design.

Here’s an example featuring two product images. On the left, the product has a light blue background that clashes with the site’s gray background. On the right, the same product image seamlessly blends into the gray background using the CSS property mix-blend-mode: darken. This highlights how CSS can effectively address issues with mismatched background colors.

To understand which color is “darker,” consider converting colors into the HSL format:

  • Hue (H): Represents the color type.
  • Saturation (S): How vivid the color is.
  • Lightness (L): Determines how bright the color is.

In HSL, the lower the Lightness (L) value, the darker the color. The darken blend mode retains the color with the lowest lightness.

A Simple Trick with Big Impact🌟This approach is both effective and easy to implement, allowing you to avoid major design overhauls while achieving a polished look. The next time you encounter mismatched image backgrounds, try this CSS property and watch the magic happen!

If you have any questions about your project, please write to us 🚀🚀🚀

We are happy to help🤝

Related articles

Tell us what you're building

03
Oleksii, mobile app developer at Skynix

"I'm Oleksii. I work hands-on with our team here at Skynix, turning ideas into real, working products. Tell me what you're building — I read every request myself and reply within one business day."

Oleksii Prozhoha — Skynix, working hands-on with the team
What do you need?
Attach a wireframe or screenshot — PNG or JPG up to 5 MB.

Read by Oleksii · reply within one business day.

bracket icon
bracket icon
bracket icon
bracket icon
bracket icon
bracket icon
slash icon
slash icon
slash icon
slash icon
slash icon
slash icon
bracket icon
bracket icon
bracket icon
bracket icon
bracket icon
bracket icon