
- 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 Style Object borderWidth Property
HTML DOM Style Object borderWidth property sets or returns the border width of the element.
It can take from one to four values which can be implemented as follows:
- One Value: For one value, border width for all four borders will be same. For example: h1 {border-width: 4px}
- Two Value: For two value, border width for top and bottom border will be same , left and right border will be of same width. For example: h1 {border-width: 4px thin}
- Three Value: For three value, top and bottom border will be of different border width whereas left and right border will be of same width. For example: h1 {border-width: 4px thin medium}
- Four Value: For four value, all borders will have different width. For example: h1 {border-width: 4px thin medium thick}
Syntax
Given below are the syntax to get or set the borderWidth property.
Set the borderWidth property:object.style.borderWidth= "thin | medium | thick | length | initial | inherit";Get the borderWidth property:
object.style.borderWidth;
Property Values
Value | Description |
---|---|
thin | It specifies a thin border. |
medium | It is default value which specifies a medium border. |
thick | It specifies a thick border. |
length | It specifies border width in CSS measurement units like px. |
initial | It is used to set this property to it's default value. |
inherit | It is used to inherit the property of it's parent element. |
Return Value
It returns a string value which represents border width of an element.
Examples of HTML DOM Style Object 'borderWidth' Property
The following examples illustrates different border width values.
Change the Border width
In the following example we have changed the border width from 2px to thick.
<!DOCTYPE html> <html> <head> <title> HTML DOM Style Object borderWidth Property </title> <style> #border { border: 2px solid; } </style> </head> <body> <p> Click to change the border style. </p> <button onclick="fun()">Change Border</button> <section id="border"> Welcome to Tutorials Point... </section> <script> function fun() { document.getElementById("border") .style.borderWidth = "thick"; } </script> </body> </html>
Set Multiple Border width
In the following example we have used two-value, three-value, four-value to set different border width for different sides.
<!DOCTYPE html> <html lang="en"> <head> <Title> HTML DOM Style Object borderWidth Property </Title> <style> h1 { border : solid black; } </style> </head> <body> <p> Click to change the border style. </p> <button onclick="funtwo()">Two Border</button> <button onclick="funthree()">Three Border</button> <button onclick="funfour()">Four Border</button> <h1 id="border"> Welcome to Tutorials Point... </h1> <script> function funtwo() { document.getElementById("border") .style.borderWidth = "4px thin"; } function funthree() { document.getElementById("border") .style.borderWidth = "4px thin 8px"; } function funfour() { document.getElementById("border") .style.borderWidth = "4px thin 8px thick"; } </script> </body> </html>
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
borderWidth | Yes 1 | Yes 12 | Yes 1 | Yes 1 | Yes 3.5 |
html_dom.htm
Advertisements