Transitioning from SCSS to CSS in Shopify Themes for Store Owners

Published on Aug 10, 2024

By Michael Chen

#Shopify#CSS#Web Development
Software source code. Program code. Code on a computer screen. The developer is working on program codes in the office. Photo with source code.

Understanding the Shift from SCSS to CSS in Shopify Themes

The Deprecation of SCSS/SASS

Shopify has recently made a significant change in its theming system by deprecating SCSS/SASS. This move has left many developers and store owners wondering how to effectively manage styles and variables in their themes. The transition from SCSS to plain CSS has brought about new challenges, particularly when it comes to working with variables and customizing themes.

The New CSS Landscape in Shopify Themes

With the deprecation of SCSS, newly downloaded Shopify themes now include regular CSS files (theme.css) instead of the previously used Liquid files (theme.css.liquid). This change has altered the way variables are handled and how theme customizations are implemented. While this shift provides a more standardized approach to CSS, it has also introduced some confusion among developers accustomed to the old system.

The Challenge of Variable Management

One of the primary concerns arising from this change is how to effectively call and manage variables from the schema portions of the website. In the past, developers could easily use Liquid syntax to reference variables, such as color: {{settings.my_font_color}};. However, the new system relies on CSS custom properties (CSS variables), which use a different syntax: color: var(--my-font-color);.

Navigating the New Variable System in Shopify Themes

Understanding CSS Custom Properties

CSS custom properties, also known as CSS variables, provide a powerful way to store and reuse specific values throughout a stylesheet. They offer similar functionality to the variables in preprocessors like SASS, but with the added benefit of being native to CSS and dynamically updatable via JavaScript.

Locating Variable Definitions

One of the main challenges developers face is locating where these CSS variables are defined. Unlike SCSS variables, which were typically defined at the top of a stylesheet, CSS custom properties are often set on the :root pseudo-class or another high-level element. However, in Shopify themes, the location of these definitions may not be immediately apparent.

The Solution: css-variables.liquid Snippet

The key to understanding how Shopify themes are now managing variables lies in a file called css-variables.liquid. This snippet is where the magic happens. It’s responsible for defining the CSS custom properties based on the theme settings selected by the merchant.

Implementing Custom Variables in Modern Shopify Themes

Adding Your Own Variables

To add your own custom variables to a Shopify theme, you’ll need to work with the css-variables.liquid snippet. This file acts as a bridge between the theme settings and the CSS, allowing you to define variables that can be used throughout your stylesheets.

Syntax for Defining Variables

When adding new variables, you’ll typically use syntax similar to this:

:root {
  --my-custom-color: {{ settings.my_custom_color }};
}

This approach allows you to create CSS variables that pull their values from the theme settings, maintaining the flexibility and customization options that merchants expect.

Using Custom Variables in Your CSS

Once you’ve defined your variables in the css-variables.liquid snippet, you can use them in your CSS files like this:

.my-element {
  color: var(--my-custom-color);
}

This method ensures that your custom styles remain connected to the theme settings, allowing for easy customization through the Shopify admin interface.

Best Practices for Working with CSS Variables in Shopify

Organizing Your Variables

Keep your variable definitions organized within the css-variables.liquid file. Group related variables together and use comments to explain their purpose. This practice will make it easier for you and other developers to maintain the theme in the future.

Leveraging Theme Settings

Make the most of Shopify’s theme settings by connecting your CSS variables to customizable options. This approach allows merchants to easily modify the look and feel of their store without diving into the code.

Testing and Debugging

When working with CSS variables, use browser developer tools to inspect and manipulate variables in real-time. This can be incredibly helpful for debugging and fine-tuning your styles.

Adapting to Shopify’s Evolving Theming System

Staying Informed

Shopify’s theming system continues to evolve, and staying informed about these changes is crucial. Regularly check Shopify’s official documentation and developer blogs for updates and best practices.

Embracing Modern CSS Techniques

The move away from SCSS to native CSS features like custom properties is part of a broader trend in web development. Embrace these changes and explore how modern CSS can improve your theme development workflow.

Community Resources

Engage with the Shopify developer community through forums, social media, and events. Sharing experiences and solutions with fellow developers can provide valuable insights and help you overcome challenges more quickly.

By understanding and adapting to these changes in Shopify’s theming system, developers can continue to create flexible, customizable themes that meet the needs of merchants and provide engaging shopping experiences for customers. The transition from SCSS to CSS variables may present initial challenges, but it also opens up new possibilities for efficient and dynamic theme development.

Take Our Quick Quiz:

Which primary product image do you think has the highest conversion rate?