Lesson 18 / الدرس 18
Tables: the basics / الجداول: الأساسيات
A table is a grid of rows and cells for data that truly has rows and columns — not a tool for arranging the page.
الجدول شبكة من الصفوف والخلايا للبيانات التي فيها فعلًا صفوف وأعمدة — وليس أداة لترتيب الصفحة.
A table lays out data in rows and columns, the way you would on paper: a price list, a class schedule, a comparison of two products. HTML builds one from three tags: <table> wraps the whole grid, <tr> is one row, and <td> is one cell inside that row.
<table> يحيط بالشبكة كلها، و <tr> صف واحد، و <td> خلية واحدة داخل ذلك الصف.<table>
<tr>
<td>Dates (1kg)</td>
<td>5 JD</td>
</tr>
<tr>
<td>Honey (500g)</td>
<td>7 JD</td>
</tr>
</table>
<tr> should hold the same number of cells as the others so the grid lines up.
<tr> عدد الخلايا نفسه الذي تحمله بقية الصفوف حتى تصطف الشبكة.Header cells: th
A plain <td> is a data cell. A <th> is a header cell — it labels the column or row under it. The browser shows it bold and centered by default, but the real reason to use it is for a screen reader: it announces "Price, header" and then connects every cell below it back to that label as the visitor moves through the table.
<td> خلية بيانات. أما <th> فهي خلية عنوان — تسمّي العمود أو الصف الذي تحته. يعرضها المتصفح افتراضيًا عريضة وفي المنتصف، لكن السبب الحقيقي لاستخدامها هو قارئ الشاشة: فهو يعلن "Price, header" ثم يربط كل خلية تحتها بذلك العنوان أثناء تنقّل الزائر في الجدول.<table>
<tr>
<th>Product</th>
<th>Price</th>
</tr>
<tr>
<td>Dates (1kg)</td>
<td>5 JD</td>
</tr>
<tr>
<td>Honey (500g)</td>
<td>7 JD</td>
</tr>
</table>
<th>, not <td>.
<th> لا <td>.<td>، وصورة في التالي، وقائمة أسعار في ثالث، لترتيب صفحة كاملة، كان أمرًا شائعًا يومًا، حين كانت CSS عاجزة عن ذلك. أما اليوم فهذا يُفسد الصفحة: يعلن قارئ الشاشة أشياء لا معنى لها مثل "صف 1 من 1، عمود 3 من 3" فوق محتوى ليس جدوليًا أصلًا، والشبكة الثابتة لا تتكيّف مع شاشة الهاتف. إن احتجت إلى ترتيب محتوى في الصفحة، فاستخدم CSS لذلك — فتلك ليست مهمة <table>.When to use a table — and when not to
-
Use a table when the content really has rows and columns: prices, schedules, comparisons. استخدم الجدول عندما يكون للمحتوى فعلًا صفوف وأعمدة: أسعار، أو جداول مواعيد، أو مقارنات.
-
Avoid a table when you just want to place things next to each other on the page — that is CSS's job. تجنّب الجدول عندما تريد فقط وضع أشياء بجانب بعضها في الصفحة — فتلك مهمة CSS.
-
Ask yourself: would a person read this data by row and column? If not, it probably is not a table. اسأل نفسك: هل سيقرأ الشخص هذه البيانات صفًا وعمودًا؟ إن لم يكن كذلك، فهي على الأرجح ليست جدولًا.
| Tag | What it does |
|---|---|
| <table> | Wraps the whole grid |
| <tr> | One row |
| <td> | One data cell |
| <th> | One header cell |
The tags used in this lesson.
Try it live / جرّب بنفسك
Check yourself / اختبر نفسك
1. Which tag wraps one row of a table?
<tr> is one row; <td> is one cell inside it.
<tr> صف واحد، و <td> خلية واحدة بداخله.
2.
What is the real reason to use <th> instead of <td> for a column heading?
<th> بدل <td> لعنوان عمود؟The bold, centered look is just the default style. What matters is that a screen reader announces it as a header and links the data cells below it back to that label.
3. You want three things side by side on the page: a menu, a photo, and a price list. What should you use?
None of that is tabular data — it is page layout, and page layout is a job for CSS, not for <table>.
<table>.Score / النتيجة: 0 / 3
Your task / مهمتك
Build a real data table: a weekly price list or class schedule with at least three rows and two columns. Give it a header row with <th>, and use <td> for the data.
ابنِ جدول بيانات حقيقيًا: قائمة أسعار أسبوعية أو جدول حصص، بثلاثة صفوف وعمودين على الأقل. أعطه صف عنوان بـ <th>، واستخدم <td> للبيانات.
-
One
<table>with at least three<tr><table>واحد فيه ثلاثة<tr>على الأقل -
A header row using
<th>, not<td>صف عنوان باستخدام<th>لا<td> - Every row has the same number of cells كل صف فيه عدد الخلايا نفسه
- The table holds real tabular data, not page layout الجدول يحمل بيانات جدولية حقيقية، لا ترتيب صفحة