Won't it be a better choice to use id here instead of class?

Hi! I’m going through the ‘Learn CSS Grid by building a magazine’. And they have used classes to name some elements but I think those class names will not be used again in the file so won’t it be a better choice to use id?

Link for Step #8 of the lesson

Here’s the code till Step #8:

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="styles.css" />
      <section class="heading">
        <header class="hero">
            alt="freecodecamp logo"
          <h1 class="hero-title">OUR NEW CURRICULUM</h1>
          <p class="hero-subtitle">
            Our efforts to restructure our curriculum with a more project-based focus

As you can see there are classes like heading, hero-img, hero-subtitle, hero-title that won’t be used again. So if they aren’t being used again why haven’t they used id for this purpose?

Link for the last step of the lesson

I checked the final html file at the end of the lesson and these classes have not been used again with any other element. So then why haven’t they used id for this purpose? Wouldn’t it make more sense to use id to name elements?

In general you want to use classes over ids because ids are harder to maintain and can only be used once.
(So you want to save them for the occasion when they are needed).

But ultimately you get to decide what is appropriate.

Okay, I see… Thanks!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.