How to Map Mouse Position in CSS

Let’s look at how to get the user’s mouse position and map it into CSS custom properties: --positionX and --positionY. We could do this in JavaScript. If we did, we could do things like make make an element …

The post How to Map Mouse Position in CSS appeared first on CSS-Tricks. You can support CSS-Tricks by being an MVP Supporter.

https://css-tricks.com/how-to-map-mouse-position-in-css/

Created 5y | Mar 1, 2021, 5:20:50 PM


Login to add comment

Other posts in this group

Covering hidden=until-found

Short story: Slapping hidden=until-found on an element in HTML enables any hidden content within the element to be findable in the browser with in-page search.


Aug 15, 2025, 1:30:21 PM | CSS tricks
On Accessibility Conformance, Design Systems, and CSS “Base” Units

My brain can’t help but try to make connections between seemingly disparate ideas. And that’s what happened yesterday when I read:

  • Hidde’s
Aug 14, 2025, 2:20:30 PM | CSS tricks
We Might Need Something Between Root and Relative CSS Units for “Base Elements”

I've come to realize that perhaps we need to have a unit between root and relative values. This would bring about a whole new possibility when creating reusable components.


Aug 13, 2025, 3:10:33 PM | CSS tricks
CSS-Questions

CSS-Questions is a mini site where you can test your CSS knowledge with over 100 questions.


CSS-Questions or

Aug 12, 2025, 3:50:20 PM | CSS tricks
Stuff & Nonsense Practical Layout Workshop

Web design veteran Andy Clarke is offering a two-hour workshop all about creating practical and creative page layouts this September 18. Register and save a few bucks with a coupon code.


Aug 11, 2025, 4:40:19 PM | CSS tricks
Getting Creative With Quotes

How do you design block quotes and pull quotes to reflect a brand’s visual identity and help tell its story? Here’s how I do it by styling the HTML blockquote element using borders, de

Aug 11, 2025, 2:30:13 PM | CSS tricks
How to Prepare for CSS-Specific Interview Questions

Get advice answering a set of 10 CSS-related questions you likely will encounter in front-end interviews.


Aug 8, 2025, 2:30:14 PM | CSS tricks