Where do style sheets live?

In the intro to HTML, we are taken through styling basics. CSS is mentioned briefly as the being the information that gves the web page structure (colour, etc). I get that but where does the CSS actually come from? Is the CSS file stored in the server along with the HTML file and when the client requests the HTML for the page, the associated CSS is sent with it as a separate file? Or, is it that the CSS is sort of worked into the HTML and the two sets of data are sent to the client as one single file?

Thinking about my own web use, there have been times when I’ve navigated to a page and part (or more) of it hasn’t got any styling, just raw HTML and then I hit refresh (sending a new request to the server?) and the CSS loads in as it should.

Yes, both are files held on the server in whatever folder we uploaded them to. Usually CSS is kept in its own folder, just off the site root:

site_root/index.html  <-- home page

When a request is first received, the requested page is retrieved and if there is any preprocessing to be done, it is done on the temporarily held file. The returned page is raw HTML. The CSS does not come down with that page. It is the page that once loaded will then request the CSS file. That’s what the LINK element in the head is for.


This response is really helpful; thank you!! :star_struck:

1 Like