CSS in 2024

CSS has evolved significantly. Modern features like CSS Grid, Flexbox, and custom properties make layout and styling more powerful than ever.

CSS Grid Layout

Grid lets you create complex two-dimensional layouts with ease:


.container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.item {
    background: #f0f0f0;
    padding: 1rem;
    border-radius: 8px;
}

CSS Custom Properties

Variables in CSS make theming straightforward:


:root {
    --primary-color: #007bff;
    --font-size-base: 16px;
}

body {
    color: var(--primary-color);
    font-size: var(--font-size-base);
}

Tips for Better CSS

  • Use rem units for responsive typography
  • Prefer Flexbox for one-dimensional layouts
  • Use Grid for two-dimensional layouts
  • Keep specificity low with BEM naming conventions