How to Create a Modern Tag Cloud in Blogger Using CSS & JavaScript
If you are running a Blogger site, you know that the default "Labels" widget is often plain and doesn't always match a modern UI/UX design. A well-designed tag cloud not only makes your blog look professional but also improves navigation, allowing users to find content faster.
In this tutorial, we will show you how to create a dynamic, stylish Label Cloud for your Blogger sidebar. This widget features a clean "pill" design, smooth hover transitions, and a responsive layout.
Why Use a Custom Tag Cloud?
- Improved User Experience: Visitors can quickly scan topics.
- Reduced Bounce Rate: Easy navigation encourages users to click more pages.
- Mobile Friendly: The flex-wrap design ensures tags look great on smartphones.
- Aesthetic Appeal: Minimalist design with a professional "Oswald" font touch.
The Implementation Guide
To add this to your blog, follow these simple steps:
- Log in to your Blogger Dashboard.
- Go to Layout > Add a Gadget.
- Choose HTML/JavaScript.
- Paste the code provided below and click Save.
The Optimized Code
I have optimized the script to ensure it fetches your blog's labels automatically and displays them in an alphabetical, clean list.
<div class="zaibi-tags-wrapper">
<div id="labels-cloud">
<div class="loading-tags">Loading categories...</div>
</div>
</div>
<style>
/* Modern Tag Cloud Styling */
.zaibi-tags-wrapper {
padding: 15px 0;
font-family: 'Oswald', 'Segoe UI', sans-serif;
}
#labels-cloud {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
#labels-cloud a {
background: #ffffff;
color: #1a1a2e;
padding: 8px 18px;
border-radius: 30px;
font-size: 13px;
text-decoration: none !important;
text-transform: uppercase;
font-weight: 600;
border: 1px solid #eee;
transition: all 0.3s ease-in-out;
display: inline-flex;
align-items: center;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
/* Hover Animation */
#labels-cloud a:hover {
background: #1a1a2e;
color: #ffffff;
border-color: #1a1a2e;
transform: translateY(-3px);
box-shadow: 0 6px 12px rgba(26, 26, 46, 0.15);
}
.loading-tags {
font-size: 13px;
color: #999;
font-style: italic;
}
</style>
<script>
function loadZaibiTags() {
// Automatically detects your blog URL
var blogURL = window.location.protocol + "//" + window.location.hostname;
var script = document.createElement('script');
script.src = blogURL + '/feeds/posts/default?alt=json-in-script&max-results=0&callback=displayTagsWithCount';
document.body.appendChild(script);
}
function displayTagsWithCount(json) {
var categories = json.feed.category;
var container = document.getElementById('labels-cloud');
var html = "";
if (categories && categories.length > 0) {
// Alphabetical Sort
categories.sort(function(a, b) {
return a.term.localeCompare(b.term);
});
for (var i = 0; i < categories.length; i++) {
var labelName = categories[i].term;
var labelURL = "/search/label/" + encodeURIComponent(labelName);
html += '<a href="' + labelURL + '">' + labelName + '</a>';
}
container.innerHTML = html;
} else {
container.innerHTML = "No tags found.";
}
}
loadZaibiTags();
</script>
How it Works
The script uses the Blogger JSON Feed API. Instead of manually typing your labels, the JavaScript fetches every category (label) you have used in your posts. The CSS then applies a "Flexbox" layout, which makes the tags wrap beautifully to the next line regardless of the screen size.
Customization Tips
- Change Colors: If you want a different color, simply change the 1a1a2e (Dark Navy) in the CSS to your brand color (e.g., ff0000 for Red).
- Font: We used 'Oswald'. Ensure your theme has this font loaded, or change it to 'Arial' or 'Roboto' in the CSS.
