Quantcast

Document Type Declarations in HTML5

Document type declaration is needed at the top of each web page in HTML5. Without specifying a ‘doctype’, your HTML just isn’t valid HTML and most browsers viewing them will switch to ‘quirks mode’, which means that they won’t understand the document and hence perform any random operation. The document declaration for HTML5 looks like this:

Two most important elements to be mentioned in document type declaration are language and content types. You should identify the primary language of a document either through an HTTP header or with the xml:lang attribute inside the opening html tag. Although this is not necessary to produce a valid HMTL document, it is an accessibility consideration. The value is an abbreviation, such as ‘en’ (English), ‘fr’ (French), ‘de’ (German) or ‘mg’ (Malagasy).

The declaration for a document with primarily English content for example would look like this:

After declaring a primary language, if you use languages other than that in your content, you should further use the xml:lang attribute in-line (such as <span xml:lang=”de”>HTML Hund</span>).

Content types include the media type and character set of an HTML document. These things are specified in an HTML header such as:

The first part (in this example, the text/html bit) is the MIME type of the file, and this lets the browser know what media type a file is and therefore what to do with it. All files have some kind of MIME type. A JPEG image is image/jpeg, a CSS file is text/css and the type generally used for HTML is text/html.

Perhaps the easiest way to set an HTTP header (or mimic it) is to use an ‘HTTP-equivalent’ meta tag in the HTML, which would look something like this:

Slightly more complicated, but preferable (due to it being a proper HTTP header AND cutting down on HTML), is to send the header by using a server-side scripting language. With PHP, you might use something like this:

If you don’t want to (or can’t) use a server-side scripting language, you might be able to go straight to the server with an ‘.htaccess’ file. Most servers (Apache compatible) can have a small text file with the file name ‘.htaccess’ that sits in the root directory and with the following line in it, you can associate all files with the extension ‘.html’ with a MIME type and character set:

Document types are the crucial and essential part of an HTML document without which the document cannot be considered complete. Skipping these declarations can kill the purpose of the entire web page.

Looking for a quality hosting service? here are a few I suggest.
BlueHost | HostGator | Media Temple
Admin
Admin
Ali has been an entrepreneur in web, video and related technologies. Having worked with many business across the globe, Ali stands truly a great pillar in the business working with him.