CSS triangle generator

This CSS triangle generator builds a triangle from a zero-width, zero-height box with one coloured border, and writes the code for the direction, size and colour you pick.

A CSS triangle is a zero-width, zero-height box whose single coloured border forms the triangle; pick a direction and size and copy the code.

How to use the generator

  1. Pick one of the eight directions, then drag or type a width and height between 1 and 500px.
  2. Choose a colour with the picker or type a hex, rgb() or hsl() value.
  3. Switch between Border trick and clip-path, check the live preview, then press Copy CSS.

Direction

Output

Live preview

Your CSS

width: 0;
height: 0;
border-style: solid;
border-width: 0 40px 60px 40px;
border-color: transparent transparent #111111 transparent;

How the border trick makes a triangle

An element with no width or height has no content box, so its borders meet in the middle. Each border is drawn as a triangle that points away from the centre. If you colour only one border and make the others transparent, that single coloured border is the triangle you see.

The width of the coloured border sets the triangle height, and the widths of the two transparent side borders set its base. That is why a 60px bottom border with 40px left and right borders makes a 80px-wide, 60px-tall triangle pointing up.

Border trick vs clip-path

Border trickclip-path
Supports borders and shadows on the triangle itself.Cannot add a border or shadow to the clipped shape.
Needs a fixed width and height.Needs a fixed width and height.
Works in all browsers.Works in all modern browsers.
Can be used as a tooltip arrow via ::after.Can be used as a tooltip arrow via ::after.

Copy-ready triangle examples

Tooltip arrow using ::after

.tooltip {
  position: relative;
  background: #111111;
  color: #ffffff;
  padding: 8px 12px;
  border-radius: 6px;
}
.tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -6px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 6px 6px 0 6px;
  border-color: #111111 transparent transparent transparent;
}

Dropdown caret

.caret {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 6px 5px 0 5px;
  border-color: #111111 transparent transparent transparent;
}

Down triangle

.triangle-down {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 40px 30px 0 30px;
  border-color: #111111 transparent transparent transparent;
}

Related generators

Pair a triangle with the other CSS generators on this site.

Frequently asked questions

How do you make a triangle in CSS?

Set an element to width: 0 and height: 0, give it a solid border, then colour only one side and make the other sides transparent. The coloured border is a triangle. For example, a bottom border of 60px with 40px left and right borders and a transparent top border points up.

How do I add a triangle arrow to a tooltip?

Give the tooltip position: relative, then add an ::after pseudo-element with content: an empty string, position: absolute, and the zero-size border trick. Place it at top: 100% and left: 50%, offset it by half its width with a negative margin-left, and colour the border to match the tooltip background.

Should I use border or clip-path for triangles?

Use the border trick when the triangle needs its own border, shadow or the widest browser support, and when it is a small arrow on a tooltip or dropdown. Use clip-path when you want a larger shape, a gradient fill or a triangle cut out of an image, and you can accept a fixed width and height.

How do I make a right-angle triangle in CSS?

Use two borders instead of three. Set width: 0 and height: 0, then give the element a top border and a right border of different widths, with the other two borders at zero. For example, border-width: 60px 80px 0 0 with border-color: #111111 transparent transparent transparent makes a right-angle triangle in the top-left corner.

More CSS generators

Color tools

Image tools

Image & SVG tools

Typography & units

More free tools

All free tools