Icon
An icon is a small vector picture the size and the color of the text around it. The set has 848 drawings, most in three themes, each a component you import by name; Icon draws your own.
When to use
- Use an icon to make a button, a menu item or a status easier to recognize. Keep a word next to it when the meaning is not obvious.
- Import only the icons you use from
svelte-ant-design/icons: a build keeps those drawings and drops the rest of the 848. - Use
Iconfor a drawing of your own, or for one that you take from@ant-design/icons-svgyourself.
Examples
no props: the size and the color of the text
font-size and color set on the parent
inside a line of text
Your settings are saved .
<script lang="ts">
import { HomeOutlined, SettingOutlined, SmileOutlined } from 'svelte-ant-design/icons';
</script>
<div class="stack">
<div class="field">
<span class="caption">no props: the size and the color of the text</span>
<div class="row">
<HomeOutlined />
<SettingOutlined />
<SmileOutlined />
</div>
</div>
<div class="field">
<span class="caption">font-size and color set on the parent</span>
<div class="row big">
<HomeOutlined />
<SettingOutlined />
<SmileOutlined />
</div>
</div>
<div class="field">
<span class="caption">inside a line of text</span>
<p class="line">Your settings <SettingOutlined /> are saved <SmileOutlined />.</p>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
}
.big {
color: var(--ads-color-primary);
font-size: 28px;
}
.line {
margin: 0;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
StarOutlined, StarFilled, StarTwoTone
HeartOutlined, HeartFilled, HeartTwoTone
<script lang="ts">
import { HeartFilled, HeartOutlined, HeartTwoTone, StarFilled, StarOutlined, StarTwoTone } from 'svelte-ant-design/icons';
</script>
<div class="stack">
<div class="field">
<span class="caption">StarOutlined, StarFilled, StarTwoTone</span>
<div class="row">
<StarOutlined />
<StarFilled />
<StarTwoTone />
</div>
</div>
<div class="field">
<span class="caption">HeartOutlined, HeartFilled, HeartTwoTone</span>
<div class="row">
<HeartOutlined />
<HeartFilled />
<HeartTwoTone />
</div>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
font-size: 28px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
spin: the switch turns it on and off
the loading icon turns by itself
rotate: 0, 90, 180 and 270 degrees
rotate and spin together
<script lang="ts">
import { Switch } from 'svelte-ant-design';
import { ArrowUpOutlined, LoadingOutlined, RocketOutlined, SyncOutlined } from 'svelte-ant-design/icons';
let spinning = $state(true);
</script>
<div class="stack">
<div class="field">
<span class="caption">spin: the switch turns it on and off</span>
<div class="row">
<Switch bind:checked={spinning} aria-label="Spin" />
<SyncOutlined spin={spinning} />
</div>
</div>
<div class="field">
<span class="caption">the loading icon turns by itself</span>
<div class="row">
<LoadingOutlined />
</div>
</div>
<div class="field">
<span class="caption">rotate: 0, 90, 180 and 270 degrees</span>
<div class="row">
<ArrowUpOutlined rotate={0} />
<ArrowUpOutlined rotate={90} />
<ArrowUpOutlined rotate={180} />
<ArrowUpOutlined rotate={270} />
</div>
</div>
<div class="field">
<span class="caption">rotate and spin together</span>
<div class="row">
<RocketOutlined rotate={45} spin />
</div>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
font-size: 24px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
no twoToneColor: the theme colors
twoToneColor="#eb2f96", twoToneColor="#52c41a": the second color is derived
twoToneColor as a pair: [primary, secondary]
setTwoToneColor: the default of every two-tone icon of the page that has no color of its own getTwoToneColor(): var(--ads-icon-twotone-primary) / var(--ads-icon-twotone-secondary)
<script lang="ts">
import { Button, getTwoToneColor, setTwoToneColor } from 'svelte-ant-design';
import { CheckCircleTwoTone, HeartTwoTone, SmileTwoTone } from 'svelte-ant-design/icons';
import { onDestroy } from 'svelte';
// The colors the library starts with: the theme tokens. `setTwoToneColor` with them puts the default back.
const THEME = ['var(--ads-icon-twotone-primary)', 'var(--ads-icon-twotone-secondary)'] as [string, string];
// The global color belongs to the whole page; leaving this example puts the default back.
onDestroy(() => setTwoToneColor(THEME));
</script>
<div class="stack">
<div class="field">
<span class="caption">no twoToneColor: the theme colors</span>
<div class="row">
<SmileTwoTone />
</div>
</div>
<div class="field">
<span class="caption">twoToneColor="#eb2f96", twoToneColor="#52c41a": the second color is derived</span>
<div class="row">
<HeartTwoTone twoToneColor="#eb2f96" />
<CheckCircleTwoTone twoToneColor="#52c41a" />
</div>
</div>
<div class="field">
<span class="caption">twoToneColor as a pair: [primary, secondary]</span>
<div class="row">
<SmileTwoTone twoToneColor={['#1677ff', '#ffe58f']} />
<HeartTwoTone twoToneColor={['#722ed1', '#d3adf7']} />
</div>
</div>
<div class="field">
<span class="caption">setTwoToneColor: the default of every two-tone icon of the page that has no color of its own</span>
<div class="row">
<HeartTwoTone />
<Button size="small" onclick={() => setTwoToneColor('#fa8c16')}>Orange</Button>
<Button size="small" onclick={() => setTwoToneColor(THEME)}>Theme</Button>
</div>
<span role="status">getTwoToneColor(): {getTwoToneColor().join(' / ')}</span>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
font-size: 24px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
no label: an image named by the drawing (star)
label="Favourite": your own name, in your own language
label="": hidden from assistive technology, next to visible text
Notifications
<script lang="ts">
import { BellOutlined, StarOutlined } from 'svelte-ant-design/icons';
</script>
<div class="stack">
<div class="field">
<span class="caption">no label: an image named by the drawing (star)</span>
<div class="row">
<StarOutlined />
</div>
</div>
<div class="field">
<span class="caption">label="Favourite": your own name, in your own language</span>
<div class="row">
<StarOutlined label="Favourite" />
</div>
</div>
<div class="field">
<span class="caption">label="": hidden from assistive technology, next to visible text</span>
<div class="row">
<BellOutlined label="" />
<span>Notifications</span>
</div>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
font-size: 20px;
}
.row span {
font-size: 14px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
in a Button with text: the icon is hidden, the text names the button
in an icon-only Button: the button is named, the icon is hidden
an icon with onclick, role="button", tabindex and keys
stars: 0
<script lang="ts">
import { Button } from 'svelte-ant-design';
import { DeleteOutlined, SearchOutlined, StarOutlined } from 'svelte-ant-design/icons';
let stars = $state(0);
// An icon with a click handler is not a button by itself: it gets a role, a place in the tab order and the keys.
function onkeydown(event: KeyboardEvent) {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
stars += 1;
}
}
</script>
{#snippet search()}
<SearchOutlined label="" />
{/snippet}
{#snippet remove()}
<DeleteOutlined label="" />
{/snippet}
<div class="stack">
<div class="field">
<span class="caption">in a Button with text: the icon is hidden, the text names the button</span>
<div class="row">
<Button type="primary" icon={search}>Search</Button>
</div>
</div>
<div class="field">
<span class="caption">in an icon-only Button: the button is named, the icon is hidden</span>
<div class="row">
<Button shape="circle" icon={remove} aria-label="Delete" />
</div>
</div>
<div class="field">
<span class="caption">an icon with onclick, role="button", tabindex and keys</span>
<div class="row">
<StarOutlined label="Add a star" role="button" tabindex={0} onclick={() => (stars += 1)} {onkeydown} style="cursor: pointer; font-size: 24px" />
</div>
<span role="status">stars: {stars}</span>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
icon: a definition, with spin, rotate and label like any other
children: your own svg inside the icon
<script lang="ts">
import { Icon, type IconDefinition } from 'svelte-ant-design';
// A drawing is data: a name, a theme and the nodes of an svg. This is the shape that `@ant-design/icons-svg` uses for its own.
const flag: IconDefinition = {
name: 'flag',
theme: 'filled',
icon: {
tag: 'svg',
attrs: { viewBox: '0 0 24 24', focusable: 'false' },
children: [{ tag: 'path', attrs: { d: 'M5 2h2v20H5zM8 3h12l-3 5 3 5H8z' } }]
}
};
</script>
{#snippet drop()}
<svg viewBox="0 0 24 24" width="1em" height="1em" fill="currentColor"><path d="M12 2C8 8 5 11 5 15a7 7 0 0 0 14 0c0-4-3-7-7-13z" /></svg>
{/snippet}
<div class="stack">
<div class="field">
<span class="caption">icon: a definition, with spin, rotate and label like any other</span>
<div class="row">
<Icon icon={flag} />
<Icon icon={flag} rotate={90} label="Flag, turned" />
</div>
</div>
<div class="field">
<span class="caption">children: your own svg inside the icon</span>
<div class="row">
<Icon label="Drop">
{@render drop()}
</Icon>
<Icon spin label="Drop, spinning">
{@render drop()}
</Icon>
</div>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
font-size: 28px;
color: var(--ads-color-primary);
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
component: a Svelte component that renders an svg (panda-svg.part.svelte, shown below the example)
<script lang="ts">
import { Icon } from 'svelte-ant-design';
import PandaSvg from './panda-svg.part.svelte';
</script>
<div class="stack">
<div class="field">
<span class="caption">component: a Svelte component that renders an svg (panda-svg.part.svelte, shown below the example)</span>
<div class="row">
<Icon component={PandaSvg} label="Panda" />
<Icon component={PandaSvg} label="Panda, big" style="font-size: 40px" />
<Icon component={PandaSvg} spin rotate={20} label="Panda, spinning" />
</div>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
font-size: 28px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
<!-- panda-svg.part.svelte -->
<script lang="ts">
// A custom drawing for Icon's `component` prop: it renders one svg and uses the width, the height and the fill it is given.
let { width = '1em', height = '1em', fill = 'currentColor' }: { width?: string; height?: string; fill?: string } = $props();
</script>
<svg viewBox="0 0 24 24" {width} {height} aria-hidden="true">
<circle cx="5.5" cy="5.5" r="3.5" {fill} />
<circle cx="18.5" cy="5.5" r="3.5" {fill} />
<circle cx="12" cy="13" r="9" fill="none" stroke={fill} stroke-width="2" />
<circle cx="8.5" cy="12" r="1.6" {fill} />
<circle cx="15.5" cy="12" r="1.6" {fill} />
</svg>
IconFont type="icon-ring", type="icon-square"
extraCommonProps: style for every icon of the font
<script lang="ts">
import { createFromIconfontCN } from 'svelte-ant-design';
// In your project `scriptUrl` is the address that your iconfont.cn project gives you, for example '//at.alicdn.com/t/font_xxx.js'.
// Here the sprite script is made on the page, so that the example works without a network. It does what that script does:
// it puts a <svg> with a <symbol id="icon-..."> for every icon at the start of the body.
const sprite = `(function () {
var holder = document.createElement('div');
holder.innerHTML = '<svg><symbol id="icon-ring" viewBox="0 0 24 24"><circle cx="12" cy="12" r="9" fill="none" stroke="currentColor" stroke-width="3"/></symbol>' +
'<symbol id="icon-square" viewBox="0 0 24 24"><rect x="4" y="4" width="16" height="16" rx="3" fill="currentColor"/></symbol></svg>';
var svg = holder.firstChild;
svg.style.position = 'absolute';
svg.style.width = 0;
svg.style.height = 0;
document.body.insertBefore(svg, document.body.firstChild);
})();`;
const scriptUrl = typeof document === 'undefined' ? '' : URL.createObjectURL(new Blob([sprite], { type: 'text/javascript' }));
const IconFont = createFromIconfontCN({ scriptUrl });
// `extraCommonProps` go to every icon of this font; the props of one icon win.
const Marker = createFromIconfontCN({ scriptUrl, extraCommonProps: { style: 'color: var(--ads-color-primary)' } });
</script>
<div class="stack">
<div class="field">
<span class="caption">IconFont type="icon-ring", type="icon-square"</span>
<div class="row">
<IconFont type="icon-ring" label="Ring" />
<IconFont type="icon-square" label="Square" />
<IconFont type="icon-ring" spin label="Ring, spinning" />
</div>
</div>
<div class="field">
<span class="caption">extraCommonProps: style for every icon of the font</span>
<div class="row">
<Marker type="icon-square" label="Square" />
<Marker type="icon-ring" label="Ring" rotate={45} />
</div>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
font-size: 28px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
All icons
Every drawing of the set, as the component you import, in the six groups and the order of the list of Ant Design: all themes together or one at a time. Click one to copy its name. The brand marks belong to their owners. A few drawings look uneven at some sizes on a pixel grid (ShareAltOutlined at 12 px is one); that is the drawing, not the component.
848 icons
Directional Icons91
Suggested Icons54
API
A ready icon such as StarOutlined takes the properties below except icon, component and children.
| Property | Description | Type | Default |
|---|---|---|---|
| icon | Icon only. The data of one drawing: { name, theme, icon }, where icon is the nodes of an svg, or for a two-tone drawing a function of the two colors. A definition imported from @ant-design/icons-svg fits. | IconDefinition | — |
| component | Icon only. A Svelte component that renders an <svg>. It gets width and height of 1em and fill of currentColor. Wins over icon. | Component<IconComponentProps> | — |
| children | Icon only. Your own content, an <svg>, drawn inside the wrapper. It wins over component and icon. | Snippet | — |
| spin | Turns the icon (its wrapper) once a second, endlessly; slower under prefers-reduced-motion. The loading drawing turns without it, and spin={false} stops that. | boolean | false |
| rotate | Degrees by which the drawing is turned. The wrapper does not move, so spin and rotate work together. A value that is not a finite number is ignored. | number | — |
| twoToneColor | Colors of a two-tone drawing: one color (the second is the lightest shade of its palette) or the pair [primary, secondary]. A color that is not a literal one, such as var(--x), keeps the default second color. Outlined and filled drawings ignore it. | string | [string, string] | — |
| label | The accessible name. Without it the name is the drawing's, in English (star); a custom drawing has none and is hidden. label="" hides the icon from assistive technology. An aria-label you pass counts as the name too. | string | — |
| class | An additional CSS class for the wrapper, next to ads-icon and ads-icon-<name>. | string | — |
| style | Inline style of the wrapper. The drawing is 1em square, so font-size sizes it and color paints it. | string | — |
| native attributes | Native attributes of the wrapper <span> (onclick, tabindex, role, title, data-*, aria-*) are forwarded to it. The icon adds no tab stop. | HTMLAttributes<HTMLSpanElement> | — |
Differences from Ant Design: the wrapper class is
ads-icon, not anticon; spin is slower under reduced motion and spin={false} stops the loading drawing; a custom drawing with no label is hidden; the default two-tone colors follow the theme tokens. String names with loading over the network (Angular) and a provider for icon defaults are not taken. The drawings and their names come from @ant-design/icons-svg (MIT), the data package that the React and Vue icon packages of Ant Design use too.Functions
| Function | Description | Type |
|---|---|---|
| setTwoToneColor | Sets the colors of every two-tone icon that has no twoToneColor of its own. A rendered icon changes at once. Call it once at start-up: on the server the value is shared by every request, so it is for one theme, not one user. | (color: string | [string, string]) => void |
| getTwoToneColor | The current pair [primary, secondary]. Before setTwoToneColor it is the two theme tokens as var(...) strings. The array is a copy. | () => [string, string] |
| createFromIconfontCN | Loads the sprite script of an iconfont.cn project (one <script> per address, once, in the order of the list, so a later one overrides an earlier one for a name used twice) and returns an icon component with a type prop. extraCommonProps go to every icon; the props of one icon win. On the server nothing is loaded. The icon has no name unless you give a label. | ({ scriptUrl, extraCommonProps }) => Component |
Design tokens
| Token | Description | Default |
|---|---|---|
| --ads-icon-twotone-primary | Main color of a two-tone icon that has no color of its own. It follows the primary color of the theme. | var(--ads-color-primary) |
| --ads-icon-twotone-secondary | Light color of such an icon: the lightest shade of the primary color. The dark theme has its own value. | #e6f4ff |
Accessibility
- Each icon is a
<span role="img">named by its drawing, in English (aria-label="star"); the svg inside is hidden from assistive technology. - The English name is wrong on a site in another language. Give
labelyour own text, orlabel=""to hide an icon that sits next to visible text: it then has no role and no name. - A custom drawing (
componentorchildren) has no name, so it is hidden until you give it alabel. - An icon cannot take focus and is not a tab stop. For a click, use a
Buttonand let it carry the name, or addrole="button",tabindexand the Enter and Space keys yourself. - The light part of a two-tone icon is decoration. By design it is far below 3:1 against a white page, so never let it carry meaning alone.
- Spinning is not announced; say in text that something is loading, as the
Spindoes. Withprefers-reduced-motionthe turn is slower (2.5 seconds), which Ant Design does not do. - Checked with a real screen reader (Orca with Firefox): it reads a drawing as its name and "image", a
labelin place of that name, nothing at all forlabel="", a button by its own text or name when the icon inside is hidden, and an icon withrole="button"as a button with its label. Not checked: NVDA, JAWS, VoiceOver and a phone screen reader.