Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What DOCTYPE is recommended for my HTML output for IE7/IE8/FF3+? and how can I update my HTML validation in Visual Studio to reflect that change?

I noticed that Visual Studio defaults the DOCTYPE to XHTML 1.0 Transitional. This seems okay, but I think that's more of a standard for "generation 6" browsers. We're now in gen 7 and 8 browsers, and I'm wondering what DOCTYPE I should be putting in my HTML.

On a related note: Is there a way to add other DOCTYPEs to the HTML validation in Visual Studio 2008? Tools > Options > Text Editor > HTML > Validation

like image 341
Ben Lesh Avatar asked Dec 16 '09 15:12

Ben Lesh


5 Answers

<!doctype html>

is the way to go. This works fine in all decent browsers, including IE6 (not that it is a decent one though). Also see http://hsivonen.iki.fi/doctype/ for more background info and a browser behaviour table.

You could also consider XHTML strict, but why would you massage clean HTML into a XML format? It is only interesting if you want to parse/generate/validate HTML using some XML tool, which often isn't the case in real world. Google also just uses <!doctype html> and Stackoverflow uses nicely HTML strict.

like image 82
BalusC Avatar answered Nov 15 '22 06:11

BalusC


Note to anyone else reading this thread looking for answers: I've just discovered that the declaration for HTML 5 is simply <!DOCTYPE HTML> nothing fancy there, really.

Also, to add HTML5 validation to Visual Studio 2008 I found this article. It's working pretty well so far.

Other things to note: Visual Studio adds xmlns="http://www.w3.org/1999/xhtml" to your <html> tag, and you probably don't want/need that in there if you're going for HTML5.

Thanks guys for pointing me in the right direction.

like image 44
Ben Lesh Avatar answered Nov 15 '22 05:11

Ben Lesh


First of all you probably want to avoid the Transitional Doctype for new content. Transitional is intended for legacy content that needs to be thoroughly altered before confirming to the strict DTDs but this isn't an issue for new documents.

Furthermore, at least in my experience XHTML generates more trouble than it's beneficial. Unless you require XHTML for some things (such as allowing XML parsers to read your site [but even then chances are that it doesn't validate and therefore is unsuitable for that]) I'd recommend sticking to HTML 4 Strict. Also XHTML needs special attention with IE, even in IE 8.

like image 2
Joey Avatar answered Nov 15 '22 07:11

Joey


Personally I'd go for either XHTML 1.0 Strict or HTML 4.01 Strict.

Unless you're literally "transitioning" from using older versions of HTML, it doesn't make much sense to use the transitional doctype.

XHTML 1.1 is also an option however you'll need to ensure you're serving your document with a application/xhtml+xml MIME type.

HTML 5 is still very new but could be an option if you're putting out something cutting edge that you only expect to work in the most up-to-date browsers.

The schemas for Visual Studio are usually kept in:

C:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\schemas\html

I beleive you can add new ones in here as needed. I'll post more details on this as I find it.

like image 2
Jamie Dixon Avatar answered Nov 15 '22 05:11

Jamie Dixon


You should be using a Strict doctype. Whether that's HTML 4.01 Strict or XHTML 1.0 Strict is up to you. Lately I've personally been using the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">

I really like the way RDFa works. It bolts onto HTML more cleanly than microformats by defining its own attributes rather than overloading the class and title attributes. But because RDFa is still not really consumable like microformats are, I'm using both alongside each other.

like image 1
Scott Avatar answered Nov 15 '22 07:11

Scott