Vue3 Fundamentals · Components, Props & Events

Fallthrough attributes

Fallthrough attributes

A parent can put an attribute on your component that you never declared as a prop — a class, an id, a data- attribute. Where does it go?

Vue calls these fallthrough attributes. When your component has a single root element, Vue merges them onto that element automatically:

<template>
  <div class="card">
    <h1>Title</h1>
  </div>
</template>

A parent writing <Card class="highlight" /> gets <div class="card highlight">. The parent's class lands on the root, merged with the root's own class.

The rule depends on the root. A component with one root element inherits attributes; a component with several root nodes has no single element to inherit them, so Vue warns and drops them.

That makes the root a decision, not an accident. If you want a parent's class to reach the component, give the component a single root element to receive it. The Test passes a class and checks where it lands.

Challenge

A parent's class is being dropped. Give the component a root to receive it: export an App component from App.vue that renders its heading and paragraph inside a single root element.

The Test mounts your component with class="highlight" and checks the class lands on the component's root. The starter renders two root nodes, so Vue cannot inherit the attribute and the Test fails. Wrap the content in one root element.

App.vue
<script setup>
const title = 'Title';
</script>

<template>
  <h1>{{ title }}</h1>
  <p>Body</p>
</template>

No test run yet

The Test is hidden. Run it to check the Challenge — you only see the result, never the test source.