Vue.js 3.0 Tutorial
Vue.js 3.0 Component Advanced
Vue.js 3.0 Transitions & Animations
Vue.js 3.0 Reusable & Combinable
Vue.js 3.0 Advanced
Vue.js 3.0 Tools
Vue.js 3.0 Scale
Vue.js 3.0 Accessibility
Vue.js 3.0 Migrating from Vue2
Vue.js 3.0 Contribute Documentation
Vue.js 3.0 API References
Vue.js 3.0 Style Guide
HTML semantics refers to using the correct HTML elements for their intended purpose. For example, using a <nav>
element for navigation, <header>
for a header, <footer>
for a footer, and so on. This is important because it helps machines (like search engine crawlers and screen readers) understand the content and structure of your webpage.
Here's a basic example of how you can use semantic HTML in a Vue 3.0 component:
<template> <section> <header> <h1>{{ title }}</h1> </header> <nav> <ul> <li v-for="(item, index) in menu" :key="index"> <a :href="item.link">{{ item.text }}</a> </li> </ul> </nav> <main> <p>{{ content }}</p> </main> <footer> <p>{{ footer }}</p> </footer> </section> </template> <script> export default { data() { return { title: 'My App', menu: [ { text: 'Home', link: '#' }, { text: 'About', link: '#' }, { text: 'Contact', link: '#' }, ], content: 'This is the main content of my app.', footer: 'This is the footer of my app.', }; }, }; </script>
In this Vue.js component:
<section>
to group related content together.<header>
is used to contain the heading of the section.<nav>
element for navigation.<main>
element is used for the main content of the document.<footer>
element for the footer.While Vue.js doesn't specifically enforce semantic HTML, as a developer, it's your responsibility to structure your HTML correctly and semantically. This can be beneficial not only for accessibility and SEO, but also for understanding and maintaining your code.
ARIA Roles and Vue 3.0:
<template> <button aria-label="Close" @click="closeModal">X</button> </template> <script> export default { methods: { closeModal() { // Close modal logic }, }, }; </script>
Proper Use of HTML Elements in Vue 3.0:
<template> <nav> <ul> <li><a href="/">Home</a></li> <li><a href="/about">About</a></li> </ul> </nav> </template>
Vue 3.0 Semantic Component Naming:
<script> export default { name: 'AccessibleModal', // ... }; </script>
Vue 3.0 Semantic Attributes and Properties:
<template> <img :src="imageSrc" alt="Vue Logo" aria-describedby="logoDescription"> <p id="logoDescription">Vue.js Logo</p> </template> <script> export default { data() { return { imageSrc: 'vue-logo.png', }; }, }; </script>
Vue 3.0 HTML5 Semantic Elements:
<header>
, <nav>
, <main>
, <article>
, <footer>
, etc., for improved document structure.<template> <article> <header> <h1>{{ articleTitle }}</h1> <p>Published on: {{ publishDate }}</p> </header> <main> <!-- Article content goes here --> </main> <footer> <p>Author: {{ author }}</p> </footer> </article> </template> <script> export default { data() { return { articleTitle: 'Vue 3.0 Accessibility', publishDate: '2023-01-01', author: 'Your Name', }; }, }; </script>