For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /guide/styling/index.md.

CSS on Lynx

Lynx draws your app with its own CSS engine, not a browser's. Most layout and visual CSS carries over. Some defaults differ, though, and some features are missing.

This page covers what trips up web developers, and what to write instead.

For every property and value Lynx accepts, see the Lynx CSS reference.

At a glance

On the webOn Lynx
:root, html, bodypage
display: block by defaultdisplay: linear (a vertical stack) by default. flex and grid work
box-sizing: content-box, collapsing marginsborder-box, and margins never collapse
Text anywhereText drawn by a <text>
color and fonts inheritInto HTML text tags and loose text, not a Lynx <text>
1rem is 16px1rem is 14px
overflow: auto scrollsOnly <scroll-view> and <list> scroll
position: fixed pins to the viewportPositions against the page. Use <overlay> for floating UI
:hover, ::before, !importantNot supported
hsl(240 6% 10%)Dropped silently. Write hsl(240, 6%, 10%) or rgba()

The root is page

src/styles.css
page {
  background-color: #ffffff;
  --brand: rgba(79, 70, 229, 1);
}
  • page is the root element of every Lynx app. Its selector does the job of :root and body.
  • html and body match nothing.
  • Put app-wide CSS variables on page. Every element below it can read them.

Layout

.toolbar {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
  • Elements stack vertically by default. Lynx's default display is linear, which lays children out in a column. flex and grid work as on the web.
  • display: block becomes linear. Lynx has no block layout, and would lay a block element out as a row. So the build rewrites it in your stylesheets, and AngularLynx does the same in inline styles.
    • :host { display: block } keeps working.
    • inline-flex and inline-grid become flex and grid.
    • inline and inline-block become linear. An element can't sit inline next to others, though, so it still stretches across its parent.
  • flex-direction: row needs display: flex. On a linear element it does nothing. In Tailwind, write flex flex-row, not flex-row alone.
  • Children stretch across their parent. A child with no width fills the parent's cross axis. Add align-self: flex-start (Tailwind self-start) to make a badge hug its content.
  • Boxes are border-box, and margins never collapse: a 16px bottom margin above a 16px top margin makes 32px.
  • min-width and min-height default to 0, not auto. A flex item can shrink below its content and clip its text. Set a min-width to stop it.
  • Every element is position: relative by default, so z-index works on any element.
  • Siblings paint in source order. A later sibling draws on top, even when an earlier one is position: absolute.
  • position: fixed acts like position: absolute against the page. For floating UI such as menus, use <overlay>.
  • position: sticky works only inside a <scroll-view>.
  • overflow is visible or hidden. A <view> never scrolls. Use <scroll-view> or <list>.

Elements and layout covers which element to use for what.

Text

.summary {
  font-size: 15px;
  line-height: 22px;
  text-overflow: ellipsis;
}
<text class="summary" text-maxline="2">
  Your order left the warehouse this morning and arrives on Friday.
</text>
  • Only a <text> draws text. Text placed directly in a <view> is drawn in a <text> of its own, which inherits text styles (see Text inheritance).
  • Put text styles on the <text>. A color, font-size or line-height on a <view> doesn't reach the text inside it (see Text inheritance).
  • line-height works only on <text>.
  • white-space is normal or nowrap. There's no pre, so spaces and line breaks always collapse.
  • There's no text-transform, so Tailwind's uppercase does nothing. Change the case in TypeScript.
  • There's no text-align: justify.
  • Clamp lines with the text-maxline attribute, as above, instead of -webkit-line-clamp.
    • Pair it with text-overflow: ellipsis. Without it, Android draws the extra lines past the box.
    • The build warns about a text-maxline without one.
    • <ui-text [maxLines]> sets both.

Inheritance

Most CSS properties don't inherit on Lynx. A color on a <view> doesn't reach the <text> inside it. font-size, CSS variables, HTML text tags and loose text are the exceptions.

Text inheritance covers what inherits, and how to make every text property inherit as on the web.

Units

UnitOn Lynx
pxA device-independent pixel, as on the web
rem14px, Lynx's root font size. The default font-size is 14px
rpx1/750 of the screen width, so 750rpx is always full width
%, em, vw, vhAs on the web
  • rem is 14px, not 16px. Rem-based sizes come out 12.5% smaller than in a browser. That includes Tailwind's scale: h-11 is 38.5px. Use px where a size must line up with something exact.
  • The UI components theme makes 1rem 16px, with page { font-size: 16px }, so Tailwind's scale matches the web there.
  • Lengths need units. Only 0 can go without one, and margin: 5 is ignored. Times need units too: 0ms, not 0.
  • calc() and env() work. min(), max() and clamp() don't.

Colors

FormatExampleWorks
Hex#18181b, #ff000080Yes
Namedred, transparentYes
rgb() / rgba(), commasrgba(24, 24, 27, 0.5)Yes
rgb(), spacesrgb(24 24 27 / 0.5)Yes
hsl() / hsla(), commashsla(240, 5.9%, 10%, 0.5)Yes
hsl(), spaceshsl(240 5.9% 10% / 0.5)No
currentColorNo
  • Space-separated hsl() fails silently. The element draws transparent, with no warning. Lynx's parser reads hsl() only in its comma form.
  • currentColor isn't supported. Use the color itself, or a CSS variable.

Theme colors in CSS variables

Store each color whole in a variable, then reference the variable directly:

src/styles.css
page {
  --primary: rgba(24, 24, 27, 1);
  --primary-foreground: rgba(250, 250, 250, 1);
  --primary-subtle: rgba(24, 24, 27, 0.1);
}

.button {
  background-color: var(--primary);
}

.button-label {
  color: var(--primary-foreground);
}
  • Don't store raw channels (--primary: 240 5.9% 10%) to wrap later in hsl(var(--primary)). That expands to the space-separated hsl() Lynx drops, which is why shadcn-style themes render blank.
  • For a translucent shade, add a variable of its own, like --primary-subtle, or use channels in rgba(), below.
  • Set variables in a stylesheet, a style attribute or a binding. [style.--primary]="brand()" sets one at runtime. Everything inside the element reads it, on iOS, Android and in the web preview.

One color at any opacity

Keep a color's channels in a second variable, comma-separated, and wrap it in rgba():

src/styles.css
page {
  --primary: rgba(24, 24, 27, 1);
  --primary-rgb: 24, 24, 27;
}

.scrim {
  background-color: rgba(var(--primary-rgb), 0.5);
}
  • Lynx replaces var() with the variable's text before it reads the color, so 24, 24, 27 fills three arguments, as in a browser.
  • Write the channels with commas for rgba(). Space-separated channels work only in the rgb(var(--x) / 0.5) form.
  • An undefined variable drops the whole value, and the element draws transparent.

The UI components theme works this way. Its Tailwind plugin turns bg-primary/50 into rgba(var(--primary-rgb), 0.5). See Theming.

Selectors and rules

  • Selectors that work: type (text), class, ID, *, compound (.a.b), descendant, child (>), sibling (+, ~), :not(), and attribute selectors such as [disabled], which the build turns into classes (see Attribute selectors).
  • At-rules that work: @font-face, @keyframes, @import and @media, against the page's size (see Adaptive layouts).
MissingUse instead
:hover, :focus, :activeA class bound to a signal: see Pressed states
::before, ::afterA real element
:first-child, :nth-child() and other structural classesA class bound to @for's $first, $last or $index
:is(), :where(), :has()Separate selectors
@supports, @layer, @container, @propertyNothing
!importantA more specific selector
pointer-eventsLeave it out: the build fails on it. The last sibling gets the taps
float, columnsFlexbox or grid
outlineborder

Combinators restyle when a class changes, as on the web. .selected .label applies as soon as an ancestor gains selected.

To turn this off, set the enableCSSInvalidation plugin option to false. That saves Lynx some work when a class changes. A combinator then only matches when the element's own classes are set.

Attribute selectors

Lynx's CSS engine matches no attribute selector, so the build turns each into a class, and the runtime gives an element that class while its attribute matches. Write them as on the web:

src/styles.css
.btn[disabled] {
  opacity: 0.5;
}

:root[data-theme='dark'] .card {
  background-color: #18181b;
}

[aria-expanded='true'] > .chevron {
  transform: rotate(90deg);
}
<view class="btn" [attr.disabled]="busy() ? '' : null"></view>
<view [attr.aria-expanded]="open()"><view class="chevron"></view></view>
  • Every operator works: [a], [a=v], [a~=v], [a|=v], [a^=v], [a$=v], [a*=v] and the i flag, in global and component styles, and inside a :not() of compounds, such as :not([disabled]).
  • :root and html are the page. Bind the attribute on the root component's host, which is the page: host: { '[attr.data-theme]': 'theme()' }. :root[data-theme='dark'] becomes page with a class, which weighs one type selector and one class (0,1,1), where on the web it weighs two classes (0,2,0). html[…] keeps its weight. If a rule of the same weight competes with a :root[…] rule, make the :root[…] one more specific or put it later.
  • A changing attribute restyles at once, with the descendants a combinator matches.
  • A property binding of false ([disabled]="false") counts as no attribute, as a browser's boolean properties do.
  • Some stay as written, with a build warning naming the selector and the file: one inside :is(), :where() or :has(), one inside a :not() with a combinator in it (:not(.list [hidden])), one with a namespace, and [class], [style] and [id]. Use a class there.

Pressed states

:active rules don't apply in AngularLynx builds, and neither does Tailwind's active: variant. Set a signal, such as pressing = signal(false), from touch events instead, and bind a class to it:

<view
  [class.bg-muted]="pressing()"
  (bindtouchstart)="pressing.set(true)"
  (bindtouchend)="pressing.set(false)"
  (bindtouchcancel)="pressing.set(false)"
  (bindmousedown)="pressing.set(true)"
  (bindmouseup)="pressing.set(false)"
  (bindmouseleave)="pressing.set(false)"
></view>

The mouse events are for the web preview, which sends no touches for a cursor. The UI components draw their pressed states this way.

Component styles

styles and styleUrl are scoped to the component, as in Angular on the web. Angular scopes them with attributes, which the build turns into classes.

Component styles covers :host, ::ng-deep, view encapsulation and type selectors.