DEV Community

Je Phiri
Je Phiri

Posted on

1

Floating button for chat app in HTML, JavaScript and CSS

If you're looking to add a floating button for chat apps, you can achieve this using HTML, CSS, and JavaScript. Here's a simple example:

HTML
html
Copy
Edit
<!DOCTYPE html>




Floating Chat Button


<!-- Floating Chat Button -->
<div class="chat-button" id="chatButton">

</div>

<script src="script.js"></script>



CSS (styles.css)
css
Copy
Edit
.chat-button {
position: fixed;
bottom: 20px;
right: 20px;
background-color: #007bff;
color: white;
width: 60px;
height: 60px;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
cursor: pointer;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
transition: background 0.3s, transform 0.2s;
}

.chat-button:hover {
background-color: #0056b3;
transform: scale(1.1);
}
JavaScript (script.js)
js
Copy
Edit
document.getElementById('chatButton').addEventListener('click', function() {
alert('Chat button clicked! You can integrate this with a chat service.');
});
This code creates a simple floating chat button that you can integrate with a chat application like WhatsApp, Messenger, or a custom chatbot.
This floating chat app button appears at the bottom right of the screen and toggles a simple chat box when clicked.

Heroku

Amplify your impact where it matters most — building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (1)

Collapse
 
kelvincode1234 profile image
Precious Kelvin Nwaogu • Edited

Image description

Postmark Image

"Please fix this..."

Focus on creating stellar experiences without email headaches. Postmark's reliable API and detailed analytics make your transactional emails as polished as your product.

Start free