ရိုးရိုးလေး ရှင်းပြမယ်
ရိုးရိုးလေး ရှင်းရရင်
<img> element က page ထဲကို ပုံတစ်ပုံ ထည့်ပါတယ်။ src က ပုံ file ရှိတဲ့နေရာ၊ alt က ပုံကို မမြင်ရတဲ့သူအတွက် ပုံရဲ့ စာသား အစားထိုးချက်ပါ။ Radio မှာ ပွဲတစ်ခုကို နားထောင်တာ စဉ်းစားကြည့်ပါ — မမြင်ရတဲ့ ပရိသတ်အတွက် ကွင်းထဲမှာ ဘာဖြစ်နေလဲ announcer က ပြောပြပေးပါတယ်။ alt text က အဲဒီ announcer ပါ။
Screen reader သုံးသူတွေ၊ internet နှေးလို့ ပုံ မပေါ်တဲ့သူတွေ၊ search engine တွေ အားလုံးက alt ကို ဖတ်ပါတယ်။ width နဲ့ height ကတော့ ပုံ မရောက်ခင်ကတည်းက နေရာ ဘယ်လောက် ချန်ထားရမလဲ browser ကို ပြောပေးပါတယ်။
Problem → Why → Solution
ပြဿနာ: alt မပါ၊ size မပါတဲ့ ပုံတွေ
Online shop တစ်ခုရဲ့ page ထိပ်မှာ banner ပုံ၊ product ပုံနဲ့ cart icon link တစ်ခု ရှိပါတယ်။ ဖုန်းနဲ့ ဖွင့်လိုက်တော့ banner ပုံ ရောက်လာတာနဲ့ page တစ်ခုလုံး အောက်ကို ခုန်ဆင်းသွားပြီး user က "Buy now" ကို နှိပ်မလို့ လုပ်တုန်း တခြားနေရာကို နှိပ်မိသွားပါတယ်။ Screen reader သုံးသူကတော့ "IMG_2041.jpg" နဲ့ "link, cart-icon.png" ဆိုတာကိုပဲ ကြားရပါတယ်။
<img src="banner.jpg">
<img src="IMG_2041.jpg" alt="image">
<a href="/cart"><img src="cart-icon.png"></a>
<p><button>Buy now</button></p>ဘာကြောင့် ဒီလို ဖြစ်တာလဲ
width နဲ့ height မရှိတော့ browser က ပုံ download ပြီးမှ အရွယ်အစားကို သိပြီး အဲဒီအချိန်ကျမှ နေရာ ဖွင့်ပေးလို့ အောက်က content တွေ ခုန်ဆင်းသွားပါတယ် — ဒါကို layout shift လို့ ခေါ်ပါတယ်။ alt မပါရင် screen reader အများစုက file နာမည်ကို ဖတ်ပြပြီး alt="image" ကလည်း ဘာမှ မပြောပါဘူး။ Link ထဲမှာ alt မပါတဲ့ ပုံတစ်ခုတည်း ရှိရင် link မှာ နာမည် လုံးဝ မရှိတော့ပါဘူး။
Core concept: alt က ပုံရဲ့ အလုပ်ကို ဖော်ပြတယ်
<img> က void element ပါ — closing tag မရှိပါဘူး။ src က ပုံ file ရဲ့ path ဒါမှမဟုတ် URL ဖြစ်ပြီး alt ကို အမြဲ ထည့်ရပါမယ်။ alt ထဲမှာ ဘာရေးရမလဲ ဆိုတာ ပုံရဲ့ အလုပ်ပေါ် မူတည်ပါတယ်။ သတင်းပေးတဲ့ ပုံ (photo, chart) ဆိုရင် ပုံကနေ ရရမယ့် အချက်ကို တိုတိုရှင်းရှင်း ရေးပါ။ "Image of" ဒါမှမဟုတ် "Photo of" နဲ့ မစပါနဲ့၊ screen reader က ပုံ ဖြစ်ကြောင်း ကြေညာပြီးသားပါ။ Link ဒါမှမဟုတ် button ထဲက ပုံဆိုရင် alt က ပုံရဲ့ ပုံပန်းသဏ္ဌာန် မဟုတ်ဘဲ action ကို ဖော်ပြရပါမယ် — cart icon ဆိုရင် "View cart" ပါ။
အလှဆင်ဖို့ သက်သက် ပုံ (decorative image) ဆိုရင် alt="" ဆိုပြီး alt ကို အလွတ် ထားပါ။ alt="" က "ဒီပုံကို ကျော်လိုက်ပါ" လို့ screen reader ကို ပြောတာပါ။ alt attribute ကို လုံးဝ မထည့်တာနဲ့ မတူပါဘူး — alt မပါရင် file နာမည်ကို ဖတ်ပြတတ်ပါတယ်။ Image load မဖြစ်ရင် browser က ပုံရှိရမယ့် နေရာမှာ alt text ကို ပြပါတယ်။
width နဲ့ height ကို unit မပါဘဲ pixel နဲ့ ရေးပါ (width="600" height="400")။ Browser က ဒီ ဂဏန်းနှစ်ခုကနေ ပုံရဲ့ aspect ratio ကို တွက်ပြီး ပုံ မရောက်ခင်ကတည်းက နေရာ ချန်ထားလို့ layout shift မဖြစ်တော့ပါဘူး။ ဒီ attribute တွေကို ဖယ်စရာ မလိုဘဲ CSS မှာ img { max-width: 100%; height: auto; } ထည့်လိုက်ရင် ကျဉ်းတဲ့ screen မှာ ပုံက အချိုးမပျက်ဘဲ ချုံ့သွားပါတယ်။ ဒါကြောင့် အဖြေက နှစ်ခုလုံး ပါ: HTML က ratio ကို ပေးပြီး CSS က အရွယ်အစားကို ထိန်းပါတယ်။
loading="lazy" က screen အောက်ပိုင်းမှာ ရှိတဲ့ ပုံတွေကို user scroll လုပ်ပြီး နီးလာမှ download လုပ်ခိုင်းလို့ data နဲ့ အချိန် ချွေတာပါတယ်။ Page ထိပ်ဆုံးက အဓိက ပုံကိုတော့ lazy မလုပ်ပါနဲ့၊ နောက်ကျပြီး ပေါ်လာပါမယ်။
- သတင်းပေးလား → အချက်ကို alt မှာ
- Link/button ထဲမှာလား → action ကို alt
- အလှသက်သက်လား → alt=""
- width/height + CSS height: auto
ပုံကို ဖုန်းထဲကနေ သူငယ်ချင်းကို ဖုန်းဆက်ပြီး ရှင်းပြရရင် ဘာပြောမလဲ — အဲဒါ alt ပါ။
အထွေထွေ ပုံစံ
<img src="path/to/file.jpg" alt="What the image tells the reader"
width="W" height="H">
<a href="/destination"><img src="icon.svg" alt="Action name" width="24" height="24"></a>
<img src="decoration.svg" alt="" width="W" height="H">
<img src="far-down.jpg" alt="..." width="W" height="H" loading="lazy">
<style>
img { max-width: 100%; height: auto; }
</style>img တိုင်းမှာ src, alt, width, height ပါပါတယ်။ alt ရဲ့ content က ပုံရဲ့ အလုပ်ပေါ် မူတည်ပြီး CSS rule တစ်ခုက ပုံအားလုံးကို responsive ဖြစ်စေပါတယ်။
Example: team page ပေါ်က ပုံသုံးမျိုး
Team photo ကို figure ထဲမှာ caption နဲ့ ထားပြီး decorative leaf icon တစ်ခု၊ page အောက်ပိုင်းက lazy-load ပုံတစ်ခုကို ထပ်ထည့်ထားပါတယ်။ Image file တွေကို HTML file နဲ့ folder တစ်ခုတည်းမှာ ထားပြီး စမ်းကြည့်ပါ၊ ပြီးရင် file တစ်ခုရဲ့ နာမည်ကို ပြောင်းပြီး alt text ပေါ်လာတာကို ကြည့်ပါ။
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Our team</title>
<style>
img { max-width: 100%; height: auto; }
</style>
</head>
<body>
<h1>Our team</h1>
<figure>
<img src="team-photo.jpg" alt="Our team working together" width="600" height="400">
<figcaption>The Golden Leaf team at the Yangon shop.</figcaption>
</figure>
<p>
<img src="leaf.svg" alt="" width="24" height="24">
We have been serving tea since 2019.
</p>
<img src="shop-front.jpg" alt="The shop's green front door under a hanging tea sign"
width="600" height="400" loading="lazy">
</body>
</html>Code ကို တစ်ပိုင်းချင်း ရှင်းပြမယ်
- Line 7
img { max-width: 100%; height: auto; }ပုံကို container ထက် ပိုမကျယ်စေဘဲ height: auto က width နဲ့အတူ height ကိုပါ အချိုးကျ လျှော့ပေးပါတယ်။ height: auto မပါရင် height attribute ရဲ့ 400 ကျန်နေပြီး ပုံ ပြားသွားပါတယ်။
- Line 13
<img src="team-photo.jpg" alt="Our team working together" width="600" height="400">width နဲ့ height က 3:2 ratio ကို ပေးလို့ ပုံ မရောက်ခင် နေရာ ချန်ထားပြီး alt က ပုံရဲ့ အချက်ကို ပြောပါတယ်။
- Line 14
<figcaption>The Golden Leaf team at the Yangon shop.</figcaption>Caption က လူတိုင်း မြင်ရတဲ့ စာသားဖြစ်ပြီး context ထပ်ပေးပါတယ်။ alt နဲ့ စာသား တူတူ မရေးပါနဲ့၊ screen reader သုံးသူက နှစ်ခါ ကြားရပါမယ်။
- Line 17
<img src="leaf.svg" alt="" width="24" height="24">Leaf icon က အလှဆင်မှု သက်သက်ဖြစ်ပြီး ဘာအချက်မှ မပေးလို့ alt="" ပါ။ Screen reader က ဒီပုံကို ကျော်ပြီး စာကြောင်းကိုပဲ ဖတ်ပါတယ်။
- Lines 20-21
<img src="shop-front.jpg" alt="The shop's green front door under a hanging tea sign" width="600" height="400" loading="lazy">Page အောက်ပိုင်းမှာ ရှိလို့ loading="lazy" ပေးထားပါတယ်၊ user scroll လုပ်ပြီး နီးလာမှ download လုပ်ပါတယ်။ Attribute များတဲ့အခါ line နှစ်ကြောင်း ခွဲရေးလို့ ရပါတယ်။
"Our team" heading အောက်မှာ 600×400 team photo နဲ့ အောက်က caption၊ ပြီးတော့ icon သေးသေးလေးနဲ့ "We have been serving tea since 2019." စာကြောင်း၊ နောက်ဆုံးမှာ ဆိုင်ရှေ့ ပုံ ပေါ်ပါမယ်။ 320px လို ကျဉ်းတဲ့ screen မှာ ပုံတွေက အချိုးမပျက်ဘဲ ကျဉ်းလာပါတယ်။ team-photo.jpg မရှိရင် ပုံရှိရမယ့်နေရာမှာ "Our team working together" ဆိုတဲ့ alt text ပေါ်ပါမယ်။alt ဆုံးဖြတ်ချက် table နဲ့ ပုံ ပြားသွားတဲ့ bug
| ပုံ | alt |
|---|---|
| ဆိုင်ရှေ့ photo | ဆိုင်ရှေ့ရဲ့ ထူးခြားချက်ကို ဖော်ပြတဲ့ စာကြောင်းတို |
| Logo က home page link ထဲမှာ | "Golden Leaf home" |
| Cart icon တစ်ခုတည်းပါတဲ့ link | "View cart" |
| Heading ဘေးက အလှ icon | alt="" |
| ဘေးက စာသားက ပြောပြီးသား ပုံ | alt="" (ထပ်မပြော) |
Headless Chromium မှာ 600×400 ပုံကို 320px အကျယ် screen မှာ စမ်းကြည့်တဲ့အခါ max-width: 100% တစ်ခုတည်းဆိုရင် ပုံက 304×400 ဖြစ်သွားပြီး ပြားသွားပါတယ်၊ height: auto ထည့်လိုက်တော့ 304×203 ဖြစ်ပြီး အချိုး မှန်ပါတယ်။ ပုံ load မဖြစ်သေးခင်လည်း width/height ကြောင့် 304×203 နေရာကို ချန်ထားပါတယ်။
<style>
/* On a 320px screen: 304 x 400, squashed */
.wrong { max-width: 100%; }
/* On a 320px screen: 304 x 203, in proportion */
.right { max-width: 100%; height: auto; }
</style>
<img class="wrong" src="team-photo.jpg" alt="Our team, squashed"
width="600" height="400">
<img class="right" src="team-photo.jpg" alt="Our team, in proportion"
width="600" height="400">လက်တွေ့ project တွေမှာ
Real project တွေမှာ ဘယ်လို သုံးလဲ
E-commerce site တွေမှာ product ပုံတိုင်းရဲ့ alt ကို CMS ထဲမှာ ဖြည့်ခိုင်းထားပြီး alt မပါရင် publish လုပ်လို့ မရအောင် စစ်ထားတာမျိုး ရှိပါတယ်။ Google Lighthouse လို tool တွေက alt မပါတဲ့ ပုံတွေကို accessibility ပြဿနာအဖြစ်၊ width/height မပါလို့ ဖြစ်တဲ့ layout shift ကို performance ပြဿနာ (Cumulative Layout Shift) အဖြစ် report လုပ်ပါတယ်။ ဒါကြောင့် framework အများစုရဲ့ image component တွေက width နဲ့ height ကို မဖြစ်မနေ တောင်းပါတယ်။
News site တွေက ဓာတ်ပုံတိုင်းကို figure ထဲမှာ ထားပြီး figcaption မှာ ဓာတ်ပုံဆရာ နာမည်နဲ့ context ကို ရေးကြပါတယ်။ ရှည်တဲ့ article တွေနဲ့ gallery တွေမှာ ပထမ screen ရဲ့ အောက်က ပုံတွေကို loading="lazy" နဲ့ ထားလို့ ဖုန်းမှာ page မြန်မြန် ပွင့်ပါတယ်။ Social media platform တွေကလည်း user တွေကို ပုံ upload လုပ်တဲ့အခါ alt text ထည့်ခွင့် ပေးကြပြီး ဒီ စာသားက HTML ရဲ့ alt attribute ထဲကို ရောက်သွားပါတယ်။
အမှားများ
အဖြစ်များတဲ့ အမှားတွေ
1. alt ကို လုံးဝ မထည့်တာ ဒါမှမဟုတ် အသုံးမဝင်တဲ့ alt
alt မပါရင် screen reader က "IMG_2041.jpg" လို file နာမည်ကို ဖတ်တတ်ပြီး alt="image", alt="photo" ကလည်း ဘာမှ မပြောပါဘူး။ ပုံကနေ ရရမယ့် အချက်ကို ရေးပါ၊ အလှသက်သက်ဆိုရင် alt="" ပါ။
2. Responsive ဖြစ်ဖို့ width/height ကို ဖယ်တာ
width/height ကို ဖယ်လိုက်ရင် browser က ratio ကို မသိတော့လို့ layout shift ပြန်ဖြစ်ပါတယ်။ Attribute တွေကို ထားပြီး CSS မှာ max-width: 100%; height: auto; ထည့်ပါ။
3. height: auto မေ့တာ
max-width: 100% တစ်ခုတည်းဆိုရင် ကျဉ်းတဲ့ screen မှာ width ပဲ ကျဉ်းပြီး height က attribute အတိုင်း ကျန်လို့ ပုံ ပြားသွားပါတယ်။ height: auto ကို အမြဲ တွဲရေးပါ။
4. Page ထိပ်က အဓိက ပုံကို lazy လုပ်တာ
Hero ပုံကို loading="lazy" ပေးရင် browser က နောက်ကျမှ download လုပ်လို့ user မြင်ရတဲ့ ပထမ screen နှေးပါတယ်။ Lazy ကို အောက်ပိုင်း ပုံတွေမှာပဲ သုံးပါ။
Best Practices
အကောင်းဆုံး အလေ့အကျင့်များ
- alt ကို ရေးပြီးရင် ပုံကို မကြည့်ဘဲ alt ကိုပဲ ဖတ်ကြည့်ပါ၊ page ရဲ့ အဓိပ္ပာယ် ပြည့်စုံသေးလား စစ်ပါ။
- Image file ကို ပြမယ့် အရွယ်အစားထက် အများကြီး မကြီးစေပါနဲ့၊ 4000px ဓာတ်ပုံကို 600px နေရာမှာ ပြရင် data အလကား ကုန်ပါတယ်။
- Logo နဲ့ icon တွေအတွက် SVG၊ ဓာတ်ပုံတွေအတွက် JPEG ဒါမှမဟုတ် WebP ကို ရွေးပါ။
- Chart လို ရှုပ်ထွေးတဲ့ ပုံဆိုရင် alt မှာ အဓိက အချက်ကို ရေးပြီး အသေးစိတ် data ကို ပုံဘေးက စာသား ဒါမှမဟုတ် table မှာ ထည့်ပါ။
Mini challenge
Mini challenge: product card
Tea set တစ်စုံအတွက် product card တစ်ခု ရေးပါ။ ပုံတိုင်းမှာ သူ့ အလုပ်နဲ့ ကိုက်တဲ့ alt ပါပြီး responsive ဖြစ်ရပါမယ်။
- Product photo: သတင်းပေးတဲ့ alt၊ width, height
- Cart icon တစ်ခုတည်းပါတဲ့ link: action ကို alt မှာ
- Decorative divider ပုံ: alt=""
- Card အောက်က gallery ပုံ: figure, figcaption, loading="lazy"၊ CSS rule တစ်ခုနဲ့ responsive
<!-- Place inside the <body> of a full page -->
<style>
/* TODO: one rule that makes every image shrink in proportion */
</style>
<h1>Celadon tea set</h1>
<!-- TODO: product photo (informative alt, width, height) -->
<!-- TODO: a link to /cart whose only content is an icon image -->
<!-- TODO: a decorative divider image -->
<!-- TODO: figure with a lazy-loaded gallery image and a figcaption -->ရလဒ်: ပုံတိုင်း ပေါ်ပြီး ဖုန်းအကျယ်မှာ အချိုးမပျက်ဘဲ ကျဉ်းပါမယ်။ Screen reader က product photo ကို ဖော်ပြချက်နဲ့၊ cart link ကို "View cart" အဖြစ် ဖတ်ပြီး divider ကို ကျော်သွားပါမယ်။
အရိပ်အမြွက် ကြည့်ရန်
Cart link ရဲ့ alt ကို "ဒီ link ကို နှိပ်ရင် ဘာဖြစ်မလဲ" လို့ မေးပြီး ရေးပါ။ Gallery ပုံရဲ့ alt နဲ့ figcaption ကို တူတူ မရေးပါနဲ့ — alt က မြင်ရတာကို၊ caption က context ကို ပြောပါတယ်။
အဖြေ ကြည့်ရန်
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Celadon tea set</title>
<style>
img { max-width: 100%; height: auto; }
</style>
</head>
<body>
<h1>Celadon tea set</h1>
<img src="tea-set.jpg" alt="A pale green teapot with four matching cups on a tray"
width="800" height="600">
<p>
<a href="/cart"><img src="cart.svg" alt="View cart" width="32" height="32"></a>
</p>
<img src="divider.svg" alt="" width="400" height="20">
<figure>
<img src="tea-set-detail.jpg" alt="Close-up of a cup's crackled glaze"
width="800" height="600" loading="lazy">
<figcaption>Each cup is glazed by hand, so no two are alike.</figcaption>
</figure>
</body>
</html>Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
မှတ်ထားရမယ့် အချက်များ
- <img> မှာ src နဲ့ alt အမြဲ ပါရပြီး alt က ပုံရဲ့ အလုပ်ကို ဖော်ပြပါတယ်။
- Link ထဲက ပုံရဲ့ alt က action၊ decorative ပုံရဲ့ alt က အလွတ် (alt="") ပါ။
- width/height ကို ထားပြီး CSS max-width: 100%; height: auto; နဲ့ responsive လုပ်ပါ။
- Page အောက်ပိုင်း ပုံတွေကို loading="lazy"၊ caption ကို figure နဲ့ figcaption နဲ့ ရေးပါ။