How Do I Center an Ad Unit on a Page Using Google Ad Manager HTML Ad Tag Code?

How Do I Center an Ad Unit on a Page Using Google Ad Manager HTML Ad Tag Code?

How Do I Center an Ad Unit on a Page Using Google Ad Manager HTML Ad Tag Code?

Info Note: This article relates to Google Ad Manager HTML ad tag code.

By default, when you add an ad unit to your website, it is left-aligned. To center your ad unit on the page, wrap your ad code in a <div> that uses CSS Flexbox to center its contents.

Step-by-Step Instructions

  1. Wrap your ad code with the following HTML:
    <div style="display:flex;justify-content:center;">
      <!-- AD CODE GOES HERE -->
    </div>

Replace <!-- AD CODE GOES HERE --> with your actual ad code.

Example

Here is an example of how your final code might look:

<div style="display:flex;justify-content:center;">
  <div id='div-gpt-ad-1602686592219-0' style='width: 300px; height: 250px;'>
    <script>
      googletag.cmd.push(function() { googletag.display('div-gpt-ad-1602686592219-0'); });
    </script>
  </div>
</div>

This will ensure your ad unit is centered on the page.