How To Get ItemID Class in body tag

Want to style specific Joomla pages? One useful trick is grabbing the ItemID class from the <body> tag. Joomla automatically adds a unique class like itemid-123 to help you target pages with custom CSS or scripts.

 

This php code goes before </head> section inside your template index.php:

 <?php
defined('_JEXEC') or die; // Menu Item ID $itemId = JRequest::getInt('Itemid', 0);
?>

Modify <body> tag like this:

<body class="<?php echo 'item-' . $itemId;?>">

Then you can write custom css rules in your stylesheet:

.item-6{ background: #ff0000; } .item-7{ background: #BADA55; } 

Related Articles

Boki

Boki

With more than 15 years of hands-on experience in Joomla, the author specializes in building and redesigning websites that are both functional and easy to use. Driven by a passion for clean code and thoughtful design, they help individuals and businesses bring their digital ideas to life—turning concepts into smooth, engaging online experiences.

About

Saint Art Designs is a freelance Joomla web developer specializing in modern, responsive, and secure websites.

  • Joomla Web Development Service
  • Joomla Web Design
  • Joomla Upgrade
  • Joomla SEO

Why Hire Me?

With over two decades of experience in Joomla development, I deliver high-quality, stable, and scalable websites.

Each project is approached with precision, clear communication, and a focus on long-term value.

Get a Quote

Online Profiles

Freelancer
Upwork
Linkedin
Facebook
Google Review

Contact Info