Button With Hover Effect using HTML and CSS


Posted on Jan. 28, 2021, 8 p.m. by Bishal     (  2842)


Card Thumbnail
In this blog of Code With Bishal, I am going to show you how can you create a Button with animation using HTML and CSS. So, stay with me till the end and you will get all the downloadable resources.

 

What is an Animated Button?

In HTML,   <button>  is an element used to create a clickable buttons. The button created in this tutorial gives visitors an attractive animated button made with HTML and CSS.

 

DigitalOcean Referral Badge

 

How can I try the code before downloading the resources?

You can try and customize the code using the try now button below or keep reading you will find a demo in this page.

 

 

DigitalOcean Referral Badge

 

 

Demo Button

 

 

Step by step guide for creating an Animated Button using HTML and CSS:

  • Create a file with the name index.html

  • Open index.html

  • Add the Broiler plate of HTML

 

DigitalOcean Referral Badge

 

Broiler Plate of HTML:

<!DOCTYPE html>
<html>
<head>
<title>Animated Button - Code With Bishal</title>
</head>
<!-- created by Code With Bishal - www.codewithbishal.com
-->
<body>
</body>
</html>
 
  • Create a file style.css

  • Link External CSS with your HTML file

Here is how can you link:

Add these code in the <head>  </head> of your HTML document:

<link rel="stylesheet" href="style.css">


Now add some style to your button:

Add these code to the style.css file

.button {
border-radius: 4px;
background-color: #9933ff; /* change this to change the background colour of button */
border: none;
color: #fff; /* change this to change the colour of text */
text-align: center;
font-size: 28px; /* change this to change the font size of the text */
padding: 20px;
width: 300px; /* change the width of the button */
transition: all 0.5s;
cursor: pointer;
margin: 5px;
}

.button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}

.button span::after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}

.button:hover span {
padding-right: 25px;
}

.button:hover span::after {
opacity: 1;
right: 0;
}


 

DigitalOcean Referral Badge

 

Source Code

1) HTML Code:

<!DOCTYPE html>
<html>
<head>
<title>Animated Button by Code With Bishal</title>
</head>
<body>
<button class="button"><span>Button With Animation </span> </button>
</body>
</html>

 

DigitalOcean Referral Badge

 

2) CSS Code:

.button {
border-radius: 4px;
background-color: #9933ff; /* change this to change the background colour of button */
border: none;
color: #fff; /* change this to change the colour of text */
text-align: center;
font-size: 28px; /* change this to change the font size of the text */
padding: 20px;
width: 300px; /* change the width of the button */
transition: all 0.5s;
cursor: pointer;
margin: 5px;
}

.button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}

.button span::after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}

.button:hover span {
padding-right: 25px;
}

.button:hover span::after {
opacity: 1;
right: 0;
}

 

 

 

DigitalOcean Referral Badge

 





Leave a Comment:
No comments Found. Be the First one to comment