跳到主要内容

HTML 规则

注意

HTML Validate 规则参考 html-validate:recommended,但是由于需要整理的内容非常多,在开发过程中,仍以实际的 HTML Validate 检查为准。本章内容仅供参考

HTML语法与概念

与HTML语法和概念相关的规则。

规则描述
✔️attr-delimiter禁止在属性键和值之间存在空格
✔️attr-spacing要求属性之间用空格分隔
✔️close-attr禁止结束标签包含属性
✔️close-order要求元素以正确的顺序关闭
✔️element-name禁止使用无效的元素名称
✔️form-dup-name要求表单控件具有唯一的名称
✔️map-dup-name要求 <map name> 是唯一的
✔️map-id-name要求 <map> 元素上的 name 和 id 匹配
✔️no-dup-attr禁止重复的属性
✔️no-dup-class禁止重复的类
✔️no-raw-characters禁止使用未转义的特殊字符
✔️no-redundant-for禁止使用冗余的 label for 属性
✔️script-type要求 <script> 元素具有有效的类型
✔️unrecognized-char-ref禁止无法识别的字符引用
✔️valid-autocomplete要求 autocomplete 属性有效
✔️valid-id要求 id 是一个有效的标识符

内容模型

规则描述
✔️attribute-allowed-values验证允许的属性值
✔️attribute-misuse要求属性在正确的上下文中使用
✔️element-permitted-content验证允许的内容
✔️element-permitted-occurrences验证允许的元素出现次数
✔️element-permitted-order验证所需的元素顺序
✔️element-permitted-parent验证允许的父元素
✔️element-required-ancestor验证所需的祖先元素
✔️element-required-attributes确保设置了必需的属性
✔️element-required-content确保存在必需的元素
✔️input-attributes验证输入属性的使用
✔️no-multiple-main禁止多个 <main>
✔️script-element要求 <script> 有结束标签
✔️void-content禁止空元素包含内容

已弃用

与使用已弃用或过时功能相关的规则。

规则描述
✔️deprecated禁止使用已弃用的元素
✔️deprecated-rule禁止使用已弃用的规则
✔️no-conditional-comment禁止使用条件注释
✔️no-deprecated-attr禁止使用已弃用的属性

可访问性

规则描述
✔️area-alt要求 <area> 元素提供替代文本
✔️aria-hidden-body禁止在 <body> 上设置 aria-hidden
✔️aria-label-misuse禁止误用 aria-label
✔️empty-heading要求标题具有文本内容
✔️empty-title要求 title 具有文本内容
✔️hidden-focusable禁止对可聚焦元素使用 aria-hidden
📃input-missing-label要求输入框有标签
✔️meta-refresh要求 meta refresh 的延迟时间为 0 秒
✔️multiple-labeled-controls禁止标签与多个控件关联
✔️no-abstract-role禁止使用抽象的 WAI-ARIA 角色
✔️no-autoplay禁止媒体元素自动播放
✔️no-implicit-button-type禁止隐式的按钮类型
✔️no-redundant-aria-label禁止 aria-label 和 label 具有相同的文本内容
✔️no-redundant-role禁止使用冗余的角色
✔️prefer-native-element倾向于使用原生 HTML 元素而不是角色
✔️tel-non-breaking要求电话号码中使用非换行字符
✔️text-content要求元素具有有效的文本内容
✔️unique-landmark要求地标具有唯一的名称
✔️wcag/h30WCAG H30: 提供链接文本
✔️wcag/h32WCAG H32: 提供提交按钮
✔️wcag/h36WCAG H36: 要求用作提交按钮的图像提供替代文本
✔️wcag/h37WCAG H37: 在 img 元素上使用 alt 属性
✔️wcag/h63WCAG H63: 使用 scope 属性关联表头单元格和数据单元格
✔️wcag/h67WCAG H67: 在 img 元素上使用空 alt 文本且无 title 属性
✔️wcag/h71WCAG H71: 为表单控件组提供描述

安全

规则描述
📃require-sri要求资源具有 SRI (子资源完整性)

SEO

规则描述
✔️long-title要求 title 文本不能过长

风格

规则描述
✔️attr-case要求属性名称使用特定的大小写
✔️attr-quotes要求属性使用引号
✔️attribute-boolean-style要求布尔属性使用特定样式
✔️attribute-empty-style要求空属性使用特定样式
✔️doctype-style要求 DOCTYPE 使用特定的大小写
✔️element-case要求元素名称使用特定的大小写
✔️no-implicit-close要求具有可选结束标签的元素被显式关闭
✔️no-implicit-input-type禁止隐式的输入类型
✔️no-inline-style禁止内联样式
✔️no-self-closing禁止自闭合元素
✔️no-trailing-whitespace禁止尾部空白
✔️prefer-button倾向于使用 <button> 而不是 <input> 作为按钮
✔️prefer-tbody倾向于将 <tr> 包裹在 <tbody>
✔️void-style要求空元素使用特定的闭合样式

文档

这些规则用于完整的文档。

规则描述
✔️doctype-html要求使用 "html" 文档类型
📃heading-level要求标题从 h1 开始并逐级递增
📃missing-doctype要求文档具有文档类型
✔️no-dup-id禁止重复的 ID
📃no-missing-references要求所有元素引用都存在
✔️no-utf8-bom禁止文档包含 UTF-8 BOM

未分类

规则描述
✔️no-unused-disable禁止未使用的禁用指令