Understanding CSS Class and ID

css_logo

Often these selectors can confuse beginners. In CSS a class is represented by a dot “.” while an id is a hash “#”. Simply put an id is used on a unique style that doesnt repeat whilst a class can be re-used.

Often it can be hard to decide where to use a class versus an id for an element

Use a class tag if:

1.The style is used in various places throughout the document.
2.The style is very general.

Use an id tag if:

1.The style is only used once ever in the document.
2.The style is specific to a certain area of the document.

Remember that an id can only appear once in any HTML document. Once you’ve used that id it should not be used again on that page.

Leave a Comment

Your email address will not be published. Required fields are marked *