Open In App

CSS Introduction

Last Updated : 27 Jun, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

CSS (Cascading Style Sheets) is a language designed to simplify the process of making web pages presentable.

  • It allows you to apply styles to HTML documents by prescribing colors, fonts, spacing, and positioning.
  • The main advantages are the separation of content (in HTML) and styling (in CSS) and the same CSS rules can be used across all pages and not have to be rewritten.
  • HTML uses tags, and CSS uses rule sets.
  • CSS styles are applied to the HTML element using selectors.
Webpage-With---without-CSS

What is Cascading?

Cascading in CSS refers to how styles are applied to elements based on priority rules. When multiple CSS rules target the same element, the browser decides which style to apply by following the cascading order: inline styles, internal styles, and external stylesheets. The specificity of selectors, the order of CSS rules, and the use of important tags further determine which styles take precedence. This allows developers to layer styles and create more complex designs without overriding other rules unnecessarily. Understanding this behavior is essential for efficient and effective styling.

Why CSS?

  • Saves Time: Write CSS once and reuse it across multiple HTML pages.
  • Easy Maintenance: Change the style globally with a single modification.
  • Search Engine Friendly: Clean coding technique that improves readability for search engines.
  • Superior Styles: Offers a wider array of attributes compared to HTML.
  • Offline Browsing: CSS can store web applications locally using an offline cache, allowing offline viewing.

CSS Syntax

CSS consists of style rules that are interpreted by the browser and applied to the corresponding elements. A style rule set includes a selector and a declaration block.

  • Selector: Targets specific HTML elements to apply styles.
  • Declaration: Combination of a property and its corresponding value.
HTML
// HTML Element
<h1>GeeksforGeeks</h1>


CSS
// CSS Style
h1 {
    color: blue; font-size: 12px;
}


Where -
Selector - h1
Declaration - { color: blue; font-size: 12px; }

  • The selector points to the HTML element that you want to style.
  • The declaration block contains one or more declarations separated by semicolons.
  • Each declaration includes a CSS property name and a value, separated by a colon.

Example

CSS
p {
    color: blue;
    text-align: center;
}

CSS declaration always ends with a semicolon, and declaration blocks are surrounded by curly braces. In this example, all paragraph element (<p> tag) will be centre-aligned, with a blue text color.

Ways to Apply CSS

1. Inline CSS: Directly within the HTML element using the style attribute.

2. Internal CSS: Within a <style> tag in the <head> section.

3. External CSS: The external CSS is the CSS linked to an HTML file using the <link> tag.

Key Advantages and Disadvantages of CSS

Here are some key advantages and disadvantages of css:

Advantages of CSS

Disadvantages of CSS

  • Cross-Browser Compatibility Issues: Different browsers may interpret CSS differently, causing inconsistencies in design.
  • Complexity in Large Projects: As projects grow, CSS can become hard to manage, leading to cluttered code and style conflicts.
  • Limited Dynamic Behavior: CSS is mainly for static design, so it can't handle complex interactions or animations without JavaScript

For more, please read our detailed article on Advantages and Disadvantages of CSS.


Next Article

Similar Reads