UGURUS offers elite coaching and mentorship for agency owners looking to grow. Start with the free Agency Accelerator today.
The border
property is a shorthand syntax in CSS that accepts multiple values for drawing a line around the element it is applied to.
.belement{
border: 3px solid red;
width: 200px;
aspect-ratio: 1;
}
Syntax
border: <line-width> || <line-style> || <color>
Values
The border
property accepts one or more of the following values in combination:
border-width
: Specifies the thickness of the border.- : A numeric value measured in
px
,em
,rem
,vh
andvw
units. thin
: The equivalent of1px
medium
: The equivalent of3px
thick
: The equivalent of5px
- : A numeric value measured in
border-style
: Specifies the type of line drawn around the element, including:solid
: A solid, continuous line.none
(default): No line is drawn.hidden
: A line is drawn, but not visible. this can be handy for adding a little extra width to an element without displaying a border.dashed
: A line that consists of dashes.dotted
: A line that consists of dots.double
: Two lines are drawn around the element.groove
: Adds a bevel based on the color value in a way that makes the element appear pressed into the document.ridge
: Similar togroove
, but reverses the color values in a way that makes the element appear raised.inset
: Adds a split tone to the line that makes the element appear slightly depressed.outset
: Similar toinset
, but reverses the colors in a way that makes the element appear slightly raised.
border-color
: Specifies the color of the border and accepts all valid color values.
Phew, that’s a lot of values for one little ol’ property! Here’s a demo that illustrates the differences between all of those style values:
Constituent properties
The border
property is a shorthand for the following border-related properties:
Physical Properties | Logical Properties |
---|---|
border-top | border-block-start |
border-bottom | border-block-end |
border-left | border-inline-start |
border-right | border-inline-end |
So, this:
.element {
border: 3px solid #f8a100;
}
…is the same as:
.element {
border-top: 3px solid #f8a100;
border-right: 3px solid #f8a100;
border-bottom: 3px solid #f8a100;
border-left: 3px solid #f8a100;
}
…or the logical equivalent:
.element {
border-block-start: 3px solid #f8a100;
border-inline-end: 3px solid #f8a100;
border-block-end: 3px solid #f8a100;
border-inline-start: 3px solid #f8a100;
}
We can declare borders in just the block
or inline
direction since a couple of those logical properties have their own shorthands:
.element {
/* The top (start) and bottom (end) borders */
border-block: 3px solid #f8a100;
/* The left (start) and right (end) borders */
border-inline: 3px solid #f8a100;
}
Browser support
You can count on excellent support for the border
property across all browsers.
Chrome | Safari | Firefox | Opera | IE | Android | iOS |
---|---|---|---|---|---|---|
Yes | Yes | Yes | 3.5+ | 4+ | Yes | Yes |
More information
- CSS Backgrounds and Borders Module Level 3 Specification
- Understanding border-image
- A Tale of Border Gradients
Related
border-block
.element { border-block: 5px solid #f8a100; }
border-boundary
.element { border-boundary: display; }
border-collapse
.element { border-collapse: separate; }
border-image
.element { border-image: url(border.png) 25 25 round; }
border-inline
.element { border-inline: 5px solid #f8a100; }
border-radius
.element { border-radius: 10px; }
border-spacing
.element { border-spacing: 5px; }
Any more about borders?
border-radius, …
border-radius is a different property, it is not included in the shorthand
border
, but if you are looking for it, you can also find it in the almanac: https://css-tricks.com/almanac/properties/b/border-radius/Hi Chris,
Would like to see the list of available border style properties here. Believe that would be helpful.
Also, you insight/opinion on these styles. I see solid, dotted, dashed frequently but not the others…are they going out of style?…are they being deprecated?
All the best,
John
Who is this Chris you are trying to speak to?
how this site is really helpful but am in agreement with john what about the other styles hidden, dotted, dashed, solid, double, groove, ridge, inset, outset?
why are they not included.
Thanks for the help. This site is good when I have trouble making the code right.
this is really very helpfull, thanks guys
i want a shadow for my border-bottom. Help
Hey there and thanks for reaching out! Both
border
andbox-shadow
are properties that are applied to an element. They work pretty well together, too. :)For example, you can have an orange bottom border on a box, then apply a dark box shadow on it:
.my-element {
height: 100px;
width: 100px;
border-bottom: orange;
box shadow: 3px 3px 3px #000; /* Sets a black shadow to the right and bottom and blurs it a smidge */
}
Hey Sara, thanks or this great article. Would you happen to know if, by any chance, it is possible to add a height property to a border? Something like https://prnt.sc/uiprv7
I wanted to add a gradient styled color for the border on my website. Anyone knows how to do it.
Hi Guys. I’d like to know if it’s possible to have percentage colors inside a border with CSS only? Like 3 colors separated… 2% red, 7% green, 91% gray. Something like that but not gradient. Like a progress…
I have to ask shouldn’t the first example be a square?
(not being a nitpicker, just confused)
I’d like to know how you changed the appearance of the scroll bar on the right.
Hello,
I am trying to use the Double edge.
How can you indicate the thickness of the lines and the space, in a distinct way?
I searched all over the web, I only found a link that states “border-double-thickness” but only applies it online.
I kept looking for “border-double-thickness”, but I couldn’t find anything.
This is the link
https://www.antennahouse.com/hubfs/xsl-fo-sample/block/axf-border-double-thickness-1.pdf?hsLang=en#
Do you know how to indicate how to do it?
Thank you
Hello,
I’m exploring the edges in CSS Properties and found one thing with no absolute solution. When I give border property with some value to an element,
eg:
the four sides of an element actually not occupies 2px, instead it takes only 1.6px. Where is the rest 0.4px going?