---
title: "Sensors and the viewport · vuejs.school"
description: "Measure elements, notice when they scroll into view, close menus on an outside click, and read media queries, all as refs."
canonical_url: "https://vuejs.school/learn/vueuse/sensors-and-the-viewport"
meta:
  "og:description": "Measure elements, notice when they scroll into view, close menus on an outside click, and read media queries, all as refs."
  "og:image": "https://vuejs.school/_og/d/a_~U2Vuc29ycyBhbmQgdGhlIHZpZXdwb3J0IMK3IHZ1ZWpzLnNjaG9vbA%2Cc_OgCard.takumi%2Ctitle_Sensors%2Band%2Bthe%2Bviewport%2Cdescription_~TWVhc3VyZSBlbGVtZW50cywgbm90aWNlIHdoZW4gdGhleSBzY3JvbGwgaW50byB2aWV3LCBjbG9zZSBtZW51cyBvbiBhbiBvdXRzaWRlIGNsaWNrLCBhbmQgcmVhZCBtZWRpYSBxdWVyaWVzLCBhbGwgYXMgcmVmcy4%2Ceyebrow_~VnVlVXNlIMK3IExlc3NvbiA0IG9mIDY%2Ctint_sand%2Cp_Ii9sZWFybi92dWV1c2Uvc2Vuc29ycy1hbmQtdGhlLXZpZXdwb3J0Ig%2Cs_dfWS11m3KaWJwoGv.png"
  "og:image:alt": "Sensors and the viewport · vuejs.school"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "Sensors and the viewport · vuejs.school"
  "twitter:image": "https://vuejs.school/_og/d/a_~U2Vuc29ycyBhbmQgdGhlIHZpZXdwb3J0IMK3IHZ1ZWpzLnNjaG9vbA%2Cc_OgCard.takumi%2Ctitle_Sensors%2Band%2Bthe%2Bviewport%2Cdescription_~TWVhc3VyZSBlbGVtZW50cywgbm90aWNlIHdoZW4gdGhleSBzY3JvbGwgaW50byB2aWV3LCBjbG9zZSBtZW51cyBvbiBhbiBvdXRzaWRlIGNsaWNrLCBhbmQgcmVhZCBtZWRpYSBxdWVyaWVzLCBhbGwgYXMgcmVmcy4%2Ceyebrow_~VnVlVXNlIMK3IExlc3NvbiA0IG9mIDY%2Ctint_sand%2Cp_Ii9sZWFybi92dWV1c2Uvc2Vuc29ycy1hbmQtdGhlLXZpZXdwb3J0Ig%2Cs_dfWS11m3KaWJwoGv.png"
  "twitter:image:alt": "Sensors and the viewport · vuejs.school"
---

> Index of every page on this site: [llms.txt](https://vuejs.school/llms.txt)

# **Sensors and the viewport**

Measure elements, notice when they scroll into view, close menus on an outside click, and read media queries, all as refs.

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://vuejs.school/#website","@type":"WebSite","description":"A free AI-instructed school for Vue.js. Short tutorials, runnable code and quizzes that adapt to you.","name":"vuejs.school","url":"https://vuejs.school/","publisher":{"@id":"https://vuejs.school/#identity"}},{"@id":"https://vuejs.school/learn/vueuse/sensors-and-the-viewport#webpage","@type":"WebPage","description":"Measure elements, notice when they scroll into view, close menus on an outside click, and read media queries, all as refs.","name":"Sensors and the viewport","url":"https://vuejs.school/learn/vueuse/sensors-and-the-viewport","breadcrumb":{"@id":"https://vuejs.school/learn/vueuse/sensors-and-the-viewport#breadcrumb"},"isPartOf":{"@id":"https://vuejs.school/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://vuejs.school/learn/vueuse/sensors-and-the-viewport"]}],"primaryImageOfPage":{"@id":"https://vuejs.school/#logo"}},{"@id":"https://vuejs.school/#identity","@type":"Organization","description":"A free AI-instructed school for Vue.js. Short tutorials, runnable code and quizzes that adapt to you.","name":"vuejs.school","url":"https://vuejs.school","logo":{"@id":"https://vuejs.school/#logo"}},{"@id":"https://vuejs.school/learn/vueuse/sensors-and-the-viewport#article","description":"Measure elements, notice when they scroll into view, close menus on an outside click, and read media queries, all as refs.","headline":"Sensors and the viewport","inLanguage":"en","isAccessibleForFree":true,"thumbnailUrl":"https://vuejs.school/_og/d/a_~U2Vuc29ycyBhbmQgdGhlIHZpZXdwb3J0IMK3IHZ1ZWpzLnNjaG9vbA%2Cc_OgCard.takumi%2Ctitle_Sensors%2Band%2Bthe%2Bviewport%2Cdescription_~TWVhc3VyZSBlbGVtZW50cywgbm90aWNlIHdoZW4gdGhleSBzY3JvbGwgaW50byB2aWV3LCBjbG9zZSBtZW51cyBvbiBhbiBvdXRzaWRlIGNsaWNrLCBhbmQgcmVhZCBtZWRpYSBxdWVyaWVzLCBhbGwgYXMgcmVmcy4%2Ceyebrow_~VnVlVXNlIMK3IExlc3NvbiA0IG9mIDY%2Ctint_sand%2Cp_Ii9sZWFybi92dWV1c2Uvc2Vuc29ycy1hbmQtdGhlLXZpZXdwb3J0Ig%2Cs_dfWS11m3KaWJwoGv.png","@type":["Article","TechArticle"],"articleSection":["Composables"],"author":{"@id":"https://vuejs.school/#identity"},"image":{"@id":"https://vuejs.school/#/schema/image/1"},"isPartOf":{"@id":"https://vuejs.school/learn/vueuse/sensors-and-the-viewport#webpage"},"keywords":["useElementSize()","useElementVisibility()","onClickOutside()","useBreakpoints()"],"mainEntityOfPage":{"@id":"https://vuejs.school/learn/vueuse/sensors-and-the-viewport#webpage"},"publisher":{"@id":"https://vuejs.school/#identity"}},{"@id":"https://vuejs.school/learn/vueuse/sensors-and-the-viewport#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Skill tree","item":"https://vuejs.school/track","position":1},{"@type":"ListItem","name":"VueUse","item":"https://vuejs.school/track/vueuse","position":2},{"@type":"ListItem","name":"Sensors and the viewport","position":3}]},{"@id":"https://vuejs.school/#logo","@type":"ImageObject","caption":"vuejs.school","contentUrl":"https://vuejs.school/apple-touch-icon.png","inLanguage":"en","url":"https://vuejs.school/apple-touch-icon.png"},{"@id":"https://vuejs.school/#/schema/image/1","@type":"ImageObject","contentUrl":"https://vuejs.school/_og/d/a_~U2Vuc29ycyBhbmQgdGhlIHZpZXdwb3J0IMK3IHZ1ZWpzLnNjaG9vbA%2Cc_OgCard.takumi%2Ctitle_Sensors%2Band%2Bthe%2Bviewport%2Cdescription_~TWVhc3VyZSBlbGVtZW50cywgbm90aWNlIHdoZW4gdGhleSBzY3JvbGwgaW50byB2aWV3LCBjbG9zZSBtZW51cyBvbiBhbiBvdXRzaWRlIGNsaWNrLCBhbmQgcmVhZCBtZWRpYSBxdWVyaWVzLCBhbGwgYXMgcmVmcy4%2Ceyebrow_~VnVlVXNlIMK3IExlc3NvbiA0IG9mIDY%2Ctint_sand%2Cp_Ii9sZWFybi92dWV1c2Uvc2Vuc29ycy1hbmQtdGhlLXZpZXdwb3J0Ig%2Cs_dfWS11m3KaWJwoGv.png","inLanguage":"en","url":"https://vuejs.school/_og/d/a_~U2Vuc29ycyBhbmQgdGhlIHZpZXdwb3J0IMK3IHZ1ZWpzLnNjaG9vbA%2Cc_OgCard.takumi%2Ctitle_Sensors%2Band%2Bthe%2Bviewport%2Cdescription_~TWVhc3VyZSBlbGVtZW50cywgbm90aWNlIHdoZW4gdGhleSBzY3JvbGwgaW50byB2aWV3LCBjbG9zZSBtZW51cyBvbiBhbiBvdXRzaWRlIGNsaWNrLCBhbmQgcmVhZCBtZWRpYSBxdWVyaWVzLCBhbGwgYXMgcmVmcy4%2Ceyebrow_~VnVlVXNlIMK3IExlc3NvbiA0IG9mIDY%2Ctint_sand%2Cp_Ii9sZWFybi92dWV1c2Uvc2Vuc29ycy1hbmQtdGhlLXZpZXdwb3J0Ig%2Cs_dfWS11m3KaWJwoGv.png"}]}
```