Which one do i select ? class or id or what?

Just a simple question, in this example

<div id="navigation" class="topnav">

if I wanted to use a selector which one would I use, ‘navigation’ or ‘topnav’? If navigation, why? If topnav, why?
Can I use either one, why?

Thank you for any help.

Please edit your code, highlight the code, and format it. Press the </> button in the editor to indicate the code should not be parsed.

yes, sir.

It doesn’t matter. I would question why you need both though if you have no specific reason.

IDs are unqiue per page. One per page.

Classes can be reused throughout the page. Do you need to keep both? Probably not.

You can use either.

1 Like

There might be hypothetical situations where you have something like

<div id="navigation" class="topnav">
.....
<div id="logobar" class="topnav">
.....
<div id="advertisement" class="topnav">

If you wanted each div.topnav to have the same style you would target the class.

If you wanted a div#_____ to have a style unique to it but not the other ones you would target the id

1 Like

If you just what to style that particular HTML use the id, but if you have multiple html tags using topnav the use the class.

1 Like

Thank you everyone for your HELP! I am truly grateful. God Bless.

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