Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
iconify-icon
Advanced tools
Icon web component that loads icon data on demand. Over 200,000 icons to choose from
There are many excellent icon sets available. Each icon set has its own custom syntax, some are available only as fonts. Unfortunately, almost all of them load an entire set, even if you are displaying just a few icons. This makes it hard to use different icon sets.
Iconify tries to unify all icon sets. You can use the same code no matter what icon set you choose. You can mix icons from multiple icon sets on the same page.
Iconify is the most versatile icon framework.
For more information visit https://iconify.design/.
Iconify Icon web component renders icons.
Add this line to your page to load IconifyIcon (you can add it to <head>
section of the page or before </body>
):
<script src="https://code.iconify.design/iconify-icon/2.3.0/iconify-icon.min.js"></script>
or
<script src="https://cdn.jsdelivr.net/npm/iconify-icon@2.3.0/dist/iconify-icon.min.js"></script>
or, if you are building a project with a bundler, you can include the script by installing iconify-icon
as a dependency and importing it in your project:
import 'iconify-icon';
To add any icon, write something like this:
<iconify-icon icon="eva:people-outline"></iconify-icon>
That is it. Change icon
attribute to the name of the icon you want to use. There are over 200,000 premade icons to choose from, including Material Symbols, Photphor, Remix Icons, Carbon, Unicons, Bootstrap Icons and even several emoji sets.
Do you want to make your own icon sets? Everything you need is available on GitHub: tools for creating custom icon sets, Iconify API application and documentation to help you.
What are advantages of using IconifyIcon web component?
Advantages of using Iconify components:
currentColor
) and font size for size (height is set to 1em
), making it easy to change color and size.Main advantage of web component over other implementations is shadow DOM. Using shadow DOM instead of inlining SVG has the following advantages:
<iconify-icon />
tags, which reduces document size. Frameworks that use SSR and hydration, using web component for icons means same HTML code generated on server and rendered in client, preventing potential hydration errors. Actual icon code is hidden in shadow DOM.Below is a shortened version of documentation.
Full documentation is available on Iconify documentation website.
Iconify icon script registers a web component iconify-icon
.
Web component uses the following logic to render icon:
icon
attribute.Usually, icon fonts do not render like normal images, they render like text. Text is aligned slightly below the baseline.
Visual example to show the difference:
You can change that behavior by applying style:
<iconify-icon
icon="material-symbols:account-circle"
style="vertical-align: -0.125em"
></iconify-icon>
Web component also has inline
attribute that does the same, to make it easier for developers:
<iconify-icon inline icon="material-symbols:account-circle"></iconify-icon>
Web component has several render modes, which can be changed by passing mode
property:
svg
: renders icon as <svg>
.bg
: renders icon as <span>
with background set to SVG.mask
: same as bg
, but uses masks instead, combined with background-color: currentColor
, which results in icon rendered as background that uses text color.style
: bg
or mask
, depending on icon content.Why are these modes needed?
It solves issues with SVG 2 animations. Usually, when SVG contains animations, animations do not start until DOM is ready. This can be affected by small things like ad code failing to load, preventing animations from working and causing frustration to developers. However, this is not an issue if SVG is rendered as background - animations are ran instantly. Also performance of SVG 2 animations is much better when used as background or mask. Background is used when icon does not contain currentColor
, so all colors are displayed properly. Mask is used when icon contains currentColor
, so icon is used as mask for background that uses currentColor
, so icon correctly follows currentColor
.
If background and masks are so good, why SVG mode is available? First issue is color: if icon has mix of currentColor
and palette (please do not design icons like that, it is bad practice!), icon colors will be incorrect, so such icons should be rendered as <svg>
. Second issue is performance of icons without animations. Animated icons do perform much better as background or mask, but icons without animation usually perform better as <svg>
.
What is default rendering mode? That depends on icon. If icon contains SVG 2 animation tags, icon is rendered as <span>
with background or mask (mask for icons that contain currentColor
, background for other icons), otherwise icon is rendered as <svg>
.
When you use an icon font, each visitor loads an entire font, even if your page only uses a few icons. This is a major downside of using icon fonts. That limits developers to one or two fonts or icon sets.
Unlike icon fonts, Iconify Icon web component does not load the entire icon set. Unlike fonts and SVG frameworks, Iconify only loads icons that are used on the current page instead of loading entire icon sets. How is it done? By serving icons dynamically from publicly available JSON API.
Relying on a third party service is often not an option. Many companies and developers prefer to keep everything on their own servers to have full control.
Iconify API and icon sets are all available on GitHub, making it easy to host API on your own server.
For more details see Iconify API documentation.
You can also create custom Iconify API to serve your own icons. For more details see hosting custom icons in Iconify documentation.
Iconify Icon web component is designed to be used with Iconify API, loading icon data on demand instead of bundling it..
If you want to use icons without Iconify API, there are many other options available.
There are 2 types of icons: monotone and coloured.
Monotone icons use font colour, just like glyph fonts. To change colour, you can do this:
<iconify-icon class="icon-bell" icon="vaadin:bell"></iconify-icon>
and add this to CSS:
.icon-bell {
color: #f80;
}
.icon-bell:hover {
color: #f00;
}
Sample:
By default all icons are scaled to 1em height. To control icon height use font-size:
<iconify-icon class="icon-clipboard" icon="emojione:clipboard"></iconify-icon>
and add this to css:
.icon-clipboard {
font-size: 32px;
}
Sample:
you might also need to set line-height:
.icon-clipboard {
font-size: 32px;
line-height: 1em;
}
You can also set custom dimensions using width
and height
attributes:
<iconify-icon icon="twemoji:ice-cream" width="32" height="32"></iconify-icon>
Sample:
If you want to control icon dimensions with CSS, do the following:
height
attribute to none
or unset
, which will remove attribute from rendered SVG.width
and height
for iconify-icon.Example:
<iconify-icon
icon="twemoji:ice-cream"
height="unset"
style="width: 40px; height: 40px;"
></iconify-icon>
This allows easily changing width and height separately in CSS instead of relying on font-size. In some use cases you might need to add display: block;
to CSS.
You can rotate and flip icon by adding flip
and rotate
attributes:
<iconify-icon icon="twemoji-helicopter" flip="horizontal"></iconify-icon>
<iconify-icon icon="twemoji-helicopter" rotate="90deg"></iconify-icon>
Possible values for flip
: horizontal, vertical.
Possible values for rotate
: 90deg, 180deg, 270deg.
If you use both flip and rotation, the icon is flipped first, then rotated.
To use custom transformations use CSS transform rule.
<iconify-icon icon="twemoji-helicopter" class="icon-helicopter"></iconify-icon>
.icon-helicopter {
transform: 45deg;
}
Samples:
There are over 200,000 icons to choose from.
Few popular icon sets (monotone icons):
and many others.
Emoji collections (mostly colored icons):
Also, there are several thematic collections, such as weather icons, map icons, etc.
You can use browse or search available icons on the Iconify website: https://icon-sets.iconify.design/
Click an icon to get HTML code.
Iconify web component supports all modern browsers.
This package is licensed under MIT license.
SPDX-License-Identifier: MIT
This license does not apply to icons. Icons are released under different licenses, see each icon set for details. Icons available by default are all licensed under some kind of open-source or free license.
© 2022-PRESENT Vjacheslav Trushkin
FAQs
Icon web component that loads icon data on demand. Over 200,000 icons to choose from
The npm package iconify-icon receives a total of 0 weekly downloads. As such, iconify-icon popularity was classified as not popular.
We found that iconify-icon demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.