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:
- It returns the overflowY property.
object.style.overflowY
- It is used to set the overflowY property.
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:
- scroll: The content is clipped to fit the element box and a scrollbar is provided help scroll the extra overflowed content. The scrollbar here is added even if the content is not clipped.
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><h1style="color: green">GeeksforGeeks</h1><b>DOM Style overflowY Property</b><p>The overflowY property specifies thebehavior of content when it overflowsa block-level element’s top andbottom edges.</p><divclass="content">GeeksforGeeks is a computer science portalwith a huge variety of well written andexplained computer science and programmingarticles, quizzes and interview questions.<br>The portal also has dedicated GATEpreparation and competitive programmingsections.</div><buttononclick="myGeeks()">Change overflowY</button><!-- script to create overflowY --><script>function myGeeks() {elem = document.querySelector('.content');elem.style.overflowY = 'scroll';}</script></body></html>Output:
Before click on the button:
After click on the button:
- hidden: The content is clipped and hidden to fit the element. No scrollbars are provided when using this value.
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><h1style="color: green">GeeksforGeeks</h1><b>DOM Style overflowY Property</b><p>The overflowY property specifies thebehavior of content when it overflowsa block-level element’s top andbottom edges.</p><divclass="content">GeeksforGeeks is a computer science portalwith a huge variety of well written andexplained computer science and programmingarticles, quizzes and interview questions.<br>The portal also has dedicated GATEpreparation and competitive programmingsections.</div><buttononclick="myGeeks()">Change overflowY</button><!-- script to create overflowY --><script>function myGeeks() {elem = document.querySelector('.content');elem.style.overflowY = 'hidden';}</script></body></html>Output:
Before click on the button:
After click on the button:
- visible: The content is not clipped and may overflow out to the top or bottom of the containing element.
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><h1style="color: green">GeeksforGeeks</h1><b>DOM Style overflowY Property</b><p>The overflowY property specifies thebehavior of content when it overflowsa block-level element’s top and bottomedges.</p><divclass="content">GeeksforGeeks is a computer scienceportal with a huge variety of wellwritten and explained computer scienceand programming articles, quizzes andinterview questions. <br>The portalalso has dedicated GATE preparationand competitive programming sections.</div><buttononclick="myGeeks()">Change overflowY</button><!-- script to use oveflowY property --><script>function myGeeks() {elem = document.querySelector('.content');elem.style.overflowY = 'visible';}</script></body></html>Output:
Before click on the button:
After click on the button:
- auto: The behavior of auto depends on the content and scrollbars are added only when the content overflows.
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><h1style="color: green">GeeksforGeeks</h1><b>DOM Style overflowY Property</b><p>The overflowY property specifies thebehavior of content when it overflowsa block-level element’s top and bottomedges.</p><divclass="content">GeeksforGeeks is a computer scienceportal with a huge variety of wellwritten and explained computer scienceand programming articles, quizzes andinterview questions. <br>The portalalso has dedicated GATE preparationand competitive programming sections.</div><buttononclick="myGeeks()">Change overflowY</button><!-- script to use oveflowY property --><script>function myGeeks() {elem = document.querySelector('.content');elem.style.overflowY = 'auto';}</script></body></html>Output:
Before click on the button:
After click on the button:
- initial: It sets the style overflowY property to its default value.
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><h1style="color: green">GeeksforGeeks</h1><b>DOM Style overflowY Property</b><p>The overflowY property specifies thebehavior of content when it overflowsa block-level element’s top and bottomedges.</p><divclass="content">GeeksforGeeks is a computer scienceportal with a huge variety of wellwritten and explained computer scienceand programming articles, quizzes andinterview questions. <br>The portalalso has dedicated GATE preparationand competitive programming sections.</div><buttononclick="myGeeks()">Change overflowY</button><!-- script to use oveflowY property --><script>function myGeeks() {elem = document.querySelector('.content');elem.style.overflowY = 'initial';}</script></body></html>Output:
Before click on the button:
After click on the button:
- inherit: This inherits the property from its parent.
Example:
<!DOCTYPE html><html><head><title>DOM Style overflowY Property</title><style>#parent {/* setting the parent divto 'auto' */overflow-y: auto;}.content {background-color: lightgreen;height: 150px;width: 200px;}button {margin-top: 60px;}</style></head><body><h1style="color: green;">GeeksforGeeks</h1><b>DOM Style overflowY Property</b><p>The overflowY property specifies thebehavior of content when it overflowsa block-level element’s top and bottomedges.</p><divid="parent"><divclass="content">GeeksforGeeks is a computer scienceportal with a huge variety of wellwritten and explained computer scienceand programming articles, quizzes andinterview questions. <br>The portalalso has dedicated GATE preparation andcompetitive programming sections.</div></div><buttononclick="myGeeks()">Change overflowY</button><!-- script to set style overflowY property --><script>function myGeeks() {elem = document.querySelector('.content');elem.style.overflowY = 'inherit';}</script></body></html>Output:
Before click on the button:
After click on the button:
Supported Browsers: The browser supported by DOM style overflowY property are listed below:
- Chrome
- Internet Explorer
- Firefox
- Safari
- Opera


