Skip to content
UniKit

CSS speech bubble generator

Generate speech bubbles with a pure-CSS triangle arrow: eight directions including the four corners, arrow size and offset, background, border colour and width, radius — with a live preview and complete CSS using ::before / ::after.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Live preview

A speech bubble whose arrow is a pure border triangle

Arrow direction

12px
120px

Arrow & size

240px
72px
12px

Colours & border

2px

Code

CSS
.bubble {
  position: relative;
  box-sizing: border-box;
  width: 240px;
  min-height: 72px;
  padding: 12px 16px;
  background: #FFFFFF;
  border: 2px solid #D6D9DE;
  border-radius: 12px;
}

.bubble::before,
.bubble::after {
  content: "";
  position: absolute;
  width: 0;
  height: 0;
}

.bubble::before {
  top: 100%;
  left: 118px;
  margin-left: -14.8px;
  border-left: 14.8px solid transparent;
  border-right: 14.8px solid transparent;
  border-top: 14.8px solid #D6D9DE;
}

.bubble::after {
  top: 100%;
  left: 118px;
  margin-left: -12px;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-top: 12px solid #FFFFFF;
}

A corner arrow is a right triangle built from two borders whose hypotenuse is tangent to the rounded corner, so a larger radius pushes the arrow further out; a small (or zero) radius keeps it snug against the bubble.

What this tool does

  • Build a speech bubble or hint box: choose the arrow direction and offset, tune the arrow size, background, border colour and radius, then copy the complete CSS with its ::before / ::after rules.
  • Build a tooltip: point the arrow up and keep the radius small so the bubble hugs the element; with a border the two triangles automatically cut an opening in it.
  • Build a corner ribbon: switch the arrow to one of the four diagonal directions and it becomes a 45° spike whose hypotenuse is tangent to the rounded corner.
  • Debug "the arrow covers my border" or "the arrow is a square": that is almost always a missing `content: ""` or `position: absolute` on the pseudo-element — the generated rules already include both.

Example

Input

Defaults: arrow pointing down, arrow size 12px, offset 120px, bubble 240 × min 72, background #FFFFFF, border 2px #D6D9DE, radius 12px

Output

.bubble {
  position: relative;
  box-sizing: border-box;
  width: 240px;
  min-height: 72px;
  padding: 12px 16px;
  background: #FFFFFF;
  border: 2px solid #D6D9DE;
  border-radius: 12px;
}

.bubble::before,
.bubble::after {
  content: "";
  position: absolute;
  width: 0;
  height: 0;
}

.bubble::before {
  top: 100%;
  left: 118px;
  margin-left: -14.8px;
  border-left: 14.8px solid transparent;
  border-right: 14.8px solid transparent;
  border-top: 14.8px solid #D6D9DE;
}

.bubble::after {
  top: 100%;
  left: 118px;
  margin-left: -12px;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-top: 12px solid #FFFFFF;
}

The outer triangle (::before, border colour) is 2 × √2 ≈ 2.8px larger than the inner one (::after, background colour): the perpendicular distance between their 45° hypotenuses equals the 2px border width, which is what cuts the opening in the bubble border.

Frequently asked questions

How is the triangle drawn, and why are width / height 0?

This is the classic border-triangle trick: a box with width and height 0 makes each of its four borders collapse into a triangle. Colouring one border and leaving its neighbours transparent yields an isosceles right triangle. The zero width and height are essential — remove them and you get a square.

How do the corner arrows differ from the four sides?

The four sides use one coloured border plus two transparent ones. The corners are isosceles right triangles assembled from two adjacent borders (for example border-top coloured plus border-right transparent). Their hypotenuse is tangent to the rounded corner at an intercept of `radius × (2 − √2)`, so a larger radius pushes the arrow further from the corner.

Why does the arrow cover the bubble border?

Both triangles have their base on the padding box edge of the bubble (`top: 100%` and friends), while the border sits outside it. The outer triangle uses the border colour and the inner one is 2 × √2 px smaller, so together they fill the gap in the border exactly.

What about browser support?

Everything involved is very old CSS (border triangles, absolutely positioned pseudo-elements, border-radius): it works from IE9 upwards and is safe in every modern browser. The one caveat is a translucent bubble background — the two triangles must be translucent too, otherwise the arrow shows up as a solid block.

The pseudo-element does not show up at all.

Two usual causes: a missing `content: ""` (a pseudo-element without content is never rendered), or `overflow: hidden` on an ancestor clipping the arrow that sticks outside the bubble. The generated rules always include content, position: absolute and the zero width/height.

How is the arrow offset measured?

It is the distance from the arrow centre to the left (for top/bottom arrows) or top (for left/right arrows) outer edge of the bubble, automatically clamped by half the outer triangle so the arrow can never overflow the bubble. Set it to half the bubble width to centre the arrow.

Keywords:tooltipspeech bubble

Related tools