JavaScript Document timeline Property

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance property

What You’ll Learn

Document.timeline is a read-only instance property that returns the document’s default DocumentTimeline for the Web Animations API. Learn currentTime, Performance.timeOrigin, inactive null states, and five examples with try-it labs.

01

Kind

Read-only property

02

Returns

DocumentTimeline

03

Time base

timeOrigin

04

API

Web Animations

05

Inactive

currentTime null

06

Status

Baseline widely

Introduction

CSS transitions and the Web Animations API need a shared clock so animations stay in sync. Every document has one default timeline that tracks elapsed time since the page’s performance time origin.

MDN: the timeline read-only property represents the default timeline of the current document. This timeline is a special instance of DocumentTimeline. It is unique to each document and persists for the lifetime of the document, including calls to Document.open().

💡
Milliseconds since time origin

MDN: the timeline expresses time in milliseconds since Performance.timeOrigin. Before the time origin it is inactive and currentTime is null.

Related Document tutorials: readyState, prerendering, hidden, Document constructor.

Understanding Document.timeline

A read-only instance property from the Web Animations spec.

  • ValueDocumentTimeline object (MDN).
  • Scope — one default timeline per document; survives document.open() (MDN).
  • currentTime — ms since Performance.timeOrigin when active (MDN).
  • InactivecurrentTime is null before time origin or on non-active documents (MDN).
  • Status — Baseline Widely available (since July 2020, MDN).

📝 Syntax

JavaScript
document.timeline

Value

A DocumentTimeline object (MDN).

Read currentTime

JavaScript
const time = document.timeline.currentTime;
console.log("Document timeline (ms):", time);

⚡ Quick Reference

GoalCode / note
Get timelinedocument.timeline
Read clockdocument.timeline.currentTime
Check activecurrentTime !== null
Time originperformance.timeOrigin
High-res nowperformance.now()
Animate elementelement.animate(keyframes, options)

🔍 At a Glance

Four facts about document.timeline.

Type
DocumentTimeline

Read-only

Clock
currentTime

ms

Origin
timeOrigin

MDN

Status
Baseline

Since 2020

📋 timeline.currentTime vs performance.now()

document.timeline.currentTimeperformance.now()
Spec areaWeb AnimationsPerformance API
UnitMillisecondsMilliseconds
When inactivenull (MDN)Always a number in active documents
Animation syncYes — default timelineGeneral timing, not animation root

Examples Gallery

Examples follow MDN Document: timeline. Each includes a try-it lab you can run in the browser.

📚 Getting Started

Access the document’s default timeline.

Example 1 — Read document.timeline

Confirm the property returns a DocumentTimeline.

JavaScript
const tl = document.timeline;
console.log(tl.constructor.name); // "DocumentTimeline"
Try It Yourself

How It Works

Every active document exposes exactly one default timeline object.

Example 2 — Read currentTime

Log elapsed milliseconds on the document clock (MDN).

JavaScript
const ms = document.timeline.currentTime;
console.log("Timeline ms:", ms);
Try It Yourself

How It Works

On a live page after the time origin, currentTime is a non-null number.

📈 Time Origin, Animations & Safety

Connect timeline to performance and Web Animations.

Example 3 — Compare with performance.timeOrigin

Show the epoch anchor MDN references.

JavaScript
console.log({
  timeOrigin: performance.timeOrigin,
  timelineNow: document.timeline.currentTime,
  performanceNow: performance.now()
});
Try It Yourself

How It Works

timeline.currentTime and performance.now() both measure ms since the same origin on active pages.

Example 4 — Animate Using the Default Timeline

element.animate() uses the document timeline unless you pass another.

JavaScript
const box = document.querySelector(".box");
const anim = box.animate(
  [{ opacity: 0 }, { opacity: 1 }],
  { duration: 1000, fill: "forwards" }
);

console.log("Animation timeline:", anim.timeline === document.timeline);
Try It Yourself

How It Works

Web Animations share document.timeline so effects stay synchronized.

Example 5 — Guard When Timeline Is Inactive

MDN: currentTime can be null on inactive documents.

JavaScript
function getTimelineMs() {
  const t = document.timeline.currentTime;
  if (t === null) {
    return "Timeline inactive (currentTime is null)";
  }
  return `Active at ${t} ms`;
}

console.log(getTimelineMs());
Try It Yourself

How It Works

Always check for null when writing code that may run on detached or not-yet-active documents.

🚀 Common Use Cases

  • Web Animations — default clock for element.animate().
  • Animation debugging — log currentTime when effects desync.
  • Custom timelines — compare against document default before overriding.
  • Performance correlation — relate animations to performance.now().
  • SPA navigation — understand timeline persistence after document.open().
  • Teaching WAAPI — explain where animation time comes from.

🧠 How document.timeline Works

1

Browser sets time origin

performance.timeOrigin marks when the document clock starts.

Performance
2

Document exposes timeline

One DocumentTimeline per document (MDN).

Property
3

Animations attach to the clock

element.animate() uses this timeline by default.

WAAPI
4

Read currentTime

Milliseconds since origin — or null when inactive (MDN).

📝 Notes

  • MDN: Baseline Widely available (since July 2020) — no Deprecated / Experimental / Non-standard banner.
  • Timeline persists across document.open() for the same document (MDN).
  • Before time origin or on non-active documents, currentTime is null (MDN).
  • Prefer element.animate() or CSS animations for effects; timeline is the underlying clock.
  • Related: readyState, hidden, Document constructor.

Browser Support

Document.timeline is marked Baseline Widely available on MDN (since July 2020). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline · Widely available

Document.timeline

Read-only DocumentTimeline — default Web Animations clock with currentTime since timeOrigin.

Widely Available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer Not supported
No support
Document.timeline Baseline support

Bottom line: Use document.timeline to inspect the default animation clock. Pair with element.animate() and performance.now() for timing and debugging.

Conclusion

Document.timeline is the default DocumentTimeline for Web Animations on a page. Read currentTime for milliseconds since Performance.timeOrigin, guard for null on inactive documents, and use it to understand how element.animate() stays synchronized.

Continue with title, ownerDocument, readyState, styleSheets, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Check currentTime !== null before using the clock
  • Use element.animate() for WAAPI effects
  • Compare with performance.now() when debugging
  • Remember one timeline per document (MDN)
  • Prefer CSS animations for simple visual effects

❌ Don’t

  • Assign to document.timeline (read-only)
  • Assume currentTime is never null
  • Confuse timeline with document.readyState
  • Expect IE support for Web Animations timeline
  • Replace requestAnimationFrame with timeline reads for every frame

Key Takeaways

Knowledge Unlocked

Five things to remember about document.timeline

Default Web Animations clock for the document.

5
Core concepts
🕑02

Clock

currentTime

ms
🎯03

Origin

timeOrigin

MDN
🎬04

WAAPI

animate()

Sync
05

Status

Baseline

2020+

❓ Frequently Asked Questions

A read-only DocumentTimeline object representing the default timeline of the current document (MDN). It is used by the Web Animations API.
No. MDN marks Document.timeline as Baseline Widely available (since July 2020). It is part of the Web Animations specification.
MDN: milliseconds since Performance.timeOrigin. Before the time origin the timeline is inactive and currentTime is null.
Yes. MDN: the timeline is unique to each document and persists for the lifetime of the document, including calls to Document.open().
Animations on elements use document timelines by default. document.timeline is the root DocumentTimeline for the page.
MDN: before the time origin, or when the document is non-active (not associated with a Window, for example).
Did you know?

MDN states that the document timeline is unique to each document and persists for the entire lifetime of that document—even when you call document.open() to replace its contents. The same timeline object keeps ticking.

Next: title

Learn how to read and set the page title for browser tabs and bookmarks.

title →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful