New answer
In addition to the below answer using gradients, I also have an online generator for triangle shapes where you can get some border-only triangles: https://css-generators.com/triangle-shapes/
Old answer
Here is an idea using multiple background and linear-gradient
:
.triangle {
width:100px;
height:100px;
background:
/* Left side */
linear-gradient(to bottom left,
transparent 49.5%,#000 50% calc(50% + 10px),
transparent calc(50% + 11px)) right/50% 100%,
/* right side */
linear-gradient(to bottom right,
transparent 49.5%,#000 50% calc(50% + 10px),
transparent calc(50% + 11px)) left/50% 100%,
/* bottom side*/
linear-gradient(#000,#000) bottom/calc(100% - 20px) 10px;
background-repeat:no-repeat;
}
<div class="triangle"></div>
You can consider CSS variables to easily adjust the shape:
.triangle {
--t:10px; /* Thickness */
--c:black; /* Color */
width:100px;
height:100px;
display:inline-block;
background:
/* Left side */
linear-gradient(to bottom left,
transparent 49.5%,var(--c) 50% calc(50% + var(--t)),
transparent calc(50% + var(--t) + 1px)) right/50% 100%,
/* right side */
linear-gradient(to bottom right,
transparent 49.5%,var(--c) 50% calc(50% + var(--t)),
transparent calc(50% + var(--t) + 1px)) left/50% 100%,
/* bottom side*/
linear-gradient(var(--c),var(--c)) bottom/calc(100% - 2*var(--t)) var(--t);
background-repeat:no-repeat;
}
body {
background:pink;
}
<div class="triangle"></div>
<div class="triangle" style="--t:5px;--c:blue;width:150px"></div>
<div class="triangle" style="--t:8px;--c:red;height:150px"></div>
<div class="triangle" style="--t:15px;--c:green;width:80px"></div>
A different syntax with less gradient:
.triangle {
--t:10px; /* Thickness */
--c:black; /* Color */
width:100px;
height:100px;
display:inline-block;
border:var(--t) solid transparent;
border-bottom-color:var(--c);
background:
/* Left side */
linear-gradient(to bottom left,
transparent 49.5%,var(--c) 50% calc(50% + var(--t)),
transparent calc(50% + var(--t) + 1px)) right,
/* right side */
linear-gradient(to bottom right,
transparent 49.5%,var(--c) 50% calc(50% + var(--t)),
transparent calc(50% + var(--t) + 1px)) left;
background-size:50% 100%;
background-origin:border-box;
background-repeat:no-repeat;
}
body {
background:pink;
}
<div class="triangle"></div>
<div class="triangle" style="--t:5px;--c:blue;width:150px"></div>
<div class="triangle" style="--t:8px;--c:red;height:150px"></div>
<div class="triangle" style="--t:15px;--c:green;width:80px"></div>
You can consider the same idea to create a rectangle triangle:
.triangle {
--t:10; /* Thickness */
--c:black; /* Color */
width:100px;
height:100px;
display:inline-block;
border:calc(var(--t)*1px) solid transparent;
border-image:
linear-gradient(to bottom left,
transparent 49.5%,var(--c) 50%) var(--t);
background:
/* Left side */
linear-gradient(to bottom left,
transparent 49.5%,var(--c) 50% calc(50% + var(--t)*1px),
transparent calc(50% + var(--t)*1px + 1px));
background-origin:border-box;
background-repeat:no-repeat;
}
body {
background:pink;
}
<div class="triangle"></div>
<div class="triangle" style="--t:5;--c:blue;width:150px"></div>
<div class="triangle" style="--t:8;--c:red;height:150px"></div>
<div class="triangle" style="--t:15;--c:green;width:80px"></div>
If you want an equilateral triangle simply keep a ratio bettween the width/height using the initial code
.triangle {
--t:10px; /* Thickness */
--c:black; /* Color */
width:100px;
display:inline-block;
border:var(--t) solid transparent;
border-bottom-color:var(--c);
background:
/* Left side */
linear-gradient(to bottom left,
transparent 49.5%,var(--c) 50% calc(50% + var(--t)),
transparent calc(50% + var(--t) + 1px)) right,
/* right side */
linear-gradient(to bottom right,
transparent 49.5%,var(--c) 50% calc(50% + var(--t)),
transparent calc(50% + var(--t) + 1px)) left;
background-size:50% 100%;
background-origin:border-box;
background-repeat:no-repeat;
}
.triangle:before {
content:"";
display:block;
padding-top:86.6%;
}
body {
background:pink;
}
<div class="triangle"></div>
<div class="triangle" style="--t:5px;--c:blue;width:150px"></div>
<div class="triangle" style="--t:8px;--c:red;width:50px"></div>
<div class="triangle" style="--t:15px;--c:green;width:80px"></div>
Related answer for more details about the calculation: How do CSS triangles work?