# 4. Styles

## 4.1 ID styles and class styles

| | ID style (`I`) | Class style (`C`) |
|---|---|---|
| Applies to | That one element (its server ID `jk-…`) | **Every document** that uses the class — classes are global |
| Set in the editor | The right panel, with the element selected | Add the class to an element, then edit it from the class chip or from the **Styles** view in the left panel |
| Published | With the document's CSS (`css/<id>.<version>.css`) when the document is published | In `css/common.css`, regenerated whenever any document compiles |
| Deleting | Remove the declarations (CLI/REST: send `css: ""`) | Removing the class from an element leaves the global definition; the row stays |

Both live in one table, `{prefix}jikji_styles`, keyed by name, so an ID and a class cannot share a name and a name's type (`I`/`C`) cannot change. Names use letters, digits, `-` and `_`, do not start with a digit, and are at most 150 characters; the editor refuses to add anything else, and the server refuses to save a document with an unsaveable name rather than dropping it silently. Renaming a class is not supported (the name is also in every document's HTML).

The editor's **Styles** view lists the classes the current page uses — including classes on elements inside text blocks, excluding classes inside Code blocks and inside SVGs. A class listed there can be edited before it has a style row; the first change creates the row. A class whose name equals an element ID in the document cannot be styled (the panel says so): remove the class and use another name.

## 4.2 The style panel

With an element selected, the Properties tab shows its **ID**, its classes (**Add class**), a **State** selector and the style sections:

| Section | Controls |
|---|---|
| Layout | Display, flex/grid direction, wrap, align, justify, gaps, columns, rows |
| Flex Child / Grid Child | Grow, shrink, basis, order, align self, column/row placement |
| Spacing | Margin and padding — a box control with linked or per-side editing |
| Size | Width, height, min/max, aspect ratio, overflow, object fit |
| Position | Position, offsets, z-index |
| Typography | Family, size, weight, line height, color, align, decoration, case, spacing |
| Backgrounds | Color, image (media library), size, position, repeat, attach; layers |
| Borders | Style, width, color, radius; outline |
| Box Shadows / Text Shadows | Layers with X, Y, blur, spread, color |
| Transitions / Transforms | Property, duration, easing, delay; transform functions, origin, perspective, backface |
| Filter / Backdrop Filter, Opacity | |
| List Item | Marker |
| Advanced | **Add declaration** — any allowed property by name |

Values are stored as typed (`!important` included); the editor does not confirm a value the browser cannot parse and tells you why.

## 4.3 Breakpoints and responsive editing

Jikji is **desktop-first**. The toolbar's canvas size selects both the preview width and the breakpoint you are editing:

| Canvas size | Edits | Media query on the page |
|---|---|---|
| Desktop (or any width above the tablet value) | Base declarations | none |
| Tablet Portrait | `--jikji-bp-tablet` (991px by default) | `@media (max-width: 991px)` |
| Mobile Landscape | `--jikji-bp-mobile-landscape` (767px) | `@media (max-width: 767px)` |
| Mobile Portrait | `--jikji-bp-mobile-portrait` (478px) | `@media (max-width: 478px)` |

Smaller breakpoints inherit from larger ones (base → tablet → mobile landscape → mobile portrait); a value set at a narrower size overrides only there. Styles store the **variable name**, not the pixel value, so changing a breakpoint in Appearance → Jikji regenerates every stylesheet with the new value. The three values must strictly decrease; the settings screen refuses to save an invalid order, and if an old invalid set is stored the editor warns that responsive edits may land on the wrong breakpoint.

`W`, `H` and `%` in the toolbar set an exact canvas width, height and zoom.

## 4.4 States

The **State** selector in the Properties tab switches the style sections to a state block, and the canvas shows the selected element in that state while it is chosen:

| State | Selector on the page |
|---|---|
| Hover | `:hover` |
| Keyboard focus | `:focus-visible` |
| Focus inside | `:focus-within` |
| Pressed | `:active` |
| Disabled | `:disabled`, `[aria-disabled="true"]` |
| Current (aria-current) | `[aria-current]` (not `"false"`) |
| Selected (aria-selected) | `[aria-selected="true"]` |
| Expanded (aria-expanded) | `[aria-expanded="true"]` |
| Open (details) | `[open]` |
| Checked | `:checked` |

State blocks apply at every width (they cannot be put inside a media query). In a style row they are written `@state hover{…}` after the base declarations ([4.6](#46-the-style-row-format)).

## 4.5 What CSS is accepted

The server keeps only properties on its **allowlist** — box and logical properties (`margin-inline`, `padding-block`, `inset-*`, `block-size`…), flex and grid, typography (`font-variant-numeric`, `text-underline-offset`, `text-decoration-thickness`…), backgrounds and borders, scroll (`scroll-margin-*`, `scroll-padding-*`, `scroll-snap-*`), transforms, transitions, filters, `clip-path`, `fill`, `stroke`, and so on (the list is `Jikji\Compiler\Css_Sanitizer::ALLOWED_PROPERTIES`, and the editor's controls match it). Custom properties `--name` are accepted (not `--jikji-*`, which is reserved) with the same value checks.

Dropped declarations — unsupported properties, dangerous values (`{}<>`, `javascript:`, `expression(`), malformed declarations — are reported in the save result as `cssDropped` (`{name, property, value, media, reason}` with `reason` `unsupported`, `unsafe` or `invalid`) and as one warning line; the rest is saved. From the CLI or REST, `--strict-css` / `strictCss: true` refuses the whole save with `jikji_css_dropped` when anything would be dropped — use it when porting mock-up CSS, and move what Jikji does not take (compound selectors, pseudo-elements, `@font-face`, `@keyframes`) into the theme stylesheet and use its classes.

## 4.6 The style row format

CLI and REST send style rows as JSON. One row is a name, a type and a `css` string of **declarations, then `@state` blocks, then whole `@media` blocks**:

```json
[
  {"name": "{hero}", "type": "I", "css": "padding:96px 24px;background:#f5f3ff;@media (max-width: --jikji-bp-tablet){padding:64px 20px;}@media (max-width: --jikji-bp-mobile-portrait){padding:40px 16px;}"},
  {"name": "btn-primary", "type": "C", "css": "--btn-bg:#5b3df5;display:inline-block;padding-block:12px;padding-inline:22px;border-radius:6px;background:var(--btn-bg);color:#ffffff;@state hover{background:#4a2fe0;}@state focus-visible{outline:2px solid #5b3df5;outline-offset:2px;}"}
]
```

- Media conditions use the breakpoint variables; the compiler substitutes the configured pixel values.
- `@state <name>{…}` takes the names of [4.4](#44-states) and compiles to `#id:hover{…}` and so on.
- A row for an element in a loop compiles to `:is(#id,[id^="id--"])` so every repeated copy keeps the style at ID specificity ([Dynamic data 5.5](05-dynamic-data.md#55-loops)).
- Sending a document's rows: send **all** of the document's ID rows each time (rows not sent stay as they are); send a class row only when creating or changing that class, with `baseCss` (the current `css`) when changing — `wp jikji` refuses an existing class sent without it (`jikji_class_exists`) unless `--update-classes` is given, and REST does the same with `existingClasses: "refuse"` (its default is overwrite). Check existing classes first with `wp jikji styles list` or `GET /styles`.

## 4.7 How Jikji CSS meets the theme

Stylesheets load in this order: core and global styles (theme.json) → the theme stylesheet → `common.css` (classes) → the document's CSS (IDs and states). At equal specificity Jikji wins because it comes later; a theme rule with higher specificity still wins — lower the theme selector or use an ID style. Compound selectors (`.nav[open]>summary .icon`), pseudo-elements and keyframes belong in the theme; the Jikji document uses their classes.
