A plain HTML page uses the browser's default style: black text on a white background, with the same fonts everywhere. CSS lets the author replace those defaults with a design, without changing the HTML itself.
What CSS Is
CSS stands for Cascading Style Sheets. A style sheet is a set of rules that say how elements should look. The word cascading refers to the way the browser decides between rules when more than one applies to an element. The current level, CSS3, is divided into modules for colours, layout, animation and other areas, and each module is developed on its own.
Definition: CSS. A style language that controls the colours, fonts, spacing and layout of HTML elements.
The Syntax of a Rule
A CSS rule has two parts. The selector names the elements to style. The declaration block, written inside braces, holds one or more declarations. Each declaration is a property, a colon, a value and a semicolon.
Definition: Declaration. One property and its value, written as a pair such as color: red.
For example, the rule h1 { color: blue; font-size: 32px; } makes every first-level heading blue and 32 pixels tall. CSS ignores spaces and line breaks, so a rule is usually written with one declaration on each line to keep it readable.
Why Separate Presentation from Content
Keeping style apart from structure has clear benefits, which Table 2.1 summarises.
Table 2.1: Benefits of separating CSS from HTML
| Benefit | Explanation |
|---|---|
| One change, many pages | A shared style sheet restyles a whole site from one place |
| Smaller pages | The HTML contains no repeated formatting |
| Faster loading | The browser stores the style sheet and reuses it |
| Easier reading | Structure and design can be read and edited separately |
| Flexibility | The same HTML can have different styles for screen, print and phone |
Comments
CSS comments begin with /* and end with */. A browser ignores them, and developers use them to explain rules or to switch a rule off while testing.
Example 2.1: Styling a plain page
The same HTML is shown with and without a few CSS rules. The rules are:
body { font-family: Arial, sans-serif; }
h1 { color: #1F3864; }
p { font-size: 18px; line-height: 1.5; }
<style>
body { font-family: Arial, sans-serif; }
h1 { color: #1F3864; }
p { font-size: 18px; line-height: 1.5; }
</style>
<h1>Welcome</h1>
<p>CSS changes the look without touching the structure.</p>
Output in the browser:
Common mistakes
- Forgetting the semicolon between declarations, which breaks the declaration that follows.
- Writing a colon and a value but leaving out the property name or the braces.
- Using formatting tags in HTML for appearance, instead of rules in CSS.
- Mixing up the colon, which separates a property from its value, with the semicolon, which ends the declaration.
Key takeaways
- CSS controls the presentation of a page, and HTML controls its structure.
- A rule is a selector followed by declarations in braces.
- A declaration is a property, a colon, a value and a semicolon.
- One style sheet can style many pages, so a design change is made in one place.
Practice questions
- What do the letters CSS stand for?
- Name the two parts of a CSS rule.
- Give one benefit of keeping CSS apart from HTML.
Answers to the practice questions
- Cascading Style Sheets.
- The selector and the declaration block.
- A change made in one style sheet updates every page that uses it.
Sources
- Official BCA syllabus (NEP 2025 scheme), Web Application Development, course code 25BCA405DS04, Unit II
