CSS Table Width

Even if you use CSS exlusively to control your layouts, there may be times where an HTML table is still required (for example, to present tabular data). You can still use CSS to control the table width, borders, background and other properties.

To use CSS to control the table width, use the CSS width property. For example:

Copy to Clipboard
<table style="width:400px;">

If you're using an embedded style sheet or external style sheet, table width can be declared there too - just call its class. For example:

Copy to Clipboard
HTML Code (for your HTML document):
<table class="wide-table">

CSS Code (for your style sheet):
table.wide-table { width:100%; }

Examples

Here are some examples of tables with different widths.

CodeResult

Cell 1 Cell 2
Cell 3 Cell 4
CodeResult

Cell 1 Cell 2
Cell 3 Cell 4
CodeResult

Cell 1 Cell 2
Cell 3 Cell 4
CodeResult

Cell 1 Cell 2
Cell 3 Cell 4

You can also use the CSS table-layout property to make larger tables load faster.

For more on tables, check out the HTML Table Tutorial and the HTML Table Generator.

Enjoy this page?

Sponsored Link: Design CODE-FREE Websites

Check a Domain:

ZappyHost Logo
Webydo Banner Ad