CSS, or Cascading Style Sheets, is a language used to style HTML content. It controls the layout, colors, fonts, and overall visual appearance of web pages. Here’s an overview of CSS basics, selectors, properties, and how you can use them to create beautiful, responsive designs.
What is CSS?
CSS separates the content of a web page from its presentation. It allows you to apply styles consistently across multiple pages and ensures that your website maintains a unified look and feel.
Basic Syntax
A CSS rule consists of a selector and a declaration block.
selector {
property: value;
}
Selectors
Element Selector: Targets HTML elements.
p {
color: blue;
}
Class Selector: Targets elements with a specific class attribute.
.example {
font-size: 20px;
}
ID Selector: Targets a single element with a specific ID.
#unique {
background-color: yellow;
}
Properties
CSS properties define the styles applied to elements. Here are a few common properties:color: Sets the text color.
background-color
: Sets the background color.
font-size
: Sets the size of the text.
margin
: Sets the space around elements.
padding
: Sets the space inside elements.
Example
body {
font-family: Arial, sans-serif;
line-height: 1.6;
}
h1 {
color: #333;
}
p {
margin: 10px 0;
}
Conclusion
CSS is a powerful tool for web design, allowing you to create visually appealing and responsive websites. By mastering CSS, you can enhance the user experience and make your web pages stand out.
Top comments (0)