How to Truncate Text with Framer Code Override

Nov 3, 2024

Truncate text with framer
Truncate text with framer

In this tutorial, you'll learn how to use the truncate text Framer code override.

Currently, Framer doesn't have a native way to truncate text. You can track the progress of this feature by following the feature request.

How the Truncate Text Code Override Works

The code override automatically adds CSS styles to limit the number of lines in the text. It uses the webkit-line-clamp CSS property along with the text-overflow property set to ellipsis.

How to Use the Truncate Text Code Override

To use code override in your Framer project, follow these steps:

  1. Open the remix link associated with this article to access the custom code override.

  2. In your Framer project, create a new custom code override named Text.tsx.

  3. Copy the code from the remixed project into your Text.tsx file.

  4. The code override contains a function called withTruncateText. Apply this function to any text you want to truncate.

  5. After applying the withTruncateText function to a text element, rename the text element to specify the number of lines using the following format: Lines:[value]

    • For example, to limit the number of lines to 2, rename it to "Lines:2"

  6. Preview your page to see the truncation in action.

And voilà! By following these steps, you can now truncate text in your Framer project!