SimpleTuts.com

CSS Basics

Introduction to CSS and Basic Styling Methods

In this class, students will learn what CSS is, why it is used, and how to apply basic styles to HTML elements using inline and internal CSS.

Class Objective

Introduction to CSS

What is CSS?

Why CSS is Needed?

CSS Syntax

Basic CSS structure:


selector {
    property: value;
}

Example:


p {
    color: blue;
}

CSS Methods

Inline CSS

Inline CSS is written inside an HTML tag using the style attribute.


<h1 style="color: red;">Welcome</h1>

Internal CSS

Internal CSS is written inside the <style> tag in the <head> section.


<!DOCTYPE html>
<html>
<head>
    <style>
        h1 {
            color: green;
            text-align: center;
        }
        p {
            font-size: 18px;
        }
    </style>
</head>
<body>
    <h1>CSS Basics</h1>
    <p>This paragraph is styled using CSS.</p>
</body>
</html>
Run Code

Common CSS Properties

Text Color


color: blue;

Background Color


background-color: lightgray;

Font Size and Font Family


font-size: 20px;
font-family: Arial;

Text Alignment


text-align: center;

Practice Task

Assignment