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 trialTony Brown
Courses Plus Student 1,678 PointsInstead of using @import in the external css, couldn't we reference the normalizing stylesheet in the head of the html?
Instead of using @import in the external css, couldn't we reference the normalizing stylesheet in the head of the html using a style element, like below?
Instead of have the following at the top of the external css file to normalize the css: @import "import-styles.css";
Couldn't we also do the following inside the head of the html?
<link rel="stylesheet" href="css/import-styles.css">
<link rel="stylesheet" href="css/style.css">
2 Answers
Ryan Field
Courses Plus Student 21,242 PointsYou certainly could, and in fact, if you have a lot of CSS files, that way might be better since the @import
directive causes the browser to make another call instead of loading it asynchronously. With CSS preprocessors like Sass, this is less of an issue since all your CSS goes in one file, but in general, I believe it is best practice to refrain from making too many @import
calls.
Guil Hernandez
Treehouse TeacherHi Anthony Brown,
Sure you can. They both require an extra request to the server – they're just being made from different locations.
In most cases, you're better off linking a style sheet since @import
blocks parallel downloading. The browser has to wait to @import
a file before downloading the rest of the file...
Tony Brown
Courses Plus Student 1,678 PointsThanks, Guil! But I went and tried using the link element and the styles didn't apply to page. Any thoughts?
Tony Brown
Courses Plus Student 1,678 PointsTony Brown
Courses Plus Student 1,678 PointsThanks, Ryan!