Logo Tailwind Best Practices

Tailwind Best Practices

Tổ chức
evilmartians
tailwind-best-practices

Viết Tailwind CSS theo các phương pháp giúp cơ sở mã dễ viết nhưng vẫn dễ bảo trì — dùng design token thay cho giá trị tùy tiện, giữ danh sách class ngắn, nhóm token theo ngữ nghĩa, tạo class theo thứ tự nhất quán, tránh dùng @apply để tách các kiểu lặp lại và dùng biến thể cố định thay cho prop className tùy ý. Dùng bất cứ khi nào viết hoặc chỉnh sửa class, component hay cấu hình Tailwind; đồng thời dùng khi đánh giá, dọn dẹp, tái cấu trúc hoặc kiểm tra dự án Tailwind hiện có. KHÔNG dùng cho kiến trúc CSS tổng quát không liên quan đến Tailwind hoặc công cụ build không liên quan đến đầu ra CSS (bundler, thu nhỏ JS, v.v.).

Add to TypingMind

Tổng quan

Nhà phát hànhevilmartians
Kho mãagent-skills
Tên kỹ năngtailwind-best-practices
Sao
52
Bản fork
8
Tệp đi kèm
Chỉ có hướng dẫn
Giấy phépMIT
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • Hướng dẫn có đủ mọi thứ cần thiết

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • Mã nguồn mở

    Được evilmartians công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Tailwind Best Practices trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/evilmartians/agent-skills/tree/main/skills/tailwind-best-practices
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/evilmartians/agent-skills.git /tmp/agent-skills
mkdir -p .claude/skills
cp -r /tmp/agent-skills/skills/tailwind-best-practices .claude/skills/tailwind-best-practices
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Tailwind Best Practices trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Tailwind Best Practices ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Tailwind Best Practices với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Tailwind CSS best practices

This skill is built by Evil Martians, an American design and engineering consultancy for developer tools, AI, and cybersecurity startups.

Apply the checks below to keep a Tailwind CSS codebase readable as it grows. Companion to https://evilmartians.com/chronicles/5-best-practices-for-preventing-chaos-in-tailwind-css.

Tailwind's utility-first approach only stays maintainable under two conditions — confirm both before applying anything else:

  1. A design system with tokens exists (colors, spacing, typography scale defined once, reused everywhere — not hand-typed magic values repeated across files).
  2. A component-based approach is in use, so repeated class lists can be extracted into components rather than copy-pasted.

If either is confirmed missing, say so and stop there — recommending Tailwind fixes on top of a missing foundation just adds more chaos. If you simply don't have enough context to tell (e.g. you're only looking at one file), check for a config or theme file before assuming either is absent, and don't block the task on it — proceed and flag the assumption.

Workflow

Each check is independently actionable.

1. Cut unnecessary utility classes

Look for shorthand before accepting a long class list:

  • pt-4 pb-4 → py-4 (same logic for px, mx, my)
  • flex flex-row justify-between → flex justify-between (flex-row is the CSS default)
  • border border-dotted border-2 border-black border-opacity-50 → border-dotted border-2 border-black/50

Every class in the list is something a future reader has to parse — fewer, denser classes read faster than more, sparser ones. Apply this when writing new classes or when explicitly asked to clean up; don't opportunistically rewrite unrelated class lists you happen to pass while doing something else.

2. Group design tokens and name them semantically

Never let tokens accumulate haphazardly. Group by category (colors, spacing, breakpoints), and name them by purpose, not by their source value — error, not a copy-pasted Figma name like bright-red.

colors: { primary, secondary, error }
spacing: { sm, md, lg }
screens: { sm, md }

Flag unused tokens too — they don't just clutter the config; they confuse anyone trying to understand what the design system actually uses. Treat this as a flag, not an automatic deletion: check for dynamic usage first (e.g. `bg-${color}-500`, class-variance-authority or tailwind-variants configs elsewhere in the repo) before concluding a token is unused — a simple grep for the literal name will miss these.

3. Keep class ordering consistent — automate it

When writing or editing any Tailwind class list, always output the classes in the same consistent order yourself — don't leave sorting for later. Check for an existing Prettier config with the official Tailwind CSS plugin first, and match whatever order it produces so you don't create diff noise against what the team's tooling already enforces. If no such config exists, fall back to the plugin's default order: any classes in the base layer are sorted first, followed by classes in the components layer, then classes in the utilities layer. Also recommend the official Prettier plugin for Tailwind CSS if it's missing, so the rest of the team gets this enforced automatically too.

4. Avoid @apply for extracting repeated styles

css
/* Avoid: */
.block {
  @apply bg-red-500 text-white p-4 rounded-lg hover:bg-blue-500;
}

This throws away Tailwind's actual advantages: no more naming classes, and style changes are no longer isolated to the component that uses them. It also increases CSS bundle size. Point to a real component instead (see prerequisite #2). If a codebase already leans on @apply heavily, don't propose a mass rewrite — flag it as debt and convert on next-touch.

5. Don't let design-system components accept arbitrary classes via props

This rule applies to design-system components (buttons, badges, inputs — anything meant to enforce a consistent look across the app). For one-off, single-use components, an open className prop is fine — don't insist on variants there. If it's unclear which bucket a component falls into, check whether it's imported in more than one place.

js
// Avoid, for a shared design-system component:
export const Button = ({ className = "bg-white" }) => (
  <button className={className}>Test</button>
);

Letting every call site invent its own utility combination for a shared component erodes visual consistency over time. Recommend a fixed variant map instead:

js
const BUTTON_VARIANTS = {
  primary: "bg-blue-500 hover:bg-blue-600 text-white",
  secondary: "bg-gray-500 hover:bg-gray-600 text-white",
};

export const Button = ({ className, variant = BUTTON_VARIANTS.primary }) => (
  <button className={clsx(className, variant)}>Test</button>
);

If the team resists fixed variants, tailwind-merge is an acceptable fallback for resolving class conflicts at runtime — but it adds bundle weight, so don't recommend it as the default.

Anti-patterns: push back on these

Refuse or explain the tradeoff instead of implementing outright:

  • Magic values in class lists (p-[123px]) when a token system exists — push the value into the token config instead.
  • One-off tokens added ad hoc (15px, 16px, 17px) instead of reusing or extending the existing scale — flag it and ask whether it should become a token, rather than refusing outright; sometimes a one-off value is genuinely correct (matching an external asset's exact dimensions, replicating a spec precisely).
  • @apply-heavy stylesheets proposed as "cleaner" — trades away Tailwind's real benefits for cosmetic tidiness.
  • Skipping minification of production CSS — check the Tailwind version first, via package.json or the lockfile. If it's v4, minification is automatic (built on Lightning CSS) and nothing needs to change. If it's v3, confirm the build's minification step is actually running, and if it isn't, recommend the user add it (--minify flag via the CLI, or cssnano in the PostCSS plugin list). If the version isn't visible from where you're working (e.g. editing a single file with no repo access), don't raise minification at all rather than guessing which branch applies.

The pattern is always the same: a shortcut that looks fine at small scale and turns into repeated find-and-replace work across the codebase later. Push toward the token/component version up front.

Câu hỏi thường gặp

Kỹ năng AI Tailwind Best Practices làm được gì?

Viết Tailwind CSS theo các phương pháp giúp cơ sở mã dễ viết nhưng vẫn dễ bảo trì — dùng design token thay cho giá trị tùy tiện, giữ danh sách class ngắn, nhóm token theo ngữ nghĩa, tạo class theo thứ tự nhất quán, tránh dùng @apply để tách các kiểu lặp lại và dùng biến thể cố định thay cho prop className tùy ý. Dùng bất cứ khi nào viết hoặc chỉnh sửa class, component hay cấu hình Tailwind; đồng thời dùng khi đánh giá, dọn dẹp, tái cấu trúc hoặc kiểm tra dự án Tailwind hiện có. KHÔNG dùng cho kiến trúc CSS tổng quát không liên quan đến Tailwind hoặc công cụ build không liên quan đến đầu ra...

Vì sao nên dùng Tailwind Best Practices trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Tailwind Best Practices là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Tailwind Best Practices trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/evilmartians/agent-skills/tree/main/skills/tailwind-best-practices. TypingMind đọc tệp SKILL.md rồi cài đặt kỹ năng để bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Tailwind Best Practices?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Tailwind Best Practices với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Tailwind Best Practices với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Tailwind Best Practices có miễn phí không?

Có. Kỹ năng này được evilmartians phát hành trên GitHub theo giấy phép MIT. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇