CSS arrows created with transform rotate: 3 demos
Creating arrows based on CSS
The arrows in websites can be required for different purposes including showing the next, previous pages or sections, checkout steps etc. or many other real world stuff where arrows are used.
In this tutorial, I am going to share with you creating the arrows based on pure CSS.
The CSS arrows are using the transform property with rotate values along with other properties.
A demo of left and right arrows
In this demo, the arrows CSS are created for the left and right directions. In the markup section, links are used that are assigned CSS classes, have a look:
See online demo and code
The CSS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
* { box-sizing: border-box; } body { text-align: center; padding-top: 100px; width: 400px; position: relative; margin: 0 auto; } .demo-arrow-cls { display: inline-block; position: absolute; width: 60px; height: 60px; background: transparent; text-indent: -9999px; border-top: 1px solid #408080; border-left: 1px solid #72B8B8; transition: all .3s ease-in-out; text-decoration: none; color: transparent; } .demo-arrow-cls:hover { border-color: #800000; border-width: 2px; } .demo-arrow-cls:before { display: block; height: 200%; width: 200%; margin-left: -50%; margin-top: -50%; content: ""; transform: rotate(45deg); } .demo-arrow-cls.back { transform: rotate(-45deg); left: 0; } .demo-arrow-cls.forward { transform: rotate(140deg); right: 0; } |
The markup:
1 2 3 |
<a href="#" class="demo-arrow-cls back">« Back</a> <a href="#" class="demo-arrow-cls forward">Forward » </a> |
So how is it done?
The demo-arrow-cls CSS class defines a few properties including the transition that uses ease-in-out value for the arrow. There, the border-top and border-left define the color and lining of the arrow. You may use dashed, dotted lining as well (see next example).
The demo-arrow-cls.back class is assigned the CSS transform property with rotate at 45 degrees. The demo-arrow-cls.forward is given the transform property as well with 140 degrees in rotate value.
Another demo with a different arrow style
In this demo, a few properties are changed like border colors. The top and left borders are given the dashed lining with 3px. The transition is linear unlike ease-in-out used in above example. The direction is set opposite to the above example:
See online demo and code
The CSS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
* { box-sizing: border-box; } body { text-align: center; padding-top: 100px; width: 400px; position: relative; margin: 0 auto; } .demo-arrow-cls { display: inline-block; position: absolute; width: 60px; height: 60px; background: transparent; text-indent: -9999px; border-bottom: 3px dashed #408080; border-right: 3px dashed #72B8B8; transition: all .3s linear; text-decoration: none; color: transparent; } .demo-arrow-cls:hover { border-color: #FF8000; border-width: 3px; } .demo-arrow-cls:before { display: block; height: 200%; width: 200%; margin-left: -50%; margin-top: -50%; content: ""; transform: rotate(45deg); } .demo-arrow-cls.back { transform: rotate(-45deg); left: 0; } .demo-arrow-cls.forward { transform: rotate(140deg); right: 0; } |
In the demo, instead of top and left borders the bottom and right borders are used.
A demo of up direction arrow
In this example, an up arrow is created by changing the angle to 135 degrees instead of 45 degrees. See the live demo by clicking the links below:
See online demo and code
The CSS in this example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
* { box-sizing: border-box; } body { text-align: center; padding-top: 100px; width: 400px; position: relative; margin: 0 auto; } .demo-arrow-cls { display: inline-block; position: absolute; width: 60px; height: 60px; background: transparent; text-indent: -9999px; border-bottom: 5px dotted #FF8000; border-right: 5px dotted #FF8000; transition: all .2s ease; text-decoration: none; color: transparent; } .demo-arrow-cls:hover { border-color: #804040; border-width: 4px; } .demo-arrow-cls:before { display: block; height: 200%; width: 200%; margin-left: -50%; margin-top: -50%; content: ""; transform: rotate(45deg); } .demo-arrow-cls.up { transform: rotate(-135deg); left: 0; } |
Credit: bronsrobin