Creating an Animated Pill Shaped button using HTML and CSS

A Pill−shaped button is a round corner attractive−looking button. The button can have transitions and hover effects to make it an attractive and smooth experience. We will use transitions in CSS to create smoothe hove effects. This type of button design can be used for various purposes, such as sign−up forms, call−to−action buttons, and more.

As an alternative implementation method, some developers may choose to use JavaScript to create animated buttons, which can provide more advanced animation effects and interactive features. However, this approach may require additional programming skills and can also increase the website's load time.


  • Define the viewport for the web page.

  • Write CSS code to style the buttons.

  • Define a class "button" for styling and create a pill shape for the button.

  • Set the background color for the button to #ddd, border to none, color to black, padding to 10px on the top and bottom, 20px on the left and right.

  • Center the text using text−align property, remove text−decoration, and display the button as an inline block.

  • Add a margin of 5px on the top and bottom and 3px on the left and right to the button.

  • Add a border radius of 20px to make the button look like a pill shape.

  • Add a hover effect to the button using the :hover pseudo−class in CSS.

  • When the user hovers over the button, change the background color to #f1f1f1 and add a transition effect with a duration of 0.5 seconds.

  • Add an h2 tag with the text "Pill Buttons".

  • Create two buttons using the button class: Button 1 and Button 2.


<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1">
/*buttons are styled and a pill shape is created*/
.button {
  background-color: #ddd;
  border: none;
  color: black;
  padding: 10px 20px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  margin: 5px 3px;
  border-radius: 20px;
/*Adding hover effect to the button*/
.button:hover {
  background-color: #f1f1f1;
  transition-duration: 0.5s;

<h2>Pill Buttons</h2>
<!-- Define buttons with button class -->
<button class="button">Button 1</button>
<button class="button">Button 2</button>



Pill shaped buttons are commonly used in websites, mobile applications, and as directed links. These buttons can also convey a sense of interactivity and responsiveness, making the website feel more dynamic and engaging. However, creating animated buttons can also have some constraints, such as increasing the website's load time, which may affect the user experience.

Some constraints of this animated pill−shaped button using HTML and CSS include:

  • Browser compatibility: The animation effects may not display correctly or may not be supported in all web browsers.

  • Load time: Animated buttons can increase the website's load time, which can affect the user experience, especially on slower internet connections.

  • Limited interactivity: HTML and CSS have some limitations when it comes to creating interactive features, such as hover effects or click animations.

  • Responsive design: The button's design and animation effects may not scale correctly on different devices or screen sizes.

Updated on: 18-Aug-2023


Kickstart Your Career

Get certified by completing the course

Get Started