3

I tried to add some custom styles in Magento but I couldn't find out how to do this.

How do I add the custom css stylesheets in magento-2.2.6?

3

2 Answers 2

5

You need to follow the below steps:

Step 1: Create default_head_blocks.xml like below:

app/design/frontend/[vendor]/[theme]/Magento_Theme/layout/default_head_blocks.xml

Step 2: Andd create local.css like below

app/design/frontend/[vendor]/[theme]/web/css/local.css

Step 3: Add the below code to default_head_blocks.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../vendor/magento/framework/Module/etc/module.xsd">
  <head>
    <css src="css/local.css" />
  </head>
</page>
1
  • 1
    This is the most straightforward answer kudos! Commented Jul 10, 2019 at 9:58
5

You have to add it in your current theme like this:

  1. app/design/frontend/{Yourtheme}/{name}/Magento_Theme/layout/default_head_blocks.xml

    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../vendor/magento/framework/Module/etc/module.xsd">
        <head>
            <css src="css/local.css" />
        </head>
    </page>
    
  2. app/design/frontend/{Yourtheme}/{name}/web/css/local.css

    Your css code goe here
    
  3. Deploy the static content:

    php bin/magento setup:static-content:deploy -f
    
2
  • @nukala satish what did not work ?
    – PЯINCƎ
    Commented Jul 7, 2018 at 11:53
  • When i tried this in magento2.2.6. its not working brother Commented Oct 26, 2018 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.