skip to main | skip to sidebar

Tag-Cloudfor those who want or can only use JavaScript to convert regular tags list into a Tag-Cloud. jQuery and regular expressions are here to help.
Why Tag-Cloud? It is better looking and more meaningful.

Since Aug. 25, 2009: blogger now offers a built-in Tag-cloud. So you won't need this code for that job. still, jQuery manipulation is cool :)

Check demo :
click Reset to see tags original output.
click Get Cloudy 1 to convert it to Tag-Cloud without frequencies.
or click Get Cloudy 2 to convert it to Tag-Cloud with frequencies.

Code uses jQuery to manipulate and style those LI tags according to their frequencies, and regular expressions to extract the frequency contained in parentheses ().

Here is JavaScript code
<script src='' type='text/javascript'></script>
<script type='text/javascript'>
   function getTagsCloudy(placeHolderID,scale,percentClassPrefix,keepFreq,overwriteCSS){
      var list = $('#'+placeHolderID+' li');
      // overwrite CSS
      var max=0, min=0;
      //First pass : calc max and min
      list.each(function (i) {
         //extract and parse frequency
         freq = getTagFrequency($(this));
         //Calc max and min
         if (freq>max) max= freq;
         if (freq<min || min==0) min= freq;
      //Second pass : calc percent
      list.each(function (i) {
         //extract and parse frequency
         freq = getTagFrequency($(this));
         // Remove tags frequency ?
         if (!keepFreq) $(this).html($(this).html().replace(/\n/g,'').replace(/\(\s*\d+\s*\)/g, '') );
         //Calc percentage
         var percent = Math.ceil( ((freq-min+1)/(max-min+1)) * scale );
   function getTagFrequency(x) {
      var matchs= x.text().replace(/\n/g,'').match(/\s*\d+\s*/g);
      if (!matchs) return 0;
      var freq = parseInt(matchs[matchs.length -1]);
      return freq>0? freq : 0;
   // Calling it on document ready
         'border':'none 0',
         'padding':'2px 2px 1px 1px',
         'margin':'0 0 0 0',

you pass to the function :
1- The place holder ID of container div/widget.
2- Scale; for example 10 : then you need to make CSS classes from 1 to 10.
3- percentClassPrefix: like 'cloud-percent', then you need to prefix CSS Classes names with 'cloud-percent'
4- keepFreq : true to keep the frequencies or false to remove it.
5- overwriteCSS: Options/associative array to overwrite styles set or inherited on regular tags list. How to figure that out, use Firbug. Bottom line you want to remove list bullets and extra margins or padding or border and add some floating.

Here is CSS code
<style title="text/css">
   /* If you use 10 scale, then you need classes from 1-10 */ { font-size:70% } { font-size:80% } { font-size:80% } { font-size:90% } { font-size:100% }
   /* you can bold higher frequency tags or color them */ { font-size:110%; font-weight:100;} { font-size:110%; font-weight:100;} { font-size:120%; font-weight:200;} { font-size:130%; font-weight:300;} { font-size:140%; font-weight:400;}{ font-size:150%; font-weight:500;}
   /* neded To make container div expand with the content layout changes */
   .Label div {Overflow:Auto}

If you use 10 scale, then you need classes from 1-10, and as you see you can control how they are styled.
You can bold higher frequency tags or color them, you can even hide minimum frequency tags by setting [display:none;] on the first class.

And the HTML code of Tags/Labels:
See how they were originally output by Blogspot. And you don't need to change it.
Tags list should look like it.. which is the default output of Blogger..
<div class="widget Label" id="Label100">
<div class='widget-content'>
      <li><a href=''>ADO.Net</a>(7)</li>
      <li><a href=''>AJAX</a>(2)</li>
      <li><a href=''>ASP</a>(11)</li>
      <li><a href=''>ASP.Net</a>(15)</li>
      <li><a href=''>DAL</a>(7)</li>
      <li><a href=''>IIS</a>(6)</li>
      <li><a href=''>javascript</a>(5)</li>
      <li><a href=''>jQuery</a>(3)</li>
      <li><a href=''>OOP</a>(5)</li>
      <li><a href=''>Paging</a>(9)</li>
      <li><a href=''>performance</a>(7)</li>
      <li><a href=''>Regular expressions</a>(3)</li>
      <li><a href=''>SEO</a>(4)</li>
      <li><a href=''>SQL Server</a>(6)</li>
      <li><a href=''>Unicode</a>(4)</li>
      <li><a href=''>VB.Net</a> (7)</li>
      <li><a href=''>XML</a> (3)</li>

In Other words : <li> <a href="some link"> Label name </a> (5) </li> . Of Course extra line-breaks or spaces are ignored.

that's it..! let it get cloudy..


  1. ooblogger // March 17, 2009 at 7:33:00 PM GMT+11  


    Please add your site at is a place where other people can find you among the best sites on the internet!
    Its just started and we are collecting the best found on the net! We will be delighted to have you in the sweebs listings.


  2. Finance Blog // April 29, 2009 at 3:21:00 AM GMT+10  

    Hi mike,

    your blog is very useful. especially at blogger.
    many "blogger tips blog" has very old hacks and techniques. but yours is new and get me (and I think other visitors) excited every time.

    I am trying to develop some blogger hacks. If you want to share as an article ( in this site ) I can send some of them.

    thanks again

  3. Mike // April 30, 2009 at 7:54:00 AM GMT+10  

    @Finance Blog,
    thanks for ur feedback.. please email me with more details about sharing articles..

Post a Comment

Thank you for taking the time to comment..
* If you have a tech issue with one of my plugins, you may email me on mike[at]
More Tech Tips! | Technology tips on web development


Mike MoreWeb developer, jQuery plugin author, social media fan and Technology Blogger.
My favorite topics are: jQuery , Javascript , ASP.Net , Twitter , Google..
<connect with="me"> </connect>

Subscribe by email

Enter your email address:

or via RSS