Does it make any difference where you place your css

2 replies
  • WEB DESIGN
  • |
Hello Fellow Warriors...

I'm putting together a large number of templates that require css...

My question is this...

Is it easier to place css in it's own file? (e.g. style.css)

or is it easier to place the css directly inside the template page between the header tags?

I'm still pretty new at css and I am leaning more towards placing the css in between the header tags of my template page just to cut down on the number of files that I create when designing.

Does it make any difference where you place your css?

Would love to get some feedback from others...thanks
#css #difference #make #place
  • Profile picture of the author Kezz
    I would definitely recommend you have your CSS in a separate file as it will make your life much easier overall.

    1. You'll be able to work on your CSS in one window/tab, while working on your HTML in another.

    If you have your CSS in your head you have to scroll up and down all the time as you're creating and applying classes, which makes it painful to try and return to the correct lines.

    2. If at any time in the future you then want to use that same stylesheet on another page or in another site all together, it is a simple matter of linking that stylesheet. Otherwise you'll have to manually copy and paste your code from head to head to head.

    Keeping your stylesheets separate makes them an easy to use future ready asset.

    3. The actual coding process will take a little less time (due to my first point) and browsers are all used to loading separate stylesheets, so given there being no major downsides, you might as well take the upsides that come with external stylesheets.


    TIP

    Most people write their CSS classes like this:

    .myclass {
    color: #000;
    margin: 10px;
    padding: 5px;
    }

    But the trouble is that all that white space actually adds up to a little extra processing time for the browser.

    You get the best possible performance by having a little white space as possible in your CSS, so the above should instead be written like:

    .myclass {color:#000;margin:10px;padding:5px;}


    Keep having fun learning CSS!
    {{ DiscussionBoard.errors[5165109].message }}
    • Profile picture of the author KevinBurns
      kezz,

      you made some excellent points that I never thought about before.
      especially the extra processing part. never thought of it that way.

      thanks
      {{ DiscussionBoard.errors[5165173].message }}

Trending Topics