Project
Module for Nuxt allowing pleasant use of svg icons
Date
April 2022
Status
Active
nuxt-icons is an open-source Nuxt module I wrote and published to npm. It solves a small but persistent annoyance - SVG icons are supposed to behave like text - inherit color, scale with font-size, sit on the baseline - but out of the box they don't.
This module fixes it.
You drop SVG files into assets/icons/, and the module:
<nuxt-icon name="arrow-right" />font-size like text doeswidth: 1em; height: 1em; vertical-align: middle - icons sit inline on the baseline without hacksicons/admin/badge.svg → <nuxt-icon name="admin/badge" />filled attribute and the SVG keeps its own fill colors instead of inheriting currentColorpnpm add nuxt-icons
npm install nuxt-icons
yarn add nuxt-icons
export default defineNuxtConfig({
modules: ['nuxt-icons']
})
Then create assets/icons/ and drop your SVGs in.
<!-- Inherits current text color and font-size -->
<nuxt-icon name="arrow-right" />
<!-- Keeps original colors (brand logos, flags, etc.) -->
<nuxt-icon name="github" filled />
<!-- Nested folder structure -->
<nuxt-icon name="social/twitter" />
Styling happens via regular CSS - just target .nuxt-icon svg:
.nuxt-icon svg {
font-size: 1.5rem;
color: var(--color-primary);
transition: color 0.2s;
}
Written in Vue and TypeScript, currently at v4.0.0 with full Nuxt 4 support. Open source, MIT licensed, and used in most of my own Nuxt projects before @nuxt/icon became the mainstream solution.