CSS Tutorial
Learn CSS step by step with easy examples
What is CSS?
CSS stands for Cascading Style Sheets. While HTML provides the structure and content of a web page, CSS controls how it looks - the colors, fonts, layout, spacing, and overall design.
Think of it this way:
- HTML = The skeleton and organs of a body
- CSS = The skin, clothes, and appearance
CSS Syntax
CSS rules are made up of a selector and declarations:
Breaking it down:
- h1Selector - Tells CSS which HTML element to style
- { }Declaration block - Contains the style rules
- colorProperty - What aspect to style
- blueValue - How to style it
How to Add CSS to HTML
There are three ways to add CSS to your HTML:
text-[#9cdcfe]
">style="color: red; font-size: 30px;">text-[#9cdcfe]
">style="color: blue; font-weight: bold;">Quick but not recommended for large projects
Good for single-page styling
Best for multiple pages
CSS Selectors
Selectors tell CSS which HTML elements to style. Here are the most common ones:
This paragraph is highlighted
This is a warning
Welcome to My Site
Colors
CSS offers several ways to specify colors:
Color Tips:
- • Use hex colors (#ff0000) for precise control
- • Use color names (red, blue) for quick testing
- • Use RGBA for transparency effects
- • Test colors for accessibility (contrast)
Text Styling
Make your text look exactly how you want:
The Box Model
Every HTML element is a rectangular box. The box model describes how space is calculated:
Box Model Properties:
- Content: The actual content (text, images)
- Padding: Space between content and border
- Border: Line around the padding
- Margin: Space outside the border
Basic Layout
Learn how to position and arrange elements on your page:
Responsive Design Basics
Make your website look good on all devices with media queries:
Responsive Tips:
- • Start with mobile design first
- • Use percentages instead of fixed pixels
- • Test on different screen sizes
- • Keep touch targets at least 44px
Common CSS Examples
Here are some practical examples you can use right away:
Practice Exercise
Create a simple webpage with these CSS styles:
- A blue heading centered on the page
- Paragraphs with a larger font size and line spacing
- A button with a hover effect
- A colored background for the whole page
- A simple navigation bar
Use our code editor to practice! Start with basic HTML and add CSS styling step by step.