DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for DOM layout: How to get the width and height of DOM elements.
Shruti Kapoor
Shruti Kapoor

Posted on

DOM layout: How to get the width and height of DOM elements.

I will be sharing bite sized learnings about JavaScript regularly in this series. Follow along with me as I re-learn JavaScript. This series will cover JS fundamentals, browsers, DOM, system design, domain architecture and frameworks.

clientWidth: The width of the element inside the element.

clientHeight: The height of the element inside the element.

offsetWidth: The width of the element including the border.

offsetHeight: The height of the element including the border.

pageXOffset: horizontal scroll position

pageYOffset: vertical scroll position

getBoundingClientRect: A function to get the most precise position of an element on the screen. It returns an object with properties indicating the pixel positions of the sides of the element relative to the top left of the screen. Word of caution - calling getBoundingClientRect causes reflow. More details here

Top comments (0)

Need a better mental model for async/await?

Check out this classic DEV post on the subject.

β­οΈπŸŽ€ JavaScript Visualized: Promises & Async/Await

async await