--- title: In-DOM Template Parsing Caveats impact: HIGH impactDescription: Browser HTML parsing before Vue compilation causes case sensitivity, self-closing tag, and element nesting issues type: gotcha tags: [vue3, templates, in-dom, html-parsing, kebab-case, self-closing-tags] --- # In-DOM Template Parsing Caveats **Impact: HIGH** - When writing Vue templates directly in the DOM (not in `.vue` files), the browser's native HTML parser processes the template BEFORE Vue sees it. This causes three critical issues: case sensitivity problems, self-closing tag failures, and element placement restrictions. These issues do NOT apply to Single-File Components (SFCs) or string templates where Vue's compiler handles parsing directly. ## Task Checklist - [ ] Use kebab-case for component names in in-DOM templates - [ ] Use kebab-case for prop names in in-DOM templates - [ ] Use explicit closing tags (not self-closing) in in-DOM templates - [ ] Use `is="vue:component-name"` for components inside restricted elements - [ ] Prefer SFCs to avoid all in-DOM parsing issues ## Issue 1: Case Insensitivity HTML is case-insensitive. The browser lowercases everything before Vue sees it. **Incorrect (in-DOM template):** ```html ``` **Correct (in-DOM template):** ```html ``` **In SFCs, PascalCase works fine:** ```vue ``` ## Issue 2: Self-Closing Tags Fail HTML only allows self-closing syntax for void elements (``, ``, etc.). For all others, the browser expects closing tags. **Incorrect (in-DOM template):** ```html ``` **Correct (in-DOM template):** ```html ``` **In SFCs, self-closing works fine:** ```vue ``` ## Issue 3: Element Placement Restrictions Some HTML elements have strict rules about valid children. Invalid elements are hoisted out by the browser before Vue sees the template. **Restricted parent elements:** - `