bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/CSS/Advanced Styling
CSS•Advanced Styling

CSS Button Hover Effects

This page covers CSS button hover effects, shadows, disabled states, and width.

CSS Hoverable Buttons

The CSS :hover pseudo-class is used to change the style of a button when you mouse over it.

Tip

Use the CSS transition-duration property to determine the speed of the "hover" effect:

Example

Formatted code
.button {
  transition-duration: 0.4s;
} .button:hover {
background-color: #4CAF50; /* Green */
color: white;
}

Live preview

CSS Buttons With Shadow

The CSS box-shadow property is used to add a shadow to a button:

Example

Formatted code
.button1 {box-shadow:0 8px 16px 0 rgba(0,0,0,0.6)} .button2:hover {box-shadow:0 8px 16px 0 rgba(0,0,0,0.6)}

Live preview

CSS Disabled Button

The CSS opacity property can be used to add transparency to a button (creates a "disabled" look).

Tip

You can also add the cursor property with a value of "not-allowed", which will display a "no parking sign" when you mouse over the button:

Example

Formatted code
.disabledbtn {
  opacity: 0.6;
  cursor: not-allowed;
}

Live preview

CSS Button Width

By default, the size of a button is determined by its text content.

The CSS width property can be used to define a specific width for a button.

Tip

Use pixels to set a fixed width, or percent for a responsive width (e.g. 50% of its parent element).

Example

Formatted code
.button1 {width: 250px;} .button2 {width: 50%;} .button3 {width: 100%;}

Live preview

Previous

CSS Styling Buttons

Next

CSS Button Groups

This chapter

Overview
53

Lessons

154m

Read time

1. CSS Rounded Corners2. Sass Tutorial3. CSS Border Images4. CSS Multiple Backgrounds5. CSS Background Size6. CSS Background Origin7. CSS Background Clip8. CSS Colors9. CSS Color Keywords10. CSS Gradients11. CSS Radial Gradients12. CSS Conic Gradients13. CSS Shadow Effects14. CSS Box Shadow15. CSS Text Effects16. CSS Custom Fonts17. CSS 2D Transforms18. CSS 2D Transform Scale19. CSS 2D Transform Skew / Matrix20. CSS 3D Transforms21. CSS Transitions22. CSS Transition Timing23. CSS Animations24. CSS Animation Timing25. CSS Animation Properties26. CSS Tooltip27. CSS Tooltip Arrows28. CSS Styling Images29. CSS Image Effects30. CSS Image Hover Overlays31. CSS Responsive Modal Images32. CSS Centering Images33. CSS Image Filter Effects34. CSS Image Shapes35. CSS object-fit Property36. CSS object-position Property37. CSS Masking38. CSS Gradient Mask Layers39. CSS SVG Mask Layers40. CSS Styling Buttons41. CSS Button Hover Effects42. CSS Button Groups43. CSS Pagination Styles44. CSS Multiple Columns45. CSS Column Rules46. CSS User Interface47. CSS Variables - var() Function48. CSS Overriding Variables49. CSS Variables and JavaScript50. CSS Variables in Media Queries51. CSS @property Rule52. CSS Box Sizing53. CSS Media Queries

On this page

CSS Hoverable ButtonsCSS Buttons With ShadowCSS Disabled ButtonCSS Button Width