- β¨ What Is CSS? CSS stands for Cascading Style Sheets. Itβs a language that tells the browser how your website should look.
HTML builds the structure of a web page (like walls in a house), and CSS adds the design (like paint, furniture, and decorations).
- π¨ Why Use CSS?
Makes your website look modern and clean
Lets you control colors, fonts, spacing, layout
Helps create responsive websites that look good on all devices
- π οΈ Types of CSS
There are 3 main ways to use CSS. Let's look at each one
- Inline CSS β Style directly in the HTML tag
<p style="color: red; font-size: 20px;">This is red text!</p>
output:
β
Easy for testing
β Not recommended for big websites β it becomes hard to manage.
- Internal CSS β Write inside the HTML file Put your styles in a block inside the <head> tag.</li> </ol> <p><code><!DOCTYPE html><br> <html><br> <head><br> <style><br> h1 {<br> color: blue;<br> }<br> p {<br> font-size: 18px;<br> }<br> </style><br> </head><br> <body><br> <h1>Welcome!</h1><br> <p>This is styled using internal CSS.</p><br> </body><br> </html><br> </code></p> <p>output:</p> <p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hkls1ya8qpmtmi7jdvxe.png" alt="Image description"/></p> <p>β Great for small projects<br> β Not reusable across multiple pages</p> <p>3οΈβ£ External CSS β The best and cleanest way.</p> <p>Write CSS in a separate file, then link to it from your HTML.<br> Step 1: HTML file index.html</p> <p><!DOCTYPE html><br> <html><br> <head><br> <link rel="stylesheet" href="style.css"><br> </head><br> <body><br> <h1>Hello!</h1><br> <p>This is styled using external CSS.</p><br> </body><br> </html></p> <p>Step 2: CSS file style.css</p> <p>body {<br> background-color: #f5f5f5;<br> font-family: Arial, sans-serif;<br> }</p> <p>h1 {<br> color: green;<br> text-align: center;<br> }</p> <p>p {<br> color: gray;<br> font-size: 18px;<br> }</p> <p>output:</p> <p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sxjgixhisorjsxwcim4w.png" alt="Image description"/></p> <p>β Best for real websites<br> β Keeps styles organized and reusable</p> <p>ποΈ Written by Himanshu Bhagwat<br> π Learning through @devsync </p>
Top comments (0)