title: Easy to maintain CSS or lightweight HTML?
body: <p>I'm in charge of supervising the whole IT side of a website (both infrastructure and development) and I'm having a difference of opinion with the lead frontend developer. His approach is to create individual classes that each bring one functionality, and combine as many classes as needed to style an element:</p>
  
  <pre><code>HTML
  &lt;div class="float_left padding_10 width_60_percent"&gt;&lt;/div&gt;
  &lt;div class="float_left width_30_percent"&gt;&lt;/div&gt;
  &lt;div class="float_left padding_10 width_10_percent"&gt;&lt;/div&gt;
  CSS
  .float_left { float: left; }
  .padding_10 { padding: 10px; }
  .width_60_percent { width: 60%; }
  .width_30_percent { width: 30%; }
  .width_30_percent { width: 10%; }
  </code></pre>
  
  <p><strong>Pros:</strong></p>
  
  <p>-<strong>understanding of CSS via the HTML</strong>: you can understand what the CSS is doing by just looking at the class names in the HTML.<br>
  -<strong>ease of creation</strong>: once you have your set of classes defined, it's just a matter of combining them in the HTML, you don't have to constantly write new CSS.<br>
  -<strong>ease of maintenance</strong>: same reason as above.<br>
  -<strong>portability</strong>: you can use the same approach for any website you work on (which makes sense for him as he is a contractor working on different projects).<br>
  -<strong>smaller CSS</strong>: as long as your layout reaches a certain critical size whereby the same classes are being re-used again and again (which would be the case with a proper layout, but obviously isn't reflected above due to the conciseness of the example).</p>
  
  <p><strong>Cons:</strong></p>
  
  <p>-<strong>bigger HTML</strong>.<br>
  -<strong>HTML harder to read</strong> if you're not interested in the CSS part (which my backend developers creating the views aren't).<br>
  -<strong>harder to integrate Javascript based on class selectors</strong> (we're using jQuery).</p>
  
  <p>My approach isn't dictated by the ease of writing/maintaining CSS itself, but rather by concerns that a substantial part of our HTML code is going to be used solely for the purpose of integrating our CSS, which will impact performance: I believe it's better to have a bigger CSS which gets served and cached once, and a smaller HTML which saves you bandwidth on every page view, rather than the opposite. Accordingly, I would opt for the following approach:</p>
  
  <pre><code>HTML
  &lt;div id="column_left"&gt;&lt;/div&gt;
  &lt;div id="column_middle"&gt;&lt;/div&gt;
  &lt;div id="column_right"&gt;&lt;/div&gt;
  CSS
  #column_left { float: left; padding: 10px; width: 60%; }
  #column_middle { float: left; width: 30%; }
  #column_right { float: left; padding: 10px; width: 10%; }
  </code></pre>
  
  <p><strong>Pros/Cons</strong><br>
  Opposite as above.</p>
  
  <p>I have the feeling that having a lightweight HTML code is critical to achieving growth of your website:<br>
  -page load will be faster which will help with SEO and user experience.<br>
  -more pages can be served with the same bandwidth will which save you infrastructure cost.</p>
  
  <p>In an attempt to get a de-facto answer, we scanned "big" websites to see what part of HTML was allocated to using ids and classes. Here is the code:</p>
  
  <pre><code>&lt;?php
  require_once 'simple_html_dom.php';
  $pages = array('http://www.amazon.com', 'http://www.ebay.com', 'mywebsite.html', 'http://stackoverflow.com','facebook.html');
  foreach ($pages as $page) {
      echo "\n$page\n";
      $html = new simple_html_dom();
      $string = file_get_contents($page);
      $total = mb_strlen($string);
      echo "HTML = " . $total . " characters\n";
      $html-&gt;load($string);
      foreach (array('id', 'class') as $attribute) {
          $count = 0;
          $elements = $html-&gt;find("*[$attribute]");
          foreach ($elements as $element) {
              // length of id or classes, + id="..." or class="..."
              $count = $count + mb_strlen($element-&gt;$attribute) + mb_strlen($attribute) + 3;
              //echo $element-&gt;$attribute . "\n";
          }
          echo "  -from $attribute attributes = $count -&gt; " . round($count / $total * 100) . "%\n";
      }
  }
  </code></pre>
  
  <p>and here are the results:</p>
  
  <pre><code>http://www.amazon.com
  HTML = 101680 characters
    -from id attributes = 943 -&gt; 1%
    -from class attributes = 6933 -&gt; 7%
  
  http://www.ebay.com
  HTML = 71022 characters
    -from id attributes = 1631 -&gt; 2%
    -from class attributes = 4689 -&gt; 7%
  
  ourwebsite.html
  HTML = 35929 characters
    -from id attributes = 754 -&gt; 2%
    -from class attributes = 2607 -&gt; 7%
  
  http://www.imdb.com/
  HTML = 74178 characters
    -from id attributes = 1078 -&gt; 1%
    -from class attributes = 5653 -&gt; 8%
  
  http://stackoverflow.com
  HTML = 204169 characters
    -from id attributes = 3376 -&gt; 2%
    -from class attributes = 39015 -&gt; 19%
  
  facebook.html
  HTML = 419001 characters
    -from id attributes = 6871 -&gt; 2%
    -from class attributes = 85016 -&gt; 20%
  </code></pre>
  
  <p>So far we've been using "my" approach and I'm happy to see we're keeping the percentages  of code related to the <code>id and</code>class` attributes within the same proportions as other big websites (around 2% and 7% respectively). Nonetheless in order to validate that choice, I would like to ask the following questions that I hope experienced developers/webmasters will be able to answer:</p>
  
  <p><strong>Q1: Do you see other pros/cons in favour/against either of the 2 approaches?</strong>  </p>
  
  <p><strong>Q2: From your experience, is it that critical to worry about having a lightweight HTML code, or does this become neglectable with the use of compression and other criteria (e.g. you will spend more money fighting with your frontend developers)?</strong>  </p>
  
  <p>By looking at the results, you will see that there seems to be a pattern in the amount of code related to the <code>id</code> and <code>class</code> attributes (although I know scanning more websites would provide a more accurate picture):<br>
  -all websites have around 1% to 2% of their HTML code related to <code>id</code> attributes.<br>
  -4 of the websites have around 7% of their HTML code related to <code>classes</code>.<br>
  -the others have around 20% of their HTML code related to <code>classes</code>.  </p>
  
  <p><strong>Q3: Is there a technical explanation (e.g. are Facebook and Stackoverflow using the same frameworks to generate their CSS) for these patterns?</strong></p>