Code / Web Basics: HTML & CSS / Unit 3: CSS basics: colour and style

CSS rules and selectors CSS नियम और सिलेक्टर

Lesson 6 of 14 · about 15 minutes · Style tags, classes and ids.

⚡ 0 XP

Step 1 of 2

Your first CSS rule

#e78936#2f9e66#1b2353#f6c453color: #e78936;

HTML says what things are. CSS says how they look. A CSS rule has a selector and declarations:

  • h1 { color: crimson; }
  • h1 is the selector — it picks every <h1>
  • color is a property and crimson is its value
  • each declaration ends with a semicolon ;

In these challenges you only write CSS; the HTML page is already made for you.

Example
h1 {
  color: crimson;
}
body {
  background-color: lightyellow;
}

🎯 Challenge: Colour Gupta Sweets +10 XP

Write CSS so that:

  • the h1 text has a colour (not black)
  • the body has a light background colour (not white)

Try twice to unlock the solution (0/2)

style.cssCtrl ⏎
Preview
Console

Output from console.log appears here.

Checklist

Press Run to check your code.

  • The h1 has a colour other than black
  • The body has a background colour (not white)
Lesson notes (text version)

1. Your first CSS rule

HTML says what things are. CSS says how they look. A CSS rule has a selector and declarations:

  • h1 { color: crimson; }
  • h1 is the selector — it picks every <h1>
  • color is a property and crimson is its value
  • each declaration ends with a semicolon ;

In these challenges you only write CSS; the HTML page is already made for you.

                h1 {
  color: crimson;
}
body {
  background-color: lightyellow;
}
              

Challenge: Colour Gupta Sweets

Write CSS so that:

  • the h1 text has a colour (not black)
  • the body has a light background colour (not white)

2. Classes and ids

A tag selector styles every tag of that kind. To style only some elements, give them names in HTML:

  • class="veg" — many elements can share a class. Select it with a dot: .veg { … }
  • id="today" — an id is unique on the page. Select it with a hash: #today { … }
  • an element can have several classes: class="veg special"

Prefer classes for styling; use ids for one-of-a-kind things.

                .veg {
  color: green;
}
#today {
  background-color: gold;
}
              

Challenge: Udupi café menu

Style the menu using selectors:

  • every .veg item gets a colour (not black) — the coffee line without a class must stay black
  • the .special item is bold (font-weight: bold)
  • #today gets a background colour

Search by task, format or tool name.