0Pricing
Design Systems & Component Libraries · บทเรียน

แนวทางปฏิบัติที่ดีที่สุดด้านการเข้าถึง (a11y)

นำหลักการออกแบบที่ครอบคลุมไปใช้ เพื่อให้องค์ประกอบของคุณเข้าถึงได้สำหรับผู้ใช้ทุกคน รวมถึงผู้พิการ

แนวทางปฏิบัติที่ดีที่สุดด้านการเข้าถึง (a11y) เป็นบทเรียน Design Systems & Component Libraries ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Design Systems & Component Libraries และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Design Systems & Component Libraries มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

What is Accessibility (a11y)?

Accessibility, often shortened to a11y, means designing and building products that everyone can use, regardless of their abilities.

  • It ensures people with disabilities can perceive, understand, navigate, and interact with your UI components.
  • This includes users with visual, auditory, motor, and cognitive impairments.
  • Building accessible components benefits all users, improving overall usability.

Why a11y Matters

Ignoring accessibility can exclude a significant portion of your potential users. Beyond ethical considerations, there are strong practical and legal reasons:

  • Wider Audience: Reach more users globally.
  • Improved SEO: Many a11y practices align with good SEO.
  • Legal Compliance: Avoid potential lawsuits and comply with laws like the ADA.
  • Better UX for All: Features like keyboard navigation or clear contrast help everyone.

WCAG: The Guiding Standard

The Web Content Accessibility Guidelines (WCAG) are the international standard for web accessibility, developed by the W3C.

WCAG is structured around four main principles, often remembered by the acronym POUR:

  • Perceivable: Information must be presented in ways users can perceive.
  • Operable: Interface components and navigation must be operable.
  • Understandable: Information and the operation of the user interface must be understandable.
  • Robust: Content must be robust enough to be interpreted reliably by a wide range of user agents, including assistive technologies.

Semantic HTML: The Foundation

Using the correct HTML elements is the most fundamental step for accessibility. Semantic HTML provides meaning to content, which assistive technologies can understand.

For example, use a <button> for a button, not a <div> styled to look like one. This gives it built-in keyboard interaction and roles.

Try running this example:

<!DOCTYPE html>
<html>
<head>
  <title>Semantic Button</title>
</head>
<body>
  <button onclick="alert('Clicked!')">
    Click Me (Semantic)
  </button>
  <div style="
    padding: 10px;
    border: 1px solid blue;
    display: inline-block;
    cursor: pointer;
    margin-left: 10px;
  " onclick="alert('Clicked!')">
    Click Me (Non-Semantic)
  </div>
</body>
</html>

ARIA Attributes: Enhancing Semantics

Sometimes, native HTML isn't enough to convey the full meaning or state of a complex UI component. This is where WAI-ARIA (Web Accessibility Initiative - Accessible Rich Internet Applications) comes in.

ARIA attributes provide additional semantic information to assistive technologies, but they don't change how an element looks or behaves for sighted users.

  • Roles: Define the type of UI element (e.g., role="alert", role="navigation").
  • States: Describe the current condition of an element (e.g., aria-expanded="true", aria-checked="false").
  • Properties: Give attributes to an element (e.g., aria-labelledby="heading").

Using ARIA Labels

The aria-label attribute is crucial for providing an accessible name for elements that might otherwise lack one, or whose visual label isn't sufficient.

It's often used for icon-only buttons or when a button's purpose isn't clear from its visual text alone.

Try running this example:

<!DOCTYPE html>
<html>
<head>
  <title>ARIA Label Example</title>
  <style>
    .icon-button {
      background: none;
      border: none;
      font-size: 24px;
      cursor: pointer;
    }
  </style>
</head>
<body>
  <button class="icon-button" aria-label="Delete item">
    🗑️
  </button>
  <p>The trash icon button has an accessible name "Delete item" for screen readers.</p>
</body>
</html>

Keyboard Navigation & Focus

Many users, including those with motor impairments or who are blind, navigate websites using only a keyboard. Ensure all interactive elements are reachable and operable via keyboard.

  • Tab Order: Elements should be navigable in a logical order using the Tab key.
  • Focus Indicators: Make sure the focused element is clearly visible (e.g., with an outline).
  • Interactive Elements: Buttons, links, and form controls should be operable with Enter or Space.
  • tabindex: Use tabindex="0" for elements not naturally focusable but needing to be, and tabindex="-1" to make elements focusable programmatically but not via tab key. Avoid tabindex values greater than 0.

Color Contrast for Readability

Sufficient color contrast between text and its background is vital for users with low vision or color blindness. WCAG recommends specific contrast ratios:

  • Normal Text: At least 4.5:1 contrast ratio.
  • Large Text (18pt/24px or 14pt/18.66px bold): At least 3:1 contrast ratio.
  • UI Components/Graphical Objects: At least 3:1 contrast ratio against adjacent colors.

Use online contrast checkers or browser developer tools to verify your color choices.

Alternative Text for Images

Images convey visual information, but screen readers cannot 'see' them. The alt attribute provides a textual description of an image.

  • Descriptive alt: For informative images, describe the content and function.
  • Empty alt (alt=""): For purely decorative images that don't convey essential information.
  • Avoid Redundancy: Don't start with "Image of..." if it's obvious.

Try running this example:

<!DOCTYPE html>
<html>
<head>
  <title>Alt Text Example</title>
</head>
<body>
  <img src="https://via.placeholder.com/150/0000FF/FFFFFF?text=Blue+Square" 
       alt="A blue square" width="150" height="150">
  <p>The image above has an alt text description for screen readers.</p>
  
  <img src="https://via.placeholder.com/150/CCCCCC/000000?text=Decorative" 
       alt="" width="150" height="150">
  <p>This image is decorative and has an empty alt attribute.</p>
</body>
</html>

Accessibility Check

Which of the following practices is BEST for ensuring a button is accessible to all users, especially those using screen readers?

Recap: Building Inclusive UIs

In this lesson, we explored the critical aspects of building accessible UI components. We learned that a11y ensures everyone can use your products, following WCAG principles.

  • Semantic HTML is the foundation.
  • ARIA attributes enhance semantics for complex components.
  • Keyboard navigation is essential for operability.
  • Color contrast ensures readability.
  • Alt text describes images for screen readers.

By applying these best practices, you create a more inclusive and robust user experience for all.

คำถามที่พบบ่อย

บทเรียน “แนวทางปฏิบัติที่ดีที่สุดด้านการเข้าถึง (a11y)” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “แนวทางปฏิบัติที่ดีที่สุดด้านการเข้าถึง (a11y)” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Design Systems & Component Libraries ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Design Systems & Component Libraries มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “แนวทางปฏิบัติที่ดีที่สุดด้านการเข้าถึง (a11y)”

นำหลักการออกแบบที่ครอบคลุมไปใช้ เพื่อให้องค์ประกอบของคุณเข้าถึงได้สำหรับผู้ใช้ทุกคน รวมถึงผู้พิการ คุณปฏิบัติ Design Systems & Component Libraries ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Design Systems & Component Libraries หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Design Systems & Component Libraries บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “แนวทางปฏิบัติที่ดีที่สุดด้านการเข้าถึง (a11y)” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Design Systems & Component Libraries นี้ได้ไหม

ได้ บทเรียน Design Systems & Component Libraries ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. องค์ประกอบไร้สถานะเทียบกับมีสถานะ
  2. พร็อปส์ สถานะ และการจัดการเหตุการณ์
  3. แนวทางปฏิบัติที่ดีที่สุดด้านการเข้าถึง (a11y)
  4. การประกอบและรูปแบบ Children
← กลับไปที่ Design Systems & Component Libraries