9 awesome CSS border tricks that will critically help you with styling
Tags: html, css, tutorial, beginners
Published: 2020-05-06 15:15:18

This article was originally published at: https://www.blog.duomly.com/css-border-with-examples-tutorial/

---

###Introduction to CSS border###

Hi guys, today we will talk about… BORDERS!

The CSS border is something that you will most probably use almost every day, if you're front-end developer, of course.

I've found a few useful (some more, some less, some just funny) tips and tricks that you can use in your project.

Let's start!

If you prefer video here is the youtube version.
{% youtube 0EGhxluwMAk %}

###1. Animated CSS border###

What to do when we would like to make our item more visible?

Let's animate it!

We can animate our borders, even without changing the size of the element, and it's very easy.

To do that, we just need to create a custom keyframe for the animation and use it in the animation param inside our element's CSS code.

Let's take a look at the example.

{% codepen https://codepen.io/duomly/pen/OJyzzpN %}

###2. CSS border images###

Have you ever imagine donuts around your element?

Now you can add them by pure CSS without too much effort.

To do it, you need to use the border-image attribute in your element's CSS code.


Let's take a look at the example.

{% codepen https://codepen.io/duomly/pen/PoPEEVp %}

###3. Snake style CSS border###

What if we need a double-color ultra visible border?

We can wear a snake uniform and color it however we want.

Let's try the code from the example.

{% codepen https://codepen.io/duomly/pen/LYpeded %}

###4. Stairs style CSS border###

Have you ever tried to add 3d style border around your div?

Adding some multi-color depth into our element is very easy. We simply need a few box-shadows in the CSS.

Let's test our example!

{% codepen https://codepen.io/duomly/pen/MWarGeO %}

###5. Only shadow CSS border###
Sometimes we need to add a border to the ready design, but adding a few more pixels would be a bit problematic. It could change the position of the elements.

Not anymore!

Now we can use box-shadow around our element as a border, take a look in the code.

{% codepen https://codepen.io/duomly/pen/MWarGEQ %}

###6. CSS border with shadow and outline###
We can achieve a similar effect to the snake-style in a few ways.
Next, one of them is mixing box-shadow and outline param in the CSS of our element.

Let's take a look.

{% codepen https://codepen.io/duomly/pen/pojpVOL %}

###7. Few shadows and outline###

We can even create a few colors and elements in our border.

To do that, we need to mix box-shadows and outline, like in the example below.

Let's experiments with that a bit.

{% codepen https://codepen.io/duomly/pen/gOaozEg %}

###8. Double CSS border with box-shadow###

We can also mix just a border with some box-shadow and outline.

That will create a lovely effect of a line with spikes, like in the example below.

Let's check the code!

Codepen:

{% codepen https://codepen.io/duomly/pen/YzyYLmq %}

###9. Multi-color CSS border###

And what if we would like to color our borders a bit more than in the previous examples?

We can even set up every wall of the element in a different color.

To achieve that, we will need some custom background with the gradient inside.

Take a look at the example below.

{% codepen https://codepen.io/duomly/pen/ExVoRjq %}

###Conclusion###

Ok, it was the last one of the ideas for now.

I hope you like them, and those few will be useful for you.

Feel free to test them, experiment, and show in comments what ideas you found to make borders different.

Congratulations, you are the borders expert now!

<a href="https://www.duomly.com">![Programming courses online](https://dev-to-uploads.s3.amazonaws.com/i/oqwnv2xnygy3o544zhnf.jpg)</a>

Thanks for Reading,
Radek from Duomly