Why use CSS Triangle Generator
A CSS triangle is an element with no width and no height whose borders do all the drawing: one border is colored and becomes the triangle, and the borders next to it are transparent and cut its slanted edges. This generator writes the border-width and border-color values for a triangle pointing up, down, left or right. Base width and Height each run from 10 to 200 pixels in steps of 2. The base is split into two equal side borders and the height becomes the single colored border, so the result is always an isosceles triangle with its point centered on the base.
CSS triangle code for up, down, left and right
Generated with Base width 80, Height 60 and the default color #4f46e5. border-width and border-color list their values in the order top, right, bottom, left.
| Points towards | border-width | border-color |
|---|---|---|
| Up | 0 40px 60px 40px | transparent transparent #4f46e5 transparent |
| Down | 60px 40px 0 40px | #4f46e5 transparent transparent transparent |
| Left | 40px 60px 40px 0 | transparent #4f46e5 transparent transparent |
| Right | 40px 0 40px 60px | transparent transparent transparent #4f46e5 |
Every rule also contains width: 0; height: 0; border-style: solid;
How base width and height map to border widths
colored border = Height; each adjacent border = Base width / 2; border on the pointing side = 0
For a triangle pointing up with Base width 80 and Height 60, the bottom border is 60px, the left and right borders are 40px each and the top border is 0. The element's outer box ends up exactly Base width by Height (80 by 60 pixels), which is the space the triangle takes in the layout. For left and right triangles the roles swap: Height becomes the horizontal border and Base width is split between the top and bottom borders.
Tooltip arrow, dropdown caret and other common sizes
Each result is the tool's output for those settings.
Arrow under a dark tooltip
Points towards Down, Colour #333333, Base width 12, Height 10
border-width: 10px 6px 0 6px; border-color: #333333 transparent transparent transparent;
Match Colour to the tooltip background so the arrow reads as part of it.
Caret on top of a dropdown menu
Points towards Up, Colour #1f2937, Base width 16, Height 10
border-width: 0 8px 10px 8px; border-color: transparent transparent #1f2937 transparent;
Tail on the left side of a chat bubble
Points towards Left, Colour #e5e7eb, Base width 24, Height 14
border-width: 12px 14px 12px 0; border-color: transparent #e5e7eb transparent transparent;
Play-style arrow pointing right
Points towards Right, Colour #ffffff, Base width 20, Height 12
border-width: 10px 0 10px 12px; border-color: transparent transparent transparent #ffffff;
Close to equilateral
Points towards Up, Base width 100, Height 86
border-width: 0 50px 86px 50px;
An equilateral triangle's height is about 0.866 times its side, so 86 is the nearest slider value for a 100px base.
Right angle at the point
Points towards Up, Base width 100, Height 50
border-width: 0 50px 50px 50px;
When Height is half of Base width, the two slanted edges meet at 90 degrees.
Attaching the triangle to a tooltip with ::after
The usual place for a generated triangle is a pseudo-element, so no extra markup is needed. Give the tooltip position: relative, then paste the five generated declarations into .tooltip::after along with content: "" and position: absolute.
For an arrow under the tooltip, generate a triangle that points Down and add top: 100%; left: 50%; transform: translateX(-50%). The top: 100% puts the arrow's flat side against the tooltip's bottom edge and the translate centers it. For an arrow above the tooltip, generate Up and use bottom: 100% instead. For side arrows, generate Left or Right and use right: 100% or left: 100% with top: 50% and transform: translateY(-50%).
To give the arrow an outline that matches a bordered tooltip, use both pseudo-elements: ::before holds a triangle in the border color, and ::after holds the fill-colored triangle offset by the border thickness toward the tooltip so that only a thin edge of the first one shows.
Border triangle vs clip-path vs SVG
| Method | Needs a sized element | Can hold a gradient or image | Good for |
|---|---|---|---|
| Border trick (this tool) | No, width and height are 0 | No, solid color only | Small carets and tooltip arrows on pseudo-elements |
| clip-path: polygon(50% 0, 100% 100%, 0 100%) | Yes | Yes | Larger shapes, responsive sizes, shapes that animate |
| Inline SVG polygon | Yes | Yes, plus strokes | Icons and triangles that need a real outline |
This generator outputs the border method only.
What this generator does not produce
- Corner triangles. Diagonal directions such as top-left are not offered. By hand, a 100px right-angled triangle in the top-left corner is border-width: 100px 100px 0 0 with border-color set to your color followed by three transparent values.
- Uneven triangles. The point is always centered over the base, so scalene shapes need different left and right border widths typed in manually.
- Units other than px. Swap in em or rem after copying if the arrow should scale with text.
- Semi-transparent fills. Colour outputs an opaque hex value; replace it with an rgba() value by hand if needed.
- Outlines and shadows. Use the stacked pseudo-element approach or filter: drop-shadow() described above.
Step by step
- 1
Choose a direction in Points towards: Up, Down, Left or Right.
- 2
Pick the fill with Colour. The output uses a six-digit hex value.
- 3
Set Base width, the length of the flat side opposite the point.
- 4
Set Height, the distance from the base to the point.
- 5
Copy or download the .triangle rule from the CSS panel and rename the selector, for example to .tooltip::after.