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.

Import
import { StarOutlined } from 'svelte-ant-design/icons'; import { Icon } from 'svelte-ant-design';
Links
src/lib/Icon Report an issue Component README

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 Icon for a drawing of your own, or for one that you take from @ant-design/icons-svg yourself.

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 .

Basic

An icon is the size and the color of the text around it: set font-size and color on the icon or on a parent. Every drawing is a component named after the drawing and its theme, imported from svelte-ant-design/icons.

StarOutlined, StarFilled, StarTwoTone
HeartOutlined, HeartFilled, HeartTwoTone

Themes

Most drawings come in three themes: Outlined, Filled and TwoTone. The theme is the end of the component name.

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

Spin and rotate

spin turns the icon once a second, endlessly (slower when the user asks for reduced motion). The loading drawing turns by itself, and spin={false} stops it. rotate turns the drawing by degrees, and the two work together.

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)

Two-tone colors

twoToneColor takes one color, and the second is the lightest shade of its palette, or a pair [primary, secondary]. With none, the theme tokens paint it. setTwoToneColor sets the default for the whole page: it changes every two-tone icon without a color of its own, those of the other examples too.

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

Accessible name

By default the icon is an image named by its drawing, in English. label gives it a name of your own; label="" hides it from assistive technology, which is right for an icon next to visible text.

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

Icons that are clicked

An icon is not a button. Put it inside a Button and let the button carry the name, or give the icon role="button", tabindex and the keys itself. Other attributes of the wrapper, such as onclick and style, pass through.

icon: a definition, with spin, rotate and label like any other
children: your own svg inside the icon

Custom drawing

icon takes a definition, which is data: a name, a theme and the nodes of an svg. children takes your own svg. Both get spin, rotate, class and label like a ready icon.

component: a Svelte component that renders an svg (panda-svg.part.svelte, shown below the example)

Custom component

component takes a Svelte component that renders an <svg>; it gets width, height and fill and is drawn inside the same wrapper. Its code is shown after the example.

IconFont type="icon-ring", type="icon-square"
extraCommonProps: style for every icon of the font

iconfont.cn

createFromIconfontCN loads the sprite script of an iconfont.cn project and returns an icon component with a type prop. It runs a script from the address you give it, so use only your own. Here the sprite is made on the page, so the example works offline.

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.

API

A ready icon such as StarOutlined takes the properties below except icon, component and children.

PropertyDescriptionTypeDefault
iconIcon 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—
componentIcon only. A Svelte component that renders an <svg>. It gets width and height of 1em and fill of currentColor. Wins over icon.Component<IconComponentProps>—
childrenIcon only. Your own content, an <svg>, drawn inside the wrapper. It wins over component and icon.Snippet—
spinTurns the icon (its wrapper) once a second, endlessly; slower under prefers-reduced-motion. The loading drawing turns without it, and spin={false} stops that.booleanfalse
rotateDegrees 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—
twoToneColorColors 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]—
labelThe 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—
classAn additional CSS class for the wrapper, next to ads-icon and ads-icon-<name>.string—
styleInline style of the wrapper. The drawing is 1em square, so font-size sizes it and color paints it.string—
native attributesNative 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

FunctionDescriptionType
setTwoToneColorSets 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
getTwoToneColorThe current pair [primary, secondary]. Before setTwoToneColor it is the two theme tokens as var(...) strings. The array is a copy.() => [string, string]
createFromIconfontCNLoads 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

TokenDescriptionDefault
--ads-icon-twotone-primaryMain 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-secondaryLight 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 label your own text, or label="" to hide an icon that sits next to visible text: it then has no role and no name.
  • A custom drawing (component or children) has no name, so it is hidden until you give it a label.
  • An icon cannot take focus and is not a tab stop. For a click, use a Button and let it carry the name, or add role="button", tabindex and 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 Spin does. With prefers-reduced-motion the 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 label in place of that name, nothing at all for label="", a button by its own text or name when the icon inside is hidden, and an icon with role="button" as a button with its label. Not checked: NVDA, JAWS, VoiceOver and a phone screen reader.