DEV Community

Cover image for Must known CSS properties for styling
Rowsan Ali
Rowsan Ali

Posted on

Must known CSS properties for styling

Cascading Style Sheets (CSS) are the backbone of web design. They empower web developers to control the visual presentation of web pages, covering everything from layout and typography to colors and animations. In this guide, we will delve into an extensive list of CSS properties for styling your web pages, accompanied by detailed explanations and code examples to illustrate their usage.
Follow me on X

1. Color and Background Properties

Color (color): This property sets the text color. You can use named colors or hexadecimal values.

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

Background Color (background-color): Sets the background color of an element.

div {
  background-color: #3366FF;
}
Enter fullscreen mode Exit fullscreen mode

Background Image (background-image): Allows you to set a background image.

body {
  background-image: url('bg-image.jpg');
  background-size: cover;
}
Enter fullscreen mode Exit fullscreen mode

2. Text Properties

Font Family (font-family): Specifies the font for text. You can provide multiple font choices in case the user's system doesn't have the first choice.

h1 {
  font-family: 'Arial', sans-serif;
}
Enter fullscreen mode Exit fullscreen mode

Font Size (font-size): Sets the size of text.

p {
  font-size: 16px;
}
Enter fullscreen mode Exit fullscreen mode

Font Weight (font-weight): Adjusts the thickness of text, typically for boldness.

strong {
  font-weight: bold;
}
Enter fullscreen mode Exit fullscreen mode

3. Text Decoration Properties

Text Decoration (text-decoration): Adds underlines, overlines, or line-through to text.

a {
  text-decoration: underline;
}
Enter fullscreen mode Exit fullscreen mode

4. Text Alignment Properties

Text Align (text-align): Sets the alignment of text within an element.

div {
  text-align: center;
}
Enter fullscreen mode Exit fullscreen mode

5. Margin and Padding Properties

Margin (margin): Specifies the space outside an element.

div {
  margin: 10px;
}
Enter fullscreen mode Exit fullscreen mode

Padding (padding): Defines the space inside an element.

p {
  padding: 20px;
}
Enter fullscreen mode Exit fullscreen mode

6. Border Properties

Border (border): Sets the border around an element. You can define the border width, style, and color.

button {
  border: 1px solid #000;
}
Enter fullscreen mode Exit fullscreen mode

Border Radius (border-radius): Rounds the corners of an element.

img {
  border-radius: 50%;
}
Enter fullscreen mode Exit fullscreen mode

7. Box Shadow Properties

Box Shadow (box-shadow): Adds a shadow to an element. You can define the shadow's horizontal and vertical offsets, blur radius, spread, and color.

div {
  box-shadow: 5px 5px 10px #888888;
}
Enter fullscreen mode Exit fullscreen mode

8. Display and Position Properties

Display (display): Controls how an element is displayed. Options include block, inline, and flex.

span {
  display: block;
}
Enter fullscreen mode Exit fullscreen mode

Position (position): Sets the positioning method for an element. Common values are static, relative, absolute, and fixed.

#menu {
  position: fixed;
  top: 0;
}
Enter fullscreen mode Exit fullscreen mode

9. Flexbox and Grid Properties

Flex Container (display: flex): Turns an element into a flex container, enabling flexible layouts.

.container {
  display: flex;
}
Enter fullscreen mode Exit fullscreen mode

Grid Container (display: grid): Defines an element as a grid container, useful for creating grid-based layouts.

.container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
}
Enter fullscreen mode Exit fullscreen mode

10. Animation and Transition Properties

Animation (@keyframes): Defines keyframes for animations, specifying how an element changes over time.

@keyframes slide-in {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(0);
  }
}
Enter fullscreen mode Exit fullscreen mode

Transition (transition): Specifies how CSS properties change over time during transitions.

button {
  transition: background-color 0.3s ease;
}
Enter fullscreen mode Exit fullscreen mode

Conclusion

CSS is an indispensable tool for web developers to craft visually appealing and responsive websites. Understanding the broad range of CSS properties and their applications is crucial for creating web designs that align with your vision. This guide has provided an overview of essential CSS properties, but there is much more to explore. Continue to experiment and push the boundaries of CSS to create captivating and functional web designs.

Top comments (0)