Communitygithub.com

ui-hierarchy

視覚的な階層構造を持つUIを構築します。フラットで重みが均一なコンポーネントではなく、意図的な優先順位付けを行います。

ui-hierarchy とは?

このスキルは、AIがUIコード(HTML/CSS、React、Tailwind、SwiftUI、Figma-to-code出力)を作成またはレビューする際に、視覚的な階層構造を強制します。特に、画面に複数のボタン、カード、またはアイテムリストがある場合に自動的にトリガーされ、すべての要素が同じコントラストで表示され、主要なアクションが不明確になる問題を防止します。手順は以下の通りです。まず、コードを書く前に要素をランク付けし、各画面に1つのプライマリアクションのみを割り当てます。次に、サイズ、太さ、色、周囲のスペース、位置/サーフェスのうち少なくとも2つの次元で異なるように設定し、視覚的な差を明確にします。また、群化のためにスペーシングを適切に調整し(グループ間はグループ内の少なくとも2倍)、カードや境界線、影は必要な場合にのみ使用します。最後に、自動監査("目を細めてテスト"(Squint test)およびグレースケールテスト)を実行し、結果を報告します。出力は常にランクブロック、コード、監査ラインの3部構成で提供されます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/whynotcuong/coren-design-skills/tree/HEAD/skills/ui-hierarchy

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

UI hierarchy

Tóm tắt: chạy khi AI code hoặc review giao diện. Bắt AI xếp hạng phần tử trước khi code, mỗi màn đúng một nút chính, chữ và khoảng cách phải chênh đủ rõ, cuối cùng tự soát bằng phép thử nheo mắt.

The failure this exists to prevent

Generated UI is usually not ugly. It is flat. Every button gets the same fill, every block gets the same card, every gap is the same size, and the type scale spans 14px to 20px. The result reads as a wall of equally important things, so the user has to parse the whole screen to find the one thing they came for.

The fix is not more decoration. It is spending emphasis like a limited budget: a few things loud, most things quiet.

Step 1: Rank before you style

Never start with markup. First write down the ranking for the view, as a short comment or a note in the reply:

Primary   : the one thing this screen exists for
Secondary : 2-4 supporting elements
Tertiary  : everything else (metadata, labels, helper text, escape hatches)

If more than roughly 20% of the elements land in Primary or Secondary, the ranking is wrong. Push things down. A screen where everything matters is a screen where nothing does.

Ask which single element the user should see first if the screen flashed for one second. That element gets the strongest treatment on the page, and nothing else competes with it.

Step 2: One primary action per view

Buttons are where flatness shows first. Use a strict ladder:

RankTreatmentCount per view
PrimarySolid fill, highest contrast, accent or near-blackExactly 1
SecondaryNeutral fill or 1px border, no accent color0-2
TertiaryText only, muted, no border, no backgroundAny

Rules that matter more than the table:

  • Two solid filled buttons side by side is a bug, not a style choice. Demote one.
  • "Cancel", "Back", "Skip", "Learn more" are tertiary. They are escape hatches, not choices of equal standing.
  • Destructive actions are not automatically red-filled. Red fill is reserved for when deleting is the primary action, typically inside a confirm dialog. In a row of items, delete is a quiet tertiary control.
  • Icon buttons in a toolbar are tertiary by default. If one of them is genuinely primary, give it a label.

The same ladder applies to non-buttons: one lead headline per section, one hero number per stat block, one highlighted row per list.

Step 3: Make differences visible, not technically present

Two elements of different rank must differ on at least two of these dimensions:

  • size
  • weight
  • color / opacity
  • surrounding space
  • position or surface

Changing one dimension slightly (16px to 17px, weight 500 to 600) reads as inconsistency, not hierarchy. When something is one step down in rank, make it look one step down.

Practical steps that are actually visible:

  • Type size: at least 1.25x between adjacent levels, 1.5x or more between a display element and body text.
  • Weight: jump 400 to 600 or 700. Do not use 500 as a ranking step; it is for optical tuning within one level.
  • Muted text: drop to roughly 55-70% of the primary text's contrast, and usually one size step down. Keep body text at 4.5:1 against its background.
  • Accent color: appears in about 3 places per screen at most. Once the accent is on every badge, chip and icon, it stops meaning "look here".

Squint test. Before finishing, mentally blur the screen. The primary element should still be the first thing that resolves. If everything blurs into one even texture, the hierarchy is decorative only.

Grayscale test. Remove all color. If the primary action is no longer identifiable, the hierarchy was carried entirely by hue and will collapse for anyone who scans quickly.

Step 4: Spacing carries grouping

Uniform spacing is the second-biggest cause of flatness. If every gap is the same, the eye cannot tell what belongs to what, and the UI compensates by wrapping everything in boxes.

Rule: the space around a group must be at least 2x the space inside it.

A workable default rhythm:

  • inside a group (label to value, icon to text): 4-8px
  • between related groups: 16-24px
  • between sections: 48-80px

Label sits close to its field. Helper text sits close to its field. Section headings sit closer to the content below them than to the content above. Getting this right removes most of the need for borders.

Step 5: Surfaces must be earned

Cards, borders and shadows are hierarchy tools, so spending them everywhere spends them on nothing.

  • Default to no card. Use whitespace to separate first.
  • Pick one separation method per level: border or background shift or shadow. Stacking all three on every block flattens the page again.
  • Elevation should map to actual layering: content on base, overlays and menus raised. A static content block is not "raised".
  • If every block on the screen is a bordered card, delete the borders from the non-primary ones and increase their outer spacing instead.

Step 6: Audit before handing it over

Run this pass on the finished code. Read references/audit.md for the failure catalog and before/after examples.

  1. Count solid filled buttons in the view. More than one, fix it.
  2. Squint test and grayscale test.
  3. Count how many places the accent color appears.
  4. Check that outer spacing beats inner spacing at every grouping level.
  5. Check whether the type scale actually steps, or just drifts by 1-2px.
  6. Remove every border and shadow that is not doing separation work.

State the result of this audit briefly when delivering the code, and name anything deliberately left flat and why.

Output contract

Every delivery of UI code under this skill has three parts, in this order. The contract exists so the ranking is a real decision made before the markup, not a rationalization written after it.

1. Rank block, before any code:

Primary   : <element>: <why it wins>
Secondary : <2-4 elements>
Tertiary  : <the rest, summarized>

2. The code.

3. Audit line, three sentences maximum: number of solid filled buttons, number of accent appearances, and anything deliberately left flat with the reason.

If the request is a small edit rather than a whole screen, shrink the contract to one line naming the rank of the thing being changed and what it must not outrank. Do not skip it entirely.

Token layer

Style by role, never by raw value, so hierarchy stays adjustable in one place:

--text-primary / --text-secondary / --text-muted
--surface-base / --surface-raised / --surface-sunken
--action-primary / --action-secondary / --action-quiet
--border-subtle / --border-strong
--space-1 (4) / --space-2 (8) / --space-4 (16) / --space-6 (24) / --space-12 (48)

If the project already has a design system or tokens, use its role names instead of inventing a parallel set. In Tailwind, express roles through a small set of composed classes rather than sprinkling arbitrary values per element.

Documenting a screen for developers

This skill does not cover handoff documentation (Anatomy, numbered markers, state samples). When the user asks to present, arrange or lay out a screen for dev, use the figma-dev-handoff-doc skill instead. Hierarchy rules here still apply to any new UI built along the way.

Screen archetypes

For hierarchy maps of specific screen types (form, list/table, dashboard, detail page, empty state, settings, modal), read references/archetypes.md.

Working in Vietnamese

When the conversation is in Vietnamese, read references/glossary-vi.md and use its term pairs so the vocabulary stays consistent across sessions. Explain hierarchy decisions by intent, not by class names.

What this skill does not cover

Brand aesthetics, motion, illustration, and copywriting (for UI text, use the copy-trim skill). Hierarchy is the structural layer underneath those. A screen can pass every rule here and still look generic, but a screen that fails these rules cannot be saved by styling.

Individual skills in this repo

This repo contains 2 individual skills — each has its own dedicated page.

関連スキル