AdSense Code Generator

Generate Google AdSense ad unit code.

In AdSense, open Account, then Settings, then Account information.

Create a unit under Ads, then By ad unit, and copy its number.

Ad type
Options
 

    
Your ads.txt line

      

Save it in a file named ads.txt at the root of your site, for example example.com/ads.txt.

Use this tool on EWD Labs

This copy of the tool can't run here. Open the original, free version instead.

Open AdSense Code Generator

Runs in your browser. Nothing you type is uploaded.

How to use the AdSense code generator

  1. Type your publisher ID. It starts with pub- and has 16 digits.
  2. Pick an ad type. For anything except Auto ads, create a matching ad unit in AdSense and type its ad unit ID.
  3. Copy the code and paste it into your page where the ad should appear.
  4. Copy the ads.txt line into a file called ads.txt at the root of your website, so advertisers know your ads are genuine.

Which ad type to choose

  • Responsive display: fits any screen. The best choice for most pages.
  • Fixed size: always the same size, such as 300 × 250. Use it only where the space can't change.
  • In-article: sits between paragraphs of an article.
  • In-feed: sits inside lists of posts or products. AdSense gives you a layout key for each in-feed unit.
  • Multiplex: a grid of ads that looks like recommended content, usually at the end of an article.
  • Auto ads: one line in the head of every page, and Google places the ads for you.

You only need the script line once per page, even if you show several ads. Keep ads clear of buttons so people don't click them by mistake, which AdSense policies don't allow.

The code follows Google's published ad tag format (AdSense ad tags), checked December 2026. This tool is not made by or connected with Google.

Frequently asked questions

Where do I find my AdSense publisher ID?

Sign in to AdSense and open Account, then Settings, then Account information. It starts with pub- and has 16 digits.

Do I need to add the AdSense script for every ad?

No. The script line is needed once per page. Untick Include the AdSense script line for the second and later ads on the same page.

What is ads.txt and do I need it?

ads.txt is a small file at the root of your website that lists who can sell ads on it. AdSense recommends it, and missing it can lower your earnings.

Is this an official Google tool?

No. It builds the same code format Google publishes, but it is not made by or connected with Google.