October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

CSS Hover Effects: Examples and How to Create Them

Create CSS hover effects for buttons, links, and cards, and make sure the feedback remains usable for keyboard and touch users.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To create a CSS hover effect, write the element’s normal style, then add a state rule such as .button:hover to change its appearance while a pointing device is over it. Put any transition on the normal rule so the change animates both on entry and exit. Hover should add feedback, not be the only way to find information or use a control: provide keyboard focus feedback and a usable touch interaction too.

Start with a basic button hover effect

This example changes a button’s background color on hover and gives keyboard users a visible focus indicator:

<button class="button">Save changes</button>
.button {
  background: #2457d6;
  color: white;
  transition: background-color 160ms ease;
}

.button:hover {
  background: #173b98;
}

.button:focus-visible {
  outline: 3px solid #111;
  outline-offset: 3px;
}

The base .button rule defines the resting appearance. Adding :hover selects that same element while the pointer is over it. The separate :focus-visible rule supplies a keyboard focus treatment; hover and keyboard focus are different states.

CSS hover effect examples

Change a link’s color

Keep links identifiable when the pointer is not over them, then use hover as an additional cue:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
a {
  color: #174ea6;
}

a:hover {
  color: #982b16;
}

Reveal an underline

A text-decoration change gives a restrained response without moving surrounding content:

.text-link {
  text-decoration: none;
}

.text-link:hover {
  text-decoration: underline;
}

Do not rely on hover alone to make a link recognizable. Its resting style should still signal that it is a link.

Add a subtle shadow to a card

A shadow can make a card feel interactive without changing the space it occupies in the layout:

.card {
  box-shadow: 0 2px 8px rgb(0 0 0 / 10%);
}

.card:hover {
  box-shadow: 0 8px 24px rgb(0 0 0 / 18%);
}

Add a slight lift

A small transform can reinforce the shadow. Avoid changing margins or dimensions for hover feedback, since that can make nearby content jump:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.card {
  transform: none;
}

@media (prefers-reduced-motion: no-preference) {
  .card {
    transition: transform 160ms ease;
  }

  .card:hover {
    transform: translateY(-2px);
  }
}

Reveal an image overlay carefully

An overlay can add a visual treatment to an image, but do not place essential information or an action where it is only available on hover. Keep equivalent information and controls available at rest or through an interaction that also works on touch and keyboard.

How to choose properties and transitions

Use the property that expresses the feedback you need: color for a state change, text decoration or border for an affordance, shadow for elevation, or a small transform for motion. A transition belongs on the base rule rather than only the hover rule; that way the browser can animate both when the pointer enters and when it leaves. Specify only the properties the effect needs, such as background-color or transform, rather than animating unrelated styles.

Keep hover usable across links, keyboards, touch, and motion settings

Use the conventional link-state order

When link-state rules have equal specificity, put them in LVHA order: :link, :visited, :hover, then :active. Later rules can otherwise override earlier ones when both match.

a:link {
  color: #174ea6;
}

a:visited {
  color: #653a82;
}

a:hover {
  color: #982b16;
}

a:active {
  color: #111;
}

Provide a visible keyboard focus state

Keyboard users do not hover a control in the pointer sense. Add a visible focus style, for example with :focus-visible, and do not remove the browser’s focus indicator without replacing it with a clear one. MDN documents :hover, :focus, and :focus-visible among CSS pseudo-classes: MDN’s pseudo-classes reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Scope pointer-only decoration to hover-capable input

The (hover: hover) media feature can apply a decorative effect when the primary input can conveniently hover:

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
@media (hover: hover) {
  .card:hover {
    box-shadow: 0 8px 24px rgb(0 0 0 / 18%);
  }
}

This is a capability check, not a substitute for a touch interaction. MDN notes that touchscreen hover behavior can vary between browsers: there may be no hover match, a brief match, or a lingering state. In its :hover reference, MDN states, “The :hover pseudo-class is problematic on touchscreens.” See also its hover media feature reference.

Respect reduced-motion preferences

For motion effects, make the transition available only when the user has not asked the system to reduce motion. The lift example above uses (prefers-reduced-motion: no-preference); users who prefer reduced motion still get the card’s base appearance without the animated lift. For broader accessibility guidance, see web.dev’s accessibility module.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Test the effect and troubleshoot common problems

  • The hover style does not appear: Check that the selector matches the element and that another rule is not overriding it. For links with equally specific state rules, check LVHA order.
  • The effect works with a mouse but not as expected on a phone: Do not make content or a required action depend on hover. Provide a tap-accessible or persistent alternative; touch browsers differ in how they handle hover.
  • Keyboard users cannot see where they are: Add a clear :focus-visible treatment and navigate the page using the keyboard to check it.
  • Nearby content jumps: Avoid changing dimensions, margins, or positioning on hover. Prefer color, shadow, or a small transform that does not reflow surrounding content.
  • Motion is distracting: Restrict animated effects with prefers-reduced-motion and keep the reduced-motion presentation usable without animation.

Test the actual page with keyboard navigation and touch-capable input; a hover rule alone does not establish that a particular implementation works for every browser or device.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Or skip the browser setup

If you need a screenshot of a page showing a hover state, first make that state visible in the page or use a capture workflow that can interact with the element; a static screenshot request does not itself hover or click controls. ScreenshotNeo is a website screenshot API and MCP server from Yorker Media. Its browser capture accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; these steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses include X-Page-Verdict and X-Billed headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents.

One GET request returns an image or PDF. For example, capture a page as WebP with cURL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for parameters, including options for element capture and clicking an element before capture. ScreenshotNeo has 1,000 screenshots per month free with no card; paid plans start at $5 for 3,000. Learn about ScreenshotNeo or sign up for the free plan.

Quick Recap

SaleBestseller No. 1
HTML and CSS: Design and Build Websites
HTML and CSS: Design and Build Websites
HTML CSS Design and Build Web Sites; Comes with secure packaging; It can be a gift option
$14.18
SaleBestseller No. 3
SaleBestseller No. 4
Web Design with HTML, CSS, JavaScript and jQuery Set
Web Design with HTML, CSS, JavaScript and jQuery Set
Brand: Wiley; Set of 2 Volumes
$35.05

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.