How to Use Code Snippets in Hubspot Content
Hubspot makes it easy to reuse custom code across pages, blogs, and templates by storing it as a centralized snippet you can insert anywhere with a simple tag.
This guide walks you through creating, editing, and inserting code snippets so your development work in Hubspot stays consistent, maintainable, and fast to update.
What Hubspot Code Snippets Are
Code snippets are reusable blocks of code that live in the design manager. Instead of copying and pasting the same HTML, HubL, CSS, or JavaScript into multiple templates or modules, you reference a snippet once and manage it from a single location.
When you update a snippet, any template or module that references it will automatically use the latest version after you republish that asset.
Why Use Snippets in Hubspot Projects
- Centralize repeated logic like headers, footers, and signup sections.
- Reduce errors from manual copying and pasting.
- Make updates faster across large sites.
- Improve collaboration between developers and content editors.
Accessing the Design Manager in Hubspot
All snippet work happens inside the design manager. To get there:
- In your Hubspot account, click the settings or gear icon in the main navigation.
- Navigate to Website > Themes or directly to Tools > Design Manager, depending on your portal layout.
- Open the design manager to view your folders, templates, and coded files.
The design manager is where you will create and organize code snippets alongside other theme assets.
How to Create a Code Snippet in Hubspot
Follow these steps to create a new reusable snippet for your site or landing pages:
- Open the design manager in your Hubspot portal.
- In the left sidebar, navigate to the folder where you want to store the snippet.
- Click the File menu (or right-click in the file tree) and choose New file.
- In the file type options, select Snippet. This ensures Hubspot treats the file as a reusable code resource.
- Name your snippet clearly, for example newsletter-signup-snippet or pricing-table-snippet.
- Click Create to open the new snippet in the code editor.
You now have a dedicated file where you can write the code you want to reuse throughout your Hubspot content.
Writing Code in Your Hubspot Snippet
Inside the new snippet file, you can add:
- HTML structures, such as sections, divs, and forms.
- HubL tags and expressions for dynamic content.
- Inline CSS or class hooks that connect to your theme styles.
- JavaScript for interactive components (keeping best practices and performance in mind).
Save the file when you are finished. Hubspot will compile and make the snippet available to your coded templates and modules.
Finding the Snippet Tag in Hubspot
Each snippet has a unique HubL tag used to embed it. After creating a snippet:
- Confirm the snippet is selected in the design manager.
- In the code editor, look for the helper text at the top that shows the embed syntax.
- The usage will look similar to:
{% snippet "path/to/your-snippet" %}
Copy this tag exactly, including the file path, so you can insert it into templates or modules inside Hubspot.
Organizing Snippets for Large Hubspot Sites
To keep code manageable:
- Store global snippets (headers, footers) in a dedicated snippets folder.
- Use consistent naming, such as global-header-snippet.html.
- Document how each snippet is intended to be used.
Inserting Snippets into Hubspot Templates
Once a snippet exists, you can insert it into any coded template in the design manager.
- Open the desired template in the Hubspot design manager.
- Place your cursor where the repeated content should appear.
- Paste the snippet tag you copied earlier, for example:
{% snippet "Custom/snippets/newsletter-signup-snippet" %} - Save and publish the template.
Any page that uses this template will now display the snippet content wherever the tag is placed.
Using Snippets in Hubspot Modules
If you build custom coded modules in Hubspot, you can also embed snippets inside them:
- Create or open a coded module in the design manager.
- In the HTML + HubL section, paste the snippet tag.
- Optionally, wrap the tag in conditional logic or add fields so editors can control parameters.
- Save and publish the module, then add it to templates or pages.
This approach lets you combine reusable markup with editor-friendly controls in Hubspot.
Editing and Updating Snippets in Hubspot
One of the biggest advantages of snippets is centralized maintenance.
- Open the design manager and select the snippet file.
- Update the HTML, HubL, styles, or scripts as needed.
- Click Save and then Publish changes.
- Republish any templates or modules that depend on the snippet if required.
After publishing, every Hubspot page that uses those templates or modules will reflect the latest snippet version.
Version Control Best Practices in Hubspot
- Test major snippet changes in a staging or test template first.
- Add comments in the code to explain complex logic.
- Coordinate updates with your team so content editors know what is changing.
Where Snippets Can Be Used in Hubspot
You can leverage snippets across multiple asset types:
- Coded website templates for core site pages.
- Coded landing page templates for campaigns.
- Coded email templates (where supported by HubL).
- Custom coded modules used inside drag-and-drop layouts.
This flexibility helps standardize design and functionality across your entire Hubspot environment.
Limitations and Notes for Hubspot Snippets
Keep the following in mind when planning your architecture:
- Snippets are intended for coded templates and modules, not directly inside the visual page editor fields.
- Overly complex snippets may impact performance; keep logic lean where possible.
- Permissions in Hubspot govern who can edit or publish coded files, including snippets.
Understanding these constraints will help you design a stable, scalable setup.
Advanced Hubspot Snippet Tips
To get more from snippets, consider these patterns:
- Use HubL variables and conditionals inside snippets to handle small variations.
- Create base snippets for shared layout and extend them with module-level options.
- Combine snippets with theme fields so marketers can toggle features on and off.
With a thoughtful structure, you can turn Hubspot into a flexible component system driven by snippets.
Learning More About Hubspot Code Snippets
For detailed reference on supported features and syntax, review the official documentation: Hubspot code snippets help article.
If you need strategic or technical implementation support beyond what the basic docs cover, you can explore expert services at Consultevo, which specializes in marketing technology and implementation.
By structuring your reusable components as snippets and managing them through the design manager, you ensure your Hubspot website and landing pages stay consistent, easy to maintain, and ready to scale.
Need Help With Hubspot?
If you want expert help building, automating, or scaling your Hubspot , work with ConsultEvo, a team who has a decade of Hubspot experience.
“`
