How to add a border to a table and adjust the width in HTML/XHTML

If the border attribute and value is not specified, the table will be displayed without any borders. To display a table with borders, you have to specify the border attribute and value.

The code below shows you how to add a border to a table and adjust the width in HTML.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>Web Development Tutorials.com</title>
</head>
<body>

<table border="1">
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>

</body>
</html>

The code above creates the table with a border value of "1".

1 2
3 4

The code below shows you how to create a table with a border value of "0".

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>Web Development Tutorials.com</title>
</head>
<body>

<table border="0">
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>

</body>
</html>

The code above creates the table with a border value of "0".

1 2
3 4

The code below shows you how to create a table with a border value of "0".

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>Web Development Tutorials.com</title>
</head>
<body>

<table border="8">
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>

</body>
</html>

The code above creates the table with a border value of "8".

1 2
3 4

Use the text editor below to practice what you have learned.

Free Website Templates

Free Web Tools

Recommended Websites