/

HTML / CSS / JavaScript Tutorial

CSS Property: overflow

[this page | pdf | back links]

The CSS (CSS2) overflow property indicates what happens when content overflows 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 is rendered outside the element’s box

 

Default Value:

visible

JavaScript syntax:

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

Inherited:

No

Animatable:

No

 

EXAMPLE:


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

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

</body>
</html>

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


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile