In this tutorial, we are going to learn how to add a pressed effect on a button using CSS. This effect is a part of modern UI design and is used on many websites. This effect allows the user to experience an interaction with the button element as compared to the normal behavior.
We’ll take advantage of the active pseudo class. This class is added to an HTML element automatically when it is clicked.
We can use CSS transform property to add a pressed effect on the button when it is active. CSS transform property allows us to scale, rotate, move and skew an element.
For this method, we can play with the translate function in CSS. We’ll use
translateY(length) function on active state of button. The translateY() function moves an element on y-axis to a given length (in px).
You can play with other methods when the
active pseudo-class is active to create your own effects when the button is clicked.
- How to call PHP function on the click of a Button ?
- How to create button dynamically with click event in Angular ?
- How to load notification alert on top right corner without click of button in bootstrap ?
- button tag vs input type="button" attribute
- CSS | Shadow Effect
- Parallax scrolling effect using CSS.
- How to disable a CSS :hover effect?
- How to use Explode effect in jQuery ?
- How to Create Paradoxical Effect using CSS ?
- jQuery | Effect fadeOut() Method
- jQuery | Effect show() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.