Close button not working on custom HTML banner built with HubSpot CTA feature

I am creating a banner using custom HTML and CSS via the CTA feature in HubSpot Content Hub.

Users need to be able to click a close button when they want to dismiss the banner. However, the close button cannot be clicked because the link acts as a wrapper, as shown below.

<div class="hs-web-interactive-inline" style="" data-hubspot-wrapper-cta-id="XXXXX" id="hs-cta-XXXXX" data-rendered="true">
 <!-- start module: path:@hubspot/inline_html_interactive --> 
 <style data-hubspot-cta-style="hs-inline-web-interactive-XXXXX">
.floating-banner {
}

.floating-banner img {
}

.close-btn {
}

.close-btn:hover {
}
</style> 
 <a href="https://cta-na2.hubspot.com/web-interactives/XXXXX" target="_blank" rel="noopener" class="hs-inline-web-interactive-XXXX " data-hubspot-cta-id="XXXX"> 
 <div class="floating-banner" id="floatingBanner">
 <button class="close-btn" id="closeBannerBtn" aria-label="close">×</button> 
 <img alt="banner" src="https://XXXXX/image-01.png">
 </div> </a> 
 <!-- end module: path:@hubspot/inline_html_interactive --> 
</div>

To be exact, even when the close button is clicked, it redirects to the link’s destination because the anchor link wraps the entire element and sits on a higher layer.

Are there any good workarounds for this? Do you have any ideas?

This is a common challenge when using HubSpot’s Custom HTML/Interactive CTAs. Because HubSpot’s engine prioritizes tracking, it automatically wraps your entire HTML block in an anchor tag (<a>). Since this wrapper sits “higher” in the DOM hierarchy, it intercepts all clicks before they reach your internal button.
The best solution is to use JavaScript Event Bubbling control. By adding a small script to your button, you can tell the browser to “stop” the click event from reaching the HubSpot wrapper.
Here is the code and the steps to implement it:

The Solution: stopPropagation()
In your Button Content (HTML) area, update your close button code to include these two specific JavaScript commands:

  • event.preventDefault(); (Prevents the link from opening)
  • event.stopPropagation(); (Prevents the click from “bubbling up” to HubSpot’s wrapper link)

1. The HTML
Update your button tag inside the CTA editor like this:
code
Html

<div class=“floating-banner” id=“floatingBanner”>
<!-- The onclick attribute here is the fix -->
<button class=“close-btn” id=“closeBannerBtn” aria-label=“close”
onclick=“event.preventDefault(); event.stopPropagation(); document.getElementById(‘floatingBanner’).style.display=‘none’;”>
×
</button>
<img alt=“banner” src=“https://XXXXX/image-01.png”>
</div>

2. The CSS (Styles Tab)
To ensure your close button is physically “clickable” and stays on top of the image, ensure your CSS has a high z-index and pointer-events:
code
CSS

.close-btn {
position: absolute;
top: 10px;
right: 10px;
z-index: 9999; /* Ensures it sits above the HubSpot link layer */
cursor: pointer;
pointer-events: auto; /* Explicitly tells the browser this element accepts clicks */
}

Why this works
In standard HTML, when you click a child element (your button), the click “bubbles up” to the parent element (HubSpot’s <a> tag).

By using event.stopPropagation(), you are effectively putting up a wall. The browser executes the “hide banner” command but never tells the parent <a> tag that a click happened, so the redirect never triggers.
How to verify it:

  • The Hover Test: When you hover over the banner image, you should see the destination URL in the bottom-left of your browser. When you hover over the X, that URL should ideally disappear or the cursor should remain a pointer.
  • The Click Test: Click the X. If the banner vanishes and you remain on the same page, the logic is working.

Pro-Tip for HubSpot CTAs:
If you find that event.stopPropagation() is still being overridden by HubSpot’s internal scripts, go to the Advanced section of your CTA and ensure that the “Close” button is a <button type=“button”> rather than an <a> or <input>. HubSpot’s script sometimes treats nested <a> tags differently.

Taken help from AI

“Thank you! It looks like I can avoid this by using JavaScript events. I really appreciate your insights. I’ll give it a try.”