
How to Add AdSense Code to a Blogger Theme Without XML Errors (Parse HTML Explained)
You copy the AdSense code, open your Blogger theme, paste it in the head section, press Save, and Blogger answers with a red message that starts with "Error parsing XML", gives a line and column number, and then says: "Attribute name "async" associated with an element type "script" must be followed by the ' = ' character." Nothing is saved. You try again, maybe in a different place, and get the same message or a new one about an entity that "must end with the ';' delimiter".
It feels strange, because both AdSense and Blogger belong to Google, and the code came straight from your AdSense account. But the error is not random, and the fix is small once you understand what Blogger is checking.
In this guide I will explain why the Blogger theme editor rejects code that works on every other website, what each common error message means, how to make AdSense code safe for the theme (this is what people call "parsing" the code), and when you can skip the theme editor completely. I also built a free Parse HTML for Blogger tool while writing this, so you can convert your code in one tap instead of editing it by hand.
The Short Answer
Blogger themes are XML templates. XML has stricter rules than HTML, so some normal HTML in the AdSense code is not allowed. The main problem is the word async on its own. To fix it, write async="async" instead of async. If your code also has an ampersand in a link, an and-and operator in a script, a less-than sign in a script, or tags like br that are not closed, those need small changes too.
You have three options:
- Connect AdSense through the Earnings tab in Blogger, so you do not need to touch the theme at all.
- Paste the code in a Layout gadget (HTML/JavaScript), which accepts normal HTML.
- Paste an XML-safe version of the code in Theme, then Edit HTML, just above the closing head tag. The Parse HTML for Blogger tool creates that version for you.
The rest of this article explains each step and each error in detail, so you can fix it yourself and understand what you are changing.
FREE TOOL
Parse HTML for Blogger: fix AdSense code in one tap
Paste your code, tap Convert, copy the XML-safe result. It runs in your browser and nothing is uploaded.
Why Blogger Rejects Code That Works Everywhere Else
When a browser loads a normal web page, it reads the code as HTML. HTML is forgiving on purpose. You can write an attribute without a value, leave a br tag unclosed, or put an ampersand in the middle of a link, and the browser will still understand what you meant.
A Blogger theme is different. When you open Theme, then Edit HTML, you are editing an XML template. Blogger reads that template with an XML parser every time you save it, and only after that does it turn the template into the HTML pages your visitors see. If the template is not valid XML, Blogger cannot read it, so it refuses to save and shows "Error parsing XML" with a line and column number.

XML rules that matter for AdSense and similar code:
- Every attribute must have a value, in quotes. HTML allows async on its own. XML needs async="async".
- Every tag must be closed. HTML allows a plain br tag. XML needs the self-closing form with a slash.
- The ampersand is special. In XML it always starts an entity, such as the entity for the ampersand itself. A bare ampersand in a link breaks the file.
- The less-than sign is special. In XML it always starts a tag. A less-than sign inside JavaScript breaks the file unless the script is protected.
- Only five named entities exist: amp, lt, gt, quot and apos. HTML names like nbsp or copy are unknown to XML.
None of these rules change what the code does in the browser. They only change how the code has to be written inside the theme. That is why the fix is safe: the visitor's browser still receives working HTML.
What I tested
While building the Free Seo Lab tool, I wanted to see exactly which snippets break and why, instead of guessing from old forum posts. I ran the common snippets through a standard Java XML parser, which gives the same wording as the messages Blogger shows. These are the results:
- The AdSense Auto ads code (the loader script with async and crossorigin) failed on async.
- The AdSense display ad unit code, meaning the ins tag and the small push script, passed without any change. Only the loader line in front of it was a problem.
- The Google Analytics tag failed on async in the first line. The inline part of the tag passed.
- A link with an ampersand in the address failed with "The reference to entity "b" must end with the ';' delimiter."
- A script with an and-and operator failed with "The entity name must immediately follow the '&' in the entity reference."
- A script with a less-than comparison failed with "The content of elements must consist of well-formed character data or markup."
- A plain br tag and an nbsp entity each failed with their own message.
After converting each snippet with the tool, every one of them passed the same parser. I ran this both with CDATA wrapping turned on and turned off.
First Question: Do You Need to Edit the Theme at All?
Many Blogger users go straight to Edit HTML because a video told them to. Often that is not necessary. Blogger has two simpler routes, and both avoid XML errors completely.

Option 1: The Earnings tab
Blogger's own help page, Advertise on your blog, describes signing up for AdSense from the Blogger dashboard: select your blog, open Earnings and create or connect an AdSense account. When your blog is connected this way, Blogger knows your AdSense account and can handle the code for you.
Free Seo Lab is connected through the Earnings tab, and you can see the connection in the page source. Blogger's own data block on every page lists the AdSense client ID for the blog. I did not paste any AdSense loader into the theme for that.
Blogger Community answers from Product Experts make the same point: when your blog is connected and approved, you usually do not need to add any code, and you can choose Auto ads in the Earnings tab. If you go this route, adding a second copy of the Auto ads code by hand is not needed.
Option 2: Layout gadgets
In Layout, you can add an AdSense gadget once your account is connected, or an HTML/JavaScript gadget for code from AdSense or any other service. Blogger's help page explains both. The HTML/JavaScript gadget accepts normal HTML, so in most cases you can paste the code exactly as AdSense gives it to you. This is the best choice for an ad unit in the sidebar or between sections of your layout.
Option 3: Theme, Edit HTML
You need the theme editor when you want the code in a place that gadgets cannot reach. The most common case is the AdSense code itself. AdSense Help, on its page about where to place AdSense code, says to paste it between the opening and closing head tags of your site. In Blogger the head section only exists inside the theme. Other cases are ads inside the post template, custom scripts, or verification snippets that must sit in the head.
This is the only route where XML rules apply, and it is the one this guide is mainly about.
| Method | Where | XML errors possible? | Best for |
|---|---|---|---|
| Earnings tab | Blogger dashboard | No | Most Blogger users, Auto ads |
| HTML/JavaScript gadget | Layout | Rarely | Ad units in sidebar or layout sections |
| Edit HTML | Theme | Yes | Head code, ads inside the post template |
Before You Edit: Back Up Your Theme
This takes one minute and protects you from every possible mistake. In Blogger, open Theme, tap the small down arrow next to the Customize button, and choose Backup. Download the file and keep it on your phone or computer. If anything goes wrong after you save a change, the same menu has a Restore option where you can upload that file.
I always do this before touching a theme, even for a one-line change. A theme file with a missing tag can make the whole blog look broken, and the backup is the fastest way back.
Step by Step: Add the AdSense Code to the Blogger Theme
Here is the full process for the AdSense code, the snippet you need for Auto ads and for site verification.
Step 1: Copy the code from AdSense
According to AdSense Help, you sign in to AdSense, click Ads, click Get code, and then click Copy code snippet. For an ad unit, you go to Ads, then By ad unit, find the unit and click Get code. Copy the whole code exactly as it is shown. Do not type it by hand.
Step 2: Make the code XML-safe
Open the Parse HTML for Blogger tool, paste the code in the Your code box, leave the mode on Theme fix, and tap Convert. The tool shows the converted code and a short report. For the standard AdSense code, the report should say that it added a value to one attribute: async. The tool also runs an XML check in your browser and tells you whether the result is valid XML.
If you prefer to do it by hand, find the word async in the first line and change it to async="async". Leave everything else, including your publisher ID and crossorigin="anonymous", exactly as it is.
Step 3: Open the theme editor
In Blogger, go to Theme. Tap the down arrow next to Customize and choose Edit HTML. On a phone, the editor is small, so take your time. On a computer you can click inside the code and press Ctrl and F to search.
Step 4: Find the closing head tag
Search for the closing head tag. In most themes it appears once, near the top part of the file, after the skin and style section. Place your cursor at the start of that line.
Step 5: Paste and save
Paste the converted code on a new line just above the closing head tag. Then tap the Save icon. If the code is XML-safe, Blogger saves without any message, and you can confirm the code is live with the check later in this article. If you still get an error, read the line and column number in the message, and look at the error table below.
The Common Errors, One by One
These are the messages you are most likely to see. Blogger puts "Error parsing XML, line X, column Y:" in front of each one. The line and column tell you where in the theme the parser stopped, which is usually exactly where you pasted the code.

Attribute name "async" ... must be followed by the ' = ' character
This is the one almost everyone sees with AdSense. The loader script uses async with no value. In XML every attribute needs a value, so the parser expects an equals sign after async and does not find one.
Fix: write async="async". Browsers treat async="async" exactly like async, so the script still loads in the background without blocking your page. The same problem and the same fix apply to defer and to other attributes without values, such as checked on a checkbox. The Google Analytics tag has the same async issue in its first line.
The reference to entity "b" must end with the ';' delimiter
This message confuses people because the word in quotes looks random. It is not. The parser saw an ampersand and expected an entity name followed by a semicolon. It read the text right after the ampersand, for example "b" from a link like page?a=1 followed by an ampersand and b=2, and then found an equals sign instead of a semicolon.
So the word in the message is simply whatever follows the ampersand in your code. If you see utm_source, the problem is in a tracking link. If you see a JavaScript variable name, the problem is inside a script.
Fix: inside a link or any other attribute, replace the ampersand with the XML entity for an ampersand (amp with an ampersand in front and a semicolon after). When Blogger outputs the page, the browser reads it back as a normal ampersand, so the link still works. Inside a script, wrap the script in CDATA instead. The tool does both automatically.
The current AdSense code does not contain an ampersand, so if you see this error after pasting AdSense code, look at what else is on the same line. Often it is a different script or a link that was pasted at the same time.
The entity name must immediately follow the '&' in the entity reference
This is the same problem in a different form. The parser found an ampersand followed by something that cannot start an entity name, such as a space or a second ampersand. In practice it almost always means a JavaScript and-and operator inside a script, like a check that two things are true.
Fix: wrap the script in CDATA. Do not try to replace each ampersand in a long script by hand. It is easy to miss one, and the script becomes hard to read.
The content of elements must consist of well-formed character data or markup
The parser found a less-than sign and expected a tag name after it, but found something else, like a space or a number. In scripts this usually comes from a comparison such as checking whether the screen width is less than 768.
Fix: wrap the script in CDATA.
The element type "br" must be terminated by the matching end-tag
HTML lets you write a br tag without closing it. XML expects every tag to be closed, so it keeps looking for a closing br tag and fails when it reaches the end of the parent element. The same applies to img, hr, input, meta and link tags.
Fix: use the self-closing form, with a space and a slash before the end of the tag.
The entity "nbsp" was referenced, but not declared
The non-breaking space entity and similar names, like copy for the copyright sign, exist in HTML but not in plain XML. The parser does not know what they mean.
Fix: use the numeric form of the same character. For nbsp that is 160, written as an ampersand, a hash sign, 160 and a semicolon. The tool converts the most common named entities for you.
Open quote is expected for attribute "class"
This appears when an attribute value has no quotes, like class=note. HTML allows it for simple values. XML does not.
Fix: put the value in quotes.
What "Parse HTML" Actually Means
If you search for help with Blogger code, you will see the phrase "parse HTML" or "parse your code before adding it" again and again. It is used for two different things, and mixing them up causes a lot of confusion.
Meaning 1: Escape code so it shows as text
The classic meaning is to replace every special character with an entity: the less-than sign, the greater-than sign, the ampersand and sometimes quotes. The result is code that the browser displays as text instead of running it. Bloggers who write tutorials use this to show code inside a post.
Many older Blogger tutorials also told people to fully parse the AdSense code before placing it inside the post template in the theme. That approach turns the whole code into entities and depends on how the template outputs it, which makes it hard to read and easy to break.
Meaning 2: Make the code valid XML
The second meaning, and the one you need for the head section, is to change only what XML does not allow: give async a value, close empty tags, escape bare ampersands in attributes and protect scripts with CDATA. The code stays readable and keeps working exactly as before.
The Free Seo Lab tool has a separate mode for each. Theme fix is meaning 2. Parse is meaning 1. There is also Unparse, which reverses meaning 1, for the times you copy code from a tutorial and get entities instead of real tags.
| You want to | Use | Result |
|---|---|---|
| Add AdSense or a script to the theme | Theme fix | Readable code that passes the XML check |
| Show code to readers in a post | Parse | Code displayed as text |
| Turn parsed code back into normal code | Unparse | Real tags again |
CDATA Explained Simply
CDATA stands for character data. It is a standard XML feature that tells the parser: everything between these markers is plain text, do not look for tags or entities inside it. That is exactly what a script needs, because JavaScript is full of characters that look like XML markup.
The opening marker is a less-than sign, an exclamation mark and the word CDATA in square brackets. The closing marker is two closing square brackets followed by a greater-than sign. If you put these markers inside a script directly, the browser would try to run them as JavaScript and fail. That is why Blogger themes write them after two slashes, which makes them JavaScript comments. The XML parser sees CDATA, the browser sees comments, and both are happy.

You do not need CDATA for every script. The small AdSense push script that comes with an ad unit contains no ampersand and no less-than sign, so it is already valid XML, and my tests confirmed that. CDATA matters for longer scripts, such as a custom script from a tutorial, a lazy-loading snippet or code from another ad network. The tool only wraps a script in CDATA when the script contains one of those risky characters, and it leaves scripts that already have CDATA alone.
Adding an Ad Unit Inside Your Posts Through the Theme
Some bloggers want an ad in a fixed place in every post, for example right after the post title. That means editing the post template inside the theme, and it is more advanced than adding head code.
If you do this, remember two things from my tests. First, the ad unit code itself, meaning the ins tag and the push script, was already valid XML. Second, the loader line in front of it has async without a value, so it needs the Theme fix like the Auto ads code. Running the whole ad unit code through Theme fix handles both in one step.
Where exactly to paste it depends on your theme, because every template organizes the post area differently. Back up the theme first, make one change at a time, and check a post on both phone and computer after each save. If you are not comfortable with theme code, Auto ads or an HTML/JavaScript gadget are simpler and safer choices for a beginner.
Is It Allowed to Change the AdSense Code?
This is a fair question, because AdSense has rules about code modifications. AdSense Help has a page called Modifications of AdSense ad code. It says the program policies do not permit any alteration to AdSense code that artificially inflates ad performance or harms advertiser conversions, and it recommends copying and pasting the ad code in general. It also lists techniques to avoid, such as hiding ad units or making ads cover content.
Writing async as async="async" does none of those things. It does not change which script loads, how ads are chosen, where they appear or how users interact with them. It only changes how the same instruction is written so that Blogger's XML parser can read it. Wrapping a script in CDATA inside JavaScript comments is the same kind of change.
What you should never change:
- The publisher ID, the ca-pub number.
- The ad slot number of an ad unit.
- The script address.
- The ad format and size settings, unless AdSense itself gives you the option.
If you are ever unsure, the safest path is the Earnings tab or a Layout gadget, where you paste the code exactly as AdSense gives it.
Using the Free Parse HTML for Blogger Tool
I built the Parse HTML for Blogger tool because the existing tools I found either did only the old escaping or were hard to use on a phone. This one is made for beginners, and it works fully in your browser, so your code is never uploaded.
How to use it:
- Paste your code in the Your code box, or tap Sample to load an example.
- Keep Theme fix selected for anything that goes into Edit HTML. Choose Parse if you want to show code in a post, or Unparse to decode parsed code.
- Tap Convert. Read the report under the result. It lists every change, such as values added to attributes, ampersands escaped, tags closed or scripts wrapped in CDATA.
- Look at the XML check. Green means the result passed an XML check in your browser. If your original code failed, the report shows the error it would have caused.
- Tap Copy result and paste it in Blogger.
If you work on other parts of your blog setup, the Free SEO Tools for Bloggers page lists all the other free tools on Free Seo Lab, including the Meta Tag Generator and the Schema Markup Generator.
After You Save: How to Check It Worked
Saving without an error only proves the theme is valid XML. It does not prove the code is on the page or that ads will show. Here is the check I use.

- The theme saved. No red message appeared, and the editor did not jump back to an error line.
- The code is in the page source. Open your blog, view the page source and search for adsbygoogle.js. You should find it with your own ca-pub number. If you used the Earnings tab instead, search for your ca-pub number.
- Only one publisher ID. If you find two different ca-pub numbers, you probably pasted code from a different AdSense account, or an old snippet is still in the theme or a gadget. Remove the one that does not belong to your account. Blogger Community experts point out that code from an account other than the one linked in the Earnings tab causes problems.
- No duplicate code. If Blogger already adds the code through the Earnings tab, a second copy in the theme is not needed. Search the theme and your HTML/JavaScript gadgets for adsbygoogle and remove extra copies you added by hand.
- The site status in AdSense. Ads only show when AdSense has approved your site. In AdSense, open Sites. "Getting ready" means the review is still running. Code on the page does not speed this up, and there is nothing else to do except keep publishing helpful posts.
If you added AdSense manually instead of through the Earnings tab, also check the ads.txt file. Blogger's help page says that if you manually integrated AdSense, you need to set up the ads.txt content yourself, under Settings, Monetization, Enable custom ads.txt.
Mistakes to Avoid
These are the mistakes I see most often in questions about Blogger and AdSense code.
- Pasting inside the skin or style section. The b:skin part of the theme holds CSS. A script pasted inside it will not run, and the CSS may break. Paste above the closing head tag, outside other sections.
- Pasting inside another script. If you paste in the middle of an existing script, you break both. Always start a new line between complete tags.
- Removing async instead of fixing it. Some people delete async to make the error go away. The theme saves, but the script then loads in a way that can slow your page. Write async="async" instead.
- Using smart quotes. If you copy code through a word processor or some chat apps, straight quotes can turn into curly ones. XML does not accept curly quotes around attribute values. Copy from AdSense directly, or paste through the tool, which will show an XML error if something like this slipped in.
- Editing the live theme without a backup. It only takes one wrong paste to break the layout. The Backup option is right there in the same menu.
A Note on Old Tutorials
Many articles on this topic are years old, and the AdSense code they show may not match what your account gives you today. Trust your account. The XML rules, on the other hand, have not changed. Async needs a value, ampersands need escaping, scripts with risky characters need CDATA, and empty tags need closing. That is why a tool that applies those rules to whatever code you paste will keep working even when the code itself changes.
For other Blogger settings that beginners often get wrong, I have separate guides on custom robots header tags in Blogger, the Discovered - currently not indexed status and the Alternate page with proper canonical tag status in Search Console.
Getting Ready for AdSense Approval
Adding the code correctly is only one part of AdSense. The bigger part is the site itself. Google does not publish a minimum number of posts or words for approval, but your blog needs enough original, useful content, clear navigation and the basic pages people expect, like About, Contact and Privacy Policy.
I wrote about this in detail in how many blog posts you need before launching a blog and before applying for AdSense, and in the guide on how many words you need for AdSense approval, which also covers the free word counter tool. If your theme or settings have technical problems, the technical SEO checklist for beginners is a good place to start.
Frequently Asked Questions
Why does Blogger say "Error parsing XML" when I add AdSense code?
Because the Blogger theme is an XML template, and the AdSense code is written for HTML. The usual cause is the word async without a value. Change it to async="async", or run the code through the Parse HTML for Blogger tool with Theme fix selected.
Where should I paste the AdSense code in Blogger?
AdSense Help says to paste it between the opening and closing head tags. In Blogger, that means Theme, then Edit HTML, on a new line just above the closing head tag. If your blog is connected through the Earnings tab, you may not need to paste it at all.
What does "The reference to entity must end with the ';' delimiter" mean?
It means the parser found an ampersand that is not part of a valid entity. The word in the message is the text right after the ampersand. Escape the ampersand in links, or wrap the script in CDATA if it is inside JavaScript.
Do I need to parse the AdSense code for an HTML/JavaScript gadget?
Usually not. The gadget accepts normal HTML. Paste the original code first, and only convert it if Blogger shows an error.
What is CDATA in Blogger themes?
It is a standard XML marker that tells the parser to treat a block of text as plain characters. In themes it is written inside JavaScript comments, so the browser ignores it and the script runs normally.
Will editing the AdSense code get my account banned?
Changing how the code is written so Blogger can save it does not change how ads are served, so it is not the kind of modification the AdSense code modification page warns about. Do not change the publisher ID, slot number, script address or ad behavior. If you want to avoid any doubt, use the Earnings tab or a Layout gadget.
Why are ads not showing after I added the code?
Most often because the site is not approved yet. Check Sites in AdSense. If it says Getting ready, the review is still running. Also check that the code with your own ca-pub number is in the page source and that you did not add code from a different account.
Final Thoughts
The "Error parsing XML" message looks scary, but it is Blogger protecting your theme from code it cannot read. In almost every AdSense case the fix is one word: async becomes async="async". Other snippets may need an escaped ampersand, a closed tag or a CDATA wrapper, and each error message tells you which one if you know how to read it.
Start with the simplest route. If the Earnings tab or a Layout gadget can do the job, use it. If you need the theme, back it up, convert the code with the Parse HTML for Blogger tool, paste it above the closing head tag, and check the page source after you save. Then go back to what actually gets a blog approved and read: writing helpful posts.
Free Seo Lab is an independent blog and is not affiliated with Google, Blogger or AdSense. The steps in this article are based on the AdSense Help and Blogger Help pages available at the time of writing and on the XML tests described above. Menus and code can change, so always follow what your own AdSense account shows.