Welcome to our CSS Formatting tutorial! In this lesson, we'll dive deep into the world of Cascading Style Sheets, explaining the basics and advanced concepts with real-world examples. By the end of this tutorial, you'll be well-equipped to style your web pages like a pro! 💡
CSS (Cascading Style Sheets) is a style sheet language used for describing the look and formatting of a document written in a markup language. In other words, it helps us design the layout, colors, fonts, and more for our web pages.
CSS allows us to separate the content (HTML) from the presentation (CSS), making it easier to maintain and update the look of our web pages. It also enables us to create consistent and visually appealing designs, as well as make our pages more accessible for users with different needs.
A CSS rule consists of two main parts: the selector and the declaration(s).
selector {
property: value;
}selector: This is what the CSS rule applies to. It can be an HTML element, class, or ID.property: This is the CSS attribute we want to change, such as color, font-size, or margin.value: This is the new value we want to set for the property.There are several types of selectors in CSS, each with its own use case.
p for paragraphs.p {
color: red;
}.example for an element with the class "example".<p class="example">This is an example paragraph.</p>
.example {
color: blue;
}#example for an element with the ID "example".<div id="example">This is an example div.</div>
#example {
font-size: 2em;
}:hover for elements when they are being hovered over.a:hover {
color: purple;
}There are hundreds of properties and values in CSS, but here are some essential ones to get you started:
color: Sets the text color, e.g., color: red;.font-size: Sets the font size, e.g., font-size: 16px;.margin: Sets the space around an element, e.g., margin: 10px;.padding: Sets the space within an element, e.g., padding: 10px;.background-color: Sets the background color, e.g., background-color: #f0f0f0;.To link your HTML and CSS files, you can use the <link> tag in the <head> section of your HTML file:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
<title>My Web Page</title>
</head>
<body>
<!-- Your HTML content goes here -->
</body>
</html>What does CSS do?
By the end of this tutorial, you'll have a solid understanding of CSS basics and be ready to style your web pages like a pro! Stay tuned for more advanced CSS concepts in our future lessons. Happy coding! 💡💻