DEV Community

premprakash yadav
premprakash yadav

Posted on

Understanding CSS: Styling the Web

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;
}      
Enter fullscreen mode Exit fullscreen mode

Selectors
Element Selector: Targets HTML elements.

p {
   color: blue;
   } 
Enter fullscreen mode Exit fullscreen mode

Class Selector: Targets elements with a specific class attribute.

 .example {
    font-size: 20px;
  } 
Enter fullscreen mode Exit fullscreen mode

ID Selector: Targets a single element with a specific ID.

#unique {
        background-color: yellow;
        } 
Enter fullscreen mode Exit fullscreen mode

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;
        }
Enter fullscreen mode Exit fullscreen mode

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)