Open In App

CSS Introduction

CSS (Cascading Style Sheets) is a simply designed language intended to simplify the process of making web pages presentable. CSS allows you to apply styles to HTML documents. It describes how a webpage should look. It prescribes colors, fonts, spacing, etc. In short, you can make your website look however you want. CSS lets developers and designers define how it behaves, including how elements are positioned in the browser.

HTML uses tags and CSS uses rulesets. CSS styles are applied to the HTML element using selectors. CSS is easy to learn and understand, but it provides powerful control over the presentation of an HTML document.



Why CSS?

CSS Versions Release Year

CSS Syntax

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



// HTML Element
<h1>GeeksforGeeks</h2>

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

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

Example




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.

Web Page with & without CSS

Without CSS: In this example, we have not added any CSS style.




<!DOCTYPE html>
<html>
    
<head>
    <title>Simple Web Page</title>
</head>
    
<body>
    <main>
       <h1>HTML Page</h1>
       <p>This is a basic web page.</p>
    </main>
</body>
    
</html>

Output:

Without CSS

Using CSS: In this example, we will add some CSS styles inside the HTML document to show how CSS makes a HTML page attractive and user-friendly.




<!DOCTYPE html>
<html>
  
<head>
    <title>Simple web page</title>
    <style>
        main {
            width: 600px;
            height: 200px;
            padding: 10px;
            background: beige;
        }
          
        h1 {
            color: olivedrab;
            border-bottom: 1px dotted darkgreen;
        }
          
        p {
            font-family: sans-serif;
            color: orange;
        }
    </style>
</head>
  
<body>
    <main>
        <h1>My first Page</h1>
        <p>This is a basic web page.</p>
    </main>
</body>
  
</html>

Output:

With CSS


Article Tags :