Wells-it.com - Web Hosting

difference in class and id css

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.

They have: 38 posts

Joined: Nov 2006

can anyone give a good explanation in the difference between an id and a class in CSS I've found that I can really use them interchangeably.. so is there a right time to use one or the other?

A patch is a piece of software which replaces old bugs with new bugs.

West Chatham Homes | Custom American made Caps | Custom Handmade Knives

andy206uk's picture
DeveloperModerator

He has: 1,754 posts

Joined: Jul 2002

Hi,

An ID should always be unique, therefore you should only use them to identify unique parts of the page for instance your header. Each ID should only appear on a page ONCE.

Classes can be used as many times as you like.

At least... that's how I understand it... Laughing out loud

Andyk

Blog of a Web Designer
Give a man a fish and you feed him for a day. Teach him to use the Net and he won't bother you for weeks.

Roo's picture
Developer

She has: 836 posts

Joined: Apr 1999

Yes, that about sums it up Smiling. I've never tried it, but if you were to try to use an ID more than once I don't think it would even display more than once. Am I right or wrong about that?

andy206uk's picture
DeveloperModerator

He has: 1,754 posts

Joined: Jul 2002

That's how it should work, but in my experience most browsers just treat it like a class and repeat the styling. The HTML validator growls at you if you do use them more than once though...

Andyk

Blog of a Web Designer
Give a man a fish and you feed him for a day. Teach him to use the Net and he won't bother you for weeks.

Megan's picture
Administrator

She has: 10,304 posts

Joined: Jun 1999

The browsers have no problem with duplicate ID's. The validator does.

Think of Classes and ID's this way: a class is a group. Anyone can belong. An ID is an identification number - it has to be unique to one individual.

They have: 38 posts

Joined: Nov 2006

alright thanks for the help guys