<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/hover-proximity-using-modern-css-master-dev-blog-wa5xjv85b" -->

---
title: Hover Proximity Using Modern CSS – Master.dev Blog
description: An in-depth technique for creating a 'hover proximity' effect in CSS grids, where hovering an element visually affects nearby elements with distance-based...
canonical: https://daily.dev/posts/hover-proximity-using-modern-css-master-dev-blog-wa5xjv85b
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Hover Proximity Using Modern CSS – Master.dev Blog | daily.dev
og:description: An in-depth technique for creating a 'hover proximity' effect in CSS grids, where hovering an element visually affects nearby elements with distance-based...
og:url: https://daily.dev/posts/hover-proximity-using-modern-css-master-dev-blog-wa5xjv85b
og:image: https://api.daily.dev/og/posts/wA5XJV85B.png
og:image:alt: Hover Proximity Using Modern CSS – Master.dev Blog
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Hover Proximity Using Modern CSS – Master.dev Blog

**[Frontend Masters](https://daily.dev/sources/frontendmasters)** · 18 min read · 18 upvotes · 1 comments

## Summary

An in-depth technique for creating a 'hover proximity' effect in CSS grids, where hovering an element visually affects nearby elements with distance-based scaling, opacity, or border-radius changes—entirely without JavaScript. The approach calculates each element's [x, y] coordinates using sibling-index() and sibling-count(), derives the hovered element's coordinates via scroll-driven animations (view-timeline and animation-timeline tied to element position), and applies conditional styling using the new if() and style() query syntax. The piece also shows variations like selecting rows, columns, or diagonals, and closes with a distance-based formula for smooth proximity effects. Only Chrome and Edge fully support the required features at time of writing.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.master.dev/hover-proximity-using-modern-css>

## Questions this post answers

### How can I get the coordinates of a hovered element in a CSS grid without JavaScript?

Use scroll-driven animations with view-timeline defined on the hovered element via :hover and animation-timeline on the container, with overflow hidden making the container a scroll container. Two custom timelines track x and y position, animating variables from 0 to 1 that get multiplied by (columns-1) and (rows-1) and rounded to produce integer coordinates for the hovered item.

_Developers exploring CSS-only interaction tricks can find deep technical breakdowns like this on daily.dev._

### How do I calculate the number of columns in a responsive CSS grid using container queries?

Make the container a size container with container-type: inline-size, then compute columns with round(down,(100cqw + gap)/(size + gap)). This accounts for the fact that there are N-1 gaps between N columns, so the formula adds one gap to the container width before dividing, rounding down to get an integer column count.

_daily.dev helps developers track responsive CSS grid techniques like this as browser support evolves._

### How does the CSS if() function work with style queries to select elements by distance?

The if() function combined with style() conditions lets you branch styling based on custom property comparisons, such as checking whether abs(var(--x) - var(--i)) is less than or equal to a threshold to select elements within a certain grid distance from a hovered item. Conditions are evaluated in order, with an else branch as fallback, enabling proximity-based styling without JavaScript.

_Frontend developers weighing new CSS conditional syntax can stay current on features like if() via daily.dev._

## Community discussion

Top comments from developers on daily.dev.

**@agustinbarrientos** · 0 upvotes

> Could keyboard focus feed the same coordinates as pointer hover? That would preserve the proximity cue without adding a second system.

## Similar posts on daily.dev

- [Hover Proximity with Scroll-Driven Animations](https://daily.dev/posts/hover-proximity-with-scroll-driven-animations-uxxsa159d) · CSS Tip · 10 upvotes · 0 comments
- [Potentially Coming to a Browser :near\(\) You](https://daily.dev/posts/potentially-coming-to-a-browser-near-you-xgzxroft7) · CSS-Tricks · 30 upvotes · 0 comments
- [Extracting Grid Information Using CSS – Master.dev Blog](https://daily.dev/posts/extracting-grid-information-using-css-master-dev-blog-1k0d7bgns) · Frontend Masters · 3 upvotes · 0 comments
- [Elastic/Bouncy Hover Effect](https://daily.dev/posts/elastic-bouncy-hover-effect-0se5rz4ih) · CSS Tip · 47 upvotes · 2 comments

---

Tags: [#css](https://daily.dev/tags/css)

[View this post on daily.dev](https://daily.dev/posts/hover-proximity-using-modern-css-master-dev-blog-wa5xjv85b)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Hover Proximity Using Modern CSS – Master.dev Blog","url":"https://daily.dev/posts/hover-proximity-using-modern-css-master-dev-blog-wa5xjv85b","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/hover-proximity-using-modern-css-master-dev-blog-wa5xjv85b"},"datePublished":"2026-08-26T12:58:49.615Z","dateModified":"2026-09-14T06:32:03.313Z","description":"An in-depth technique for creating a 'hover proximity' effect in CSS grids, where hovering an element visually affects nearby elements with distance-based...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/263964519bc5a26f1d5982ad8b6ea2a9?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/263964519bc5a26f1d5982ad8b6ea2a9?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Frontend Masters","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Frontend Masters","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/d34dd87208f24090bfb0917307fcf89f","url":"https://daily.dev/sources/frontendmasters"},"commentCount":1,"discussionUrl":"https://daily.dev/posts/hover-proximity-using-modern-css-master-dev-blog-wa5xjv85b","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":18},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"css","timeRequired":"PT18M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Frontend Masters","item":"https://daily.dev/sources/frontendmasters"},{"@type":"ListItem","position":3,"name":"Hover Proximity Using Modern CSS – Master.dev Blog"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/hover-proximity-using-modern-css-master-dev-blog-wa5xjv85b","comment":[{"@type":"Comment","text":"Could keyboard focus feed the same coordinates as pointer hover? That would preserve the proximity cue without adding a second system.","datePublished":"2026-09-04T19:09:08.986Z","url":"https://daily.dev/posts/wA5XJV85B#c-YxELDYEwx","author":{"@type":"Person","name":"Agustin Barrientos","url":"https://daily.dev/agustinbarrientos","image":"https://media.daily.dev/image/upload/s--5ayxQnqn--/f_auto/v1788281802/avatars/avatar_wQYYVe5Tbj0NJ7C7qPoa8?_a=BAMAMicg0"}}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/hover-proximity-using-modern-css-master-dev-blog-wa5xjv85b#faq","mainEntity":[{"@type":"Question","name":"How can I get the coordinates of a hovered element in a CSS grid without JavaScript?","acceptedAnswer":{"@type":"Answer","text":"Use scroll-driven animations with view-timeline defined on the hovered element via :hover and animation-timeline on the container, with overflow hidden making the container a scroll container. Two custom timelines track x and y position, animating variables from 0 to 1 that get multiplied by (columns-1) and (rows-1) and rounded to produce integer coordinates for the hovered item. Developers exploring CSS-only interaction tricks can find deep technical breakdowns like this on daily.dev."}},{"@type":"Question","name":"How do I calculate the number of columns in a responsive CSS grid using container queries?","acceptedAnswer":{"@type":"Answer","text":"Make the container a size container with container-type: inline-size, then compute columns with round(down,(100cqw + gap)/(size + gap)). This accounts for the fact that there are N-1 gaps between N columns, so the formula adds one gap to the container width before dividing, rounding down to get an integer column count. daily.dev helps developers track responsive CSS grid techniques like this as browser support evolves."}},{"@type":"Question","name":"How does the CSS if() function work with style queries to select elements by distance?","acceptedAnswer":{"@type":"Answer","text":"The if() function combined with style() conditions lets you branch styling based on custom property comparisons, such as checking whether abs(var(--x) - var(--i)) is less than or equal to a threshold to select elements within a certain grid distance from a hovered item. Conditions are evaluated in order, with an else branch as fallback, enabling proximity-based styling without JavaScript. Frontend developers weighing new CSS conditional syntax can stay current on features like if() via daily.dev."}}]}
```

