HTML W3Schools Table Border: Complete Guide to Styling and Code Examples

The <table> element in HTML is used to create tables. The border attribute defines the thickness of the border around the table, but it is deprecated in HTML5. Instead, CSS should be used for styling table borders. However, for educational purposes, let's explore the border attribute as taught on W3Schools.

the table borders for different types of text
the table borders for different types of text

Understanding the <table> element and the border attribute can help you structure and present data more effectively in your HTML documents. Let's dive deeper into the subject, starting with an explanation of the <table> element itself.

Responsive HTML Table With Rounded Corners
Responsive HTML Table With Rounded Corners

Understanding the <table> Element

The <table> element is used to create a table. It is defined with a border attribute that sets the thickness of the border around the table, with values in pixels. Let's explore this through examples.

๐Ÿงพ How to Create Tables in HTML
๐Ÿงพ How to Create Tables in HTML

You can create a basic table with a border using the following code:

Country Capital
USA Washington D.C.
How to Add HTML Table Borders Without CSS
How to Add HTML Table Borders Without CSS

In this example, border="1" sets the thickness of the table border to 1 pixel.

Adjusting Border Thickness

The value of the border attribute can be adjusted to change the thickness of the border. For instance, to create a thicker border:

a diagram showing the different types of sound waves
a diagram showing the different types of sound waves
Country Capital
USA Washington D.C.

The table now has a 5-pixel border.

Handling Borderless Tables

HTML Tables Tags Tutorial with Example โ€” TutorialBrain
HTML Tables Tags Tutorial with Example โ€” TutorialBrain

To create a table without a border, you can set the border attribute to 0:

Country Capital
USA Washington D.C.
the table shows different types of bonds in each type of bondor, which one is for
the table shows different types of bonds in each type of bondor, which one is for
HTML Table Styler ๐Ÿ“… CSS Generator
HTML Table Styler ๐Ÿ“… CSS Generator
css border
css border
the table borders for different types of text
the table borders for different types of text
an image of a text description with the words html tables in red and blue on it
an image of a text description with the words html tables in red and blue on it
How To Style Table Borders In CSS HTML
How To Style Table Borders In CSS HTML
W3Schools.com
W3Schools.com
CSS border styles
CSS border styles
Table Diagram Blank
Table Diagram Blank
30 Best Free HTML/CSS Table Templates Templates 2026 - Colorlib
30 Best Free HTML/CSS Table Templates Templates 2026 - Colorlib
40 Best CSS Table Templates For Creating Appealing Tables 2026
40 Best CSS Table Templates For Creating Appealing Tables 2026
tables in html table with text and images on the page, which is displayed below
tables in html table with text and images on the page, which is displayed below
a blue and black rectangular frame on a white background with space for text or image
a blue and black rectangular frame on a white background with space for text or image
CSS Table Layout
CSS Table Layout
Responsive Table V1 - Free HTML/CSS Table Template 2026 - Colorlib
Responsive Table V1 - Free HTML/CSS Table Template 2026 - Colorlib
HTML Table
HTML Table
an image of a table with numbers and symbols on the top right hand corner that says tables
an image of a table with numbers and symbols on the top right hand corner that says tables
an image of a computer screen with the text, table headings and tables headings
an image of a computer screen with the text, table headings and tables headings
a wooden frame with a white board in the middle and a brown border around it
a wooden frame with a white board in the middle and a brown border around it
Responsive Table HTML and CSS Only
Responsive Table HTML and CSS Only

This creates a table without any visible borders.

Using CSS for Table Borders

While the border attribute provides basic styling, modern web design often uses CSS for more control and customization. It's important to know how to apply CSS styles to table borders.

Here's how you can use CSS to style a table border:

table { border-collapse: collapse; width: 100%; } th, td { border: 1px solid black; padding: 8px; text-align: left; }

The table rule sets the border-collapse property to collapse, which removes any extra space between borders. The width is set to 100% for responsiveness. The th and td rules set the border, padding, and text-align properties for table cells.

Responsive Table Borders with CSS

Using CSS, you can also create responsive table borders that adjust based on the screen size:

@media screen and (max-width: 600px) { table { border-collapse: separate; border-spacing: 10px 0; } }

In this example, when the screen width is 600px or less, the border-collapse property changes to separate, and the border-spacing property is applied, adding horizontal space between table cells.

Border-Image Property

The border-image property in CSS allows you to use an image for the table border, providing more control and customization:

table { border-image: url('border-image.png') 10 round; }

The url value specifies the image to use, and '10' sets the width of the border. The 'round' keyword rounds the corners of the border.

Understanding and practicing the use of table borders, both with HTML attributes and CSS, can greatly enhance your web design skills. It's also crucial to stay updated with modern practices, such as using CSS for styling, for creating more responsive and visually appealing web designs.

Related Articles

W3schools Html Symbols W3schools Html Run K State Rec Classes Kent State Rec Center Classes Html W3schools Tags Html W3schools Select W3schools Html Entities Html W3schools Online Editor Html W3schools Tutorial Html W3schools Image