A generated CSS triangle has zero width and height because its visible shape is painted entirely by borders, while the element's content box remains empty.
That zero value is deliberate, not a failed size setting. The content area supplies no rectangular space, while the border areas still occupy room. Two transparent border sides form the diagonal edges, and one opaque colored side supplies the visible face. The triangle consequently lives in the border box rather than in a normally sized content box.

The content box versus the painted triangle
The border-triangle technique starts with an element whose content width and content height are both zero. There is no content-sized rectangle for text or normal content flow. The border area remains the place where the shape is rendered, which is why a browser's content-box measurement can show zero even though a colored triangle is plainly visible.
The generator applies this technique to a plain div without SVG, canvas, an image file, or a pseudo-element library. Transparent borders still reserve geometric space even when no color is visible, and the colored border occupies the rest of the painted area. Treat the dimensions selected in a generator as the triangle's visible dimensions, not as CSS width and height values to paste onto the div.
MDN's CSS backgrounds and borders guide explains the border properties and transparent-color behavior behind this technique, while the CSS Backgrounds and Borders Level 3 specification defines the longhand widths, styles, and colors used to form it.
Border direction and visible dimensions
The selected direction determines which border is opaque and which two are transparent. The transparent borders meet the colored border along diagonal junctions, creating the triangle's sloping edges.
| Direction | Colored border | Transparent borders | Dimension mapping |
|---|---|---|---|
| Up | border-bottom | border-left and border-right | The colored border supplies the visible height; the two side borders split the visible width. |
| Down | border-top | border-left and border-right | The colored border supplies the visible height; the two side borders split the visible width. |
| Left | border-right | border-top and border-bottom | The colored border supplies the visible width; the top and bottom borders split the visible height. |
| Right | border-left | border-top and border-bottom | The colored border supplies the visible width; the top and bottom borders split the visible height. |
An upward triangle uses transparent left and right borders with a colored bottom border. A downward triangle reverses the top and bottom borders. A left-facing triangle uses a colored right border, while a right-facing triangle uses a colored left border. The generator writes each border longhand explicitly, so the geometry remains visible and auditable in the copied CSS.
The mapping also explains why the same width and height controls produce different border widths in different directions. For up and down triangles, the two side borders add up to the visible width and the colored border equals the visible height. For left and right triangles, the top and bottom borders add up to the visible height and the colored border equals the visible width.
Even dimensions are divided equally between the two transparent borders. Odd dimensions use a floor value and the next whole-pixel value to preserve the requested painted total. For a 41px vertical base, the formula is painted width = transparent-left width + transparent-right width. Substituting the split gives 20px + 21px = 41px, retaining the requested width instead of using two fractional 20.5px borders that Chromium could quantize down to 20px each. Rasterization can still vary with zoom level and device pixel ratio.
Generate and inspect a CSS triangle
- Open the CSS Triangle Generator. Choose up, down, left, or right, enter whole-number visible width and height values from 10 through 300 pixels, and supply a color as a hash followed by exactly six hexadecimal digits. A valid color is normalized to lowercase.
- Inspect the live result at roughly the size and on the background where it will be used. The preview uses the same derived border declarations as the CSS output, making it useful for checking direction, color, and geometry. It does not validate the complete layout or accessibility behavior of the destination component.
- Use Copy CSS and Copy HTML. Each clipboard request asks for permission separately, and a successful status identifies the format copied. If browser policy blocks clipboard access, both code blocks stay visible for manual selection and the page does not report a false success.
- Paste the CSS and HTML together. The HTML contains one div with the generated class and aria-hidden="true". If lizely-triangle conflicts with an existing stylesheet, rename it in both outputs together so the selector and class stay synchronized.
- Preserve the hidden decorative treatment only when the triangle conveys no information. If it indicates state, direction, validation, navigation, or another meaning, keep the shape hidden from assistive technology but add visible text or an accessible label to the surrounding semantic control.
- Test the final component at 200 percent zoom, in high-contrast and forced-colors modes, and at common mobile widths. For a triangle beside text, check both light and dark themes instead of assuming the literal border color provides sufficient contrast.
The browser controls constrain ordinary input, and the generator independently rejects unsupported directions, malformed colors, decimal dimensions, and values outside the accepted range. It does not quietly clamp invalid input or return partial code.
Generation and copying happen entirely in the current browser tab. There is no upload, account, server rendering, or saved design state, and the copied snippet contains no script, event handler, inline image, remote request, or dependency.
Why a zero content box can affect layout
Although the content box is zero, the painted borders occupy space. That distinction can make alignment, transforms, hit testing, outlines, overflow, and general layout less intuitive than an SVG with an explicit viewBox. The generator preview confirms border geometry, but it cannot confirm how the triangle behaves inside the final component.
Do not add width or height to the div to make it appear larger; that expands the content box and can distort the border shape. If the triangle disappears, check that the relevant border widths are nonzero, the border styles are solid, and a later stylesheet rule has not overridden the generated longhands. If the preview is correct but the integrated result is not, review what can go wrong when you generate a CSS triangle.
Accessibility belongs to the surrounding component
The generated aria-hidden attribute is appropriate for a decorative arrow or separator that communicates no information. It keeps the shape out of the accessibility tree, but it does not make an unlabeled control understandable. A triangle that communicates meaning must not be the only carrier of that meaning.
For meaningful uses, give the surrounding button, link, menu item, or other semantic control visible text or an accessible label, and retain aria-hidden on the decorative triangle. Prefer one semantic control with one decorative shape over duplicating hidden elements to simulate a control.
The preview's geometry does not establish accessibility. Verify the complete component, its focus behavior, its accessible name, and its contrast in the environments where users will encounter it.
Know where the border technique stops
This generator creates a simple, solid, straight-edged triangle. It cannot directly create a rounded tip, curved edge, hollow shape, gradient fill, stroke, complex shadow, or arbitrary polygon. Use SVG or clip-path for those forms, then test browser support in the intended environment.
The chosen HEX color becomes an opaque border. The focused generator does not produce alpha colors, CSS variables, gradients, currentColor, wide-gamut syntax, or theme tokens. After copying, replacing the literal with a trusted design token can improve theming, provided the target syntax is supported and the transparent side borders remain transparent.
One triangle has negligible performance cost, but hundreds of decorative elements can add DOM and paint work. The method remains dependency-free and compact, so it remains useful when its straight edges and simple color meet the design requirement.
If you're weighing options, HTML and CSS Color Names Chart: Same HEX, Different Names covers this in detail.