Skip to main content
Login Register
Code2night
  • Home
  • Blog Archive
  • Learn
    • Tutorials
    • Videos
  • Interview Q&A
  • Resources
    • Cheatsheets
    • Tech Comparisons
  • Languages
    • Angular Angular js ASP.NET Asp.net Core ASP.NET Core, C# ASP.NET MVC ASP.NET Web Forms C C# C#, ASP.NET Core, Dapper
      C#, ASP.NET Core, Dapper, Entity Framework DotNet General Web Development HTML, CSS HTML/CSS Java JavaScript JavaScript, HTML, CSS JavaScript, Node.js Node.js
      Python Python 3.11, Pandas, SQL Python 3.11, SQL Python 3.11, SQLAlchemy Python 3.11, SQLAlchemy, SQL Python 3.11, SQLite React Security SQL Server TypeScript
  • Post Blog
  • Tools
    • Beautifiers
      JSON Beautifier HTML Beautifier XML Beautifier CSS Beautifier JS Beautifier SQL Formatter
      Dev Utilities
      JWT Decoder Regex Tester Diff Checker Cron Explainer String Escape Hash Generator Password Generator
      Converters
      Base64 Encode/Decode URL Encoder/Decoder JSON to CSV CSV to JSON JSON to TypeScript Markdown to HTML Number Base Converter Timestamp Converter Case Converter
      Generators
      UUID / GUID Generator Lorem Ipsum QR Code Generator Meta Tag Generator
      Image Tools
      Image Converter Image Resizer Image Compressor Image to Base64 PNG to ICO Background Remover Color Picker
      Text & Content
      Word Counter PDF Editor
      SEO & Web
      SEO Analyzer URL Checker World Clock
  1. Home
  2. Blog
  3. HTML/CSS
  4. How to add a WhatsApp share button on a website

How to add a WhatsApp share button on a website

Date- Aug 22,2022 Updated Jan 2026 19397 Free Download Pay & Download
apiwhatsappcom Share to whatsapp

Understanding the WhatsApp Share Button

The WhatsApp share button is a simple yet powerful tool that enables users to share content from your website directly to their WhatsApp contacts. By integrating this feature, you enhance user experience and encourage content sharing, which can lead to increased traffic and engagement on your site. WhatsApp, being one of the most widely used messaging platforms globally, provides a unique opportunity to reach a diverse audience.

When users click the WhatsApp share button, a pre-filled message containing the link to your content is generated. This functionality not only saves time for users but also increases the likelihood of them sharing your content, as it requires minimal effort on their part.

Prerequisites

Before you start adding the WhatsApp share button to your website, ensure you have a basic understanding of HTML and CSS. Familiarity with linking external stylesheets will also be helpful. Additionally, you'll need access to your website's code to implement the necessary changes.

Adding the WhatsApp Share Button

To add the WhatsApp share button, you primarily need an anchor tag that links to the WhatsApp API. The following steps will guide you through the process:

First, include the Font Awesome library in your HTML to use its icons. Add the following line within the <head> section of your HTML:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

Next, create the anchor tag for the WhatsApp share button. Replace the URL in the href attribute with the link you want to share:

<a class="whts" href="https://api.whatsapp.com/send?text=https://www.code2night.com/" data-action="share/whatsapp/share"> <i class="fa fa-whatsapp"></i> </a>

This code creates a clickable WhatsApp icon that, when clicked, opens WhatsApp with the specified link. Users can then choose their contacts to share the link with.

Styling the WhatsApp Icon

To ensure that the WhatsApp button aligns with your website’s design, you can apply custom CSS styles. Below is an example of how to style the WhatsApp icon:

<style> 
.fa-whatsapp { 
    color: #fff; 
    background: linear-gradient(#25d366,#25d366) 14% 84%/16% 16% no-repeat, radial-gradient(#25d366 60%,transparent 0); 
} 
a.whts { 
    font-size: 38px; 
    margin: 35px; 
    vertical-align: top; 
    position: relative; 
    top: 2px; 
} 
</style>

This CSS will give your WhatsApp icon a distinctive look that matches WhatsApp's branding, making it easily recognizable to users.

How to add a WhatsApp share button on a website

Testing the WhatsApp Share Button

Once you have added the button and styled it, it's crucial to test its functionality. Click on the share button to ensure that it opens WhatsApp correctly. On desktop, it will prompt you to open WhatsApp Web. If you are on a mobile device with WhatsApp installed, it will directly open the app.

Ensure that the link is correctly populated in the message field. This is essential for the user experience, as a broken link can discourage sharing. If you encounter any issues, double-check the URL format and the WhatsApp API link structure.

Edge Cases & Gotchas

While adding a WhatsApp share button is straightforward, there are some edge cases and potential issues to be aware of:

  • URL Encoding: If your URL contains special characters (like spaces or symbols), ensure it is properly URL-encoded. For example, spaces should be replaced with %20.
  • Mobile vs. Desktop Behavior: The sharing experience differs between mobile and desktop. On mobile, the WhatsApp app opens directly, while on desktop, users are redirected to WhatsApp Web. Make sure to consider this in your design.
  • Browser Compatibility: Some browsers may handle the WhatsApp API differently. Test your implementation across multiple browsers to ensure consistent behavior.

Performance & Best Practices

To enhance the performance and usability of your WhatsApp share button, consider the following best practices:

  • Use a Clean URL: Ensure the URL you are sharing is clean and straightforward. Avoid unnecessary parameters that may confuse users.
  • Test on Multiple Devices: Always test the share button on various devices and browsers to ensure it works seamlessly everywhere.
  • Track Clicks: Use analytics tools to track how often the share button is clicked. This data can help you understand user engagement and improve your content strategy.
  • Positioning: Place the share button where it is easily accessible, such as at the end of an article or near the content that users are likely to share.

Conclusion

Adding a WhatsApp share button to your website can significantly enhance user engagement and make sharing content easier for your audience. By following the steps outlined in this tutorial, you can implement this feature effectively. Remember to test your implementation and monitor its performance to make any necessary adjustments.

Key Takeaways:

  • WhatsApp share buttons facilitate easy content sharing, enhancing user engagement.
  • Properly styling and positioning the button is crucial for usability.
  • Testing across devices ensures a seamless user experience.
  • Tracking analytics can provide insights into user behavior and content effectiveness.

S
Shubham Batra
Programming author at Code2Night — sharing tutorials on ASP.NET, C#, and more.
View all posts →

Related Articles

Responsive Slick Slider
Jul 28, 2022
Slick Slider with single slide
May 09, 2021
Code syntax higlighter using Prism js
Dec 12, 2020
Create a Music Player in HTML/CSS: Step-by-Step Guide
Sep 04, 2021
Previous in HTML/CSS
Responsive Slick Slider
Next in HTML/CSS
How to create a table with fixed header and scrollable body
Buy me a pizza

Comments

🔥 Trending This Month

  • 1
    HTTP Error 500.32 Failed to load ASP NET Core runtime 6,938 views
  • 2
    Error-An error occurred while processing your request in .… 11,272 views
  • 3
    Comprehensive Guide to Error Handling in Express.js 235 views
  • 4
    ConfigurationBuilder does not contain a definition for Set… 19,459 views
  • 5
    Mastering JavaScript Error Handling with Try, Catch, and F… 161 views
  • 6
    Mastering Unconditional Statements in C: A Complete Guide … 21,497 views
  • 7
    Unable to connect to any of the specified MySQL hosts 6,232 views

On this page

🎯

Interview Prep

Ace your HTML/CSS interview with curated Q&As for all levels.

View HTML/CSS Interview Q&As

More in HTML/CSS

  • How to create a table with fixed header and scrollable body 6464 views
  • Free PHP, HTML, CSS, JavaScript/TypeScript editor - CodeLobs… 4954 views
  • Child internet safety 4356 views
  • Complete Guide to Creating a Registration Form in HTML/CSS 4179 views
  • Mastering Chapter 1 CSS: A Complete Guide with Examples in H… 3737 views
View all HTML/CSS posts →

Tags

AspNet C# programming AspNet MVC c programming AspNet Core C software development tutorial MVC memory management Paypal coding coding best practices data structures programming tutorial tutorials object oriented programming Slick Slider StripeNet
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1770
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, Haryana, India
info@code2night.com
Quick Links
  • Home
  • Blog Archive
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
  • SEO Analyzer
Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • SQL Formatter
  • Diff Checker
  • Regex Tester
  • Markdown to HTML
  • Word Counter
More Tools
  • Password Generator
  • QR Code Generator
  • Hash Generator
  • Base64 Encoder
  • JWT Decoder
  • UUID Generator
  • Image Converter
  • PNG to ICO
  • SEO Analyzer
By Language
  • Angular
  • Angular js
  • ASP.NET
  • Asp.net Core
  • ASP.NET Core, C#
  • ASP.NET MVC
  • ASP.NET Web Forms
  • C
  • C#
  • C#, ASP.NET Core, Dapper
  • C#, ASP.NET Core, Dapper, Entity Framework
  • DotNet
  • General Web Development
  • HTML, CSS
  • HTML/CSS
  • Java
  • JavaScript
  • JavaScript, HTML, CSS
  • JavaScript, Node.js
  • Node.js
  • Python
  • Python 3.11, Pandas, SQL
  • Python 3.11, SQL
  • Python 3.11, SQLAlchemy
  • Python 3.11, SQLAlchemy, SQL
  • Python 3.11, SQLite
  • React
  • Security
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Made with for developers  |  Privacy  ·  Terms
Translate Page
We use cookies to improve your experience and analyze site traffic. By clicking Accept, you consent to our use of cookies. Privacy Policy
Accessibility
Text size
High contrast
Grayscale
Dyslexia font
Highlight links
Pause animations
Large cursor