A user wants to display a black announcement bar on their Shopify homepage while keeping a gradient color on all other pages.
Initial Attempts:
Multiple solutions were proposed involving CSS targeting and conditional Liquid code
Early suggestions failed because they either changed the announcement bar color on all pages or weren’t properly implemented
The user struggled with understanding where to place conditional Liquid code (the “main wrapper” concept)
Working Solution:
The issue was resolved by adding conditional Liquid code to theme.liquid above the </head> tag:
Uses {% if template == 'index' %} to target only the homepage
Applies custom CSS to set the announcement bar background to black (#000000)
The solution was later extended to also change the text color to white (#FFFFFF) for better contrast
Outcome:
The user successfully implemented the code after receiving step-by-step guidance and marked the solution as working. The announcement bar now displays black with white text on the homepage only, while other pages retain the original gradient styling.
Summarized with AI on October 29.
AI used: claude-sonnet-4-5-20250929.
Yes, I already have a nice gradient color which I want to keep for all other pages. But specifically for the home page, I like to keep the announcement bar simply black. I know this is advance. I hope we can manage to do this
Go to online store ----> themes ----> go to three Dots ----> edit code ---->find theme.liquid files ----> place the code ---->
under the tag before the body ----->
if this code work please do not forget to like and mark it solution
Step 1: Go to Shopify Admin > Online Store > Themes > Edit code
Step 2: Go to the Sections folder and open the file where your announcement bar is coded. It might be announcement-bar.liquid or part of header.liquid.
Step 3: Add the following code to the main wrapper of the announcement bar:
Step 4: Now go to the Assets folder.
Step 5: Open base.css (or theme.css) and scroll to the bottom.
Step 6: Paste the following CSS:
.home-announcement {
background-color: black !important;
}
Step 7: Click Save and check your homepage.
Now your homepage announcement bar will be black, and all other pages will stay unchanged.
If you need assistance to do this, you can inbox me.
If our suggestions are useful, please let us know by giving it a like or marking it as a solution. Thank you
For me this didn’t workout. Do you have idea why that may be? I have some code for the announcement bar in the Custom CSS, but the code is only about Bold text.
I did this one, and yes it changed the color to black, but in every page. I want to make the change only in the home page and all the other pages the color to be as already is.