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
Kat Ingalls
1,593 PointsHTML document setup
Super beginner question but: In first exercise here, the page displayed fine without specifying DOCTYPE or using <html> tags. So why do you include these elements when setting up your html file? Are they really necessary? Or is it just "good practice?" Thanks!
4 Answers
Dustin Matlock
33,856 PointsHi Kat, a doctype tells a web browser what version of HTML you're using. Without the doctype, a web browser could go into quirks mode, which is an attempt to render the page as close as possible to the HTML version it thinks you're using. A doctype is essentially a set of rules the browser goes by to compare and render your code against.
HTML Versions Timeline & Comparison
Chris McKay
2,401 PointsThat's a very good question. Specifying the Doctype is very important. Please see http://www.w3.org/QA/Tips/Doctype and http://www.w3schools.com/tags/tag_doctype.asp
The tags are optional and will depend on the services that you are interacting with. For example, if you want your content to be properly indexed by search engines and social media sites, you will want to ensure you use proper metatags. For example, let's say you wanted your content to be displayed as a summary card with a large image on twitter when someone linked to it, vs just the regular link, you would need to include certain metatags - https://dev.twitter.com/cards/types/summary-large-image
Browsers and OSes will also use data from the metatags to determine how your content is displayed. For example, notice that mobile safari has specific metatags that affect how the user can view and interact with the content.
Here is a good overview of metatags you may or may not want to include in your documents - http://www.sitepoint.com/meta-tags-html-basics-best-practices/
Kat Ingalls
1,593 PointsThanks Chris & Dustin Both of your explanations were really helpful. I think I was missing the idea that there's different 'types' of HTML that you could specify. Obviously as I'm starting out I'm just being introduced to 'html', which makes sense but was a little confusing. The w3schools page helped a lot. Thanks again!
Dustin Matlock
33,856 PointsHey Kat, the story goes a ways back—even to the point of being somewhat controversial. However, it may help to know the history.