Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Styling

Velox styles elements with CSS. A component declares styles in its <style> block, elements can carry inline style attributes, and a built-in user-agent stylesheet provides sensible HTML defaults. All three layers run through one cascade on every frame — there is no separate build step for CSS.

Where styles live

LayerDeclared inPrecedence
User-agentBuilt in (velox-style ua.css)Lowest
Author<style> blocks in .vx filesMiddle
Inlinestyle attributes on elementsHighest

Inline styles win over stylesheet rules, which win over the UA sheet — the same ordering browsers apply.

<template>
  <div class="card" style="margin-top: 12px">…</div>
</template>

<style scoped>
.card {
  width: 100%;
  padding: 16px;
  background-color: #1a1a2e;
}
</style>

Scoped and global styles

Declare the block <style scoped> to confine every rule to that component’s own elements:

  • The component gets a unique data-v-<hash> scope id derived from its name.
  • Each selector is rewritten with the matching attribute selector — .header becomes .header[data-v-abc1ef23].
  • The scope id is exposed as SCOPE_ID so rendered VNodes are tagged with the same attribute the scoped selectors rely on.

An unscoped <style> block passes through unchanged and applies globally. Inside a scoped block, @keyframes inner selectors (from, to, percent offsets) stay unscoped while the outer rules are scoped.


The cascade

apply_with_cascade composes the layers UA < author < inline and runs the result over the whole tree once per frame:

  • Matching is by compound selector against the element and, for multi-part selectors, its ancestors.
  • :hover matches when the pointer is over the element (the renderer supplies the hover predicate).
  • ::placeholder declarations are written to a separate attribute (style:placeholder) so they can never repaint the element’s own value.

Selectors

SelectorExampleMatches
TagbuttonElements with that tag
Universal*Any element
Class.btnElements whose class attribute contains the token
Compoundh1.titleTag and class on the same element
Attribute[disabled] / [type="text"]Elements carrying the attribute (optionally with an exact value)
Descendant.header h1An h1 with any .header ancestor
Childdiv > .cardA .card exactly one level below a div
Hoverbutton:hoverThe element while the pointer is over it
Pseudo-elementinput::placeholderThe placeholder of an <input> that is currently showing it

Note: ::placeholder is the only pseudo-element Velox supports, and it matches only an <input> — not a textarea — that carries a non-empty placeholder attribute and an empty value. A filled field shows the value, not the placeholder, so a ::placeholder rule never wins there.


Supported properties

The table below lists every property the style engine parses and which rendering reader honors it. The live path has three readers — the flexbox/table layout pass, the box painter, and the text painter — and a property is honest only if at least one of them looks it up. Properties marked parsed only survive the cascade but are then dropped; veloxc lint reports them.

Layout and box model

PropertyValuesRendered by
displayblock, inline, inline-block, flex, grid, none (hidden alias)Layout + box painter
positionstatic, relative, absolute, fixed, stickyLayout + box painter
z-indexIntegerStacking context
opacity0.0–1.0 (clamped)Layout + box painter
width / heightLengthLayout
min-width / min-heightLengthLayout
max-width / max-heightLengthLayout
marginLength shorthand (1–4 values) + margin-top/-right/-bottom/-leftLayout
paddingLength shorthand (1–4 values) + padding-top/-right/-bottom/-leftLayout + box painter
top / right / bottom / leftLengthLayout
box-sizingcontent-box, border-boxLayout (UA default is border-box)

Flexbox

PropertyValuesRendered by
flex-directionrow, row-reverse, column, column-reverseLayout
flex-wrapnowrap, wrap, wrap-reverseLayout
justify-contentflex-start (start), flex-end (end), center, space-between, space-around, space-evenlyLayout
align-itemsflex-start (start), flex-end (end), center, baseline, stretchLayout
align-selfauto + the align-items valuesLayout
flex-grow / flex-shrinkNumberLayout
flex-basisLengthLayout
gap (grid-gap)Length (sets both axes)Layout
row-gap / column-gapLengthLayout

Backgrounds and borders

PropertyValuesRendered by
background-colorColorBox painter
backgroundColor-only shorthand — the first color token is usedBox painter
border<width> <style> <color> shorthandBox painter
border-widthLength shorthand (1–4 values)Box painter
border-radiusLength shorthand (1–4 values)Box painter
border-styleBorder style valuesParsed only
border-colorColor valuesParsed only
background-imageValue stringParsed only

Typography

PropertyValuesRendered by
colorColorText painter (inherits)
font-sizeLengthText painter (inherits)
font-familyFamily string (e.g. system-ui)Text painter (inherits)
font-weightnormal, bold, bolder, lighter, or 100–900Text painter (inherits)
line-heightNumber (multiplier), px lengthText painter (inherits)
text-alignleft, center, right, justifyText painter (inherits)
vertical-alignbaseline, top, bottom, middleLayout (inherits)
text-decorationnone, underline, overline, line-throughText painter (inherits)
font-stylenormal, italic, obliqueParsed only
letter-spacingLengthParsed only

Overflow and misc

PropertyValuesRendered by
overflowvisible, hidden, scroll, autoLayout + box painter
overflow-xvisible, hidden, scroll, autoParsed only — use the overflow shorthand
overflow-yvisible, hidden, scroll, autoParsed only — use the overflow shorthand
white-spacenormal, nowrap, pre, pre-wrap, pre-lineText painter (inherits)
text-overflowclip, ellipsisText painter
visibilityvisible, hidden, collapseParsed only — visibility: hidden hides nothing; use display: none or v-show
transformTransform functions (translateX, scaleX, …)Parsed only — forces a stacking context, no visual effect
box-shadow2px 2px 4px rgba(0,0,0,0.5) formParsed only
transitionComma-separated <property> <duration> <timing>Parsed only — no reader plays a transition

Tip: veloxc lint reports exactly the parsed only properties above, by file and rule index. Unknown declarations are filtered out silently by the cascade, so lint deliberately does not flag them — vendor prefixes and custom properties stay quiet.

Tip: to hide an element use display: none (or v-show in templates), not visibility: hidden. To round corners use border-radius, and give depth with border — not box-shadow.


Units

All length values share one parser:

UnitExampleResolves against
px16pxPhysical pixels
%100%Parent size
rem1.5remRoot font size
em1.25emParent font size
vw50vwViewport width
vh100vhViewport height
dvw / dvh100dvhViewport width/height (treated as vw/vh)
autoautoAutomatic (layout-dependent)
(none)0, 16Unitless zero, plain numbers as px

A responsive page fills the viewport with a root of width: 100%; min-height: 100vh — the canonical pattern in every scaffold and example, and one the layout engine reflows visibly on every window resize.

Colors

FormExamples
Namedblack, white, red, green, blue, yellow, cyan, magenta, silver, gray/grey, maroon, olive, lime, aqua, teal, navy, fuchsia, purple, orange, pink, transparent
Hex#abc, #aabbcc, #aabbccdd (3, 6, or 8 digits)
Functionalrgb(255, 0, 0), rgba(255, 0, 0, 0.5)

Inheritance

Inherited properties flow from parent to child per browser CSS behavior:

color, font-size, font-family, font-weight, font-style, line-height, letter-spacing, text-align, vertical-align, white-space, visibility, cursor, text-decoration

Everything else is non-inherited: each element reads its own declaration, so a descendant of a clipped box is not clipped unless it says so. ::placeholder declarations never inherit — not even from their own element.

Fonts

Font matching resolves against system fonts and custom font files. font-weight accepts the CSS keywords and the full 100–900 numeric scale (Thin 100 through Black 900, default Normal 400); font-style accepts normal, italic, and oblique; line-height accepts normal (browser default 1.2×), a number multiplier, or a px length.

See also