#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →

Maximizing Website Conversions: Creating Effective Sticky Call-to-Action Bars for Modern Businesses

Picture a long course page or blog post. The only "Book a demo" button sits at the top, and by the time a reader is convinced, three screens down, it has scrolled out of sight. A sticky call-to-action bar fixes that by keeping one action within reach as the reader scrolls. Done badly, it becomes one more thing covering the content. This tutorial builds a bar that appears only after the reader has scrolled past the top section, can be dismissed, works with keyboards and screen readers, respects phone notches, and reports clicks to analytics.

Decide what the bar is for

A sticky bar should carry one action, the one most readers of that page are likely to want next. On a course page that might be "Book a free demo"; on a product page, "Add to cart"; on a SaaS pricing page, "Start free trial". Two or three buttons in a bar compete with each other and with the page. Write the text before writing any code: a short statement of what the reader gets, and a verb on the button.

Step 1: The HTML

<div class="cta-bar" id="ctaBar" role="region" aria-label="Book a free demo">
  <p class="cta-bar__text">Free 30-minute demo class this Saturday</p>
  <a class="cta-bar__btn" href="/demo">Book a seat</a>
  <button class="cta-bar__close" type="button" aria-label="Dismiss">&times;</button>
</div>

Place it just before the closing </body> tag. The role="region" with a label lets screen-reader users find it as a landmark. The close control is a real <button>, so it works with the keyboard without extra code.

Step 2: The CSS

.cta-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 16px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: #14325c;
  color: #fff;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.15);
  transform: translateY(120%);
  visibility: hidden;
  transition: transform 0.3s ease, visibility 0.3s;
}
.cta-bar.is-visible {
  transform: translateY(0);
  visibility: visible;
}
.cta-bar__text { margin: 0; font-size: 15px; }
.cta-bar__btn {
  background: #ffb703;
  color: #14325c;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 6px;
  text-decoration: none;
  white-space: nowrap;
}
.cta-bar__btn:focus-visible,
.cta-bar__close:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.cta-bar__close {
  background: none;
  border: 0;
  color: #fff;
  font-size: 24px;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
}
body.has-cta-bar { padding-bottom: 72px; }

@media (max-width: 480px) {
  .cta-bar__text { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  .cta-bar { transition: none; }
}

A few choices here matter more than they look:

  • visibility: hidden while off-screen keeps the hidden button out of the tab order, so keyboard users do not land on something they cannot see.
  • env(safe-area-inset-bottom) adds space above the home indicator on phones with gesture bars. For it to work on iOS, the page's viewport meta tag needs viewport-fit=cover.
  • body.has-cta-bar adds bottom padding while the bar is visible, so the last lines of the page and the footer links are not hidden behind it.
  • The 44 px close button follows the common minimum touch-target size used in mobile design guidelines.

Step 3: Show it at the right moment

A bar that appears on page load just duplicates the button already in the hero. It is more useful once the hero has scrolled away. IntersectionObserver does this without listening to every scroll event:

const bar = document.getElementById("ctaBar");
const hero = document.querySelector(".hero");
let dismissed = false;
try { dismissed = sessionStorage.getItem("ctaDismissed") === "1"; } catch (e) {}

if (bar && hero && !dismissed) {
  const io = new IntersectionObserver(([entry]) => {
    const show = !entry.isIntersecting;
    bar.classList.toggle("is-visible", show);
    document.body.classList.toggle("has-cta-bar", show);
  });
  io.observe(hero);

  bar.querySelector(".cta-bar__close").addEventListener("click", () => {
    bar.classList.remove("is-visible");
    document.body.classList.remove("has-cta-bar");
    io.disconnect();
    try { sessionStorage.setItem("ctaDismissed", "1"); } catch (e) {}
  });
}

How it behaves: while any part of the hero is on screen, isIntersecting is true and the bar stays hidden. Once the hero scrolls fully out of view, the bar slides up. Scrolling back to the top hides it again. Clicking the close button hides it for the rest of the browser session; the try/catch blocks stop the script from failing in browsers that block storage. If the page has no element with the class hero, nothing happens, which is safer than a bar that appears everywhere.

Step 4: Track clicks

If the site uses Google Analytics 4 through gtag.js, send an event when the button is clicked, so you can compare the bar against the other buttons on the page:

bar.querySelector(".cta-bar__btn").addEventListener("click", () => {
  if (typeof gtag === "function") {
    gtag("event", "cta_click", { cta_location: "sticky_bar" });
  }
});

Register cta_location as a custom dimension in GA4 to see it in reports. The same idea, applied to links that leave your site, is covered in outbound link tracking, and a general GA4 setup is in tracking visitor behaviour with GA4.

Design rules that keep it helpful

  • Keep it short. One line of text on desktop, and on a phone a bar that takes only a small slice of the screen. Google's guidance on intrusive interstitials says banners using a reasonable amount of screen space are fine, while elements that cover the main content can hurt the mobile experience.
  • Do not stack it. If the site already has a cookie banner or a chat widget at the bottom, place the bar so they do not overlap, or show only one at a time.
  • Match the page. "Book a demo" on a pricing page makes sense; the same bar on a privacy policy page does not. Show it only on pages where the action fits.
  • Use real contrast. Text and button colours should meet WCAG contrast guidelines (4.5:1 for normal text).
  • Test it. Compare clicks and completed sign-ups with and without the bar, or with two versions of the text, over a few weeks. Change one thing at a time.

Top bar or bottom bar?

On phones, a bottom bar sits where thumbs reach easily, and it does not push the site header around. On desktop, a slim top bar under the navigation is also common. For a top bar inside the normal page flow, position: sticky; top: 0; is simpler than fixed, but it only sticks within its parent element, so place it as a direct child of body or of a full-height wrapper.

Related patterns

A floating action button does a similar job for app-like interfaces; see adding floating action buttons. For the page around the bar, read landing pages with effective CTAs and using AI to improve landing pages.

Placed Students

Our Clients

Partners

...