Hreflang Tags Testing

Validate hreflang annotations for international SEO.

ISO 639-1 LANGUAGE CODES ISO 3166-1 COUNTRY CODES x-default CHECK 100% FREE
Free Professional Tool | No Registration Required | Updated: January 2026
AI-GENERATED TOOL

Note: This Hreflang Tags Testing tool was created with the help of AI. All validation runs 100% locally in your browser — your HTML, URLs and hreflang annotations never leave your device (URL fetching uses public CORS proxies). The language/country code checks use static ISO reference lists and always recommend a final sanity check against the official ISO 639-1 and ISO 3166-1 registries before shipping changes.

Get International SEO Right

Fix hreflang mistakes before they split your ranking signals across language and region versions.

Validator Generator URL Fetcher

Paste HTML with hreflang tags

Validation options

Validation Report

Paste HTML and click Validate Hreflang to see the full report.

Validate hreflang on a live page

Fetches the HTML through public CORS proxies and runs the same validation. If the fetch fails, copy the page source and use the Validate HTML tab instead.

Generate Hreflang Tags

Enter one hreflang-code + URL pair per line, in the format code | url.

Generated Tags

Generated hreflang tags will appear here.

Place these tags inside <head>. Every language page must link to all the others — including itself.

Complete Hreflang Guide

What Is Hreflang?

Hreflang (short for "HTML language reference") is a set of HTML annotations that tell search engines which language and, optionally, which region each version of a page is intended for. It solves a very specific problem: when you publish the same content in multiple languages or target different regions with the same language, Google needs to know which version to show to which user.

The tag itself looks like this:

<link rel="alternate" hreflang="en-US" href="https://example.com/">

Anatomy of a Hreflang Value

  • Language (required): ISO 639-1 two-letter code, e.g. en, fr, de. Three-letter ISO 639-2 codes are also accepted by Google.
  • Region (optional): ISO 3166-1 alpha-2 two-letter country code, e.g. US, GB, CA. Separated by a hyphen.
  • x-default (special): the fallback version for users whose language/region isn't matched by any other annotation.

The Rules You Must Follow

  1. Every version must link to every other version — including itself. If you have 5 languages, each page carries 5 hreflang tags.
  2. Use absolute URLs — always start with https:// and the full domain.
  3. Language first, region second: en-US, not US-en.
  4. Hyphens, not underscores: en-GB, not en_GB.
  5. Region must be uppercase: en-GB, not en-gb.
  6. One x-default per cluster — usually the global or language-selector page.
  7. Never use hreflang as a canonical substitute — the two tags do different jobs.

Common Hreflang Mistakes

MistakeExampleFix
Underscore separatoren_USUse hyphen: en-US
Lowercase regionen-usUppercase: en-US
Invalid language codeeng-US for English in the USUse ISO 639-1: en-US
Missing return tagPage A links to B, but B doesn't link back to AAdd reciprocal tags on both pages
No self-referenceOnly other languages are listedAdd a tag with your own hreflang
Relative URL/fr/Use full URL: https://example.com/fr/
Duplicate hreflangTwo en-US entriesKeep one; disambiguate by URL path
Missing x-defaultOnly language variants presentAdd an x-default fallback

How to Use This Tester

  1. Validate HTML: paste a full HTML document (or just the hreflang tags) and click Validate. You'll get a full annotation table plus a prioritised list of issues.
  2. Validate by URL: paste a live page URL. The tool fetches the HTML via CORS proxies and runs the same validation.
  3. Generate Tags: paste your hreflang code / URL pairs and produce a ready-to-paste block with a self-referencing tag and optional x-default.

Pro Tip: Hreflang is a signal, not a directive. Google uses it together with content language, canonical tags and user settings. That means hreflang mistakes won't always cause a visible problem in the short term — but they'll reduce how reliably your regional and language pages rank in the right places.

⚠️ AI-Generated Tool Notice: This tester was built with AI assistance. The language and country code lists are embedded static references and may not include every ISO 639-3 or ISO 3166-1 code. Always cross-check against the official IANA Language Subtag Registry and Google's Search Console International Targeting report before finalising changes.

Frequently Asked Questions

No. If you have a single language version and don't target distinct regional variants (like US English vs UK English with different content), hreflang isn't necessary. However, if you target en-US and en-GB with the same language but different content or pricing, hreflang helps disambiguate.

Three places are supported by Google: (1) HTML head using <link rel="alternate" hreflang="…">, (2) HTTP response headers (Link: <…>; rel="alternate"; hreflang="…") — useful for PDFs and non-HTML files, and (3) XML sitemaps using the xhtml:link extension. This tool validates the HTML head format.

x-default marks the fallback page to show when no other hreflang matches the user's language or region. Google strongly recommends it — often the global English version or a language-selector page. Without it, Google has to guess which version to show to unmatched users, and that guess is often wrong.

No — they solve different problems. Canonical says "this is the preferred URL when the content is the same." Hreflang says "these are equivalent pages in different languages/regions." A page can (and often should) have both a self-referencing canonical and a full set of hreflang tags.

Anywhere from a few days to several weeks, depending on crawl frequency and how many pages are affected. Google often re-evaluates hreflang clusters during its regular crawling. Use Search Console → International Targeting (for legacy accounts) or the new URL Inspection tool to see whether Google has picked up your annotations.

Ready to Fix Your Hreflang Setup?

Validate, audit and generate hreflang annotations in seconds — for any multilingual or multi-regional website.

Updated: January 2026 | Free for Commercial Use | 100% Client-Side Processing

Why Choose Our Hreflang Tester?

Full ISO Validation

Every language and country code is checked against embedded ISO 639-1 and ISO 3166-1 reference lists.

Cluster Awareness

Detects missing self-references, duplicate codes and x-default problems across the whole annotation set.

Generator Included

Bulk-generate correctly formatted hreflang blocks with self-reference and x-default support.

100% Private

HTML validation runs entirely in your browser. Only URL fetching uses public proxies.

More SEO Tools

'; } let doc; try { doc = new DOMParser().parseFromString(parseTarget, 'text/html'); } catch (e) { addError('Could not parse HTML', 'The browser could not parse the HTML you provided.'); return { issues, passed, annotations: [] }; } // Find all link[rel~="alternate"][hreflang] let links = Array.from(doc.querySelectorAll('link[rel~="alternate" i][hreflang]')); // Fallback: some pages use rel="alternate hreflang" (space-separated rel attribute) if (!links.length) { const allLinks = Array.from(doc.querySelectorAll('link')); links = allLinks.filter(l => { const rel = (l.getAttribute('rel') || '').toLowerCase(); return rel.split(/\s+/).includes('alternate') && l.hasAttribute('hreflang'); }); } if (!links.length) { addError('No hreflang tags found', 'No tags were found. If your site isn\'t multi-language or multi-regional, that\'s expected. Otherwise, add hreflang annotations to the .'); return { issues, passed, annotations: [] }; } // Parse all annotations const annotations = links.map((link, i) => { const hreflang = (link.getAttribute('hreflang') || '').trim(); const href = (link.getAttribute('href') || '').trim(); return { index: i + 1, hreflang, href }; }); // Run checks const seenHreflang = new Map(); const seenHref = new Map(); let xDefaultCount = 0; let validCount = 0; annotations.forEach(a => { const label = 'Tag #' + a.index + ' [' + (a.hreflang || '?') + ']'; /* --- href checks --- */ if (!a.href) { addError(label + ' — missing href', 'The hreflang link has no href attribute.', ''); } else if (!/^https?:\/\//i.test(a.href)) { addError(label + ' — relative URL', 'Hreflang href must be an absolute URL starting with https:// or http://.', 'href="' + a.href + '" → use a full https:// URL'); } else if (/^http:\/\//i.test(a.href)) { addWarn(label + ' — uses HTTP', 'Prefer HTTPS in hrefs to match your canonical URLs and avoid mixed-signal issues.', a.href.replace(/^http:/i, 'https:')); } else { validCount++; } /* --- hreflang value checks --- */ if (!a.hreflang) { addError(label + ' — empty hreflang', 'The hreflang attribute is present but empty.'); return; } const code = a.hreflang; // x-default if (code.toLowerCase() === 'x-default') { xDefaultCount++; passed.push(label + ' — x-default fallback present'); return; } // Format check if (code.indexOf('_') !== -1) { addError(label + ' — underscore separator', 'Hreflang codes use hyphens, not underscores. Google will ignore this tag.', code.replace(/_/g, '-')); return; } const parts = code.split('-'); if (parts.length === 1) { // Language only const lang = parts[0].toLowerCase(); if (lang.length < 2 || lang.length > 3) { addError(label + ' — invalid language length', 'A language-only hreflang must be 2 (ISO 639-1) or 3 (ISO 639-2/3) letters.', 'e.g. "en", "fr", "eng"'); } else if (parts[0] !== lang) { addWarn(label + ' — language code has uppercase', 'Language codes are conventionally lowercase. Google accepts both, but lowercase is standard.', lang); } else if (lang.length === 2 && !ISO_LANG.has(lang)) { addWarn(label + ' — unknown language code', '"' + lang + '" is not a recognized ISO 639-1 code. Double-check you meant to use it.', 'See IANA Language Subtag Registry'); } else { const name = LANG_NAMES[lang] ? ' (' + LANG_NAMES[lang] + ')' : ''; passed.push(label + ' — valid language code "' + lang + '"' + name); } } else if (parts.length === 2) { // Language + Region const lang = parts[0].toLowerCase(); const region = parts[1]; if (lang.length < 2 || lang.length > 3) { addError(label + ' — invalid language length', 'Language part must be 2 or 3 letters.', 'e.g. "en-US", "fr-CA"'); } else if (lang.length === 2 && !ISO_LANG.has(lang)) { addWarn(label + ' — unknown language code', '"' + lang + '" is not a recognized ISO 639-1 code.', 'See IANA Language Subtag Registry'); } if (region.length !== 2) { addError(label + ' — invalid region length', 'Region part must be exactly 2 letters (ISO 3166-1 alpha-2).', 'e.g. "en-US", "en-GB"'); } else if (region !== region.toUpperCase()) { addError(label + ' — region is lowercase', 'Region codes must be UPPERCASE. Google ignores lowercase regions.', code.replace('-' + region, '-' + region.toUpperCase())); } else if (!ISO_COUNTRY.has(region)) { addWarn(label + ' — unknown region code', '"' + region + '" is not a recognized ISO 3166-1 alpha-2 country code.', 'See ISO 3166-1 alpha-2 registry'); } else if (ISO_LANG.has(lang) && ISO_COUNTRY.has(region)) { const ln = LANG_NAMES[lang] || lang; const cn = COUNTRY_NAMES[region] || region; passed.push(label + ' — valid "' + code + '" (' + ln + ' · ' + cn + ')'); } } else { addError(label + ' — invalid format', 'Hreflang values have at most two parts: language and (optional) region. Script subtags (e.g. zh-Hans-CN) are not supported by Google.', 'Use "zh-CN" or "zh"'); } /* --- duplicate hreflang detection --- */ const key = code.toLowerCase(); if (seenHreflang.has(key)) { addError(label + ' — duplicate hreflang value', '"' + code + '" is used more than once. Each hreflang value may only appear once per page.', 'Remove the duplicate entry'); } else { seenHreflang.set(key, a.index); } /* --- duplicate href detection --- */ if (a.href) { const hrefKey = a.href.replace(/\/$/, '').toLowerCase(); if (seenHref.has(hrefKey)) { const prev = seenHref.get(hrefKey); addWarn(label + ' — duplicate URL', 'The same URL is used for multiple hreflang values (tag #' + prev + ' and #' + a.index + '). Make sure this is intentional — e.g. sharing one fallback.', 'Differentiate URLs by language path or subdomain'); } else { seenHref.set(hrefKey, a.index); } } }); /* --- x-default presence --- */ if (xDefaultCount === 0 && options.warnXDefault !== false) { addWarn('Missing x-default', 'No x-default hreflang was found. Google recommends adding one to specify which version to show to unmatched users.', ''); } else if (xDefaultCount > 1) { addError('Multiple x-default tags', 'Only one x-default is allowed per hreflang cluster. Found ' + xDefaultCount + '.'); } else if (xDefaultCount === 1) { // already passed above } /* --- self-reference check --- */ // If the document declares its own canonical URL, use that; otherwise look for a if (options.requireSelf !== false) { const canonical = doc.querySelector('link[rel="canonical" i]'); const canonicalHref = canonical ? (canonical.getAttribute('href') || '').replace(/\/$/, '').toLowerCase() : ''; if (canonicalHref) { const hasSelf = annotations.some(a => a.href.replace(/\/$/, '').toLowerCase() === canonicalHref); if (!hasSelf) { addWarn('No self-referencing hreflang tag', 'This page has a canonical of "' + canonicalHref + '" but no hreflang tag points to it. Each page must include a hreflang tag pointing to itself.', ''); } else { passed.push('Self-referencing hreflang tag is present'); } } else { // No canonical to compare against — informational only addWarn('No canonical found for self-reference check', 'To verify a self-referencing hreflang tag, add a to the page or provide it below.'); } } /* --- minimum cluster size check --- */ if (annotations.length === 1) { addWarn('Single hreflang tag', 'A hreflang cluster usually includes at least 2 tags — one for each language/region plus x-default. A single tag only makes sense if the page is otherwise non-international.', ''); } /* --- count summary --- */ passed.push('Found ' + annotations.length + ' hreflang annotation(s) — ' + validCount + ' with absolute URLs'); return { issues, passed, annotations }; } /* ===================================================================== REPORT RENDERING ===================================================================== */ function renderReport(container, result) { const errors = result.issues.filter(i => i.severity === 'error'); const warnings = result.issues.filter(i => i.severity === 'warning'); const isValid = errors.length === 0; const score = Math.max(0, Math.round(100 - errors.length * 12 - warnings.length * 5)); const scoreColor = score >= 90 ? 'text-green-500' : score >= 70 ? 'text-blue-500' : score >= 40 ? 'text-yellow-500' : 'text-red-500'; let html = ''; html += `
${isValid ? 'HREFLANG OK' : 'ISSUES FOUND'}

${errors.length} error(s) · ${warnings.length} warning(s) · ${result.passed.length} passed

${score}%
Score
`; /* Annotations table */ if (result.annotations.length) { html += '

Annotations found (' + result.annotations.length + ')

'; html += '
'; html += ''; html += ''; result.annotations.forEach(a => { const codeLower = a.hreflang.toLowerCase(); const isXDef = codeLower === 'x-default'; html += ''; html += ''; html += ''; html += ''; html += ''; }); html += '
#hreflanghref
' + a.index + '' + esc(a.hreflang || '—') + '' + (isXDef ? ' x-default' : '') + '' + esc(a.href || '—') + '
'; } /* Errors */ if (errors.length) { html += '

Errors (' + errors.length + ')

'; html += '
'; errors.forEach(i => { html += issueRow(i, 'error'); }); html += '
'; } /* Warnings */ if (warnings.length) { html += '

Warnings & recommendations (' + warnings.length + ')

'; html += '
'; warnings.forEach(i => { html += issueRow(i, 'warning'); }); html += '
'; } /* Passed */ if (result.passed.length) { html += '

Passed checks (' + result.passed.length + ')

'; html += '
'; result.passed.forEach(p => { html += `
${esc(p)}
`; }); html += '
'; } container.innerHTML = html; } function issueRow(issue, severity) { const icon = severity === 'error' ? 'fa-circle-xmark text-red-500' : 'fa-triangle-exclamation text-yellow-500'; const codeBlock = issue.code ? '
' + esc(issue.code) + '
' : ''; return `
${esc(issue.title)}
${esc(issue.detail)}
${codeBlock}
`; } /* ===================================================================== VALIDATE HTML TAB ===================================================================== */ const SAMPLE_HTML = [ '', '', '', ' ', ' Example International Page', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', '', '

Welcome

', '' ].join('\n'); $('validate-btn').addEventListener('click', () => { const html = $('validate-input').value; if (!html.trim()) { showToast('Please paste some HTML first'); return; } const result = validateHreflang(html, { warnXDefault: $('opt-xdefault-warn').checked, requireSelf: $('opt-selftag').checked }); renderReport($('validate-results'), result); }); $('sample-btn').addEventListener('click', () => { $('validate-input').value = SAMPLE_HTML; }); $('clear-btn').addEventListener('click', () => { $('validate-input').value = ''; $('validate-results').innerHTML = `

Paste HTML and click Validate Hreflang to see the full report.

`; }); /* ===================================================================== VALIDATE BY URL TAB ===================================================================== */ const PROXIES = [ { name: 'allorigins', build: u => 'https://api.allorigins.win/raw?url=' + encodeURIComponent(u) }, { name: 'codetabs', build: u => 'https://api.codetabs.com/v1/proxy?quest=' + encodeURIComponent(u) }, { name: 'cors.x2u.in', build: u => 'https://cors.x2u.in/' + u }, { name: 'corsproxy.io', build: u => 'https://corsproxy.io/?' + encodeURIComponent(u) }, { name: 'thingproxy', build: u => 'https://thingproxy.freeboard.io/fetch/' + u }, { name: 'yacdn', build: u => 'https://yacdn.org/proxy/' + u }, { name: 'whateverorigin',build: u => 'https://whateverorigin.org/get?url=' + encodeURIComponent(u) }, { name: 'cors-anywhere', build: u => 'https://cors-anywhere.herokuapp.com/' + u } ]; function fetchWithTimeout(url, timeoutMs) { timeoutMs = timeoutMs || 12000; return new Promise((resolve, reject) => { const controller = new AbortController(); const timer = setTimeout(() => { try { controller.abort(); } catch(e) {} reject(new Error('Request timed out')); }, timeoutMs); fetch(url, { signal: controller.signal, headers: { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' } }) .then(res => { clearTimeout(timer); if (!res.ok) { reject(new Error('HTTP ' + res.status)); return; } resolve(res); }) .catch(err => { clearTimeout(timer); reject(err); }); }); } async function fetchPageHtml(url, onProgress) { let lastError = null; for (let i = 0; i < PROXIES.length; i++) { const proxy = PROXIES[i]; if (onProgress) onProgress('Trying proxy ' + (i + 1) + '/' + PROXIES.length + ': ' + proxy.name + ' …'); try { const res = await fetchWithTimeout(proxy.build(url), 12000); let text = await res.text(); if (text && text.trim().startsWith('{')) { try { const json = JSON.parse(text); if (json.contents && typeof json.contents === 'string') text = json.contents; else if (json.body && typeof json.body === 'string') text = json.body; } catch (e) {} } if (text && text.length > 100 && text.indexOf('<') !== -1) { if (onProgress) onProgress('Success via ' + proxy.name + '! Running validation…'); return text; } lastError = new Error('Response from ' + proxy.name + ' was not usable HTML'); } catch (err) { lastError = err; } } throw lastError || new Error('All CORS proxies failed'); } $('fetch-btn').addEventListener('click', async function () { const url = $('fetch-url').value.trim(); if (!url) { showToast('Please enter a URL'); return; } if (!/^https?:\/\//i.test(url)) { showToast('Include http:// or https://'); return; } const btn = this; const statusBox = $('fetch-status'); const statusText = $('fetch-status-text'); const results = $('fetch-results'); btn.disabled = true; btn.innerHTML = 'Fetching…'; statusBox.classList.remove('hidden'); results.innerHTML = ''; statusText.textContent = 'Starting CORS proxy fallback chain…'; try { const html = await fetchPageHtml(url, msg => { statusText.textContent = msg; }); const result = validateHreflang(html, { warnXDefault: true, requireSelf: true }); renderReport(results, result); statusBox.classList.add('hidden'); } catch (err) { statusBox.classList.add('hidden'); results.innerHTML = `

Could Not Fetch the Page

All ${PROXIES.length} CORS proxies failed. The site may block proxy requests, require authentication, or be temporarily unavailable.

✅ Recommended workaround:

  1. Open ${esc(url)} in your browser.
  2. Press Ctrl + U to view the source.
  3. Copy the HTML and paste it into the Validate HTML tab.

Last error: ${esc(err && err.message ? err.message : 'Unknown error')}

`; } finally { btn.disabled = false; btn.innerHTML = 'Fetch & Validate'; } }); $('fetch-sample-btn').addEventListener('click', () => { $('fetch-url').value = 'https://www.w3.org/'; }); $('fetch-clear-btn').addEventListener('click', () => { $('fetch-url').value = ''; $('fetch-status').classList.add('hidden'); $('fetch-results').innerHTML = ''; }); /* ===================================================================== GENERATE TAB ===================================================================== */ const GEN_SAMPLE = [ 'en-US | https://example.com/', 'en-GB | https://example.com/uk/', 'fr-FR | https://example.com/fr/', 'de-DE | https://example.com/de/', 'es-ES | https://example.com/es/', 'ja-JP | https://example.com/ja/', 'x-default | https://example.com/' ].join('\n'); function generateHreflang() { const raw = $('gen-input').value; const lines = raw.split('\n').map(l => l.trim()).filter(Boolean); if (!lines.length) { showToast('Please enter at least one line'); return; } const includeComment = $('gen-include-comment').checked; const includeSelf = $('gen-selfref').checked; const pairs = []; lines.forEach(line => { const parts = line.split('|').map(p => p.trim()); if (parts.length < 2) return; const code = parts[0]; const url = parts.slice(1).join('|').trim(); // in case URL has a pipe (unlikely) if (!code || !url) return; pairs.push({ code, url }); }); // Add self-reference if requested and not already present if (includeSelf) { const selfCode = $('gen-selfref-code').value.trim(); const selfUrl = $('gen-selfref-url').value.trim(); if (selfCode && selfUrl) { const already = pairs.some(p => p.code.toLowerCase() === selfCode.toLowerCase() && p.url.replace(/\/$/, '').toLowerCase() === selfUrl.replace(/\/$/, '').toLowerCase()); if (!already) { pairs.unshift({ code: selfCode, url: selfUrl }); } } } if (!pairs.length) { showToast('No valid code | URL pairs found'); return; } const linesOut = []; if (includeComment) { linesOut.push(''); } pairs.forEach(p => { linesOut.push(''); }); const output = linesOut.join('\n'); $('gen-output').innerHTML = '
' + esc(output) + '
'; } $('gen-btn').addEventListener('click', generateHreflang); $('gen-sample-btn').addEventListener('click', () => { $('gen-input').value = GEN_SAMPLE; $('gen-selfref-code').value = 'en-US'; $('gen-selfref-url').value = 'https://example.com/'; }); $('gen-clear-btn').addEventListener('click', () => { $('gen-input').value = ''; $('gen-selfref-url').value = ''; $('gen-output').innerHTML = '
Generated hreflang tags will appear here.
'; }); $('gen-copy-btn').addEventListener('click', function () { const text = $('gen-output').innerText; if (text && text.indexOf('will appear here') === -1) copyToClipboard(text, 'Hreflang tags copied!'); else showToast('Generate tags first'); }); $('gen-download-btn').addEventListener('click', function () { const text = $('gen-output').innerText; if (text && text.indexOf('will appear here') === -1) downloadText(text, 'hreflang-tags.html', 'text/html;charset=utf-8'); else showToast('Generate tags first'); }); /* ================= FOOTER TOGGLE ================= */ document.querySelectorAll('.footer-toggle-btn').forEach(btn => { btn.addEventListener('click', function () { if (window.innerWidth > 768) return; const content = this.nextElementSibling; if (content && content.classList.contains('footer-col-content')) { content.classList.toggle('collapsed'); } }); });