Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The first example is fine, if you're only setting one property then doing it in a single line isn't a big deal.

Your second CSS example is no bueno. Don't put multiple properties on a single line. It might make sense to you to put display and margin and padding on a single line but it might not make sense to me. These should all be on separate lines, it's not worth "saving lines" to make your CSS harder to parse for someone who doesn't already know that you like to group X, Y and Z properties.



> it's not worth "saving lines" to make your CSS harder to parse for someone who doesn't already know that you like to group X, Y and Z properties.

Well somewhat in between you could also put properties in alphabetical order as suggested in this Google Style Guide. That tend to work for me since "text" properties will be towards the end of the rule, and for me the layout properties like border, display, margin and padding is something I'd want to see first.

But where I prefer some freedom vs hard rules is that I'll also align properties to make the differences more obvious. In this YUI2 example, the second class is applied to a mobile version of the dialog, the common properties come first, that way the difference is obvious:

  /* dialog body wrapper for extra css styling (.rtk-skin-dlg .yui-panel .bd .body) */
  .rtk-skin-dlg .body { background:#fff; padding:10px; border-radius:3px; box-shadow:0 1px 3px rgba(0,0,0,0.2) inset; }
  .rtk-mobl-dlg .body { background:#fff; padding:10px; }


Well that is the whole point, I wish I made the example better.

How is it harder to parse? Putting everything in separate lines make the CSS file 10 times longer, and it's more difficult to see groups of rules that fit together along with their common structure.

Nowadays unless you edit on a tablet your text editor probably handles 120 columns or more.

But I really can't see the argument for readability. When I navigate a stylesheet for a website I'm working on, I want to see the larger structure. I don't need to see clearly the properties within a single rule. I want to see from top down.

Still, this could be argued forever. Apples and bananas :) I guess it's the same discussion as space vs tabs, or 2 space vs 4 spaces.

Here's a better example from one project which used YUI2 (it's old, but I think it shows my point of view, that the dtk-skin-dlg structure is very obvious along with the hd/bd/ft structure YUI 2 uses and the styles applied to them, that's the structure I want to see readily when I work in a stylesheet without having to scroll to understand it's all connected together):

  /* dialog body */
  .dtk-skin-dlg .yui-panel { outline:none; }
  .dtk-skin-dlg .yui-panel .hd { font:16px/1em Verdana, sans-serif; color:#ddd; padding:10px 10px 0; background:none; }
  .dtk-skin-dlg .yui-panel .bd { padding:10px 10px 10px; background:none; font-size:12px; line-height:19px; color:#000; }
  .dtk-skin-dlg .yui-panel .ft { padding:5px 10px 10px; background:none; font-size:12px; line-height:1.2em; color:#000; }
  
  /* dialog footers, right aligned */
  .dtk-skin-dlg .ft-right { clear:both; width:100%; padding:5px 0 0; text-align:right; }
  
  /* left align buttons INSIDE ft-right */
  .dtk-skin-dlg .ft-left  { float:left; text-align:left; /*padding from ft-right*/ }
  
  /* dialog body wrapper for extra css styling  */
  .dtk-skin-dlg .body { background:#fff; padding:10px; border-radius:3px; box-shadow:0 1px 3px rgba(0,0,0,0.2) inset; }
  .dtk-mobl-dlg .body { background:#fff; padding:10px; }


> Putting everything in separate lines make the CSS file 10 times longer, and it's more difficult to see groups of rules that fit together along with their common structure.

You block them together just like we do with code. Good code doesn't put multiple statements on a line, good CSS doesn't either. File length means nothing, if someone's looking for a specific class there are tools to do that, saving a few lines and making the CSS harder to read and edit isn't worth it.

The examples above are much more readable like this (margin added for illustration of grouping related properties):

    .dtk-skin-dlg .yui-panel .hd {
        font: 16px/1em Verdana, sans serif;
        color: #ddd;
        
        background: none;
        
        padding: 10px 10px 0;
        margin: auto;
    }
Written that way, when someone finds that rule in the file they can easily parse the relevant property without having to scan a 200 character long line.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: