THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Style borderWidth Property

Style Object Reference 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 Reference Style Object