Skip to content

The Ultimate CSS Cheat Sheet – Boost Your Styling Skills!

CSS is an essential part of modern web design, allowing developers to create visually stunning and responsive websites. Whether you're a beginner or a

2 min readCSS

1. CSS Functions

CSS functions are used to dynamically compute property values, making styling more flexible and scalable.

attr()

  • Retrieves an attribute value from an HTML element and inserts it into the stylesheet.
  • Example:
a::after {
  content: " (" attr(href) ")";
}
  • Useful for adding dynamic content from HTML attributes.

calc()

  • Performs calculations directly in CSS.
  • Example:
width: calc(100% - 50px);
  • Helps create responsive designs with precise measurements.

clamp()

  • Defines a value between a minimum, preferred, and maximum range.
  • Example:
font-size: clamp(1rem, 2vw, 3rem);
  • Ensures text remains readable across different screen sizes.

max() & min()

  • Returns the maximum or minimum value among given values.
  • Example:
width: max(300px, 50%);
  • Useful for setting adaptive layouts.

var()

  • Used to declare and use CSS variables.
  • Example:
:root {
  --primary-color: #ff6600;
}
body {
  background-color: var(--primary-color);
}
  • Enables theming and reuse of values.

2. CSS Color Manipulation

CSS provides several functions to manipulate colors dynamically.

hsl()

  • Defines colors using Hue, Saturation, and Lightness.
  • Example:
color: hsl(200, 50%, 50%);
  • Makes color adjustments more intuitive.

rgba()

  • Defines colors with an alpha (transparency) value.
  • Example:
background-color: rgba(255, 0, 0, 0.5);
  • Allows fine-tuned opacity control.

invert()

  • Inverts colors for a negative effect.
  • Example:
filter: invert(100%);
  • Useful for dark mode toggles.

saturate()

  • Adjusts the color saturation.
  • Example:
filter: saturate(200%);
  • Enhances or dulls colors dynamically.

contrast()

  • Adjusts the contrast of an element.
  • Example:
filter: contrast(150%);
  • Improves readability of text over images.

3. CSS Filters & Effects

These properties help create visual effects without using images.

blur()

  • Applies a blur effect to an element.
  • Example:
filter: blur(5px);
  • Useful for background overlays.

brightness()

  • Adjusts the brightness of an element.
  • Example:
filter: brightness(120%);
  • Enhances visibility under different conditions.

grayscale()

  • Converts an element to grayscale.
  • Example:
filter: grayscale(100%);
  • Often used for hover effects or image styling.

opacity()

  • Controls the transparency of an element.
  • Example:
opacity: 0.5;
  • Ideal for creating overlay effects.

4. CSS Transformations

CSS transform functions allow elements to be rotated, scaled, or moved.

rotate()

  • Rotates an element by a specified angle.
  • Example:
transform: rotate(45deg);

scale()

  • Resizes an element.
  • Example:
transform: scale(1.5);

translate()

  • Moves an element along the X or Y axis.
  • Example:
transform: translate(50px, 100px);

skew()

  • Skews an element.
  • Example:
transform: skew(10deg, 5deg);

perspective()

  • Creates a 3D perspective effect.
  • Example:
perspective: 500px;

matrix()

  • Combines multiple transformations in one.
  • Example:
transform: matrix(1, 0.5, -0.5, 1, 50, 100);

5. CSS Transitions & Animations

Transitions and animations add smooth effects to web elements.

cubic-bezier()

  • Defines custom easing for transitions.
  • Example:
transition-timing-function: cubic-bezier(0.25, 1, 0.5, 1);

steps()

  • Creates a stepped animation effect.
  • Example:
animation-timing-function: steps(5, end);

url()

  • Defines a background image.
  • Example:
background-image: url('image.jpg');

FAQs

1. How do CSS filters work?

CSS filters apply effects like blur, brightness, and contrast to elements. They are commonly used on images but can be applied to any HTML element.

2. What is the difference between rgba() and hsl()?

rgba() defines colors using red, green, blue, and alpha (opacity). hsl() uses hue, saturation, and lightness, making it easier to create color variations.

3. When should I use calc() in CSS?

Use calc() when you need to dynamically calculate CSS values, such as setting flexible margins or padding that adjusts based on viewport size.

Build work

Need this built properly?

I build the web and mobile products these notes come out of, in React, React Native and Node. A first conversation costs nothing and often ends with a smaller scope than you expected.