Skip to the page
Najova

Docs

/

Guides

webNaja and the web you know

If you know HTML, CSS and JavaScript, here's where each of them went in webNaja, and how to write plain HTML when you want to.

The same card, two ways

Here's a card in HTML and CSS: the markup, a class name, and rules for that class in a style sheet.

card.html
<!-- HTML and CSS: the markup, the class names, and a style sheet. -->
<style>
  .card { padding: 20px; border: 1px solid #e3e1ee; border-radius: 12px; }
  .card a { color: #6a4cf0; }
  @media (max-width: 640px) { .card { padding: 12px; } }
</style>
<section class="card">
  <h2>Rye</h2>
  <p>Baked at <strong>6 every morning</strong>.</p>
  <a href="/order">Order</a>
</section>

In webNaja, the parts are written in the page and the style has a name. The browser gets the same kind of HTML and CSS: webNaja writes it for you.

index.wnaj
$style[card]
  padding = 20
  border = theme.border
  corner = 12
  text = theme.accent ; for link
  padding = 12 ; phone
$endstyle

$page[Bread]
  $section[;style=card]
    $heading[Rye;2]
    $paragraph[Baked at **6 every morning**.]
    $link[Order;/order]
  $endsection
$endpage

› naja serve, then open /

GET /  →  200
.s-card{padding:20px;border:1px solid var(--border);border-radius:12px}
.s-card a{color:var(--accent)}
@media (max-width:640px){.s-card{padding:12px}}
<main class="nj-page" id="page">
<section class="nj-section s-card">
<h2 class="nj-heading" id="rye">Rye</h2>
<p class="nj-paragraph">Baked at <strong>6 every morning</strong>.</p>
<a href="/order" class="nj-link">Order</a>
</section>
</main>

The same card. The border colour and the link colour come from the theme, so they change in the dark look too.

HTML

In HTMLIn webNaja
<h1> to <h6>$heading, with the level as a number: $heading[Rye;2]
<p>, <strong>, <em>$paragraph, with **bold** and *italic* inside
<a href>$link, or look=primary for a button-like link
<div> with flex or grid$row, $column and $grid
<ul> and <li>$items, each part inside it one item
<table>$sheet and $cells
<img alt>$image, with what it shows as its second value
<form>, <input>, <label>$form and $input, with the label built in
<section>, <nav>$section and $nav

CSS

In CSSIn webNaja
.card { ... }$style[card] and style=card on the part
--accent and other variables$theme, read as theme.accent
:hover, :focus-visible; hover and ; focus at the end of a line
@media (max-width: 640px); phone, or ; below 960
prefers-color-scheme: dark; dark
.card a; for link
@keyframes$motion
@font-face$font

CSS names work in a style too, like margin or line-height, and each value is checked, so a typo is a mistake you see at once instead of a rule the browser quietly skips. See Styles and themes.

JavaScript and the server

On the webIn webNaja
A click listener that calls your servername= on a button, and $on[name.Clicked] in the same file
Changing the page from a scriptChange a named part in $on, and only that part is updated
A server route, like /api/scoreA file at that path, like api/score.wnaj
res.json(), res.status()$sendJson and $status
Templates with loops and ifs$each and $if right in the page
fetch() to another API$fetch, on the server

A page's front end and back end are one file, so there's no API between them to keep in step. See Servers and APIs.

Writing HTML yourself

When a part doesn't do what you want, $thread[html] lets you write plain HTML in the page, with Najova values inside it. Values are made safe on the way in, so < and & show as text instead of breaking the page. $rawHtml puts in HTML you trust as it is.

index.wnaj
$let[special;Rye & caraway <today only>]
$page[Bread]
  $heading[Today]
  $thread[html]
    <figure class="board">
      <figcaption>$get[special]</figcaption>
    </figure>
  $endthread
$endpage

› naja serve, then open /

GET /  →  200
<main class="nj-page" id="page">
<h1 class="nj-heading">Today</h1>
    <figure class="board">
      <figcaption>Rye &amp; caraway &lt;today only&gt;</figcaption>
    </figure>
</main>

What you get without asking

Every webNaja page comes with things that are easy to forget by hand: a "Skip to the page" link for keyboard users, a visible outline on whatever has focus, labels on form fields, layouts that fit a phone, a dark look that follows the visitor's computer, and text from visitors made safe. You can change any of them, but you don't have to remember them.