Repaso
EspaƱol

In CSS, what is the difference between .btn and #btn?

Options

  1. There is no difference between the two selectors
  2. .btn targets a class (many); #btn an id (one) (Correct option)
  3. #btn targets only the button elements of a page
  4. .btn is not a valid selector in modern CSS

Answer

.btn targets elements with class="btn" (can be many); #btn targets the element with id="btn" (should be unique)

Why

A class (.) is a reusable label: many elements can share class="btn".

An id (#) should identify exactly one element per page.

For styling, classes are preferred: IDs have very high specificity, which makes them hard to override later.

Remember

. = class (many), # = id (one).

Key terms

Practice this question in Repaso