Loading
Border Overview
The CSS border property is used to define a border around HTML elements. It includes settings for:

  • Width (thickness)
  • Style (appearance)
  • Color (visual tone)
Borders are essential for improving layout clarity, visual grouping, and overall design aesthetics.



Border Components


1. border-width

Defines the thickness of the border.

/* Apply same width to all sides */
border-width: 2px;

/* Different width for each side */
border-top-width: 5px;
border-right-width: 1px;



2. border-style

Specifies the type of line used in the border.

border-style: solid; /* Applies to all sides */
border-top-style: dashed;
border-right-style: dotted;
border-bottom-style: double;
border-left-style: groove;



3. border-color

Sets the color of the border. You can use named colors, HEX, RGB or RGBA formats.

border-color: red;
border-top-color: #00FF00;
border-right-color: rgb(255, 0, 0);
border-left-color: rgba(0, 0, 255, 0.5);



Border Style Values

ValueDescription
noneNo border
hiddenSame as none (used for table elements)
dottedA series of dots
dashedShort dashes
solidA solid line
doubleTwo solid lines with a gap
grooveCarved look
ridgeRaised border
insetAppears embedded
outsetAppears raised outward



Example: All Border Styles

<!DOCTYPE html>
<html>
  <body>
    <p style="border-style: none;">No border.</p>
    <p style="border-style: hidden;">Hidden border.</p>
    <p style="border-style: dotted;">Dotted border.</p>
    <p style="border-style: dashed;">Dashed border.</p>
    <p style="border-style: solid;">Solid border.</p>
    <p style="border-style: double;">Double border.</p>
    <p style="border-style: groove;">Groove border.</p>
    <p style="border-style: ridge;">Ridge border.</p>
    <p style="border-style: inset;">Inset border.</p>
    <p style="border-style: outset;">Outset border.</p>
    <p style="border-style: none dashed solid dotted;">Mixed border.</p>
  </body>
</html>

Output:

Uploaded Image




Comparison Between Border and Outline

FeatureBorderOutline
DefinitionAffects the elements box itselfDraws a line outside the element
Affects LayoutYesNo
PositionInside the box modelOutside the box model
Control SidesYes (top, right, bottom, left)No (applies to all sides only)
OffsetNoYes (outline-offset)
Shorthandborderoutline