animation-duration

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2015.

* Some parts of this feature may have varying levels of support.

animation-durationCSS のプロパティで、 1 回のアニメーション周期が完了するまでの再生時間を設定します。

試してみましょう

アニメーションのプロパティすべてを一度に設定するには、一括指定プロパティである animation プロパティを使用すると便利です。

構文

css
/* 単一のアニメーション */
animation-duration: auto; /* 既定値 */
animation-duration: 6s;
animation-duration: 120ms;

/* 複数のアニメーション */
animation-duration: 1.64s, 15.22s;
animation-duration: 10s, 35s, 230ms;

/* グローバル値 */
animation-duration: inherit;
animation-duration: initial;
animation-duration: revert;
animation-duration: revert-layer;
animation-duration: unset;

auto Experimental

時間ベースのアニメーションでは、 auto0s の値と等価です(下記参照)。 CSS スクロール駆動アニメーションでは、 auto はタイムライン全体をアニメーションで埋めます。

<time>

1 回のアニメーションの周期にかかる時間。この値は、秒 (s) またはミリ秒 (ms) で指定することができます。値は正の数か 0 でなければならず、単位は必須です。

値が指定されなかった場合、既定値である 0s が使用され、この場合でもアニメーションは実行されます(animationStartanimationEnd イベントが発生します)。長さが 0s のときにアニメーションが表示されるかどうかは、下記で説明する animation-fill-mode の値によります。

  • animation-fill-modebackwards または both に設定した場合、 animation-direction で定義したアニメーションの最初のフレームが animation-delay(/ja/docs/Web/CSS/animation-delay) のカウントダウン中に表示されます。
  • animation-fill-modeforwards または both に設定した場合、アニメーションの最後のフレームは animation-delay が経過した後に、 animation-direction で定義したように表示されます。
  • animation-fill-modenone に設定すると、アニメーションは目に見える効果はありません。

メモ: 負の数は無効であり、宣言が無視されます。一部、初期の接頭辞付きの実装は 0s と等価に解釈するかもしれません。

メモ: animation-* プロパティにカンマ区切りで複数の値を指定した場合、 animation-name に現れる順にアニメーションに適用されます。アニメーションの数と animation-* プロパティの値が一致しない場合は、複数のアニメーションプロパティ値の設定 を参照してください。

メモ: CSS スクロール駆動アニメーションを作成するとき、animation-duration の値を秒やミリ秒で指定することは実際には意味がありません。テストしたところ、スクロール進行タイムラインアニメーションには効果がないように見えましたが、ビュー進行タイムラインアニメーションでは、アニメーションがタイムラインの終わりに近づいて起こるようになるようでした。しかし、Firefox がアニメーションを正常に適用するには animation-duration の設定が要求されます。そのため、Firefoxでアニメーションが動作するように animation-duration1ms に設定することをお勧めします。

公式定義

初期値0s
適用対象すべての要素、::before / ::after 擬似要素
継承なし
計算値指定通り
アニメーションの種類アニメーション不可

形式文法

animation-duration = 
<time [0s,∞]>#

アニメーション時間の設定

これは animation-duration が 0.7 秒のアニメーションです。

HTML

html
<div class="box"></div>

CSS

css
.box {
  background-color: rebeccapurple;
  border-radius: 10px;
  width: 100px;
  height: 100px;
}

.box:hover {
  animation-name: rotate;
  animation-duration: 0.7s;
}

@keyframes rotate {
  0% {
    transform: rotate(0);
  }
  100% {
    transform: rotate(360deg);
  }
}

結果

矩形の上にカーソルを当てると、アニメーションを開始します。

他の例については、 CSS アニメーションを参照してください。

仕様書

Specification
CSS Animations Level 1
# animation-duration

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
animation-duration
auto value
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.
Requires a vendor prefix or different name for use.
Has more compatibility info.

関連情報