My latest articles.
When working with WordPress, one of its hidden superpowers is that it automatically adds helpful classes to the <body> tag of every page. These classes tell you what kind of page you’re on (homepage, post, page, archive, etc.), and you can use them to write very precise CSS selectors.
A common need is to apply styles to all pages except the homepage. Here’s how to do it.
<body> ClassesWhen WordPress loads a page, it inserts context-specific classes into the <body> tag. For example:
Homepage
<body class="home page page-id-2 ...">
Notice the home class.
About Page
<body class="page page-id-7 ...">
Notice there is no home class.
Single Blog Post
<body class="single-post postid-45 ...">
This behavior gives you a powerful way to write CSS that only applies in certain contexts.
:not() SelectorCSS provides the :not() pseudo-class, which allows you to exclude specific elements from your styling.
For example:
p:not(.highlight) {
color: gray;
}
This would style all paragraphs except the ones with a highlight class.
Since WordPress always adds home to the <body> on the homepage, we can exclude it in CSS:
body:not(.home) {
/* Styles apply to every page except the homepage */
}
If you want to specifically limit it to WordPress Pages only (and not posts or archives), use:
body.page:not(.home) {
/* Styles apply to all WordPress pages except the homepage */
}
body.page → targets pages (like “About” or “Contact”).:not(.home) → excludes the homepage.So together:
This approach is clean, scalable, and doesn’t require editing templates or adding custom PHP. It’s pure CSS that leverages WordPress’s built-in body classes.
Use cases include:
By combining WordPress’s automatic <body> classes with the CSS :not() selector, you can easily create rules that apply to all pages except the homepage. This method is flexible, efficient, and theme-agnostic — no extra code or plugins required.
Try inspecting your <body> tag using your browser’s developer tools, and you’ll see exactly which classes you can target for even more control.