Research / Defining and Using Icons

Icons are a fundamental part of the visual appearance of an application.

This Page is Partly Outdated

The Vaadin icon component has gained more feature since I wrote this, making it easier to use icons.

The current way of defining and using icons in a Vaadin application involves JavaScript, which is not natural for designers, and prevents using the icons with standard HTML elements (a <vaadin-icon> element is needed to use an icon).

For icons used in components, a custom icon font is needed to be able to override them. This leads to duplication of the same icon in two formats.

If we agree that icon fonts are the least desirable option for icons, as they are the most difficult to author (binary formats), we have two options left: defining SVG-based icons in JavaScript or CSS.

Defining Icons in JavaScript

Benefits:

Drawbacks:

Defining Icons in CSS

Benefits:

Drawbacks:

Authoring and Using Icons

Authoring an icon set can be considered equally cumbersome in both options. In CSS the SVG needs to be URL encoded and each icon separately defined using a CSS selector, while in JavaScript some boilerplate code is needed, both JS and SVG. A tool that generates the definitions from a collection of SVG files can be created for either option.

Using an icon is equally convenient in both options. You either import a JavaScript module, or a style sheet, and create a HTML element with an attribute that defines which icon to use, for example <vaadin-icon icon="search"></vaadin-icon> or <icon search></icon>.

The CSS alternative assumes it is convenient to import a style sheet into a component shadow root if needed.

See Icons for a prototype.