CSS helps make websites look nice and organized. It controls colors, fonts, and layout so pages are easy to read and pretty.
0
0
Role of CSS in web development
Introduction
When you want to change the color or size of text on a webpage.
When you want to arrange images and text neatly on the screen.
When you want your website to look good on phones and computers.
When you want to add space between elements so the page is not crowded.
When you want to make buttons and links stand out for users.
Syntax
CSS
selector {
property: value;
}The selector chooses which HTML parts to style.
Inside the braces, property sets what to change, and value tells how to change it.
Examples
This makes all paragraphs have blue text.
CSS
p {
color: blue;
}This sets all main headings to be bigger and centered.
CSS
h1 {
font-size: 2rem;
text-align: center;
}This styles elements with class 'button' to have green background, space inside, and rounded corners.
CSS
.button { background-color: green; padding: 1rem; border-radius: 0.5rem; }
Sample Program
This webpage uses CSS to set background color, center the heading, style paragraphs with readable font size and color, and highlight a word with a yellow background.
CSS
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>CSS Role Example</title> <style> body { font-family: Arial, sans-serif; background-color: #f0f8ff; margin: 2rem; } h1 { color: #2a52be; text-align: center; } p { color: #333333; font-size: 1.2rem; max-width: 600px; margin: 1rem auto; line-height: 1.5; } .highlight { background-color: #ffeb3b; padding: 0.5rem; border-radius: 0.3rem; } </style> </head> <body> <h1>Welcome to CSS</h1> <p>CSS helps you <span class="highlight">style</span> your web pages by changing colors, fonts, and layout.</p> <p>It makes websites look nice and easy to use on any device.</p> </body> </html>
OutputSuccess
Important Notes
CSS separates content (HTML) from design, making it easier to update styles without changing the page structure.
Using classes and IDs in CSS helps style specific parts without affecting others.
Responsive CSS makes websites look good on phones, tablets, and desktops by adjusting layout and sizes.
Summary
CSS controls how web pages look by styling colors, fonts, and layout.
It helps make websites attractive and easy to use on different devices.
CSS uses selectors and properties to apply styles to HTML elements.