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 trialJesse Vorvick
6,047 PointsIs <!doctype html> really necessary?
When I was first learning basic HTML5, I remember there was a lot more code before the opening html tag besides <!doctype html>. I was later told that this is unnecessary, and that nothing is needed before the opening html tag because nowadays browsers already know when they are being presented with HTML code. I tried deleting the <!doctype html> tag in this workspace and sure enough, the page loaded just fine. Can someone please explain this to me?
4 Answers
Steven Parker
231,268 PointsAs you had heard, browsers will let you get away without a doctype declaration. But it is "best practice" to always include it, and as you noticed, the modern HTML5 version is much more compact and easier to include than before.
Jesse Vorvick
6,047 PointsInteresting! Thanks for the detailed replies!
Jamie Gobeille
Full Stack JavaScript Techdegree Graduate 19,573 PointsIt is not required but highly recommended to do so.
https://stackoverflow.com/questions/1818587/what-is-the-functionality-of-doctype
Jesse Vorvick
6,047 PointsGreat, thanks! Do we include it so that older versions of browsers can read the code properly? Or are there problems that occur with more complex projects if it isn't included? Thanks.
Steven Parker
231,268 PointsThe HTML specs say that A DOCTYPE is a required preamble.
But it also explains that:
DOCTYPEs are required for legacy reasons. When omitted, browsers tend to use a different rendering mode that is incompatible with some specifications. Including the DOCTYPE in a document ensures that the browser makes a best-effort attempt at following the relevant specifications.