Skip to content

Latest commit

 

History

History
37 lines (28 loc) · 967 Bytes

create-a-custom-emoji-cursor.md

File metadata and controls

37 lines (28 loc) · 967 Bytes
title category date topics
Create a custom emoji cursor
Trick
2021-04-12 12:26:00 +7
CSS

There are two popular ways to create a custom cursor:

  • Using an image
  • Creating a canvas element and generate the base 64 image

Both approaches finally change the cursor by setting the image's URL to the cursor property:

.custom-cursor {
    cursor: url(/path/to/image.png), auto;
}

/* Or */
.custom-cursor {
    cursor: url('data:image/png;base64,...'), auto;
}

To create a custom emoji cursor, we can use an inline SVG element which displays the emoji at the center as following:

.custom-cursor {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewport="0 0 48 48" style="fill:black;font-size:24px"><text y="50%">🚀</text></svg>')
            16 0, auto;
}

Demo

:demo[]{title="Create a custom emoji cursor" url="/demo/create-a-custom-emoji-cursor/index.html"}