Overview
The CSS border property allow you to specify the style, width, color, radius, etc. of an element’s border. The element’s border is the line that can appear on any of an element’s sides or all of the sides. It can have varying thicknesses, colors, styles, etc.
Each side of the element can be styled separately from the others, or all can be styled as one.
For instance, the note below has a solid, green, 4px border applied to just the left side of the element.
Note
The following are basic examples. Towards the bottom of this page you’ll find a complete list of all applicable properties, where you can find more information on the properties discussed, and sometimes find more involved properties not discussed on this page.
To have a border, the width and style must be set. If the color is not specified, the color of the text will be used.
div {
border-width: 1px;
border-style: solid;
}
Border Color
The border-color property sets the color of all four borders of an element, and can have from one to four values.
/* set all 4 borders to red */
div {
border-color: red;
}
Border Style
The border-style property sets the style of all four borders of an element, and can have from one to four values.
/* sets all 4 borders */
div {
border-style: dashed;
}
Border Width
The border-width property sets the width of an element’s borders. An element must have a border before you can change the width.
/* sets all 4 borders */
div {
border-width: thick;
}
Border Image
The border-image property allows for the use of an image as the border of an element.
/* file location, border width, image repeats */
div {
border-image: url(border_image.jpg) 15 repeat;
}
Border Radius
The border-radius property defines the radius of an element’s corners to give the element rounded corners. This property can have from one to four values.
/* all borders have an equal radius */
div {
border-radius: 20px;
}
Note
An element does not need to have a border applied for the border-radius property to be used. The name is a little misleading in that the border-radius will create a corner radius on an element with or without a border.
Border Properties
- CSS – border PropertyThe border property is a shorthand property for all the other properties a CSS border can be given.
- CSS – border-image-source PropertyThe border-image-source property specifies the path to the image that is to be used as the border.
- CSS – border-image-width PropertyThe border-image-width property specifies the width of the border image.
- CSS – border-bottom PropertyThe border-bottom property is a shorthand property for all the other properties a CSS bottom border can be given.
- CSS – border-bottom-color PropertyThe border-bottom-color property sets the color of an element’s bottom border. An element must have a border before a color can be applied.
- CSS – border-bottom-left-radius PropertyThe border-bottom-left-radius property defines the radius of the bottom-left corner, giving it a rounded look.
- CSS – border-bottom-right-radius PropertyThe border-bottom-right-radius property defines the radius of the bottom-right corner, giving it a rounded look.
- CSS – border-bottom-style PropertyThe border-bottom-style property sets the style of an element’s bottom border to dotted, dashed, solid, double, etc.
- CSS – border-bottom-width PropertyThe border-bottom-width property sets the width of an element’s bottom border. An element must have a border before you can change the width.
- CSS – border-collapse PropertyThe border-collapse property sets whether table borders should collapse into a single border or remain separated as is the default.
- CSS – border-color PropertyThe border-color property sets the color of all four borders of an element, and can have from one to four values.
- CSS – border-image PropertyThe border-image property is a shorthand property for all the other properties a CSS border image can be given.
- CSS – border-image-outset PropertyThe border-image-outset property specifies the amount that the border image area should extend beyond the border box.
- CSS – border-image-repeat PropertyThe border-image-repeat property specifies whether the border image should be repeated, rounded, spaced or stretched.
- CSS – border-image-slice PropertyThe border-image-slice property specifies how to slice the border image. The image is always sliced into nine sections: four corners, four edges and the middle.
- CSS – border-left-color PropertyThe border-left-color property sets the color of an element’s left border. An element must have a border before a color can be applied.
- CSS – border-left PropertyThe border-left property is a shorthand property for all the other properties a CSS left border can be given.
- CSS – border-left-style PropertyThe border-left-style property sets the style of an element’s left border to dotted, dashed, solid, double, etc.
- CSS – border-left-width PropertyThe border-left-width property sets the width of an element’s left border. An element must have a border before you can change the width.
- CSS – border-radius PropertyThe border-radius property defines the radius of an element’s corners to give the element rounded corners. This property can have from one to four values.
- CSS – border-right PropertyThe border-right property is a shorthand property for all the other properties a CSS right border can be given.
- CSS – border-right-color PropertyThe border-right-color property sets the color of an element’s right border. An element must have a border before a color can be applied.
- CSS – border-right-style PropertyThe border-right-style property sets the style of an element’s right border to dotted, dashed, solid, double, etc.
- CSS – border-right-width PropertyThe border-right-width property sets the width of an element’s right border. An element must have a border before you can change the width.
- CSS – border-style PropertyThe border-style property sets the style of all four borders of an element, and can have from one to four values.
- CSS – border-top PropertyThe border-top property is a shorthand property for all the other properties a CSS top border can be given.
- CSS – border-top-color PropertyThe border-top-color property sets the color of an element’s top border. An element must have a border before a color can be applied.
- CSS – border-top-left-radius PropertyThe border-top-left-radius property defines the radius of the top-left corner, giving it a rounded look.
- CSS – border-top-right-radius PropertyThe border-top-right-radius property defines the radius of the top-right corner, giving it a rounded look.
- CSS – border-top-style PropertyThe border-top-style property sets the style of an element’s top border to dotted, dashed, solid, double, etc.
- CSS – border-top-width PropertyThe border-top-width property sets the width of an element’s top border. An element must have a border before you can change the width.
- CSS – border-width PropertyThe border-width property sets the width of an element’s borders. An element must have a border before you can change the width.
CSS Notes:
- The “inherit”, “initial” and “unset” keywords can be used with any CSS property to set its value
- In CSS there are many ways to express a color value in a property
We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.