Tag: seo

  • Aria Attributes

    Aria Attributes

    Getting Real with ARIA Attributes for Web Accessibility

    Let’s talk about web accessibility—making sure everyone, including folks with disabilities, can use your website. ARIA (Accessible Rich Internet Applications) is here to help you beef up your web game so assistive technologies like screen readers can understand what’s going on. Here’s the lowdown on ARIA, why you should care, and how to use it without overthinking things.

    What’s the Deal with ARIA Attributes?

    ARIA attributes add extra meaning to your HTML so that assistive technologies know what’s what. They’re great for filling in the gaps when plain HTML doesn’t cut it for interactive stuff like dropdowns, sliders, or tabs. Think of ARIA as the subtitles for your web content—super helpful for people who need them.

    If you add html5 elements like <nav> <header> <footer> etc., then roles are implemented correctly. But with simple <div>, we need to inform browser/reader about elements role.

    Why Bother with ARIA?

    1. Make Stuff Accessible: ARIA helps you create fancy, dynamic content that works for everyone.
    2. Keep Things User-Friendly: Whether someone uses a mouse, keyboard, or screen reader, ARIA makes it easier for them to interact with your site.
    3. Stay on the Right Side of the Law: Accessibility isn’t optional anymore—it’s a legal and ethical must.

    ARIA Attributes You Should Know

    Roles: What Things Are

    Roles tell assistive tech what an element does:

    • role="button": Says, “This is a button.”
    • role="alert": Marks an area as a “Heads up! Something just happened.”
    • role="navigation": Identifies a navigation section.

    States: How Things Are Right Now

    States are dynamic. They change as users interact:

    • aria-expanded: Tells whether something like a dropdown is open or closed.
      <button aria-expanded="false">Menu</button>
    • aria-checked: Indicates if a checkbox or toggle is checked.
      <input type="checkbox" aria-checked="true">

    Properties: The Extra Details

    Properties give more context about an element. They usually stay the same:

    • aria-labelledby: Links to the ID of an element that labels something.
      <label id="label1">Name</label>
      <input type="text" aria-labelledby="label1">
    • aria-describedby: Points to an element that gives more details.
      <button aria-describedby="desc1">Info</button>
      <div id="desc1">This button opens the settings panel.</div>

    Pro Tips for Using ARIA

    1. Stick to HTML First: Native HTML elements already come with built-in accessibility. Use ARIA only when you really need it.
    2. Less is More: Don’t overdo it with ARIA. Adding too much can confuse assistive tech.
    3. Test Everything: Use screen readers like NVDA or VoiceOver, and tools like Axe or Lighthouse to check your work.
    4. Keep ARIA Updated: If a state changes (like aria-expanded), make sure you update it in real-time.
    5. Follow the Rules: Check the official WAI-ARIA docs if you’re unsure about anything.

    Avoid These Rookie Mistakes

    • Role Overkill: Don’t give elements roles they don’t need. It’ll mess things up.
    • Ignoring Keyboards: Make sure users can tab through and interact with everything.
    • Forgetting Updates: If you’re using dynamic ARIA states, update them properly or you’ll leave users in the dark.

    Wrapping Up

    ARIA attributes are like secret weapons for accessible web design. They’re powerful, but you’ve got to use them wisely. Stick to the basics, test everything, and always put yourself in the shoes of your users. Accessibility isn’t just about following rules—it’s about making the web a better place for everyone.

    Examples:

    Adding alt attribute to img tag

    <img src="path/to/image.ext" alt="alternative text to image">

    Getting label from other tag

    <div class="card">
    	<img src="path/to/image.ext" aria-labelledby="img-caption-1">
    	<div class="text-container">
    		<p id="img-caption-1">Description to card and image</p>
    		<button>Learn more</button>
    	</div>
    </div>