
- 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 clientTop Property
The HTML DOM Element clientTop property is used to retrieve the width of an element's top border, and the width value will be in pixels (px). This property excludes padding and margin spacing.
It is useful for obtaining accurate element positioning and size calculations in webpage layouts.
Syntax
Following is the syntax of the HTML DOM Element clientTop property −
element.clientTop;
Parameters
Since this is a property, it will not accept any parameter.
Return Value
This property returns a number (in pixels) that holds the viewable width of the element.
Example 1: Retrieving the Top Border Width
The following is the basic example of the HTML DOM Element clientTop property −
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM Element clientTop</title> <style> #myElement { width: 190px; height: 90px; padding: 25px; border-top: 9px solid black; border-left: 9px solid red; background-color: lightblue; } </style> </head> <body> <h3>HTML DOM Element clientTop Property</h3> <p>Retrieving Top Border Width of an Element</p> <div id="myElement">Example Element</div> <p>Click the button to retrieve the top border width of the element:</p> <button onclick="getTopBorderWidth()">Get Top Border Width</button> <p id="result"></p> <script> function getTopBorderWidth() { var element = document.getElementById("myElement"); var topBorderWidth = element.clientTop; var resultElement = document.getElementById("result"); resultElement.innerHTML = "Top border width of #myElement: " + topBorderWidth + " pixels"; } </script> </body> </html>
The above program displays the top border width of the "div" element.
Example 2: Top Border Width of a Sidebar Element
Here is another example of the HTML DOM Element clientTop property. We use this property to retrieve the top border of the sidebar element −
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM Element clientTop</title> <style> .sidebar { width: 250px; position: fixed; background-color: #333; color: white; border-top: 10px solid black; resize: horizontal; overflow-x: hidden; z-index: 1; } .content { margin-left: 260px; } </style> </head> <body> <h3>HTML DOM Element clientTop Property</h3> <p>Retrieving Top Border Width of a Sidebar Element</p> <div class="sidebar" id="sidebar"> <h2>Sidebar</h2> <p>This is a resizable sidebar element.</p> </div> <div class="content"> <h2>Main Content</h2> <p>Content goes here...</p> <button onclick="getTopBorderWidth()">Get Top Border Width</button> <div id="result">Top border width of the sidebar will be displayed here: <span id = "spn"></span> </div> </div> <script> function getTopBorderWidth() { var sidebar = document.getElementById("sidebar"); var topBorderWidth = sidebar.clientTop; var spnEle = document.getElementById("spn"); spnEle.innerHTML =+ topBorderWidth + " px"; } </script> </body> </html>
When the button is clicked, it displays the top border width of the sidebar element.
Example 3: Top Border Width of the First Header
In the example below, we use this property to retrieve the border width of the first header element −
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM Element clientTop</title> <style> h3{ border-top: 10px solid black; padding: 10px; } </style> </head> <body> <h3>HTML DOM Element clientTop Property</h3> <p>Finding Top Border Width of the First Header Element</p> <p>Click button to find the top border width of the first header</p> <button onclick="getTopBorderWidth()">Find Top Border Width</button> <p id="result">Top border width of the first header :</p> <script> function getTopBorderWidth() { var firstHeader = document.querySelector("h3"); var topBorderWidth = firstHeader.clientTop; var resultElement = document.getElementById("result"); resultElement.textContent = "Top border width of the first header: "+ topBorderWidth+ " pixels"; } </script> </body> </html>
When the button clicks, the top border width of the first header element will be displayed on the web page.
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
clientTop | Yes | Yes | Yes | Yes | Yes |