Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
HTML

HTML: Implement Accessibility (A11y) Best Practices

- 07.07.26 - ErcanOPAK

♿ Accessibility = Web for Everyone

Web is for everyone. Accessibility ensures equal access. Screen readers, keyboard navigation, inclusive design.

📝 Essential Accessibility

<!-- Semantic HTML -->
<!-- Use correct elements -->
<header></header>
<nav></nav>
<main></main>
<article></article>
<section></section>
<aside></aside>
<footer></footer>

<!-- ARIA Attributes -->
<button aria-label="Close dialog">×</button>

<div role="dialog" aria-labelledby="dialog-title">
    <h2 id="dialog-title">Confirm Action</h2>
</div>

<nav aria-label="Main navigation"></nav>

<!-- Landmarks -->
<header role="banner"></header>
<main role="main"></main>
<footer role="contentinfo"></footer>

<!-- Focus Management -->
<div tabindex="0">Focusable element</div>
<div tabindex="-1">Programmatically focusable</div>

<!-- Skip link -->
<a href="#main-content" class="skip-link">Skip to main content</a>

<!-- Image alt text -->
<img src="photo.jpg" alt="Description of image">
<img src="decorative.jpg" alt="" role="presentation">

🎯 Advanced Accessibility

<!-- Keyboard Navigation -->
<div role="button" tabindex="0" 
     onkeydown="if(event.key==='Enter' || event.key===' ') handleClick()" 
     onclick="handleClick()">Custom Button</div>

<!-- Live Regions -->
<div aria-live="polite" aria-atomic="true">Update message</div>
<div aria-live="assertive">Important alert!</div>

<!-- Form Labels -->
<label for="email">Email Address</label>
<input type="email" id="email" required aria-describedby="email-help">
<div id="email-help">We'll never share your email</div>

<!-- Required fields -->
<input type="text" required aria-required="true">

<!-- Error messages -->
<input type="text" aria-invalid="true" aria-describedby="error-message">
<div id="error-message" role="alert">Please enter a valid email</div>

<!-- Color contrast -->
/* Ensure 4.5:1 contrast ratio for text */

<!-- Focus indicators -->
*:focus {
    outline: 3px solid #005a9c;
    outline-offset: 2px;
}

<!-- Screen reader only -->
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

💡 Accessibility Checklist

  • Use semantic HTML
  • Provide alt text for images
  • Ensure keyboard navigation
  • Maintain color contrast
  • Label form elements
  • Use ARIA roles when needed
  • Test with screen readers
  • Provide captions for media

“Accessibility is inclusion. Web for everyone. Essential for modern web development.”

— Accessibility Specialist

Related posts:

HTML: Use Audio and Video Tags for Multimedia

HTML: Use Tables for Tabular Data

HTML: Use Viewport Meta Tag for Mobile Responsive Design

Post Views: 0

Post navigation

CSS: Use CSS Variables for Maintainable Styles
JavaScript: Understand Closures for Scope and Privacy

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

July 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  
« Jun    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (960)
  • How to add default value for Entity Framework migrations for DateTime and Bool (898)
  • How to make theater mode the default for Youtube (857)
  • Get the First and Last Word from a String or Sentence in SQL (840)
  • How to select distinct rows in a datatable in C# (814)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (597)
  • Add Constraint to SQL Table to ensure email contains @ (582)
  • Average of all values in a column that are not zero in SQL (545)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (512)
  • Find numbers with more than two decimal places in SQL (460)

Recent Posts

  • C#: Use Using Statements for Resource Management
  • C#: Use Lambda Expressions for Concise Code
  • SQL: Use GROUP BY for Data Aggregation
  • .NET Core: Master Routing for Clean URLs
  • Git: Use Reset to Undo Local Changes
  • Ajax: Use Axios for HTTP Requests
  • JavaScript: Understand Hoisting
  • HTML: Use Web Storage for Client-Side Data
  • CSS: Use Filter Effects for Visual Magic
  • Windows 11: Unlock God Mode for All Settings

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (960)
  • How to add default value for Entity Framework migrations for DateTime and Bool (898)
  • How to make theater mode the default for Youtube (857)
  • Get the First and Last Word from a String or Sentence in SQL (840)
  • How to select distinct rows in a datatable in C# (814)

Recent Posts

  • C#: Use Using Statements for Resource Management
  • C#: Use Lambda Expressions for Concise Code
  • SQL: Use GROUP BY for Data Aggregation
  • .NET Core: Master Routing for Clean URLs
  • Git: Use Reset to Undo Local Changes

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com