<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-map-mouse-position-in-css-y6xmo5vz7" -->

---
title: How to Map Mouse Position in CSS | daily.dev
description: The goal is to create an invisible grid on the screen, and use the :hover pseudo-class to map each ‘cell’ to a set of values that we will allocate to the...
canonical: https://daily.dev/posts/how-to-map-mouse-position-in-css-y6xmo5vz7
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to Map Mouse Position in CSS | daily.dev
og:description: The goal is to create an invisible grid on the screen, and use the :hover pseudo-class to map each ‘cell’ to a set of values that we will allocate to the...
og:url: https://daily.dev/posts/how-to-map-mouse-position-in-css-y6xmo5vz7
og:image: https://api.daily.dev/og/posts/y6Xmo5vZ7.png
og:image:alt: How to Map Mouse Position in CSS
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.

# How to Map Mouse Position in CSS

**[CSS-Tricks](https://daily.dev/sources/css_tricks)** · 7 min read · 35 upvotes · 1 comments

## Summary

The goal is to create an invisible grid on the screen, and use the :hover pseudo-class to map each ‘cell’ to a set of values that we will allocate to the custom properties. We will use the mouse position to set the value of these properties, and then use them set the .square element’s width and height accordingly.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://css-tricks.com/how-to-map-mouse-position-in-css/>

## Community discussion

Top comments from developers on daily.dev.

**@ghost** · 1 upvotes

> Wonderful use of the SASS for loop and using custom CSS properties with calc() function.

---

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

[View this post on daily.dev](https://daily.dev/posts/how-to-map-mouse-position-in-css-y6xmo5vz7)

```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":"How to Map Mouse Position in CSS","url":"https://daily.dev/posts/how-to-map-mouse-position-in-css-y6xmo5vz7","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-map-mouse-position-in-css-y6xmo5vz7"},"datePublished":"2021-03-01T16:47:17.138Z","dateModified":"2021-10-07T14:17:10.317Z","description":"The goal is to create an invisible grid on the screen, and use the :hover pseudo-class to map each ‘cell’ to a set of values that we will allocate to the...","image":"https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/02/css-mouse-cursor-mapping.gif?fit=900%2C450\u0026ssl=1","thumbnailUrl":"https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/02/css-mouse-cursor-mapping.gif?fit=900%2C450\u0026ssl=1","isAccessibleForFree":true,"articleSection":"CSS-Tricks","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":"CSS-Tricks","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/css_tricks","url":"https://daily.dev/sources/css_tricks"},"commentCount":1,"discussionUrl":"https://daily.dev/posts/how-to-map-mouse-position-in-css-y6xmo5vz7","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":35},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"webdev,css","timeRequired":"PT7M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"CSS-Tricks","item":"https://daily.dev/sources/css_tricks"},{"@type":"ListItem","position":3,"name":"How to Map Mouse Position in CSS"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/how-to-map-mouse-position-in-css-y6xmo5vz7","comment":[{"@type":"Comment","text":"Wonderful use of the SASS for loop and using custom CSS properties with calc() function.","datePublished":"2021-03-01T17:55:07.096Z","url":"https://daily.dev/posts/y6Xmo5vZ7#c-kRjvvaU95","author":{"@type":"Person","name":"Deleted user","url":"https://daily.dev/ghost","image":"https://media.daily.dev/image/upload/s--hNIUzLiO--/f_auto/v1705327420/public/ghost_vlftth"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}}]}
```

