sodcalculator

10 Tech How-To

CSS Features Ready to Use in Projects

Guide 10-28323 · Updated · Step by step

Modern CSS now includes stable, widely supported features like Flexbox, Grid, custom properties, and container queries that you can use in production today. This article outlines which CSS features are safe to adopt, how they work, and what to watch out for, so you can build with confidence.

Background: The Evolution of CSS

CSS has come a long way from simple styling of text and boxes. In the early 2010s, developers relied on floats, tables, and JavaScript libraries to create layouts. The introduction of Flexbox (2012) and Grid (2017) changed that, offering native, robust layout systems. Since then, the CSS Working Group has steadily added features like custom properties, logical properties, and container queries, all designed to make styling more intuitive and performant. Today, the “baseline” of browser support is broader than ever, and many modern features are ready for real projects without fallbacks.

Core Layout: Flexbox and Grid

Flexbox and CSS Grid are the two pillars of modern layout. Flexbox is ideal for one-dimensional layouts—either a row or a column—and is perfect for aligning items, distributing space, and handling dynamic sizes. Grid, on the other hand, handles two-dimensional layouts with explicit rows and columns, making it the go-to for entire page structures and complex components.

  • Flexbox basics: Use display: flex on a container, then control alignment with justify-content and align-items. It shines for navbars, card rows, and centering content.
  • Grid essentials: Define a grid with display: grid and grid-template-columns. You can create responsive layouts with repeat(auto-fit, minmax(200px, 1fr)) without media queries.
  • Browser support: Both are supported in all current browsers (Chrome, Firefox, Safari, Edge) for over five years. You can safely use them without prefixes.

When to choose which? If you only need to align items in one direction, use Flexbox. If you need to place items in both rows and columns, use Grid. They also work together: use Grid for the page skeleton and Flexbox inside components.

Custom Properties (CSS Variables)

Custom properties, often called CSS variables, let you store values like colors, spacing, or font sizes in one place and reuse them throughout your stylesheet. This drastically improves maintainability and enables theming.

Define them on a selector with --name: value; and use them with var(--name). For example:

:root {
  --primary-color: #3498db;
  --spacing: 8px;
}
.button {
  background-color: var(--primary-color);
  padding: var(--spacing);
}

They are supported in all modern browsers and can be updated at runtime with JavaScript, making them perfect for dark mode or user-customizable themes. Unlike preprocessor variables (like Sass), they work in the browser and cascade, meaning you can redefine them inside media queries or classes.

Container Queries: Responsive Components

Container queries are one of the most exciting additions in recent years. They allow you to style an element based on the size of its parent container, not the viewport. This is a game-changer for reusable components that need to adapt to different contexts.

To use them, define a container with container-type: inline-size; on a parent, then write queries like @container (min-width: 400px) { ... } inside the child. This lets a card component look different when placed in a narrow sidebar versus a wide main area.

As of 2023, container queries are supported in all major browsers (Chrome 105+, Firefox 110+, Safari 16+). They work well for component libraries and design systems, reducing the need for complex media query hacks.

Modern Selectors and Pseudo-Classes

CSS has evolved beyond simple classes and IDs. Newer selectors like :is(), :where(), :has(), and :not() simplify writing complex rules.

  • :is() and :where() let you group selectors to reduce repetition. For example, :is(h1, h2, h3) { margin-top: 0; }. The difference: :where() has zero specificity, which is useful for base styles.
  • :has() is often called the “parent selector” because it lets you style a parent based on its children. For instance, figure:has(img) { border: 1px solid; } styles a figure only if it contains an image. It is supported in all major browsers since late 2023.
  • :not() has been around longer and now accepts a list of selectors, e.g., input:not([type="text"], [type="email"]).

These selectors reduce the need for extra classes and make stylesheets cleaner and more maintainable.

How to Choose What to Use

With so many features, how do you decide which are “ready”? A practical approach is to check browser support using a site like Can I Use, but you can also rely on the Baseline status from the Web Platform Dashboard. Features marked as “Baseline 2023” or earlier are safe for most projects.

Consider your audience: if you must support older browsers (like Internet Explorer), many modern features are off-limits without fallbacks. However, IE is largely obsolete, and most current projects target evergreen browsers. For enterprise or public-sector sites with strict requirements, you might need to provide fallbacks for features like :has() or container queries.

Here is a quick checklist:

  • Check if the feature works in all browsers you support.
  • Use graceful degradation: provide a fallback layout for older browsers.
  • Test on real devices, not just desktop.
  • Use feature queries (@supports) to apply progressive enhancement.

Common Problems and Mistakes

Even with modern CSS, developers hit common pitfalls. One is mixing units incorrectly, like using fr units in Flexbox (they don’t work; use flex). Another is forgetting that custom properties are case-sensitive, so --Color and --color are different.

With Grid, a frequent mistake is using grid-template-areas without defining all areas, causing the layout to break. Also, remember that auto-fit and auto-fill behave differently: auto-fit collapses empty tracks, while auto-fill keeps them. This can cause unexpected gaps.

For container queries, a common issue is forgetting to set container-type on the parent, so the query never fires. Also, container queries can’t be used on the container itself—only on its descendants.

Frequently Asked Questions

Can I use CSS Grid and Flexbox together?

Yes, absolutely. They are complementary. Use Grid for the overall page layout (rows and columns) and Flexbox for aligning content within individual grid cells or for one-dimensional lists.

What is the difference between :is() and :where()?

Both group selectors, but :is() takes the specificity of its most specific argument, while :where() always has zero specificity. This means :where() is safer for base styles that you want to override easily.

Are container queries ready for production?

Yes, as of 2023, they are supported in all evergreen browsers. However, if you need to support older versions (like Chrome 104 or earlier), you should provide a fallback layout using media queries.

Do I still need a preprocessor like Sass?

Not necessarily. Modern CSS with custom properties, nesting (now native in many browsers), and other features covers many use cases. However, preprocessors still offer mixins, functions, and file splitting, which can be handy for large projects.

How do I check if a CSS feature is supported?

Use Can I Use or the MDN Browser Compatibility Data. You can also use @supports in your CSS to conditionally apply styles only if a feature is supported.

What is the best way to handle older browsers?

Use progressive enhancement: start with a basic layout that works everywhere, then enhance with modern features using @supports or feature detection. Avoid relying on a feature for critical functionality without a fallback.

Conclusion

Modern CSS offers a rich set of features that are ready to use in your projects today. By understanding what each feature does, checking browser support, and applying progressive enhancement, you can build robust, maintainable, and future-proof stylesheets. Start with Flexbox, Grid, and custom properties, then gradually adopt newer features like container queries and :has() as your audience allows.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →