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 This article relates to Google Ad Manager HTML Ad Tag Code.

By default, when you add an ad unit to your website, it will be left-aligned. To center your ad unit on the page, you can wrap your ad code with a <div> that uses CSS Flexbox to center its contents. Follow the steps below:

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.