DEV Community

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

Posted on

6 4

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)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay