Latest web development tutorials
 

Style borderWidth Property

< Style Object

Example

Change the width of the four borders of a <div> element:

document.getElementById("myDiv").style.borderWidth = "thick";
Try it Yourself »

Definition and Usage

The borderWidth property sets or returns the width of an element's border.

This property can take from one to four values:

  • One value, like: p {border-width: thick} - all four borders will be thick
  • Two values, like: p {border-width: thick thin} - the top and bottom border will be thick, left and right border will be thin
  • Three values, like: p {border-width: thick thin medium}- the top border will be thick, left and right border will be thin, bottom border will be medium
  • Four values, like: p {border-width: thick thin medium 10px} - the top border will be thick, right border will be thin, bottom border will be medium, left border will be 10px

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The borderWidth property is supported in all major browsers.


Syntax

Return the borderWidth property:

object.style.borderWidth

Set the borderWidth property:

object.style.borderWidth="thin|medium|thick|length|initial|inherit"

Property Values

Value Description
thin Defines a thin border
medium Defines a medium border. This is default
thick Defines a thick border
length The width of the border in length units
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit

Technical Details

Default Value: medium 
Return Value: A String, representing the width of an element's border
CSS Version CSS1

More Examples

Example

Change the width of the top and bottom border to thick, and the left and right border to thin of a <div> element:

document.getElementById("myDiv").style.borderWidth = "thick thin";
Try it Yourself »

Example

Change the width of the four borders of a <div> element, using the length value:

document.getElementById("myDiv").style.borderWidth = "1px 5px 10px 20px";
Try it Yourself »

Example

Return the width of the border of a <div> element:

alert(document.getElementById("myDiv").style.borderWidth);
Try it Yourself »

Related Pages

CSS tutorial: CSS Border

CSS reference: border-width property

HTML DOM reference: border property


< Style Object