
- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursors
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS Advanced
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Media Types
- CSS - Paged Media
- CSS - Aural Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS3 - Rounded Corner
- CSS3 - Border Images
- CSS3 - Multi Background
- CSS3 - Color
- CSS3 - Gradients
- CSS3 - Shadow
- CSS3 - Text
- CSS3 - Web font
- CSS3 - 2d transform
- CSS3 - 3d transform
- CSS3 - Animation
- CSS3 - Multi columns
- CSS3 - User Interface
- CSS3 - Box Sizing
- CSS Responsive
- CSS - Responsive Web Design
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
Adding Borders to Tables in CSS
The CSS border property is used to define a border for an element. The syntax of CSS border property is as follows−
Syntax
Selector { border: /*value*/ }
Example
The following examples illustrate CSS border property−
<!DOCTYPE html> <html> <head> <style> table { margin: 1em; border: 3px double green; border-right-style: dashed; border-left-width: 17px; border-bottom-color: orange; } td { font-size: 24px; border-right-style: dotted; border-width: 3px; border-right-color: red; } </style> </head> <body> <table> <tr> <td>demo</td> <td>text</td> </tr> <tr> <td>goes</td> <td>here</td> </tr> </table> </body> </html>
Output
This gives the following output−
Example
<!DOCTYPE html> <html> <head> <style> table { margin: auto; caption-side: bottom; border: 2px dashed black; } td { border: 2px solid midnightblue; text-align: center; } td[colspan] { box-shadow: inset 0 0 10px lightblue; text-align: center; } caption { font-size: 16px; font-weight: bold; } </style> </head> <body> <h2<Ranking</h2> <table> <caption>Men's ODI Player Ranking</caption> <tr> <th>Player</th> <th>Rank</th> </tr> <tr> <td>Virat Kohli</td> <td>1</td> </tr> <tr> <td>Rohit Sharma</td> <td>2</td> </tr> <tr> <td>Babar Azam</td> <td>3</td> </tr> <tr> <td>Ross Taylor</td> <td>4</td> </tr> <tr> <td colspan="2">Sept2019</td> </tr> </table> </body> </html>
Output
This gives the following output−
- Related Articles
- Adding Borders to Tables using CSS
- Collapsing Table Borders in CSS
- Outlines Vs Borders in CSS
- Add borders to pagination using CSS
- Collapsing Table Borders using CSS
- How to create and style borders using CSS?
- How to eliminate blue borders around linked images using CSS?
- Styling Tables with CSS
- Create a link button with borders using CSS
- Effect of Color Property on Borders and Outlines in CSS
- Add rounded borders to first and last link in the pagination using CSS
- Styling Tables Working with CSS
- Set the color of the four borders using CSS
- Adding a mask to an image using CSS
- Essential CSS Properties for Styling Tables

Advertisements