Border in CSS

The border feature in CSS allows to define the style, width and color for the border of an element.

Style of border in CSS

The border-style specifies the border type to display. Usable values ​​include:

  1. dotter - dotted line
  2. dashed - dashed line
  3. solid - straight lines
  4. double - double line
  5. groove
  6. ridge
  7. inset
  8. outset
  9. none - no borders
  10. hidden - hidden border

The border-property can have from 1 to 4 values ​​(top, bottom, left, right)

Border in CSS Picture 1
The image shows the above contour types

Note: None of the following CSS border properties will work if you haven't selected the border-style for it.

Width of the border

border-width properties define the width of 4 contours, which can be equal to units such as print, px, pt, cm, em . or by using 1 of 3 predefined values ​​of thin (thin), medium ( medium) and thick (thick).

The border-width can have from 1 to 4 values ​​above, below, left, and right.

Border in CSS Picture 2
The border-width feature defines the width of the border

Contour colors in CSS

The border-color is used to select colors for 4 borders. Colors in CSS can be selected by:

  1. name: Specific name like 'red' .
  2. Hex: HEX value like # ff0000 .
  3. RGB: RGB values ​​like rgb (255, 0, 0) .
  4. transparent: Transparent

The border-color has from 1 to 4 values ​​(top, bottom, left, right) if not set, it takes the element's color.

Border in CSS Picture 3
Select the color for the border of the element

Border for each edge in CSS

In the examples above you can see that you can select multiple border styles for each edge, in CSS, there are also properties defined for each edge of the border (top, bottom, left, right).

 p { 
border-top-style: dotted;
border-right-style: solid;
border-bottom-style: dotted;
border-left-style: solid;
}

The above code will produce the same result like this.

 p { 
border-style: dotted solid;
}

The reason is because of how the values ​​work in border-style. properties border-style.

If the border-style has 4 values:

  1. border-style: dotted solid double dashed;
    1. upper border - dotted line
    2. right border - straight line
    3. lower border - double line
    4. left border - broken line

If the border-style has 3 values:

  1. border-style: dotted solid double;
    1. upper border - dotted line
    2. left and right borders - straight lines
    3. lower border - double line

If the border-style has two values:

  1. border-style: dotted solid;
    1. upper and lower border - dotted line
    2. left and right borders - straight lines

If the border-style has a value:

  1. border-style: dotted;
    1. All edges are dotted lines

Selecting different border styles for the border-style property as shown in the above example can be applied to border-width and border-color.

Border - shortened feature

As you can see in the examples above, there are many features for contour. To simplify the code, all can be included in a single property. The border feature is a shortened feature for the following properties:

  1. border-width
  2. border-style (required)
  3. border-color
 p { 
border: 5px solid red;
}

It is also possible to define contour properties only for a single border edge as in the examples of the left border, the following lower border.

 p { 
border-left: 6px solid red;
background-color: lightgrey;
}

p {
border-bottom: 6px solid red;
background-color: lightgrey;
}

Rounded edge

The border-radius used to add a rounded border to an element.








Border-radius feature



Normal border


Round border


More round edges


The most rounded edges




Border in CSS Picture 4
The image shows the circular levels of the border edge

Note: border-radius not supported in IE8 and earlier versions.

Last lesson: Background in CSS

The following article: Margins in CSS

4.5 ★ | 2 Vote

May be interested

  • How to create a border for photos in PhotoshopHow to create a border for photos in Photoshop
    how to create a border for photos in photoshop. to make photos become more sparkling and beautiful, especially for portraits or artwork. today's article thuthuatphanmem.vn will guide you how to create borders for photos in photoshop in a simple way.
  • How to get a curved border display on Android phones like Samsung Galaxy S8How to get a curved border display on Android phones like Samsung Galaxy S8
    one way to help android users experience curved screen borders on mobile phones is by changing the display border from square to curved. the following article will show you how to get a curved border display on your android phone, using the cornerfly app.
  • How to Add a Border to WordHow to Add a Border to Word
    this wikihow teaches you how to create a border around text, images, or pages in a microsoft word document. open your word document. double-click the word document to which you want to add borders. this will open the document in microsoft...
  • Add a text box or border around text on a Google Docs documentAdd a text box or border around text on a Google Docs document
    have you ever opened google docs to write a textbook or homework, and then realized you don't know how to create a text box? although google docs doesn't have a dedicated button to create text boxes, there are some creative solutions to this problem. today's tipsmake will show you how to add a frame (or border) around text in a google docs document.
  • Create a border around Word documentsCreate a border around Word documents
    create a border around word documents. you can create a border for a paragraph or for the whole page.
  • Create beautiful border borders in WordCreate beautiful border borders in Word
    when you compose documents in word, you will usually have a cover for that text. to create eye-catching covers you need to create beautiful borders for that cover. with most of the beautiful borders that microsoft has provided, you will get the border
  • How to create a white border for photos in PhotoshopHow to create a white border for photos in Photoshop
    in photoshop also there are tools to help you create white borders for images quickly. in this article, i will guide you how to create a white border for photos in photoshop.
  • Hacker successfully stole 100,000 photos from border control databaseHacker successfully stole 100,000 photos from border control database
    the us customs and border protection department officially released a statement on monday that the database of one of their subcontractors was 'visited' by hackers in a malicious cyberattack.
  • Table in HTMLTable in HTML
    what does it take to create a table in html? is it complicated? want to add color to the table border, how to add the background color to the text in the table? in this article tipsmake.com will answer those questions and guide you to basic operations with tables on html, in addition to adding alternate color schemes for rows in the html table. invite you to follow along.
  • How to create spaces between letters and cell borders in ExcelHow to create spaces between letters and cell borders in Excel
    adding spaces between text and cell borders in excel makes it easier to read the document.