Skip to main content
Vuetify0 v1.0 is here
Vuetify0 Logo
Theme
Mode
Palettes
Accessibility
Vuetify One
Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

useResizeObserver

A composable for detecting element size changes using the Resize Observer API with automatic cleanup.

Edit this page
Report a Bug
Open issues
View on GitHub
Copy Markdown

StableAdvancedJun 29, 2026

Usage

The useResizeObserver composable wraps the Resize Observer API to detect when an element’s dimensions change. It’s useful for responsive components, charts, virtualized lists, and aspect ratio maintenance.

Tip

Why wrap ResizeObserver? The native ResizeObserver has no awareness of Vue’s effectScope lifecycle. If you create one inside a composable, it won’t automatically disconnect when the scope is disposed. useResizeObserver integrates onScopeDispose for automatic cleanup, defers creation until after hydration for SSR safety, and adds reactive target tracking — things the native API can’t do on its own.

vue
<script setup lang="ts">
  import { useResizeObserver } from '@vuetify/v0'
  import { ref, useTemplateRef } from 'vue'

  const container = useTemplateRef('container')
  const width = ref(0)
  const height = ref(0)

  useResizeObserver(container, (entries) => {
    const entry = entries[0]
    width.value = entry.contentRect.width
    height.value = entry.contentRect.height
  })
</script>

<template>
  <div ref="container" class="resizable">
    <p>Width: {{ width }}px</p>
    <p>Height: {{ height }}px</p>
  </div>
</template>

Architecture

useResizeObserver wraps the native ResizeObserver API with Vue reactivity:

Resize Observer Hierarchy

Use controls to zoom and pan. Click outside or press Escape to close.

Resize Observer Hierarchy

Options

OptionTypeDefaultNotes
immediatebooleanfalseFire the callback immediately on mount before any resize
oncebooleanfalseStop observing after the first callback fires
box'content-box' | 'border-box''content-box'Which box model to observe

Reactivity

Property/MethodReactiveNotes
isActiveComputed from observer ref
isPausedShallowRef, readonly
targetAccepts MaybeRef, watched for changes
pause()Temporarily stop observing without disconnecting
resume()Resume after pause()
stop()Disconnect the observer permanently

useElementSize

Property/MethodReactiveNotes
widthShallowRef
heightShallowRef

Examples

Responsive Grid

A drag-resizable container with a card grid that recalculates its column count based on the container’s own width, not the viewport. The useResizeObserver callback writes the contentRect.width into a shallowRef; a computed maps width ranges to column counts (1 below 400 px, 2 from 400–600 px, 3 above 600 px). The dimension badge in the top-right corner shows the live pixel values so you can see the breakpoints as you drag the right edge.

This component-query pattern is the key use case for useResizeObserver over CSS media queries: the container can be placed at any width in the page and still respond correctly to its own available space, independent of the viewport. It is also the recommended approach for charts, virtual lists, and any element whose internal layout depends on its measured size rather than a global breakpoint. For tracking element visibility rather than size, see useIntersectionObserver.

0 x 0
Analytics
Users
Revenue
Orders
Messages
Settings

Drag the right edge to resize. Columns: 1

FAQ

Discord
Need help? Join our community for support and discussions ↗

API Reference

The following API details are for the useResizeObserver composable.
Was this page helpful?

© 2016-1970 Vuetify, LLC
Services
Ctrl+/