CSS / CSS Basics

Introduction to CSS

Start your journey to mastering CSS with this introductory tutorial. Here, you'll learn about the basics of CSS, what it is, how it's used, and why it's crucial for web developmen…

Tutorial 3 of 5 5 resources in this section

Section overview

5 resources

Introduces the core concepts of CSS, including selectors, properties, and basic styling techniques.

Introduction to CSS

1. Introduction

Goal of the tutorial

This tutorial aims to introduce you to the basics of CSS (Cascading Style Sheets), an essential language for web development that is used to describe how HTML elements should be displayed.

Learning outcomes

After completing this tutorial, you will be able to:
- Understand what CSS is and why it's important
- Write basic CSS syntax
- Apply CSS to HTML to style web pages

Prerequisites

Basic understanding of HTML is expected. If you're not familiar with HTML, consider reviewing an HTML tutorial first.

2. Step-by-Step Guide

CSS is used to control the look and feel of your web pages. It allows you to specify styles for individual HTML elements, whole pages, or entire websites.

CSS Syntax

A CSS rule-set consists of a selector and a declaration block. The selector points to the HTML element you want to style. The declaration block contains one or more declarations separated by semicolons.

selector {
    property: value;
}

How to Add CSS

There are three ways to insert CSS:
- Inline: by using the style attribute inside HTML elements
- Internal: by using a <style> block in the <head> section of the HTML file
- External: by linking to an external CSS file using <link> tag in the <head> section of the HTML file

Best Practices

  • Try to use an external CSS file where possible. This keeps your HTML clean and makes your styles reusable across different pages.
  • Use comments (/* This is a comment */) to describe your code and make it easier to understand.
  • Keep your CSS code DRY (Don't Repeat Yourself). If multiple elements share the same styles, group them in one selector.

3. Code Examples

Example 1: Inline CSS

HTML elements can be styled directly using the style attribute. However, this method is generally not recommended because it can quickly become unmanageable.

<p style="color: red;">This is a red paragraph.</p>

Example 2: Internal CSS

You can include CSS in your HTML document within <style> tags in the <head> section.

<head>
  <style>
    p {
      color: blue;
    }
  </style>
</head>
<body>
  <p>This is a blue paragraph.</p>
</body>

Example 3: External CSS

The best way to include CSS is through an external file. This keeps your HTML clean and your styles reusable.

<head>
  <link rel="stylesheet" type="text/css" href="styles.css">
</head>

In your styles.css file:

p {
  color: green;
}

4. Summary

In this tutorial, we've covered the basic concepts of CSS, including its syntax, how to include it in HTML, and some best practices. The next step is to dive deeper into CSS to learn about more complex selectors, the box model, layout techniques, and responsive design.

5. Practice Exercises

  1. Create an HTML page with a <p> tag and use inline CSS to change its color.
  2. Create an HTML page with a <div> and a <p> tag. Use internal CSS to give them different background colors.
  3. Create an HTML page with a <h1> tag and an external CSS file. Use the CSS file to change the font size of the <h1> tag.

Remember, practice is crucial in mastering CSS. Try to experiment with different properties and values and see what they do. Good luck!

Need Help Implementing This?

We build custom systems, plugins, and scalable infrastructure.

Discuss Your Project

Related topics

Keep learning with adjacent tracks.

View category

HTML

Learn the fundamental building blocks of the web using HTML.

Explore

JavaScript

Learn JavaScript to add interactivity and dynamic behavior to web pages.

Explore

Python

Explore Python for web development, data analysis, and automation.

Explore

SQL

Learn SQL to manage and query relational databases.

Explore

PHP

Master PHP to build dynamic and secure web applications.

Explore

Popular tools

Helpful utilities for quick tasks.

Browse tools

PDF to Word Converter

Convert PDF files to editable Word documents.

Use tool

Word to PDF Converter

Easily convert Word documents to PDFs.

Use tool

Random String Generator

Generate random alphanumeric strings for API keys or unique IDs.

Use tool

Base64 Encoder/Decoder

Encode and decode Base64 strings.

Use tool

PDF Password Protector

Add or remove passwords from PDF files.

Use tool

Latest articles

Fresh insights from the CodiWiki team.

Visit blog

AI in Drug Discovery: Accelerating Medical Breakthroughs

In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…

Read article

AI in Retail: Personalized Shopping and Inventory Management

In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …

Read article

AI in Public Safety: Predictive Policing and Crime Prevention

In the realm of public safety, the integration of Artificial Intelligence (AI) stands as a beacon of innovati…

Read article

AI in Mental Health: Assisting with Therapy and Diagnostics

In the realm of mental health, the integration of Artificial Intelligence (AI) stands as a beacon of hope and…

Read article

AI in Legal Compliance: Ensuring Regulatory Adherence

In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…

Read article

Need help implementing this?

Get senior engineering support to ship it cleanly and on time.

Get Implementation Help