Linking to the style sheet


#1

Can anyone tell me where I should place the link element to the style sheet in the index.html file I mean should I place in the head or in the body and thanks.


#2

You want to add the <link> into the <head>.


#3

But why when I tried to add the link in the body in my editor it worked ?


#4

You can put stylesheet <link> in the <head> or <body>. Typically, you will find the main stylesheet in the <head>. Why?

When the browser gets to the <body>, that’s the content section. It will start rendering that onto the screen. We like to have our styles loaded to ensure that what is being displayed on the screen matches what we want. Why?

Imagine that you wait to load the stylesheet later after the content (or some content) has already been displayed in the browser for the viewer. It will not look styled. And then bam, the stylesheet loads and the web page changes stylistically. That restyling looks weird and glitchy to the viewer. It’s not a good experience for them.

Does that make sense?


#5

#6

Thank you so much for your help. Yes,now I understand why we should link in the because we want our code to be organised and we want our browser to do exactly what we want so it doesn’t get glitchy. Thanks alot


#7

Bingo, you got it. You are building a solid user’s experience and want to ensure that the person viewing your website sees it the way you intended. Cheers


#8

Thank you so much. You are a great mentor. Thanks for being here.


#9

Aww, that’s very kind of you to say. Glad to help you out.


#10

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.