Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Juan Guillermo Mariño
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Juan Guillermo Mariño
Front End Web Development Techdegree Graduate 19,423 Points

Is it really necesary to always put the <!DOCTYPE html> element?

I understood that the <!DOCTYPE html> tag must always be the first thing on the page and always be at the top so the browser can understand what kind of content to expect in the page. Is it really that necesary ALL THE TIME?

2 Answers

Doug Swift
Doug Swift
7,803 Points

It is necessary if you are working with HTML and especially HTML5 so the Browser renders the page in Standards mode. Without it, the browser is forced to render in quarks mode. The DOCTYPE has no other purpose and is therefore optional for XML because documents with an XML media type are always handled in standards mode.

it is an instruction to the web browser about what version of the markup language the page is written in. The doctype declaration refers to a Document Type Definition dtd.