Back to Guides
Guide
12 min read

How to Add Custom CSS to Shopify

Want to customise your Shopify store beyond what the theme settings allow? This guide covers every method for adding custom CSS, from quick fixes to professional approaches.

Flex Commerce Team
Updated February 2024

Understanding Shopify CSS

Before diving into the methods, it helps to understand how CSS works in Shopify. Every Shopify theme loads CSS files that control the visual appearance of your store. When you add custom CSS, you are either adding to these existing styles or overriding them.

CSS follows a specificity hierarchy. This means that more specific selectors override less specific ones, and styles that come later in the code can override earlier ones. Understanding this is key to making your custom styles work reliably.

CSS Specificity Basics

  • Element selectors (p, div, h1) have the lowest specificity
  • Class selectors (.button, .header) have medium specificity
  • ID selectors (#main-nav) have high specificity
  • Inline styles and !important have the highest specificity

The method you choose for adding CSS depends on your technical comfort level and the scope of changes you need to make. Let us explore each option from simplest to most advanced.

Theme Editor Method

Many modern Shopify themes include a built-in custom CSS field in the theme settings. This is the quickest and safest way to add small CSS customisations without touching any code files.

How to Find the Custom CSS Setting

  1. 1
    Open your Shopify admin

    Navigate to Online Store, then Themes.

  2. 2
    Click Customise on your active theme

    This opens the theme editor where you can preview changes.

  3. 3
    Go to Theme Settings

    Click the gear icon or Theme Settings in the sidebar.

  4. 4
    Look for Custom CSS or Advanced

    The exact location varies by theme. Check sections like Advanced, Custom Code, or CSS.

Example: Changing Button Colours

Here is a simple example of custom CSS you might add:

.btn, .button, .shopify-payment-button button {
  background-color: #ef436b !important;
  border-color: #ef436b !important;
}

.btn:hover, .button:hover {
  background-color: #d63d5f !important;
  border-color: #d63d5f !important;
}

Pro Tip

Always preview your changes on mobile as well as desktop. The theme editor lets you switch between device views to check responsiveness.

Custom Liquid Section

If your theme does not have a custom CSS setting, or you need to add CSS to specific pages only, you can use the Custom Liquid section. This section type lets you add any HTML, CSS, or JavaScript to your pages.

Adding a Custom Liquid Section

  1. 1
    Open the theme editor

    Go to Online Store, Themes, then click Customise.

  2. 2
    Navigate to the page you want to customise

    Use the page selector at the top to choose your page.

  3. 3
    Add a Custom Liquid section

    Click Add Section and search for Custom Liquid or Custom HTML.

  4. 4
    Add your CSS wrapped in style tags

    Paste your CSS code between opening and closing style tags.

Custom Liquid CSS Example

<style>
  /* Hide the quantity selector on product pages */
  .product-form__quantity {
    display: none;
  }

  /* Make the add to cart button full width */
  .product-form__submit {
    width: 100%;
    max-width: none;
  }
</style>

This method is particularly useful when you want different styles on different pages. You can add Custom Liquid sections to individual product pages, collection pages, or any template in your theme.

Theme Asset Files

For larger CSS customisations or a more professional setup, you should edit your theme files directly. This gives you full control and keeps your CSS organised in dedicated files.

Creating a Custom CSS File

  1. 1
    Access the code editor

    Go to Online Store, Themes, click the three dots, then Edit Code.

  2. 2
    Navigate to Assets folder

    Find the Assets folder in the left sidebar and click on it.

  3. 3
    Add a new asset

    Click Add a new asset and create a blank file called custom.css.

  4. 4
    Link the CSS file in theme.liquid

    Add the following line in your theme.liquid file, just before the closing head tag.

Linking Your Custom CSS

Add this line to theme.liquid before the closing head tag:

{{ 'custom.css' | asset_url | stylesheet_tag }}

Using theme.scss.liquid

Some older themes use SCSS instead of CSS. If your theme has a theme.scss.liquid file, you can add your styles directly to the bottom of that file. SCSS supports variables and nesting, which can make your CSS more maintainable.

Pro Tip

Always duplicate your theme before making code changes. Go to Actions, then Duplicate. This gives you a backup you can restore if something goes wrong.

CSS Best Practices

Writing maintainable CSS is just as important as making it work. Follow these practices to keep your customisations organised and future-proof.

Use Comments

Comment your CSS to explain what each section does. Future you (or your developer) will thank you.

/* =================================
   Product Page Customisations
   ================================= */

/* Hide compare at price when not on sale */
.price__compare-at {
  display: none;
}

Avoid !important When Possible

Using !important makes CSS harder to override later. Instead, try to match or exceed the specificity of the original styles. If you must use !important, document why.

Use Consistent Naming

If you create new classes, use a consistent prefix like .custom- to distinguish your code from theme code. This prevents conflicts and makes debugging easier.

Test Across Devices

Always test your CSS on mobile, tablet, and desktop. Use browser developer tools to simulate different screen sizes and check for responsive issues.

Mobile-First Media Queries

When writing responsive CSS, use min-width media queries for a mobile-first approach:

/* Mobile styles (default) */
.product-grid {
  grid-template-columns: 1fr;
}

/* Tablet and up */
@media (min-width: 768px) {
  .product-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Desktop */
@media (min-width: 1024px) {
  .product-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

Common Customisations

Here are CSS snippets for frequently requested customisations that you can adapt for your store:

Custom Font

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

body, button, input, select, textarea {
  font-family: 'Inter', sans-serif;
}

Hide Sold Out Badge

.badge--sold-out,
.product__badge--sold-out {
  display: none;
}

Sticky Add to Cart Bar

.product-form {
  position: sticky;
  bottom: 0;
  background: white;
  padding: 1rem;
  box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.1);
  z-index: 100;
}

@media (min-width: 768px) {
  .product-form {
    position: static;
    box-shadow: none;
    padding: 0;
  }
}

Custom Scrollbar

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #555;
}

Troubleshooting

CSS not working as expected? Here are the most common issues and how to fix them:

Styles Not Applying

Problem: Your CSS is not having any effect.

Solutions: Check for typos in your selectors. Use browser developer tools to inspect the element and see what classes it actually has. Try increasing specificity or adding !important as a test.

Styles Only Work in Preview

Problem: CSS works in the editor but not on the live site.

Solutions: Clear your browser cache and Shopify cache. Check that you saved and published your changes. Verify the CSS file is linked correctly in theme.liquid.

Mobile Styles Breaking

Problem: Looks good on desktop, broken on mobile.

Solutions: Check your media queries are correct. Test in actual mobile browsers, not just desktop simulation. Look for fixed widths that should be percentages.

Finding the Right Selector

Problem: You cannot figure out what class to target.

Solution: Right-click the element and select Inspect. This opens developer tools showing you the exact HTML and classes. You can even test CSS changes live in the Styles panel.

Next Steps

Now that you know how to add custom CSS to your Shopify store, here is how to continue improving your customisation skills:

  1. 1
    Learn browser developer tools

    Master the Elements and Styles panels. They are essential for CSS debugging.

  2. 2
    Understand CSS Grid and Flexbox

    Modern layout techniques that make responsive design much easier.

  3. 3
    Explore CSS variables

    Learn how Shopify themes use CSS custom properties for easy colour changes.

Need Custom Development?

Whether you need simple CSS tweaks or a complete theme overhaul, our developers can bring your vision to life.