15 icons in code, the 2026 answers
Icons in code
The icon questions developers keep asking, answered for 2026: SVG colour and sizing, sprites, React and Next.js, favicons, email, animation and icon fonts. Old answers fixed, with the browser support checked.
Change an SVG’s colour with CSS
Change an SVG icon’s colour with CSS today: currentColor for inline SVG, mask-image for img and background files, CSS variables for multi-colour icons.
Favicon files for 2026
The minimal favicon set for 2026: favicon.ico, an SVG with dark mode, a 180 px Apple touch icon and 192/512 manifest icons, with the exact tags to paste.
SVG icons in React and Next.js
Import SVG icons in React and Next.js in 2026: vite-plugin-svgr with ?react, SVGR under Turbopack in Next 16, plain img tags, and when an icon package is simpler.
Align an icon with text
Align an icon with text in CSS: inline-flex with align-items and gap, 1em icons, vertical-align -0.125em, and the new text-box trim (Baseline since August 2026).
SVG icon cut off or blurry?
Fix SVG icons that are cut off, blurry or the wrong size: what viewBox and width/height do, why icons clip or go soft, and how to keep strokes the same width.
Icons in React Server Components
Why icon libraries break or bloat React Server Components: fixing createContext and “Functions cannot be passed” errors, icons by name, and measuring bundles.
SVG icons in email
SVG in email in 2026: which clients show it (Gmail now does, as a PNG), why 2x PNG is still the safe choice, plus retina sizes, dark mode and alt text.
Icons showing as squares
Icon fonts showing squares or words? Find the cause (blocked font, CSP, wrong Font Awesome version, Material ligatures) and the correct 2026 setup or SVG fix.
Icon button size and labels
Icon button sizes for 2026: WCAG 2.2 AA asks 24 x 24 px, AAA 44, Apple 44 pt, Android 48 dp. Plus aria-label vs hidden text, aria-hidden SVGs and event.target.
SVG sprites in 2026
SVG sprites today: symbol and use href (xlink:href is legacy), colouring with currentColor and CSS variables, and why cross-origin sprites still fail.
SVG icons in CSS
Yes, you can put an SVG icon in ::before, ::after or a background. Colour it with a CSS mask and currentColor, and URL-encode data URIs instead of base64.
An icon inside an input field
Put a search, mail or password icon inside an input with a wrapper, an inline SVG and padding. Plus show-password buttons, clear buttons, focus colours and RTL.
How to animate SVG icons
SMIL is not deprecated: Chrome dropped that plan in 2016. How to animate SVG icons today with CSS, SMIL, Web Animations or Lottie, and respect reduced motion.
Optimise SVG icons with SVGO
Optimise SVG icons safely with SVGO 4: what changed in June 2025, the settings that still break icons and sprites, a tested config, and SVGOMG for non-coders.
Migrate from an icon font to SVG
Migrate from an icon font to SVG step by step: list your icon classes, map names, swap in components, sprites or drop-in CSS classes, then test it all.