0Pricing
Web Accessibility Academy · درس

ربط الأخطاء بالحقول باستخدام aria-describedby

اجعلوا الرسالة تُقرأ مع حقل الإدخال

ربط الأخطاء بالحقول باستخدام aria-describedby درس مجاني في Web Accessibility Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Web Accessibility Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Web Accessibility Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

A Floating Error

An error message sitting near a field looks connected to you. But to a screen reader it is just loose text the user may never hear. ⚠️

The Fix Is a Link

You need to formally tie the message to its input. The attribute that does this is aria-describedby, and it lives on the field.

Point to an id

Give the error element an id, then set the input's aria-describedby to that same id. Now the two are officially linked.

<input id="email" aria-describedby="email-err">
<p id="email-err">Enter a valid email.</p>

What the User Hears

When focus lands on the input, the screen reader reads the label, the type, and then the description. The error is no longer orphaned.

Name Then Description

aria-describedby does not replace the label. The label gives the name; describedby adds extra info that is read after it.

Multiple Descriptions

You can list several ids, space-separated. The browser reads them in order, so you can join a hint and an error together.

<input aria-describedby="hint err">

Only When It Applies

Add the error id to aria-describedby only while the error is showing. Pointing at an empty or hidden node can read nothing or confuse users.

Keep the Text Real

The described element must hold real, visible text. aria-describedby reads its content, so an empty span describes nothing useful.

Hidden Targets Stay Silent

If the target has display none, most screen readers skip it. Keep error text rendered and visible so the description is actually announced.

Works With aria-invalid

Pair describedby with aria-invalid on the same field. One says this failed; the other says here is why. Together they tell the full story.

Not Just for Errors

The same attribute carries format hints too, like password rules. Errors are one common use, not the only one.

<input aria-describedby="pw-rule">
<p id="pw-rule">At least 8 characters.</p>

Quick Check

How do you make a screen reader read an error with its field?

Recap

Tie errors to fields with aria-describedby pointing at a real, visible id. The screen reader then reads the field and its error together. ✅

الأسئلة الشائعة

هل درس «ربط الأخطاء بالحقول باستخدام aria-describedby» مجاني؟

نعم — نص درس «ربط الأخطاء بالحقول باستخدام aria-describedby» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Web Accessibility Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Web Accessibility Academy 4 دروس في المجموع.

ماذا ستتعلم في «ربط الأخطاء بالحقول باستخدام aria-describedby»؟

اجعلوا الرسالة تُقرأ مع حقل الإدخال تتمرن على Web Accessibility Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Web Accessibility Academy؟

لا تُشترط خبرة سابقة. Web Accessibility Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «ربط الأخطاء بالحقول باستخدام aria-describedby»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Web Accessibility Academy هذا؟

نعم. كل درس في Web Accessibility Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. ربط الأخطاء بالحقول باستخدام aria-describedby
  2. تحديد الحالة غير الصالحة باستخدام aria-invalid
  3. نقل التركيز إلى أول خطأ
  4. مضمّن، أو عند فقدان التركيز، أو عند الإرسال: التوقيت مهم
← العودة إلى Web Accessibility Academy