Thomas Walichiewicz has proposed a :near() pseudo-class for CSS, published as a CSS Working Group issue at the end of 2025. The selector would match an element when the pointer comes within a given distance of it, with that distance supplied as a <length> argument.
button:near(3rem) {
/* Pointer is within 3rem of the button */
}
No browser supports the selector yet. Since the distance being measured is a straight line between pointer and element (the Euclidean distance, computable in JavaScript via the Pythagorean theorem), demos of :near() today have to simulate it rather than rely on engine support.
Where the selector fits
Dimming and hiding
A common motivation for :near() is reducing visual clutter: keep secondary components dimmed or hidden until the pointer approaches. Dimming has an advantage over :hover in that the trigger fires "earlier," which helps users who struggle to hit low-visibility targets — but any dimmed state still has to satisfy accessible color contrast requirements. Hiding avoids the contrast problem entirely, at the cost of a different accessibility concern.
The familiar example is a share button that appears when you hover an image, as on Pinterest. Users generally know the button sits in a corner but not its exact size or offset, so a :near()-triggered reveal means they don't need to hover with pixel precision.
Keeping such a button hoverable, focusable and find-in-page-able rules out the obvious hiding techniques:
display: hidden— not hoverable, focusable or findablevisibility: hidden— same problemsopacity: 0— once find-in-page locates it, there's no way to reveal it
That leaves content-visibility: hidden, whose catch is that the element ceases to occupy space — and you can't be near something that isn't there. Space must be reserved even though its size is unknown up front. Oddly enough, the same constraint applies to finding things by proximity that motivated the selector in the first place.
Reserving space in the simulation
A working simulation wraps the button in a container with 3rem of padding and reveals the button while that container is hovered. This enlarges the hoverable region instead of the button itself, effectively standing in for button:near(3rem).
The space-reservation half relies on two declarations working together:
contain-intrinsic-size: auto noneon the hidden target.automeans "whatever the rendered size was";noneis a required fallback that can also be a<length>, but here it isn't needed.- An animation that declares
content-visibility: visiblefor1ms, forcing a render so thatcontain-intrinsic-sizecaptures the button's size and reserves the space — after which the element can be hovered while invisible.
<div id="image">
<div id="simulate-near">
<button hidden="until-found">Share</button>
</div>
</div>
@keyframes show-content {
from {
content-visibility: visible;
}
}
button {
/* Hide it by default */
&:not([hidden="until-found"]) {
content-visibility: hidden;
}
/* But make it visible for 1ms */
animation: 1ms show-content;
/* Save the size while visible */
contain-intrinsic-size: auto none;
}
If the button instead carries hidden=until-found — the attribute-value that makes it focusable and find-in-page-able — content-visibility: hidden isn't declared explicitly, because the attribute handles that. In both cases the one-millisecond visible frame is what lets the intrinsic size capture happen.
<div id="image">
<div id="simulate-near">
<button hidden="until-found">Share</button>
</div>
</div>
@keyframes show-content {
from {
content-visibility: visible;
}
}
#simulate-near {
/* Instead of :near(3rem) */
padding: 3rem;
button {
/* Unset any styles */
border: unset;
background: unset;
/* But include size-related styles */
padding: 1rem;
/* Hide it by default */
&:not([hidden="until-found"]) {
content-visibility: hidden;
}
/* But make it visible for 1ms */
animation: 1ms show-content;
/* Save the size while visible */
contain-intrinsic-size: auto none;
}
&:where(:hover, :has(:focus-visible)) button {
color: white;
background: black;
content-visibility: visible;
}
}
content-visibility: hidden hides only content, not the element, which is why the simulated styles unset border and background; padding stays because it contributes to the size being rendered. The styles, along with content-visibility: visible, are then applied to the button when the wrapper is :hovered or matches :has(:focus-visible).
<div id="image">
<button hidden="until-found">Share</button>
</div>
@keyframes show-content {
from {
content-visibility: visible;
}
}
button {
/* Unset any styles */
border: unset;
background: unset;
/* But include size-related styles */
padding: 1rem;
/* Hide it by default */
&:not([hidden="until-found"]) {
content-visibility: hidden;
}
/* But make it visible for 1ms */
animation: 1ms show-content;
/* Save the size while visible */
contain-intrinsic-size: auto none;
&:where(:near(3rem), :hover, :focus-visible) {
color: white;
background: black;
content-visibility: visible;
}
}
Written with native :near(), the same behavior needs no wrapper markup and none of these selectors — the animation/contain-intrinsic-size technique remains available where accessibility demands it.
Near as a signal beyond selectors
Speculation Rules
No proposal exists to make :near() trigger prefetching or prerendering, and the selector's functionality isn't slated for extension. Even so, the Speculation Rules API already treats mousedown, touchstart, pointer direction and velocity, viewport presence and scroll pauses as signals to start prefetching/prerendering, so proximity is a plausible addition.
The case for treating "near" as a general concept is that custom hit-testing over pointermove carries high performance cost and implementation complexity, as Walichiewicz notes. A native notion of proximity could serve several features at once.
Hover-triggered overlays
Interest Invoker interactions are vulnerable to accidental pointer exits: the pointer can fall into the gap between trigger and target, or overshoot the target's bounds while reaching for elements near its edge. The API's interest-show-delay and interest-hide-delay properties guard against accidental activation and deactivation, but delay-based, time-sensitive interaction is not a pleasant user experience.
Proximity could supplement or replace the delays so overlays don't vanish on a mis-move, configured through a CSS property along the lines of near-radius: 3rem (or simply near: 3rem). Unlike :near(), such a property would invoke behavior — here the interest and loseinterest JavaScript events.
Walichiewicz's proposal adds a "drag to reorder" hint that appears when hovering near a draggable element; showing a tooltip even milliseconds sooner likely shortens task time. Simulating this with valid HTML is difficult, mainly because <a> and <button> can only contain certain elements.
Risks and accessibility
Misuse
Proximity hiding could encourage developers to bury content conditionally where better UI design was the right answer — or, perversely, to add clutter such as unnecessary icons because hiding them became easy. Heatmapping, fingerprinting and aggressive advertising are further abuse vectors, as are performance-damaging uses. The proposal itself documents these risks and discusses implementations that would thwart them.
Not hover, not focus
:near() must not imply :hover or :focus/:focus-visible. The question to ask before reaching for it is whether the behavior is preemptive or presumptive: users should never be led to believe they're hovering or focusing an interactive element when they aren't yet. This shows up throughout WCAG, most visibly in Success Criterion 2.4.7: Focus Visible (Level AA).
Related is Success Criterion 2.5.8: Target Size (Level AA), which requires interactive elements smaller than 24x24px to carry extra spacing calculated as 24px - target width / 24px - target height. Whether a :near() value would count toward that is ambiguous.
Open questions
Proximity as a first-class concept is worth pursuing: the selector as proposed, and the underlying measurement reused by Speculation Rules and Interest Invoker. Since the effects of :near() are already achievable today with extra markup and some CSS trickery, the pressure point is WCAG guidance — it must be rock-solid before any implementation starts.



