English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules (RULES)

Comprehensive List of CSS Properties

CSS border property usage and examples

The CSS border property sets the width, style, and color of all four sides of the element's border. It is used to set border properties individually, that is, a shorthand property, andborder-width,border-styleandborder-coloris a single declaration.

The following table summarizes the usage context and version history of this attribute.

Default Value:View individual properties
Applicable To:All Elements
Inheritance:No
Animatable:Yes,See individual properties.See Animation Properties.
Version:CSS 1,2,3
JavaScript Syntax:    
object    object.style.border="1px solid red"

border Usage Syntax

The syntax of this attribute is as follows:

border: [ border-width border-style border-color ] | initial | inherit

Note:If any of the listed properties are missing or omitted, the default value of the property (if any) will be inserted. For more details, see each property.

The following examples demonstrate how to use the border property.

h1 { border: 5px solid #ff0000;}
p { color: #00ff00; border: 5px solid;}
Test and see‹/›

Note:Ifborder-colormissing or not specified (for example, border: 5px solid;),colorthen the value of the element attribute will be used. However, in the presence ofborder-styleIn this case, skipping or ignoring this value will not display any border because the border-The default value of the style attribute is none.

Attribute Values

The following table describes the values of this property.

ValueDescription
border-widthSet the width of the element border.
border-styleSet the line style of the element border.
border-colorSet the color of the element border.
initialSet this property to its default value.
inheritIf specified, the associated elements use the calculated value of the parent element's border property.

Browser Compatibility

Browser Compatibility of border Property, all mainstream browsers support this property.

  • Firefox 1+

  • Google Chrome1+

  • Internet Explorer 4+

  • Apple Safari 1+

  • Opera 4+

Further Reading

See Tutorial:CSS Border,CSS3 Border.

Related Properties:border-width,border-style,border-color,border-collapse,border-image,border-radius,border-spacing.