Technical SEO

What does Google do with hreflang that is only in the source code?

An experiment on searchviu.com shows which version of a page Google reads for hreflang.

Source codehreflang="de"hreflang="en"RenderedGoogle reads the right side
Eoghan HennFirst published: July 13, 2017Last updated: October 15, 20267 min read
Experiment from 2017

The method and results come from our test in July 2017. The section What has changed since then? describes where Google stands today.

In short
  • Today Google names three ways to declare hreflang: the HTML head, the HTTP header and the XML sitemap. JavaScript does not appear in Google's hreflang documentation. According to Google, indexing is based on the rendered HTML.
  • In 2017 we wanted to know whether Google reads hreflang from the source code or from the rendered HTML. On searchviu.com, the hreflang tags stayed in the source code, and a script in Google Tag Manager removed them again during rendering.
  • Shortly afterwards, google.de showed the English homepage directly below the German one. After about two weeks, the number of hreflang tags in Search Console dropped.

The question behind the test

Every page that uses JavaScript has two versions. The source code is the HTML the server delivers. You see it in the browser via “View page source”. The rendered HTML only exists once the browser has executed the scripts. You see it in the developer tools under “Inspect”. Specialists also speak of pre-DOM and post-DOM.

Usually both versions match when it comes to SEO tags. In July 2017 we wanted to know what Google does when they contradict each other. We tested this using hreflang as an example. The trigger was a second test in which we wanted to set hreflang anew with Google Tag Manager. It is described in the guide hreflang with Google Tag Manager.

Experiment setup

We tested on our own website, searchviu.com. At the time it ran on WordPress, and the Polylang plugin set the hreflang tags automatically. There was no quick way to switch them off in the plugin. So we removed them during rendering with Google Tag Manager. A custom HTML tag with a short script deletes all link elements with an hreflang attribute from the DOM. The idea came from a tutorial by Sam Nemzer on Moz. This is what such a script looks like.

// Custom HTML tag in Google Tag Manager, trigger: all pages <script> document.querySelectorAll('link[rel="alternate"][hreflang]') .forEach(function (el) { el.parentNode.removeChild(el); }); </script>

This created a contradiction. The source code contained the complete hreflang tags, the rendered HTML did not.

Source code (pre-DOM)Rendered HTML (post-DOM)
Where you see itView page sourceDeveloper tools, Inspect
hreflang tags in the testpresentremoved
Who creates itServerBrowser after executing JavaScript

How did Google react?

Before the test, google.de only showed the German homepage for a search for searchVIU. Shortly after the change in Tag Manager, the English root URL with an English snippet appeared in position 2, directly below the German homepage. That is exactly what hreflang prevents when it works.

As a second piece of evidence, we watched the hreflang report in Search Console. For about two weeks nothing happened there. Then the number of detected hreflang tags dropped. At the time we only recorded the exact number as a screenshot.

Timeline
  1. July 2017. hreflang removed from the rendered HTML via Tag Manager.
  2. Shortly afterwards. The English homepage appears in position 2 on google.de.
  3. After about two weeks. Search Console counts fewer hreflang tags.

Our conclusion

For hreflang, Google used the rendered HTML in this test and ignored the tags in the source code. In hindsight, this did not surprise us much. If Google can read two versions with contradictory information, it has to choose one. The rendered HTML shows what a user also sees.

The test has limits. It ran on a single website, essentially on the homepage. There was no control group. You will find the follow-up tests with more pages in the guides JavaScript SEO experiments with Google Tag Manager and Canonical via JavaScript. They point in the same direction.

What has changed since then?

Since May 2019, Googlebot has rendered with a current version of Chromium and updates it regularly. Google's JavaScript SEO documentation describes three phases: crawling, rendering and indexing. Every page with status 200 goes into the render queue and, after rendering, is indexed based on the rendered HTML. That fits our result from 2017.

For hreflang, Google still names three ways: the HTML head, the HTTP header and the XML sitemap. JavaScript does not appear in this documentation. The “International Targeting” report with hreflang errors no longer exists in Search Console. According to its own help pages, Google still uses hreflang, though. There is also a new point. According to an analysis by Vercel from December 2024, the crawlers of ChatGPT, Claude and Perplexity do not execute JavaScript. There is more on this in the guide AI crawlers.

We have not repeated the test itself. So we do not know from our own measurement how Google resolves such a contradiction today.

What does this mean for your website?

  1. Set hreflang in the source code, in the HTTP header or in the sitemap. That way the tag is there before any script runs.
  2. Check whether scripts, consent tools or Tag Manager tags change the head afterwards.
  3. Compare the source code and the rendered HTML. The following script counts the hreflang tags in both versions.
// Run in the browser console. Counts hreflang in the source code and in the DOM. (async () => { const raw = await (await fetch(location.href)).text(); const src = new DOMParser().parseFromString(raw, 'text/html'); const sel = 'link[rel="alternate"][hreflang]'; console.table({ source: src.querySelectorAll(sel).length, rendered: document.querySelectorAll(sel).length }); })();

If the numbers differ, a script is changing your hreflang tags. How to set up and check hreflang in general is covered in the guide hreflang.

Common mistakes

  • A script in Tag Manager removes head elements that are correct in the source code.
  • hreflang is only set via JavaScript. AI crawlers without rendering then do not see the language versions.
  • Only the source code is checked, for example with a crawler without rendering.
  • Results are evaluated too soon after a change. In the test it took about two weeks before the first movement in Search Console.

FAQ

Does Google read hreflang from the rendered HTML?

In our 2017 test, yes. Google ignored hreflang tags that were only in the source code and were removed during rendering. According to its documentation, Google renders every page with status 200 and indexes based on the rendered HTML. For hreflang itself, Google does not document JavaScript.

Can I set hreflang with JavaScript or Google Tag Manager?

Our follow-up test suggests that it works. In its documentation, however, Google only names the HTML head, HTTP header and XML sitemap. For AI crawlers without rendering, hreflang set via JavaScript is missing.

What is the difference between pre-DOM and post-DOM?

Pre-DOM is the source code the server delivers. Post-DOM is the HTML after the browser has executed the scripts.

Where can I see hreflang errors now that the report is gone from Search Console?

With a crawl that compares the source code and the rendered HTML, and with the URL Inspection tool in Search Console for individual URLs.

How long does it take for Google to notice an hreflang change?

In the test, search showed the effects quickly, while Search Console reacted after about two weeks. This is a single observation from 2017.

In the weekly full crawl, searchVIU renders every page with Google Chrome and stores the source code and the rendered HTML. For every URL you see whether hreflang looks different after rendering than in the source code. The hreflang topic report shows what has changed since the last crawl. Find out more on the International websites page.

Request a demo

Sources

Retrieved on October 15, 2026. If something is out of date or missing, let us know.

  1. Google Search Central Blog, The new evergreen Googlebot: https://developers.google.com/search/blog/2019/05/the-new-evergreen-googlebot · May 2019
  2. Google, Understand the JavaScript SEO basics: https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics · As of Mar 4, 2026
  3. Google, Tell Google about localized versions of your page: https://developers.google.com/search/docs/specialty/international/localized-versions · As of Sep 21, 2026
  4. Search Console Help, The International Targeting report is being deprecated: https://support.google.com/webmasters/answer/12474899 · Retrieved Oct 15, 2026
  5. Search Console Help, URL Inspection tool: https://support.google.com/webmasters/answer/9012289 · Retrieved Oct 15, 2026
  6. Vercel, The rise of the AI crawler: https://vercel.com/blog/the-rise-of-the-ai-crawler · Dec 17, 2024
  7. Moz, Sam Nemzer, How to Implement SEO Changes Using Google Tag Manager: https://moz.com/blog/seo-changes-using-google-tag-manager