HTML CSS examples for CSS Property:border
The border property sets the width, style, and color for all four sides of an element's border.
It is a shorthand property for setting the individual border properties:
The following table summarizes the border property.
Item | Value |
---|---|
Default value: | See individual properties |
Applies to: | All elements |
Inherited: | No |
Animatable: | Yes, See individual properties. |
The syntax of the property is as follows:
border: [ border-width border-style border-color ] | initial | inherit
If any property listed above is omitted, the default value will be inserted.
If border-color is not specified, for example, border:5px solid; the value of the element's color property will be used instead.
Omitting border-style will hide the border, since the default value for border-style property is none.
The following table describes the values of border property.
Value | Description |
---|---|
border-width | Sets the width of the element border. |
border-style | Sets the line style of the element border. |
border-color | Sets the color of the element border. |
initial | Sets this property to its default value. |
inherit | takes the value of its parent element border property. |
The example below shows the border property.
<!DOCTYPE html> <html lang="en"> <head> <title>Example of CSS border property</title> <style type="text/css"> h1 {<!-- ww w . j av a 2s . com--> border: 5px solid #ff0000; } p { color: #00ff00; border: 5px solid; } </style> </head> <body> <h1>This is a heading.</h1> <p>This is a paragraph.</p> </body> </html>