CSS Button Hover Effects
This example demonstrates how to create interactive button hover effects using CSS transitions, transforms, shadows, gradients, and pseudo-elements. Each effect provides visual feedback when a visitor moves the mouse pointer over a button.
Background Color Hover Effect
The :hover pseudo-class changes the button's background color when the pointer moves over it.
Color Change
The transition property creates a smooth change between the normal and hover background colors.
Outline Fill Hover Effect
An outline button starts with a transparent background and fills with color when hovered.
Outline Fill
This effect is useful for secondary buttons that become more prominent during interaction.
Lift Hover Effect
The transform property moves the button upward, while the shadow becomes larger to create a lifting effect.
Lift Button
The translateY() function moves the button vertically without changing the surrounding layout.
Scale Hover Effect
The scale() function increases the button's visual size when hovered.
Scale Button
This effect creates a subtle zoom animation without changing the button's actual layout dimensions.
Shadow Hover Effect
The box-shadow property creates a colored shadow around the button.
Shadow Effect
Shadows can help emphasize interactive elements and provide additional visual feedback.
Rounded Corner Hover Effect
The border-radius property changes the shape of the button's corners.
Rounded Button
This example changes a pill-shaped button into a button with slightly rounded corners.
Sliding Background Hover Effect
The ::before pseudo-element creates a colored background that slides across the button.
Sliding Background
The translateX() function moves the pseudo-element horizontally when the button is hovered.
Vertical Fill Hover Effect
A pseudo-element expands vertically to fill the button's background from bottom to top.
Vertical Fill
The scaleY() function controls the height of the background effect, while transform-origin: bottom determines where the animation begins.
Gradient Hover Effect
A linear gradient shifts its position when the button is hovered, creating a smooth color movement.
Gradient Shift
The background-position property controls which portion of the gradient is visible.
Border Hover Effect
The border color changes and an inset shadow creates the appearance of a thicker border.
Border Effect
This effect emphasizes the button without requiring a background color change.
Rotate Hover Effect
The rotate() function tilts the button slightly when hovered.
Rotate Button
Small rotations can create a playful effect, but should be used sparingly to avoid distracting visitors.
Animated Arrow Hover Effect
The arrow moves horizontally when the pointer moves over the button.
Continue →
This effect is commonly used for calls to action and navigation links.
Interactive Button Example
Select one of the buttons below to display a message. This demonstrates how CSS hover effects can be combined with JavaScript functionality.
Color Change
Lift Effect
Gradient Effect
Select a button to see the result.
Try It: Move your mouse over each button to compare the hover effects. Use the Tab key to test keyboard focus indicators, and select the buttons in the interactive example to display a message.
How Button Hover Effects Work
CSS hover effects use the :hover pseudo-class to apply styles when the pointer is positioned over an element.
The following CSS changes a button's background color:
.btn-color:hover {
background-color: #0b4564;
}
The hover state can modify background colors, text colors, borders, shadows, transforms, and other visual properties.
Using CSS Transitions
The transition property controls how smoothly a CSS property changes between states.
For example, the following declaration creates a smooth background color transition:
transition: background-color 0.3s ease;
The 0.3s value specifies the transition duration, while ease controls the timing function.
Transitions are useful for creating subtle effects that respond to user interaction.
The transform property changes an element's visual position, size, or rotation without affecting the normal document flow.
Common transform functions include translateY(), scale(), and rotate().
The following example moves a button upward when hovered:
.btn-lift:hover {
transform: translateY(-5px);
}
Transforms can be combined with transitions to create smooth movement effects.
Using CSS Pseudo-Elements
The ::before and ::after pseudo-elements allow additional decorative content to be styled without adding extra HTML elements.
In the sliding and vertical fill examples, a ::before pseudo-element creates the animated background.
The position: relative declaration establishes the button as the positioning reference for its absolutely positioned pseudo-element.
The overflow: hidden declaration prevents the animated background from extending beyond the button's boundaries.
Hover Effect Accessibility
Hover effects should enhance usability without being the only way to identify important actions.
Touchscreen devices may not provide a conventional hover interaction, so buttons should remain understandable without hovering.
The :focus-visible pseudo-class provides a visible focus indicator for keyboard navigation.
The prefers-reduced-motion media query disables transitions and movement effects for visitors who request reduced motion.
Use sufficient color contrast in both the normal and hover states to keep button text readable.
Customizing Button Hover Effects
You can change the hover colors by modifying the background-color, color, and border-color declarations.
Adjust the transition duration to make effects faster or slower.
Modify the transform values to control how far a button moves, scales, or rotates.
You can also combine effects, such as a background color transition with a subtle shadow or lift animation.
Keep hover effects consistent throughout your website to create a predictable and professional interface.