Core concepts

Variants

Variants apply a class under a condition: from a screen width, in a state, or on a pseudo-element.

Breakpoints

JX is mobile-first: a class without a breakpoint applies everywhere, md: from 768 px up, and so on. Rules are sorted by increasing width.

Variant Min width Example
sm: 640px sm : cols : 2
md: 768px md : cols : 2
lg: 1024px lg : cols : 2
xl: 1280px xl : cols : 2
2xl: 1536px 2xl : cols : 2
cols:1
.cols\:1 {
  grid-template-columns: repeat(1, minmax(0, 1fr));
}
md : cols : 2
@media (min-width: 768px) {
  .md\:cols\:2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
xl : cols : 4
@media (min-width: 1280px) {
  .xl\:cols\:4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

States

Pseudo-classes are written as prefixes. These are the supported states:

hover: focus: active: visited: disabled: checked: focus-within: focus-visible: first: last: odd: even: enabled: required: optional: valid: invalid: user-valid: user-invalid: read-only: placeholder-shown: autofill: indeterminate: open: modal:
hover : bg : blue-700
.hover\:bg\:blue-700:hover {
  background-color: #1d4ed8;
}
focus-visible : ring : 2
.focus-visible\:ring\:2:focus-visible {
  box-shadow: 0 0 0 2px var(--jx-ring-color, currentColor);
}
disabled : o : 50
.disabled\:o\:50:disabled {
  opacity: 0.5;
}
user-invalid : bc : red
.user-invalid\:bc\:red:user-invalid {
  border-color: #ef4444;
}

Pseudo-elements

A pseudo-element always goes at the end of the selector, wherever it appears in the class. A class accepts only one.

Variant Selector
placeholder: ::placeholder
file: ::file-selector-button
backdrop: ::backdrop
placeholder : c : gray
.placeholder\:c\:gray::placeholder {
  color: #6b7280;
}
file : bg : blue
.file\:bg\:blue::file-selector-button {
  background-color: #3b82f6;
}

Dark mode

dark: applies a class when the system uses a dark theme. This is the default mode, dark_mode: media.

dark : bg : gray-900
@media (prefers-color-scheme: dark) {
  .dark\:bg\:gray-900 {
    background-color: #111827;
  }
}
dark : c : white
@media (prefers-color-scheme: dark) {
  .dark\:c\:white {
    color: #ffffff;
  }
}

For a light / dark toggle, switch to dark_mode: class in jx.yaml: dark: then applies under an ancestor carrying the dark class, usually <html>.

jx.yaml
# jx.yaml
dark_mode: class
.dark .dark\:bg\:gray-900 {
  background-color: #111827;
}

Groups and peers

Put the group class on a parent: its descendants react to its state with group-hover:, group-focus:… Every pseudo-class accepts this prefix.

a(classes: 'group flex ai:center gap:2', [
  span(classes: 'c:gray-700 group-hover:c:blue', [.text('Read more')]),
  span(classes: 'tr:transform group-hover:tx:1', [.text('→')]),
])
group-hover : c : blue
.group:hover .group-hover\:c\:blue {
  color: #3b82f6;
}
group-focus-visible : ring : 2
.group:focus-visible .group-focus-visible\:ring\:2 {
  box-shadow: 0 0 0 2px var(--jx-ring-color, currentColor);
}

peer does the same between siblings: the element carrying peer-* must come after the one carrying peer in the document.

input(type: InputType.checkbox, classes: 'peer sr-only'),
span(classes: 'bg:gray-300 peer-checked:bg:teal', []),
peer-checked : bg : teal
.peer:checked ~ .peer-checked\:bg\:teal {
  background-color: #14b8a6;
}
peer-invalid : c : red
.peer:invalid ~ .peer-invalid\:c\:red {
  color: #ef4444;
}

Preferences and print

Variant Condition
dark: (prefers-color-scheme: dark)
motion-safe: (prefers-reduced-motion: no-preference)
motion-reduce: (prefers-reduced-motion: reduce)
contrast-more: (prefers-contrast: more)
portrait: (orientation: portrait)
landscape: (orientation: landscape)
print: print
motion-reduce : anim : none
@media (prefers-reduced-motion: reduce) {
  .motion-reduce\:anim\:none {
    animation: none;
  }
}
print:hidden
@media print {
  .print\:hidden {
    display: none;
  }
}

Combining variants

Variants stack. The breakpoint produces the media query, the states complete the selector:

md : hover : bg : blue
@media (min-width: 768px) {
  .md\:hover\:bg\:blue:hover {
    background-color: #3b82f6;
  }
}
lg : focus : placeholder : c : gray-300
@media (min-width: 1024px) {
  .lg\:focus\:placeholder\:c\:gray-300:focus::placeholder {
    color: #d1d5db;
  }
}
md : dark : group-hover : c : white
@media (min-width: 768px) and (prefers-color-scheme: dark) {
  .group:hover .md\:dark\:group-hover\:c\:white {
    color: #ffffff;
  }
}

Note

A class accepts at most eight variants, and the same variant cannot be repeated.