Mirich
Mirich

Reputation: 351

Is it a norm to use class or id for header and section in html

I am new to HTML and CSS and as I was watching beginner tutorials on Youtube, I faced some confusion concerning if it is ok to use class or id for header and section. Since header and section should not be used as a wrapper and have to be used for document outline purposes only. Bearning in mind this fact why we use class or id with header and section to give style to both. For example:

<header class="showcase">
<header>

and

<section class="about">
<section>

Upvotes: 0

Views: 5911

Answers (5)

Pedram03
Pedram03

Reputation: 1

it is generally a good practice to specify classes for sections in HTML. This can help maintain a cohesive design and make it easier to update the styling of multiple sections at once by modifying the CSS rules for that class.

Upvotes: 0

jolle snaas
jolle snaas

Reputation: 95

I does not matter at all, but personally I like to use class elements for things that I'm gonging to use multiple times (Example text sizes or colours) and ID's for things like logo's that will only appear once on the page.

Also, I like to use ID's for JavaScript and Classes for CSS.

But it totally does not matter at all, so use with whatever you feel convertible with!

Upvotes: 0

ProEvilz
ProEvilz

Reputation: 5445

It's perfectly acceptable to put a class or and id on either <header> or <section> since it's valid HTML to use up to multiple of them - it makes it easier to target them.

With that said, an id should always be unique per page. For example, never use the same id more than once in the entire page... that's what classes are used for.

It's also perfectly acceptable to style the <header> and <section> tags directly. It's ultimately your choice... To reinforce this concept, even browsers will have slightly different default styles for those elements. E.g. Opera may have slightly different default CSS to what Chrome might have.

Upvotes: 1

Piyush Jain
Piyush Jain

Reputation: 1986

Ideally you can right css for header and footer without adding class, because we will have only one header and footer in one application. But for section you can use class because there can be multiple sections on a page. Common styles for section you can write using section only and for other styles you can use class.

If you have more doubts, let m know.

Upvotes: 1

Szekelygobe
Szekelygobe

Reputation: 2695

I use class and id all the time for ALL HTML elements. One thing to pay attention is for the id to be unique.

Upvotes: 1

Related Questions