Favorites

DOM Window.setInterval() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Window.setInterval()
DOM Window MethodThis method is supported by all modern browsers.
Updated 28th November 2026

The setInterval() method runs a function repeatedly, with a fixed delay between each run, until it is stopped with clearInterval().

Description

The setInterval() method calls a function repeatedly, waiting the given delay between calls, until clearInterval() is called with its ID. Browsers slow intervals down in background tabs. If each run might take longer than the delay, or you need a varying delay, a chain of setTimeout() calls is more reliable. For animation, use requestAnimationFrame().

The callback is first called after one delay has passed, not immediately; call your function once yourself before starting the interval if it should run straight away. Intervals keep running until cleared, even if the elements they update have been removed, so always keep the ID and clear it when finished.

Browsers enforce a minimum delay of a few milliseconds, and nested or background-tab timers can be slowed to once per second or less to save power, so intervals aren't suitable for precise timing. For clocks, base the display on Date.now() rather than counting ticks.

Syntax

setInterval(callback, delay)
setInterval(callback, delay, arg1, arg2, ...)

Parameters

  • callbackThe function to run repeatedly.
  • delayThe time between runs, in milliseconds.
  • arg1, arg2, ...Optional. Arguments passed to the callback.

Return Value

A positive integer interval ID, which can be passed to clearInterval().

Example

let n = 3;
const id = setInterval(() => {
  console.log(n);
  if (--n === 0) {
    clearInterval(id);
    console.log('Lift off!');
  }
}, 400);

Browser Support

The following information will show you the current browser support for the Window.setInterval() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee