How to use the AdSense code generator
- Type your publisher ID. It starts with
pub-and has 16 digits. - Pick an ad type. For anything except Auto ads, create a matching ad unit in AdSense and type its ad unit ID.
- Copy the code and paste it into your page where the ad should appear.
- Copy the ads.txt line into a file called
ads.txtat 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.