Blog

Common CSS Challenges in HubSpot Themes and How to Solve Them

Written by Pawan Sharma | Jan 17, 2025 1:30:00 PM

HubSpot CMS themes are the best option for creating professional websites!

Developers sometimes encounter specific CSS challenges when using these themes, so don’t worry.

This blog explores some of the most common issues and offers practical solutions to help you overcome them, ensuring you achieve better performance, consistency, and an enjoyable user experience.

Template CSS Issues

Sometimes, you might notice that the preview and live environments don’t quite match up due to different CSS files being assigned. But don’t worry! 

Here’s a simple solution: 

Head to HubSpot's design manager to check which CSS file is linked to your template. It’s a good idea to make sure that both your preview and live environments are using the same CSS resources by looking at the template settings. And just to be safe, always try testing your changes in a staging environment before going live!

How to add custom CSS to HubSpot template file.

Use the Module’s Unique ID to Avoid Conflicts

Each module instance gets a unique ID. You can use to styles per instance.

Overwriting Theme Assets Safely

Editing parent theme files can put your customisations at risk during updates, so it's best to be cautious!

Here’s a simple solution: 

Create a HubSpot child theme to customise your website safely. Custom styles should be added to child.css and JavaScript to child.js. Avoid cloning parent theme files; override specific styles or scripts when needed

Use child.css to Override Theme Styles

Most HubSpot themes have a child.css file where you can safely override styles.

Steps:

  1. Navigate to your-theme/css/child.css
  2. Add your custom styles without modifying core theme files



Mapping Theme Settings to CSS Variables

Keeping a consistent style across our components can be challenging when we don't have mapped theme settings to guide us.

Here’s a simple solution: 

Embrace the power of CSS custom properties (variables) and harmonise them with your theme settings! By defining these variables in a root stylesheet, you can ensure easy management and consistency across your design. Plus, when you update the variables centrally, you'll effortlessly see the changes throughout your theme!

1. Define Theme Settings in fields.json

To allow users to configure styles from Theme Settings, define variables inside fields.json.

✅ Example (fields.json):