Css triangle generator cropped

Live preview

A CSS triangle is a zero-size box whose borders do the drawing. With width and height set to 0, the four borders meet at a point in the middle, so each border is a triangle. Colour one border and make the ones next to it transparent, and the coloured border shows up as a triangle pointing the opposite way — for an upward triangle, the bottom border is coloured and the left and right borders are transparent. That is why the coloured border sits on the side the triangle points away from.

What is the CSS Triangle Generator?

The CSS Triangle Generator is a free online tool that makes a triangle in pure CSS — no image, no SVG, no extra file. You pick a direction, set the width, height and colour, and the tool shows you a live preview plus the CSS that draws the triangle. Copy the code, paste it into your stylesheet, and you have a triangle that scales cleanly, matches your colours exactly and costs nothing to download. It is made for anyone who needs a small arrow, pointer or corner shape on a page: beginners learning how CSS borders work, bloggers adding a dropdown arrow, and developers who want a triangle without reaching for an image editor.

The trick behind a CSS triangle is a zero-size box. An HTML element with a width and height of 0 has no content area, but its borders are still drawn — and where the four borders meet in the middle, each border is itself a triangle. Colour one border and make the ones next to it transparent, and the coloured border shows up as a triangle pointing the opposite way. That is the whole technique, and it is why the generated CSS looks the way it does: a .triangle rule with width: 0, height: 0 and two or three border declarations.

Everything runs in your browser. There is no sign-up, no account, and nothing you type leaves your device.

How to use the CSS Triangle Generator

  1. Pick a direction. The Direction dropdown offers eight choices: Up, Down, Left, Right, Top-left, Top-right, Bottom-left and Bottom-right. Up is selected by default. The four straight directions make an isosceles triangle pointing that way; the four corner directions make a right-angled triangle in that corner.
  2. Set the width and height. Width (px) and Height (px) both default to 100. For a triangle pointing up or down, the width is the base of the triangle and the height is the point. For a triangle pointing left or right, the width is the point and the height is the base. The numbers can be anything from 1 upwards.
  3. Pick a colour. The Colour picker defaults to crimson (#e62f41). Choose any colour you like — the preview updates as you pick.
  4. Watch the live preview. The preview shows your triangle at the size and colour you set, updating with every change.
  5. Copy the CSS. Press Copy CSS to take the .triangle rule, or Reset to return to the upward crimson triangle.

Worked example: an upward triangle

Leave the direction on Up, the width and height on 100, and the colour on #e62f41. The tool generates this CSS:

.triangle {
  width: 0;
  height: 0;
  border-left: 50px solid transparent;
  border-right: 50px solid transparent;
  border-bottom: 100px solid #e62f41;
}

Read it from the bottom up: the bottom border is 100px tall and coloured, so it forms the visible triangle, while the left and right borders are each 50px wide and transparent — they shape the sides without being seen. The coloured border sits on the side the triangle points away from: for an upward triangle, the bottom border is coloured.

Now change the direction to Top-left. The output becomes two borders instead of three:

.triangle {
  width: 0;
  height: 0;
  border-top: 100px solid #e62f41;
  border-right: 100px solid transparent;
}

A corner triangle needs only two borders, because it fills one corner of the zero-size box rather than pointing across it.

Where a CSS triangle comes in handy

Dropdown and menu arrows. A small triangle next to a menu label is the clearest way to say “there is more here”. Use a downward triangle in the same colour as the menu text, about 8 to 12 pixels wide, and it reads as an arrow without any image. Because it is pure CSS, it follows the text colour and size of the menu automatically when you change the theme.

Tooltip pointers. A tooltip box with a little triangle on its edge looks like it is pointing at the thing it describes. Place an upward triangle above a tooltip that sits below its target, or a downward triangle below one that sits above it.

Speech-bubble tails and section dividers. A chat bubble needs a tail, and a section divider sometimes needs a pointed edge. A corner triangle makes a neat bubble tail, and a wide, short upward or downward triangle makes a clean zigzag divider between two sections. In both cases the shape is a few lines of CSS, loads instantly and stays sharp at any screen size.

Tips for better CSS triangles

  • Remember which border is coloured. The coloured border is always on the side the triangle points away from. Up means the bottom border is coloured, down means the top, left means the right, and right means the left. If your triangle points the wrong way, you have the coloured border on the wrong side — switch the direction in the tool and copy the new code.
  • Width and height do different jobs. For an up or down triangle, the width sets the base and the height sets how far the point reaches. For a left or right triangle, it is the other way round: the height is the base and the width is the point. Change one at a time in the preview and you will see exactly which edge moves.
  • Corner triangles use two borders. A top-left, top-right, bottom-left or bottom-right triangle is drawn with one coloured border and one transparent border. That is why the generated CSS for a corner direction has only two border lines. Do not add the missing borders back — the shape is complete without them.
  • Rename the class before you paste it in. The generated rule is called .triangle, which is a generic name that could clash with another rule in your stylesheet. Give it a name that says what it is, such as .menu-arrow or .tooltip-pointer, and update the class on your element to match.
  • Use it in a pseudo-element for arrows. You do not need an extra empty element in your HTML to show a triangle. Put the border declarations on a ::before or ::after pseudo-element of the thing the arrow belongs to — for example, the menu button or the tooltip box — and the arrow appears without any extra markup.

Frequently asked questions

Why is a CSS triangle made from borders?

Because of how borders meet. On a normal box, each border is a trapezoid that meets its neighbours at 45 degrees. Shrink the box to zero width and height and those trapezoids become triangles that meet at a single point in the middle. Colour one of them and make the adjacent ones transparent, and the coloured one is visible as a triangle. No image or extra element is needed — the borders are doing all the drawing.

Can I make a right-angled triangle?

Yes. Choose one of the four corner directions: Top-left, Top-right, Bottom-left or Bottom-right. A corner triangle fills one corner of the zero-size box, so it has a right angle and only needs two borders — one coloured, one transparent. It is the right shape for speech-bubble tails and corner ribbons.

How do I make the triangle point down?

Select Down in the Direction dropdown. The tool colours the top border and makes the left and right borders transparent, so the point faces downwards. If you are writing the CSS by hand, remember the rule: the coloured border sits on the side the triangle points away from.

Why does my triangle look like a square or a diamond?

That usually means a border is missing or the wrong colour. A full triangle needs the coloured border plus the transparent borders that shape its sides — for an upward triangle, that is a coloured bottom border with transparent left and right borders. If all four borders are coloured, the shape is a diamond.

Does a CSS triangle work in all browsers?

Yes. The technique uses only width, height and borders, which every browser has supported for decades. There is nothing experimental about it, and it needs no prefix or fallback. The triangle also scales perfectly, because it is drawn by the browser rather than stored as pixels.

Conclusion

The CSS Triangle Generator turns a clever CSS trick into a two-minute job: pick a direction, set the size and colour, and copy a .triangle rule that works everywhere. Try it as a dropdown arrow first — a small downward triangle next to a menu label — and then use the same technique for tooltip pointers and bubble tails. And when your triangle needs rounded corners or a soft shadow around it, the CSS Border Radius Generator and the CSS Box Shadow Generator are the tools to reach for next.

Related Tools