К основному содержанию
правило

fontawesome — правило для Cursor: настройка иконок и установка

Правило задаёт стандарты подключения Font Awesome 7, выбора стилей и размеров иконок и настройки Kit. Помогает поддерживать единый вид интерфейса и избегать ошибок при загрузке.

Установить в Cursor · Вручную: положить файлы Все способы и платформы ↓
.cursor/rules/fontawesome.mdc
Открыть на GitHub

Что делает fontawesome

Правило описывает работу с Font Awesome 7 в веб-интерфейсе. Оно рекомендует подключать Kit через скрипт в head, использовать тег i с явным префиксом стиля, а размер иконок задавать классами вроде fa-lg или fa-5x. Для собственных значков предусмотрена загрузка SVG в Kit с префиксом fa-kit.

Отдельные рекомендации касаются размера загружаемых ресурсов: в настройках Kit следует оставлять только используемые стили и категории иконок. Самостоятельный хостинг рассматривается как вариант для проектов с особыми требованиями к производительности и обслуживанию ресурсов. Для большинства проектов правило рекомендует подключение через Kit.

При загрузке собственных SVG важны корректный viewBox, явные width и height, а также подходящая структура path. Если значки отображаются пустыми или квадратами, нужно проверить расположение скрипта Kit и ошибки загрузки в консоли браузера. Опечатка в классе иконки тоже приводит к проблемам с отображением.

Какие задачи решает

  • Подключить Font Awesome Kit в head страницы
  • Выбрать явный стиль для каждой иконки
  • Настроить размер значков через классы Font Awesome
  • Сократить загрузку ненужных наборов иконок в Kit
  • Проверить SVG и исправить ошибки отображения значков

Примеры запросов агенту

  • Проверь подключение Font Awesome 7 и перенеси скрипт Kit в head, если он стоит неправильно.
  • Исправь классы иконок в интерфейсе и задай явные стили и размеры Font Awesome.
  • Проверь собственные SVG для Kit на корректность viewBox, width, height и структуры path.

Как установить fontawesome

Вручную: положить файлы

.cursor/rules/fontawesome.mdc

Во frontmatter: description, globs, alwaysApply

По шагам, с командами для каждой платформы: Cursor rules: файлы .mdc, четыре режима и замена .cursorrules

Вопросы о fontawesome

Как установить правило fontawesome в Cursor?

Добавь файл правила в .cursor/rules/fontawesome.mdc. После этого Cursor сможет использовать его рекомендации при работе с кодом проекта.

Что делает правило fontawesome?

Оно задаёт рекомендации по подключению Font Awesome 7, разметке иконок, их стилям и размерам. Также описывает настройку Kit и проверку собственных SVG.

Как правильно подключать Font Awesome Kit?

Размести скрипт Kit внутри head каждой страницы. В настройках Kit оставь только используемые стили и категории, чтобы не загружать лишние наборы иконок.

Исходный текст

fontawesome.mdc · CC0-1.0
---
description: This guide provides definitive rules for integrating and utilizing Font Awesome 7 icons, focusing on accessibility, performance, and maintainability through Kit-based setup and modern best practices.
globs: **/*
---
# fontawesome Best Practices

Font Awesome 7 is the definitive source for scalable UI icons in our web applications. Leveraging its power correctly ensures visual consistency, accessibility, and optimal performance. This guide outlines our team's mandatory best practices for Font Awesome integration.

## 1. Code Organization and Structure

Always use a Font Awesome Kit for integration. It's the most robust and feature-rich method, providing auto-accessibility and simplified management.

### 1.1 Kit-Based Setup

**Always embed your Font Awesome Kit script in the `<head>` of every page.** This ensures icons load early, prevents FOUT (Flash of Unstyled Text/Icons), and enables critical auto-accessibility features.

❌ **BAD: Script in `<body>` or via local files (unless explicitly self-hosting)**
```html
<body>
  <!-- ... other content ... -->
  <script src="https://kit.fontawesome.com/[YOUR_KIT_CODE].js" crossorigin="anonymous"></script>
</body>
```

✅ **GOOD: Script in `<head>`**
```html
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My Awesome App</title>
  <!-- Font Awesome Kit must be here -->
  <script src="https://kit.fontawesome.com/[YOUR_KIT_CODE].js" crossorigin="anonymous"></script>
  <!-- ... other head elements ... -->
</head>
```

### 1.2 Icon Markup

Use the `<i>` tag with appropriate Font Awesome classes. This is the simplest and most widely supported method.

❌ **BAD: Using `<span>` or other elements without a strong reason**
```html
<span class="fa-solid fa-user"></span>
```

✅ **GOOD: Using `<i>` for standard icons**
```html
<i class="fa-solid fa-user"></i>
```

### 1.3 Custom Icons

For icons not available in Font Awesome, upload them to your Kit. Treat them exactly like native icons for consistency.

❌ **BAD: Manually embedding custom SVGs or using separate icon libraries**
```html
<img src="/assets/custom-icon.svg" alt="Custom Icon">
```

✅ **GOOD: Uploading custom SVGs to your Kit and using `fa-kit` prefix**
```html
<!-- In your Kit, you've uploaded 'my-custom-icon.svg' -->
<i class="fa-kit fa-my-custom-icon"></i>
<!-- For duotone custom icons -->
<i class="fa-kit-duotone fa-my-duotone-icon"></i>
```

## 2. Common Patterns and Anti-patterns

### 2.1 Icon Styles

Always specify the icon style (e.g., `fa-solid`, `fa-regular`, `fa-brands`). Consistency in style is crucial for a unified UI.

❌ **BAD: Omitting style, relying on default (which can change or be ambiguous)**
```html
<i class="fa-user"></i> <!-- Which style? -->
```

✅ **GOOD: Explicitly defining the style**
```html
<i class="fa-solid fa-user"></i>
<i class="fa-regular fa-star"></i>
<i class="fa-brands fa-github"></i>
<i class="fa-sharp fa-solid fa-gear"></i>
```

### 2.2 Sizing Icons

Utilize Font Awesome's sizing utilities to maintain consistent vertical alignment and scale. Avoid custom CSS `font-size` overrides unless absolutely necessary for unique cases.

#### 2.2.1 Relative Sizing (for UI elements)

Use `fa-xs` to `fa-2xl` when icons need to align with text or other UI components. These classes adjust size while preserving vertical alignment.

❌ **BAD: Custom CSS `font-size` for inline icons**
```html
<p><i class="fa-solid fa-coffee" style="font-size: 1.2em;"></i> My coffee</p>
```

✅ **GOOD: Relative sizing classes for text alignment**
```html
<p><i class="fa-solid fa-coffee fa-lg"></i> My coffee</p>
<button><i class="fa-solid fa-plus fa-sm"></i> Add Item</button>
```

#### 2.2.2 Literal Sizing (for standalone icons)

Use `fa-1x` to `fa-10x` for larger, standalone icons where precise text alignment is not the primary concern.

❌ **BAD: Scaling large icons with `em` units that might break alignment**
```html
<div style="font-size: 5em;"><i class="fa-solid fa-camera"></i></div>
```

✅ **GOOD: Literal sizing classes for large, independent icons**
```html
<div class="hero-icon">
  <i class="fa-solid fa-camera fa-5x"></i>
  <h3>Capture the Moment</h3>
</div>
```

## 3. Performance Considerations

### 3.1 Kit Configuration

**Always configure your Kit to load only the icon subsets you actually use.** This significantly reduces download size and improves page load times. Regularly review and prune unused icon styles or categories.

❌ **BAD: Using a Kit with all icon styles enabled by default**
(This is a configuration anti-pattern, not directly code-related, but impacts code performance.)

✅ **GOOD: Customizing Kit to include only `Solid` and `Brands` if those are the only styles used.**
(Action: Visit fontawesome.com/kits, configure your kit.)

### 3.2 Self-Hosting (Advanced)

Only consider self-hosting Font Awesome if you have strict performance requirements, advanced caching strategies, and full control over your asset delivery. For most projects, Kit-based CDN is superior.

❌ **BAD: Self-hosting without a clear performance benefit or maintenance plan**
(Increased complexity, manual updates, potential for outdated versions.)

✅ **GOOD: Kit-based CDN for most projects; self-hosting only with justification and expertise.**
(Action: Stick to Kit unless a performance audit explicitly demands self-hosting and your team has the resources.)

## 4. Common Pitfalls and Gotchas

### 4.1 Missing Kit Script

Icons won't render if the Kit script is missing or incorrectly placed. Always verify its presence in the `<head>`.

❌ **BAD: Icons showing as squares or empty space**
```html
<!-- No Font Awesome script in head -->
<i class="fa-solid fa-bug"></i> <!-- Renders as a square -->
```

✅ **GOOD: Verify script is loaded and accessible**
(Action: Check browser console for network errors related to the Kit script, ensure correct URL.)

### 4.2 Incorrect Class Names

Typos in icon names or style prefixes are common. Use the Font Awesome search tool to confirm exact class names.

❌ **BAD: Typo in icon name**
```html
<i class="fa-solid fa-calender"></i> <!-- Should be fa-calendar -->
```

✅ **GOOD: Double-checking icon names**
```html
<i class="fa-solid fa-calendar"></i>
```

### 4.3 SVG Upload Guidelines

When uploading custom SVGs to a Kit, adhere strictly to Font Awesome's guidelines to prevent rendering issues.

*   **`viewBox`**: Must have explicit `width` and `height`.
*   **Paths**: Single `<path>` for monotone, two `<path>` elements (one with <100% opacity) for duotone.
*   **No unsupported attributes**: Keep SVGs clean.

❌ **BAD: Uploading complex SVGs with multiple groups, raster images, or missing `viewBox`**
(Leads to broken icons, inconsistent scaling, or upload failures.)

✅ **GOOD: Simplified SVGs, optimized for icon use**
```xml
<!-- Monotone Example -->
<svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
  <path fill="currentColor" d="M0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256z"/>
</svg>

<!-- Duotone Example (simplified) -->
<svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
  <path fill="currentColor" opacity="0.4" d="M... (secondary layer) ..."/>
  <path fill="currentColor" d="M... (primary layer) ..."/>
</svg>
```

## 5. Accessibility

Accessibility is paramount. Font Awesome Kits provide "auto-accessibility" features, but developers must provide the correct context.

### 5.1 Decorative Icons

If an icon is purely visual and adds no unique meaning (e.g., a bullet point in a list), ensure it's hidden from screen readers. Auto-accessibility handles this if the icon is *not* the sole content of an interactive element.

❌ **BAD: Decorative icon without `aria-hidden` when not auto-handled**
```html
<i class="fa-solid fa-star"></i> Welcome!
```

✅ **GOOD: Rely on Auto-Accessibility or explicitly hide decorative icons**
```html
<p><i class="fa-solid fa-star" aria-hidden="true"></i> Welcome to our site!</p>
<!-- Auto-accessibility will add aria-hidden="true" if the icon is adjacent to text -->
<button type="submit">
  <i class="fa-solid fa-envelope"></i> Email Us!
</button>
```

### 5.2 Semantic Icons

If an icon conveys meaning (e.g., a "next page" arrow, a "message" icon in a button), provide an accessible text alternative. Use the `title` attribute, and Font Awesome's auto-accessibility will convert it into a screen-reader-only span.

❌ **BAD: Semantic icon without any accessible label**
```html
<button type="submit">
  <i class="fa-solid fa-arrow-right"></i>
</button>
```

✅ **GOOD: Semantic icon with a descriptive `title` attribute**
```html
<button type="submit">
  <i class="fa-solid fa-arrow-right" title="Next Page"></i>
</button>
<!-- Auto-accessibility will render this as: -->
<!-- <i class="fa-solid fa-arrow-right" aria-hidden="true"></i> -->
<!-- <span class="sr-only">Next Page</span> -->
```

### 5.3 Manual Accessibility (Fallback)

If Auto-Accessibility is unavailable (e.g., self-hosting older versions, specific framework integrations), you must manually apply `aria-hidden="true"` for decorative icons or an `sr-only` span for semantic ones.

❌ **BAD: Assuming auto-accessibility is always active**
(Always verify your setup or explicitly add attributes.)

✅ **GOOD: Understanding when manual intervention is needed**
```html
<!-- Manual decorative -->
<i class="fa-solid fa-bell" aria-hidden="true"></i> Notifications

<!-- Manual semantic -->
<button>
  <i class="fa-solid fa-trash" aria-hidden="true"></i>
  <span class="sr-only">Delete Item</span>
</button>
```

## 6. Theming

Font Awesome icons inherit `font-size` and `color` from their parent elements. Leverage this for consistent theming.

❌ **BAD: Applying inline styles or overly specific CSS to individual icons**
```html
<i class="fa-solid fa-gear" style="color: blue; font-size: 24px;"></i>
```

✅ **GOOD: Styling icons via parent elements or utility classes**
```css
/* In your CSS */
.primary-button .fa-icon {
  color: var(--color-primary);
}
.large-heading .fa-icon {
  font-size: 1.2em; /* Scales relative to heading */
}
```
```html
<button class="primary-button">
  <i class="fa-solid fa-gear fa-icon"></i> Settings
</button>
<h1 class="large-heading">
  <i class="fa-solid fa-chart-line fa-icon"></i> Dashboard
</h1>
```

## 7. Component Architecture

When integrating Font Awesome into component-based frameworks (React, Vue, Angular), **always use the official Font Awesome component libraries** for that framework. They handle SVG rendering, accessibility, and updates gracefully.

❌ **BAD: Manually embedding `<i>` tags within framework components without official wrappers**
```jsx
// React example
function MyButton() {
  return <button><i className="fa-solid fa-save"></i> Save</button>;
}
```

✅ **GOOD: Using official Font Awesome components**
```jsx
// React example with @fortawesome/react-fontawesome
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faSave } from '@fortawesome/free-solid-svg-icons';

function MyButton() {
  return <button><FontAwesomeIcon icon={faSave} /> Save</button>;
}
```

## 8. Testing Approaches

### 8.1 Visual Regression Testing

Include Font Awesome icons in your visual regression tests (e.g., Storybook with Chromatic, Playwright visual comparisons). This catches unexpected changes in icon rendering, sizing, or alignment.

### 8.2 Accessibility Testing

Regularly run automated accessibility checks (e.g., Axe-core, Lighthouse) on pages containing icons. Manually test with screen readers to ensure semantic icons are correctly announced and decorative icons are ignored.

❌ **BAD: Assuming icons "look fine" and skipping visual/accessibility tests**
(Icons are critical UI elements and can easily break or become inaccessible.)

✅ **GOOD: Integrating icon rendering and accessibility into CI/CD pipelines.**
(Action: Add visual regression and accessibility checks to your component stories or end-to-end tests.)

© sanjeed5 · CC0-1.0 · sanjeed5/awesome-cursor-rules-mdc

Похожие правила IDE

Все правила IDE по теме «Фронтенд и UI» →
better-icons better-auth Ищет векторные значки в 200 каталогах через Iconify и скачивает SVG прямо из терминала или через вызовы агента. CX Codex +1 5 900установок icon-set-generator jezweb Скилл рисует набор SVG-иконок под конкретный проект: один стиль, одна сетка, одинаковый штрих. Пригодится, когда сайту нужен свой набор, а не Lucide. CX Codex +1 1 900установок morphing-icons raphael-salaja Скилл помогает создавать компоненты иконок, плавно перетекающих друг в друга за счёт трансформации трёх SVG-линий вместо обычного crossfade. CX Codex +1 362установок Iconoteka iconoteka Даёт ассистенту доступ к 1400 иконкам в 7 начертаниях и 2 стилях. Вместо выдуманного пути он вернёт готовую SVG-разметку. CX Codex +1 ★ 13звёзд репо Svg/icons MCP svgicons-com Подключает ИИ-ассистента к каталогу из 320K+ открытых SVG-иконок: поиск, подбор под интерфейс, экспорт в PNG и коллекции. CX Codex +1 setup-fa FortAwesome Настраивает Font Awesome в проекте с нуля: определяет фреймворк, подбирает Kit или npm-пакеты и создаёт файл конфигурации .font-awesome.md. CX Codex +1 503установок

Из того же набора240

Весь набор →
git Задаёт командные стандарты Git в Cursor: правила именования веток, формат Conventional Commits, чистку истории через rebase и хуки pre-commit. ★ 3 580звёзд репо gensim Правило задаёт практики для Python-кода с gensim: воспроизводимый запуск моделей и подготовку корпусов для тематического моделирования. Пригодится при сборке NLP-пайплайна. ★ 3 580звёзд репо gcp Правило для Cursor задаёт, как писать, разворачивать и сопровождать приложения на Google Cloud: IaC, идемпотентность, права сервисных аккаунтов. ★ 3 580звёзд репо gcp-cli Задаёт стандарты написания скриптов для Google Cloud CLI. Помогает генерировать надёжные bash-скрипты с явными флагами проектов и строгим режимом обработки ошибок. ★ 3 580звёзд репо flutter Правило задаёт Cursor единый стиль Flutter-кода: форматирование, линты, слои MVVM и Riverpod. Пригодится, когда агент пишет виджеты и состояние в одном файле. ★ 3 580звёзд репо flask Задаёт стандарты архитектуры Flask в Cursor: шаблоны фабрики приложений, синтаксис Blueprints и запуск через WSGI или ASGI. ★ 3 580звёзд репо flask-restful Правило задаёт структуру Flask-RESTful API и рекомендует Pydantic для проверки входных данных и сериализации ответов. Пригодится при создании или рефакторинге Python API. ★ 3 580звёзд репо flake8 Правило для Cursor задаёт, как настроить flake8 и какие проверки включить. Пригодится, если в проекте есть Python и хочется ловить стилевые ошибки и баги до коммита. ★ 3 580звёзд репо

Спонсоры проекта

Компании, которые помогают держать аналитику открытой