aria-label وaria-labelledby وaria-describedby
توفير أسماء وأوصاف ميسّرة للعناصر
aria-label وaria-labelledby وaria-describedby درس مجاني في HTML Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في HTML Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة HTML Academy 4 دروس في المجموع.
أهمية الأسماء المتاحة للوصول
يحتاج كل عنصر تفاعلي إلى اسم متاح للوصول — وهو سلسلة نصية تستخدمها تقنيات المساعدة للتعرّف عليه. ومن دون اسم متاح للوصول، لا تستطيع قارئات الشاشة إخبار المستخدمين بوظيفة الزر أو حقل الإدخال.
aria-label
توفر aria-label اسمًا نصيًا متاحًا للوصول مباشرةً على العنصر:
<button aria-label="Close dialog">×</button>
<!-- The × character has no accessible meaning
aria-label provides the name: 'Close dialog, button' -->
<input type="search" aria-label="Search products">
<!-- No visible label — aria-label provides the accessible name -->aria-labelledby
تشير aria-labelledby إلى عنصر آخر ليكون الاسم المتاح للوصول:
<h2 id="section-title">Billing Information</h2>
<form aria-labelledby="section-title">
<!-- Form's accessible name is 'Billing Information' -->
</form>
<!-- Multiple id references: -->
<button aria-labelledby="action-verb object-name">
Delete
</button>
<span id="object-name" hidden>User Account</span>
<!-- Screen reader: 'Delete User Account, button' -->aria-describedby
توفر aria-describedby وصفًا موسّعًا (إضافةً إلى الاسم):
<label for="pwd">Password</label>
<input
type="password"
id="pwd"
aria-describedby="pwd-hint"
>
<p id="pwd-hint">Must be 8+ characters with one uppercase letter and one number.</p>
<!-- Screen reader: 'Password [input]' then reads the description on focus -->التسمية مقابل الوصف
الفرق بين الاسم والوصف المتاحين للوصول:
- الاسم المتاح للوصول — يعرّف العنصر (aria-label أو aria-labelledby أو عنصر label)
- الوصف — يضيف سياقًا إضافيًا إلى الاسم (aria-describedby)
- تعلن قارئات الشاشة: الاسم، والدور، والحالة → ثم الوصف
aria-label على المعالم
استخدموا aria-label للتمييز بين معالم متعددة من النوع نفسه:
<nav aria-label="Primary">...</nav>
<nav aria-label="Breadcrumb">...</nav>
<!-- Screen reader landmark list:
'Primary, navigation'
'Breadcrumb, navigation' -->
<!-- When only one nav, aria-label is optional but still helpful -->aria-labelledby على الأقسام
اربطوا الأقسام بعناوينها لتوفير سياق لمستخدمي قارئات الشاشة:
<section aria-labelledby="about-heading">
<h2 id="about-heading">About Our Team</h2>
<p>We are a team of passionate developers...</p>
</section>
<!-- Screen reader: 'About Our Team, region' when entering section -->aria-label مقابل النص المرئي
تتجاوز aria-label النص المرئي — فاستخدموها بحذر:
<button aria-label="Delete account permanently">
Delete
</button>
<!-- Screen reader hears: 'Delete account permanently'
Sighted user reads: 'Delete' -->
<!-- Best practice: visible text and aria-label should agree
If possible, include extra context in visible text too:
<button>Delete account permanently</button> -->
<!-- aria-label should start with the visible text when possible
for speech recognition users who use voice commands -->aria-describedby للأخطاء
اربطوا رسائل الخطأ بحقول الإدخال الخاصة بها:
<label for="email">Email</label>
<input
type="email"
id="email"
aria-describedby="email-error"
aria-invalid="true"
>
<span id="email-error" role="alert">
Please enter a valid email address.
</span>
<!-- When input receives focus, screen reader reads:
'Email [field], invalid. Please enter a valid email address.' -->مراجع aria-describedby متعددة
يمكن أن تشير aria-describedby إلى عناصر متعددة:
<input
type="password"
aria-label="New password"
aria-describedby="pwd-hint pwd-strength"
>
<p id="pwd-hint">Must be 8+ characters.</p>
<meter id="pwd-strength" aria-label="Password strength" value="2" max="4">Medium</meter>
<!-- Both elements are announced as the description -->التسميات المرئية مقابل المخفية
عندما لا يكون وضع تسمية مرئية ممكنًا، استخدموا الفئة sr-only:
<label for="search" class="sr-only">Search</label>
<input type="search" id="search" placeholder="Search...">
/* Visually hidden but in accessibility tree: */
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0,0,0,0);
white-space: nowrap;
border: 0;
}تحقق سريع
ما الفرق بين aria-label وaria-labelledby؟
مراجعة: تسميات ARIA
أساسيات التسمية المتاحة للوصول:
aria-label— اسم نصي مضمن للعناصر التي لا تملك تسميات مرئيةaria-labelledby— تشير إلى نص مرئي موجود باستخدام idaria-describedby— وصف إضافي (يُقرأ بعد الاسم)- فضّلوا التسميات المرئية وعناصر label الأصلية في HTML
- تميّز aria-label على المعالم بين المناطق المتعددة من النوع نفسه
الأسئلة الشائعة
هل درس «aria-label وaria-labelledby وaria-describedby» مجاني؟
نعم — نص درس «aria-label وaria-labelledby وaria-describedby» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة HTML Academy، انتقل إلى CoddyKit PRO. تتضمن دورة HTML Academy 4 دروس في المجموع.
ماذا ستتعلم في «aria-label وaria-labelledby وaria-describedby»؟
توفير أسماء وأوصاف ميسّرة للعناصر تتمرن على HTML Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ HTML Academy؟
لا تُشترط خبرة سابقة. HTML Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «aria-label وaria-labelledby وaria-describedby»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس HTML Academy هذا؟
نعم. كل درس في HTML Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- متى تستخدمون ARIA بدلًا من HTML الأصلي
- role وbutton وalert وdialog وlandmark
- aria-label وaria-labelledby وaria-describedby
- aria-hidden وaria-live