{{ title }}
{{ subtitle }}
---
title: Single-File Component Structure, Styling, and Template Patterns
impact: MEDIUM
impactDescription: Consistent SFC structure and styling choices improve maintainability, tooling support, and render performance
type: best-practice
tags: [vue3, sfc, scoped-css, styles, build-tools, performance, template, v-html, v-for, computed, v-if, v-show]
---
# Single-File Component Structure, Styling, and Template Patterns
**Impact: MEDIUM** - Using SFCs with consistent structure and performant styling keeps components easier to maintain and avoids unnecessary render overhead.
## Task List
- Use `.vue` SFCs instead of separate `.js`/`.ts` and `.css` files for components
- Colocate template, script, and styles in the same SFC by default
- Use PascalCase for component names in templates and filenames
- Prefer component-scoped styles
- Prefer class selectors (not element selectors) in scoped CSS for performance
- Access DOM / component refs with `useTemplateRef()` in Vue 3.5+
- Use camelCase keys in `:style` bindings for consistency and IDE support
- Use `v-for` and `v-if` correctly
- Never use `v-html` with untrusted/user-provided content
- Choose `v-if` vs `v-show` based on toggle frequency and initial render cost
## Colocate template, script, and styles
**BAD:**
```
components/
├── UserCard.vue
├── UserCard.js
└── UserCard.css
```
**GOOD:**
```vue
{{ subtitle }} {{ subtitle }}{{ displayName }}
{{ title }}
{{ title }}
{{ props.plainText }}
``` ## Choose `v-if` vs `v-show` by toggle behavior **BAD:** ```vue