My css is not working in magento 2

My css is not working in magento 2

August 15, 2026 · Illustrated author avatarBy Stefan Bogdanescu
My css is not working in magento 2

Overriding CSS in Magento 2: A Comprehensive Guide

If you’re facing challenges with your custom CSS not working as expected in Magento 2, you’ve come to the right place. This comprehensive guide will walk you through the process of overriding existing templates and applying your own styles efficiently.

Understanding the Magento 2 Theme Structure

In Magento 2, themes are stored under app/design/frontend. Each theme consists of a vendor name (usually your company’s domain), a theme name, and three folders: web, i18n, and theme.

The web folder contains all the front-end assets like CSS, JavaScript, and images. This is where you’ll be working primarily for customizing styles.

Creating Your Custom Theme

Let’s assume your company domain is mycompany.com and your theme name is my_first_theme. You would create a folder structure as follows:

app/design/frontend
└── mycompany
    └── my_first_theme
        ├── web
        │   ├── css
        │   ├── less
        │   ├── js
        │   └── media
        ├── i18n
        └── theme

Writing Custom CSS

1. Using LESS Files

Magento 2 uses the .LESS preprocessor for stylesheets. To add your custom styles, create a _theme.less file in your less folder:

app/design/frontend/mycompany/my_first_theme/web/less/_theme.less

Open this file and start writing your LESS code. Remember to include the correct selectors to override existing styles.

2. Using CSS Files

If you prefer plain CSS, you can use the css folder instead:

app/design/frontend/mycompany/my_first_theme/web/css/_theme.css

Write your custom CSS in this file, again ensuring you target the right elements with proper selectors.

Compiling and Deploying Your Styles

After writing or updating your stylesheets, you need to compile them into a single styles.css file that Magento 2 can use. You do this via the command line:

php bin/magento setup:static-content:deploy

This command will take all your LESS files and compile them using the default Magento theme settings.

Changing the Default CSS File

You mentioned finding a styles.css file in pub/media. This is actually the correct location for the compiled stylesheet that Magento 2 uses. If you modify this file directly, your changes should apply to both the front-end and back-end.

However, it’s best practice not to modify this file directly; instead, make your changes in your custom theme files (_theme.less or _theme.css), then compile and deploy as described above.

Conclusion

Overriding CSS in Magento 2 is a straightforward process once you understand the folder structure and how themes work. Remember:

  • Always create your custom stylesheets in the appropriate less or css folders of your theme.
  • Use the correct selectors to target the elements you want to style.
  • Never modify the styles.css file directly; always use the Magento 2 command-line tools for compiling and deploying.

If you need further assistance with Magento 2 development, feel free to explore our comprehensive guides at https://laravelcompany.com/magento-2-development-tutorials. We cover a wide range of topics from theme customization to module development.

Magento 2 Themes Errors JavaScript

Our network