Blog about Web Programming and Electronics
💬 👤
back Back to blog
WEB (HTML, CSS, PHP)

CSS Basics for Beginners: How to Style Webpages

If HTML provides the structural skeleton of a webpage, CSS (Cascading Style Sheets) is the engine that delivers colors, visual hierarchy, typography, and responsive adjustments across mobile phones, tablets, and desktop displays. Without CSS, the web would be reduced to unstyled, black-and-white text documents. In this article, we explore the core principles of stylesheets and fundamental styling rules.

How a CSS Rule Works

Every CSS rule consists of two foundational parts: a selector pointing to the targeted HTML elements, and a declaration block defining properties and values.

Construct Example Functional Role
Selector p or .button Specifies which HTML nodes should receive the defined styles.
Property color, font-size Identifies the visual attribute being manipulated (e.g., text color, margins).
Value #007acc, 16px Applies the exact parameter to the corresponding property.

Three Methods of Applying CSS

Styles can be integrated into web documents through three mechanisms, with external stylesheets representing the industry standard.

  1. External CSS: Rules are stored in a dedicated style.css file linked via <link rel="stylesheet" href="style.css"> in the document head.
  2. Internal CSS: Declarations are placed directly within a <style> tag inside the HTML head.
  3. Inline CSS: Styles are assigned to individual elements using the style="..." attribute.

Practical CSS Styling Example

The snippet below demonstrates how a few concise CSS rules transform generic typography and create a modern interactive button.

/* Global body styling */
body {
    font-family: Arial, sans-serif;
    background-color: #f4f6f9;
    color: #333333;
    padding: 20px;
}

/* Primary heading style */
h1 {
    color: #0056b3;
    border-bottom: 2px solid #0056b3;
    padding-bottom: 8px;
}

/* Styled call-to-action button */
.my-button {
    background-color: #28a745;
    color: #ffffff;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

Want to Learn More About CSS?

To master modern layout models like Flexbox and CSS Grid, visual transitions, and mobile-responsive media queries, check out our comprehensive CSS Beginner Tutorial.

back Back to blog