Thuta Learning
HTML
BasicWeb Developmentအခြေခံ

Headings

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

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

  • Heading level ကို font size ကြည့်ပြီး မဟုတ်ဘဲ content ရဲ့ structure ကြည့်ပြီး ရွေးနိုင်ဖို့
  • ရှင်းလင်းတဲ့ <h1> တစ်ခု ရေးပြီး <h2>, <h3> တွေကို level မကျော်ဘဲ အဆင့်လိုက် စီနိုင်ဖို့
  • Heading level ကို မပြောင်းဘဲ CSS နဲ့ အရွယ်အစား ပြောင်းနိုင်ဖို့
  • Heading တွေချည်းပဲ ဖတ်ကြည့်ပြီး page ရဲ့ outline မှန်မမှန် စစ်နိုင်ဖို့

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

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

စာအုပ်တစ်အုပ်ရဲ့ မာတိကာ (table of contents) ကို စဉ်းစားကြည့်ပါ။ စာအုပ်နာမည် တစ်ခု ရှိတယ်၊ အခန်း (chapter) တွေ ရှိတယ်၊ အခန်းတစ်ခန်းထဲမှာ အပိုင်းငယ် (section) တွေ ရှိတယ်။ HTML heading တွေက web page အတွက် အဲဒီ မာတိကာပါပဲ — <h1> က စာအုပ်နာမည်၊ <h2> က chapter၊ <h3> က chapter ထဲက section ပါ။ <h6> အထိ level ခြောက်ဆင့် ရှိပါတယ်။

Browser က heading တွေကို default အနေနဲ့ စာလုံးကြီးကြီး၊ bold နဲ့ ပြပေးပါတယ်။ ဒါပေမယ့် အရွယ်အစားက ဘေးထွက်ဆိုးကျိုး (side effect) သက်သက်ပါ။ Heading ရဲ့ တကယ့် အလုပ်က "ဒီစာသားက နောက်က content အပိုင်းရဲ့ ခေါင်းစဉ်ပါ၊ ဒီ level မှာ ရှိပါတယ်" လို့ ကြေညာပေးတာပါ။

Problem → Why → Solution

ပြဿနာ: ကြည့်ကောင်းအောင် level ရွေးလိုက်တာ

အောက်က page ကို ရေးတဲ့သူက "Related posts" ခေါင်းစဉ်ကို စာလုံးသေးသေး လိုချင်လို့ <h5> ကို ရွေးလိုက်ပါတယ်။ "Free shipping" banner ကိုတော့ စာလုံးကြီးကြီး လိုချင်လို့ <h1> နောက်တစ်ခု သုံးလိုက်ပြီး "Ingredients" ကိုတော့ heading မသုံးဘဲ bold paragraph တစ်ခုနဲ့ပဲ ရေးလိုက်ပါတယ်။ မျက်စိနဲ့ ကြည့်ရင် page က အဆင်ပြေသလို ထင်ရပါတယ်။

recipe.html
<h1>Free shipping on all orders!</h1>
<h1>Coconut Noodle Soup</h1>
<p><b>Ingredients</b></p>
<p>Noodles, coconut milk, chicken, onion.</p>
<h5>Related posts</h5>

ဘာကြောင့် ပြဿနာ ဖြစ်တာလဲ

Screen reader သုံးသူတွေက page တစ်ခုကို heading list ကနေ လမ်းလျှောက်ကြတာ များပါတယ်၊ keyboard shortcut တစ်ခုနဲ့ heading တစ်ခုကနေ နောက်တစ်ခုဆီ ခုန်ကြပါတယ်။ ဒီ page မှာ သူတို့ ကြားရမှာက main title နှစ်ခု (တစ်ခုက ကြော်ငြာ)၊ "Ingredients" က list ထဲမှာ လုံးဝ မပါဘူး၊ "Related posts" ကတော့ level 2, 3, 4 မရှိဘဲ level 5 ကို ရုတ်တရက် ရောက်လာတာပါ။ Search engine တွေနဲ့ အလိုအလျောက် table of contents ထုတ်ပေးတဲ့ tool တွေလည်း ဒီ structure အမှားကိုပဲ ယုံပြီး အလုပ်လုပ်ပါတယ်။

Core concept: level က rank ပါ၊ size မဟုတ်ပါ

Heading element ခြောက်ခု ရှိပါတယ်: <h1>, <h2>, <h3>, <h4>, <h5>, <h6>။ ဂဏန်းက rank ကို ဆိုလိုပါတယ်။ <h2> တစ်ခုက အပိုင်းအသစ်တစ်ခုကို စတင်ပြီး နောက် <h2> ဒါမှမဟုတ် ပိုမြင့်တဲ့ heading တစ်ခု မရောက်မချင်း အဲဒီ အပိုင်း ဆက်ရှိနေပါတယ်။ အဲဒီကြားထဲက <h3> တွေက အဲဒီ <h2> ရဲ့ အပိုင်းခွဲတွေ ဖြစ်ပါတယ်။ ဒီနည်းနဲ့ heading တွေက page ကို သစ်ပင်ပုံ (tree) outline တစ်ခုအဖြစ် ဖွဲ့စည်းပေးပါတယ်။

<h1> က page တစ်ခုလုံးရဲ့ ခေါင်းစဉ်ပါ — ဒီ page က ဘာအကြောင်းလဲ ဆိုတာပါ။ HTML standard က <h1> အများကြီး ထားခွင့်ပြုပေမယ့် accessibility guide တွေနဲ့ team အများစုက page တစ်ခုမှာ main <h1> တစ်ခုပဲ ထားဖို့ အကြံပြုကြပါတယ်။ ရှေးက spec မှာ <section> ထဲက <h1> ကို level နိမ့်အဖြစ် အလိုအလျောက် ပြောင်းပေးမယ့် "outline algorithm" ဆိုတာ ရှိခဲ့ပေမယ့် browser တွေနဲ့ screen reader တွေ တကယ် implement မလုပ်ခဲ့လို့ spec ကနေ ဖယ်ရှားလိုက်ပါပြီ။ ဒါကြောင့် level ကို ကိုယ်တိုင် တိတိကျကျ ရေးရပါတယ်။

အဆင့်ဆင်းတဲ့အခါ တစ်ဆင့်ချင်း ဆင်းပါ: <h2> နောက်မှာ အပိုင်းခွဲ လိုရင် <h3>၊ <h5> မဟုတ်ပါဘူး။ အဆင့်တက်တဲ့အခါကတော့ ကျော်လို့ ရပါတယ် — <h4> ပြီးရင် <h2> အသစ်တစ်ခုနဲ့ အပိုင်းကြီးအသစ် စလို့ ရပါတယ်၊ အဲဒါက "အပိုင်းခွဲတွေ ပြီးပြီ" လို့ ပြောတာပါ။

Browser ရဲ့ default stylesheet က <h1> ကို 2em၊ <h2> ကို 1.5em လို အရွယ်အစားတွေ ပေးပြီး <h5>, <h6> ကို ပုံမှန်စာထက် သေးအောင် ပြပါတယ်။ ဒါတွေက default သက်သက်ပါ။ CSS နဲ့ <h2> ကို သေးအောင်၊ <h4> ကို ကြီးအောင် ပြောင်းလို့ ရလို့ "ဒီစာ သေးချင်တယ်" ဆိုတာ heading level ရွေးဖို့ အကြောင်းပြချက် ဘယ်တော့မှ မဖြစ်သင့်ပါဘူး။

Heading ထဲက စာသားကို တိုတိုနဲ့ ရှင်းရှင်း ရေးပါ — နောက်က အပိုင်းမှာ ဘာပါလဲ ဆိုတာကို ဖော်ပြတဲ့ label တစ်ခုပါ။ Slogan၊ tagline ဒါမှမဟုတ် ခေါင်းစဉ်အောက်က subtitle လို စာသားတွေက heading မဟုတ်လို့ <p> နဲ့ ရေးပါ။ Heading ကို ခေါင်းစဉ် တကယ်ဖြစ်တဲ့ စာသားအတွက်ပဲ သုံးပါ။

မှတ်ထားရမယ့် ပုံစံ: မာတိကာ ရေးသလို
  1. Page ရဲ့ topic ကို <h1> တစ်ခု
  2. အပိုင်းကြီးတစ်ခုစီကို <h2>
  3. အပိုင်းထဲက ခေါင်းစဉ်ခွဲကို <h3>
  4. အရွယ်အစားနဲ့ အရောင်ကို CSS

Heading တွေချည်းပဲ ဖတ်ကြည့်လို့ မာတိကာ မှန်မှန်ကန်ကန် ထွက်လာရင် level တွေ မှန်ပါတယ်။

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

html
<h1>Page topic</h1>
  <h2>Major part</h2>
    <h3>Subtopic</h3>
    <h3>Subtopic</h3>
  <h2>Next major part</h2>
    <h3>Subtopic</h3>
      <h4>Detail</h4>

Indent ကို outline မြင်သာအောင် ထည့်ထားတာပါ၊ browser က indent ကို ဂရုမစိုက်ပါဘူး။ Level တစ်ခုကို ဆင်းတိုင်း ဂဏန်းက တစ်ခုပဲ တိုးပြီး အပိုင်းအသစ်ကို စတဲ့အခါ level မြင့်တဲ့ heading ဆီ ပြန်တက်လို့ ရပါတယ်။

Example: tutorial page တစ်ခုရဲ့ outline

ဒီ page မှာ <h1> တစ်ခု၊ <h2> နှစ်ခု၊ <h3> သုံးခု ပါပါတယ်။ Heading တစ်ခုစီရဲ့ နောက်မှာ အဲဒီ အပိုင်းရဲ့ content ဖြစ်တဲ့ paragraph တစ်ခု ပါပါတယ်။ Browser မှာ ဖွင့်ကြည့်ပြီး heading တွေချည်းပဲ ဖတ်ကြည့်ပါ — မာတိကာတစ်ခု ထွက်လာပါမယ်။

headings.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>HTML Full Tutorial</title>
</head>
<body>
  <h1>HTML Full Tutorial</h1>
  <p>Learn to build web pages from the ground up.</p>

  <h2>HTML Basics</h2>
  <h3>Elements and Tags</h3>
  <p>An element is a start tag, some content and an end tag.</p>
  <h3>Attributes</h3>
  <p>Attributes add extra information to an element.</p>

  <h2>Text Content</h2>
  <h3>Headings</h3>
  <p>Headings give the page an outline.</p>
</body>
</html>

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

  1. Line 8<h1>HTML Full Tutorial</h1>

    Page တစ်ခုလုံးရဲ့ topic ကို ဖော်ပြတဲ့ <h1> တစ်ခုတည်းပါ။ <title> နဲ့ စာသား ဆင်တူလေ့ ရှိပေမယ့် <title> က browser tab မှာ ပေါ်ပြီး <h1> က page ထဲမှာ ပေါ်ပါတယ်။

  2. Line 9<p>Learn to build web pages from the ground up.</p>

    Tagline က ခေါင်းစဉ် မဟုတ်လို့ <p> ဖြစ်ပါတယ်။ ဒါကို <h2> လုပ်လိုက်ရင် outline ထဲမှာ အပိုင်းအသစ် မှားပြီး ပေါ်လာပါမယ်။

  3. Lines 11-12<h2>HTML Basics</h2> <h3>Elements and Tags</h3>

    <h2> က အပိုင်းကြီးတစ်ခုကို စပြီး ချက်ချင်း <h3> နဲ့ အပိုင်းခွဲ စပါတယ်။ Level တစ်ဆင့်ပဲ ဆင်းလို့ outline မှာ ကွက်လပ် မရှိပါဘူး။

  4. Line 14<h3>Attributes</h3>

    ဒုတိယ <h3> က ပထမ <h3> ရဲ့ အပိုင်းကို ပိတ်ပြီး "HTML Basics" အောက်မှာပဲ အပိုင်းခွဲ အသစ်တစ်ခု စပါတယ်။ ညီအစ်ကို (sibling) နှစ်ယောက်ပါ။

  5. Line 17<h2>Text Content</h2>

    <h3> ကနေ <h2> ကို ပြန်တက်တာက "HTML Basics" အပိုင်း ပြီးသွားပြီလို့ ပြောတာပါ။ အဆင့်တက်တဲ့အခါ ဒီလို ပြန်တက်တာ မှန်ပါတယ်။

You should see
"HTML Full Tutorial" က အကြီးဆုံး bold စာအဖြစ် ပေါ်ပြီး "HTML Basics" နဲ့ "Text Content" က နည်းနည်းသေးပါတယ်၊ "Elements and Tags", "Attributes", "Headings" က ထပ်သေးပါတယ်။ Heading တစ်ခုစီရဲ့ အောက်မှာ သူ့ paragraph ရှိပါတယ်။ Heading တွေချည်း ဖတ်ရင်: HTML Full Tutorial > HTML Basics (Elements and Tags, Attributes) > Text Content (Headings)။

Level ကို မပြောင်းဘဲ အမြင်ကို ပြောင်းနည်း

Design က sidebar ထဲက "Related posts" ခေါင်းစဉ်ကို သေးသေးလေး လိုချင်တယ် ဆိုပါစို့။ မှန်ကန်တဲ့ အဖြေက structure အရ ဖြစ်သင့်တဲ့ level (ဒီနေရာမှာ <h2>) ကို ရေးပြီး class တစ်ခု ပေးကာ CSS နဲ့ အရွယ်အစား ပြောင်းတာပါ။ HTML က "ဒါ ဘာလဲ" ကို ပြောပြီး CSS က "ဘယ်လို ပုံပေါက်မလဲ" ကို ပြောပါတယ်။

sidebar.html
<style>
  .sidebar-title {
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
</style>

<h2 class="sidebar-title">Related posts</h2>
<p>Five tips for cleaner HTML</p>
Levelဘာအတွက် သုံးလဲ
<h1>Page တစ်ခုလုံးရဲ့ topic (တစ်ခုတည်း)
<h2>Page ရဲ့ အပိုင်းကြီးတွေ
<h3><h2> တစ်ခုအောက်က အပိုင်းခွဲတွေ
<h4> - <h6>ရှည်တဲ့ documentation လို နက်တဲ့ structure

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

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

Documentation site တွေနဲ့ blog engine အများစုက article ထဲက <h2> နဲ့ <h3> တွေကို စုပြီး "On this page" ဆိုတဲ့ table of contents ကို အလိုအလျောက် ထုတ်ပေးကြပါတယ်။ Level တွေ မှားရင် အဲဒီ navigation ကလည်း မှားပြီး ထွက်လာပါတယ်။ CMS editor တွေမှာ "Heading 2", "Heading 3" ဆိုပြီး dropdown ပေးထားတာလည်း ဒီ level တွေကိုပဲ ရွေးခိုင်းနေတာပါ။

Accessibility audit tool တွေ (ဥပမာ axe ဒါမှမဟုတ် Lighthouse) က heading level ကျော်တာနဲ့ page မှာ <h1> မရှိတာကို စစ်ပေးပါတယ်။ Screen reader တွေမှာ heading list ကို ဖွင့်ပြီး ကိုယ်လိုချင်တဲ့ အပိုင်းဆီ တန်းသွားလို့ ရလို့ ရှည်တဲ့ page တွေမှာ heading တွေက အဓိက လမ်းညွှန်ပါ။ Search engine တွေကလည်း page က ဘာအကြောင်းလဲ နားလည်ဖို့ heading စာသားကို signal တစ်ခုအဖြစ် သုံးကြပါတယ်။ Team တွေက page အသစ်တစ်ခု review လုပ်တဲ့အခါ browser extension တစ်ခုနဲ့ heading outline ကို ထုတ်ကြည့်ပြီး မာတိကာလို ဖတ်လို့ ရမရ စစ်လေ့ ရှိပါတယ်။

အမှားများ

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

1. Font size အတွက် level ရွေးတာ

<h2> ရဲ့ နောက်မှာ စာလုံးသေးချင်လို့ <h5> ရေးလိုက်ရင် outline မှာ level 3 နဲ့ 4 ပျောက်သွားပါတယ်။ Structure အရ <h3> ကို ရေးပြီး font-size ကို CSS နဲ့ လျှော့ပါ။

2. Bold paragraph ကို heading အတု လုပ်တာ

<p><b>Ingredients</b></p> က heading လို ပုံပေါက်ပေမယ့် heading list ထဲမှာ မပါပါဘူး။ Screen reader သုံးသူက ဒီ အပိုင်းကို ခုန်သွားလို့ မရပါဘူး။ ခေါင်းစဉ်ဖြစ်ရင် <h2> လို heading element အစစ်ကို သုံးပါ။

3. ကြီးချင်တဲ့ စာတိုင်းကို <h1> ပေးတာ

Promotion banner၊ logo၊ card title တစ်ခုစီကို <h1> ပေးလိုက်ရင် page ရဲ့ topic ဘာလဲဆိုတာ မရှင်းတော့ပါဘူး။ <h1> ကို page ရဲ့ main topic အတွက် ချန်ထားပြီး banner စာသားကို <p> နဲ့ CSS နဲ့ ရေးပါ။

Best Practices

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

  • Content ရေးခင် heading outline ကို အရင် ချရေးပါ၊ outline ရှင်းရင် page ရှင်းပါတယ်။
  • Heading စာသားကို ဖတ်ရုံနဲ့ အဲဒီ အပိုင်းမှာ ဘာပါလဲ သိနိုင်အောင် ရေးပါ ("More" လို မဟုတ်ဘဲ "Shipping costs")။
  • Heading styling အားလုံးကို CSS file ထဲမှာ ထားပြီး HTML ထဲမှာ level ကိုပဲ ဂရုစိုက်ပါ။

Mini challenge

Mini challenge: ဟင်းချက်နည်း page ရဲ့ outline

ဟင်းချက်နည်း page တစ်ခုကို heading level မှန်မှန်နဲ့ ရေးပါ။ "Steps" အပိုင်းအောက်မှာ အပိုင်းခွဲ နှစ်ခု ရှိပြီး sidebar ခေါင်းစဉ်ကို CSS နဲ့ သေးအောင် လုပ်ရပါမယ်။

  • ဟင်းနာမည်ကို <h1> တစ်ခုတည်း
  • Ingredients, Steps, Related recipes ကို <h2>
  • Steps အောက်မှာ Prepare နဲ့ Cook ကို <h3>
  • Related recipes ကို class နဲ့ CSS သုံးပြီး သေးအောင် ပြ
recipe.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Recipe</title>
  <style>
    /* TODO: a class rule that makes the sidebar heading small */
  </style>
</head>
<body>
  <!-- TODO: the dish name as the page's only <h1> -->

  <!-- TODO: an "Ingredients" part with a short paragraph -->

  <!-- TODO: a "Steps" part with "Prepare" and "Cook" subsections -->

  <!-- TODO: a "Related recipes" part using the small class -->
</body>
</html>

ရလဒ်: Heading outline က: Coconut Noodle Soup > Ingredients, Steps (Prepare, Cook), Related recipes ဖြစ်ပြီး "Related recipes" က <h2> ဖြစ်ပေမယ့် ပုံမှန်စာအရွယ်လောက်ပဲ ပေါ်ပါမယ်။

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

အရင်ဆုံး heading တွေချည်းပဲ ရေးပြီး မာတိကာလို ဖတ်ကြည့်ပါ။ ပြီးမှ paragraph တွေ ဖြည့်ပါ။ "Related recipes" က အပိုင်းကြီးတစ်ခုမို့ level က <h2> ပါ၊ သေးတာက CSS ရဲ့ အလုပ်ပါ။

အဖြေ ကြည့်ရန်
recipe.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Coconut Noodle Soup</title>
  <style>
    .small-heading {
      font-size: 1rem;
      color: #555;
    }
  </style>
</head>
<body>
  <h1>Coconut Noodle Soup</h1>
  <p>A rich noodle soup ready in about forty minutes.</p>

  <h2>Ingredients</h2>
  <p>Egg noodles, coconut milk, chicken, onion, chickpea flour.</p>

  <h2>Steps</h2>
  <h3>Prepare</h3>
  <p>Slice the onion and cut the chicken into small pieces.</p>
  <h3>Cook</h3>
  <p>Simmer the chicken in coconut milk, then serve over noodles.</p>

  <h2 class="small-heading">Related recipes</h2>
  <p>Fish noodle soup, chicken curry.</p>
</body>
</html>

Quick Quiz 1 / 3

Page မှာ <h1> ရှိပြီး "Pricing" ဆိုတဲ့ <h2> အောက်မှာ "Monthly plan" ဆိုတဲ့ ခေါင်းစဉ်ခွဲ ထည့်ချင်ပါတယ်။ ဘယ် level ကို သုံးသင့်လဲ။

Quick Quiz 2 / 3

Designer က article အောက်ခြေက "Comments" ခေါင်းစဉ်ကို သေးသေးလေး လိုချင်ပါတယ်။ အဲဒါက article ရဲ့ အပိုင်းကြီးတစ်ခု ဖြစ်ပါတယ်။ အကောင်းဆုံး ဖြေရှင်းနည်းက ဘာလဲ။

Quick Quiz 3 / 3

Screen reader သုံးသူတစ်ယောက်အတွက် heading level မှန်မှန်ကန်ကန် ရှိတာက ဘာကို အဓိက ပေးလဲ။

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

  • <h1> ကနေ <h6> အထိ ဂဏန်းက rank ပါ၊ font size မဟုတ်ပါ။
  • Page တစ်ခုမှာ main topic အတွက် <h1> တစ်ခု ထားပြီး အဆင့်ဆင်းတဲ့အခါ တစ်ဆင့်ချင်း ဆင်းပါ။
  • အရွယ်အစား၊ အရောင်တွေကို CSS နဲ့ ပြောင်းပါ၊ level ကို ပြောင်းစရာ မလိုပါ။
  • Heading တွေချည်း ဖတ်ကြည့်လို့ မာတိကာ ကောင်းကောင်း ထွက်လာရင် structure မှန်ပါတယ်။

HTML Living Standard — Sections and Semantics — WHATWG

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

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

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

Headings | Thuta Learning