Solution 1 :

Use </td> instead of <td> for the closing tags of boxes 6 and 7. The colspan for box 2 is not necessary. The other three colspans were too large. This code should get you to Figure 2.

    <table width="30%">
      <tr>
        <td colspan="3">1</td>
        <td>2</td>
      </tr>
      <tr>
        <td>3</td>
        <td rowspan="2" colspan="3">4</td>
      </tr>
      <tr>
        <td>5</td>
      </tr>
      <tr>
        <td colspan="2">6</td>
        <td>7</td>
        <td>8</td>
      </tr>
      <tr>
        <td>9</td>
        <td>10</td>
        <td>11</td>
        <td>12</td>
      </tr>
    </table>

Solution 2 :

This would make the first figure:

<table width="30%">
<tr>
<td>1</td>
<td>2</td>
<td rowspan="2">3</td>
</tr>
<tr>
<td>4</td>
<td rowspan="4">5</td>
</tr>
<tr>
</tr>
<tr>
<td rowspan="3">6</td>
<td>7</td>
</tr>
<tr>
<td>8</td>
</tr>
<tr>
<td>9</td>
<td rowspan="2">10</td>
</tr>
<tr>
<td>11</td>
<td>12</td>
</tr>
</table>

Solution 3 :

There were some errors in your html related to closing </td> tags. This should work:

<html>
<head>
    <style>
    table,
    td,
    th {
        border: 2px solid gray;
        text-align: center
    }
    </style>
</head>

<body>
    <table width="30%">
        <tr>
            <td colspan="5">1</td>
            <td colspan="3">2</td>
        </tr>
        <tr>
            <td>3</td>
            <td rowspan="2" colspan="6">4</td>
        </tr>
        <tr>
            <td>5</td>
        </tr>
        <tr>
      <td colspan="4">6</td>
      <td colspan="2">7</td>
            <td colspan="2">8</td>
        </tr>
        <tr>
            <td colspan="2">9</td>
            <td colspan="2">10</td>
            <td colspan="2">11</td>
            <td colspan="2">12</td>
        </tr>
    </table>
</body>
</html>

Demo: https://jsfiddle.net/js2ye3uo/

Problem :

I had a problem while creating a small table with specific details like in the pic enter image description here

I did this code but it doesn’t give the wanted results

<html>
<head>
 <style>
       table,td,th{border: 2px solid gray; text-align:center}
      </style>
</head>
<body>
<table width="30%">
<tr>
<td colspan="4">1</td>
<td colspan="3">2</td>
</tr>
<tr>
<td>3</td>
<td rowspan="2" colspan="8">4</td>
</tr>
<tr>
<td>5</td>
</tr>
<tr>
<td colspan="4">6<td>
<td>7<td>
<td>8</td>
</tr>
<tr>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
</tr>
</table>
</body>
</html>

Comments

Comment posted by tacoshy

do you need that table for displaying actual data or do you need it for styling puprose. For last table shouldnt be used at all and you rather should look into the use of a css-grid befor learnign outdated and wrong HTML and CSS use.

Comment posted by dark

what about the 1st figure

Comment posted by Marc Hauschildt

Similarly, you need to use

instead of

at the end of boxes 6 and 7. Move box 3 to the first row and add a rowspan. Remove the colspan from boxes 1 and 2. Move box 5 to the second row and add a rowspan. Remove the rowspan and colspan from box 4. Move box 8 to a new row after the row with boxes 6 and 7. Change box 6’s colspan of 4 to a rowspan of 3. Move boxes 11 and 12 to a new row after boxes 9 and 10. Add a rowspan to box 10.

By