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

HTML How to Make a Website Creating HTML Content Include External CSS

Tony Brown
PLUS
Tony Brown
Courses Plus Student 1,678 Points

Why do we use the rel="" and href="" for normalize.css, and not src="" like we did with the images?

Both are coming from our sidebar. Why are the attributes different?

Montalvo Miguelo
Montalvo Miguelo
24,789 Points

The rel attribute specifies that you are adding an stylesheet. The href specifies where is located your stylesheet

<link rel="stylesheet" href="app.css">

For images you use the src attribute to set where is the image located.

<img src="img/logo.png" alt="">
Tony Brown
Tony Brown
Courses Plus Student 1,678 Points

Right, but if the stylesheet is located locally and not on an external link, then it's more or less in the same spot as the images. Why must we use ---- link rel="stylesheet" href="css/normalize.css" ---- instead of ---- link rel="stylesheet" src="css/normalize.css" ----

???

1 Answer

Floyd Orr
Floyd Orr
11,723 Points

There is a differentiation between src and href and they can't be used interchangeably. We use src for replaced elements while href for establishing a relationship between the referencing document and an external resource.

href attribute specifies the location of a Web resource thus defining a link or relationship between the current element (in case of anchor a) or current document (in case of link) and the destination anchor or resource defined by this attribute. When we write:

<link href="style.css" rel="stylesheet" /> The browser understands that this resource is a stylesheet and the processing parsing of the page is not paused (rendering might be paused since the browser needs the style rules to paint and render the page). It is not similar to dumping the contents of the css file inside the style tag. (Hence is is advisable to use link rather than @import for attaching stylesheets to your html document.)

src attribute just embeds the resource in the current document at the location of the element's definition. For eg. When the browser finds

<script src="script.js"></script> The loading and processing of the page is paused until this the browser fetches, compiles and executes the file. It is similar to dumping the contents of the js file inside the script tag. Similar is the case with img tag. It is an empty tag and the content, that should come inside it, is defined by the src attribute. The browser pauses the loading until it fetches and loads the image. [so is the case with iframe]

This is the reason why it is advisable to load all JavaScript files at the bottom (before the </body> tag)

Tony Brown
Tony Brown
Courses Plus Student 1,678 Points

It's all a bit over my head as of yet, but I think I got that. Thanks!