Mar 27, 202511:38 AM - edited Mar 27, 202511:40 AM
Participant
How do i add stylesheet to my sections and templates?
SOLVE
Hello everyone, I am trying to add a stylesheet to my section and template. I created a new css+Hubl file in ProjectFolder > CSS > Sections/Templates I pick the same name that my Section/Template has starting with an underscore for the CSS file I created. In my section, I gave my dnd-section like this:
I used that class name in my section to style my section.
.career-main-header-style {
padding-bottom: 5rem !important;
background-color: red !important;
}
I also add my css filename to ProjectFolder > CSS > Main.css
/* Sections
Section CSS classes
*/
{% include './sections/_Career_Header_Section.css' %}
but the stylesheet is not working and the style doesn't apply to my section. is there anything i am missing? Is there any way i can style my sections and templates?
1. {% dnd_section %} doesn't support the class attribute, so you can't use it there. Instead, you can add the class to {% dnd_area %}.
2. {% include %} cannot be used in HubSpot templates to add CSS styles. {% include %} is meant for HubL partials (e.g., reusable templates or modules) but not for CSS files. Use {% require_css %} to load external or project CSS files.
This will apply CSS to your {% dnd_area %}. If you want to apply CSS to {% dnd_section %}, you can do either inline CSS or target via CSS Using dnd-section Class: .career-main-header-style .dnd-section{ background-color: red; }
I hope this will help you out. Please mark it as Solution Accepted and upvote to help another Community member. Thanks!
As above, you apear to be calling CareerPageTemplate.css where your file name is CareerPage.css but also in the context of main.css you would be compiling css so here you would use include. However you shouldn't need to have it both included in your main and called in the template, just one or the other.
1. {% dnd_section %} doesn't support the class attribute, so you can't use it there. Instead, you can add the class to {% dnd_area %}.
2. {% include %} cannot be used in HubSpot templates to add CSS styles. {% include %} is meant for HubL partials (e.g., reusable templates or modules) but not for CSS files. Use {% require_css %} to load external or project CSS files.
This will apply CSS to your {% dnd_area %}. If you want to apply CSS to {% dnd_section %}, you can do either inline CSS or target via CSS Using dnd-section Class: .career-main-header-style .dnd-section{ background-color: red; }
I hope this will help you out. Please mark it as Solution Accepted and upvote to help another Community member. Thanks!
How do i add stylesheet to my sections and templates?
SOLVE
Hi @GRajput Thanks so much for your prompt reply I tried to follow your instructions, but it still doesn't work Would you please guide me on how to modify my files this is my template
I created a new css+Hubl file in ProjectFolder > CSS > Sections/Templates
It seems your path to the css file is wrong here:
{% include './sections/_Career_Header_Section.css' %}
Right click on your css file and use copy path to get the full path to the file.
Also, I know
{% include "hubspot/styles/patches/recommended.css" %}
is mentioned in the hubspot documentation but I would have only ever used include for html content and testing it out now I can't get it to work.
I'd use require_css instead:
{{ require_css(get_asset_url('PATH TO YOUR CSS FILE')) }}
Edit: Ah, yes, the include method for css would only be used to compile your css files (as in main.css in the boilerplate). You can't use it in the context you're using it. Use the require_css method instead.
I'd love to put you in touch with some of our Top Experts: Hi @Anton, @BarryGrennan and do you have suggestions to help @ADuka, please?
Have a wonderful weekend and thanks so much in advance for your contributions! ❤️
Warmly, Bérangère
HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates. Learn More.
How do i add stylesheet to my sections and templates?
SOLVE
Hi @BérangèreL Thanks so much for your prompt reply I tried to follow your instructions, but it still doesn't work Would you please guide me on how to modify my files this is my template
As above, you apear to be calling CareerPageTemplate.css where your file name is CareerPage.css but also in the context of main.css you would be compiling css so here you would use include. However you shouldn't need to have it both included in your main and called in the template, just one or the other.
HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates. Learn More.