views:

518

answers:

7

Consider:

p {
  ...
}

.foo {
  ...
}

#bar {
  ...
}

What is the correct name for these statements in CSS? I've seen them called selectors, rules or rulesets, but which is correct?

A: 

I usually call them rules or classes.

Dave Ward
+9  A: 

They are called selectors: http://www.codestyle.org/css/Glossary.shtml

class selector

A syntax for specifying a CSS selector by means of a general purpose, repeatable class attribute of an element. The name of class selectors in style rules is preceded by a full stop or period, ., e.g.:

.Condensed{
  letter-spacing:   0.1em;
}

id selector

A syntax for specifying a CSS selector by means of a unique id attribute of an element. The name of id selectors in style rules is preceded by a hash or pound symbol, #, e.g.:

#Subtitle{
  letter-spacing:   0.1em;
}

See also, the W3 specs: http://www.w3.org/TR/CSS2/selector.html

gclaghorn
what about p { ... } and #bar {...}, class selector seems odd for those?
lexu
Technically .Consdensed is the selector. The entire thing the declaration and the selector is the rule
JoshBerke
I think he's actually referring to the entire rule. The three of them together are the ruleset. The only thing that is a selector is the code outside the {}
jonwd7
+1  A: 

They are selectors - see W3C specification

Paul Dixon
+1 for linking to CSS 2 spec.
RichardOD
+27  A: 

A rule would be considered:

p {....}

A selector in this case is:

p

A rule is made up of selectors & declarations. A declaration is property:value so the entire rule would be:

selector { property:value}

A rule can have multiple declartions and multiple selectors so we can actually have:

selector, selector2
{
  property:value;
  property2:value;
}

A ruleset would be multiple rules.

Here's a quick source on this or the CSS 1 Specification.

JoshBerke
Why the down vote?
JoshBerke
A: 

According to the specification, they are called Selectors.

Jamie Ide
+2  A: 

CSS is made up of a number of rules in the form

selector{declaration}

So the .foo and #bar and p are called selectors but the full statement with the curlies are called rules.

Vincent Ramdhanie
A: 

In this example:

p.class, #id > a {
foo:bar;
}

p, #id > a is group of selectors. p.class and #id are selectors. Selectors are built from simple selectors and combinators: p is a type selector, .class is a class selector (not a class). Combinators are '+', '>', ' ', etc.

selectors {...} is a rule. It's a mistake to call it class.

foo:bar is a declaration for foo property.

http://www.w3.org/TR/CSS2/grammar.html

porneL