Introduction to CSS
Introduction to CSS
CSS (Cascading Style Sheets) is used to style and design web pages created with HTML. While HTML provides the structure of a website, CSS controls the appearance such as colors, layouts, fonts, spacing, and responsiveness.
CSS helps transform a simple HTML page into a visually attractive and professional website. It is an essential skill for web designing and frontend development.
Why CSS is Important in Web Designing
CSS plays a crucial role in improving the design and user experience of a website. Without CSS, websites would look plain and unstructured.
Key benefits of CSS:
- Improves website design and layout
- Enhances user experience
- Supports responsive design
- Reduces code repetition
- Helps create modern UI designs
Types of CSS
There are three ways to apply CSS to a web page.
Inline CSS
Inline CSS is applied directly inside an HTML tag using the style attribute.
Internal CSS
Internal CSS is written inside the <style> tag within the <head> section of the HTML document.
<style>
p {
color: blue;
}
</style>
</head>
External CSS
External CSS is written in a separate .css file and linked to the HTML file.
<link rel=“stylesheet” href=“style.css”>
</head>
color: green;
}
External CSS is the most recommended method because it keeps code clean and reusable.
Basic CSS Syntax
CSS follows a simple syntax that includes a selector and properties.
property: value;
}
Example
color: blue;
font-size: 30px;
}
h1is the selectorcolorandfont-sizeare propertiesblueand30pxare values
How CSS Works with HTML
CSS selects HTML elements and applies styles to them. Browsers like Google Chrome read both HTML and CSS together to display styled web pages.
Example: HTML with CSS
<html>
<head>
<style>
body {
background-color: lightgray;
}
h1 {
color: blue;
}
</style>
</head>
<body>
<h1>Welcome to Web Designing</h1>
<p>This page is styled using CSS.</p>
</body>
</html>
Best Practices for Using CSS
- Use external CSS for large projects
- Keep code clean and organized
- Use meaningful class names
- Avoid inline CSS unless necessary
- Follow consistent design patterns
What You Will Learn Next
In the next lesson, you will learn about CSS selectors and properties in detail, which will help you target and style elements effectively.
Click here for more free courses
FAQs
What is CSS used for?
CSS is used to style and design web pages by controlling colors, layout, and fonts.
Which type of CSS is best?
External CSS is best because it is reusable and keeps code organized.
Is CSS necessary for web designing?
Yes, CSS is essential for creating visually appealing websites.
Can I use CSS without HTML?
No, CSS is used along with HTML to style web pages.
Which browser supports CSS?
All modern browsers like Google Chrome support CSS.



