15 amazing CSS tips and tricks you should know
Tags: css, html, webdev, beginners
Published: 2021-04-26 09:15:06

---
canonical_url: https://www.blog.duomly.com/12-css-tips-and-tricks-which-help-you-to-create-an-amazing-websites/
---

This article was originally published at: https://www.blog.duomly.com/12-css-tips-and-tricks-which-help-you-to-create-an-amazing-websites/

CSS is Cascading Style Sheets and is used to describe how HTML elements should display. It’s one of the first technology learned by soon to be front-end and web developers, and it’s an absolute have to know basic.

Although it seems CSS can’t do a lot besides giving our HTML colors, positions, etc., but it can also let us create animations and bring some life to our apps and websites. Probably now many of us take care of mastering CSS and learning it so deeply, but it’s totally worth to know some useful tips and tricks which may help you to create stunning websites!

Are you ready to check out 20 tips and tricks which can change your CSS usage from now?

Let’s start!

{% youtube JOp6GaA-pcY %}

<h3>1. Vertical align with flex</h3>
Since the Flexible Box Layout Model appeared, it became very popular, because it makes positioning and aligning elements easier. Using flex (Flexible Box Layout Model sub-property) made vertical alignment fast, nice, and easy before we had to do it a little bit around in many cases. Let’s take a look at code example for vertical positioning with flex because it allows doing a lot with alignment.

{% codepen https://codepen.io/annafromduomly/pen/eYYgNQb default-tab=css,result %}

As you can see in the code above, we used display: flex and align-items: center,
justify-content: center to ensure our child element will be exactly in the center of the parent element.

Easy, right?

<h3>2. Blend modes</h3>
We can do lots of cool stuff in CSS right now, and one of them is a blend mode. There are two properties for blend modes: mix-blend-mode, which defines blending between element and element behind it, and background-blend-mode, which defines blending between the background image and background color of the element. Let’s take a look at how it works:

{% codepen https://codepen.io/annafromduomly/pen/NWWdOPN default-tab=css,result %}

In the code above, we set image and header with text. The text is an element that is blended with the image. We used overlay value, but there are 15 other values that can be used. Now, let’s check the background-blend-mode code example:

{% codepen https://codepen.io/annafromduomly/pen/JjjEmyx default-tab=css,result %}

In this case, we can see how the background image got blended with the color. The first image is before blending, and the second one is after blending.

Isn’t it amazing what we can do with CSS?

<h3>3. Parallax scrolling</h3>
Parallax is a very common trend in modern web design. It’s about scrolling background content at a different speed than foreground content when we scroll the page. Let’s see how this magic can be done using CSS:

{% codepen https://codepen.io/annafromduomly/pen/oNNBQeL default-tab=css,result %}

In the example, you can see how our text and background image are moving differently. We used transformZ, to fasten one element and slow another one. Looks good, right?

<h3>4. Shape outside</h3>
There is another great feature that came with CSS, and it’s not very common. It’s shape-outside property. It decides how content will wrap around the floated element. Let’s take a look at how it works:

{% codepen https://codepen.io/annafromduomly/pen/MWWJZyw default-tab=css,result %}

In the code example, you can see that the text overflows the circle. We set the value of shape-outside to circle 50%, but it’s also possible to set an image, triangle, square, etc. Check it out and play with it!

<h3>5. Truncate the string</h3>
I hate when my text doesn’t suit inside the div, and it goes out anesthetically. In Javascript, there are a few ways how we can manage it but, did you know that it’s possible to cut the text in CSS as well? Let’s check it out:

{% codepen https://codepen.io/annafromduomly/pen/MWWJZQe default-tab=css,result %}

Above, you can see how CSS can cut the text and finish it with …. I used overflow: hidden, white-space: nowrap, and finally to got three dots, I used text-overflow: ellipsis.

<h3>6. Clip path</h3>
Sometimes the designer went a little bit more creative, and now you have to put an image in a specific shape, like the triangle or other. For this, you could use clip-path property! Let’s take a quick look at how it works:

{% codepen https://codepen.io/annafromduomly/pen/KKKaJyX default-tab=css,result %}

In the example above, I created a circle, eclipse, and a custom polygon shape.

<h3>7. Full height and full width</h3>
If we would like to set our app or website adjusted to the viewport, vh and vw units make it much easier. vh means it’s 100% of the viewport height, and vw means the 100% width of the viewport. Let’s check how it works in a real example:

{% codepen https://codepen.io/annafromduomly/pen/YzzxPNG default-tab=css,result %}

In the example above, I set the blue-box element to 50vw and 50vh, which means it should have a 50% of the viewport width and 50% of the viewport height, and if you resize the viewport you may notice how it adjusts.

Cool, right?

<h3>8. Image filters</h3>
Playing with images may bring lots of amazing effects for the layout and help to create stunning results. CSS allows using lots of filters on the images to help developers play with the graphic without changing it in Photoshop. Let’s take a look at the filters we may use:

{% codepen https://codepen.io/annafromduomly/pen/PooKweE default-tab=css,result %}

In the example above, you can see seven different filters used in the same image.

<h3>9. CSS animations</h3>
Animations can grab a user’s attention on the website, and this is why it’s used in web design so often. Creating it in CSS makes things much easier, let’s take a closer look at an example animation in CSS:

{% codepen https://codepen.io/annafromduomly/pen/abbyzeZ default-tab=css,result %}

In the code above, I’ve created a small dot that changes the position and opacity every 25% until it will get 100% and then starts once again. It’s also possible to change colors and other properties of the elements.

<h3>10. Element rotation</h3>
Another type of animation which can be done in CSS is rotation, it’s a little bit more dynamic, and it’s great to add some life to loader element, logo or image in the gallery. Let’s check what we can do with rotation:

{% codepen https://codepen.io/annafromduomly/pen/GRRvJjB default-tab=css,result %}

In the example, we can see a cat rotating four times during one cycle of the animation.

<h3>11. Mask</h3>
If you ever did graphic design, you probably know how helpful are masks. It’s also possible to use image masks in CSS. Let’s try to make a mask for an image:

{% codepen https://codepen.io/annafromduomly/pen/qBBXdxp default-tab=css,result %}

In the example above, I’ve created a circle gradient mask, but you can also use an SVG graphic as a mask, by adding the URL to the file.

<h3>12. Zoom on hover</h3>
When you create an image gallery, you want to mark somehow the hovered image very often. The great idea is to add zoom on hover to accentuate the hovered photo. Let’s take a look at how it works:

{% codepen https://codepen.io/annafromduomly/pen/qBBXOmL default-tab=css,result %}

In the example above, I’ve created a small images gallery and add scale property on hover to make the hovered image bigger than the others. Easy right?

### 13. Frosted glass CSS

Frosted glass is one of the most trendy things in CSS & website UI world last time, but how can you build it? It's easy, and now I'll show you how!

Let's take a look at the example, and build frosted glass with us.

{% codepen https://codepen.io/annafromduomly/pen/oNByVMe %}

### 14. CSS only carousel

Do you remember times when building carousel needed skills like jQuery or javascript and much work?
I do, but did you know, now you can build a carousel with CSS only?

It's possible, and now, I will show you how to do that easily.

{% codepen https://codepen.io/annafromduomly/pen/rNjKRRL %}

### 15. How to use CSS variables

You do not need sass or less to specify variables anymore!

You can use this powerful feature in pure CSS now, specify, for example, color, and use it in many places without copying its hex code.

Let's take a look at the example, and you will learn how.

{% codepen https://codepen.io/annafromduomly/pen/GRrGLRw %}

<h3>Conclusion</h3>
We want to create stunning websites and apps, but sometimes we think it takes lots of effort and time to create an animation or a mask on the image. As I showed you in this article, sometimes it’s much more comfortable than changing the imaged in a graphics program.

I hope you will find these tips and tricks helpful and useful for your future coding. If you know any interesting tricks in CSS, share your favorites with me in comments or social media, I really would like to know.

Have a nice coding!

<a href="https://www.duomly.com">
![Duomly - Programming online courses](https://thepracticaldev.s3.amazonaws.com/i/gqrqor91ylayg19e2qi4.png)
</a>