Types: Stored (persisted in database), Reflected (in URL/request), DOM-based (client-side). Prevention: output encoding (HTML, JS, URL, CSS contexts), Content Security Policy (CSP), input validation, HttpOnly cookies, sanitize HTML (DOMPurify). Modern frameworks auto-escape but watch dangerouslySetInnerHTML, v-html, etc.