Create Social Media Sharing Buttons

Create Social Media Sharing Buttons

Adding social media share buttons to your website gives users an easy way to share your content, improving your visibility on social networks. This guide explores the importance of social media share buttons, their impact on user engagement, and a step-by-step tutorial for integrating these buttons into your site using HTML, CSS, and JavaScript.

Why are social media share buttons necessary?

Social media share buttons provide quick access to popular social platforms like Facebook, Twitter, LinkedIn and WhatsApp. Here’s why they are indispensable for modern websites:

  • Extended Reach: Share buttons make it easy for visitors to share your content with their followers, increasing visibility and expanding your audience reach organically.
  • Increased Engagement: A website with share buttons encourages more interaction, fostering a community around your content.
  • Improved SEO: While search engines don’t directly factor social shares into rankings, traffic generated through social platforms can positively impact your SEO by increasing page visits and dwell times.
  • Enhanced User Experience: Visitors appreciate user-friendly features, and with an easily accessible share button, you’re providing a feature that encourages repeat visits and longer site sessions.

How to Add Social Media Share Buttons

Let’s break down the process of adding social media share buttons, using Bootstrap for styling and Font Awesome for icons.

Create the HTML Structure

Start with a simple HTML layout where your social media buttons will appear. Below is a sample HTML template with the required elements:

				
					<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Social Media Share</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.min.css">
</head>
<body>
    <div class="container">
        <div id="share-buttons" class="text-center mt-4">
            <p>Share this article:</p>
            <a class="facebook" target="_blank"><i class="fab fa-facebook"></i></a>
            <a class="twitter" target="_blank"><i class="fab fa-twitter"></i></a>
            <a class="linkedin" target="_blank"><i class="fab fa-linkedin"></i></a>
            <a class="whatsapp" target="_blank"><i class="fab fa-whatsapp"></i></a>
            <a class="telegram" target="_blank"><i class="fab fa-telegram"></i></a>
        </div>
    </div>
</body>
</html>

				
			

This HTML file includes:

  • A link to Bootstrap for styling.
  • Font Awesome icons for each social platform.
  • A simple structure with container and text-center classes for alignment.

Style the Buttons with CSS

				
					#share-buttons i {
    font-size: 50px;
    margin: 20px;
    opacity: 0.6;
    transition: opacity 0.3s;
}
.facebook { color: #3b5998; }
.twitter { color: #55acee; }
.linkedin { color: #0077b5; }
.whatsapp { color: #25D366; }
.telegram { color: #229ED9; }
.facebook:hover, .twitter:hover, .linkedin:hover, .whatsapp:hover, .telegram:hover {
    opacity: 0.9;
}
				
			
  • Sets font size and color based on each platform’s branding.
  • Includes hover effects for a smoother user experience.

Set Up JavaScript for Sharing

				
					const link = encodeURI("https://www.yourwebsite.com");
const msg = encodeURIComponent("Check out this great article!");
const title = encodeURIComponent("Your Article Title Here");

document.querySelector(".facebook").href = `https://www.facebook.com/share.php?u=${link}`;
document.querySelector(".twitter").href = `https://twitter.com/share?url=${link}&text=${msg}`;
document.querySelector(".linkedin").href = `https://www.linkedin.com/sharing/share-offsite/?url=${link}`;
document.querySelector(".whatsapp").href = `https://api.whatsapp.com/send?text=${msg}: ${link}`;
document.querySelector(".telegram").href = `https://telegram.me/share/url?url=${link}&text=${msg}`;

				
			
  • encodeURI and encodeURIComponent ensure the URL, title, and message are in a format accepted by each platform.
  • Each social media button is assigned a unique sharing URL, allowing users to directly share content with a single click.

Additional Tips for Maximizing Social Media Shares

  • Use Open Graph Tags: These meta tags define how shared content appears on social media platforms. For instance:
				
					<meta property="og:title" content="Your Article Title Here">
<meta property="og:description" content="A brief description of your content.">
<meta property="og:image" content="https://www.yourwebsite.com/image.jpg">
<meta property="og:url" content="https://www.yourwebsite.com">
				
			

Adding the Open Graph tag ensures that your content looks polished and professional when shared on platforms like Facebook and LinkedIn.

  • Add Analytics Tracking: Integrate Google Analytics or Facebook Pixel tracking with your share buttons to monitor how frequently they are used and which platforms drive the most traffic.

  • Place Buttons Strategically: Place share buttons where users are most likely to notice them, such as at the top of articles, alongside the content, or in a floating sidebar.

  • Choose Platforms Based on Audience: Not every platform is suitable for every audience. For instance, LinkedIn works well for professional content, while Instagram and Pinterest are ideal for visually-oriented posts.

Conclusion

Adding social media share buttons is an effective way to increase engagement and encourage user-generated promotion. By following the above steps, you can easily include share buttons in your website, which will benefit from increased visibility and better user experience. With a well-placed set of buttons and an understanding of your audience’s preferred social platforms, you’ll see positive results in traffic, engagement, and overall brand reach.

Social Media Share Button Source Code

FREE DOWNLOAD

Send download link to:

coding2w_newspaper

Leave a Reply

Your email address will not be published. Required fields are marked *