Skip to main content Accessibility Feedback

The Viewport

Element.getBoundingClientRect()

Get information about the size of an element and its position relative to the viewport.

let app = document.querySelector('#app');
let details = app.getBoundingClientRect();

// logs an object with top, let, bottom, right, height, and width properties
console.log(details);

Preorder my new course on Web Components! Want to learn how to build Web Components from scratch, master best practices, and more? Preorder today and get $100 off of the launch price.


Find this useful? You can support my work by purchasing an annual membership.