How I can add critical path css rending in <style>body{color:#202020}</style> in header?

I did research but not getting clear picture. I can add meta and custom css file in default_head_blocks.xml but not sure about adding style tags in header section.

2 Answers 2


You don't need to make changes in any file to add style tag in head. You can do it from admin panel.

From admin Menu Go to Content->Design->Configuration. Now select you store view and click on edit from Action column.

Now under Other Settings Tab select HTML Head section and you can add your style inside Scripts and Style Sheets input.

  • Perfect this option is similar to Magento 1 but I need to load it via phtml or layout file for CMS page only.
    – Prabhakar
    Commented Feb 26, 2018 at 9:03
  • then instead of phtml file create separate css file and add that to your cms page
    – Piyush
    Commented Feb 26, 2018 at 9:11
  • @Piyush do you have any reference for it Commented Oct 21, 2019 at 8:10

You can add style tags directly into header.phtml which can be found under app/design/frontend/Your_Vendor/Your_Theme/Magento_Theme/templates/html if you have extended it in your theme or in the theme module of core magento (app/code/Magento/Theme or vendor/Magento/Module_Theme).

Do not change core files , extend it on your own theme.

  • I tried with phtml file in my theme and clear the cache but no help. Other scripts are loaded in head but not <style>..</style> tag.
    – Prabhakar
    Commented Feb 26, 2018 at 9:02
  • Please be clear on what you are asking, you have mentioned header in question description and head in question itself. Both are different things. Commented Feb 26, 2018 at 9:19
  • It's works. Custom template was not loading. Thanks for the quick help. One more query is there any way to load scripts meta or style only for cms page and not for whole site?
    – Prabhakar
    Commented Feb 26, 2018 at 9:19
  • You can add the script urls in cms_index_index.xml and check if it works. Commented Feb 26, 2018 at 9:25
  • Also mark my answer as accepted if it helped you Commented Feb 26, 2018 at 9:39

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.