Shopify Custom CSS Not Working? How to Override H2 Font Size for Mobile
Hey everyone! Ever banged your head against a wall trying to get a simple CSS change to stick on your Shopify store? You're not alone. Customizing your Shopify store's appearance can sometimes feel like a game of hide-and-seek, especially when it comes to responsive design. We recently dove into a really common, yet frustrating, issue on the Shopify community forums where a store owner, Mazzah, was tearing their hair out trying to adjust the H2 font size specifically for mobile devices on their Dwell theme. It's a classic example of how tricky custom CSS can be, even for seemingly small tweaks. But thanks to some fantastic community input, we can break down exactly what went wrong and how to fix it, not just for Mazzah, but for anyone facing similar styling headaches.
Mazzah's initial code looked something like this:
@media only screen and (max-width: 768px) {
.h2 {
font-size: 22px !important;
}
}
Seems reasonable, right? You want to target H2s on mobile, set a font size, and use !important to make sure it overrides. But it just wasn't working. So, what was the puzzle?
The Core Culprit: Understanding CSS Selectors
This was the very first thing several community members, like Priyasha, devcoders, and Titan from Shopplaza, jumped on. The main issue? The dot! In CSS, As Titan from Shopplaza brilliantly put it, many Shopify themes "decouple visual heading size from semantic HTML level." This means something that looks like an H2 on your page might actually be a If you're targeting a standard HTML If the H2 content is nested within a container that has the class This targets both the element with the class Another critical point raised by Shopplaza_team was the placement of the custom CSS. Shopify's theme editor offers multiple places to add CSS, and understanding their scope is vital: Mazzah had initially placed the code in a section-specific box, which explained why it wasn't having the desired global effect. Responsive design is non-negotiable for modern e-commerce. Media queries allow you to apply different styles based on screen size, device type, and other characteristics. Mazzah's original code used Always check your theme's documentation or inspect the live site's CSS to confirm the exact breakpoints it uses. Consistency is key for a seamless mobile experience. The However, in scenarios where theme styles are highly specific or inline, Combining all the insights, here's the refined, working solution that Mazzah found success with, applicable to many Shopify themes: Remember to click Save in the top right corner of the theme editor and then perform a hard refresh on your live storefront to see the changes. Mastering custom CSS on Shopify takes practice, but understanding these fundamental principles—selectors, placement, and responsive design—will save you countless hours of frustration. This particular H2 font size puzzle highlights how a few small details can make all the difference. Keep learning, keep experimenting, and soon you'll be styling your Shopify store with confidence. If you're looking to start your own online store or need help with an existing one, Shopify offers a robust and user-friendly platform that can be customized to your heart's content. And for those bigger projects, remember Shopping Cart Mover is here to help with all your development and migration needs!.h2 targets an element that has a class named 'h2' (e.g., ). However, an actual HTML heading tag is simply . If your theme uses the standard H2 tag without a matching class, your .h2 selector won't find anything to style.
tag or a tag that simply doesn't have class="h2" applied to it. The key takeaway here is to always inspect the element using your browser's developer tools (right-click on the element and select "Inspect") to see its actual HTML tag and any classes it might have.
Solution for Selectors:
tag, use:h2 { /* ... styles ... */ }.h2, or if the H2 itself has that class, a more robust selector might be needed, as suggested by Ploqo:.h2, .h2 * { /* ... styles ... */ }.h2 and any child elements within it, covering more bases.Where to Put Your Custom CSS: Global vs. Section-Specific
Understanding Media Queries and Theme Breakpoints
max-width: 768px, a common breakpoint. However, as Priyasha and Ploqo pointed out, the Dwell theme specifically uses 749px as its mobile breakpoint. A slight mismatch like this can prevent your styles from kicking in at the exact moment you expect them to.The
!important Declaration: Use with Caution!important declaration in CSS forces a style to take precedence over others, regardless of specificity. While it can be a quick fix to ensure your styles apply, it's generally considered bad practice if overused. It can make your CSS harder to maintain and debug later on, as it breaks the natural cascade of styles. In many cases, a more specific selector can achieve the same result without needing !important.!important might be necessary as a last resort to override them. Mazzah's solution ultimately used it, which is acceptable when other options prove too complex for a simple override.The Comprehensive Solution for Mobile H2 Font Size on Dwell Theme
@media screen and (max-width: 749px) {
h2 { /* Or .h2, .h2 * if inspecting reveals a class wrapper */
font-size: 22px !important; /* Adjust 22px to your desired size */
}
}Best Practices for Shopify Custom CSS