INTRODUCTION
This project creates a modern animated button using HTML and CSS. The design focuses on a smooth flip effect that switches between two text layers when the user hovers over it. The background uses soft shadows to give a subtle 3D look that fits well with a neumorphic style. The layout centers the button on the screen so it stands out clearly. The code also includes transitions to make the animation feel smooth and responsive. Overall, it’s a simple interface element that adds a stylish interactive touch to any webpage.
code preview
html code
Button 3D Effect - Dark CSS
Dark CSS
Hover Me
css code
@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');
/* Reset default margins, padding, and set border-box */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
/* Center content on full screen with light gray background */
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: #e0e5ec;
}
/* Base button styling with gradient and shadow effects */
.btn {
position: relative;
box-shadow: none;
width: 130px;
height: 40px;
line-height: 42px;
color: #fff;
-webkit-perspective: 230px;
perspective: 230px;
cursor: pointer;
}
/* First span (front face) - rotated 90deg on load */
.btn span {
background: rgb(0, 172, 238);
background: linear-gradient(0deg, rgba(0, 172, 238, 1) 0%, rgba(2, 126, 251, 1) 100%);
display: block;
position: absolute;
width: 130px;
height: 40px;
box-shadow: inset 2px 2px 2px 0px rgba(255, 255, 255, .5),
7px 7px 20px 0px rgba(0, 0, 0, .1),
4px 4px 5px 0px rgba(0, 0, 0, .1);
border-radius: 5px;
margin: 0;
text-align: center;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
-webkit-transition: all .3s;
transition: all .3s;
}
/* First child - hidden initially with 3D rotation on X axis */
.btn span:nth-child(1) {
box-shadow:
-7px -7px 20px 0px #fff9,
-4px -4px 5px 0px #fff9,
7px 7px 20px 0px #0002,
4px 4px 5px 0px #0001;
-webkit-transform: rotateX(90deg);
-moz-transform: rotateX(90deg);
transform: rotateX(90deg);
-webkit-transform-origin: 50% 50% -20px;
-moz-transform-origin: 50% 50% -20px;
transform-origin: 50% 50% -20px;
}
/* Second child - visible initially */
.btn span:nth-child(2) {
-webkit-transform: rotateX(0deg);
-moz-transform: rotateX(0deg);
transform: rotateX(0deg);
-webkit-transform-origin: 50% 50% -20px;
-moz-transform-origin: 50% 50% -20px;
transform-origin: 50% 50% -20px;
}
/* On hover: first child rotates to front (0deg) */
.btn:hover span:nth-child(1) {
box-shadow: inset 2px 2px 2px 0px rgba(255, 255, 255, .5),
7px 7px 20px 0px rgba(0, 0, 0, .1),
4px 4px 5px 0px rgba(0, 0, 0, .1);
-webkit-transform: rotateX(0deg);
-moz-transform: rotateX(0deg);
transform: rotateX(0deg);
}
/* On hover: second child rotates away (-90deg) and text fades */
.btn:hover span:nth-child(2) {
box-shadow: inset 2px 2px 2px 0px rgba(255, 255, 255, .5),
7px 7px 20px 0px rgba(0, 0, 0, .1),
4px 4px 5px 0px rgba(0, 0, 0, .1);
color: transparent;
-webkit-transform: rotateX(-90deg);
-moz-transform: rotateX(-90deg);
transform: rotateX(-90deg);
}