How do I make a table scrollable

Martin Kristiansen picture Martin Kristiansen · Sep 26, 2012 · Viewed 53.8k times · Source

Does anyone know a vanilla way of making the body of a table scrollable using only html and css?

The obvious solution

tbody {
    height: 200px;
    overflow-y: scroll;
}

does not work.

Wouldnt this be the obvious use of tables?

am I doing something wrong?

Answer

Christoph picture Christoph · Sep 26, 2012

You need to declare a height first, else your table will expand to the according with of it's content.

table{
   overflow-y:scroll;
   height:100px;
   display:block;
}

EDIT: after clarifying your problem i edited the fiddle: check out this Example or that way. It's rather hacky and not quaranteed to work crossbrowser but might work for your case.