CSS: An Easy Introduction to Beginners


What is CSS

CSS, or Cascading Style Sheets, is a language used to style the appearance of web pages. Imagine a web page without CSS – it would just be plain text. CSS is what makes websites look visually appealing by adding colors, layouts, fonts, and other design elements.


Here is the example. The area labeled "HTML ONLY" shows how your website will seem if you use simply HTML, while the portion labeled "HTML WITH CSS" shows how your website will appear if you use HTML along with CSS.


Cool right!

Syntax of CSS (CSS in External file or Internal)

Selector {
    Property1: Value
    Property2: Value
}

EX:
p {
    color: blue;

    font-size: 24px;
}

Syntax of CSS (Inline)

<span style="property1: value; property2: value;"></span>

EX:
<span style="color: red; font-size: 40px;"></span>

what is selectors?

CSS selectors allow you to target specific HTML elements. You can select elements by tag name (e.g., h1, p), class (e.g., .container, .button), ID (e.g., #header, #footer), or other attributes.


How we can call CSS from HTML File?
There are 3 ways to include css styling in html file:

1. Inline CSS (Bad Practice: unmaintainability, problems with readability, and reusability)

index.html

<!DOCTYPE html> 

<html lang="en"> 

<head> 

<title>My First WebPage</title>

</head>
<body>

    <p style="font-size: 35px;"></p>

</body>

</html>

2. Internal CSS

index.html

<!DOCTYPE html> 

<html lang="en"> 

<head> 

<title>My First WebPage</title>
<style> 

    .custom-font-size {

        font-size: 35px;

    }

</style>
</head>
<body>

    <p class="custom-font-size"></p>

</body>

</html>

3. External CSS (Best Practice)

index.html

<!DOCTYPE html> 

<html lang="en"> 

<head> 

<title>My First WebPage</title>
<link href="./main.css" rel="stylesheet"></link>
</head>
<body>

    <p class="custom-font-size"></p>

</body>

</html>

main.css

.custom-font-size {

    font-size: 35px;

}

Comments

Popular posts from this blog

Host Your Node.js App on AWS EC2 Instance for Free in 2024

GitCommandsPro Your Guide to Essential Git Commands in 2024

SOAP Explained: With Javascript