Sling Academy
Home/Next.js/How to style Link component in Next.js

How to style Link component in Next.js

Last updated: January 09, 2023

In Next.js, <Link> is one of the most-used components. To style it, you can use the className or the style props (in the old days, we had to add a <a> tag inside a <Link>, but now there is no need to do so).

Example:

JSX code:

<Link href="/about" className='my-link'>
   About Us
</Link>

CSS:

.my-link {
  color: orange;
  text-decoration: underline;
}

Another example with inline styles:

// pages/index.js
import Link from 'next/link';

export default function Home() {
  return (
    <div>
      <div style={{ padding: 30 }}>
        <p>
          <Link
            href='/about'
            style={{
              textDecoration: 'none',
              color: 'red',
              fontSize: 30,
              fontStyle: 'italic',
            }}
          >
            Sling Academy
          </Link>
        </p>
        <p>
          <Link
            href='/contact'
            style={{
              textDecoration: 'underline',
              color: 'blue',
              fontSize: 30,
            }}
          >
            Contact Us
          </Link>
        </p>
      </div>
    </div>
  );
}

Screenshot:

Hope this helps! If you find something wrong, please comment.

Next Article: How to use Font Awesome with Next.js

Previous Article: How to Use Styled JSX in Next.js: Tutorial & Examples

Series: Working with CSS in Next.js

Next.js

Related Articles

You May Also Like

  • Solving Next.js Image Component Error with CSS Classes
  • How to Use MUI (Material UI) in Next.js 14
  • Fixing Data Update Issues in Next.js Production
  • Fixing Next.js Undefined ENV Variables in Production Build
  • Solving Next.js SyntaxError: Unexpected token ‘export’
  • Next.js Error: Found Page Without a React Component as Default Export – How to Fix
  • Fixing Next.js Error: Blank Page on Production Build
  • Fixing Next.js Error when Importing SVGs: A Step-by-Step Guide
  • Next.js Issue: useEffect Hook Running Twice in Client
  • Fixing ‘self’ is not defined error in Next.js when importing client-side libraries
  • How to Dockerize a Next.js App for Production
  • How to set up Next.js with Docker Composer and Nginx
  • Solving Next.js CORS Issues: A Comprehensive Guide
  • Fixing Next.js Hydration Mismatch Error in Simple Ways
  • Next.js Error: Cannot use import statement outside a module
  • Next.js: How to Access Files in the Public Folder
  • Fixing Next.js Import CSS Error: A Simple Guide
  • Fixing LocalStorage Not Defined Error in Next.js
  • Fixing Next.js Error: No HTTP Methods Exported