
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML table with 100% width, with vertical scroll inside tbody
We will set the vertical scroll using the overflow-y property −
overflow-y: auto;
We will hide the horizontal scroll using the overflow-x property −
overflow-x: hidden;
Example
Let us see an example −
<!DOCTYPE html> <html> <head> <title> Display table with vertical scrollbar </title> <style> table.scrolldown { width: 100%; border-spacing: 0; border: 1px solid black; } table.scrolldown tbody, table.scrolldown thead { display: block; } thead tr th { height: 60px; line-height: 60px; background: red; color: white; } table.scrolldown tbody { height: 120px; overflow-y: auto; overflow-x: hidden; } tbody { border-top: 2px solid black; background: orange; } tbody td, thead th { width : 200px; border-right: 1px solid black; } td { text-align:center; } </style> </head> <body> <h1>Rankings</h1> <p>(Vertical Scroll in a Table)</p> <table class="scrolldown"> <thead> <tr> <th>Player</th> <th>Country</th> <th>Rank</th> <th>Points</th> </tr> </thead> <tbody> <tr> <td>Virat</td> <td>IND</td> <td>1</td> <td>90</td> </tr> <tr> <td>David</td> <td>AUS</td> <td>2</td> <td>80</td> </tr> <tr> <td>Steve</td> <td>AUS</td> <td>3</td> <td>70</td> </tr> <tr> <td>Rohit</td> <td>IND</td> <td>4</td> <td>60</td> </tr> <tr> <td>Ben</td> <td>ENG</td> <td>5</td> <td>55</td> </tr> <tr> <td>Rashid</td> <td>AFG</td> <td>6</td> <td>50</td> </tr> <tr> <td>Pollard</td> <td>WI</td> <td>7</td> <td>40</td> </tr> </tbody> </table> </body> </html>
Output

- Related Articles
- Flexbox and vertical scroll in a full-height app using newer Flexbox API with HTML
- HTML Tables with Fixed Header on Scroll in CSS
- Set width between table cells with CSS
- How to set table width in HTML?
- How to use an HTML tag inside HTML table?
- Bootstrap 3 truncate long text inside rows of a table in a responsive way with HTML
- Disabling Scroll Anchoring with CSS
- Drawing lines with continuously varying line width on HTML canvas
- How to display vertical grid lines in a table with Java?
- Bootstrap complex form layout for combined vertical/inline fields with HTML
- With JavaScript how to change the width of a table border?
- Scroll Element into View with Selenium.
- How to enable vertical scroll bar for android webview?
- Vertical Buttongroup with Bootstrap
- Set scroll view with intervals in JavaScript

Advertisements