https://www.htmhell.dev/adventcalendar/2023/4/ Skip to content 1. Hell 2. Heaven 3. Newsletter 4. Advent Calendar 5. HTMHell on Twitter 6. HTMHell homepage Back to Basics: 5 HTML attributes for improved accessibility and user experience by Daniela Kubesch published on Dec 04, 2023 In the fast-paced world of web development, it's easy to get caught up in the latest frameworks, libraries and cutting-edge technologies. But sometimes, the most impactful improvements come from revisiting the fundamentals. In this blog post, I'll guide you through five HTML attributes that not only improve accessibility but also enhance the overall user experience. Whether you are an experienced developer or just starting, let's explore the potential of these elements to create a more inclusive web experience. 1. hreflang The hreflang attribute specifies the language of a linked resource on an or element. It works like the lang attribute but is specifically used for links. Why use hreflang? You can improve the user experience and SEO by using hreflang for both internal and external site links. Using hreflang on internal website links provides a way to tell search engines about different variations of a page for other languages or regions. This means that English speakers would receive the English version of the site, while Swedish speakers would receive the Swedish version. There is no need for manual switching on the user's end, resulting in a smoother experience. How to use hreflang Add the hreflang attribute with the needed ISO language code to your element. For an English website, this would be en. English Website You can also be more specific with the language code and use regional variations. For example, we can add en-GB for British English. English Website If your website is available in multiple languages, you can use hreflang to specify the language and region of a document associated with a specific URL. Adding the attribute will help search engines understand the language and regional targeting of different web page versions. Add hreflang with the required language code to each link. One link should act as the default fallback version, identifiable by adding hreflang="x-default" instead of the language code. Lastly, set the value of the rel attribute to "alternate" for each link in the language switcher to indicate that the linked pages are alternatives to the present page. You can also use hreflang in your language switcher. English German Sometimes, language switchers use link text in the language they are switching to. You can indicate this by additionally using the lang attribute. English Deutsch Note: Adding the lang attribute is particularly important for assistive technology users. For instance, screen readers alter their voice and pronunciation based on the language attribute. An additional way to enhance accessibility is to include aria-current ="true" to the presently active link. English Deutsch 2. translate The translate attribute is used to indicate whether an element should be translated or not. Why use translate? Most website text is translatable by default (with some exceptions such as text on images or within SVGs). Translation tools, such as Google Translate, may suggest translation of page contents if the site's defined language differs from the browser's default language. However, there may be instances where this behaviour is unwanted. Specific terms like company names, e-mail addresses or code examples should generally not be translated to avoid confusion. Automated translations are not always completely accurate, particularly with niche or technical words. How to use translate You can use translate on any HTML element. Assign an empty string ("") or yes for translation and no to avoid translation.

Wien ist (wieder) die lebenswerteste Stadt der Welt!

Wien ist (wieder) die lebenswerteste Stadt der Welt!

Vienna named world's most liveable city (again)!

Wien named world's most liveable city (again)!

3. reversed The reversed attribute is used to reverse ordered lists (
    ) in the opposite order. Why use reversed? Using the reversed attribute keeps the order of visual and semantic list items the same, but they are numbered from highest to lowest. This means adding this attribute to your ordered list (
      ) will not reverse the list items but only the list numbers. For instance, this behaviour is helpful if you want to count down your top five desserts. However, the reversed attribute does not affect unordered lists (