How to Regenerate CSS File in pub/static Folder in Magento 2
Made a CSS change into the files of your theme?
Not able to see those changes in the pub/static folder?
Not being rendered on the frontend of the Magento 2 store?
No worries, I got your back here.
Read the solution to regenerate CSS file in pub/static folder in Magento 2.
As a store owner, you may want to change the layout or design on the frontend from time to time to keep the content updated according to the latest trend, potential customers’ taste or as your products or services get updated. However, you may have the issue reflecting the changes on the frontend that you implemented from the admin panel.
One of the reasons may be the failure of generating CSS file in pub/static folder in Magento 2.
Hence, you will have to regenerate CSS file in pub/static folder in Magento 2 to offer the new or updated content in the storefront to the customers.
Here’s how you can do it:
The solution to regenerate CSS file in pub/static folder in Magento 2:
Run the following commands to re-generate CSS, JS files, etc.
- php bin/magento setup:upgrade
- php bin/magento setup:static-content:deploy -f for Magento 2.2.x and Magento 2.3.x.If you are using Magento 2.1.x, use php bin/magento setup:static-content:deploy
- If you face permission issue, give 777 permission to pub/static generated var folders for Magento 2.2.x and Magento 2.3.x.For Magento 2.1.x, give permission 777 to var/view_preprocessed var/cache var/page_cache var/tmp var/generation pub/static
Note: You have to specify locale in php bin/magento setup:static-content:deploy.
e.g php bin/magento setup:static-content:deploy -f hi_IN for Hindi (India)
That was all.
If you still have any doubts, do not hesitate to mention them in the Comments section below. I’d be happy to help.
Feel free to share the solution on social media with fellow developers 😊
Thanks.
Also Read:
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
7 Comments
hi,
i’ve delete pub/static folder including .htaccess file. Now, CSS & js files not generating after running the deploy command. So, What can I do?
Thanks.
Hello,
One should not delete the folder directly.
Now, you can do one thing.
You can find the pub/static folders and paste it from the similar version of your Magento.
Thank You
Done that and it worked. But a few minutes later still the same…
Any ideas?
Hello,
It’s strange that it worked for you only for a few minutes! Never faced such an issue where pub/static is automatically removed.
Maybe it is due to some third-party module.
Thanks.
I haveanother similer error
missing pub/static file path on my web page. actual file and folder is there. How to fix this issue?
Hello Vipin,
Please try the solution at https://meetanshi.com/blog/remove-version-number-in-file-paths-in-magento-2/
I hope it helps.
Good article!