将我的网站转换为 html5
目前我的网站采用严格的 XHTML 编码。是否可以仅通过更改doctypes将其转换为HTML5?或者我还需要做其他改变吗?
Currently I have my website coded in XHTML strict. Can it be converted to HTML5 only by changing doctypes? Or are there other changes I need to make?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查您的网站是否兼容 html5 的一个非常有用的工具是 W3C 标记验证器。如果您将 doctype 更新为
,然后通过验证器运行 html,它将显示 html 当前与 html5 不兼容的所有实例。
这很可能包括更改一些自关闭标签,某些属性可能已更改,如果您确实希望 html5 保持最新(而不仅仅是兼容),您应该考虑使用
更新还可能使您的页面在不兼容的浏览器上看起来有所不同,在这种情况下,我建议使用 html5shiv,以便旧版本的IE 支持您正在使用的新标签。
A really useful tool for checking if your site is html5 compatible is the W3C Markup Validator. If you update the doctype to
<!DOCTYPE html>
and then run the html through the validator, it will show you all instances of where your html is not currently compatible with html5.This will most likely include changing some self closing tags, some properties may have changed and if you truly want to be html5 up to date (rather than just compatible) you should consider using the
<header>, <nav>, <section>, <article>
tags, instead of just normal divs.Updating may also make your page look different on non compatible browsers, in this case I recommend using html5shiv so that older versions of IE support the new tags that you're using.
如果您想要“真正的”HTML5,例如菜单、部分、页脚等,您还必须更改许多标签元素...
此外,它可能需要对 CSS 进行一些更改,因为在 HTML5 中,所有元素都有 div 的属性。
您需要使用一些脚本来支持旧 IE 中的 HTML5。
You also have to change many tag elements if you want "true" HTML5 such as menu, section, footer...
Also it may require some changes in CSS as in HTML5 all elements have div's properties.
And you'll need to use some scripts to support HTML5 in old IEs.
XHTML 在 HTML5 中工作得很好,被昵称为“XHTML5”,但是,如果您不将其作为 application/xhtml+xml 提供,那么您就无法获得任何这些优势。如果您不提供 XHTML 服务,那么您就不应该使用 XHTML。仅仅更改文档类型也不会获得任何好处,除非您要重写当前页面并添加一些新元素、使用 API 等等。
如果您只想随着时间的推移进行逐步转换,则可以交换文档类型,并且您可能不会注意到任何差异。通过验证器运行它以检查错误。在继续之前修复您的错误。
XHTML works fine in HTML5 and is nicknamed 'XHTML5' but, if you're not serving it as application/xhtml+xml, then you're not getting any of those advantages. You shouldn't be using XHTML if you're not serving as such anyway. You're also not gaining anything by just changing the doctype unless you're going to rewrite the current page and add some new elements, use APIs, and all that.
If you are only going to do a step-by-step conversion over time, you can swap doctypes and you probably won't notice any difference. Run it through the validator to check for errors. Fix your errors before moving on.