Thuta Learning
HTML
IntermediateWeb Developmentအခြေခံ

Table Caption & Scope

HTMLသင်ခန်းစာ 2025 မိနစ်

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Table တစ်ခုစီကို ရည်ရွယ်ချက် ပြောတဲ့ caption တိုတို ပေးနိုင်ဖို့
  • Column header မှာ scope="col"၊ row header မှာ scope="row" ကို မှန်မှန် သုံးနိုင်ဖို့
  • Screen reader က data cell တစ်ခုကို ဘယ် header တွေနဲ့ တွဲဖတ်မလဲ ကြိုတွက်နိုင်ဖို့
  • colgroup / rowgroup scope နဲ့ headers attribute ကို ဘယ်အချိန် လိုအပ်လဲ ဆုံးဖြတ်နိုင်ဖို့

ရိုးရိုးလေး ရှင်းပြမယ်

ရိုးရိုးလေး ရှင်းရရင်

ဇယားတစ်ခုကို မျက်စိနဲ့ ကြည့်တဲ့အခါ "6,250" ကို တွေ့ရင် ဘယ်ဘက်ကို ကြည့်လိုက်တာနဲ့ February၊ အပေါ်ကို ကြည့်လိုက်တာနဲ့ Sales ဆိုတာ ချက်ချင်း သိပါတယ်။ Screen reader user ကတော့ cell တစ်ခုချင်းကို နားနဲ့ ကြားရတာမို့ အဲဒီလို "ကြည့်လိုက်" လို့ မရပါဘူး။

ဒါကြောင့် HTML က browser ကို "ဒီ cell က ဒီ row header နဲ့ ဒီ column header နဲ့ ဆိုင်တယ်" လို့ ရှင်းရှင်း ပြောပေးရပါတယ်။ caption က ဇယားရဲ့ နာမည်ကို ပြောပြီး th နဲ့ scope က header တစ်ခုစီ ဘယ်ဘက်ကို ညွှန်လဲ ပြောပါတယ်။

Problem → Why → Solution

ပြဿနာ: header တွေ ပုန်းနေတဲ့ ဇယား

Sales report ဇယား တစ်ခုမှာ header row ကို td နဲ့ b tag နဲ့ ရေးထားပြီး လ နာမည်တွေကိုလည်း td ထဲ ထည့်ထားပါတယ်။ Caption မရှိလို့ page မှာ ဇယား သုံးခု ရှိရင် screen reader ရဲ့ table စာရင်းမှာ နာမည်မဲ့ "table" သုံးခုပဲ ပေါ်ပါတယ်။ User က ဇယားထဲ ဝင်ပြီး cell တွေကို ရွှေ့ကြည့်တဲ့အခါ "6,250"၊ "148" ဆိုတဲ့ ဂဏန်းတွေကိုပဲ ကြားရပြီး ဘယ်လ၊ ဘာ data လဲ မှတ်ထားရပါတယ်။

report.html
<table>
  <tr><td><b>Month</b></td><td><b>Sales</b></td><td><b>Orders</b></td></tr>
  <tr><td>January</td><td>5,000</td><td>120</td></tr>
  <tr><td>February</td><td>6,250</td><td>148</td></tr>
</table>

ဘာကြောင့် bold လုပ်ရုံ မလုံလောက်တာလဲ

b က စာလုံးကို မည်းစေရုံပဲ၊ cell ရဲ့ role ကို မပြောင်းပါဘူး။ Browser မှာ header cell မရှိရင် data cell တွေကို ဘယ် header နဲ့ တွဲရမလဲ မသိလို့ screen reader က ဂဏန်းကိုပဲ ဖတ်ပါတယ်။ th ကို သုံးပြီး scope ပေးလိုက်ရင် "February, Sales, 6,250" လို context ပါတဲ့ announcement ရနိုင်ပါတယ်။

Core concept: caption က နာမည်၊ scope က ညွှန်ပြချက်

caption က table ရဲ့ ပထမဆုံး child ဖြစ်ရပြီး table ရဲ့ accessible name ဖြစ်လာပါတယ်။ Screen reader user တွေက page ပေါ်က table တွေကို နာမည်နဲ့ စာရင်းပြုစုပြီး ရှာကြလို့ "Monthly sales, January to March" လို တိုတိုနဲ့ ရှင်းတဲ့ caption က table ကို မဝင်ခင်ကတည်းက ဘာအကြောင်းလဲ သိစေပါတယ်။ Caption က မျက်စိနဲ့ ကြည့်သူတွေအတွက်လည်း ဇယားခေါင်းစဉ် ဖြစ်ပါတယ်၊ ပုံစံကို CSS နဲ့ ပြောင်းနိုင်ပါတယ်။

scope valueHeader က ဘယ်ကို ညွှန်လဲ
colသူ့အောက်က column တစ်ခုလုံး
rowသူ့ညာဘက်က row တစ်ခုလုံး
colgroupcolgroup နဲ့ သတ်မှတ်ထားတဲ့ column အုပ်စု
rowgroupသူ ရှိနေတဲ့ thead/tbody/tfoot row အုပ်စု

Browser တွေက scope မပါတဲ့ ရိုးရှင်းတဲ့ table တွေမှာ ပထမ row ရဲ့ th တွေကို column header၊ ပထမ column ရဲ့ th တွေကို row header လို့ ခန့်မှန်းပေးပါတယ်။ ဒါပေမယ့် ခန့်မှန်းချက်က browser နဲ့ screen reader အလိုက် ကွာနိုင်ပြီး header row နှစ်ခု ရှိတာ၊ header က အလယ်မှာ ရှိတာလို အခြေအနေမှာ မှားတတ်ပါတယ်။ scope ကို ထည့်လိုက်တာက ခန့်မှန်းစရာ မလိုအောင် ပြောလိုက်တာပါ၊ ကုန်ကျစရိတ်လည်း attribute တစ်ခုပဲ ဖြစ်ပါတယ်။

Header နှစ်ဆင့် ရှိတဲ့ table တွေမှာ (ဥပမာ "Term 1" အောက်မှာ Maths နဲ့ English) အပေါ်ဆုံး header ကို colspan နဲ့ scope="colgroup" ပေးပြီး colgroup element နဲ့ column အုပ်စုကို သတ်မှတ်ပါတယ်။ scope နဲ့ မဖော်ပြနိုင်လောက်အောင် ရှုပ်ထွေးမှပဲ th တွေကို id ပေးပြီး td မှာ headers="id1 id2" နဲ့ တိုက်ရိုက် ချိတ်ပါ — ဒါပေမယ့် အဲဒီ အဆင့် ရောက်ရင် table ကို ခွဲလို့ ရမလား အရင် စဉ်းစားပါ။

Header စာသားတွေကိုလည်း နားနဲ့ ကြားရင် နားလည်အောင် ရေးပါ။ "Qty" ထက် "Quantity"၊ "$" ထက် "Sales (USD)" က ပိုရှင်းပါတယ်။ Cell အလွတ်ကို screen reader က "blank" လို့ ဖတ်တတ်လို့ "None" ဒါမှမဟုတ် "—" လို တန်ဖိုး ထည့်ပေးပါ။ ခေတ်ဟောင်း summary attribute က obsolete ဖြစ်လို့ ဇယားကို ပိုရှင်းပြချင်ရင် caption ထဲမှာ ဒါမှမဟုတ် table ရှေ့က paragraph မှာ ရေးပါ။

မှတ်ထားရမယ့် ပုံစံ: cell တိုင်းမှာ လိပ်စာ နှစ်ခု
  1. caption က ဇယားကို နာမည်ပေး
  2. Column header: th scope="col"
  3. Row header: th scope="row"
  4. td = row header + column header

Data cell တစ်ခုကို ကြားတဲ့အခါ "ဘယ် row၊ ဘယ် column" ဆိုတဲ့ မေးခွန်း နှစ်ခုကို markup က ဖြေပေးနိုင်ရပါမယ်။

အထွေထွေ ပုံစံ

html
<table>
  <caption>Purpose of the table</caption>
  <tr>
    <th scope="col">Row label heading</th>
    <th scope="col">Column heading</th>
  </tr>
  <tr>
    <th scope="row">Row heading</th>
    <td>Value</td>
  </tr>
</table>

အပေါ်ဆုံး row ရဲ့ th တွေက scope="col" ဖြစ်ပြီး row တစ်ခုစီရဲ့ ပထမ cell က scope="row" ပါတဲ့ th ပါ။ ကျန်တဲ့ cell တွေက td ပါ။

Example: လစဉ် sales report

Border တွေကို border="1" attribute နဲ့ မဟုတ်ဘဲ CSS နဲ့ ဆွဲထားပါတယ်။ Data cell တိုင်းမှာ row header (လ) နဲ့ column header (တိုင်းတာချက်) နှစ်ခုစလုံး ရှိနေပြီး th တိုင်းက scope နဲ့ ဘယ်ဘက်ကို label လုပ်လဲ ပြောထားတာကို သတိထားကြည့်ပါ။

sales-report.html
<style>
  table { border-collapse: collapse; }
  th, td { border: 1px solid #999; padding: 0.4rem 0.8rem; }
  th[scope="row"] { text-align: left; }
  td { text-align: right; }
</style>

<table>
  <caption>Monthly sales, January to March</caption>
  <thead>
    <tr>
      <th scope="col">Month</th>
      <th scope="col">Sales (USD)</th>
      <th scope="col">Orders</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">January</th>
      <td>5,000</td>
      <td>120</td>
    </tr>
    <tr>
      <th scope="row">February</th>
      <td>6,250</td>
      <td>148</td>
    </tr>
    <tr>
      <th scope="row">March</th>
      <td>5,800</td>
      <td>133</td>
    </tr>
  </tbody>
</table>

Code ကို တစ်ပိုင်းချင်း ရှင်းပြမယ်

  1. caption<caption>Monthly sales, January to March</caption>

    Table ရဲ့ ပထမ child ဖြစ်ပြီး accessible name ဖြစ်လာပါတယ်။ ဘာ data၊ ဘယ်ကာလလဲ နှစ်ခုလုံး ပြောထားပါတယ်။

  2. Column header<th scope="col">Sales (USD)</th>

    ဒီ header က သူ့အောက်က column တစ်ခုလုံးနဲ့ ဆိုင်ပါတယ်။ Unit (USD) ကို header မှာ ရေးထားလို့ cell တွေမှာ $ ထပ်ရေးစရာ မလိုပါဘူး။

  3. Row header<th scope="row">February</th>

    Row ရဲ့ ပထမ cell က td မဟုတ်ဘဲ th ဖြစ်ပြီး scope="row" က ညာဘက်က cell တွေ အားလုံးနဲ့ ဆိုင်ကြောင်း ပြောပါတယ်။

  4. Data cell<td>6,250</td>

    ဒီ cell မှာ ကိုယ်ပိုင် label မလိုပါဘူး — row header February နဲ့ column header Sales (USD) က context ကို ပေးပါတယ်။

  5. Alignmentth[scope="row"] { text-align: left; }

    th ရဲ့ default က အလယ်ကပ် ဖြစ်လို့ row header တွေကို ဘယ်ကပ် ပြန်ထားပါတယ်။ scope attribute ကို CSS selector အဖြစ်လည်း သုံးနိုင်တာကို သတိပြုပါ။

You should see
"Monthly sales, January to March" caption အောက်မှာ column 3 ခု၊ row 4 ခု ပါတဲ့ ဇယား ပေါ်ပါတယ်:
Month | Sales (USD) | Orders
January | 5,000 | 120
February | 6,250 | 148
March | 5,800 | 133
Header တွေနဲ့ လ နာမည်တွေ စာလုံးမည်း၊ လ နာမည်တွေ ဘယ်ကပ်၊ ဂဏန်းတွေ ညာကပ် ဖြစ်ပါတယ်။ Accessibility tree မှာ လ နာမည်တွေက row header၊ ထိပ်ဆုံး row က column header ဖြစ်ပါတယ်။

Header နှစ်ဆင့်: colgroup scope

အောက်က ဇယားမှာ "Term 1" နဲ့ "Term 2" က column နှစ်ခုစီရဲ့ အပေါ်မှာ ရှိပါတယ်။ colgroup element တွေက column အုပ်စုကို သတ်မှတ်ပြီး scope="colgroup" က header ကို အဲဒီ အုပ်စုနဲ့ ချိတ်ပါတယ်။ ဒါကြောင့် Aye ရဲ့ 90 ကို "Aye, Term 2, Maths" လို header သုံးခုနဲ့ တွဲဖတ်နိုင်ပါတယ်။ colgroup scope မပါရင် Maths column နှစ်ခုက အသံအတူတူ ထွက်ပြီး နားထောင်သူက ရမှတ်တစ်ခု ဘယ် term ကလဲ ခွဲမသိနိုင်ပါဘူး။

exam-results.html
<table>
  <caption>Exam results by term</caption>
  <colgroup><col></colgroup>
  <colgroup span="2"></colgroup>
  <colgroup span="2"></colgroup>
  <thead>
    <tr>
      <th scope="col" rowspan="2">Student</th>
      <th scope="colgroup" colspan="2">Term 1</th>
      <th scope="colgroup" colspan="2">Term 2</th>
    </tr>
    <tr>
      <th scope="col">Maths</th><th scope="col">English</th>
      <th scope="col">Maths</th><th scope="col">English</th>
    </tr>
  </thead>
  <tbody>
    <tr><th scope="row">Aye</th><td>85</td><td>78</td><td>90</td><td>82</td></tr>
    <tr><th scope="row">Ko Ko</th><td>72</td><td>88</td><td>75</td><td>91</td></tr>
  </tbody>
</table>

လက်တွေ့ project တွေမှာ

Real project တွေမှာ ဘယ်လို သုံးလဲ

အစိုးရ website တွေ၊ ဘဏ်တွေ၊ ပညာရေး platform တွေလို accessibility စံနှုန်း (WCAG) ကို လိုက်နာရတဲ့ project တွေမှာ data table တိုင်းမှာ caption နဲ့ header ဆက်စပ်မှု ရှိမရှိကို audit လုပ်ပါတယ်။ WCAG 2.2 ရဲ့ success criterion 1.3.1 "Info and Relationships" က မျက်စိနဲ့ မြင်ရတဲ့ ဖွဲ့စည်းပုံကို code ထဲမှာလည်း ဖော်ပြရမယ်လို့ တောင်းဆိုပြီး th နဲ့ scope က ဇယားအတွက် အဲဒါကို ဖြည့်ဆည်းတဲ့ နည်းလမ်းပါ။ axe, Lighthouse လို tool တွေက header မရှိတဲ့ data table တွေကို ဖမ်းနိုင်ပေမယ့် caption ရဲ့ အဓိပ္ပာယ် ရှိမရှိကိုတော့ လူကပဲ စစ်ရပါတယ်။

Sort လုပ်လို့ရတဲ့ dashboard table တွေမှာ column header ထဲမှာ button တစ်ခု ထည့်ပြီး လက်ရှိ sort လုပ်ထားတဲ့ column ရဲ့ th မှာ aria-sort="ascending" ဒါမှမဟုတ် "descending" ကို ထည့်ကြပါတယ်။ ဒါမှ မျက်စိနဲ့ မြင်ရတဲ့ မြှားလေးရဲ့ အဓိပ္ပာယ်ကို screen reader user တွေလည်း သိရပါတယ်။

အမှားများ

အဖြစ်များတဲ့ အမှားတွေ

1. Row header ကို td နဲ့ ရေးတာ

Column header တွေကို th လုပ်ပြီး row ရဲ့ ပထမ cell (လ နာမည်၊ product နာမည်) ကို td ထဲမှာ ထားခဲ့တာ အဖြစ်အများဆုံးပါ။ Data cell တွေက column header နဲ့ပဲ တွဲဖတ်ခံရပြီး ဘယ် row လဲ ဆိုတာ ပျောက်သွားပါတယ်။ အဲဒီ cell ကို <th scope="row"> ပြောင်းပါ။

2. Caption အစား table အပြင်က heading ကို သုံးတာ

<h3>Monthly sales</h3> ကို table ရဲ့ အပေါ်မှာ ထားရုံနဲ့ table ရဲ့ နာမည် မဖြစ်ပါဘူး၊ table စာရင်းမှာ နာမည်မဲ့ ကျန်နေပါတယ်။ Heading က page ဖွဲ့စည်းပုံအတွက် လိုရင် ထားလို့ ရပေမယ့် table ထဲမှာ caption ကိုလည်း ထည့်ပါ (ဒါမှမဟုတ် aria-labelledby နဲ့ heading ကို ချိတ်ပါ)။

3. scope ကို td ပေါ်မှာ ထည့်တာ

scope ကို td ပေါ်မှာ ထည့်ခွင့် မရှိပါဘူး (HTML5 မှာ obsolete)၊ ဒါကြောင့် <td scope="row"> က header မဖြစ်ပါဘူး။ Header ဖြစ်ရမယ့် cell ကို th အဖြစ် ပြောင်းမှ scope က အလုပ်လုပ်ပါတယ်။

Best Practices

အကောင်းဆုံး အလေ့အကျင့်များ

  • Caption ကို စကားလုံး အနည်းငယ်နဲ့ ရေးပါ — ဘာ data လဲ၊ ဘယ်ကာလ/ဘယ်အုပ်စုလဲ။
  • Header တွေမှာ အတိုကောက် မသုံးပါနဲ့၊ မဖြစ်မနေ လိုရင် abbr element နဲ့ အပြည့်အစုံကို ပေးပါ။
  • Screen reader (Windows မှာ NVDA, Mac မှာ VoiceOver) နဲ့ table navigation key တွေသုံးပြီး ဇယားကို တစ်ခါလောက် ကိုယ်တိုင် နားထောင်ကြည့်ပါ။
  • အရောင်တစ်ခုတည်းနဲ့ အဓိပ္ပာယ် မပေးပါနဲ့ ("အနီရောင် cell တွေက နောက်ကျ")၊ စာသား ဒါမှမဟုတ် icon ပါ ထည့်ပါ။

Mini challenge

Mini challenge: အတန်းချိန်ဇယား

Grade 9 အတွက် နေ့ သုံးရက်၊ အချိန် သုံးပိုင်း ပါတဲ့ အတန်းချိန်ဇယား ရေးပါ။ Screen reader user က cell တိုင်းကို နေ့ နဲ့ အချိန် နှစ်ခုစလုံးနဲ့ တွဲကြားရပါမယ်။

  • ရည်ရွယ်ချက် ပြောတဲ့ caption ပါရမယ်
  • ထိပ်ဆုံး row မှာ "Day" နဲ့ အချိန် သုံးခု (9:00, 10:00, 11:00) ကို th scope="col" နဲ့ ရေးရမယ်
  • Monday, Tuesday, Wednesday ကို th scope="row" နဲ့ ရေးရမယ်
  • Cell အလွတ် မရှိရ — စာသင်ချိန် မရှိရင် "Free period" ရေးရမယ်
timetable.html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Timetable</title>
</head>
<body>
  <table>
    <!-- TODO: caption -->
    <thead>
      <!-- TODO: one row: Day + three time-slot column headers -->
    </thead>
    <tbody>
      <!-- TODO: three rows, each starting with a day row header -->
    </tbody>
  </table>
</body>
</html>

ရလဒ်: "Grade 9 timetable, Monday to Wednesday" caption အောက်မှာ Day | 9:00 | 10:00 | 11:00 header row နဲ့ နေ့ သုံးရက်ရဲ့ row တွေ ပေါ်ပါတယ်။ Accessibility tree မှာ ထိပ်ဆုံး row ရဲ့ cell 4 ခုက column header၊ နေ့ နာမည်တွေက row header ဖြစ်ပြီး ဥပမာ Tuesday ရဲ့ 10:00 cell ("Free period") ကို Tuesday နဲ့ 10:00 နှစ်ခုစလုံးနဲ့ ချိတ်ထားပါတယ်။

အရိပ်အမြွက် ကြည့်ရန်

Row တစ်ခုစီမှာ cell လေးခု ရှိရပါမယ် — နေ့အတွက် th တစ်ခုနဲ့ အချိန်အတွက် td သုံးခု။ ထိပ်ဆုံး ဘယ်ဘက် cell "Day" ကလည်း သူ့အောက်က နေ့ column ကို ညွှန်လို့ scope="col" ပါ။

အဖြေ ကြည့်ရန်
timetable.html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Timetable</title>
  <style>
    table { border-collapse: collapse; }
    th, td { border: 1px solid #999; padding: 0.3rem 0.6rem; }
    th[scope="row"] { text-align: left; }
  </style>
</head>
<body>
  <table>
    <caption>Grade 9 timetable, Monday to Wednesday</caption>
    <thead>
      <tr>
        <th scope="col">Day</th>
        <th scope="col">9:00</th>
        <th scope="col">10:00</th>
        <th scope="col">11:00</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row">Monday</th>
        <td>Maths</td><td>English</td><td>Science</td>
      </tr>
      <tr>
        <th scope="row">Tuesday</th>
        <td>History</td><td>Free period</td><td>Maths</td>
      </tr>
      <tr>
        <th scope="row">Wednesday</th>
        <td>Science</td><td>Art</td><td>English</td>
      </tr>
    </tbody>
  </table>
</body>
</html>

Quick Quiz 1 / 3

Sales ဇယား row တစ်ခုရဲ့ ပထမဆုံး cell "January" ကို ဘယ်လို ရေးသင့်လဲ။

Quick Quiz 2 / 3

caption element ကို ဘယ်နေရာမှာ ထားရမလဲ။

Quick Quiz 3 / 3

ဇယားရဲ့ ရည်ရွယ်ချက်ကို screen reader user တွေကို ပြောဖို့ ဘယ်နည်းက မှန်လဲ။

မှတ်ထားရမယ့် အချက်များ

  • Data table တိုင်းမှာ table ရဲ့ ပထမဆုံး child အဖြစ် ရည်ရွယ်ချက် ပြောတဲ့ caption တိုတို ထည့်ပါ။
  • Column header တွေကို th scope="col"၊ row header တွေကို th scope="row" နဲ့ ရေးပါ၊ ဒါမှ td တိုင်းမှာ row နဲ့ column context နှစ်ခုလုံး ရှိပါမယ်။
  • Header နှစ်ဆင့် ရှိရင် colgroup နဲ့ scope="colgroup" ကို သုံးပြီး headers/id ကို နောက်ဆုံး နည်းလမ်းအဖြစ်ပဲ ထားပါ။
  • Header ကို နားနဲ့ ကြားရင် နားလည်အောင် ရေးပြီး cell အလွတ် မထားပါနဲ့၊ summary attribute ကို မသုံးပါနဲ့။

Web Content Accessibility Guidelines (WCAG) 2.2 — W3C

နောက်ဆုံးပြင်ဆင်ရက်

Progress ကို ဤ browser (ဤစက်) တွင်သာ သိမ်းထားပါသည်။ အခြားစက်များနှင့် sync မလုပ်ပါ။

ဤသင်ခန်းစာတွင် အမှားတွေ့ပါက အကြောင်းကြားရန်သင့် email app ကို ဤသင်ခန်းစာလိပ်စာ ဖြည့်ပြီးသားဖြင့် ဖွင့်ပေးပါမည် — သင်ကိုယ်တိုင် ပို့မှသာ ပို့မည်ဖြစ်သည်။

Table Caption & Scope | Thuta Learning