CSS Introduction

CSS Tutorial What is CSS CSS Syntax CSS Selector How to include CSS CSS Comments

CSS Attributes

CSS Background CSS Border CSS Display CSS Float CSS Font CSS Color CSS Hover CSS Important CSS Line-height CSS Margin CSS Opacity CSS Filter CSS Images CSS Overflow CSS Padding CSS Position CSS Vertical align CSS White space CSS Width Word-wrap in CSS Box-shadow in CSS Text-transform in CSS CSS Outline CSS Visibility CSS Counters CSS Clear fix CSS Icons CSS Justify-content Text-decoration in CSS CSS Lists CSS nth selector CSS Sticky CSS Background-clip CSS Checkbox-style CSS Letter-spacing CSS Navigation bar CSS Overlay CSS Root CSS Specificity CSS Text-indent CSS Text-stroke CSS Zoom CSS Order CSS Descendent selector CSS Clip CSS calc() CSS Background-blend-mode CSS radio-button CSS Superscript and subscript CSS Text-effects CSS Text-align CSS Variables CSS Page-break-before CSS Page-break-inside CSS Page-break-after CSS Content property CSS Word-spacing CSS Animation CSS @keyframes rules CSS Pseudo-classes CSS Pseudo-elements CSS Radial-gradient CSS Translate CSS Gradients CSS z-index CSS Loaders CSS Units CSS Transition CSS Masking CSS Arrow CSS Pagination

Questions

What is Bootstrap CSS What is CSS used for How to center a table in CSS What is a CSS File How to center a button in CSS How to change background color in CSS How to change the font in CSS How to change font size in CSS How to resize an image in CSS How to get rid of bullet pioints in CSS Is CSS a programming language How to edit CSS in WordPress How to use google fonts in CSS How to create blinking text using CSS How to Set Space between the Flexbox Is CSS a Programming Language

Difference

Difference between HTML and CSS Grid Vs Flexbox in CSS Difference between CSS Grid and CSS Flexbox

Misc

Create a 3D text effect using HTML and CSS Hover condition for a:before and a:after in CSS Bem CSS Boder Types CSS Features of CSS Font Face CSS Image Overlay CSS B Tag CSS Carousel CSS CSS Arrow CSS Focus Flex Grow in CSS Bem CSS Features of CSS Font Face CSS Removing Underline from Link in CSS Width Property in CSS Radio Button in CSS

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