# Using set\_response\_code(404) removes CSS / stylesheet

**URL:** <https://community.hubspot.com/t/using-set-response-code-404-removes-css-stylesheet/143836>\
**Category:** CMS Development\
**Created:** [December 9, 2025, 11:43am UTC](https://community.hubspot.com/t/using-set-response-code-404-removes-css-stylesheet/143836 "2025-12-09T11:43:27Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_al](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/_al/32/55480_2.png) [@\_al](https://community.hubspot.com/u/_al)\
**Post date:** [December 9, 2025, 11:43am UTC](https://community.hubspot.com/t/using-set-response-code-404-removes-css-stylesheet/143836/1 "2025-12-09T11:43:27Z")

</div>

We’re using {{ set\_response\_code(404) }} to manually trigger the 404 page under some circumstances.

This works fine, the 404 response code is set, and the 404-template is rendered instead of the template that triggered the 404.

We’re also using {{ require\_css(get\_asset\_url(‘../../dist/app.css’)) }} to add our stylesheet in our base-template. This too works fine obviously.

However, for some reason, when we trigger the 404, the app.css is removed from the rendered template.

Looking at the source code of a manually triggered 404 page, and a regular 404 page (a URL that simply doesn’t exist), they look identical except for one missing line which is \<link rel=stylesheet href=app.css\> (shortened) (also see screenshots of HTML).

Has anyone experienced this before? Why would this be happening? We’re fairly certain this actually did work a couple of months back because when we built this site we obviously tested it plenty, including the manually triggered 404-pages, and this bug never came up in testing.

 ![1232279_1_Screenshot 2025-12-08 at 11.54.54.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/0/0/0034ca306632818ba521edf7f1d8cf34a84916f5.png)

 ![1232279_2_Screenshot 2025-12-08 at 11.54.46.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/5/4/543413c85254eaf3fffffbc9f423ac3f487251b7.png)

---

<div class="post-metadata">

**Author:** ![Berangere](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/berangere/32/220784_2.png) [@Berangere](https://community.hubspot.com/u/Berangere)\
**Post date:** [December 9, 2025, 12:32pm UTC](https://community.hubspot.com/t/using-set-response-code-404-removes-css-stylesheet/143836/2 "2025-12-09T12:32:17Z")

</div>

Hi [@\_al](https://community.hubspot.com/t5/user/viewprofilepage/user-id/81188), I hope that you are well!  
Thanks for reaching out to the HubSpot Community!  
I’d like to share these resources that might help you:  
- [Require\_CSS](https://developers.hubspot.com/docs/cms/reference/hubl/functions#require-css)  
- [Error pages](https://developers.hubspot.com/docs/cms/start-building/building-blocks/templates/overview#error-pages)  
- [System Pages Tab](https://developers.hubspot.com/docs/cms/start-building/introduction/developer-environment/website-settings#system-pages-tab)  
Now, let’s put you in touch with our Top Experts: Hi [@Mike\_Eastwood](https://community.hubspot.com/t5/user/viewprofilepage/user-id/9259), @Anton and @Christensen do you have have any insights to share with [@\_al](https://community.hubspot.com/t5/user/viewprofilepage/user-id/81188), please?

Thanks so much and have a lovely day!  
Bérangère

---

<div class="post-metadata">

**Author:** ![\_al](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/_al/32/55480_2.png) [@\_al](https://community.hubspot.com/u/_al)\
**Post date:** [December 12, 2025, 12:35am UTC](https://community.hubspot.com/t/using-set-response-code-404-removes-css-stylesheet/143836/3 "2025-12-12T00:35:55Z")

</div>

Thanks for your reply, but those links won’t help at all which should be obvious if you read the question.

Here’s hoping someone with inner knowledge of HS CMS will reply. set\_response\_code() isn’t even a documented function so I don’t really expect to get a real answer to this.

---

<div class="post-metadata">

**Author:** ![Berangere](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/berangere/32/220784_2.png) [@Berangere](https://community.hubspot.com/u/Berangere)\
**Post date:** [December 12, 2025, 12:10pm UTC](https://community.hubspot.com/t/using-set-response-code-404-removes-css-stylesheet/143836/4 "2025-12-12T12:10:12Z")

</div>

Hi [@\_al](https://community.hubspot.com/t5/user/viewprofilepage/user-id/81188) and thanks for sharing these additional details.  
When using require\_css(get\_asset\_url(‘../../dist/app.css’)), the CSS is added to {{ standard\_header\_includes }} in the \<head\>.  
When set\_response\_code(404) triggers the 404 template to render instead of the original template, it seems the CSS requirements from the original template may not be carrying over.

Here are some workarounds you might want to try:

- CSS loaded via require\_css() is rendered within {{ standard\_header\_includes }} in the \<head\>. When a 404 template is triggered, it may be rendering a different template context that doesn’t include the CSS requirements from the original template.  
- Ensure your 404 template has its own require\_css() call for the stylesheet, rather than relying on inheritance from a base template.  
Let’s invite some of our Top Experts to this discussion: Hi @d-lupo, @RubenBurdin and [@sylvain\_tirreau](https://community.hubspot.com/t5/user/viewprofilepage/user-id/601366) do you have other suggestions to help [@\_al](https://community.hubspot.com/t5/user/viewprofilepage/user-id/81188), please?  
Thanks so much and have a wonderful weekend!  
Bérangère  
_This post was created with the assistance of AI tools._

---

<div class="post-metadata">

**Author:** ![\_al](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/_al/32/55480_2.png) [@\_al](https://community.hubspot.com/u/_al)\
**Post date:** [December 12, 2025, 1:57pm UTC](https://community.hubspot.com/t/using-set-response-code-404-removes-css-stylesheet/143836/5 "2025-12-12T13:57:05Z")

</div>

Thanks. Just to clarify, it’s only when we manually trigger a 404 using set\_response\_code() that this happens. Our 404-template is being rendered, but the CSS is missing.

When a regular 404 page shows up the very same template is rendered, but the CSS is NOT missing.

Regular 404: [https://gronflagg.se/this-is-a-404](https://gronflagg.se/this-is-a-404)

Manually triggered 404: [Demo Trip](https://gronflagg.se/resa/134811631852)

If you look at the Network tab in devtools you’ll see it loads the exact same things except for 4 files; the CSS (template\_app.min.css) and the three font files that the CSS references.

Our JS-file, included using {{ require\_js(get\_asset\_url(‘../../dist/app.js’)) }} is loaded in both cases however.

---

<div class="post-metadata">

**Author:** ![RubenBurdin](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/rubenburdin/32/75212_2.png) [@RubenBurdin](https://community.hubspot.com/u/RubenBurdin)\
**Post date:** [December 15, 2025, 3:22pm UTC](https://community.hubspot.com/t/using-set-response-code-404-removes-css-stylesheet/143836/6 "2025-12-15T15:22:57Z")

</div>

Hi [@\_al](https://community.hubspot.com/t5/user/viewprofilepage/user-id/81188) , yeah that’s a maddening one, especially since “real” 404s and “forced” 404s look like they should be identical.

What’s happening under the hood is usually about when HubSpot collects required assets. require\_css() doesn’t print a \<link\> immediately. It registers the dependency so HubSpot can later inject it into {{ standard\_header\_includes }} in the final \<head\> render.

HubSpot’s docs explicitly say the link tag is added inside standard\_header\_includes. ([https://developers.hubspot.com/docs/cms/reference/modules/files) And standard\_header\_includes is the mechanism that outputs “any attached stylesheets” plus other head bits. (](https://developers.hubspot.com/docs/cms/reference/modules/files)[https://developers.hubspot.com/docs/cms/reference/hubl/variables)](https://developers.hubspot.com/docs/cms/reference/hubl/variables)

With set\_response\_code(404), you’re in undocumented territory, and the most common failure mode is: the 404 swap happens after the dependency collection phase for the original request, so the “required CSS” registry is effectively reset or never re-applied to the system 404 render context.

That would also explain why your JS still shows up if it’s being required in a different phase or location.

One quick thing to sanity-check: is your set\_response\_code(404) called before anything outputs the \<head\> / before {{ standard\_header\_includes }} runs? If it’s not right at the top, try moving it as early as possible. If that still doesn’t fix it, the most reliable workaround is to ensure the 404 system template itself requires the theme CSS (and ideally via an absolute get\_asset\_url(‘/…’) path, not ../../), so the CSS requirement is registered in the actual template HubSpot ends up rendering. Hope this helps.

---

<div class="post-metadata">

**Author:** ![\_al](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/_al/32/55480_2.png) [@\_al](https://community.hubspot.com/u/_al)\
**Post date:** [December 18, 2025, 8:15pm UTC](https://community.hubspot.com/t/using-set-response-code-404-removes-css-stylesheet/143836/7 "2025-12-18T20:15:19Z")

</div>

Thanks for this. Makes sense. What’s confusing is that it did work previously (a few months back).

I guess I’ll try require\_css() again in the 404-template and hope that won’t make it include the CSS twice for regular 404s (where the CSS is already included).

The set\_response\_code() call is made on the module level, so well nested inside the base-template, the template that extends base and then a module that’s inside that template.

But I’ll keep digging.

---

<div class="post-metadata">

**Author:** ![\_al](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/_al/32/55480_2.png) [@\_al](https://community.hubspot.com/u/_al)\
**Post date:** [March 20, 2026, 9:43pm UTC](https://community.hubspot.com/t/using-set-response-code-404-removes-css-stylesheet/143836/8 "2026-03-20T21:43:32Z")

</div>

require\_css() in the 404-template file didn’t change anything.

What’s even more annoying is that templates that include set\_response\_code(404) can no longer even be used.

We have a few of them (templates that have a condition where a 404 may be triggered), and when the editor tries to save their website/landing pages using those templates HS just throws an error now.

This worked fine a few months ago.

Getting pretty tired of the HubSpot CMS developer experience…

---

<div class="post-metadata">

**Author:** ![STierney](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/stierney/32/186066_2.png) [@STierney](https://community.hubspot.com/u/STierney)\
**Post date:** [March 20, 2026, 11:24pm UTC](https://community.hubspot.com/t/using-set-response-code-404-removes-css-stylesheet/143836/9 "2026-03-20T23:24:58Z")

</div>

Hey [@\_al](https://community.hubspot.com/t5/user/viewprofilepage/user-id/81188),  
Thanks for following up here!  
I’d like to re-tag @RubenBurdin to see what else he may suggest here!  
Shane, Senior Community Moderator

---

<div class="post-metadata">

**Author:** ![GRajput](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/grajput/32/102020_2.png) [@GRajput](https://community.hubspot.com/u/GRajput)\
**Post date:** [December 18, 2025, 8:22am UTC](https://community.hubspot.com/t/using-set-response-code-404-removes-css-stylesheet/143836/10 "2025-12-18T08:22:13Z")

</div>

Hi [@\_al](https://community.hubspot.com/t5/user/viewprofilepage/user-id/81188)  
When a 404 is triggered manually using

`{{ set_response_code(404) }}`

, HubSpot may switch to the system 404 layout, which can skip any

`require_css`

calls from the original template. Adding the stylesheet directly in the 404 template or in a global include that the 404 template also uses ensures the CSS loads consistently.

I hope this will help you out. Please mark it as **Solution Accepted and upvote** to help another Community member.

Thanks!

---

<div class="post-metadata">

**Author:** ![\_al](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/_al/32/55480_2.png) [@\_al](https://community.hubspot.com/u/_al)\
**Post date:** [December 18, 2025, 8:17pm UTC](https://community.hubspot.com/t/using-set-response-code-404-removes-css-stylesheet/143836/11 "2025-12-18T20:17:02Z")

</div>

It doesn’t switch the template though. It renders the exact same template, only the CSS is missing for some reason.

---

<div class="post-metadata">

**Author:** ![STierney](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/stierney/32/186066_2.png) [@STierney](https://community.hubspot.com/u/STierney)\
**Post date:** [December 22, 2025, 6:04pm UTC](https://community.hubspot.com/t/using-set-response-code-404-removes-css-stylesheet/143836/12 "2025-12-22T18:04:12Z")

</div>

Hey [@\_al](https://community.hubspot.com/t5/user/viewprofilepage/user-id/81188) - thanks so much for these updates!  
I’d like to re-tag @GRajput to see if he has any insight given this extended context.  
Shane, Senior Community Moderator
