Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To style an individual WordPress post, target a class on its post container; to change just one element, give that block a custom CSS class. For page-wide context, target the classes on the body. In a block theme, check the Site Editor’s Styles controls first. The right method depends on how much of the page should change and what markup your active theme outputs.

Choose the scope before writing CSS

Start by deciding what should look different. A selector tied to one block affects that block; a post-container selector can style one post or a group of posts; a body selector can style the page context and other page-level elements. Theme markup and available editor controls vary, so inspect the rendered page and confirm the controls in your installed WordPress version.

What you want to change Best starting point Scope
One block inside a post Add a custom CSS class to that block in the editor That block instance
One post or a post group Use the post container classes output by post_class() A post, category, format, or other class represented in the markup
Styling based on the overall page Use body_class() classes, or add a class with its filter The page body and any elements selected through it
A block type throughout a block theme Use the relevant block-type CSS option in Styles That block type site-wide, not one post instance

Style one post or a group with post_class()

In a theme template, post_class() outputs classes for the post container. WordPress documents it as a way to supply classes that can support styling an individual post or posts assigned to a category or post format; it accepts an optional post ID or object. See the WordPress post_class() reference.

First check that the template wrapping the post calls post_class(). Then inspect the front-end HTML to see the actual element and classes before writing a selector. The active theme determines the markup, so a selector copied from another theme may not match your site. WordPress discusses this dependency in its CSS administration documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For example, if the rendered post container has a class you want to target, write CSS using that observed class and place the rule where your theme or site accepts custom CSS. Do not assume a particular post-ID class or wrapper name without checking the page source: the useful selector is the one your active template actually emits.

Use body classes when the page context matters

body_class() adds classes to the page’s <body> element. It is useful when styling depends on the overall page context rather than a single block. If the built-in classes do not express the condition you need, the body_class filter lets a theme add a custom body class. The function is documented in the body_class() reference.

Because a body-based selector can reach many elements on that page, keep the rule narrow and intentional. If only the post content needs a change, a post-container selector is usually a better fit than styling broadly from the body.

Change one block in the editor

When only one block—such as a heading, image, or callout—needs a different appearance, add a custom CSS class to that block and target that class in your CSS. WordPress.com’s guide explains how to add additional CSS classes to blocks. The class identifies that block instance, unlike a rule for the block type that can apply across the site.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check Styles in a block theme

For a block theme, review the Site Editor’s Styles controls before adding custom CSS. WordPress documents global settings and custom CSS options in its Styles overview; its Theme Handbook guide to applying styles covers how styles can be applied. A CSS rule for a block type is broader than a custom class placed on one block, so choose based on whether you want a site-wide change or a one-instance change.

WordPress warns that CSS customizations saved through Styles are cleared when switching themes. Keep a copy of custom CSS you may need to reuse, and verify how your theme stores styles before changing themes.

Rank #4
Teacher Record Book
  • Keep track of everything from attendance to test scores
  • Spiral bound
  • Measures 8-1/2" x 11"

Apply and verify the change

  1. Identify the target. Choose one block, a post container, a post group, or the page body.
  2. Check the theme and editor. In a block theme, look in the Site Editor’s Styles controls. For template-based CSS, inspect the rendered markup to confirm the class or element exists.
  3. Add the class or rule at the matching scope. Use a block’s custom class for a single block, post-container classes for post-level styling, or body classes when the page context is the reason for the change.
  4. Preview the affected page and related pages. Confirm that the intended post or block changes and that other posts or blocks remain unaffected. If nothing changes, recheck the selector against the actual markup and the place where the CSS was saved.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.