返回顶部
I

Icons

Implement accessible icons with proper sizing, color inheritance, and performance.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
993
下载量
2
收藏
概述
安装方式
版本历史

Icons

## SVG vs Icon Fonts SVG is the modern standard: - Better accessibility (native ARIA support) - No flash of invisible/wrong icon (FOIT) - Multicolor support - Smaller bundles with tree-shaking Only consider icon fonts for legacy IE11 support. ## Accessibility Patterns **Decorative icons (next to visible text):** ```html <button> <svg aria-hidden="true" focusable="false">...</svg> Save </button> ``` **Informative icons (standalone, no label):** ```html <button aria-label="Save document"> <svg aria-hidden="true" focusable="false">...</svg> </button> <!-- Or with visually hidden text --> <button> <svg aria-hidden="true">...</svg> <span class="sr-only">Save document</span> </button> ``` **SVG with accessible name:** ```html <svg role="img" aria-labelledby="icon-title"> <title id="icon-title">Warning: system error</title> <!-- paths --> </svg> ``` Key rules: - `aria-hidden="true"` on SVGs that duplicate visible text - `focusable="false"` prevents unwanted tab stops in IE/Edge - `<title>` must be first child inside `<svg>` for screen reader support - IDs must be unique if multiple SVGs are inline ## Color Inheritance ```svg <svg fill="currentColor"> <path d="..."/> </svg> ``` `currentColor` inherits from CSS `color` property. The icon changes color with hover states automatically: ```css .button { color: blue; } .button:hover { color: red; } /* icon turns red too */ ``` Remove hardcoded `fill="#000"` from SVGs before using currentColor. For stroke-based icons, use `stroke="currentColor"` instead. ## Sizing Standard grid sizes: 16, 20, 24, 32px Match stroke weight to size: | Size | Stroke | Use case | |------|--------|----------| | 16px | 1px | Dense layouts, small text | | 20px | 1.25px | Default UI | | 24px | 1.5px | Buttons, primary actions | | 32px | 2px | Headers, navigation | Touch targets need 44x44px minimum—icon can be smaller if tappable area is larger via padding. ```css .icon-button { width: 24px; height: 24px; padding: 10px; /* Creates 44x44 touch target */ } ``` ## Scaling with Text ```css .icon { width: 1em; height: 1em; } ``` Icon scales with surrounding text size automatically. ## Symbol Sprites For many repeated icons, reduce DOM nodes with sprites: ```html <!-- Define once, hidden --> <svg style="display:none"> <symbol id="icon-search" viewBox="0 0 24 24"> <path d="..."/> </symbol> <symbol id="icon-menu" viewBox="0 0 24 24"> <path d="..."/> </symbol> </svg> <!-- Use anywhere --> <svg aria-hidden="true"><use href="#icon-search"/></svg> ``` External sprites (`<use href="/icons.svg#search"/>`) don't work in older Safari without polyfill. ## Performance Benchmark (1000 icons): - `<img>` with data URI: 67ms (fastest) - Inline SVG optimized: 75ms - Symbol sprite: 99ms - `<img>` external: 76ms Recommendations: - Tree-shake icon libraries (Lucide, Heroicons support this) - Don't import entire Font Awesome (1MB+)—use subset or switch to SVG - Inline critical icons, lazy-load sprite for non-critical ## Consistency - Stick to one icon set—mixing styles looks unprofessional - Match icon stroke weight to your font weight (regular text = 1.5px stroke) - Pick one style per context: outlined for inactive, filled for active - Optical alignment differs from mathematical—circles reach edges, squares don't - Name icons by appearance, not meaning: `stopwatch` not `speed` ## Common Mistakes - Missing `aria-hidden` on decorative icons—screen readers announce gibberish - Mixing rounded and sharp icon styles in same interface - Giant icon libraries for 10 icons—massive bundle bloat - Icon-only buttons without accessible name—impossible to use with screen readers - Hardcoded colors preventing theme switching - Stroke width not scaling with icon size—16px icon with 2px stroke looks heavy

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 icons-1776420056 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 icons-1776420056 技能

通过命令行安装

skillhub install icons-1776420056

下载 Zip 包

⬇ 下载 Icons v1.0.0

文件大小: 2.49 KB | 发布时间: 2026-4-17 19:37

v1.0.0 最新 2026-4-17 19:37
Initial release

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部