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

CSS How to Make a Website CSS: Cascading Style Sheets Use ID Selectors

Doug Tvedt
Doug Tvedt
5,354 Points

Why don't I have to identify the !DOCTYPE with css files?

I had to identify an html document type has !DOCTYPE html. I'm just curious why this document identifier is not required for CSS files.

3 Answers

Because DOCTYPE declarations are for HTML based documents. The DOCTYPE informs the browser what version of HTML to expect, and allows the browser to render the content correctly. These days, most people use the HTML5 DOCTYPE

<!DOCTYPE html> 

But pre HTML5 it was not uncommon to see HTML 4.01 DOCTYPE declarations that used Strict or Transitional or even XHTML 1.0 Strict or Transitional.

HTML 4.01 Strict

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 

HTML 4.01 Transitional

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 

XHTML 1.0 Strict

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

XHTML 1.0 Transitional

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

You can see how much easier HTML5 has made it with it's shortened DOCTYPE declaration, but by looking at the other DOCTYPEs you can also see how they declare to the browser what to expect, and Strict vs. Transitional can also have an impact on how your code validates with the W3C. Strict does not allow certain elements and attributes where transitional was a bit more loose.

Ryan Field
Ryan Field
Courses Plus Student 21,242 Points

In addition to what Mike has said above, you also don't need to declare a DOCTYPE for CSS and other files because they are actually loaded and read into the page by your putting a <link rel="stylesheet" ... > in the head of your document. The browser loads your HTML, and then when it finds one of these links, it requests the contents of that fine and they are basically added to your page in the order they are requested. This is partly why it matters what order your CSS links are inserted.

Doug Tvedt
Doug Tvedt
5,354 Points

Thanks for the responses guys. That makes sense. I didn't realize DOCTYPE was only to identify the html version. Sounds like HTML5 was a positive step forward.