Cascading Style Sheets (CSS) is a language used to describe the presentation of a web page written in HTML or XML. It controls colours, fonts, layout, and many other visual aspects.
When several style rules apply to the same element, the browser decides which rule wins based on:
!important )External stylesheets are saved as separate files with the .css extension. They can be linked to one or more HTML pages.
style.css.css/.<head> of each HTML page:
<link rel="stylesheet" href="style.css">
A CSS rule consists of a selector and a declaration block.
| Part | Purpose | Example |
|---|---|---|
| Selector | Identifies the HTML element(s) to style | p, #header, .menu |
| Declaration block | Contains one or more property‑value pairs | { color: red; font-size: 14px; } |
| Property | The aspect of presentation to change | color, margin, background‑color |
| Value | The setting applied to the property | red, 10px, #f0f0f0 |
color – text colourbackground-color – background colour of an elementfont-family, font-size, font-weighttext-align, text-decorationmargin and padding – space outside and inside the borderborder – style, width, colour of the element’s borderwidth and heightdisplay – block, inline, inline‑blockBelow is a simple HTML page linked to an external stylesheet.
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sample Page</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1 id="title">Welcome to My Site</h1>
<p class="intro">This paragraph demonstrates external CSS.</p>
</body>
</html>
/* style.css */
#title {
color: #003366;
text-align: center;
margin-top: 20px;
}
.intro {
font-family: Arial, sans-serif;
font-size: 16px;
line-height: 1.5;
color: #333333;
}
.css, not .txt or .html.<link> element inside the <head> of every HTML page that needs the styles.href attribute matches the actual location of the CSS file.;) and the declaration block ends with a closing brace (}).website.website, create index.html with a heading, a paragraph, and a navigation list.styles.css in the same folder.Verdana, size 14px, and colour #555555.styles.css to index.html using the <link> element.index.html in a web browser and verify that the styles are applied.Saving styles in CSS format allows you to separate presentation from content, reuse designs across multiple pages, and maintain a clean workflow. Remember to use the correct file extension, proper syntax, and accurate linking to ensure your styles are applied consistently.