docs / Language

Styles

Component-scoped CSS via a <style> element in the body, how it is extracted, and how it is emitted on server and client.

Components carry their own CSS in a `<style>` element. The compiler extracts the element from the body and hoists it to component level.

app/components/Card.vsk
										
											component Card(props: { title: string }) {
  <div class="card">
    <h2>{props.title}</h2>
  </div>

  <style>
    .card { border: 1px solid #ccc; padding: 8px; }
    .card h2 { margin: 0; }
  </style>
}
										
									

How it is compiled

  • The IR generator removes `<style>` nodes from the render body and stores their text as the component's style property (extractStyle).
  • Server output emits a literal `<style>...</style>` block with the raw CSS.
  • Client output creates a `<style>` element keyed by the component identifier and appends it to document.head.
  • An unclosed `<style>` is a parse error: "Unclosed `<style>` element: missing `</style>`".