CSS (Cascading Style Sheets) is a powerful language that allows you to control the appearance of your web pages. With just a few lines of CSS, you can change the font, color, size, and layout of your elements.

In this article, we’ll go over 12 essential CSS codes that you need to know. These codes will help you create beautiful and professional-looking web pages.
1. The Box Model
The box model is a fundamental concept in CSS. It defines the size and shape of elements on your page.
The box model consists of four parts:
- Content: The actual content of the element, such as text or images.
- Padding: The space between the content and the border.
- Border: The line that surrounds the element.
- Margin: The space between the border and the other elements on the page.
2. Positioning
Positioning allows you to control where elements are placed on your page. There are three main types of positioning:
- Static: Elements are placed in their normal flow in the document.
- Relative: Elements are positioned relative to their normal position.
- Absolute: Elements are positioned absolutely on the page, regardless of the position of other elements.
3. Floats
Floats allow you to wrap text around elements. This is useful for creating sidebars, images, and other elements that need to flow around text.
4. Flexbox
Flexbox is a powerful new layout system that allows you to create complex layouts with ease. Flexbox is based on the concept of flexible boxes, which can be resized and rearranged to fit the available space.
5. Grid
The grid layout system allows you to create complex layouts using a grid system. Grid is similar to flexbox, but it is more powerful and flexible.
6. Transitions
Transitions allow you to animate changes to elements on your page. This is useful for creating effects such as fading in and out elements, or resizing elements.
7. Animations
Animations allow you to create more complex animations than transitions. With animations, you can control the duration, timing, and easing of the animation.
8. Media Queries
Media queries allow you to change the appearance of your page depending on the screen size, orientation, or other factors. This is useful for creating responsive designs that look good on all devices.
9. Variables
Variables allow you to store values that can be reused throughout your CSS code. This can help you keep your code organized and DRY (Don’t Repeat Yourself).
10. Functions
Functions allow you to perform calculations and other operations in your CSS code. This can be useful for creating more dynamic and flexible layouts.
11. Selectors
Selectors are used to select elements in your HTML code. There are many different types of selectors, including:
-
Element selectors: Select elements based on their tag name, such as
or
.- Class selectors: Select elements based on their class attribute, such as
.my-class
.- ID selectors: Select elements based on their ID attribute, such as
#my-id
.- Universal selector: Selects all elements on the page, regardless of their type.
12. Shorthand Properties
Shorthand properties allow you to set multiple properties with a single line of code. For example, the
margin
property can be used to set the margin for all four sides of an element.Conclusion
These are just a few of the essential CSS codes that you need to know. By mastering these codes, you’ll be able to create beautiful and professional-looking web pages.
Additional Resources
- Class selectors: Select elements based on their class attribute, such as