# Not able to understand how css border works

**URL:** <https://forum.freecodecamp.org/t/not-able-to-understand-how-css-border-works/498534>\
**Category:** General\
**Created:** [February 25, 2022, 3:05pm UTC](https://forum.freecodecamp.org/t/not-able-to-understand-how-css-border-works/498534 "2022-02-25T15:05:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sndlynk](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sndlynk/32/240785_2.png) [@sndlynk](https://forum.freecodecamp.org/u/sndlynk)\
**Post date:** [February 25, 2022, 3:05pm UTC](https://forum.freecodecamp.org/t/not-able-to-understand-how-css-border-works/498534/1 "2022-02-25T15:05:29Z")

</div>

[https://codepen.io/sndlynk/pen/WNXgQJq](https://codepen.io/sndlynk/pen/WNXgQJq).  
In the above code, I am not able to understand if no width and height is given for an element and border is set then how space is defined for border.  
As in above code `border-width: 0px 200px 200px 200px;` why blue color space width is more as compare to black color space and green color space . As we have clearly defined all to be same width.

---

<div class="post-metadata">

**Author:** ![userNameOnline](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/usernameonline/32/108878_2.png) [@userNameOnline](https://forum.freecodecamp.org/u/userNameOnline)\
**Post date:** [February 25, 2022, 3:17pm UTC](https://forum.freecodecamp.org/t/not-able-to-understand-how-css-border-works/498534/2 "2022-02-25T15:17:14Z")

</div>

Try using the shorthand css property of border

---

<div class="post-metadata">

**Author:** ![sndlynk](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sndlynk/32/240785_2.png) [@sndlynk](https://forum.freecodecamp.org/u/sndlynk)\
**Post date:** [February 25, 2022, 3:24pm UTC](https://forum.freecodecamp.org/t/not-able-to-understand-how-css-border-works/498534/3 "2022-02-25T15:24:04Z")

</div>

sorry … but my question is different then your provided answer.

---

<div class="post-metadata">

**Author:** ![Jagaya](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jagaya/32/202277_2.png) [@Jagaya](https://forum.freecodecamp.org/u/Jagaya)\
**Post date:** [February 25, 2022, 3:25pm UTC](https://forum.freecodecamp.org/t/not-able-to-understand-how-css-border-works/498534/4 "2022-02-25T15:25:03Z")

</div>

> [@sndlynk](#):
>
> why blue color space width is more as compare to red color space and green color space .

It isn’t - the “width” for borders is NOT the same as the “witdh” of an element.  
When I want a 2px border on the bottom, I want it to be 2px wide from top-to-bottom. When I want 2px border on the left, it is 2px wide from left to right.  
And that’s exactly what’s happening - the blue border “width top to bottom” is 200px, just as black and green are “200px wide left to right”.

Ofcourse for general elements, “width” refers to left-to-right and “height” to top-to-bottom. But that’s for areas. Borders are considered “lines” with a linewidth.

If you go and add in the red border with 200px, you can even see that in fact all borders cover the area of the blue triangle - but because red is 0px, it’s only the bottom half of the resulting square → and the resulting square has width and height of 400px each.

---

<div class="post-metadata">

**Author:** ![sndlynk](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sndlynk/32/240785_2.png) [@sndlynk](https://forum.freecodecamp.org/u/sndlynk)\
**Post date:** [February 25, 2022, 3:30pm UTC](https://forum.freecodecamp.org/t/not-able-to-understand-how-css-border-works/498534/5 "2022-02-25T15:30:28Z")

</div>

Thank you… for your detailed explaination … I

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [August 27, 2022, 3:30am UTC](https://forum.freecodecamp.org/t/not-able-to-understand-how-css-border-works/498534/6 "2022-08-27T03:30:54Z")

</div>

Closed on August 27, 2022, 3:30am UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
