Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for How to Use Icons in Shadcn UI with Next.js
Aaronn
Aaronn

Posted on • Originally published atfrontendshape.com

     

How to Use Icons in Shadcn UI with Next.js

In this section, we'll see how to use icons in Next.js with ShadCN UI. ShadCN UI includes Lucide-React icons by default, and you also have the option to incorporate SVG icons fromHeroicons.

npm install lucide-react# yarnyarn add lucide-react
Enter fullscreen modeExit fullscreen mode

Next.js with Shadcn UI Icons: Small, Medium, and Large Sizes.

import{Mail}from"lucide-react"exportdefaultfunctionDemoIcon(){return(<divclassName="flex gap-4"><MailclassName="h-4 w-4"/><MailclassName="h-6 w-6"/><MailclassName="h-8 w-8"/><MailclassName="h-12 w-12"/><MailclassName="h-16 w-16"/></div>)}
Enter fullscreen modeExit fullscreen mode

shadcn ui icons
Next.js with Shadcn UI button with Icon using lucide-react icon.

import{Mail}from"lucide-react"import{Button}from"@/components/ui/button"exportdefaultfunctionDemoIcon(){return(<Button><MailclassName="mr-2 h-4 w-4"/>      Send Mail</Button>)}
Enter fullscreen modeExit fullscreen mode

button with icon
If you prefer using SVG icons in Next.js with Shadcn UI, you can easily integrate icons from heroicons.com. or you can install@heroicons/react.

npm install @heroicons/react
Enter fullscreen modeExit fullscreen mode

shadcn ui heroicons icons
Next.js with Shadcn UI SVG Icons: Small, Medium, and Large Sizes.

exportdefaultfunctionDemoIcon(){return(<divclassName="flex gap-4"><svgxmlns="http://www.w3.org/2000/svg"fill="none"viewBox="0 0 24 24"strokeWidth={1.5}stroke="currentColor"className="w-4 h-4"><pathstrokeLinecap="round"strokeLinejoin="round"d="M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75"/></svg><svgxmlns="http://www.w3.org/2000/svg"fill="none"viewBox="0 0 24 24"strokeWidth={1.5}stroke="currentColor"className="w-6 h-6"><pathstrokeLinecap="round"strokeLinejoin="round"d="M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75"/></svg><svgxmlns="http://www.w3.org/2000/svg"fill="none"viewBox="0 0 24 24"strokeWidth={1.5}stroke="currentColor"className="w-8 h-8"><pathstrokeLinecap="round"strokeLinejoin="round"d="M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75"/></svg><svgxmlns="http://www.w3.org/2000/svg"fill="none"viewBox="0 0 24 24"strokeWidth={1.5}stroke="currentColor"className="w-12 h-12"><pathstrokeLinecap="round"strokeLinejoin="round"d="M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75"/></svg><svgxmlns="http://www.w3.org/2000/svg"fill="none"viewBox="0 0 24 24"strokeWidth={1.5}stroke="currentColor"className="w-16 h-16"><pathstrokeLinecap="round"strokeLinejoin="round"d="M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75"/></svg></div>)}
Enter fullscreen modeExit fullscreen mode

svg icons
Next.js with Shadcn UI button with SVG Icon using heroicons icon.

import{Button}from"@/components/ui/button"exportdefaultfunctionDemoIcon(){return(<Button><svgxmlns="http://www.w3.org/2000/svg"fill="none"viewBox="0 0 24 24"strokeWidth={1.5}stroke="currentColor"className="mr-1 w-4 h-4"><pathstrokeLinecap="round"strokeLinejoin="round"d="M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75"/></svg>      Send Mail</Button>)}
Enter fullscreen modeExit fullscreen mode

button with svg icon

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Full Stack Developer | React| NEXTJS| Nodejs | Tailwind CSS
  • Joined

More fromAaronn

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp