Skip to content

Instantly share code, notes, and snippets.

@paulghaddad
Last active August 29, 2015 14:13
Show Gist options
  • Save paulghaddad/baa2233208fdf2d5f526 to your computer and use it in GitHub Desktop.
Save paulghaddad/baa2233208fdf2d5f526 to your computer and use it in GitHub Desktop.
LevelUp 5: Uses semantic classes and IDs, and knows what deserves an ID
1. Name a few things that are often given IDs, but probably don't deserve them.
Unless an element will be targeted by JavaScript, it shouldn't require an ID. IDs are a very specific CSS selector, and if you write your CSS correctly, shouldn't be needed at all. Common elements that are given IDs are the header, footer, and sidebar regions of a page, whether they use the HTML5 elements, or a div. IDs aren't needed for such elements.
In addition to increasing specificity, using IDs for your CSS couples your presentation with your interaction. If you need to change or move an ID because your JavaScript changes, your CSS will also need to change. It is best to use classes for CSS and IDs for JavaScript.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment