Jump to content

ID vs Class in HTML

Go to solution Solved by DimasRMDO,

Each element can only have one ID, with each page having only one element with that ID.

Multiple elements can have the same class, and elements can have multiple classes.

 

Kinda confusing, it just changes what you're manipulating.

 


Well these help me at least, thank you!

Still trying to figure things out, but these give me some clues.

Uh.... I've been thinking about this.... What's the differences between ID and Class? For example...

<div class="___"></div>

and

<div id="___"></div>

What's the difference? In the end it'll be edited in CSS anyway and the result is the same....

Does "ID" and "Class" affect Javascript or maybe something else?

Where I hang out: The Garage - Car Enthusiast Club

My cars: 2006 Mazda RX-8 (MT) | 2014 Mazda 6 (AT) | 2009 Honda Jazz (AT)


PC Specs

Indonesia

CPU: i5-4690 | Motherboard: MSI B85-G43 | Memory: Corsair Vengeance 2x4GB | Power Supply: Corsair CX500 | Video Card: MSI GTX 970

Storage: Kingston V300 120GB & WD Blue 1TB | Network Card: ASUS PCE-AC56 | Peripherals: Microsoft Wired 600 & Logitech G29 + Shifter

 

Australia 

CPU: Ryzen 3 2200G | Motherboard: MSI - B450 Tomahawk | Memory: Mushkin - 8GB (1 x 8GB) | Storage: Mushkin 250GB & Western Digital - Caviar Blue 1TB
Video Card: GIGABYTE - RX 580 8GB | Case: Corsair - 100R ATX Mid Tower | Power Supply: Avolv 550W 80+ Gold

 

Link to comment
https://linustechtips.com/topic/484030-id-vs-class-in-html/
Share on other sites

Link to post
Share on other sites

My Rigs:

Gaming/CAD/Rendering Rig
Case:
 Corsair Air 240 , CPU: i7-4790K, Mobo: ASUS Gryphon Z97 mATX,  GPU: Gigabyte G1 Gaming GTX 970, RAM: G.Skill Sniper 16GB, SSD: SAMSUNG 1TB 840 EVO, Cooling: Corsair H80i PCPP: https://au.pcpartpicker.com/b/f2TH99SFF HTPC
Case:
Silverstone ML06B, CPU: Pentium G3258, Mobo: Gigabyte GA-H97N-WiFi, RAM: G.Skill 4GB, SSD: Kingston SSDNow 120GB PCPP: https://au.pcpartpicker.com/b/JmZ8TW
Link to comment
https://linustechtips.com/topic/484030-id-vs-class-in-html/#findComment-6492905
Share on other sites

Link to post
Share on other sites

Each element can only have one ID, with each page having only one element with that ID.

Multiple elements can have the same class, and elements can have multiple classes.

 

Kinda confusing, it just changes what you're manipulating.

 


Well these help me at least, thank you!

Still trying to figure things out, but these give me some clues.

Where I hang out: The Garage - Car Enthusiast Club

My cars: 2006 Mazda RX-8 (MT) | 2014 Mazda 6 (AT) | 2009 Honda Jazz (AT)


PC Specs

Indonesia

CPU: i5-4690 | Motherboard: MSI B85-G43 | Memory: Corsair Vengeance 2x4GB | Power Supply: Corsair CX500 | Video Card: MSI GTX 970

Storage: Kingston V300 120GB & WD Blue 1TB | Network Card: ASUS PCE-AC56 | Peripherals: Microsoft Wired 600 & Logitech G29 + Shifter

 

Australia 

CPU: Ryzen 3 2200G | Motherboard: MSI - B450 Tomahawk | Memory: Mushkin - 8GB (1 x 8GB) | Storage: Mushkin 250GB & Western Digital - Caviar Blue 1TB
Video Card: GIGABYTE - RX 580 8GB | Case: Corsair - 100R ATX Mid Tower | Power Supply: Avolv 550W 80+ Gold

 

Link to comment
https://linustechtips.com/topic/484030-id-vs-class-in-html/#findComment-6499571
Share on other sites

Link to post
Share on other sites

Uh.... I've been thinking about this.... What's the differences between ID and Class? For example...

<div class="___"></div>

and

<div id="___"></div>

What's the difference? In the end it'll be edited in CSS anyway and the result is the same....

Does "ID" and "Class" affect Javascript or maybe something else?

 

Classes are useful for JavaScript (such as the .addClass() method) but they can also be useful for when you're reading your code. I've done quite a bit of freelance web design myself and using both class and ID helps me distinguish unique elements from uniform elements. But as Jared pointed out, you can have multiple classes on each element, making it useful for implementing things such as Bootstrap or Google Material Design.

Link to comment
https://linustechtips.com/topic/484030-id-vs-class-in-html/#findComment-6499848
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×