How to perform cellpadding and cellspacing in CSS

Cell spacing

The cell spacing property in CSS is used to set the space between the cells. We can set the space in pixels between each cell in the table. We can set the cell spacing using the border-spacing property.

Explanation

HTML

  • Line 4: We write the content in the h1 tag.

  • Lines 5 to 26: We make a table with 3 columns, Name, Profession, and Age. Then, we add the information to the table.

CSS

  • Lines 1 to 13: We set the border size and border color of the table and the cell spacing (border-spacing) and the color of the heading.

Cell padding

The cell padding is used to specify the amount of space between the content of the cells and their border.

Explanation

HTML

  • Line 4: We write the content in the h1 tag.

  • Lines 5 to 26: We make a table with three columns, Name, Profession, and Age. Then we add the information to the table.

CSS

  • Lines 1 to 13: We set the border size and border color of the table, the cell padding, and the heading color.
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources