1

I am creating a CMS page, what is the proper way to add a style sheet for this page, through the Layout Update XML field like this <head><css src="Magento_Contact::css/styles.css"/></head>, or do i put the css in the modules css/source/_module.less sheet (this seems to apply the css for this page on all pages across the site which is unnecessary and unwanted)?

asked Jul 26, 2017 at 21:28

1 Answer 1

1

Yes you are correct _module.less will add to all pages, XML within "design tab -> Layout Update XML" (as you have discussed on CMS pages) or within theme however will allow you to target individual pages or types of pages.

Adding CSS to CMS page should be doable by adding below code to "Layout Update XML":

<head>
 <css src="css/cmsstyles.css" />
</head>

cmsstyles.css should go in your theme within web/css folder.

I have seen a few people having issues however with this on certain Magento version however this works for me currently on Magento 2.1.7.

See here for a similar question with many answers:

Adding CSS to a CMS page using Layout Update XML

Teja Bhagavan Kollepara
3,8275 gold badges33 silver badges69 bronze badges
answered Jul 26, 2017 at 21:54

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.