UTILS.
Private by default
▲

CSS Triangle Generator

Generate a pure-CSS triangle in any direction and copy the CSS.

Your files stay on this device

Files are processed in your browser, never uploaded. The site downloads code and assets to run the tools. No accounts or trackers.

Use Download to save this tool as one HTML file for offline use.

Privacy →

About this tool

CSS Triangle Generator builds a triangle with the classic border trick and gives you the rule to paste into your stylesheet. Pick one of eight directions, drag the size slider from 10 to 200 px and choose a colour. The preview updates live, and the output box shows the declarations, which you can copy with one click.

The trick relies on an element with zero width and zero height, so only its borders take up space. Where borders meet they are cut diagonally, so making two neighbouring borders transparent leaves a single coloured wedge. For the up, down, left and right arrows the two side borders are transparent and the opposite side carries the colour. The slider value is the half-width of the base and also the height, so a 60 px setting gives a 120 px wide, 60 px tall arrow. The four corner options colour one border and make an adjacent one transparent, giving a right-angled triangle with legs of twice the size.

The output contains only declarations, with no selector, so wrap them in your own class or in a ::before or ::after pseudo-element with content: ''. The colour is a solid hex value from the picker. Everything is generated in your browser and nothing is uploaded.

Frequently asked questions

How does the border trick work?
A box with width and height of zero is made only of its borders, and each border meets the next along a diagonal. Making two adjacent borders transparent and leaving one coloured reveals a triangle pointing away from the coloured side.
Why are width and height set to 0?
With no content area the borders meet at a point, and that is what forms the triangle. If the box had any size, the triangle would sit inside a coloured rectangle instead.
What does the size slider control?
For the four straight directions it is the half-width of the base and the height, so the base is twice the slider value. For the four corner directions it sets border widths of twice the value, producing a right-angled triangle.
Can I use a semi-transparent or gradient fill?
Not from this tool, which outputs one solid hex colour. You can edit the copied colour to an rgba() value, since only one border is coloured. For gradients or rounded points, clip-path or an inline SVG is a better fit.

More tools