Which of the following is a valid CSS selector to select all <p> elements?

2025

Which of the following is a valid CSS selector to select all <p> elements?

Answer: A. p { }Concept: In CSS, a type selector is written as the element's tag name on its own — no prefix character and no angle brackets — and it applies to every element…

  1. A.

    p { }

  2. B.

    #p { }

  3. C.

    .p { }

  4. D.

    <p> { }

Attempted by 251 students.

Show answer & explanation

Correct answer: A

Concept: In CSS, a type selector is written as the element's tag name on its own — no prefix character and no angle brackets — and it applies to every element of that type in the document. The prefix characters mark different selector kinds: # introduces an ID selector, keyed to an element's id attribute, and . introduces a class selector, keyed to a name listed in an element's class attribute.

Application: the rule has to reach every <p> element, and a <p> element is identified by its tag name, so the selector is that tag name written on its own, followed by the declaration block: p { }.

Cross-check — what each candidate selector would actually reach:

  • p { } — bare tag name, so a type selector; it applies to every <p> element in the document.

  • #p { } — the # prefix makes it an ID selector; it applies to the element carrying id="p", whatever its tag.

  • .p { } — the . prefix makes it a class selector; it applies to elements carrying class="p", whatever their tag.

  • <p> { } — angle brackets are HTML markup syntax and CSS selector grammar has no such form, so the CSS parser discards the rule.

Only the bare tag name selects elements by their type, so p { } is the valid CSS selector for all <p> elements.

Explore the full course: Tpsc Assistant Technical Officer

Loading lesson…