CSS Triangle Generator
Create pure CSS triangles in any direction using the border trick — for tooltips, arrows, and decoration.
Last updated: March 25, 2026
Find this tool useful? Support the project to keep it free!
Buy me a coffeeWhat is CSS Triangle Generator?
CSS triangles exploit a geometric property of how borders are rendered. When an element has zero width and zero height (width: 0; height: 0), its four borders meet at the center point of the element. Each border occupies one quadrant of this meeting point. By making three borders transparent and one border opaque-colored, the visible border quadrant appears as a filled triangle pointing towards the element center from that border's side.
The direction the triangle points depends on which border is colored: border-bottom = triangle pointing up (the colored bottom border fills the bottom half of the element), border-top = triangle pointing down, border-left = triangle pointing right, border-right = triangle pointing left. The size of the triangle is controlled by the border-width values — the colored border's width sets the height of the triangle, and the adjacent borders' widths set the horizontal spread. Unequal adjacent border widths create right-angled or isosceles variants.
How to Use CSS Triangle Generator
Select the direction the triangle should point: Up, Down, Left, Right, or a diagonal corner direction
Adjust the triangle's Base Width (horizontal spread) and Height (how tall/deep the triangle is)
Choose the Fill Color from the color picker
Preview the resulting CSS triangle in real-time in the preview panel
Click "Copy CSS" to get the complete selector-ready CSS code for the triangle element
Common Use Cases
- Creating a speech bubble or tooltip pointer arrow (triangle attached to a bubble box)
- Dropdown menu downward-pointing indicator chevron for a select-style menu
- Breadcrumb navigation separator using a right-pointing triangle between path segments
- Creating a "corner ribbon" effect using a colored triangle clipped into a card corner
- Decorative diagonal divider between page sections as an alternative to a straight horizontal rule
- Visual indicator pointing to the active item in a vertical navigation sidebar
- Accordion or collapsible section toggle indicator (triangle rotates 90° on open)
- CSS-only decorative bullet point using a small right-pointing triangle instead of a disc
Example Input and Output
Creating a tooltip "caret" — a downward triangle attached below a tooltip box:
Direction: Points down (caret pointing to content below)
Base width: 20px (10px each side)
Height: 10px
Color: #333 (match tooltip background)/* Down-pointing triangle (used as tooltip caret) */
.tooltip::after {
content: '';
position: absolute;
top: 100%; /* position below the tooltip box */
left: 50%;
transform: translateX(-50%);
width: 0;
height: 0;
/* Transparent side borders set total width */
border-left: 10px solid transparent;
border-right: 10px solid transparent;
/* Colored top border creates the downward triangle */
border-top: 10px solid #333;
}
/* Tooltip container */
.tooltip {
position: relative;
background: #333; color: #fff;
padding: 6px 10px; border-radius: 4px;
}Client-Side Processing
All CSS generation and preview happen locally in your browser. No data is sent to our servers.
Modern Alternative: clip-path
For more complex triangle needs, use clip-path: polygon(). Unlike the border trick, clip-path elements can have background-color, background-image, gradients, and children: div { width: 100px; height: 80px; clip-path: polygon(50% 0%, 0% 100%, 100% 100%); background: #333; }. This creates a filled upward triangle without the width:0 constraint of the border trick.
Pseudo-Element Usage
In practice, CSS triangles are almost always implemented using ::before or ::after pseudo-elements on the parent element (like a tooltip or dropdown), not on dedicated empty <div> elements. This avoids adding meaningless markup: .tooltip::after { content: ""; width: 0; height: 0; ... }. The content: "" is required for the pseudo-element to render even when it has no text content.
Frequently Asked Questions
Why does setting a border create a triangle?
How do I change the triangle orientation?
How do I create an isosceles vs right-angled triangle?
Are CSS triangles accessible?
Is the CSS border trick better than using SVG triangles?
Can I use clip-path instead of the border trick?
How This Tool Works
The triangle preview is rendered by a <div> with the configured border values applied inline. When direction or size changes, border-width values are recalculated: the colored border width = triangle height, and the two adjacent transparent border widths = half the base width each. The fourth border (opposite the direction) is set to 0. The assembled CSS block is formatted for display and clipboard copy.
Technical Stack