Skip to main content

What is CSS and way to write

Updated 2 min readMarkdown

What is CSS

CSS stands for cascading style sheet.CSS is a stylesheet language used to style and design HTML element on web pages.

Cascading Means that when multiple CSS rules apply to same HTML element,the browser follows a set of rules to decide which style should be applied.

There are three ways to add CSS to HTML:

  1. Inline CSS
  2. Internal CSS
  3. External CSS

Let understand these three ways:

  1. Inline CSS

In this way CSS is written directly inside a HTML element.

HTML:

<p style="color:brown">Welcome to CSS</p>

Browser Preview:

  1. Internal CSS

In this way CSS is Written inside <style> tag inside <head> tag in the HTML document.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        p{
            color:green;
        }
    </style>
</head>
<body>
    
<p>Welcome to CSS</p>
   
</body>
</html>

Browser Preview:

  1. External CSS

CSS is written in a separate .css file and connected to HTML.

  1. Create a new file style.css
  1. Use <link> tag to connect that css file
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>

HTML:

<body>
    <p>Welcome to CSS</p>
</body>

In style.css file

p{
    color:green
}

Browser Preview:

No comments yet. Be the first to comment.