If you’re an aspiring WordPress theme designer, mastering CSS is key to unlocking greater control, customization, and efficiency in your workflow.
Luckily, WordPress automatically adds CSS classes that you can utilize in your themes. Several of these CSS classes are automatically added to the section of every page on a WordPress website.
In this article, we’ll explain the WordPress body class. We’ll also share tips and tricks for using WordPress body classes, from years of theme development experience, to help you enhance your projects.
Here is a quick overview of what you’ll learn in this article.
What is WordPress Body Class?
Body class (body_class) is a WordPress function that allows you to assign CSS classes to the body element.
The HTML body tag normally begins in a theme’s header.php file, which loads on every page. This allows you to dynamically figure out which page a user is viewing and then add the CSS classes accordingly.
Normally, most starter themes and frameworks already include the body class function inside the HTML body tag. However, if your theme does not have it, then you can add it by modifying the body tag like this: