Skip to main content
1.0.0 Dark Light System

Icon

<lynk-icon> | LynkIcon
stable Since 1.0.0

Icons are symbols that can be used to represent various options within an application.

Lynk comes bundled with over 1,500 icons courtesy of the Bootstrap Icons project. These icons are part of the default icon library. If you prefer, you can register custom icon libraries as well.

Depending on how you’re loading Lynk, you may need to copy icon assets and/or set the base path so Lynk knows where to load them from. Otherwise, icons may not appear and you’ll see 404 Not Found errors in the dev console.

Default Icons

All available icons in the default icon library are shown below. Click or tap on any icon to copy its name, then you can use it in your HTML like this.

<lynk-icon name="icon-name-here"></lynk-icon>

Examples

Colors

Icons inherit their color from the current text color. Thus, you can set the color property on the <lynk-icon> element or an ancestor to change the color.

<div style="color: #4a90e2;">
  <lynk-icon name="exclamation-triangle"></lynk-icon>
  <lynk-icon name="archive"></lynk-icon>
  <lynk-icon name="battery-charging"></lynk-icon>
  <lynk-icon name="bell"></lynk-icon>
</div>
<div style="color: #9013fe;">
  <lynk-icon name="clock"></lynk-icon>
  <lynk-icon name="cloud"></lynk-icon>
  <lynk-icon name="download"></lynk-icon>
  <lynk-icon name="file-earmark"></lynk-icon>
</div>
<div style="color: #417505;">
  <lynk-icon name="flag"></lynk-icon>
  <lynk-icon name="heart"></lynk-icon>
  <lynk-icon name="image"></lynk-icon>
  <lynk-icon name="lightning"></lynk-icon>
</div>
<div style="color: #f5a623;">
  <lynk-icon name="mic"></lynk-icon>
  <lynk-icon name="search"></lynk-icon>
  <lynk-icon name="star"></lynk-icon>
  <lynk-icon name="trash"></lynk-icon>
</div>

Sizing

Icons are sized relative to the current font size. To change their size, set the font-size property on the icon itself or on a parent element as shown below.

<div style="font-size: 32px;">
  <lynk-icon name="exclamation-triangle"></lynk-icon>
  <lynk-icon name="archive"></lynk-icon>
  <lynk-icon name="battery-charging"></lynk-icon>
  <lynk-icon name="bell"></lynk-icon>
  <lynk-icon name="clock"></lynk-icon>
  <lynk-icon name="cloud"></lynk-icon>
  <lynk-icon name="download"></lynk-icon>
  <lynk-icon name="file-earmark"></lynk-icon>
  <lynk-icon name="flag"></lynk-icon>
  <lynk-icon name="heart"></lynk-icon>
  <lynk-icon name="image"></lynk-icon>
  <lynk-icon name="lightning"></lynk-icon>
  <lynk-icon name="mic"></lynk-icon>
  <lynk-icon name="search"></lynk-icon>
  <lynk-icon name="star"></lynk-icon>
  <lynk-icon name="trash"></lynk-icon>
</div>

Labels

For non-decorative icons, use the label attribute to announce it to assistive devices.

<lynk-icon name="star-fill" label="Add to favorites"></lynk-icon>

Custom Icons

Custom icons can be loaded individually with the src attribute. Only SVGs on a local or CORS-enabled endpoint are supported. If you’re using more than one custom icon, it might make sense to register a custom icon library.

<lynk-icon
  src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB3aWR0aD0iNzUycHQiIGhlaWdodD0iNzUycHQiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDc1MiA3NTIiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiA8ZyBmaWxsPSIjZmZmIj4KICA8cGF0aCBkPSJtMzU0LjY5IDQzNy41N3YyMS4zMTJoNDIuNjIxdi0yMS4zMTJ6Ii8+CiAgPHBhdGggZD0ibTI5My4xMiAzNTQuNjloMjEuMzEydjIxLjMxMmgtMjEuMzEyeiIvPgogIDxwYXRoIGQ9Im0yOTMuMTIgMjUwLjVoMjEuMzEydjIxLjMxMmgtMjEuMzEyeiIvPgogIDxwYXRoIGQ9Im00MzcuNTcgMzU0LjY5aDIxLjMxMnYyMS4zMTJoLTIxLjMxMnoiLz4KICA8cGF0aCBkPSJtNDM3LjU3IDI1MC41aDIxLjMxMnYyMS4zMTJoLTIxLjMxMnoiLz4KICA8cGF0aCBkPSJtNTIwLjg5IDIwNy44OGgtMzEzLjAydjMzMy44OGgzMzMuODh2LTMzMy44OHptLTgxLjc2NiAyMS4zMTJoNDEuMDU5djE2OC4xMmgtNjEuNTYydi0xNjguMTJ6bS0xNDYuODEgMGg0MS4wNTl2MTY4LjEyaC02MS41NjZ2LTE2OC4xMnptMjMwLjQ5IDI1Mi41OXY0MS4wMzVoLTI5MS4yNXYtNjEuNTY2aDE4Ljk0MXY0MC4yNTRoMjUxdi00MC4yNTRoMjEuMzEyem0tMjA4LjM4LTEuNTg5OGgtNDIuNjI1di0yMS4zMTJsNDIuNjI1IDAuMDAzOTA2em0xMjMuMTMtMjEuMzEyaDQyLjYyMXYyMS4zMTJoLTQyLjYyNXptODUuMjQ2LTIwOC45LTAuMDAzOTA2IDE4Ny41OWgtMTA0LjE5djQyLjYyMWgtODUuMjQ2di00Mi42MjFoLTEwNC4xOXYtMjA4LjM4aDIxLjMxMnYxODcuMDdsMTA0LjE5LTAuMDAzOTA2di0xODcuMDZoNDIuNjIxdjE4Ny4wN2gxMDQuMTl2LTE4Ny4wN2gyMS4zMTJ6Ii8+CiA8L2c+Cjwvc3ZnPgo="
  style="font-size: 8rem;"
></lynk-icon>

Icon Libraries

You can register additional icons to use with the <lynk-icon> component through icon libraries. Icon files can exist locally or on a CORS-enabled endpoint (e.g. a CDN). There is no limit to how many icon libraries you can register and there is no cost associated with registering them, as individual icons are only requested when they’re used.

Lynk ships with two built-in icon libraries, default and system. The default icon library contains all of the icons in the Bootstrap Icons project. The system icon library contains only a small subset of icons that are used internally by Lynk components.

To register an additional icon library, use the registerIconLibrary() function that’s exported from utilities/icon-library.js. At a minimum, you must provide a name and a resolver function. The resolver function translates an icon name to a URL where the corresponding SVG file exists. Refer to the examples below to better understand how it works.

If necessary, a mutator function can be used to mutate the SVG element before rendering. This is necessary for some libraries due to the many possible ways SVGs are crafted. For example, icons should ideally inherit the current text color via currentColor, so you may need to apply fill="currentColor or stroke="currentColor" to the SVG element using this function.

Here’s an example that registers an icon library located in the /assets/icons directory.

<script type="module">
  import { registerIconLibrary } from '/dist/utilities/icon-library.js';

  registerIconLibrary('my-icons', {
    resolver: name => `/assets/icons/${name}.svg`,
    mutator: svg => svg.setAttribute('fill', 'currentColor')
  });
</script>

To display an icon, set the library and name attributes of an <lynk-icon> element.

<!-- This will show the icon located at /assets/icons/smile.svg -->
<lynk-icon library="my-icons" name="smile"></lynk-icon>

If an icon is used before registration occurs, it will be empty initially but shown when registered.

The following examples demonstrate how to register a number of popular, open source icon libraries via CDN. Feel free to adapt the code as you see fit to use your own origin or naming conventions.

Material Icons

This will register the Material Icons library using the jsDelivr CDN. This library has three variations: outline (default), round (*_round), and sharp (*_sharp). A mutator function is required to set the SVG’s fill to currentColor.

Icons in this library are licensed under the Apache 2.0 License.



<script type="module">
  import { registerIconLibrary } from '/dist/utilities/icon-library.js';

  registerIconLibrary('material', {
    resolver: name => {
      const match = name.match(/^(.*?)(_(round|sharp))?$/);
      return `https://cdn.jsdelivr.net/npm/@material-icons/svg@1.0.5/svg/${match[1]}/${match[3] || 'outline'}.svg`;
    },
    mutator: svg => svg.setAttribute('fill', 'currentColor')
  });
</script>

<div style="font-size: 24px;">
  <lynk-icon library="material" name="notifications"></lynk-icon>
  <lynk-icon library="material" name="email"></lynk-icon>
  <lynk-icon library="material" name="delete"></lynk-icon>
  <lynk-icon library="material" name="volume_up"></lynk-icon>
  <lynk-icon library="material" name="settings"></lynk-icon>
  <lynk-icon library="material" name="shopping_basket"></lynk-icon>
  <br />
  <lynk-icon library="material" name="notifications_round"></lynk-icon>
  <lynk-icon library="material" name="email_round"></lynk-icon>
  <lynk-icon library="material" name="delete_round"></lynk-icon>
  <lynk-icon library="material" name="volume_up_round"></lynk-icon>
  <lynk-icon library="material" name="settings_round"></lynk-icon>
  <lynk-icon library="material" name="shopping_basket_round"></lynk-icon>
  <br />
  <lynk-icon library="material" name="notifications_sharp"></lynk-icon>
  <lynk-icon library="material" name="email_sharp"></lynk-icon>
  <lynk-icon library="material" name="delete_sharp"></lynk-icon>
  <lynk-icon library="material" name="volume_up_sharp"></lynk-icon>
  <lynk-icon library="material" name="settings_sharp"></lynk-icon>
  <lynk-icon library="material" name="shopping_basket_sharp"></lynk-icon>
</div>

Customizing the Default Library

The default icon library contains over 1,300 icons courtesy of the Bootstrap Icons project. These are the icons that display when you use <lynk-icon> without the library attribute. If you prefer to have these icons resolve elsewhere or to a different icon library, register an icon library using the default name and a custom resolver.

This example will load the same set of icons from the jsDelivr CDN instead of your local assets folder.

<script type="module">
  import { registerIconLibrary } from '/dist/utilities/icon-library.js';

  registerIconLibrary('default', {
    resolver: name => `https://cdn.jsdelivr.net/npm/bootstrap-icons@1.0.0/icons/${name}.svg`
  });
</script>

Customizing the System Library

The system library contains only the icons used internally by Lynk components. Unlike the default icon library, the system library does not rely on physical assets. Instead, its icons are hard-coded as data URIs into the resolver to ensure their availability.

If you want to change the icons Lynk uses internally, you can register an icon library using the system name and a custom resolver. If you choose to do this, it’s your responsibility to provide all of the icons that are required by components. You can reference src/components/library.system.ts for a complete list of system icons used by Lynk.

<script type="module">
  import { registerIconLibrary } from '/dist/utilities/icon-library.js';

  registerIconLibrary('system', {
    resolver: name => `/path/to/custom/icons/${name}.svg`
  });
</script>

Importing

If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.

Bundler

To import this component using a bundler:

import '@uplynk/lynk-design/dist/components/icon/icon.js';

Properties

Name Description Reflects Type Default
name The name of the icon to draw. Available names depend on the icon library being used. string | undefined -
src An external URL of an SVG file. Be sure you trust the content you are including, as it will be executed as code and can result in XSS attacks. string | undefined -
label An alternate description to use for assistive devices. If omitted, the icon will be considered presentational and ignored by assistive devices. string ''
library The name of a registered custom icon library. string 'default'
updateComplete A read-only promise that resolves when the component has finished updating.

Learn more about attributes and properties.

Events

Name React Event Description Event Detail
ev-load EvLoad Emitted when the icon has loaded. When using spriteSheet: true this will not emit. -
ev-error EvError Emitted when the icon fails to load due to an error. When using spriteSheet: true this will not emit. -

Learn more about events.

Parts

Name Description
svg The internal SVG element.
use The element generated when using spriteSheet: true

Learn more about customizing CSS parts.