Use SVG Icons in Power Apps Canvas Apps

Share
Use SVG Icons in Power Apps Canvas Apps

The built-in Power Apps icon set is small, and you can't recolor or restyle it freely. SVG fixes that. Any icon library becomes available, the color follows your theme, and the stroke weight is yours to set. There is nothing to upload and no media file to manage.

This post covers the formula that makes it work, a reusable asset table, and the mistakes that cost the most time.

The core formula

An Image control accepts a data URI. Set its Image property to:

"data:image/svg+xml;utf8," & EncodeUrl(
    "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='#D39B75' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><path d='M3 10.5 12 3l9 7.5V21H3z'/></svg>"
)

Three details matter here:

  • Use single quotes inside the SVG. Power Fx strings are wrapped in double quotes, so single-quoted attributes avoid escaping.
  • Wrap the SVG in EncodeUrl. Characters like # and < break the data URI if left raw. Without encoding, a hex color silently stops the icon from rendering.
  • Always include viewBox. It lets the icon scale to whatever size the control is. Set the control's ImagePosition to Fit.

Store icons once, reuse everywhere

Pasting SVG into every control gets messy fast. Keep the icons in one table and look them up by name.

Best option: an _AppAssets SharePoint list

Create a SharePoint list named _AppAssets and add it to your app as a data source. Two columns are enough:

Column

Type

Holds

Title

Single line of text

The icon name, such as home

Code

Multiple lines of text (plain text)

The full SVG markup, with stroke='currentColor'

Add one row per icon. Keep the Code column as plain text, because rich text wraps the SVG in HTML and it stops rendering.

A list beats embedding icons in the app for three reasons:

  • Every app that points at the list shares one icon set.
  • You can add or fix an icon without republishing the app.
  • The SVG markup stays out of your app's source, so formulas stay readable.

Alternative: a colAssets collection

If you can't create a list, load the same two columns into a collection in App.OnStart and look icons up in colAssets instead of _AppAssets:

ClearCollect(
    colAssets,
    { Title: "home",   Code: "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><path d='M3 10.5 12 3l9 7.5V21H3z'/></svg>" },
    { Title: "search", Code: "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><path d='m20 20-3.5-3.5'/></svg>" }
);

Using an icon

The Image control's Image property becomes the formula below. If you used the collection, swap _AppAssets for colAssets:

"data:image/svg+xml;utf8," & EncodeUrl(
    Substitute(
        LookUp(_AppAssets, Title = "home", Code),
        "currentColor",
        "#D39B75"
    )
)

Every icon is stored with stroke='currentColor' as a placeholder. Substitute swaps in the real color at render time, so one stored icon works in any color.

Make the color follow your theme

If your app has a theme record, pass its color instead of a hardcoded hex:

Substitute(
    LookUp(_AppAssets, Title = "home", Code),
    "currentColor",
    ThemeColors.IconColor
)

ColorHex() returns eight digits with an alpha channel (#RRGGBBAA). SVG strokes expect six. Left(..., 7) keeps the # plus six digits and drops the alpha. Skipping this is the most common reason an icon shows up blank.

Switch between light and dark mode and every icon recolors with no extra work.

Icons inside HtmlText

The same lookup works in an HtmlText control, which is useful for cards, headers, and badges:

"<img width='20' height='20' src='data:image/svg+xml;utf8," &
EncodeUrl(Substitute(LookUp(_AppAssets, Title = "search", Code), "currentColor", "#D39B75")) &
"'/>"

If the icon doesn't appear, check the quoting first. The src attribute here is wrapped in single quotes, and the encoded SVG contains none, so it is safe. Raw unencoded SVG inside src is not.

Common mistakes

  • Icon renders blank: the stroke color is 8-digit hex, or currentColor was never substituted.
  • Icon is cropped or tiny: viewBox is missing, or ImagePosition isn't Fit.
  • Formula errors on a long SVG: double quotes inside the string. Use single quotes in the SVG.
  • Icon shows as text or fails from the list: the Code column is rich text. Switch it to plain text.
  • Slow app start: a large colAssets collection loaded in OnStart. Prefer the _AppAssets list and look icons up on demand.
  • Stroke looks heavy at small sizes: drop stroke-width to 1 or 1.25 below 20 px.

Where to get the icons

The Brilaro SVG icon library lets you search the full icon set, pick a color and stroke, and copy the finished Power Apps formula for any icon, or download the SVG. Paste the SVG into the Code column of your _AppAssets list.

Recap

  1. Build the data URI with "data:image/svg+xml;utf8," & EncodeUrl(...).
  2. Store icons in an _AppAssets SharePoint list (or a colAssets collection) with currentColor as a placeholder.
  3. Substitute the color at render time, using Left(ColorHex(...), 7) for theme colors.
  4. Single quotes inside the SVG, and always a viewBox.