Magento – Magento 2 – custom CSS not showing up

cssmagento2

I recently started working in Magento 2, after reading docs and tutorial I set up my first magento site and is running successfully on my localhost.
I am now setting a new Magento 2 project, I used the same way I setup the previous project, but now, my custom.css file not loading and I can't even find that in the page source if it's loaded. I've checked many times the path etc., and everything seems OK.

I've added the custom.css file in the following path:

app/design/frontend/<vendor>/<theme>/Magento_Theme/layout/default_head_blocks.xml

I have noticed that running the command

php bin/magento setup:static-content:deploy

not generating the custom.css file in the static folder.
Please help me sort out where I am doing mistake.

Thanks.

Best Answer

Here is 2 ways to add you custom styles in your theme.

1. Backend

Navigate to Content > Design > Configuration > Select Theme > HTML Head section > Scripts and Style Sheets field

2. Less processor.

here is your theme directory

app / design / frontend / [vendor] / [yourtheme]

create new file

Magento_Theme / web / css / source / _extend.less

add new styles here


deploy changes

you need to deploy static content to see any changes. For development purpose Magento 2 provides grunt tool.

  1. cp package.json.sample package.json
  2. cp Gruntfile.js.sample Gruntfile.js
  3. npm install (yes you need node and npm installed)
  4. add your theme to this file

dev / tools / grunt / configs / themes.js

you will find luma example here

  1. cd Magento_root && grunt watch

More information here http://devdocs.magento.com/guides/v2.1/frontend-dev-guide/css-topics/css_debug.html