Skip to content
Hekana Spray
Documentation
Getting started
Theme development
Components and tags

Localization

Apps and custom code

Examples and recipes
API reference
Publishing
Build apps
AI development

Styling and responsive design

Style a Sneferu theme with design tokens, tag props and your own CSS, with tablet and mobile breakpoints and right-to-left support.

On this page

A theme is styled in three layers:

  1. Design tokens in theme.json become CSS variables.
  2. Tag props (padding-y, columns, size, color, …) generate scoped CSS for each hk-* tag, with tablet and mobile variants.
  3. Your stylesheet in assets/*.css styles everything else.

Tokens → CSS variables

json
"tokens": {
  "colors": { "primary": "#111827", "secondary": "#1F2937", "accent": "#B45309",
              "background": "#FFFFFF", "text": "#111827", "muted": "#6B7280" },
  "layout": { "contentWidth": "1200px" }
}

becomes one rule on the theme's root element:

css
[data-hk-theme="my-theme"] {
  --hk-color-primary: #111827;
  --hk-color-secondary: #1F2937;
  --hk-color-accent: #B45309;
  --hk-color-background: #FFFFFF;
  --hk-color-text: #111827;
  --hk-color-muted: #6B7280;
  --hk-content-width: 1200px;
  --color-primary: var(--hk-color-primary);   /* also secondary, accent, background, text */
  background: var(--hk-color-background);
  color: var(--hk-color-text);
}
TokenVariableUse
colors.<key> (key: lower-case letters, digits, -)--hk-color-<key>in CSS: var(--hk-color-accent); in colour props and settings: theme:accent
layout.contentWidth ("1200px", 3-4 digits)--hk-content-widthmax width of hk-section content and hk-container (fallback 1280px). "full" emits --hk-content-width:none and --hk-gutter:clamp(16px,3vw,56px): content spans the viewport with a fluid side gutter (hk-section pads with var(--hk-gutter,16px))

Use tokens instead of hard-coded colours so one change in theme.json restyles the whole theme:

html
<hk-section background="theme:primary">
  <hk-heading text="{{ section.settings.title }}" color="theme:background" />
</hk-section>
css
.sn-btn-solid { background: var(--hk-color-accent); color: var(--hk-color-background); }

A color setting ("default": "theme:primary") lets the merchant pick either a token or a hex colour, and passes straight into a colour prop: background="{{ section.settings.background }}".

Fonts

Name fonts in theme.json. All three keys are optional:

json
"tokens": {
  "colors": { "primary": "#111827", "secondary": "#1F2937", "accent": "#B45309",
              "background": "#FFFFFF", "text": "#111827" },
  "fonts": { "heading": "Cairo", "body": "Inter", "mono": "Martian Mono" }
}

Only families from the catalogue below are accepted, written exactly as shown. Anything else is compile error SN3032 (with a "did you mean" when the name is close). tokens.fonts uses these catalogue fonts, which Hekana serves itself. Font files you put in assets/ are accepted by the CLI but are not served on the store, so they cannot be used through tokens.fonts.

FamilyArabicWeights
Cairoyes200-1000 (variable)
IBM Plex Sans Arabicyes300, 400, 500, 600, 700
Tajawalyes400, 500, 700, 800
Almaraiyes400, 700, 800
Readex Proyes160-700 (variable)
Noto Kufi Arabicyes100-900 (variable)
Rubikyes300-900 (variable)
Baloo Bhaijaan 2yes400-800 (variable)
Amiriyes400, 700
Noto Naskh Arabicyes400-700 (variable)
El Messiriyes400-700 (variable)
Reem Kufiyes400-700 (variable)
Lalezaryes400
Changayes200-800 (variable)
Markazi Textyes400-700 (variable)
Scheherazade Newyes400, 500, 600, 700
Aref Ruqaayes400, 700
Interno100-900 (variable)
Martian Monono100-800 (variable)
Space Groteskno300-700 (variable)
JetBrains Monono100-800 (variable)
Playfair Displayno400-900 (variable)
Cormorant Garamondno300-700 (variable)
Frauncesno100-900 (variable)
Oswaldno200-700 (variable)
Bebas Neueno400
Nunitono200-1000 (variable)
Fredokano300-700 (variable)
DM Sansno100-1000 (variable)
Manropeno200-800 (variable)

Serif with Arabic and Latin: Amiri, Aref Ruqaa, Markazi Text, Noto Naskh Arabic, Scheherazade New. Latin-only serif: Playfair Display, Cormorant Garamond, Fraunces. Condensed display: Oswald, Bebas Neue. Rounded: Nunito, Fredoka.

On the page this becomes --hk-font-heading, --hk-font-body and --hk-font-mono on the theme root, font-family: var(--hk-font-body) on the root, and font-family: var(--hk-font-heading) on h1 to h6. --hk-font-mono is defined but not applied anywhere: use it yourself, for example code, pre { font-family: var(--hk-font-mono); }. Only the families the page needs are loaded (font-display: swap); a family's Arabic file is declared on English pages too, but the browser downloads it only when an Arabic glyph appears.

Arabic pages. When a chosen font has no Arabic glyphs (Inter, Martian Mono, Space Grotesk, JetBrains Mono), its stack on an Arabic page is "Inter", "Cairo", sans-serif, so Arabic text uses Cairo instead of the browser default. A theme that declares no fonts gets Cairo on Arabic pages and the system fonts on English pages. On an Arabic page without a heading font, headings use the body font. mono defaults to the system monospace stack.

In sneferu dev the same families are loaded from Google Fonts, so the preview needs a network connection; published themes never load anything from Google.

Your CSS: assets/*.css

Every .css file at the top level of assets/ is the theme stylesheet. It is loaded after the tokens and after the tags' own CSS, so with equal specificity your rules win.

Write styles for:

  • your own markup (header, .logo, .tier-price);
  • classes you put on hk-* tags with class="…";
  • the stable hooks the tags render:
TagStable classes
hk-buttonsn-btn, sn-btn-solid / sn-btn-outline / sn-btn-ghost
hk-cardsn-card
hk-badgesn-badge, sn-badge-accent / -neutral / -success / -warning
hk-pricesn-price, sn-now, sn-was
hk-product-card, hk-product-grid itemssn-product-card, sn-title, plus sn-price
hk-gridsn-grid
hk-sectioninner wrapper sn-inner

Do not target the numbered classes (sn-c3, sn-s-hero-c2): they depend on position and change when the page changes.

hk-button, hk-badge and the product card come with structure but no visual style, so every theme needs base rules for them. A starting point:

css
.sn-btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px;
  padding-inline: 20px; border-radius: 10px; font-weight: 600; text-decoration: none;
  border: 2px solid var(--hk-color-accent); }
.sn-btn-solid { background: var(--hk-color-accent); color: var(--hk-color-background); }
.sn-btn-outline { background: transparent; color: var(--hk-color-accent); }
.sn-btn-ghost { background: transparent; border-color: transparent; color: inherit; }
.sn-badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.sn-badge-accent { background: var(--hk-color-accent); color: var(--hk-color-background); }
.sn-badge-neutral { background: color-mix(in srgb, var(--hk-color-text) 10%, transparent); }
.sn-product-card { display: flex; flex-direction: column; gap: 8px; color: inherit; text-decoration: none; }
.sn-product-card img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: 12px; }
.sn-was { opacity: .6; margin-inline-start: 6px; }

Keep touch targets at least 44px high on mobile (the min-height above).

What CSS cannot do in a theme:

  • <style> and <link> elements are not allowed (SN2001); CSS lives in assets/.
  • A style="…" attribute may be static on plain HTML elements, but never contain {{ }} (SN2009). style is not accepted on hk-* tags (SN2004): use props or a class.
  • {% if %} cannot sit inside an attribute value (SN2020). Switch a class with class="btn btn-{{ block.settings.style }}" and a select setting, or wrap two versions of the element in {% if %}.
  • In the dev preview the stylesheet is inlined in the page, so a relative url() inside CSS does not point at assets/. Use asset_url() in templates for images (<img src="{{ asset_url('logo.svg') }}" alt="">) and fonts that are already available to the page.
  • All theme CSS together may be at most 512 KB.

Resets and specificity

Scope your selectors under the theme's root attribute so they never touch the rest of the page. A broad reset written that way is more specific than you might expect:

css
[data-hk-theme='x'] a { color: inherit; }   /* specificity (0,1,1) */
.btn { color: white; }                      /* specificity (0,1,0) */

The reset wins over .btn on every <a class="btn">, because an attribute selector plus an element beats a single class. Wrap the whole selector in :where(), which always counts as zero specificity, and the reset drops to (0,0,0):

css
:where([data-hk-theme='x'] a) { color: inherit; }   /* specificity (0,0,0) */
.btn { color: white; }                              /* wins */

To keep the element's own weight, wrap only the scope: :where([data-hk-theme='x']) a has specificity (0,0,1), which .btn still beats.

Use :where() for resets and other low-priority defaults, and plain selectors for the styles that are meant to win.

Responsive props

Breakpoints are desktop-first:

PrefixApplies at
noneevery width (the base value)
tablet-1023px and below
mobile-639px and below

A prop marked responsive in the tag reference takes the prefixes:

html
<hk-grid columns="4" tablet-columns="2" mobile-columns="1" gap="24" mobile-gap="12">…</hk-grid>
<hk-heading text="{{ section.settings.title }}" size="56" tablet-size="40" mobile-size="28" />
<hk-section padding-y="96" mobile-padding-y="48">…</hk-section>
<hk-stack direction="row" mobile-direction="column" gap="16">…</hk-stack>

The product grid in the cookbook uses columns="4" tablet-columns="3" mobile-columns="2" and size="32" mobile-size="24" on its heading. The same file at two widths:

sections/product-grid.snf (excerpt)Sneferu
<hk-heading text="{{ section.settings.heading }}" level="h2" size="32" mobile-size="24" />
<hk-product-grid products="{{ collection('featured').products }}" limit="{{ section.settings.count }}" columns="4" tablet-columns="3" mobile-columns="2" />
Result
1080 px wide: the base values, four columns.

Responsive props today: hk-section padding-y; hk-container padding-x; hk-stack direction, gap; hk-grid columns, gap; hk-heading and hk-text size; hk-card padding; hk-product-grid columns. A prefix on any other prop is SN2004 (with a "did you mean" hint).

For anything else, use a media query with the same widths in your CSS:

css
@media (max-width: 639px) { .announcement-link { font-size: 14px; } }

Left-to-right and right-to-left

An English page is left-to-right; an Arabic page is right-to-left. The renderer sets the direction and language on the theme root:

html
<div data-hk-theme="my-theme" dir="ltr" lang="en">…</div>

Rules that keep one stylesheet correct in both directions:

DoInstead of
margin-inline-start, padding-inline, inset-inline-endmargin-left, padding-right, right
text-align: start / end (and align="start" on tags)text-align: left / right
border-inline-startborder-left
flex and grid (they follow dir automatically)floats and absolute left/right offsets
[dir="rtl"] .arrow { transform: scaleX(-1); } for icons that pointa separate RTL stylesheet
  • The hk-* tags already use logical properties (margin-inline, padding-inline, padding-block) and start/end alignment.
  • dir and locale are available in templates ({{ dir }}, {% if locale == 'en' %}) for the rare case where markup must differ.
  • Arabic script needs more line height than Latin: 1.6-1.8 for body text is a good default, with no letter-spacing.
  • Test every locale the theme lists: http://127.0.0.1:4100/?locale=<code>.
  • Write numbers with Western digits (EGP 1,290.00), as money and date do.

Passthrough attributes on hk-* tags

Every hk-* tag accepts these attributes and writes them on its root element:

AttributeBehaviour
classadded after the tag's own classes, reduced to letters, digits, -, _
idone safe token
role, titlewritten as given (escaped)
data-*written as given (escaped); data-hk-* is reserved for the platform and dropped
aria-*written as given (escaped)

They are the main styling hook for tags:

html
<hk-card class="tier" data-best="{{ best }}" aria-label="{{ name }}">…</hk-card>
css
.tier[data-best="true"] { outline: 2px solid var(--hk-color-accent); }

Next steps