---
title: "Render CSS text-overflow: ellipsis in C#"
url: https://recursiveai.org/onerender/cookbook/render-css-text-overflow-ellipsis/
description: "Use OneRender to paint CSS text-overflow: ellipsis in C#. Constrain a single line, hide its overflow, and render the ellipsis to a PNG."
version: "1.6.1"
---

# Render CSS text-overflow: ellipsis in C#

**OneRender** is a free, open-source HTML and CSS rendering library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneRender.Image) · [GitHub](https://github.com/recursive-ai-oss/onerender-csharp) · [Docs](https://recursiveai.org/onerender/docs/) · [Download example (.zip)](https://recursiveai.org/onerender/cookbook/render-css-text-overflow-ellipsis/render-css-text-overflow-ellipsis.zip)

Set a width, keep the label on one line, and hide its overflow to paint an ellipsis (…).

```shell
dotnet add package RecursiveAI.OneRender.Image
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OneRender.Image;

var image = HtmlRender.ToImage("""
    <style>
      p { width: 160px; white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis }
    </style>
    <p>Quarterly budget
       reconciliation report</p>
    """, new HtmlRenderOptions
    { Width = 240, Height = 70 });
File.WriteAllBytes(
    "ellipsis.png", image.ToPng());
Console.WriteLine("Wrote ellipsis.png");
```

Paste the code above into Program.cs of a new `dotnet new console` project and `dotnet run`, or unzip [the example](https://recursiveai.org/onerender/cookbook/render-css-text-overflow-ellipsis/render-css-text-overflow-ellipsis.zip) and `dotnet run`.

```text
Wrote ellipsis.png
```

![A single line reading Quarterly budget reco followed by an ellipsis.](https://recursiveai.org/onerender/images/render-css-text-overflow-ellipsis/ellipsis.png)

If the line wraps or still has room for all its text, there’s nothing at the line’s end for `text-overflow` to replace.

## Variations

**Use a custom marker.** Replace `text-overflow: ellipsis` with this declaration in the same rule:

```css
text-overflow: " [more]";
```

![A single line reading Quarterly budget followed by the custom marker [more].](https://recursiveai.org/onerender/images/render-css-text-overflow-ellipsis/custom-marker.png)

## Related recipes

- [Render HTML to PNG in C#](https://recursiveai.org/onerender/cookbook/html-to-png/)
- [Render CSS Flexbox to an image in C#](https://recursiveai.org/onerender/cookbook/render-css-flexbox-to-image/)

## The short answer

Give the text a block container with a width, set `white-space: nowrap` so a long label stays on one line, then combine `overflow: hidden` and `text-overflow: ellipsis`. Pass that HTML to `HtmlRender.ToImage` and save the PNG. The paragraph retains its full text in the source HTML; OneRender chooses what fits when it paints the line, so you don’t need to estimate a character count in C#.

## Why isn’t CSS text-overflow: ellipsis working?

Start by checking the element that owns the line. The [CSS property](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/text-overflow) affects overflowing inline content in a block container. A `span` in the middle of a paragraph isn’t a block container simply because you assign it a width. Put the rule on the surrounding paragraph or another block container that actually limits the line. With `overflow: visible`, the text is free to extend past the edge, so there’s no ellipsis. And with normal wrapping, text can move to another line instead of crossing the edge at all.

The width of the text box matters, not just the width of the final PNG. If the label is in a flex row, check whether the item is allowed to shrink; the [automatic minimum size of a flex item](https://www.w3.org/TR/css-flexbox-1/#min-size-auto) can keep the item wider than the space you intended to give it. Inspect the width on the actual block before changing the text. The example uses a fixed width so the effect doesn’t depend on the viewport width alone.

## Does text-overflow: ellipsis remove text from the rendered PDF?

In OneRender, the cut text is neither drawn nor extracted from a PDF. The markup is unchanged, but it doesn’t follow that the hidden part will be there when someone copies text out of the PDF. If the complete label matters in print, use a print layout that wraps the text or gives it enough width. OneRender reserves room for the marker and cuts at whole grapheme clusters, so characters that combine into one visible unit aren’t split at the cut. The marker is at the inline end (left for `direction: rtl`), and the two-value `text-overflow` form isn’t supported. See the [1.5.0 changelog](https://recursiveai.org/onerender/docs/changelog/) for the painting rules.
