ExampleUse of the text-overflow property: Show div { Try it Yourself » More "Try it Yourself" examples below. Definition and UsageThe Both of the following properties are required for text-overflow:
Show demo ❯
Browser SupportThe numbers in the table specify the first browser version that fully supports the property. Numbers followed by -o- specify the first version that worked with a prefix.
CSS Syntaxtext-overflow: clip|ellipsis|string|initial|inherit; Property Values
More ExamplesExampleText-overflow with a hover effect (show entire text on hover): div.a { div.a:hover { Try it Yourself » Related PagesCSS tutorial: CSS Text Effects HTML DOM reference: textOverflow property Home » CSS Using CSS, it is possible to limit the text length to N lines using CSS. This concept is known as line clamping or multiple line truncating. Here, we will learn how we can limit text length to n lines using the line-clamp property. The best solution to this problem is using the line-clamp property of CSS. The line-clamp property shortens text at a specific number of lines. It is defined as shorthand for max-lines and block-overflow. Syntax: .line { line-clamp: [none|<integer>]; } The combination of line-clamp property with overflow-hidden value helps to limit the text length. Lets us see via an example: Example: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <style> .line { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 1; /* number of lines to show */ line-clamp: 1; -webkit-box-orient: vertical; } .block{ height:40%; width:20%; background-color: #b3d4fc; } </style> <body> <div class="block"> <h2>BLOCK</h2> <p class="line">You must be the change you wish to see in the world." - Gandhi. "Live for what's worth dying for, and leverage technology to create the world you wish to see</p> </div> </body> </html> Output: As we can see the text line is limited to 1 in the example. If we want to change this limit we can directly do it by changing the following values according to our preference. -webkit-line-clamp: 5; line-clamp: 5; Output: After replacing the values in the code Note: -webkit-line-clamp, line-clamp the value which you are assigning should be the same for both. CSS Tutorial & Examples » How do I limit text lines in CSS?The easiest way to limit text to n lines is to use line-clamp . N can be any positive number, but it will be two or three lines most of the time. On my blog, I'm using line-clamp in all post-type components to ensure that it will have the same height as siblings.
How do you show a 3 line paragraph in CSS?“3 line show css” Code Answer's. body {. margin: 20px;. . text {. overflow: hidden;. text-overflow: ellipsis;. display: -webkit-box;. How do I restrict text length in HTML?You can specify a minimum length (in characters) for the entered value using the minlength attribute; similarly, use maxlength to set the maximum length of the entered value, in characters.
How do I truncate text after two lines?2) Truncate text after multiple lines using line-clamp
With line-clamp text can be truncated after multiple lines, whats even more interesting is you can truncate it by specifying the line number where you want to truncate it. eg: -webkit-line-clamp: 3; will truncate start truncating the text from the third line.
|