Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)75k · #2873

html-xml-lang-mismatch

Skill này làm gì

Skill này kiểm tra các thuộc tính ngôn ngữ trên phần tử html của trang. Skill dành cho lập trình viên làm trang XHTML hoặc trang phải chạy được cả như HTML lẫn XML.

Khi nào nên dùng

  • ✓Khi một trang đặt cả lang và xml:lang với giá trị khác nhau.
  • ✓Khi trình đọc màn hình phát âm văn bản bằng giọng của ngôn ngữ sai.
  • ✓Khi bạn xuất bản tài liệu kiểu XHTML hoặc EPUB.

Liên kết skill

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/html-xml-lang-mismatch/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/html-xml-lang-mismatch/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Bạn có thể kiểm tra xem các thuộc tính ngôn ngữ trên trang của tôi có khớp nhau không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent kiểm tra phần tử html có lang và xml:lang hay không, rồi xác nhận hai giá trị giống nhau và là mã ngôn ngữ hợp lệ. Agent báo mọi chỗ lệch, kể cả khác ở phần phụ như en và en-US.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Match lang and xml:lang attributes

Screen readers use the lang attribute to select the correct voice profile and pronunciation engine. If lang and xml:lang disagree, XML-based processors (including some EPUB readers and older assistive technologies) may use xml:lang and get a different language than intended — causing text to be read aloud in the wrong language. For example, French text read with an English voice profile produces unintelligible output for French-speaking blind users.

Quick Reference

  • If both lang and xml:lang are present on <html>, their values must be identical
  • xml:lang is only needed for XHTML or polyglot documents (valid as both HTML and XML)
  • For standard HTML5 documents, only lang is required — xml:lang is redundant
  • The primary language tag must be a valid BCP 47 language code (e.g., en, en-US, fr, zh-Hant)
  • Relates to WCAG 2.1 SC 3.1.1 (Language of Page)

Check

Inspect the <html> element for both lang and xml:lang attributes. If both are present, verify their values are identical (including subtags — en vs en-US is a mismatch). Also verify that the value is a valid BCP 47 language tag. Flag if the values differ in any way.

Fix

If lang and xml:lang are present but differ: update both to the same valid BCP 47 language code matching the primary language of the document content. If this is a standard HTML5 document (served as text/html), remove xml:lang — it is unnecessary. If this is XHTML or a polyglot document, keep both and ensure they are identical.

Explain

WCAG 2.1 SC 3.1.1 requires that the default human language of each web page can be programmatically determined. The lang attribute on <html> serves this purpose for HTML parsers. The xml:lang attribute serves the same purpose for XML parsers. When a document must be valid as both HTML and XML (polyglot), both attributes must be present and identical. A mismatch means the document claims different languages depending on which parser reads it, which can cause screen readers, translation tools, and spell checkers to use wrong language rules.

Code Review

Review the rendered markup and interactive states that affect Match lang and xml:lang attributes. Flag exact elements, roles, labels, focus behavior, or keyboard interactions that violate the rule, and note how to verify the fix with browser accessibility tooling or assistive tech.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/accessibility/html-xml-lang-mismatch

Câu hỏi thường gặp

Trang HTML5 chuẩn có cần xml:lang không?

Không. Skill nói trang HTML5 chuẩn chỉ cần lang, vì xml:lang là thừa ở đó.

Vì sao sự lệch nhau lại quan trọng?

Một số công cụ XML và công nghệ hỗ trợ cũ có thể đọc xml:lang, và điều này có thể cho ra ngôn ngữ sai.

Skill dựa trên tiêu chuẩn nào?

Skill trích dẫn tiêu chí thành công 3.1.1 của WCAG 2.1, quy tắc Language of Page.

Chi tiết

Mô tả gốc của tác giả

Use when applies to XHTML documents and polyglot HTML documents that must parse correctly as both HTML5 and XML. For modern HTML5-only documents, only `lang` is needed and `xml:lang` is not required. Check when auditing documents served as application/xhtml+xml or documents that include both attributes.

repo: thedaviddias/Front-End-Checklist

Độ phổ biến

Sao GitHub
75k
Vị trí xếp hạng
#2873
Giấy phép
MIT
Cập nhật
31/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự