
- HTML Home
- HTML Roadmap
- HTML Introduction
- HTML History & Evolution
- HTML Editors
- HTML Basic Tags
- HTML Elements
- HTML Attributes
- HTML Headings
- HTML Paragraphs
- HTML Fonts
- HTML Blocks
- HTML Style Sheet
- HTML Formatting
- HTML Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - Document Object Model (DOM)
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - DOM Element offsetHeight Property
The HTML DOM ElementoffsetHeightproperty is used to retrieve the complete viewable height of that element on the webpage.
The returned height includes both its vertical padding and borders, calculated in pixels. If an element has no styling (like no height or padding defined) and no content, its offset height will indeed be 0px.
Following is the list of similar offset properties:
Syntax
Following is the syntax of the HTML DOM Element offsetHeight property −
element.offsetHeight
Parameters
Since this is a property, it will not accept any parameter.
Return Value
This property returns the height of an element in pixels, including its padding and border.
Example 1: Retrieving the offsetHeight Property Value
The following is the basic example of the HTML DOM Element offsetHeight property. It displays the height of a div element −
<!DOCTYPE html> <html> <head> <title>HTML DOM Element offsetHeight</title> <style> .box { width: 200px; padding: 20px; border: 1px solid black; } </style> </head> <body> <h3>HTML DOM Element offsetHeight Property</h3> <p>Displays the offset height of the box.</p> <div class="box" id="myBox">Welcome to Tutorialspoint</div> <p id="res"></p> <script> var element = document.getElementById("myBox"); var height = element.offsetHeight; document.getElementById("res").innerHTML = "Offset height: " + height; </script> </body> </html>
The above program displays the offset height of the "div" element.
Example 2: offsetHeight of ScrollBar
Following is another example of the HTML DOM Element offsetHeight property. We use this property to retrieve the offset height of the scroll bar −
<!DOCTYPE html> <html> <head> <title>HTML DOM Element offsetHeight</title> <style> .scroll-box { width: 200px; height: 100px; border: 1px solid black; overflow-y: scroll; } </style> </head> <body> <h3>HTML DOM Element offsetHeight Property</h3> <div class="scroll-box" id="myScrollBox"> <p>Scroll down to see more content.</p> <p>Content 1</p> <p>Content 2</p> <p>Content 3</p> <p>Content 4</p> </div> <p id="heightDisplay"></p> <script> var element = document.getElementById("myScrollBox"); var height = element.offsetHeight; document.getElementById("heightDisplay").textContent = "Offset height of the scroll box: " + height + "px"; </script> </body> </html>
After executing the above program, it displays the offset height of the scrollbar.
Example 3
If an element has no styling (like no height or padding defined) and no content, its offset height will indeed be 0px −
<!DOCTYPE html> <html> <head> <title>HTML DOM Element offsetHeight</title> </head> <body> <h3>HTML DOM Element offsetHeight Property</h3> <div id="myScrollBox"></div> <p id="heightDisplay"></p> <script> var element = document.getElementById("myScrollBox"); var height = element.offsetHeight; document.getElementById("heightDisplay").textContent = "Offset height: " + height + " px"; </script> </body> </html>
The above program returns the offset height as zero.
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
offseHeight | Yes | Yes | Yes | Yes | Yes |