← Back to Vue.js Course | Chapter 10: Best Practices | Lesson 1 of 6

Component naming

Consistent component names make code easier to read, search and avoid clashing with HTML.

In this page:

  1. Component naming
Syntax
markup
<!-- PascalCase in single-file components -->
<MultiWordName />

<!-- kebab-case in in-DOM templates -->
<multi-word-name></multi-word-name>

Component naming

Use PascalCase for component names in single-file components and multi-word names such as TodoItem to avoid HTML element clashes. Base components can use a Base prefix, single-instance ones The, and tightly coupled children a parent prefix.

In in-DOM templates use kebab-case tags.

Note: Multi-word names never collide with current or future HTML elements.

Example: Component naming

markup
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>
<body>
<div id="app">
  <todo-item text="Buy milk"></todo-item>
  <todo-item text="Write code"></todo-item>
</div>
<script>
  const app = Vue.createApp({});
  // Registered with PascalCase, used with kebab-case in the page
  app.component("TodoItem", { props: ["text"], template: "<p>[ ] {{ text }}</p>" });
  app.mount("#app");
</script>
</body>
</html>

<!-- Output:
Rendered: [ ] Buy milk[ ] Write code
-->
Related Topics
Common Mistakes
  1. Single-word names like Card or Button
  2. Mixed naming styles
  3. PascalCase tags in in-DOM templates
Chapter Summary
  • Use multi-word names
  • PascalCase in SFCs
  • kebab-case in in-DOM templates
  • Prefix conventions help
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.