Toolypet
ブログに戻る
CSS

CSS Animation & Transition 完全ガイド 2026

CSS transitionとanimationの違い、使い方、パフォーマンス最適化まで。滑らかなUIインタラクションを作る実践ガイド。

Toolypet Team

Toolypet Team

Development Team

7 分で読めます

CSS Animation & Transition 完全ガイド 2026

ボタンのホバー効果、ローディングスピナー、ページ遷移...モダンWebではアニメーションは必須です。

JavaScriptなしでCSSだけで滑らかなインタラクションを作る方法を学びましょう。


Transition vs Animation

特性TransitionAnimation
トリガー状態変化が必要 (:hover など)自動実行可能
キーフレーム開始-終了の2つ無制限
ループ不可無限ループ可能
方向順方向のみ逆方向、交互可能
用途単純な状態遷移複雑なアニメーション

CSS Transition

基本構文

transition: property duration timing-function delay;
プロパティ説明デフォルト
property遷移するプロパティall
duration持続時間0s
timing-function加速曲線ease
delay開始遅延0s

基本例

/* 単一プロパティ */
.button {
  background: #3b82f6;
  transition: background 0.3s ease;
}

.button:hover {
  background: #2563eb;
}

/* 複数プロパティ */
.card {
  transform: translateY(0);
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

タイミング関数

/* 組み込み関数 */
.ease { transition-timing-function: ease; }         /* デフォルト */
.linear { transition-timing-function: linear; }     /* 一定速度 */
.ease-in { transition-timing-function: ease-in; }   /* ゆっくり開始 */
.ease-out { transition-timing-function: ease-out; } /* ゆっくり終了 */
.ease-in-out { transition-timing-function: ease-in-out; }

/* カスタムベジェ曲線 */
.custom { transition-timing-function: cubic-bezier(0.68, -0.55, 0.27, 1.55); }

/* ステップ */
.steps { transition-timing-function: steps(4, end); }

人気のベジェ曲線

/* バウンス */
.bounce { transition: all 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55); }

/* スムーズ */
.smooth { transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94); }

/* スナップ */
.snap { transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); }

CSS Animation

基本構文

@keyframes アニメーション名 {
  from { /* 開始状態 */ }
  to { /* 終了状態 */ }
}

/* または */
@keyframes アニメーション名 {
  0% { /* 開始 */ }
  50% { /* 中間 */ }
  100% { /* 終了 */ }
}

.element {
  animation: 名前 duration timing-function delay iteration-count direction fill-mode;
}

Animationプロパティ

プロパティ説明
animation-nameキーフレーム名必須
animation-duration時間必須
animation-timing-functionタイミングease
animation-delay遅延時間0s
animation-iteration-count繰り返し回数1, infinite
animation-direction方向normal, reverse, alternate
animation-fill-mode終了状態none, forwards, backwards, both
animation-play-state再生状態running, paused

実践アニメーション例

1. フェードイン

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.fade-in {
  animation: fadeIn 0.5s ease forwards;
}

/* 上からフェードイン */
@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in-down {
  animation: fadeInDown 0.5s ease forwards;
}

2. ローディングスピナー

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e5e7eb;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

3. パルス効果

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.pulse {
  animation: pulse 2s ease-in-out infinite;
}

/* パルスリング */
@keyframes pulseRing {
  0% {
    transform: scale(0.8);
    opacity: 1;
  }
  100% {
    transform: scale(2);
    opacity: 0;
  }
}

.pulse-ring {
  position: relative;
}

.pulse-ring::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid #3b82f6;
  border-radius: 50%;
  animation: pulseRing 1.5s ease-out infinite;
}

4. バウンス

@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
    animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
  }
  50% {
    transform: translateY(-25%);
    animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
  }
}

.bounce {
  animation: bounce 1s infinite;
}

5. シェイク(エラー)

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.shake {
  animation: shake 0.5s ease;
}

/* JavaScriptでトリガー */
/* element.classList.add('shake'); */

6. タイピング効果

@keyframes typing {
  from { width: 0; }
  to { width: 100%; }
}

@keyframes blink {
  50% { border-color: transparent; }
}

.typing {
  overflow: hidden;
  white-space: nowrap;
  border-right: 3px solid;
  width: 0;
  animation:
    typing 3s steps(30) forwards,
    blink 0.7s step-end infinite;
}

7. スケルトンローディング

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

.skeleton {
  background: linear-gradient(
    90deg,
    #f0f0f0 25%,
    #e0e0e0 50%,
    #f0f0f0 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

Transformと組み合わせる

Transformプロパティ

/* 移動 */
transform: translateX(100px);
transform: translateY(50px);
transform: translate(100px, 50px);

/* 回転 */
transform: rotate(45deg);
transform: rotateX(45deg); /* 3D */
transform: rotateY(45deg); /* 3D */

/* 拡大縮小 */
transform: scale(1.5);
transform: scaleX(2);

/* 傾き */
transform: skew(10deg);

/* 組み合わせ */
transform: translateX(100px) rotate(45deg) scale(1.2);

3D効果

/* 親要素にパースペクティブを設定 */
.perspective-container {
  perspective: 1000px;
}

/* カードフリップ */
.card-3d {
  transform-style: preserve-3d;
  transition: transform 0.6s;
}

.card-3d:hover {
  transform: rotateY(180deg);
}

.card-front, .card-back {
  backface-visibility: hidden;
}

.card-back {
  transform: rotateY(180deg);
}

パフォーマンス最適化

GPU加速プロパティ

/* ✅ GPU加速(パフォーマンス良好) */
transform: translateX(100px);
transform: scale(1.1);
transform: rotate(45deg);
opacity: 0.5;

/* ❌ CPU演算(リフロー発生) */
left: 100px;
width: 200px;
height: 200px;
margin: 10px;

will-change

/* アニメーション対象にヒント */
.animated {
  will-change: transform, opacity;
}

/* ホバー時のみ */
.card:hover {
  will-change: transform;
}

/* アニメーション後に削除推奨 */

リフローを避ける

/* ❌ 避けるべきパターン */
.bad {
  animation: move 1s infinite;
}
@keyframes move {
  to { left: 100px; } /* リフロー発生 */
}

/* ✅ 推奨パターン */
.good {
  animation: moveGood 1s infinite;
}
@keyframes moveGood {
  to { transform: translateX(100px); } /* GPU加速 */
}

アクセシビリティ

モーション軽減設定の尊重

/* ユーザーがモーション軽減を望む場合 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* または選択的に */
@media (prefers-reduced-motion: reduce) {
  .animated {
    animation: none;
  }

  .transition {
    transition: none;
  }
}

実践UIパターン

ボタンホバー

.button {
  background: #3b82f6;
  color: white;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.button:hover {
  background: #2563eb;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59,130,246,0.4);
}

.button:active {
  transform: translateY(0);
}

メニュードロップダウン

.dropdown {
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s ease;
}

.menu:hover .dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

モーダル開閉

.modal-overlay {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  transform: scale(0.9) translateY(20px);
  transition: transform 0.3s ease;
}

.modal-overlay.active .modal {
  transform: scale(1) translateY(0);
}

順次表示

.item {
  opacity: 0;
  transform: translateY(20px);
  animation: fadeInUp 0.5s ease forwards;
}

.item:nth-child(1) { animation-delay: 0.1s; }
.item:nth-child(2) { animation-delay: 0.2s; }
.item:nth-child(3) { animation-delay: 0.3s; }

@keyframes fadeInUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

FAQ

Q1: transitionが動作しない

A: 確認すること:

  • 変更されるプロパティがアニメーション可能か
  • display: noneからの遷移は動作しない
  • 開始値と終了値が明示されているか

Q2: アニメーション終了後の状態を維持するには?

A: animation-fill-mode: forwardsを使用

.element {
  animation: fadeIn 1s ease forwards;
}

Q3: パフォーマンスが悪い

A:

  • transformopacityのみアニメーション
  • will-changeを適切に使用
  • 多すぎる要素のアニメーションを避ける

Q4: CSSとJavaScriptアニメーション、どちらが良い?

A:

  • 単純な遷移: CSS
  • 複雑なシーケンス: JavaScript(GSAPなど)
  • ユーザー入力反応: JavaScript
  • 自動ループ: CSS

まとめ

CSSアニメーションの要点:

  1. Transition: 状態変化に反応
  2. Animation: 自動実行、キーフレーム
  3. Transform: GPU加速、優れたパフォーマンス
  4. タイミング: ease、cubic-bezier
  5. アクセシビリティ: prefers-reduced-motion を尊重

関連ツール

ツール用途
Animation ジェネレータキーフレーム生成
Transform ジェネレータ変換効果
フィルタージェネレータCSSフィルター
CSSanimationtransitionアニメーションUIインタラクション

著者について

Toolypet Team

Toolypet Team

Development Team

The Toolypet Team creates free, privacy-focused web tools for developers and designers. All tools run entirely in your browser with no data sent to servers.

Web DevelopmentCSS ToolsDeveloper ToolsSEOSecurity