The above figure illustrates the number of points. I am intentionally leaving a gap at the top to understand that we need an 8-point polygon. You may intuitively think that we need a 6-point polygon since we started with a 3-point polygon for the simple triangle but no.
This said, we only have 6 different coordinates because if we close the gap at that top, we will have an overlap between 4 points so two points will get repeated.
Let’s take the previous triangle and create a border-only version of it:
<iframe height="300" style="width: 100%;height: 300px" scrolling="no" title="Untitled" src="https://codepen.io/t_afif/embed/preview/dyrZPoL/3c854c7556ef0e4244084f992a592c94?default-tab=result" frameborder="no" loading="lazy" allowtransparency="true" allowfullscreen="true">
See the Pen <a href="https://codepen.io/t_afif/pen/dyrZPoL/3c854c7556ef0e4244084f992a592c94">Untitled</a> by Temani Afif (<a href="https://codepen.io/t_afif">@t_afif</a>)
on <a href="https://codepen.io">CodePen</a>. </iframe>
.triangle {
width: 200px;
aspect-ratio: 1;
clip-path:
polygon(
/* the outer points */
0 0,100% 100%,0 100%,0 0,
/* the inner points */
5% 10%,5% 95%,90% 95%,5% 10%
);
}
The “outer points” are the ones we used to create the basic triangle where the first point (0,0) is repeated twice and the “inner points are the new ones that will define the border of our triangle. The first point (5%,10%) is also repeated twice.
The difficult part here is to find the correct coordinates for the inner points to get a uniform thickness on all the sides. You will need some geometry/math knowledge to identify the formulas and I know that it can be tricky that’s why having an online generator can be a lifesaver.
The code of the previous triangle can be written like below:
.triangle {
--b: 15px; /* control the border thickness */
width: 150px;
aspect-ratio: 1;
clip-path:
polygon(
/* outer points */
0 100%,0 0,100% 100%,0 100%,
/* inner points */
var(--b) calc(100% - var(--b)),
calc(100% - var(--b)/tan(22.5deg)) calc(100% - var(--b)),
var(--b) calc(var(--b)/tan(22.5deg)),
var(--b) calc(100% - var(--b))
);
}
Even if you don’t understand all the values/formulas of the clip-path, all you have to do is update one variable to control the border thickness.
<iframe height="300" style="width: 100%;height:300px" scrolling="no" title="Untitled" src="https://codepen.io/t_afif/embed/preview/XWGzJpP/a330133c89e30d9a81e78e51ac2263b4?default-tab=result" frameborder="no" loading="lazy" allowtransparency="true" allowfullscreen="true">
See the Pen <a href="https://codepen.io/t_afif/pen/XWGzJpP/a330133c89e30d9a81e78e51ac2263b4">Untitled</a> by Temani Afif (<a href="https://codepen.io/t_afif">@t_afif</a>)
on <a href="https://codepen.io">CodePen</a>.
</iframe>
You will find 12 variations within my collection. I tried to create the most common ones.