Published by Patrick Mutisya · 14 days ago
By the end of this lesson you will be able to:
The align attribute on a <td> or <th> element controls horizontal alignment.
| Left | Centre | Right | Justify |
|---|---|---|---|
| This text is aligned to the left. | This text is centred. | This text is aligned to the right. | This text is fully justified, meaning it stretches to fill the cell width. |
The valign attribute controls vertical alignment within a cell.
| Top | Middle | Bottom |
|---|---|---|
| Top‑aligned text. | Middle‑aligned text. | Bottom‑aligned text. |
Use the border attribute on the <table> element.
Table with gridlines (border = 1):
| Cell 1 | Cell 2 |
| Cell 3 | Cell 4 |
Table without gridlines (border = 0):
| Cell 1 | Cell 2 |
| Cell 3 | Cell 4 |
Set a column width that forces the text to wrap. The width attribute on <td> (or <col>) can be used.
This is a long piece of text that will automatically wrap onto multiple lines because the column width is limited. | Short text. |
Use the bgcolor attribute to apply a background colour.
| Light red shading | Light green shading | Light blue shading |
The height attribute on a <tr> sets the minimum row height.
| Row height set to 60 px. | Another cell in the same row. |
| Default height row. | Default height row. |
Use <colgroup> with <col> elements to define column widths.
| Column 1 (150 px) | Column 2 (250 px) |
|---|---|
| Fixed width column. | This column is wider, allowing more text before wrapping occurs. |
align for left, centre, right, justify.valign for top, middle, bottom.border="1" to show gridlines; border="0" to hide them.width on cells or columns to force text wrapping.bgcolor for cell shading.height on <tr> to change row height.<colgroup> and <col> with width to control column width.