Master W3Schools Table Border: Complete Guide To Styling And Code Examples

Logan Jul 13, 2026

W3Schools, a popular online learning platform, offers a wealth of resources for web developers, including comprehensive tutorials and references. One of the most fundamental elements in web design is the HTML table, a mechanism used to arrange data in rows and columns. Today, we'll delve into the concept of table borders provided by W3Schools.

Школьный фон
Школьный фон

W3Schools tabla border tutorial is a fantastic starting point for understanding how to add and style borders around HTML tables. Let's dive in to understand the intricacies better.

an image of school supplies in the shape of a frame
an image of school supplies in the shape of a frame

Understanding Table Borders in W3Schools

W3Schools introduces the border attribute, which allows you to specify the width of the border around an HTML table. The value can either be a numeric value representing the width in pixels or a specific keyword like thin, medium, thick, or groove (a 3D effect).

Borde de página horizontal, Borde Ilustrado Vuelta al Cole, Fondo escolar para cartel
Borde de página horizontal, Borde Ilustrado Vuelta al Cole, Fondo escolar para cartel

By default, tables in HTML span the full width of their containing element. However, the border attribute enables you to set a consistent border around each cell, giving the table a more defined structure.

Setting Border Width

an image of school supplies and pencils on watercolor paper with space for text
an image of school supplies and pencils on watercolor paper with space for text

To set a specific width for table borders, use the following syntax:

```html

``` Replace n with the desired border width in pixels. For example, border="5" sets a 5-pixel-wide border. You can also use keywords like border="thin" for a thin border, border="medium" for a medium border, or border="thick" for a thick border. The border="groove" keyword provides a 3D groove effect.

To illustrate this, consider the following example from W3Schools:

an image of school supplies with space for text
an image of school supplies with space for text

```html

Header 1 Header 2
Cell 1 Cell 2
Cell 3 Cell 4

```

CSS Styling for Table Borders

While the border attribute is helpful, CSS provides more control over table borders. W3Schools cover this in-depth, teaching you how to:

a wooden frame with colorful flags hanging from it's sides on a chalkboard background
a wooden frame with colorful flags hanging from it's sides on a chalkboard background
  • Change border color
  • Add background color to table cells
  • Round table borders
  • Add different border styles, such as dashed or double borders
  • And more!

Here's a simple CSS example showing how to change border color:

an illustration of a school border with different items
an illustration of a school border with different items
Bordüre A4 zum Ausdrucken, süßes Briefpapier für das Klassenzimmer, Briefpapier zum Schulanfang, Lehrer PDF zum Herunterladen
Bordüre A4 zum Ausdrucken, süßes Briefpapier für das Klassenzimmer, Briefpapier zum Schulanfang, Lehrer PDF zum Herunterladen
Télécharger Une bordure de papeterie scolaire gratuitement
Télécharger Une bordure de papeterie scolaire gratuitement
W3Schools.com
W3Schools.com
an image of school supplies and stationery on a yellow background with place for text
an image of school supplies and stationery on a yellow background with place for text
School Borders - 12 Free PDF Printables | Printablee
School Borders - 12 Free PDF Printables | Printablee
an overhead view of various school supplies including pencils, rulers and eraseers
an overhead view of various school supplies including pencils, rulers and eraseers
a frame with numbers and letters on it
a frame with numbers and letters on it
colorful lines with different colors on them
colorful lines with different colors on them
a square frame with numbers in the middle and one at the bottom, on a white background
a square frame with numbers in the middle and one at the bottom, on a white background
a school supplies frame with a calculator and pencils
a school supplies frame with a calculator and pencils
School Supplies Border A4 Printable, Cute Pencil Eraser Frame, Kids Writing Paper, Classroom Printable Stationery PDF
School Supplies Border A4 Printable, Cute Pencil Eraser Frame, Kids Writing Paper, Classroom Printable Stationery PDF
four different colored labels with white and blue borders on each side, one is blank
four different colored labels with white and blue borders on each side, one is blank
a colorful striped bookmark on a white background
a colorful striped bookmark on a white background
Colorful Beige Cute Watercolor School Supply Page Border A4 Document - Templates by Canva
Colorful Beige Cute Watercolor School Supply Page Border A4 Document - Templates by Canva
two black borders with colorful circles on them
two black borders with colorful circles on them
Colorful Classroom Border for Creative Projects
Colorful Classroom Border for Creative Projects
an image of a frame with numbers and percentages on the bottom half of it
an image of a frame with numbers and percentages on the bottom half of it
Table Diagram Blank
Table Diagram Blank
Alphabet Borders - 10 Free PDF Printables | Printablee
Alphabet Borders - 10 Free PDF Printables | Printablee

```css table { border-collapse: collapse; border: 1px solid blue; } th, td { border: 1px solid blue; padding: 15px; } ```

Advanced Table Borders with CSS

W3Schools also provides advanced insights into CSS border properties, such as border-top, border-right, border-bottom, and border-left, giving you pixel-precise control over table borders.

Additionally, you'll learn about CSS background properties, like background-color and background-image, to add visual appeal to your tables. Understanding these properties can transform simple HTML tables into visually engaging data displays.

rounded-border Example

W3Schools offers a tutorial on giving tables rounded corners using the border-radius property. This can add a touch of elegance and modernism to your web pages.

Here's a quick example using this property:

```css table { background-color: lightgray; border-radius: 30px; padding: 20px; } ```

Border Spacing

W3Schools also teaches you how to control the spacing between table borders and cells. You'll learn about the border-spacing property and how to use it in combination with border-collapse to create visually appealing and neatly spaced tables.

Understanding these properties can help you create responsive tables that look good on various devices and screen sizes.

In conclusion, W3Schools' table border tutorials offer a wealth of information for web developers and designers looking to create engaging and visually appealing tables. From the basics of using the border attribute to advanced CSS techniques, W3Schools provides a solid foundation to help you master table borders.

With practice and experimentation, you'll be well on your way to crafting tables that not only display data effectively but also enhance the aesthetic appeal of your web pages. So, get started, explore, and happy coding!