Get element width and height and subscribe to changes


Resize textarea by dragging its right bottom corner
Width: 0px, height: 0px
import { useElementSize } from '@mantine/hooks';
function Demo() {
const theme = useMantineTheme();
const { ref, width, height } = useElementSize();
return (
<textarea ref={ref} style={{ width: 400, height: 120 }} />
<div>Width: {width}px, height: {height}px</div>


use-element-size is a simpler version of use-resize-observer hook. Hook returns ref object that should be passed to the observed element, and the element's height and width. On the first render (as well as during SSR), or when no element is being observed, width and height properties are equal to 0.

const { ref, width, height } = useElementSize();


function useElementSize<T extends HTMLElement = any>(): {
width: number,
height: number
Build fully functional accessible web applications faster than ever
Your feedback is most valuable contribution to the project, please share how you use Mantine, what features are missing and what is done good
Leave feedback