How many id-s and classes...

  • HKt0p5
  • Graduate
  • Graduate
  • User avatar
  • Posts: 135
  • Loc: Bulgaria

Post 3+ Months Ago

How many div id-s and p.classes and a.classes can I have in a css file and in an HTML file?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

There could only be two logical limits on such things.

1) Limits imposed by browsers by design of the rendering engine, likely different from browser to browser
2) Limits imposed by a computers available resources, which will vary from user to user

In either case I would be willing to bet the number is high enough that you should never realisticly have to worry about it as a developer.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

Out of curiosity I generated a 20.8 MB CSS file that includes 500K unique ID and class CSS rules (for a total of one million) using the following script and tried it.

Code: [ Select ]
<?php
ini_set('memory_limit', '256M');
$str = '';
for($i = 0; $i < 500000; $i++)
{
    $str .= "#_$i{color:#fff;}\n";
    $str .= "._$i{color:#fff;}\n";
}

file_put_contents('test.css', $str);
unset($str);

?>
  1. <?php
  2. ini_set('memory_limit', '256M');
  3. $str = '';
  4. for($i = 0; $i < 500000; $i++)
  5. {
  6.     $str .= "#_$i{color:#fff;}\n";
  7.     $str .= "._$i{color:#fff;}\n";
  8. }
  9. file_put_contents('test.css', $str);
  10. unset($str);
  11. ?>


On Ubuntu/Gnome, Opera and Firefox became unresponsive for 5-10 seconds, then displayed the page.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 63 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.