简体   繁体   中英

What DocType should I use for my webapp?

I'm confused with HTML and XHTML specifications, which of these should I chose from and why.

For example, a web application written in PHP that searches an image database and shows matches in a dynamic way (something like an infinite scroll) should use what kind of doctype?

You should use the newest, HTML5.

<!DOCTYPE html>

Not only is it the easiest to remember, but it is the newest version of the language, containing many improvements. The difference with HTML and XHTML is mainly in the restrictions you have in your coding style. XHTML technically has to be HTML. However, for many reasons , this doesn't make sense, and as such you might as well use HTML. That doesn't mean you can't follow proper syntax though (like closing the tags in the order they were opened).

Your choice of doctype has nothing to do with the language or applications you will be using. It's purpose is to indicate to the browser the document's type definition, that is, the "type" of the tags used in the web page; similar to how "type" is used in programming languages. However, browsers do not look this up on the internet cause it's built in to the browser program and, nowadays, it's only used to indicate whether the browser should be in "standards mode" or "quirks mode". So the choice is HTML or XHTML.

The new doctype, as shown above, can be used with either HTML or XHTML. If you were to use one of the previous doctypes, you would have to use the HTML 4.01 version for HTML, or the XHTML version if you are serving your markup as XHTML (and not HTML).

Far too often we see people using the XHTML doctype but serving the pages as HTML. Browsers treat that markup as "tag soup" or "broken HTML" because XHTML is an application of XML.

New web pages have no use for the "transitional" version as that is for web pages that are "transitioning" from using older, deprecated markup to current standards compliance. It allows current pages to validate even though the elements contained are deprecated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM