Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • jQuery
  • AngularJS
  • ReactJS
  • Next.js
  • React Native
  • NodeJS
  • Express.js
  • MongoDB
  • MERN Stack
  • PHP
  • WordPress
  • Bootstrap
  • Tailwind
  • CSS Frameworks
  • JS Frameworks
  • Web Development
Open In App
Next Article:
How to Create an Animated Search Box using HTML and CSS ?
Next article icon

How to create a animated pill shaped button using HTML and CSS ?

Last Updated : 26 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Most mobile applications and websites have some eye-catching animation that tries to grab the attention of the user, these animations trigger some event fire or on an infinite loop, website events are triggered on mouse clicks or mouse hovers while on mobile touch events or infinite loop is activated. Won’t you be glad to learn how to make one of those animations? now in this demo, we will be learning to make a website Share button animation that animates on mouse hover.

A glimpse of the Main outcome:

Animated Pill Shaped Button

Approach:

  • Make an HTML file.
  • Make a div with the choice of your name as a selector class, here we have used btn_wrap.
  • Make the outer overlay using a span tag, this will be the label of the pill.
  • Make a div with the class name of your choice to put the icons in.
  • Put the icons inside i element, you can put as many icons as you want, just don’t forget to increase the width of the pill.
  • Style the span, i, and container selectors accordingly.
  • Animate the btn_wrap while on hover using the transform property.
  • Add the transition delay on each child icon for smooth revelation.

HTML: Here we will create a structure according to our approach and make it a wrap as a share button on multiple social media platforms.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <!-- FontAwesome icon CDN Link -->     <script src= "https://kit.fontawesome.com/152767c355.js"              crossorigin="anonymous">     </script>     <title>Animated Pill Shaped Button</title> </head>  <body>     <!-- Button Wrapper -->     <div class="btn_wrap">         <span> Share </span>         <div class="container">             <!-- Individual Icon Buttons -->             <i class="fab fa-facebook-f"></i>             <i class="fab fa-whatsapp"></i>             <i class="fab fa-instagram"></i>             <i class="fab fa-twitter"></i>         </div>     </div> </body> </html> 

CSS: Here we will style our structure that has been created by using HTML.

CSS
body {     display: flex;     justify-content: center;     align-items: center;     height: 100vh;     background-color: #fefefe; }  i {     opacity: 0;     font-size: 28px;     color: #1f1e1e;     transform: scale(0.1); }  .btn_wrap {     position: relative;     display: flex;     justify-content: center;     align-items: center;     overflow: hidden;     cursor: pointer;     width: 240px;     height: 72px;     background-color: #eeeeed;     border-radius: 80px;     padding: 0 18px;     will-change: transform;     transition: all 0.2s ease-in-out; }  .btn_wrap:hover {     transform: scale(1.1); }  span {     position: absolute;     z-index: 99;     width: 240px;     height: 72px;     border-radius: 80px;     font-family: sans-serif;     font-size: 20px;     text-align: center;     line-height: 70px;     letter-spacing: 2px;     color: #eeeeed;     background-color: #1f1e1e;     padding: 0 18px;     transition: all 1.2s ease; }  .container {     display: flex;     justify-content: space-around;     align-items: center;     width: 240px;     height: 64px;     border-radius: 80px; }  .container i:nth-of-type(1) {     transition-delay: 1.1s; }  .container i:nth-of-type(2) {     transition-delay: 0.9s; }  .container i:nth-of-type(3) {     transition-delay: 0.7s; }  .container i:nth-of-type(4) {     transition-delay: 0.4s; }  .btn_wrap:hover span {     transition-delay: 0.25s;     transform: translateX(-280px); }  .btn_wrap:hover i {     opacity: 1;     transform: scale(1); } 

Complete Code: Here we will use the CSS in the HTML files’ head section, so we can see the output online.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <!-- FontAwesome icon CDN Link -->     <script src= "https://kit.fontawesome.com/152767c355.js"              crossorigin="anonymous">     </script>     <title>Animated Pill Shaped Button</title>     <style>         body {             display: flex;             justify-content: center;             align-items: center;             height: 100vh;             background-color: #fefefe;         }          i {             opacity: 0;             font-size: 28px;             color: #1f1e1e;             transform: scale(0.1);         }          .btn_wrap {             position: relative;             display: flex;             justify-content: center;             align-items: center;             overflow: hidden;             cursor: pointer;             width: 240px;             height: 72px;             background-color: #eeeeed;             border-radius: 80px;             padding: 0 18px;             transition: all 0.2s ease-in-out;         }          .btn_wrap:hover {             transform: scale(1.1);         }          span {             position: absolute;             z-index: 99;             width: 240px;             height: 72px;             border-radius: 80px;             font-family: sans-serif;             font-size: 20px;             text-align: center;             line-height: 70px;             letter-spacing: 2px;             color: #eeeeed;             background-color: #1f1e1e;             padding: 0 18px;             transition: all 1.2s ease;         }          .container {             display: flex;             justify-content: space-around;             align-items: center;             width: 240px;             height: 64px;             border-radius: 80px;         }          .container i:nth-of-type(1) {             transition-delay: 1.1s;         }          .container i:nth-of-type(2) {             transition-delay: 0.9s;         }          .container i:nth-of-type(3) {             transition-delay: 0.7s;         }          .container i:nth-of-type(4) {             transition-delay: 0.4s;         }          .btn_wrap:hover span {             transition-delay: 0.25s;             transform: translateX(-280px);         }          .btn_wrap:hover i {             opacity: 1;             transform: scale(1);         }     </style> </head>  <body>     <!-- Button Wrapper -->     <div class="btn_wrap">         <span> Share </span>         <div class="container">             <!-- Individual Icon Buttons -->             <i class="fab fa-facebook-f"></i>             <i class="fab fa-whatsapp"></i>             <i class="fab fa-instagram"></i>             <i class="fab fa-twitter"></i>         </div>     </div> </body> </html> 

Output: As you can see when the mouse hovers over the Share button pill the icons are revealed, here the example is for demo purposes, you can make the icons responsive and redirect accordingly or something creative.

https://media.geeksforgeeks.org/wp-content/uploads/20240724153459/202211191449511-ezgifcom-resize-video.mp4


Next Article
How to Create an Animated Search Box using HTML and CSS ?

S

satyamm09
Improve
Article Tags :
  • Technical Scripter
  • Web Technologies
  • Web Templates

Similar Reads

  • How to Create an Animated Search Box using HTML and CSS ?
    The task is to create an Animated Search Box using HTML and CSS. The search bar is one of the most important components of the website. Basically, it is used for connecting people with websites. In the face of complicated web content, users express their needs by searching keywords, expecting to obt
    2 min read
  • How to create animated banner links using HTML and CSS?
    Links are one of the most important parts of any component that is used in website making. Almost every component had some form of links in it. A common example is a menu/nav-bar. All we see is some button like home, about, etc. but under the hood they all are links. Sometimes there comes a situatio
    2 min read
  • How to create Shaky button using HTML and CSS?
    To create a shaky button using HTML and CSS involves adding an animation effect to a button element, making it appear to shake when interacted with. This effect can be used to draw attention to buttons, such as a snooze button or a button requiring immediate action. ApproachHTML page structure is de
    2 min read
  • How to create a shinny button using HTML and CSS ?
    Buttons are undoubtedly one of the most important components of any website or app. A button should be designed in such a way that it stands out of the other component so that it is becoming clear to the user where to click and what is the button used for. There are infinite ways in which a button c
    3 min read
  • How to Create a Dot loading Animation using HTML and CSS?
    The Dot Loading animation can be used to enhance the user interface of a website, it can be added while the website loads. This animation can be easily created using HTML and CSS. HTML Code: In this section we will create the basic structure of the dot loader using a div tag which will have some spa
    2 min read
  • How to create Animated bars using HTML and CSS?
    Dancing bars are one of the classical components that are used in making a good looking website. They are very simple to implement and can be used as a loader or an animation while recording sound. Approach: The approach is to use unordered list to create bars and then animate them using keyframes.
    2 min read
  • How to Create Animated Loading Button using CSS?
    An animated loading button provides a visual cue during processing, often featuring a spinner or pulsing effect. To create one using CSS, style a button element, include a spinner inside, and use CSS animations (like keyframes) to animate the spinner on button activation. Table of Content Using Font
    3 min read
  • How to Create Animated Loader Ring using HTML and CSS?
    An Animated Loader Ring using HTML and CSS is a circular loading animation that visually indicates progress or loading status. It is created with a simple HTML structure and animated using CSS properties like border, transform, and @keyframes for rotation effects. ApproachHTML Structure: The code us
    2 min read
  • How to Create Neon Light Button using HTML and CSS?
    The neon light button animation effect can be easily created by using HTML and CSS. By using HTML, we will design the basic structure of the button and then by using the CSS, we can create the neon light animation effect. HTML code: In this section, we will design a simple button structure using anc
    2 min read
  • Create a Tooltip Button Animation using HTML and CSS
    The Tooltip Animation can be implemented to display additional information about a user or profile when hovering over a designated button or icon. Animations, like tooltips and button animations, add a layer of interactivity to the user interface, making the experience more engaging and enjoyable. P
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences