Elements and layout
AngularLynx templates use Lynx elements, such as <view>, <text> and <image>, instead of HTML tags. Each element becomes a real piece of iOS or Android UI, so your app looks, scrolls and responds like any other app on the phone.
Build a screen from Lynx elements
- There's no browser underneath. iOS and Android each have their own UI toolkit, and Lynx turns each element into a piece of it. HTML tags have no meaning there, so Lynx defines its own small set.
<view>is the box, like a<div>.<text>holds text and<image>shows a picture. The mapping table lists the rest.- Import
LYNX_ELEMENTSin every component that uses Lynx elements. The template type checker andng testneed it. The build accepts the tags and their attributes without it, and warns about a component you use but left out ofimports, or a mistyped input (see Elements). - Common HTML tags render as Lynx elements. A
<div>renders as a<view>, and a<p>as a<text>. That gets ported web code on screen. See HTML tags.
Style elements with CSS classes or style, as on the web. Lynx CSS has some gaps, such as no :hover and no ::before. See CSS on Lynx.
Put all text in <text>
- Only a
<text>draws text. A word placed straight in a<view>still shows, because AngularLynx wraps it in a<text>of its own. That<text>takes the text styles of its ancestors' classes, as the HTML tags do. - Nest
<text>for inline styles. A<text>inside another<text>flows inline, like a<span>, and picks up text styles such as color from the outer one. - Write text across lines naturally. AngularLynx trims the leading and trailing spaces that template indentation leaves, so the text above renders flush.
- From a
<view>, a<text>you write inherits only its font size. Afont-sizeon the<view>reaches it, as on the web, but acolordoesn't. Set the other text styles on the<text>itself. Inside another<text>, it inherits more.
Lay out with the default column
Every element starts in Lynx's linear layout, display: linear. Children stack top to bottom, like a vertical flex column.
- Children stretch to the full width. A child with no width fills its parent's cross axis. Add
self-start(align-self: flex-start) to make it hug its content, as a badge or pill should. - There's no
blockorinline. Lynx has no text flow outside<text>, so every element is a box. - Boxes use
border-box, and margins never collapse. Two 16px margins between siblings give 32px of space.
Use flex for rows and alignment
- Add
flex(display: flex) first. It switches the element to flexbox, which behaves like CSS flexbox on the web. Its default direction is a row, as on the web. flex-rowalone does nothing. Linear layout ignoresflex-direction, so a view withflex-rowbut noflexstill stacks its children.gridworks too. Usedisplay: gridwhen you need rows and columns.
Scroll with <scroll-view> or <list>
overflow: scrolldoesn't scroll. Only<scroll-view>and<list>scroll.- Give a
<scroll-view>a height. Use a fixed height, orh-fullinside a parent with a known height. Without one, it grows to fit its content and never scrolls. flex-1on the scroll view doesn't bound it. To fill leftover space, putflex-1 flex flex-colon a wrapping<view>andh-full w-fullon the<scroll-view>.- Use
<list>for long or endless lists. It only creates the rows on screen and reuses them as you scroll. See<list>.
Float content above the page
Use <overlay> for dialogs, sheets and menus that sit on top of everything. position: fixed doesn't pin to the screen on Lynx: it positions against the app's root element, the page, and scrolls with it. See Dialogs and overlays.
HTML tags
A template written for the browser renders: AngularLynx creates the Lynx element each common HTML tag stands for.
<view>:div,section,article,aside,header,footer,main,nav,ul,ol,li,dl,dt,dd,form,fieldset,figure,figcaption,blockquote,address,hgroup,search,menuandhr.<text>:span,p,h1–h6,a,button,label,strong,b,em,i,small,code,s,u,mark,sub,sup,abbr,cite,q,time,del,ins,kbd,samp,varanddfn.<image auto-size>:img.- Already Lynx elements:
input,textarea,video,canvasandsvg.
What carries over:
- Text tags hold text. Text shows inside them, and a tag inside one runs inline, so
<p>Joined <strong>today</strong></p>reads as one line. - Text and inline tags share a line. In a block tag or a
<view>, text runs on as one line with the inline tags beside it:<div>Hi <b>there</b>, <a>friend</a></div>. Inline tags arespan,a,strongand the like, notporbutton. In a flex or grid container, each is an item of its own, as on the web. - A space alone between two tags is dropped, as in any Angular app. Angular's compiler deletes whitespace-only text by default, so
<b>Name:</b> <span>{{ name }}</span>reads "Name:Ada" in a browser too. Write the space as&ngsp;(<b>Name:</b>&ngsp;<span>…</span>), put it inside a tag, or setpreserveWhitespaces: trueon the component. - Text styles inherit. An ancestor's class or stylesheet rule can set
color,font-size,font-weight,line-heightortext-align. That reaches the text tags and the loose text inside it, as on the web. A<text>you write as a Lynx element takes only its font size this way. - Inline styles inherit as rules do. An inline
styleor[style.x]binding passes text styles down to HTML text tags and loose text. So<div style="color: red">colors the<p>inside it, and<text style="font-size: 18px">the<b>inside it. - An
<img>takes its picture's size, until CSS gives it one. Itsaltis what screen readers say. - Type selectors still match.
p { margin-bottom: 8px; }styles every<p>. hiddenhides the element, as[hidden]="!open()"does on the web.- DOM events Lynx also sends run.
(click)runs on a tap. See Handling taps and events.
What doesn't carry over:
- An inline tag in a
<text>you write matches that<text>. That<text>inherits only its font size, so the tag takes the styles the<text>sets itself, and its size.<text>Total: <b>{{ sum }}</b></text>stays one size, whatever the size around it. - An inline tag in a line draws no box. On iOS and Android, a
<span>or<code>in the middle of a line shows only its background, behind its letters. It has no padding, borders or rounded corners. A badge on a line of its own keeps them. - Inline text tags keep their browser text styles, with a few differences. See Inline tag styles.
- A
<q>draws quotation marks in its language, but some CSS can't change them. See Quotation marks. - There are no other browser styles. An
<h1>is the size of any other text and a<button>has no border, as with Tailwind's Preflight reset. Style them yourself. - There's no browser behavior.
<a href>opens nothing (userouterLink), a<form>doesn't submit, anddisableddoesn't stop a<button>'s taps. - Other tags don't work. A
<table>,<select>or<br>renders as a plain<view>, and the build warns about it.
Write Lynx elements in new code. They have their own attributes, such as <image mode>, and $event types with what each event sends.
Inline tag styles
The build gives inline text tags their browser text styles:
- Bold:
<b>and<strong> - Italic:
<em>,<i>,<cite>,<dfn>and<var> - Underlined:
<u>and<ins> - Struck through:
<s>and<del> - Monospace:
<code>,<kbd>and<samp> - Smaller:
<small>, plus<sub>and<sup>, which are also lowered or raised - Black on yellow:
<mark> - Underlined in the link color (lighter in dark mode): an
<a>with anhref - Dotted underline: an
<abbr>with atitle
Your own CSS for them wins, as it would in a browser. The differences:
- Two lines from one pair. A
<u>or<ins>(or a link) inside an<s>or<del>, or the other way round, gets both lines. They come from a rule with two classes, which beats a single class of yours on either tag of the pair. <a routerLink>keeps the text's style. It has nohref, so it isn't styled as a link.- Raised tags don't add
emto pixels. On iOS and Android, a<sup>or<sub>inside a tag you raise by pixels (vertical-align: 10px) rises by its own distance only. Lynx can't add anemdistance to pixels.- Raise the outer tag by an
emdistance instead, and the<sup>rises by both. - Or give the
<sup>a pixel distance of its own (style="vertical-align: 6px"), which adds to the outer tag's. - The same goes for a tag with an
emdistance in its own inline style, inside a tag raised by pixels.
- Raise the outer tag by an
- Android draws no dotted line under an
<abbr>. Lynx Explorer on Android also draws<code>in the default font, not monospace. Your app's own build has it.
Quotation marks
A <q> draws quotation marks in its language, as a browser does:
- “ ” around its text in English, and ‘ ’ inside another
<q> - « » in French
- „ “ in German
Its language is the nearest lang attribute on it or above it. Without one, it's the app's LOCALE_ID (which provideLocale() sets), as a localized web build sets <html lang> to the locale.
CSS quotes changes the marks, as in a browser. Set it in a rule (q { quotes: '«' '»' '‹' '›' }, or none for no marks), on the <q> or inherited from an element above it. An inline style works too.
Some quotes values leave a <q> its language's marks:
- A rule the runtime can't tell applies to the
<q>: a selector with an attribute, a sibling or:first-child, or a rule in a@media - A
var()
HTML to Lynx mapping
For buttons, inputs and other controls with a finished look, use the UI components.
Every element, including the ones with no HTML equivalent, has a reference page under API → Elements.
Related
- Handling taps and events
- CSS on Lynx: every CSS difference from the web
- Content projection:
<ng-content>and the<text>rules LYNX_ELEMENTS: every element directive
