HomeComponentGradient Text

Gradient Text

Published Nov 20, 2024
By Raina Saxena

Gradient Text

Base Component

Copy and paste the following base component in your project
Make sure to install all the required dependencies

GradientText.tsx
import React from 'react'
import { twMerge } from 'tailwind-merge'
 
interface TextProps{
    startColor : string,
    endColor : string,
    text : string,
    className?: string
}
 
const GradientText: React.FC<TextProps> = ({startColor="#666666", endColor="#ffffff", text, className}) => {
  return (
    <h1
      className={twMerge("text-5xl font-bold text-center",className)}
      style={{
        backgroundImage: `linear-gradient(to bottom, ${startColor}, ${endColor})`,
        WebkitBackgroundClip: 'text',
        WebkitTextFillColor: 'transparent',
      }}
    >
      {text}
    </h1>
  )
}
 
export default GradientText

Component Props


Required Props

PropTypeDefault
text
string
Gradient Text
startColor
string
#000000
endColor
string
#ffffff

Optional Props

PropTypeDefault
className
string
-
Built with Next.js