InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

CSS properties

  • CSS3 flexbox
  • all
  • animation
  • background-color
  • background-image
  • border
  • border-color
  • border-radius
  • border-style
  • border-width
  • bottom
  • box-shadow
  • box-sizing
  • calc function
  • clip
  • color
  • color value currentColor
  • color values
  • cursor
  • float
  • font
  • font-family
  • font-size
  • font-style
  • font-variant
  • font-weight
  • generated content
  • left
  • letter-spacing
  • line-height
  • list-style
  • list-style-image
  • list-style-position
  • list-style-type
  • margin
  • max-height
  • max-width
  • min-height
  • min-width
  • opacity
  • outline
  • outline-color
  • outline-style
  • outline-width
  • overflow
  • padding
  • pointer-events
  • position
  • resize
  • right
  • text-align
  • text-decoration
  • text-indent
  • text-overflow
  • text-shadow
  • text-transform
  • top
  • transform
  • transition
  • transition-delay
  • transition-duration
  • transition-property
  • transition-timing-function
  • visibility
  • white-space
  • word-break
  • word-spacing
  • word-wrap/overflow-wrap
  • z-index
 
  • Home
  • > Tutorials
  • > CSS
  • > CSS properties

CSS overflow – visible, hidden and scroll for overflowing content

on Feb 22, 2016

CSS overflow property decides how to display content if it goes beyond the boundaries of a block (e.g. when inside div).

CSS property overflow

CSS version: CSS 2.1
Value: visible | hidden | scroll | auto | inherit
Initial: visible
Applies to: block containers
Inherited: no
Note that overflow applies to both x and y axis. One can also use overflow-x and overflow-y separately. These behave similarly.

overflow values

visibleDefault. content is visible.
hiddenContent is hidden/clipped.
scrollContent is clipped but scrollable. Scroll bar appears even when not clipped. Note that on Mac depending upon General show scroll settings (if auto), this appears similar to scroll:auto
autoscrollable whenever content is clipped. When not clipped, scroll bar would not appear.
inheritinherit from parent

Example – overflow:visible

Here content text from first div is overflowing outside div and is visible. Note that overflow:visible is default value so it is not added to style.

<style type="text/css">
.box1 {
  width: 100px;
  height: 40px;
  background-color:lightgreen;
}
.box2 {
  width: 100px; height:100px;
  background-color:lightgray;
}
</style>

<div class="box1">
This is some text which can oveflow and overlap with other elements.
</div>
<div class="box2">
</div>
refresh done
try it online

Example – overflow:hidden

Here overflowing content text from div is hidden/clipped.

<style type="text/css">
.box1 {
  width: 100px;
  height: 60px;
  background-color:lightgreen;
  overflow:hidden;
}
</style>

<div class="box1">
hidden example - this is some text which will get clipped.
</div>
refresh done
try it online

Example – overflow:scroll

Here overflowing content text from div is hidden/clipped and is scrollable.

<style type="text/css">
.box1 {
  background-color:lightgreen;
  width: 200px; height: 50px;
  overflow:scroll;
}
.box2 {
  background-color:lightgreen;
  width: 300px; height: 60px;
  overflow:scroll;
}
</style>

<div class="box1">
scroll - this is some text which will get clipped and scroll will appear.
</div>
<br/>
<div class="box2">
scroll - this is some text which will not get clipped but scroll will still appear.
</div>
refresh done
try it online

Example – overflow:auto

Here overflowing content text from div is hidden/clipped and is scrollable when text get clipped. Note that as per CSS overflow spec this behaviour is browser dependent.

<style type="text/css">
.box1 {
  background-color:lightgreen;
  width: 200px; height: 50px;
  overflow:auto;
}
.box2 {
  background-color:lightgreen;
  width: 300px; height: 60px;
  overflow:auto;
}
</style>

<div class="box1">
auto - this is some text which will get clipped and scroll will appear.
</div>
<br/>
<div class="box2">
auto - this is some text which will not get clipped but scroll will also not appear.
</div>
refresh done
try it online

Related

  • CSS white-space - collaping and wrapping of whitespaces and newlines
  • CSS text-overflow - truncate text with three dots
  • HTML pre tag tutorial
  • CSS clip

Specification

  • W3C CSS 2.1 overflow specification

Suggested posts:

  1. CSS border-color – define color of four borders
  2. CSS – drop cap effect
  3. CSS resize – make block element resizable by user
  4. CSS text-overflow – truncate text with three dots
  5. CSS – align multiple divs horizontally
  6. CSS selector specificity
  7. Vim (vi) – multiline search replace with confirmation
  8. CSS clip
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged CSS, CSS properties, Tutorials
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress