CSS TutorialLesson #61

Table Size

property is used to set the width of a table.

CSS Table Width

The CSS width property is used to set the width of a table.

The width can be set:

  • in percent (%)
  • as a fixed length (px)
  • by the auto keyword

CSS Table Width in Percent

To create a table that spans the entire screen (full-width), use width: 100%;:

FirstnameLastnameSavings
PeterGriffin$100
LoisGriffin$150
JoeSwanson$300

Example

Example Code

css
Try it Yourself
table
{

  width: 100%;

}

To create a table that spans half the page, use width: 50%;:

FirstnameLastnameSavings
PeterGriffin$100
LoisGriffin$150
JoeSwanson$300

Example

Example Code

css
Try it Yourself
table
{

  width: 50%;

}

CSS Table Width in a Fixed Width

To create a table with a fixed width, use width: 500px:

FirstnameLastnameSavings
PeterGriffin$100
LoisGriffin$150
JoeSwanson$300

Example

Example Code

css
Try it Yourself
table
{

  width: 500px;

}

CSS Table Width Using auto

To let the browser calculate the width, use width: auto;:

FirstnameLastnameSavings
PeterGriffin$100
LoisGriffin$150
JoeSwanson$300

Example

Example Code

css
Try it Yourself
table
{

  width: auto;

}

CSS Table Height

The CSS height property is used to set the height of a table.

The height can be set:

  • in percent (%)
  • as a fixed length (px)
  • by the auto keyword

The example below sets the height of the table headers (<th>) to 70px:

FirstnameLastnameSavings
PeterGriffin$100
LoisGriffin$150
JoeSwanson$300

Example

Example Code

css
Try it Yourself
th
{

  height: 70px;

}


Interactive Code Examples

CSS Example 1

css
Try it Yourself
Interactive runnable CSS example from EA Academy.
Live Output Preview:

CSS Example 2

css
Try it Yourself
Interactive runnable CSS example from EA Academy.
Live Output Preview:

CSS Example 3

css
Try it Yourself
Interactive runnable CSS example from EA Academy.
Live Output Preview:

CSS Example 4

css
Try it Yourself
Interactive runnable CSS example from EA Academy.
Live Output Preview:

CSS Example 5

css
Try it Yourself
Interactive runnable CSS example from EA Academy.
Live Output Preview: