1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

What Is The Difference Between Class And ID?

Discussion in 'CSS' started by gobbly2100, Jun 4, 2007.

  1. #1
    Can someone explain what the actual difference is between class and ID?
     
    gobbly2100, Jun 4, 2007 IP
  2. fsmedia

    fsmedia Prominent Member

    Messages:
    5,163
    Likes Received:
    262
    Best Answers:
    0
    Trophy Points:
    390
    #2
    classes can be used unlimited amount of times, an ID can only be used once.

    I use IDs for things like id="container" or id="header" or just something that is unique and won't be used again.

    Classes are good for repeating items such as something like comments in a blog.
     
    fsmedia, Jun 4, 2007 IP
  3. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ID values can be used once per page, whereas class values can be used repeatedly.

    You can have multiple IDs, like id="value1" and id="value2" on a page, but you cannot have two IDs on the same page with id="value1"; in these cases classes would be better.

    It's a best practice to restrict the use of IDs to global page elements, such as your header, menu, content area, sidebar and footer, or for those page elements you intend to modify via the DOM (using JavaScript).
     
    Dan Schulz, Jun 4, 2007 IP
  4. htmlmaster

    htmlmaster Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yes you are right dan:)
     
    htmlmaster, Jun 5, 2007 IP