a11y.skipToMainContent
1

CSS Triangle Generator

Generate pure-CSS triangles with the border trick — pick a direction, size and color, then copy the CSS.

px
px

Diagonal (corner) triangles are right-angled and ignore the separate height value, using the width for both sides.

Preview

CSS

Was this tool helpful?
Send output to:
Advertisement

How to use CSS Triangle Generator

  1. Choose a direction — up, down, left, right, or one of the four diagonal corners.
  2. Set the width and height to control the triangle's base and point.
  3. Pick the fill color for the visible side of the triangle.
  4. Click Copy CSS to copy the width, height and border declarations.

What is CSS Triangle Generator?

A pure-CSS triangle is made by giving a zero-size element thick borders and then making three of those borders transparent. Where the colored border meets the transparent ones, the diagonal seams form a triangle — no images or SVG needed.

This generator handles the math for you: choose one of eight directions (the four sides plus four right-angled corners), set the width, height and color, and copy the resulting width: 0; height: 0; and border-* declarations straight into your stylesheet.

Advertisement

FAQ

How does the CSS border triangle trick work?
An element with width 0 and height 0 still renders its borders, which meet at 45-degree diagonal seams. Coloring one border and making the other three transparent leaves a single triangular shape, with its point opposite the colored side.
Why are corner triangles right-angled?
Diagonal directions use only two adjacent borders, so the triangle has a square corner where those borders meet. Because both sides come from the same border width, corner triangles use the width value for both legs and ignore the separate height.
How do I change the triangle's size?
Adjust the width and height: a larger colored border makes the triangle longer in that direction, while the transparent borders set the width of the base. The tool updates the border values for you as you drag the sliders.

Related tools

Author

MW
Marcus Webb"The DevTool Craftsman"

Full-Stack Developer & Tools Architect

Marcus has been writing code since the dial-up era. He has contributed to open-source developer tools, built CI/CD pipelines for startups, and debugged production incidents at 3 AM more times than he would like to admit. His philosophy is that the best developer tool is the one that gets out of your way, and he writes about practical tooling that helps teams ship faster with fewer headaches.

← Back to Developer Tools · All tags

Last updated:

Advertisement