HTML Tables with CSS Styles
I've put together some common CSS tables styles so that you can quickly copy/paste the code for yourselves. You can modify the styles as you see fit.
They're 5 pretty basic css tables styles that are commonly used by web developers so I made this little mini-resource for quick copy and pasting styles.
I now also have a HTML table generator if you want to very quickly create a custom table and the required HTML and CSS code for it.
Hope this comes in handy.
Five Basic CSS Table Styles (Two Using Javascript)
Here is the code for a:
- Basic CSS styled table
- CSS table style with background images
- HTML table styled using CSS gradients
- Table with alternating row colors
- CSS table with row highlight on hover
1. CSS Table with One Pixel Borders
First up is the collapsed border table that has the solid line borders making this the basis for most popular table styles.
The code includes the CSS which you can add to your stylesheet and please note a class has been added to the table tag.
Info Header 1 | Info Header 2 | Info Header 3 |
---|---|---|
Text 1A | Text 1B | Text 1C |
Text 2A | Text 2B | Text 2C |
Copy/Paste Code for CSS Table with One Pixel Borders
2. CSS Table with Background Images
This image approach is a little old school but it may still come in handy once in a while. If you're looking for a more modern approach, then check out the CSS Table Gradient example below.
This table is similar to the one above except it uses background images which allows the table cells to have a subtle color gradation in them. The images also have a one pixel white line on the left and top which gives the cells a slight 3D effect.
You'll probably have to make two small changes to the CSS to reflect where the table images live on your server other than that it's fairly straightforward.
Info Header 1 | Info Header 2 | Info Header 3 |
---|---|---|
Text 1A | Text 1B | Text 1C |
Text 2A | Text 2B | Text 2C |
Step 1. Download a zip of the table images (code included) or right click and save these two images to your desktop: cell-blue.jpg and cell-grey.jpg
Step 2. Copy the code in the box below. Remember to change the css image location. The table tag requires a class.
3. HTML Table using CSS Gradients
This one is a more modern version of the image one - it uses CSS gradients to achieve the bevelled look of the image table example. It's a completely image free table rendering.
This code will display correctly across all modern browsers even Internet Explorer 9. It's not pixel perfect in Internet Explorer 7 or 8 but it's a good enough rendering and doesn't impare legibility.
Copy/Paste Code for CSS Gradient Table