All coursesCustom code in Webflow
Previewing, testing, & troubleshooting
We’re transitioning to a new UI, and are in the process of updating our Webflow University courses and videos.

Previewing, testing, & troubleshooting

Make sure your custom code runs where it should (and nowhere else)

Previewing, testing, & troubleshooting

Make sure your custom code runs where it should (and nowhere else)

Custom code can unlock new functionality, but it also means you need to double-check that it’s running where and when you expect it to. Unlike native Webflow features, custom code doesn’t always behave the same way in preview and published environments.

The goal of previewing and testing isn’t to catch every possible edge case. It’s to make sure your code is set up correctly before anyone else sees it.

Previewing custom code

Previewing custom code works a bit differently than previewing native Webflow features. Some scripts require custom code to be enabled, others depend on a published URL, and some behave differently in Preview mode.

Enable custom code in preview

In Webflow, custom code only runs in Preview when the Enable custom code setting is turned on.  This setting acts as a safety switch. It prevents scripts from running unintentionally while you’re building.

Enable custom code toggle turned on in Webflow’s Preview mode.

You can also turn this on by default in Site settings so new pages automatically allow custom code.

When preview mode isn’t enough

If custom code is enabled but still doesn’t appear to work, that could be because some scripts won’t run in Preview mode. 

This is especially common for scripts that:

  • Only run on published URLs
  • Require a real domain or page path
  • Depend on third-party services loading correctly

If something doesn’t appear to work in Preview mode, publishing to staging is a good next step.

A dropdown showing the option to publish to Staging in Webflow.

Checking & troubleshooting code

Most issues with custom code come from scope or placement, and you can usually spot them quickly once you know what to look for.

Start by checking scope.

Make sure the code is added at the right level — embedded in the layout, scoped to a single page, or applied site-wide. If a feature appears on the wrong page or shows up inconsistently, scope is often the cause.

Next, check placement.

Scripts placed in the <head> load earlier, while scripts placed before </body> load later and can interact with page content that’s already loaded. If a script depends on elements already being on the page, placement is often the difference between “works” and “doesn’t.”

Then, check for runtime issues.

If the code is scoped and placed correctly but still behaves unexpectedly, look at what’s actually happening on the page, such as:

  • A feature works on one page load but not another
  • A widget appears but doesn’t respond to interaction
  • Layout or interactions change after adding code
  • The site feels noticeably slower

When that happens:

  • Verify targets by confirming that the elements the script relies on actually exist on that page
  • Isolate the change by temporarily removing the most recent snippet to confirm it’s the cause

With this flow, you can narrow the issue down to scope, placement, or the script itself.

Rolling back safely with Backups

If a custom code change causes unexpected issues, you can always restore your site to a previous version to return to a stable state and re-test changes. Webflow periodically creates automatic backups, and you can also save your own. This is especially useful when experimenting or adding third-party scripts.

Webflow version Backups panel showing previous versions available for restore.

When to pause and reassess

If custom code affects multiple pages unexpectedly, causes performance issues, or conflicts with other tools, it may be best to remove it temporarily and revisit scope, placement, or the provider’s documentation before continuing.

Most custom code problems are placement problems, not coding problems. Preview intentionally, test with scope in mind, and make small changes before publishing.

Ready for more?

Next, we’ll look at best practices for maintaining custom code over time, so it stays understandable, performant, and easy to work with as your site grows.

No items found.

1

Getting started

Getting started
Getting started
Coming soon

1

Background & preview
5:00
Background & preview
Coming soon

1

Where you can add custom code
5:00
Where you can add custom code
Coming soon

2

Adding custom code

Adding custom code
Adding custom code
Coming soon

2

The code embed element
The code embed element
Coming soon

2

At the layout level (Code Embed element)
4:00
At the layout level (Code Embed element)
Coming soon

2

Page & site level code
Page & site level code
Coming soon

2

Page-level code
5:00
Page-level code
Coming soon

2

Site-level code
5:00
Site-level code
Coming soon

2

Custom code and the Webflow CMS
5:00
Custom code and the Webflow CMS
Coming soon

3

Managing custom code

Managing custom code
Managing custom code
Coming soon

3

Previewing, testing, & troubleshooting
5:00
Previewing, testing, & troubleshooting
Coming soon

3

Best practices for maintainable code
5:00
Best practices for maintainable code
Coming soon

4

Wrap up

Wrap up
Wrap up
Coming soon

4

Try it: Add custom code
5:00
Try it: Add custom code
Coming soon

4

Additional resources
4:00
Additional resources
Coming soon

Course progress

0%

Assessment

Up next

Best practices for maintainable code

Keeping custom code clear, predictable, and easy to change
Complete & continue
Complete course