CSS First Example



Live Example of CSS :

<html>
    <head>
        <style type="text/css">
            h1 {
                color:red;
                text-align:center;
            }
            p {
                color:black;
                text-align:left;
                font-size:18px;
                font-weight:bold;
            }
        </style>
    </head>
    <body>
        <h1>Hello World!</h1>
        <p>This is sample paragraph.This is Styled paragraph using CSS.</p>
    </body>
</html>

Output :

Output of CSS Example

Explanation of CSS Code

CSS is used to style the HTML elements. We are writing plain HTML code and included style sheet code in the head section of HTML web page.CSS code is written in the following tags –

<style type="text/css">
.
.
.
.
.
</style>

Rules :

We have created two rules in the above sample code snippet –

h1 
{
color:red;
text-align:center;
}

and

p 
{   
color:black;
text-align:left;
font-size:18px;
font-weight:bold;
}

these two rules are for HTML elements i.e h1 and p
Whenever we write these HTML tags then all the properties specified in the CSS rule are applied.