CSS / LESSON 01

Style your first page

Connect CSS to HTML and read a rule as selector, property, and value.

Content updated

By the end, you can…

  • HTML gives content meaning. CSS changes its presentation. Start with one rule and one visible change.
  • Explain the example, change one value, and check the result in your own page.
Before you begin

One idea at a time

CSS stands for Cascading Style Sheets. A stylesheet is a file of presentation rules. Your browser already gives HTML a default appearance. CSS lets you change that appearance while keeping the same headings, paragraphs, and links. You do not need JavaScript to style a page. Keep the HTML from your first page and add a stylesheet beside it so you can see which file owns the content and which owns its appearance.

Read a rule as a small instruction: find these elements, then apply these declarations. In p { color: navy; }, p is the selector. Inside the braces, color is a property and navy is its value. A colon separates property and value; a semicolon ends the declaration. You can put several declarations inside one pair of braces.

What to remember first

Remember first

HTML gives content meaning. CSS changes its presentation. Start with one rule and one visible change.

Read the CSS before trying it

pSelector: which elements?
A type selector matches every paragraph. Later you will target a reusable class instead.
colorText color
Changes the letters, not the surface behind them.
background-colorBackground surface
Sets the color behind an element’s content. A value beginning with # is a hexadecimal color code; use the supplied colors for now. Lesson 3 explains the notation.
font-sizeSize of the letters
18px is a length in CSS pixels, a browser measurement rather than a count of physical screen dots. We will compare relative units in the text lesson.
<link>Load an external stylesheet
Put this void element in head. rel="stylesheet" identifies the relationship; href gives the CSS file path. It has no closing tag.

Walk through an example

html
<!-- In head: -->
<link rel="stylesheet" href="styles.css" />
<!-- In body: -->
<h1>Hello, CSS!</h1>
<p>I am learning to style my page.</p>
css
body {
  background-color: #f0f9ff;
}
h1 {
  color: #1e3a8a;
}
p {
  font-size: 18px;
}

Create styles.css in the same folder as index.html. Put the link inside the existing head, then the heading and paragraph inside body. The CSS file contains only CSS, without style tags. Save both files and open index.html. The page surface becomes pale blue, the heading dark blue, and the paragraph uses the requested size.

See it happen: try a small change

Style your first page: compare the result

Predict what will change, choose a version, and compare the live result with the CSS. Use the real controls when the example includes them.

Code to notice

/* No lesson CSS added yet. */

Live result

Lesson example
index.htmlPreview

What changed: The preview has a basic readable frame. No lesson CSS has been added yet; HTML still has a browser appearance.

Look a little closer

There are three ways to attach CSS. External CSS uses link and a separate file, which is convenient when several pages share styles. Internal CSS puts rules between <style> and </style> in head. Inline CSS puts declarations in a style attribute on one element. These are different locations for CSS, not three different languages.

Use the external file for this course so the workflow stays consistent. The interactive preview embeds the selected rules for you; it does not create files on your computer. If an edit does not appear locally, confirm the filename in href, save the stylesheet, and refresh the HTML page before changing unrelated code.

Recognize the other two locations

A style element holds a whole rule; a style attribute holds declarations without a selector or braces. These small alternatives demonstrate the same text color. Try one location at a time so conflicting rules do not distract from the result.

html
<!-- Internal: inside head -->
<style>
  p {
    color: navy;
  }
</style>
<!-- Inline: on one paragraph in body -->
<p style="color: navy">One styled paragraph.</p>

Try it in your own project

Create styles.css beside index.html and add the link shown above to the existing head. Put only the heading and paragraph inside body; the HTML comments mark the two locations. Save the CSS without style tags, then save both files and refresh index.html. Change the heading color first to confirm that the connection works.

The preview uses a small set of readable starting styles for its font, spacing, and controls. The code to notice shows the lesson's own rules. Your local browser defaults may look different before you add those rules; focus on the relationship being demonstrated rather than matching every pixel of the preview.

A common wrong turn

A CSS file named styles.css.txt will not match href="styles.css". Also do not paste <style> into the external stylesheet. The browser expects rules there, not HTML tags. Fix the connection before experimenting with more properties.

Your turn: style your first page

Create a small reading page with an external stylesheet. Change its page background, main heading color, and paragraph size. Keep the writing understandable without the styling.

Try this task in your own index.html and styles.css files. Save both files and refresh your browser to see changes. Continue below follows the course order, including its practice checkpoint.

Related practice in the course path

This practice appears in CSS fundamentals, step 6. Follow Continue below to reach it after its prerequisites.

For related guided practice, Style a reading card gives you starter code, a live preview, hints, and checks. The task above is a separate variation to try in your own project.

Open Style a reading card practice →

  1. Save index.html and styles.css together, and put the stylesheet link in head.
  2. Add one of the three properties at a time. Save and refresh after each change.
  3. Temporarily remove one declaration and predict what will return to the browser default. Restore it and explain the difference.

Go to the source

Examples are authored for Tuklas and checked with code and reference documentation. This is not a claim of independent human review. Suggest a correction.