×

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 Color

CSS Colors: The CSS color property is used for setting the HTML element’s color. The color of the fonts and the color of the background can be set-up by using...

5 minutes read.

CSS User Interface

Introduction User Interface can be defined as series of visual elements like screens, buttons, forms that help the user interact with the software application or hardware device. CSS User Interface allows the...

6 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.

Difference between HTML and CSS

HTML HTML stands for HyperText Markup Language and is used to create web pages and websites and web applications, which means we can create static web pages. Html is a scripting...

3 minutes read.

How to Set Space between the Flexbox

For managing layout on the Web, CSS Flexbox and CSS Grid are two excellent tools. Flexbox handles one-dimensional layouts quite well, whereas CSS Grid manages two-dimensional layouts with columns and...

4 minutes read.

CSS Outline

CSS Outline: This CSS property is quite similar to the border property of CSS. It eases us to design an additional border around the element to obtain visual attention. The...

4 minutes read.

CSS Line Height

CSS Line Height: This property in CSS can be used to describe the line box’s minimal height inside the element. It sets-up the distinction among two lines in our content. It...

3 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 Sticky

CSS Sticky The position property in CSS is applied to set an element’s position. This property is also applied to position an element behind the other element. It is useful for...

1 minute read.

How to change the font in CSS

How to change the font in CSS? Professionals can't deny typefaces — how users organize and style text — if we want to completely customize the website's design. One may wish...

4 minutes read.

CSS Hover

CSS Hover: CSS :hover is used to select the various elements whenever we point the mouse on these elements. We can also use this selector on all the HTML elements,...

3 minutes read.

CSS Opacity

The CSS Opacity property is used to set the clarity of the image. It is defined as degree and specify the transparency of an element. Note: Opacity value will be less...

1 minute read.

What is a CSS File?

What is a CSS File and How to use it in Html? CSS: - CSS stands for Cascading Style Sheet. CSS is a file of style sheets that describe the presentation of...

4 minutes read.

CSS Arrow

CSS Arrow The arrow of CSS is applied to insert an array with the tooltip. It can make a tooltip as any speech bubble. Also, this arrow can be illustrated in...

4 minutes read.

CSS Visibility

Visibility in CSS: This visibility property in CSS is employed to describe whether the components are visible or not. Note: An invisible component also grabs the space over the page. If...

2 minutes read.

CSS Units

CSS Units In CSS, there are so many units available to show the length’s measurement. A single unit of CSS is applied to examine the size of the property, which the...

5 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.

Untitled Reusable Block

  ...

1 minute read.

CSS Text-align

Text-align The text-align property of CSS sets the table-cell box’s horizontal alignment or any block element. The text-align property is the same as the CSS property vertical-align but towards any horizontal...

1 minute read.

What is CSS

CSS stands for Cascading Style Sheet. It gives an additional style to the HTML document. A cascading style sheet is a language that is designed to define the document formatting...

3 minutes read.