×

CSS Ellipsis

The CSS ellipsis kind of is the value that mostly is used by the property: text-overflow.

Here, we will discuss the following:

What is CSS Ellipsis?
Syntax for CSS ellipsis
How to use CSS Ellipsis?
How CSS ellipsis value is used by text-overflow property?
Why text-overflow ellipsis doesn’t work?
Examples

What is CSS Ellipsis?

  • As a result of using this keyword value, an ellipsis will for the most part appear (''...\', U+2026 HORIZONTAL ELLIPSIS) to represent clipped text.
  • Therefore the most part is an ellipsis displayed inside the content area, which reduces the amount of displayed text.
  • A clipped ellipsis appears if there is not enough space to display it.
  • An area of the text specifically is clipped and is represented as \'...\'.
  • The text-overflow property specifies how users should mostly be notified when there specifically is content that is overflowing and cannot mostly be displayed.
  • The text can be clipped, displayed with an ellipsis (...), or displayed with a custom string.

Syntax for CSS ellipsis

text-overflow: clip | ellipsis | string | initial | inherit;
text-overflow: ellipsis; 

JavaScript syntax

object.style.textOverflow="ellipsis"

How to use CSS ellipsis?

  • For clipping at the transition between characters, you will need to specify text-overflow as an empty string, if that is supported in your browser: text-overflow: ‘‘;
  • As part of the context, this keyword value will show an ellipsis ('...' , U+2026 HORIZONTAL ELLIPSIS ) to indicate that the text has been clipped.

How CSS ellipsis value is used by text-overflow property?

ValueDescription
ellipsisA clipped text ellipsis ("...") should be drawn to represent it.

Why text-overflow ellipsis doesn’t work?

  • When the following conditions literally are true, text-overflow:ellipsis will work:
  • The width of an element must mostly be expressed in pixels (px) in a major way. The width in percent % (percentage) will not work. 
  • A CSS literally attribute overflow:hidden and a white-space:nowrap must be applied to the element.
  • The text-overflow: ellipsis doesn’t work if we don’t particularly follow the above two conditions.

Examples
Some codes or examples related to CSS ellipsis.

Example 1:
The following example illustrates how to use the text overflow property with its value set to ellipsis.

Code is as follows:

<!DOCTYPE html>
<html>
<head>
    <title> CSS text-overflow property using ellipsis  </title>
    <style type="text/css">
    div {
        width: 450px;
        font-size: 45px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    </style>
</head>
 
<body>
    <div> Javatpoint: A computer science portal for Javatpoint. </div>
</body>
</html>

The output of the above code is:

CSS Ellipsis

Example 2:

<!DOCTYPE html>
<html>
<head>
<style> 


div.b {
  white-space: nowrap; 
  width: 55px; 
  overflow: hidden;
  text-overflow: ellipsis; 
  border: 1px solid black;
}


</style>
</head>
<body>


<h1>The text-overflow ellipsis Property</h1>
<p>The following div contains a <br> text that will show how ellipsis works </p>
<h2>text-overflow: ellipsis:</h2>
<div class="b">How are you ?</div>
</body>
</html>

The output of the above code is:

CSS Ellipsis

Example 3

<!DOCTYPE html>
<html>
<head>
<style>
body {
  background-color: whitesmoke;
}
#myDIV {
  height:300px;
  background-color: lightcyan;
}
#myDIV2 { 
  width:210px;
  white-space: nowrap;
  overflow: hidden;
  border:2px solid;
  text-overflow: ellipsis;
}


</style>
</head>
<body>


<h1>The text-overflow ellipsis</h1>


<div id="myDIV">
<div id="myDIV2">The text overflow property, using ellipsis value is as follows.</div>
</div>


</body>
</html>

The output of the above code is:

CSS Ellipsis

Example 4

A text overflow with a hover effect (shows the whole text when hovered):

Code is follows:

<!DOCTYPE html>
<html>
<head>
<style> 
div.a {
  white-space: nowrap; 
  width: 110px; 
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid black;
}


div.a:hover {
  overflow: visible;
}
</style>
</head>
<body>


<h1>The text-overflow Property with ellipsis value</h1>


<p> To see the entire text, hover over the div below. </p>


<div class="a">This will show some long text which is not fit in box. </div>


</body>
</html>

The output of the above code is:

CSS Ellipsis

Related Topics

CSS Content Property

Content Property The content attribute produces dynamic content. It can be applied with any pseudo-element ::after and ::before. These CSS properties are entirely supported inside every browser and applied to include...

5 minutes read.

CSS calc()

CSS calc(): The CSS calc() function is a CSS function of inbuilt type, which permits us to implement calculations. It is used for calculating the angle, integer frequency, number, time,...

3 minutes read.

CSS Animation

CSS Animation: The animation property of CSS is applied to make animation over any webpage. It is used as the animation replacement made by JavaScript and Flash. Rules of CSS3 @keyframes The...

3 minutes read.

CSS Lists

CSS Lists: Several properties are available in CSS that are used to manage the lists. Lists are distributed as ordered and unordered kind of lists. The ordered lists provide the...

7 minutes read.

CSS translate() Function

Translate() CSS function This function in CSS is a CSS in-built function. It relocates the element in the horizontal direction or in the vertical direction. It can move the items from...

2 minutes read.

How to use google fonts in CSS

Fonts: - Fonts are used to make our website look more beautiful. Choosing appropriate font according to the web design or layout is also important. Many typefaces are accessible in...

4 minutes read.

CSS Display

CSS Display: The CSS Display property is one of an essential property among all other properties of CSS. The display property specifies how the HTML elements should be displayed on...

4 minutes read.

CSS Ellipsis

The CSS ellipsis kind of is the value that mostly is used by the property: text-overflow. Here, we will discuss the following: What is CSS Ellipsis? Syntax for CSS ellipsis How to...

3 minutes read.

CSS Math Functions

The CSS math functions permit numerical articulations. These CSS math functions can particularly be utilized in maybe unforeseen ways, for example, inside angles and shading the functions and in the...

3 minutes read.

Is CSS a programming language?

 A programming language is a set of grammatical rules and a vocabulary for commanding a machine to accomplish specified tasks. High-level languages like BASIC, C, C++, COBOL, Java, FORTRAN, Ada...

4 minutes read.

How To Use CSS

You can use CSS(Cascading Style Sheet) in four ways. These are given below: The given above CSS type, in which various technique will be used. These are different from each other and...

2 minutes read.

CSS Tutorial

CSS refers to the Cascading Style Sheet. CSS is a form of a programming language. In other words, CSS is a language of the style sheet that is utilised for...

9 minutes read.

CSS Pseudo-elements

Pseudo-elements The pseudo-classes in CSS can be represented as any keyword which is connected to the selector that represents any selected element’s unique state. On the other hand, pseudo-elements can be...

6 minutes read.

CSS Word Wrap

Word Wrap in CSS: The word-wrap property in CSS is referred to break any lengthy word and wrap towards the next or following line. It is employed for preventing overflow...

1 minute read.

CSS Text-Overflow

Introduction: The text-overflow property of CSS is used to format the text which is overflowing the boundaries of the container. This property helps user to clip the text, to display the...

5 minutes read.

CSS Align

CSS Center Align Elements CSS center align is used to create align by using block element. You should specify margin: auto;properties. The element will take up the specified width and the remaining space....

2 minutes read.

CSS Syntax

The CSS syntax contains the selector and the declaration block, which will be clearer with the following example: Selector: A CSS selector specifies the HTML tag we wish to style. A selector can be...

2 minutes read.

CSS Word-spacing

Word-spacing The work-spacing property of CSS is applied to manage the space among the words. We can decrease or increase the space among the words by the use of this property. It...

3 minutes read.

Combine Background Image with Gradient Overlay

With the help of CSS gradient, we can display smooth and straightforward transitions between two or more colours. We can add the background images by combining the gradient property with...

2 minutes read.

CSS Text-Transform Property

Text-Transform in CSS The text-transform property permits us to alter the text case. It controls the capitalization of the text. This property is employed to design the text appearance in every...

3 minutes read.