CSS

Last Updated: 10/18/2022

Borders

Shorthand

  • You specify width, style (required) and color
  • Width specifies the width/thickness of the borders

Syntax

border: border-width border-style border-color

Example

div {
	border: 10px solid blue;
}
div {
	border-width: 10px;
	border-style: solid;
	border-color: blue;
}

Individual Values

border-top: 10px solid blue;
border-right: 10px solid blue;
border-bottom: 10px solid blue;
border-left: 10px solid blue;

or

Border Width

  • Can be set as a specific size (px, pt, cm, em, etc)
  • You can also use one of the three pre-defined values: thin, medium, or thick
border-width: 10px; 

Individual Values

/* top 10px, right 15px, bootom 20px, left 25px */
border-width: 10px 15px 20px 25px; 

/* top 10px, right 15px, bottom 20px, left 15px */
border-width: 10px 15px 20px; 

/* top 10px, right 15px, bottom 10px, left 15px */
border-width: 10px 15px; 

/* top 10px, right 10px, bootom 10px, left 10px */
border-width: 10px; 

/* Individual borders */
border-top-width: 10px;
border-right-width: 15px;
border-bottom-width: 20px;
border-left-width: 25px;

Border Style

  • Specifies what kind of border to display.
  • Possible values are
    • solid
    • dashed
    • dotted
    • double
    • groove
    • ridge
    • outset
    • inset
    • none
border-style: solid;
border-style: solid dotted;
border-style: solid dotted dashed;
border-style: solid dotted dashed double;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;

Border Color

  • Used to set the color of the four borders.
  • Color can specified in rgb, rgba, hex, hsl, hsla
  • You can use transparent keyword
border-color: red;
border-color: red green;
border-color: red green blue;
border-color: red green blue yellow;
border-top-color: red;
border-right-color: red;
border-bottom-color: red;
border-left-color: red;

Border Radius

  • Used to add rounded borders to an element
div {
	width: 200px;
	height: 200px;
	border: 5px solid blue;
	border-radius: 10px;
}
/* Circle Shape*/
div {
	width: 200px;
	height: 200px;
	border: 5px solid blue;
	border-radius: 50%;
}