Create Custom CSS File in Shopify: Simple Steps to Elevate Your Store

Customizing your Shopify store can seem daunting, but it’s easier than you might think! If you want to change the look and feel of your site without relying on pre-built themes, learning how to create a custom CSS file is the way to go. Custom CSS allows you to style your store exactly how you envision it—whether it’s tweaking fonts, colors, or layout.

In this guide, we’ll walk you through how Shopify development experts create and apply a custom CSS file in Shopify. Ready to dive in? Let’s get started!

How to Create a CSS File in Shopify

Creating a custom CSS file for your Shopify store may sound technical, but it’s actually a pretty straightforward process. Let’s break it down step by step so you can start customizing your store in no time!

Step 1: Create the CSS File

First, you’ll need to create a CSS file. You can do this locally on your computer using any text editor like VS Code or Notepad++. Just make sure you save the file with a .css extension. For best practices, name your file something like theme-custom.css. This will help distinguish your custom styles from the default theme files (which are typically named theme.css).

Why this is important: Naming your file something like theme-custom.css not only helps you stay organized but also makes it easier for another developer (or you) to pick up where you left off if any changes are needed later on.

If you’re working with a theme like Shopify’s Dawn, you may see section-specific CSS files. These files load only when a particular section of the store is being displayed.

Step 2: Upload the CSS File

Once you’ve created your custom CSS file, it’s time to upload it to Shopify. Here’s how you can do it:

  • Log in to your Shopify dashboard.
  • Navigate to Online Store > Themes.
  • Click the three dots (…) next to your current theme and select Edit Code.
  • On the left-hand sidebar, look for the Assets folder and click it.
  • Click Add a New Asset. You’ll see two options: Upload a File or Create a Blank File.
  • If you already created the CSS file on your computer, select Upload a File and find your theme-custom.css file.
  • If you want to create the file directly in Shopify, choose Create a Blank File, then select the .css extension, and name the file theme-custom.css.

Step 3: Link the CSS File to Your Theme

Now that the file is uploaded, you need to let Shopify know to load it. This means linking the CSS file to your theme’s main layout file.

  • Inside the code editor, find the Layout folder and open the theme.liquid file.
  • In the <head> section of the file, add the following code below the other CSS links:
{{ 'theme-custom.css' | asset_url | stylesheet_tag }}

This tells Shopify to load your custom CSS file whenever your store is viewed.

Step 4: Save and Test the CSS File

Before wrapping up, save your changes by clicking the Save button. Now, let’s make sure everything is working properly:

  • Open your store’s frontend in a browser.
  • Open the developer tools by pressing F12 (Windows) or ⌘ + Option + I (Mac).
  • Reload the page with CTRL + F5 (Windows) or ⌘ + Shift + R (Mac).
  • In the Network tab, filter by “CSS” and look for your theme-custom.css file. If you see a status of “200,” that means your file is loading correctly!

How to Edit Existing CSS File

If you prefer editing the CSS that’s already part of your theme, you can do that too! Most Shopify themes have an existing CSS file that handles the overall design of your store. This file is usually called theme.scss.liquid in older themes or base.css in newer Shopify 2.0 themes like Dawn.

Step 1: Locate the Existing CSS File

To find the CSS file in your theme, follow these steps:

  • Log in to your Shopify admin.
  • Go to Online Store > Themes.
  • Click Actions next to your theme, then select Edit Code.
  • In the left-hand sidebar, scroll down to the Assets folder.
  • Inside this folder, you’ll see files like theme.scss.liquid or base.css. Click on the file you want to edit.

Step 2: Edit or Add Your Custom CSS

Once you’ve opened the file, you can edit the existing styles or add new ones. Here’s a tip: To keep things organized, create a section at the bottom of the file and label it something like “Custom CSS.” This way, all your customizations are easy to find later.

Example:

/* Custom CSS */
.custom-button {
  background-color: #ff5733;
  color: white;
}

Step 3: Save Your Changes

After adding or editing your CSS, don’t forget to click the Save button to apply the changes to your store.

Note: One thing to keep in mind is that if you update or switch your theme, any changes you’ve made to the existing CSS file might be lost. To avoid this, always keep a copy of your custom CSS. You can simply copy everything from your “Custom CSS” section and paste it into the new theme’s CSS file if you ever need to switch or update.

Struggling with Shopify store customization?

Tips for Using Custom CSS in Your Shopify Store

When working with custom CSS in Shopify, a few best practices can help you get the most out of your customizations while keeping things organized and efficient. Here are some tips to keep in mind.

Always Backup Your Custom CSS

Before making any changes, it’s a good idea to keep a backup of your custom CSS. Whether you’re updating your theme or tweaking styles, having a backup ensures you won’t lose any of your hard work.

You can copy your custom CSS into a separate document or keep it in a specific section in your Shopify theme, like a “Custom CSS” section, for easy access.

Use Clear, Descriptive Class Names

When writing CSS, always use clear and descriptive class names. This will help you (or anyone else working on your store) understand what each section of code does at a glance. Instead of something generic like .button1, go for something more meaningful like .primary-button or .header-button.

Organize Your CSS

It’s easy for CSS files to get messy, especially as you add more styles. Keep your code organized by grouping related styles together.

For example, you can group all button styles in one section and all header styles in another. Adding comments in your CSS file can also make it easier to navigate later.

Example:

/* Button Styles */
.primary-button {
  background-color: #007bff;
  color: white;
}
/* Header Styles */
.header-title {
  font-size: 24px;
  color: #333;
}

Test Your Changes on Different Devices

Shopify stores are often accessed on various devices like desktops, tablets, and mobile phones. After applying your custom CSS, be sure to test your store’s design on different devices to ensure that everything looks good and functions as expected across all screen sizes.

Use the Shopify Preview Feature

Before making your custom CSS live, use the Shopify preview feature to check how the changes will look without affecting your live store. This gives you the chance to tweak and perfect your design before showing it to your customers.

Use CSS Specificity Wisely

When adding custom CSS, you might sometimes notice that your changes don’t apply as expected. This often happens because the theme’s original CSS has higher specificity. To ensure your custom styles override the default ones, you can increase the specificity of your CSS selectors or in some cases, use the !important rule (but use it sparingly).

Example:

.header-title {
  color: #ff5733 !important;
}

Minimize the Use of !important

Although !important can help enforce your custom styles, overusing it can make your CSS harder to manage and troubleshoot. Use it only when necessary, and focus on writing clean, well-targeted CSS that doesn’t rely on !important for most changes.

Keep Performance in Mind

Adding too much custom CSS can slow down your store’s performance. Try to be efficient with your code, only adding the styles you really need. Reducing unnecessary styles helps keep your store fast, which leads to a better user experience and can even help with SEO.

Transform your Shopify store, maximize sales!

FAQs on Creating a Custom CSS File in Shopify

Does Shopify use HTML or CSS?
Yes, Shopify uses both HTML and CSS. While most of the theme files contain Shopify's templating language called Liquid, they also include HTML, CSS, JavaScript, and JSON to control the design and functionality of your store.
Where is the CSS code in Shopify?
You can find the CSS code in Shopify by going to Online Store > Themes > Actions > Edit Code and then looking for the Assets folder. Inside, you’ll find CSS files like theme.scss.liquid or base.css, where you can edit or add custom CSS.
How do I add a custom class in Shopify?
To add a custom class in Shopify:
  • Go to Online Store → Themes → Actions → Edit Code.
  • In the code editor, locate the specific section file where you want to add the class.
  • Open the file, find the HTML element you want to modify, and add your custom class within the code. Save the changes, and your class will be applied.

Final Words

Customizing your Shopify store with custom CSS gives you the freedom to design your store exactly how you want it. Whether you’re fine-tuning the layout or giving your store a completely new look, adding custom CSS is a simple yet effective way to make your brand stand out. With the steps we’ve covered, you can easily create, edit, and manage your custom styles.

Remember, whether you’re making small adjustments or big changes, keeping your CSS organized and backing up your work will save you time and effort down the road. Now it’s your turn to start experimenting and transforming your Shopify store into something that reflects your brand and its USP!

And if you need advanced customizations for your store, hire Shopify developers for the best results and minimum hassle!

author
Mehul Patel is a seasoned IT Engineer with expertise as a WordPress Developer. With a strong background in Core PHP and WordPress, he has excelled in website development, theme customization, and plugin development.

Leave a comment