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

lang-attribute

Skill này làm gì

Skill này kiểm tra trang có khai báo ngôn ngữ đúng cách không, và các phần viết bằng ngôn ngữ khác có được đánh dấu hay không. Skill dành cho lập trình viên và biên tập viên của mọi website.

Khi nào nên dùng

  • ✓Khi trang không có ngôn ngữ nào được đặt trên phần tử html.
  • ✓Khi trình đọc màn hình đọc văn bản của bạn với cách phát âm sai.
  • ✓Khi trang có các đoạn viết bằng ngôn ngữ khác.

Liên kết skill

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/lang-attribute/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/lang-attribute/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 trang của tôi có khai báo ngôn ngữ đúng cách 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ó giá trị lang hợp lệ, chẳng hạn en hoặc fr-CA. Agent cũng gợi ý thuộc tính lang cho các phần đổi ngôn ngữ.

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.

Set the page lang attribute

Screen readers select the correct text-to-speech voice and pronunciation engine based on the lang attribute. Without it, VoiceOver defaults to the user's system language, and NVDA uses its default voice — both may mispronounce words in other languages, making content unintelligible. French text read with an English voice profile is incomprehensible. The lang attribute also enables browser translation features (Chrome's Translate), hyphenation algorithms (CSS hyphens: auto), and correct spell checking. This is a WCAG Level A requirement — the most fundamental accessibility baseline.

Quick Reference

  • The <html> element must have a lang attribute — WCAG 2.1 SC 3.1.1 (Language of Page, Level A)
  • The value must be a valid BCP 47 language tag: en, en-US, fr, zh-Hant, ar, etc.
  • Use lang on individual elements to indicate language changes within the page — WCAG 2.1 SC 3.1.2 (Level AA)
  • The lang attribute affects screen reader pronunciation, spell checking, hyphenation, and browser translation
  • An empty lang='' is treated as unknown language — equivalent to having no lang attribute

Check

Inspect the <html> element in the page source. Verify: (1) a lang attribute is present; (2) its value is non-empty; (3) its value is a valid BCP 47 language code matching the primary language of the page content (e.g., en for English, fr for French, zh-Hant for Traditional Chinese). Flag: missing lang, empty lang='', language codes using full names instead of codes (e.g., lang='english' is invalid), and mismatches where the declared language does not match the actual content language. For multilingual pages, also check for lang changes on block-level elements containing content in a different language.

Fix

Add or correct the lang attribute on the <html> element: <html lang='en'> for English, <html lang='fr'> for French, <html lang='es'> for Spanish, <html lang='de'> for German, <html lang='ja'> for Japanese, <html lang='zh-Hans'> for Simplified Chinese, <html lang='zh-Hant'> for Traditional Chinese, <html lang='ar'> for Arabic. For content sections in different languages, add lang to the containing block element. Validate language codes against the IANA Language Subtag Registry.

Explain

WCAG 2.1 SC 3.1.1 (Language of Page, Level A) requires that the default human language of each web page can be programmatically determined. The lang attribute on <html> fulfills this requirement. The value must be a BCP 47 language tag — a standardized system of subtags that identifies language, script, and region. The primary language subtag (e.g., en, fr) is required; region subtags (e.g., en-US, fr-CA) are optional but useful for dialect-specific pronunciation and spell checking. SC 3.1.2 (Language of Parts, Level AA) extends this to inline language changes within a page.

Code Review

Review templates, server-rendered HTML, and shared components that output markup related to Set the page lang attribute. Flag exact elements, attributes, and routes where the rendered HTML violates the rule.


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

Rule page: https://frontendchecklist.io/rules/html/lang-attribute

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

Vì sao lang quan trọng với trình đọc màn hình?

Skill nói trình đọc màn hình dùng nó để chọn giọng đọc và cách phát âm đúng.

Giá trị nào là hợp lệ?

Một mã ngôn ngữ BCP 47 hợp lệ, chẳng hạn en, en-US, fr hoặc zh-Hant.

Điều gì xảy ra nếu lang để trống?

Skill nói lang trống được xử lý giống như không đặt ngôn ngữ nào.

Chi tiết

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

Use when applies to all HTML documents. Check the `<html>` opening tag for a `lang` attribute with a non-empty, valid BCP 47 language code. Also check for `lang` attribute changes on individual elements when the document contains content in multiple languages (inline quotes, foreign terms, multilingual sections). The `lang` attribute is inherited — child elements inherit the language from their nearest ancestor with `lang`.

repo: thedaviddias/Front-End-Checklist

Độ phổ biến

Sao GitHub
75k
Vị trí xếp hạng
#2913
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ự