Javatpoint Logo
Javatpoint Logo

How to Make an HTML Table Border

Knowing how to construct an HTML table is necessary for adding a border to one. Tables may be made by combining the table> element with the tr>, td>, and th> tags in HTML.

Making the HTML Table's Border

An HTML table should add a border after creation because borders are not included by default. Let's look at a sample using the HTML border property first.

Using the border element to create an HTML table as an example:

Output:

How to Make an HTML Table Border

Nevertheless, if you want to add a border to your tables, we advise utilizing the CSS border property. You must specify the style> of your table before you can apply a border to it.

Remember to include borders for the th and td tags to have a complete table. Set the border-collapse property as well (by default, border-collapse: separate will be used if you don't define it).

An Illustration of How to Add Borders to an HTML Table

Output:

How to Make an HTML Table Border

How to Use CSS to Modify the Border Style of an HTML Table

The CSS border shorthand property and the border-width, border-style, and border-color properties individually may be used to customize your table. See the sample below to see how these qualities manifest themselves.

Example of altering the CSS border style of an HTML table

Output:

How to Make an HTML Table Border

You can use any of the following properties: border-top, border-right, border-bottom, and border-left if you don't want the border to wrap around the entire table (or if you require distinct borders on each side of the table).

An Illustration of How to Add Bottom Borders to an HTML Table

Output:

How to Make an HTML Table Border

How to Make Borders All Round

The CSS border-radius property may be used to create rounded borders as well. Remember to delete the border-collapse attribute for this situation to function correctly. Let's look at an instance where the table's components are rounded.

An illustration of a table with rounded edges in HTML

Output:

How to Make an HTML Table Border

How to Apply a Border to the "p" Element, "h2" Element, or "div" Element

Other HTML components can also have borders added in the same way. Look at an example of border addition to the p, h2, and div components.

An illustration of how to apply borders to the p>, h2>, and div> elements:

Output:

How to Make an HTML Table Border

Check out the sample below to see how to give your paragraphs a rounded border. For the result you want, use the border-radius attribute.

Output:

How to Make an HTML Table Border





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA