DEV Community

V Sai Harsha
V Sai Harsha

Posted on • Updated on

CSS Cheatsheet

CSS is a fundamental technology for designing and styling web content. This cheat sheet provides a quick reference to commonly used CSS properties, selectors, and techniques. Whether you're a beginner or an experienced developer, this cheat sheet will help you enhance your web design skills.

Table of Contents

  1. Selectors
  2. Box Model
  3. Positioning
  4. Typography
  5. Colors
  6. Backgrounds
  7. Borders
  8. Transforms
  9. Transitions
  10. Flexbox
  11. Grid Layout

Selectors

Element Selector

p {
  /* Selects all <p> elements */
}
Enter fullscreen mode Exit fullscreen mode

Class Selector

.button {
  /* Selects all elements with class="button" */
}
Enter fullscreen mode Exit fullscreen mode

ID Selector

#header {
  /* Selects the element with id="header" */
}
Enter fullscreen mode Exit fullscreen mode

Descendant Selector

article p {
  /* Selects all <p> elements inside <article> elements */
}
Enter fullscreen mode Exit fullscreen mode

Pseudo-class Selector

a:hover {
  /* Selects links on hover */
}
Enter fullscreen mode Exit fullscreen mode

Universal Selector

* {
  /* Selects all elements */
}
Enter fullscreen mode Exit fullscreen mode

Box Model

Width and Height

.box {
  width: 200px;
  height: 100px;
}
Enter fullscreen mode Exit fullscreen mode

Margin

.box {
  margin: 10px;
}
Enter fullscreen mode Exit fullscreen mode

Padding

.box {
  padding: 10px;
}
Enter fullscreen mode Exit fullscreen mode

Border

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

Box Sizing

.box {
  box-sizing: border-box;
}
Enter fullscreen mode Exit fullscreen mode

Positioning

Position

.element {
  position: relative;
  /* Other values: absolute, fixed, static */
}
Enter fullscreen mode Exit fullscreen mode

Float

.image {
  float: left;
  /* Other values: right */
}
Enter fullscreen mode Exit fullscreen mode

Flexbox

.container {
  display: flex;
  justify-content: center;
  align-items: center;
}
Enter fullscreen mode Exit fullscreen mode

Grid Layout

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

Typography

Font Family

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

Font Size

h1 {
  font-size: 24px;
}
Enter fullscreen mode Exit fullscreen mode

Font Weight

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

Text Alignment

p {
  text-align: center;
  /* Other values: left, right, justify */
}
Enter fullscreen mode Exit fullscreen mode

Colors

Color Property

.element {
  color: #333;
}
Enter fullscreen mode Exit fullscreen mode

Background Color

.container {
  background-color: #f0f0f0;
}
Enter fullscreen mode Exit fullscreen mode

Transparency

.overlay {
  background-color: rgba(0, 0, 0, 0.5);
}
Enter fullscreen mode Exit fullscreen mode

Backgrounds

Background Image

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

Background Repeat

.tile {
  background-repeat: no-repeat;
  background-size: 100% 100%;
}
Enter fullscreen mode Exit fullscreen mode

Borders

Border Radius

.button {
  border-radius: 5px;
}
Enter fullscreen mode Exit fullscreen mode

Border Color

.input {
  border: 1px solid #ccc;
}
Enter fullscreen mode Exit fullscreen mode

Transforms

Scale

.box {
  transform: scale(1.2);
}
Enter fullscreen mode Exit fullscreen mode

Rotate

.card {
  transform: rotate(45deg);
}
Enter fullscreen mode Exit fullscreen mode

Transitions

Transition Property

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

Hover Effect

.button:hover {
  background-color: #007bff;
  color: #fff;
}
Enter fullscreen mode Exit fullscreen mode

Flexbox

Flex Container

.container {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}
Enter fullscreen mode Exit fullscreen mode

Grid Layout

Grid Container

.grid-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
Enter fullscreen mode Exit fullscreen mode

This cheatsheet provides a concise reference to common CSS properties and techniques. Use it as a quick guide while working on your web projects to create beautiful and responsive designs.

Estimated Reading Time: 5 minutes

Top comments (0)