Magento 2 LESS & CSS Customization

🎨 Magento 2 LESS & CSS Customization – Style Your Store Like a Pro

Magento 2 uses LESS (a CSS preprocessor) to make styles modular, reusable, and customizable. Want to make your store look unique? This is the place to start!

🔍 What is LESS in Magento 2?

  • Variables: Store common values like colors, margins, etc.
  • Mixins: Reusable chunks of CSS.
  • Nesting: Cleaner hierarchical CSS rules.

🧪 Where to Put Your Custom Styles

You should always add your changes in your custom theme, never in the core files. Here’s the file path:

app/design/frontend/Vendor/theme/web/css/source/_extend.less

✅ Example: Change Background Color Using LESS

@page__background-color: #f0f0f0;

body {
    background-color: @page__background-color;
}

Try It Now

📁 Required Theme File Structure

Create this folder layout for your custom theme if not already done:

app/design/frontend/Vendor/theme/
├── Magento_Theme/
│   └── layout/
│       └── default_head_blocks.xml
├── web/
│   └── css/
│       └── source/
│           └── _extend.less
└── theme.xml

Try It Now

🛠️ Add Your Theme to Magento

Declare the theme in theme.xml:


    Your Custom Theme
    Magento/blank

Try It Now

🧼 Deploy the Styles

Once you’ve made your changes, run:

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush

Try It Now

📌 Summary

  • Use _extend.less to override styles safely.
  • Stick to your custom theme – never touch core files!
  • Use LESS variables and mixins for consistency.
  • Don’t forget to deploy static content and flush cache.

Now you’re ready to make your Magento 2 store not just work well—but look amazing too! 🎉