The Wayback Machine - https://web.archive.org/web/20240907065656/https://www.geeksforgeeks.org/html-table-borders/
Open In App

HTML Table Borders

Last Updated : 22 Jan, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

HTML Table Borders define the visible lines around cells and the overall table. They help in creating clear distinctions between various sections of the table, making it easier to understand and show information clearly. This attribute allows you to control the border’s style, color, and width, for the visual presentation of your table.

Syntax

table {
width: 100%;
border: 1px solid #100808;
}
th, td {
border: 1px solid #eca0a0;
padding: 10px;
}

Adding the Table Border

HTML table borders are crucial in defining the structure and appearance of tables on a webpage. Set the border property to the <table>, <td>, and <th> elements to achieve the table border effect.

Example: Illustration of the creation of an HTML Table with a Border.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width,
                   initial-scale=1.0">
    <title>HTML Table border</title>
    <style>
        body {
            font-family: Arial, Helvetica, sans-serif;
        }
  
        h1,
        h3 {
            text-align: center;
            color: green;
        }
  
        table {
            width: 100%;
            border: 1px solid #100808;
        }
  
        th,
        td {
            border: 1px solid #eca0a0;
            padding: 10px;
            text-align: center;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <h3>Table with border
    </h3>
    <table>
        <thead>
            <tr>
                <th>Name</th>
                <th>Class</th>
                <th>
                    Roll No
                </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Mahima</td>
                <td>10</td>
                <td>1</td>
            </tr>
            <tr>
                <td>Krishn</td>
                <td>8</td>
                <td>3</td>
            </tr>
            <tr>
                <td>Shivika</td>
                <td>8</td>
                <td>5</td>
            </tr>
        </tbody>
    </table>
</body>
  
</html>


Output:

Table Borders Collapsed

Table Collapsed borders are a visual styling option for HTML tables where adjacent cell borders are merged or collapsed into a single border-line. Set the border property to the <table>, <td>, and <th> elements to achieve the table border effect.

Example: Illustration of the creation of Table Borders Collapsed.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, 
                   initial-scale=1.0">
    <title>
          HTML Table border collapsed
      </title>
    <style>
        body {
            font-family: Arial, Helvetica, sans-serif;
        }
  
        h1,
        h3 {
            text-align: center;
            color: green;
        }
  
        table {
            width: 100%;
            border: 1px solid #100808;
            border-collapse: collapse;
        }
  
        th,
        td {
            border: 1px solid #413434;
            padding: 10px;
            text-align: center;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <h3>
       Table with Collapsed border
    </h3>
    <table>
        <thead>
            <tr>
                <th>Name</th>
                <th>Class</th>
                <th>
                    Roll No
                </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Mahima</td>
                <td>10</td>
                <td>1</td>
            </tr>
            <tr>
                <td>Krishn</td>
                <td>8</td>
                <td>3</td>
            </tr>
            <tr>
                <td>Shivika</td>
                <td>8</td>
                <td>5</td>
            </tr>
        </tbody>
    </table>
</body>
  
</html>


Output:

Table Borders Style

Table Borders Style applies the border-collapse: collapse property to the <table>, <td>, and <th> elements, and sets the border and background-color properties for styling the table and its elements.

Example: Illustration of the Style Table border.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,
                   initial-scale=1.0">
    <title>HTML Table border-style</title>
    <style>
        body {
            font-family: Arial, Helvetica, sans-serif;
        }
  
        h1,
        h3 {
            text-align: center;
            color: green;
        }
  
        table {
            width: 100%;
            border: 1px solid #100808;
            border-collapse: collapse;
        }
  
        th,
        td {
            text-align: center;
            border: 1px solid #413434;
            padding: 10px;
            background-color: rgb(181, 216, 181);
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <h3>Table Border Style
    </h3>
    <table>
        <thead>
            <tr>
                <th>Name</th>
                <th>Class</th>
                <th>
                    Roll No
                </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Mahima</td>
                <td>10</td>
                <td>1</td>
            </tr>
            <tr>
                <td>Krishn</td>
                <td>8</td>
                <td>3</td>
            </tr>
            <tr>
                <td>Shivika</td>
                <td>8</td>
                <td>5</td>
            </tr>
        </tbody>
    </table>
</body>
  
</html>


Output:

Rounded Table Borders

Rounded table borders make the corners of a table look smooth and curved instead of sharp and straight. This styling technique uses a design feature called “border-radius” to achieve the rounded effect. Apply the border-radius property to the <table>, <td>, and <th> elements to achieve rounded corners for the table borders.

Example: Illustration of the round shaped cells with the help of Table border.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width,
                   initial-scale=1.0">
    <title>HTML rounded table</title>
    <style>
        body {
            font-family: Arial, Helvetica, sans-serif;
        }
  
        h1,
        h3 {
            text-align: center;
            color: green;
        }
  
        table {
            width: 100%;
            border: 1px solid #100808;
            border-radius: 20px;
  
        }
  
        th,
        td {
            text-align: center;
            border: 1px solid #413434;
            padding: 10px;
            background-color: rgb(181, 216, 181);
            border-radius: 40px;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <h3>
          HTML rounded table
    </h3>
    <table>
        <thead>
            <tr>
                <th>Name</th>
                <th>Class</th>
                <th>
                    Roll No
                </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Mahima</td>
                <td>10</td>
                <td>1</td>
            </tr>
            <tr>
                <td>Krishn</td>
                <td>8</td>
                <td>3</td>
            </tr>
            <tr>
                <td>Shivika</td>
                <td>8</td>
                <td>5</td>
            </tr>
        </tbody>
    </table>
</body>
  
</html>


Output:

border

Style Table border with border-style

The border-style property allows you to define different styles for table borders. The property contains different border styling including solid, dashed, dotted, double, groove, ridge, inset, outset, none, and hidden.

Example: Illustration of the Styling the Table border with border-style.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width,
                   initial-scale=1.0">
    <title>HTML Table using border-style</title>
    <style>
        body {
            font-family: Arial, Helvetica, sans-serif;
        }
  
        h1,
        h3 {
            text-align: center;
            color: green;
        }
  
        table {
            width: 100%;
            border: 1px solid #100808;
            border-radius: 12px;
            border-color: #2df804;
  
        }
  
        th,
        td {
            text-align: center;
            padding: 10px;
            background-color: rgb(181, 216, 181);
            border-radius: 40px;
            border-style: dotted;
            border-color: #f80404;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <h3>
       HTML Table using border-style
    </h3>
    <table>
        <thead>
            <tr>
                <th>Name</th>
                <th>Class</th>
                <th>
                    Roll No
                </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Mahima</td>
                <td>10</td>
                <td>1</td>
            </tr>
            <tr>
                <td>Krishn</td>
                <td>8</td>
                <td>3</td>
            </tr>
            <tr>
                <td>Shivika</td>
                <td>8</td>
                <td>5</td>
            </tr>
        </tbody>
    </table>
</body>
  
</html>


Output:

border5



Similar Reads

How to set the collapsing borders model for a table ?
CSS describes the way HTML elements should be displayed. There are various CSS properties that can add magic to the basic HTML document. This article is focused on setting the collapsing borders model for the table element of HTML. HTML tables allow us to arrange our data using rows and columns. The &lt;table&gt; tag defines an HTML table. Each tab
3 min read
Pure CSS Table with Horizontal Borders
A table is an arrangement of data in rows and columns, or possibly in a more complex structure. Tables are widely used in communication, research, and data analysis. In Pure CSS, we will add a "pure-table" class to add styles to the table. This class adds padding and borders to table elements and emphasizes the header. A table with Horizontal Borde
2 min read
Bootstrap 5 Table borders
Bootstrap 5 Table borders classes are used to set or unset the border of the table. With bootstrap 5 table borders are easy to customize with border or no border. Bordered tables: This is used to set the border on each side of the table.Tables without borders: This is used to make the table borderless all over the table like there will be no row an
2 min read
How to remove borders of a canvas-type text using Fabric.js ?
In this article, we are going to see how to remove the borders of a canvas-like text using FabricJS. The canvas means text written is movable and can be stretched according to requirement. Further, the text itself cannot be edited like a textbox.Approach: To make it possible we are going to use a JavaScript library called FabricJS. After importing
2 min read
Borders in bootstrap with examples
Borders: Borders are generally used to display an outline around a box or table cell or any other HTML element. In Bootstrap, there are different classes available to add or remove borders. The classes that are used to add borders are referred as Additive classes and those that are used to remove borders are referred as subtractive classes. Additiv
4 min read
How to remove controlling borders of a canvas circle using Fabric.js ?
In this article, we are going to see how to remove the controlling borders of a canvas circle using FabricJS. The canvas means the circle is movable and can be stretched according to requirement. Further, the circle can be customized when it comes to initial stroke color, fill color, stroke width, or radius. Approach: To make it possible, we are go
2 min read
How to change Input box borders after filling the box using JavaScript ?
In this article, we will change the input border after filling in the text on the input text field. The onchange event attribute works when the value of the element changes and selects the new value from the list. Approach: Whenever the input value is changed with some value by the user, the onchange event attribute is triggered. After the event is
2 min read
Tailwind CSS Borders Complete Reference
Tailwind CSS is a highly customizable, low-level CSS framework that gives you all of the buildings blocks that you need. Tailwind CSS Border utility settings the radius, width, color, opacity, etc., of element's borders. all the properties covered as in this class form. Tailwind CSS Class Description Example Border RadiusIt is used to set the borde
2 min read
React MUI Borders
Material UI is an open-source design framework that showcases different components made in react. It is developed and maintained by Google since 2014. What is Borders API offered by Material UI? The Borders API, provided by MUI, allows us to control the border and border-radius of DOM elements that have border utilities. passed to Borders API props
3 min read
Primer CSS Responsive Borders
Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approach to CSS is influenced by Object-Oriented CSS principles, functional CSS, an
3 min read
Primer CSS Borders
Primer CSS is a free and open-source CSS framework. It is built upon the systems that create the foundation of the basic style elements such as spacing, typography, and color. Created with GitHub’s design system, it is highly reusable and flexible. Primer CSS Borders is a utility class that applies borders to a div container of HTML by simply apply
3 min read
Tachyons Theming Borders
CSS border properties allow us to set the style, color, and width of the border. Tachyon is a toolkit that is used to create a responsive website. Used Classes: Border: The "ba" class is used to create a simple border.Border Top: The "bt" class is used to create a border from the top.Border Right: The "br" class is used to create a border from the
4 min read
Pure CSS applying Padding and Borders to Grid Units
Pure CSS is a free and open-source CSS framework. It is a set of instruments for developing responsive websites and online applications. This was created by Yahoo and is used to create websites that are quicker, more aesthetically beautiful, and more user-friendly. It effectively replaces Bootstrap. The responsive design was considered when creatin
3 min read
Bootstrap 5 Borders Sizes
Bootstrap 5 Border utility is used to set the style of the border element. The border styles can be of border-color, border-width, border-radius, etc. The Border Sizes are used to set the border-radius rounded corners larger or smaller. The range of border sizes varies from 0 to 3, where 0 represents smaller-size rounded corners and 3 represents la
2 min read
Bootstrap 5 Borders Subtractive
Bootstrap5 Borders Subtractive is used to remove borders from the box by defining which side the border is to be removed or we can remove the border from all sides at once. Bootstrap 5 Borders Subtractive Classes: border-0: This class is used to remove borders from all around the elementborder-top-0: This class is used to remove the border from the
3 min read
Bootstrap 5 Borders Additive
Bootstrap5 Borders Additive classes are mainly used to display an outline around a box and it provides style, color, and radius of an element border on the side we want. For eg: if we want the border only on the top of the box we can have it by using the border-top additive class. Bootstrap 5 Borders Additive classes: border: This class is used to
2 min read
Bootstrap 5 Tables without borders
Bootstrap5 Tables without borders is used to create a table in borderless form. It is mostly used when we do not want to show the separation in the table content. Tables without Borders Class: table-borderless: This class is used to create borderless tables Syntax: &lt;table class="table table-borderless"&gt; ... &lt;/table&gt; Example 1: In this e
2 min read
How to add Borders and Shadows to Elements in CSS ?
Apply box shadows to elements to create a 3D effect, whereas adding borders to containers or boxes can enhance the structural clarity of a layout. In this article, we will learn how to add borders and shadows to the elements in CSS. We will explore two different approaches to adding borders and shadows. Table of Content Using the border and box-sha
2 min read
Chakra UI Borders
Chakra UI is a popular React component library that simplifies the process of building user interfaces with a set of customizable and accessible components. Among those feature it also provide support for styling and layout including the management of borders. It provides various properties to customize borders. In this article, we will learn about
2 min read
How to Add Borders to Pagination in CSS ?
Add borders to Pagination is when you have many pages of content and must move between them. Making these page buttons look better can make navigating easier and more enjoyable for users. One way to do this is by adding borders to the page buttons using CSS. These are the following approaches: Table of ContentUsing Border PropertyUsing Border-Style
3 min read
Gradient borders
Creating visually appealing borders can significantly enhance the user experience on your website. One such technique is the use of gradient borders. Although CSS does not directly support gradient borders, there are two effective methods to achieve this: Try It: .custom-item { border: 1px solid gray; font-family: 'Gill Sans', 'Gill Sans MT', Calib
3 min read
Bootstrap 5 Borders
Bootstrap 5 Borders offer predefined border styles to elements. Classes like .border, .border-0, .border-top, .border-bottom, .border-left, and .border-right provide easy customization for borders, including color, width, and radius, enhancing UI design. iframe { width: 100%; height: 450px;} @media (max-width: 1145px) {.article--viewer .a-wrapper .
2 min read
CSS Borders
A CSS border is a line that surrounds an HTML element, providing a visual separation between the element and its surroundings. Borders can be styled in various ways, including adjusting their width, color, and style. The basic properties used to define borders in CSS are border-width, border-style, and border-color. This Borders in CSS article will
6 min read
How to create Table with 100% width, with Vertical Scroll inside Table body in HTML?
To add a vertical scroll bar inside the table body, use the overflow-y property. By changing the display property of tbody to block, we can display the block-level element. However, when changing the display property of tbody, we must also change the property of thead to prevent the table layout from breaking. ApproachApply the class scroll down to
2 min read
Which table property specifies the width that should appear between table cells in CSS ?
In this article, we will see how to specify the width that should appear between table cells. CSS provides the border-spacing property that can be used to set the distance between the borders of neighboring cells in the Table. This property works only when the border-collapse property is set to no-collapse separate. Syntax: border-spacing: length|i
2 min read
How to add table row in a table using jQuery?
jQuery can be used to add table rows dynamically. This can be used in web applications where the user may need to add more rows if required. Steps to add table row: The required markup for the row is constructed. markup = &quot;&lt;tr&gt;&lt;td&gt; + information + &lt;/td&gt;&lt;/tr&gt;&quot; The table body is selected to which the table rows to be
2 min read
How to remove table row from table using jQuery ?
The jQuery remove() method is used to remove a row from HTML table. jQuery remove() Method: This method removes the selected elements alongwith text and child nodes. This method also removes data and events of the selected elements. Syntax: $(selector).remove(selector) Parameters: It accepts single parameter selector which is optional. It specifies
2 min read
How create table without using &lt;table&gt; tag ?
HyperText Markup Language (HTML) is the standard markup language used to create web pages. HTML allows table creation using the &lt;table&gt; tag. However, tables can also be created in HTML without using &lt;table&gt; tag with the help of Cascading Style Sheet (CSS). CSS is a mechanism for adding style (e.g. fonts, colors, padding, and other decor
3 min read
Design a table using table tag and its attributes
In this article, we will create a table using HTML. To create this table, we must know the tags required to create the table. At first, we will create the structure of the table and we will use attributes to design the table. Approach: To create the table we have to use the &lt;table&gt; tag and we will use attributes of the &lt;table&gt; tag to de
1 min read
Angular PrimeNG Table Column Widths of a Scrollable Table
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use Table Column Widths of a Scrollable Table in Angular PrimeNG. Angular PrimeNG Table Column Widths of a Scrollable
5 min read
Article Tags :