How to Add a Pressed Effect on Button Click in CSS? Last Updated : 15 Nov, 2024 Comments Improve Suggest changes Like Article Like Report To add a pressed effect on a button click using only CSS, you can use the :active pseudo-class, which applies styles when the button is clicked or tapped.1. Using CSS transform PropertyThe CSS transform property enables you to adjust an element's appearance by applying scaling, rotation, translation, or skewing effects. By leveraging the transform property, you can create a "pressed" effect on a button, making it look as though it's being pushed down when clicked.Syntaxtransform: scale() html <!DOCTYPE html> <html> <head> <style> .btn { border: none; padding: 12px 40px; font-size: 16px; background-color: green; color: #fff; border-radius: 5px; box-shadow: 7px 6px 28px 1px rgba(0, 0, 0, 0.24); cursor: pointer; outline: none; transition: 0.2s all; } /* Adding transformation when the button is active */ .btn:active { transform: scale(0.98); /* Scaling button to 0.98 to its original size */ box-shadow: 3px 2px 22px 1px rgba(0, 0, 0, 0.24); /* Lowering the shadow */ } </style> </head> <body> <button class="btn">Button</button> </body> </html> Output2. Using translate() FnctionThe translateY() function moves an element along the Y-axis by a specified amount. This movement can simulate the button being pressed downwards.Syntaxtransform: translateY() html <!DOCTYPE html> <html> <head> <style> .btn { padding: 15px 40px; font-size: 16px; text-align: center; cursor: pointer; outline: none; color: #fff; background-color: green; border: none; border-radius: 5px; } /* Adding styles on 'active' state */ .btn:active { box-shadow: 7px 6px 28px 1px rgba(0, 0, 0, 0.24); transform: translateY(4px); /* Moving button 4px to y-axis */ } </style> </head> <body> <button class="btn">Click Me</button> </body> </html> OutputCSS is the foundation of webpages, is used for webpage development by styling websites and web apps.You can learn CSS from the ground up by following this CSS Tutorial and CSS Examples. Comment More infoAdvertise with us Next Article How to Add a Pressed Effect on Button Click in CSS? F frikishaan Follow Improve Article Tags : Web Technologies HTML CSS CSS-Misc CSS-Questions +1 More Similar Reads How to create a Ripple Effect on Click the Button ? A Ripple Effect on button click is a visual animation where a wave-like circle spreads outward from the click point, simulating a water ripple. This effect enhances user interaction feedback, making button clicks feel more dynamic and visually engaging.ApproachHTML Structure: Uses an <button> 2 min read How to Add Shadow to Button in CSS ? This article will show you how to add shadow to a button using CSS. Button shadow can enhance its visual appeal and make it stand out on your webpage. This article will cover various approaches to adding shadow to a button using CSS. Table of Content Add Shadow on button using box-shadow PropertyAdd 3 min read How to Create an Effect to Change Button Color using HTML and CSS ? The color-changing effect of a button is very common but what we are going to do a slightly advanced version of this effect. The background will change like a clip effect rotating at some particular angle. Approach: The approach is to provide two or three background and then rotating them on differe 3 min read How To Add Hover Effects To A Button In JavaScript? Modern web design would not be the same without hover effects, which improve user experience by giving visual clues when buttons and other interactive elements are interacted with.More flexibility and interactivity than can be achieved with CSS alone are made possible by the addition of dynamic hove 2 min read How to create Incoming Call Animation Effect using CSS ? In this article, we will learn how to create an incoming call animation effect, by using CSS. Approach: To create this effect, we essentially need to animate the shadow effects around the element frame, which can be easily manipulated using the CSS box-shadow property. It is described by X and Y off 2 min read Like