<p>ok so after quite a few days, craft then updated and now it works. I didn't really do anything to fix it it just worked after updating</p>

CC BY-SA 4.0
2021-06-09T10:36:54.867Z
2021-06-09T10:36:54.867Z
Steven Zhang
<p>Why use <code>includeCssFile</code> at all for your core CSS? Typically you'd use that for injecting template-specific CSS files (e.g. carousel scripts) that you don't want to load on every page. (The advantage is that you can call that includeCssFile function in deeply nested templates without worrying about template inheritance or whether another partial has already included that CSS file).</p>
<p>So in short, just use a normal <code>&lt;link rel=&quot;stylesheet&quot; href=&quot;/css/main.css&quot;&gt;</code> for your core CSS file.</p>

CC BY-SA 4.0
2021-06-02T11:20:33.277Z
I tried this and it didn't make any difference unfortunately
Steven Zhang
CC BY-SA 4.0
2021-06-08T12:02:20.443Z
If that doesn't work, then really your problem is nothing to do with Craft.
James Smith
CC BY-SA 4.0
2021-06-09T13:11:08.373Z
This is the correct answer IMO. FYI ``includeCssFile`` is being [deprecated](https://craftcms.com/docs/3.x/upgrade.html#template-tags) as of Craft 3 so you'd want to replace with ``do view.registerCssFile`` as well.
RitterKnight
CC BY-SA 4.0
2021-06-01T10:34:02.337Z
2021-06-01T10:34:02.337Z
James Smith
<p>Can you please try <code>{%includeCssFile &quot;/css/main.css&quot;%}</code> (prepend with a /)</p>

CC BY-SA 4.0
2021-05-31T13:43:39.523Z
I changed `{%includeCssFile "css/main.css"%}` in my _layout.html template file to `{%includeCssFile "/css/main.css"%}` but now none of my web pages have css styling anymore, including my home page which worked before
Steven Zhang
CC BY-SA 4.0
2021-05-31T15:26:22.593Z
your CSS file is located in <projectRoot>/web/css/main.css. can you confirm that?
Matthias Redl-Mann
CC BY-SA 4.0
2021-06-01T01:47:14.450Z
Yep! my CSS file is in web/css/main.css
Steven Zhang
CC BY-SA 4.0
2021-06-01T05:59:48.417Z
OK, no clue why it does not work, but it must be something very obvious we are missing here. Without seeing this on a public server I can not go further into detail. If you want, you can send me a public URL via E-Mail at mr@getdesigned.at and I will have a look...
Matthias Redl-Mann
CC BY-SA 4.0
2021-05-31T12:13:03.693Z
2021-05-31T12:13:03.693Z
Matthias Redl-Mann
<p>So I am making a new craft cms website, I have my page entries linked to the template pages/_entry.html, which works fine. I then made another type of pages called news, linked to the template news/entry.html. Both of them have <code>{% extends &quot;_layout&quot; %}</code> to get a common layout and the css styling. when I click preview, the page entries work (including css) but the CSS of news entry doesn't show up, it simply goes to the default styling (which is no styling).
I tried making both the news and page entries have their templates linked to pages/_entry.html, and once again, only the page entries show up with proper css styling but not the news entry. I tried this with a product in craft commerce as well, and the same happened where no styling would be present.
I even tried switching both news and page entries to news/entry.html but with no luck, I get the same result.</p>
<p>Is this a bug with craft cms or am I doing something horribly wrong?</p>
<p>both pages/_entry.html and news/_entry.html only have <code>{% extends &quot;_layout&quot; %}</code> for now to troubleshoot this process. In my _layout.html I have <code>{%includeCssFile &quot;css/main.css&quot;%} </code> to link to my css file.</p>

CC BY-SA 4.0
2021-05-30T17:32:25.837Z
How do the URLs or your 2 sections "pages" and "news" look like? I guess it is just a relative path problem to your css file.
Matthias Redl-Mann
CC BY-SA 4.0
2021-05-31T11:07:57.663Z
@MatthiasRedl-Mann my URL for "pages" looks like:
Entry URI Format: {slug}
Template: pages/_entry

my URL for a product page looks like:
Entry URI Format: shop/products/{slug}
Template: pages/_entry

my URL for "news" page looks like:
Entry URI Format: {postDate.year}/{slug}
Template: pages/_entry

all three of them point to the same template, but only the "pages" have the proper CSS displayed, the rest have no CSS
Steven Zhang
<craft3><templating><plugin-craftcommerce><css>
CSS file not being read by other templates
# CSS file not being read by other templates

(Asked by: username_0 on 2021-05-30)

So I am making a new craft cms website, I have my page entries linked to the template pages/\_entry.html, which works fine. I then made another type of pages called news, linked to the template news/entry.html. Both of them have `{% extends "_layout" %}` to get a common layout and the css styling. when I click preview, the page entries work (including css) but the CSS of news entry doesn't show up, it simply goes to the default styling (which is no styling).
I tried making both the news and page entries have their templates linked to pages/\_entry.html, and once again, only the page entries show up with proper css styling but not the news entry. I tried this with a product in craft commerce as well, and the same happened where no styling would be present.
I even tried switching both news and page entries to news/entry.html but with no luck, I get the same result.

Is this a bug with craft cms or am I doing something horribly wrong?

both pages/\_entry.html and news/\_entry.html only have `{% extends "_layout" %}` for now to troubleshoot this process. In my \_layout.html I have `{%includeCssFile "css/main.css"%}`  to link to my css file.

**Tags:** craft3, templating, plugin-craftcommerce, css

> **Comments:**
> **username_1**: How do the URLs or your 2 sections "pages" and "news" look like? I guess it is just a relative path problem to your css file.  
> **username_0**: @MatthiasRedl-Mann my URL for "pages" looks like: Entry URI Format: {slug} Template: pages/_entry  my URL for a product page looks like: Entry URI Format: shop/products/{slug} Template: pages/_entry  my URL for "news" page looks like: Entry URI Format: {postDate.year}/{slug} Template: pages/_entry  all three of them point to the same template, but only the "pages" have the proper CSS displayed, the rest have no CSS  

---

## 3 answers

### Answer by username_0 on 2021-06-09. Score: 0 | Accepted answer

ok so after quite a few days, craft then updated and now it works. I didn't really do anything to fix it it just worked after updating


---

### Answer by username_2 on 2021-06-01. Score: 3

Why use `includeCssFile` at all for your core CSS? Typically you'd use that for injecting template-specific CSS files (e.g. carousel scripts) that you don't want to load on every page. (The advantage is that you can call that includeCssFile function in deeply nested templates without worrying about template inheritance or whether another partial has already included that CSS file).

So in short, just use a normal  for your core CSS file.

> **Comments:**
> **username_0**: I tried this and it didn't make any difference unfortunately  
> **username_2**: If that doesn't work, then really your problem is nothing to do with Craft.  
> **username_3**: This is the correct answer IMO. FYI ``includeCssFile`` is being [deprecated](https://craftcms.com/docs/3.x/upgrade.html#template-tags) as of Craft 3 so you'd want to replace with ``do view.registerCssFile`` as well.  

---

### Answer by username_1 on 2021-05-31. Score: 1

Can you please try `{%includeCssFile "/css/main.css"%}` (prepend with a /)

> **Comments:**
> **username_0**: I changed `{%includeCssFile "css/main.css"%}` in my _layout.html template file to `{%includeCssFile "/css/main.css"%}` but now none of my web pages have css styling anymore, including my home page which worked before  
> **username_1**: your CSS file is located in <projectRoot>/web/css/main.css. can you confirm that?  
> **username_0**: Yep! my CSS file is in web/css/main.css  
> **username_1**: OK, no clue why it does not work, but it must be something very obvious we are missing here. Without seeing this on a public server I can not go further into detail. If you want, you can send me a public URL via E-Mail at mr@getdesigned.at and I will have a look...  

---

