> [!NOTE]
> We recommend the built-in countdown timer the HTML5 IMA SDK provides using [UIElements](https://developers.google.com/interactive-media-ads/docs/sdks/html5/client-side/reference/namespace/google.ima.md.txt#google.ima.UiElements) . If you'd still like to implement your own, follow these steps.

This guide walks you through adding a countdown timer to an HTML5 IMA SDK implementation.

## Prerequisites

This guide assumes that you have a working HTML5 IMA SDK implementation. If you don't,
refer to [Set up the IMA SDK](https://developers.google.com/interactive-media-ads/docs/sdks/html5).

## Create the timer

Adding a countdown timer to your IMA-enabled video player only requires
adding a few lines of JavaScript to poll the `remainingTime` property
of the `AdsManager` instance. We use the `setInterval()` method to
call a function every second to check `adsManager.remainingTime`.

```
// Global countdown timer
var countdownTimer;
...
function onAdsManagerLoaded(adsManagerLoadedEvent) {
  adsManager = adsManagerLoadedEvent.getAdsManager(
      videoElement);
  ...
  adsManager.addEventListener(
      google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED,
      onContentResumeRequested);
  adsManager.addEventListener(
      google.ima.AdEvent.Type.STARTED,
      onAdsStarted);
}
...
function onAdsStarted(adEvent) {
  countdownTimer = setInterval(function() {
    var timeRemaining = adsManager.getRemainingTime();
    // Update UI with timeRemaining
  }, 1000);
}
...
function onContentResumeRequested(adEvent) {
  ...
  if (countdownTimer) {
    clearInterval(countdownTimer);
  }
}
  
```

## Try it out

See this functioning implementation.
<iframe height="487" scrolling="no" src="//codepen.io/imasdk/embed/WQYZzK/?height=487&amp;theme-id=0&amp;default-tab=js" frameborder="no" allowtransparency="true" allowfullscreen="true" style="width: 100%;">See the Pen <a href='http://codepen.io/imasdk/pen/WQYZzK/'>WQYZzK</a> by IMA SDK (<a href='http://codepen.io/imasdk'>@imasdk</a>) on <a href='http://codepen.io'>CodePen</a>.
</iframe>