REFERENCE / STYLES

Style reference

Every selector, value, property and token that <style> accepts, which elements each property affects, and what is not supported.

Core janelkit Included with janelkit. Nothing extra to install.
REFERENCEExact signatures, behavior and vocabulary. Look things up here; learn them in the Guide.
Alpha / 0.2 — These pages document JanelKit 0.2 and its packages. Each series (0.1, 0.2…) may change the public API, always with migration notes: see Changes and migration. The website uses Svelte; the desktop examples use Python and JanelKit, not JavaScript.

How to read this page

<style> is not CSS. It is a fixed list of CSS-like properties that JanelKit translates to Qt Quick. This page lists all of it: if a selector, property or value is not here, JanelKit does not support it.

Every declaration ends in one of three outcomes. Knowing which one helps when a style seems to do nothing.

OutcomeWhenWhat you see
AppliedThe property, its value and the element are all supported.The style changes the element.
Warning, then ignoredUnknown property, invalid value, or a property that does not apply to that element.A compile warning with file, line and column, for example propiedad de estilo no soportada: 'filter' ("unsupported style property"). The rest of the file still works.
Compile errorAn unsupported selector, an at-rule (@media, @keyframes…), nesting, or a rule without braces.The component does not compile. The message lists the selectors that are supported.

Common mistakes

  • A warning is only produced when the rule applies to at least one element. A rule that matches nothing is never checked, so a typo there stays silent.
  • A few invalid values are accepted at compile time and stop the application at startup. They are listed in Known problems at the end of this page.

Learn moreStyles and themes ↗

Element groups

The Applies to column of the property tables uses these groups. A property used on an element outside its group produces a warning such as 'box-shadow' no tiene efecto en <button> ("has no effect on").

GroupElements
Boxesflex, <column>, <row>
Scroll areas<scroll>, <list>
Text controls<text>, <button>, <textfield>, <textarea>, <checkbox>, <switch>, <select>, <radiogroup>, <tabs>
Fields<button>, <textfield>, <textarea>, <select>
Any element except <window>All built-in elements except <window>: the groups above plus <slider>, <progressbar>, <image>, <video>, <spacer>, <shortcut>, and <Pages> and <Sections> of janelkit-router. Also your own .qml elements.
Every elementAll of the above and <window>.

Selectors

A rule starts with one or more selectors separated by commas. Selectors only see elements written in the same component; see Scope and precedence.

SelectorExampleMatches
Class.titleElements whose class includes title, from class="…", class:title={…} or class={…}.
Elementbutton, flex, columnEvery element of that type in this component. Built-in elements only: lowercase, as in the template.
Compound.button.primary, flex.cardElements that meet every part at once.
Pseudo-class.row:hoverElements in that state; see the next table.
Descendant.card .titleA .title at any depth inside a .card, also through {#if} and {#each}.
Child.menu > .itemAn .item whose direct parent is a .menu.
List.a, .bElements that match either selector.

Common mistakes

  • These are compile errors: ids (#main), the universal selector (*), attribute selectors ([disabled]), sibling combinators (+ and ~), :not(), :nth-child(), :empty, :root and pseudo-elements (::before, ::placeholder).
  • A selector naming a component, such as Card { … }, compiles without a warning but applies nothing. Put a class on the tag instead: <Card class="highlight" />.
  • Only /* … */ comments are allowed. A // line is read as a selector and is a compile error.

Pseudo-classes (states)

States are tracked by the view, so hovering never calls Python. A rule with a pseudo-class can change any supported property, and transition animates the change.

Pseudo-classActive whileNotes
:hoverThe pointer is over the element or one of its children.On a box with on:click it replaces the default hover highlight.
:pressedThe element is being pressed with the mouse or a finger.:active is accepted as another name. On a box with on:click, Space also counts.
:focusThe element has keyboard focus.
:focus-visibleThe element has focus and got it from the keyboard.Boxes only take focus from the keyboard, so on boxes it equals :focus.
:focus-withinThe element or something inside it has focus.
:disabledenabled={False}.
:checkedchecked is true.<checkbox>, <switch>, and boxes with a checked attribute.
:selectedselected is true.Boxes with a selected attribute.
:expandedexpanded is true.Boxes with an expanded attribute.
:first-childFirst visible child of its container.Also inside {#each}.
:last-childLast visible child of its container.Also inside {#each}.
:draggingThe element is being dragged.Set by the drag and drop engine.
:drag-overA dragged element is over this drop zone.Set by the drag and drop engine.

Scope and precedence

Styles are local to the component. A rule affects the elements written in that component’s template, including content it passes into a child’s slots, and never the inside of another component. Theme tokens and inherited text properties are how styles cross that boundary.

When several rules set the same property on one element, JanelKit decides like CSS, with two additions for attributes and inline styles.

  1. The more specific rule wins: more classes and pseudo-classes first, then more element names. .card:hover .actions beats .actions even if it comes earlier.
  2. With equal specificity, the rule that comes later in <style> wins.
  3. An attribute written on the element (gap={4}) beats rules without state, but rules with state (pseudo-classes, class:x, class={…}) beat the attribute.
  4. A rule that depends on a conditional or dynamic class of the element itself (class:x, class={…}) is applied above the others.
  5. An inline style= beats every rule, including states: :hover cannot change a property set inline.

Common mistakes

  • In slot content, a descendant selector can use the fixed classes of ancestors outside the slot, but not their states or conditional classes. The compiler warns and ignores that rule.
  • There is no global stylesheet and no !important. Share appearance through theme tokens, custom properties or a component.

Values

Each property accepts one of these value types. The property tables say which.

TypeAcceptedNot accepted (warning)
Length16px, 16, 0.5px, -8px. Pixels; the unit is optional..5 (needs a leading 0), em, rem, vw, vh, %, calc(), min(), max(), clamp()
Percentage50% — only where a property table says so: width, height, flex-basis, top, right, bottom, left, inset.Percentages anywhere else, such as padding or max-width.
Color#rgb, #rrggbb, #aarrggbb (alpha first), rgb(255, 0, 0), rgba(255, 0, 0, 0.5), and Qt’s color names such as red, darkslategray and transparent.hsl(), hwb(), lab(), oklch(), rgb(255 0 0) with spaces, rgb(… / 50%), percentages inside rgb(), gradients, currentColor (see Known problems).
Theme tokenvar(--primary), var(--space-4). Follows the active theme.
Custom propertyvar(--accent), or var(--accent, var(--primary)) with a fallback.
NumberUnitless numbers where stated: opacity 0.5, line-height 1.4, flex-shrink 1.50% for opacity, .5
Duration200ms, 0.2s, .2s
Angle45deg, 0.25turn, 45 (degrees)rad, grad

Common mistakes

  • Eight-digit hex colors are #aarrggbb, alpha first. The browser’s #rrggbbaa gives a different color.
  • Write 0.5, not .5. A number that starts with a dot is rejected, except inside rgba() and in durations.

Color, background and borders

On a <window>, background sets the window color and border does not apply.

PropertyApplies toValues and notes
colorText controls; Boxes (inherited by the <text> inside)Color.
background, background-colorBoxes, Scroll areas, <text>, Fields, <window>Color. A <text> with background, padding and border-radius makes a badge.
borderBoxes, Scroll areas, <text>, FieldsWidth and color in any order: 1px solid #ccc, 1px var(--border). solid is optional; none or 0 removes it. A color alone means 1px.
border-widthSame as borderLength.
border-colorSame as borderColor.
border-radiusSame as borderOne length. Two to four lengths (one per corner, as in CSS) only on Boxes. No percentages.
border-top, border-right, border-bottom, border-leftBoxesLike border, for one side: separators.
border-top-width, border-right-width, border-bottom-width, border-left-widthBoxesLength.
border-top-color, border-right-color, border-bottom-color, border-left-colorBoxesColor.

Common mistakes

  • Only solid borders exist. dashed and dotted are not supported, and without a color they stop the application at startup (see Known problems).

Spacing

Padding is the space inside an element, margin the space outside it, and gap the space between the children of a container. Prefer gap on the container over margins on each child.

PropertyApplies toValues and notes
paddingBoxes, Scroll areas, Text controlsOne to four lengths, as in CSS. On <scroll> and <list> it pads the content inside.
padding-top, padding-right, padding-bottom, padding-leftSame as paddingLength.
marginAny element except <window>One to four values: lengths, negative lengths or auto. auto pushes the element (margin-left: auto). Margins never collapse.
margin-top, margin-right, margin-bottom, margin-leftAny element except <window>Length or auto.
gapBoxes, Scroll areasOne length between children. For two values use row-gap and column-gap.
row-gap, column-gapBoxesLength: between lines and between columns when wrapping.

Flex layout

Layout follows a subset of CSS flexbox. flex uses the web defaults (row, align-items: stretch, children shrink); <column> and <row> are shortcuts with their own defaults. The Layout chapter explains how they behave.

PropertyApplies toValues and notes
flex-direction, directionflexrow (default), column, row-reverse, column-reverse.
flex-wrapBoxesnowrap, wrap.
align-itemsBoxes, <scroll>start, center, end, stretch; baseline only on Boxes. flex-start and flex-end are accepted as start and end.
justify-contentBoxes, <scroll>start, center, end, space-between, space-around, space-evenly.
align-contentBoxesThe justify-content values plus stretch: distributes wrapped lines.
align-selfAny element except <window>auto, start, center, end, stretch.
flexAny element except <window>1 (= 1 1 0), 1 0 200px (grow, shrink, basis), auto (= 1 1 auto), none (= 0 0 auto). Grow must be a whole number.
flex-growAny element except <window>Whole number. On its own it keeps the basis at auto, as in CSS.
flex-shrinkAny element except <window>Number.
flex-basisAny element except <window>Length, percentage, auto or content.
orderAny element except <window>Whole number, may be negative.
overflowBoxesvisible, hidden (clips, without rounding the corners), auto and scroll (make the box scrollable).

Learn moreLayout ↗

Size

Without a size, an element takes its natural size, and in a <column>, text, fields and boxes stretch to the full width. Set a size only when the layout needs one.

PropertyApplies toValues and notes
width, heightEvery elementLength; percentage of the container; 100% fills the available space; auto and fit-content keep the natural size. On a <window>, a length only.
min-width, max-width, min-height, max-heightEvery elementLength only, no percentages.

Position

Elements are placed by the layout of their container. position takes an element out of that order, for overlays, badges and pop-up menus.

PropertyApplies toValues and notes
positionAny element except <window>static (default), relative, absolute, fixed. No sticky.
top, right, bottom, leftAny element except <window>Length, percentage of the containing box, or auto.
insetAny element except <window>One to four values, like margin. inset: 0 covers the containing box.
z-indexAny element except <window>Whole number or auto. Orders siblings only, not the whole window.

How it works

  1. relative moves the element from its place without moving the others, and becomes the reference for absolute elements inside it.
  2. absolute leaves the flow and is placed against the nearest ancestor box with a position, or the window if there is none.
  3. fixed is placed against the window and follows it when resized: use it for overlays and dialogs.
  4. An absolute or fixed box blocks the pointer for what is underneath it.

Text

Properties set on a box are inherited by the <text> elements inside it; see Inherited text. On a <window>, font properties apply to the whole window.

PropertyApplies toValues and notes
font-sizeText controls, Boxes, <window>Length.
font-weightText controls, Boxes, <window>1 to 1000, normal (400), bold (700), lighter (300), bolder (800). lighter and bolder are fixed weights, not relative to the parent.
font-familyText controls, Boxes, <window>One family name, quoted or not, or a token such as var(--font-family). No fallback list.
font-styleText controls, Boxes, <window>italic, normal.
letter-spacingText controls, BoxesLength.
text-transformText controls, Boxesnone, uppercase, lowercase, capitalize.
text-align<text>, <textfield>, <textarea>, Boxesleft, center, right, justify.
line-height<text>, BoxesUnitless factor, such as 1.4. Lengths are rejected.
white-space<text>, Boxesnormal, nowrap (one line). pre-wrap is accepted and behaves like normal.
text-overflow<text>, Boxesellipsis, clip.
user-select<text>text (the text can be selected and copied), auto, none.

Effects and interaction

These properties change how an element looks or reacts without changing the layout. Most of them only exist on Boxes, so wrap a control in a <column> to give it a shadow or an outline.

PropertyApplies toValues and notes
opacityEvery elementNumber from 0 to 1, written 0.5.
transformAny element except <window>scale(n), rotate(45deg), translate(x, y), translateX(x), translateY(y), none, combined with spaces. Always from the center; it does not affect layout. Replaces the whole transform, as in CSS.
box-shadowBoxesx y [blur [spread]] [color]: 0 2px 8px rgba(0, 0, 0, 0.15). Default color is black at 25 %. One shadow; extra shadows produce a warning and are ignored. No inset. none removes it.
outlineBoxesA ring that takes no space: 2px solid var(--primary). Width defaults to 2px. A rule with outline replaces the default focus ring.
outline-width, outline-color, outline-offsetBoxesLength, color, length. A negative offset draws the ring inside.
cursorAny element except <window>default, auto, pointer, text, move, grab, grabbing, not-allowed, wait, progress, crosshair, help, ew-resize, ns-resize, nesw-resize, nwse-resize, col-resize, row-resize.
pointer-eventsBoxesauto, none: the box ignores the mouse (no :hover, click or cursor); its children still receive it.
visibilityBoxesvisible, hidden: keeps its space but is not drawn and receives no events.
transitionAny element except <window>property duration, separated by commas: background 200ms, opacity 0.3s, or all 150ms. Animates color, background, background-color, border-color, opacity, width, height, border-radius and transform; on Boxes also box-shadow, outline and outline-color. Always eases out.

Common mistakes

  • transition ignores a timing function or delay: ease-in and 100ms after the duration compile without a warning and have no effect.
  • scale takes one factor. scale(1, 2), skew(), rotate(1rad) and transform-origin are not supported.

Inherited text

color, font-family, font-size, font-weight, font-style, letter-spacing, text-transform, text-align, line-height, white-space and text-overflow set on a box are inherited by every <text> inside it, at any depth, also inside other components and slot content, unless the <text> sets its own.

The text of Qt controls such as <button> and <textfield> does not inherit: style those directly.

css
/* One rule recolors all the text of the selected row. */
.row:selected { background: var(--primary); color: var(--on-primary); }
Copy

Custom properties

--name: value on a box defines a variable for that box and everything inside it, including other components. It can change with states and classes. var(--name) reads it.

var(--name) looks for a custom property only if this component defines it or the call has a fallback. Otherwise it is read as a theme token. To read a variable that the parent component sets, give it a fallback: var(--button-bg, var(--surface)).

css
.card { --accent: var(--primary); border-left: 3px solid var(--accent); }
.card.alert { --accent: var(--danger); }
.card:hover { --accent: var(--success); }
.title { color: var(--accent); }
Copy

Common mistakes

  • Custom properties can only be defined on Boxes (flex, <column>, <row>). On another element they produce a warning.

Inline styles

style="gap: 4px; background: #222" accepts every property on this page for one element, with the same values.

style={{…}} takes a dictionary computed in Python and updates when its data changes. It accepts fewer properties: background, background-color, color, border-color, border-width, border-radius, opacity, gap, padding, font-size, width, height, top, right, bottom, left, z-index, and custom properties --name on Boxes. Numbers are pixels; text such as "50%" is a percentage where the property allows it.

janel
<flex style={{"width": f"{progress}%", "background": color, "--accent": accent}} />
Copy

Fragment · Add it to an existing component; it is not a complete file.

Common mistakes

  • Inline styles beat every rule, including :hover. Put values that should change with state in <style>.
  • Dictionary keys must be fixed strings; for classes use class={…}.

Theme tokens

Tokens are the values of the active theme. Use them with var(--name); they change when the theme changes. A token name with underscores in Python is written with hyphens in CSS: brand_dark is var(--brand-dark). A var(--x) that does not exist in the active theme produces a warning with its location when the application starts.

TokenLightDarkUse
--bg#f5f6f8#14161aWindow background
--surface#ffffff#1e2127Cards and fields
--surface-alt#eef0f4#272b33Secondary areas
--text#1b1f24#e6e8ecMain text
--text-muted#626b78#99a1adSecondary text
--border#d5dae1#373c46Borders
--primary / --on-primary#3b5bdb / #ffffff#7b93ff / #0d1330Accent and text on it
--danger / --on-danger#e03131 / #ffffff#ff6b6b / #1f0606Destructive actions
--success#2b8a3e#51cf66Success
--warning#e8590c#ffa94dWarnings
--hover / --pressed#10000000 / #24000000#1affffff / #33ffffffTranslucent interaction layers
--radius-sm, --radius, --radius-lg4, 8, 14sameCorner radii
--font-familyempty: system fontsameFont
--font-size-sm, --font-size, --font-size-lg, --font-size-xl12, 14, 18, 24sameFont sizes
--space-1 … --space-64, 8, 12, 16, 24, 32sameSpacing
python
from janelkit import theme

theme.set("dark")                          # or "light"; theme.toggle() switches
theme.extend("light", brand="#7048e8")     # add or change tokens; without a name, in every theme
theme.define("sepia", base="light", bg="#f4ecd8", text="#433422")
Copy

Learn moreStyles and themes ↗

Common CSS that is not supported

Each item below was compiled against JanelKit 0.2. The Result column says what happens; the last column gives the closest supported way.

CSSResultUse instead
@media, @keyframes, @font-face, @import, nestingCompile errorA computed value with class:x or style={…}; transition for animations.
display (none, grid, flex)Warning{#if} or {#hidden} to hide; flex or <column>/<row> for layout; flex-wrap for grids.
grid-template-*, place-items, justify-itemsWarningflex-wrap with flex: 1 1 200px on the items.
position: stickyWarningPut the header outside the <scroll>.
em, rem, vw, vh, calc(), min(), clamp()WarningPixels, theme tokens, percentages where allowed, or values computed in Python with style={…}.
hsl(), modern rgb() syntax, gradientsWarningHex or rgb()/rgba() with commas.
background-image, url()Warning<image> inside an absolute box.
text-decoration, text-shadow, word-breakWarningNo equivalent.
font shorthandWarningfont-size, font-weight, font-family and font-style separately.
border-style, dashed and dotted bordersWarningSolid borders only.
box-shadow: inset, several shadowsWarningOne outer shadow.
filter, backdrop-filter, clip-path, mix-blend-modeWarningNo equivalent.
transform: skew(), scale(x, y), transform-originWarningscale(n), rotate(), translate().
animation, transition-timing-function, transition-delayWarning for the properties; ignored inside transitiontransition with a state or class change.
overflow-x, overflow-yWarningoverflow on a box, or a <scroll>.
aspect-ratio, box-sizingWarningExplicit width and height.
scrollbar-*WarningNo equivalent.
!importantWarning (invalid value)A more specific selector, or style=.

Known problems in 0.2

These values compile without any warning and janel build accepts them, but the application then fails to start with Qt rechazó el QML generado: Invalid property assignment ("Qt rejected the generated QML"). The error points at the element, so the fix is quick once you know the cause.

WrittenWhat happensWrite instead
A misspelled color name: color: bluThe application does not start.Check the spelling, or use a hex value or a token.
A CSS color name Qt does not know: rebeccapurpleThe application does not start.#663399.
A border style without a color: border: 2px dasheddashed is read as a color name; the application does not start.border: 2px solid var(--border).
outline: 2px dottedSame as above.outline: 2px solid var(--primary).
currentColor in a border or colorRead as a color name; the application does not start.The same token as the text color.

Common mistakes

  • Also silent, without stopping the application: a rule whose selector matches nothing (including Card { … } for a component), and a timing function or delay inside transition.

English documentation based on the JanelKit source. For additional details, browse the source docs ↗.