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 click a button on webpage using selenium ?
- How to call PHP function on the click of a Button ?
- How to add input fields dynamically on button click in AngularJS ?
- 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 ?
- How to Design Stitched Glowing Effect for Button using HTML and CSS ?
- How to Create an Effect to Change Button Color using HTML and CSS ?
- How to create a radio button similar to toggle button using Bootstrap ?
- button tag vs input type="button" attribute
- Vue.js | v-on:click directive
- AngularJS | ng-click Directive
- How to add many functions in one ng-click directive?
- HTML | DOM click() Method
- v-on:click.middle Directive in Vue.js
- How to remove focus around buttons on click?
- How to remove active nav-tab when click outside of nav-tab in 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.