×

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 Pagination

CSS Pagination The pagination in CSS is an advantageous approach for indexing of a website’s distinct pages over the homepage. When our site contains multiple pages, we must insert a few...

13 minutes read.

CSS Counters

CSS Counters: The CSS counter property is similar to the variables. CSS counters are controlled via CSS, and its values are incremented via rules of CSS to record how much...

4 minutes 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.

CSS Page-break-inside Attribute

Page-break-inside Attribute As its name implies, the page-break-before property is applied to include page break inside any element, at the time of printing any document. It adds the page break before...

3 minutes read.

CSS Text-decoration

CSS Text-decoration: It is an essential property of CSS that is used to decorate the content of the text. It can add-on the lines above, under, and over the text....

3 minutes read.

CSS Zoom

CSS Zoom: Zoom property in CSS extents the content. This property controls the content’s level of magnification. Rather than the use of this CSS property, we may also apply the...

3 minutes 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.

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 :root selector

CSS :root selector This CSS pseudo-class matches any document’s root element. It chooses the parent of the highest-level inside the document DOM or tree. An element of <html> is always a...

2 minutes read.

CSS Background

CSS Background The properties of CSS background are applied to describe the effects of background on the element. Here are five properties of background that affects various elements of HTML: Background-colorBackground-imageBackground-repeatBackground-attachment Background-position Background-color The color of the background...

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

How to get rid/remove of bullet pioints in CSS

We include a list of items on the web pages that were sometimes numbered and sometimes bulleted in various styles. In HTML, there are two kinds of lists: ordered and unordered...

3 minutes read.

CSS Masking

CSS Masking The CSS mask property is applied to hide a component with the use of the masking or clipping an image at any specific point. The masking depicts the use...

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

Difference between CSS Grid and CSS Flexbox

The way that information is arranged on a website reveals a lot about you or your company. Organizational abilities are just as important as having the right materials. The design...

3 minutes read.

How to change font size in CSS

How to change font size in CSS? Font Size: - Users may attract attention to content on a website page in various ways. One element in a sentence can be highlighted. You...

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

CSS Border: The border property of CSS allows us to define the style, color, width, and radius of the element’s border. It is applied to various elements to set-up the...

4 minutes read.