JavaScript Tutorial

CSS Border

The CSS border is a shorthand property used to set the border on an element. This border property is used to specify the style, color and size of the border of an element.

Understanding different border styles

The border-style property sets the style of a box's border such as solid, dotted, etc. It is a shorthand property for setting the line style for all four sides of the element's border.

The border-style property can have the following values: none, hidden, solid, dashed, dotted, double, inset, outset, groove, and ridge.

Input:-

 

Output:-

Note: We must specify a border style in order to make the border appear around an element because the default border style is none. Whereas, the default border width or thickness is medium, and the default border color is the same as the text color.

Setting the Border Width

The border-width property specifies the width of the border area. It is a shorthand property for setting the thickness of all four sides of an element's border simultaneously.

The border width can be specified using length values such as px, em, rem, etc. Additionally, three keywords can be used: thin, medium, and thick. Percentage values are not allowed.

Input:-

 

Output:-

 

Specifying the Border Color

This property determines the color of the border area. It is also a shorthand property for setting the color of all four sides of an element's border.

The CSS border-width or border-color property does not function independently. The border-style property must be used to set the border style first.

Input:-

 

Output:-

 

The Border Shorthand Property

The border property is a shorthand property that combines one or more of the individual border properties: border-width, border-style, and border-color, into a single rule.

If an individual border property is not specified when using the border shorthand property, the default value for that property will be used, if any.

For example, if the border-color property is missing or not specified when setting the border, the element's color property will be used as the value for the border color.

Input:-

 

Output:-

 


Test your CSS skills.

EXERCISE - 1

Set rounded borders to the <p> by using border property.

<p>Learn, Build & Test Your Codes.</p>

<style>

      p{

        border: 3px solid blue;

        border-radius: 5px;

      }

    </style>

      

      <body>

        <p>Learn, Build & Test Your Codes.</p>

      </body>

<style>

      p{

        border: 3px solid blue;

        border-radius: 5px;

      }

    </style>

      

      <body>

        <p>Learn, Build & Test Your Codes.</p>

      </body>

CSS Quiz Test
Go back to Previous Course