Skip to content

Floating WhatsApp button in HTML and CSS

A WhatsApp button pinned to the bottom of the screen that opens a welcome bubble with common topics and a pre-filled message, with no third-party widget.

Here is an excerpt of this component's code in HTML and CSS. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in HTML and CSS

index.html
<!doctype html>
<html lang="fr">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Bouton WhatsApp flottant</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <main class="demo">
      <div class="bwf-page">
        <header class="bwf-hero">
style.css
:root {
  --bwf-text: #0f1f17;
  --bwf-body: #3b4a42;
  --bwf-accent: #0f6b37;
  --bwf-surface: #ffffff;
  --bwf-line: #d5e6dc;
  --bwf-shadow: 0 12px 32px rgb(15 31 23 / 0.18);
  --bwf-fab-shadow: 0 8px 24px rgb(15 31 23 / 0.28);
  --bwf-head-bg: #0f5132;
  --bwf-head-text: #ffffff;
  --bwf-head-sub: #d1fae5;
  --bwf-greet-bg: #e7f6ec;
whatsapp-button.js
// Builds the wa.me link from the message, so nothing is loaded from WhatsApp before the visitor clicks.
document.querySelectorAll("[data-bwf]").forEach((root) => {
  const panel = root.querySelector("[data-bwf-panel]");
  const toggle = root.querySelector("[data-bwf-toggle]");
  const message = root.querySelector("[data-bwf-message]");
  const send = root.querySelector("[data-bwf-send]");
  const topics = root.querySelectorAll("[data-bwf-topic]");
  const base = `https://wa.me/${root.dataset.bwfPhone}`;

  function update() {
    const text = message.value.trim();
    send.href = text ? `${base}?text=${encodeURIComponent(text)}` : base;

Free component: copy it freely, including for commercial projects.

Buttons components in HTML and CSS
  • A row of buttons to share the page on Facebook, LinkedIn, WhatsApp or by email, with a copy-link button and no third-party script.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Toggle heart buttons that count favourites, remember them between visits and announce them to screen readers.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A button that adds an event to Google Calendar, Outlook or any calendar through an .ics file, with no third-party service.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A button that copies an IBAN, a reference, an address or a promo code and confirms "Copied", on screen and to screen readers.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A bar pinned to the bottom of mobile screens with Call and Directions buttons and a live open-now status, built for trades and local shops.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Circular icon buttons with an accessible tooltip on hover and focus.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component