Best Practices When USing CSS ID's and Classes

Today's Date

This week at DBC phase 0 has been filled with a log of Html and Css. One thing that was a bit hard to comprehend this week is when to use Id's and Classes in CSS. First, I think well need to define a few things before getting into the best practices of CSS. CSS stands for Cascading Style Sheets and holds all the keys to making your site look good(all of the design features). Within CSS there are ways to organize content and design on your website. You do this through CSS ID's(identifiers) and Class classifications.

You can organize your content to style with ID's and Classes. You use classes to make designs to larger aspects of your site that you want to keep consistent. Classes help create a theme throughout the site where you can make design adjustments to a variety of content. ID's are where you get a little more specific with design. These can be attributed to a line or group of lines to specifically style or align differently than the rest of the site. Now we will talk about how to best use these different elements.

One thing that stands out with best practices between the two CSS elements are how many times you can use one or the other in a CSS/HTML document. When using an ID you are only SUPPOSED to use that ID one time throughout the whole site. However, when using Classes, you can use that class attribute as many times as you want on the site. If you do intend to use an ID more than once, some sites will display your content the way you want, however, be warned, some sites will NOT. On the other hand, Classes, feel free to use as many times as you want. Finally, when denoting a class or an identifier, it is important to understand the correct syntax for making style changes. When referring to an identifier, you use a "#" before the class name to tell the CSS form that you are styling an ID. When referring to a Class, you need to use a "." before the class name in order to make your styling adjustments.

I'm hoping I'm not the only one who learned something from writing this blog post!


More to Come!


-Scott Stern