CSS Skeleton Image

An image placeholder that keeps its aspect ratio and shows a photo icon under a diagonal shimmer.

  • placeholder
  • photo
  • aspect-ratio
  • lazy loading
  • shimmer
HTML
<div class="skel-image" role="status" aria-label="Loading image"></div>
CSS
.skel-image {
  position: relative;
  width: min(100%, 280px);
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 14px;
  background: #e5e7eb;
}

/* Photo icon */
.skel-image::before {
  content: "";
  position: absolute;
  inset: 0;
  width: 48px;
  height: 48px;
  margin: auto;
  background: #cbd5e1;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='2'/%3E%3Ccircle cx='9' cy='9' r='2'/%3E%3Cpath d='m21 15-3.1-3.1a2 2 0 0 0-2.8 0L6 21'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='2'/%3E%3Ccircle cx='9' cy='9' r='2'/%3E%3Cpath d='m21 15-3.1-3.1a2 2 0 0 0-2.8 0L6 21'/%3E%3C/svg%3E") center / contain no-repeat;
}

.skel-image::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, #fff0 30%, #ffffff99 50%, #fff0 70%) 0 0 / 250% 100%;
  animation: skel-image-shine 1.8s ease-in-out infinite;
}

@keyframes skel-image-shine {
  from { background-position: 100% 0; }
  to { background-position: 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  .skel-image::after { animation: none; }
}

About this CSS Skeleton Image

This CSS Skeleton Image is 38 lines of pure CSS (1.4 KB) with no JavaScript and no dependencies. It uses keyframe animations, linear gradients, masks and aspect-ratio. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.

CSS features used

Customize it

The colors in this snippet. Search and replace them to match your brand:

  • #e5e7eb
  • #cbd5e1
  • #fff0
  • #ffffff99

How to use this skeleton image

  1. Copy the HTML and paste it where you want the element to appear.
  2. Copy the CSS into your stylesheet, or inside a <style> tag.
  3. Keep the .skel-image class name, or rename it in both places. Then tweak colors, sizes and timing to match your design.
  4. Using React or Next.js? Change class to className in the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).

Building with an AI tool?

“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.

Feedback