Open In App

HTML | DOM Style textOverflow Property

The Style textOverflow property in HTML DOM is used to specify the behavior of the text when it overflows the containing element box. 

Syntax:



object.style.textOverflow
object.style.textOverflow = "clip|ellipsis|initial|inherit"

Return Values: It returns a string value, which representing the text-overflow property of an element.

Property Values:



Example: 




<!DOCTYPE html>
<html>
     
<head>
    <title>
        DOM Style textOverflow Property
    </title>
     
    <style>
        .content {
            background-color: lightgreen;
            height: 100px;
            width: 300px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
    <b>DOM Style textOverflow Property</b>
    <p>
        The textOverflow property specifies how text
        should be displayed when it overflows the
        container element.
    </p>
    <div class="content">
        GeeksforGeeks is a computer science portal with
        a huge variety of well written <br>explained
        computer science and programming articles,
        quizzes and interview questions. <br>The portal
        also has dedicated GATE preparation and
        competitive programming sections.
    </div>
    <button onclick="setOverflow()">
        Change textOverflow
    </button>
 
    <!-- Script to set textOverflow to clip -->
    <script>
        function setOverflow() {
            elem = document.querySelector('.content');
            elem.style.textOverflow = 'clip';
        }
    </script>
</body>
 
</html>

Output: 

Before clicking the button:

  

After clicking the button:

 

Example: 




<!DOCTYPE html>
<html>
     
<head>
    <title>
        DOM Style textOverflow Property
    </title>
    <style>
        .content {
            background-color: lightgreen;
            height: 100px;
            width: 300px;
            white-space: nowrap;
            overflow: hidden;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
    <b>DOM Style textOverflow Property</b>
    <p>
        The textOverflow property specifies how text
        should be displayed when it overflows the
        container element.
    </p>
    <div class="content">
        GeeksforGeeks is a computer science portal with
        a huge variety of well written <br>explained
        computer science and programming articles,
        quizzes and interview questions. <br>The portal
        also has dedicated GATE preparation and
        competitive programming sections.
    </div>
    <button onclick="setOverflow()">
        Change textOverflow
    </button>
 
    <!-- Script to set textOverflow to ellipsis -->
    <script>
        function setOverflow() {
            elem = document.querySelector('.content');
            elem.style.textOverflow = 'ellipsis';
        }
    </script>
</body>
 
</html>

Output: 

Before clicking the button:

  

After clicking the button:

 

Example: 




<!DOCTYPE html>
<html>
     
<head>
    <title>
        DOM Style textOverflow Property
    </title>
    <style>
        .content {
            background-color: lightgreen;
            height: 100px;
            width: 300px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
    <b>DOM Style textOverflow Property</b>
    <p>
        The textOverflow property specifies how text
        should be displayed when it overflows the
        container element.
    </p>
    <div class="content">
        GeeksforGeeks is a computer science portal with
        a huge variety of well written <br>explained
        computer science and programming articles,
        quizzes and interview questions. <br>The portal
        also has dedicated GATE preparation and
        competitive programming sections.
    </div>
    <button onclick="setOverflow()">
        Change textOverflow
    </button>
 
    <!-- Script to set textOverflow to initial -->
    <script>
        function setOverflow() {
            elem = document.querySelector('.content');
            elem.style.textOverflow = 'initial';
        }
    </script>
</body>
 
</html>

Output: 

Before clicking the button: 

 

After clicking the button:

 

Example: 




<!DOCTYPE html>
<html>
     
<head>
    <title>
        DOM Style textOverflow Property
    </title>
    <style>
        #parent {
            text-overflow: ellipsis;
        }
        .content {
            background-color: lightgreen;
            height: 100px;
            width: 300px;
            white-space: nowrap;
            overflow: hidden;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
    <b>DOM Style textOverflow Property</b>
    <p>
        The textOverflow property specifies how text
        should be displayed when it overflows the
        container element.
    </p>
    <div id="parent">
        <div class="content">
            GeeksforGeeks is a computer science portal with
            a huge variety of well written <br>explained
            computer science and programming articles,
            quizzes and interview questions. <br>The portal
            also has dedicated GATE preparation and
            competitive programming sections.
        </div>
    </div>
    <button onclick="setOverflow()">
        Change textOverflow
    </button>
 
    <!-- Script to set textOverflow to inherit -->
    <script>
        function setOverflow() {
            elem = document.querySelector('.content');
            elem.style.textOverflow = 'inherit';
        }
    </script>
</body>
 
</html>

Output: 

Before clicking the button:

  

After clicking the button:

 

Supported Browsers: The browser supported by textOverflow property are listed below:


Article Tags :