Be able to save styles in cascading stylesheet format

Resources | Subject Notes | Information Communication Technology ICT

Saving Styles in Cascading Style Sheets (CSS)

Introduction

Cascading Style Sheets (CSS) are used to control the presentation of HTML elements. Saving styles as a CSS file allows for consistent styling across multiple web pages and improves website organization.

Creating a CSS File

To create a CSS file:

  1. Create a new text file with a `.css` extension (e.g., styles.css).
  2. Open the CSS file in a text editor.
  3. Write CSS rules to define the styles.

CSS Syntax

CSS rules consist of a selector and a declaration block. A declaration block contains one or more declarations, each with a property and a value.

Example:

h1 {
  color: blue;
  font-size: 24px;
}

Saving Styles

Once the CSS rules are written, save the CSS file.

Linking the CSS File to an HTML Document

To apply the saved styles to an HTML document, use the element in the section.

Example:




  Website Authoring
  


  

This is a Heading

This is a paragraph of text.

Benefits of Using CSS

  • Consistency: Ensures a uniform look and feel across the website.
  • Maintainability: Styles can be updated in one place, affecting all pages.
  • Efficiency: Reduces the amount of code in HTML files.
  • Accessibility: Can improve the accessibility of web content.

Example CSS Styles

Here are some examples of CSS styles you can save in a CSS file:

Property Value
color red
font-size 16px
font-family Arial
background-color #f0f0f0

Conclusion

Saving styles in a CSS file is a fundamental aspect of website authoring. It promotes organization, consistency, and maintainability of web designs.