Tables Flashcards
What is the primary use of HTML tables?
HTML tables are used for tabular data, consisting of rows and columns.
When should you use a <table>
element?
Use a <table>
for data that needs to be compared, sorted, or cross-referenced.
What are the main elements inside a <table>
in order?
The main elements are: <caption>
, <colgroup>
, <thead>
, <tbody>
, <tfoot>
, and <tr>
.
What does the <caption> element define in a table?
The <caption>
element defines the table’s title and is the first element inside a <table>
.
What are the three sections that a table can have?
A table can have up to three sections: <thead>
, <tbody>
, and <tfoot>
.
What are the table cells in HTML?
Table cells are defined by <th>
(header cell) and <td>
(data cell).
How do you define a table row and what can it contain?
A table row is defined by <tr>
, which contains either header cells (<th>
) or data cells (<td>
).
What attributes are used to merge cells horizontally and vertically in a table?
The colspan
attribute merges cells horizontally (across columns) and rowspan
merges cells vertically (across rows).
What is the role of the <colgroup>
element in HTML tables?
The <colgroup>
element defines groups of columns for styling purposes, typically used with the <col>
element for limited column styling.
What is the purpose of the scope
attribute in table headers?
The scope
attribute defines the relationship between a header and the cells it applies to, such as scope="col"
for column headers or scope="row"
for row headers.
What is the correct order of elements inside a <table>
tag?
The correct order is: <caption>
, <thead>
, <tbody>
, <tfoot>
, and then rows <tr>
with cells <th>
or <td>
.
How do you style specific columns in a table?
Use <colgroup>
and <col>
to group and style columns in a table.