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 create a Ripple Effect on Click the Button ?
- How to set radio button checked by button click in AngularJS ?
- How to add input fields dynamically on button click in AngularJS ?
- How to Create an Effect to Change Button Color using HTML and CSS ?
- How to Design Stitched Glowing Effect for Button using HTML and CSS ?
- How to call PHP function on the click of a Button ?
- How to load notification alert on top right corner without click of button in bootstrap ?
- How to create button dynamically with click event in Angular ?
- How to click a button on webpage using selenium ?
- How to set checkbox checked on button click in AngularJS ?
- How to add many functions in one ng-click directive?
- How to add active class on click event in custom list group in Bootstrap 4 ?
- How to add a custom right-click menu to a webpage ?
- button tag vs input type="button" attribute
- How to create a radio button similar to toggle button using Bootstrap ?
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.