CSS

CSS Overview Selectors Declarations Rule Sets Comments Reset/Normalize Origin Importance Order Specificity Inheritance Cascade Layers Inline Styles Internal Styles External Styles @import Absolute Units Relative Units Dynamic Viewport Angle Units Time Units Frequency Units: Resolution Units Keywords Color Formats Color Functions & Spaces Background Color Background Image Background Repeat Background Position Background Size Background Attachment Background Shorthand Multiple Backgrounds Linear Gradients Radial Gradients Conic Gradients Font Family Font Size Font Weight Font Style Line Height Text Align Text Decoration Text Transform Letter Spacing Word Spacing Text Shadow Text Wrap Variable Fonts Content Box Padding Box Border Box Margin Box Box Sizing Property Margin Padding Border Outline Box Shadow Block Display Inline Display Inline Block Display Static Position Relative Position Absolute Position Fixed Position Sticky Position Top Element Position Right Element Position Bottom Element Position Left Element Position Z Index Flexbox Box Layout Display Flex Flex Direction Flex Wrap Justify Content Align Items Align Content Gap, Row Gap & Column Gap Flex Grow Flex Shrink Flex Basis Flex Shorthand Order Property Align Self Practical Applications CSS Grid Layout Grid Display Grid Template Columns Grid Template Rows Grid Template Areas Justify Items Grid Auto Columns Justify Self Nested Grids Responsive Web Design Min Width Max Width Orientation Logical Operators Pointer Hover Prefers Color Scheme Fluid Images Flexible Typography Viewport Width Advanced CSS Features Defining variables Using variables Scope & Inheritance of CSS Variables Property Value Fallback Practical Applications :Hover :Active :Focus :Focus Visible :Visited :Link :First Child :Last Child :Nth Child :Nth of Type :Empty :Checked :Disabled :Enabled :Valid :Invalid :Required :Has :Not :Is :Where ::Before Pseudo Element ::After Pseudo Element ::First Letter ::First Line ::Selection ::Marker CSS 2D Transformations CSS 3D Transformations Transform Origin Transform Style Backface Visibility Transition Property Transition Duration Transition Timing Function Transition Delay Transition Shorthand Ease Timing Function Linear Timing Function Ease In Timing Function Ease Out Timing Function Ease In Out Timing Function Cubic Bezier Function Animations (@keyframes) Defining @keyframes Animation Name CSS Animation Duration Animation Timing Function CSS Animation Delay CSS Animation Iteration Count Animations Direction CSS Animation Fill Mode CSS Animation Play State CSS Filter Blur CSS Filter Brightness CSS Filter Contrast() CSS Drop Shadow CSS Grayscale CSS Hue Rotate CSS Invert CSS Opacity CSS Saturate CSS Sepia Mix Blend Mode Background Blend Mode Object Fit & Object Position Scroll Snap Type Scroll Snap Align Scroll Padding Scroll Margin Scroll Triggered Animations JS Variables

Background Blend Mode


The background-blend-mode CSS property defines how an element's background images and its background color should blend with each other. This powerful feature allows you to create a wide variety of visual effects, from simple color overlays to complex, artistic compositions, directly in the browser.


Example 1: Multiply Blend Mode

.multiply-effect {
  /* Sets a background image */
  background-image: url('https://via.placeholder.com/600x400');

  /* Sets a solid background color */
  background-color: #ff6347; /* Tomato */

  /* Blends the image and color using the multiply mode */
  background-blend-mode: multiply;

  /* Ensures the background covers the entire element */
  background-size: cover;
  height: 400px;
}

Explanation: The multiply blend mode multiplies the colors of the background image and the background color. This results in a darker image, as the lighter pixels of the image take on the hue of the background color.


Example 2: Screen Blend Mode

.screen-effect {
  /* Specifies the background image */
  background-image: url('https://via.placeholder.com/600x400');

  /* Defines a solid background color */
  background-color: #4682b4; /* SteelBlue */

  /* Applies the screen blend mode */
  background-blend-mode: screen;

  /* Stretches the background to fill the element */
  background-size: cover;
  height: 400px;
}

Explanation: The screen blend mode inverts the colors of both the image and the background color, multiplies them, and then inverts the result. This creates a lighter, brighter effect, the opposite of multiply.


Example 3: Overlay Blend Mode

.overlay-effect {
  /* The image for the background */
  background-image: url('https://via.placeholder.com/600x400');

  /* The color to blend with the image */
  background-color: #32cd32; /* LimeGreen */

  /* Uses the overlay blend mode for a combined effect */
  background-blend-mode: overlay;

  /* Makes sure the background image covers the element */
  background-size: cover;
  height: 400px;
}

Explanation: The overlay blend mode combines the multiply and screen modes. Darker parts of the image become darker, and lighter parts become lighter, which increases the contrast of the final image.


Example 4: Difference Blend Mode

.difference-effect {
  /* Setting the background image */
  background-image: url('https://via.placeholder.com/600x400');

  /* Setting the background color to blend */
  background-color: #ffff00; /* Yellow */

  /* Applying the difference blend mode */
  background-blend-mode: difference;

  /* Resizing the background to cover the element */
  background-size: cover;
  height: 400px;
}

Explanation: The difference blend mode subtracts the darker of the two colors from the lighter color. This can create a psychedelic or inverted color effect, depending on the colors used.


Example 5: Luminosity Blend Mode

.luminosity-effect {
  /* Define the background image */
  background-image: url('https://via.placeholder.com/600x400');

  /* Define the background color for blending */
  background-color: #ee82ee; /* Violet */

  /* Use the luminosity blend mode */
  background-blend-mode: luminosity;

  /* Ensure the background image fits the element */
  background-size: cover;
  height: 400px;
}

Explanation: The luminosity blend mode preserves the luminosity of the top layer (the image) while adopting the hue and saturation of the bottom layer (the color). This is great for creating monochromatic images with a color tint.


Example 6: Gradient Blend

.gradient-blend-effect {
  /* A linear gradient as the background image */
  background-image: linear-gradient(to right, #ff0000, #0000ff); /* Red to Blue */

  /* A solid color to blend with the gradient */
  background-color: #00ff00; /* Green */

  /* Blending the gradient and the solid color */
  background-blend-mode: lighten;

  /* Defining the height of the element */
  height: 400px;
}

Explanation: The lighten blend mode compares the color information for each pixel of the gradient and the background color and selects the lighter of the two. This results in a blended background with the brightest color values from both layers.


Example 7: Multiple Backgrounds and Blend Modes

.multiple-blend-effect {
  /* Two background images are used */
  background-image: url('https://via.placeholder.com/300x200'), url('https://via.placeholder.com/300x200/0000FF');

  /* A solid background color */
  background-color: #ff1493; /* DeepPink */

  /* Two corresponding blend modes are applied */
  background-blend-mode: screen, multiply;

  /* Positioning the background images */
  background-position: left, right;
  background-repeat: no-repeat;
  height: 400px;
}

Explanation: You can apply different blend modes to multiple background images. In this example, the first image is blended with the background color using screen, and the second image is blended using multiply.