Blog>
Snippets

Ensure accessibility in Vue.js 3 for SEO

Provide an example that improves SEO by ensuring that the Vue.js 3 web app meets accessibility standards, such as ARIA landmark roles and correct tab index usage.
<template>
  <header role="banner">
    <!-- Content for Header -->
  </header>
  <main role="main">
    <h1 tabindex="0">Main Content Title</h1>
    <!-- More Main Content -->
  </main>
  <nav role="navigation" v-bind:aria-label="'Main Navigation'">
    <!-- Navigation Links -->
  </nav>
  <aside role="complementary">
    <!-- Sidebar Content -->
  </aside>
  <footer role="contentinfo">
    <!-- Footer Content -->
  </footer>
</template>

<script>
export default {
  name: 'App',
  methods: {
    // Define methods to improve accessibility if needed
  }
}
</script>
This template defines the primary ARIA landmark roles for the various sections in a Vue.js 3 application. ARIA roles such as 'banner', 'main', 'navigation', 'complementary', and 'contentinfo' are used to describe the purpose of regions in the document to assistive technology. The 'tabindex="0"' is used to include the h1 element in the tab order of the document for keyboard navigation.