How To add Custom CSS for Specific Pages

No results found. Try again with different words?

Search must be at least 3 characters.

How To add Custom CSS for Specific Pages

WordPress makes it quite easy for us to style specific pages by adding a unique page-specific class to every page. You can use custom CSS on specific pages in WordPress. If you’ve ever wanted to apply styling to a specific unique page but are unsure how to, this document will help you.

To add custom CSS on specific WordPress pages, you will need to add your CSS code to the styles.css file accessible via your WordPress backend, generally by following this path:

Appearance > Theme Editor > Styles.css

Note:

Depending on the Theme you are using, you may have a Custom CSS tab built into the theme, which does the same thing for you and outputs your styles within your Styes.css file, but allows you to input your CSS in an editor within a Theme tab.

How to apply CSS on Specific Page or Post

There are various ways with which you can add apply CSS on a specific page or a post. But, the most common one is

  1. Using the HTML id or class

1. Using the HTML id or class

This is one of the most common approaches if you want to apply CSS on a specific page or post. All we need to do is grab a unique identifier that a page or post will have. Then, this HTML class or id allows us to target all our CSS scripts to the desired page or post.

1.1. Find the HTML class or id of the page

First, you must find the id or class used for the CSS script. This can be easily found with the help of the browser inspection tool.

Just open the page where you apply CSS and right-click on the element you want to edit. Then click on Inspect.

From the above screenshot, the home page’s unique identifier is the “home” class. Therefore, if you want to apply some CSS rules only to the home page, you must use this class in your selectors.

For example, let’s say we want to apply some style to the logo only on the home page. Then, besides the home class, we also need the logo image selector. Again, this can be obtained from the browser inspection tool.

In this case, we’ll use the “custom logo” class to apply our style to the logo. Let’s put them together with the class grabbed on the previous step. Finally, we can apply our script only on the home page using the following CSS selector:

.home .custom-logo{ /*your CSS here */}

1.2. Find the HTML class or id of the post

Similar to the pages, each post should have a unique HTML class. Again, just inspect the element on the post you want to apply CSS with the help of the browser developer tool. Then, you will see the unique identifier with the postid attribute.

For the following post with the Astra theme, the class that identifies this post is postid-130187.

Finally, create your own CSS selector that meets your requirement, just like the custom logo example. Then, you can apply the CSS on the specific page or post by adding it in Appearance > Customize > Additional CSS.

.postid-130187 .custom-logo{ /*your CSS here */}
Was this article helpful?
Did not find a solution? We are here to help you succeed.

Related Docs

Grab this rare opportunity to save up to 50%

WOAH, HOLD ON THERE!

Don't Miss Our Biggest Discount

00
Months
00
Days
00
Hours
00
Minutes
00
Seconds

You are backed by 100% risk-free money-back guarantee.

Scroll to Top
Now choose your preferred
page builder addon
Choose your preferred page builder addon

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.