SEO in NextJS (How to correctly use <NextSeo> tags in Nextjs for SEO)
Tags: webdev, javascript, nextjs, react
Published: 2023-11-12 08:42:48

## Optimizing SEO in Next.js:



![Optimizing SEO (Search Engine Optimization) in Next.js](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9gm2c6yrsj7us9n2z0yg.png)




## 1. Automatic Head Management:
Next.js simplifies the process of managing the document head, which includes crucial SEO elements such as title tags, meta descriptions, and canonical URLs. This is achieved using the <Head> component and the <NextSeo> component.

## 2. Clean and Semantic URLs:
Next.js follows a file-based routing system, resulting in clean and semantic URLs. Search engines appreciate URLs that reflect the content hierarchy, positively influencing SEO.

## 3. Server-Side Rendering (SSR):
Next.js supports Server-Side Rendering, ensuring that the HTML is generated on the server and delivered to the client. This improves the speed of page rendering and positively impacts SEO, as search engines favor fast-loading pages.

## SEO-Friendly Routing:
The file-based routing system in Next.js contributes to SEO-friendly URLs. Each page is represented by a corresponding file, making it easy to understand and optimize for search engines.



### Implementing Practical SEO  in Next.js with the `<NextSeo> ` Component:

## Prerequisites
 First of all you need to install `<Nextseo>` in your nextjs app by running this command:

```
npm i next-seo
```

Insert this code into the page you want to improve its search engine ranking. You can adjust the code for your own page as needed.



```
import { NextSeo } from "next-seo";
import Head from "next/head";
import React from "react";

const AboutMePage = () => {
  return (
    <>
      <Head>
        <NextSeo
          title="About Me - Sufian Mustafa"
          description="Learn more about Sufian Mustafa, a passionate web developer with expertise in creating stunning web applications and websites"
          author="Sufian Mustafa"
          canonical="https://sufianmustafa.com/about"
          openGraph={{
            title: "About Me - Sufian Mustafa",
            description:
              "Get to know Sufian Mustafa, a web developer known for creating user-friendly and visually appealing websites. Discover his skills, experience, and passion for web development.",
            type: "webpage",
            url: "https://sufianmustafa.com/about",
            images: [
              {
                url: "https://res.cloudinary.com/dtvtphhsc/image/upload/v1697724760/Screenshot_248_tpjuk3.png",
                width: 800,
                height: 800,
                alt: "About Me - Sufian Mustafa",
              },
            ],
          }}
        />
      </Head>
      {/* Your About Me page Code goes here */}
    </>
  );
};

export default AboutMePage;

```

## Code Explanation:

- `<NextSeo>` Component:
- The NextSeo component is imported from the next-seo package. It's used to define SEO metadata for the current page.

-   `<Head>` Component:
The Head component from Next.js is used to manage the document head, where metadata like title and meta tags are specified.


- SEO Metadata:
Inside the NextSeo component, various metadata is set:
title and description: Define the title and description of the page for both SEO and Open Graph.
author: Specifies the author of the page.
canonical: Defines the canonical URL, providing search engines with the preferred URL for the page.



- Open Graph (OG) Tags:
Open Graph tags are crucial for social media sharing. They define how the content appears when shared on platforms like Facebook.
openGraph object: Includes properties like title, description, type, url, and an array of images with their URLs, dimensions, and alt text.


This implementation ensures that your About Me page is not only well-optimized for search engines but also presents a polished appearance when shared on social media platforms.

Feel free to use and customize this code for other pages on your site, updating the metadata accordingly.


`<Nextseo>`npm link: (https://www.npmjs.com/package/next-seo)

PLz Add your reaction💖
if you find it helpful! Happy coding! 🚀


My wesite link [https://sufianmustafa.com/]