- Select the direction your triangle should point (e.g., top, bottom, left, right, or diagonal).
- Enter the desired dimensions for the triangle's width and height in pixels.
- Choose the color of the triangle using the color picker or hex input field.
- Copy the generated CSS snippet from the output area.
- Paste the code into your project's stylesheet and apply the class to an HTML element or pseudo-element (
::before/::after).
CSS Triangle Generator
CSS Triangle Generator tool on AzWebTools.
Result
Fill inputs and click run.
How to Use This Tool
Learn More About CSS Triangle Generator
The Magic Behind CSS Triangles
Creating triangles in CSS without SVGs or background images relies on a technique known as the "CSS border hack." Because web browsers render CSS borders with angled intersections, developers can manipulate these angles to draw geometric shapes.
When an HTML element has a width and height of zero, its borders collapse inward, meeting at exact center points. By making three of the borders transparent and applying a visible color to the fourth, a perfect triangle is formed.
Why Use CSS Triangles?
- Performance: They require zero HTTP requests, unlike PNG or JPG images, keeping page load times minimal.
- Scalability: They can be resized directly via CSS without losing quality or rendering pixelated.
- Ease of Styling: Colors can be changed dynamically using CSS variables, hover states, or JavaScript without swapping out image assets.
Understanding the Code Structure
A typical CSS triangle pointing upwards requires a solid bottom border, while the left and right borders are set to transparent. The height of the triangle is controlled by the bottom border's width, and the overall width of the triangle is determined by the sum of the left and right border widths.
The Origin of the CSS Border Hack
- Technique Name
- CSS Border Hack
- Primary Use
- Tooltips & Pointers
Examples
Upward Equilateral (100x100)
{"direction":"top","width":100,"height":100,"color":"#3b82f6"}{
"direction": "top",
"width": 100,
"height": 100,
"color": "#3b82f6"
}Right Arrow (50x100)
{"direction":"right","width":50,"height":100,"color":"#10b981"}{
"direction": "right",
"width": 50,
"height": 100,
"color": "#10b981"
}Top-Right Corner (100x100)
{"direction":"top-right","width":100,"height":100,"color":"#f59e0b"}{
"direction": "top-right",
"width": 100,
"height": 100,
"color": "#f59e0b"
}Use Cases
- Tooltip directional arrows
- Chat bubble pointer tails
- Dropdown menu indicators
- Breadcrumb navigation dividers
- Custom pure-CSS UI elements