Getting Started with Web Icons
Updated on
Icons sit quietly all over a web interface, but they do a lot of work. They save space, speed up recognition, and keep a UI consistent when text alone would be clumsy or too slow to scan. This guide covers the basics that matter in practice: formats, sizing, colour, implementation, accessibility, performance, and the system rules that stop an icon set turning into a mess.
Picking an icon format without overthinking it
The main web icon formats are SVG, PNG, and icon fonts. They are not interchangeable, and treating them as if they are usually causes the trouble.
SVG (Scalable Vector Graphics) is the default choice for most web icons. It scales cleanly at any size or pixel density, and for simple graphics it is usually smaller than a raster file. It also gives you room to work with CSS and JavaScript, which matters when icons need to change colour, animate, or react to state.
PNG (Portable Network Graphics) still earns its keep for icons with gradients, shadows, or photographic details that do not translate well to vector artwork. The catch is obvious enough: you need multiple sizes if you want it to behave properly across different display densities.
Icon fonts used to be the common shortcut before SVG support was broadly reliable. They still work, but the trade-off is poor accessibility and limited styling control. For new work, SVG sprites are usually the cleaner option.
Size choices that actually make sense
Icon size affects usability as much as appearance. Too small, and the icon becomes fiddly or ambiguous. Too large, and it starts eating layout space it has not earned. The standard sizes below cover most web use cases.
- 16x16px - small inline icons, favicons, dense UI elements
- 20x20px - compact buttons, form field icons
- 24x24px - standard UI icons, the most common web size
- 32x32px - feature icons, larger touch targets
- 48x48px - app icons, prominent navigation elements
- 64x64px and larger - illustrations, hero sections, empty states
Touch interfaces need more breathing room. Apple recommends a minimum of 44x44 points for tappable elements, while Google's Material Design suggests 48x48dp. The icon itself can stay at 24px if the hit area is large enough. That distinction matters, because users tap the target, not the artwork.
Colour, contrast and where icons fail
Icons need enough contrast to remain legible against their backgrounds. The Web Content Accessibility Guidelines (WCAG) recommend at least a 3:1 contrast ratio for graphical objects such as icons. In practice, low-contrast icons disappear first in dark mode, on tinted panels, and on interfaces that lean too hard on pale greys.
It helps to check how the same icon behaves in different states rather than judging it in one neat mock-up. Light mode versus dark mode, hover and active states, disabled states with reduced opacity, and selected or highlighted states all reveal different problems.
Using currentColor in SVG icons lets them inherit the text colour automatically. That works well for single-colour icons and keeps the icon aligned with surrounding text without having to maintain separate colour variants for every theme.
Adding icons to a page without making a meal of it
The way icons are implemented affects performance and accessibility, not just code style. Inline SVG, SVG sprites and image elements each solve a different problem.
Inline SVG
Embedding SVG directly in the HTML gives the most control. Individual elements can be styled with CSS, animated, and displayed immediately without another HTTP request. The downside is simple enough: the markup gets heavier if you repeat the same pattern everywhere.
SVG Sprites
On sites with a large icon library, SVG sprites are usually the practical choice. Multiple icons live in one file, and individual symbols are referenced with the <use> element. That reduces requests while keeping the icons styleable.
Image Elements
<img> tags are straightforward, but they are less flexible. Use meaningful alt text when the icon carries information. Use alt="" when the icon is purely decorative. Anything else creates noise for assistive technology, which is not a good trade.
Accessibility basics people still skip
Icons help sighted users, but they can create barriers if they are treated as decoration by default. The minimum standard is not complicated, but it does need to be deliberate.
- Provide text alternatives for meaningful icons using
aria-labelor accompanying text - Hide decorative icons from screen readers with
aria-hidden="true" - Don't rely on icons alone to convey critical information
- Ensure icons have sufficient size and contrast for users with visual impairments
- Test icon buttons work with keyboard navigation
Keeping icon files lean
Individual icons are small, but large icon sets add up quickly. The usual fixes are boring because they work: trim the SVG, avoid unnecessary requests, and stop the browser guessing layout dimensions.
- Minimise SVG code by removing unnecessary metadata and optimising paths
- Use SVG sprites to reduce HTTP requests
- Lazy load icons below the fold when possible
- Set explicit width and height attributes to prevent layout shift
- Consider using icon component libraries that implement tree-shaking
Tools like SVGO can automatically optimise SVG files, often reducing file size by 50% or more without visible quality loss. That is the sort of saving you notice when a set contains dozens of icons, not one lonely menu symbol.
Building an icon set that stays consistent
A consistent icon system is easier to read and much easier to maintain. The useful part is not the visual polish alone. It is the fact that teams stop making one-off decisions every time a new icon appears.
- Style - outlined, filled, or a combination, with clear usage rules
- Stroke weight - consistent line thickness across all icons
- Corner radius - matching rounded or sharp corners
- Grid - design icons on the same base grid for optical alignment
- Padding - consistent internal spacing within icon boundaries
Document the rules and make them available to the whole team. Without that, new icons drift, and the set starts looking like it was assembled from three different projects and a rescue mission.