/    Sign up×
Community /Pin to ProfileBookmark

class vs id

ok, i have recently learned css and have a pretty good understanding of it (i think ;P) I just came across this forum and am very happy. My first question i havent been able to find an answer to on my own is: what is the difference between using id and class? i dont c really a difference to either other then id uses # basically ? i must be missing something as i see some style sheets w/ both. all help appreciated (also i dont mind if u go off on other things after answering my question, just means more knowledge to learn ;P) thx all

to post a comment
CSS

5 Comments(s)

Copy linkTweet thisAlerts:
@LightningAug 06.2004 — Class is generic for an object in css. You can use it over and over. An example would be a paragraph type that you use throughout your html.

ID is for a specific instance. One that you want to reference directly using JavaScript, as an example.
Copy linkTweet thisAlerts:
@pawkyauthorAug 06.2004 — [i]Originally posted by Lightning [/i]

[B]Class is generic for an object in css. You can use it over and over. An example would be a paragraph type that you use throughout your html.



ID is for a specific instance. One that you want to reference directly using JavaScript, as an example. [/B]
[/QUOTE]


so ID is used more when your using scripts? what other instances? or is that pretty much it? thx
Copy linkTweet thisAlerts:
@rmtAug 06.2004 — I've always thought that an id can only be used once on a page, whereas a class can be used multiple times.

Ross
Copy linkTweet thisAlerts:
@LightningAug 06.2004 — You're both correct. You'd only want to use a css object with an ID only once on your page.

Are IDs used more when you're using scripts? That would be the logical choice, as an ID or name attribute do nothing except take up code space unless thay're being referenced in some way by a script.
Copy linkTweet thisAlerts:
@pawkyauthorAug 06.2004 — i guess it makes sense now ? thx for the help all
×

Success!

Help @pawky spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...