5 Ways to Write Better CSS

5 Ways to Instantly Write Better CSS

Feb 16th, 2009 in HTML & CSS by Trevor Davis

Sure, anyone can write CSS. Even programs are doing it for you now. But is the CSS any good? Here are 5 tips to start improving yours.

PG

Author: Trevor Davis

Hi, I’m Trevor Davis, and I make websites. I’m obsessed with them; it’s a problem. I’m a 24 year old Front-End Developer living in Alexandria, VA. I work full-time at Matrix Group International and freelance on the side. I specialize in CSS, HTML, jQuery and WordPress. I spend a lot of my time writing blog articles, building websites, playing basketball, and watching movies.

1. Reset

Seriously, always use a reset of some sort. Whether you are using the Eric Meyer Reset, the YUI Reset, or your own custom reset, just use something.

It can be as simple as removing the margin and padding from all elements:

html, body, div, h1, h2, h3, h4, h5, h6, ul, ol, dl, li, dt, dd, p, blockquote,
pre, form, fieldset, table, th, td { margin: 0; padding: 0; }

The Eric Meyer and YUI Resets are awesome, but to me, they just go too far. I feel like you end up resetting everything, and then redefining a lot of properties on the elements. This is why Eric Meyer recommends that you should not just take his reset stylesheet and drop it in your projects if there is a more effective way of using it. Tweak it. Build on it. Make it your own.

Oh and please, stop this:

* { margin: 0; padding: 0; }

It takes more time to process, and what do you think should happen to a radio button when you remove the padding? Form elements can sometimes do some funky things, so it may be best to just leave some of them alone.

2. Alphabetize

A Little Quiz

Which example would you think is faster to find the margin-right property?

Example 1

div#header h1 {
	z-index: 101;
	color: #000;
	position: relative;
	line-height: 24px;
	margin-right: 48px;
	border-bottom: 1px solid #dedede;
	font-size: 18px;
}

Example 2

div#header h1 {
	border-bottom: 1px solid #dedede;
	color: #000;
	font-size: 18px;
	line-height: 24px;
	margin-right: 48px;
	position: relative;
	z-index: 101;
}

You can’t tell me that Example 2 isn’t faster. By alphabetizing your properties, you are creating this consistency that will help you reduce the time you spend searching for a specific property.

I know some people who organize one way and others who organize another, but at my company, we made a consensus decision to all organize alphabetically. It has definitely helped when working with other people’s code. I cringe every time I go into a stylesheet where the properties are not sorted alphabetically.

3. Organization

You should organize your stylesheet so that it is easy to find things and related items are close together. Use comments effectively. For example, this is how I structure my stylesheets:

/*****Reset*****/
Remove margin and padding from elements

/*****Basic Elements*****/
Define styles for basic elements: body, h1-h6, ul, ol, a, p, etc.

/*****Generic Classes*****/
Define styles for simple things like floating to the sides, removing a bottom margin on elements, etc
Yes, these may not be as semantic as we would all like, but they are necessary for coding efficiently 

/*****Basic Layout*****/
Define the basic template: header, footer, etc. Elements that help to define the basic layout of the site

/*****Header*****/
Define all elements in the header

/*****Content*****/
Define all elements in the content area

/*****Footer*****/
Define all elements in the footer

/*****Etc*****/
Continue to define the other sections one by one

By using comments and grouping similar elements, it becomes much quicker to find what you are looking for.

4. Consistency

Whatever way you decide to code, stick with it. I am sick and tired of the whole 1 line vs. multiple lines for your CSS debate. There is no debate! Everyone has their own opinion, so pick what works for you and stick with it throughout the stylesheet.

Personally, I use a combination of both. If a selector is going to have more than 3 properties, I break it to multiple lines:

div#header { float: left; width: 100%; }
div#header div.column {
	border-right: 1px solid #ccc;
	float: right;
	margin-right: 50px;
	padding: 10px;
	width: 300px;
}
div#header h1 { float: left; position: relative; width: 250px; }

It works for me because 3 properties is about what fits on 1 line in my text editor before wrapping to another line. So just figure out what works for you and be consistent.

5. Start in the right place

Don’t you dare touch your stylesheet until you have written your markup!

When I am preparing to slice a site, I go through and mark-up the entire document from the opening body tag to the closing body tag before even creating a CSS file. I don’t add any superfluous divs, ids, or classes. I will add some generic divs like header, content, footer because I know these things are going to exist.

By marking up the document first, you won’t run into such diseases as divitis and classitis, which can sometimes be fatal! You only need to add in that stuff once you have begun to write the CSS and realize that you are going to need another hook to accomplish what you are trying to achieve.

Utilize CSS’s descendant selectors to target children elements; don’t just automatically add a class or id to the element. Just remember, CSS is worthless without a well formatted document.

*Editor's Note: I can't stress this point enough. As Trevor said, don't even touch your CSS file until the markup is 100% complete.

Conclusion

These are just some of the tips that help me to write better code. This is by no means the end of the list. As I come up with others, I’ll share.

What tips do you have for writing better CSS?


Related Posts

Check out some more great tutorials and articles that you might like

Enjoy this Post?

Your vote will help us grow this site and provide even more awesomeness

Plus Members

Source Files, Bonus Tutorials and
More for $9 a month for all TUTS+
sites in one subscription.

Join Now

User Comments

( ADD YOURS )
  1. PG

    Jack F February 16th

    Enjoyed this list, thanks. Personally I write my CSS on one line, but I’m fortunate to have a wide enough screen to fit lots of them on.

    I do need to organise my stylesheet better though for sure.

    Thanks!

    ( Reply )
  2. PG

    Shane February 16th

    I am keen on laying out my CSS in a particular way. All my recent built sites are like that although mine isnt! oops! Resetting too is a good valuable practise

    ( Reply )
  3. PG

    Patternhead February 16th

    Some sensible advice here. Not everything works for me. Alpabetize is just not needed in my opinion.

    ( Reply )
    1. PG

      Mike Smith March 3rd

      Yeah, the Alphabetize option isn’t working for me either. I have a set way of writing styles and am so used to it, if it was different I’d go nuts.lol

      But I agree, a really nice post

      ( Reply )
      1. PG

        Jan March 13th

        I also dont care much about the alphabetizing. I know i should because it really would be a lot more organized but i kind of am to lazy to write down everything following the alphabet.

        But nice and helpful tips here. I like to seperate each area (e.g. Header, Footer…) with commented lines, to get a better overview what the whole area contains.

        Nice!

    2. PG

      Rajaji November 4th

      I agree to that 100%! Alphabetically arranging is just not needed here. Rarely there are more than 5-6 properties in a class or id so to me there is no need.

      I have been lately using the CSS Reset and I am proud to say that now I have much better control.

      Thanks for this very useful article!

      ( Reply )
  4. PG

    cccmien February 16th

    I tend to use indentation when styling nested (child) elements. It works quite well for me when it comes to finding a specific property.

    ( Reply )
    1. PG

      ham June 8th

      I agree. I have started using indentation when writing out my stylesheets and it works way better then I ever thought it would.

      ( Reply )
  5. PG

    Bernd Artmüller February 16th

    thanks for writing this article. i am already working this way, but the first tip is great. i’ll consider it on the next projects

    ( Reply )
  6. PG

    Richard February 16th

    Think I might try ordering my properties. Didn’t like it when I read it but by the time I finished the article I have warmed up to it.

    Also I am one line per property kind of guy but I’m liking the whole if it isn’t more than 3 properties long keep it on one line.

    Cool content as ever NT. Thanks!

    ( Reply )
  7. PG

    Ben Reid February 16th

    1. I always have a reset stylesheet.

    2. I normally order them by my own kind of logic so something like width, height, padding, margin, backgrounds, borders etc…

    3. Organization is key, especially when you have multiple people working on the same stylesheet.

    4. Yes! Essential, I’m a bit OCD with it.

    5. Yup!

    And all my styles are written in one line, I used to do them in big blocks but have turned to the line side!

    ( Reply )
  8. PG

    Nick Reffitt February 16th

    Excellent article, I can definately feel a sense of frustration :)

    Good idea to list the properties in a style alphabetically which I’ll certainly use in future projects. I should really be using a reset too :(

    ( Reply )
  9. PG

    insic February 16th

    Cool list of tips. reset is really necessary indeed.

    ( Reply )
    1. PG

      crazyaccess March 27th

      hi!

      Looking very nice

      ( Reply )
      1. PG

        Michal Kopanski May 13th

        LOL.

        Didn’t realize Net.Tut+ was a dating site =x

        Cool tips.

  10. PG

    nutral February 16th

    I always use multiple lines, even when its just one property. I don’t really think its necessary to alphabetize all the css.

    ( Reply )
  11. PG

    Pix February 16th

    i’m making some experiment about css organization and now i’m all for dividing them by function:

    - one for build a layout (just margin padding… spaces in general)
    - one for typography (anything is about letters and fonts)
    - one for colors (bg-color, line colors)

    in this way it happens sometimes i find mysel writing twice an instructions, and i’m not sure this is even a good way to organize css but as i said before i like to experiment

    ( Reply )
  12. PG

    Nathan Davies February 16th

    Great tips, though I write the CSS before the site. Allow me to explain. I sketch the site layout(s) and then slice them up on paper, calculating measurements and deciding link behaviour etc. I also have some standard stuff for handling forms layout that appears in every stylesheet.

    Using the sketch and notes I code the style and then the site and test.

    I also split my style – layout and colour into 2 sheets, plus one for print. This makes changing colour really straight forward and ammending layout means I don’t have the colour definitions to scan through.

    ( Reply )
  13. PG

    Stephen Coley February 16th

    Concerning #2… separating width and height would drive me up the wall. If I were positioning with top and left, I would want to keep position top and left together as well. I think #2 might have just been a personal preference. It seems kind of counter intuitive.

    ( Reply )
  14. PG

    Fred Soler February 16th

    Essential to work in team.
    Nice.

    ( Reply )
  15. PG

    Son NH February 16th

    I agree with Patternhead. Alphabetize is good idea but not necessary and sometime waste your time in my opinion. When you write CSS, sometime you don’t know which property should be put to the code. You can only alphabetize the CSS once you know exactly all properties of each selector.

    ( Reply )
    1. PG

      Rob April 6th

      Exactly! When I write CSS, I don’t know which properties I’m going to use for each CSS style, so alphebetizing doesn’t always work. And. I’m certainly not going to go through 200 CSS styles to start re-arranging and alphebetizing properties. But I do think organization is helpful in anything that we do.

      ( Reply )
      1. PG

        Arowolo November 9th

        Alphabetizing properties is not going to work. but Alphabetizing selector, classes or Ids might work.

        Organizing your css by commenting sections of your style sheet should just do fine.

        Great job…

  16. PG

    Spence February 16th

    Nice article, think putting them in alphabetical order is a bit over the top though!

    ( Reply )
  17. PG

    Shuja Shabandri February 16th

    Nice post.

    Regarding #3
    You can use @group style

    /* @group Header */

    .css-code-here {}

    /* @end */

    Good CSS editors like CSS Edit, coda and i think many others support this style of grouping.

    These groups actually show up in the sidebar using which you can easily navigate.

    ( Reply )
    1. PG

      donna April 5th

      @Shuja Good tip I didn’t know about! I use CSS Edit and I’ll try the @group style, sounds like it will be really helpful. Thanks for posting that!

      ( Reply )
  18. PG

    Jayphen February 16th

    Nice tips, but alphabetising is going a bit far I think. The extra time spent thinking about the order of your properties will just slow you down too much for what it’s worth. Editing the stylesheet in the future will also be just that much more annoying if you have to work out where to put in the new property & value. Generally there are no more than 10 properties for each selector anyway, so it’s not like you have to search through a long list to find what you’re looking for.

    ( Reply )
  19. PG

    gareth hunt February 16th

    This article is a bit of an oversimplification.

    Firstly, there is no real benefit in alphabetising your css. If I’m changing styles related to the box model or positioning of an element then it’s not necessarily any easier to have to skip across the declarations to find the relevant styles. In contrast, many people will use their own ordering. I use one that orders styles on positioning, then box model (from inside to out), then font declarations, etc. A lot of people will group related styles because of the inherent way in which you code. If you choose to alphabetise, then so be it, but a lot of us will cringe at alphabetised CSS too. It’s the same as the “one line, new line” argument…but in this case there is actual logic to organising based on the inherent relatedness of css properties rather than using an external ordering system such as the alphabet :P

    While the case for writing all html before any css is worthy, in practice, it’s not something that experienced developers will do. I’d also guess that people guilty of using too many extra elements are not going to have that much more success either, for until their knowledge of css is improved, they are likely to go back and add extra markup to achieve the desired visual effect. Experienced developers are also going to be regularly diving into the html to add new elements, change the source based on client decisions, and will know how to achieve certain effects with the absolute minimum of html. And if we’re talking about unnecessary or presentational markup, then not using clearing divs or clearing classes should also get a mention ;) .

    Good tips as guidelines for beginners or moderately experienced coders, but the reality is more complex and the organisation of css stylesheets if far more down to personal preference and personal ways of mentally organising and visualising documents.

    ( Reply )
    1. PG

      Heinrich March 18th

      I have to agree on CSS’ing alphabetically. Usually there are only 5 or 6 lines that are being used in a div / class etc. We should stop being lazy!! Otherwise great article. I always try and keep my stylesheet together in a way where I’ve got everything together. Always good to get some CSS tips! You’re never too old or too good to learn!

      ( Reply )
  20. PG

    Nikola February 16th

    nice tips, thanks

    ( Reply )
  21. PG

    Patrik February 16th

    Awesome post, thanks!

    ( Reply )
  22. PG

    Jauhari February 16th

    CSS Rulez! ;)

    ( Reply )
  23. PG

    Xobb February 16th

    I’m not very experienced with CSS, so I find it useful. Thanks.

    ( Reply )
  24. PG

    Dan Harper February 16th

    Good post for beginners. I started alphabetising my properties recently and it definitely makes my code easier to skim through.

    However I’ve found myself occasionally having to run through the alphabet in my head to get some in the right order (makes me sound stupid, I know lol).

    ( Reply )
    1. PG

      Rob April 6th

      Oh DAN! That’s so silly! HAHA..just kidding! You know what…I’ve done that too! So, no worries! I used to do math with my fingers when I was younger.

      ( Reply )
  25. PG

    M.A.Yoosuf February 16th

    its kind of usefull, i was realy doingh the “A Little Quiz” part i was doing in first way, yeah, in future i will not do in future thank you man.

    small small thiungs are changing me to a profersional guy ;)

    ( Reply )
  26. PG

    Amo February 16th

    What this article fails to explain is why certain things should and shouldn’t be done. For example;

    Reset CSS – this is used in an attempt to eliminate the inconsistencies between different browsers, their initial default settings of things such as margins and padding and to reduce the number of conditional CSS attributes as possible. Essentially, it helps to make your site look the same irrespective of the browser.

    Alphabetize – more a personal preference than anything else. I tend to write by CSS slightly differently. Starting with the general layout attributes (positioning, floats etc) and then onto line heights, font-sizes and so on – and finally, colours, borders and fills. The logic behind this is that as the CSS file is interpreted by the browser, it’ll handle the layout of the page before the colours and theme elements – so the user sees the page as it’s intended, quicker.

    Organisation – while it’s important to have well organised CSS, there should be a fine line between having a well commented file, and too many comments. The example given in my opinion has far too many comments which add to the file size of the CSS file and simply increases the page load time.

    During development, comments are good – especially if there are a few people working on a single project, however before going into a live environment CSS should be minified sufficiently to compress the file as much as possible.

    I’d agree to some extent about starting with the document markup and then onto the stylesheet, however it’s not always possible with a complex design and in such instances the two are often developed hand in hand.

    An important note that I feel the article was missing was to ALWAYS encapsulate design within the CSS file, i.e. to never have inline CSS in the main xHTML document.

    ( Reply )
    1. PG

      sebastian March 3rd

      concerning the comments and file size:
      if you develop using multipe style sheets you should combine them into one file and then minimize this file (http://www.maxkiesler.com/index.php/weblog/comments/how_to_minimize_your_javascript_and_css_files_for_faster_page_loads/).

      even if you only work with a single style sheet, minimizing is a good practice. so you can add as many comments as you like =P

      ( Reply )
  27. PG

    Andy Gongea February 16th

    This topic is pretty hard to cover because everyone has some good practices and behaviors.

    Personally I use the float as the first property followed by the width and height. In this way you can keep the visual side accessible.

    I do use the reset but right now I’m not sure if it is needed.

    ( Reply )
  28. PG

    Sammy February 16th

    Your quiz example number 1 doesn’t have any logic (or does it ?), so it’s easy to pretend alphabetizing is best. But it is just one way of doing it, there are others. For example, I like to put in this order: everything positioning related (position, top, left, z-index), width and height (if any), margin and padding together, and at the end all the font properties (color, font-weight, line-height, etc). Different logic. Same consistency.

    ( Reply )
  29. I’m really good at CSS, but I’m surely will make use of some of the tips in this piece.

    ( Reply )
  30. PG

    Will February 16th

    I tend to Organise my code by both alphabetising and by grouping similar properties. Like Stephen said separating Width & Height is ridiculous.

    I first group all related selectors (e.g width & height & padding; font & text-align & text-decoration etc.) and then organise them in to alphabetical order. When you create a system like this it helps to quickly drill down into your code.

    ( Reply )
  31. PG

    OpenSourceHunter February 16th

    Very nice, i will use this info ;)

    greetz

    ( Reply )
  32. PG

    Ethan February 16th

    Very nice! I ply do most of. These things (I’m so proud of myself!) May I ask, what is divitis and classitis? :P

    ( Reply )
    1. PG

      Andy Bishop April 17th

      That’s when you encase anything and everything in divs and classes. In reality you can (and should) add ids and classes to other elements as well.

      ( Reply )
  33. PG

    Bruno Abrantes February 16th

    Nice post, but, as others suggested, everyone has their own practices and quirks when writing CSS. I personally only use multiple line CSS, even if it’s just one property. I find it easier to read. Oh, and really nice tip on the alphabetization thing. It might not be that helpful when you’re on your own, but when coding together with a group it’s invaluable.

    ( Reply )
  34. PG

    garethhunt February 16th

    why was my previous post not included?

    ( Reply )
  35. PG

    DKumar M. February 16th

    I Appreciate the efforts behind titles but there is nothing which can make you Instantly Write Better CSS But i do admit the point you covered in this post is very essential and important for beginners.

    ( Reply )
  36. PG

    Shane Sponagle February 16th

    Good tips. I am happy that I already practice most of them. To alphabetize the properties is a good idea, never thought of that.

    ( Reply )
  37. PG

    Phillip Raffnsøe February 16th

    Very good list!

    Funny how i never thought about alphabetizing my stylesheets! Thanks for sharing that simple yet extremely useful tip.

    Phillip

    ( Reply )
  38. PG

    Alex Righetto February 16th

    I’m very interested about this topic.
    I’m testing several options to get the “perfect css”:

    these are the rules I use:

    1 style with the less numbers of rules
    2 style with the less number of selector
    3 keep it clear
    4 Selectors have different wheight, so let’s display them sequentially
    ex:
    p
    .myclass
    #myid
    5 indent the elements.
    h3{}
    h3.myclass{}
    #myid{}

    so it’s simple to detect rules.

    6.mainly, selectors are displaied in the sequence they appear in html.

    what do you think about my rules?

    it’s an approach that could be more clear.

    ( Reply )
  39. PG

    Vasili February 16th

    I do all of them minus number one. Alphabetizing is so helpful. :D

    ( Reply )
  40. PG

    eddie yang February 16th

    Good post~

    ( Reply )
  41. PG

    James February 16th

    * { margin: 0; padding: 0; }

    I’ve seen no convincing evidence that using the star selector “takes more time to process”. If you can back this up with some empirical evidence on how it affects page load time I’ll be more inclined to believe it, but in the meantime this technique has served me well.

    You’re right to be suspicious about how various browsers will treat styles applied to replaced elements such as radio buttons, especially as the W3C specs are silent on these matters. However, these are marginal cases and are exactly what browser makers spend 1000’s of man hours testing and coding exceptions for. In the unlikely event that it does become a problem in a production-ready browser it can easily be worked around.

    ( Reply )
  42. nice tips! thank you ;)

    ( Reply )
  43. PG

    Shane February 16th

    Good list for CSS beginners – I think the value of 5 cannot be underestimated.

    ( Reply )
  44. PG

    Mark Bowen February 16th

    Alphabetizing would be good I admit but only if you really really have it bred into you otherwise it really really slows you down.

    Also your question about where is it easier to find the margin-right doesn’t really make sense because :

    1 It is in the same place both times (third from bottom) ;-)

    and

    2 You know what you are looking for so will find it quickly anyway.

    I do agree that it can be nice in much more complex examples but does take quite a while to get used to doing that.

    Nice read though.

    Best wishes,

    Mark

    ( Reply )
  45. PG

    Ryan February 16th

    Good call on the alphabetizing. I also agree with using multiple lines. Drives me crazy to open a css file where everything is one line.

    ( Reply )
  46. PG

    Gene February 16th

    nice!

    i really like it.. :D

    ( Reply )
  47. PG

    celebrus February 16th

    I feel the whole alphabetical order thing is overkill.

    ( Reply )
  48. PG

    Shaun February 16th

    A simple but amazingly good list of reminders. Its really easy to get sloppy and let the standards slip!

    ( Reply )
  49. PG

    Alan February 16th

    On the global reset, good call. I used to use it. I now see it more of a problem than a solution. I can’t count the number of various forum posts where someone is asking why ~this~ element has no spacing, only to look at the stylesheet and see the global reset. This of course is mainly due to someone downloading a theme and not quite grasping what CSS is and how it works.

    I do believe that a reset is fine for projects that are not going to be available to the public. Chances are then, that the people editing the pages will have some grasp over the concept of a reset or at least, will have someone on staff who does.

    If a theme author is going to use a reset, they should be responsible enough to redefine all the elements later on in the stylesheet.

    On point five, I think this is purely a personal preference. If I am coding a fixed width centered layout, I will automatically set up the CSS for the HTML, Body and Container. Setting widths, padding and font styles. Same goes for centering or when using a sticky-footer technique.

    If its something as simple as a fixed two-column with header and footer, i will usually write all the structural CSS for those elements before I even open a new HTML document.

    Of course this might be due to experience. If you can look at your layout and code it in your head before you even start slicing the comp, there really isn’t anything wrong with it.

    Personally, I don’t like using things like margin-right or border-left. I would much rather see:

    margin: 0 10px 0 0; or border: solid #000; border-width: 0 0 0 1px;

    Granted, shorthand for the border properties results in more code but, if a client wants something changed in the future, it’s still less code than:

    border-left: 1px solid #000; border-right: 1px solid #000;

    ( Reply )
  50. PG

    andrisetiawan February 16th

    bookmarked ;)

    ( Reply )
  51. PG

    Gary February 16th

    Great tips. I tend to design (but not fully write) the CSS before the markup however. I think that helps me not create lots of divs and classes because I am pre-planning the document structure to work with as few divs and classes and necessary.

    ( Reply )
  52. PG

    Kevin Quillen February 16th

    “* { margin: 0; padding: 0; }

    I’ve seen no convincing evidence that using the star selector “takes more time to process”. If you can back this up with some empirical evidence on how it affects page load time I’ll be more inclined to believe it, but in the meantime this technique has served me well.”

    Ditto. Stats please? I use that single line before starting anything else so that I am almost positive my end result will be near-identical in all browsers. Haven’t been wrong yet..

    ( Reply )
  53. PG

    Matthijn February 16th

    It takes more time to process….

    Yeah, like 2 entire nano seconds.

    ( Reply )
  54. PG

    Alex February 16th

    Nice list, though I disagree on the * taking longer to process. If anything then I would imagine the whole list _typed-out_ is more intensive than just the *, I would be surprised to see stats actually showing a noticeable slowdown (and by noticeable I mean a few seconds, not milli seconds).

    ( Reply )
  55. PG

    Chris February 16th

    I think declaring CSS properties on a single line is an important organizational preference of mine. You can fit more classes and IDs on the screen and people are designed to read from left to right. Declaring each property on a single line is cumbersome, in my opinion.

    Just wanted to add my two cents. Great article!

    ( Reply )
  56. PG

    Keller February 16th

    “like 2 entire nano seconds” Ja thats was funny… i think thats not even close…

    ( Reply )
  57. PG

    Ben Hunsaker February 16th

    Great list. I personally aggree for the most part with number five; however, I tend to develope the html mostly but towards the end I develop them both at the same time. I don’t know if that is good practise or not. I also like grouping the CSS attributes by function and not alphabatizing but that is me working by myself but can deffiantly see if you are working with a group that alphabatizing them. I love all the others. Great work.

    ( Reply )
  58. PG

    FireDart February 16th

    Great list, I already do half of what you say, but the rest is a great idea I, must look into.

    Thanks!

    ( Reply )
  59. PG

    Jonathan Blundell February 16th

    @amo

    Thanks for explaining the CSS Reset. I’d never heard that before and was wondering why it would be important at all.

    I’ll have to start trying it. May help get over *some* of my frustrations with IE.

    ( Reply )
  60. PG

    abdusfauzi February 16th

    hmm. i think, i’m still need to make the use of RESET.css as a habit. It save time a lot and consistency across browser’s war nowadays. :)

    the most important point through out the post : MANAGE YOUR DEVELOPMENT PROCESS.

    nice post. :)

    ( Reply )
  61. PG

    Snookerman February 16th

    1. Reset – I agree that a reset is good, but there is no evidence that the star selector reset takes more time to process. I’ve never had any problems with that or with elements that need their padding.

    2. Alphabetize – Probably the most unnecessary out of these tips. Sure, it’s good to have some order, but alphabetical order is highly arbitrary and doesn’t make much sense.
    In my opinion, it’s much better to order the properties after what they do: width and height, margin and padding, background and color, font-size and line-height, etc.

    3. Organization – This is important but it doesn’t have to be overdone. I usually put things in the same order described but I hardy ever use any comments. Unless the stylesheet is really, really long, a few comments are more than enough, in my opinion.

    4. Consistency – Unless you create your stylesheets by copying and pasting from other people, I don’t think anyone has problems with this. Just write it in a way that makes it easy for you to work with and when you’re done, compress the stylesheet to remove all unnecessary whitespace.

    5. Start in the right place – Could not agree more. If you finish the markup first, it will make it really easy to redesign you site or create an alternate style.

    ( Reply )
  62. PG

    Doug February 16th

    Nice post!

    Although, I don’t like #5. I have to do both at the same time.

    ( Reply )
  63. PG

    Frog February 16th

    CSS shorthand should have behttp://www.thefloatingfrog.co.uk/frog-blog/2008/09/10-css-shorthand-techniques-youll-use-everyday/en included too as the icing:

    ( Reply )
  64. PG

    Nick February 16th

    Great post…I never thought about alphabetizing.

    Now its time to implement what I’ve learned! Thanks.

    ( Reply )
  65. PG

    Idan Smith February 16th

    so true!!

    i’m using the same tactics while i’m coding new page!

    ( Reply )
  66. PG

    John Nemec February 16th

    Great Post… Even though I don’t always alphabetize my code because I’m too busy coding. You still get a link!

    ( Reply )
  67. PG

    Jeremy February 16th

    I still haven’t gotten to the point of alphabetizing my css properties, I just kind of have a *flow* that they always seem to wind up coming out in. Also, I’m not big on writing a css selector’s properties over multiple lines anymore, the CSS document gets way too long and big in file size unless you run it through some sort of compressor later.

    Another helpful thing is CSS indention. If you’re use to doing development, this might come naturally. But I’ll indent “child styles” under parent styles and so forth. Helps a lot.

    ( Reply )
  68. PG

    Timothy February 16th

    Resets are key.

    Oh, and stop hacks. Use IE Conditional comments. Indent properly. And master z-indexing.

    ( Reply )
  69. PG

    Buzzlair Voufincci February 16th

    Always use a category

    “”"”"”"”"”"
    Header
    “”"”"”"”"”"

    and so on….

    ( Reply )
  70. PG

    Raymond Selda February 16th

    Alphabetizing is good but I like my width and height beside each other.

    I used to write in blocks of code then switched to a one liner and now I’m seriously thinking on switching to writing in blocks again after reading this article. hahaha. Each style has its pros and cons and it really boils down to your personal choice.

    Thank you for this post. It serves as a great reminder.

    ( Reply )
  71. PG

    Nicole February 16th

    Those are great 5 ways to write better CSS. Resets are the greatest, but as it says above, stay away from *. I personally use Eric Meyer’s CSS Reset and it works wonders; it decreases time spent on browser compatibility checks. Also what Timothy said, stop the hacks! IE Conditional comments are the way to go if you are having problems.

    I hope everyone looks at this article to produce cleaner and better CSS.

    ( Reply )
  72. PG

    Fernanda February 16th

    I loved your article. I’ve been using those same rules and a little bit more whenever i started a new stylesheet, and it always came as a lot of help.

    ( Reply )
  73. PG

    Marie Poulin February 16th

    Nice tips. I fully agree with you on #4… using a combination of indents with multiple lines makes it really easy to find what you are looking for.
    Cheers!

    ( Reply )
  74. PG

    Michael Thompson February 16th

    Alphabetizing isn’t a personal preference. Neither is indenting. They’re both proper practice and should be used, and if you’re writing your CSS by hand you should be using a text editor that can manage auto-indenting and sorting with a few keystrokes or mouse-clicks.

    Do not maintain your CSS file on one line. That’s absurdly more difficult to work with. The only time to one-line your CSS file is when you release it. Again, your text editor should be able to strip newlines with just a few keystrokes and mouse clicks.

    If any of this is too hard for you, stop writing CSS.

    /troll

    ( Reply )
  75. PG

    Tocki February 16th

    Thanks for the tips. Always interesting to see how others do their work. I like the idea of sorting the CSS alphabeticaly – i always did it in legical groups, what has its limits…

    ( Reply )
  76. PG

    Amrit Hallan February 16th

    There are two tips I can certainly use: alphabetize the definitions, and write the markup first. Although I work both on the markup and style side-by-side, it is a good idea to create the complete markup first. I provide writing services to my clients, but I prefer to design my own websites and blogs.

    ( Reply )
  77. PG

    Leandros February 16th

    Greeat tut !!! I really like these rules

    ( Reply )
  78. PG

    Bryan Kwon February 16th

    * { margin: 0; padding: 0; }

    I don’t know how it takes more time to process, but I do agree that this could make styling form elements a bit more difficult.

    As for alphabetizing, I believe some functions in text editors like textmate make this easier to do so.

    ( Reply )
  79. PG

    Thiago Menezes February 16th

    What’s with the images? O.o

    ( Reply )
  80. PG

    Michael Rice February 16th

    I’ve been using every single one of these since I can remember!
    Go me!

    ( Reply )
  81. PG

    Benoit February 16th

    I’d like to add a few tips of my own…

    # Use multiple stylesheets when needed. For instance, I always create a reset.css file with Meyer’s reset inside it. If the stylesheet is really long (which can happen if you do want a complex UI), divide it. Most of the time, you’ll use a jQuery plugin (or more) that require specific CSS properties… It’s a chore to scroll down a stylesheet. Dividing it can improve your productivity as a designer a lot!

    Note : use @import method to call other CSS files inside a css file. So you have your main.css, that calls everything (it avoids a big html header). Sweet!

    # Use float:left;

    Some may think it is a personal choice, but believe me, I have never seen better cross browser compatibility since I’m using float:left. It requires the use of a reset and some clear:both divs, but really, I think we can say it’s good practice.

    # The earlier you test, the better you’ll rest. (If IE breaks up completely your design while it’s finished and perfect, polished on FF, you will spend a lot of time trying to figure out what’s happening).

    # Use Firebug!!!! I feel naked without it. Seriously, do. You can edit the css on the fly, see what will work or not etc… And learn a lot from the masters ;)

    I hope my comment wasn’t just noise! Chears everyone, viva el webdesineo

    ( Reply )
  82. PG

    Patrick February 16th

    Some great ideas and practices here. I personally like No. 5, about starting in the right place. A lot of younger web coders will assign classes and IDs to almost every tag. I recommend reading Bulletproof Web Design for some great insight into avoiding divitis.

    ( Reply )
  83. PG

    Kevin Quillen February 16th

    “Do not maintain your CSS file on one line. That’s absurdly more difficult to work with. The only time to one-line your CSS file is when you release it. Again, your text editor should be able to strip newlines with just a few keystrokes and mouse clicks.

    If any of this is too hard for you, stop writing CSS.”

    HAHA ’stop writing’. I spit out my red bull. I concur!

    There is no reason to do everything on one line when there are plenty of aggregation/compression scripts out there to use, even ones that will run on the server at runtime. Save yourself the headache…

    ( Reply )
  84. PG

    EVula February 16th

    I generally don’t organize my classes as meticulously as you suggest in item #3, primarily because I use BBEdit and I can just jump straight to individual IDs or classes (for example, I know the unordered list code immediately after #head isn’t relevant to the #foot section, etc).

    As for the one line/multi line code, I generally go with multiple lines, except for specific classes that are only supposed to do one thing (and aren’t likely to get changed); then I just reduce it all down to a single line, regardless of how many different CSS declarations it has. (for example, a .dropcap class)

    ( Reply )
  85. PG

    D. Young February 16th

    Overall, a decent guide for beginners. From a production level standpoint, however, there are a few things I would like to point out.

    First, this article assumes that everyone reading it understands the power of the cascade. The single greatest change anyone can make to their css is to understand the cascading effect, and not duplicate unnecessary information. For instance, when declaring fonts, you only need to declare the font once, in the body tag, and not for each element. I cannot tell you how many times I have seen stylesheets that do this:

    body { font-family: Verdana, Arial, Helvetica; font-size: small; font-weight normal; color: #000000; }
    h4 { font-family: Verdana, Arial, Helvetica; font-size: small; font-weight normal; color: #000000; }
    p { font-family: Verdana, Arial, Helvetica; font-size: small; font-weight normal; color: #000000; }

    when this is all that’s needed:

    body { font: normal small Verdana,Arial,Geneva,Helvetica,sans-serif; color: #000; }

    Since almost everything inherits from body, common styles like fonts and colors can be defined here. Then, you would only need to change properties on subsequent tags that needed to be overridden. For instance:

    h1 { color: #f10; } /* Red H1 Tag – Still uses same font-family as body */

    Eliminating duplicate attributes shortens the overall character count of the css document, thereby decreasing the file size, which can, in turn, lead to smaller load times.

    Second, anyone developing complex, reusable, skin-able designs will ultimately have additional elements in the markup of the page to allow maximum flexibility for other UI designers (or more appropriately, skinners) and this article suggests that the addition of extraneous tags is “bad” (hence, tagitis). That means, that those of us actually coding these modules have to be as forward thinking as possible, and there’s just no way to create a completely expandable (both horizontally and vertically) rounded corner box that uses a .png background with alpha transparency and shadows with a single instance of a div that’s cross-browser / platform compatible.

    Third, alphabetizing may be a “good” practice, but in truth, it has no real monetary value in a production environment and is therefore not (IMHO) a justified use of time. I have to disagree with an earlier post and agree with a majority that this is merely a “preference” and not any type of requirement. If you are working in a team environment with even marginally experienced CSS developers, they should be able to interpret your CSS regardless of what order styles are specified.

    Fourth, CSS selectors, especially when working with descendant selectors, are simply not implemented consistently (nor widely) enough to justify omission of css classes where needed. For instance, IE7 implements :first-child, but not :last-child. Nor does it implement :focus correctly. When developing UIs that are going to appear on multiple platforms, it’s best to stick with what will work in all the browsers you are targeting, and if that means adding some extra classes, then as a designer, that’s what you do. After all, in production work, getting the job done, under-budget and on-time is the main objective.

    My last contention is not with the article itself, but rather with one of the comments:

    “Alphabetizing isn’t a personal preference. Neither is indenting. They’re both proper practice and should be used, and if you’re writing your CSS by hand you should be using a text editor that can manage auto-indenting and sorting with a few keystrokes or mouse-clicks.

    Do not maintain your CSS file on one line. That’s absurdly more difficult to work with. The only time to one-line your CSS file is when you release it. Again, your text editor should be able to strip newlines with just a few keystrokes and mouse clicks.

    If any of this is too hard for you, stop writing CSS.”

    As a .NET developer, I can attest first-hand that the only code I let Visual Studio 2008 touch is whatever C# code is used on the code-behind. Visual Studio also does not contain a decent “minimizer” to remove extra line-breaks and white-space from CSS documents that are hand coded. If you’ve implemented something in your CSS that is perfectly valid, but does not match the schema in VS, it flat out refuses to format the code…period. A perfect example is combining multiple classes. For instance: a.link-button.continue is a class definition that allows me to address every instance of an tag with both the link-button class and the continue class (Continue) where “link-button” defines the general look and feel of all my buttons, and “continue” contains overrides for width margin, and background-image properties. Though valid, VS sees this as an “error” and therefore aborts any “auto-formatting” operation.

    As for maintaining your CSS on one line being “absurdly more difficult” – that is subjective at best. Anyone who codes complex CSS documents by hand should have no more difficulty reading CSS on one line as opposed to multiple lines. The ONLY exception to this that I can think of is grouping multiple specific class definitions into a single list for the purpose of assigning shared attributes. Then, perhaps, the classes could each be on their own line.

    Example:

    #header ul li, #leftColumn-menu ul li, #rightColumn-menu ul li, #footer ul li, div.post-menu ul li { margin: 0 10px; display: inline; line-height: 150%; } /* not a perfect example…but it illustrates the point. */

    ( Reply )
  86. PG

    That CSS Guy February 16th

    After you markup, and BEFORE you CSS- Validate your markup! It will save you headaches down the road!

    ( Reply )
  87. PG

    Randy February 16th

    I don’t alphabetize because I like to separate “placement”(padding, margin, left, etc) from “aesthetic”(color, font-size, etc). Usually, when correcting the layout the FIRST thing I want to do is reposition “placement” of things so why have that info spread out?

    Besides, too many years in the construction/furniture making industry have taught me ALWAYS use width followed by height in that order!

    ( Reply )
  88. PG

    Joe Hana February 16th

    Really nice post, but, as many others said, I can´t agree with the alphabetical structure. I also give them first the layout and position attributes, followed by borders, colors, text,…

    Another thing is that you show many ways of how a designer should make his css easier too understand – but for whom? For others? If you ask me, I do not want that my client mess up anything in the code, or that my client hired up a “cheaper” designer – or whatever else.

    I don´t know what the others think but this is my personal opinion – and I think this is the reality.

    Even a designer has to pay his bills, so I don´t see any reason why to make his own code more “readable” for others.

    ( Reply )
  89. PG

    Hugo V. February 16th

    Apart the reset, that more than once I wish I have used before starting a project, I really use everything described.

    That’s a good list for those giving the first steps on css development.

    ( Reply )
  90. PG

    Alex Hughes February 16th

    Great article.
    Always gives me a confidence boost when I read through articles like so and see that methods I already use are being encouraged.

    However, I can’t say I have ever ordered my properties. Maybe I should? Do not really see the point as I have never used so many properties for one element that I can not see all above the fold and just spot the required out…

    ( Reply )
  91. PG

    Jash Sayani February 16th

    Great post!

    Waiting for the “ToDo list” Screencast of the week!

    ( Reply )
  92. PG

    JohnONolan February 16th

    As a million people have now said – I think the alphebetising is overkill. and no – based on your example I didn’t find the 2nd one any quicker, and if I did it was because you put it on exactly the same link on both examples.

    Other than that, some useful information.

    ( Reply )
  93. PG

    Greg Fisher February 16th

    I particularly agree with the last part- ALWAYS MARK IT UP BEFORE TOUCHING CSS!! Saves so much time.

    ( Reply )
  94. PG

    Andrew February 16th

    Nice post. Thanks.

    ( Reply )
  95. PG

    ericb February 16th

    great! thanks for sharing!

    ( Reply )
  96. PG

    Mary February 16th

    I liked your tips and pictures :) Thanks!

    ( Reply )
  97. PG

    Shane February 16th

    @Joe Hanna – CSS isn’t as complex as a programming language; although it supports commenting, the need for comments is lower than some non-trivial PHP, for example.

    However, your comment ‘making it easier to understand – for whom? Others?’ is a little short-sighted.

    I digress a little here since I’m talking about programming languages, but the most common failing I find in other developers is their complete lack of commitment to commenting their code. Quite often I’ve seen them revisit their own work and not understand what’s going on, so not commenting is dangerous and could bite the person who’s written the code in the arse.

    It’s a bit of an issue with me at the moment because I’ve been working with somebody else’s code, and they’ve failed to comment in any meaningful way. When I asked the guy to take me through it, he hadn’t a clue what was going on, and now I’ve been left to sort out some complex bugs!

    ( Reply )
  98. PG

    Greg February 16th

    I think alphabetizing your css isn’t all that useful. I would rather rely on my editors searching capabilities. But to each his own.

    ( Reply )
  99. PG

    timuism February 16th

    I love the idea of putting styles with less than 3 properties on one line. Thanks for the tips!

    ( Reply )
  100. PG

    Dean February 16th

    WTF with the comments. Sounds like most are either 12 years old, or stoned.

    I’m confused as to what the definition of better CSS is.

    1/ reset doesnt make you write better CSS.

    2/ the order of the properties is irrelevant for writing better CSS.

    3/ any efforts in organisation are good for writing better CSS.

    4/ any efforts in consistency are good for writing better CSS.

    5/ 100% is a little harsh, band depending on the make-up of the various teams involved (solution design, design, front end, back end), it may be impractical to not apply any style until all markup is done. Writing markup before CSS, or writing CSS with document structure in mind, is good for writing better CSS.

    I think my tip would be a combination of 3, 4 and 5 in that writing a CSS document should be a structural exercise as much as it is a presentational exercise. CSS architecture plays a very under rated role in front end web development.

    ( Reply )
  101. PG

    Desizntech February 16th

    Very good!!Nice one useful information

    ( Reply )
  102. PG

    Jarryd February 16th

    Nice to know I do everything listed already!

    The only thing different is usually ( depends on if I remember or not :P ) that I compress my stylesheets when they are ready for production, otherwise I keep everything multi-lined.

    ( Reply )
  103. PG

    hiroshi February 16th

    Very Nice but Nothing in the list is new.

    ( Reply )
  104. PG

    iDevelopThings February 16th

    Great tips.. Thanks..

    ( Reply )
  105. PG

    Adam February 16th

    Images used in this tutorial are really too big to me. It’s tutorial, not gallery, isn’t it?

    ( Reply )
  106. PG

    Jermayn February 16th

    Personally the last tip was the best. The others can all be argued about but the last tip is just pure genius and a great tip to follow.

    Thanks

    ( Reply )
  107. PG

    Rob February 16th

    Good article; I enjoyed reading this! My opinion on the matter of organizing CSS styles is this: Everyone has their own preference and style for writing CSS style. Whatever works best for the coder should be used!

    Now, I’ve had friends who have kept text styles in one style sheet, colors in another style sheet, the main frame work in another style sheet. This seems over kill to me, but hey, whatever floats your boat!

    I like creating ONE stylesheet with code hints that describe each section of styles.

    What bothers me is that there seems to be a consensus in the web world that CSS is “easy.” This is not true. If you’ve worked with Internet Explorer, than you know frustrating it can be. Nothing about CSS is easy! CSS takes a lot of tinkering, adjusting, hours and hours of time. Simply put, there is nothing easy about it.

    My argument against “CSS is easy” is “why are there hundreds (if not thousands) of CSS tutorials on the web. This explains that there are still quite a few people who are trying to make that leap to CSS!

    ( Reply )
  108. PG

    Jeff Hui February 16th

    Great article! I should experiment with alphabetizing since I usually just incremental search to find the css property i’m looking for.

    ( Reply )
  109. PG

    Eneza February 16th

    “don’t even touch your CSS file until the markup is 100% complete. ”

    Its already there!!! Very Well Said!

    ( Reply )
  110. PG

    Dan Ritz February 16th

    I used to do the reset thing on everything!!! But the more I got involved in managing the website after they launched, the more of a pain in the behind it became.

    There’s always a “code” tag or something that you never expected the website owner to use that looks completely busted instead of just lacking a sexy touch until you can fix it. 99% of the stuff you end up defining in the CSS anyways. And the differences left over are rarely anything that require a framework for.

    Resets make me feel a lot better when I’m taking the first step of the CSS action, but always end up causing me more grief than they’re worth.

    I think they’re unnecessary overhead.

    ( Reply )
  111. PG

    Shane February 16th

    Huh that was amazing. As a novice web designer I am always looking for ways to improve myself. I do alphabetize my attributes, I find it speeds up the process, but I do admit to using more than one line for my CSS code, didn’t care for the one line approach too much, too cluttered for my tastes, but to each their own.

    I am totally loving the HTML first CSS last approach. I’ve been doing it backwards lol. Oh well, newbie mistakes I guess. Great article, I dugg it!

    ( Reply )
  112. PG

    Wazdesign February 16th

    hummm…… Alpabetically is good… but hard to crack need practice for that

    ( Reply )
  113. PG

    Tom Karels February 16th

    #5 is a great tip. Would be cool if you guys did a screencast on how you set up your markup

    ( Reply )
  114. PG

    Nepal sites February 16th

    nice article on improving CSS skills.

    ( Reply )
  115. PG

    Paris Vega February 16th

    #1 and #5 are essential. Good post.

    ( Reply )
  116. PG

    Bogdan February 17th

    As the organisation of CSS code is concerned I can really recommend CSSEdit by McRabbit. I have never been faster writing CSS or finding already existing selectors. Take a look:

    http://macrabbit.com/cssedit/

    ( Reply )
    1. PG

      Jorijn Smit April 14th

      *bump*
      As the organisation of CSS code is concerned I can really recommend CSSEdit by McRabbit. I have never been faster writing CSS or finding already existing selectors. Take a look:

      http://macrabbit.com/cssedit/

      ( Reply )
  117. PG

    Lee Simpson February 17th

    Nice post. Really simple 101 stuff but always nice to have this stuff driven home.

    ( Reply )
  118. PG

    Garry February 17th

    Some great info here. Very helpful and a nice refresher in some respects.

    One thing in a lot of peoples comments is criticizing the use of alphabetical arranging for each element. I think a lot of you are missing the point of what Trevor is saying. He is saying when you have a team of people who are potentially going to be working on the same style sheet, it makes sense for it to be sorted this way as different designers can jump in and know whats going on.

    If it’s just you and no one else will be working on it, then its down to you how you arrange it.

    All in all a good list of suggestions.

    ( Reply )
  119. PG

    Diego February 17th

    Creo que lo mejor es utilizar las pautas que te permitan entender y modificar mas rapido el codigo, en esto no hay regla simple y cada uno tiene la suya

    ( Reply )
  120. PG

    Muhammed February 17th

    Grea8 tips Thank you so much

    ( Reply )
  121. PG

    Andrew Rossborough February 17th

    Great post!

    I do all of these, except alphabetizing. Well, sometimes my organisation gets a bit disorganised when I’m rapidly trying to solve cross-browser issues! But I try!

    ( Reply )
    1. PG

      Rob April 6th

      Good to hear! I think another important point with CSS, is to combine properties in one line instead of multiple. For instance, I’ve seen people write this before:

      background{
      background-image:url(images/background.jpg);
      background-position:center;
      background-repeat:no-repeat;
      }

      When, they could do this:

      background{
      background:url(images/background.jpg) center no-repeat;
      }

      Makes writing CSS much faster!

      ( Reply )
  122. PG

    stefan February 17th

    Haven’t read all the thread but regarding point 2 alphabetize styles, if you use firebug the plugin appears to do this for you then you can simply copy and paste back into your style sheet, this is really handy.

    ( Reply )
  123. PG

    stefan February 17th

    in addition to my previous comment, it’s also does add in quite a bit of crap you didn’t write so be careful with randomly copying and pasting.

    ( Reply )
  124. PG

    Denis February 17th

    > CSS is worthless without a well formatted document

    Is there a reason to have one opening HTML tag and two closing /HTML tags on this page? And the same with BODY tags. Is this called well formatted? ;-)

    ( Reply )
  125. PG

    Stephen M. James February 17th

    Alphabetizing would be good if you had 10 or more attributes–less than 10 I feel doesn’t warrant it.

    I agree one should do HTML markup first, but you can go to the CSS, once all child nodes are finished.

    ( Reply )
  126. PG

    Derek February 17th

    Great Points. I like the alphabetizing if I wasn’t using the CSS editor in coda which I let organize attributes on its own.

    If I had straight coded it – I like the idea a lot.

    ( Reply )
  127. PG

    Joseph H. February 17th

    I’m gonna have to agree with everyone who said Alphabetizing is a bit too much. The fact of the matter is that if you need to go back and add something to a class or element, you don’t have time to assess where that will go, then put it in. To me, it’s not a worthy trade off

    All the other tips I thought were extremely useful though.

    ( Reply )
  128. PG

    Stoyan February 17th

    nice tips, only poor choice of example
    div#header
    IMO should be just
    #header
    since IDs are unique, specifying the element is redundant and maybe more expensive for the browser to match. Certainly more to download.

    ( Reply )
  129. PG

    Andre February 17th

    Err on the side of over commenting and maintain good versioning. That means, don’t touch the stylesheet until you’ve backed it up.

    ( Reply )
  130. PG

    Jen Germann February 17th

    Nice post! I definitely incorporate these things into my stylesheets, except for the alphabetizing. For me, it’s hard to think about borders before I’ve set dimensions and padding. I think as long as it’s consistent, the stylesheet can still be neat and organized.

    ( Reply )
  131. PG

    Patrick Wood February 17th

    Thanks for the helpful post. am somewhat of a novice when it comes to writing CSS. Definitely some good ideas in the post and comments about keeping your CSS more consistent, organized, readable, and leaner.

    But there is something I do not understand and I hope someone can explain it to me. How can you write *all* of your markup without at least knowing what your basic CSS is going to be?

    How would you write markup for columns without knowing the CSS? Would it not be better to at least have the basic CSS layout already prepared and use it in your markup? Is there some technique I am missing?

    ( Reply )
  132. PG

    korbinian polk February 17th

    #5 is the only point worth to be emphasized

    ( Reply )
  133. PG

    rachid February 17th

    Good to know,thanks

    ( Reply )
  134. PG

    KP February 17th

    What about tidy CSS? I see a lot of people recommending the use of CSS Tidy and similar utilities to speed up load times and optimize sites. The use of such a utility seems to go against a couple of the principles you’ve mentioned in this post – alphabetize and organize.

    ( Reply )
  135. PG

    nick February 17th

    Alphabetizing is clearly not a way to write better CSS.

    It makes plenty of sense to set your width and height first so you know what everything following is working inside of. Having to scroll your eyes up and down to find height/width is not useful to actually writing better CSS.

    ( Reply )
  136. PG

    IPOX studios February 18th

    Thanks, I’m just learning CSS, so this will help!

    ( Reply )
  137. PG

    andy February 18th

    alphabetizing if there is such word is a bit ocd for me – so is worry about all on one line or not

    ( Reply )
  138. PG

    Sebastian Dadał February 18th

    I already do all this… feels good :)

    ( Reply )
  139. PG

    Rahul February 18th

    The end line is saving time, and it feels great too when you accomplish that too. ;)

    ( Reply )
  140. PG

    John Woods February 18th

    OUtstanding! Excellent tips dude!

    RT
    http://www.anonymity.eu.tc

    ( Reply )
  141. PG

    jdzzle February 18th

    i usually put the most relevant stuff such as width, height, display, position at the top. then usually padding and margin comes after that. i do most of what this article suggests already.
    i think i can offer a tip: your layout should look like a vertically layered cake in some respect.. granted if you have a menu floating to the left that could take up 2 layers of the cake, but then those 2 layers become 1… *shrug*

    ( Reply )
  142. PG

    Brandon S. Adkins February 18th

    the “complete your markup before doing CSS” is a very good point.

    however, sometimes i find it easier to follow this in increments.
    in other words, do part of your markup, and then the related css. continue the markup and then fill in the related css again. rinse and repeat. this process works well for me and still results in well formatted documents.

    ( Reply )
  143. PG

    pcdatadoctor February 18th

    Great post, I will have to start doing things like that more with my coding.

    ( Reply )
  144. PG

    care February 18th

    I am ready to doing this, so cool submission

    ( Reply )
  145. PG

    Antony Jones February 19th

    @JackF

    As happy I am that you have a wide screen and can write all your code on one line, the majority of people don’t, making your code more difficult to maintain/adapt by other people.

    Unmaintainable code is bad code.

    Don’t do it :)

    ( Reply )
  146. PG

    Streetdaddy February 19th

    FormatCSS is a free online tool for formatting CSS, including alphabetisation of rules and properties: http://www.lonniebest.com/FormatCSS/

    In my experience it has never broken my CSS.

    ( Reply )
    1. PG

      Lonnie Lee Best March 17th

      Thanks for testifying about my tool!

      ( Reply )
  147. PG

    Warren Marks February 19th

    First tip is great, i would be using it in my next CSS job i do.

    I use multiline css code, it makes me feel easy and at home with css :-)

    I think alphabetic order of properties is just an overkill!

    Yeah commenting and indentation make me feel great when it comes to revisit a stylesheet after some weeks!

    Thanks for sharing!

    ( Reply )
  148. PG

    Stephen H February 19th

    Alphabetizing your declarations is one of the most ridiculous ‘tips’ i’ve ever heard of.

    For the 0.034 seconds it takes your brain to scan through 5 different declarations to find which one you want, versus the time you would take in re-arranging the declarations is laughable.

    Or do you write your style declarations in that order first?

    “Golly, I sure would like to add the width of my element right now…but it starts with an W and that comes before B and P, so i guess i’ll have to my background and padding declarations first!”

    Give me a break. Have we become that lazy that we can’t quickly scan through 5 short lines of code?

    ( Reply )
  149. PG

    Sean Delaney February 19th

    Very informative. I will be applying this steps in my next project which actually starts on Monday…so its nice timing to have found this post today!

    Thanks.

    ( Reply )
  150. PG

    besart February 19th

    Great tips for writing better CSS code, Thank you!

    ( Reply )
  151. PG

    Matt February 19th

    Man, it’s almost like you read minds. This is almost the exact route I take when styling my css.

    It was kind of weird reading it, as I thought, “hey, that’s what I do”.

    I guess the saying is true – great minds think alike.

    ( Reply )
  152. PG

    Gibi February 19th

    Thanks, I’m just learning CSS, so this will help!

    ( Reply )
  153. PG

    Igor P. February 19th

    Um…. Yeah so the thing about alphabetizing… The margin-right property is in the exact same spot in both examples. So once I found it on the first one, I found it in the second on in 0 time. So bad example.

    ( Reply )
  154. PG

    Micheil February 19th

    I must be really odd, I found it easier to find the margin-bottom property in first example of #2 than in the second example.

    Could this just be habitual?

    ( Reply )
  155. PG

    mangst February 19th

    Very much agree with Consistency. I’d rather have my code be “consistently disorganized” than have little bits of organization here and there.

    The Flickr photos are a nice addition to the article.

    ( Reply )
  156. PG

    Martyn February 19th

    Like the tips but im not overly sure about the alphabetizing the CSS rules. Even If I had enough time in the day that’s probably one thing I still wouldn’t do but commenting on your CSS is a definite must for all coders.

    ( Reply )
  157. PG

    Irshad February 19th

    Great post, I definitely need to sort my CSS out. I just started as a web designer so I need to gain experience.

    ( Reply )
  158. PG

    Alex February 19th

    These are excellent points. But like others have said I personally would never alphabetize the properties. I don’t see the properties as words, rather as what effect they have on my markup. Therefore I start with the structural positional properties (display, position, width, height, margin, padding), followed by the presentational properties (border, background, color, font, text).

    ( Reply )
  159. PG

    Css Tutorial Dude February 19th

    great tutorial, I am gonna start alphabetizing my properties from now on.

    ( Reply )
  160. PG

    Angelo February 19th

    Gee, I never stopped to think to order my CSS attributes alphabeticly…

    I always use(d) long blocks of comments, so I can see directly where what element is, on first sight, and it always worked for me :-)

    With my latest project, for the first time, I used multiple stylesheets, too… It’s clean and tidy, but it’s a bit of a fuzz, if you’re looking for that one sheet, and you’re getting disturbed…

    Anyway, I think I’ll give it a try in my next project. Thanks for the hint ;-)

    ( Reply )
  161. PG

    Jonathon VS February 19th

    I agree to a certain extent (especially with #5!), but some things I think are a matter of preference.

    For example, resetting your CSS is nice in some cases because you get better compatibility with several browsers, but in many cases, you’re really just setting a CSS property to 0 and then setting it again to something else. What’s the point of setting a list’s margins to 0, then setting them to 1em later, when you can cut your code in half by just setting its value to 1em in the first place? By including the reset code, you’re adding code and increasing loading and processing times (albeit marginally) for something that makes absolutely no difference. My advice in most cases is just to learn the default behaviours of browsers and write CSS to accommodate. I’ve come to learn that the more generic your styles are (e.g. element selectors instead of class selectors), the less you have to define styles twice.

    Similarly, I agree with Mark in that alphabetizing your CSS is only handy if that’s the way you think. Typically, in my CSS, I put structural styles (e.g. margins, padding, floats, positioning) at the top of each rule and formatting styles (e.g. bold, colour, font size) at the bottom because that’s the way I think. While it may be quicker to have alphabetical styles when other people look at my CSS, it wouldn’t be any quicker for me. It depends on whether this site created/maintained by me or my Web team.

    ( Reply )
  162. PG

    Chris Paraiso February 19th

    Awesome tips. I definately need to start organizing better.

    ( Reply )
  163. PG

    George Fragos February 19th

    We all have our own ways. Reset is necessary but rather than having a separate section or sheet I prefer to only have one style for each markup. Perhaps the hard way but mine. I hadn’t thought about alphabetizing before. The idea make s sense to me since it makes my code easier to read because of the consistency. I’ve already updated my business site. Truth is that site’s CSS is normally my starting point when designing a client’s site.

    ( Reply )
  164. PG

    Tom Hudson February 19th

    Number 5 is especially important. Marking up your document before hand allows you to minimise the number of classes (and IDs) you’ll end up using: makes you cognisant of what the eff you’re doing in structuring the content of your document. Then the design really does become independent of the structure while simultaneously enhancing the functionality of the structure itself.

    ( Reply )
  165. PG

    carlosvm February 20th

    Hahaha…
    Today I’ve found a new word…. :(

    ORGANISE!!

    Sounds good.. I will try it in my new project.

    ( Reply )
  166. PG

    covax February 20th

    Great article.
    Always gives me a confidence boost when I read through articles like so and see that methods I already use are being encouraged.

    However, I can’t say I have ever ordered my properties. Maybe I should? Do not really see the point as I have never used so many properties for one element that I can not see all above the fold and just spot the required out….

    ( Reply )
  167. PG

    Rizq February 20th

    Good Post !!!

    ( Reply )
  168. PG

    Adrian Rodriguez February 21st

    Thanks for the help. I have been practicing most of these tips and just recently started doing the very first one in resetting everything. I like to use more than one line of code when I am defining more than one style to the element. I usually just do something like

    div {
    margin: 0;
    }

    Even for one line, because it’s just what I have been used to doing, only because it helps others find the styles easier in my css when everything is not bunched up together.

    Thanks for the tips!

    ( Reply )
  169. PG

    Julie Berlin February 21st

    This tip might be useful for some of you. I have a basic stylesheet that contains my reset css, almost all of the (non-deprecated) html element names, basic class names that I reuse in each project, and microformat class names but with just basic or no style rules. It serves as my starting point for new projects, saves me some typing and it ensures that my styles will usually be in a certain order that I’m used to.
    I too like to put my style properties on their own line and I usually order them according to my own logic, not alphabetically; I will put declarations that relate to position and size first, then margin and padding, then borders and background, then font..

    ( Reply )
  170. PG

    Nick @ Kerplunc February 22nd

    I don’t bother with a reset. The default styles are sometimes useful, and there for a purpose. I just remove them as I go/need.

    I also write my CSS all on one line, because I have 1680px of screenspace for them :)

    As for alphabetasizing stuff, I don’t bother, because it’s all on one line, it generally takes slightly longer to find the stuff I need anyway. I try get it right first time :)

    ( Reply )
  171. PG

    Jesse Vlasveld February 22nd

    Most of these tips are excellent. Although I can’t quite agree with the alphabetizing, which I think is more of a personal preference.
    I like to put the positioning elements in front, like floats, width height and margin, followed by the colors, borders, etc.

    ( Reply )
  172. PG

    Jörn February 22nd

    I will create a structure with some imports:
    @import url(reset.css); /* reset */
    @import url(layout.css); /* grid and so one */
    @import url(typography.css);
    @import url(navi.css); /* style group */
    @import url(form.css); /* style group */

    I have only one file in the code
    global.css

    ( Reply )
  173. PG

    Iain Collins February 22nd

    My thoughts on the advice here:

    Tip 1) Suggesting to always use a CSS reset and same time as lambasting people for resetting elements they don’t need to as if it’s ‘expensive’ operation (which it’s not) while at the same time advocating resetting elements that don’t need to be reset is contradictory.

    You will need to test your layout in all likely target browsers if you want to be sure content is displayed as intended in them, blanket CSS resets are not away around that. As such, it makes the most sense to change CSS properties as required than to always define a bunch of redundant markup.

    Tip 2) In both examples the line required is on the same line so it takes the same time to find both whether you use your editors find function or look line by line. I do not agree with the assertion that one example is quicker than the other.

    You will lose a lot more time house keeping than you will ever save if you are so retentive you must manually arrange elements so that they displayed alphabetically at all times.

    If it really bothers you the sensible thing is to start using an editor/macro that does that for you (or something like Coda that can abstract the CSS markup to a GUI, or use Emacs/Textmate/E-TextEditor etc) rather than to advocate keeping it in order manually.

    Alternatively, you could knock up a script in a few lines in Perl/Ruby/Python/etc to do that for you (it’s very simple), assuming you can’t find one that exists already.

    Tip 3) Putting all your CSS markup for different elements of a page on one big style sheet like that is not a very good idea – this is really where using @import() comes in.

    Tip 4) “I am sick and tired of the whole 1 line vs. multiple lines for your CSS debate. There is no debate! Everyone has their own opinion, so pick what works for you and stick with it throughout the stylesheet.”

    Regardless of your view, suggesting there is no debate is implausible. Advocating consistency and then being inconsistent yourself is again contradictory. I agree with the general point in that I can’t say I care either really – but if I was as with Tip 2 I would use an editor to handle the details.

    I will say that if there are a bunch of you working on the same sites, talk about it and come to a consensus if turns out to be an issue. Techniques for resolving naming conventions and syntax formatting debates are very well covered elsewhere already.

    People will inevitably disagree, all you can do is come up with the least contentious solution, and naming conventions are a far thornier issue than syntax.

    Tip 5) I don’t think this is a big problem, people don’t usually write CSS before markup so I don’t think you need to explicitly advise them not to.

    However…I will say that suggesting waiting until markup is “100% complete” is impractical. Even setting aside the dynamic nature of websites, the state of CSS support in mainstream browsers often mandates the creation of theoretically redundant elements – or the repositioning if existing ones – in order achieve a desired layout (without say, resorting to JavaScript or other unwieldy workarounds).

    The lamentable MSIE 6 is the worst offender still in wide use in this regard – the order and nesting of of elements can be crucially important with some common layouts because of it’s numerous shortcomings.

    ( Reply )
  174. PG

    JoTGi February 23rd

    Thank you for your post, it’s really useful for people who are begining like me :)

    ( Reply )
  175. PG

    Danish Jalbani February 23rd

    Amazing post, I love your writing style

    I also follow some rules that are helpful.
    What I do is that I try to make use of ID wherever I think it is possible because I guess it makes my work easy, I just assign the ID to the part I want styled that way.

    Just a suggestion.

    Again, the post was awsome.
    Thanks

    ( Reply )
  176. PG

    Kian Ann February 23rd

    Another tip I use very regularly is to indent my CSS.

    Just like HTML or programming code, indentation does help a lot to understand the structure of the CSS code.

    ( Reply )
  177. PG

    gvtbs February 23rd

    我是一个来自中国的前端开发人员,能交个朋友吗?gvtbs@163.com

    ( Reply )
  178. PG

    Brian February 24th

    Well I am pretty new to website design generally and CSS in particular so just reading these notes was a useful exercise and has given me plenty to think about.

    ( Reply )
  179. PG

    shipin February 24th

    这真是一些不错的建议,非常感谢.
    但是关于第二点(2. Alphabetize)我不是很认同,虽然这样的排序在查找方面有一定的优势,但是我认为在排序上应该把修改频率高的属性排在前面比较好,因为很多时候我们要修改块级元素的宽高和间距属性,或者给它们添加背景属性,我们是否应该按下面的顺序写会更好呢?
    div#header h1 {
    background: #FFFFFF url(“http://”) 0 0 no-repeat ;
    float: left;
    margin-right: 48px;
    padding: 10px 0 0;
    width: 100px;
    border-bottom: 1px solid #dedede;
    color: #000;
    font-size: 18px;
    line-height: 24px;
    }

    ( Reply )
    1. PG

      Sirwan April 3rd

      i was just wondering why do you write in another language if you read it in english?

      ( Reply )
  180. PG

    Amal February 24th

    there is no technical befit for arranging code alphabetic order. sometimes its may create problem.think about the box model technique.

    * {margin:0; padding:0} i don’t found any problem with this. moreover its easy, shorter and professional.

    others technique you may use for better practice but have no technical benefit.

    thanks for your post.

    ( Reply )
  181. PG

    ST Verschoof February 24th

    This helps me so much. I am lousy at organizing in my css sheets, and indeed I have trouble finding certain values. I am going to follow these rules!!! Thank you!

    ( Reply )
  182. PG

    joe cannes February 24th

    Frankly, * {margin:0; padding:0} works fine with lightbox, the Eric Meyer Reset example and your reset example causes too many problem with lightbox.

    I used the 2 examples and was having problems with lightbox, and finally found out it was the reset css causing lightbox to misfunction

    ( Reply )
  183. PG

    Abhijeet Pathak February 25th

    Very informative article. In case of small rules, I usually prefer writing them on single line, but indention is also no problem due to good editors like Notepad++ etc.

    ( Reply )
  184. PG

    Vidal February 26th

    When your css is a mess,….apply source-formatting works nice too in dreamweaver….

    ( Reply )
  185. PG

    Harsha M V February 26th

    Wow.. I am a much organised person… i am feeling like organising my just created website… Thanx Davis

    ( Reply )
  186. PG

    mrdata February 26th

    what about validation?

    I think validation should be the 6th way this article should include.

    It’s easy with CSSEdit:

    Open the style sheet you’d like to validate.
    Open the Validation inspector
    choose File > Validate
    or type ⌘-shift-V
    If there are any errors, click on them to go to the offending piece of CSS.
    After fixing things (or breaking them more), repeat step 2.

    ( Reply )
  187. PG

    nszumowski February 27th

    this has been open in my browser for a couple of days and finally just got to reading it. great post, #2 is an awesome idea, I kind of want to look over my old code to spruce it up a bit! as for the global reset, i’ve never had a problem with anything and this is the first time i’ve heard someone mention an alternative. if your suggestion speeds loading time, i’ll give it a try! thanks again!

    ( Reply )
  188. PG

    Dinna February 27th

    hi! i’m an alien with this CSS stuff. and i’m having problem with my multiply page. i love writing poems and my main problem is that with all my poems posted at my page, it’s very awful because of the very long list of poems. so i tried looking for a css on how to put the poems in a scrollable box. i searched at google but i can’t find one that would teach me how to put my blog in a scrollable box. that’s why i’m hopeful that you would spend time to help me out with this one. btw, my multiply page is http://www.glarenmei.multiply.com. see for yourself how ugly my blog box is. so please help me out with this one. thank you and more power to you. your tutorial here is awesome and very helpful especially to CSS newbies like me.

    ( Reply )
  189. PG

    Buzzlair Voufincci February 27th

    cool but i wonder it aint work for small tag :D

    ( Reply )
  190. PG

    Alexey Novikov February 28th

    Alphabetizing is evil. Group selectors by meaning, not by letters.

    By the way, it is fast enough to find meaning-based selectors. Sometimes faster than is they are alphabetized

    ( Reply )
  191. PG

    Alexey Novikov February 28th

    Jörn, more files is worse. More files — more server requests.

    ( Reply )
  192. PG

    Kat Thompson March 2nd

    Great post – as someone self taught and only normally working with smallish websites I feel heartened to know that I’m generally doing ok with css. I’ve always found it easiest to get the basic structure mark up done and then when adding the css after the site just seems to spring into life. Cheers.

    ( Reply )
  193. PG

    Andy March 3rd

    Good post but I disagree about alphabetising. I think its easier to group related / similar properties together, such as margin and padding.
    In section 4 you write div#header and div#header h1 instead of #header & #header h1 – why? This is understandable with classes where you may add specific styling dependent on the element but not ID’s which need to be unique.

    ( Reply )
  194. PG

    Graeme March 8th

    Thanks for the advice!

    I’ve just been learning css and web design for a year now so these tips will come in handy. I will use your stylesheet structure from now on I think.

    ( Reply )
  195. PG

    Lukillas March 8th

    Great! I’ve just taken some of these tips and started using it on a little project I’ve started at work. Thanks!

    ( Reply )
  196. PG

    David L March 10th

    I am as new to this as a 2 week old infant and I was lucky to stumble on you while searching for HELP! It’s been a long time since writing DOS (82) and I have forgotten some valueable lessons. Thank you for thinking of us ‘newbies’.

    ( Reply )
  197. PG

    tom watson March 11th

    “You can’t tell me that Example 2 isn’t faster.”

    yes i can.

    tard.

    ( Reply )
  198. PG

    Cristhian Bedon March 12th

    This is great tips, and something everyone should try to practice. Everyone has their own method of styling and coding. But being organized isn’t bad.

    ( Reply )
  199. PG

    Soh March 13th

    On point :-)

    ( Reply )
  200. PG

    violence March 14th

    realy good advices

    ( Reply )
  201. PG

    70watts March 15th

    Alphabetize props? Really?

    If it can be automated, I’ll buy it, but it’s impractical and excessive. How many props do you have behind a selector anyway.

    Organizing selectors though? Golden.

    ( Reply )
  202. good advise with Reset.
    Thanks a lot!

    ( Reply )
  203. PG

    Marc P March 16th

    Point 2 is a bit retarded.

    I would say it would take longer to check and remember to keep each letter in alphabetical order than to press (CTRL+F) and find it.

    There’s being organized and then there’s being anal..

    ( Reply )
  204. PG

    Zyend March 18th

    I like one liner too, as for Organization, I use:

    #header {background-color:fff}
    #header h1 {color:#000}
    #header ul {}
    #header li {}

    etc.. this way, i can quickly find what i need in a line.
    I dont’ agree with 2.Alphabetize & 5.Start in the right place, for new developer, yes it’s logical, but personally I i don’t need it.

    ( Reply )
  205. PG

    Nagarajan P.V. March 19th

    The font-family tag can also be the part of the style definition defined for all elements so that no need to mention the font-family individually in each and every definition.

    In case if required the style can be overwritten in the individual style definition.

    html, body, div, h1, h2, h3, h4, h5, h6, ul, ol, dl, li, dt, dd, p, blockquote, pre, form, fieldset, table, th, td { margin: 0; padding: 0; font-family:Arial,Verdana;}

    ( Reply )
  206. PG

    Marcus March 30th

    Thank you for this tips. I’m somehow an advanced HTML/CSS-Newbie and I didn’t know how to improve my css organisation but now I’ll try to follow your 2nd and 3rd tip.

    Again: THANK YOU!

    ( Reply )
  207. PG

    Scarf*oo April 3rd

    Wow, great post, but I can’t agree with the alphabetization of css properties. I prefer to structure them by importance, or the impact on the visual side the properties create. For example, the position, display, float properties come first, followed by widths, margins, borders and paddings, and lastly come fonts, colors, backgrounds, etc.

    ( Reply )
  208. PG

    Ronald April 5th

    This is a great post especially the reset, I’ll apply that to my stylesheets, thanks for this great list, helps alot.

    ( Reply )
  209. PG

    DMC April 8th

    Completely disagree about alphabetizing, that’s just pedantic, and useless. I didn’t find the second example faster to read at all.

    I’m having a hard time believing that your company made a collective decision to alphabetize all css. Sounds like a real fun place to work…

    ( Reply )
  210. PG

    kakday April 8th

    thank alot

    ( Reply )
  211. PG

    Pantelis Vratsalis April 15th

    Great advice Trevor!

    All 5 points are quite significant (especially the last one about markup and css files is a huge issue. I used [and am still tempted to do it sometimes] to create both files in parallel, and was ending up confused and with a lot of classes I could had avoided :) .

    I think it might be useful to start on the alphabetical thing, too, even though I think it is minor, since most blocks don’t include more than 8-10 elements, so it’s not that bad to let it look messy there :)

    Thanks a lot again

    ( Reply )
  212. PG

    Erik Reppen April 17th

    I’ve seen no evidence of the universal selector slowing sites down in any measurable fashion worth talking about. Certainly not any more than adding 80 more selectors to a reset declaration. I think that’s the Yahoo guys going overboard on their efficiency studies. But yeah the ginormous resets are ridiculous. If you want to get good at this, don’t put anything into your stylesheets if it doesn’t have a good reason to be there. Pre-emptive CSS like adding clearfix to every container just makes a mess and creates more potential for unnecessary confusion as to who is doing what.

    ( Reply )
  213. PG

    Mahbub April 19th

    Organization is tough when you’re writing / updating css randomly. There should be a tool which organizes similar selectors together. And I don’t thing Alphabetize is a common phenomena to write better css.

    ( Reply )
  214. PG

    SammyK April 29th

    I thought my stylesheets were all BA and all, but – alphabetize! Holy crap! That’s genius.

    ( Reply )
  215. PG

    amer May 2nd

    nice

    ( Reply )
  216. Nice post. I like everything except for the Alphabetize option. Again that’s my opinion. Thank for a great post.

    ( Reply )
  217. PG

    Tim May 18th

    I think this article has some good general advice. I personally don’t use resets, though I’ve considered it, and I wouldn’t alphabetize my code. There are certain things for me which I always have together, like margin and padding or width and height.

    Also, I’m not fond of single line method. I find it easier to find things when they’re all on their own line. I compress before I upload for a live site, so it’s not an issue either way for me.

    I would have added learning shorthand css to this list. It can be a huge time and space saver to do shorthand css declarations as opposed to typing out each specific property.

    ( Reply )
  218. PG

    Martin May 20th

    THANK YOU! I have been messing with my personal website all morning trying to figure out why IE6 was a few pixels off.

    Yes, this noob was using * { margin: 0; padding: 0}

    Changed it to Eric Meyer’s Reset … add an overflow: hidden to my menu and boom, perfect.

    ( Reply )
  219. PG

    Robert June 1st

    Nice tips, need to start grouping my css

    ( Reply )
  220. PG

    Jenny June 4th

    I’ll have to add these tips to my stylesheet. They really do look like things would be neater if I did it this way.

    ( Reply )
  221. PG

    Xar June 19th

    this is cool man!

    ( Reply )
  222. PG

    Jose Fernandez June 29th

    What’s with all the alphabetizing hate? Personally being a programmer first and a designer second I alphabetize. I find it much easier to work with. If you’ve already been doing this for a few years and have your own system, by all means follow it, but if you’re somewhat inexperienced I would suggest you try alphabetizing for a bit to see how it works for you.

    ( Reply )
  223. PG

    p3t4r June 30th

    Great tip about the reset.
    After I started using reset stylesheet, coding has been much easier for me!

    ( Reply )
  224. PG

    Eliseu M. July 10th

    All remember to insert:

    -moz-
    and
    -webkit-

    at the begging of the new CSS3 selectors, like box-shadow!

    Great tutorial man, gratz!!

    ( Reply )
  225. PG

    jerrey July 19th

    It’s useful! thanks.

    ( Reply )
  226. PG

    Adrian July 30th

    Great article.

    A query regarding alphabetization…

    I am using a help/PDF authoring tool that has a CSS editor incorporated. The editor is rather unintuitive so you often have to look at the CSS file directly in Notepad (etc) to troubleshoot style issues. Styles are placed in the file in the order that they are defined and because of the various sections it is very difficult to navigate. Anyone know of a tool that will sort selectors in a CSS while respecting the @media section that the selectors are in? The only tools I have found cannot handle this — they treat the @media declaration as a corrupt selector.

    Thanks,

    Adrian

    ( Reply )
  227. PG

    Marcell August 11th

    Great post! I have to say I have not been the best css organizer when it comes to designing. Now thanks to this article I will be organize when coding.

    ( Reply )
  228. The alphabetization tip is a good tip.

    I like consistency as well; however you ruined it for me by showing an inconsistent example :) ‘up to 3 on one line’ is not a good stab at consistency. A good indicator is the fact that people will have a hard time formulating your consistency rule by looking at your css.

    ( Reply )
  229. PG

    DemoGeek September 16th

    I completely agree with you on the one-liner vs multi-liner divide. It should be a personal choice than enforced upon.

    ( Reply )
  230. PG

    Wazdesign September 17th

    Search for Free CSS toolbox. it make properties alphabetically.

    ( Reply )
  231. PG

    sachin singh December 1st

    Wow, gr8 tips, i am a beginner but seriousely this helped me alot……. Keep floating tutorials like this

    ( Reply )
  232. PG

    sachin singh December 1st

    gr8 tips, i am a beginner but loved it…… nice advice…… helped me alot… keep floating tutorials like this..

    ( Reply )
  233. PG

    Muhammad Usman Arshad December 2nd

    nice guide thanks for sharing

    ( Reply )
  234. PG

    Shruti February 4th

    i really like this tips, using this tips will make my css in batter way

    ( Reply )
  1. Arrow
    Gravatar

    Your Name
    February 4th