HTML table span entire width


<table border="1" width="100%" ID="Table2">

This code still leaves an “inch” of space on both sides of the table. I am trying to get the table to span the entire width of the page.

Try (in your <head> section, or existing CSS definitions)…

  body {
    margin: 0;
    padding: 0;

There might be a margin style that your table is inheriting. Try setting the margin of the table to 0:

<table border="1" width="100%" ID="Table2" style="margin: 0px;">

<table border="1"; width=100%>

works for me.

You need to set the margin of the body to 0 for the table to stretch the full width. Alternatively, you can set the margin of the table to a negative number as well.

Just FYI:

html should be table and width: 100%.

span should be margin: auto;.

Just in case you’re using Bootstrap 4, you can add px-0 (set left/right padding to 0) and mx-0 (set left/right margin to 0) CSS class to the body tag, like below:

<body class="px-0; mx-0">
    <!--your body HTML-->

Leave a Comment