everything about web

A Comprehensive Guide to the World of Web Design & Development:

CSS, HTML, Performance, Web Design, and all Aspects of Front-End Development

Advertisements

CSS Shadow Art: How to Craft a Pixelated Masterpiece

  1. What is Pixelated Art
  2. How does CSS box-shadow Work
  3. How to Create a Pixelated Art from CSS Shadow
  4. Animate the pixel

What is Pixelated Art

Pixelated art, also known as pixel art, is a digital art form that utilizes small, square pixels to create an image. It rose to prominence in the 1980s and 1990s when video games were limited in graphical capabilities and relied on blocky, simplistic graphics.

Despite the tiny size of pixels today, pixelated art retains its unique aesthetic and continues to evoke a sense of nostalgia and retro vibe in the artwork. In this tutorial, we will guide you through the process and the concept of creating pixel art using CSS box-shadow, so let’s jump right in!

How does CSS box-shadow Work

Before we begin the step-by-step guide on creating pixel art, Firstly, it is essential to understand how CSS box-shadow works.

The box-shadow property takes several attribute values to control the appearance of the shadow:

box-shadow: [inset] [offset-x] [offset-y] [blur-radius] [spread-radius] [color];

Attributes in a glace:

AttributeDescriptionValue Type
insetOptional value that changes the shadow to an inner shadowIf not specified, default to drop shadow
offset-xHorizontal offset of the shadow from the elementunit length (eg: px, em…)
offset-yVertical offset of the shadow from the elementunit length (eg: px, em…)
blur-radiusAmount of blur radiusIf not specified, default will set to 0 (sharp edge)
spread-radiusAmount of the shadow extends beyond the elementIf not specified, default will set to 0 (shadow will be the same size as the element)
colorColor of the shadowIf not specified, it defaults to currentcolor.

Examples:

.uiPencil_shadow{
  width: 100px;
  height: 25px;
  background-color: #d24507;
  box-shadow: 5px 5px 2px 2px #72d596;
}
.uiPencil_shadow{
  width: 100px;
  height: 25px;
  background-color: #d24507;
  box-shadow: inset 5px 5px 2px 2px #72d596;
}
.uiPencil_shadow{
  width: 100px;
  height: 25px;
  background-color: #d24507;
  box-shadow: 5px 5px #72d596;
}

How to Create a Pixelated Art from CSS Shadow

Step 1:

To create pixel art with CSS shadows, first, create a container element to place your artwork. This can be any HTML element, such as a <div> , <span> or <p>

<div class="uiPencil_pixel" style="width:1px; height: 1px;"></div>

Step 2:

Next, add box-shadow properties to the .uiPencil_pixel container to create the appearance of pixels.

To create a single pixel, set the offset-x and offset-y to 1px, and the blur-radius to 0. This will create a small square that simulates a pixel.

.uiPencil_pixel{
   width:1px; 
   height: 1px;
   box-shadow: 1px 1px red;
   transform: scale(7);
}

In this example, to achieve a better preview, we will use transform: scale(7); to zoom in 7 times since the 1px pixel size is too small.

Step 3:

To create a larger block of pixels in CSS shadow art, you can add additional box-shadow properties with different horizontal (offset-x) and vertical (offset-y) values.

For example, to create a heart-shaped pixel block with a size of 5×5, you can apply the following offset position:

Once you have planned out your design, you can convert it to CSS code, for example:

:root  {
    --c1: #E44D26;
    --c2: #F97C5B;
}
.uiPencil_pixel {
  width:1px; 
  height: 1px;
  transform: scale(7);  
  box-shadow:
    1px 0px var(--c1),
    3px 0px var(--c1),
    0px 1px var(--c1),
    1px 1px var(--c2),
    2px 1px var(--c1),
    3px 1px var(--c2),
    4px 1px var(--c1),
    0px 2px var(--c1),
    1px 2px var(--c2),
    2px 2px var(--c2),
    3px 2px var(--c2),
    4px 2px var(--c1),
    1px 3px var(--c1),
    2px 3px var(--c2),
    3px 3px var(--c1),
    2px 4px var(--c1);
}

To achieve a better preview of the pixel art, you can use the transform property with the scale function. In this example, we will use transform: scale(7); to zoom in on the design. You can adjust the scale value based on your needs.

Animate the Pixel

You can also enhance your artwork by adding animation with the @keyframe rule. Here’s an example:

:root {
  --c1: #E44D26;
  --c2: #F97C5B;
}
@keyframes animate {
 0%, 100% {
  box-shadow:
    1px 0px var(--c1),
    3px 0px var(--c1),
    0px 1px var(--c1),
    1px 1px var(--c2),
    2px 1px var(--c1),
    3px 1px var(--c2),
    4px 1px var(--c1),
    0px 2px var(--c1),
    1px 2px var(--c2),
    2px 2px var(--c2),
    3px 2px var(--c2),
    4px 2px var(--c1),
    1px 3px var(--c1),
    2px 3px var(--c2),
    3px 3px var(--c1),
    2px 4px var(--c1);
 }
 50% {
  box-shadow:
    1px 1px var(--c2),
    2px 1px var(--c2),
    3px 1px var(--c2),
    1px 2px var(--c2),
    2px 2px var(--c2),
    3px 2px var(--c2),
    1px 3px var(--c2),
    2px 3px var(--c2),
    3px 3px var(--c2);
 }
}
.uiPencil_pixel {
  transform: scale(7);
  width:1px; 
  height: 1px;
  animation: animate 2s ease infinite;
}
</style>

<div class="uiPencil_pixel"></div>

You are all set now!

Congratulations! You now have all the basic knowledge to create pixel art using CSS box shadows. Unleash your creativity now!

My mini baby Yoda:

With a little creativity, the possibilities are endless. Happy Coding!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

If you found this article helpful and would like to show your support, you can buy me a coffee using the link below. Thanks a bunch!

Choose an amount

$5.00
$10.00
$15.00

Or enter a custom amount

$

Thank you for your contribution!

Donate

Topics:

CSS (31) css pseudo (3) debug (2) design (7) fonts (2) html (6) image (9) JavaScript (1) layout (5) MiniGame (3) optimization (10) performance (9) responsive (8)


Advertisements

Recent Post:

Advertisements

Related Posts

Advertisements
Advertisements
%d bloggers like this: