Magento 2: File path for changes in css

Magento 2: File path for changes in css

September 16, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 2: File path for changes in css

Preserving CSS Changes in Magento 2: A Comprehensive Guide

Are you new to Magento 2 development and struggling to maintain your CSS changes? You’re not alone. In this post, we’ll dive into the intricacies of Magento’s static file generation process and provide a step-by-step guide to preserve your hard-earned styles.

Understanding Magento 2’s Static File Generation

Magento 2 uses a unique system for generating static files, including CSS, JavaScript, and images. These files are compiled from their respective source files and stored in the pub/static directory based on the theme and locale settings.

The default Magento themes—Blanks and Luma—are located at /app/design/frontend/Magento/. When you make changes to the CSS or JavaScript files in these directories, they get overwritten during the static file generation process, which occurs when performing a deployment (e.g., via bin/magento setup:static-content:deploy).

Preserving Your CSS Changes

To preserve your CSS changes without them being overwritten, you need to create a child theme and make your modifications there. Here’s how:

  1. Create a Child Theme

    Navigate to the /app/design/frontend directory and copy the luma folder to a new location, such as my_luma_child. Rename it accordingly.

mkdir my_luma_child
  1. Configure the Child Theme

    Open the my_luma_child folder and create a theme.xml file with the following content:

< theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
  <title>My Luma Child Theme</title>
  <parent>Magento/luma</parent>
  <media>
    <preview_image>media.preview.jpg</preview_image>
    <logo>media.logo.svg</logo>
  </media>
</theme>

Replace media.preview.jpg and media.logo.svg with the actual paths to your preview image and logo files.

  1. Make Your CSS Changes

    Navigate to /my_luma_child/Magento_Luma/css/source/_extend.less. This is where you can safely make your CSS modifications without them being overwritten during deployment.

  2. Configure the Theme in Magento’s Admin Panel

    Log in to your Magento admin panel and navigate to Stores > Configuration > General > Design. Set the theme for your store view to My Luma Child Theme (my_luma_child).

Best Practices for CSS Development in Magento 2

  • Always use Less or SCSS for your CSS files instead of plain CSS. This allows you to take advantage of variables, mixins, and other powerful features.

  • Avoid modifying the core theme files directly. As mentioned earlier, doing so can lead to your changes being overwritten during deployments.

  • Use Magento’s built-in theming system to create child themes. This ensures that your customizations remain intact even when you update the parent theme.

Conclusion

Persisting CSS changes in Magento 2 requires a solid understanding of the static file generation process and proper use of child themes. By following the steps outlined above, you can safely make modifications to the Luma theme without fearing them being overwritten during deployments.

If you’re looking for more advanced Magento development tips and best practices, be sure to check out our comprehensive guides at Laravel Company. We cover everything from module development to performance optimization.

Happy coding!

Magento 2 Themes Configuration Deployment

Our network