Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,795 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.