Card: CSS Rule

The CSS Rule

How to Enchant Your Elements with Style

Selectors and declarations are the spells that breathe new life into your webpage’s elements. Every spell begins with a selector, followed by a declaration block. Don’t worry — it sounds more complicated than it is. The block contains property-value pairs that define how your element looks. And it doesn’t stop at one transformation. Add a few more, and your element will look like a wizard with style — from its color to its border.

Ah, and don’t forget the semicolon — that small, unassuming detail. Leave it out, and the next spell gets stuck, rendering your magic ineffective. With that said, let’s delve into the mysteries of CSS rules and ensure your spells work perfectly — and look amazing in the process!

The Anatomy of a CSS Rule

Some magical terms you should master

Infografik: Codesnippet einer CSS-Regel

Always these foreign words

The who’s who of technical terms

  • Selector: The magical pointer.
  • Declaration { … }: The spell itself.
  • Property: What you want to change.
  • Colon (:): The invisible magician connecting property and value.
  • Value: How it should look.
  • Semicolon (;): The final wand flourish to complete the spell.

Example:

Selector { property : value ; }

Token: Selector

Selector

The Magical Pointer

The selector is your wand, determining which elements on your webpage feel the power of CSS. With a precise gesture, you point to what you want to transform—whether it’s a proud heading, a humble paragraph, or an image in need of a touch-up. The selector is the key to unleashing your magical styles on the right elements.

h1, .classname, ...
Token: Declaration

Declaration

The Spell of Styling

The declaration is the core, the actual spell that reshapes the appearance of your elements. It consists of a property and a value, which together define the shape and appearance. Here, you change colors, sizes, and styles. The semicolon at the end acts as the final wand flourish—without it, the magic fizzles out, leaving your spell ineffective.

h1 {

}
Token: Property-Value Pair

Property-Value Pair

The Secret Formula

Every declaration has its secret formula: the property-value pair, the true source of magic. The property defines what you want to change, and the value determines how it should look—be it a shimmering color or a new shape. The colon in between is the invisible magician, connecting the two and making the magic possible.

h1 {
    font-family: Georgia, serif;
}
HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS-Declaration</title>
    <style>
        body {
            font-family: Georgia, 'Times New Roman', Times, serif;
            color: maroon;
        }

        p {
            font-style: italic;
        }
    </style>
</head>

<body>
		<h1>Welcome</h1>
    <p>in the fabulous world of Aetheron</p>
</body>

</html>
Scroll to Top