CSS & HTML

Maximize the Use of Hover in Modern CSS

By Aigars Silkalns Updated 7 min read

Maximize the Use of Hover in Modern CSS

Hover is still one of the best tools for hiding secondary actions, previewing content and adding polish, but it only works for people with a mouse. The modern way to use it is to treat hover as an enhancement: write the effect once, trigger it from hover and keyboard focus, and fall back to always-visible controls on touch screens. This guide shows the three patterns the original article covered (beautify, declutter, extra information) rebuilt with plain CSS.

No jQuery is needed for any of it. Everything below uses :hover, :focus-within, :focus-visible, :has() and the hover media feature.

What the old version did, and why it broke

The 2009 version leaned on jQuery mouseenter handlers that toggled display and positioned tooltips under the cursor. That approach has three problems today. Touch screens fire emulated hover on tap, so effects stick. Elements set to display: none cannot be reached by keyboard, so the content is invisible to anyone not using a mouse. And a script for something CSS handles natively adds weight and failure modes for no gain.

The three jobs hover does well

Hover effects fall into three groups, and each needs a different safety net.

Job Example What must also be true
Beautify Underline slides in, arrow appears on a link The link is still clear without the effect
Minimize clutter Quick-view and wishlist buttons on a product card Controls are reachable by keyboard and on touch
Show more information Tooltip, image preview Also appears on focus; nothing essential lives only here

Know when hover exists

Phones and tablets have no real hover. Browsers emulate it with a tap, which leaves an effect “stuck” on the last element touched. The hover media feature lets you apply hover-only behavior to devices that can actually hover. It reports on the primary input, and MDN lists it as Baseline widely available.

/* Everyone gets the base state: visible and usable */
.btn { background: var(--accent); }

/* Only hover-capable devices get the hover treatment */
@media (hover: hover) {
  .btn:hover { background: color-mix(in oklch, var(--accent), black 15%); }
}

On hybrid laptops with a touchscreen, hover: hover can be false if the touchscreen is the primary input, which would hide your hover effects from a mouse user. If the effect is purely decorative, @media (any-hover: hover), which is true when any connected input can hover, is the safer choice. Use hover: hover when the hover state hides something and the touch layout must stay visible.

The rule that follows from this: if hiding something behind hover is a design choice, the default (outside the media query) must show it. Touch users then see the controls all the time, and desktop users get the cleaner layout.

1. Beautify: a link arrow that is not just decoration

The original IconDock effect, an arrow appearing on link hover, is a good small example. Use a transition on translate and opacity, which animate smoothly, and give keyboard users the same treatment.

.title-link { text-decoration: none; }
.title-link::after {
  content: "\2192";
  display: inline-block;
  margin-inline-start: .25em;
  opacity: 0;
  translate: -6px 0;
  transition: opacity .2s, translate .2s;
}
.title-link:is(:hover, :focus-visible)::after { opacity: 1; translate: 0; }

@media (prefers-reduced-motion: reduce) {
  .title-link::after { transition: none; }
}

If an effect fires too easily as the pointer crosses the page, add a short transition-delay (around 100 to 150 ms) on the reveal only. That is a cheap hover-intent filter and needs no script.

Notice :is(:hover, :focus-visible). Pairing the two selectors is the single habit that fixes most inaccessible hover effects. :focus-visible matches when the browser decides a focus indicator is needed, typically keyboard navigation, so mouse clicks do not trigger the effect.

2. Minimize clutter: reveal actions on a card

Show product actions only when someone is interested in the card. Here the action row is visible by default and is hidden only on devices that can hover. :focus-within keeps it visible while any link inside the card has keyboard focus.

<article class="card">
  <div class="media">
    <img src="lamp.jpg" alt="" width="400" height="300">
    <div class="actions">
      <a href="/lamp/colors">Colors</a>
      <a href="/lamp">Quick view</a>
    </div>
  </div>
  <h2>Desk lamp</h2>
</article>
.media { position: relative; }
.actions {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  gap: 8px;
  padding: 12px;
  background: linear-gradient(transparent, #0009);
  transition: opacity .2s, translate .2s;
}
.actions a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

@media (hover: hover) {
  .actions { opacity: 0; translate: 0 8px; }
  .card:hover .actions,
  .card:focus-within .actions { opacity: 1; translate: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .actions { transition: none; }
}
Three product cards with a chair, a lamp and a mug; the pointer is over the lamp card, which shows Colors and Quick view buttons while the other two cards are dimmed
The pointer is over the middle card: its buttons appear and the siblings dim (the :has() rule below). Tabbing to a button in any card produces the same reveal.

Two details matter here. The buttons are hidden with opacity, not display: none, so they stay in the tab order and a keyboard user can land on them; :focus-within then reveals the row at that moment. And the @media (hover: hover) wrapper means a phone never hides them at all.

For ready-made versions of this idea, see our product grid with hover add to cart and team grid with hover reveal. If you want to go further with motion, Easy CSS Animation With Transition & Transforms covers the transition basics used above.

3. Show additional information: a tooltip that works on focus

The old approach used jQuery to position a tooltip under the cursor. A small tooltip that points at a control can be pure CSS. Keep the text short, connect it to the control with aria-describedby, and show it on hover and focus.

<span class="tip">
  <button aria-describedby="t1">Download</button>
  <span role="tooltip" id="t1">Free for personal and commercial use.</span>
</span>
.tip { position: relative; display: inline-block; }
.tip [role="tooltip"] {
  position: absolute;
  top: calc(100% + 8px);
  width: 240px;
  visibility: hidden;
  opacity: 0;
  transition: opacity .15s, visibility .15s;
}
/* invisible bridge so the pointer can travel from button to tooltip */
.tip [role="tooltip"]::before { content: ""; position: absolute; inset: -10px 0 100% 0; }

.tip:hover [role="tooltip"],
.tip:focus-within [role="tooltip"] { visibility: visible; opacity: 1; }

/* :has() lets the wrapper react to its child's focus state */
.tip:has(:focus-visible) button { outline: 3px solid var(--accent); outline-offset: 2px; }
A Download button with a visible focus ring and a dark tooltip below it reading Free for personal and commercial use
Reached by pressing Tab: the focus ring and the tooltip appear together.

Why the extra work? WCAG 1.4.13 (Content on Hover or Focus) asks that hover-revealed content be dismissible (usually with Escape), hoverable (the pointer can move onto it without it vanishing) and persistent (it stays until you move away). The invisible bridge handles “hoverable”. Pure CSS cannot handle “dismissible”, so add a small handler: Escape sets a data-dismissed attribute that hides the tooltip, and leaving the control clears it.

const tips = document.querySelectorAll('.tip');
document.addEventListener('keydown', (e) => {
  if (e.key === 'Escape') tips.forEach((t) => t.setAttribute('data-dismissed', ''));
});
tips.forEach((t) => ['mouseleave', 'focusout'].forEach((ev) =>
  t.addEventListener(ev, () => t.removeAttribute('data-dismissed'))));
.tip[data-dismissed] [role="tooltip"] { visibility: hidden; opacity: 0; }

I tested this in Chromium: the tooltip stays open while the pointer crosses the gap and rests on the tooltip, Escape closes it under both hover and focus, and the attribute is cleared on mouse leave or blur.

Tooltips must never be the only place a fact appears: touch users cannot trigger them reliably, so give them the same information in visible text or a click-to-open disclosure. Disabled buttons need extra care too. They are not focusable and in most browsers do not fire pointer events, so a tooltip on a disabled button never shows. Use aria-disabled="true" on a focusable button, or put the tooltip trigger on a wrapper, and explain why the action is unavailable.

For anything longer than a phrase, or anything with a link in it, use a click-to-open disclosure or the popover attribute instead. MDN lists popover as Baseline widely available (since April 2024). Its hint value is meant for hover and focus, and MDN notes such popovers are usually wired to mouseover and focus events with JavaScript. A declarative route is emerging: the interestfor attribute (interest invokers) shows a popover on hover, focus or long-press without a script, and shipped in Chromium (Chrome 142). It is not Baseline yet, so treat it as progressive enhancement and feature-detect it with Object.hasOwn(HTMLButtonElement.prototype, 'interestForElement').

Bonus: dim the siblings with :has()

Because :has() can select a parent based on its children, you can focus attention on one card by quieting the others. This was impossible in CSS when the original article was written and needed JavaScript.

@media (hover: hover) {
  .grid:has(.card:is(:hover, :focus-within)) .card:not(:is(:hover, :focus-within)) {
    opacity: .6;
    transition: opacity .2s;
  }
}

Keep the dimming subtle: text inside a faded card must still meet contrast requirements, so avoid going much below the value shown. It is a hint about where attention is, not a way to hide the rest of the page.

I tested the arrow, the card reveal, the sibling dimming and the tooltip together in one demo page in Chromium. The sibling dim and the card reveal share the same :hover and :focus-within selectors, so they stay in sync.

Hover checklist

  1. Every :hover rule that reveals or moves something has a matching :focus-visible or :focus-within rule.
  2. Hover-only hiding sits inside @media (hover: hover), so touch devices see everything.
  3. Hidden controls use opacity or visibility, not display: none, so they remain reachable while you tab. (With visibility: hidden, they are not focusable until shown, which is right for a tooltip but wrong for a button.)
  4. Animations are short, use opacity and translate, and are switched off under prefers-reduced-motion.
  5. Hover content stays visible when the pointer moves onto it, and can be dismissed.
  6. Nothing essential is available only on hover.

Need more patterns to start from? Browse the pricing table with hover effects and expanding search bar snippets, or the 30 truly interactive websites for inspiration on how far hover and motion can go.

62 comments from the archive
  1. first!

    I wonder if there is a simple way to make hover work trouble-free on IE browsers without javascript…

    great post by the way!

  2. Many sites now use these hover effects to reduce clutter throughout the interface, and I think it’s a great idea, but IE6 only supports :hover on a tags, so applying the hover effect to DIVs, TDs, etc relies on JavaScript to add the mouseover effect.

    A simple (and fairly old) example of this are the suckerfish CSS dropdowns that relies on JavaScript to add the :hover effect to LI tags.

  3. Same comment than others. Hover is a great tool for fairly simple interactivity improvement.
    It is still a pain that IE6 does not support it totally.
    Java script to fix it is widely available on the web and not too complex but it makes :hover complicated while it should be easy to use.

  4. Hover plays a major role in usability indeed.
    Great examples and tutorials.
    Thanks

  5. Nice Overview nick… Hover is one of my 1st preferences while designing any project. Thanks for the good read.

    DKumar M.
    @instantShift

  6. The big problem with hover is that you cannot use it on a device such as iPhone! You cannot hover, only touch.

  7. I really like the concept of using hover to minimize clutter
    like in many web apps and also commenters’ name/url in WebDesignerWall :)

  8. Another example of hover is in cpanel (go to ftp accounts). It’s not to special, but it gives some good ideas.

  9. thanks for this article. i will consider adding some hover elements into my project!

  10. Really solid post. Makes me get excited about DOM manipulation and jQuery. Thanks

  11. …but I was under the impression that you couldn’t apply hovers to anything other than a elements in Firefox et al?

  12. Good point! One question: do you use some kind of program for the lens effect?

  13. @Daniel H, you can use :hover on any element in IE7 onwards and all other major browsers, IE6 is the only one that wont have it.

  14. Oh, but you’ve forgotten the most common use of hover: to deny service to iPhone (or other touchscreen) users!

  15. Unfortunately Hover has it limits in CSS2. It is really beautiful in CSS3. And combined with Java even better.

    The downfall is that:
    1. Not many people have their browser up to date to have CSS3
    2. Some people have Javascript Turned Off

    Thus, some of those Maximized use of Hover can’t be even used at all.

  16. I have always given great importance to hover status in Web Design. Thanks for this helpful post!

  17. I have never even thought of using hovers outside of the typical color or text decoration swap. Thanks for the tip. I’m sure I’ll be creative with it one day.

  18. Using Hover to display a tool tip or additional information about a product or service is a phenominal idea.

  19. Excellent Examples, though many uses Javascript/JQuery and didn’t support old goody IE6 (div:hover).

  20. IE6 doesn’t do :hover, but don’t let that stop you from making your site beautiful. If the feature you want to implement is required for the site to function then use a javascript solution just for IE6, the rest can still use the :hover tag. If the feature is just for visual impact then it shouldn’t matter if IE6 users are missing out. Designs don’t have to look exactly the same in IE6 as everywhere else. As long as they still look good that is all that matters.

  21. The idea of minimizing clutter is a fantastic idea. These ideas shows that users are becoming used to how the web works and expect to see a Edit Delete Rename against a picture etc, so they know where to look. As designers that gives the ability to give users what they want in a more compact way.

    Lovely ideas thanks!

  22. Great article, I just love when CSS gets used for things that only a while ago were javascript’s domain.

  23. Great article, I’ll be testing the tutorials soon and maybe apply the hover on some websites

  24. I like the idea of using CSS to hide and show elements.

    I’m trying to build this idea into one my new sites this now. Instead of showing individual products and the products next to each other I’ve simply displayed the individual products with a “+” icon. When you roll over the icon the saver bundles appear, helping simplify the catalog. Thanks for the inspiration

  25. Great food for thought. I’ll be taking this into major consideration on my future site – really relevant points about minimising clutter, as most sites are all over the shop. I like it in relation to tutorials as well. I’m going to give it major thought over the weekend. Thanks as usual for your insightful blog.
    Blossom
    x

  26. hey, you should update your site a little more often because I love your posts, but after not seeing new ones for a while i forget to come back…

    otherwise, this is an awesome site i love it!

  27. Good collection of live examples and nice detailing.

    Let’s *’hover’* ;)

    enjoy :)

  28. Thank you for the inspiration! I agree, I don’t think people use hover to its fullest potential.

  29. Thank you for the inspiration! I agree, I don’t think people use hover to its fullest potential.

  30. Yeah! I started to use more of hover in last projects and I can tell one thing – it’s the easiest way to bring something cool for visitors what will force them to discover what else is prepared for them. It’s the way to bring some interactivity to serious page, I like it. Thanx for more inspiration!

  31. Only one person mentioned that this doesn’t work on touchscreen devices, like iPhone? This is a serious issue. Interactive mobile web devices are become VERY prevalent and MANY people are visiting websites on iPhones and other touchscreen devices. Using hover will render your website useless to millions of viewers on these touchscreen devices.

    Use hover with caution! Accessibility should almost always win over coolness!

    Andy

  32. I was just thinking about the hover effect to show more info just this morning. I’m glad I checked on your site and landed on this article. :)

  33. There are some great examples of hover effects here mainly because they are functional and aid useability – more often they really don’t. Nothing worse that being on a site where, where ever you move your mouse something pops up!

  34. I love this web!! I don`t speak english because I’m from Argentina, but I still understand something, I think jaja Thanks, this is great!! The best of the best!!!
    Sorry for the language

  35. Great post! It really came in handy when my client wanted to cram more info into one section of the page. Without this I would have had a bit of a tough time! Thanks for savig my bacon!

  36. Some nice examples of hover shown here. One of the best examples I can think of is the BBC website with the music widget on the home page. https://www.bbc.co.uk/ They use it really well to avoid clutter. Infact they use hover very effectively through the whole site.

  37. I hate to admit it, but hovering and other DHTML tricks makes my life easier and my users/customer happier.

  38. Very nice post. I love the hover effect you added on Best Web Gallery, it really gives the user a great preview quickly yet subtly.

  39. Thanks Thanks What’s the problem here? Google could bury the meager profit number from even the biggest media conglomerates.

  40. Is this the same type of hovering that one would use when creating a hover that would say give more detail to an item? It looks really similar. I am taking a refresher course on the latest in CSS, but they haven’t gone over the cool hovering that I see on so many shopping sites that give more detail of the products they are selling. This would be a very useful tool for me to learn. Thanks for the info you have here, if you happen to know where I can find info on what I am mentioning, please post it here – or send me an email. So far, they haven’t touched on what I want to learn more about at all in my course, and it only has two more weeks left of classes.

  41. Some great demo’s but I noticed IE8 displays a 2/3px border around the Animated Hover demo as the em block shifts. Flawless in firefox but IE8 could be considered problematic.

  42. The ultimate Tutorial about “How to impress your wife with CSS and JavaScript”. Everlasting!

    Thanks for that!

  43. The ultimate Tutorial about “How to impress your wife with CSS and JavaScript”. Everlasting!

  44. I hope you will keep updating your content constantly as you have one dedicated reader here.

  45. The image hoverblock is very eloquent and dead simple. Thanks for this resource!

  46. Best technical and tutorial design, This is a good and I will use for fix my picture.

  47. Recently i am looking fot the white iphone 4 conversion kit. If you have any recommendation, plz tell me. I will be very grateful!

  48. The Christmas time is comming, and the most desire present i want to get, is the latest white iphone 4, can i get one? Tell you after Xmas.

  49. These are really stunning, there are even some sites that are new to me. All the colour schemes complex 41are definatly brave but I really think they work to make the sites eye catching and engaging.

  50. dear sir/madam
    how to create css layout so please send me
    tutorials brajesh pathak

Comments are closed on this article.