Building Tables
Yaser Rahmati | یاسر رحمتی
Building tables in HTML involves using several key tags to structure data in rows and columns. Here's how to do it:
Basic Structure of a Table
The main tags used for creating tables are:
<table>
: Defines the table.<tr>
: Defines a table row.<th>
: Defines a header cell.<td>
: Defines a data cell.
Example of a Simple Table
This will render a table with three columns: Name, Age, and City.
Breakdown of Tags
<table>
: This tag creates the table itself.<tr>
: Table row. Each<tr>
creates a new row.<th>
: Table header cell. These are bold by default and appear at the top of the table.<td>
: Table data cell. These hold the actual data inside the table.
Adding Borders and Spacing
By default, HTML tables don’t have borders or spacing between cells. You can add them using the border
attribute or better yet, using CSS.
This will create a table with borders around the cells. But it’s more modern to use CSS for styling:
Table with Rowspan and Colspan
You can also merge cells across rows and columns using rowspan
and colspan
.
Colspan Example:
Merges two columns together.
This creates a header spanning across two columns.
Rowspan Example:
Merges cells across multiple rows.
This creates a table where the "Name" cell spans across two rows.
Adding a Caption
A table can also have a caption to describe its content.
Example of a Full Table
Keywords
HTML
, Hypertext Markup Language
, Tags
, Elements
, Attributes
, Head
, Body
, Paragraph
, Heading
, Title
, Meta
, Link
, Image
, Anchor
, Hyperlink
, List
, Table
, Form
, Input
, Button
, CSS
, Class
, ID
, Inline
, Block
, Div
, Span
, Script
, Styles
, Font
, Color
, Background
, Margin
, Padding
, Border
, Doctype
, HTML5
, Video
, Audio
, Canvas
, SVG
External Links
🌐 Personal Website 📄 Resume 🎥 Video Archive 💼 Finance Blog 🔐 Network & Security Notebook 🎬 Aparat Channel
Last updated