div {
    max-width: 200px;
    border: 2px solid red;

    /* Required CSS to limit text to specified lines 
       and display an ellipsis (...) */
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    -webkit-line-clamp: 3; /* Number of lines to display */
}
<div>
    The -webkit-line-clamp property restricts a text block to a specified number of lines. 
    This property functions when the display property of the element is set to -webkit-box 
    and the -webkit-box-orient property is set to vertical. 
    If the text exceeds the specified number of lines, an ellipsis (...) is displayed. 
    When the overflow property of the element is set to a value other than visible, 
    the text is truncated to the specified number of lines;
    otherwise, the text continues to be displayed even after the ellipsis appears.
</div>
Rendered Output
clamp
Clamp tool image – Image generated by Google AI
<style>
    p {
        max-width: 400px;
        border: 2px solid red;
    }
</style>
<div>
    <h2>Demo - 1</h2>
    <style>
        .demo-1 {
            -webkit-line-clamp: 2;
        }
    </style>
    <p class="demo-1">
        The -webkit-line-clamp property restricts a text block to a specified number of lines. 
        This property functions when the display property of the element is set to -webkit-box 
        and the -webkit-box-orient property is set to vertical. 
        If the text exceeds the specified number of lines, an ellipsis (...) is displayed. 
        When the overflow property of the element is set to a value other than visible, 
        the text is truncated to the specified number of lines;
        otherwise, the text continues to be displayed even after the ellipsis appears.
    </p>
</div>
<div>
    <h2>Demo - 2</h2>
    <style>
        .demo-2 {
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
            overflow: auto;
        }
    </style>
    <p class="demo-2">
        The -webkit-line-clamp property restricts a text block to a specified number of lines. 
        This property functions when the display property of the element is set to -webkit-box 
        and the -webkit-box-orient property is set to vertical. 
        If the text exceeds the specified number of lines, an ellipsis (...) is displayed. 
        When the overflow property of the element is set to a value other than visible, 
        the text is truncated to the specified number of lines;
        otherwise, the text continues to be displayed even after the ellipsis appears.
    </p>
</div>
<div>
    <h2>Demo - 3</h2>
    <style>
        .demo-3 {
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 3;
            overflow: hidden;
        }
    </style>
    <p class="demo-3">
        The -webkit-line-clamp property restricts a text block to a specified number of lines. 
        This property functions when the display property of the element is set to -webkit-box 
        and the -webkit-box-orient property is set to vertical. 
        If the text exceeds the specified number of lines, an ellipsis (...) is displayed. 
        When the overflow property of the element is set to a value other than visible, 
        the text is truncated to the specified number of lines;
        otherwise, the text continues to be displayed even after the ellipsis appears.
    </p>
</div>
<div>
    <h2>Demo - 4</h2>
    <style>
        .demo-4 {
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 3;
            overflow: visible;
        }
    </style>
    <p class="demo-4">
        The -webkit-line-clamp property restricts a text block to a specified number of lines. 
        This property functions when the display property of the element is set to -webkit-box 
        and the -webkit-box-orient property is set to vertical. 
        If the text exceeds the specified number of lines, an ellipsis (...) is displayed. 
        When the overflow property of the element is set to a value other than visible, 
        the text is truncated to the specified number of lines;
        otherwise, the text continues to be displayed even after the ellipsis appears.
    </p>
</div>
Rendered Output
selector {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: /* value */;
}
/* Initial value – Check browser compatibility */
-webkit-line-clamp: none;

/* Positive integers (greater than 0) */
-webkit-line-clamp: 2;
-webkit-line-clamp: 5;

/* Global values */
-webkit-line-clamp: inherit;
-webkit-line-clamp: initial;
-webkit-line-clamp: revert;
-webkit-line-clamp: revert-layer;
-webkit-line-clamp: unset;
p {
    max-width: 400px;
    border: 2px solid red;
    overflow: visible;
    -webkit-line-clamp: 2;
    /* display: -webkit-box and 
       -webkit-box-orient: vertical are not applied here. */
}
<p>
    The -webkit-line-clamp property restricts a text block to a specified number of lines. 
    This property functions when the display property of the element is set to -webkit-box 
    and the -webkit-box-orient property is set to vertical. 
    If the text exceeds the specified number of lines, an ellipsis (...) is displayed. 
    When the overflow property of the element is set to a value other than visible, 
    the text is truncated to the specified number of lines;
    otherwise, the text continues to be displayed even after the ellipsis appears.
</p>
Rendered Output
p {
    max-width: 400px;
    border: 2px solid red;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    
    /* The text continues to be displayed 
       even after the ellipsis (...) appears. */
    overflow: visible;
}
<p>
    The -webkit-line-clamp property restricts a text block to a specified number of lines. 
    This property functions when the display property of the element is set to -webkit-box 
    and the -webkit-box-orient property is set to vertical. 
    If the text exceeds the specified number of lines, an ellipsis (...) is displayed. 
    When the overflow property of the element is set to a value other than visible, 
    the text is truncated to the specified number of lines;
    otherwise, the text continues to be displayed even after the ellipsis appears.
</p>
Rendered Output

Last updated: