Course contentsShow
← Web Development
Lesson 2028 of 2,98237. Image and Asset OptimizationFree lesson

Solid Color Placeholders

Use dominant color extraction and CSS background-color to create instant, zero-byte placeholders for images.

Solid Color Placeholders

What you'll learn: How to use a single dominant color as an instant, zero-byte placeholder while images load.

The Core Idea

A solid color placeholder extracts the most prominent color from an image and applies it as a CSS background-color to the image container. While the actual image downloads, users see this color instead of empty white space or jarring layout shifts. Think of it like painting a wall the dominant color of a future painting—it sets the visual tone immediately without waiting for the full artwork to arrive.

This technique requires zero extra bytes at runtime because the color value is just a small string (like #a7c4e8) embedded directly in your HTML or CSS.

How It Works

  1. Extract the dominant color from your image during build time (using tools or manual sampling)
  2. Set it as background-color on the image element or its container
  3. The image loads on top of this color backdrop
  4. Users perceive continuity rather than sudden content appearance
<div style="background-color: #7a9e5f; aspect-ratio: 16/9;">
  <img 
    src="forest.jpg" 
    alt="Forest landscape"
    loading="lazy"
    style="width: 100%; height: 100%; object-fit: cover;"
  >
</div>

In this example, the greenish #7a9e5f appears instantly. When forest.jpg loads, it seamlessly replaces the placeholder without layout shift.

Why This Matters

Unlike blurred placeholders (which require extra image bytes) or skeleton screens (which need custom markup), solid color placeholders are lightweight and automatic. They work perfectly with lazy loading—the color holds the space while Intersection Observer triggers the image fetch.

Key Takeaway: Solid color placeholders provide instant visual feedback at zero bandwidth cost by using CSS background colors derived from your images' dominant hues.