Open In App

HTML | DOM Style overflowX Property

The Style overflowX property in HTML DOM is used to specify the behavior of the content when it overflows an element’s left and right edges. The content may be hidden, shown or a scrollbar according to the value. 

Syntax:



object.style.overflowX
object.style.overflowX = "hidden|visible|scroll|auto|initial|
inherit"

Return Values: It returns a string value, which represents the overflow-x property of an element

Property Values:



Example: 




<!DOCTYPE html>
<html>
     
<head>
    <title>
        DOM Style overflowX Property
    </title>
     
    <style>
        .content {
            background-color: lightgreen;
            height: 150px;
            width: 200px;
            white-space: nowrap;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
     
    <b>DOM Style overflowX Property</b>
     
    <p>
        The overflowX property specifies the behavior of
        content when it overflows a block-level element’s
        left and right edges.
    </p>
     
    <div class="content">
        GeeksforGeeks is a computer science portal with a
        huge variety of well written and<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 overflowX
    </button>
     
    <!-- Script to set overflowX to hidden -->
    <script>
        function setOverflow() {
            elem = document.querySelector('.content');
            elem.style.overflowX = 'hidden';
        }
    </script>
</body>
 
</html>                   

 

Example: 




<!DOCTYPE html>
<html>
     
<head>
    <title>
        DOM Style overflowX Property
    </title>
     
    <style>
        .content {
            background-color: lightgreen;
            height: 150px;
            width: 200px;
            white-space: nowrap;
            overflow-x: hidden;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
     
    <b>DOM Style overflowX Property</b>
     
    <p>
        The overflowX property specifies the behavior of
        content when it overflows a block-level element’s
        left and right edges.
    </p>
     
    <div class="content">
        GeeksforGeeks is a computer science portal with a
        huge variety of well written and<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 overflowX
    </button>
     
    <!-- Script to set overflowX to visible -->
    <script>
        function setOverflow() {
            elem = document.querySelector('.content');
            elem.style.overflowX = 'visible';
        }
    </script>
</body>
 
</html>                   

 

 

Example: 




<!DOCTYPE html>
<html>
     
<head>
    <title>
        DOM Style overflowX Property
    </title>
     
    <style>
        .content {
            background-color: lightgreen;
            height: 150px;
            width: 200px;
            white-space: nowrap;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
     
    <b>DOM Style overflowX Property</b>
     
    <p>
        The overflowX property specifies the behavior of
        content when it overflows a block-level element’s
        left and right edges.
    </p>
     
    <div class="content">
        GeeksforGeeks is a computer science portal with a
        huge variety of well written and<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 overflowX
    </button>
     
    <!-- Script to set overflowX to scroll -->   
    <script>
        function setOverflow() {
            elem = document.querySelector('.content');
            elem.style.overflowX = 'scroll';
        }
    </script>
</body>
</html>                   

 

 

Example: 




<!DOCTYPE html>
<html>
     
<head>
    <title>
        DOM Style overflowX Property
    </title>
     
    <style>
        .content {
            background-color: lightgreen;
            height: 150px;
            width: 200px;
            white-space: nowrap;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
     
    <b>DOM Style overflowX Property</b>
     
    <p>
        The overflowX property specifies the behavior of
        content when it overflows a block-level element’s
        left and right edges.
    </p>
     
    <div class="content">
        GeeksforGeeks is a computer science portal with a
        huge variety of well written and<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 overflowX
    </button>
     
    <!-- Script to set overflowX to auto -->
    <script>
        function setOverflow() {
            elem = document.querySelector('.content');
            elem.style.overflowX = 'auto';
        }
    </script>
</body>
 
</html>                   

 

 

Example: 




<!DOCTYPE html>
<html>
     
<head>
    <title>
        DOM Style overflowX Property
    </title>
     
    <style>
        .content {
            background-color: lightgreen;
            height: 150px;
            width: 200px;
            white-space: nowrap;
 
            /* Setting the overflow-x property to 'scroll' to
            observe the effect of initial */
            overflow-x: scroll;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
     
    <b>DOM Style overflowX Property</b>
     
    <p>
        The overflowX property specifies the behavior of
        content when it overflows a block-level element’s
        left and right edges.
    </p>
     
    <div class="content">
        GeeksforGeeks is a computer science portal with a
        huge variety of well written and<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 overflowX
    </button>
     
    <!-- Script to set overflowX to initial -->
    <script>
        function setOverflow() {
            elem = document.querySelector('.content');
            elem.style.overflowX = 'initial';
        }
    </script>
</body>
</html>                   

 

 

Example: 




<!DOCTYPE html>
<html>
     
<head>
    <title>
        DOM Style overflowX Property
    </title>
     
    <style>
        #parent {
             
            /* Setting the overflow-x property
            of the parent */
            overflow-x: hidden;
        }
        .content {
            background-color: lightgreen;
            height: 150px;
            width: 200px;
            white-space: nowrap;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
     
    <b>DOM Style overflowX Property</b>
     
    <p>
        The overflowX property specifies the behavior of
        content when it overflows a block-level element’s
        left and right edges.
    </p>
     
    <div id="parent">
        <div class="content">
            GeeksforGeeks is a computer science portal
            with a huge variety of well written and <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 overflowX
    </button>
     
    <!-- Script to use overflowX to inherit -->
    <script>
        function setOverflow() {
            elem = document.querySelector('.content');
            elem.style.overflowX = 'inherit';
        }
    </script>
</body>
 
</html>                   

 

 

Supported Browsers:


Article Tags :