Skip to content
cosmodev ~/tools/hreflang-tag-generator

hreflang 标签生成器

Generators

将语言版本列表转换为有效的 hreflang 集合 — 区域设置规范化、重复检测和 x-default 处理 — 输出为 HTML link 标签或 XML 站点地图片段。

Language versions

One row per language version: a locale like en or de-AT and its absolute URL.

The page for users whose language does not match any row — usually the default version.

(文档为英文)

What it does

The Hreflang Tag Generator turns a table of language versions into a correct hreflang set. Type locales loosely — en-us normalizes to en-US, PT-br to pt-BR — and the tool validates the rest: each locale must be ll or ll-CC, every URL must be absolute http(s), and no locale may appear twice. Add an x-default URL for visitors whose language matches none of the rows. The output comes in two shapes: HTML <link rel="alternate"> tags for your <head>, or xhtml:link lines for an XML sitemap entry.

Everything runs 100% client-side.

How to use it

  1. Add one row per language version: locale on the left, absolute URL on the right.
  2. Optionally set the x-default URL — it is emitted last.
  3. Switch the output between HTML and Sitemap and copy the block.

Examples

  • en → https://example.com/, de-de → https://example.com/de/, x-default https://example.com/ → three link tags, with de-DE normalized and x-default last.
  • Rows en and EN → the output lists Row 2: locale "en" is already used. and emits nothing until the duplicate is gone.

Good to know

  • Google’s hreflang grammar accepts two-letter language codes, optionally with a two-letter region — script subtags and three-letter codes are rejected rather than guessed at.
  • The sitemap block belongs inside a <url> entry, next to the <loc> tag — the tool indents it accordingly.
  • Every error names its row number, so long tables stay fixable.
源代码14 种语言

100% 客户端运行 · 你的数据永远不会离开浏览器。 觉得好用?分享给同事吧。