doctype
它能做什么
这项技能检查网页是否以正确的 HTML5 doctype 行开头。适合希望在各个浏览器中显示一致的开发者。
适用场景
- ✓当页面在每个浏览器中的显示都不同时。
- ✓当你新建页面或模板时。
- ✓当框架生成的输出可能缺少声明时。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/doctype/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“你能检查一下我的页面是否有正确的 HTML5 doctype 吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会检查页面原始 HTML 的第一行。如果声明缺失、过时或不在首位,它会建议正确的一行。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Use the HTML5 doctype
Without the HTML5 doctype, browsers fall back to Quirks Mode, which emulates the rendering behavior of pre-standards browsers from the late 1990s. In Quirks Mode, the CSS box model changes (padding adds to element width), vertical centering breaks, and many modern HTML5 APIs may behave unexpectedly. This causes cross-browser rendering inconsistencies that are difficult to debug and may produce inaccessible layouts.
Quick Reference
- Every HTML document must begin with
<!DOCTYPE html>as its very first line - Without a doctype, browsers enter Quirks Mode — a legacy compatibility mode with inconsistent CSS and JavaScript behavior
- The HTML5 doctype is case-insensitive but
<!DOCTYPE html>(uppercase DOCTYPE) is the conventional form - No other content, not even whitespace or BOM characters, should appear before the doctype
- Frameworks like Next.js, Nuxt, and Remix automatically include the doctype — verify in rendered HTML, not source templates
Check
Check the very first line of the HTML document source (not the DOM — the raw HTTP response). The document must begin with <!DOCTYPE html> (case-insensitive). Flag if: (1) the doctype is missing entirely; (2) an old HTML4 or XHTML doctype is used (contains PUBLIC and a DTD URL); (3) the doctype is not the absolute first content (whitespace or BOM before it triggers some browsers to enter Quirks Mode); (4) the doctype has incorrect syntax.
Fix
Add <!DOCTYPE html> as the absolute first line of the HTML document, before the <html> tag. Remove any old HTML4 or XHTML doctypes. Ensure no whitespace, comments, or BOM markers precede the doctype. For framework projects: verify in the root HTML template file, and confirm in the rendered HTML by viewing page source in the browser.
Explain
The DOCTYPE declaration tells the browser which version of HTML the document uses. <!DOCTYPE html> activates Standards Mode (also called Full Standards Mode) in all modern browsers, ensuring consistent rendering behavior. Without it, browsers enter Quirks Mode to emulate old IE behavior — a compatibility mode that changes the box model, float clearing, table rendering, and other CSS behaviors. The HTML5 doctype was intentionally made simple (just <!DOCTYPE html>) to replace the verbose HTML4/XHTML doctypes that required a full DTD URL.
Code Review
Review templates, server-rendered HTML, and shared components that output markup related to Use the HTML5 doctype. 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.
常见问题
没有 doctype 会怎样?
浏览器会切换到怪异模式(quirks mode),这是一种旧的兼容模式,布局和脚本可能会出现无法预测的行为。
应该在哪里检查?
这项技能说明,应检查浏览器接收到的原始 HTML,例如框架中的根模板。
它之前可以有其他内容吗?
不可以。这项技能说明,声明之前不应有任何内容,哪怕是空白字符。
详情
作者的原始描述
Use when applies to all HTML documents. Always check the very first line of the raw HTML source (view-source: or DevTools > Network > Response). In SSR frameworks, check the root HTML template (e.g., _document.tsx in Next.js, index.html in Vite/Vue, application.html.erb in Rails). The doctype is not a tag — it is a declaration and does not need a closing tag.
热度
- GitHub 星标
- 75k
- 排名
- #2819
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。