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:
- Design tokens in
theme.jsonbecome CSS variables. - Tag props (
padding-y,columns,size,color, …) generate scoped CSS for eachhk-*tag, with tablet and mobile variants. - Your stylesheet in
assets/*.cssstyles everything else.
Tokens → CSS variables
"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:
[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);
}| Token | Variable | Use |
|---|---|---|
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-width | max 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:
<hk-section background="theme:primary">
<hk-heading text="{{ section.settings.title }}" color="theme:background" />
</hk-section>.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:
"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.
| Family | Arabic | Weights |
|---|---|---|
| Cairo | yes | 200-1000 (variable) |
| IBM Plex Sans Arabic | yes | 300, 400, 500, 600, 700 |
| Tajawal | yes | 400, 500, 700, 800 |
| Almarai | yes | 400, 700, 800 |
| Readex Pro | yes | 160-700 (variable) |
| Noto Kufi Arabic | yes | 100-900 (variable) |
| Rubik | yes | 300-900 (variable) |
| Baloo Bhaijaan 2 | yes | 400-800 (variable) |
| Amiri | yes | 400, 700 |
| Noto Naskh Arabic | yes | 400-700 (variable) |
| El Messiri | yes | 400-700 (variable) |
| Reem Kufi | yes | 400-700 (variable) |
| Lalezar | yes | 400 |
| Changa | yes | 200-800 (variable) |
| Markazi Text | yes | 400-700 (variable) |
| Scheherazade New | yes | 400, 500, 600, 700 |
| Aref Ruqaa | yes | 400, 700 |
| Inter | no | 100-900 (variable) |
| Martian Mono | no | 100-800 (variable) |
| Space Grotesk | no | 300-700 (variable) |
| JetBrains Mono | no | 100-800 (variable) |
| Playfair Display | no | 400-900 (variable) |
| Cormorant Garamond | no | 300-700 (variable) |
| Fraunces | no | 100-900 (variable) |
| Oswald | no | 200-700 (variable) |
| Bebas Neue | no | 400 |
| Nunito | no | 200-1000 (variable) |
| Fredoka | no | 300-700 (variable) |
| DM Sans | no | 100-1000 (variable) |
| Manrope | no | 200-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 withclass="…"; - the stable hooks the tags render:
| Tag | Stable classes |
|---|---|
hk-button | sn-btn, sn-btn-solid / sn-btn-outline / sn-btn-ghost |
hk-card | sn-card |
hk-badge | sn-badge, sn-badge-accent / -neutral / -success / -warning |
hk-price | sn-price, sn-now, sn-was |
hk-product-card, hk-product-grid items | sn-product-card, sn-title, plus sn-price |
hk-grid | sn-grid |
hk-section | inner 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:
.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 inassets/.- A
style="…"attribute may be static on plain HTML elements, but never contain{{ }}(SN2009).styleis not accepted onhk-*tags (SN2004): use props or a class. {% if %}cannot sit inside an attribute value (SN2020). Switch a class withclass="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 atassets/. Useasset_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:
[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):
: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:
| Prefix | Applies at |
|---|---|
| none | every width (the base value) |
tablet- | 1023px and below |
mobile- | 639px and below |
A prop marked responsive in the tag reference takes the prefixes:
<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:
<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" />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:
@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:
<div data-hk-theme="my-theme" dir="ltr" lang="en">…</div>Rules that keep one stylesheet correct in both directions:
| Do | Instead of |
|---|---|
margin-inline-start, padding-inline, inset-inline-end | margin-left, padding-right, right |
text-align: start / end (and align="start" on tags) | text-align: left / right |
border-inline-start | border-left |
flex and grid (they follow dir automatically) | floats and absolute left/right offsets |
[dir="rtl"] .arrow { transform: scaleX(-1); } for icons that point | a separate RTL stylesheet |
- The
hk-*tags already use logical properties (margin-inline,padding-inline,padding-block) andstart/endalignment. dirandlocaleare 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), asmoneyanddatedo.
Passthrough attributes on hk-* tags
Every hk-* tag accepts these attributes and writes them on its root element:
| Attribute | Behaviour |
|---|---|
class | added after the tag's own classes, reduced to letters, digits, -, _ |
id | one safe token |
role, title | written 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:
<hk-card class="tier" data-best="{{ best }}" aria-label="{{ name }}">…</hk-card>.tier[data-best="true"] { outline: 2px solid var(--hk-color-accent); }