Hello, my name is: Amy

What is the difference between classes and ids in CSS?

Both IDs and classes are assigned to HTML elements as attributes. The difference is that IDs are meant to be used once in each HTML page as a way to give an element a unique name and identifier. Each element can have only one ID assigned. Generally speaking, it's a best practice to avoid styling an object with an ID.

Classes on the other hand may be applied to multiple elements, and multiple classes may be applied to the same element.

The id of the line below is more2, and there are two classes assigned: link and read-more.

<a id="more2" href="#" class="link read-more"></a>

Stylesheet Reference

If you needed to refer to ids/classes in a stylesheet you would reference a class by preceding the name with a . and an id, a #:

{% highlight html%}

more2 {

/* But really, avoid this */

} .link { / styles / } .read-more { /more styles / } {% endhighlight %}