# スケルトンスクリーンのCSSアニメーション実装

> コンテンツ読み込み中のプレースホルダー。グラデーションのbackground-positionを動かして「光が流れる」質感を作ります。

- カテゴリ: ローディング
- URL: https://www.css-dictionary.com/animations/skeleton-shimmer/

## HTML

```html
<div class="skeleton-card">
  <div class="skeleton avatar"></div>
  <div class="lines">
    <div class="skeleton line"></div>
    <div class="skeleton line short"></div>
  </div>
</div>
```

## CSS

```css
.skeleton-card {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 260px;
}

.skeleton {
  background: linear-gradient(
    90deg,
    #ece4d2 25%,
    #f7f1e3 37%,
    #ece4d2 63%
  );
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

@keyframes shimmer {
  from { background-position: 100% 0; }
  to { background-position: 0 0; }
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  flex-shrink: 0;
}

.lines { flex: 1; }
.line {
  height: 12px;
  border-radius: 6px;
  margin-block: 8px;
}
.line.short { width: 60%; }

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
}
```

## 仕組みの解説

要素の背景に「地の色→少し明るい色→地の色」の横グラデーションを敷き、background-sizeを400%に拡大してからbackground-positionを100%→0%へ動かすと、光の帯が左から右へ流れて見えます。widthやtransformを動かさないためリフローが起きず、多数のスケルトンを同時に表示しても軽いのが利点です。

## 実装のポイント

実物のレイアウト（アバター+2行）に形を似せるほど、読み込み後の切り替わりが自然に感じられます。

## 使っているプロパティ

- [linear-gradient](https://www.css-dictionary.com/property/linear-gradient.md)
- [background-size](https://www.css-dictionary.com/property/background-size.md)
- [background-position](https://www.css-dictionary.com/property/background-position.md)
- [animation](https://www.css-dictionary.com/property/animation.md)

