Skip to content
← Back to rules

jsx-a11y/lang Correctness

它的作用

<html> 元素上的 lang 属性必须是有效的 IETF BCP 47 语言标签。

为什么这不好?

如果网页的语言没有被指定为有效语言, 屏幕阅读器会假定使用用户设置的默认语言。 对于会说多种语言并以不止一种语言访问网站的用户来说, 语言设置会成为一个问题。

示例

以下是此规则的错误代码示例:

jsx
<html>
<html lang="foo">

以下是此规则的正确代码示例:

jsx
<html lang="en">
<html lang="en-US">

资源

如何使用

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["jsx-a11y"],
  "rules": {
    "jsx-a11y/lang": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["jsx-a11y"],
  rules: {
    "jsx-a11y/lang": "error",
  },
});
bash
oxlint --deny jsx-a11y/lang --jsx-a11y-plugin

版本

此规则在 v0.1.1 中添加。

参考