
- CSS - Home
- CSS - Roadmap
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Types
- CSS - Measurement Units
- CSS - Selectors
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Border Block
- CSS - Border Inline
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursor
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS - Inline Block
- CSS - Dropdowns
- CSS - Visibility
- CSS - Overflow
- CSS - Clearfix
- CSS - Float
- CSS - Arrows
- CSS - Resize
- CSS - Quotes
- CSS - Order
- CSS - Position
- CSS - Hyphens
- CSS - Hover
- CSS - Display
- CSS - Focus
- CSS - Zoom
- CSS - Translate
- CSS - Height
- CSS - Hyphenate Character
- CSS - Width
- CSS - Opacity
- CSS - Z-Index
- CSS - Bottom
- CSS - Navbar
- CSS - Overlay
- CSS - Forms
- CSS - Align
- CSS - Icons
- CSS - Image Gallery
- CSS - Comments
- CSS - Loaders
- CSS - Attr Selectors
- CSS - Combinators
- CSS - Root
- CSS - Box Model
- CSS - Counters
- CSS - Clip
- CSS - Writing Mode
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - Pointer Events
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS - Cascading
- CSS - Universal Selectors
- CSS - ID Selectors
- CSS - Group Selectors
- CSS - Class Selectors
- CSS - Child Selectors
- CSS - Element Selectors
- CSS - Descendant Selectors
- CSS - General Sibling Selectors
- CSS - Adjacent Sibling Selectors
- CSS Advanced
- CSS - Grid
- CSS - Grid Layout
- CSS - Flexbox
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Paged Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS - Image Sprites
- CSS - Important
- CSS - Data Types
- CSS3 Advanced Features
- CSS - Rounded Corner
- CSS - Border Images
- CSS - Multi Background
- CSS - Color
- CSS - Gradients
- CSS - Box Shadow
- CSS - Box Decoration Break
- CSS - Caret Color
- CSS - Text Shadow
- CSS - Text
- CSS - 2d transform
- CSS - 3d transform
- CSS - Transition
- CSS - Animation
- CSS - Multi columns
- CSS - Box Sizing
- CSS - Tooltips
- CSS - Buttons
- CSS - Pagination
- CSS - Variables
- CSS - Media Queries
- CSS - Functions
- CSS - Math Functions
- CSS - Masking
- CSS - Shapes
- CSS - Style Images
- CSS - Specificity
- CSS - Custom Properties
- CSS Responsive
- CSS RWD - Introduction
- CSS RWD - Viewport
- CSS RWD - Grid View
- CSS RWD - Media Queries
- CSS RWD - Images
- CSS RWD - Videos
- CSS RWD - Frameworks
- CSS References
- CSS Interview Questions
- CSS Online Quiz
- CSS Online Test
- CSS Mock Test
- CSS - Quick Guide
- CSS - Cheatsheet
- CSS - Properties References
- CSS - Functions References
- CSS - Color References
- CSS - Web Browser References
- CSS - Web Safe Fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
CSS - border-color Property
CSS border-color property lets you set the color of an element's four borders. You can specify different colors for each border side based on the number of values provided. The border-style must be defined.
Syntax
border-color: color | transparent | initial | inherit;
Property Values
Value | Description |
---|---|
color | It specifies the color of border. Different color formats can be used (names,rgb values,hex values,hsl values etc.). Default color is the current color of the element. |
transparent | It specifies that the border must be transparent. | initial | This sets the property to its default value. |
inherit | This inherits the property from the parent element. |
Examples of CSS Border Color Property
The following examples explain the border-color property with different values.
Border Color using Color Names
The color of the border can be set using color names. In the following example, different number of color values have been given and border colors have been set using color names.
Example
<!DOCTYPE html> <html> <head> <style> #one { background-color:grey; padding: 15px; border: 5px solid; border-color: red; } #two { background-color:grey; padding: 15px; border: 5px solid; border-color: red blue; } #three { background-color:grey; padding: 15px; border: 5px solid; border-color: red green blue; } #four { background-color:grey; padding: 15px; border: 5px solid; border-color: red green orange blue; } </style> </head> <body> <h2> CSS border-color property </h2> <p id="one"> This example is showing all borders in a single color. </p> <p id="two"> This example is showing all borders in two different colors. </p> <p id="three"> This example is showing all borders in three different colors. </p> <p id="four"> This example is showing all borders in four different colors. </p> </body> </html>
Border Color using Hexadecimal Values
The color of the border can be set using hexadecimal values. In the following example, different number of color values have been given and border colors have been set using hexadecimal values.
Example
<!DOCTYPE html> <html> <head> <style> #one { background-color:grey; padding: 15px; border: 5px solid; border-color: #33cc33; } #two { background-color:grey; padding: 15px; border: 5px solid; border-color: #33cc33 #ff6600; } #three { background-color:grey; padding: 15px; border: 5px solid; border-color: #33cc33 #ffff66 #ff6600; } #four { background-color:grey; padding: 15px; border: 5px solid; border-color: #33cc33 #ffff66 #669900 #ff6600; } </style> </head> <body> <h2> CSS border-color property </h2> <p id="one"> This example is showing all borders in a single color. </p> <p id="two"> This example is showing all borders in two different colors. </p> <p id="three"> This example is showing all borders in three different colors. </p> <p id="four"> This example is showing all borders in four different colors. </p> </body> </html>
Border Color using RGB Values
The color of the border can be set using rgb values. In the following example, different number of color values have been given and border colors have been set using rgb values.
Example
<!DOCTYPE html> <html> <head> <style> #one { background-color:grey; padding: 15px; border: 5px solid; border-color: rgb(204, 51, 255); } #two { background-color:grey; padding: 15px; border: 5px solid; border-color: rgb(204, 51, 255) rgb(255, 80, 80); } #three { background-color:grey; padding: 15px; border: 5px solid; border-color: rgb(204, 51, 255) rgb(102, 0, 255) rgb(255, 80, 80); } #four { background-color:grey; padding: 15px; border: 5px solid; border-color: rgb(204, 51, 255) rgb(102, 0, 255) rgb(102, 0, 102) rgb(255, 80, 80); } </style> </head> <body> <h2> CSS border-color property </h2> <p id="one"> This example is showing all borders in a single color. </p> <p id="two"> This example is showing all borders in two different colors. </p> <p id="three"> This example is showing all borders in three different colors. </p> <p id="four"> This example is showing all borders in four different colors. </p> </body> </html>
Border Color using HSL Values
The color of the border can be set using hsl values. In the following example, different number of color values have been given and border colors have been set using hsl values.
Example
<!DOCTYPE html> <html> <head> <style> #one { background-color:grey; padding: 15px; border: 5px solid; border-color: hsl(195, 100%, 40%); } #two { background-color:grey; padding: 15px; border: 5px solid; border-color: hsl(195, 100%, 40%) hsl(330, 50%, 40%); } #three { background-color:grey; padding: 15px; border: 5px solid; border-color: hsl(195, 100%, 40%) hsl(24, 100%, 50%) hsl(330, 50%, 40%); } #four { background-color:grey; padding: 15px; border: 5px solid; border-color: hsl(195, 100%, 40%) hsl(24, 100%, 50%) hsl(30, 100%, 40%) hsl(330, 50%, 40%); } </style> </head> <body> <h2> CSS border-color property </h2> <p id="one"> This example is showing all borders in a single color. </p> <p id="two"> This example is showing all borders in two different colors. </p> <p id="three"> This example is showing all borders in three different colors. </p> <p id="four"> This example is showing all borders in four different colors. </p> </body> </html>
Note: Different number of values affect the border color property differently.
- One value: if one color value is given, then it is applied to all the four borders.
- Two values: if two values are given, then the first color is applied to top and bottom borders and the second color to left and right borders.
- Three values: if three values are given, first color is for top border, second color for left and right borders and third color for bottom border.
- Four values: if four values are given, first color is for top border, second color for right border, third color for bottom borders and fourth for left border.
Border Color using Transparent Value
To have transparent borders, we use the transparent value. In the following example, transparent value has been used.
Example
<!DOCTYPE html> <html> <head> <style> #transparent { background-color:grey; padding: 15px; border: 5px solid; border-color: transparent; } </style> </head> <body> <h2> CSS border-color property </h2> <p id="transparent"> This example shows transparent borders. </p> </body> </html>
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
border-color | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |