Hello fellow developers! We are excited to announce some fantastic updates and new features in CSS that will enhance your web development experience. Let's dive right in! πͺ
1οΈβ£ Custom Properties (Variables) π¨
CSS now supports custom properties, allowing you to define your own variables and reuse them throughout your stylesheets. This helps in creating more flexible and maintainable code. Here's an example:
:root {
--primary-color: #ff0000;
}
.button {
background-color: var(--primary-color);
}
2οΈβ£ Grid Layout π
CSS Grid Layout provides a powerful two-dimensional grid system for creating complex layouts. It allows you to easily divide your page into regions and position elements with precision. Check out this snippet:
.container {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 10px;
}
3οΈβ£ Flexbox Enhancements π€©
Flexbox has received some exciting enhancements to make it even more versatile. Now, you can use gap property to add spacing between flex items and use gap and row-gap in flex containers. Take a look:
.container {
display: flex;
gap: 20px;
}
4οΈβ£ Scroll Snapping π
Scroll snapping enables smooth scrolling behavior, allowing you to control where the scroll position stops within a container. It's great for creating engaging scrolling experiences. Use the following code to enable scroll snapping:
.container {
scroll-snap-type: y mandatory;
}
5οΈβ£ Dark Mode Support π
CSS now has built-in support for dark mode with the prefers-color-scheme media query. You can easily adapt your styles based on the user's preferred color scheme. Check it out:
@media (prefers-color-scheme: dark) {
body {
background-color: #111111;
color: #ffffff;
}
}
These are just a few highlights from the latest CSS updates and new features. We hope you find them useful in your web development projects. Let your creativity flow and enjoy building beautiful websites! π
Happy coding! π»π¨π
~By Danish
Top comments (3)
I think its also worth noting for variable they can be local ones with in a single ruleset like:
CSS Variables have been around since 2017 though, they are not new CSS properties.
some new css properties