skip to Main Content

I want to know about cellspacing and cellpadding in HTML

I was coding in vscode so when i tried typing cellspacing it didn’t show me as a table attribute.I just started learning HTML so can someone help me in this.
This is what I mean
Same problem for cellpadding too. Is there any other way to do this?

2

Answers


  1. cellpadding is deprecated obsolete, that’s why it won’t show up in vscode.

    Defines the space between the content of a cell and its border. This attribute is obsolete: instead of using it, apply the padding CSS property to the <th> and <td> elements.

    Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table#cellpadding

    Login or Signup to reply.
  2. cellpadding attribute is used to set padding between cells.

    Same as style padding :

    td {
       padding: 10px;
    }
    
    <table border="1" cellpadding="10">
      <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
      </tr>
      <tr>
        <td>4</td>
        <td>5</td>
        <td>6</td>
      </tr>
      <tr>
        <td>7</td>
        <td>8</td>
        <td>9</td>
      </tr>
    </table>

    while cellspacing attribute is used to set space between cells.

    <table border="1" cellspacing="10">
      <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
      </tr>
      <tr>
        <td>4</td>
        <td>5</td>
        <td>6</td>
      </tr>
      <tr>
        <td>7</td>
        <td>8</td>
        <td>9</td>
      </tr>
    </table>

    cellpadding and cellspacing attribute in single code.

    <table border="1" cellpadding="10" cellspacing="10">
      <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
      </tr>
      <tr>
        <td>4</td>
        <td>5</td>
        <td>6</td>
      </tr>
      <tr>
        <td>7</td>
        <td>8</td>
        <td>9</td>
      </tr>
    </table>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search