Open In App

HTML | DOM Style overflowY Property

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

Syntax:



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

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

Property Values:



Example: 




<!DOCTYPE html>
<html>
     
<head>
    <title>
        DOM Style overflowY Property
    </title>
     
    <style>
        .content {
            background-color: lightgreen;
            height: 150px;
            width: 200px;
            overflow-y: hidden;
        }
 
        button {
            margin-top: 60px;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
     
    <b>DOM Style overflowY Property</b>
     
    <p>
        The overflowY property specifies the
        behavior of content when it overflows
        a block-level element’s top and
        bottom edges.
    </p>
     
    <div class = "content">
        GeeksforGeeks is a computer science portal
        with a huge variety of well written and
        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 = "myGeeks()">
        Change overflowY
    </button>
     
    <!-- script to create overflowY -->
    <script>
        function myGeeks() {
            elem = document.querySelector('.content');
            elem.style.overflowY = 'scroll';
        }
    </script>
</body>
 
</html>                   

  

After click on the button: 

Example: 




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

  

After click on the button:

 

Example: 




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

  

After click on the button:

 

Example: 




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

  

After click on the button:

 

Example: 




<!DOCTYPE html>
<html>
     
<head>
    <title>
        DOM Style overflowY Property
    </title>
     
    <style>
        .content {
            background-color: lightgreen;
            height: 150px;
            width: 200px;
            overflow-y: scroll;
        }
 
        button {
            margin-top: 60px;
        }
    </style>
</head>
 
<body>
    <h1 style = "color: green">
        GeeksforGeeks
    </h1>
     
    <b>DOM Style overflowY Property</b>
     
    <p>
        The overflowY property specifies the
        behavior of content when it overflows
        a block-level element’s top and bottom
        edges.
    </p>
     
    <div class = "content">
        GeeksforGeeks is a computer science
        portal with a huge variety of well
        written and 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 = "myGeeks()">
        Change overflowY
    </button>
     
    <!-- script to use oveflowY property -->
    <script>
        function myGeeks() {
            elem = document.querySelector('.content');
            elem.style.overflowY = 'initial';
        }
    </script>
</body>
 
</html>                   

 

After click on the button:

 

Example: 




<!DOCTYPE html>
<html>
     
<head>
    <title>
        DOM Style overflowY Property
    </title>
     
    <style>
        #parent {
             
            /* setting the parent div
            to 'auto' */
            overflow-y: auto;
        }
 
        .content {
            background-color: lightgreen;
            height: 150px;
            width: 200px;
        }
 
        button {
            margin-top: 60px;
        }
    </style>
</head>
 
<body>
    <h1 style = "color: green;">
        GeeksforGeeks
    </h1>
     
    <b>DOM Style overflowY Property</b>
     
    <p>
        The overflowY property specifies the
        behavior of content when it overflows
        a block-level element’s top and bottom
        edges.
    </p>
     
    <div id = "parent">
        <div class = "content">
            GeeksforGeeks is a computer science
            portal with a huge variety of well
            written and 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 = "myGeeks()">
        Change overflowY
    </button>
     
    <!-- script to set style overflowY property -->
    <script>
        function myGeeks() {
            elem = document.querySelector('.content');
            elem.style.overflowY = 'inherit';
        }
    </script>
</body>
 
</html>                   

  

After click on the button: 

Supported Browsers: The browser supported by DOM style overflowY property are listed below:


Article Tags :