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)?

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

Your Answer

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

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