Skip to main content

What is CSS? Full Beginner Guide With All Important Concepts

CSS stands for Cascading Style Sheets. While HTML provides structure to a webpage, CSS controls how the webpage looks — colors, layouts, fonts, backgrounds, spacing, and much more.

HTML = Structure
CSS = Design & Layout

How to Use CSS in HTML

There are 3 ways to include CSS in a webpage:

1. Inline CSS

<h1 style="color:blue;">Hello World!</h1>

2. Internal CSS

<style>
  h1 { color: blue; }
</style>

3. External CSS (Best Method)

<link rel="stylesheet" href="style.css">

CSS Syntax

selector {
  property: value;
}
Example:
p {
  color: red;
}

CSS Selectors

1. Element Selector

p { color: blue; }

2. Class Selector

.myText { color: red; }

3. ID Selector

#heading { font-size: 24px; }

4. Universal Selector

* { margin: 0; padding: 0; }

5. Group Selector

h1, p { color: green; }

CSS Colors

color: red;
color: #00bcd4;
color: rgb(0, 200, 100);

Backgrounds

background-color: yellow;
background-image: url("bg.jpg");
background-size: cover;

Border Styling

border: 2px solid blue;
border-radius: 10px;

Text Styling

Example:
h1 {
  font-family: Arial;
  font-size: 30px;
  text-align: center;
}

The CSS Box Model

Every HTML element has:
  • content
  • padding
  • border
  • margin
Example:
div {
  margin: 20px;
  padding: 10px;
  border: 1px solid black;
}

Display Property

Common values:
  • block
  • inline
  • flex
  • grid
Example:
div { display: flex; }

Position Property

Common types:
  • static
  • relative
  • absolute
  • fixed
  • sticky
Example:
.box {
  position: absolute;
  top: 20px;
  left: 50px;
}

Flexbox (Modern Layout)

.container {
  display: flex;
  gap: 10px;
}

Grid Layout

.container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
}

Hover Effects

button:hover {
  background: red;
}

Animations

@keyframes move {
  from { left: 0; }
  to { left: 100px; }
}

Final Summary

  • CSS controls the visual design of web pages
  • Selectors target HTML elements
  • Properties define the style
  • Box model determines element spacing
  • Flexbox & Grid are modern layout systems

In the next lesson, we will build real websites using CSS step by step.

Comments

Popular posts from this blog

HTML Tables Tutorial — Learn Tables with Examples Tables organize tabular data (rows & columns). They are great for schedules, price lists, spec sheets, comparison charts, and any data that fits a grid. This guide covers: Table basics: <table> , <tr> , <td> , <th> Headers, captions, and groups ( <caption> , <thead> , <tbody> , <tfoot> ) Colspan & rowspan Styling and responsive tables Accessibility and best practices Table of Contents Basic Structure Headers & Captions Colspan & Rowspan Grouping Rows: thead / tbody / tfoot Styling Tables Responsive Tables Accessibility Tips Practical Examples Best Practices 1. Basic Structure Minimal valid table: <table> <tr> <td>Cell 1</td> <td>Cell 2</td> </tr> </table> Elements: <table> — container for the table <tr> — table ...
HTML Forms Tutorial HTML Forms Tutorial HTML Forms allow users to enter and submit data. They are used everywhere—login forms, signup forms, search boxes, feedback forms, etc. In this complete tutorial, you will learn all form elements with examples and demos. 1. What is an HTML Form? A form collects user input using different form elements like text fields, checkboxes, radio buttons, buttons, and more. <form> Form elements go here... </form> 2. Basic Form Structure <form action="#" method="post"> <input type="text" placeholder="Enter name"> <button>Submit</button> </form> Submit Attributes: action → URL where form data is sent method="POST" → Secure data sending method="GET" → Data shows in URL 3. Text Input Field <input type="text" placeholder="Your Name...
What is HTML? A Beginner-Friendly Explanation If you want to become a web developer, HTML is the first language you should learn. It is the foundation of every website on the internet. In simple words: HTML (HyperText Markup Language) is used to create the structure and content of a webpage. Why HTML is important? Websites cannot exist without HTML It is simple and beginner-friendly Used with CSS and JavaScript Works on all browsers How does HTML work? HTML is made of tags . Tags tell the browser what type of content is being shown. Example of an HTML tag: <p>This is a paragraph.</p> Here: <p> is the opening tag </p> is the closing tag The text inside is the content Basic HTML Page Example Below is a simple webpage example you can try: <!DOCTYPE html> <html> <head> <title>My First Webpage</title> </head> <body> <h1>Hello World!</h1> <p>This is my...