Go back

Introduction to CSS

There are 3 ways we can link CSS to a HTML Document -

Inline CSS

In this option we use the style property of HTML elements to provide style

<h1 style="color: yellow">Hello</h1>
<!-- The code above makes the text yellow -->

<style></style> Tag

We use the style tag to write multi line and multi element CSS inside our HTML code

<!DOCTYPE html>
<html lang="en">
    <head>
        ...
        <style>
            h1{
                color: #fcfcfc; /* makes the text gray */
            }
            body{
                background-color: #212121; /* A dark black baground */
            }
        </style>
    </head>
    <body>
        <h1>Hello World</h1>
        <p>this is some sample text</p>
    </body>
</html>

Seperate .css file

We can also store our css in a different file. To link the css we can use the link tag as below -

<link rel="stylesheet" href="style.css" />

This will reference a style.css file for the styles.

Few base CSS properties

Ways to represent color in CSS

There are other color representations in CSS you can read about them form this link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_colors/Color_values