1What is CSS and why is it used?
CSS (Cascading Style Sheets) is a stylesheet language used to describe the presentation and visual styling of HTML documents.
Purpose of CSS:
- Controls the visual appearance of web pages (colors, fonts, layouts)
- Separates content (HTML) from presentation (CSS)
- Enables responsive design for different screen sizes
- Improves website maintainability and consistency
- Reduces code repetition across multiple pages
Example:
<!-- HTML -->
<h1 class="title">Welcome</h1>
<p class="description">This is styled text.</p>
<!-- CSS -->
<style>
.title {
color: #2c3e50;
font-size: 32px;
text-align: center;
}
.description {
color: #7f8c8d;
font-size: 16px;
line-height: 1.6;
}
</style>