What is CSS?
CSS (Cascading Style Sheets) is the language used to style and format HTML documents. It controls colors, fonts, layouts, spacing, and even animations. By separating content (HTML) from presentation (CSS), websites become easier to maintain and style.
Why Use CSS?
- Control the look and feel of your site from a single file.
- Make pages consistent and professional.
- Improve accessibility and user experience.
- Enable responsive design for different devices.
Ways to Add CSS
There are three main ways to apply CSS to HTML:
- Inline CSS: Using the
style
attribute directly in an element. - Internal CSS: Using a
<style>
block inside the HTML file's head section. - External CSS: Linking to a separate
.css
file (the preferred method).
Example of CSS in Action
/* style.css */
body {
background-color: #f0f8ff;
font-family: Arial, sans-serif;
color: #333;
}
This CSS changes the background color of the whole page, sets a font family, and changes the text color.