🎓 A1Learner
🔍
0 of 50 lessons completed

Template Attributes

A template attribute is an HTML attribute in a Vue template. The attribute adds detail to an element.

A class attribute

This line names the style group greeting.

<p class="greeting">Hello, Vue!</p>

An id attribute

This line gives the element the name welcome.

<p id="welcome">Hello, Vue!</p>

A link attribute

This line links to the Vue site.

<a href="https://vuejs.org">Vue site</a>

Example

<script setup>
const message = 'Hello, Vue!'
</script>
<template>
  <div>
    <p class="greeting" id="welcome">{{ message }}</p>
    <a href="https://vuejs.org">Vue site</a>
  </div>
</template>

Key points

  • A template attribute is an HTML attribute in a Vue template.
  • An attribute is a small detail on an HTML element.
  • The class attribute names a style group for the element.
  • The id attribute gives the element its own name.

In this example, the script block holds a plain const. The const is named message. Its value is Hello, Vue!. The first line shows that value. It carries the class greeting and the id welcome. The second line is a link. It points to the Vue site.

Note

Plain attributes hold fixed values. They do not change with the code.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

What does the class attribute do?