
- 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 clientLeft Property
The HTML DOM Element clientLeft property is used to retrieve the width of an element's left border, excluding left padding or margin. The returned width will be measured in pixels (px).
It is useful for accessing and determining the accurate size of the element's border, and it is a read-only property, which means it cannot be set or updated.
Syntax
Following is the syntax of the HTML DOM Element clientLeft property −
element.clientLeft;
Parameters
Since this is a property, it will not accept any parameter.
Return Value
This property returns the left border width of the element in pixels.
Example 1: Retrieving the Left Border Width of an Element
The following is the basic example of the HTML DOM Element clientLeft property. It retrieves the width of an element's left border −
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM Element clientLeft</title> <style> #myElement { width: 200px; height: 100px; border: 10px solid black; border-left: 30px solid red; } #result { color: blue; } </style> </head> <body> <h3>HTML DOM Element clientLeft property</h3> <div id="myElement">Example Element</div> <p id="result"></p> <script> document.addEventListener("DOMContentLoaded", function() { var element = document.getElementById("myElement"); var leftBorderWidth = element.clientLeft; var resultElement = document.getElementById("result"); resultElement.textContent = "Left border width of #myElement: " + leftBorderWidth + " pixels"; }); </script> </body> </html>
The above program displays the width of the left border of a "div" element as "29px".
Example 2: Left Border Width of Last div Element
Following is another example of the HTML DOM Element clientLeft property. We use this property to retrieve the width of the left border of the last <div> element −
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM Element clientLeft</title> <style> .example-div { width: 200px; height: 100px; border: 10px solid black; margin-bottom: 10px; } .border-width { color: green; font-weight: bold; } </style> </head> <body> <h3>HTML DOM Element clientLeft property</h3> <div class="example-div">First div element</div> <div class="example-div">Second div element</div> <div class="example-div" id="lastDiv">Third div element (last)</div> <div id="result">Left border width of the last will be displayed here: <span id="spn"></span> </div> <script> document.addEventListener("DOMContentLoaded", ()=> { var lastDiv = document.getElementById("lastDiv"); var leftBorderWidth = lastDiv.clientLeft; var spnEle = document.getElementById("spn"); spnEle.innerHTML = leftBorderWidth + "px" }); </script> </body> </html>
Once the above program is executed, it displays the width of the left border of the last "div" as 10px.
Example 3: Width of a Sidebar Element
In the example below, we use clientLeft property to retrieve the width of the left border of a sidebar element in the document −
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM Element clientLeft</title> <style> .sidebar { width: 250px; height: 100vh; position: fixed; top: 0; background-color: #333; color: white; padding: 20px; box-sizing: border-box; border-right: 10px solid #666; overflow-x: hidden; resize: horizontal; z-index: 1; } .content { margin-left: 260px; } </style> </head> <body> <h3>HTML DOM Element clientLeft property</h3> <div class="sidebar" id="sidebar"> <h2>Sidebar</h2> <p>This is a resizable sidebar element.</p> </div> <div class="content"> <h1>Main Content</h1> <p>Content goes here...</p> <div id="result">Width of the sidebar will be displayed here: <span id="spn"></span> </div> </div> <script> document.addEventListener("DOMContentLoaded", function() { var sidebar = document.getElementById("sidebar"); var resultElement = document.getElementById("result"); // Define a function to update sidebar width function updateSidebarWidth() { var sidebarWidth = sidebar.offsetWidth; var spnEle = document.getElementById("spn"); spnEle.innerHTML = sidebarWidth + "px" } // Call the function when page loaded updateSidebarWidth(); // Call the function when resize happen window.addEventListener("resize",updateSidebarWidth); sidebar.addEventListener("mousemove", function() { updateSidebarWidth(); }); }); </script> </body> </html>
The above program displays the width of the left border of a sidebar element as "250px".
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
clientLeft | Yes 1 | Yes 12 | Yes 1 | Yes 3 | Yes 9 |