/

HTML / CSS / JavaScript Tutorial

CSS Property: overflow-y

[this page | pdf | back links]

The CSS (CSS2) overflow-y property indicates what to with top/bottom edges of content overflowing an element’s box.

 

Valid property values (other than inherit and initial) are:

 

Value

Description

auto

Overflow is clipped and a scroll-bar should typically be added

hidden

Overflow is clipped. No scroll-bar is added, so rest of content is effectively invisible

scroll

Overflow is clipped and a scroll-bar is added

visible

(default value). Overflow is not clipped and may be rendered outside the element’s box

 

Default Value:

visible

JavaScript syntax:

e.g. object.style.overflowY="scroll"

Inherited:

No

Animatable:

No

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
div {width: 80px; height: 20px; border: 2px solid red;}
.x1 {overflow-y: scroll}
</style>
</head>
<body>
1. Element with default property<br>
<div>abcdefgh abcdefgh abcdefgh</div><br><br>
2. Element set using in-file HTML style<br>
<div class="x1">abcdefgh abcdefgh abcdefgh</div><br><br>
3. Element set using JavaScript<br>
<div id="x2">abcdefgh abcdefgh abcdefgh</div>

<script>
document.getElementById("x2").style.overflowY = "scroll";
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyOverflowY() {
  var x = document.createElement("DIV"); x.style.overflowY = "scroll"; return (window.getComputedStyle(x, null).overflowY == "scroll");
}


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile